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>
256 lines
8.4 KiB
JavaScript
256 lines
8.4 KiB
JavaScript
'use strict';
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const {
|
|
cleanClaudeMcpServers,
|
|
cleanCodexConfig,
|
|
withGuardHook,
|
|
withPluginDir,
|
|
withSandboxDefaults,
|
|
} = require('./agent-setup.cjs');
|
|
|
|
const SEEDED = String.raw`model="gpt-6-astra"
|
|
model_reasoning_effort = "xhigh"
|
|
notify = [ "C:\\Users\\dev\\AppData\\Local\\OpenAI\\Codex\\bin\\notify.exe", "turn-ended" ]
|
|
|
|
[projects."/workspace"]
|
|
trust_level = "trusted"
|
|
|
|
[mcp_servers.headroom]
|
|
command = 'C:\Users\dev\.local\bin\headroom.CMD'
|
|
args = ["mcp", "serve"]
|
|
|
|
[mcp_servers.headroom.env]
|
|
HEADROOM_PROXY_URL = "http://127.0.0.1:18787"
|
|
|
|
[mcp_servers.memory]
|
|
command = "C:/Users/dev/tools/python.exe"
|
|
|
|
[mcp_servers.gitnexus]
|
|
command = "npx"
|
|
args = ["-y", "gitnexus@latest", "mcp"]
|
|
|
|
[mcp_servers.docs]
|
|
url = "https://developers.openai.com/mcp"
|
|
|
|
[marketplaces.openai-bundled]
|
|
source_type = "local"
|
|
source = '\\?\C:\Users\dev\.codex\.tmp\bundled-marketplaces\openai-bundled'
|
|
|
|
[marketplaces.mattpocock]
|
|
source_type = "git"
|
|
source = "https://github.com/mattpocock/skills.git"
|
|
|
|
[plugins."browser@openai-bundled"]
|
|
enabled = true
|
|
`;
|
|
|
|
test('a config seeded from Windows loses its host-only entries and nothing else', () => {
|
|
const { text, removed } = cleanCodexConfig(SEEDED);
|
|
|
|
assert.deepEqual(removed, [
|
|
'notify',
|
|
'mcp_servers.headroom',
|
|
'mcp_servers.memory',
|
|
'marketplaces.openai-bundled',
|
|
]);
|
|
assert.equal(
|
|
text,
|
|
String.raw`model="gpt-6-astra"
|
|
model_reasoning_effort = "xhigh"
|
|
|
|
[projects."/workspace"]
|
|
trust_level = "trusted"
|
|
|
|
[mcp_servers.gitnexus]
|
|
command = "npx"
|
|
args = ["-y", "gitnexus@latest", "mcp"]
|
|
|
|
[mcp_servers.docs]
|
|
url = "https://developers.openai.com/mcp"
|
|
|
|
[marketplaces.mattpocock]
|
|
source_type = "git"
|
|
source = "https://github.com/mattpocock/skills.git"
|
|
|
|
[plugins."browser@openai-bundled"]
|
|
enabled = true
|
|
`,
|
|
);
|
|
});
|
|
|
|
test('a Linux config is returned byte for byte, and cleaning twice changes nothing more', () => {
|
|
const linux =
|
|
'model = "x"\nnotify = ["/usr/bin/notify-send", "done"]\n\n[mcp_servers.gitnexus]\ncommand = "npx"\n';
|
|
assert.deepEqual(cleanCodexConfig(linux), { text: linux, removed: [] });
|
|
|
|
const once = cleanCodexConfig(SEEDED).text;
|
|
assert.deepEqual(cleanCodexConfig(once), { text: once, removed: [] });
|
|
});
|
|
|
|
test('a bracket inside a notify string does not end a multi-line array early', () => {
|
|
const text = 'notify = [\n "C:\\\\tools\\\\notify.exe",\n "[done]",\n "x",\n]\nmodel = "x"\n';
|
|
assert.deepEqual(cleanCodexConfig(text), { text: 'model = "x"\n', removed: ['notify'] });
|
|
});
|
|
|
|
test('a notify array spread over several lines is removed whole', () => {
|
|
const text = 'notify = [\n "C:\\\\tools\\\\notify.exe",\n "done",\n]\nmodel = "x"\n';
|
|
assert.deepEqual(cleanCodexConfig(text), { text: 'model = "x"\n', removed: ['notify'] });
|
|
});
|
|
|
|
test('a comment after a table header or a value does not hide a host-only entry', () => {
|
|
const text = [
|
|
'model = "x"',
|
|
'',
|
|
'[mcp_servers.memory] # local tool',
|
|
`command = 'C:\\tools\\memory.exe' # the host build`,
|
|
'',
|
|
'[mcp_servers.gitnexus] # note',
|
|
'command = "npx" # stays',
|
|
'',
|
|
].join('\n');
|
|
|
|
assert.deepEqual(cleanCodexConfig(text), {
|
|
text: ['model = "x"', '', '[mcp_servers.gitnexus] # note', 'command = "npx" # stays', ''].join(
|
|
'\n',
|
|
),
|
|
removed: ['mcp_servers.memory'],
|
|
});
|
|
});
|
|
|
|
test('a line that opens with a bracket but is no table header stays where it is', () => {
|
|
const text = 'args = [\n ["a", "b"],\n]\n\n[tui]\nx = 1\n';
|
|
assert.deepEqual(cleanCodexConfig(text), { text, removed: [] });
|
|
});
|
|
|
|
test('sandbox defaults are added only where the sandbox cannot start and none is chosen', () => {
|
|
const config = 'model = "x"\n\n[projects."/workspace"]\ntrust_level = "trusted"\n';
|
|
|
|
assert.equal(withSandboxDefaults(config, true), config);
|
|
|
|
const added = withSandboxDefaults(config, false);
|
|
assert.match(added, /^model = "x"\n\n# Set by \.devcontainer\/agent-setup\.cjs/);
|
|
assert.match(
|
|
added,
|
|
/\nsandbox_mode = "danger-full-access"\napproval_policy = "on-request"\n\n\[projects/,
|
|
);
|
|
assert.equal(withSandboxDefaults(added, false), added);
|
|
|
|
const chosen = 'sandbox_mode = "workspace-write"\n\n[tui]\nx = 1\n';
|
|
assert.equal(withSandboxDefaults(chosen, false), chosen);
|
|
});
|
|
|
|
test('an approval policy the config already sets is kept, not written twice', () => {
|
|
const config = 'approval_policy = "never"\n\n[tui]\nx = 1\n';
|
|
const added = withSandboxDefaults(config, false);
|
|
|
|
assert.equal(added.match(/^approval_policy\s*=/gm).length, 1);
|
|
assert.match(added, /^approval_policy = "never"$/m);
|
|
assert.match(added, /^sandbox_mode = "danger-full-access"$/m);
|
|
assert.equal(withSandboxDefaults(added, false), added);
|
|
});
|
|
|
|
test('a missing config still gets the sandbox default', () => {
|
|
const added = withSandboxDefaults(cleanCodexConfig('').text, false);
|
|
|
|
assert.match(added, /^sandbox_mode = "danger-full-access"$/m);
|
|
assert.match(added, /^approval_policy = "on-request"$/m);
|
|
assert.equal(withSandboxDefaults('', true), '');
|
|
});
|
|
|
|
test('a quoted table name with dots in it is one entry', () => {
|
|
const text = [
|
|
'[mcp_servers."win.tool"]',
|
|
"command = 'C:\\tools\\win.exe'",
|
|
'',
|
|
'[mcp_servers."win.tool".env]',
|
|
'A = "1"',
|
|
'',
|
|
'[mcp_servers."linux.tool"]',
|
|
'command = "npx"',
|
|
'',
|
|
].join('\n');
|
|
|
|
assert.deepEqual(cleanCodexConfig(text), {
|
|
text: ['[mcp_servers."linux.tool"]', 'command = "npx"', ''].join('\n'),
|
|
removed: ['mcp_servers.win.tool'],
|
|
});
|
|
});
|
|
|
|
test('sandbox defaults land before the first table even in a config with no top-level keys', () => {
|
|
const added = withSandboxDefaults('[tui]\nx = 1\n', false);
|
|
assert.ok(added.indexOf('sandbox_mode') < added.indexOf('[tui]'));
|
|
});
|
|
|
|
test('the guard is registered once, after the hooks already there', () => {
|
|
const existing = {
|
|
hooks: {
|
|
PreToolUse: [
|
|
{
|
|
matcher: 'Grep|Glob|Bash',
|
|
hooks: [{ type: 'command', command: 'node gitnexus-hook.cjs' }],
|
|
},
|
|
],
|
|
PostToolUse: [
|
|
{ matcher: 'Bash', hooks: [{ type: 'command', command: 'node gitnexus-hook.cjs' }] },
|
|
],
|
|
},
|
|
};
|
|
const next = withGuardHook(existing, '/home/node/.codex/hooks/guard/deny-destructive.cjs');
|
|
|
|
assert.equal(next.hooks.PreToolUse.length, 2);
|
|
assert.deepEqual(next.hooks.PreToolUse[0], existing.hooks.PreToolUse[0]);
|
|
assert.equal(next.hooks.PreToolUse[1].matcher, 'Bash');
|
|
assert.equal(
|
|
next.hooks.PreToolUse[1].hooks[0].command,
|
|
"node '/home/node/.codex/hooks/guard/deny-destructive.cjs'",
|
|
);
|
|
assert.deepEqual(next.hooks.PostToolUse, existing.hooks.PostToolUse);
|
|
assert.equal(withGuardHook(next, '/home/node/.codex/hooks/guard/deny-destructive.cjs'), next);
|
|
});
|
|
|
|
test('the guard is registered in a hooks file that does not exist yet', () => {
|
|
const next = withGuardHook({}, '/g.cjs');
|
|
assert.equal(next.hooks.PreToolUse.length, 1);
|
|
});
|
|
|
|
test('Claude MCP servers started by a Windows executable are removed, others kept', () => {
|
|
const config = {
|
|
userID: 'u',
|
|
mcpServers: {
|
|
context7: { type: 'http', url: 'https://mcp.context7.com/mcp' },
|
|
headroom: { command: 'C:\\Users\\dev\\.local\\bin\\headroom.CMD' },
|
|
local: { command: 'npx', args: ['-y', 'x'] },
|
|
},
|
|
projects: {
|
|
'/workspace': { mcpServers: { tool: { command: 'D:/tools/tool.exe' } }, history: [1] },
|
|
'/other': { history: [] },
|
|
},
|
|
};
|
|
const { config: next, removed } = cleanClaudeMcpServers(config);
|
|
|
|
assert.deepEqual(removed, ['headroom', 'tool']);
|
|
assert.deepEqual(Object.keys(next.mcpServers), ['context7', 'local']);
|
|
assert.deepEqual(next.projects['/workspace'], { mcpServers: {}, history: [1] });
|
|
assert.equal(next.userID, 'u');
|
|
|
|
const clean = cleanClaudeMcpServers(next);
|
|
assert.equal(clean.config, next);
|
|
assert.deepEqual(clean.removed, []);
|
|
});
|
|
|
|
test('the mod folder joins the plugin folders once and keeps the ones already there', () => {
|
|
const dir = '/home/node/.claude/mods/side-panels';
|
|
assert.equal(withPluginDir({ model: 'm' }, dir).env.CLAUDE_CODE_PLUGIN_DIRS, dir);
|
|
|
|
const other = { env: { CLAUDE_CODE_PLUGIN_DIRS: '/opt/mine', DEBUG: '1' } };
|
|
const next = withPluginDir(other, dir);
|
|
assert.equal(next.env.CLAUDE_CODE_PLUGIN_DIRS, ['/opt/mine', dir].join(path.delimiter));
|
|
assert.equal(next.env.DEBUG, '1');
|
|
assert.equal(withPluginDir(next, dir), next);
|
|
|
|
const tilde = { env: { CLAUDE_CODE_PLUGIN_DIRS: '~/.claude/mods/side-panels' } };
|
|
assert.equal(withPluginDir(tilde, dir, '/home/node'), tilde);
|
|
});
|