mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-05 00:27:26 +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>
133 lines
5.1 KiB
TypeScript
133 lines
5.1 KiB
TypeScript
import type { WorkList, Worktree } from '../types';
|
|
import { post } from './bus';
|
|
import type { Host, PaneId } from './host';
|
|
import { finishedSince, readRun, sizeOf, statusOf } from './review';
|
|
|
|
const field = (fields: string, key: string) =>
|
|
new RegExp(`(?:^|, )${key}=(.*?)(?=, \\w+=|$)`).exec(fields)?.[1] ?? '';
|
|
|
|
// ponytail: reads claude-mem's folded text, not its export. A value holding
|
|
// ", word=" cuts early and a list line claude-mem shortened is skipped; fold
|
|
// GET /api/work-state/export instead if either starts to matter.
|
|
export const parseWork = (text: string): WorkList[] => {
|
|
const lists: WorkList[] = [];
|
|
for (const line of text.split('\n')) {
|
|
const item = /^ {2}- \[(\w+)\] (.*?)(?: \((\w+=.*)\))?, updated (.*)$/.exec(line);
|
|
if (item) {
|
|
lists.at(-1)?.items.push({
|
|
status: item[1] ?? '',
|
|
task: item[2] ?? '',
|
|
next: field(item[3] ?? '', 'next'),
|
|
updated: item[4] ?? '',
|
|
});
|
|
continue;
|
|
}
|
|
const head = /^- (\S+?)(?:: (.*), updated (.*))?$/.exec(line);
|
|
if (!head) continue;
|
|
const state = head[2];
|
|
lists.push({
|
|
name: head[1] ?? '',
|
|
items:
|
|
state === undefined
|
|
? []
|
|
: [
|
|
{
|
|
status: 'state',
|
|
task: field(state, 'phase') || state.slice(0, 80),
|
|
next: field(state, 'next') || field(state, 'next_steps'),
|
|
updated: head[3] ?? '',
|
|
},
|
|
],
|
|
});
|
|
}
|
|
|
|
return lists;
|
|
};
|
|
|
|
const linesOf = (text: string) => text.split('\n').filter(Boolean);
|
|
|
|
/** How much a worktree wants a look: gone folder, then dirty or unreadable, then unpushed. */
|
|
export const rank = (one: Worktree) =>
|
|
(one.isPrunable ? 4 : 0) + (one.dirty !== 0 ? 2 : 0) + ((one.ahead ?? 0) > 0 ? 1 : 0);
|
|
|
|
const inspect = async (host: Host, block: string): Promise<Worktree> => {
|
|
const path = /^worktree (.*)$/m.exec(block)?.[1] ?? '';
|
|
const branch = /^branch refs\/heads\/(.*)$/m.exec(block)?.[1] ?? 'detached';
|
|
if (/^prunable/m.test(block)) return { path, branch, dirty: 0, ahead: null, isPrunable: true };
|
|
// Reading must not take the index lock from a git command the person is running.
|
|
const status = await host.git(['--no-optional-locks', 'status', '--porcelain'], path);
|
|
// No count comes back for a branch with no upstream: its push state is unknown, not clean.
|
|
const ahead = (await host.git(['rev-list', '--count', '@{upstream}..HEAD'], path))?.trim();
|
|
|
|
return {
|
|
path,
|
|
branch,
|
|
dirty: status === undefined ? null : linesOf(status).length,
|
|
ahead: ahead === undefined || ahead === '' ? null : Number(ahead),
|
|
isPrunable: false,
|
|
};
|
|
};
|
|
|
|
const readWorktrees = async (host: Host) => {
|
|
const listed = await host.git(['worktree', 'list', '--porcelain']);
|
|
if (listed === undefined) throw new Error('git worktree list failed');
|
|
const blocks = listed.split('\n\n').filter(Boolean);
|
|
const list: Worktree[] = [];
|
|
// ponytail: two git calls a worktree, 8 worktrees at a time, every refresh.
|
|
// Cache by HEAD and index mtime if a hundred worktrees start to feel slow.
|
|
for (let at = 0; at < blocks.length; at += 8) {
|
|
list.push(
|
|
...(await Promise.all(blocks.slice(at, at + 8).map((block) => inspect(host, block)))),
|
|
);
|
|
}
|
|
|
|
return list.sort((a, b) => rank(b) - rank(a) || a.path.localeCompare(b.path));
|
|
};
|
|
|
|
const READ: Record<PaneId, (host: Host) => Promise<unknown>> = {
|
|
worktrees: async (host) => host.put.worktrees(await readWorktrees(host)),
|
|
work: async (host) => host.put.work(parseWork(await host.mem('work_state_read', {}))),
|
|
agents: async (host) => {
|
|
await host.put.agents(await host.agents());
|
|
const before = await host.run();
|
|
const after = await readRun(host, Date.now());
|
|
await host.put.run(after);
|
|
const dir = after?.dir ?? '';
|
|
// A Codex leg is no subagent: its finish reaches the bus from its exit marker.
|
|
for (const lane of finishedSince(before, after)) {
|
|
await post(host, {
|
|
at: Date.now(),
|
|
kind: 'result',
|
|
from: `${lane.name} (review run)`,
|
|
to: 'main',
|
|
text: `${statusOf(lane)}, ${sizeOf(lane.bytes)}, in ${dir}`,
|
|
key: `lane:${dir}/${lane.name}`,
|
|
});
|
|
}
|
|
},
|
|
activity: async (host) => {
|
|
const status = await host.git(['--no-optional-locks', 'status', '--short']);
|
|
if (status === undefined) throw new Error('git status failed');
|
|
await host.put.changed(linesOf(status));
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Reads the panes asked for (none named: all of them) that a surface draws
|
|
* now, and leaves each one's note: when it was read, or why it failed. A
|
|
* closed or unplaced pane costs nothing.
|
|
*/
|
|
export const refresh = async (host: Host, asked: readonly PaneId[]) => {
|
|
const placed = await host.placed();
|
|
const due = (Object.keys(READ) as PaneId[]).filter(
|
|
(pane) => placed.has(pane) && (asked.length === 0 || asked.includes(pane)),
|
|
);
|
|
await Promise.all(
|
|
due.map((pane) =>
|
|
READ[pane](host).then(
|
|
() => host.put.note(pane, `at ${new Date().toISOString().slice(11, 16)} UTC`),
|
|
(error: unknown) => host.put.note(pane, `failed: ${String(error).slice(0, 120)}`),
|
|
),
|
|
),
|
|
);
|
|
};
|