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
tech(M2): irgendein Kommando davor, und die Shell-Sperre war aus
David89f8f242921a
diff --git a/src/lib/__tests__/shell-command-classify.test.ts b/src/lib/__tests__/shell-command-classify.test.tsindex ec2e58ac..0c50f320 100644--- a/src/lib/__tests__/shell-command-classify.test.ts+++ b/src/lib/__tests__/shell-command-classify.test.ts@@ -172,6 +172,63 @@ describe('the --no-verify ban survives the merge', () => {})})+// Die Sperre hing an commandKind, und commandKind entscheidet nach dem ERSTEN+// passenden Praefix. Irgendein Kommando davor — und sei es `echo hi` — machte+// sie wirkungslos; gefangen wurde nur `git add … && git commit …`, weil+// commandKind dafuer einen Sonderfall traegt. Alle fuenf Zeilen der Messung+// stehen hier, dazu die Faelle, die weiter durchlaufen muessen.+describe('the --no-verify ban applies to a commit anywhere in the line', () => {+ const refused = (c: string) => rejectShellCommand(c) !== null++ it('refuses the bare commit (unchanged)', () => {+ expect(refused('git commit --no-verify -m x')).toBe(true)+ })++ it('refuses a commit behind a read command', () => {+ expect(refused('git status && git commit --no-verify -m x')).toBe(true)+ })++ it('refuses a commit behind an unrelated command', () => {+ expect(refused('echo hi && git commit --no-verify -m x')).toBe(true)+ })++ it('refuses a commit behind a semicolon', () => {+ expect(refused('cd repo; git commit --no-verify -m x')).toBe(true)+ })++ it('still refuses the add-then-commit chain commandKind special-cased', () => {+ expect(refused('git add -A && git commit --no-verify -m x')).toBe(true)+ })++ it('refuses a commit hidden in a substitution or a pipe', () => {+ expect(refused('echo $(git commit --no-verify -m x)')).toBe(true)+ expect(refused('true | git commit --no-verify -m x')).toBe(true)+ expect(refused('git commit --no-verify -m x > /tmp/out')).toBe(true)+ })++ it('refuses even when a quoted separator splits the flag off the commit', () => {+ // Der Split ist anfuehrungszeichen-blind: `;` in der Nachricht trennt das+ // Flag vom Commit. Deshalb wird --no-verify weiter gegen die GANZE Zeile+ // geprueft, nicht je Segment.+ expect(refused('git commit -m "a;b" --no-verify')).toBe(true)+ })++ // Negativkontrollen: die Sperre gilt --no-verify, nicht dem Committen.+ it('lets an ordinary commit run inside a chain', () => {+ expect(rejectShellCommand('git add -A && git commit -m wip')).toBeNull()+ expect(rejectShellCommand('git status && git commit -m wip')).toBeNull()+ })++ it('lets an ordinary chain without a commit run', () => {+ expect(rejectShellCommand('git status && ls')).toBeNull()+ expect(rejectShellCommand('echo hi && ls -la')).toBeNull()+ })++ it('does not fire when a segment merely mentions the word commit', () => {+ expect(rejectShellCommand('git log --grep=commit')).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)diff --git a/src/lib/shell-command-classify.ts b/src/lib/shell-command-classify.tsindex 11e08979..608116d1 100644--- a/src/lib/shell-command-classify.ts+++ b/src/lib/shell-command-classify.ts@@ -131,17 +131,47 @@ export function isReadOnlyCommand(command: string): boolean {return READ_ONLY_PREFIXES.some((p) => c === p || c.startsWith(`${p} `))}+/**+ * Every command in a chained line.+ *+ * Split on the SAME {@link CHAINING} pattern `isReadOnlyCommand` refuses on,+ * so both functions agree on what a separator is: `;` `&` `|`, a newline,+ * every output redirection, and the two substitution openers. The pattern has+ * no capture groups, so `split` drops the separators and hands back only the+ * commands between them — including the BODY of a `$(…)` or a backtick pair,+ * which is a place a commit hides just as well as after an `&&`.+ */+function commandSegments(command: string): string[] {+ return command.split(CHAINING).map((s) => s.trim()).filter((s) => s.length > 0)+}+/*** 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).*+ * The ban applies to a commit ANYWHERE in the line. It used to ask+ * `commandKind`, which reports the kind of whatever comes FIRST, so anything+ * at all in front of the commit turned the refusal off: `git status && git+ * commit --no-verify` classified as 'git-status', `echo hi && …` and `cd+ * repo; …` as 'generic', and all three ran. Only `git add … && git commit …`+ * was caught, by a special case in `commandKind` that patched this exact hole+ * for exactly one prefix. Segmenting covers every prefix and needs no special+ * case; `commandKind` is left alone because `commandTimeoutMs` and+ * `commandIcon` read it too.+ *+ * `--no-verify` is deliberately still matched against the WHOLE line rather+ * than per segment: the split is quote-blind, so a `;` inside a commit+ * message would otherwise put the flag in a different segment from the commit+ * (`git commit -m "a;b" --no-verify`) and hand back the very bypass this is+ * closing. Testing the wider string can only ever refuse more, never less.+ ** 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)) {+ const commits = commandSegments(command).some((seg) => /^git\s+commit\b/.test(seg))+ if (commits && /--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