mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
* feat(devcontainer): provision the Claude Code and Codex agent setup The dev container seeds ~/.claude and ~/.codex once from the host. A config copied from a Windows host names MCP servers, a notify program and plugin marketplaces by C:\ paths that fail on every start in the Linux container, and Codex's bubblewrap sandbox cannot start where the container cannot create user namespaces. Fixing that by hand is lost on a volume reset, a fresh clone or another machine. post-create.sh now ends with agent-setup.cjs, which is idempotent and safe to re-run: - drop Windows-only MCP servers, marketplaces and notify from the seeded Codex config, and Windows-only MCP servers from ~/.claude.json - default Codex to full access with ask-on-request when user namespaces are unavailable and the config chooses no sandbox mode - install codex-guard.cjs as a Codex PreToolUse hook that refuses recursive deletes of protected roots, force pushes, pushes to main, git clean -x, npm publish and similar - install the side-panels mod for Claude Code - refetch the marketplace snapshots the seeded Codex config names, and give Codex compound-engineering and claude-mem when they are enabled in Claude Code - track the pr-tri-review skill and write its Codex entry, so the review runs from either CLI with the other as the second engine A failed step is reported and the rest still run; GITNEXUS_AGENT_SETUP=off skips the step. Hook trust in Codex stays a manual step. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * docs(pr-tri-review): run the Codex legs on gpt-6-astra or gpt-6.1-sol at xhigh The skill still named gpt-5.5 for every Codex leg. One variable now sets the model for all three legs: CODEX_MODEL, gpt-6-astra unless set, with gpt-6.1-sol as the cheaper tier. Both take --effort xhigh on the task legs; adversarial-review still takes a model and no effort. The digest names the model actually used. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(devcontainer): address PR review feedback (#3946) - codex-guard: drop redirections before reading the command word, so `2>/dev/null rm -rf /` is refused like the plain command - agent-setup: a TOML table header or string value followed by a comment is still a header or a value; a header with a trailing comment no longer crashes the Codex config step - side-panels bus: entries carry the key of the event they record; only a second report of the same event is skipped, so the same words sent twice are two entries - side-panels board: the claude-mem list is closed at session end when this session relayed to it, also after the board was switched off - side-panels review run: runs started in the same second are ordered by folder time, not by their random suffix - side-panels worktrees: a worktree whose status cannot be read is shown as unreadable, and one with no upstream as "push state unknown", instead of clean; a failed `git worktree list` or `git status` fails the read rather than showing an empty result Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(devcontainer): judge a guarded command wherever it stands (#3946) The guard read only the first word of a simple command, after a fixed list of prefixes. What may precede a command is open-ended, so each spelling the list missed was a bypass: `2>& 1 rm -rf /`, `timeout 10 rm -rf /`, `! rm -rf /`, `(rm -rf /)`. A watched command is now judged at any position in a simple command. Grouping and substitution marks end a command, so what stands inside `( )`, `{ }`, `$( )` and backticks is read too, and `eval` is followed like `sh -c`. `rm` right after a tool with its own rm subcommand (`git rm`, `docker rm`) is left alone. The cost is that an unquoted mention is refused as well (`echo rm -rf /`); a quoted one is not. shutdown/reboot/halt/poweroff are no longer watched: they do no harm in a container and are common words as arguments. Also note in the mod test that a session.send event names its recipient as a string. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(devcontainer): close the relative-path gap and state the guard's limit (#3946) - codex-guard: a leading `./` is stripped before a target is matched, and `..`, `../*` and `.*` are protected, so `rm -rf ./*` in the workspace is refused like `rm -rf *` - codex-guard and README: describe the guard as a best-effort check on command text, not a boundary. A target or command built from a variable or a substitution is not seen; refusing every such form would refuse routine cleanup. The two computed-target forms are in the test table as allowed, marked as the stated limit - side-panels review run: show the newest run that has a lane written in the last six hours, instead of nothing when the newest is stale - side-panels agents: an idle agent is not dimmed; it counts as active Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(devcontainer): address the fourth round of review feedback (#3946) agent-setup: - an approval_policy the Codex config already sets is kept instead of being written a second time (TOML refuses a duplicate key) - a missing config.toml still gets the sandbox default: the file is created when the container cannot sandbox - a quoted table name with dots (`[mcp_servers."win.tool"]`) is read as one entry, so its Windows-only server is removed with its subtables codex-guard: - `.` and `..` segments in an rm target are resolved before matching, so `/workspace/../*` is `/*` - a hidden-file glob (`dir/.*`) is refused wherever it stands - `-f` clustered with other short options (`git push -fu`) is a force push - a shell nested past the depth the guard follows is refused unread - the malformed-payload test no longer inherits CODEX_GUARD side-panels: - a message that was not delivered is not put on the bus or relayed Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * refactor(devcontainer): simplify the agent setup code without changing behaviour (#3946) - agent-setup: one writeText under the backup-keeping writer replaces two inline compare-then-write copies - codex-guard: hoist nameOf, normalise an rm target once per target - side-panels: one isLive predicate, one block for the worktree name lists, the lane dimming derived from statusOf, named review-run time windows, one default for a pane's note, one helper to split git output into lines, MARKER no longer exported - side-panels: a pane's independent reads run together, and `git status` runs with --no-optional-locks so reading never takes the index lock from a git command the person is running The committed and the simplified script produce the same config files on identical scratch homes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix(devcontainer): close gaps a fifth review pass found (#3946) - codex-guard: refuse `git push --mirror`, which overwrites and deletes remote refs without a force flag. - agent-setup: a `]` inside a string no longer ends a multi-line `notify` array early, so a Windows notify program is removed whole. - side-panels: `/panels` closes only the panes this mod opened, whatever `$.ui.panes()` lists. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
155 lines
4.4 KiB
JavaScript
155 lines
4.4 KiB
JavaScript
'use strict';
|
|
const assert = require('node:assert/strict');
|
|
const { spawnSync } = require('node:child_process');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const { refusal } = require('./codex-guard.cjs');
|
|
|
|
const GUARD = path.join(__dirname, 'codex-guard.cjs');
|
|
|
|
const DENIED = [
|
|
'rm -rf /',
|
|
'sudo rm -rf ~',
|
|
'rm -fr "$HOME"',
|
|
'cd /tmp/x && rm -rf *',
|
|
'rm -rf /workspace',
|
|
'rm -rf /workspace/.git',
|
|
'rm -r ~/.claude',
|
|
'rm /home/node/.claude-mem/claude-mem.db',
|
|
"bash -lc 'rm -rf ..'",
|
|
'git push --force origin feature',
|
|
'git push -f',
|
|
'git push origin +feature',
|
|
'git push origin main',
|
|
'git push origin HEAD:main',
|
|
'git -C /workspace clean -fdx',
|
|
'git clean -ndx',
|
|
'dd if=/dev/zero of=/dev/sda',
|
|
'chmod -R 777 /',
|
|
'npm publish',
|
|
'cd gitnexus && npm publish --access public',
|
|
'gh repo delete abc/def --yes',
|
|
':(){ :|:& };:',
|
|
'find . -name x | xargs rm -rf /',
|
|
'FOO=1 sudo -n rm -rf ~/',
|
|
'git -c user.name=x push --force',
|
|
'2>/dev/null rm -rf /',
|
|
'>/tmp/log rm -rf ~',
|
|
'> /tmp/log rm -rf /workspace',
|
|
'</dev/null git push --force origin feature',
|
|
'rm 2>/dev/null -rf /',
|
|
// What precedes a command is open-ended, so it is judged wherever it stands.
|
|
'2>& 1 rm -rf /',
|
|
'timeout 10 rm -rf /',
|
|
'stdbuf -o0 rm -rf /workspace',
|
|
'! rm -rf /',
|
|
'(rm -rf /)',
|
|
'{ rm -rf ~; }',
|
|
'if true; then rm -rf /; fi',
|
|
'echo "$(rm -rf /)"',
|
|
'echo `git clean -fdx`',
|
|
'eval "rm -rf /"',
|
|
'busybox rm -rf /',
|
|
// A leading ./ names the same thing.
|
|
'cd /workspace && rm -rf ./*',
|
|
'rm -rf ../*',
|
|
'rm -rf .*',
|
|
'rm -rf ././',
|
|
'rm -rf ./.git',
|
|
'rm -rf /workspace/../*',
|
|
'rm -rf /tmp/../workspace',
|
|
'rm -rf /workspace/.*',
|
|
'rm -rf build/.*',
|
|
'git push -fu origin feature',
|
|
'git push -uf origin feature',
|
|
'git push --mirror origin',
|
|
// Four shells deep: refused unread.
|
|
`sh -c "sh -c 'sh -c \\"sh -c \\\\\\"rm -rf /\\\\\\"\\"'"`,
|
|
// An unquoted mention is refused too: the guard fails closed.
|
|
'echo rm -rf / > notes.txt',
|
|
];
|
|
|
|
const ALLOWED = [
|
|
'rm -rf build/',
|
|
'rm -rf /tmp/pr-tri-review/123/run',
|
|
'rm -rf node_modules dist',
|
|
'rm file.txt',
|
|
'git push origin feature',
|
|
'git push --force-with-lease origin feature',
|
|
'git push -u origin fix/main-thread',
|
|
'git clean -fd',
|
|
'git commit -m "remove rm -rf / from docs"',
|
|
'grep -rn "git push --force" docs/',
|
|
'npm run publish:check',
|
|
'chmod -R u+w dist',
|
|
'gh release view v1',
|
|
'echo main',
|
|
'echo "rm -rf /" > notes.txt',
|
|
'git log --grep "push origin main"',
|
|
'bash -lc "ls && git status"',
|
|
'ls /nope 2>/dev/null',
|
|
'git rm -r --cached .',
|
|
'rm -rf ./build',
|
|
'rm -rf /workspace/gitnexus/../dist',
|
|
'git push -u origin feature',
|
|
'sh -c "sh -c \'ls\'"',
|
|
'rm -rf ./node_modules/.cache',
|
|
// The stated limit: a computed target is not seen.
|
|
'rm -rf "$TMP"',
|
|
'rm -rf "$(mktemp -d)"',
|
|
'docker rm -f web',
|
|
'npm run reboot',
|
|
"echo 'rm -rf /' > notes.txt",
|
|
'rm -rf build 2>&1',
|
|
];
|
|
|
|
for (const command of DENIED) {
|
|
test(`refuses: ${command}`, () => {
|
|
assert.equal(typeof refusal(command), 'string');
|
|
});
|
|
}
|
|
|
|
for (const command of ALLOWED) {
|
|
test(`allows: ${command}`, () => {
|
|
assert.equal(refusal(command), undefined);
|
|
});
|
|
}
|
|
|
|
const run = (payload, env = {}) =>
|
|
spawnSync(process.execPath, [GUARD], {
|
|
// A string is sent as it is, so a test can hand over a payload that is not JSON.
|
|
input: typeof payload === 'string' ? payload : JSON.stringify(payload),
|
|
encoding: 'utf8',
|
|
env: { ...process.env, CODEX_GUARD: '', ...env },
|
|
});
|
|
|
|
test('a refused Bash call exits 2 and names the reason on stderr', () => {
|
|
const ran = run({ tool_name: 'Bash', tool_input: { command: 'git clean -fdx' } });
|
|
assert.equal(ran.status, 2);
|
|
assert.match(ran.stderr, /git clean -x/);
|
|
});
|
|
|
|
test('an allowed Bash call exits 0 with nothing on stderr', () => {
|
|
const ran = run({ tool_name: 'Bash', tool_input: { command: 'ls -la' } });
|
|
assert.equal(ran.status, 0);
|
|
assert.equal(ran.stderr, '');
|
|
});
|
|
|
|
test('another tool is never judged', () => {
|
|
const ran = run({ tool_name: 'apply_patch', tool_input: { command: 'rm -rf /' } });
|
|
assert.equal(ran.status, 0);
|
|
});
|
|
|
|
test('CODEX_GUARD=off lets a refused command through', () => {
|
|
const ran = run(
|
|
{ tool_name: 'Bash', tool_input: { command: 'rm -rf /' } },
|
|
{ CODEX_GUARD: 'off' },
|
|
);
|
|
assert.equal(ran.status, 0);
|
|
});
|
|
|
|
test('an unreadable payload does not block', () => {
|
|
const ran = run('not json');
|
|
assert.equal(ran.status, 0);
|
|
});
|