The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(agent): command classifier and environment block replace tool-name plumbing
Davidcc172cfdf71e
diff --git a/src/lib/__tests__/host-platform.test.ts b/src/lib/__tests__/host-platform.test.tsindex 38731d90..69dc708c 100644--- a/src/lib/__tests__/host-platform.test.ts+++ b/src/lib/__tests__/host-platform.test.ts@@ -18,7 +18,7 @@import { describe, it, expect } from 'vitest'import { readFileSync } from 'node:fs'import { resolve } from 'node:path'-import { hostPlatform, platformPromptLine, type HostPlatform } from '../host-platform'+import { hostPlatform, platformPromptLine, hostEnvironmentBlock, type HostPlatform } from '../host-platform'describe('hostPlatform', () => {it('recognises the three platforms LU ships on', () => {@@ -73,7 +73,8 @@ describe('platformPromptLine', () => {it('invents nothing on an unknown platform', () => {const line = platformPromptLine('unknown')expect(line).toMatch(/unknown/i)- expect(line).toMatch(/system_info/)+ // system_info is retired (2.6.6); the shell itself is the probe now.+ expect(line).toMatch(/uname -s/)// A wrong incantation is worse than none.for (const cmd of ['open ', 'explorer', 'xdg-open', 'Invoke-Item', 'gtk-launch']) {expect(line).not.toContain(cmd)@@ -112,7 +113,25 @@ describe('the tools really are gone', () => {// There is no render harness in this repo, so the prompt is guarded at the// source, like DownloadBadge-autoclose.test.ts does.const agent = read('hooks', 'useAgentChat.ts')- expect(agent).toMatch(/platformPromptLine\(\)/)- expect(agent).toMatch(/The OS is stated above, so do not spend a call finding it out/)+ expect(agent).toMatch(/hostEnvironmentBlock\(\)/)+ expect(agent).toMatch(/OS, clock and timezone are stated above/)+ // Codex pays for the block too now (it never had the platform sentence).+ const codex = read('hooks', 'useCodex.ts')+ expect(codex).toMatch(/hostEnvironmentBlock\(\)/)+ })+})++describe('hostEnvironmentBlock', () => {+ it('carries platform sentence, clock and timezone in one block', () => {+ const fixed = new Date('2026-08-21T12:00:00Z')+ const block = hostEnvironmentBlock('macos', fixed)+ expect(block).toContain('macOS')+ expect(block).toContain('2026')+ expect(block).toMatch(/Trust this line/)+ })++ it('replaces the clock tool, so it must name the date of the run', () => {+ const fixed = new Date('2026-08-21T12:00:00Z')+ expect(hostEnvironmentBlock('linux', fixed)).toMatch(/August 2026/)})})diff --git a/src/lib/__tests__/shell-command-classify.test.ts b/src/lib/__tests__/shell-command-classify.test.tsnew file mode 100644index 00000000..20c532bf--- /dev/null+++ b/src/lib/__tests__/shell-command-classify.test.ts@@ -0,0 +1,125 @@+/**+ * The classifier is the load-bearing wall of the 2.6.6 tool merge: read-only+ * mode, the --no-verify ban, the test timeout and the icons all hang on it.+ * The most important property (plan E7): /review must be able to SEE the+ * diff and must NOT be able to write, including via chained commands.+ */+import { describe, it, expect } from 'vitest'+import {+ commandKind,+ commandIcon,+ commandTimeoutMs,+ isReadOnlyCommand,+ rejectShellCommand,+ TEST_RUN_TIMEOUT_MS,+} from '../shell-command-classify'++describe('read-only classifier', () => {+ it('lets a reviewer read', () => {+ for (const c of [+ 'git status --porcelain=2 --branch',+ 'git log --oneline -n 20',+ 'git diff HEAD~1',+ 'git show abc1234',+ 'git blame src/main.ts',+ 'ls -la src',+ 'cat package.json',+ 'pwd',+ ]) {+ expect(isReadOnlyCommand(c), c).toBe(true)+ }+ })++ it('refuses everything that writes', () => {+ for (const c of [+ 'git commit -m "x"',+ 'git push',+ 'rm -rf x',+ 'npm install',+ 'echo hi > file.txt',+ ]) {+ expect(isReadOnlyCommand(c), c).toBe(false)+ }+ })++ it('refuses chaining instead of parsing it, a read-only mode that can be talked around is not one', () => {+ for (const c of [+ 'git log; rm -rf x',+ 'git status && git push',+ 'git diff | tee /tmp/out',+ 'cat `which node`',+ 'ls $(pwd)/..',+ 'git log || rm x',+ ]) {+ expect(isReadOnlyCommand(c), c).toBe(false)+ }+ })++ it('does not mistake a prefix-lookalike for a read', () => {+ // "lsof" starts with "ls" as characters but not as a command word.+ expect(isReadOnlyCommand('lsof -i :3000')).toBe(false)+ expect(isReadOnlyCommand('catalog-tool run')).toBe(false)+ })+})++describe('command kinds', () => {+ it('recognises the git verbs', () => {+ expect(commandKind('git status')).toBe('git-status')+ expect(commandKind('git log --oneline -n 20')).toBe('git-log')+ expect(commandKind('git diff HEAD~1')).toBe('git-diff')+ expect(commandKind('git commit -m "msg"')).toBe('git-commit')+ expect(commandKind('git add -A && git commit -m "msg"')).toBe('git-commit')+ expect(commandKind('git push origin main')).toBe('git-push')+ })++ it('recognises test runs across runners', () => {+ for (const c of [+ 'npm test',+ 'npm run test',+ 'pnpm test',+ 'npx vitest run src/foo.test.ts',+ 'npx jest',+ 'cargo test',+ 'go test ./...',+ 'pytest tests/',+ 'python -m pytest',+ ]) {+ expect(commandKind(c), c).toBe('test-run')+ }+ })++ it('everything else is generic', () => {+ expect(commandKind('npm install')).toBe('generic')+ expect(commandKind('node script.js')).toBe('generic')+ })+})++describe('the --no-verify ban survives the merge', () => {+ it('refuses a commit with --no-verify, with a reason', () => {+ const msg = rejectShellCommand('git commit --no-verify -m "x"')+ expect(msg).toBeTruthy()+ expect(msg).toContain('--no-verify')+ })++ it('lets a normal commit through', () => {+ expect(rejectShellCommand('git commit -m "x"')).toBeNull()+ })++ it('does not fire on --no-verify outside a commit', () => {+ expect(rejectShellCommand('grep -rn -- --no-verify docs/')).toBeNull()+ })+})++describe('timeout and icon follow the command', () => {+ it('a recognised test run keeps the 300 s budget', () => {+ expect(commandTimeoutMs('npm test', 600_000)).toBe(TEST_RUN_TIMEOUT_MS)+ expect(commandTimeoutMs('npm install', 600_000)).toBe(600_000)+ })++ it('a commit still looks like a commit', () => {+ expect(commandIcon('git commit -m "x"')).toBe('git-commit')+ expect(commandIcon('git push')).toBe('git-push')+ expect(commandIcon('npx vitest run')).toBe('test')+ expect(commandIcon('node x.js')).toBe('terminal')+ })+})diff --git a/src/lib/host-platform.ts b/src/lib/host-platform.tsindex be5edd6d..f62b271e 100644--- a/src/lib/host-platform.ts+++ b/src/lib/host-platform.ts@@ -54,8 +54,36 @@ export function platformPromptLine(p: HostPlatform = hostPlatform()): string {case 'linux':return 'This machine runs Linux and shell_execute runs bash. Open a file or folder with `xdg-open <path>`, start an application with `gtk-launch <name>`. There is no reveal, so open the containing folder instead.'default:- // Never invent a platform: a wrong incantation is worse than none, and- // system_info is still there for the agent that really needs to know.- return 'The operating system of this machine is unknown. Call system_info before running a platform-specific command.'+ // Never invent a platform: a wrong incantation is worse than none. The+ // shell itself is the probe now that system_info is gone (2.6.6).+ return 'The operating system of this machine is unknown. Probe it with shell_execute (`uname -s`, and on failure assume Windows PowerShell) before running a platform-specific command.'}}++/**+ * The environment block for agent system prompts: platform sentence plus+ * clock, timezone and (when known) working directory.+ *+ * This retires system_info and get_current_time from the tool catalog+ * (2.6.6, plan section E3) with the same argument that removed desktop_open+ * and app_launch above: a few prompt tokens replace two schemas (~218 tokens+ * per step) AND the round trip small models spent asking what machine they+ * are on. The timestamp is taken when the run starts; that is what the old+ * tool call would have returned too.+ */+export function hostEnvironmentBlock(+ p: HostPlatform = hostPlatform(),+ now: Date = new Date(),+): string {+ let tz = ''+ try {+ tz = Intl.DateTimeFormat().resolvedOptions().timeZone ?? ''+ } catch {+ // No timezone is better than a wrong one.+ }+ const stamp = now.toLocaleString('en-GB', { dateStyle: 'full', timeStyle: 'short' })+ return [+ platformPromptLine(p),+ `Date and time at the start of this run: ${stamp}${tz ? ` (${tz})` : ''}. Trust this line; there is no clock tool.`,+ ].join('\n')+}diff --git a/src/lib/shell-command-classify.ts b/src/lib/shell-command-classify.tsnew file mode 100644index 00000000..de6e9557--- /dev/null+++ b/src/lib/shell-command-classify.ts@@ -0,0 +1,116 @@+/**+ * One classifier for what a shell command IS (read-only, commit, push, test+ * run), derived from the command text instead of a tool name.+ *+ * The 2.6.6 merge folds the twelve typed shell wrappers (git_status,+ * git_commit, run_tests, …) into shell_execute (plan section E2–E4). Four+ * behaviours used to hang on those NAMES and would silently die with them:+ * the read-only catalog for /review-style commands, the --no-verify ban, the+ * parsed summaries small models rely on, and the per-kind icon in the tool+ * block. They all hang on this file now.+ *+ * Read-only is deliberately conservative: a fixed prefix list, and any+ * chaining or substitution syntax disqualifies the command outright instead+ * of being parsed. A read-only mode that can be talked around is not one.+ */++export type ShellCommandKind =+ | 'git-status'+ | 'git-log'+ | 'git-diff'+ | 'git-commit'+ | 'git-push'+ | 'test-run'+ | 'read'+ | 'generic'++/** Chaining/substitution syntax: none of it is allowed in read-only mode. */+const CHAINING = /[;&|`]|\$\(/++/** Prefixes a reviewer may run. Kept short on purpose (plan E4 point 1). */+const READ_ONLY_PREFIXES = [+ 'git status',+ 'git log',+ 'git diff',+ 'git show',+ 'git blame',+ 'git branch',+ 'ls',+ 'cat ',+ 'pwd',+]++/** A test run keeps run_tests' 300 s budget instead of the shell's 600 s. */+const TEST_RUN = /^(npm|pnpm|yarn|bun)( run)? test\b|^(npx|pnpm|yarn|bun x?) ?(vitest|jest|mocha|playwright test)\b|^(cargo|go) test\b|^pytest\b|^python3? -m pytest\b/++export function commandKind(command: string): ShellCommandKind {+ const c = command.trim()+ if (/^git\s+status\b/.test(c)) return 'git-status'+ if (/^git\s+log\b/.test(c)) return 'git-log'+ if (/^git\s+(diff|show|blame)\b/.test(c)) return 'git-diff'+ if (/^git\s+commit\b/.test(c) || (/^git\s+add\b/.test(c) && /git\s+commit\b/.test(c))) return 'git-commit'+ if (/^git\s+push\b/.test(c)) return 'git-push'+ if (TEST_RUN.test(c)) return 'test-run'+ if (isReadOnlyCommand(c)) return 'read'+ return 'generic'+}++/**+ * May this command run while the catalog is stripped to read-only+ * (Code-Review Mode, /review, /plan, /diff …)?+ */+export function isReadOnlyCommand(command: string): boolean {+ const c = command.trim()+ if (!c || CHAINING.test(c)) return false+ // Word-boundary match: `ls -la` yes, `lsof` no.+ return READ_ONLY_PREFIXES.some((p) => {+ const pt = p.trim()+ return c === pt || c.startsWith(`${pt} `)+ })+}++/**+ * The one refusal that stays hard: --no-verify on a commit. The old+ * git_commit tool could not emit it (buildGitCommitCommand never did); with+ * the model writing the command itself, the executor has to say no+ * (plan E4 point 2).+ *+ * Returns the refusal text, or null when the command may run.+ */+export function rejectShellCommand(command: string): string | null {+ const kind = commandKind(command)+ if (kind === 'git-commit' && /--no-verify\b/.test(command)) {+ return 'Refused: git commit --no-verify skips the repository hooks. Fix what the hook reports instead of silencing it, then commit normally.'+ }+ return null+}++/** Timeout for the command, in ms. A recognised test run keeps run_tests' cap. */+export const TEST_RUN_TIMEOUT_MS = 300_000++export function commandTimeoutMs(command: string, fallbackMs: number): number {+ return commandKind(command) === 'test-run' ? TEST_RUN_TIMEOUT_MS : fallbackMs+}++/**+ * The icon key for the tool block (plan E4 point 6, audit D4): derived from+ * the command so a commit still looks like a commit after the merge.+ */+export function commandIcon(command: string): string {+ switch (commandKind(command)) {+ case 'git-status':+ case 'git-log':+ case 'git-diff':+ return 'git-read'+ case 'git-commit':+ return 'git-commit'+ case 'git-push':+ return 'git-push'+ case 'test-run':+ return 'test'+ case 'read':+ return 'read'+ default:+ return 'terminal'+ }+}