chore(cleanup): remove system-check skills
Remove check_system_memory, check_storage, check_battery_and_cpu and check_internet_connection along with their windows/ implementation and the empty mac/ placeholder. These general-purpose system-check skills have no place in Max's exclusive freelance-coach pipeline, which now runs server-side in Max API. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
bae5ace70c
commit
7c480e1ce4
@@ -1,6 +1,4 @@
|
||||
import type { SkillDefinition } from './types'
|
||||
import { windowsSkills } from './windows'
|
||||
import { macSkills } from './mac'
|
||||
import { memorySkills } from './memory'
|
||||
import { webSkills } from './web'
|
||||
import { browserSkills } from './browser'
|
||||
@@ -8,8 +6,7 @@ import { browserSkills } from './browser'
|
||||
export type { SkillDefinition } from './types'
|
||||
|
||||
export function loadSkills(): SkillDefinition[] {
|
||||
const platformSkills = process.platform === 'darwin' ? macSkills : windowsSkills
|
||||
return [...platformSkills, ...memorySkills, ...webSkills, ...browserSkills]
|
||||
return [...memorySkills, ...webSkills, ...browserSkills]
|
||||
}
|
||||
|
||||
export function findSkill(name: string): SkillDefinition | undefined {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import type { SkillDefinition } from '../types'
|
||||
|
||||
// A completer : equivalents macOS des competences Windows (osascript / open / etc.).
|
||||
export const macSkills: SkillDefinition[] = []
|
||||
@@ -1,34 +0,0 @@
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { POWERSHELL_EXE } from './lib/systemPaths'
|
||||
import type { SkillDefinition } from '../types'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
interface ConnectionInfo {
|
||||
Connected: boolean
|
||||
Ip: string | null
|
||||
}
|
||||
|
||||
const PS_SCRIPT = `
|
||||
$ping = Test-Connection -ComputerName 8.8.8.8 -Count 1 -Quiet -ErrorAction SilentlyContinue
|
||||
$ip = (Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.InterfaceAlias -notmatch 'Loopback' -and $_.IPAddress -notlike '169.254.*' } |
|
||||
Select-Object -First 1).IPAddress
|
||||
[PSCustomObject]@{ Connected = [bool]$ping; Ip = $ip } | ConvertTo-Json
|
||||
`
|
||||
|
||||
export const checkInternet: SkillDefinition = {
|
||||
name: 'check_internet_connection',
|
||||
description: "Teste si la connexion internet fonctionne et donne l'adresse IP locale.",
|
||||
parameters: { type: 'object', properties: {} },
|
||||
execute: async () => {
|
||||
const { stdout } = await execFileAsync(POWERSHELL_EXE, ['-NoProfile', '-Command', PS_SCRIPT], {
|
||||
timeout: 10000
|
||||
})
|
||||
const data = JSON.parse(stdout) as ConnectionInfo
|
||||
return data.Connected
|
||||
? `Internet fonctionne. Adresse IP locale : ${data.Ip ?? 'inconnue'}.`
|
||||
: 'Pas de connexion internet detectee.'
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { SkillDefinition } from '../types'
|
||||
import { systemMemory } from './systemMemory'
|
||||
import { systemStorage } from './systemStorage'
|
||||
import { systemStatus } from './systemStatus'
|
||||
import { checkInternet } from './checkInternet'
|
||||
|
||||
export const windowsSkills: SkillDefinition[] = [
|
||||
systemMemory,
|
||||
systemStorage,
|
||||
systemStatus,
|
||||
checkInternet
|
||||
]
|
||||
@@ -1,9 +0,0 @@
|
||||
import { join } from 'path'
|
||||
|
||||
// Sur certaines configurations, le PATH de l'environnement ou tourne l'app ne contient pas
|
||||
// System32 : un execFile('powershell.exe', ...) ou execFile('taskkill', ...) en nom nu echoue
|
||||
// alors avec ENOENT. On resout donc toujours les chemins absolus des binaires systeme utilises.
|
||||
const systemRoot = process.env.SystemRoot || process.env.windir || 'C:\\Windows'
|
||||
const system32 = join(systemRoot, 'System32')
|
||||
|
||||
export const POWERSHELL_EXE = join(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe')
|
||||
@@ -1,16 +0,0 @@
|
||||
import { freemem, totalmem } from 'os'
|
||||
import type { SkillDefinition } from '../types'
|
||||
|
||||
const toGo = (bytes: number): string => (bytes / 1024 ** 3).toFixed(1)
|
||||
|
||||
export const systemMemory: SkillDefinition = {
|
||||
name: 'check_system_memory',
|
||||
description: "Renvoie l'etat de la memoire RAM de l'ordinateur (totale, utilisee, libre).",
|
||||
parameters: { type: 'object', properties: {} },
|
||||
execute: async () => {
|
||||
const total = totalmem()
|
||||
const free = freemem()
|
||||
const used = total - free
|
||||
return `Memoire RAM : ${toGo(used)} Go utilises sur ${toGo(total)} Go (${toGo(free)} Go libres).`
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { POWERSHELL_EXE } from './lib/systemPaths'
|
||||
import type { SkillDefinition } from '../types'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
interface StatusInfo {
|
||||
BatteryPercent: number | null
|
||||
Charging: boolean | null
|
||||
CpuPercent: number
|
||||
}
|
||||
|
||||
const PS_SCRIPT = `
|
||||
$battery = Get-CimInstance Win32_Battery -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
$cpu = (Get-CimInstance Win32_Processor | Measure-Object -Property LoadPercentage -Average).Average
|
||||
[PSCustomObject]@{
|
||||
BatteryPercent = if ($battery) { $battery.EstimatedChargeRemaining } else { $null }
|
||||
Charging = if ($battery) { $battery.BatteryStatus -eq 2 } else { $null }
|
||||
CpuPercent = [math]::Round($cpu, 0)
|
||||
} | ConvertTo-Json
|
||||
`
|
||||
|
||||
export const systemStatus: SkillDefinition = {
|
||||
name: 'check_battery_and_cpu',
|
||||
description:
|
||||
'Renvoie le niveau de batterie (si ordinateur portable) et la charge processeur actuelle.',
|
||||
parameters: { type: 'object', properties: {} },
|
||||
execute: async () => {
|
||||
const { stdout } = await execFileAsync(POWERSHELL_EXE, ['-NoProfile', '-Command', PS_SCRIPT])
|
||||
const data = JSON.parse(stdout) as StatusInfo
|
||||
|
||||
const batteryText =
|
||||
data.BatteryPercent !== null
|
||||
? `Batterie a ${data.BatteryPercent}%${data.Charging ? ' (en charge)' : ''}.`
|
||||
: 'Pas de batterie detectee (ordinateur fixe).'
|
||||
|
||||
return `${batteryText} Processeur utilise a ${data.CpuPercent}%.`
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { POWERSHELL_EXE } from './lib/systemPaths'
|
||||
import type { SkillDefinition } from '../types'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
interface VolumeInfo {
|
||||
DriveLetter: string
|
||||
SizeGB: number
|
||||
FreeGB: number
|
||||
}
|
||||
|
||||
const PS_SCRIPT = `Get-Volume | Where-Object { $_.DriveLetter } | Select-Object DriveLetter,@{N='SizeGB';E={[math]::Round($_.Size/1GB,1)}},@{N='FreeGB';E={[math]::Round($_.SizeRemaining/1GB,1)}} | ConvertTo-Json`
|
||||
|
||||
export const systemStorage: SkillDefinition = {
|
||||
name: 'check_storage',
|
||||
description:
|
||||
"Renvoie l'espace de stockage utilise et disponible sur les disques de l'ordinateur.",
|
||||
parameters: { type: 'object', properties: {} },
|
||||
execute: async () => {
|
||||
const { stdout } = await execFileAsync(POWERSHELL_EXE, ['-NoProfile', '-Command', PS_SCRIPT])
|
||||
const parsed = JSON.parse(stdout) as VolumeInfo | VolumeInfo[]
|
||||
const volumes = Array.isArray(parsed) ? parsed : [parsed]
|
||||
return volumes
|
||||
.map(
|
||||
(v) =>
|
||||
`Disque ${v.DriveLetter} : ${(v.SizeGB - v.FreeGB).toFixed(1)} Go utilises sur ${v.SizeGB} Go (${v.FreeGB} Go libres)`
|
||||
)
|
||||
.join('. ')
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
|
||||
describe('systemPaths', () => {
|
||||
const originalSystemRoot = process.env.SystemRoot
|
||||
const originalWindir = process.env.windir
|
||||
|
||||
afterEach(() => {
|
||||
if (originalSystemRoot === undefined) delete process.env.SystemRoot
|
||||
else process.env.SystemRoot = originalSystemRoot
|
||||
if (originalWindir === undefined) delete process.env.windir
|
||||
else process.env.windir = originalWindir
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
it('should fall back to C:\\Windows when neither SystemRoot nor windir is set', async () => {
|
||||
delete process.env.SystemRoot
|
||||
delete process.env.windir
|
||||
vi.resetModules()
|
||||
const { POWERSHELL_EXE } = await import('../../src/main/skills/windows/lib/systemPaths')
|
||||
expect(POWERSHELL_EXE).toContain('C:\\Windows')
|
||||
})
|
||||
|
||||
it('should use SystemRoot when set', async () => {
|
||||
process.env.SystemRoot = 'D:\\CustomWindows'
|
||||
vi.resetModules()
|
||||
const { POWERSHELL_EXE } = await import('../../src/main/skills/windows/lib/systemPaths')
|
||||
expect(POWERSHELL_EXE).toContain('D:\\CustomWindows')
|
||||
})
|
||||
})
|
||||
@@ -1,15 +0,0 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
vi.mock('os', () => ({
|
||||
totalmem: () => 16 * 1024 ** 3,
|
||||
freemem: () => 4 * 1024 ** 3
|
||||
}))
|
||||
|
||||
const { systemMemory } = await import('../../src/main/skills/windows/systemMemory')
|
||||
|
||||
describe('check_system_memory', () => {
|
||||
it('should report used/total/free memory in GB computed from os.totalmem/freemem', async () => {
|
||||
const result = await systemMemory.execute({})
|
||||
expect(result).toBe('Memoire RAM : 12.0 Go utilises sur 16.0 Go (4.0 Go libres).')
|
||||
})
|
||||
})
|
||||
@@ -1,85 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
const execFileMock = vi.fn(
|
||||
(
|
||||
_cmd: string,
|
||||
_args: string[],
|
||||
_opts: unknown,
|
||||
cb?: (err: Error | null, result: unknown) => void
|
||||
) => {
|
||||
const callback = typeof _opts === 'function' ? (_opts as typeof cb) : cb
|
||||
callback?.(null, { stdout: '{}', stderr: '' })
|
||||
}
|
||||
)
|
||||
vi.mock('child_process', () => ({ execFile: execFileMock }))
|
||||
|
||||
const { systemStatus } = await import('../../src/main/skills/windows/systemStatus')
|
||||
const { systemStorage } = await import('../../src/main/skills/windows/systemStorage')
|
||||
const { checkInternet } = await import('../../src/main/skills/windows/checkInternet')
|
||||
|
||||
function mockStdout(json: unknown): void {
|
||||
execFileMock.mockImplementation(
|
||||
(
|
||||
_cmd: string,
|
||||
_args: string[],
|
||||
optsOrCb: unknown,
|
||||
cb?: (err: Error | null, result: unknown) => void
|
||||
) => {
|
||||
const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb
|
||||
callback?.(null, { stdout: JSON.stringify(json), stderr: '' })
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('check_battery_and_cpu', () => {
|
||||
it('should report no battery for a desktop computer', async () => {
|
||||
mockStdout({ BatteryPercent: null, Charging: null, CpuPercent: 42 })
|
||||
const result = await systemStatus.execute({})
|
||||
expect(result).toMatch(/Pas de batterie detectee/)
|
||||
expect(result).toMatch(/42%/)
|
||||
})
|
||||
|
||||
it('should report battery level and charging state for a laptop', async () => {
|
||||
mockStdout({ BatteryPercent: 80, Charging: true, CpuPercent: 10 })
|
||||
const result = await systemStatus.execute({})
|
||||
expect(result).toMatch(/Batterie a 80%/)
|
||||
expect(result).toMatch(/en charge/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('check_storage', () => {
|
||||
it('should report usage for a single drive', async () => {
|
||||
mockStdout({ DriveLetter: 'C', SizeGB: 500, FreeGB: 100 })
|
||||
const result = await systemStorage.execute({})
|
||||
expect(result).toMatch(/Disque C : 400\.0 Go utilises sur 500 Go \(100 Go libres\)/)
|
||||
})
|
||||
|
||||
it('should report usage for multiple drives', async () => {
|
||||
mockStdout([
|
||||
{ DriveLetter: 'C', SizeGB: 500, FreeGB: 100 },
|
||||
{ DriveLetter: 'D', SizeGB: 1000, FreeGB: 900 }
|
||||
])
|
||||
const result = await systemStorage.execute({})
|
||||
expect(result).toMatch(/Disque C/)
|
||||
expect(result).toMatch(/Disque D/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('check_internet_connection', () => {
|
||||
it('should report a working connection with its local IP', async () => {
|
||||
mockStdout({ Connected: true, Ip: '192.168.1.10' })
|
||||
const result = await checkInternet.execute({})
|
||||
expect(result).toMatch(/Internet fonctionne/)
|
||||
expect(result).toMatch(/192\.168\.1\.10/)
|
||||
})
|
||||
|
||||
it('should report no connection', async () => {
|
||||
mockStdout({ Connected: false, Ip: null })
|
||||
const result = await checkInternet.execute({})
|
||||
expect(result).toMatch(/Pas de connexion internet/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user