Compare commits

...

7 Commits

Author SHA1 Message Date
nntrivi2001 887dc4640e chore(release): bump version to 1.8.12 2026-09-28 17:49:38 +07:00
nntrivi2001 2b8f83d2dd refactor(lanes): drop the workflow skills and Superpowers link; pipelines go dormant
The plugin stops shipping its workflow layer:
- skills/ship-feature and skills/ship-feature-lane, the 18 stage/ship slash
  commands (plugin.json keeps agenthub-doctor/update/open), and all four
  agents/ (qc-local, senior-gate-reviewer, backend-reviewer, frontend-reviewer).
- CLI `agenthub skills install`, `agenthub lanes agents install`,
  `agenthub ship-full|ship-quick`; routes POST /api/skills/install and
  POST /api/lanes/:id/agents/install; the Settings button, the lane Tools
  menu item and the Add-lane setup step that called them.
- The Superpowers auto-install: server/lib/skill-plugins.js, the bootstrap's
  autoInstallSkillPlugins / skillPluginsSettled gate and the doctor row.

Pipelines are kept but dormant: server/data/pipelines/ is deleted, so no
template ships. `default` resolves to EMPTY_PIPELINE (no nodes, progress 0),
createLane still accepts it, POST /api/lanes/:id/stage answers 400
ENOPIPELINE, and the Workspace hides the stage timer, pickers, PipelineMap
and strip stage chip for a lane with no nodes. A template dropped into
DASHBOARD_PIPELINES_DIR turns it all back on. The server suite loads its
templates from server/__tests__/fixtures/pipelines/.

Docs: CLAUDE.md (marker, retired rules), README(.vi), INSTALL, ARCHITECTURE,
docs/LANES|PLUGINS|CLI|API, agenthub-introduction.html.
2026-09-28 17:49:05 +07:00
nntrivi2001 3c238bc5c4 chore(release): bump version to 1.8.11 2026-09-28 10:26:56 +07:00
nntrivi2001 9d096b61f7 feat(lanes): Antigravity lanes, release exited panes, fresh Codex starts
- antigravity: a third lane tool running Antigravity's `agy` CLI. `-i`
  carries the first prompt, `--continue` resumes; `agy` has no model,
  effort or permission flag, and `--dangerously-skip-permissions` is never
  emitted. No pipeline, no agents install, and no AI Router (native only,
  else EUNSUPPORTED). Add lane gains an Antigravity choice and the binary
  probe maps it to `agy`.
- UI: the lane card no longer renders a frame holding only a "Codex" chip,
  and the prompt box names the lane's CLI ("Ask Codex anything…"), via
  LANE_TOOL_LABEL.
- runs: a pane that exits is released on a 10 s server beat
  (healAllRunIds, DASHBOARD_RUN_HEAL_MS). Codex and Antigravity fire no
  hook, so their lanes stayed "running" until something re-read them.
- codex: Start no longer sends resumeLast — only "Resume last session"
  continues the previous thread.
2026-09-28 10:22:07 +07:00
nntrivi2001 952e8584f0 feat: per-change-block hunk actions (#50), codex lanes without a pipeline, macOS LaunchAgent
- git (#50): stage-hunk/discard-hunk take an optional `block` — one run of
  consecutive +/- lines inside an @@ hunk. `onlyBlock` (server/lib/git-diff.js)
  cuts git's fresh hunk down to it, folding the other blocks into the side
  being checked; LaneDiffView hangs one review bar per block (unified + split)
  and its arrows walk blocks.
- git exclude: entries AgentHub writes for a lane go to the COMMON git dir with
  the lane's path prefix (server/lib/git-exclude.js, used by router-apply and
  lane-mcp) — a linked worktree's own info/exclude is never read by git, and a
  subdir lane has no .git. MCP sync no longer fails with ENOTDIR on a worktree
  lane or creates a stray .git in a non-repo lane.
- codex lanes carry no pipeline: codex-ingest mirrors only idle/running,
  codex-nudge is removed, agents install writes nothing for codex, the
  Workspace hides stage/pipeline/feature pickers/PipelineMap for them, and
  every server start clears leftover codex stage data and the old AGENTS.md
  stage block.
- Changes panel: a whole file opens for reading and enters the editor on a
  click on its text (caret at the clicked line), not automatically.
- macOS: LaunchAgent start-at-login (scripts/launchd-service.js, picked by
  scripts/service-manager.js).
- Adds the AgentHub introduction slides and their image-embedding script.
2026-09-25 17:30:28 +07:00
nntrivi2001 3f6e903c22 chore(release): bump version to 1.8.10 2026-09-25 13:37:46 +07:00
nntrivi2001 1da46f10f4 feat(git): per-block conflict view with mine/theirs choices (#45)
Opening a conflicted file in the Changes panel now shows each conflict
block as its two sides, labelled from git's markers and tinted apart,
with Keep mine / Take theirs / Keep both per block (undoable, ^/v to
jump). Save and mark resolved writes the chosen text through the
whole-file editor's PUT /git/file (baseSha stale check) then runs
resolve done. The Merge conflicts group's buttons are text, and a
conflicted file is marked with a red ! in the Files tree.

Fix: ls-files --cached lists an unmerged path once per stage, so the
tree showed a conflicted file three times; lsFiles now dedupes.
2026-09-25 13:35:50 +07:00
117 changed files with 4470 additions and 4851 deletions
+1 -19
View File
@@ -12,25 +12,7 @@
"commands": [
"./plugins/agenthub/commands/agenthub-doctor.md",
"./plugins/agenthub/commands/agenthub-update.md",
"./plugins/agenthub/commands/agenthub-open.md",
"./plugins/agenthub/commands/intake.md",
"./plugins/agenthub/commands/plan.md",
"./plugins/agenthub/commands/implement.md",
"./plugins/agenthub/commands/tests.md",
"./plugins/agenthub/commands/e2e.md",
"./plugins/agenthub/commands/e2e-passed.md",
"./plugins/agenthub/commands/review.md",
"./plugins/agenthub/commands/qc-plan.md",
"./plugins/agenthub/commands/qc.md",
"./plugins/agenthub/commands/gate.md",
"./plugins/agenthub/commands/publishing.md",
"./plugins/agenthub/commands/pr-open.md",
"./plugins/agenthub/commands/reported.md",
"./plugins/agenthub/commands/watching-pr.md",
"./plugins/agenthub/commands/merged.md",
"./plugins/agenthub/commands/done.md",
"./plugins/agenthub/commands/ship-full.md",
"./plugins/agenthub/commands/ship-quick.md"
"./plugins/agenthub/commands/agenthub-open.md"
],
"hooks": {
"PreToolUse": [
+4 -35
View File
@@ -11,42 +11,11 @@
- Update docs whenever workflow or architecture changes — follow `skills/update-project-docs/` automatically at the end of every change-set (README + VN/CN/KO mirrors, ARCHITECTURE, wiki + i18n + cache bump, server/client READMEs, docs/*).
- Every applicable source file you create or update (`.js/.ts/.tsx/.cjs/.mjs/.py/.sh/.css`) must start with the authorship header: a truthful file overview plus the exact line `@author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>`. See `skills/file-headers/` and `.claude/rules/file-headers.md`; verify with `bash skills/file-headers/scripts/check-headers.sh`.
## Declare your lane stage as you work
## Lane stage
This repository is watched by AgentHub, its own dashboard. A **lane** is keyed by
working directory, and the pipeline map only moves forward when the agent doing
the work declares its stage:
```bash
agenthub stage <stage> --tool codex --evidence "<what is actually done>"
```
- Call it at every real transition — starting to plan, starting to implement,
running tests, opening the PR — not once at the end.
- Stage names, `default` template: `intake → plan → implement → tests → review
→ gate → ship → done` (the 16-node `ship-feature` template accepts these as
aliases too; `agenthub stage` warns on stderr and names the valid nodes if a stage
matches none).
- **`--tool codex` matters.** One directory can back both a `claude` lane and a
`codex` lane, and without a tool the command fails rather than guess (it names
both candidates). Inside a pane the dashboard started you need nothing — that
pane carries `AGENTHUB_LANE_ID`, which outranks everything but `--lane`.
- If `agenthub stage` reports that no lane owns the directory, this checkout was
never adopted: skip the stage calls and carry on. Stage reporting is
reporting, never control flow — a failed `agenthub stage` never justifies skipping
a step of the actual work.
The dashboard also *infers* your stage from your tool calls (it reads Codex's
own rollout journals — see `docs/LANES.md#stage-detection`), and on a codex lane
that inference does move the pipeline map forward on its own. It still never
counts as **evidence**: a node it moved through stays amber and never renders
green. Only your own declaration does that — which is why the call above is
worth making even when the map already looks right.
If you hold a stage for a while with no evidence recorded, the dashboard may
type a one-line `[agenthub]` reminder straight into this pane asking you to run
`agenthub stage ... --evidence "..."`. That is the dashboard, not the user — treat
it as the same instruction as this section and just make the real call.
AgentHub's `codex` (and `antigravity`) lanes carry no pipeline: the dashboard shows no stage for
them and never infers or advances one, so there is no `agenthub stage` call to
make while you work here as Codex.
## Where to work
- `server/` for API/routes/data processing.
+19 -86
View File
@@ -370,7 +370,7 @@ graph TD
| `lib/lane-services.js` | (A2) `ensureDatabase`/`dropDatabase` call the profile's `db-create`/`db-drop` hooks — AgentHub stays stack-agnostic on purpose. A state-dir marker file tracks whether a slot's database was already created, since a plain `createdb` can't be re-run safely and AgentHub can't assume the hook is idempotent; this is also how `upLane` knows to seed only a freshly-created database. `dropDatabase` asserts the lane is `managed` and that the name being dropped is one this lane's own slot actually derives (itself or its `_test` sibling) before spawning anything |
| `lib/lane-features.js` | (B) Per-feature state and archive. `activateFeature` archives the lane's current active feature (if different) and restores the target's saved stage onto the live `lanes` row — the row stays the one live view every other reader already uses. `canonicalizeSlug` is a DELIBERATELY separate rule from `worktree.js:slugify` (drops a leading `feat/`, keeps `[A-Za-z0-9._-]`, does not lowercase) — the two must never be conflated. `clearLane` (`lib/lanes.js`) archives the active feature (if any) before resetting; a lane that never activated one is unaffected |
| `lib/git-diff.js` | (#34/#35) Reads a lane's code changes as structured hunks for the Workspace Changes panel — `work` (HEAD vs the working tree, untracked files included), `branch` (`<base>...HEAD`) or `commit` (one sha), at a caller-chosen `context` (default 3, clamped to 5000, which is how the viewer expands a diff towards the whole file). Also the four reads behind History, the whole-file view, quick-open and the file explorer: `listCommits`, `readFileAt` (the `work` revision is realpath-confined to the lane; anything else goes through `git show`), `listPaths` and `listTree` (both `git ls-files`, so `.gitignore` is honoured without a skip-list). Read-only, argv-only through `worktree.js:git()`. An untracked file's patch is SYNTHESIZED from the file itself rather than fetched with `git diff --no-index`, which exits non-zero on a difference and would read as a failure. Three caps (300 files, 200 KB per file, 1 MB per full read) keep a lane mid-build from shipping megabytes of patch into a browser; a cap that bit sets `truncated` |
| `lib/git-ops.js` | (#34) The git WRITES a lane offers: `fetch`, `pull`, `push`, `stage`, `unstage`, `discard`, `stage-hunk`/`discard-hunk` (one hunk, matched by its `@@` line against a fresh diff; `discard-hunk` needs `confirm:true`), `commit` (everything, or `only:"staged"`), `switch`, `branch-create` (never switches) and `branch-delete` (`-d`, refusing `main`/`master`/`development`/`develop`, the current branch and one another worktree holds), `publish` (`remote add origin -- <url>` + `push -u origin HEAD`, only when the repo has NO remote and a commit; the one write whose destination comes from the request, so the URL is allowlisted by `validateRemoteUrl` — `https://` without userinfo, `ssh://`, scp-like `user@host:path` — and `origin` is removed again when the push fails), and `merge`/`resolve`/`merge-commit`/`merge-abort` (issue #45: a named branch into a clean repo-root lane, conflicts resolved per file, abort behind `confirm:true`). A caller-supplied path is validated against `git status` before it reaches an argv, so only a path git already reports as changed is reachable; `discard` — the one irreversible action — additionally requires `confirm: true`. No rebase, reset or stash, because a dashboard button is the wrong place to start an operation whose recovery needs a terminal (`reset` stays behind worktree.js's three-check destroy guard). `pull` is ALWAYS `--ff-only` and `switch` refuses a dirty tree, so neither can invent a merge commit or a conflict underneath a running agent; `push` pushes `HEAD`, never a branch name from the request. Network actions carry a 60s timeout |
| `lib/git-ops.js` | (#34) The git WRITES a lane offers: `fetch`, `pull`, `push`, `stage`, `unstage`, `discard`, `stage-hunk`/`discard-hunk` (one hunk, matched by its `@@` line against a fresh diff — or one `block`, a run of +/- lines inside it, the others folded into context by `onlyBlock` in `git-diff.js` (#50); `discard-hunk` needs `confirm:true`), `commit` (everything, or `only:"staged"`), `switch`, `branch-create` (never switches) and `branch-delete` (`-d`, refusing `main`/`master`/`development`/`develop`, the current branch and one another worktree holds), `publish` (`remote add origin -- <url>` + `push -u origin HEAD`, only when the repo has NO remote and a commit; the one write whose destination comes from the request, so the URL is allowlisted by `validateRemoteUrl` — `https://` without userinfo, `ssh://`, scp-like `user@host:path` — and `origin` is removed again when the push fails), and `merge`/`resolve`/`merge-commit`/`merge-abort` (issue #45: a named branch into a clean repo-root lane, conflicts resolved per file, abort behind `confirm:true`). A caller-supplied path is validated against `git status` before it reaches an argv, so only a path git already reports as changed is reachable; `discard` — the one irreversible action — additionally requires `confirm: true`. No rebase, reset or stash, because a dashboard button is the wrong place to start an operation whose recovery needs a terminal (`reset` stays behind worktree.js's three-check destroy guard). `pull` is ALWAYS `--ff-only` and `switch` refuses a dirty tree, so neither can invent a merge commit or a conflict underneath a running agent; `push` pushes `HEAD`, never a branch name from the request. Network actions carry a 60s timeout |
| `lib/proof.js` | (C) Proof gallery: lists/serves/deletes QC screenshots grouped by feature slug (Task B's `lane_features`) and phase, under `<lane.cwd>/.playwright-mcp/proof/<slug>/<group>/`. Every path is resolved, realpath'd, and containment-checked before touching `fs` — the entire security surface. `ensureProofLink` ports Shipyard's `ensure_proof_link` (converge a stray clone-root `proof/` onto the canonical dir); never auto-invoked, exposed only as `agenthub lanes proof-link` |
| `lib/named-lock.js` | (D) Cross-lane named locks — the OTHER axis from `lib/lane-lock.js`'s per-lane, in-process serialization, deliberately a separate module. `mkdir` is the atomicity primitive (EEXIST decides "already held" in one syscall, never check-then-create). `LOCK_MAX_HOLD` (default 2700s) breaks a stale holder on the next acquire, floored at 300s so the floor — not the configurable default — is the actual safety property: nothing can force-break a live holder by setting the env var low. Single-shot only; the CLI's `agenthub lock acquire` owns the polling loop, keeping the server side non-orchestrating like every other lane primitive |
@@ -606,7 +606,7 @@ graph LR
| `/activity` | ActivityFeed | `GET /api/events?limit=100` — click row to expand inline payload; "Session →" button navigates to `/sessions/:id` |
| `/workflows` | Workflows | `GET /api/workflows?status=active\|completed`, `GET /api/workflows/session/:id` + WebSocket auto-refresh (3s debounce) |
| `/cc-config` | *(redirect)* | Redirects to `/settings?tool=claude-code` — the config explorer moved under the Settings hub as one of its per-tool panels (see `/settings` below) |
| `/run` | Workspace | Merged workspace page combining lanes and runs. Attaches to a tmux-backed pseudoterminal tied to a lane: the UI selects a lane, calls `POST /api/run` with that lane's `id`, and receives a `runId` + tmux session name. The Workspace displays a horizontal lane strip at the top, the selected lane's pipeline map, and a real interactive terminal (xterm.js) fed by `/ws-pty/:runId` binary frames below. `TerminalView` takes the keyboard on mount (`term.focus()`), so typing in a lane reaches tmux without clicking the pane first, and it reports the server's `exit` frame to its owner through `onExit` — `LaneConsolePane` runs `newRun()` there, so a pane that ends (a double Ctrl+C out of `claude`, `exit`, a crash) swaps straight back to the run setup form instead of leaving a dead terminal behind a "New run" button. It re-attaches 1.5 s after any unexpected socket close (server restart included) and stops only on that `exit` frame — a dead socket used to leave the pane frozen on its last frame, looking live while swallowing every keystroke and mouse report. It also calls `preventDefault()` on Shift+Tab (keeping xterm's own handling): xterm emits `ESC[Z` for that combo but, unlike plain Tab, never marks the event cancelled, so the browser's default moved focus out of the terminal and the pane saw only the first press — `shift+tab to cycle` (claude's permission mode) looked dead in the browser while working in a real terminal. It also installs a custom wheel handler that returns `false`: without it, xterm falls back on an alt-screen buffer to translating each wheel notch into a cursor-key press (`ESC[A`/`ESC[B`), which a `claude` pane reads as arrow up/down and uses to walk the prompt history instead of scrolling. That handler suppresses only the emulation branch — real mouse reports are emitted by a separate listener xterm registers when the pane's program enables mouse tracking. Its xterm viewport scrollbar is hidden by design (`.xterm-viewport` rule in `client/src/index.css`): tmux repaints the whole pane, so xterm's scrollback is always empty and scrolling happens via mouse reports forwarded to the pane's program, not the DOM. Pre-flight: `GET /api/run/{tmux,binary,cwds,files}` for tmux availability + `claude` binary check + `@`-file autocomplete. Start/resume: `POST /api/run` (requires `laneId`; optionally accepts `prompt` to send immediately); `GET /api/run/:id` (returns handle); `DELETE /api/run/:id` (stops). History: `GET /api/run/history?laneId=<n>` lists only that lane's runs. PTY streaming: `/ws-pty/:runId` delivers raw PTY frames as binary WebSocket frames — no JSON envelope overhead, direct to xterm.js for live rendering; the same tmux session can have multiple simultaneous clients (browser Workspace, `agenthub lanes shell` CLI, other tools), all synced live. Lane self-heal: `GET /api/lanes/:id` auto-corrects `run_id`/`status` if the tmux session has been killed externally. Tier 1 TUI parity: tmux session is a real shell, not headless — supports editors, pagers, interactive subcommands. **The console never writes a lane's stage** — stage moves only through `agenthub stage` commands. Live / Offline indicator next to the title |
| `/run` | Workspace | Merged workspace page combining lanes and runs. Attaches to a tmux-backed pseudoterminal tied to a lane: the UI selects a lane, calls `POST /api/run` with that lane's `id`, and receives a `runId` + tmux session name. The Workspace displays a horizontal lane strip at the top, the selected lane's pipeline map (only while a pipeline template is installed — none ships), and a real interactive terminal (xterm.js) fed by `/ws-pty/:runId` binary frames below. `TerminalView` takes the keyboard on mount (`term.focus()`), so typing in a lane reaches tmux without clicking the pane first, and it reports the server's `exit` frame to its owner through `onExit` — `LaneConsolePane` runs `newRun()` there, so a pane that ends (a double Ctrl+C out of `claude`, `exit`, a crash) swaps straight back to the run setup form instead of leaving a dead terminal behind a "New run" button. It re-attaches 1.5 s after any unexpected socket close (server restart included) and stops only on that `exit` frame — a dead socket used to leave the pane frozen on its last frame, looking live while swallowing every keystroke and mouse report. It also calls `preventDefault()` on Shift+Tab (keeping xterm's own handling): xterm emits `ESC[Z` for that combo but, unlike plain Tab, never marks the event cancelled, so the browser's default moved focus out of the terminal and the pane saw only the first press — `shift+tab to cycle` (claude's permission mode) looked dead in the browser while working in a real terminal. It also installs a custom wheel handler that returns `false`: without it, xterm falls back on an alt-screen buffer to translating each wheel notch into a cursor-key press (`ESC[A`/`ESC[B`), which a `claude` pane reads as arrow up/down and uses to walk the prompt history instead of scrolling. That handler suppresses only the emulation branch — real mouse reports are emitted by a separate listener xterm registers when the pane's program enables mouse tracking. Its xterm viewport scrollbar is hidden by design (`.xterm-viewport` rule in `client/src/index.css`): tmux repaints the whole pane, so xterm's scrollback is always empty and scrolling happens via mouse reports forwarded to the pane's program, not the DOM. Pre-flight: `GET /api/run/{tmux,binary,cwds,files}` for tmux availability + `claude` binary check + `@`-file autocomplete. Start/resume: `POST /api/run` (requires `laneId`; optionally accepts `prompt` to send immediately); `GET /api/run/:id` (returns handle); `DELETE /api/run/:id` (stops). History: `GET /api/run/history?laneId=<n>` lists only that lane's runs. PTY streaming: `/ws-pty/:runId` delivers raw PTY frames as binary WebSocket frames — no JSON envelope overhead, direct to xterm.js for live rendering; the same tmux session can have multiple simultaneous clients (browser Workspace, `agenthub lanes shell` CLI, other tools), all synced live. Lane self-heal: `GET /api/lanes/:id` auto-corrects `run_id`/`status` if the tmux session has been killed externally. Tier 1 TUI parity: tmux session is a real shell, not headless — supports editors, pagers, interactive subcommands. **The console never writes a lane's stage** — stage moves only through `agenthub stage` commands. Live / Offline indicator next to the title |
| `/settings` | SettingsHub | Tabbed shell (`?tool=` query param picks the active tab, `PageTabs`) hosting the dashboard's own settings plus one configuration panel per AI tool. **dashboard** tab (default, no `?tool=`) → `Settings`: an **Appearance** section first (mode + named theme, `localStorage` only), `GET /api/settings/info`, `GET /api/pricing`, `GET /api/pricing/cost` + `localStorage` for notification prefs; hosts the **Remote Data Sources** panel (`components/RemoteSources.tsx`) — CRUD + test + sync over `/api/remote-sources`, live status from `remote_source.status` WS messages. **claude-code** tab (`?tool=claude-code`) → `CcConfig`: 12-tab Claude Code configuration explorer. Reads via `GET /api/cc-config/{overview,skills,agents,commands,output-styles,plugins,marketplaces,mcp,hooks,hook-scripts,keybindings,statusline,settings,memory}`. Mutations for skills/agents/commands/output-styles/memory — including the per-project file-based auto-memory store (`*.md` under `~/.claude/projects/<slug>/memory/`, grouped by project and searchable in the Memory tab, with clickable `MEMORY.md` index links that scroll to + highlight the matching fact file) — via `PUT /api/cc-config/file` + `DELETE /api/cc-config/file` (timestamped backups, atomic writes). The Keybindings tab additionally offers a structured inline editor that persists via `PUT /api/cc-config/keybindings` (same backup-first, atomic-write guarantees). `GET /api/cc-config/file?path=…` for single-file viewer. `GET /api/cc-config/backups` for the recovery modal. A **Switch profile** button left of Backups opens the auth-profile modal (`/api/cc-config/profiles*`): save the logged-in Anthropic account, rename it by clicking its name, then switch between accounts — only the login is swapped, so skills / subagents / memory / plugins / marketplaces / settings stay put. There is no name field (the server derives the identifier) and the save button shows only while the live account is unsaved, since one account is one profile. It cannot log in for you (`claude auth login` does that) and a switch applies to new sessions only. Subscribes to `cc_config_changed` WS messages for live refresh on both dashboard mutations and external file edits picked up by `cc-watcher`. The Settings tab (within CcConfig) leads with a client-side **Current configuration** summary that resolves the `/config` options (model, verbose, theme, output style, effort, auto-compact, notifications, …) across user / project / project-local scopes, showing defaults when unset. **codex** tab (`?tool=codex`) → `CodexConfig`: the Codex CLI counterpart — 8 tabs (overview, skills, agents, rules, memory, config, mcp, plugins; marketplaces are folded into the plugins tab rather than given their own, since the CLI treats them as one small add/remove surface). Codex's scope union is `"user"` \| `"project"` only — no `"project-local"`, no per-project file-based memory. Reads/mutates via `GET/PUT/DELETE /api/codex-config/*` (skills/agents/rules/memory/config are file-backed with the same backup-first write path as `cc-config`; mcp/plugins/marketplaces are CLI-owned add/remove only, no artifact editor). Subscribes to `codex_config_changed` WS messages. Both config panels share a tool-agnostic component set under `client/src/components/config/` (`EditorModal`, `ConfirmDeleteModal`, `FileViewer`, `ToastNotice`, `MdItemList`, `ScopeBadge`, `configPrimitives`) generic over an artifact-type parameter, so the two tools' editors stay visually and behaviorally consistent without duplicating the modal code. Every tab shows the Live / Offline indicator next to the page title |
| `/*` | NotFound | None (static 404 page) |
@@ -1107,14 +1107,6 @@ launcher, and the detached server spawn with `NODE_PATH` and
the plugin cache, which Claude Code garbage-collects and replaces on every
update.
Last in that worker — deliberately, because it clones from the network and
nothing above it may wait — it installs the plugins the pipeline templates drive
(`superpowers`) via `server/lib/skill-plugins.js`, the same module
`/agenthub-doctor`'s `Skill plugins` row reports from. The report is derived from
the templates; the install consults a fixed allowlist in that file instead,
because a template is user-writable. Full behavior:
[`docs/PLUGINS.md`](docs/PLUGINS.md).
---
## Import Pipeline
@@ -1512,56 +1504,39 @@ changes.
---
## Codex Lane Ingestion (no hooks)
## Codex Lane Status (no hooks)
A `codex` lane has no hook stream at all — Codex does not implement Claude
Code's hook protocol — so `touchLaneFromHook` (the only caller of
`stage-detect.detect()`) can never see one, and is deliberately pinned to
`"claude"` so a Claude hook cannot touch a codex lane sharing the same
directory.
directory. Codex lanes carry **no pipeline**: nothing detects, advances or
nudges their stage, and the Workspace hides the stage chip, time-on-stage,
pipeline/feature pickers and PipelineMap for them.
`server/lib/codex-ingest.js` is the codex-side source. Codex appends a rollout
journal per thread at
`server/lib/codex-ingest.js` only mirrors a codex lane's `status`. Codex appends
a rollout journal per thread at
`$CODEX_HOME/sessions/<YYYY>/<MM>/<DD>/rollout-<ts>-<threadId>.jsonl`
(`$CODEX_HOME` defaults to `~/.codex`); the first line is a `session_meta`
payload carrying the thread's `cwd`, and each tool call is a `custom_tool_call`
or `function_call` payload. One pass:
payload carrying the thread's `cwd`. One pass:
1. `rolloutFiles()` walks `sessions/` (depth ≤ 4), newest mtime first, capped at
40 files.
2. `rolloutCwd()` reads the thread's cwd from the file's first line (memoized —
it is written once, at thread creation) and matches it to a `codex` lane by
it is written once, at thread creation; the cache is pruned to the current
scan once it exceeds 4 × the 40-file cap) and matches it to a `codex` lane by
deepest path-boundary prefix.
3. Only bytes appended since the last pass are read. On the FIRST sight of a
file only its recent 64 KiB tail is read, and nothing at all when that file
is already idle — replaying a thread that finished days ago would paint
stages for work nobody is doing. `completeLines()` does the framing **on the
buffer, never on a decoded string** (a tail offset can land inside a
multi-byte UTF-8 sequence, where the decoder's U+FFFD would throw the byte
math off): a tail read's leading fragment is dropped, the stored offset
advances only past the last newline, and a trailing fragment is re-read whole
next pass. A read is capped at 4 MiB, and the two tracking maps are pruned to
the current scan once they exceed 4 × the 40-file cap.
4. `eventsFromPayload()` maps each payload onto the hook-shaped
`{tool_name, tool_input}` the matcher already understands: shell calls
(`exec`/`exec_command`/`shell`/`local_shell`) → `Bash`, an embedded
`apply_patch` heredoc → one `Write`/`Edit` per touched file, `update_plan` →
`TaskCreate`, `spawn_agent` → `Agent`. Everything else is ignored. Newlines
inside a patch heredoc arrive escaped (it rides inside a JS string literal),
so they are unescaped before the file list is scanned.
5. The last matching event of the batch goes through the same
`recordDetection()` as a hook — same forward-only, declared-wins,
amber-never-green rules — and the same pass mirrors the lane's `status`
between `idle` and `running` from the journal's mtime, under the identical
guard hook ingestion uses (no `run_id`, only from `idle`/`running`). Nothing
else is written: not `stage`, not `notes`, not `slot`/`ports`.
3. The lane is `running` while that journal's mtime is under two minutes old,
`idle` once older **or in the future** (a clock stepped back would otherwise
read as live), under the identical guard hook ingestion uses (no `run_id`,
only from `idle`/`running`). Nothing else is written: not `stage`, not
`notes`, not `slot`/`ports`.
`startCodexPoll(broadcastLane)` runs it on an unref'd 15 s interval from
`server/index.js`, tunable via `DASHBOARD_CODEX_POLL_MS` (`0` disables). Every
step is fail-safe: an absent `~/.codex`, a malformed journal, a lane deleted
mid-pass or a busy SQLite is swallowed locally, and a pass never throws into the
event loop. No schema change, no new route, no new WebSocket message type — the
existing `lane_update` broadcast carries it.
event loop. The existing `lane_update` broadcast carries the change.
Codex 0.149 also mirrors threads into version-suffixed SQLite files
(`state_5.sqlite`, `thread_history_1.sqlite`), but every thread row still points
@@ -1569,45 +1544,6 @@ at a live rollout file, so reading the JSONL avoids coupling to a schema the
next Codex release renames. `rolloutFiles()` is the single function to re-point
if that changes.
A written detection then **also advances the lane's declared `stage`** —
`setStage(lane.id, { stage: nodeId, keepDetection: true })`, the only place in
AgentHub where an inference moves the blue `current` ring. It is gated on
`recordDetection` having written, so it inherits forward-only/declared-wins/TTL
unchanged; it passes no `evidence`, so the node renders `passed-no-evidence`
(amber) and never `done`; and `keepDetection` is the sole exception to
`setStage`'s clearing of the detection columns, so the card still shows which
command moved it rather than looking like an agent's own claim. No template's
last node carries `detect` rules, so a lane can never be auto-declared `done`.
### Codex evidence reliability (`server/lib/codex-nudge.js`)
Auto-advance moves the ring but can never supply evidence; only the session's
own `agenthub stage --evidence` call can, so two mechanisms make that more likely
without weakening declared-wins/inferred-never-`done`. (Opening-prompt priming
used to be a third: `LaneConsolePane.tsx` pre-filled the prompt box from the
lane's pipeline — the driving slash command on a Claude lane, a plain-text
stage checklist on a codex one. It is gone: whatever sits in that box is sent
as a real prompt when the run starts, so the box now stays empty and the
prompt is the user's alone.)
- **`AGENTS.md` stage block** (`server/lib/lane-agents.js`): on a `codex` lane,
`agenthub lanes agents install` writes a marker-delimited
`<!-- agenthub:stage:start -->` section into `<lane cwd>/AGENTS.md` instead of
copying the two agent templates into `.claude/agents/`, which Codex never
reads. Appended to an existing file (user prose preserved), and a reinstall
replaces exactly that block.
- **Missing-evidence nudge** (`sweepCodexNudges`, an unref'd 60 s interval from
`server/index.js`, tunable via `DASHBOARD_CODEX_NUDGE_MS`, `0` disables):
when a codex lane's current stage has been held for at least two minutes with
`stages[stage].evidence` still null and hasn't already been nudged for that
exact stage, it types a one-line `[agenthub] ... run: agenthub stage ... --evidence
"..."` reminder into the lane's live tmux pane via `tmux.sendText` (skipped if
the pane isn't running an interactive program — `pty-run.js`'s
`SHELL_COMMANDS` — since Enter there would execute the reminder as a shell
command instead of submitting it as a chat turn). It never writes `stage`,
`stages` or `detected_stage` — any resulting evidence is still something the
codex session declared itself, through the real `agenthub stage` call.
---
## Agent Extension Layer
@@ -1643,12 +1579,9 @@ graph TD
- `.claude/rules/` adds path-scoped guidance by file area.
- `skills/` provides reusable workflows, shipped as the `agenthub` plugin's own skills (`/agenthub:<name>`, bare `/<name>` alias):
- onboarding
- feature shipping
- live issue debugging
- `agents/` provides specialized review workers (shipped as the `agenthub` plugin's agents):
- backend reviewer
- frontend reviewer
- qc-local, senior-gate-reviewer (the ship-feature-lane pipeline's QC and publish gate)
- project-doc updates
- file headers
- `plugins/` provides distributable plugin marketplace (see [Plugin Marketplace](#plugin-marketplace)):
- agenthub-analytics (session reports, cost analysis, usage trends, productivity scoring)
- agenthub-productivity (standups, weekly reports, sprint summaries, workflow optimization)
+8 -11
View File
File diff suppressed because one or more lines are too long
+22 -15
View File
@@ -31,11 +31,10 @@ dashboard, run it from source, or stay on Node 20.
| npm | 9+ | Comes with Node.js |
| Claude Code | 2.x+ | Required for hook integration |
| Git | Any | Cloning the repository, and every lane operation (worktrees, branch/status reads) |
| **tmux** | 3.x | **Required for the run console** — the browser terminal, `agenthub lanes shell`, typing `/reload-plugins` into a live pane, and the Codex nudge. See [Step 0](#step-0--system-packages) |
| **tmux** | 3.x | **Required for the run console** — the browser terminal, `agenthub lanes shell`, and typing `/reload-plugins` into a live pane. See [Step 0](#step-0--system-packages) |
| Codex CLI | Any | Optional — only for lanes whose tool is `codex` |
| GitHub CLI (`gh`) | Any | Optional — only for `agenthub lanes ci status` and the PR stages of `/agenthub:ship-full` |
| GitHub CLI (`gh`) | Any | Optional — only for `agenthub lanes ci status` |
| Python | 3.6+ | Optional — only for `scripts/expand-ts-module-docs.py` (doc generation) |
| `superpowers` plugin | Any | Optional — required only by `/agenthub:ship-feature` and `/agenthub:ship-feature-lane`, which drive its skills step by step (and which the built-in pipeline templates name as their per-node commands). Nothing else in AgentHub needs it; `/agenthub-doctor` reports it as `WARN` when absent. **Installed automatically** by the plugin's `SessionStart` bootstrap (opt out with `AGENTHUB_AUTO_INSTALL_PLUGINS=0`); by hand: `claude plugin install superpowers@claude-plugins-official` |
---
@@ -101,9 +100,14 @@ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # where the plugin put
`node:sqlite`); a checkout still runs on Node 20. The `agenthub` launcher
pins the node that installed it and falls back to `node` on `PATH` when a
`brew upgrade` or `nvm` switch deletes that binary.
- **No systemd, so no auto-start on boot.** The server is a detached process
that runs until logout or reboot. It comes back at the next Claude Code
session start (within about 10 s), or by hand with `agenthub start`. A
- **Starts at login by itself (LaunchAgent).** The plugin bootstrap installs
`~/Library/LaunchAgents/io.smartgift.agenthub.plist` (a checkout: `agenthub
service install`), so the dashboard comes back after every login with no
Claude Code session, and launchd restarts it if it dies. Lane panes survive
a restart of the server. Its output goes to `~/Library/Logs/agenthub.log`.
A LaunchAgent needs a login at the Mac itself; over SSH only, or when
`launchctl` fails, the server is a detached process started by the next
Claude Code session (within about 10 s) or by `agenthub start`, as before. A
discovery entry left over from before the reboot is ignored, so a recycled
pid can never pass for a live dashboard.
- **Started from a Claude Code session.** The server drops the variables that
@@ -124,15 +128,17 @@ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # where the plugin put
**Mac checklist** — please run it and report the result on issue #22:
1. Fresh plugin install from a Terminal `claude` session: `/agenthub-doctor` is all OK (the systemd row says not available) and the dashboard answers on `http://localhost:4820`.
1. Fresh plugin install from a Terminal `claude` session: the dashboard answers on `http://localhost:4820`, `~/Library/LaunchAgents/io.smartgift.agenthub.plist` exists, and `/agenthub-doctor`'s launchd row says the LaunchAgent is current and running.
2. `tmux show-environment -g | grep -i claude` prints nothing.
3. Add a Repo lane by typing its path in a different case: sessions bind to it, and `agenthub stage plan` inside it moves the map.
4. **Start Run** in the browser: the terminal attaches, typing works, an image paste into `claude` works, and `exit` returns to the run form.
5. Changes panel: diff, stage and commit on a lane.
6. Switch profile and check `claude /status` shows the new account. Repeat with a non-default `CLAUDE_HOME`, which also checks the Keychain service name.
7. `brew upgrade node && brew cleanup`, then `agenthub status` still works.
8. Reboot, open `claude`, and the dashboard comes back within about 10 s.
9. `/agenthub-update` completes and the server restarts on the new version.
8. Reboot and log in WITHOUT opening `claude`: the dashboard answers within about 10 s (`agenthub service status` shows `state = running`).
9. `kill <server pid>` (from `agenthub status`): it is back within a few seconds.
10. With a lane run open, `/agenthub-update` completes, the server restarts on the new version, the plist names the new cache directory, and the run's terminal is still alive.
11. `agenthub service uninstall`: the plist is gone and nothing restarts the server after a `kill`.
---
@@ -287,13 +293,15 @@ npm start # Start Express serving client/dist on port 4820
Open **http://localhost:4820** in your browser.
`npm start` (and `agenthub start`, its backgrounded form) only run while that
process is alive — a reboot loses it. On Linux, run the server as a systemd
`--user` service instead so it comes back on its own after every reboot, with
no manual step and no Claude Code (or any other tool) needed to trigger it:
process is alive — a reboot loses it. Run the server as a systemd `--user`
service (Linux) or a LaunchAgent (macOS) instead so it comes back on its own
after every reboot, with no manual step and no Claude Code (or any other tool)
needed to trigger it:
```bash
agenthub service install # writes + enables ~/.config/systemd/user/agenthub.service
agenthub service status # systemctl --user status agenthub
agenthub service install # Linux: ~/.config/systemd/user/agenthub.service
# macOS: ~/Library/LaunchAgents/io.smartgift.agenthub.plist
agenthub service status # systemctl --user status / launchctl print
agenthub service uninstall # disable and remove it
```
@@ -310,7 +318,6 @@ This repository includes extension packs for both Claude Code and Codex.
- `CLAUDE.md`
- `.claude/rules/`
- `skills/` (shipped as the `agenthub` plugin's skills)
- `agents/` (shipped as the `agenthub` plugin's agents)
- Codex project packs live under `.codex/`:
- `AGENTS.md`
- `.codex/rules/`
+27 -58
View File
@@ -3,7 +3,7 @@
Internal SmartGift build. Local-first **control surface** for Claude Code agents —
monitoring is one part of it, not the whole. Hooks POST every tool call to an
Express + SQLite server and a React UI updates over WebSocket; **lanes** track
parallel agent work through a pipeline; and the `agenthub` CLI drives real terminal
parallel agent work, one working directory each; and the `agenthub` CLI drives real terminal
sessions, lane runtimes, and Claude Code's own configuration.
AgentHub records and shows — it does not orchestrate. The session in control makes
@@ -31,11 +31,13 @@ Internal build — all rights reserved.
**Drive**
- **Lanes.** One lane per working directory, surviving session restarts. A lane
moves through pipeline stages and the dashboard shows where it is.
- **Stage detection.** The stage is inferred from the tool stream, so a session
that never calls `agenthub stage` still shows progress — rendered dashed amber and
never as done, because an inference is not evidence.
- **Lanes.** One lane per working directory, surviving session restarts. Once you
install a pipeline template (none ships), a lane moves through its stages and
the dashboard shows where it is.
- **Stage detection.** With a template installed, the stage is inferred from the
tool stream, so a session that never calls `agenthub stage` still shows
progress — rendered dashed amber and never as done, because an inference is
not evidence.
- **Run Claude Code or Codex from the browser.** A real terminal (tmux + a real
PTY, rendered with xterm.js) attached to a lane's directory — the exact TUI
you'd see locally, fully interactive, resumable, and attachable from a real
@@ -51,8 +53,6 @@ Internal build — all rights reserved.
merge/rebase/reset button by design: recovery from those needs a terminal.
- **Per-lane app stacks.** A repo that declares `.agenthub/profile/` gets its own
slot, ports and services per lane (`agenthub lanes up|down|logs`).
- **Ship pipelines.** `/agenthub:ship-full` and `/agenthub:ship-quick` drive a
feature from intake to PR, declaring every stage to the dashboard as it goes.
**Configure**
@@ -78,10 +78,10 @@ Internal build — all rights reserved.
| **Node.js** | >= 20 (>= 22.5 for a plugin install) | Everything. Both suites are verified green on **24** and **26** |
| **npm** | 9+ | Ships with Node |
| **git** | any | Cloning, and every lane operation (worktrees, branch/status reads) |
| **tmux** | 3.x | The browser run console, `agenthub lanes shell`, typing `/reload-plugins` into a live pane, the Codex nudge |
| **tmux** | 3.x | The browser run console, `agenthub lanes shell`, typing `/reload-plugins` into a live pane |
| **Claude Code** | 2.x | Hook ingestion — the whole monitoring side |
| **Codex CLI** | any | Optional — only for `codex` lanes |
| **GitHub CLI (`gh`)** | any | Optional — only for `agenthub lanes ci status` and the PR stages of the ship pipelines |
| **GitHub CLI (`gh`)** | any | Optional — only for `agenthub lanes ci status` |
| **systemd (user)** | — | Optional — only for `agenthub service install` (Linux auto-start on boot) |
Node **25** is the one version to avoid: it breaks 6 server tests through a
@@ -122,34 +122,6 @@ terminal and a local `tmux attach -t agenthub-lane-<id>` (or `agenthub lanes
shell`) are two clients on the same pane — they stay in sync, and killing the
dashboard never kills the run.
### The superpowers plugin
The **`superpowers` plugin is required by the ship-feature pipelines only**, not
by the dashboard. `/agenthub:ship-feature` and `/agenthub:ship-feature-lane` drive
`superpowers:brainstorming`, `writing-plans`, `test-driven-development`,
`requesting-code-review` and `verification-before-completion` phase by phase,
and both built-in pipeline templates name those same slash commands as their
per-node drivers. Without it the dashboard, hooks and CLI all work
normally — the two pipeline skills are what stop partway. `/agenthub-doctor` reports
it as a `WARN` row.
**You do not normally have to install it.** The plugin's `SessionStart`
bootstrap installs it for you, once, in its detached worker — so a session never
waits on the clone, and the current session needs `/reload-plugins` before the
skills resolve (any later session picks them up on its own). The outcome is
logged to `~/.claude/agenthub/runtime/bootstrap.log`, and `/agenthub-update`
retries a failed one. To install it by hand instead, or after opting out:
```bash
claude plugin install superpowers@claude-plugins-official
```
Set `AGENTHUB_AUTO_INSTALL_PLUGINS=0` to opt out of the automatic install. Only the
plugins on a fixed allowlist in `server/lib/skill-plugins.js` are ever installed
this way — `superpowers` today. A custom pipeline template naming some other
plugin's command is *reported* by `/agenthub-doctor` and never installed, because a
template is a file anyone can drop into `DASHBOARD_PIPELINES_DIR`.
## Install as a Claude Code plugin
Two commands on a machine that has nothing but Claude Code, no clone and no
@@ -193,19 +165,20 @@ every event is counted twice.
### Run as a service (auto-start on boot)
`npm start` only runs while that terminal (or `agenthub start`'s background
process) is alive — a reboot loses it. On Linux, `agenthub service install` sets
up a systemd `--user` service instead, so `:4820` is up again on its own after
process) is alive — a reboot loses it. `agenthub service install` sets up a
systemd `--user` service (Linux) or a LaunchAgent (macOS) instead, so `:4820` is up again on its own after
every reboot, with no manual step and no Claude Code (or any AI tool) needed
to trigger it:
```bash
npm run build # the service serves the built client, same as npm start
agenthub service install # writes + enables ~/.config/systemd/user/agenthub.service
agenthub service status # systemctl --user status agenthub
agenthub service install # Linux: ~/.config/systemd/user/agenthub.service
# macOS: ~/Library/LaunchAgents/io.smartgift.agenthub.plist
agenthub service status # systemctl --user status / launchctl print
agenthub service uninstall # disable and remove it
```
`agenthub service install` also tries `loginctl enable-linger` so the service
On Linux, `agenthub service install` also tries `loginctl enable-linger` so the service
starts on a cold boot, before anyone logs in; if that needs elevated rights on
your machine it prints the `sudo loginctl enable-linger <user>` command to run
once yourself. Plugin installs get the same persistence automatically — see
@@ -223,7 +196,6 @@ agenthub sessions # recent sessions
agenthub lanes # lanes with stage and progress
agenthub lanes pipeline # this lane's pipeline template, or switch it
agenthub lanes node <id> # run ONE pipeline node's own command (no id: list them)
# (in a session: /intake, /qc, /ship-full, /ship-quick …)
agenthub stage <name> # declare the current lane's stage
agenthub tail # live event feed
```
@@ -252,20 +224,17 @@ Every lane also carries the CLI that drives it — `claude` (the default) or
Codex lane's run panel offers Codex's own sandbox, approval and reasoning-effort
choices, and resumes with `codex resume --last`. Codex emits none of this
dashboard's hooks, so a Codex lane records its runs but stays absent from
Sessions and Analytics. Its **stage detection** works anyway, from Codex's own
rollout journals on disk (`$CODEX_HOME/sessions/**/rollout-*.jsonl`, polled every
`DASHBOARD_CODEX_POLL_MS` ms, default 15000), and on a Codex lane a detection
also **advances the declared stage** — the one place an inference moves the blue
`current` ring, because a Codex session has no hook and nothing else would ever
move it. What a Codex lane cannot get for free is *evidence*: an auto-advanced
node stays amber (`passed-no-evidence`), never green, since only the session
itself can say what it finished. Two things help it get there (the run console
no longer pre-fills anything into the prompt box — that box is the user's to
type): `agenthub lanes agents install` writes the stage-declaration
instructions as a marker-delimited block in the lane's `AGENTS.md`, and a 60s
sweep (`DASHBOARD_CODEX_NUDGE_MS`, `0` disables) types a one-line reminder into
a lane's pane if its current stage sits without evidence for more than two
minutes.
Sessions and Analytics. A Codex lane also carries **no pipeline** — no stage,
no pipeline map, nothing inferred or advanced; the dashboard only mirrors its
running/idle status from Codex's own rollout journals on disk
(`$CODEX_HOME/sessions/**/rollout-*.jsonl`, polled every
`DASHBOARD_CODEX_POLL_MS` ms, default 15000).
**Pipelines are dormant.** AgentHub ships no pipeline template, so a lane has no
stages until you drop a template JSON into `DASHBOARD_PIPELINES_DIR` (see
[`docs/LANES.md`](docs/LANES.md#custom-pipeline-templates)); until then
`agenthub stage` answers `ENOPIPELINE` and the Workspace hides the pipeline map.
Further development is planned.
The declared stage comes from `agenthub stage`. The inferred stage comes from tool
events and expires after `DETECTION_TTL_MS` (default 5 minutes), so a lane can
+20 -31
View File
@@ -3,7 +3,7 @@
Bản build nội bộ SmartGift. **Bàn điều khiển** local-first cho agent Claude Code —
monitoring chỉ là một phần, không phải tất cả. Hooks POST mỗi tool call lên server
Express + SQLite và React UI cập nhật qua WebSocket; **lane** (làn đường) theo dõi
công việc song song của agent qua một pipeline; còn CLI `agenthub` điều khiển phiên
công việc song song của agent, mỗi working directory một lane; còn CLI `agenthub` điều khiển phiên
terminal thật, runtime của lane, và cả cấu hình của chính Claude Code.
AgentHub ghi nhận và trình bày — nó không điều phối. Phiên đang chạy mới là nơi ra
@@ -31,10 +31,12 @@ Internal build — all rights reserved.
**Điều khiển**
- **Lane.** Mỗi working directory một lane, sống sót qua session restart. Lane
đi qua các pipeline stage và dashboard hiển thị nó đang ở đâu.
- **Stage detection.** Stage được suy luận (infer) từ tool stream, nên một
session không bao giờ gọi `agenthub stage` vẫn hiển thị progress — render dạng
- **Lane.** Mỗi working directory một lane, sống sót qua session restart. Khi bạn
cài một pipeline template (không có template nào đi kèm), lane đi qua các
stage của nó và dashboard hiển thị nó đang ở đâu.
- **Stage detection.** Khi đã cài template, stage được suy luận (infer) từ tool
stream, nên một session không bao giờ gọi `agenthub stage` vẫn hiển thị
progress — render dạng
viền chấm màu hổ phách (amber) và không bao giờ hiện `done`, vì suy luận
không phải bằng chứng.
- **Chạy Claude Code hoặc Codex từ trình duyệt.** Một terminal thật (tmux + PTY
@@ -44,8 +46,6 @@ Internal build — all rights reserved.
chính là phần cần cài `tmux`** — xem [Yêu cầu hệ thống](#yêu-cầu-hệ-thống).
- **App stack riêng cho từng lane.** Repo khai báo `.agenthub/profile/` thì mỗi
lane được cấp slot, port và service riêng (`agenthub lanes up|down|logs`).
- **Ship pipeline.** `/agenthub:ship-full` và `/agenthub:ship-quick` đưa một
feature từ intake tới PR, khai báo từng stage về dashboard trên đường đi.
**Cấu hình**
@@ -67,10 +67,10 @@ Internal build — all rights reserved.
| **Node.js** | >= 20 (>= 22.5 nếu cài qua plugin) | Tất cả. Cả hai test suite verify xanh trên Node **24** và **26** |
| **npm** | 9+ | Đi kèm Node |
| **git** | bất kỳ | Clone repo, và mọi thao tác lane (worktree, đọc branch/status) |
| **tmux** | 3.x | Run console trên trình duyệt, `agenthub lanes shell`, gõ `/reload-plugins` vào pane đang sống, nhắc nhở Codex |
| **tmux** | 3.x | Run console trên trình duyệt, `agenthub lanes shell`, gõ `/reload-plugins` vào pane đang sống |
| **Claude Code** | 2.x | Hook ingestion — toàn bộ phần monitoring |
| **Codex CLI** | bất kỳ | Tùy chọn — chỉ cho lane dùng `codex` |
| **GitHub CLI (`gh`)** | bất kỳ | Tùy chọn — chỉ cho `agenthub lanes ci status` và các stage PR của ship pipeline |
| **GitHub CLI (`gh`)** | bất kỳ | Tùy chọn — chỉ cho `agenthub lanes ci status` |
| **systemd (user)** | — | Tùy chọn — chỉ cho `agenthub service install` (tự khởi động khi boot, Linux) |
Node **25** là bản duy nhất nên tránh: nó làm gãy 6 test server do lệch ABI
@@ -110,23 +110,6 @@ trên trình duyệt và `tmux attach -t agenthub-lane-<id>` (hoặc `agenthub l
shell`) ở máy là hai client trên cùng một pane — chúng đồng bộ với nhau, và tắt
dashboard không bao giờ giết run đang chạy. Detach bằng `Ctrl-b d`.
### Plugin superpowers
Plugin **`superpowers` chỉ cần cho ship-feature pipeline**, không cần cho
dashboard. `/agenthub:ship-feature` và `/agenthub:ship-feature-lane` lái các skill
của nó theo từng phase. Thiếu nó thì dashboard, hook và CLI vẫn chạy bình thường
— chỉ hai skill pipeline là dừng giữa chừng; `/agenthub-doctor` báo dòng `WARN`.
**Bình thường bạn không phải tự cài.** Bootstrap `SessionStart` của plugin cài
giúp một lần trong worker chạy nền, và session hiện tại cần `/reload-plugins`
thì skill mới resolve được (session sau tự nhận). Cài tay:
```bash
claude plugin install superpowers@claude-plugins-official
```
Đặt `AGENTHUB_AUTO_INSTALL_PLUGINS=0` để tắt cài tự động.
## Cài như Claude Code plugin
Hai lệnh, trên máy chỉ có Claude Code, không cần clone repo, không cần
@@ -200,7 +183,6 @@ agenthub sessions # session gần đây
agenthub lanes # danh sách lane kèm stage và progress
agenthub lanes pipeline # pipeline template của lane này, hoặc đổi nó
agenthub lanes node <id> # chạy riêng command của MỘT node (không có id: liệt kê)
# (trong session: /intake, /qc, /ship-full, /ship-quick …)
agenthub stage <name> # khai báo stage hiện tại của lane
agenthub tail # xem live event feed
```
@@ -228,10 +210,17 @@ chọn trong modal Add lane và cố định suốt vòng đời của lane. Lan
chạy với các lựa chọn riêng của Codex (sandbox, approval, reasoning effort) và
resume bằng `codex resume --last`. Codex không bắn hook của dashboard này, nên
lane Codex vẫn ghi lịch sử chạy nhưng không xuất hiện ở Sessions và Analytics.
**Stage detection thì vẫn chạy**, đọc từ rollout journal của chính Codex trên đĩa
(`$CODEX_HOME/sessions/**/rollout-*.jsonl`, poll mỗi `DASHBOARD_CODEX_POLL_MS` ms,
mặc định 15000) — thứ lane Codex không tự có là stage **khai báo**, vì chỉ chính
session đó mới gọi được `agenthub stage`.
Lane Codex cũng **không có pipeline** — không stage, không pipeline map, không
suy luận hay tự nhảy stage; dashboard chỉ phản ánh trạng thái running/idle từ
rollout journal của chính Codex trên đĩa (`$CODEX_HOME/sessions/**/rollout-*.jsonl`,
poll mỗi `DASHBOARD_CODEX_POLL_MS` ms, mặc định 15000).
**Pipeline đang tạm ngưng (dormant).** AgentHub không đi kèm pipeline template
nào, nên lane không có stage cho tới khi bạn thả một file template JSON vào
`DASHBOARD_PIPELINES_DIR` (xem
[`docs/LANES.md`](docs/LANES.md#custom-pipeline-templates)); trước đó
`agenthub stage` trả về `ENOPIPELINE` và trang Workspace ẩn pipeline map. Phần
này sẽ được phát triển tiếp.
Stage khai báo (declared) đến từ `agenthub stage`. Stage suy luận (inferred) đến
từ tool event và hết hạn sau `DETECTION_TTL_MS` (mặc định 5 phút), nên lane có
File diff suppressed because one or more lines are too long
-27
View File
@@ -1,27 +0,0 @@
---
name: backend-reviewer
description: Review backend route and hook logic for regressions, data integrity risks, and missing tests.
tools: Read, Grep, Glob, Bash
model: sonnet
memory: project
---
You are a backend reviewer for this repository. Review ONLY files under `server/` in the diff you are given — ignore `client/`, `mcp/`, or any other path even if it appears in the same diff range; another reviewer covers those.
Focus on:
- Hook event lifecycle correctness.
- Session/agent state-machine regressions.
- API contract compatibility.
- Transaction and persistence correctness.
- Missing or weak verification coverage.
## Output (MANDATORY — the caller parses your last line)
- Findings as `path:line — severity — problem — suggested fix`, most severe first.
- End with exactly one of:
- `BACKEND-REVIEW: CLEAN`
- `BACKEND-REVIEW: FINDINGS — <n>`
## Agent memory
Record recurring backend defect patterns and false-positive traps you find here (e.g. hook shapes that look wrong but aren't, common state-machine edge cases). Future backend-reviewer runs read this.
-27
View File
@@ -1,27 +0,0 @@
---
name: frontend-reviewer
description: Review React UI changes for behavior regressions, state consistency, and UX breakage.
tools: Read, Grep, Glob, Bash
model: sonnet
memory: project
---
You are a frontend reviewer for this repository. Review ONLY files under `client/` in the diff you are given — ignore `server/`, `mcp/`, or any other path even if it appears in the same diff range; another reviewer covers those.
Focus on:
- Routing and navigation consistency.
- State updates from websocket and API responses.
- Loading/empty/error state correctness.
- Breaking visual or interaction regressions.
- Missing tests for changed UI behavior.
## Output (MANDATORY — the caller parses your last line)
- Findings as `path:line — severity — problem — suggested fix`, most severe first.
- End with exactly one of:
- `FRONTEND-REVIEW: CLEAN`
- `FRONTEND-REVIEW: FINDINGS — <n>`
## Agent memory
Record recurring frontend defect patterns and false-positive traps you find here (e.g. websocket race conditions that look wrong but aren't, sibling components that should stay in sync). Future frontend-reviewer runs read this.
-74
View File
@@ -1,74 +0,0 @@
---
name: "qc-local"
description: "Local browser-QC agent for the ship-feature-lane pipeline in AgentHub. Launched by the ship-feature-lane skill at Stage 6 (foreground — it gates the pipeline) after e2e, against the lane's OWN feature-branch stack (booted via `agenthub lanes up --qc`; the branch is cut from origin/development, so the stack is development + this feature). Exercises the feature + smoke + reload/re-login coverage via the lane's local-QC Playwright MCP, saves every screenshot to `proof/<feature-slug>/qc-local/` (the AgentHub proof gallery's canonical path), and returns a parseable LOCAL-QC: PASS/FAIL verdict that doubles as the feature user-flow review for the senior gate. <example>Context: ship-feature-lane in a lane finished Stage 3's e2e green. assistant: 'e2e is green — launching the qc-local agent to browser-QC the feature-branch stack and capture the proof gallery.' <commentary>Stage-6 browser QC is the qc-local agent's job; the main session stays off the browser.</commentary></example>"
model: opus
color: green
memory: project
---
You are an elite QA automation engineer validating ONE lane's feature on that lane's OWN local stack (isolated FE/API/DB, nothing shared with other lanes), right after the feature branch's e2e passed (the branch is cut from `origin/development`, so this stack IS development + the feature as of the branch point). You are rigorous, evidence-driven, and autonomous: every claim in your report is backed by a screenshot. You never commit, push, or fix code — you verify, capture proof, and report. Your report IS the feature user-flow review the senior gate reads.
## Context you will be given (by the ship-feature-lane skill)
- **The lane's working directory** (your cwd — AgentHub resolves the lane from it automatically; there is no marker file to check).
- **Feature slug** (the `<slug>` of `feat/<slug>`), feature title, and the acceptance points to verify (from the lane spec at `docs/superpowers/specs/lane-<slug>.md` — read it yourself if the summary is thin; `git diff origin/development...HEAD` shows the change surface).
Setup: your cwd is the lane clone. You do NOT write `stage`/`status`/`notes` — the main session owns all state; you have no heartbeat call to make (you run as a synchronous subagent inside the driving session's own turn, so the lane is never seen as stalled while you work).
## Target environment
- **App**: the lane's own booted frontend — check `agenthub lanes runtime` (or the `FE_PORT`/equivalent env the skill already resolved) for the actual port; it is isolated per lane. If it's down, don't boot it yourself blindly — return `LOCAL-QC: FAIL — lane stack down (re-run: agenthub lanes up --no-build)`.
- **QC boot env**: the QC stack boots via `agenthub lanes up --qc`, which applies the profile's `QC_BOOT_ENV` (typically mock/stub flags) — LLM/paid-backend features then return CANNED responses. Canned/stub content is EXPECTED there, not a bug; judge the surrounding UX (loading states, rendering, persistence), not the stub text itself.
- **Account / login.** Two paths:
- **If a credentials block is embedded at the TOP of this agent** ("⚙ This lane's local-QC credentials"): those ARE your login — type them into the form yourself (`browser_type`, submit) when you hit a login page. You already have them; never read a file/script to fetch them.
- **If there is NO embedded block:** the app should already be in a usable/logged-in state (or requires no login for the flows you're testing). If you hit a login page you cannot get past, this profile has no seeded QC account configured yet — return `LOCAL-QC: FAIL — login required, no seed-account mechanism configured for this profile`. Do not guess at credentials or invent a login flow.
- **Tooling**: the **dedicated local-QC Playwright MCP server** (isolated Chromium profile — e.g. `playwright-qa-local` if the profile names it that). You MUST use that server's `mcp__<name>__browser_*` tool family for ALL browser interaction — never the unscoped `mcp__playwright__browser_*` or any other Playwright server (other agents/sessions own those browsers concurrently). If the tools aren't available, return `LOCAL-QC: FAIL — local-QC Playwright MCP not loaded (configure it in .mcp.json and restart the lane session — see the ship-feature-lane skill's Setup section)`.
- **Upload fixtures**: if an **"Upload fixtures dir"** line is injected at the TOP of this agent, use the files in that dir for any data-upload scenario (quote the path; it may contain spaces). If no such line is present, no fixture dataset is configured for this stack — skip data-upload-only scenarios and note that in the report. Put ad-hoc non-fixture files in the lane's `.playwright-mcp/` dir; never source uploads from `/tmp/`.
## Procedure
1. **Load the QC Plan, then execute against it.** The ship-feature-lane skill wrote a `## QC Plan` section into the lane spec (`docs/superpowers/specs/lane-<slug>.md`) at Stage 5 — it is the authoritative scope. Read it first.
- **Cover every in-scope scenario** in the plan — skip none.
- **Stay in scope** — don't wander into the plan's out-of-scope areas (that over-testing is exactly what the plan exists to prevent); the only unaffected areas you touch are the plan's smoke set.
- **If the plan is missing or thin**, derive scenarios yourself from the acceptance points + `git diff origin/development...HEAD` and proceed, covering the same shape: **primary** (each acceptance point, positive AND negative — invalid input, empty state, permission edges), **adjacent** flows sharing routes/components/data, **smoke** (login + main nav + ≥3 unaffected major areas), and **state coverage** (a reload (Cmd+R) on every stateful screen touched, one logout → re-login cycle, back-and-forth navigation between key pages).
- **When you discover a real scenario the plan missed** (a genuine risk it didn't anticipate), TEST it AND list it in your report under **"Scenarios discovered during QC"** so the skill folds it into the plan. Do NOT edit the plan file yourself — the skill is its single writer.
- **UI/UX & layout rigor — apply to EVERY form/screen the feature touches** (never just a representative one; sibling forms drift):
- **Overflow in BOTH axes.** Resize the window NARROWER (width) AND SHORTER (height — e.g. ~560px then ~350px tall), and ALSO grow the content by opening every expandable thing (dropdowns, collapsible sections, "add row" repeaters, multi-select pickers) so a step becomes taller than the viewport. Then confirm: nothing is cut off at the **top** or bottom; any fixed/sticky chrome (page header, wizard **stepper/tabs**, toolbars) stays visible and is NOT clipped; the scroll container actually scrolls; and the primary actions (Save/Next/Submit/Cancel) stay reachable and clickable. A form taller than the page must never hide its header, its step nav, or its buttons.
- **Every control has a visible label.** Each input/toggle/select/picker shows a field label. Compare sibling forms — if one labels a control and the other doesn't, that's a defect.
- **Visual hierarchy is correct.** Section/group headers are MORE prominent than the field labels inside them (size/weight/color); field labels are consistent across steps and across sibling forms; helper text is least prominent. Flag any inverted or inconsistent hierarchy.
- No text truncation/overlap; spacing, alignment, and contrast are reasonable; the form reads as natural, polished UI.
2. **Execute with the local-QC MCP's tools**:
- Use `browser_type` for React controlled inputs — never direct DOM value assignment (it doesn't fire onChange).
- After each meaningful action: `browser_snapshot` to verify state, then screenshot (see proof convention).
- Don't trust `browser_network_requests` alone for HTTP verification (it double-lists requests); prefer the lane's own backend/service logs if the profile exposes them (`agenthub lanes logs <svc>`).
- **Failure triage**: capture a failure screenshot + `browser_snapshot` + `browser_console_messages`, note repro steps, expected vs actual, severity (blocker/major/minor/cosmetic) — then CONTINUE with remaining scenarios unless the app is unusable.
3. **Proof convention (mandatory — the path is fixed infrastructure, NOT your choice):** EVERY screenshot via `browser_take_screenshot` with `filename: "proof/<feature-slug>/qc-local/<NN>-<what>.png"`, numbered in flow order (e.g. `proof/edit-report/qc-local/03-dialog-open.png`). The MCP server's pinned `--output-dir` lands these in `<lane clone>/.playwright-mcp/proof/...` — the ONLY place the dashboard's gallery reads (`agenthub lanes proof-link` converges a stray `proof/` symlink if needed). Absolute paths, other folders, or invented layouts = the proof is lost.
## Checkpoint & resume *(rate-limits and crashes must not zero your work)*
- **Checkpoint as you go:** after EACH scenario, append one line to `proof/<feature-slug>/qc-local/RESULTS.partial.md` (via the Write/Edit tools on `<lane clone>/.playwright-mcp/proof/...`): `<NN> <scenario> — ✅|❌ — <proof file> — <HEAD sha>`. A mid-run tool error or rate-limit then leaves a resumable trail instead of zeroing the run.
- **Resume on start:** if `RESULTS.partial.md` already exists for this feature AND its HEAD sha matches the tree you're QCing, treat its ✅ scenarios as done (spot-check one) and continue from the first unfinished one. Sha differs → start fresh (delete the stale partial).
- **Bounded stalls:** a single browser step hanging >2 min → close the browser, reload, retry that step ONCE; still stuck → record ❌ with proof and move on. If the run approaches ~45 min, finish the current scenario, mark the rest ⚠️ not-run, and return honestly rather than stalling silently.
## Quality bar (verify before returning)
- [ ] Every in-scope QC-Plan item was executed (or marked N/A with a reason); any discovered scenarios are listed for fold-back.
- [ ] Every primary scenario has a screenshot of its end state (pass or fail).
- [ ] Reload tested on every stateful screen touched; one full logout → re-login cycle done.
- [ ] Smoke covered login, navigation, and ≥3 unaffected areas.
- [ ] UI/UX pass done on EACH touched form: tested at narrow AND short viewports AND with dropdowns/expandables open (content taller than the page) — fixed header/stepper/buttons never cut off, scroll works, actions reachable; every control labeled; section headers more prominent than field labels; consistent label styling; no overlap/truncation; natural polished layout.
- [ ] All screenshots under `proof/<feature-slug>/qc-local/` (check with `ls .playwright-mcp/proof/<feature-slug>/qc-local/`).
- [ ] No commits made; password never echoed anywhere.
## Output format (MANDATORY — the skill parses your last line)
A scannable report (this doubles as the user-flow review for the senior gate): a **QC-Plan coverage** view (each in-scope plan item → ✅/❌/⚠️), a **Scenarios discovered during QC** list (anything you tested that wasn't in the plan, for the skill to fold back), issues with severity + repro + which proof file shows each, proof filename list, reload/re-login coverage note, UX observations worth fixing. Then end with exactly one of:
- `LOCAL-QC: PASS`
- `LOCAL-QC: FAIL — <comma-separated reasons>`
A FAIL must be specific enough for the lane's fix-loop to act on (page/flow + what broke + proof file).
## Agent memory
Record local-stack QA knowledge as you find it: flaky selectors/flows, features that break after reload or re-login, stub-mode quirks (what canned responses look like per feature), data-setup prerequisites, upload-fixture behaviors, noise-vs-real console errors. Future qc-local runs (any lane) read this.
-52
View File
@@ -1,52 +0,0 @@
---
name: "senior-gate-reviewer"
description: "Final GO/NO-GO publish-readiness gate for the ship-feature-lane pipeline in AgentHub. Invoke AFTER the code-review and feature-user-flow-review (qc-local) and AFTER local CI gates + e2e + QC have passed, immediately BEFORE the feature branch is pushed and its PR is opened (base `development`). Returns a single GO or NO-GO verdict with a required-fix list. A GO is the sole authorization to publish the PR. <example>Context: ship-feature-lane in a lane has finished implementation, gates, and reviews and is about to publish the PR. assistant: 'I'll launch the senior-gate-reviewer agent to make the final go/no-go decision before pushing the branch and opening the PR.' <commentary>This is the publish gate — it decides whether the feature is allowed in front of reviewers.</commentary></example>"
model: opus
color: red
memory: project
---
You are the **Senior Gate Reviewer** — the final, independent publish-readiness authority for the ship-feature-lane pipeline. Nothing is pushed or PR'd without your **GO**; the PR a human later merges into `development` is exactly what you approved. You are deliberately skeptical: when in doubt, you return **NO-GO** with a precise, actionable fix list. You do NOT make fixes yourself — you judge, decide, and report.
## Context you will be given (by the ship-feature-lane skill)
- **The lane's working directory** (your cwd — AgentHub resolves the lane from it automatically).
- **The original requirement** and the **upfront Q&A answers** (acceptance criteria).
- The **feature branch name** (cut from `origin/development` — the PR base it will target).
- A summary of the **two prior reviews** (code-review + the qc-local user-flow review) and which findings were resolved.
- The **`agenthub lanes sync-base --check` preflight output** (migration-collision check + how far `origin/development` moved since the branch's merge-base).
- Confirmation that **local CI gates** (the profile's lint / test / contract checks), **e2e**, and **browser QC** already passed.
If any of this context is missing, gather it yourself (read the lane spec file the skill wrote, run `git -C <lane> log/diff`).
## Your checks
**Review the PR the reviewers will see.** The PR is `<feature-branch>` based on `origin/development` — judge the change against **the PR diff**: `git -C <lane> diff origin/development...<feature-branch>` (`<feature-branch>` is in your context). There is NO local integration tree in this flow — the branch itself is what ships, and the first combined validation after a human merges it is dev CI + dev-QC; your merge-safety check (#3) is what stands between this branch and that merge. Run checks with `git -C <lane> ...`, `Read`, `Grep`, `make` as needed.
1. **Acceptance** — Does the implementation actually satisfy the original requirement + every upfront Q&A answer? Inspect **the PR diff** (defined above) and, where feasible, confirm the acceptance criteria are met in code. Missing/partial requirement coverage ⇒ NO-GO.
2. **Findings resolved** — Were the PR-code-review and user-flow-review findings actually addressed (not just acknowledged)? Spot-check **the PR diff** for each claimed fix. Unresolved material findings ⇒ NO-GO.
3. **Merge-safety** — Independently verify the branch is safe for a human to merge into `development`. **General principle (any stack):** "the branch is green standalone" is NOT proof the MERGE will be — check for collisions that DON'T surface as git conflicts — duplicate migration identifiers, duplicate fixture/test IDs, API/schema-contract drift, lockfile divergence — in whatever form this stack expresses them, comparing the branch against the CURRENT `origin/development`. Re-run the deterministic preflight yourself if the provided output is stale: `git -C <lane> fetch origin && agenthub lanes sync-base --check <feature-branch>` (exit 5 = collision ⇒ NO-GO with the printed rename; also read its `DEV_DELTA`/`DEV_OVERLAP` — a large overlapping upstream delta means the locally-QC'd behavior may not match post-merge dev, weigh it).
- **Stack-specific checks (from the active profile):** read `<lane>/.agenthub/profile/review-checks.md` with the Read tool if it exists, and apply every check it lists (e.g. migration-identifier collisions, API/contract regeneration). Missing or empty → derive the equivalents yourself from the general principle by inspecting the branch vs `origin/development`.
- **Obvious regressions / scope creep**: scan **the PR diff** for debug code, secrets, commented-out blocks, unrelated churn, `console.log`/`print` debugging, TODO/FIXME left in critical paths.
4. **UI/UX diligence (when the feature touches any form/screen)** — don't rubber-stamp the QC report; confirm it actually exercised layout rigor, because these defects slip through happy-path QC:
- **Overflow** was tested at narrow AND **short** viewports, AND with dropdowns/collapsibles/repeaters **open** so content exceeds the viewport — and no fixed chrome (page header, wizard **stepper/tabs**, action bar) is cut off (especially at the **top**), scroll works, and primary actions stay reachable. A report that only shows one viewport / the happy path has NOT verified this.
- Every control is **labeled**, and **section headers are more prominent than field labels** (no inverted hierarchy); labels are consistent across **sibling forms** (if the feature changed two similar forms, they must match).
- Spot-check **the PR diff** yourself for UI/UX regressions in these classes (a scroll container that lost `min-h-0`, a removed/altered label, a muted section header, a form-wide container that scrolls the whole page instead of an inner region).
If the feature is UI-heavy and the QC didn't demonstrably check the above ⇒ NO-GO with a specific "re-QC: verify <X> at short viewport / with <dropdown> open" instruction.
5. **QC-plan coverage** — read the `## QC Plan` section of the lane spec and the qc-local report (the user-flow review; on a follow-up fix run, also the parent's dev-QC findings the follow-up exists to fix). Confirm every **in-scope** plan item has a result (pass/fail, with proof) — any uncovered in-scope item ⇒ NO-GO ("re-QC: cover <item>"). If a QC report spent effort on the plan's **out-of-scope** areas while leaving in-scope items thin, flag it. Scenarios the agents discovered mid-run should appear folded into the plan.
## Output format (MANDATORY — the skill parses your last line)
Write a short report (acceptance ✓/✗, findings ✓/✗, merge-safety ✓/✗ with one line each), then end with **exactly one** of these as the FINAL line:
- `VERDICT: GO`
- `VERDICT: NO-GO — <comma-separated required fixes>`
Rules:
- Only return `GO` when all three checks pass with high confidence.
- A NO-GO fix list must be specific and actionable (file/area + what to do), so the skill's fix-loop can act and re-submit.
- Never push, merge, commit, or modify files. You are read-only. Your verdict is the deliverable.
+34 -174
View File
@@ -1463,16 +1463,24 @@ async function cmdStart(flags) {
}
/**
* Installs/removes a systemd `--user` service so the dashboard survives
* reboots without anything (Claude Code included) needing to start it first.
* Linux/systemd only; other platforms are told to keep using `agenthub start`.
* Installs/removes a systemd `--user` service (Linux) or a LaunchAgent
* (macOS) so the dashboard survives reboots without anything (Claude Code
* included) needing to start it first. Elsewhere, `agenthub start` by hand.
*/
async function cmdService(sub, flags) {
const svc = require(path.join(REPO_ROOT, "scripts", "systemd-service.js"));
const svc = require(path.join(REPO_ROOT, "scripts", "service-manager.js"));
if (!svc.systemctlAvailable()) {
console.error(c.red("✖ systemd --user is not available on this machine."));
console.error(
c.dim(" Auto-start on boot needs Linux + systemd. Use `agenthub start` manually instead.")
c.red(
`✖ ${svc.kind === "launchd" ? "launchd (a GUI login session)" : "systemd --user"} is not available here.`
)
);
console.error(
c.dim(
svc.kind === "launchd"
? " A LaunchAgent needs the user logged in at the Mac itself, not only over SSH. Use `agenthub start` meanwhile."
: " Auto-start on boot needs Linux + systemd. Use `agenthub start` manually instead."
)
);
process.exit(1);
}
@@ -1493,24 +1501,27 @@ async function cmdService(sub, flags) {
description: "AgentHub dashboard server",
workingDir: REPO_ROOT,
execStart: `${process.execPath} ${path.join(REPO_ROOT, "server", "index.js")}`,
argv: [process.execPath, path.join(REPO_ROOT, "server", "index.js")],
env,
});
if (result === "foreign") {
console.error(
c.red(
`✖ ~/.config/systemd/user/${name}.service already exists and wasn't written by agenthub.`
)
c.red(`✖ ${svc.unitPath(name)} already exists and wasn't written by agenthub.`)
);
console.error(c.dim(" Remove or rename it, then re-run `agenthub service install`."));
process.exit(1);
}
if (result === "failed") {
console.error(c.red("✖ Failed to write/enable the systemd unit."));
console.error(c.red(`✖ Failed to write/enable the ${svc.label}.`));
process.exit(1);
}
console.log(
`${c.green("✔")} systemd --user service '${name}' ${result === "unchanged" ? "already up to date" : "installed"} and enabled.`
`${c.green("✔")} ${svc.label} '${name}' ${result === "unchanged" ? "already up to date" : "installed"} and enabled.`
);
if (svc.kind === "launchd") {
console.log(c.dim(` It starts at every login. Server log: ${svc.logPath()}`));
return;
}
const lingered = svc.enableLinger();
if (lingered) {
console.log(
@@ -1531,20 +1542,24 @@ async function cmdService(sub, flags) {
if (sub === "uninstall") {
const result = svc.uninstallUserService(name);
if (result === "foreign") {
console.error(
c.red(
`✖ ~/.config/systemd/user/${name}.service wasn't written by agenthub — not touching it.`
)
);
console.error(c.red(`✖ ${svc.unitPath(name)} wasn't written by agenthub — not touching it.`));
process.exit(1);
}
console.log(
`${c.green("✔")} systemd service ${result === "absent" ? "was not installed" : "removed"}.`
`${c.green("✔")} ${svc.label} ${result === "absent" ? "was not installed" : "removed"}.`
);
return;
}
if (sub === "status") {
spawn("systemctl", ["--user", "status", `${name}.service`, "--no-pager"], { stdio: "inherit" });
if (svc.kind === "launchd") {
spawn("launchctl", ["print", `gui/${process.getuid()}/io.smartgift.${name}`], {
stdio: "inherit",
});
} else {
spawn("systemctl", ["--user", "status", `${name}.service`, "--no-pager"], {
stdio: "inherit",
});
}
return;
}
console.error(c.red("✖ Usage: agenthub service install|uninstall|status [--port N]"));
@@ -1639,27 +1654,6 @@ async function cmdLanesAdd(args) {
console.log(`${c.green("✔")} Created lane #${lane.id}: ${lane.title}`);
}
/**
* `agenthub skills install` — copy this checkout's `skills/ship-feature-lane/`
* into `~/.claude/skills/ship-feature-lane/`, so `/ship-feature-lane` is
* discoverable from a session running inside any lane's own working
* directory, not just inside this repo. Pure filesystem action; does not
* talk to the dashboard server at all. Reinstall, not merge — overwrites an
* existing global copy with the current one.
*/
function cmdSkillsInstall() {
const { installShipFeatureLaneSkill } = require(
path.join(REPO_ROOT, "server", "lib", "skills-install.js")
);
try {
const result = installShipFeatureLaneSkill({ repoRoot: REPO_ROOT });
console.log(`${c.green("✔")} installed ship-feature-lane skill -> ${result.path}`);
} catch (err) {
console.error(`✖ ${err.message}`);
process.exitCode = 1;
}
}
/**
* `agenthub lanes gc [--dry-run]` — reap orphaned Playwright MCP processes
* (owning session died) and cap oversized hook logs, across every lane on
@@ -2402,25 +2396,6 @@ async function cmdLanesProofLink(args) {
);
}
/** `agenthub lanes agents install [<id>] [--cwd path]` — write the ship-feature-lane
* agent templates (qc-local, senior-gate-reviewer) into <lane>/.claude/agents/,
* git-excluded. Never run automatically; a session calls it explicitly. */
async function cmdLanesAgentsInstall(args) {
const resolved = await resolveLaneArg(args);
if (!resolved) return;
const result = await post(
`/api/lanes/${resolved.laneId}/agents/install`,
{},
{ allowError: true }
);
if (result.status) {
console.error(`✖ agents install → ${result.data?.error?.message || result.status}`);
process.exitCode = 1;
return;
}
console.log(`${c.green("✔")} installed: ${result.installed.join(", ")}`);
}
/** `agenthub lanes mcp sync [<id>] [--cwd path]` — relocate the source repo's
* already-configured MCP servers into <lane>/.mcp.json and seed Chromium
* profiles. Never run automatically; a session calls it explicitly. */
@@ -2499,8 +2474,7 @@ async function cmdLanesCi(args) {
* was display-only: the dashboard rendered a copy button and the operator
* pasted it into a session by hand. This runs it, in the lane's own cwd:
*
* - a slash command (`/superpowers:brainstorming`) starts `claude` with it
* as the prompt, exactly like `agenthub ship-full` does with the whole skill;
* - a slash command starts `claude` with it as the prompt;
* - anything else (`npm test`, `agenthub lanes hook ci-gate`) is spawned directly.
*
* With no node id it lists the nodes and their commands, which is also the
@@ -2663,88 +2637,6 @@ async function cmdLanesShell(args) {
});
}
/**
* Start a `claude` session in this lane driven by a pipeline's own skill.
* Two commands, two depths of work:
*
* agenthub ship-full → the 16-node `ship-feature` template, `/agenthub:ship-feature-lane`
* — autonomous to a published PR, then watched until a
* human merges it.
* agenthub ship-quick → the 8-node `default` template, `/agenthub:ship-feature`
* — in-repo feature work that stops at review/gate.
*
* Each command puts the lane on its own template, so the choice is the command
* you type; the skill string itself lives in the template's `skill` field and
* is never duplicated here.
*
* The prompt is passed as ONE argv element to `claude`, never through a shell —
* a requirement containing quotes, `$`, or `;` is text, not code. `--print`
* shows the exact command, switches nothing, and runs nothing.
*/
const SHIP_TEMPLATES = {
"ship-full": "ship-feature",
"ship-quick": "default",
};
async function cmdShip(command, args) {
const templateId = SHIP_TEMPLATES[command];
const { flags, positional } = parseArgs(args);
const resolved = await resolveLaneArg(args);
if (!resolved) return;
let { lane } = await get(`/api/lanes/${resolved.laneId}`);
const { pipelines } = await get("/api/lanes/pipelines");
const skill = pipelines.find((p) => p.id === templateId)?.skill;
if (!skill) {
console.error(
`✖ pipeline template "${templateId}" declares no driving skill — ` +
`add a "skill" field to it (see docs/LANES.md § Custom template format)`
);
process.exitCode = 1;
return;
}
// `resolveLaneArg` only strips a leading bare lane id; the rest of the
// positionals are the requirement, joined back into one prompt line.
const requirement = positional
.filter((p) => p !== String(resolved.laneId))
.join(" ")
.trim();
const prompt = requirement ? `${skill} ${requirement}` : skill;
if (flags.print || !requirement) {
// `--print` shows what would run, so it switches nothing.
if (!requirement) console.error(`usage: agenthub ${command} "<requirement>" [<id>] [--print]`);
console.log(`cd ${lane.cwd} && claude ${JSON.stringify(prompt)}`);
if (!requirement) process.exitCode = 1;
return;
}
// The command picks the pipeline, not the lane's current setting: put the
// lane on the matching template first so the dashboard renders the right
// node count from the start rather than after the skill self-corrects.
if (lane.pipeline !== templateId) {
({ lane } = await patch(`/api/lanes/${lane.id}`, { pipeline: templateId }));
}
console.log(
`${c.dim(`lane #${lane.id} · pipeline ${lane.pipeline} (${lane.pipeline_nodes.length} nodes)`)}\n` +
`${c.cyan("→")} claude ${JSON.stringify(prompt)}`
);
const child = spawn("claude", [prompt], { stdio: "inherit", cwd: lane.cwd });
await new Promise((resolve) => {
child.on("close", (code) => {
if (code) process.exitCode = code;
resolve();
});
child.on("error", (err) => {
console.error(c.red(`✖ ${err?.message || err}`));
process.exitCode = 1;
resolve();
});
});
}
async function cmdFeatureShow(args) {
const slug = args.find((arg) => !arg.startsWith("--"));
if (!slug) {
@@ -2923,16 +2815,6 @@ const COMMAND_GROUPS = [
"[<node-id>] [extra…] [<id>] [--print]",
"Run ONE pipeline node's own command in the lane's cwd (no id: list every node and its command)",
],
[
"ship-full",
'"<requirement>" [<id>] [--print]',
"Run the 16-stage lane pipeline: implement → gates → e2e → review → QC → senior gate → PR, watched until a human merges (--print: show the command, run nothing)",
],
[
"ship-quick",
'"<requirement>" [<id>] [--print]',
"Run the 8-stage in-repo pipeline: plan → implement → tests → review → gate → ship. No PR, no browser QC",
],
[
"lanes shell",
"[<id>]",
@@ -2961,11 +2843,6 @@ const COMMAND_GROUPS = [
"[<id>]",
"Converge clone-root proof/ onto .playwright-mcp/proof (idempotent, never automatic)",
],
[
"lanes agents install",
"[<id>]",
"Write the ship-feature-lane agent templates (qc-local, senior-gate-reviewer) into <lane>/.claude/agents/, git-excluded",
],
[
"lanes mcp sync",
"[<id>]",
@@ -2986,11 +2863,6 @@ const COMMAND_GROUPS = [
"[--dry-run]",
"Reap orphaned Playwright MCP processes + cap oversized hook logs, across every lane",
],
[
"skills install",
"",
"Install skills/ship-feature-lane/ into ~/.claude/skills/ so /ship-feature-lane works from any lane",
],
[
"lock status|acquire|release",
"[<name>] [--holder X] [--timeout N]",
@@ -3817,9 +3689,6 @@ async function runCommand(argv) {
return cmdLanesRuntime(rest[0], rest.slice(1));
}
if (rest[0] === "proof-link") return cmdLanesProofLink(rest.slice(1));
if (rest[0] === "agents" && rest[1] === "install") {
return cmdLanesAgentsInstall(rest.slice(2));
}
if (rest[0] === "mcp" && rest[1] === "sync") {
return cmdLanesMcpSync(rest.slice(2));
}
@@ -3842,12 +3711,6 @@ async function runCommand(argv) {
return cmdLanesGc(rest.slice(1));
}
return cmdLanes();
case "skills": {
if (rest[0] === "install") return cmdSkillsInstall();
console.error("usage: agenthub skills install");
process.exitCode = 1;
return;
}
case "lock": {
const sub = rest[0];
if (sub === "status") return cmdLockStatus(rest.slice(1));
@@ -3861,9 +3724,6 @@ async function runCommand(argv) {
}
case "stage":
return cmdStage(rest);
case "ship-full":
case "ship-quick":
return cmdShip(cmd, rest);
case "feature": {
const sub = rest[0];
if (sub === "list") return cmdFeatureList(rest.slice(1));
+15 -8
View File
@@ -115,7 +115,6 @@ export function AddLaneModal({
const [browseOpen, setBrowseOpen] = useState(false);
const [setupResult, setSetupResult] = useState<{
profile: "scaffolded" | "skipped" | "failed";
agents: "ok" | "failed";
mcp: "ok" | "failed";
router: "ok" | "skipped" | "failed";
} | null>(null);
@@ -294,7 +293,7 @@ export function AddLaneModal({
// POST /worktree returns as soon as the DB row exists (202) — the
// actual `git worktree add` runs afterward, in the background, on the
// server. Firing setup against the lane's cwd before that finishes
// means agents/mcp write into a directory that doesn't exist yet, so
// means mcp writes into a directory that doesn't exist yet, so
// wait for provisioning to leave the "provisioning" status first.
const provisionedLane = await waitForProvisioned(result.lane.id);
if (!provisionedLane || provisionedLane.status === "failed") {
@@ -303,9 +302,8 @@ export function AddLaneModal({
return;
}
const [profileOutcome, agentsOutcome, mcpOutcome, routerOutcome] = await Promise.allSettled([
const [profileOutcome, mcpOutcome, routerOutcome] = await Promise.allSettled([
api.lanes.profileInit(result.lane.id),
api.lanes.agentsInstall(result.lane.id),
api.lanes.mcpSync(result.lane.id),
applyRouter(result.lane.id),
]);
@@ -316,7 +314,6 @@ export function AddLaneModal({
? "scaffolded"
: "skipped"
: "failed",
agents: agentsOutcome.status === "fulfilled" ? "ok" : "failed",
mcp: mcpOutcome.status === "fulfilled" ? "ok" : "failed",
router:
routerOutcome.status !== "fulfilled" ? "failed" : router === "native" ? "skipped" : "ok",
@@ -328,7 +325,6 @@ export function AddLaneModal({
console.info("[add-lane] auto-setup result:", {
profile:
profileOutcome.status === "fulfilled" ? profileOutcome.value : profileOutcome.reason,
agents: agentsOutcome.status === "fulfilled" ? agentsOutcome.value : agentsOutcome.reason,
mcp: mcpOutcome.status === "fulfilled" ? mcpOutcome.value : mcpOutcome.reason,
// Never the profile itself: it would put an endpoint and a lane id in
// the browser console. (The key is never sent here at all.)
@@ -429,6 +425,15 @@ export function AddLaneModal({
label={t("addLaneToolCodex")}
onClick={() => setTool("codex")}
/>
<Seg
active={tool === "antigravity"}
label={t("addLaneToolAntigravity")}
onClick={() => {
setTool("antigravity");
// `agy` cannot run behind an AI Router (see router-apply.js).
setRouter("native");
}}
/>
</div>
</div>
@@ -635,7 +640,10 @@ export function AddLaneModal({
hid it. The pipeline picker is gone entirely: every lane is created
on `default` (the server's own default) and the template is changed
from the lane's own header afterwards. */}
<div className="rounded-md border border-border-light bg-surface-0 p-2">
<div
className="rounded-md border border-border-light bg-surface-0 p-2"
hidden={tool === "antigravity"}
>
<div>
<fieldset>
<legend className="mb-1 text-xs text-fg-secondary">{t("addLaneRouterLabel")}</legend>
@@ -728,7 +736,6 @@ export function AddLaneModal({
ok: setupResult.profile !== "failed",
skipped: setupResult.profile === "skipped",
},
{ label: t("addLaneSetupAgents"), ok: setupResult.agents === "ok" },
{ label: t("addLaneSetupMcp"), ok: setupResult.mcp === "ok" },
{
label: t("addLaneSetupRouter"),
+8 -39
View File
@@ -271,7 +271,7 @@ export function since(sec: number | null): string {
}
/**
* Repo tooling (agents install / MCP sync / dev-sync check, and the
* Repo tooling (MCP sync / dev-sync check, and the
* create/update-readme run, which moved here from the Add-lane modal) for one lane,
* collapsed into a single dropdown. Lives outside LaneCard so it can be
* placed in the Workspace page header, next to "Add lane" — it polls its
@@ -281,16 +281,11 @@ export function since(sec: number | null): string {
export function LaneToolsMenu({ lane }: { lane: Lane }) {
const { t } = useTranslation(["lanes"]);
const [toolsMenuOpen, setToolsMenuOpen] = useState(false);
const [laneActionBusy, setLaneActionBusy] = useState<
"agents" | "mcp" | "sync-check" | "docs" | null
>(null);
const [laneActionBusy, setLaneActionBusy] = useState<"mcp" | "sync-check" | "docs" | null>(null);
const [laneActionResult, setLaneActionResult] = useState<string | null>(null);
const runtime = useLaneRuntime(lane.id, 0);
const runLaneAction = async (
which: "agents" | "mcp" | "sync-check" | "docs",
fn: () => Promise<string>
) => {
const runLaneAction = async (which: "mcp" | "sync-check" | "docs", fn: () => Promise<string>) => {
setLaneActionBusy(which);
setLaneActionResult(null);
try {
@@ -302,12 +297,6 @@ export function LaneToolsMenu({ lane }: { lane: Lane }) {
}
};
const handleAgentsInstall = () =>
runLaneAction("agents", async () => {
const result = await api.lanes.agentsInstall(lane.id);
return t("actions.agentsInstallResult", { files: result.installed.join(", ") });
});
// A skill only exists inside a CLI session, so there is nothing server-side
// to call: this opens the lane's own terminal run with the slash command as
// its first message. Claude-only — codex has no slash commands.
@@ -363,20 +352,7 @@ export function LaneToolsMenu({ lane }: { lane: Lane }) {
role="menu"
className="absolute right-0 z-10 mt-1 min-w-44 overflow-hidden rounded-md border border-border-light bg-surface-0 py-1 shadow-lg shadow-black/40"
>
<button
type="button"
role="menuitem"
data-testid="lane-agents-install"
onClick={(e) => {
e.stopPropagation();
setToolsMenuOpen(false);
void handleAgentsInstall();
}}
className="block w-full px-3 py-1.5 text-left text-fg-secondary hover:bg-surface-2"
>
{t("actions.agentsInstall")}
</button>
{lane.tool !== "codex" && (
{lane.tool === "claude" && (
<button
type="button"
role="menuitem"
@@ -484,18 +460,11 @@ export default function LaneCard({
// renders no frame at all rather than an empty box.
className="flex flex-col rounded-lg border border-border bg-surface-4 p-2.5 transition-colors hover:border-border-light empty:hidden"
>
{(lane.ci_status || lane.tool === "codex") && (
{lane.ci_status && (
<div className="mb-2 flex flex-wrap items-center gap-1.5 text-[11px]">
{lane.ci_status && (
<span className="rounded bg-surface-2 px-1.5 py-0.5 text-fg-secondary">
CI {lane.ci_status}
</span>
)}
{lane.tool === "codex" && (
<span className="rounded border border-border bg-surface-2 px-1.5 py-0.5 text-[10px] text-fg-muted">
Codex
</span>
)}
<span className="rounded bg-surface-2 px-1.5 py-0.5 text-fg-secondary">
CI {lane.ci_status}
</span>
</div>
)}
+105 -49
View File
@@ -41,8 +41,6 @@ import {
Columns2,
FileText,
FoldVertical,
ArrowLeftToLine,
ArrowRightToLine,
Folder,
Minus,
Pencil,
@@ -53,14 +51,14 @@ import {
UnfoldVertical,
} from "lucide-react";
import { api } from "../../lib/api";
import { LaneDiffView, LaneFileView, type DiffLayout } from "./LaneDiffView";
import { LaneDiffView, LaneFileView, type DiffLayout, type LaneDiffChange } from "./LaneDiffView";
import { LaneConflictView } from "./LaneConflictView";
import { LaneGitHeader, useLaneGitFacts } from "./LaneGitHeader";
import type {
LaneChangeFile,
LaneChangeRange,
LaneChanges,
LaneCommit,
LaneDiffHunk,
LaneTreeEntry,
} from "../../lib/types";
@@ -121,6 +119,9 @@ function treeMark(code: string): { letter: string; tone: string } {
// The tint fills the whole row, not just the letter, so a changed file
// stands out of a long tree at a glance.
if (code === "??") return { letter: "U", tone: "text-status-success bg-status-success/10" };
// A merge conflict (git's unmerged codes) before A/D: `AA`/`DU` are not adds or deletes.
if (["DD", "AU", "UD", "UA", "DU", "AA", "UU"].includes(code))
return { letter: "!", tone: "text-status-danger bg-status-danger/10" };
if (code.includes("A")) return { letter: "A", tone: "text-status-success bg-status-success/10" };
if (code.includes("D")) return { letter: "D", tone: "text-status-danger bg-status-danger/10" };
if (code.includes("R")) return { letter: "R", tone: "text-status-warning bg-status-warning/10" };
@@ -321,20 +322,22 @@ function ConflictActions({
const { t } = useTranslation(["lanes"]);
return (
<span className="flex shrink-0 items-center gap-0.5">
<IconButton
label={t("changes.takeOurs")}
disabled={busy}
onClick={() => onResolve(f.path, "ours")}
>
<ArrowLeftToLine className="h-3 w-3" />
</IconButton>
<IconButton
label={t("changes.takeTheirs")}
disabled={busy}
onClick={() => onResolve(f.path, "theirs")}
>
<ArrowRightToLine className="h-3 w-3" />
</IconButton>
{(["ours", "theirs"] as const).map((side) => (
<button
key={side}
type="button"
disabled={busy}
onClick={() => onResolve(f.path, side)}
title={t(side === "ours" ? "changes.takeOursHint" : "changes.takeTheirsHint")}
className={`shrink-0 rounded border px-1 text-[10px] disabled:opacity-40 ${
side === "ours"
? "border-status-success/40 text-status-success hover:bg-status-success/10"
: "border-accent/40 text-accent hover:bg-accent/10"
}`}
>
{t(side === "ours" ? "changes.takeOurs" : "changes.takeTheirs")}
</button>
))}
<IconButton
label={t("changes.markResolved")}
disabled={busy}
@@ -450,10 +453,33 @@ export function LaneChangesPanel({
// The whole-file editor's text while it is open; null = viewing.
const [draft, setDraft] = useState<string | null>(null);
const editWanted = useRef(false);
// Where the editor opens: the line clicked in the read view, and that view's
// scroll offset, so the text does not jump when the textarea replaces it.
const editAt = useRef<{ line: number; scrollTop: number } | null>(null);
const editorRef = useRef<HTMLTextAreaElement>(null);
const editing = draft !== null;
useEffect(() => {
const at = editAt.current;
const el = editorRef.current;
if (!editing || !at || !el) return;
editAt.current = null;
const offset = el.value
.split("\n")
.slice(0, at.line)
.reduce((n, l) => n + l.length + 1, 0);
el.setSelectionRange(offset, offset);
el.focus({ preventScroll: true });
el.scrollTop = at.scrollTop;
}, [editing]);
const startEdit = (line: number, scrollTop: number) => {
if (!text?.sha) return;
editAt.current = { line, scrollTop };
setDraft(text.lines.join("\n"));
};
useEffect(() => {
if (!editWanted.current || !text) return;
editWanted.current = false;
if (text.sha) setDraft(text.lines.join("\n"));
if (text.sha) startEdit(0, 0);
// Asked for from the diff, refused once the file arrived: say why here,
// not with an Edit button that silently does nothing.
else setError(t(noEditReason(text)));
@@ -463,6 +489,8 @@ export function LaneChangesPanel({
const [busy, setBusy] = useState(false);
const [confirmDiscard, setConfirmDiscard] = useState<string | null>(null);
const [armedAbort, setArmedAbort] = useState(false);
// A conflicted file opens in the conflict view; true = the plain editor.
const [rawEdit, setRawEdit] = useState(false);
// The hunk whose Undo was clicked once: `${path}\n${header}`.
const [armedHunk, setArmedHunk] = useState<string | null>(null);
// Files folded shut in review mode. A change-set is read file by file, and
@@ -697,9 +725,19 @@ export function LaneChangesPanel({
setWhole(full && range !== "commit");
setText(null);
setDraft(null);
setRawEdit(false);
setMode("file");
};
const goBack = () => {
const back = returnTo.current;
pendingScroll.current = back?.scroll ?? 0;
returnTo.current = null;
setMode(back?.mode ?? (range === "commit" ? "review" : "overview"));
setOpenFile(null);
setWhole(false);
};
// Save the editor over exactly the bytes it opened (`sha`): a file the agent
// rewrote meanwhile comes back 409 ESTALE and the draft stays for a retry.
const saveDraft = async () => {
@@ -770,16 +808,22 @@ export function LaneChangesPanel({
};
const resolve: Resolve = (path, side) => void mergeAct("resolve", { path, side });
// One hunk, matched by its `@@` line against a fresh diff at the context
// this diff was read with — so the server never applies a stale patch.
const actHunk = async (action: "stage-hunk" | "discard-hunk", path: string, hunk: string) => {
// One change block, named by its hunk's `@@` line and its index inside that
// hunk, matched against a fresh diff at the context this diff was read
// with — so the server never applies a stale patch.
const actHunk = async (
action: "stage-hunk" | "discard-hunk",
path: string,
change: LaneDiffChange
) => {
const lane = laneId;
setBusy(true);
setError(null);
try {
await api.lanes.gitAction(lane, action, {
path,
hunk,
hunk: change.hunk.header,
block: change.block,
context: data?.available ? data.context : undefined,
...(action === "discard-hunk" ? { confirm: true } : {}),
});
@@ -794,13 +838,13 @@ export function LaneChangesPanel({
}
};
// Stage / Undo on each hunk of a file with unstaged changes. The diff is
// Stage / Undo on each change block of a file with unstaged changes. The diff is
// HEAD → working tree, so a staged-only file gets none: undoing its tree
// would leave the index holding the change.
const hunkActions = (f: LaneChangeFile) =>
range === "work" && f.unstaged && !f.untracked && !f.binary
? (hunk: LaneDiffHunk) => {
const key = `${f.path}\n${hunk.header}`;
? (change: LaneDiffChange) => {
const key = `${f.path}\n${change.hunk.header}\n${change.block}`;
const armed = armedHunk === key;
return (
<>
@@ -810,7 +854,7 @@ export function LaneChangesPanel({
title={armed ? t("changes.undoHunkConfirm") : t("changes.undoHunk")}
disabled={busy}
onClick={() =>
armed ? void actHunk("discard-hunk", f.path, hunk.header) : setArmedHunk(key)
armed ? void actHunk("discard-hunk", f.path, change) : setArmedHunk(key)
}
className={`${HUNK_CHIP} ${
armed
@@ -825,7 +869,7 @@ export function LaneChangesPanel({
aria-label={t("changes.stageHunk")}
title={t("changes.stageHunk")}
disabled={busy}
onClick={() => void actHunk("stage-hunk", f.path, hunk.header)}
onClick={() => void actHunk("stage-hunk", f.path, change)}
className={`${HUNK_CHIP} border-status-success bg-status-success/25 text-status-success hover:bg-status-success/35`}
>
{t("changes.stageHunkShort")}
@@ -871,12 +915,6 @@ export function LaneChangesPanel({
return next;
});
// Full width edits in place: an editable whole file IS the editor, and
// Cancel just puts the saved text back (this effect re-seeds the draft).
const editableText = full && mode === "file" && whole && range !== "commit" && text?.sha;
useEffect(() => {
if (editableText && draft === null && text) setDraft(text.lines.join("\n"));
}, [editableText, draft, text]);
const dirty = draft !== null && draft !== text?.lines.join("\n");
const files = data?.available ? data.files : [];
@@ -896,8 +934,8 @@ export function LaneChangesPanel({
}
}, [data, files, confirmDiscard]);
// A tree or quick-open pick opens the whole file. Always-on editing (full
// width) makes a stray click here the easy way to lose typed work.
// A tree or quick-open pick opens the whole file — and, with an edit open,
// would drop it, so a dirty draft asks first.
const openWhole = (p: string) => {
if (dirty && !window.confirm(t("changes.dropEdits"))) return;
show(p);
@@ -997,14 +1035,7 @@ export function LaneChangesPanel({
{mode === "file" ? (
<button
type="button"
onClick={() => {
const back = returnTo.current;
pendingScroll.current = back?.scroll ?? 0;
returnTo.current = null;
setMode(back?.mode ?? (range === "commit" ? "review" : "overview"));
setOpenFile(null);
setWhole(false);
}}
onClick={goBack}
className="flex items-center gap-0.5 rounded border border-border-light px-1.5 py-0.5 text-[11px] text-fg-secondary hover:bg-surface-2"
>
<ChevronLeft className="h-3 w-3" />
@@ -1368,6 +1399,21 @@ export function LaneChangesPanel({
)}
</div>
</>
) : mode === "file" && range === "work" && current?.conflicted && !rawEdit && openFile ? (
<LaneConflictView
laneId={laneId}
path={openFile}
onResolved={() => {
refreshGit();
void load();
goBack();
}}
onEdit={() => {
setRawEdit(true);
editWanted.current = true;
setWhole(true);
}}
/>
) : mode === "file" ? (
current || (whole && text) ? (
<div className="flex min-h-0 flex-1 flex-col">
@@ -1384,6 +1430,9 @@ export function LaneChangesPanel({
/>
)}
{/* Only the working file is editable: a commit is history. */}
{/* The whole file enters the editor by a click on its text;
only the diff, which has no whole text to click, keeps
an Edit button. */}
{range !== "commit" &&
(draft === null && whole && text && !text.sha ? (
<span
@@ -1392,16 +1441,21 @@ export function LaneChangesPanel({
>
{t(noEditReason(text))}
</span>
) : draft === null && whole ? (
text && (
<span className="shrink-0 self-center text-[10px] text-fg-muted">
{t("changes.clickToEdit")}
</span>
)
) : draft === null ? (
<button
type="button"
data-testid="lane-file-edit"
disabled={busy}
onClick={() => {
// From the diff the file is not loaded yet: the
// editor opens as soon as the whole-file read lands.
if (whole && text?.sha) setDraft(text.lines.join("\n"));
else editWanted.current = true;
// The file is not loaded yet: the editor opens as
// soon as the whole-file read lands.
editWanted.current = true;
setWhole(true);
}}
className="flex shrink-0 items-center gap-1 self-center rounded border border-border-light px-1.5 py-0.5 text-[11px] text-fg-secondary hover:bg-surface-2 hover:text-fg-primary disabled:cursor-not-allowed disabled:opacity-40"
@@ -1422,7 +1476,7 @@ export function LaneChangesPanel({
</button>
<button
type="button"
disabled={busy || (full && !dirty)}
disabled={busy}
onClick={() => setDraft(null)}
className="shrink-0 self-center rounded border border-border-light px-1.5 py-0.5 text-[11px] text-fg-secondary hover:bg-surface-2 disabled:opacity-40"
>
@@ -1433,6 +1487,7 @@ export function LaneChangesPanel({
</div>
{whole && draft !== null ? (
<textarea
ref={editorRef}
data-testid="lane-file-editor"
aria-label={t("changes.editorLabel", { path: openFile })}
value={draft}
@@ -1454,6 +1509,7 @@ export function LaneChangesPanel({
lines={text.lines}
truncated={text.truncated}
fill
onEditAt={range !== "commit" && text.sha && !busy ? startEdit : undefined}
/>
) : (
<p className="text-[11px] text-fg-muted">{t("changes.loading")}</p>
@@ -0,0 +1,279 @@
/**
* @file LaneConflictView.tsx
* @description The Changes panel's view of ONE conflicted file during a merge
* (issue #45): the file with each conflict block drawn as its two sides —
* "mine" and "theirs", labelled from git's own markers and tinted apart — and
* a Keep mine / Take theirs / Keep both choice per block, undoable. Save and
* mark resolved writes the chosen text over exactly the version it opened
* (`gitSaveFile` with its `sha`, 409 ESTALE otherwise) and then runs
* `resolve done`, which re-checks that no marker is left. Take all mine /
* theirs is `resolve ours|theirs` for the whole file; Edit by hand hands the
* file to the panel's plain editor.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { ChevronDown, ChevronUp } from "lucide-react";
import { api } from "../../lib/api";
import {
applyChoices,
parseConflicts,
type ConflictChoice,
type ConflictPart,
} from "../../lib/conflicts";
const BASE =
"rounded border px-1.5 py-0.5 text-[11px] hover:bg-surface-2 disabled:cursor-not-allowed disabled:opacity-40";
const BTN = `${BASE} border-border-light text-fg-secondary hover:text-fg-primary`;
function Lines({ lines, className = "" }: { lines: string[]; className?: string }) {
return (
<pre className={`whitespace-pre px-2 font-mono text-[11px] leading-5 ${className}`}>
{lines.length ? lines.join("\n") : " "}
</pre>
);
}
export function LaneConflictView({
laneId,
path,
onResolved,
onEdit,
}: {
laneId: number;
path: string;
/** The file left the conflict (resolved, or a whole side taken). */
onResolved: () => void;
/** Open the file in the panel's plain editor instead. */
onEdit: () => void;
}) {
const { t } = useTranslation(["lanes"]);
const [file, setFile] = useState<{ lines: string[]; sha?: string; usable: boolean } | null>(null);
const [choices, setChoices] = useState<(ConflictChoice | undefined)[]>([]);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const blockRefs = useRef<(HTMLDivElement | null)[]>([]);
const [at, setAt] = useState(0);
useEffect(() => {
let live = true;
setFile(null);
setChoices([]);
setError(null);
api.lanes
.gitFile(laneId, path, "work")
.then((r) => {
if (!live) return;
setFile(
r.available
? { lines: r.lines, sha: r.sha, usable: !r.binary && !r.truncated && !!r.sha }
: { lines: [], usable: false }
);
})
.catch((e) => live && setError(e instanceof Error ? e.message : String(e)));
return () => {
live = false;
};
}, [laneId, path]);
const parts: ConflictPart[] | null = file?.usable ? parseConflicts(file.lines) : null;
const total = parts ? parts.filter((p) => p.kind === "conflict").length : 0;
const chosen = choices.filter(Boolean).length;
const done = total > 0 && chosen === total;
const run = async (fn: () => Promise<unknown>) => {
setBusy(true);
setError(null);
try {
await fn();
onResolved();
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
setBusy(false);
}
};
const save = () =>
run(async () => {
if (!parts || !file?.sha) return;
await api.lanes.gitSaveFile(laneId, path, applyChoices(parts, choices).join("\n"), file.sha);
await api.lanes.gitAction(laneId, "resolve", { path, side: "done" });
});
const takeAll = (side: "ours" | "theirs") =>
run(() => api.lanes.gitAction(laneId, "resolve", { path, side }));
const choose = (i: number, c: ConflictChoice | undefined) =>
setChoices((prev) => {
const next = [...prev];
next[i] = c;
return next;
});
const jump = (step: number) => {
if (!total) return;
const i = (at + step + total) % total;
setAt(i);
blockRefs.current[i]?.scrollIntoView({ block: "center" });
};
let blockIndex = -1;
return (
<div data-testid="lane-conflict-view" className="flex min-h-0 flex-1 flex-col gap-1.5">
<div className="flex flex-wrap items-center gap-1.5">
<span className="min-w-0 flex-1 truncate font-mono text-[11px] text-fg-primary">
{path}
</span>
{total > 0 && (
<span className="text-[11px] text-status-warning">
{t("conflict.left", { left: total - chosen, total })}
</span>
)}
<button
type="button"
className={BTN}
aria-label={t("conflict.prev")}
disabled={!total}
onClick={() => jump(-1)}
>
<ChevronUp className="h-3 w-3" />
</button>
<button
type="button"
className={BTN}
aria-label={t("conflict.next")}
disabled={!total}
onClick={() => jump(1)}
>
<ChevronDown className="h-3 w-3" />
</button>
<button type="button" className={BTN} disabled={busy} onClick={() => void takeAll("ours")}>
{t("conflict.allOurs")}
</button>
<button
type="button"
className={BTN}
disabled={busy}
onClick={() => void takeAll("theirs")}
>
{t("conflict.allTheirs")}
</button>
<button type="button" className={BTN} disabled={busy} onClick={onEdit}>
{t("conflict.editByHand")}
</button>
</div>
{error && (
<p role="alert" className="whitespace-pre-wrap text-[11px] text-status-danger">
{error}
</p>
)}
{!file ? (
<p className="text-[11px] text-fg-muted">{t("changes.loading")}</p>
) : !parts ? (
<p className="text-[11px] text-status-warning">
{file.usable ? t("conflict.unbalanced") : t("conflict.unusable")}
</p>
) : (
<div className="min-h-0 flex-1 overflow-auto rounded border border-border-light bg-surface-0">
{parts.map((p, n) => {
if (p.kind === "text")
return <Lines key={n} lines={p.lines} className="text-fg-primary" />;
const i = ++blockIndex;
const c = choices[i];
return (
<div
key={n}
ref={(el) => {
blockRefs.current[i] = el;
}}
data-testid="conflict-block"
className="my-1 border-y-2 border-status-warning/70"
>
<div className="flex flex-wrap items-center gap-1 bg-surface-2 px-2 py-0.5 text-[11px]">
{c ? (
<>
<span className="text-fg-muted">{t(`conflict.chose.${c}`)}</span>
<button type="button" className={BTN} onClick={() => choose(i, undefined)}>
{t("conflict.undo")}
</button>
</>
) : (
<>
<button
type="button"
className={`${BASE} border-status-success/70 font-medium text-status-success`}
onClick={() => choose(i, "ours")}
>
{t("conflict.keepOurs")}
</button>
<button
type="button"
className={`${BASE} border-accent/70 font-medium text-accent`}
onClick={() => choose(i, "theirs")}
>
{t("conflict.takeTheirs")}
</button>
<button type="button" className={BTN} onClick={() => choose(i, "both")}>
{t("conflict.keepBoth")}
</button>
</>
)}
<span className="ml-auto text-fg-muted">
{i + 1}/{total}
</span>
</div>
{c ? (
<Lines
lines={
c === "ours" ? p.ours : c === "theirs" ? p.theirs : [...p.ours, ...p.theirs]
}
className="bg-surface-2 text-fg-primary"
/>
) : (
<>
<div className="border-l-4 border-status-success bg-status-success/20">
<div className="bg-status-success/30 px-2 py-0.5 text-[11px] font-semibold text-status-success">
{t("conflict.ours", { label: p.oursLabel || "HEAD" })}
</div>
<Lines lines={p.ours} className="text-fg-primary" />
</div>
<div className="border-l-4 border-accent bg-accent/20">
<div className="bg-accent/30 px-2 py-0.5 text-[11px] font-semibold text-accent">
{t("conflict.theirs", { label: p.theirsLabel || "?" })}
</div>
<Lines lines={p.theirs} className="text-fg-primary" />
</div>
</>
)}
</div>
);
})}
</div>
)}
{parts && total > 0 && (
<div className="flex items-center justify-end gap-1.5">
<button
type="button"
className={BTN}
disabled={busy || !chosen}
onClick={() => setChoices([])}
>
{t("conflict.reset")}
</button>
<button
type="button"
disabled={busy || !done}
onClick={() => void save()}
className="rounded border border-accent/40 bg-accent/15 px-2 py-0.5 text-[11px] text-accent hover:bg-accent/25 disabled:cursor-not-allowed disabled:opacity-40"
>
{t("conflict.save")}
</button>
</div>
)}
</div>
);
}
+135 -51
View File
@@ -273,10 +273,13 @@ function Gutter({ n }: { n: number | null }) {
function Row({
tint,
style,
anchor,
children,
}: {
tint: string;
style?: CSSProperties;
/** This row starts change block `anchor` (file-wide): the bar's arrows land here. */
anchor?: number;
children: React.ReactNode;
}) {
return (
@@ -284,6 +287,7 @@ function Row({
className={`flex w-max min-w-full ${tint}`}
style={style}
data-diff-item={style ? "" : undefined}
data-change-index={anchor}
>
{children}
</div>
@@ -305,40 +309,82 @@ function markerClass(type: LaneDiffLine["type"]) {
return "text-fg-muted";
}
/** Per-hunk review controls (Undo / Keep), drawn in a bar under each hunk's
* last changed line. A context rather than a prop because lines render from
* four places; `hunks` is what the bar's "n of N" and its arrows walk. */
/** One change block: a run of consecutive +/- lines inside a hunk. git merges
* edits a few lines apart into one `@@` hunk, so the review bar acts on these
* instead (#50) — `block` is the index the server's `stage-hunk` /
* `discard-hunk` take beside the hunk's header. */
export type LaneDiffChange = {
hunk: LaneDiffHunk;
block: number;
/** First/last index in `hunk.lines` (unified). */
firstLine: number;
lastLine: number;
/** First/last split-view row. */
firstRow: number;
lastRow: number;
};
const blocksOf = new WeakMap<LaneDiffHunk, LaneDiffChange[]>();
/** A hunk's change blocks, cached per hunk object like `analyseHunk`. */
export function changeBlocks(hunk: LaneDiffHunk): LaneDiffChange[] {
const hit = blocksOf.get(hunk);
if (hit) return hit;
const out: LaneDiffChange[] = [];
const owner = new Map<LaneDiffLine, LaneDiffChange>();
hunk.lines.forEach((line, i) => {
if (line.type === "ctx") return;
let c = i > 0 && hunk.lines[i - 1]!.type !== "ctx" ? out[out.length - 1] : undefined;
if (!c) {
c = { hunk, block: out.length, firstLine: i, lastLine: i, firstRow: -1, lastRow: -1 };
out.push(c);
}
c.lastLine = i;
owner.set(line, c);
});
analyseHunk(hunk).rows.forEach((r, i) => {
const c = (r.left && owner.get(r.left)) || (r.right && owner.get(r.right));
if (!c) return;
if (c.firstRow < 0) c.firstRow = i;
c.lastRow = i;
});
blocksOf.set(hunk, out);
return out;
}
/** The block whose last line (unified) / last row (split) is `i`, if any. */
const barAtLine = (hunk: LaneDiffHunk, i: number) =>
changeBlocks(hunk).find((c) => c.lastLine === i);
const barAtRow = (hunk: LaneDiffHunk, i: number) => changeBlocks(hunk).find((c) => c.lastRow === i);
const startAtLine = (hunk: LaneDiffHunk, i: number) =>
changeBlocks(hunk).find((c) => c.firstLine === i);
const startAtRow = (hunk: LaneDiffHunk, i: number) =>
changeBlocks(hunk).find((c) => c.firstRow === i);
/** Per-block review controls (Undo / Keep), drawn in a bar under each change
* block's last line. A context rather than a prop because lines render from
* four places; `changes` is what the bar's "n of N" and its arrows walk. */
const HunkActions = createContext<{
actions: (hunk: LaneDiffHunk) => ReactNode;
hunks: LaneDiffHunk[];
actions: (change: LaneDiffChange) => ReactNode;
changes: LaneDiffChange[];
go: (index: number) => void;
} | null>(null);
/** Index of a hunk's last +/- line (unified), or last row with one (split). */
function lastChangedLine(hunk: LaneDiffHunk) {
for (let i = hunk.lines.length - 1; i >= 0; i -= 1) {
if (hunk.lines[i]!.type !== "ctx") return i;
}
return -1;
}
function lastChangedRow(hunk: LaneDiffHunk) {
const rows = analyseHunk(hunk).rows;
for (let i = rows.length - 1; i >= 0; i -= 1) {
const r = rows[i]!;
if ((r.left && r.left.type !== "ctx") || (r.right && r.right.type !== "ctx")) return i;
}
return -1;
/** File-wide index of `change`, for a row's `anchor`. */
function useAnchor(change?: LaneDiffChange) {
const ctx = useContext(HunkActions);
return change && ctx ? ctx.changes.indexOf(change) : undefined;
}
/** The review bar: hangs just BELOW the last changed line, pinned to the
/** The review bar: hangs just BELOW a change block's last line, pinned to the
* visible right edge, so it sits on the change it acts on — the editor-style
* "^ v 2 of 3 · Undo · Keep" instead of glyphs at the end of the `@@` line. */
function HunkBar({ hunk }: { hunk: LaneDiffHunk }) {
function HunkBar({ change }: { change: LaneDiffChange }) {
const { t } = useTranslation(["lanes"]);
const ctx = useContext(HunkActions);
if (!ctx) return null;
const index = ctx.hunks.indexOf(hunk);
const total = ctx.hunks.length;
const index = ctx.changes.indexOf(change);
const total = ctx.changes.length;
const nav =
"rounded px-0.5 text-fg-muted hover:bg-surface-3 hover:text-fg-primary disabled:opacity-30";
return (
@@ -370,14 +416,13 @@ function HunkBar({ hunk }: { hunk: LaneDiffHunk }) {
<span className="px-0.5 tabular-nums text-fg-muted">
{t("changes.hunkOf", { n: index + 1, total })}
</span>
{ctx.actions(hunk)}
{ctx.actions(change)}
</span>
</span>
);
}
function HunkHeader({ hunk, fixed }: { hunk: LaneDiffHunk; fixed?: boolean }) {
const ctx = useContext(HunkActions);
const at = hunk.header.split("@@")[1];
// Windowed, the header is one ROW_PX row like the lines around it.
return (
@@ -387,7 +432,6 @@ function HunkHeader({ hunk, fixed }: { hunk: LaneDiffHunk; fixed?: boolean }) {
}`}
style={fixed ? FIXED : undefined}
data-diff-item={fixed ? "" : undefined}
data-hunk-index={ctx ? ctx.hunks.indexOf(hunk) : undefined}
>
<span className="min-w-0 flex-1 truncate">
{at ? `@@${at}@@` : hunk.header}
@@ -403,16 +447,20 @@ function UnifiedLine({
emph,
style,
bar,
start,
}: {
line: LaneDiffLine;
lang: string;
emph?: [number, number];
style?: CSSProperties;
/** This is the hunk's last changed line: hang the review bar under it. */
bar?: LaneDiffHunk;
/** This is a change block's last line: hang its review bar under it. */
bar?: LaneDiffChange;
/** This is a change block's first line: the bar's arrows scroll here. */
start?: LaneDiffChange;
}) {
const anchor = useAnchor(start);
return (
<Row tint={rowTint(line.type)} style={style}>
<Row tint={rowTint(line.type)} style={style} anchor={anchor}>
<Gutter n={line.oldLine} />
<Gutter n={line.newLine} />
<span className="whitespace-pre px-2">
@@ -421,14 +469,13 @@ function UnifiedLine({
</span>
<Code text={line.text} lang={lang} emph={emph} />
</span>
{bar && <HunkBar hunk={bar} />}
{bar && <HunkBar change={bar} />}
</Row>
);
}
function UnifiedHunk({ hunk, lang }: { hunk: LaneDiffHunk; lang: string }) {
const { emph } = analyseHunk(hunk);
const last = lastChangedLine(hunk);
return (
<div>
<HunkHeader hunk={hunk} />
@@ -438,7 +485,8 @@ function UnifiedHunk({ hunk, lang }: { hunk: LaneDiffHunk; lang: string }) {
line={line}
lang={lang}
emph={emph.get(i)}
bar={i === last ? hunk : undefined}
bar={barAtLine(hunk, i)}
start={startAtLine(hunk, i)}
/>
))}
</div>
@@ -473,16 +521,19 @@ function SplitLine({
side,
style,
bar,
start,
}: {
row: PairRow;
lang: string;
side: "left" | "right";
style?: CSSProperties;
bar?: LaneDiffHunk;
bar?: LaneDiffChange;
start?: LaneDiffChange;
}) {
const line = side === "left" ? row.left : row.right;
const anchor = useAnchor(start);
return (
<Row tint={rowTint(line?.type ?? null)} style={style}>
<Row tint={rowTint(line?.type ?? null)} style={style} anchor={anchor}>
<Gutter n={(side === "left" ? line?.oldLine : line?.newLine) ?? null} />
<span className="whitespace-pre px-1">
{line ? (
@@ -493,7 +544,7 @@ function SplitLine({
/>
) : null}
</span>
{bar && <HunkBar hunk={bar} />}
{bar && <HunkBar change={bar} />}
</Row>
);
}
@@ -519,8 +570,9 @@ function SplitColumn({
row={row}
lang={lang}
side={side}
// One bar per hunk: on the right (new) column only.
bar={side === "right" && i === lastChangedRow(hunk) ? hunk : undefined}
// One bar per change block: on the right (new) column only.
bar={side === "right" ? barAtRow(hunk, i) : undefined}
start={startAtRow(hunk, i)}
/>
))}
</div>
@@ -555,7 +607,8 @@ function SplitSlice({
lang={lang}
side={side}
style={FIXED}
bar={side === "right" && i === lastChangedRow(hunk) ? hunk : undefined}
bar={side === "right" ? barAtRow(hunk, i) : undefined}
start={startAtRow(hunk, i)}
/>
)
)}
@@ -652,8 +705,8 @@ export function LaneDiffView({
layout: DiffLayout;
/** Take the parent's height (single-file view) instead of the 60vh cap. */
fill?: boolean;
/** Controls drawn in each hunk's review bar. */
hunkActions?: (hunk: LaneDiffHunk) => ReactNode;
/** Controls drawn in each change block's review bar. */
hunkActions?: (change: LaneDiffChange) => ReactNode;
}) {
const root = useRef<HTMLDivElement>(null);
const { t } = useTranslation(["lanes"]);
@@ -672,12 +725,15 @@ export function LaneDiffView({
[layout, hunks]
);
// The bar's arrows: bring hunk `index`'s header into view. A windowed
// unified diff may not have it in the DOM, so there it is found by offset.
const changes = useMemo(() => (hunks ? hunks.flatMap(changeBlocks) : []), [hunks]);
// The bar's arrows: bring change block `index`'s first line into view. A
// windowed unified diff may not have it in the DOM, so there it is found by
// offset.
const go = (index: number) => {
const el = root.current;
if (!el || !hunks) return;
const header = el.querySelector<HTMLElement>(`[data-hunk-index="${index}"]`);
const target = changes[index];
if (!el || !target) return;
const header = el.querySelector<HTMLElement>(`[data-change-index="${index}"]`);
// The review list pins each file's header over its own diff.
const sticky = el
.closest("[data-review-file]")
@@ -688,10 +744,10 @@ export function LaneDiffView({
return;
}
// Windowed: the header is not in the DOM, but its offset is known.
const at = items.findIndex((it) => it.i < 0 && it.hunk === hunks[index]);
const at = items.findIndex((it) => it.hunk === target.hunk && it.i === target.firstLine);
if (at >= 0 && layout === "unified") el.scrollTop = at * ROW_PX;
};
const review = hunkActions && hunks ? { actions: hunkActions, hunks, go } : null;
const review = hunkActions && hunks ? { actions: hunkActions, changes, go } : null;
if (file.binary)
return <p className="px-2 py-1 text-[10px] text-fg-muted">{t("changes.binary")}</p>;
@@ -727,7 +783,8 @@ export function LaneDiffView({
lang={lang}
emph={analyseHunk(hunk).emph.get(i)}
style={FIXED}
bar={i === lastChangedLine(hunk) ? hunk : undefined}
bar={barAtLine(hunk, i)}
start={startAtLine(hunk, i)}
/>
)
)}
@@ -751,12 +808,16 @@ export function LaneFileView({
lines,
truncated,
fill = false,
onEditAt,
}: {
path: string;
lines: string[];
truncated?: boolean;
/** Take the parent's height instead of the 60vh cap. */
fill?: boolean;
/** Set when the file is editable: a click on the text (0-based line, and
* where the view was scrolled) asks to open the editor there. */
onEditAt?: (line: number, scrollTop: number) => void;
}) {
const { t } = useTranslation(["lanes"]);
const lang = langFor(path);
@@ -765,9 +826,12 @@ export function LaneFileView({
const minWidth = useMemo(() => `calc(${longest(lines)}ch + 3.5rem)`, [lines]);
const row = (text: string, i: number, style?: CSSProperties) => (
<Row key={i} tint="" style={style}>
<Gutter n={i + 1} />
<span className="whitespace-pre px-2">
<Code text={text} lang={lang} />
{/* `contents`: a line marker for the click handler, not a layout box. */}
<span data-ln={i} className="contents">
<Gutter n={i + 1} />
<span className="whitespace-pre px-2">
<Code text={text} lang={lang} />
</span>
</span>
</Row>
);
@@ -775,7 +839,27 @@ export function LaneFileView({
<div
data-testid="lane-file-view"
onScroll={(e) => win.onScroll(e.currentTarget)}
className={`overflow-auto font-mono text-[11px] leading-[1.45] ${boxHeight(fill, true)}`}
tabIndex={onEditAt ? 0 : undefined}
onClick={
onEditAt &&
((e) => {
// A click that ends a drag-selection is copying, not asking to edit.
if (window.getSelection()?.toString()) return;
const ln = (e.target as HTMLElement).closest("[data-ln]")?.getAttribute("data-ln");
onEditAt(Number(ln ?? 0), e.currentTarget.scrollTop);
})
}
onKeyDown={
onEditAt &&
((e) => {
if (e.key !== "Enter") return;
e.preventDefault();
onEditAt(0, e.currentTarget.scrollTop);
})
}
className={`overflow-auto font-mono text-[11px] leading-[1.45] ${boxHeight(fill, true)}${
onEditAt ? " cursor-text" : ""
}`}
>
{win.on ? (
<Windowed count={lines.length} range={win.range} minWidth={minWidth}>
+11 -7
View File
@@ -18,6 +18,7 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import type { Lane } from "../../lib/types";
import { LANE_TOOL_LABEL } from "../../lib/types";
const LIVENESS_DOT: Record<Lane["liveness"], string> = {
active: "bg-status-success",
@@ -41,7 +42,7 @@ const LIVENESS_DOT: Record<Lane["liveness"], string> = {
* recordDetection refuses any detection that isn't strictly ahead.
*/
function detectionLeads(lane: Lane): boolean {
if (!lane.detected_stage) return false;
if (!lane.detected_stage || !lane.pipeline_nodes.length) return false;
const nodes = lane.pipeline_nodes;
return (
nodes.findIndex((n) => n.id === lane.detected_stage) >=
@@ -115,15 +116,18 @@ export default function LaneStripCard({
<span className="shrink-0 text-[10px] font-semibold tracking-widest text-fg-muted">
#{lane.id}
</span>
<span className="truncate rounded bg-surface-4 px-1.5 py-0.5 text-fg-secondary">
{lane.stage}
</span>
{lane.tool === "codex" && (
{/* Only claude lanes carry a pipeline, and only while a template is
installed; the others show their CLI's tag in place of the stage chip. */}
{lane.tool !== "claude" || lane.pipeline_nodes.length === 0 ? (
<span className="shrink-0 rounded border border-border bg-surface-2 px-1.5 py-0.5 text-[10px] text-fg-muted">
Codex
{LANE_TOOL_LABEL[lane.tool]}
</span>
) : (
<span className="truncate rounded bg-surface-4 px-1.5 py-0.5 text-fg-secondary">
{lane.stage}
</span>
)}
{detectionLeads(lane) && (
{lane.tool === "claude" && detectionLeads(lane) && (
<span
data-testid={`lane-tile-auto-${lane.id}`}
title={lane.detected_signal || undefined}
@@ -27,7 +27,6 @@ vi.mock("../../../lib/api", () => ({
browse: vi.fn(),
get: vi.fn(),
profileInit: vi.fn(),
agentsInstall: vi.fn(),
mcpSync: vi.fn(),
routerApply: vi.fn(),
},
@@ -120,7 +119,6 @@ beforeEach(() => {
vi.mocked(api.lanes.profileInit)
.mockReset()
.mockResolvedValue({ scaffolded: false, reason: "no detectable Node.js project" });
vi.mocked(api.lanes.agentsInstall).mockReset().mockResolvedValue({ installed: [] });
vi.mocked(api.lanes.mcpSync).mockReset().mockResolvedValue({ servers: [], profilesSeeded: [] });
vi.mocked(api.lanes.routerApply).mockReset().mockResolvedValue({
tool: "claude",
@@ -383,7 +381,7 @@ describe("AddLaneModal — worktree mode (default)", () => {
expect(screen.queryByRole("dialog")).toBeNull();
});
it("fires profileInit, agentsInstall, and mcpSync after a successful worktree call", async () => {
it("fires profileInit and mcpSync after a successful worktree call", async () => {
vi.mocked(api.lanes.branches).mockResolvedValue({
branches: ["main"],
current: "main",
@@ -401,7 +399,6 @@ describe("AddLaneModal — worktree mode (default)", () => {
await waitFor(() => expect(api.lanes.worktree).toHaveBeenCalled());
await waitFor(() => expect(api.lanes.profileInit).toHaveBeenCalledWith(42));
expect(api.lanes.agentsInstall).toHaveBeenCalledWith(42);
expect(api.lanes.mcpSync).toHaveBeenCalledWith(42);
await waitFor(() => expect(onAdded).toHaveBeenCalled());
});
@@ -416,7 +413,6 @@ describe("AddLaneModal — worktree mode (default)", () => {
lane: { id: 43, title: "demo2", cwd: "/lanes/demo2", status: "provisioning" } as Lane,
});
vi.mocked(api.lanes.profileInit).mockRejectedValue(new Error("boom"));
vi.mocked(api.lanes.agentsInstall).mockRejectedValue(new Error("boom"));
vi.mocked(api.lanes.mcpSync).mockRejectedValue(new Error("boom"));
const onAdded = vi.fn();
const onClose = vi.fn();
@@ -482,7 +478,6 @@ describe("AddLaneModal — worktree mode (default)", () => {
await waitFor(() => expect(onAdded).toHaveBeenCalled());
expect(await screen.findByText(/auto-setup was skipped/)).toBeInTheDocument();
expect(api.lanes.profileInit).not.toHaveBeenCalled();
expect(api.lanes.agentsInstall).not.toHaveBeenCalled();
expect(api.lanes.mcpSync).not.toHaveBeenCalled();
});
});
@@ -23,7 +23,6 @@ vi.mock("../../../lib/api", () => ({
up: vi.fn(),
down: vi.fn(),
preflight: vi.fn().mockResolvedValue({ blocked: [], warnings: [] }),
agentsInstall: vi.fn(),
mcpSync: vi.fn(),
syncBaseCheck: vi.fn(),
routerApply: vi.fn(),
@@ -96,13 +95,16 @@ function makeLane(overrides: Partial<Lane> = {}): Lane {
}
describe("LaneCard lane tool badge", () => {
it("badges a codex lane and leaves a claude lane unbadged", () => {
const { rerender } = render(
<LaneCard {...{ lane: makeLane({ tool: "codex" }), onAction: vi.fn() }} />
);
expect(screen.getByText("Codex")).toBeInTheDocument();
rerender(<LaneCard {...{ lane: makeLane({ tool: "claude" }), onAction: vi.fn() }} />);
expect(screen.queryByText("Codex")).not.toBeInTheDocument();
// The strip tile already names the CLI; a card holding only that tag was an
// empty frame in the lane detail.
it("renders nothing for a codex or antigravity lane with nothing else to show", () => {
for (const tool of ["codex", "antigravity"] as const) {
const { container, unmount } = render(
<LaneCard {...{ lane: makeLane({ tool }), onAction: vi.fn() }} />
);
expect(container.querySelector('[data-testid="lane-card-1"]')).toBeEmptyDOMElement();
unmount();
}
});
});
@@ -306,17 +308,6 @@ describe("LaneToolsMenu", () => {
} as unknown as LaneRuntime);
});
it("clicking Install agents calls the API and shows the result", async () => {
vi.mocked(api.lanes.agentsInstall).mockResolvedValue({
installed: ["qc-local.md", "senior-gate-reviewer.md"],
});
render(<LaneToolsMenu lane={makeLane()} />);
await userEvent.click(await screen.findByTestId("lane-tools-menu"));
await userEvent.click(await screen.findByTestId("lane-agents-install"));
await waitFor(() => expect(api.lanes.agentsInstall).toHaveBeenCalledWith(1));
expect(await screen.findByTestId("lane-action-result")).toHaveTextContent("qc-local.md");
});
it("clicking Sync MCP calls the API and shows the result", async () => {
vi.mocked(api.lanes.mcpSync).mockResolvedValue({
servers: ["playwright"],
@@ -321,7 +321,7 @@ describe("LaneChangesPanel", () => {
expect(screen.getByText("Staged Changes")).toBeInTheDocument();
});
it("at full width shows the tree as a sidebar and opens a file straight into the editor", async () => {
it("at full width shows the tree as a sidebar and opens a file for reading, editing on a click", async () => {
vi.mocked(api.lanes.gitTree).mockResolvedValue({
available: true,
path: "",
@@ -346,19 +346,24 @@ describe("LaneChangesPanel", () => {
expect(screen.getAllByTestId("lane-changes-browse")).toHaveLength(1);
await user.click(await within(sidebar).findByText("main.ts"));
// No Edit click: the editor is simply there, Save/Cancel idle until typed.
// Opening a file only shows it: no editor until the text itself is clicked.
const view = await screen.findByTestId("lane-file-view");
expect(screen.queryByTestId("lane-file-editor")).toBeNull();
expect(screen.queryByTestId("lane-file-edit")).toBeNull();
await user.click(view);
const editor = await screen.findByTestId("lane-file-editor");
expect(editor).toHaveValue("const whole = 1;");
expect(screen.queryByTestId("lane-file-edit")).toBeNull();
expect(editor).toHaveFocus();
expect(screen.getByTestId("lane-file-save")).toBeDisabled();
await user.type(editor, "x");
expect(screen.getByTestId("lane-file-save")).toBeEnabled();
// Cancel reverts to the saved text and stays in the editor.
// Cancel drops the edit and goes back to reading.
await user.click(screen.getByRole("button", { name: "Cancel" }));
expect(await screen.findByTestId("lane-file-editor")).toHaveValue("const whole = 1;");
expect(await screen.findByTestId("lane-file-view")).toHaveTextContent("const whole = 1;");
expect(screen.queryByTestId("lane-file-editor")).toBeNull();
});
it("at full width opens a changed file from the overview straight into the editor", async () => {
it("at full width opens a changed file from the overview for reading, not editing", async () => {
vi.mocked(api.lanes.gitFile).mockResolvedValue({
available: true,
path: "server/lib/git-ops.js",
@@ -372,10 +377,31 @@ describe("LaneChangesPanel", () => {
render(<LaneChangesPanel laneId={7} full />);
const list = await screen.findByTestId("lane-changes-overview");
await user.click(within(list).getByText("server/lib/git-ops.js"));
expect(await screen.findByTestId("lane-file-editor")).toHaveValue("a");
expect(screen.queryByTestId("lane-file-edit")).toBeNull();
expect(screen.getByTestId("lane-file-save")).toBeDisabled();
expect(screen.getByRole("button", { name: "Cancel" })).toBeDisabled();
expect(await screen.findByTestId("lane-file-view")).toHaveTextContent("a");
expect(screen.queryByTestId("lane-file-editor")).toBeNull();
});
it("does not enter the editor when a click only ends a text selection", async () => {
vi.mocked(api.lanes.gitFile).mockResolvedValue({
available: true,
path: "server/lib/git-ops.js",
rev: "work",
binary: false,
truncated: false,
lines: ["copy me"],
sha: "b".repeat(40),
});
const user = userEvent.setup();
render(<LaneChangesPanel laneId={7} full />);
const list = await screen.findByTestId("lane-changes-overview");
await user.click(within(list).getByText("server/lib/git-ops.js"));
const view = await screen.findByTestId("lane-file-view");
const spy = vi.spyOn(window, "getSelection").mockReturnValue({
toString: () => "copy",
} as unknown as Selection);
await user.click(view);
spy.mockRestore();
expect(screen.queryByTestId("lane-file-editor")).toBeNull();
});
it("needs two clicks to discard, and only the second one reaches the server", async () => {
@@ -615,9 +641,7 @@ describe("LaneChangesPanel", () => {
await user.click(screen.getByRole("button", { name: "Files" }));
await user.type(await screen.findByLabelText("Find a file by path…"), "main");
await user.click(await screen.findByText("src/main.ts"));
await screen.findByTestId("lane-file-view");
await user.click(screen.getByTestId("lane-file-edit"));
await user.click(await screen.findByTestId("lane-file-view"));
const editor = await screen.findByTestId("lane-file-editor");
expect(editor).toHaveValue("const whole = 1;");
await user.clear(editor);
@@ -676,8 +700,7 @@ describe("LaneChangesPanel", () => {
await user.click(screen.getByRole("button", { name: "Files" }));
await user.type(await screen.findByLabelText("Find a file by path…"), "main");
await user.click(await screen.findByText("src/main.ts"));
await screen.findByTestId("lane-file-view");
await user.click(screen.getByTestId("lane-file-edit"));
await user.click(await screen.findByTestId("lane-file-view"));
await user.type(await screen.findByTestId("lane-file-editor"), "y");
await user.click(screen.getByTestId("lane-file-save"));
@@ -922,6 +945,59 @@ describe("LaneChangesPanel", () => {
expect(api.lanes.gitAction).toHaveBeenCalledWith(7, "stage-hunk", {
path: "server/lib/git-ops.js",
hunk: "@@ -9,2 +10,3 @@",
block: 0,
context: 3,
});
});
it("gives each +/- block inside ONE hunk its own bar and acts on that block only (#50)", async () => {
const user = userEvent.setup();
render(<LaneChangesPanel laneId={7} />);
await screen.findByTestId("lane-changes-overview");
vi.mocked(api.lanes.changes).mockResolvedValue(
changes({
files: [
{
path: "server/lib/git-ops.js",
status: " M",
untracked: false,
unstaged: true,
added: 2,
deleted: 1,
binary: false,
hunks: [
{
header: "@@ -1,4 +1,5 @@",
context: "",
oldStart: 1,
newStart: 1,
lines: [
{ type: "del" as const, oldLine: 1, newLine: null, text: "a" },
{ type: "add" as const, oldLine: null, newLine: 1, text: "A" },
{ type: "ctx" as const, oldLine: 2, newLine: 2, text: "b" },
{ type: "ctx" as const, oldLine: 3, newLine: 3, text: "c" },
{ type: "add" as const, oldLine: null, newLine: 4, text: "new" },
{ type: "ctx" as const, oldLine: 4, newLine: 5, text: "d" },
],
},
],
},
],
})
);
await user.click(screen.getByRole("button", { name: "Review" }));
await screen.findByTestId("lane-changes-review");
const bars = screen.getAllByTestId("lane-hunk-bar");
expect(bars.map((b) => b.textContent)).toEqual([
expect.stringContaining("1 of 2"),
expect.stringContaining("2 of 2"),
]);
await user.click(screen.getAllByRole("button", { name: "Stage this hunk" })[1]!);
expect(api.lanes.gitAction).toHaveBeenCalledWith(7, "stage-hunk", {
path: "server/lib/git-ops.js",
hunk: "@@ -1,4 +1,5 @@",
block: 1,
context: 3,
});
});
@@ -959,6 +1035,7 @@ describe("LaneChangesPanel", () => {
expect(api.lanes.gitAction).toHaveBeenCalledWith(7, "discard-hunk", {
path: "server/lib/git-ops.js",
hunk: "@@ -1,2 +1,3 @@",
block: 0,
context: 3,
confirm: true,
});
@@ -1308,6 +1385,27 @@ describe("a merge in progress (issue #45)", () => {
);
});
it("opens a conflicted file in the conflict view, not the diff", async () => {
vi.mocked(api.lanes.git).mockResolvedValue(merging(1));
vi.mocked(api.lanes.changes).mockResolvedValue(conflicted);
vi.mocked(api.lanes.gitFile).mockResolvedValue({
available: true,
path: "a.txt",
rev: "work",
lines: ["<<<<<<< HEAD", "mine", "=======", "theirs", ">>>>>>> feat"],
truncated: false,
binary: false,
sha: "s1",
} as never);
const user = userEvent.setup();
render(<LaneChangesPanel laneId={3} />);
await user.click(
within(await screen.findByTestId("lane-changes-conflicts")).getByText("a.txt")
);
expect(await screen.findByTestId("lane-conflict-view")).toHaveTextContent("Theirs (feat)");
expect(api.lanes.gitFile).toHaveBeenCalledWith(3, "a.txt", "work");
});
it("completes the merge once nothing is conflicted, and aborts only on a second click", async () => {
vi.mocked(api.lanes.git).mockResolvedValue(merging(0));
const user = userEvent.setup();
@@ -0,0 +1,130 @@
/**
* @file Tests for the merge-conflict view: both sides of each block shown
* under their own labels, one choice per block with undo, Save only once
* every block is chosen — and Save writes the chosen text over the version
* opened, then marks the file resolved. Whole-file ours/theirs reuse
* `resolve`.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { LaneConflictView } from "../LaneConflictView";
import { api } from "../../../lib/api";
vi.mock("../../../lib/api", () => ({
api: { lanes: { gitFile: vi.fn(), gitSaveFile: vi.fn(), gitAction: vi.fn() } },
}));
const LINES = [
"top",
"<<<<<<< HEAD",
"mine",
"=======",
"theirs",
">>>>>>> origin/main",
"middle",
"<<<<<<< HEAD",
"a",
"=======",
"b",
">>>>>>> origin/main",
];
beforeEach(() => {
vi.mocked(api.lanes.gitFile)
.mockReset()
.mockResolvedValue({
available: true,
path: "a.txt",
rev: "work",
lines: LINES,
truncated: false,
binary: false,
sha: "s1",
} as never);
vi.mocked(api.lanes.gitSaveFile)
.mockReset()
.mockResolvedValue({ available: true } as never);
vi.mocked(api.lanes.gitAction)
.mockReset()
.mockResolvedValue({ action: "resolve", ok: true, output: "" });
});
const blocks = () => screen.getAllByTestId("conflict-block");
describe("LaneConflictView", () => {
it("shows both sides under their labels and saves once every block is chosen", async () => {
const user = userEvent.setup();
const onResolved = vi.fn();
render(<LaneConflictView laneId={3} path="a.txt" onResolved={onResolved} onEdit={vi.fn()} />);
const [first, second] = (await screen.findAllByTestId("conflict-block")) as [
HTMLElement,
HTMLElement,
];
expect(first).toHaveTextContent("Mine (HEAD)");
expect(first).toHaveTextContent("Theirs (origin/main)");
const save = screen.getByRole("button", { name: "Save and mark resolved" });
expect(save).toBeDisabled();
await user.click(within(first).getByRole("button", { name: "Keep mine" }));
// Chosen: the block is plain text now, with an undo.
await user.click(within(blocks()[0]!).getByRole("button", { name: "Undo" }));
await user.click(within(blocks()[0]!).getByRole("button", { name: "Take theirs" }));
await user.click(within(second).getByRole("button", { name: "Keep both" }));
expect(save).toBeEnabled();
await user.click(save);
await waitFor(() =>
expect(api.lanes.gitSaveFile).toHaveBeenCalledWith(
3,
"a.txt",
"top\ntheirs\nmiddle\na\nb",
"s1"
)
);
await waitFor(() =>
expect(api.lanes.gitAction).toHaveBeenCalledWith(3, "resolve", {
path: "a.txt",
side: "done",
})
);
expect(onResolved).toHaveBeenCalled();
});
it("takes a whole side for the file through resolve", async () => {
const user = userEvent.setup();
const onResolved = vi.fn();
render(<LaneConflictView laneId={3} path="a.txt" onResolved={onResolved} onEdit={vi.fn()} />);
await screen.findAllByTestId("conflict-block");
await user.click(screen.getByRole("button", { name: "Take all theirs" }));
await waitFor(() =>
expect(api.lanes.gitAction).toHaveBeenCalledWith(3, "resolve", {
path: "a.txt",
side: "theirs",
})
);
expect(onResolved).toHaveBeenCalled();
expect(api.lanes.gitSaveFile).not.toHaveBeenCalled();
});
it("offers the plain editor when the markers do not balance", async () => {
vi.mocked(api.lanes.gitFile).mockResolvedValue({
available: true,
path: "a.txt",
rev: "work",
lines: ["<<<<<<< HEAD", "x"],
truncated: false,
binary: false,
sha: "s1",
} as never);
const user = userEvent.setup();
const onEdit = vi.fn();
render(<LaneConflictView laneId={3} path="a.txt" onResolved={vi.fn()} onEdit={onEdit} />);
await screen.findByText(/markers do not line up/);
await user.click(screen.getByRole("button", { name: "Edit by hand" }));
expect(onEdit).toHaveBeenCalled();
});
});
@@ -422,8 +422,8 @@ describe("LaneDiffView — hunk review bar navigation", () => {
Object.defineProperty(scroller, "scrollHeight", { value: 1000 });
Object.defineProperty(scroller, "clientHeight", { value: 100 });
scroller.getBoundingClientRect = () => ({ top: 0 }) as DOMRect;
for (const el of view.container.querySelectorAll<HTMLElement>("[data-hunk-index]")) {
const k = Number(el.dataset.hunkIndex);
for (const el of view.container.querySelectorAll<HTMLElement>("[data-change-index]")) {
const k = Number(el.dataset.changeIndex);
el.getBoundingClientRect = () => ({ top: k * 100 - scroller.scrollTop }) as DOMRect;
}
return scroller;
@@ -454,6 +454,49 @@ describe("LaneDiffView — hunk review bar navigation", () => {
expect(screen.getAllByRole("button", { name: "Next change" })[2]).toBeDisabled();
});
it("hangs one bar under EACH +/- block of a single hunk, in both layouts (#50)", () => {
const merged: LaneChangeFile = {
...FILE,
hunks: [
{
header: "@@ -1,6 +1,6 @@",
context: "",
oldStart: 1,
newStart: 1,
lines: [
{ type: "del" as const, oldLine: 1, newLine: null, text: "a" },
{ type: "add" as const, oldLine: null, newLine: 1, text: "A" },
{ type: "ctx" as const, oldLine: 2, newLine: 2, text: "b" },
{ type: "del" as const, oldLine: 3, newLine: null, text: "c" },
{ type: "ctx" as const, oldLine: 4, newLine: 3, text: "d" },
{ type: "add" as const, oldLine: null, newLine: 4, text: "E" },
{ type: "ctx" as const, oldLine: 5, newLine: 5, text: "f" },
],
},
],
};
const seen: number[] = [];
for (const layout of ["unified", "split"] as const) {
const { unmount } = render(
<LaneDiffView
file={merged}
layout={layout}
hunkActions={(c) => {
seen.push(c.block);
return <span />;
}}
/>
);
expect(screen.getAllByTestId("lane-hunk-bar").map((b) => b.textContent)).toEqual([
expect.stringContaining("1 of 3"),
expect.stringContaining("2 of 3"),
expect.stringContaining("3 of 3"),
]);
unmount();
}
expect(seen).toEqual([0, 1, 2, 0, 1, 2]);
});
it("leaves an unwindowed review diff uncapped, so the panel is its only scroller", () => {
render(<LaneDiffView file={three} layout="unified" />);
expect(screen.getByTestId("lane-diff-view").className).not.toContain("max-h-[60vh]");
@@ -44,6 +44,7 @@ import type {
CodexApproval,
} from "../../lib/api";
import type { Session, Lane, LaneTool } from "../../lib/types";
import { LANE_TOOL_LABEL } from "../../lib/types";
import { TerminalView } from "./TerminalView";
import { RunSetup } from "./RunSetup";
import { ActiveRunsSwitcher } from "./RunHistory";
@@ -149,7 +150,7 @@ export function LaneConsolePane({
: (externalSessions ?? []).filter((s) => s.cwd && owningLaneId(s.cwd, lanes) === laneId),
[externalSessions, laneId, lanes]
);
const toolLabel = laneTool === "codex" ? "Codex" : "Claude";
const toolLabel = LANE_TOOL_LABEL[laneTool];
useEffect(() => {
onHasActiveRunChange?.(handle !== null);
@@ -568,7 +569,12 @@ export function LaneConsolePane({
{binaryStatus && !binaryStatus[laneTool]?.found && (
<div className="rounded-lg border border-status-danger/40 bg-status-danger/10 px-4 py-3 text-sm text-status-danger flex items-center gap-2">
<AlertCircle className="w-4 h-4 flex-shrink-0" />
<span>{t("binary.missing", { cli: laneTool, tool: toolLabel })}</span>
<span>
{t("binary.missing", {
cli: laneTool === "antigravity" ? "agy" : laneTool,
tool: toolLabel,
})}
</span>
</div>
)}
+28 -22
View File
@@ -56,6 +56,7 @@ import type {
CcMdItem,
} from "../../lib/api";
import type { Session, LaneTool } from "../../lib/types";
import { LANE_TOOL_LABEL } from "../../lib/types";
import { Select } from "../Select";
export interface SlashCommand {
@@ -430,10 +431,13 @@ export function RunSetup(props: RunSetupProps) {
</div>
)}
</Field>
<Field label={t("fields.model")}>
<ModelPicker value={props.model} onChange={props.onModelChange} tool={props.tool} />
</Field>
{props.tool === "codex" ? (
{/* `agy` takes no model, permission or effort flag. */}
{props.tool !== "antigravity" && (
<Field label={t("fields.model")}>
<ModelPicker value={props.model} onChange={props.onModelChange} tool={props.tool} />
</Field>
)}
{props.tool === "antigravity" ? null : props.tool === "codex" ? (
<>
<Field label={t("fields.sandbox")}>
<Select<CodexSandbox>
@@ -472,17 +476,19 @@ export function RunSetup(props: RunSetupProps) {
/>
</Field>
)}
<Field label={t("fields.effort")}>
<Select<EffortLevel>
value={props.effort}
onChange={props.onEffortChange}
options={RUN_EFFORT_CHOICES.map((c) => ({
value: c.id,
label: c.label,
hint: c.hint,
}))}
/>
</Field>
{props.tool !== "antigravity" && (
<Field label={t("fields.effort")}>
<Select<EffortLevel>
value={props.effort}
onChange={props.onEffortChange}
options={RUN_EFFORT_CHOICES.map((c) => ({
value: c.id,
label: c.label,
hint: c.hint,
}))}
/>
</Field>
)}
</div>
<div className="flex shrink-0 items-center rounded-md border border-border bg-surface-2 p-0.5 text-[11.5px]">
<Seg
@@ -542,9 +548,9 @@ export function RunSetup(props: RunSetupProps) {
value={props.prompt}
onChange={props.onPromptChange}
onSubmit={() => handleStart(props)}
placeholder={t("fields.promptPlaceholderTerminal")}
placeholder={t("fields.promptPlaceholderTerminal", { tool: LANE_TOOL_LABEL[props.tool] })}
rows={5}
slash={props.tool !== "codex"}
slash={props.tool === "claude"}
fileCwd={props.resumeSession?.cwd || props.cwd}
/>
<div className="mt-1 text-[10px] text-fg-muted">
@@ -609,18 +615,18 @@ export function RunSetup(props: RunSetupProps) {
function handleStart(props: RunSetupProps, session?: Session) {
const resume = session ?? props.resumeSession;
const codex = props.tool === "codex";
const agy = props.tool === "antigravity";
props.onStart({
laneId: props.laneId,
// A resume is pinned to its own session's folder — that's what the locked
// cwd field shows, so it's what gets sent.
cwd: resume?.cwd || props.cwd || undefined,
model: props.model || undefined,
permissionMode: codex ? undefined : props.permissionMode || undefined,
model: agy ? undefined : props.model || undefined,
permissionMode: codex || agy ? undefined : props.permissionMode || undefined,
sandbox: codex ? props.sandbox : undefined,
approval: codex ? props.approval : undefined,
effort: props.effort || undefined,
resumeSessionId: codex ? undefined : resume?.id || undefined,
resumeLast: codex && !resume ? true : undefined,
effort: agy ? undefined : props.effort || undefined,
resumeSessionId: codex || agy ? undefined : resume?.id || undefined,
// A resume continues a session that already has its own history — sending
// whatever is sitting in the prompt box would fire an extra turn nobody
// asked for, so a resume carries no prompt at all.
@@ -84,6 +84,7 @@ function baseProps() {
binaryStatus: {
claude: { found: true, path: "/usr/local/bin/claude" },
codex: { found: true, path: "/usr/local/bin/codex" },
antigravity: { found: true, path: "/usr/local/bin/agy" },
},
cwdSuggestions: [],
activeRuns: { items: [] },
@@ -380,7 +380,7 @@ describe("RunSetup — per-tool fields", () => {
});
describe("RunSetup — / and @ suggestions in the prompt box", () => {
const box = () => screen.getByPlaceholderText(i18n.t("run:fields.promptPlaceholderTerminal"));
const box = () => screen.getByPlaceholderText(/ anything…$/);
it("lists the lane's commands, skills and the CLI built-ins on /, and Enter picks one", async () => {
const { spies } = renderSetup({ prompt: "" });
@@ -423,3 +423,26 @@ describe("RunSetup — / and @ suggestions in the prompt box", () => {
expect(api.ccConfig.commands).not.toHaveBeenCalled();
});
});
describe("RunSetup — antigravity lanes", () => {
it("names the lane's CLI in the prompt box and drops the flags `agy` lacks", () => {
const { spies } = renderSetup({ tool: "antigravity", model: "opus", effort: "high" });
expect(screen.getByPlaceholderText("Ask Antigravity anything…")).toBeTruthy();
expect(screen.queryByText(i18n.t("run:fields.model"))).toBeNull();
expect(screen.queryByText(i18n.t("run:fields.effort"))).toBeNull();
fireEvent.click(screen.getByText(i18n.t("run:actions.start")));
expect(spies.onStart).toHaveBeenCalledWith(
expect.objectContaining({ model: undefined, effort: undefined, permissionMode: undefined })
);
});
});
describe("RunSetup — codex lanes", () => {
it("starts a fresh codex run instead of resuming the last one", () => {
const { spies } = renderSetup({ tool: "codex" });
fireEvent.click(screen.getByText(i18n.t("run:actions.start")));
expect(spies.onStart).toHaveBeenCalledOnce();
expect(spies.onStart.mock.calls[0][0].resumeLast).toBeUndefined();
});
});
+24 -4
View File
@@ -7,8 +7,6 @@
"action.stop": "stop",
"actionError": "Lane action failed: {{message}}",
"actionErrorUnknown": "Unknown error",
"actions.agentsInstall": "Install agents",
"actions.agentsInstallResult": "Installed: {{files}}",
"actions.busy": "…",
"actions.mcpSync": "Sync MCP",
"actions.mcpSyncResult": "Synced: {{servers}}",
@@ -49,7 +47,6 @@
"addLaneRouterLoading": "Loading router profiles…",
"addLaneRouterNative": "Native",
"addLaneRouterProfileLabel": "Router profile",
"addLaneSetupAgents": "Agents",
"addLaneSetupClose": "Close",
"addLaneSetupMcp": "MCP servers",
"addLaneSetupProfile": "Profile",
@@ -59,6 +56,7 @@
"addLaneTitlePlaceholder": "Optional",
"addLaneToolClaude": "Claude Code",
"addLaneToolCodex": "Codex",
"addLaneToolAntigravity": "Antigravity",
"addLaneToolHint": "Which CLI drives this lane. Cannot be changed later.",
"addLaneWorktreeDetached": "(detached)",
"addLaneWorktreesMore": "+{{count}} more",
@@ -256,6 +254,7 @@
"changes.edit": "Edit",
"changes.save": "Save",
"changes.cancelEdit": "Cancel",
"changes.clickToEdit": "Click the text to edit",
"changes.editorLabel": "Edit {{path}}",
"changes.prevHunk": "Previous change",
"changes.nextHunk": "Next change",
@@ -287,5 +286,26 @@
"changes.mergeAbortConfirm": "Click again to abort the merge",
"changes.takeOurs": "Keep mine",
"changes.takeTheirs": "Take theirs",
"changes.markResolved": "Mark resolved (after editing out the markers)"
"changes.markResolved": "Mark resolved (after editing out the markers)",
"conflict.left": "{{left}} of {{total}} conflicts left",
"conflict.prev": "Previous conflict",
"conflict.next": "Next conflict",
"conflict.allOurs": "Keep all mine",
"conflict.allTheirs": "Take all theirs",
"conflict.editByHand": "Edit by hand",
"conflict.unbalanced": "The conflict markers do not line up (edited by hand?) — use Edit by hand.",
"conflict.unusable": "This file cannot be shown here (binary or too large) — use Keep all mine / Take all theirs, or a terminal.",
"conflict.keepOurs": "Keep mine",
"conflict.takeTheirs": "Take theirs",
"conflict.keepBoth": "Keep both",
"conflict.chose.ours": "Kept mine",
"conflict.chose.theirs": "Took theirs",
"conflict.chose.both": "Kept both",
"conflict.undo": "Undo",
"conflict.ours": "Mine ({{label}})",
"conflict.theirs": "Theirs ({{label}})",
"conflict.reset": "Cancel",
"conflict.save": "Save and mark resolved",
"changes.takeOursHint": "Keep your version of the whole file",
"changes.takeTheirsHint": "Take the incoming version of the whole file"
}
+1 -1
View File
@@ -81,7 +81,7 @@
"permissionPlan": "plan (read-only planning)",
"prompt": "Prompt",
"promptPlaceholder": "Ask Claude anything…",
"promptPlaceholderTerminal": "Ask Claude anything…",
"promptPlaceholderTerminal": "Ask {{tool}} anything…",
"sandbox": "Sandbox",
"sandboxFullAccess": "Full access (dangerous)",
"sandboxReadOnly": "Read only",
+1 -3
View File
@@ -63,9 +63,7 @@
},
"lanesSection": {
"title": "Lanes",
"description": "Machine-wide housekeeping and one-time setup for the ship-feature-lane pipeline.",
"installSkill": "Install ship-feature-lane skill",
"installSkillSuccess": "Installed to {{path}}",
"description": "Machine-wide lane housekeeping.",
"runHousekeeping": "Run housekeeping",
"dryRun": "Dry run",
"gcResult": "Reaped {{reaped}} process(es), capped {{capped}} log(s)"
+24 -4
View File
@@ -7,8 +7,6 @@
"action.stop": "Dừng",
"actionError": "Thao tác làn đường thất bại: {{message}}",
"actionErrorUnknown": "Lỗi không xác định",
"actions.agentsInstall": "Cài agent",
"actions.agentsInstallResult": "Đã cài: {{files}}",
"actions.busy": "…",
"actions.mcpSync": "Đồng bộ MCP",
"actions.mcpSyncResult": "Đã đồng bộ: {{servers}}",
@@ -49,7 +47,6 @@
"addLaneRouterLoading": "Đang tải danh sách router…",
"addLaneRouterNative": "Native",
"addLaneRouterProfileLabel": "Profile router",
"addLaneSetupAgents": "Agent",
"addLaneSetupClose": "Đóng",
"addLaneSetupMcp": "MCP server",
"addLaneSetupProfile": "Profile",
@@ -59,6 +56,7 @@
"addLaneTitlePlaceholder": "Không bắt buộc",
"addLaneToolClaude": "Claude Code",
"addLaneToolCodex": "Codex",
"addLaneToolAntigravity": "Antigravity",
"addLaneToolHint": "CLI nào điều khiển lane này. Không thể thay đổi sau này.",
"addLaneWorktreeDetached": "(detached)",
"addLaneWorktreesMore": "+{{count}} nữa",
@@ -256,6 +254,7 @@
"changes.edit": "Sửa",
"changes.save": "Lưu",
"changes.cancelEdit": "Huỷ",
"changes.clickToEdit": "Bấm vào nội dung để sửa",
"changes.editorLabel": "Sửa {{path}}",
"changes.prevHunk": "Thay đổi trước",
"changes.nextHunk": "Thay đổi sau",
@@ -287,5 +286,26 @@
"changes.mergeAbortConfirm": "Bấm lần nữa để huỷ merge",
"changes.takeOurs": "Giữ bản của mình",
"changes.takeTheirs": "Lấy bản kia",
"changes.markResolved": "Đánh dấu đã xong (sau khi đã sửa hết dấu conflict)"
"changes.markResolved": "Đánh dấu đã xong (sau khi đã sửa hết dấu conflict)",
"conflict.left": "Còn {{left}}/{{total}} khối conflict",
"conflict.prev": "Khối trước",
"conflict.next": "Khối sau",
"conflict.allOurs": "Giữ hết của mình",
"conflict.allTheirs": "Lấy hết bản kia",
"conflict.editByHand": "Sửa tay",
"conflict.unbalanced": "Dấu conflict không khớp nhau (đã sửa tay?) - hãy dùng Sửa tay.",
"conflict.unusable": "Không hiển thị được file này ở đây (nhị phân hoặc quá lớn) - hãy dùng Giữ hết của mình / Lấy hết bản kia, hoặc terminal.",
"conflict.keepOurs": "Giữ của mình",
"conflict.takeTheirs": "Lấy bản kia",
"conflict.keepBoth": "Giữ cả hai",
"conflict.chose.ours": "Đã giữ của mình",
"conflict.chose.theirs": "Đã lấy bản kia",
"conflict.chose.both": "Đã giữ cả hai",
"conflict.undo": "Hoàn tác",
"conflict.ours": "Của mình ({{label}})",
"conflict.theirs": "Bản kia ({{label}})",
"conflict.reset": "Huỷ",
"conflict.save": "Lưu và đánh dấu đã xong",
"changes.takeOursHint": "Giữ bản của mình cho cả file",
"changes.takeTheirsHint": "Lấy bản kia cho cả file"
}
+1 -1
View File
@@ -80,7 +80,7 @@
"permissionPlan": "plan (chỉ đọc, lập kế hoạch)",
"prompt": "Prompt",
"promptPlaceholder": "Hỏi Claude bất cứ điều gì…",
"promptPlaceholderTerminal": "Hỏi Claude bất cứ điều gì…",
"promptPlaceholderTerminal": "Hỏi {{tool}} bất cứ điều gì…",
"sandbox": "Sandbox",
"sandboxFullAccess": "Truy cập đầy đủ (nguy hiểm)",
"sandboxReadOnly": "Chỉ đọc",
+1 -3
View File
@@ -63,9 +63,7 @@
},
"lanesSection": {
"title": "Lanes",
"description": "Bảo trì toàn máy và cài đặt một lần cho pipeline ship-feature-lane.",
"installSkill": "Cài skill ship-feature-lane",
"installSkillSuccess": "Đã cài vào {{path}}",
"description": "Dọn dẹp lane trên toàn máy.",
"runHousekeeping": "Chạy dọn dẹp",
"dryRun": "Chạy thử (dry run)",
"gcResult": "Đã dọn {{reaped}} tiến trình, cắt {{capped}} log"
@@ -0,0 +1,74 @@
/**
* @file Tests for the merge-conflict parser behind the Changes panel's
* conflict view: plain and diff3 blocks, the two side labels, applying a
* choice per block, and refusing a file whose markers do not balance.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect } from "vitest";
import { parseConflicts, applyChoices } from "../conflicts";
const FILE = [
"top",
"<<<<<<< HEAD",
"mine 1",
"mine 2",
"=======",
"theirs 1",
">>>>>>> origin/main",
"middle",
"<<<<<<< HEAD",
"a",
"||||||| base",
"old",
"=======",
"b",
">>>>>>> feat",
"end",
];
describe("parseConflicts", () => {
it("splits text from conflict blocks and reads both labels", () => {
const parts = parseConflicts(FILE)!;
expect(parts.map((p) => p.kind)).toEqual(["text", "conflict", "text", "conflict", "text"]);
expect(parts[1]).toMatchObject({
ours: ["mine 1", "mine 2"],
theirs: ["theirs 1"],
oursLabel: "HEAD",
theirsLabel: "origin/main",
});
// diff3: the base section is not either side.
expect(parts[3]).toMatchObject({ ours: ["a"], theirs: ["b"], theirsLabel: "feat" });
});
it("returns an empty list of blocks for a file without markers", () => {
expect(parseConflicts(["a", "b"])).toEqual([{ kind: "text", lines: ["a", "b"] }]);
});
it("refuses markers that do not balance", () => {
expect(parseConflicts(["<<<<<<< HEAD", "x", "======="])).toBeNull();
expect(parseConflicts(["x", ">>>>>>> feat"])).toBeNull();
});
});
describe("applyChoices", () => {
it("writes each block as the chosen side, both sides in order for 'both'", () => {
const parts = parseConflicts(FILE)!;
expect(applyChoices(parts, ["ours", "both"])).toEqual([
"top",
"mine 1",
"mine 2",
"middle",
"a",
"b",
"end",
]);
expect(applyChoices(parts, ["theirs", "theirs"])).toEqual([
"top",
"theirs 1",
"middle",
"b",
"end",
]);
});
});
+2 -7
View File
@@ -1130,8 +1130,6 @@ export const api = {
purged_events: number;
purged_agents: number;
}>("/settings/cleanup", { method: "POST", body: JSON.stringify(params) }),
skillsInstall: () =>
request<{ installed: true; path: string }>("/skills/install", { method: "POST", body: "{}" }),
gc: (body: { dryRun?: boolean } = {}) =>
request<{ reaped: number[]; capped: { path: string; sizeBefore: number }[] }>("/lanes/gc", {
method: "POST",
@@ -2572,6 +2570,8 @@ export const api = {
paths?: string[];
path?: string;
hunk?: string;
/** One change block (a run of +/- lines) inside `hunk`, by index. */
block?: number;
context?: number;
confirm?: boolean;
/** resolve: which side wins, or `done` for a hand-edited file. */
@@ -2717,11 +2717,6 @@ export const api = {
body: JSON.stringify(body),
}),
},
agentsInstall: (id: number) =>
request<{ installed: string[] }>(`/lanes/${id}/agents/install`, {
method: "POST",
body: "{}",
}),
/**
* POST /lanes/:id/router/apply - point this lane at an AI Router profile,
* or back at `native`. Writes the lane's own config on disk; only the
+87
View File
@@ -0,0 +1,87 @@
/**
* @file Parses git's merge-conflict markers out of a file's lines, and writes
* the file back with one side (or both) chosen per block — the model behind
* the Changes panel's conflict view. Handles diff3 style (`|||||||` base
* section, dropped: it is neither side). Pure, no React.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
export type ConflictChoice = "ours" | "theirs" | "both";
export type ConflictPart =
| { kind: "text"; lines: string[] }
| { kind: "conflict"; ours: string[]; theirs: string[]; oursLabel: string; theirsLabel: string };
const OPEN = /^<{7}(?: (.*))?$/;
const BASE = /^\|{7}(?: .*)?$/;
const MID = /^={7}$/;
const CLOSE = /^>{7}(?: (.*))?$/;
/**
* The file as text runs and conflict blocks, or null when its markers do not
* balance (a hand edit left half a block) — the caller falls back to the
* plain editor then rather than guess.
*/
export function parseConflicts(lines: string[]): ConflictPart[] | null {
const parts: ConflictPart[] = [];
let text: string[] = [];
let block: { ours: string[]; theirs: string[]; oursLabel: string } | null = null;
let section: "ours" | "base" | "theirs" = "ours";
for (const line of lines) {
if (!block) {
const open = line.match(OPEN);
if (open) {
if (text.length) parts.push({ kind: "text", lines: text });
text = [];
block = { ours: [], theirs: [], oursLabel: open[1] ?? "" };
section = "ours";
} else if (CLOSE.test(line) || MID.test(line)) {
return null;
} else {
text.push(line);
}
continue;
}
if (section === "ours" && BASE.test(line)) section = "base";
else if (section !== "theirs" && MID.test(line)) section = "theirs";
else if (section === "theirs" && CLOSE.test(line)) {
const close = line.match(CLOSE)!;
parts.push({ kind: "conflict", ...block, theirsLabel: close[1] ?? "" });
block = null;
} else if (OPEN.test(line)) return null;
else if (section === "ours") block.ours.push(line);
else if (section === "theirs") block.theirs.push(line);
}
if (block) return null;
if (text.length || !parts.length) parts.push({ kind: "text", lines: text });
return parts;
}
/** The file's lines with block `i` replaced by `choices[i]`; an unchosen block keeps its markers. */
export function applyChoices(
parts: ConflictPart[],
choices: (ConflictChoice | undefined)[]
): string[] {
const out: string[] = [];
let i = 0;
for (const p of parts) {
if (p.kind === "text") {
out.push(...p.lines);
continue;
}
const c = choices[i++];
if (c === "ours") out.push(...p.ours);
else if (c === "theirs") out.push(...p.theirs);
else if (c === "both") out.push(...p.ours, ...p.theirs);
else
out.push(
`<<<<<<< ${p.oursLabel}`.trimEnd(),
...p.ours,
"=======",
...p.theirs,
`>>>>>>> ${p.theirsLabel}`.trimEnd()
);
}
return out;
}
+8 -1
View File
@@ -2410,7 +2410,14 @@ export interface ProofFeature {
}
/** Which CLI drives a lane's pane. Fixed at lane creation and never patched. */
export type LaneTool = "claude" | "codex";
export type LaneTool = "claude" | "codex" | "antigravity";
/** How each CLI is named on screen (strip tag, console title, prompt box). */
export const LANE_TOOL_LABEL: Record<LaneTool, string> = {
claude: "Claude",
codex: "Codex",
antigravity: "Antigravity",
};
export interface Lane {
id: number;
-23
View File
@@ -699,12 +699,6 @@ export function Settings() {
return res.ok ? t("hooks.success") : t("hooks.failed");
});
const handleSkillsInstall = () =>
runAction("skills-install", async () => {
const res = await api.settings.skillsInstall();
return t("lanesSection.installSkillSuccess", { path: res.path });
});
const handleGc = () =>
runAction("gc", async () => {
const res = await api.settings.gc({ dryRun: gcDryRun });
@@ -1354,23 +1348,6 @@ export function Settings() {
<p className="text-xs text-fg-muted mb-4">{t("lanesSection.description")}</p>
<div className="card p-5 space-y-4">
<div className="flex items-center justify-between flex-wrap gap-3">
<span className="text-xs text-fg-secondary">{t("lanesSection.installSkill")}</span>
<button
onClick={handleSkillsInstall}
disabled={actionLoading !== null}
className="btn-ghost text-xs disabled:opacity-50"
>
{actionLoading === "skills-install" ? (
<RefreshCw className="w-3.5 h-3.5 animate-spin" />
) : (
<RotateCcw className="w-3.5 h-3.5" />
)}
{t("lanesSection.installSkill")}
</button>
</div>
{actionBanner(["skills-install"])}
<div className="flex items-center justify-between flex-wrap gap-3">
<label className="flex items-center gap-2 text-xs text-fg-secondary">
<input
+63 -43
View File
@@ -395,8 +395,8 @@ export function Workspace() {
}, [lanes, searchParams, setSearchParams]);
useEffect(() => {
Promise.all([api.run.binary("claude"), api.run.binary("codex")])
.then(([claude, codex]) => setBinaryStatus({ claude, codex }))
Promise.all([api.run.binary("claude"), api.run.binary("codex"), api.run.binary("antigravity")])
.then(([claude, codex, antigravity]) => setBinaryStatus({ claude, codex, antigravity }))
// Fetch failure (server unreachable, proxy misrouted, etc.) isn't proof
// `claude` or `codex` is missing from PATH — leave the probe unresolved rather than
// showing a misleading "binary missing" banner for an unrelated fault.
@@ -523,6 +523,10 @@ export function Workspace() {
}, [refreshList]);
const currentLane = selectedLaneId !== null ? lanes.find((l) => l.id === selectedLaneId) : null;
// Only claude lanes carry a pipeline (codex and antigravity emit no hooks),
// and only while a template is installed — none ships, so it is dormant.
const noPipeline =
!!currentLane && (currentLane.tool !== "claude" || currentLane.pipeline_nodes.length === 0);
// Feature list follows the selected lane, resets the viewer on lane switch.
useEffect(() => {
@@ -815,40 +819,54 @@ export function Workspace() {
<Pencil className="h-3 w-3 shrink-0 text-fg-muted opacity-0 transition-opacity group-hover:opacity-100" />
</button>
)}
<span className="shrink-0 tabular-nums text-xs text-fg-muted">
{since(currentLane.stage_seconds)}
</span>
{/* A lane with no pipeline (non-claude, or no template
installed): no time-at-stage, no pipeline or feature
picker, no map. */}
{!noPipeline && (
<span className="shrink-0 tabular-nums text-xs text-fg-muted">
{since(currentLane.stage_seconds)}
</span>
)}
{showInfo && (
<>
<select
data-testid="pipeline-picker"
aria-label={tLanes("pipelinePicker.label")}
className="rounded border border-border bg-surface-1 px-2 py-0.5 text-xs text-fg-secondary disabled:opacity-60"
value={currentLane.pipeline}
disabled={!!viewedFeature}
title={
viewedFeature
? tLanes("features.viewingArchived", { slug: viewedFeature.slug })
: undefined
}
onChange={(e) => void handlePipelineChange(currentLane.id, e.target.value)}
>
{(pipelineTemplates.length
? pipelineTemplates
: [{ id: currentLane.pipeline, name: currentLane.pipeline_name, nodes: [] }]
).map((p) => (
<option key={p.id} value={p.id}>
{p.nodes.length ? `${p.name} (${p.nodes.length})` : p.name}
</option>
))}
</select>
<LaneRouterRow lane={currentLane} />
{!noPipeline && (
<select
data-testid="pipeline-picker"
aria-label={tLanes("pipelinePicker.label")}
className="rounded border border-border bg-surface-1 px-2 py-0.5 text-xs text-fg-secondary disabled:opacity-60"
value={currentLane.pipeline}
disabled={!!viewedFeature}
title={
viewedFeature
? tLanes("features.viewingArchived", { slug: viewedFeature.slug })
: undefined
}
onChange={(e) => void handlePipelineChange(currentLane.id, e.target.value)}
>
{(pipelineTemplates.length
? pipelineTemplates
: [
{
id: currentLane.pipeline,
name: currentLane.pipeline_name,
nodes: [],
},
]
).map((p) => (
<option key={p.id} value={p.id}>
{p.nodes.length ? `${p.name} (${p.nodes.length})` : p.name}
</option>
))}
</select>
)}
{/* `agy` has no endpoint to point at a router. */}
{currentLane.tool !== "antigravity" && <LaneRouterRow lane={currentLane} />}
{/* No stage chip and no "auto: <stage>" chip here: the
PipelineMap right below this header already draws both
— the declared node as the current ring, the detected
one as its amber badge — so the chips were a second,
smaller copy of the same two facts. */}
{features.length > 0 && (
{!noPipeline && features.length > 0 && (
<select
data-testid="feature-picker"
className="rounded border border-border bg-surface-1 px-2 py-0.5 text-xs"
@@ -867,7 +885,7 @@ export function Workspace() {
</>
)}
<div className="ml-auto flex items-center gap-2">
{/* Per-lane actions (agents install, mcp sync, sync-base check)
{/* Per-lane actions (mcp sync, sync-base check)
belong beside the lane they act on, not in a page header. */}
<LaneToolsMenu lane={currentLane} />
<button
@@ -908,19 +926,21 @@ export function Workspace() {
onSelectLane={setSelectedLaneId}
/>
</div>
<div className="mb-3">
<PipelineMap
nodes={
viewedFeature ? viewedFeature.pipeline_nodes : currentLane.pipeline_nodes
}
detectedSignal={viewedFeature ? undefined : currentLane.detected_signal}
/>
{viewedFeature && (
<p data-testid="feature-viewer-banner" className="mb-2 text-xs text-fg-muted">
{tLanes("features.viewingArchived", { slug: viewedFeature.slug })}
</p>
)}
</div>
{!noPipeline && (
<div className="mb-3">
<PipelineMap
nodes={
viewedFeature ? viewedFeature.pipeline_nodes : currentLane.pipeline_nodes
}
detectedSignal={viewedFeature ? undefined : currentLane.detected_signal}
/>
{viewedFeature && (
<p data-testid="feature-viewer-banner" className="mb-2 text-xs text-fg-muted">
{tLanes("features.viewingArchived", { slug: viewedFeature.slug })}
</p>
)}
</div>
)}
{proofFeature &&
(Object.keys(proofFeature.groups).length > 0 || proofFeature.ticket_report) && (
<div data-testid="proof-gallery" className="mt-2">
@@ -8435,44 +8435,11 @@ exports[`screen snapshots > Settings 1`] = `
<p
class="text-xs text-fg-muted mb-4"
>
Machine-wide housekeeping and one-time setup for the ship-feature-lane pipeline.
Machine-wide lane housekeeping.
</p>
<div
class="card p-5 space-y-4"
>
<div
class="flex items-center justify-between flex-wrap gap-3"
>
<span
class="text-xs text-fg-secondary"
>
Install ship-feature-lane skill
</span>
<button
class="btn-ghost text-xs disabled:opacity-50"
>
<svg
class="lucide lucide-rotate-ccw w-3.5 h-3.5"
fill="none"
height="24"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"
/>
<path
d="M3 3v5h5"
/>
</svg>
Install ship-feature-lane skill
</button>
</div>
<div
class="flex items-center justify-between flex-wrap gap-3"
>
@@ -10364,7 +10331,7 @@ exports[`screen snapshots > Settings 1`] = `
<p
class="text-[10px] text-status-warning/90 mt-1"
>
UI build v1.8.9 (rebuild client to match)
UI build v1.8.12 (rebuild client to match)
</p>
</div>
<div
+16 -8
View File
@@ -135,7 +135,7 @@ POST /api/lanes/ensure
```
```json
{ "cwd": "/absolute/path/to/work", "title": "App package", "pipeline": "ship-feature", "tool": "codex" }
{ "cwd": "/absolute/path/to/work", "title": "App package", "pipeline": "default", "tool": "codex" }
```
`cwd` is optional — when missing or empty the server falls back to
@@ -192,14 +192,22 @@ slugified from its title once, at creation.
`pipeline` is patchable, which is how a lane moves between templates after
creation (`agenthub lanes pipeline <template-id>`). An id no template defines is
rejected with `400 EBADPIPELINE` rather than stored: `getPipeline` falls back
to the default template when READING, so an unvalidated write would be
rejected with `400 EBADPIPELINE` rather than stored (`default` is always
accepted): `getPipeline` falls back to the default template when READING, so an unvalidated write would be
accepted and then silently render the wrong map forever. Same 400 treatment as
`EBADKIND`. Switching a template re-resolves the lane's existing declared
`stage` string against the new node list — a stage the old template knew may
resolve to nothing in the new one, leaving `progress: 0` and no `current` node
until the next `agenthub stage`.
**Pipelines are dormant until a template is installed.** AgentHub ships no
pipeline template; templates come only from `DASHBOARD_PIPELINES_DIR` (see
`docs/LANES.md#custom-pipeline-templates`). With none installed, every lane is
on an empty `default` pipeline (`pipeline_nodes: []`, `progress: 0`),
`GET /api/lanes/pipelines` returns `{ "pipelines": [] }`, and
`POST /api/lanes/:id/stage` answers
`400 { "error": { "code": "ENOPIPELINE", "message": "no pipeline template is installed, so this lane has no stages to declare (drop a template into DASHBOARD_PIPELINES_DIR to turn stages on)", "stages": [] } }`.
#### Provision a managed worktree
```http
@@ -586,8 +594,8 @@ cannot collide on `index.lock`.
| `stage` | `git add -- <paths>` | `{"paths": ["..."]}` |
| `unstage` | `git restore --staged -- <paths>` (a staged rename also passes its original path, so both halves unstage) | `{"paths": ["..."]}` |
| `discard` | `git restore --source=HEAD --staged --worktree` (tracked) / `git clean -fd` (untracked) | `{"paths": ["..."], "confirm": true}` |
| `stage-hunk` | `git apply --cached` of ONE hunk of `git diff -U<context> HEAD -- <path>` | `{"path": "...", "hunk": "@@ -1,2 +1,3 @@", "context": 3}` |
| `discard-hunk` | `git apply -R` of that one hunk, off the working tree | `{"path": "...", "hunk": "@@ ... @@", "context": 3, "confirm": true}` |
| `stage-hunk` | `git apply --cached` of ONE hunk of `git diff -U<context> HEAD -- <path>` — or, with `block`, of only that hunk's `block`-th run of +/- lines (the other runs folded into context, as an edited `git add -p` hunk) | `{"path": "...", "hunk": "@@ -1,2 +1,3 @@", "block": 0, "context": 3}` |
| `discard-hunk` | `git apply -R` of that one hunk (or that one `block` of it), off the working tree | `{"path": "...", "hunk": "@@ ... @@", "block": 0, "context": 3, "confirm": true}` |
| `commit` | `git add -A` then `git commit -m <message>`, or the index as it stands with `only: "staged"` | `{"message": "...", "only": "staged"}` |
| `switch` | `git switch [-c] <branch>` | `{"branch": "...", "create": false}` |
| `branch-create` | `git branch <branch> [<base>]` — never switches | `{"branch": "...", "base": "..."}` |
@@ -1038,7 +1046,7 @@ every number. `status` filters by session lifecycle, same convention as
```json
{
"skills": [
{ "name": "agenthub:ship-feature", "plugin": "agenthub", "count": 12, "sessions": 5 },
{ "name": "agenthub:repo-onboarding", "plugin": "agenthub", "count": 12, "sessions": 5 },
{ "name": "daily-report", "plugin": null, "count": 3, "sessions": 3 }
],
"plugins": [
@@ -2061,7 +2069,7 @@ The `/api/run/*` namespace starts and manages `claude` subprocesses in tmux-back
```http
GET /api/run List all live runs (computed fresh from tmux state)
GET /api/run/tmux { available: bool } — whether tmux is on PATH
GET /api/run/binary?tool= { found, path } for the `claude` or `codex` binary
GET /api/run/binary?tool= { found, path } for the `claude`, `codex` or `agy` binary
GET /api/run/cwds Suggested cwds (dashboard, home, recent)
GET /api/run/history?limit=&laneId= Persisted run history; laneId narrows to one lane's runs
GET /api/run/files?cwd=&q= Fuzzy file search inside cwd for the @-file autocomplete
@@ -2074,7 +2082,7 @@ DELETE /api/run/:id Kill (SIGTERM → SIGKILL after 5 s)
`:id` must be a lane pane name, `agenthub-lane-<n>`; anything else answers 404 without reaching tmux, so these two routes can never touch a tmux session the dashboard did not start.
**`GET /api/run/binary`:** Probes for the binary (`claude` or `codex`). Optional query parameter `?tool=codex` probes for Codex; omitted or `?tool=claude` probes for Claude. Returns `{ found: bool, path: string | null }`.
**`GET /api/run/binary`:** Probes for the binary (`claude`, `codex` or `agy`). Optional query parameter `?tool=codex` probes for Codex and `?tool=antigravity` for Antigravity's `agy`; omitted or `?tool=claude` probes for Claude. Returns `{ found: bool, path: string | null }`.
**`POST /api/run` (start/attach):** Requires `laneId` (the lane this run belongs to). Creates or attaches an existing tmux session named `agenthub-lane-<id>` in the lane's working directory. If that session already exists and its pane is idling at a shell prompt, the appropriate command line (including `--resume` and any initial prompt) is typed into that pane instead of being dropped; if the pane is running a program, the request adopts the session unchanged. Optionally accepts `initialPrompt` to immediately type/send into the session (if empty or omitted, the session is created/attached with no initial input). Returns `{ id, laneId, status, cwd, model, permissionMode, effort, resumeSessionId, sessionId, startedAt, promptPreview }` where `id` is the tmux session name. The dashboard self-heals a lane's `run_id`/`status` on every read if the tmux session has been killed externally.
+2 -7
View File
@@ -235,19 +235,14 @@ A lane is a durable unit of parallel agent work — one working directory, many
| `agenthub lanes add --cwd <path> --title <text>` | Adopt an existing directory as a lane |
| `agenthub lanes add --repo <path> [--title <text>] [--base <branch>] [--slug <slug>]` | Provision a dashboard-managed git worktree as a new lane |
| `agenthub lanes profile init <repo> [--force]` | Detect a Node.js project (single-service or backend+frontend monorepo) and scaffold `.agenthub/profile/`. Refuses to overwrite an existing one without `--force` |
| `agenthub lanes pipeline [<template-id>] [<id>]` | Show which pipeline template a lane renders against, plus the available templates and their node counts; pass a template id to switch. An unknown id is refused (`400 EBADPIPELINE`), and a switch that leaves the lane's current stage unresolvable warns |
| `agenthub lanes pipeline [<template-id>] [<id>]` | Show which pipeline template a lane renders against, plus the available templates and their node counts (none until you install one in `DASHBOARD_PIPELINES_DIR`); pass a template id to switch. An unknown id is refused (`400 EBADPIPELINE`), and a switch that leaves the lane's current stage unresolvable warns |
| `agenthub lanes profile check [<path>]` | Validate a profile — parses, every referenced hook exists and is executable, no leftover `TODO:`, declared ports free. `<path>` defaults to the current directory (not a lane id) |
| `agenthub lanes reset\|remove\|purge <id> [--force] [--keep-db] --yes` | Show preflight facts, then perform a destructive action. Refuses without `--yes`; `--force` is required when commits are unpushed; `--keep-db` (`reset` only) skips dropping/recreating a data-isolated lane's database |
| `agenthub ship-full "<requirement>" [<id>] [--print]` | **The 16-stage lane pipeline.** Puts the lane on the `ship-feature` template and starts a `claude` session running its skill (`/agenthub:ship-feature-lane`): implement → gates → e2e → review → local QC → senior GO/NO-GO → push branch + open PR, then watches the PR until a human merges it. Use when the work should end in a reviewable PR |
| `agenthub ship-quick "<requirement>" [<id>] [--print]` | **The 8-stage in-repo pipeline.** Puts the lane on the `default` template and runs its skill (`/agenthub:ship-feature`): plan → implement → tests → review → gate → ship. No PR, no browser QC. Use for work that stays in the working copy |
| `agenthub stage <stage> [--tool claude\|codex] [--evidence <text>] [--note <text>] [--result pass\|fail]` | Declare the lane's current pipeline stage. Called by a skill at each phase boundary. `<stage>` may be a node id or one of its template's aliases; a name matching neither is still recorded but warns on stderr (exit stays `0`) that the pipeline map won't show it. `--tool` picks between a `claude` and a `codex` lane sharing one directory |
| `agenthub stage <stage> [--tool claude\|codex] [--evidence <text>] [--note <text>] [--result pass\|fail]` | Declare the lane's current pipeline stage. Called by a skill at each phase boundary. With no pipeline template installed (AgentHub ships none — see [Custom pipeline templates](LANES.md#custom-pipeline-templates)) it answers `400 ENOPIPELINE`. `<stage>` may be a node id or one of its template's aliases; a name matching neither is still recorded but warns on stderr (exit stays `0`) that the pipeline map won't show it. `--tool` picks between a `claude` and a `codex` lane sharing one directory |
| `agenthub feature list [<id>]` | List every feature this lane has activated, archived or live |
| `agenthub feature activate <slug> [--title text] [<id>]` | Switch to a feature by slug (echoes the canonicalized slug), archiving the current one first |
| `agenthub feature show <slug> [<id>]` | Show one feature's saved pipeline — works on an archived one too |
`agenthub ship-full` / `agenthub ship-quick` both resolve the lane from the working directory (or take a lane id), pass the requirement to `claude` as one argv element — never through a shell — and accept `--print`, which shows the exact command, switches no template and runs nothing. The skill string itself lives in the template's `skill` field; a template without one makes the command refuse rather than guess.
**Runtime** — the lane's own application stack, as opposed to `start`/`stop`, which drive its Claude run. Two lifecycles, one lane id. Each requires the repository to declare a profile at `<repo>/.agenthub/profile/` ([contract](LANES.md#lane-runtime-running-a-lanes-own-stack)); without one they report that nothing is configured rather than failing.
| Command | Description |
+1 -1
View File
@@ -253,7 +253,7 @@ DASHBOARD_DB_PATH=/var/lib/agenthub/dashboard.db
# Ingestion polls (0 disables either one)
DASHBOARD_WORKFLOW_POLL_MS=12000 # Workflow-tool run journals
DASHBOARD_CODEX_POLL_MS=15000 # Codex rollout journals → codex lane stage detection
DASHBOARD_CODEX_POLL_MS=15000 # Codex rollout journals → codex lane running/idle
CODEX_HOME= # where Codex keeps sessions/ (default ~/.codex)
# Logging
+122 -435
View File
@@ -32,9 +32,9 @@ agenthub lanes add --repo /path/to/repo --title "My Feature" --base main --slug
`--title`, `--base`, and `--slug` are optional. The CLI waits for background provisioning to finish and reports either the ready lane or its failure notes.
Adopting your main repo (`agenthub lanes add --cwd $(pwd)`) is also how you get stage detection working for sessions that work directly in it rather than in a worktree — see "Superpowers skill invocations" below. Once adopted, that lane's own card lists every managed-worktree lane whose `source_repo` matches its `cwd`, each a clickable link to jump to that lane.
Adopting your main repo (`agenthub lanes add --cwd $(pwd)`) is also how you get stage detection working for sessions that work directly in it rather than in a worktree (once a pipeline template is installed) — see "Stage detection" below. Once adopted, that lane's own card lists every managed-worktree lane whose `source_repo` matches its `cwd`, each a clickable link to jump to that lane.
Adding a lane through the dashboard's "+ Add lane" flow also auto-runs, best-effort, in parallel: `agenthub lanes profile init` (only if a Node.js project is detected — most repos won't be, and that's a normal outcome, not a failure), `agenthub lanes agents install`, and `agenthub lanes mcp sync`. None of the three blocks the lane from being created or from each other — a lane whose repo has no MCP servers configured, for instance, still gets created and is still usable, just without a synced `.mcp.json`. The modal shows a ✓/✗ summary of the three results and stays open until dismissed (Cancel/X) — it does not auto-close. Run any of the three manually later (from the lane's own card, or the CLI) if the automatic attempt didn't apply.
Adding a lane through the dashboard's "+ Add lane" flow also auto-runs, best-effort, in parallel: `agenthub lanes profile init` (only if a Node.js project is detected — most repos won't be, and that's a normal outcome, not a failure), `agenthub lanes mcp sync`, and the AI Router pick. None of the three blocks the lane from being created or from each other — a lane whose repo has no MCP servers configured, for instance, still gets created and is still usable, just without a synced `.mcp.json`. The modal shows a ✓/✗ summary of the three results and stays open until dismissed (Cancel/X) — it does not auto-close. Run any of the three manually later (from the lane's own card, or the CLI) if the automatic attempt didn't apply.
### The "+ Add lane" modal
@@ -96,7 +96,7 @@ Both modes' path field has a **Browse** button next to it, opening a small folde
A lane is driven by a tool: **Claude** (default) or **Codex**, chosen in the "+ Add lane" modal and immutable once the lane exists. A lane's tool determines which CLI is spawned when a run starts.
- **`claude` (default)** — `claude` binary is invoked; the session's hooks, messages, and tool calls flow through the dashboard. Claude lanes render Sessions, Analytics, cost, and stage-detection badges; liveness is tracked by the Claude Code session.
- **`codex` (experimental)** — `codex` binary is invoked instead. The Run Setup panel shows fields for model, sandbox, and approval mode instead of the Claude session picker, and offers "Resume last Codex run" instead of picking a session. Resume uses `codex resume --last`. Codex lanes render stage-detection badges too, fed from Codex's own rollout journals rather than hooks (see "Stage detection"), but no Sessions/Analytics/cost. (The console pre-fills nothing into the prompt box, for either tool.)
- **`codex` (experimental)** — `codex` binary is invoked instead. The Run Setup panel shows fields for model, sandbox, and approval mode instead of the Claude session picker, and offers "Resume last Codex run" instead of picking a session. Resume uses `codex resume --last`. Codex lanes carry **no pipeline**: no stage chip, no time-on-stage, no pipeline or feature picker and no PipelineMap, and nothing infers or advances their stage. They also get no Sessions/Analytics/cost. (The console pre-fills nothing into the prompt box, for either tool.)
### How Codex arguments map
@@ -116,39 +116,16 @@ Codex does not emit Claude Code hooks (sessions, agent events, tool-execution tr
- **Sessions** and **Analytics** tabs — no session history or aggregated statistics
- **Cost** surface — no per-run or per-model pricing data
**These are not bugs; they reflect Codex's architecture.** The stage you declare via `agenthub stage` (or that the driving agent calls itself) still works; liveness is tracked by the lane's tmux pane (if the stack is up) and `dashboard_runs` table (recording every invocation). Cost tracking for Codex runs would require parsing Codex's own logs, a separate design not yet implemented.
**These are not bugs; they reflect Codex's architecture.** Liveness is tracked by the lane's tmux pane (if the stack is up) and `dashboard_runs` table (recording every invocation). Cost tracking for Codex runs would require parsing Codex's own logs, a separate design not yet implemented.
**Stage detection is not in that list.** It does work for a codex lane, from
Codex's own on-disk rollout journals rather than from hooks, and unlike a claude
lane a written detection there also **advances the lane's declared `stage`** —
see "Stage detection" below. What a codex lane cannot get for free is
*evidence*: an auto-advanced node renders `passed-no-evidence` (amber), never
`done`, because only the session itself can say what it actually finished. The
run console never pre-fills a Claude slash command into a codex pane (Codex
would read `/agenthub:ship-feature-lane` as prose), so a codex session declares
evidence only when something tells it to. Three things do:
- **An opening prompt checklist.** The Run Setup panel pre-fills a codex pane's
first prompt with a plain-text list of `agenthub stage <stage> --tool codex`
calls to make, one per node of the lane's own pipeline template (built from
`Lane.pipeline_nodes`, so it always matches whatever template is in use) —
the same up-front priming a Claude lane gets from its pre-filled
`/agenthub:ship-feature-lane` skill command, just as plain text since Codex has
no slash commands. See `LaneConsolePane.tsx`'s `promptPrefill`.
- **An `AGENTS.md` block.** `agenthub lanes agents install` on a codex lane writes
a marker-delimited `<!-- agenthub:stage:start -->` section into
`<lane cwd>/AGENTS.md` — the one instruction channel Codex actually reads,
since it never loads `.claude/agents/`. Appended, never overwriting your own
prose, and a reinstall replaces exactly that block. (On a `claude` lane the
same command still copies the two agent templates instead.)
- **A missing-evidence nudge.** `server/lib/codex-nudge.js` sweeps every 60s
(`DASHBOARD_CODEX_NUDGE_MS` to change, `0` to disable) for a codex lane whose
current stage has been held for at least two minutes with no evidence
recorded, and types a one-line `[agenthub] ... run: agenthub stage ... --evidence
"..."` reminder straight into that lane's live tmux pane (`tmux.sendText`,
skipped if the pane is at a bare shell prompt). It never writes `stage`,
`stages` or `detected_stage` itself — the evidence that results is a real
declaration the session made.
**Codex lanes carry no pipeline.** Nothing infers their stage and nothing types
a stage reminder into their pane. The one thing AgentHub reads from Codex is
its running/idle status — see "Stage detection" for the journal poll that
mirrors it. Every server start also wipes what older builds left behind on a
codex lane — its stage columns, stage log (`lane_stage_events`) and feature
records (`lane_features`) — and takes the old
`<!-- agenthub:stage:start -->` block back out of its `AGENTS.md` (deleting
the file if nothing else is in it).
## Destructive lane actions
@@ -417,8 +394,8 @@ The dashboard web UI merges lanes and runs into a single **Workspace** page acce
- **No lanes yet** — the strip is replaced by a single banner (`lane-empty`): icon, one line of what a lane is, the CLI equivalent (`agenthub lanes add --cwd $(pwd)`) and an **Add lane** affordance. The whole banner IS the button — clicking anywhere on it opens the Add-lane modal, so there is no separate button to hit. The strip itself — the dashed add tile plus the lane tiles — only renders once at least one lane exists, because an add tile beside a stray sentence read as a half-drawn row. The banner stays compact on purpose: the run setup form below it is what needs the height.
- **Reordering the strip** — drag a tile onto another to move it there, or press **Alt+←/→** with a tile focused (the keyboard path; HTML5 drag-and-drop has no touch support and does not auto-scroll an overflowing strip). The order is a **per-viewer preference**, not a lane fact: it persists to `localStorage` (`agenthub.workspace.laneOrder`) exactly like the split-view layout beside it, and writes nothing server-side — `GET /api/lanes` and `agenthub lanes` keep answering in id order, and the order does not follow you to another browser. A lane the stored order has never seen (created since, or created in another tab) lands at the END rather than wherever a stale index would put it; a stored id whose lane is gone is skipped.
- **Renaming a lane** — the detail header's name is a button: click it (a pencil appears on hover) to edit in place. **Enter** saves via `PATCH /api/lanes/:id` with `{title}`, **Escape** and clicking away both cancel, and saving an empty name clears the title, which puts the lane's `cwd` back in its place. Renaming is display-only — a managed lane's branch name was slugified from its title once, at creation.
- **Lane-detail header row** — one row, and every per-lane control lives on it: liveness + status, the lane's name (no "Lane 23 ·" prefix — the id is on the strip tile), time-on-stage, the pipeline picker, the Model (AI Router) select, the feature picker (there are no stage chips here — the declared stage and the `auto: <stage>` detection both render in the PipelineMap directly below, so the chips were a second, smaller copy of the same two facts), and on the right the **Tools** menu (agents install / mcp sync / sync-base check / create-update readme, hidden when the lane declares no runtime profile), the info toggle, the split-view toggle and Remove. Tools sits here rather than in Settings because every one of its actions runs against one lane's `cwd` — in Settings it would need a lane picker just to say which. **Create/update readme file** (Claude lanes only — Codex has no slash commands) starts the lane's terminal run with `/sg-all:sg-md-writing` as its first message, so the lane opens already writing/refreshing its `CLAUDE.md`/`AGENTS.md` set; it needs the `sg-all` plugin installed in Claude Code, and without it the session just reports an unknown command. It used to be a checkbox in the Add-lane modal: creating a lane and writing its docs are separate decisions, and the second is worth re-running long after the first.
- **Detail panel** — the selected lane's declared stage, its inferred stage when detection leads, a full-width pipeline map, and a legend naming all five node states plus the dashed-amber inferred treatment.
- **Lane-detail header row** — one row, and every per-lane control lives on it: liveness + status, the lane's name (no "Lane 23 ·" prefix — the id is on the strip tile), time-on-stage, the pipeline picker, the Model (AI Router) select, the feature picker (time-on-stage and both pickers only while a pipeline template is installed; there are no stage chips here — the declared stage and the `auto: <stage>` detection both render in the PipelineMap directly below, so the chips were a second, smaller copy of the same two facts), and on the right the **Tools** menu (mcp sync / sync-base check / create-update readme, hidden when the lane declares no runtime profile), the info toggle, the split-view toggle and Remove. Tools sits here rather than in Settings because every one of its actions runs against one lane's `cwd` — in Settings it would need a lane picker just to say which. **Create/update readme file** (Claude lanes only — Codex has no slash commands) starts the lane's terminal run with `/sg-all:sg-md-writing` as its first message, so the lane opens already writing/refreshing its `CLAUDE.md`/`AGENTS.md` set; it needs the `sg-all` plugin installed in Claude Code, and without it the session just reports an unknown command. It used to be a checkbox in the Add-lane modal: creating a lane and writing its docs are separate decisions, and the second is worth re-running long after the first.
- **Detail panel** — the selected lane's declared stage, its inferred stage when detection leads, a full-width pipeline map, and a legend naming all five node states plus the dashed-amber inferred treatment Hidden while no pipeline template is installed (see "Pipeline stages and the five node states").
- **Terminal** — a real interactive terminal (xterm.js) displaying the tmux session's PTY output, with full support for interactive commands, editors, and pagers. A live run keeps its rendered history and scroll position when scrolling. It grabs the keyboard the moment it appears, so typing goes into the pane without clicking it first, and when the pane's process ends — a double Ctrl+C out of `claude`, `exit`, a crash — the console returns to the run setup form on its own, with no "New run" click.
- **Clipboard in a pane** — the lane's tmux session is started with the graphical session's own `DISPLAY`/`WAYLAND_DISPLAY`/`XAUTHORITY`/`XDG_RUNTIME_DIR` (read from `systemctl --user show-environment`, this process's own values winning; `server/lib/desktop-env.js`). The dashboard normally runs as a systemd *user* service, which has none of them, so a pane it started had no clipboard at all and `claude` answered "no image found in clipboard" on every image paste while the same CLI pasted fine in a terminal. Only those four names are forwarded, and only into panes this dashboard spawns — an already-running pane keeps the environment it was started with, so it needs a restart to gain one.
- **Split view** — a layout toggle (one pane / two side by side / a 2×2 grid, drawn as icons rather than the words, with the count kept as each button's `aria-label` and tooltip) renders that many terminal panes side by side (`grid-cols-2` for 2, a 2×2 grid for 4). EVERY pane is bound to the lane strip's selection — there is no per-pane lane picker — and each pane owns its own tmux session on that lane: pane 0 is the lane's `agenthub-lane-<id>` (its `run_id`), panes 1–3 are `agenthub-lane-<id>-<slot>` (`POST /api/lanes/:id/start` with `slot`). A pane's **Active runs** leaves out the runs the other panes are showing, so one terminal is never attached twice side by side. Only the layout persists to `localStorage` (`agenthub.workspace.splitView`); a stored per-pane lane id from an older build is ignored.
@@ -471,7 +448,7 @@ curl -X POST http://localhost:4820/api/lanes/ensure \
}
```
- If a lane already owns the `cwd` **for the requested `tool`**, returns that lane with `created: false` and HTTP `200`. `tool` (`claude` or `codex`, default `claude`) is part of the identity: adopting the same `cwd` with a different `tool` creates a second, sibling lane rather than adopting the existing one — one `cwd` can back at most one `claude` lane and one `codex` lane at a time. This applies to Repo/Adopt mode only; Worktree mode always gets its own directory.
- If a lane already owns the `cwd` **for the requested `tool`**, returns that lane with `created: false` and HTTP `200`. `tool` (`claude`, `codex` or `antigravity`, default `claude`) is part of the identity: adopting the same `cwd` with a different `tool` creates a second, sibling lane rather than adopting the existing one — one `cwd` can back at most one `claude` lane and one `codex` lane at a time. This applies to Repo/Adopt mode only; Worktree mode always gets its own directory.
- If the `cwd` is a subdirectory of an existing lane with that same tool, returns the parent lane that owns it. Pass `"exact": true` to skip that: only a lane on this very directory is returned, and a nested one is created as its own lane — the Add-lane modal does this, and shows which lane already owns the folder when the answer is `created: false`.
- If no lane owns the `(cwd, tool)` pair, creates an **adopted** lane and returns it with `created: true` and HTTP `201`.
- A relative or missing `cwd` returns `400 EBADCWD`.
@@ -567,9 +544,18 @@ its recovery is a button too: a merge that stops on conflicts puts a banner at
the top of the Changes panel — **Complete merge** (enabled once nothing is
conflicted) and **Abort merge** (two clicks; back to where the branch was) —
and lists the conflicted files in their own **Merge conflicts** group with
**Keep mine**, **Take theirs** and **Mark resolved** (after editing the
`<<<<<<<`/`>>>>>>>` markers out in the file editor; refused while any are
left). Pull and branch switch are disabled until the merge is finished or
**Keep mine** / **Take theirs** for the whole file and **Mark resolved**.
Opening a conflicted file shows the **conflict view** instead of its diff:
each conflict block drawn as its two sides — *Mine (HEAD)* tinted green,
*Theirs (<branch>)* tinted blue, labelled from git's own markers — with
**Keep mine**, **Take theirs** or **Keep both** per block (undoable, ^/v to
jump between blocks). **Save and mark resolved** is enabled once every block
is chosen; it saves over exactly the version opened (a file changed meanwhile
is refused, `409 ESTALE`) and then marks the file resolved. **Edit by hand**
opens the plain editor, for a block neither side gets right; marking resolved
is refused while any `<<<<<<<`/`>>>>>>>` marker is left. In the Files tree a
conflicted file is listed once (git indexes it once per side) and marked with
a red **!**. Pull and branch switch are disabled until the merge is finished or
aborted.
`pull --ff-only` and the dirty-tree guard on `switch` are what keep either from
inventing a merge commit or a conflict underneath a running agent. **Create**
@@ -643,13 +629,18 @@ only one that answers "show me the code" rather than "show me the change"):
one green with `U` (`A` added, `D` deleted and struck through, `R`
renamed), and a folder holding any of them gets an amber dot. The colours
come with the tree read, so **Refresh** re-reads them.
Opening a file entry shows the whole file (`/git/file`). Its **Edit** button
(any range but a commit) turns that view into a text editor: **Save** (or
Opening a file entry shows the whole file (`/git/file`) for reading, at every
panel width. **Clicking its text** (or Enter on it; any range but a commit)
turns that view into a text editor with the caret on the clicked line and
the scroll position kept — a click that only ends a drag-selection does not,
so copying never drops you into the editor. **Cancel** returns to reading.
From a diff, which has no whole text to click, an **Edit** button does the
same once the file has loaded. **Save** (or
Ctrl/Cmd+S) is `PUT /api/lanes/:id/git/file`, which writes only over the
exact version that was opened — a file the agent changed meanwhile answers
`409 ESTALE` and the draft stays for a retry — and keeps the file's CRLF
line endings and final newline. A file the editor cannot take (binary, or
over the 1 MB view cap) says so where the Edit button would be.
over the 1 MB view cap) says so in the file's header.
- **Overview** — every changed file with its `+N −M`. Polls every 15s, because
it is the cheap shape and the one you leave open while an agent works. Each
row carries its own **stage** / **unstage** / **discard** buttons.
@@ -661,14 +652,18 @@ only one that answers "show me the code" rather than "show me the change"):
a file that appears later is open by default; a lane switch clears it.
Each file's header stays **pinned** at the top while its diff scrolls past,
and carries the same stage / unstage / discard buttons as its overview row.
On a file with unstaged changes every hunk gets an editor-style **review
bar**, hung just under its last changed line and pinned to the visible
right edge: `^`/`v` to walk the hunks (each brings the next/previous `@@`
line to the top of the ONE scroller, below the sticky file header — a
On a file with unstaged changes every **change block** — each run of
consecutive `+`/`-` lines, not each `@@` hunk: git merges edits up to six
lines apart into one hunk, and one bar for all of them acted on every edit
at once (issue #50) — gets an editor-style **review bar**, hung just under
its last changed line and pinned to the visible right edge: `^`/`v` to walk
the blocks (each brings the next/previous block's first line to the top of
the ONE scroller, below the sticky file header — a
review diff has no scroll box of its own unless it is large enough to
window, above 500 rows), `n of N`, **Undo**
(`discard-hunk` — asks twice, like discard) and **Keep** (`stage-hunk`).
The single-file view offers the same bar.
(`discard-hunk` — asks twice, like discard) and **Keep** (`stage-hunk`),
both sent with the hunk's `@@` line plus the block's index, so they touch
that block alone. The single-file view offers the same bar.
- **One file** — clicking a file's path in any list opens just that file.
**All files** returns to the list it was opened from — the same mode, at the
same scroll offset — because reading a change-set is a walk down a long list
@@ -750,7 +745,9 @@ The dashboard web UI shows each lane as a card in a grid, with the selected lane
## Pipeline stages and the five node states
A lane moves through stages defined in a **pipeline template** (see "Custom pipeline templates" below). The default pipeline has eight stages: `intake`, `plan`, `implement`, `tests`, `review`, `gate`, `ship`, and `done`.
> **Pipelines are dormant.** AgentHub ships no pipeline template. Until you install one (drop a template JSON into `DASHBOARD_PIPELINES_DIR` — see "Custom pipeline templates" below), every lane sits on an empty `default` pipeline: no nodes, progress `0`. `GET /api/lanes/pipelines` returns `{"pipelines": []}`, `agenthub stage <x>` (and `POST /api/lanes/:id/stage`) answers `400 ENOPIPELINE`, and the Workspace hides the time-on-stage timer, the pipeline and feature pickers and the PipelineMap — the lane tile shows its tool tag instead of a stage chip. Install a template and all of it comes back; a template with id `default` becomes every lane's default. Further development of pipelines is planned. The rest of this section, and the stage sections after it, describe a lane on an installed template.
A lane moves through stages defined in a **pipeline template** (see "Custom pipeline templates" below).
**A lane is created on `default` unless told otherwise.** The "+ Add lane" modal does not ask — it always creates on `default`. Pick another with `agenthub lanes add --pipeline <id>` at creation, or change it afterwards from the *Pipeline template* select in the lane's detail header in Workspace.
@@ -758,63 +755,31 @@ For a lane that already exists, switch it from the terminal:
```bash
agenthub lanes pipeline # which template this lane uses, and what else exists
agenthub lanes pipeline ship-feature # switch it
agenthub lanes pipeline ml-training # switch it (any installed template id)
```
or from the dashboard: the pipeline-template select next to the lane's title in the Workspace detail panel does the same `PATCH /api/lanes/:id` the CLI uses, live (disabled while viewing an archived feature snapshot).
**The template names the skill that drives it.** `"skill": "/agenthub:ship-feature-lane"` on the 16-node `ship-feature` template, `"skill": "/agenthub:ship-feature"` on the 8-node `default` one. It rides along on every lane payload as `pipeline_skill`, and from a terminal there is one command per depth of work — the command you type picks the pipeline, so no `agenthub lanes pipeline` step first:
```bash
cd ~/lanes/myrepo__feat-export
# 16 stages: ends in a published PR, watched until a human merges it
agenthub ship-full "add an export button"
# → lane switched to `ship-feature`, then: claude "/agenthub:ship-feature-lane add an export button"
# 8 stages: in-repo feature work, stops at review/gate — no PR, no browser QC
agenthub ship-quick "fix the CSV separator"
# → lane switched to `default`, then: claude "/agenthub:ship-feature fix the CSV separator"
agenthub ship-full "add an export button" --print # show the command, switch nothing, run nothing
```
| | `agenthub ship-full` | `agenthub ship-quick` |
|---|---|---|
| Template | `ship-feature` (16 nodes) | `default` (8 nodes) |
| Skill | `/agenthub:ship-feature-lane` | `/agenthub:ship-feature` |
| Ends at | PR open on `development`, watched until merged | `ship` in the working copy |
| Includes | unit-test agent, CI gates, e2e, code review, local browser QC, senior GO/NO-GO | plan, implement, tests, review, gate |
| Use when | the work should reach reviewers | the work stays local |
The lane is resolved from the working directory, so no id is needed (pass one to target another lane). Each command puts the lane on its own template *before* spawning, so the dashboard renders the right node count from the first stage rather than after the skill self-corrects; `--print` switches nothing. The requirement is handed to `claude` as ONE argv element — never through a shell — so quotes, `$` and `;` in it are text. A template with no `skill` field makes the command refuse rather than guess.
A template may name the slash command that drives it (its optional `skill` field). It rides along on every lane payload as `pipeline_skill`; the dashboard never executes it.
### Running ONE node
`agenthub ship-full` / `agenthub ship-quick` hand the whole pipeline to a skill. When you only want one step — re-run the CI gate, redo the brainstorm, open the PR by hand — run that node's own `command`:
When you only want one step — re-run a CI gate, redo a brainstorm — run that node's own `command`:
```bash
agenthub lanes node # list every node of this lane's pipeline and its command
agenthub lanes node intake # → claude "/superpowers:brainstorming"
agenthub lanes node intake the export button # extra words are appended to the prompt
agenthub lanes node review # → claude "/code-review"
agenthub lanes node gates # → agenthub lanes hook ci-gate
agenthub lanes node pr-open --print # show the argv, run nothing
agenthub lanes node # list every node of this lane's pipeline and its command
agenthub lanes node <node-id> # run that node's command in the lane's cwd
agenthub lanes node <node-id> extra words # extra words are appended to the prompt
agenthub lanes node <node-id> --print # show the argv, run nothing
```
Both shipped templates give **every** node a command, so any of the 16 (or 8) is runnable. A node starting with `/` is spawned as `claude "<command> <extra args>"`; anything else is spawned directly. The lane comes from the working directory as usual, and the command always runs in the lane's own `cwd`.
The node is matched by **id or alias**, so one name works on either template: `default` calls the step `implement` and `ship-feature` calls it `implementing`, and `agenthub lanes node implement` finds it on both.
**From inside a Claude session, use the slash commands instead.** The plugin ships one per node — `/intake`, `/plan`, `/implement`, `/tests`, `/e2e`, `/e2e-passed`, `/review`, `/qc-plan`, `/qc`, `/gate`, `/publishing`, `/pr-open`, `/reported`, `/watching-pr`, `/merged`, `/done` — plus `/ship-full` and `/ship-quick` for the whole pipeline. Each resolves the node's command through `agenthub lanes node <id> --print` and runs it *in the current session*: a slash-command node is invoked directly (never as a nested `claude` process), anything else runs as a shell argv in the lane's cwd. Extra words are appended to the prompt: `/intake the export button`.
A node is runnable when its template gives it a `command`. A command starting with `/` is spawned as `claude "<command> <extra args>"`; anything else is spawned directly. The lane comes from the working directory as usual, and the command always runs in the lane's own `cwd`. The node is matched by **id or alias**.
Two deliberate limits:
- **The command is split on whitespace and spawned without a shell.** A template is data — files anyone can drop into `DASHBOARD_PIPELINES_DIR` — so its `command` is never interpreted as shell. A node needing a pipe or a redirect names a script that contains them.
- **Running a node does not declare its stage.** A command executing is not proof the node passed — the same reason the run console never writes a lane's stage. Declare with `agenthub stage <id>` when the work is actually done. (The exception is a node whose command *is* `agenthub stage <id>`: there the declaration is the whole step.)
**The template also decides what the Workspace run console pre-fills.** A template may name the slash command that drives it — `"skill": "/agenthub:ship-feature-lane"` on the 16-node `ship-feature` template, `"skill": "/agenthub:ship-feature"` on the 8-node `default` one. That string rides along on every lane payload as `pipeline_skill`, and the run console starts its prompt box with it (plus a trailing space) so you only type the requirement: pick the 16-node template and Run starts the 16-step skill, pick the 8-node one and it starts the 8-step skill. The dashboard never executes it — it is text in a prompt box, exactly as if you had typed it. A prompt you have already edited is never overwritten by a later template switch, and a template with no `skill` field pre-fills nothing.
Switching re-resolves the lane's existing declared `stage` against the new node list. A stage the old template knew may resolve to nothing in the new one; the switch warns when that happens (both CLI and UI), and the next `agenthub stage` fixes it.
### Aggregate pass rates across lanes
@@ -848,7 +813,7 @@ one feature's work reads `implement → tests → implement → tests` as the se
edits, runs the suite, and edits again — and when any backwards move opened a
run, a single feature was recorded as five or six of them. A real pass ends
where the session says it ends: a backwards move only starts a new run when it
is declared (`agenthub stage`, or a codex lane's ingest-driven declaration). A
is declared (`agenthub stage`). A
detection that moves backwards continues the run in flight. Reaching the last
node still closes the run for both — work after `done` is new work by anyone's
reading. On this repo's own lane the rule took a 26-run history down to 5, which
@@ -863,8 +828,6 @@ offering every other lane even while the counts show only one.
`agenthub lanes shell` attaches a real terminal to the exact tmux session the dashboard's Start/Resume buttons use for this lane (`agenthub-lane-<id>`), creating it if it doesn't exist yet. Type `claude` inside it like any normal terminal session — the dashboard's Workspace terminal view is just another client attached to the same tmux session, so both stay in sync live.
**In practice you never have to pick correctly at creation.** The template only has to match whichever skill is actually driving the lane, and the skill enforces that itself: `ship-feature-lane` runs `agenthub lanes pipeline ship-feature` and `ship-feature` runs `agenthub lanes pipeline default` before their first `agenthub stage` call — a no-op if the lane is already on that template, a self-correction if it isn't. A human chatting with the lane never needs to open the picker; whichever skill gets invoked decides the template.
The dashboard renders every node in the pipeline in one of five **states**:
| State | Color | Meaning |
@@ -880,13 +843,13 @@ The dashboard renders every node in the pipeline in one of five **states**:
A stage in this state was **claimed but not proven**. Two scenarios:
1. **Declared but no artifact left.** A skill called `agenthub stage review` without `--evidence`, claiming the stage happened but leaving no proof that work occurred.
2. **Implicitly skipped.** The lane jumped from `plan` to `implement` (to stage index 2), leaving `intake` (index 0) in `passed-no-evidence` state.
2. **Implicitly skipped.** On a template whose nodes start `intake`, `plan`, `implement`, the lane jumped from `plan` to `implement` (to stage index 2), leaving `intake` (index 0) in `passed-no-evidence` state.
In both cases, the stage is not **done** — it's incomplete or untested. Amber signals that the agent claimed to have done this work but the dashboard has no evidence to show it was actually completed. This matters in a pipeline: if your gate checks `done` not `passed-no-evidence`, a lane stuck in amber will block until evidence is provided.
## Reporting a stage
`agenthub stage` is not skill-only. Any Claude session working inside an adopted lane's cwd — including a plain chat session where no skill was ever invoked — should call it on real stage transitions. Tool-event detection (see "Inferred vs. declared" below) can only paint the amber "detected" badge; it never moves the blue `current` ring. A lane worked entirely through plain chat that never calls `agenthub stage` will keep showing whatever stage it was last declared at (often `intake`), regardless of how much real work happens.
`agenthub stage` is not skill-only. Any Claude session working inside an adopted lane's cwd — including a plain chat session where no skill was ever invoked — should call it on real stage transitions. Tool-event detection (see "Inferred vs. declared" below) can only paint the amber "detected" badge; it never moves the blue `current` ring. A lane worked entirely through plain chat that never calls `agenthub stage` will keep showing whatever stage it was last declared at, regardless of how much real work happens. With no pipeline template installed there is nothing to declare: the command answers `400 ENOPIPELINE`.
When a skill — or a plain chat session — reaches a significant milestone, it reports the current stage to the dashboard using `agenthub stage`:
@@ -908,18 +871,9 @@ agenthub stage <stage> [--lane <id>] [--cwd <path>] [--tool claude|codex] [--sta
**Parameters:**
- `<stage>` (required): the pipeline stage name or alias. The default pipeline aliases are:
- `intake` / `assigned` / `claimed` / `start`
- `plan` / `planning` / `brainstorm` / `design`
- `implement` / `implementing` / `coding` / `build`
- `tests` / `testing` / `unit` / `gates` / `pre-push-gate`
- `review` / `reviewing` / `code-review` / `self-review`
- `gate` / `verify` / `verification` / `sr-gate` / `gate-blocked`
- `ship` / `pr` / `pr-open` / `publishing` / `commit` / `push`
- `done` / `complete` / `completed` / `merged`
Aliases are **per template** — the `ship-feature` pipeline has its own set
(see "Pipeline template: ship-feature" below). A name matching no node and no
- `<stage>` (required): a node id or one of its aliases, as the lane's
pipeline template defines them (see "Custom template format"). Aliases are
**per template**. A name matching no node and no
alias is still recorded verbatim, but `phaseIdx` then resolves it to nothing:
no node renders `current` and progress reads `0`. The CLI prints a warning to
stderr and still exits `0` in that case — a typo must not break a
@@ -976,8 +930,7 @@ Such keys only exist on lanes that predate validation: `POST
/api/lanes/:id/stage` now rejects a stage naming no node of the lane's pipeline
with **400 `EBADSTAGE`** and lists the ones that exist. Aliases still resolve,
so this catches typos and names borrowed from another template — `agenthub
stage test` on a `ship-feature` lane, whose CI node is `gates` — which used to
be stored, warned about on stderr, and then counted nowhere.
stage test` on a template whose CI node is `gates` — which used to be stored, warned about on stderr, and then counted nowhere.
Every declaration is also appended to `lane_stage_events`, the append-only log
the pass-rate report reads. `lanes.stages` describes the pass in flight and is
@@ -1042,14 +995,11 @@ agenthub stage tests --evidence "Pre-push gate: all linters passing" --result pa
## Custom pipeline templates
The default pipeline is suitable for feature work: `intake` → `plan` → `implement` → `tests` → `review` → `gate` → `ship` → `done`. For different workflows (data pipelines, research phases, deployment stages), you can provide custom templates.
AgentHub ships no template, so a custom template is the only way to turn the pipeline map, stage reporting and stage detection on. A template models whatever workflow you run — feature work, data pipelines, research phases, deployment stages.
### Where templates come from
1. **Built-in:** `server/data/pipelines/default.json` (always available)
2. **User override:** directory specified by the `DASHBOARD_PIPELINES_DIR` environment variable
If both exist, **files in the user directory override built-ins** with the same `id`.
Every `*.json` file in the directory named by the `DASHBOARD_PIPELINES_DIR` environment variable is loaded once at server start; a malformed file is skipped, never fatal. A template whose `id` is `default` becomes the pipeline of every lane that names no other.
### Custom template format
@@ -1074,14 +1024,15 @@ Create a JSON file in your custom pipeline directory (e.g., `~/.agenthub/pipelin
- **id** (string, required): unique identifier for this template
- **name** (string, optional): display name shown in the UI
- **skill** (string, optional): the slash command that drives this pipeline (e.g. `"/agenthub:ship-feature-lane"`). The Workspace run console pre-fills its prompt with it for lanes on this template; omit it and the prompt starts empty. Never executed by the dashboard.
- **skill** (string, optional): the slash command that drives this pipeline (e.g. `"/my-training-skill"`). Carried on every lane payload as `pipeline_skill`. Never executed by the dashboard.
- **nodes** (array, required): list of pipeline stages, in order
- **id** (string): stage identifier (used in `agenthub stage`)
- **label** (string, optional): display name in the UI; defaults to `id` if omitted
- **icon** (string, optional): unicode emoji or single character shown before the stage name
- **gate** (boolean, optional): `true` if this stage blocks unless explicitly passed; defaults to `false`
- **command** (string, optional): the one command that drives THIS stage — a slash command (`"/superpowers:writing-plans"`) or a shell one (`"agenthub lanes hook ci-gate"`). Where `skill` above names the driver for the whole pipeline, this narrows it to the step, so a reader of the pipeline map sees what moves each node instead of inferring it from the node's `detect` regexes. Omit it (or leave it empty) for a node with no single driver; both shipped templates fill every node, using `"agenthub stage <id>"` for the nodes whose only "work" is the declaration itself (a terminal `done`, a gate another agent declares). Surfaced in the node's tooltip on a lane card and as copyable text per node on the Workflows page, and run by `agenthub lanes node <id>` (below); **never executed by the dashboard**, same contract as `skill`.
- **aliases** (array, optional): alternative names for the stage (e.g., `["training", "fit"]` lets you call `agenthub stage training`)
- **command** (string, optional): the one command that drives THIS stage — a slash command (`"/my-training-skill"`) or a shell one (`"agenthub lanes hook ci-gate"`). Where `skill` above names the driver for the whole pipeline, this narrows it to the step, so a reader of the pipeline map sees what moves each node instead of inferring it from the node's `detect` regexes. Omit it (or leave it empty) for a node with no single driver; use `"agenthub stage <id>"` for a node whose only "work" is the declaration itself (a terminal `done`, a gate another agent declares). Surfaced in the node's tooltip on a lane card and as copyable text per node on the Workflows page, and run by `agenthub lanes node <id>` (below); **never executed by the dashboard**, same contract as `skill`.
- **aliases** (array, optional): alternative names for the stage (e.g., `["training", "fit"]` lets you call `agenthub stage training`). An alias may also name a **sub-state** — *why* the lane sits on a node — without adding a node to the map. Two constraints: no alias may collide with another node's id or alias (`phaseIdx` takes the FIRST match, so a duplicate silently resolves a declaration onto the wrong node), and all aliases of one node share one record slot (`stageRecords` resolves each declared key onto its node, and the canonical id's record wins), so a sub-state that needs its own `--evidence` has to be a real node.
- **detect** (array, optional): stage-detection rules for this node — see "Stage detection → Where the rules live".
Then set the environment variable:
@@ -1095,7 +1046,7 @@ When you create a new lane, you can optionally specify which pipeline to use:
agenthub lanes add --cwd /path/to/ml-repo --title "Training run #1" --pipeline ml-training
```
(The pipeline is selected at creation time. Lanes created without `--pipeline` default to the `default` pipeline.)
(The pipeline is selected at creation time. Lanes created without `--pipeline` default to the `default` pipeline — yours if you installed one with that id, otherwise the empty one.)
## Per-feature state and archive
@@ -1155,72 +1106,23 @@ also **infers** a stage from the tool events every hook already delivers
un-instrumented sessions that never call `agenthub stage` — it fills in a lane's
pipeline map without requiring every skill to be rewritten.
Two event sources feed the identical matcher, one per tool:
| Lane `tool` | Source | Cadence |
| --- | --- | --- |
| `claude` | hooks — `touchLaneFromHook` in `server/routes/hooks.js` | every hook, live |
| `codex` | Codex's own rollout journals on disk — `server/lib/codex-ingest.js` | poll, `DASHBOARD_CODEX_POLL_MS` (default 15000; `0` disables) |
The matcher is fed by hooks — `touchLaneFromHook` in `server/routes/hooks.js`,
on every hook, live — so it only ever sees `claude` lanes.
Codex has no hook mechanism at all, so `touchLaneFromHook` is pinned to
`"claude"` — a hook must never touch a `codex` lane sharing the same directory.
`codex-ingest.js` is the codex-side equivalent: it tails
`$CODEX_HOME/sessions/<YYYY>/<MM>/<DD>/rollout-*.jsonl` (`$CODEX_HOME` defaults
to `~/.codex`), reads the thread's `cwd` from the `session_meta` on each file's
first line, and maps Codex's tool calls onto the same `{tool_name, tool_input}`
shape a Claude hook delivers:
| Codex tool call | Mapped to |
| --- | --- |
| `exec` / `exec_command` / `shell` / `local_shell` | `Bash` with the extracted `cmd` |
| any of the above carrying an `apply_patch` heredoc | one `Write` (for `*** Add File:`) or `Edit` (`Update`/`Delete`) per touched file |
| `update_plan` | `TaskCreate` |
| `spawn_agent` | `Agent` with the task name as `subagent_type` |
| anything else (messages, reasoning, web search, tool OUTPUT) | ignored |
Everything past that point is shared: the same templates, the same
forward-only/declared-wins rules, the same amber-never-green boundary. Three
codex-only details:
- **A written detection also advances the lane's declared `stage`.** This is
the one place in AgentHub where an inference moves the blue `current` ring, and
it exists because nothing else can: a codex session has no hook and rarely
calls `agenthub stage` on its own, so without it the card sits at `idle` forever
while the amber badge is the only thing that ever moves. It is gated on
`recordDetection` having *written*, so it inherits that function's
forward-only, declared-wins and TTL guards unchanged — a detection behind the
declared stage still advances nothing. The `setStage` call passes **no
evidence**, so every node it moves through renders `passed-no-evidence`
(amber), never `done`: a detection sees a tool call, never its outcome. And
it passes `keepDetection: true`, the sole exception to `setStage`'s clearing
of the detection columns — here the detection is the *reason* for the
declaration, so the card keeps showing which command caused it rather than
looking like a claim the agent made. The last node of every template carries
no `detect` rules, so this can never auto-declare a lane `done`.
- Only bytes appended since the last pass are read. On the first sight of a
journal only its recent tail is read, and nothing at all when that file is
already idle — replaying a thread that finished days ago would paint stages
for work nobody is doing. "Idle" means the journal's mtime is more than two
minutes old **or in the future**: a file that claims to be from the future
(clock stepped back, NTP correction, a restore that preserved timestamps)
makes a raw `now - mtime` negative, which would otherwise read as "written
milliseconds ago" and replay a finished thread as live work.
- The same pass mirrors the lane's `status` between `idle` and `running` from
the journal's mtime, under the identical guard hook ingestion uses (only a
lane with no `run_id`, and only from `idle`/`running` — never from
`provisioning` or `failed`). It writes nothing else: not `stage`, not
`notes`, not `slot`/`ports`.
**A codex lane's *evidence* is a separate matter.** Auto-advance moves the ring
but can never supply evidence, so every node a codex lane passes through stays
amber until the session itself runs `agenthub stage <node> --evidence "..."`. AgentHub
cannot inject an instruction into a CLI it merely spawns, so an `AGENTS.md` in
the working copy is the only lever — `agenthub lanes agents install` writes the
marker-delimited block for you (see "Installing the QC/gate agents"). Note that
from inside a codex session `agenthub stage` needs to know which lane it is: a pane
the dashboard started carries `AGENTHUB_LANE_ID`, and anywhere else `--tool codex`
disambiguates (see "Which lane a CLI command addresses" below).
Codex lanes carry no pipeline, so nothing detects or advances their stage.
`server/lib/codex-ingest.js` only mirrors a codex lane's `status` between
`idle` and `running`: every `DASHBOARD_CODEX_POLL_MS` (default 15000; `0`
disables) it lists `$CODEX_HOME/sessions/<YYYY>/<MM>/<DD>/rollout-*.jsonl`
(`$CODEX_HOME` defaults to `~/.codex`), reads each thread's `cwd` from the
`session_meta` on the file's first line, and calls the owning lane `running`
while that journal's mtime is under two minutes old — and `idle` once it is
older **or in the future** (a clock stepped back makes a raw `now - mtime`
negative, which would otherwise read as live). It uses the identical guard hook
ingestion uses (only a lane with no `run_id`, and only from `idle`/`running` —
never from `provisioning` or `failed`) and writes nothing else: not `stage`,
not `notes`, not `slot`/`ports`.
### The evidence boundary
@@ -1249,9 +1151,8 @@ leads the declared one (see "Viewing lanes" below), and `LaneStripCard.tsx`'s
and the browser never disagree about which one is the headline. Both locate the
declaration by the node the server already resolved it onto (the one whose
`state` is `current`), never by looking `lane.stage` up as a node id: most of
what the ship-feature skill declares is an ALIAS (`tests`, `booting`, `ship`,
`gate-blocked`), which is not an id, and an id lookup scores it -1 — every
detection, however far behind, would then read as leading.
what a skill declares may be an ALIAS, which is not an id, and an id lookup
scores it -1 — every detection, however far behind, would then read as leading.
### Which lane a signal is credited to
@@ -1294,7 +1195,7 @@ contain whole code blocks:
Each rule is tested against these fields **one at a time**, never against a join
of them. An `Agent` event really carries `description` + `prompt` +
`subagent_type` together, so a rule anchored to the agent's identity —
`{"tool": "Agent", "match": "^Explore$"}` in `ship-feature.json` — would never
`{"tool": "Agent", "match": "^Explore$"}` — would never
fire against a concatenation of all three, and a rule could otherwise match
across the seam between two unrelated fields. Write anchored rules against the
one field that identifies the tool call.
@@ -1310,18 +1211,6 @@ to the flattened input. Either way the result is capped at 120 characters
lane's tooltip sometimes shows a file path or a skill name rather than a shell
command: it's whichever of the fields above the matching rule's `tool` carried.
### Superpowers skill invocations
The built-in `default` pipeline's `intake`, `plan`, `implement`, `review`, and
`ship` nodes each carry a `{"tool": "Skill", "match": "..."}` rule matching the
workflow skill names they expect (`brainstorming`, `writing-plans`,
`executing-plans`/`subagent-driven-development`, Claude Code's own
`code-review` plus `requesting-code-review`/`receiving-code-review`,
`finishing-a-development-branch`). Invoking one of
these skills is a much stronger signal than a matched Bash command, but it is
still detection, not declaration — it renders dashed amber and never `done`,
same as every other detected stage.
Detection only ever attributes to a lane whose `cwd` matches the hook's
session `cwd` (see "Which lane a signal is credited to" above). A session
working directly in a source repo that was never itself adopted as a lane —
@@ -1361,90 +1250,36 @@ read per call, so no restart is needed for a test harness that sets it.
### Where the rules live
Detection rules are not code — they live in the pipeline template itself, as
a `detect` array on each node. The built-in `default.json`
(`server/data/pipelines/default.json`) ships these rules today, node by node:
a `detect` array on each node. AgentHub ships no template, so no rule fires
until you install one.
| Node | Detect rules |
|---|---|
| `intake` | `Agent` matching subagent `Explore` — a lane sitting at nothing else yet, but already exploring, shows *something* instead of idle; `Skill` matching `brainstorming`, which is intake's own declared command |
| `plan` | `Skill` matching `writing-plans`; `Write` matching `docs/.*plan.*\.md`; `Agent` matching `Plan\|Software Architect\|Backend Architect\|UX Architect`; `TaskCreate` (any) |
| `implement` | `Skill` matching `executing-plans\|subagent-driven-development\|test-driven-development`; `Edit` (any); `Write` to any path NOT under a `docs/` directory (`^(?!.*(?:^\|/)docs/)`) |
| `tests` | `Bash` matching `\b(npm (run )?test\|pytest\|vitest\|jest\|go test\|cargo test\|node\s+--test\|rspec\|phpunit\|dotnet test\|mvn test\|gradle test)\b`; `Agent` matching `Test Results Analyzer\|API Tester\|Performance Benchmarker` |
| `review` | `Skill` matching `code-review\|requesting-code-review\|receiving-code-review`; `Bash` matching `\bgh\b[^;&\|]*\bpr diff\b`; `Agent` matching a name containing `reviewer`/`Reviewer` (excluding `senior-gate-reviewer`, a lookbehind), `Evidence Collector`, or `Accessibility Auditor` |
| `gate` | `Skill` matching `verification-before-completion`; `Agent` matching `senior-gate-reviewer\|Reality Checker` — entering the gate, never its verdict |
| `ship` | `Bash` matching a `git push` **invocation** — `git`, then option groups, then `push` as the first non-flag token — or `gh … pr create` |
| `done` | none — see below |
A few lessons from rules that ran against real sessions, worth keeping when you
write your own:
**`git diff` is deliberately NOT a review signal.** It was, and measured on a
real session four `git diff --stat` runs — used to verify a generated file —
outranked 81 test runs and 30 edits and pinned the lane at `review`, because
`detect()` takes the LAST matching node and `recordDetection` is forward-only.
Reading a diff is constant background activity, so it carries no stage
information. `gh pr diff` stays: that one really is a review act.
- **Detection is a safety net, not the mechanism.** Because `recordDetection`
is forward-only AND never overrides a higher declared stage, a fix-loop
re-entry that drops back a node is invisible to detection — only an
`agenthub stage` declaration moves the lane back down. What detection adds is
the stage an agent forgot to declare and the heartbeat that keeps a working
lane from reading STALLED.
- **Give a terminal node (`done`, `merged`) no rule.** Inference must never
reach a terminal state on its own; that would let a heuristic assert an
outcome instead of observing activity. A rule on a gate node should detect
that the gate *activity* started, never its verdict.
- **`git diff` is not a review signal.** Measured on a real session, four
`git diff --stat` runs — used to verify a generated file — outranked 81 test
runs and 30 edits and pinned the lane at `review`, because `detect()` takes
the LAST matching node and detection is forward-only. Reading a diff is
constant background activity; `gh pr diff` really is a review act.
- **Match a `git push` *invocation*, not the word `push`.** `git[^;&|]*push`
misses `git -c credential.helper='!f() { … }; f' push` (a `;` inside a quoted
value), and `git[\s\S]*push` over-matches `git log --oneline -1 && echo "… push …"`.
Consume option groups explicitly, treating a quoted option value as one unit,
then require `push` as the first non-flag token — that accepts `git push` and
`git -c core.hooksPath=/dev/null push` while rejecting `git commit -m "don't push"`,
`docker push` and `npm run push-docs`.
**The `ship` pattern matches a git *invocation*, not the word `push`.** Two
weaker forms were tried and both failed against real commands:
- `git[^;&|]*push` (same shell segment) **misses** this repo's own push, because
`git -c credential.helper='!f() { … }; f' push` puts a `;` between the two
inside a quoted value. Six real pushes went undetected that way.
- `git[\s\S]*push` (anywhere after `git`) **over-matches**, and did so on a live
lane within minutes: `git log --oneline -1 && echo "… push …"` pinned the lane
at `ship`. Since `ship` sits near the end of the pipeline and detection is
forward-only, that single over-read stuck — the same failure `git diff` caused
for `review`.
So the pattern consumes option groups explicitly, treating a quoted option value
as one unit, and then requires `push` to be the first non-flag token. That
accepts `git push`, `git -c core.hooksPath=/dev/null push` and the credential
-helper form, while rejecting `git log … "push"`, `git commit -m "don't push"`,
`docker push`, and `npm run push-docs`.
The `ship-feature` template (`server/data/pipelines/ship-feature.json`) carries
its own rules, aimed at the commands and Superpowers skills its driving skill
actually runs:
| Node | Detect rules |
|---|---|
| `intake` | `Skill` matching `brainstorming`; `Bash` matching `agenthub … feature activate`; `Agent` matching subagent `Explore` |
| `plan` | `Skill` matching `writing-plans`; `Write` matching `docs/superpowers/specs/lane-.*\.md`; `Agent` matching `Plan\|Software Architect`; `TaskCreate` (any) |
| `implementing` | `Skill` matching `test-driven-development\|executing-plans\|subagent-driven-development\|systematic-debugging`; `Edit`/`Write` to any path NOT under `docs/superpowers/specs/` (resp. not under `docs/`) |
| `gates` | `Bash` matching `agenthub … hook ci-gate` or `agenthub … sync-base --check` |
| `e2e-feature` | `Bash` matching `agenthub … up --qc` or `agenthub … hook e2e` |
| `review` | `Skill` matching `code-review\|requesting-code-review\|receiving-code-review`; `Agent` matching a name containing `reviewer`/`Reviewer` (excluding `senior-gate-reviewer`, a lookbehind) |
| `qc` | `Agent` matching `qc-local\|Evidence Collector\|Accessibility Auditor`; `Bash` matching `agenthub … lanes proof-link` |
| `gate` | `Agent` matching `senior-gate-reviewer\|Reality Checker`; `Skill` matching `verification-before-completion` |
| `publishing` | `Skill` matching `finishing-a-development-branch`; `Bash` matching a `git push` **invocation** (the same pattern `default.json`'s `ship` uses) |
| `pr-open` | `Bash` matching `gh … pr create` |
| `watching-pr` | `Bash` matching `gh … pr view` |
| `e2e-feature-passed`, `qc-plan`, `reported`, `merged`, `done` | none — declaration-only |
Two rules are deliberately absent from this template. There is **no `git diff`
rule on `review`**, for the reason the `default` template learned the hard way
below; the `code-review` skill invocation is the honest signal. And `merged` /
`done` carry no rule at all, because inference must never reach a terminal
state — a test pins that.
Detection here is a **safety net, not the mechanism**: the `ship-feature-lane`
skill declares every one of these stages with `agenthub stage` itself. What
detection adds is the stage an agent forgot after a context compaction, the
heartbeat that keeps a working lane from reading STALLED, and coverage for a
lane running Superpowers skills without the driving skill at all. It cannot
substitute for the skill's own declarations: because `recordDetection` is
forward-only AND never overrides a higher declared stage, a fix-loop re-entry
that drops back to `gates` is invisible to detection — only the skill's
`agenthub stage gates` moves the lane back down.
`done` in `default.json` deliberately has no rule — it is explicitly out of
scope for inference (see the task's "Out of scope" list): `done` is the one
state detection must never reach on its own, since inferring it would let a
heuristic assert an outcome instead of observing activity. `intake` and `gate`
now carry entry-activity rules (an `Explore` agent, a `senior-gate-reviewer`/
`Reality Checker` agent or `verification-before-completion` skill) — these
detect that the *activity* of exploring or gate-reviewing started, never a
gate's pass/fail verdict, so the "no outcome inference" rule still holds.
To add a rule, drop a template into the directory named by the
To add a rule, put a template in the directory named by the
`DASHBOARD_PIPELINES_DIR` environment variable (see "Custom pipeline
templates" above) with a `detect` array on the node you want to match:
@@ -1468,8 +1303,8 @@ Detection never rewinds a lane and never fights a declaration:
- **Declared beats detected.** A detection is written only when the lane's
*declared* stage index is strictly less than the detection's. A lane
already declared at `review` ignores an `implement` detection outright.
**One exception: a declaration on the pipeline's LAST node** (`done`, in both
built-in templates) stops vetoing. The pipeline is finished there, so a later
**One exception: a declaration on the pipeline's LAST node** (typically
`done`) stops vetoing. The pipeline is finished there, so a later
detection is new work rather than a stale rerun of what the claim covers —
without the exception a lane left at `done` rejects every detection for the
rest of its life, which reads as "auto-detect is broken". The exception
@@ -1690,51 +1525,9 @@ The lane card shows a lock badge when the lane **holds** a named lock (its `lane
- **Never delete the lock directory by hand.** A lock that outlives its holder (e.g. after a hard reboot) is cleaned up automatically — the next `acquire` on that name finds it stale (older than `LOCK_MAX_HOLD`) and breaks it. Deleting `LANES_ROOT/.locks/<name>/` yourself only races whoever else's `acquire` is about to do the same check safely.
- **Never shrink `LOCK_MAX_HOLD` to force through a wait.** The 300-second floor exists specifically to stop this mistake. If the true holder is gone, the 300-second minimum wait is the price of safety. If the true holder is still running (e.g., a build with a network stall), shortening the timeout from 2700 to 300 does not help — it converts a slow success into a premature timeout, leaving the lock held and every other lane blocked forever.
## The ship-feature-lane skill (E1)
## Lane tooling: QC boot, sync-base, MCP, integrations, CI
The **ship-feature-lane** skill is the ported Shipyard driving skill for autonomous end-to-end feature pipelines in a single AgentHub lane. It coordinates the entire development flow: implementation (TDD) → independent unit tests → pre-push CI gates + dev preflight → e2e testing → code review → local QC → senior gate authorization → PR push and publication → CI watch → final report.
**Every stage whose job is to judge the work runs in a fresh-context subagent, never in the driving session.** The plan debate (Stage 0b), unit tests (Stage 1b), the e2e run and its triage (Stage 3), code review (Stage 4), browser QC (Stage 6), the senior gate (Stage 7), and a re-triage of CI that stayed red after a fix (Stage 10) are each dispatched with the Agent tool to a subagent that starts with an empty context and receives only artifacts it can verify itself — working directory, lane spec, diff range, commands, and the other agents' reports verbatim, never the driving session's paraphrase of why a finding was fine. The stages the driving session keeps are the ones that *do* rather than judge: intake, implementation, the mechanical gates, publishing, the CI/PR watch, and applying every fix the judges ask for. `subagent_type: fork` is explicitly forbidden for these: a fork inherits the implementing session's context, so it inherits the belief that the code is already correct. The driving session implements and applies fixes; it never grades its own work. Stages 1b/3 use the generic `general-purpose` type (nothing to install). Stage 4 uses the generic `Code Reviewer` type as its catch-all, plus — in parallel, routed by which of `server/`, `client/` the diff touches — the plugin-qualified `agenthub:backend-reviewer` / `agenthub:frontend-reviewer` domain reviewers (nothing to install; `agenthub:` addressing works from any lane). Stages 6/7 use the lane-installed `qc-local`/`senior-gate-reviewer` agents.
### Getting the skill (nothing to do, if you run the plugin)
The skill lives in `skills/ship-feature-lane/`, and the repo root **is** the `agenthub` plugin root (`"source": "./"`), so `skills/` is the plugin's own skills directory. Anyone with the `agenthub` plugin installed already has it in every session, from any lane's working directory, as **`/agenthub:ship-feature-lane`** — with the bare `/ship-feature-lane` working as an alias unless another skill or command claims that name.
Only a plain checkout without the plugin needs the fallback:
```bash
agenthub skills install
```
Copies `skills/ship-feature-lane/` into `~/.claude/skills/ship-feature-lane/` (overwrites on reinstall — run it again after pulling an update to the skill), which restores the bare `/ship-feature-lane` name. One-time per machine, same as `agenthub lanes agents install` is one-time per lane.
**Agents come from the same plugin, under two names.** `qc-local` and `senior-gate-reviewer` live in `agents/` at the repo root, so the plugin exposes them as `agenthub:qc-local` / `agenthub:senior-gate-reviewer`. `agenthub lanes agents install` copies those same files into the lane's own `.claude/agents/` — the highest-priority agent source — which is what makes the bare `subagent_type: qc-local` the skill prefers resolve inside the lane. Either name reaches the same definition; the skill falls back to the `agenthub:` form when the lane copy is missing.
### Invoking the skill
```bash
# Inside a lane's working directory:
/ship-feature-lane <requirement>
```
The skill frontloads all clarifying questions once, then runs unattended. The only interactive touchpoints are **Stage 0 (Q&A intake)** and **merging the PR on GitHub**; everything else runs to completion or escalates with a `blocked` status visible on the dashboard. Progress is declared via `agenthub stage` commands at every step.
### Current status: stages 0–8, 10–12, 14 work; stage 9 deferred, stage 13 partially wired (CI-wait works, dev-QC doesn't); stages 6–7 agent-gated
**Stages implemented now:**
- **0-8**: Intake & frontloaded Q&A → plan → implementation → independent unit tests (1b) → gates+preflight → e2e on feature branch → code review → QC plan → QC → senior gate → publish PR
- **10-12**: CI watch on the PR → report → watch PR until merge (gated fix-loop re-entries on review feedback)
- **14**: Done
**Stages currently hardcoded skipped** (pending F's integrations):
- **9 (Ticket)**: Ticket-filing integration not yet built — this stage is skipped entirely.
**Partially wired:**
- **13 (Post-merge verification)**: CI-wait half now runs for real via `agenthub lanes ci status`. The dev-QC half (QCing the deployed site) is still unavailable — Stage 13 always ends noting that gap even when CI-wait passes clean.
**Stages 6 and 7 are now unblocked** — run `agenthub lanes agents install` once per lane (see "Installing the QC/gate agents" below) before a lane's first run through Stage 6. A lane that reaches Stage 6/7 without having installed the agents will fail to find the `qc-local`/`senior-gate-reviewer` subagent type; install and re-run.
See [the skill text](../skills/ship-feature-lane/SKILL.md) for the full pipeline definition.
The commands below are primitives a driving session (or you) calls explicitly — AgentHub never sequences them.
### QC boot flag and profile integration
@@ -1757,7 +1550,7 @@ These environment variables are passed to the profile's `boot` hook during `agen
### Dev preflight and merge safety: sync-base
`agenthub lanes sync-base` is the ONE sanctioned merge in the pipeline — `origin/development` into a feature branch — used at Stages 2, 8, and 12. Three modes:
`agenthub lanes sync-base` is the ONE sanctioned merge a session runs from the CLI — `origin/development` into a feature branch. Three modes:
```bash
agenthub lanes sync-base --check feat/<slug> # read-only preflight: fetch + collision check + DEV_DELTA/DEV_OVERLAP
@@ -1777,34 +1570,9 @@ GENERATED_MERGE_PATHS="api/openapi.json api/client.ts"
`MIGRATIONS_DIR` enables the collision preflight against a numbered-migrations directory. `GENERATED_MERGE_PATHS` gives the listed files a keep-ours merge driver (never hand-merged) and folds the profile's `regen` hook output into the sync commit — the single most common cross-lane conflict, for a repo that generates an API contract/client.
### Installing the QC/gate agents: agents install
Stage 6 (browser QC) and Stage 7 (senior GO/NO-GO gate) run as subagents — `qc-local` and `senior-gate-reviewer`. The plugin already ships them as `agenthub:qc-local` / `agenthub:senior-gate-reviewer`; installing them into the lane's own `.claude/agents/` is what makes the bare names work there:
```bash
agenthub lanes agents install
```
Writes both agent definitions (from the repo's own `agents/`, the same files the plugin ships) into `<lane>/.claude/agents/` and adds that directory to the lane's local `.git/info/exclude` (never the tracked `.gitignore` — this is a per-clone runtime concern, not an app-repo change). Idempotent and never automatic, the same shape as `agenthub lanes proof-link` — a session installs the agents explicitly, once, before a lane's first run through Stage 6/7 (or after a AgentHub upgrade ships updated templates — reinstalling overwrites, it doesn't merge).
**On a `codex` lane the same command installs something else.** Codex never
reads `.claude/agents/`, so copying agent definitions there would be dead
files. Instead it writes the stage-declaration block into
`<lane>/AGENTS.md` — the project doc Codex *does* load from the working
directory — delimited by `<!-- agenthub:stage:start -->` / `<!-- agenthub:stage:end -->`
so a reinstall replaces exactly that block and nothing else. The file is
appended to when it already exists (your own prose is preserved) and created
when it does not; `installed` comes back as `["AGENTS.md"]`. This is the lever
that gets a codex session to supply the *evidence* auto-advance cannot — see
"Stage detection".
**Credentials are not embedded.** Unlike Shipyard's original per-lane agent generation, these templates carry no QA account credentials — this repo has no seeded-QA-account system yet. `qc-local` degrades gracefully: if it hits a login page with no credentials block present, it reports `LOCAL-QC: FAIL — login required, no seed-account mechanism configured for this profile` rather than guessing.
**`ticketer`, `dev-qc`, and `pr-reviewer`** are not ported yet — `ticketer` is invoked by Stage 9 (skipped), and `dev-qc` by Stage 13's dev-QC half (unavailable); `pr-reviewer` isn't referenced anywhere in this skill's text.
### Syncing MCP servers: mcp sync
A lane needs the same MCP servers (Playwright, a local-QC server) as its source repo to run Stage 3/6. `agenthub lanes mcp sync` gives it those:
A lane needs the same MCP servers (Playwright, a local-QC server) as its source repo to run e2e or browser QC. `agenthub lanes mcp sync` gives it those:
```bash
agenthub lanes mcp sync
@@ -1826,11 +1594,11 @@ A profile can declare `.agenthub/profile/integrations.env` with `TRACKER_ENABLED
agenthub lanes integration tracker # exit 0 = on, 1 = off
```
This only reports what the PROFILE wants — it doesn't file a ticket, run dev-QC, or wait on CI. The agent that would act on an enabled `dev_qc` toggle isn't built yet, and neither is a `tracker` ticketer — `ship-feature-lane`'s Stage 9 stays skipped and Stage 13's dev-QC half stays unavailable regardless of what those two toggles read. `ci_wait`'s consumer is `agenthub lanes ci status` (added — see the command reference below); Stage 13's CI-wait half now honors it for real. The CLI command and `GET /api/lanes/:id/integrations/:name` are the only readouts: the lane card used to carry a row of three badges for these, and it no longer does — two of the three could never be anything but decoration, and a badge that reports a toggle nothing acts on costs a row of card height to say nothing.
This only reports what the PROFILE wants — it doesn't file a ticket, run dev-QC, or wait on CI. Nothing in AgentHub acts on an enabled `tracker` or `dev_qc` toggle. `ci_wait`'s consumer is `agenthub lanes ci status` (below). The CLI command and `GET /api/lanes/:id/integrations/:name` are the only readouts: the lane card used to carry a row of three badges for these, and it no longer does — two of the three could never be anything but decoration, and a badge that reports a toggle nothing acts on costs a row of card height to say nothing.
### Post-merge CI status: agenthub lanes ci status
Check GitHub Actions status for a commit SHA or branch ref — used by Stage 13's CI-wait loop:
Check GitHub Actions status for a commit SHA or branch ref — one shot, so a session waiting on CI polls it:
```bash
agenthub lanes ci status <branch-or-sha> [<id>]
@@ -1838,87 +1606,6 @@ agenthub lanes ci status <branch-or-sha> [<id>]
Exit codes: `0` = all checks passed, `1` = at least one check failed, `3` = checks pending or in progress. The `<id>` parameter is optional and filters results to a specific lane if provided; if omitted, it's not needed.
### Pipeline template: ship-feature (16 node stages)
The skill uses the `ship-feature` pipeline template, which defines the following 16 stages (node IDs):
1. **intake** — frontloaded Q&A and feature activation
2. **plan** — investigation and plan debate
3. **implementing** — TDD implementation
4. **gates** — CI gates + preflight check
5. **e2e-feature** — run e2e on feature branch
6. **e2e-feature-passed** — e2e result gate
7. **review** — code review
8. **qc-plan** — bound QC scope
9. **qc** — browser QC (agent-gated until qc-local lands)
10. **gate** — senior GO/NO-GO gate (agent-gated until senior-gate-reviewer lands)
11. **publishing** — push branch + open/update PR
12. **pr-open** — PR open and published
13. **reported** — report posted
14. **watching-pr** — watch for comments, conflicts, merge
15. **merged** — PR merged, post-verify transition
16. **done** — pipeline complete
The Workspace page (`/run`) displays this template with nodes rendered in five states: `failed` (rejected), `current` (now), `done` (with evidence), `passed-no-evidence` (claimed or skipped), and `pending` (not reached).
### More stage names than nodes
Each node carries aliases, and they do two different jobs. Some absorb a
near-miss (`implement` for `implementing`). Others are **sub-states**: a name
the skill declares to say *why* the lane is sitting on a node, without adding a
node to the map.
This is the shape Shipyard converged on — its dashboard renders 13 nodes while
its `PHASES` table folds roughly 35 stage names onto them. A pipeline map is
read at a glance across many lanes at once, so it stays coarse; the stage name
is read one lane at a time, so it can be specific.
| Node | Near-miss aliases | Sub-states the skill declares |
|---|---|---|
| `intake` | `assigned`, `claimed`, `start` | `bootstrapping` |
| `plan` | `planning`, `brainstorm`, `design` | — |
| `implementing` | `implement`, `coding`, `build` | — |
| `gates` | `pre-push-gate`, `tests` | `migration-collision`, `sync-conflict` |
| `e2e-feature` | `e2e`, `live` | `booting`, `e2e-scoped` |
| `e2e-feature-passed` | `e2e-passed` | — |
| `review` | `reviewing`, `code-review`, `self-review` | — |
| `qc-plan` | — | — |
| `qc` | — | — |
| `gate` | `sr-gate`, `verify`, `verification` | `gate-blocked` |
| `publishing` | `push` | — |
| `pr-open` | `ship`, `pr`, `push-conflict` | `push-revalidate` |
| `reported` | — | — |
| `watching-pr` | — | `pr-comment-fix` |
| `merged` | — | — |
| `done` | `complete`, `completed` | — |
50 names over 16 nodes. Every one of them has a **source**: the skill declares
it, or `default.json` uses it (an agent moving between pipelines will type
what the other one taught it), or Shipyard's `PHASES` lists it. An alias with
no source is not "flexibility" — it is a synonym someone imagined, and the
`agenthub stage` warning already catches a name that resolves to nothing, which is
better feedback than silently absorbing every plausible spelling. Twelve
sourceless aliases were written and then cut for exactly this reason.
Two constraints on this:
- **No alias may collide** with another node's id or alias. `phaseIdx` takes the
FIRST match, so a duplicate would silently resolve a declaration onto the
wrong node. A test asserts the whole template is collision-free.
- **Aliases of one node share one record slot.** `lane.stages` is keyed by the
declared string, and `stageRecords` resolves each key onto its node — so
declaring `migration-collision` and then `gates` leaves ONE record for that
node (the canonical `gates` one wins). A sub-state that needs to keep its own
`--evidence` separately has to be a real node, not an alias.
`integrate`, `dev-gates`, `e2e-on-dev` and `push-dev` are deliberately **not**
nodes here. Shipyard had them and retired them on 2026-07-16 (see the comment
above `PHASES` in its `dashboard/src/lib/constants.js`); it now folds those
names into the surviving phases so old feature cards still render. AgentHub never
shipped them, so there is nothing to fold.
These nodes also carry `detect` rules; see "Stage detection → Where the rules live".
## Orchestration: what AgentHub does NOT do
**AgentHub does not chain, queue, retry, or evaluate gates.**
+29 -80
View File
@@ -87,28 +87,22 @@ checkout unnecessary.
| The `agenthub` CLI | a launcher written to `~/.local/bin/agenthub` |
| The dashboard UI (`/run` and every other client route) | built into the runtime dir by the bootstrap, so it works the moment `claude` starts |
| `/agenthub-doctor`, `/agenthub-update`, `/agenthub-open` | `plugins/agenthub/commands/` |
| `/ship-full`, `/ship-quick` and one command per pipeline node (`/intake`, `/plan`, `/implement`, `/tests`, `/e2e`, `/review`, `/qc`, `/gate`, `/publishing`, `/pr-open`, `/done`, …) | `plugins/agenthub/commands/`, one file per name |
| The skills (`ship-feature-lane`, `ship-feature`, `repo-onboarding`, `debug-live-issue`, `update-project-docs`, `file-headers`) | `skills/` at the repo root — which IS the plugin root, so they are auto-discovered as plugin skills |
| The agents (`qc-local`, `senior-gate-reviewer`, `backend-reviewer`, `frontend-reviewer`) | `agents/` at the repo root, auto-discovered the same way — exposed as `agenthub:<name>` |
| The skills (`repo-onboarding`, `debug-live-issue`, `update-project-docs`, `file-headers`) | `skills/` at the repo root — which IS the plugin root, so they are auto-discovered as plugin skills |
Plugin skills are namespaced: they are invoked as `/agenthub:<name>`, with the bare
`/<name>` working as an alias unless another skill or command claims that name.
This is why `skills/` sits at the repo root instead of `.claude/skills/` — the
latter only loads for a session whose cwd is inside this checkout, which is
useless for a lane working in a different repo. `agenthub skills install` survives
as the fallback for a plain checkout without the plugin.
useless for a lane working in a different repo.
**The agents ship the same way, from the same files.** `agents/` at the repo
root holds all four (`qc-local`, `senior-gate-reviewer`, `backend-reviewer`,
`frontend-reviewer`), so the plugin exposes them as
`agenthub:<name>`. `agenthub lanes agents install` copies `qc-local` +
`senior-gate-reviewer` from that same directory into a lane's own
`.claude/agents/` — the highest-priority agent source — which is what makes the
bare `subagent_type: qc-local` in the pipeline skill resolve there. One source
file, two ways to reach it; the skill names the bare form first and falls back
to the `agenthub:` form. On a `codex` lane the same command installs the
`<!-- agenthub:stage:start -->` block in the lane's `AGENTS.md` instead — Codex
never reads `.claude/agents/`.
That is the whole plugin: the hooks, the CLI, the dashboard, three commands and
four skills. It ships **no subagents** and no pipeline template, and it neither
depends on nor installs any other plugin (Superpowers included). The pipeline
slash commands, the `ship-feature` / `ship-feature-lane` skills and the
`qc-local` / `senior-gate-reviewer` / `backend-reviewer` / `frontend-reviewer`
agents were removed; the stage/pipeline machinery they drove stays in the
dashboard, dormant until you install a template (see `docs/LANES.md` §
"Pipeline stages and the five node states").
Because the plugin ships the hooks itself, `npm run install-hooks` is not needed
for plugin users — and must not be run alongside it. Events carry no id, so two
@@ -137,10 +131,11 @@ waits on an install:
7. **CLI** — write the `~/.local/bin/agenthub` launcher, never clobbering a `agenthub` the bootstrap did not write. It pins the node that ran the bootstrap and falls back to `node` on `PATH` when that binary is gone (a Homebrew Cellar or nvm path deleted by an upgrade).
8. **UI build** — `client/` is copied into the runtime dir and built there (`npm ci --include=dev`, falling back to `npm install --include=dev`, then `npm run build`), landing in `runtime/client-dist` — the same directory the server serves from. `--include=dev` is required, not tidy: the entire build toolchain (`vite`, `typescript`, `@vitejs/plugin-react`, `tailwindcss`, `@types/*`) is a devDependency, and npm reads an inherited `NODE_ENV=production` as `--omit=dev`. Every bootstrap descended from the running server carries that env — the self-update chain, and any `SessionStart` fired by a `claude` inside a tmux pane the server started — so without the flag the install drops `vite` and the build dies on missing types. Skipped when a bundle for the current version already exists; a failure here does not fail the bootstrap (the API still works, and `/agenthub-open` can retry) but does mean `/run` 404s until it's fixed — and when a bundle from the PREVIOUS version is still on disk the failure is quieter still: the dashboard keeps serving the old UI against the new API, visible only as the Settings page's `UI build vX (rebuild client to match)` line.
9. **Server** — on Linux with `systemd --user` available, install/refresh a
`agenthub.service` unit (see [Auto-start on boot](#auto-start-on-boot)) instead
`agenthub.service` unit — on macOS with a GUI login, the
`io.smartgift.agenthub` LaunchAgent (see [Auto-start on boot](#auto-start-on-boot)) — instead
of a bare spawn, so the server is supervised and comes back after a reboot
with no Claude Code session involved. Everywhere else (macOS, Windows, or
no systemd), spawn `server/index.js` detached, with `NODE_PATH` at the
with no Claude Code session involved. Everywhere else (Windows, no
systemd, a Mac reached only over SSH), spawn `server/index.js` detached, with `NODE_PATH` at the
runtime `node_modules` and `DASHBOARD_CLIENT_DIST` at the runtime
`client-dist` — scoped to this session, same as before this fell back to
systemd.
@@ -233,15 +228,26 @@ anyone logs in; when that needs elevated rights, it's skipped silently (check
`agenthub.service` unit not written by this bootstrap is left untouched, and the
server falls back to the old per-session detached spawn instead.
On macOS, Windows, or a Linux box without systemd, nothing changes: the
On macOS the same steps write a LaunchAgent instead
(`~/Library/LaunchAgents/io.smartgift.agenthub.plist`, `scripts/launchd-service.js`;
`scripts/service-manager.js` picks the one for the platform, and both export the
same API). `KeepAlive` plays `Restart=always`, `AbandonProcessGroup` keeps the
lane panes' tmux server alive across a restart, output goes to
`~/Library/Logs/agenthub.log`, and the hand-over restart is `launchctl bootout`
+ `bootstrap` (a `kickstart` would keep the old plist). If that bootstrap fails
and no server is left running, the bootstrap starts one detached. A LaunchAgent
needs the user's GUI login; without one (SSH only) `launchctl print gui/<uid>`
fails and the server falls back to the detached spawn below.
On Windows, a Linux box without systemd, or a Mac with no GUI login, the
server is a detached spawn started fresh on the next `SessionStart` after a
reboot, same as always. That spawn inherits the Claude Code session's env, so
`server/index.js` deletes the parent-session variables (`CLAUDECODE`,
`CLAUDE_CODE_SESSION_ID`, `CLAUDE_CODE_MESSAGING_*`, `CLAUDE_PLUGIN_ROOT`, …)
before anything else runs — otherwise tmux hands them to every lane pane. It is
a denylist: user configuration such as `CLAUDE_CONFIG_DIR`,
`CLAUDE_CODE_USE_BEDROCK` and `ANTHROPIC_*` passes through. There is no
launchd agent; see [INSTALL.md § macOS](../INSTALL.md#macos).
`CLAUDE_CODE_USE_BEDROCK` and `ANTHROPIC_*` passes through. See
[INSTALL.md § macOS](../INSTALL.md#macos).
### Who may stop the server
@@ -304,66 +310,9 @@ courtesy of `Restart=always`.
| Command | Does |
|---|---|
| `/agenthub-doctor` | Node version, bootstrap state, runtime deps, server liveness, duplicate hooks, CLI launcher + PATH, **systemd** (`WARN` when the unit names a retired plugin root — the dashboard will not survive a reboot — or when it is installed but stopped; no unit at all is fine), **tmux** (`WARN` when absent — only the run console, `agenthub lanes shell` and session reloads need it), **skill plugins** (see below), UI bundle |
| `/agenthub-doctor` | Node version, bootstrap state, runtime deps, server liveness, duplicate hooks, CLI launcher + PATH, **systemd** (`WARN` when the unit names a retired plugin root — the dashboard will not survive a reboot — or when it is installed but stopped; no unit at all is fine), **tmux** (`WARN` when absent — only the run console, `agenthub lanes shell` and session reloads need it), UI bundle |
| `/agenthub-update` | Pull the latest `agenthub` release via `claude plugin marketplace update` + `claude plugin update agenthub@<marketplace> -y`, then reinstall dependencies and restart the server (`plugin-bootstrap.js --force`). The plugin pull needs a manual `/reload-plugins` afterward to take effect in the current session — not scriptable from a command. |
| `/agenthub-open` | Rebuild the UI bundle and print the dashboard URL. Re-runs the bootstrap first when the server is down or still executing a plugin root that a mid-session `/plugin` update retired, so a fresh bundle never talks to an older server's routes |
| `/ship-full <requirement>` | Put the lane on the 16-node `ship-feature` template, then run `/agenthub:ship-feature-lane` **in this session**. The in-session twin of `agenthub ship-full` (which spawns its own `claude` from a terminal) |
| `/ship-quick <requirement>` | The same for the 8-node `default` template and `/agenthub:ship-feature` — stops at review/gate, no PR, no browser QC |
| One per pipeline node: `/intake`, `/plan`, `/implement`, `/tests`, `/e2e`, `/e2e-passed`, `/review`, `/qc-plan`, `/qc`, `/gate`, `/publishing`, `/pr-open`, `/reported`, `/watching-pr`, `/merged`, `/done` | Run just that node's own `command`, resolved through `agenthub lanes node <id> --print` against whichever template the lane is on (matched by id **or alias**, so `/implement` works on `default`'s `implement` and `ship-feature`'s `implementing`). A slash-command node is invoked in the current session, never as a nested `claude`; anything else runs as a shell argv in the lane's cwd. None of them declares a stage |
#### The `Skill plugins` row
Derived from the loaded pipeline templates, not hardcoded: every `/plugin:skill`
string a template names — as the pipeline's own `skill` or as one node's
`command` — has to come from an installed, enabled plugin. Today that means
**`superpowers`**, which `/agenthub:ship-feature` and `/agenthub:ship-feature-lane`
drive step by step (`brainstorming`, `writing-plans`,
`test-driven-development`, `verification-before-completion`,
`finishing-a-development-branch`). The `review` node is the exception: it names
the bare `/code-review`, Claude Code's own review skill, which carries no
`plugin:` prefix and so requires nothing to be installed. Install it
with `claude plugin install superpowers@claude-plugins-official`.
The row is a **WARN, never a FAIL**: the dashboard, hooks and CLI all work
without it, and only those two pipeline skills stop partway. A plugin listed but
explicitly disabled counts as missing — Claude Code will not resolve its skills.
The skills present as plain user skills under `~/.claude/skills/` count as
satisfied, so a hand-copied setup is not reported as broken. A custom template
in `DASHBOARD_PIPELINES_DIR` naming some other plugin's command is checked the
same way.
Both the derivation and the missing/satisfied rules live in
`server/lib/skill-plugins.js`, shared with the bootstrap below so the row and
the install can never disagree about what is missing.
#### Automatic install, and why it is allowlisted
`plugin-bootstrap.js` installs the missing plugins itself, at the very end of
its **detached worker** — never in the 10 s `SessionStart` hook, because the
install clones from the network. It runs `claude plugin install
superpowers@claude-plugins-official --scope user -y`; if that fails it registers
the marketplace (`claude plugin marketplace add anthropics/claude-plugins-official`)
and retries exactly once. Failure is logged with the manual command and nothing
throws — the dashboard, hooks and CLI do not need these plugins.
The result is recorded as `skillPluginsSettled` in the bootstrap's `state.json`,
which is also part of `fastPathOk()`: the check runs **once** per install, then
the hot path reads one flag. `/agenthub-update` (`--force`) is the retry.
`AGENTHUB_AUTO_INSTALL_PLUGINS=0` (or `false`/`off`) turns it off entirely.
An installed plugin only resolves in the **current** session after
`/reload-plugins`; a new session picks it up on its own. The log says so, since
the worker is detached and cannot tell the session that started it.
**Reporting is derived, installing is allowlisted.** The row above reads plugin
names out of the templates, which is right for a report. Installing from the
same source would not be: a template is a file anyone can drop into
`DASHBOARD_PIPELINES_DIR`, so it would turn "edit a JSON file" into "run this
vendor's plugin install command on the next session". Auto-install therefore
consults `AUTO_INSTALLABLE`, a fixed map in `server/lib/skill-plugins.js`, and
skips every other requirement — visible in the doctor, never installed. Adding
an entry there is a decision to install someone else's code on a user's machine
without asking; it belongs in a review, not in a config file.
### Where things live
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""Nhúng mọi ảnh cục bộ của slide vào thẳng file HTML dưới dạng data URI.
Đọc agenthub-introduction.html, thay từng src="*.png" bằng chuỗi base64, ghi ra
agenthub-introduction-standalone.html - một file duy nhất, gửi cho ai cũng thấy ảnh.
Chạy lại sau mỗi lần sửa slide.
@author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
"""
import base64
import mimetypes
import pathlib
import re
import sys
import urllib.parse
SRC = pathlib.Path(__file__).parent / "agenthub-introduction.html"
OUT = SRC.with_name("agenthub-introduction-standalone.html")
def inline(match):
raw = match.group(1)
if raw.startswith(("data:", "http://", "https://")):
return match.group(0)
path = SRC.parent / urllib.parse.unquote(raw)
if not path.is_file():
sys.exit(f"thiếu ảnh: {path}")
mime = mimetypes.guess_type(path.name)[0] or "application/octet-stream"
b64 = base64.b64encode(path.read_bytes()).decode()
return f'src="data:{mime};base64,{b64}"'
html = SRC.read_text(encoding="utf-8")
OUT.write_text(re.sub(r'src="([^"]+)"', inline, html), encoding="utf-8")
print(f"{OUT.name} - {OUT.stat().st_size / 1024 / 1024:.1f} MB")
+4 -1
View File
@@ -3,7 +3,7 @@
openapi: 3.0.3
info:
title: Agent Dashboard for Claude Code API
version: 1.8.9
version: 1.8.12
description: HTTP API for real-time Claude Code session monitoring, agent lifecycle tracking, analytics, pricing, hooks ingestion, and workflow intelligence.
contact:
name: Nguyễn Ngọc Trí Vĩ
@@ -11253,6 +11253,9 @@ paths:
hunk:
type: string
description: stage-hunk, discard-hunk; the hunk's `@@` line as the diff returned it. The server re-reads the diff and applies git's own text of that hunk; a hunk no longer present is 409 EHUNKGONE.
block:
type: integer
description: stage-hunk, discard-hunk (optional); act on only the block-th run of consecutive +/- lines inside that hunk — the other runs are folded into context. Out of range is 409 EHUNKGONE.
context:
type: integer
description: stage-hunk, discard-hunk; the context the hunk was read at.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "agenthub",
"version": "1.8.9",
"version": "1.8.12",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "agenthub",
"version": "1.8.9",
"version": "1.8.12",
"hasInstallScript": true,
"license": "UNLICENSED",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "agenthub",
"version": "1.8.9",
"version": "1.8.12",
"bin": {
"agenthub": "bin/agenthub.js"
},
@@ -25,12 +25,6 @@ Print the output verbatim, then add at most three lines of guidance based on the
- `FAIL npm` or `FAIL Disk` → nothing else in the report can be trusted until
these are fixed; both silently truncate installs.
- `WARN agenthub CLI` → print the exact `export PATH=...` line from the output.
- `WARN Skill plugins` → the pipelines name slash commands no installed plugin
provides. The dashboard is unaffected; `/agenthub:ship-feature(-lane)` is what
stops partway. The bootstrap normally installs these itself, so this row also
means that attempt has not run or did not succeed — say `/agenthub-update` retries
it, and print the `claude plugin install …` line from the output as the manual
route.
- `WARN systemd` → when it says the unit names a **previous plugin version**,
the dashboard is running now but will NOT come back after a reboot. Starting
a new Claude Code session repairs it; print the `--force` command from the
-23
View File
@@ -1,23 +0,0 @@
---
description: Declare the lane done
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `done` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node done $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Declare e2e passed (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `e2e-passed` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node e2e-passed $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: E2e on the feature branch (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `e2e` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node e2e $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Senior GO/NO-GO gate
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `gate` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node gate $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Implement (TDD)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `implement` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node implement $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Intake — brainstorm the requirement
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `intake` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node intake $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Declare merged (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `merged` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node merged $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Plan — write the implementation plan
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `plan` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node plan $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Open the PR
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `pr-open` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node pr-open $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Publish the branch
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `publishing` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node publishing $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Declare the QC plan (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `qc-plan` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node qc-plan $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Browser QC + proof gallery (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `qc` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node qc $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Declare the run reported (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `reported` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node reported $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Code review
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `review` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node review $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Run the full 16-stage lane pipeline (implement → gates → e2e → review → QC → senior gate → PR, watched until merged)
argument-hint: <requirement>
allowed-tools: Bash(agenthub lanes pipeline:*)
---
Put this lane on the 16-node `ship-feature` template first, so the dashboard
renders the right node count from the first stage rather than after the skill
self-corrects:
!`agenthub lanes pipeline ship-feature`
Then run the pipeline **in this session** by invoking `/agenthub:ship-feature-lane`
with this requirement:
$ARGUMENTS
- No requirement given → ask for one. Never guess what to build.
- The switch above failed (no lane owns this directory) → say so and stop; the
skill has no lane to report stages against.
This is the in-session twin of `agenthub ship-full "<requirement>"`, which does the
same two steps from a terminal by spawning its own `claude`.
-23
View File
@@ -1,23 +0,0 @@
---
description: Run the 8-stage in-repo pipeline (plan → implement → tests → review → gate → ship). No PR, no browser QC
argument-hint: <requirement>
allowed-tools: Bash(agenthub lanes pipeline:*)
---
Put this lane on the 8-node `default` template first, so the dashboard renders
the right node count from the first stage:
!`agenthub lanes pipeline default`
Then run the pipeline **in this session** by invoking `/agenthub:ship-feature` with
this requirement:
$ARGUMENTS
- No requirement given → ask for one. Never guess what to build.
- The switch above failed (no lane owns this directory) → say so and stop; the
skill has no lane to report stages against.
This is the in-session twin of `agenthub ship-quick "<requirement>"`. It stops at
review/gate: no PR is opened and no browser QC runs — use `/ship-full` when the
work should reach reviewers.
-23
View File
@@ -1,23 +0,0 @@
---
description: Tests / pre-push CI gates
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `tests` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node tests $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
-23
View File
@@ -1,23 +0,0 @@
---
description: Watch the PR / CI (ship-feature only)
argument-hint: [extra prompt words]
allowed-tools: Bash(agenthub lanes node:*)
---
The command this lane pipeline template declares for its `watching-pr` node, resolved
against whichever template the lane is actually on (matched by id or alias):
!`agenthub lanes node watching-pr $ARGUMENTS --print`
Run that here, in THIS session - never start a nested `claude` process:
- Line reads `cd <dir> && "claude" "<slash command>"` -> invoke that slash
command yourself, passing any extra words as its argument.
- Anything else is a shell argv -> run it with Bash from `<dir>`.
- Line is an error (`no node ...`, `declares no command`, no lane owns this
directory) -> print it verbatim and stop. Do not guess a substitute.
Do NOT call `agenthub stage` afterwards: a command running is not proof the node
passed. Declare the stage when the work is actually done. (The exception is a
node whose command already IS `agenthub stage <id>` - there the declaration is the
whole step.)
+241
View File
@@ -0,0 +1,241 @@
#!/usr/bin/env node
/**
* @file launchd-service.js
* @description The macOS twin of `systemd-service.js`: a per-user LaunchAgent
* (`~/Library/LaunchAgents/io.smartgift.<name>.plist`) that starts the AgentHub
* dashboard at login and keeps it running, without Claude Code being opened
* first. Same exports and the same return values as the systemd module, so
* `service-manager.js` can hand either one to the bootstrap, the CLI and the
* doctor. Every `launchctl` call goes through one seam (`__setExecImpl`) so
* tests never touch a real launchd.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const fs = require("fs");
const os = require("os");
const path = require("path");
const { spawnSync } = require("child_process");
const MARKER = "<!-- agenthub-managed-unit — regenerated on install, do not edit by hand -->";
const kind = "launchd";
const label = "LaunchAgent";
function jobLabel(name) {
return `io.smartgift.${name}`;
}
function unitPath(name) {
return path.join(os.homedir(), "Library", "LaunchAgents", `${jobLabel(name)}.plist`);
}
function logPath() {
return path.join(os.homedir(), "Library", "Logs", "agenthub.log");
}
function domain() {
return `gui/${process.getuid()}`;
}
let execImpl = (args, opts) => spawnSync("launchctl", args, opts);
function __setExecImpl(fn) {
execImpl = fn;
}
function __reset() {
execImpl = (args, opts) => spawnSync("launchctl", args, opts);
}
function launchctl(args) {
return execImpl(args, { encoding: "utf8", stdio: "pipe" });
}
/**
* A LaunchAgent lives in the user's GUI domain, which exists only while that
* user is logged in at the console. Over a bare SSH login there is none, and
* the caller falls back to its detached spawn.
*/
function systemctlAvailable() {
if (process.platform !== "darwin") return false;
return launchctl(["print", domain()]).status === 0;
}
function readPlist(name) {
try {
return fs.readFileSync(unitPath(name), "utf8");
} catch {
return null;
}
}
function unitIsOurs(name) {
const body = readPlist(name);
return !!body && body.includes(MARKER);
}
const xmlEscape = (s) =>
String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const xmlUnescape = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
function workingDirOf(body) {
const m = body.match(/<key>WorkingDirectory<\/key>\s*<string>([^<]*)<\/string>/);
return m ? xmlUnescape(m[1]) : null;
}
/** Same contract as the systemd twin: pure fs, never a foreign plist. */
function unitIsStale(name, root) {
const body = readPlist(name);
if (!body || !body.includes(MARKER)) return false;
return workingDirOf(body) !== root;
}
/** The directory the plist runs from — ours or not (the cache pruner's guard). */
function unitRoot(name) {
const body = readPlist(name);
return body ? workingDirOf(body) : null;
}
function isLoaded(name) {
return launchctl(["print", `${domain()}/${jobLabel(name)}`]).status === 0;
}
function unitIsActive(name) {
if (!systemctlAvailable()) return false;
const res = launchctl(["print", `${domain()}/${jobLabel(name)}`]);
return res.status === 0 && /^\s*state = running$/m.test(String(res.stdout || ""));
}
/**
* `argv` is the program and its arguments as separate strings (the systemd
* twin's `execStart` is one line; a path with a space would split here).
* `KeepAlive` true is `Restart=always`. `AbandonProcessGroup` keeps the lane
* panes alive: they run in a tmux server the dashboard spawned, and launchd
* otherwise kills a stopped job's whole process group — every running agent
* with it, on every update.
*/
function unitContent({ name, workingDir, argv, env }) {
const str = (v) => `<string>${xmlEscape(v)}</string>`;
const envLines = Object.entries(env)
.map(([k, v]) => `\t\t<key>${xmlEscape(k)}</key>\n\t\t${str(v)}`)
.join("\n");
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
${MARKER}
<plist version="1.0">
<dict>
<key>Label</key>
${str(jobLabel(name))}
<key>ProgramArguments</key>
<array>
${argv.map((a) => `\t\t${str(a)}`).join("\n")}
</array>
<key>WorkingDirectory</key>
${str(workingDir)}
<key>EnvironmentVariables</key>
<dict>
${envLines}
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>3</integer>
<key>AbandonProcessGroup</key>
<true/>
<key>StandardOutPath</key>
${str(logPath())}
<key>StandardErrorPath</key>
${str(logPath())}
</dict>
</plist>
`;
}
/**
* Writes the plist and clears any "disabled" override — and starts nothing.
* A loaded job keeps running its OLD definition until `restartUserService`;
* an unloaded one is picked up at the next login. Same split, same reason, as
* the systemd twin.
*
* @returns {"written"|"unchanged"|"foreign"|"unavailable"|"failed"}
*/
function writeUserService({ name, workingDir, argv, env = {} }) {
if (!systemctlAvailable()) return "unavailable";
const body = unitContent({ name, workingDir, argv, env });
const target = unitPath(name);
try {
const current = readPlist(name);
if (current !== null) {
if (!current.includes(MARKER)) return "foreign";
if (current === body) return "unchanged";
}
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.mkdirSync(path.dirname(logPath()), { recursive: true });
fs.writeFileSync(target, body, "utf8");
launchctl(["enable", `${domain()}/${jobLabel(name)}`]);
return "written";
} catch {
return "failed";
}
}
/**
* Reload the job from its plist. `kickstart -k` would restart the process but
* keep the definition launchd already holds — the old plugin root — so it is
* bootout + bootstrap. Unlike systemd, the caller is not reaped with the job:
* it runs in its own process group and the job abandons its group anyway.
*/
function restartUserService(name) {
if (!systemctlAvailable()) return "unavailable";
launchctl(["bootout", `${domain()}/${jobLabel(name)}`]); // not loaded: fine
const res = launchctl(["bootstrap", domain(), unitPath(name)]);
return res.status === 0 ? "restarted" : "failed";
}
/** Write, then load and start. For `agenthub service install` and a bootstrap
* that owns no running job. */
function installUserService(opts) {
const result = writeUserService(opts);
if (result === "written" || (result === "unchanged" && !isLoaded(opts.name))) {
if (restartUserService(opts.name) !== "restarted") return "failed";
} else if (result === "unchanged") {
launchctl(["kickstart", `${domain()}/${jobLabel(opts.name)}`]); // start if stopped
}
return result;
}
/** @returns {"removed"|"absent"|"foreign"|"unavailable"} */
function uninstallUserService(name) {
if (!systemctlAvailable()) return "unavailable";
const body = readPlist(name);
if (body === null) return "absent";
if (!body.includes(MARKER)) return "foreign";
launchctl(["bootout", `${domain()}/${jobLabel(name)}`]);
fs.rmSync(unitPath(name), { force: true });
return "removed";
}
/** A LaunchAgent starts at login by definition; there is no linger to grant. */
function enableLinger() {
return true;
}
module.exports = {
kind,
label,
systemctlAvailable,
unitIsOurs,
unitIsStale,
unitRoot,
unitIsActive,
writeUserService,
restartUserService,
installUserService,
uninstallUserService,
enableLinger,
unitPath,
logPath,
__setExecImpl,
__reset,
};
+23 -65
View File
@@ -9,7 +9,8 @@
* The worker installs runtime dependencies, removes hook entries left behind by
* an older `npm run install-hooks` (they would double-count every event), puts
* the `agenthub` CLI on PATH, and starts the dashboard server — as a systemd
* `--user` service when available (see `systemd-service.js`), so it survives
* `--user` service or a macOS LaunchAgent when available (see
* `service-manager.js`), so it survives
* reboots without Claude Code being opened first; otherwise a detached spawn
* scoped to this session, same as before.
*
@@ -160,16 +161,12 @@ function fastPathOk(rt = runtimeDir()) {
if (state.pluginRoot !== PLUGIN_ROOT) return false;
if (state.depsHash !== depsHash()) return false;
if (!fs.existsSync(path.join(rt, "node_modules"))) return false;
// A machine can be fully set up and still be missing the plugins the
// pipelines drive. Reading one recorded flag keeps this hot path cheap — the
// actual check (manifest + every user SKILL.md) runs once, in the worker.
if (!state.skillPluginsSettled) return false;
// A live server says nothing about whether it will come back. When our unit
// still names a previous plugin cache directory, everything looks healthy
// until the next reboot — and then the dashboard is simply gone, from a path
// Claude Code deleted long ago. Reading one file is cheap enough for a hot
// path; `unitIsStale` deliberately spawns nothing.
if (require("./systemd-service").unitIsStale("agenthub", PLUGIN_ROOT)) return false;
if (require("./service-manager").unitIsStale("agenthub", PLUGIN_ROOT)) return false;
// Leftover checkout hooks are the one defect that corrupts the DATA rather
// than the install: events carry no id, so a second handler doubles every
// event, every subagent row and every turn. `stripLegacyHooks` removes them —
@@ -499,46 +496,6 @@ function log(rt, line) {
}
}
/**
* Install the plugins AgentHub's pipelines drive but this machine cannot resolve —
* today `superpowers`, which `/agenthub:ship-feature(-lane)` calls step by step. A
* fresh `agenthub` install otherwise runs those skills partway and fails at the
* first call with no warning beforehand.
*
* Off by setting `AGENTHUB_AUTO_INSTALL_PLUGINS` to `0`, `false` or `off`; that
* leaves `/agenthub-doctor`'s WARN row as the only notice, which is the right
* behaviour for anyone who wants to choose their own plugins.
*
* One-shot: the outcome is recorded in the runtime state and the fast path
* takes it into account, so a machine with no network does not re-attempt a
* clone on every session. `/agenthub-update` (`--force`) retries.
*
* Best-effort throughout. Nothing here may throw or block: the dashboard,
* hooks and CLI all work without these plugins.
*
* @returns {"off"|"nothing-missing"|"installed"|"failed"|"error"} or the previously
* recorded outcome when this run had nothing to settle.
*/
function autoInstallSkillPlugins(rt, { force = false } = {}) {
const flag = process.env.AGENTHUB_AUTO_INSTALL_PLUGINS;
if (flag === "0" || flag === "false" || flag === "off") return "off";
// Return the PREVIOUS outcome, not a marker: writeState records whatever this
// returns, and overwriting "installed" with "already-settled" would lose the
// only record of what actually happened.
const settled = readState(rt)?.skillPluginsSettled;
if (!force && settled) return settled;
try {
const { autoInstallSkillPlugins: install } = require("../server/lib/skill-plugins");
const summary = install((line) => log(rt, line));
if (!summary.attempted.length) return "nothing-missing";
return summary.failed.length ? "failed" : "installed";
} catch (err) {
log(rt, `skill-plugin auto-install skipped: ${err.message}`);
return "error";
}
}
/* ------------------------------------------------------ plugin-cache pruning */
/** How many retired builds to leave behind, newest first, as a rollback cushion. */
@@ -591,7 +548,7 @@ function pruneRetiredPluginRoots(rt, root = PLUGIN_ROOT) {
/* no record to read — the other three protections still apply */
}
try {
const unitRoot = require("./systemd-service").unitRoot("agenthub");
const unitRoot = require("./service-manager").unitRoot("agenthub");
if (unitRoot) keep.add(path.resolve(unitRoot));
} catch {
/* best effort */
@@ -724,7 +681,7 @@ function bootstrap(rt = runtimeDir(), { force = false } = {}) {
log(rt, "built the dashboard UI bundle");
}
const svc = require("./systemd-service");
const svc = require("./service-manager");
// Who owns the running server decides how it may be retired. A unit of
// ours means systemd owns it — and this process is a descendant of that
// server, so it sits in the unit's cgroup. SIGTERM-ing the main process
@@ -763,6 +720,7 @@ function bootstrap(rt = runtimeDir(), { force = false } = {}) {
description: "AgentHub dashboard server (Claude Code plugin)",
workingDir: PLUGIN_ROOT,
execStart: `${process.execPath} ${path.join(PLUGIN_ROOT, "server", "index.js")}`,
argv: [process.execPath, path.join(PLUGIN_ROOT, "server", "index.js")],
env: {
NODE_ENV: "production",
NODE_PATH: path.join(rt, "node_modules"),
@@ -792,13 +750,14 @@ function bootstrap(rt = runtimeDir(), { force = false } = {}) {
log(
rt,
result === "unchanged"
? "systemd --user service already up to date"
? `${svc.label} already up to date`
: unitStale && !needsServer
? "repointed the systemd --user service at the current plugin version (it named a retired one)"
: "installed a systemd --user service — the dashboard now survives reboots without Claude Code"
? `repointed the ${svc.label} at the current plugin version (it named a retired one)`
: `installed a ${svc.label} — the dashboard now survives reboots without Claude Code`
);
} else if (needsServer) {
// No systemd (macOS/Windows/WSL without it), or the unit exists but
// No service manager (Windows, WSL without systemd, a Mac over SSH with
// no GUI login), or the unit exists but
// wasn't ours to touch — same detached-spawn fallback as before,
// scoped to this session only. Guarded by `needsServer`: entering this
// block for a stale unit alone must never spawn a second server onto
@@ -806,26 +765,17 @@ function bootstrap(rt = runtimeDir(), { force = false } = {}) {
const pid = startDashboard(rt);
log(
rt,
`started the dashboard server (pid ${pid})${result === "foreign" ? " — a foreign systemd unit named 'agenthub' already exists" : ""}`
`started the dashboard server (pid ${pid})${result === "foreign" ? ` — a foreign ${svc.label} named 'agenthub' already exists` : ""}`
);
}
}
// Last, and deliberately so: it clones from the network, and nothing above
// may wait on it. Runs here rather than in the foreground pass because this
// whole function is already detached from the 10 s SessionStart hook.
const skillPlugins = autoInstallSkillPlugins(rt, { force });
writeState(
{
pluginVersion: pluginVersion(),
depsHash: wantDeps,
pluginRoot: PLUGIN_ROOT,
claudeHome: getClaudeHome(),
// Settles the fast path: whatever the outcome, the next SessionStart
// must not spawn a worker just to retry a network clone. Cleared by
// `/agenthub-update` (force), which is the retry.
skillPluginsSettled: skillPlugins,
updatedAt: new Date().toISOString(),
},
rt
@@ -843,8 +793,17 @@ function bootstrap(rt = runtimeDir(), { force = false } = {}) {
// file is written and the lock is gone, so even being killed here leaves
// no debris and no half-recorded bootstrap.
if (pendingSystemdRestart) {
log(rt, "handing the server over to systemd (restarting the unit)");
require("./systemd-service").restartUserService("agenthub");
const svc = require("./service-manager");
log(rt, `handing the server over to ${svc.kind} (restarting the unit)`);
// On launchd the restart is bootout + bootstrap, and a failed bootstrap
// leaves NOTHING running (systemd's restart either happens or leaves the
// old server up). This process survives it there, so fall back.
if (svc.restartUserService("agenthub") === "failed" && !serverIsLive()) {
log(
rt,
`${svc.kind} could not start the server — started it detached (pid ${startDashboard(rt)})`
);
}
}
}
}
@@ -918,6 +877,5 @@ module.exports = {
livePids,
stopDashboard,
startDashboard,
autoInstallSkillPlugins,
bootstrap,
};
+14 -45
View File
@@ -6,10 +6,8 @@
* declared package, not just that node_modules exists), server liveness,
* duplicate hook entries (the one failure that silently doubles every token and
* cost figure), the `agenthub` CLI launcher and its PATH, the `tmux` binary
* every browser-started run depends on, whether the slash
* commands the pipeline templates name as node drivers are actually resolvable
* (the `superpowers` plugin, today), and the dashboard bundle — quoting the last
* build error when it is missing.
* every browser-started run depends on, and the dashboard bundle — quoting the
* last build error when it is missing.
* Read-only — it diagnoses, it never repairs.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -85,7 +83,6 @@ function diagnose() {
add(...cliStatus());
add(...systemdStatus());
add(...tmuxStatus());
add(...skillPluginStatus());
add(...dashboardUiStatus(rt));
@@ -190,37 +187,6 @@ function lastBuildError(logPath) {
return hit ? hit.trim().slice(0, 200) : null;
}
/**
* WARN (never FAIL) when a plugin the pipelines depend on cannot be resolved:
* the dashboard, hooks and CLI all work without it — only the pipeline
* skills that drive it stop partway, so this must not fail a doctor run.
*
* The requirement derivation and the missing/satisfied rules live in
* `server/lib/skill-plugins.js`, shared with the bootstrap that installs them.
*/
function skillPluginStatus() {
const skillPlugins = require("../server/lib/skill-plugins");
const required = skillPlugins.requiredSkillPlugins();
if (!required.size) return ["ok", "Skill plugins", "no pipeline names an external plugin"];
let missing;
try {
missing = skillPlugins.missingSkillPlugins();
} catch {
return ["warn", "Skill plugins", "could not read the installed-plugin manifest"];
}
if (!missing.length) {
return ["ok", "Skill plugins", `${[...required.keys()].sort().join(", ")} available`];
}
return [
"warn",
"Skill plugins",
`${missing.map((m) => `${m.name} (needed for ${m.skills.join(", ")})`).join("; ")} — ` +
`the pipelines name these commands; install with ` +
`claude plugin install ${missing.map((m) => m.autoInstall?.spec || m.name).join(" ")}`,
];
}
/**
* The failure this row exists for is silent by construction: a unit still
* naming a retired plugin cache directory keeps a running dashboard looking
@@ -233,16 +199,17 @@ function skillPluginStatus() {
* about.
*/
function systemdStatus() {
const svc = require("./systemd-service");
const svc = require("./service-manager");
const unit = svc.unitPath("agenthub");
const row = svc.kind;
if (!svc.unitIsOurs("agenthub")) {
if (fs.existsSync(unit)) {
return ["warn", "systemd", `${unit} exists but was not written by AgentHub — left untouched`];
return ["warn", row, `${unit} exists but was not written by AgentHub — left untouched`];
}
return [
"ok",
"systemd",
row,
svc.systemctlAvailable()
? "no unit — the server is started per session (install one with `agenthub service install`)"
: "not available on this platform — the server is started per session",
@@ -252,7 +219,7 @@ function systemdStatus() {
if (svc.unitIsStale("agenthub", PLUGIN_ROOT)) {
return [
"warn",
"systemd",
row,
`${unit} still points at a previous plugin version — the dashboard will NOT come back after a reboot. ` +
`Starting a new Claude Code session repairs it; or run: node ${path.join(PLUGIN_ROOT, "scripts", "plugin-bootstrap.js")} --force`,
];
@@ -261,19 +228,21 @@ function systemdStatus() {
if (!svc.unitIsActive("agenthub")) {
return [
"warn",
"systemd",
"unit is installed and current but not running — start it with `systemctl --user start agenthub`",
row,
svc.kind === "launchd"
? "LaunchAgent is installed and current but not running — start it with `agenthub service install`"
: "unit is installed and current but not running — start it with `systemctl --user start agenthub`",
];
}
return ["ok", "systemd", "unit is current and running — the dashboard survives reboots"];
return ["ok", row, `${svc.label} is current and running — the dashboard survives reboots`];
}
/**
* WARN (never FAIL) when `tmux` is absent: every run the dashboard starts is a
* tmux session (`server/lib/tmux.js`), so without the binary the run console,
* `agenthub lanes shell` and the session-reload keystrokes all fail — while
* sessions, analytics, lanes and the CLI keep working. Same reasoning as the
* skill-plugins row: a partial feature loss must not fail a doctor run.
* sessions, analytics, lanes and the CLI keep working. A partial feature
* loss must not fail a doctor run.
*
* This checks the doctor's own PATH. A server started as a systemd `--user`
* service can still see a different one — `GET /api/run/tmux` is the server's
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env node
/**
* @file service-manager.js
* @description Picks the per-user service manager that keeps the dashboard
* running without Claude Code: a LaunchAgent on macOS (`launchd-service.js`),
* a systemd `--user` unit everywhere else (`systemd-service.js`, which reports
* itself unavailable off Linux). Both export the same API.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
module.exports =
process.platform === "darwin" ? require("./launchd-service") : require("./systemd-service");
+2
View File
@@ -224,6 +224,8 @@ function enableLinger() {
}
module.exports = {
kind: "systemd",
label: "systemd --user service",
systemctlAvailable,
unitIsOurs,
unitIsStale,
+8 -1
View File
@@ -9,6 +9,9 @@
* (including the pane the test was launched from). Dropping `TMUX` and
* pointing `TMUX_TMPDIR` at a fresh directory gives every tmux call — the
* app's own and the tests' direct `execFileSync("tmux", …)` — its own socket.
* It also points `DASHBOARD_PIPELINES_DIR` at `server/__tests__/fixtures/
* pipelines/`: AgentHub ships no pipeline template any more, and the two old
* ones kept there are what the dormant stage/detection code is tested against.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -26,7 +29,11 @@ const files = fs
const args = process.argv.slice(2);
const tmuxDir = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-test-tmux-"));
const env = { ...process.env, TMUX_TMPDIR: tmuxDir };
const env = {
...process.env,
TMUX_TMPDIR: tmuxDir,
DASHBOARD_PIPELINES_DIR: path.join(dir, "fixtures", "pipelines"),
};
delete env.TMUX;
delete env.TMUX_PANE;
+7 -25
View File
@@ -584,30 +584,12 @@ pipeline's last node, where the pipeline is finished and a later detection is
new work — and, the one rule that matters, never counts as evidence and never
renders a node as `done` (see `docs/LANES.md#stage-detection`).
A `codex` lane has no hooks to read, so `server/lib/codex-ingest.js` feeds the
same matcher from Codex's own rollout journals under
`$CODEX_HOME/sessions/**/rollout-*.jsonl`, polled every
`DASHBOARD_CODEX_POLL_MS` ms (default 15000, `0` disables) and mapping Codex's
tool calls onto the `{tool_name, tool_input}` shape a hook delivers. The same
pass mirrors that lane's `status` between `idle` and `running` from the
journal's mtime, under the guard hook ingestion uses (no `run_id`, only from
`idle`/`running`); it writes nothing else.
Getting a codex lane's *declared* stage to actually happen is a separate
problem — only the session itself can call `agenthub stage`, and unlike a Claude
lane it has no slash command to pre-fill — and the run console pre-fills
nothing into the prompt box any more, for either tool, since anything sitting
there is sent as a real prompt on start. What is left is
`server/lib/codex-nudge.js`'s `sweepCodexNudges()` runs on an unref'd 60s
interval (`DASHBOARD_CODEX_NUDGE_MS`, `0` disables): when a codex lane's fresh
`detected_stage` has sat ahead of its declared `stage` for at least two
minutes, it types a one-line `[agenthub] ... run: agenthub stage ...` reminder into
the lane's live tmux pane via `tmux.sendText` — skipped if the pane sits at a
bare shell prompt (`pty-run.js`'s `SHELL_COMMANDS`), since pressing Enter there
would run the reminder as a shell command instead of submitting it to Codex.
It never writes `stage` or `detected_stage`, so declared-wins and
inferred-never-`done` are untouched; any resulting declaration is still the
codex session's own real `agenthub stage` call.
A `codex` lane has no hooks to read and carries no pipeline, so nothing detects
or advances its stage. `server/lib/codex-ingest.js` only mirrors its `status`
between `idle` and `running` from the mtime of Codex's own rollout journals
under `$CODEX_HOME/sessions/**/rollout-*.jsonl`, polled every
`DASHBOARD_CODEX_POLL_MS` ms (default 15000, `0` disables), under the guard hook
ingestion uses (no `run_id`, only from `idle`/`running`); it writes nothing else.
### Remote Data Sources
@@ -697,7 +679,7 @@ Reads — and carefully gated mutations for low-risk text-file artifacts — for
### Run a lane's CLI (`/api/run`)
HTTP surface for the tmux-backed terminal run: one session per lane, named `agenthub-lane-<laneId>`, running the CLI that lane declares (`claude` or `codex`). There is no in-memory handle map — every read is computed from `tmux list-sessions`, so a session killed out-of-band self-corrects on the next call. Every route enforces a same-origin / loopback-Origin guard against browser CSRF.
HTTP surface for the tmux-backed terminal run: one session per lane, named `agenthub-lane-<laneId>`, running the CLI that lane declares (`claude`, `codex`, or `agy` for an `antigravity` lane). There is no in-memory handle map — every read is computed from `tmux list-sessions`, so a session killed out-of-band self-corrects on the next call. Every route enforces a same-origin / loopback-Origin guard against browser CSRF.
| Method | Path | Description |
| -------- | ----------------------------- | ----------- |
+74 -437
View File
@@ -1,7 +1,7 @@
/**
* @file Unit tests for Codex stage ingestion: the payload→hook-event mapping,
* and one full pass over a fixture rollout journal (detection + status mirror +
* broadcast + the no-new-bytes no-op).
* @file Unit tests for the Codex lane status mirror: one pass over fixture
* rollout journals flips a codex lane idle↔running, broadcasts it, and never
* touches a lane's stage.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -26,87 +26,11 @@ function line(payload, type = "response_item") {
return JSON.stringify({ timestamp: new Date().toISOString(), ordinal: 1, type, payload });
}
describe("codex payload mapping", () => {
it("maps a function_call exec_command to a Bash event", () => {
const events = codex.eventsFromPayload({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: "/repo" }),
});
assert.deepEqual(events, [
{ tool_name: "Bash", tool_input: { command: "npm run test:server" } },
]);
});
it("maps a custom_tool_call exec to a Bash event carrying the raw script", () => {
const [event] = codex.eventsFromPayload({
type: "custom_tool_call",
name: "exec",
input: 'const r = await tools.exec_command({cmd:"git push origin feat/x"}); text(r.output);',
});
assert.equal(event.tool_name, "Bash");
assert.match(event.tool_input.command, /git push origin feat\/x/);
});
it("maps an apply_patch script to one event per touched file", () => {
const events = codex.eventsFromPayload({
type: "custom_tool_call",
name: "exec",
input:
'const patch = "*** Begin Patch\n*** Update File: server/lib/lanes.js\n+x\n' +
'*** Add File: docs/NEW.md\n+y\n*** End Patch";',
});
assert.deepEqual(events, [
{ tool_name: "Edit", tool_input: { file_path: "server/lib/lanes.js" } },
{ tool_name: "Write", tool_input: { file_path: "docs/NEW.md" } },
]);
});
it("maps an apply_patch script whose newlines are still escaped", () => {
// Verbatim from a real rollout: the patch heredoc lives inside a JS string
// literal, so after JSON.parse the line breaks are a literal backslash-n,
// not newlines. Matching only real newlines silently sees no files at all.
const events = codex.eventsFromPayload({
type: "custom_tool_call",
name: "exec",
input:
'const patch = "*** Begin Patch\\n*** Add File: config/demo.yml\\n+# demo\\n*** End Patch";',
});
assert.deepEqual(events, [
{ tool_name: "Write", tool_input: { file_path: "config/demo.yml" } },
]);
});
it("maps update_plan to TaskCreate and spawn_agent to Agent", () => {
assert.deepEqual(
codex.eventsFromPayload({ type: "function_call", name: "update_plan", arguments: "{}" }),
[{ tool_name: "TaskCreate", tool_input: {} }]
);
assert.deepEqual(
codex.eventsFromPayload({
type: "function_call",
name: "spawn_agent",
arguments: JSON.stringify({ task_name: "code_reviewer", message: "…" }),
}),
[{ tool_name: "Agent", tool_input: { subagent_type: "code_reviewer" } }]
);
});
it("ignores anything that is not a tool call", () => {
assert.deepEqual(codex.eventsFromPayload({ type: "reasoning" }), []);
assert.deepEqual(
codex.eventsFromPayload({ type: "custom_tool_call_output", name: "exec" }),
[]
);
assert.deepEqual(codex.eventsFromPayload({ type: "function_call", name: "web_search" }), []);
assert.deepEqual(codex.eventsFromPayload(null), []);
});
});
describe("codex ingest pass", () => {
describe("codex status mirror", () => {
const HOME = fs.mkdtempSync(path.join(os.tmpdir(), "codex-home-"));
const DIR = path.join(HOME, "sessions", "2026", "08", "27");
let prevHome;
let seq = 0;
before(() => {
prevHome = process.env.CODEX_HOME;
@@ -117,21 +41,18 @@ describe("codex ingest pass", () => {
after(() => {
if (prevHome === undefined) delete process.env.CODEX_HOME;
else process.env.CODEX_HOME = prevHome;
codex.__resetOffsets();
try {
fs.rmSync(HOME, { recursive: true, force: true });
} catch {
/* best-effort */
}
codex.__resetCache();
fs.rmSync(HOME, { recursive: true, force: true });
});
/** A rollout journal for `cwd` with one `npm run test:server` shell call. */
function writeRollout(name, cwd) {
const file = path.join(DIR, name);
function writeRollout(cwd, { mtime } = {}) {
seq += 1;
const file = path.join(DIR, `rollout-2026-08-27T10-00-00-${seq}.jsonl`);
fs.writeFileSync(
file,
[
line({ cwd, session_id: "abc" }, "session_meta"),
line({ cwd, session_id: `s${seq}` }, "session_meta"),
line({
type: "function_call",
name: "exec_command",
@@ -139,256 +60,97 @@ describe("codex ingest pass", () => {
}),
].join("\n") + "\n"
);
if (mtime !== undefined) fs.utimesSync(file, mtime / 1000, mtime / 1000);
codex.__resetCache();
return file;
}
it("detects a stage for a codex lane and mirrors its status", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
writeRollout("rollout-2026-08-27T10-00-00-aaa.jsonl", cwd);
codex.__resetOffsets();
const codexLane = (prefix = "codex-lane-") =>
lanes.createLane({
title: "cx",
cwd: fs.mkdtempSync(path.join(os.tmpdir(), prefix)),
tool: "codex",
});
it("marks a codex lane running while its journal is fresh, and broadcasts it", () => {
const lane = codexLane();
writeRollout(lane.cwd);
const seen = [];
assert.equal(codex.ingestCodexOnce({ broadcast: (id) => seen.push(id) }), 1);
const after = lanes.getLane(lane.id);
assert.equal(after.detected_stage, "tests"); // `npm run test:server` → default template's tests node
assert.match(after.detected_signal, /test:server/);
assert.equal(after.status, "running"); // a journal written just now means work is happening
assert.equal(lanes.getLane(lane.id).status, "running");
assert.deepEqual(seen, [lane.id]);
lanes.deleteLane(lane.id);
});
it("advances the declared stage from the detection, without evidence", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
writeRollout("rollout-2026-08-27T10-00-10-adv.jsonl", cwd);
codex.__resetOffsets();
it("never writes a stage or a detection, whatever the journal ran", () => {
const lane = codexLane();
writeRollout(lane.cwd);
codex.ingestCodexOnce({});
const after = lanes.getLane(lane.id);
// The ring moves — a codex session has nothing else that would move it…
assert.equal(after.stage, "tests");
// …but the node stays amber: an inference sees the tool call, not its result.
assert.equal(after.stages.tests.evidence, null);
// …and the badge survives, so the card still says WHY it moved.
assert.equal(after.detected_stage, "tests");
assert.match(after.detected_signal, /test:server/);
lanes.deleteLane(lane.id);
});
it("never drags an auto-advanced stage backwards", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
lanes.setStage(lane.id, { stage: "review", evidence: "declared by the session" });
writeRollout("rollout-2026-08-27T10-00-11-back.jsonl", cwd); // detects `tests`, behind `review`
codex.__resetOffsets();
codex.ingestCodexOnce({});
const after = lanes.getLane(lane.id);
assert.equal(after.stage, "review"); // declared-wins: recordDetection refused, so no advance
assert.equal(after.stage, "idle");
assert.equal(after.detected_stage, null);
assert.equal(after.stages.review.evidence, "declared by the session");
assert.equal(after.detected_signal, null);
lanes.deleteLane(lane.id);
});
it("a second pass with no appended bytes changes nothing", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
writeRollout("rollout-2026-08-27T10-00-01-bbb.jsonl", cwd);
codex.__resetOffsets();
it("a second pass with nothing new changes nothing", () => {
const lane = codexLane();
writeRollout(lane.cwd);
codex.ingestCodexOnce({});
const first = lanes.getLane(lane.id).detected_at;
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_at, first);
lanes.deleteLane(lane.id);
});
it("puts a running lane back to idle once its journal goes quiet", () => {
const lane = codexLane();
lanes.updateLane(lane.id, { status: "running" });
writeRollout(lane.cwd, { mtime: Date.now() - 6 * 60 * 60 * 1000 });
assert.equal(codex.ingestCodexOnce({}), 1);
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
it("treats a journal whose mtime is in the FUTURE as idle", () => {
// A clock stepped back (or a restore that preserved timestamps) leaves a
// finished thread's mtime ahead of now; raw `now - mtime` would read as live.
const lane = codexLane();
writeRollout(lane.cwd, { mtime: Date.now() + 6 * 60 * 60 * 1000 });
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
it("never touches a claude lane, even at the journal's own cwd", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "claude-lane-"));
const lane = lanes.createLane({ title: "cc", cwd, tool: "claude" });
writeRollout("rollout-2026-08-27T10-00-02-ccc.jsonl", cwd);
codex.__resetOffsets();
writeRollout(cwd);
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_stage, null);
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
it("ignores a journal whose cwd belongs to no lane", () => {
const orphan = fs.mkdtempSync(path.join(os.tmpdir(), "codex-orphan-"));
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
writeRollout("rollout-2026-08-27T10-00-03-ddd.jsonl", orphan);
codex.__resetOffsets();
const lane = codexLane();
writeRollout(fs.mkdtempSync(path.join(os.tmpdir(), "codex-orphan-")));
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_stage, null);
lanes.deleteLane(lane.id);
});
it("keeps byte offsets exact when a tail read starts mid multi-byte character", () => {
// The first sight of a >64 KiB journal reads only its tail, and that offset
// can land inside a 3-byte UTF-8 sequence. Splitting the decoded STRING and
// measuring it back with Buffer.byteLength then counts the decoder's U+FFFD
// replacement instead of the bytes actually consumed, so the next pass
// starts 1-2 bytes off and every later record is unparseable.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-2026-08-27T10-00-06-utf8.jsonl");
const record = (cmd) =>
line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd, workdir: cwd }),
});
// Grow an all-multi-byte filler line until the tail boundary (size - 64 KiB)
// falls on a UTF-8 continuation byte.
const head = line({ cwd, session_id: "utf8" }, "session_meta") + "\n";
const tailRecord = record("npm run test:server") + "\n";
let filler = "→".repeat(30_000);
for (let pad = 0; pad < 8; pad += 1) {
const body = head + filler + "\n" + tailRecord;
const buf = Buffer.from(body, "utf8");
const boundary = buf.length - 64 * 1024;
if (boundary > 0 && (buf[boundary] & 0xc0) === 0x80) break;
filler += "x";
}
fs.writeFileSync(file, head + filler + "\n" + tailRecord);
const buf = Buffer.from(fs.readFileSync(file));
assert.equal(buf[buf.length - 64 * 1024] & 0xc0, 0x80, "fixture must straddle a UTF-8 char");
codex.__resetOffsets();
assert.equal(codex.ingestCodexOnce({}), 1);
assert.equal(lanes.getLane(lane.id).detected_stage, "tests");
// The real proof: the next append must still parse, which it only does if
// the stored offset is exactly on the previous line boundary.
fs.appendFileSync(file, record("git push origin feat/x") + "\n");
assert.equal(codex.ingestCodexOnce({}), 1);
assert.equal(lanes.getLane(lane.id).detected_stage, "ship");
lanes.deleteLane(lane.id);
});
it("ingests a line appended exactly at the previous read's boundary", () => {
// The offset after a pass lands on a line boundary, so the next chunk's
// FIRST line is a whole record — dropping it as torn loses every append
// that arrives one line at a time, which is how a journal actually grows.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-2026-08-27T10-00-04-fff.jsonl");
fs.writeFileSync(file, line({ cwd, session_id: "boundary" }, "session_meta") + "\n");
codex.__resetOffsets();
codex.ingestCodexOnce({}); // consumes the header, offset now at EOF
assert.equal(lanes.getLane(lane.id).detected_stage, null);
fs.appendFileSync(
file,
line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: cwd }),
}) + "\n"
);
assert.equal(codex.ingestCodexOnce({}), 1);
assert.equal(lanes.getLane(lane.id).detected_stage, "tests");
lanes.deleteLane(lane.id);
});
it("re-reads a torn line whole on the next pass", () => {
// A pass that catches the writer mid-line must not consume that fragment:
// the record it belongs to would be lost forever.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-2026-08-27T10-00-05-ggg.jsonl");
const record = line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: cwd }),
});
fs.writeFileSync(
file,
line({ cwd, session_id: "torn" }, "session_meta") + "\n" + record.slice(0, 40)
);
codex.__resetOffsets();
codex.ingestCodexOnce({});
assert.equal(lanes.getLane(lane.id).detected_stage, null);
fs.appendFileSync(file, record.slice(40) + "\n"); // the writer finishes the line
assert.equal(codex.ingestCodexOnce({}), 1);
assert.equal(lanes.getLane(lane.id).detected_stage, "tests");
lanes.deleteLane(lane.id);
});
it("does not replay a journal it sees for the first time already idle", () => {
// A thread that finished days ago must not paint a stage now — the first
// sight of a stale file only records where it ends.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = writeRollout("rollout-2026-08-20T10-00-00-eee.jsonl", cwd);
const old = Date.now() - 6 * 60 * 60 * 1000;
fs.utimesSync(file, old / 1000, old / 1000);
codex.__resetOffsets();
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_stage, null);
lanes.deleteLane(lane.id);
});
it("does not replay a journal whose mtime is in the FUTURE", () => {
// A clock stepped back (or a restore that preserved timestamps) leaves a
// finished thread's mtime ahead of now. Raw `now - mtime` is then negative,
// which reads as "written milliseconds ago" and would replay it as live work.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-lane-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = writeRollout("rollout-2026-08-27T10-00-00-fut.jsonl", cwd);
const future = Date.now() + 6 * 60 * 60 * 1000;
fs.utimesSync(file, future / 1000, future / 1000);
codex.__resetOffsets();
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_stage, null);
lanes.deleteLane(lane.id);
});
it("ignores a torn/partial JSONL line at the end of a file", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-torn-line-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-torn.jsonl");
fs.writeFileSync(
file,
[
line({ cwd, session_id: "torn" }, "session_meta"),
line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: cwd }),
}),
// A torn last line: not valid JSON, so it will be skipped on next pass
'{"timestamp":"2026-08-27T10:00:00.000Z","type":"response_item","paylo',
].join("\n")
);
codex.__resetOffsets();
const seen = [];
assert.equal(codex.ingestCodexOnce({ broadcast: (id) => seen.push(id) }), 1);
const after = lanes.getLane(lane.id);
assert.equal(after.detected_stage, "tests"); // the valid line was processed
assert.deepEqual(seen, [lane.id]);
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
it("handles a journal whose session_meta is unparseable gracefully", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-bad-meta-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-bad-meta.jsonl");
// Write an invalid JSON line as the first line
fs.writeFileSync(file, "not valid json at all\n");
codex.__resetOffsets();
const lane = codexLane();
fs.writeFileSync(path.join(DIR, "rollout-bad-meta.jsonl"), "not valid json at all\n");
codex.__resetCache();
assert.equal(codex.ingestCodexOnce({}), 0);
assert.equal(lanes.getLane(lane.id).detected_stage, null);
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
@@ -397,50 +159,31 @@ describe("codex ingest pass", () => {
const inner = fs.mkdtempSync(path.join(outer, "inner"));
const outerLane = lanes.createLane({ title: "outer", cwd: outer, tool: "codex" });
const innerLane = lanes.createLane({ title: "inner", cwd: inner, tool: "codex" });
const file = path.join(DIR, "rollout-nested.jsonl");
fs.writeFileSync(
file,
[
line({ cwd: inner, session_id: "nested" }, "session_meta"),
line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: inner }),
}),
].join("\n") + "\n"
);
codex.__resetOffsets();
writeRollout(inner);
const seen = [];
assert.equal(codex.ingestCodexOnce({ broadcast: (id) => seen.push(id) }), 1);
// Inner lane should be the one detected, not outer
assert.equal(lanes.getLane(innerLane.id).detected_stage, "tests");
assert.equal(lanes.getLane(outerLane.id).detected_stage, null);
assert.equal(lanes.getLane(innerLane.id).status, "running");
assert.equal(lanes.getLane(outerLane.id).status, "idle");
assert.deepEqual(seen, [innerLane.id]);
lanes.deleteLane(innerLane.id);
lanes.deleteLane(outerLane.id);
});
it("does not touch status of a lane with an active run_id", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-run-id-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const lane = codexLane();
lanes.updateLane(lane.id, { run_id: "active-run" });
writeRollout("rollout-2026-08-27T10-00-10-rrr.jsonl", cwd);
codex.__resetOffsets();
writeRollout(lane.cwd);
codex.ingestCodexOnce({});
const after = lanes.getLane(lane.id);
// Status should not change because run_id is present
assert.equal(after.status, "idle");
assert.equal(lanes.getLane(lane.id).status, "idle");
lanes.deleteLane(lane.id);
});
it("does not change status from provisioning or failed", () => {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-status-protected-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const lane = codexLane();
lanes.updateLane(lane.id, { status: "provisioning" });
writeRollout("rollout-2026-08-27T10-00-11-ppp.jsonl", cwd);
codex.__resetOffsets();
writeRollout(lane.cwd);
codex.ingestCodexOnce({});
assert.equal(lanes.getLane(lane.id).status, "provisioning");
@@ -455,119 +198,13 @@ describe("codex ingest pass", () => {
const oldMs = process.env.DASHBOARD_CODEX_POLL_MS;
try {
process.env.DASHBOARD_CODEX_POLL_MS = "0";
// startCodexPoll should return early and not set up an interval
const timer = codex.startCodexPoll(() => {});
assert.equal(timer, undefined);
assert.equal(
codex.startCodexPoll(() => {}),
undefined
);
} finally {
if (oldMs === undefined) delete process.env.DASHBOARD_CODEX_POLL_MS;
else process.env.DASHBOARD_CODEX_POLL_MS = oldMs;
}
});
it("handles a shell call with command as an array in arguments", () => {
const events = codex.eventsFromPayload({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ command: ["npm", "run", "test:server"], workdir: "/repo" }),
});
// Should join array elements
assert.deepEqual(events, [
{ tool_name: "Bash", tool_input: { command: "npm run test:server" } },
]);
});
it("ignores a payload with a non-string name", () => {
// A payload with name as null or number should not match any tool
const events1 = codex.eventsFromPayload({
type: "function_call",
name: null,
arguments: "{}",
});
assert.deepEqual(events1, []);
const events2 = codex.eventsFromPayload({
type: "custom_tool_call",
name: 123,
input: "some script",
});
assert.deepEqual(events2, []);
});
it("uses the LAST detection in a batch to move the lane forward", () => {
// Within one ingest pass, if multiple tool calls map to different stages,
// recordDetection is called in order. Only the LAST one that actually writes
// should move the lane forward (forward-only). Simulate two tool calls:
// first impl call (implement), then tests call (tests).
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-batch-last-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
const file = path.join(DIR, "rollout-batch-last.jsonl");
fs.writeFileSync(
file,
[
line({ cwd, session_id: "batch" }, "session_meta"),
// Edit event (implement node)
line({
type: "custom_tool_call",
name: "exec",
input: 'await tools.edit("src/main.js", "add x");',
}),
// Bash event (tests node)
line({
type: "function_call",
name: "exec_command",
arguments: JSON.stringify({ cmd: "npm run test:server", workdir: cwd }),
}),
].join("\n") + "\n"
);
codex.__resetOffsets();
const seen = [];
assert.equal(codex.ingestCodexOnce({ broadcast: (id) => seen.push(id) }), 1);
const after = lanes.getLane(lane.id);
// Should detect the tests node (later in batch), not implement
assert.equal(after.detected_stage, "tests");
lanes.deleteLane(lane.id);
});
it("limits file scan to MAX_FILES newest files", () => {
// Create more than MAX_FILES journal files and verify only newest are scanned
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "codex-max-files-"));
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
// Create 50 old files (more than MAX_FILES=40)
const oldTime = Date.now() - 2 * 60 * 60 * 1000;
for (let i = 0; i < 50; i++) {
const file = path.join(DIR, `rollout-old-${String(i).padStart(2, "0")}.jsonl`);
fs.writeFileSync(file, line({ cwd, session_id: `old-${i}` }, "session_meta") + "\n");
fs.utimesSync(file, oldTime / 1000, oldTime / 1000);
}
codex.__resetOffsets();
// The scan should not stall and should return (no detection expected since all files are stale)
const result = codex.ingestCodexOnce({});
// All files are stale and not active, so no broadcast
assert.equal(result, 0);
lanes.deleteLane(lane.id);
});
it("detects correctly with Delete File in patch heredoc", () => {
const events = codex.eventsFromPayload({
type: "custom_tool_call",
name: "exec",
input: 'const patch = "*** Begin Patch\\n*** Delete File: old/removed.js\\n*** End Patch";',
});
// Delete creates an Edit event (not Write, not ignored)
assert.deepEqual(events, [{ tool_name: "Edit", tool_input: { file_path: "old/removed.js" } }]);
});
it("handles file paths with whitespace in patch patches", () => {
const events = codex.eventsFromPayload({
type: "custom_tool_call",
name: "exec",
input:
'const patch = "*** Begin Patch\\n*** Update File: src/my file.js \\n*** End Patch";',
});
// File path should be trimmed
assert.deepEqual(events, [{ tool_name: "Edit", tool_input: { file_path: "src/my file.js" } }]);
});
});
-142
View File
@@ -1,142 +0,0 @@
/**
* @file Unit tests for the codex evidence safety net: nudges a live codex pane
* to run `agenthub stage --evidence` when the lane has sat at an inferred (
* evidence-less) stage past the delay, without ever writing stage itself.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const os = require("node:os");
const path = require("node:path");
const SUITE_DB_PATH = path.join(
os.tmpdir(),
`dashboard-codex-nudge-${Date.now()}-${process.pid}.db`
);
process.env.DASHBOARD_DB_PATH = SUITE_DB_PATH;
const { describe, it, beforeEach, afterEach } = require("node:test");
const assert = require("node:assert/strict");
const { db } = require("../db");
const lanes = require("../lib/lanes");
const tmux = require("../lib/tmux");
const nudge = require("../lib/codex-nudge");
/** Backdate the current stage's enteredAt so it looks `minutes` old. */
function backdateStage(laneId, minutes) {
const lane = lanes.getLane(laneId);
const stages = { ...lane.stages };
stages[lane.stage] = {
...stages[lane.stage],
enteredAt: new Date(Date.now() - minutes * 60_000).toISOString(),
};
db.prepare("UPDATE lanes SET stages = ? WHERE id = ?").run(JSON.stringify(stages), laneId);
}
describe("codex-nudge sweep", () => {
let calls;
beforeEach(() => {
calls = [];
tmux.__setExecImpl((args) => {
calls.push(args);
if (args[0] === "display-message") return "codex"; // pane running the codex CLI
return "";
});
nudge.__resetNudgeState();
});
afterEach(() => {
tmux.__reset();
});
function makeCodexLane({ cwd, stage = "tests", evidence }) {
const lane = lanes.createLane({ title: "cx", cwd, tool: "codex" });
lanes.updateLane(lane.id, { run_id: `agenthub-lane-${lane.id}` });
lanes.setStage(lane.id, { stage, evidence });
return lane;
}
it("nudges once the lane has held an evidence-less stage past the delay", () => {
const cwd = os.tmpdir();
const lane = makeCodexLane({ cwd: `${cwd}/nudge-a` });
backdateStage(lane.id, 3); // older than the 2 min delay
assert.equal(nudge.sweepCodexNudges(), 1);
const sendKeys = calls.filter((a) => a[0] === "send-keys" && a[3] === "-l");
assert.equal(sendKeys.length, 1);
assert.match(sendKeys[0][4], /agenthub stage tests --tool codex --evidence/);
// A second pass for the same still-unevidenced stage must not repeat it.
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never nudges before the delay has elapsed", () => {
const cwd = os.tmpdir();
const lane = makeCodexLane({ cwd: `${cwd}/nudge-b` });
// enteredAt is "now" — setStage just wrote it.
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never nudges a stage the session already backed with evidence", () => {
const cwd = os.tmpdir();
const lane = makeCodexLane({ cwd: `${cwd}/nudge-c`, evidence: "12 tests green" });
backdateStage(lane.id, 10);
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never nudges a lane that has not entered a pipeline node", () => {
const cwd = os.tmpdir();
const lane = lanes.createLane({ title: "cx", cwd: `${cwd}/nudge-h`, tool: "codex" });
lanes.updateLane(lane.id, { run_id: `agenthub-lane-${lane.id}` });
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never nudges a claude lane", () => {
const cwd = os.tmpdir();
const lane = lanes.createLane({ title: "cc", cwd: `${cwd}/nudge-d`, tool: "claude" });
lanes.updateLane(lane.id, { run_id: `agenthub-lane-${lane.id}` });
lanes.setStage(lane.id, { stage: "tests" });
backdateStage(lane.id, 3);
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never nudges a lane with no live run", () => {
const cwd = os.tmpdir();
const lane = lanes.createLane({ title: "cx", cwd: `${cwd}/nudge-e`, tool: "codex" });
lanes.setStage(lane.id, { stage: "tests" });
backdateStage(lane.id, 3);
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("never types into a pane sitting at a bare shell prompt", () => {
const cwd = os.tmpdir();
const lane = makeCodexLane({ cwd: `${cwd}/nudge-f` });
backdateStage(lane.id, 3);
tmux.__setExecImpl((args) => {
calls.push(args);
if (args[0] === "display-message") return "bash";
return "";
});
assert.equal(nudge.sweepCodexNudges(), 0);
lanes.deleteLane(lane.id);
});
it("nudges again once the lane moves to another evidence-less stage", () => {
const cwd = os.tmpdir();
const lane = makeCodexLane({ cwd: `${cwd}/nudge-g` });
backdateStage(lane.id, 3);
assert.equal(nudge.sweepCodexNudges(), 1);
lanes.setStage(lane.id, { stage: "review" });
backdateStage(lane.id, 3);
assert.equal(nudge.sweepCodexNudges(), 1);
lanes.deleteLane(lane.id);
});
});
@@ -9,11 +9,7 @@
"icon": "📝",
"gate": false,
"command": "/superpowers:brainstorming",
"aliases": [
"assigned",
"claimed",
"start"
],
"aliases": ["assigned", "claimed", "start"],
"detect": [
{
"tool": "Agent",
@@ -31,11 +27,7 @@
"icon": "🧭",
"gate": false,
"command": "/superpowers:writing-plans",
"aliases": [
"planning",
"brainstorm",
"design"
],
"aliases": ["planning", "brainstorm", "design"],
"detect": [
{
"tool": "Skill",
@@ -60,11 +52,7 @@
"icon": "🛠",
"gate": false,
"command": "/superpowers:test-driven-development",
"aliases": [
"implementing",
"coding",
"build"
],
"aliases": ["implementing", "coding", "build"],
"detect": [
{
"tool": "Skill",
@@ -85,12 +73,7 @@
"icon": "🧪",
"gate": true,
"command": "npm test",
"aliases": [
"testing",
"unit",
"gates",
"pre-push-gate"
],
"aliases": ["testing", "unit", "gates", "pre-push-gate"],
"detect": [
{
"tool": "Bash",
@@ -108,11 +91,7 @@
"icon": "👀",
"gate": true,
"command": "/code-review",
"aliases": [
"reviewing",
"code-review",
"self-review"
],
"aliases": ["reviewing", "code-review", "self-review"],
"detect": [
{
"tool": "Skill",
@@ -134,12 +113,7 @@
"icon": "🚦",
"gate": true,
"command": "/superpowers:verification-before-completion",
"aliases": [
"verify",
"verification",
"sr-gate",
"gate-blocked"
],
"aliases": ["verify", "verification", "sr-gate", "gate-blocked"],
"detect": [
{
"tool": "Skill",
@@ -157,13 +131,7 @@
"icon": "🔀",
"gate": false,
"command": "/superpowers:finishing-a-development-branch",
"aliases": [
"pr",
"pr-open",
"publishing",
"commit",
"push"
],
"aliases": ["pr", "pr-open", "publishing", "commit", "push"],
"detect": [
{
"tool": "Skill",
@@ -181,11 +149,7 @@
"icon": "✅",
"gate": false,
"command": "agenthub stage done",
"aliases": [
"complete",
"completed",
"merged"
]
"aliases": ["complete", "completed", "merged"]
}
]
}
@@ -9,12 +9,7 @@
"icon": "📝",
"gate": false,
"command": "/superpowers:brainstorming",
"aliases": [
"assigned",
"claimed",
"start",
"bootstrapping"
],
"aliases": ["assigned", "claimed", "start", "bootstrapping"],
"detect": [
{
"tool": "Skill",
@@ -36,11 +31,7 @@
"icon": "🧭",
"gate": false,
"command": "/superpowers:writing-plans",
"aliases": [
"planning",
"brainstorm",
"design"
],
"aliases": ["planning", "brainstorm", "design"],
"detect": [
{
"tool": "Skill",
@@ -65,11 +56,7 @@
"icon": "🛠",
"gate": false,
"command": "/superpowers:test-driven-development",
"aliases": [
"implement",
"coding",
"build"
],
"aliases": ["implement", "coding", "build"],
"detect": [
{
"tool": "Skill",
@@ -91,12 +78,7 @@
"icon": "🧪",
"gate": true,
"command": "agenthub lanes hook ci-gate",
"aliases": [
"pre-push-gate",
"tests",
"migration-collision",
"sync-conflict"
],
"aliases": ["pre-push-gate", "tests", "migration-collision", "sync-conflict"],
"detect": [
{
"tool": "Bash",
@@ -114,12 +96,7 @@
"icon": "🧪",
"gate": false,
"command": "agenthub lanes up --qc",
"aliases": [
"e2e",
"e2e-scoped",
"booting",
"live"
],
"aliases": ["e2e", "e2e-scoped", "booting", "live"],
"detect": [
{
"tool": "Bash",
@@ -133,9 +110,7 @@
"icon": "🧪",
"gate": true,
"command": "agenthub stage e2e-feature-passed",
"aliases": [
"e2e-passed"
]
"aliases": ["e2e-passed"]
},
{
"id": "review",
@@ -143,11 +118,7 @@
"icon": "👀",
"gate": true,
"command": "/code-review",
"aliases": [
"reviewing",
"code-review",
"self-review"
],
"aliases": ["reviewing", "code-review", "self-review"],
"detect": [
{
"tool": "Skill",
@@ -191,12 +162,7 @@
"icon": "🚦",
"gate": true,
"command": "/superpowers:verification-before-completion",
"aliases": [
"sr-gate",
"verify",
"verification",
"gate-blocked"
],
"aliases": ["sr-gate", "verify", "verification", "gate-blocked"],
"detect": [
{
"tool": "Agent",
@@ -214,9 +180,7 @@
"icon": "🔀",
"gate": false,
"command": "/superpowers:finishing-a-development-branch",
"aliases": [
"push"
],
"aliases": ["push"],
"detect": [
{
"tool": "Skill",
@@ -234,12 +198,7 @@
"icon": "🔀",
"gate": false,
"command": "gh pr create --base development",
"aliases": [
"ship",
"pr",
"push-conflict",
"push-revalidate"
],
"aliases": ["ship", "pr", "push-conflict", "push-revalidate"],
"detect": [
{
"tool": "Bash",
@@ -261,9 +220,7 @@
"icon": "👁",
"gate": false,
"command": "agenthub lanes ci status",
"aliases": [
"pr-comment-fix"
],
"aliases": ["pr-comment-fix"],
"detect": [
{
"tool": "Bash",
@@ -285,10 +242,7 @@
"icon": "✅",
"gate": false,
"command": "agenthub stage done",
"aliases": [
"complete",
"completed"
]
"aliases": ["complete", "completed"]
}
]
}
+101
View File
@@ -661,6 +661,107 @@ describe("runGitAction — one hunk at a time", () => {
});
});
describe("runGitAction — one change block inside a hunk (issue #50)", () => {
beforeEach(freshFixture);
const base = Array.from({ length: 20 }, (_, i) => `line ${i + 1}`);
/** Three change blocks close enough for git to merge into ONE hunk: lines
* 4-5 replaced, a line inserted after 8, line 11 deleted. */
function threeBlocks() {
write(LANE, "near.txt", base.join("\n") + "\n");
gc(LANE, "add", "near.txt");
gc(LANE, "commit", "-qm", "near");
const next = [...base];
next.splice(3, 2, "FOUR", "FIVE");
next.splice(8, 0, "INSERTED");
next.splice(11, 1); // "line 11"
write(LANE, "near.txt", next.join("\n") + "\n");
return next;
}
const hunkOf = async () => {
const [file] = (await collectChanges(LANE, { range: "work", file: "near.txt" })).files;
return file.hunks;
};
const read = () => fs.readFileSync(path.join(LANE, "near.txt"), "utf8").split("\n");
it("sees the three blocks as one git hunk (the shape the issue reports)", async () => {
threeBlocks();
assert.equal((await hunkOf()).length, 1);
});
it("stages ONE block, leaving the other two in the working tree", async () => {
threeBlocks();
const [hunk] = await hunkOf();
await runGitAction(LANE, "stage-hunk", { path: "near.txt", hunk: hunk.header, block: 1 });
const staged = g(LANE, "diff", "--cached", "--", "near.txt");
assert.match(staged, /^\+INSERTED$/m);
assert.doesNotMatch(staged, /FOUR|FIVE|^-line 11$/m);
const unstaged = g(LANE, "diff", "--", "near.txt");
assert.match(unstaged, /^\+FOUR$/m);
assert.match(unstaged, /^-line 11$/m);
assert.doesNotMatch(unstaged, /^\+INSERTED$/m); // staged: only context now
});
it("stages the LAST block after earlier ones shifted the line count", async () => {
threeBlocks();
const [hunk] = await hunkOf();
await runGitAction(LANE, "stage-hunk", { path: "near.txt", hunk: hunk.header, block: 2 });
const staged = g(LANE, "diff", "--cached", "--", "near.txt");
assert.match(staged, /^-line 11$/m);
assert.doesNotMatch(staged, /FOUR|INSERTED/);
});
it("undoes ONE block in the working tree, keeping the blocks around it", async () => {
const edited = threeBlocks();
const [hunk] = await hunkOf();
await runGitAction(LANE, "discard-hunk", {
path: "near.txt",
hunk: hunk.header,
block: 0,
confirm: true,
});
const want = [...edited];
want.splice(3, 2, "line 4", "line 5");
assert.deepEqual(read(), [...want, ""]);
});
it("splits a hunk whose last block only drops the final newline", async () => {
// One hunk: line 2 replaced, and line 6 losing its final newline — git
// writes that second block with a "\\ No newline" marker after its "+".
write(LANE, "tail.txt", "l1\nl2\nl3\nl4\nl5\nl6\n");
gc(LANE, "add", "tail.txt");
gc(LANE, "commit", "-qm", "tail");
write(LANE, "tail.txt", "l1\nTWO\nl3\nl4\nl5\nl6");
const [file] = (await collectChanges(LANE, { range: "work", file: "tail.txt" })).files;
assert.equal(file.hunks.length, 1);
const header = file.hunks[0].header;
await runGitAction(LANE, "stage-hunk", { path: "tail.txt", hunk: header, block: 1 });
const staged = g(LANE, "diff", "--cached", "--", "tail.txt");
assert.match(staged, /No newline at end of file/);
assert.doesNotMatch(staged, /TWO/);
await runGitAction(LANE, "discard-hunk", {
path: "tail.txt",
hunk: header,
block: 0,
confirm: true,
});
assert.equal(fs.readFileSync(path.join(LANE, "tail.txt"), "utf8"), "l1\nl2\nl3\nl4\nl5\nl6");
});
it("refuses a block the hunk does not have", async () => {
threeBlocks();
const [hunk] = await hunkOf();
for (const block of [3, -1, 1.5, "0"]) {
await assert.rejects(
() => runGitAction(LANE, "stage-hunk", { path: "near.txt", hunk: hunk.header, block }),
{ code: "EHUNKGONE" }
);
}
});
});
describe("an unborn repo and `publish`", () => {
const EMPTY = path.join(ROOT, "empty");
const URL_OK = "https://example.test/owner/r.git";
+10
View File
@@ -16,6 +16,7 @@ const { execFileSync } = require("node:child_process");
const { runGitAction } = require("../lib/git-ops");
const { gitFacts } = require("../lib/worktree");
const { listTree, listPaths } = require("../lib/git-diff");
const ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-merge-"));
const REPO = path.join(ROOT, "repo");
@@ -87,6 +88,15 @@ describe("merge", () => {
});
});
describe("listing files mid-merge", () => {
it("lists a conflicted file once, not once per merge stage", async () => {
await merge();
const root = await listTree(REPO, {});
assert.equal(root.entries.filter((e) => e.name === "a.txt").length, 1);
assert.deepEqual((await listPaths(REPO, { q: "a.txt" })).paths, ["a.txt"]);
});
});
describe("resolve", () => {
it("takes our side or theirs, and only for a conflicted path", async () => {
await merge();
+58 -90
View File
@@ -1,7 +1,6 @@
/**
* @file Tests for lane-agents.js: agent-template installation into a lane's
* .claude/agents/, including path resolution, git-exclude idempotence, and
* missing-repo rejection.
* @file Tests for lane-agents.js's removeStageDoc and the codex pipeline
* cleanup it pairs with (clearCodexPipelines).
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
@@ -18,7 +17,7 @@ const { describe, it, after } = require("node:test");
const assert = require("node:assert/strict");
const lanesLib = require("../lib/lanes");
const { installAgents } = require("../lib/lane-agents");
const { removeStageDoc } = require("../lib/lane-agents");
after(() => fs.rmSync(SUITE_ROOT, { recursive: true, force: true }));
@@ -48,97 +47,66 @@ function makeRepoDir() {
return cwd;
}
/** Create a lane record backed by an existing directory. */
function makeLane(cwd) {
return lanesLib.createLane({ title: "agents-test", cwd, kind: "managed" });
}
describe("codex pipeline cleanup", () => {
const START = "<!-- agenthub:stage:start -->";
const END = "<!-- agenthub:stage:end -->";
const BLOCK = `${START}\n## Declare your lane stage as you work\n\nagenthub stage …\n${END}\n`;
describe("installAgents", () => {
it("copies agent templates from agents/ dir into lane's .claude/agents/", async () => {
it("removes only the AgentHub block, keeping the user's own AGENTS.md prose", () => {
const cwd = makeRepoDir();
const lane = makeLane(cwd);
const result = await installAgents(lane);
assert.deepEqual([...result.installed].sort(), ["qc-local.md", "senior-gate-reviewer.md"]);
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents", "qc-local.md")));
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents", "senior-gate-reviewer.md")));
// Verify the source path is new (agents/) not old (data/agent-templates/)
const oldPath = path.join(__dirname, "..", "data", "agent-templates", "ship-feature-lane");
assert.equal(fs.existsSync(oldPath), false);
});
it("throws ENOTGITREPO when lane cwd has no .git", async () => {
const cwd = path.join(SUITE_ROOT, "no-git");
fs.mkdirSync(cwd, { recursive: true });
const lane = makeLane(cwd);
await assert.rejects(
() => installAgents(lane),
(err) => err.code === "ENOTGITREPO"
);
});
it("adds .claude/agents/ line to git info/exclude idempotently", async () => {
const cwd = makeRepoDir();
const lane = makeLane(cwd);
await installAgents(lane); // first
await installAgents(lane); // reinstall — should not duplicate
const excludePath = path.join(cwd, ".git", "info", "exclude");
const content = fs.readFileSync(excludePath, "utf8");
const matches = content.split("\n").filter((l) => l === ".claude/agents/");
assert.equal(matches.length, 1);
});
it("overwrites existing agents on reinstall", async () => {
const cwd = makeRepoDir();
const lane = makeLane(cwd);
await installAgents(lane);
// Tamper with the installed file
const agentPath = path.join(cwd, ".claude", "agents", "qc-local.md");
fs.writeFileSync(agentPath, "tampered");
// Reinstall
await installAgents(lane);
const content = fs.readFileSync(agentPath, "utf8");
assert.ok(content.includes("#"), "reinstalled file should look like markdown, not 'tampered'");
assert.notEqual(content, "tampered");
});
it("creates .claude/agents/ dir if it does not exist", async () => {
const cwd = makeRepoDir();
const lane = makeLane(cwd);
assert.equal(fs.existsSync(path.join(cwd, ".claude", "agents")), false);
await installAgents(lane);
assert.ok(fs.existsSync(path.join(cwd, ".claude", "agents")));
});
it("installs the AGENTS.md stage block for a codex lane, not .claude/agents/", async () => {
const cwd = makeRepoDir();
const lane = lanesLib.createLane({ title: "cx", cwd, kind: "managed", tool: "codex" });
const result = await installAgents(lane);
assert.deepEqual(result.installed, ["AGENTS.md"]);
assert.equal(fs.existsSync(path.join(cwd, ".claude", "agents")), false);
const doc = fs.readFileSync(path.join(cwd, "AGENTS.md"), "utf8");
assert.match(doc, /agenthub stage <stage> --tool codex/);
});
it("preserves the user's own AGENTS.md prose and replaces only the block", async () => {
const cwd = makeRepoDir();
const lane = lanesLib.createLane({ title: "cx", cwd, kind: "managed", tool: "codex" });
const file = path.join(cwd, "AGENTS.md");
fs.writeFileSync(file, "# House rules\n\nNever force-push.\n");
await installAgents(lane);
await installAgents(lane); // reinstall must not duplicate the block
fs.writeFileSync(file, `# House rules\n\nNever force-push.\n\n${BLOCK}\n## More\n\nKeep me.\n`);
assert.equal(removeStageDoc(cwd), true);
const doc = fs.readFileSync(file, "utf8");
assert.ok(!doc.includes(START) && !doc.includes(END));
assert.match(doc, /Never force-push\./);
assert.equal(doc.split("<!-- agenthub:stage:start -->").length - 1, 1);
assert.equal(doc.split("<!-- agenthub:stage:end -->").length - 1, 1);
assert.match(doc, /Keep me\./);
});
it("deletes an AGENTS.md that held nothing but the block", () => {
const cwd = makeRepoDir();
fs.writeFileSync(path.join(cwd, "AGENTS.md"), BLOCK);
assert.equal(removeStageDoc(cwd), true);
assert.equal(fs.existsSync(path.join(cwd, "AGENTS.md")), false);
});
it("leaves a file without the block, or no file at all, untouched", () => {
const cwd = makeRepoDir();
assert.equal(removeStageDoc(cwd), false);
fs.writeFileSync(path.join(cwd, "AGENTS.md"), "# Mine\n");
assert.equal(removeStageDoc(cwd), false);
assert.equal(fs.readFileSync(path.join(cwd, "AGENTS.md"), "utf8"), "# Mine\n");
});
it("wipes a codex lane's stage, detection, stage log and features — and no claude lane's", () => {
const codex = lanesLib.createLane({ title: "cx", cwd: makeRepoDir(), tool: "codex" });
const claude = lanesLib.createLane({ title: "cc", cwd: makeRepoDir(), tool: "claude" });
for (const lane of [codex, claude]) {
lanesLib.setStage(lane.id, { stage: "tests", evidence: "old" });
lanesLib.recordDetection(lane.id, { nodeId: "review", signal: "npm test" });
}
const { db } = require("../db");
const insertFeature = db.prepare("INSERT INTO lane_features (lane_id, slug) VALUES (?, ?)");
insertFeature.run(codex.id, "old-feature");
insertFeature.run(claude.id, "kept-feature");
assert.equal(lanesLib.clearCodexPipelines(), 1);
const cx = lanesLib.getLane(codex.id);
assert.equal(cx.stage, "idle");
assert.deepEqual(cx.stages, {});
assert.equal(cx.detected_stage, null);
const count = (table, id) =>
db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE lane_id = ?`).get(id).n;
assert.equal(count("lane_stage_events", codex.id), 0);
assert.equal(count("lane_features", codex.id), 0);
const cc = lanesLib.getLane(claude.id);
assert.equal(cc.stage, "tests");
assert.ok(count("lane_stage_events", claude.id) > 0);
assert.equal(count("lane_features", claude.id), 1);
assert.equal(lanesLib.clearCodexPipelines(), 0); // idempotent
});
});
+16
View File
@@ -1302,4 +1302,20 @@ describe("lane ensure, start mode, lane_id and releasing a finished run", () =>
restorePath();
}
});
it("healAllRunIds releases a lane whose pane exited, with no read to trigger it", async () => {
// A codex/antigravity pane fires no hook on exit, so nothing re-reads its
// lane; the server's periodic sweep is what has to notice.
const lanesLib = require("../lib/lanes");
const { healAllRunIds } = require("../routes/lanes");
const lane = await adoptedLane("heal-all-sweep");
// No tmux session by this name exists on the suite's private server.
lanesLib.updateLane(lane.id, { run_id: `agenthub-lane-${lane.id}`, status: "running" });
healAllRunIds();
const after = lanesLib.getLane(lane.id);
assert.equal(after.run_id, null);
assert.equal(after.status, "idle");
});
});
+66 -9
View File
@@ -12,6 +12,7 @@ const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
const SUITE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-mcp-"));
const FAKE_HOME = path.join(SUITE_ROOT, "home");
@@ -163,21 +164,77 @@ describe("syncMcp — profile seeding", () => {
});
});
describe("syncMcp — .git/info/exclude idempotency", () => {
it("appends .mcp.json once and does not duplicate it on a second call", async () => {
describe("syncMcp — keeping .mcp.json out of git", () => {
// Real repos, asserted through `git status`: git reads info/exclude from the
// COMMON git dir only, which a fake `.git` dir cannot show.
// A pre-commit hook running this suite exports GIT_INDEX_FILE & co., which
// would point these fixture calls at the outer repo.
const git = (cwd, ...args) => {
const env = { ...process.env };
for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR"]) {
delete env[name];
}
return execFileSync("git", args, { cwd, env, encoding: "utf8" });
};
const untracked = (cwd) => git(cwd, "status", "--porcelain").split("\n").filter(Boolean);
function mcpLane(cwd) {
const sourceRepo = path.join(SUITE_ROOT, "src-exclude");
fs.mkdirSync(sourceRepo, { recursive: true });
writeClaudeJson({
[sourceRepo]: { mcpServers: { playwright: { command: "npx", args: [] } } },
});
const lane = makeLane(sourceRepo);
fs.mkdirSync(path.join(lane.cwd, ".git"), { recursive: true });
return { cwd, source_repo: sourceRepo };
}
await laneMcp.syncMcp(lane);
await laneMcp.syncMcp(lane);
function makeRepo() {
const repo = makeLane(null).cwd;
git(repo, "init", "-q");
git(
repo,
"-c",
"user.name=t",
"-c",
"user.email=t@t",
"commit",
"-q",
"--allow-empty",
"-m",
"init"
);
return repo;
}
const exclude = fs.readFileSync(path.join(lane.cwd, ".git", "info", "exclude"), "utf8");
const matches = exclude.split("\n").filter((line) => line === ".mcp.json");
assert.equal(matches.length, 1);
it("hides .mcp.json, once, however many times it syncs", async () => {
const repo = makeRepo();
await laneMcp.syncMcp(mcpLane(repo));
await laneMcp.syncMcp(mcpLane(repo));
assert.deepEqual(untracked(repo), []);
const exclude = fs.readFileSync(path.join(repo, ".git", "info", "exclude"), "utf8");
assert.equal(exclude.split("\n").filter((line) => line.includes(".mcp.json")).length, 1);
});
it("hides it in a worktree lane, whose .git is a pointer file", async () => {
const repo = makeRepo();
const wt = path.join(SUITE_ROOT, `wt-${laneSeq}`);
git(repo, "worktree", "add", "-q", "-b", "lane1", wt);
await laneMcp.syncMcp(mcpLane(wt));
assert.deepEqual(untracked(wt), []);
});
it("hides it in a lane that is a subdirectory of its repo", async () => {
const repo = makeRepo();
const sub = path.join(repo, "packages", "app");
fs.mkdirSync(sub, { recursive: true });
await laneMcp.syncMcp(mcpLane(sub));
assert.deepEqual(untracked(repo), []);
});
it("creates no .git in a lane that is not a repo", async () => {
const cwd = makeLane(null).cwd;
await laneMcp.syncMcp(mcpLane(cwd));
assert.ok(fs.existsSync(path.join(cwd, ".mcp.json")));
assert.equal(fs.existsSync(path.join(cwd, ".git")), false);
});
});
+5 -31
View File
@@ -20,6 +20,11 @@ const SOURCE_REPO = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-worktree-sou
const REMOTE_REPO = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-worktree-remote-"));
process.env.DASHBOARD_DB_PATH = TEST_DB;
process.env.DASHBOARD_PIPELINES_DIR = PIPELINE_DIR;
// AgentHub ships no pipeline template; the CLI's stage commands are tested
// against the two old ones kept as fixtures.
for (const f of ["default.json", "ship-feature.json"]) {
fs.copyFileSync(path.join(__dirname, "fixtures", "pipelines", f), path.join(PIPELINE_DIR, f));
}
process.env.DASHBOARD_REMOTE_SYNC_MS = "0";
process.env.DASHBOARD_LIVENESS_PROBE = "0";
process.env.LANES_ROOT = LANES_ROOT;
@@ -675,37 +680,6 @@ describe("agenthub lanes — inferred stage detection", () => {
});
});
describe("agenthub ship-full / agenthub ship-quick", () => {
it("ship-quick prints the 8-stage pipeline's skill, ship-full the 16-stage one", async () => {
const quick = await cli(["ship-quick", "add", "an", "export", "button", "--print"], LANE_DIR);
assert.equal(quick.status, 0, quick.stderr);
assert.match(quick.stdout, /claude "\/agenthub:ship-feature add an export button"/);
const full = await cli(["ship-full", "add", "an", "export", "button", "--print"], LANE_DIR);
assert.equal(full.status, 0, full.stderr);
assert.match(full.stdout, /claude "\/agenthub:ship-feature-lane add an export button"/);
});
it("--print switches nothing: the lane keeps whatever template it was on", async () => {
const before = await get(`/api/lanes`);
const lane = before.body.lanes.find((l) => l.cwd === LANE_DIR);
const r = await cli(["ship-full", "anything", "--print"], LANE_DIR);
assert.equal(r.status, 0, r.stderr);
const after = await get(`/api/lanes`);
assert.equal(after.body.lanes.find((l) => l.id === lane.id).pipeline, lane.pipeline);
});
it("exits non-zero with the command's own usage when no requirement is given", async () => {
const r = await cli(["ship-full"], LANE_DIR);
assert.notEqual(r.status, 0);
assert.match(r.stderr, /usage: agenthub ship-full/);
const q = await cli(["ship-quick"], LANE_DIR);
assert.notEqual(q.status, 0);
assert.match(q.stderr, /usage: agenthub ship-quick/);
});
});
describe("agenthub lanes node", () => {
it("with no node id, lists every node and its command, and exits non-zero with usage", async () => {
const r = await cli(["lanes", "node"], LANE_DIR);
+176
View File
@@ -0,0 +1,176 @@
/**
* @file Tests scripts/launchd-service.js, the macOS LaunchAgent twin of the
* systemd unit: the plist it writes (KeepAlive, AbandonProcessGroup so lane
* panes survive a restart, the plugin root as WorkingDirectory), that writing
* starts nothing, that a restart re-reads the plist (bootout + bootstrap, not
* kickstart), and that a foreign plist is never touched. `launchctl` is
* stubbed and the platform faked, so this runs on any OS.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { describe, it, beforeEach, after } = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const TMP_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-launchd-"));
const prevHome = process.env.HOME;
process.env.HOME = TMP_HOME;
const realPlatform = Object.getOwnPropertyDescriptor(process, "platform");
Object.defineProperty(process, "platform", { value: "darwin" });
const svc = require("../../scripts/launchd-service");
const DOMAIN = `gui/${process.getuid()}`;
const JOB = `${DOMAIN}/io.smartgift.agenthub`;
let calls = [];
let loaded = false;
let running = false;
let failBootstrap = false;
let noGui = false;
beforeEach(() => {
calls = [];
loaded = running = failBootstrap = noGui = false;
fs.rmSync(svc.unitPath("agenthub"), { force: true });
svc.__setExecImpl((args) => {
if (args[0] === "print" && args[1] === DOMAIN) return { status: noGui ? 113 : 0 };
calls.push(args.join(" "));
if (args[0] === "print") {
return {
status: loaded ? 0 : 113,
stdout: running ? "\tstate = running\n" : "\tstate = not running\n",
};
}
if (args[0] === "bootstrap") return { status: failBootstrap ? 5 : 0 };
return { status: 0 };
});
});
after(() => {
svc.__reset();
Object.defineProperty(process, "platform", realPlatform);
if (prevHome === undefined) delete process.env.HOME;
else process.env.HOME = prevHome;
fs.rmSync(TMP_HOME, { recursive: true, force: true });
});
const UNIT = {
name: "agenthub",
description: "AgentHub dashboard server (Claude Code plugin)",
workingDir: "/plugin/root/new & improved",
execStart: "/usr/local/bin/node /plugin/root/new/server/index.js",
argv: ["/usr/local/bin/node", "/plugin/root/new & improved/server/index.js"],
env: { NODE_ENV: "production", PATH: "/usr/bin:/bin" },
};
const plist = () => fs.readFileSync(svc.unitPath("agenthub"), "utf8");
describe("launchd-service — writeUserService", () => {
it("writes a LaunchAgent that restarts forever and spares the lane panes, and starts nothing", () => {
assert.equal(svc.writeUserService(UNIT), "written");
const body = plist();
assert.ok(svc.unitPath("agenthub").startsWith(path.join(TMP_HOME, "Library", "LaunchAgents")));
assert.match(body, /<key>Label<\/key>\s*<string>io\.smartgift\.agenthub<\/string>/);
assert.match(body, /<key>KeepAlive<\/key>\s*<true\/>/);
assert.match(body, /<key>RunAtLoad<\/key>\s*<true\/>/);
assert.match(body, /<key>AbandonProcessGroup<\/key>\s*<true\/>/);
// argv stays split, so a path with a space is one argument; XML escaped.
assert.match(body, /<string>\/plugin\/root\/new &amp; improved\/server\/index\.js<\/string>/);
assert.match(body, /<key>PATH<\/key>\s*<string>\/usr\/bin:\/bin<\/string>/);
assert.deepEqual(calls, [`enable ${JOB}`], "writing must not load or start the job");
});
it("leaves an identical plist alone", () => {
svc.writeUserService(UNIT);
calls = [];
assert.equal(svc.writeUserService(UNIT), "unchanged");
assert.deepEqual(calls, []);
});
it("never overwrites a plist it did not write", () => {
fs.mkdirSync(path.dirname(svc.unitPath("agenthub")), { recursive: true });
fs.writeFileSync(svc.unitPath("agenthub"), "<plist>theirs</plist>");
assert.equal(svc.writeUserService(UNIT), "foreign");
assert.equal(plist(), "<plist>theirs</plist>");
assert.equal(svc.uninstallUserService("agenthub"), "foreign");
assert.ok(fs.existsSync(svc.unitPath("agenthub")));
});
it("is unavailable without a GUI login, and writes nothing", () => {
noGui = true;
assert.equal(svc.systemctlAvailable(), false);
assert.equal(svc.writeUserService(UNIT), "unavailable");
assert.ok(!fs.existsSync(svc.unitPath("agenthub")));
});
});
describe("launchd-service — stale and root", () => {
it("reads the working directory back, escaped path included", () => {
svc.writeUserService(UNIT);
assert.equal(svc.unitRoot("agenthub"), UNIT.workingDir);
assert.equal(svc.unitIsStale("agenthub", UNIT.workingDir), false);
assert.equal(svc.unitIsStale("agenthub", "/plugin/root/newer"), true);
});
it("calls neither a missing nor a foreign plist stale", () => {
assert.equal(svc.unitIsStale("agenthub", "/x"), false);
fs.mkdirSync(path.dirname(svc.unitPath("agenthub")), { recursive: true });
fs.writeFileSync(
svc.unitPath("agenthub"),
"<key>WorkingDirectory</key><string>/elsewhere</string>"
);
assert.equal(svc.unitIsStale("agenthub", "/x"), false);
assert.equal(svc.unitRoot("agenthub"), "/elsewhere", "the pruner still must not delete it");
});
});
describe("launchd-service — restart, install, uninstall", () => {
it("restarts by bootout + bootstrap, so the new plist is what runs", () => {
svc.writeUserService(UNIT);
calls = [];
assert.equal(svc.restartUserService("agenthub"), "restarted");
assert.deepEqual(calls, [`bootout ${JOB}`, `bootstrap ${DOMAIN} ${svc.unitPath("agenthub")}`]);
});
it("reports a failed bootstrap, so the caller can fall back", () => {
failBootstrap = true;
assert.equal(svc.restartUserService("agenthub"), "failed");
});
it("install loads a new plist, and only kickstarts one already loaded", () => {
assert.equal(svc.installUserService(UNIT), "written");
assert.ok(calls.includes(`bootstrap ${DOMAIN} ${svc.unitPath("agenthub")}`));
calls = [];
loaded = true;
assert.equal(svc.installUserService(UNIT), "unchanged");
assert.ok(calls.includes(`kickstart ${JOB}`));
assert.ok(!calls.some((c) => c.startsWith("bootout")), "a running dashboard is not bounced");
});
it("uninstall unloads and deletes our plist", () => {
svc.writeUserService(UNIT);
calls = [];
assert.equal(svc.uninstallUserService("agenthub"), "removed");
assert.deepEqual(calls, [`bootout ${JOB}`]);
assert.ok(!fs.existsSync(svc.unitPath("agenthub")));
assert.equal(svc.uninstallUserService("agenthub"), "absent");
});
it("is active only when launchd says the job is running", () => {
assert.equal(svc.unitIsActive("agenthub"), false);
loaded = true;
assert.equal(svc.unitIsActive("agenthub"), false);
running = true;
assert.equal(svc.unitIsActive("agenthub"), true);
});
});
describe("service-manager", () => {
it("hands out the LaunchAgent on macOS", () => {
delete require.cache[require.resolve("../../scripts/service-manager")];
assert.equal(require("../../scripts/service-manager").kind, "launchd");
});
});
@@ -0,0 +1,82 @@
/**
* @file With NO pipeline template installed (the shipped state since the
* built-in templates were removed), lanes must still be created, rendered and
* reported on: getPipeline() answers an empty pipeline, `default` stays a
* valid id, and a stage declaration is refused with a plain explanation.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const os = require("node:os");
const fs = require("node:fs");
const path = require("node:path");
const ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "pipelines-dormant-"));
process.env.DASHBOARD_DB_PATH = path.join(ROOT, "t.db");
process.env.DASHBOARD_DATA_DIR = path.join(ROOT, "data");
process.env.CLAUDE_HOME = path.join(ROOT, ".claude");
process.env.AGENTHUB_SHELL_PATH = "0";
const savedDir = process.env.DASHBOARD_PIPELINES_DIR;
delete process.env.DASHBOARD_PIPELINES_DIR;
const { describe, it, before, after } = require("node:test");
const assert = require("node:assert/strict");
const http = require("node:http");
const pipelines = require("../lib/pipelines");
pipelines.reload();
const lanes = require("../lib/lanes");
const { createApp } = require("../index");
let app;
let base;
const request = (method, p, body) =>
fetch(`${base}${p}`, {
method,
headers: { "Content-Type": "application/json" },
body: body === undefined ? undefined : JSON.stringify(body),
}).then(async (r) => ({ status: r.status, body: await r.json().catch(() => null) }));
before(async () => {
app = http.createServer(createApp());
await new Promise((r) => app.listen(0, "127.0.0.1", r));
base = `http://127.0.0.1:${app.address().port}`;
});
after(async () => {
await new Promise((r) => app.close(r));
if (savedDir !== undefined) process.env.DASHBOARD_PIPELINES_DIR = savedDir;
pipelines.reload();
fs.rmSync(ROOT, { recursive: true, force: true });
});
describe("no pipeline template installed", () => {
it("ships no template and answers an empty default pipeline", () => {
assert.deepEqual(pipelines.listPipelines(), []);
const p = pipelines.getPipeline("default");
assert.equal(p.id, "default");
assert.deepEqual(p.nodes, []);
assert.equal(pipelines.getPipeline("anything").nodes.length, 0);
assert.deepEqual(pipelines.nodeStates(p, { stage: "plan", stages: {} }), []);
assert.equal(pipelines.progressPct(p, { stage: "plan" }), 0);
});
it("still creates a lane on the default pipeline and renders it", () => {
const lane = lanes.createLane({ cwd: path.join(ROOT, "a"), title: "a" });
assert.equal(lane.pipeline, "default");
const payload = lanes.lanePayload(lane);
assert.deepEqual(payload.pipeline_nodes, []);
assert.equal(payload.progress, 0);
});
it("refuses a stage declaration with a plain reason", async () => {
const lane = lanes.createLane({ cwd: path.join(ROOT, "b"), title: "b" });
const r = await request("POST", `/api/lanes/${lane.id}/stage`, { stage: "plan" });
assert.equal(r.status, 400);
assert.equal(r.body.error.code, "ENOPIPELINE");
assert.match(r.body.error.message, /no pipeline template is installed/);
});
it("lists no pipelines over the API and still serves the lane list", async () => {
assert.deepEqual((await request("GET", "/api/lanes/pipelines")).body, { pipelines: [] });
assert.equal((await request("GET", "/api/lanes")).status, 200);
});
});
-30
View File
@@ -185,7 +185,6 @@ describe("fast path", () => {
pluginVersion: pkg.version,
depsHash: boot.depsHash(),
pluginRoot: ROOT,
skillPluginsSettled: "nothing-missing",
},
RT
);
@@ -206,35 +205,6 @@ describe("fast path", () => {
});
});
describe("skill-plugin auto-install gate", () => {
// Both cases here must return WITHOUT reaching server/lib/skill-plugins.js —
// that module shells out to `claude plugin install`, and no test may.
beforeEach(resetRuntime);
after(() => delete process.env.AGENTHUB_AUTO_INSTALL_PLUGINS);
for (const flag of ["0", "false", "off"]) {
it(`is off when AGENTHUB_AUTO_INSTALL_PLUGINS=${flag}`, () => {
process.env.AGENTHUB_AUTO_INSTALL_PLUGINS = flag;
assert.equal(boot.autoInstallSkillPlugins(RT), "off");
});
}
it("runs once: a settled state is returned verbatim, not re-attempted", () => {
delete process.env.AGENTHUB_AUTO_INSTALL_PLUGINS;
boot.writeState({ skillPluginsSettled: "installed" }, RT);
// Verbatim matters: writeState records whatever comes back, so a marker
// here would erase the only record of what actually happened.
assert.equal(boot.autoInstallSkillPlugins(RT), "installed");
});
it("is off under the flag even when forced, so /agenthub-update honours the opt-out", () => {
process.env.AGENTHUB_AUTO_INSTALL_PLUGINS = "0";
boot.writeState({ skillPluginsSettled: "failed" }, RT);
assert.equal(boot.autoInstallSkillPlugins(RT, { force: true }), "off");
});
});
describe("bootstrap lock", () => {
beforeEach(resetRuntime);
@@ -1,123 +0,0 @@
/**
* @file Tests the `Skill plugins` row of scripts/plugin-doctor.js — the check
* that tells a fresh install its pipelines name slash commands no installed
* plugin provides (today: `superpowers`, which `/agenthub:ship-feature-lane` drives
* step by step). The row must WARN and never FAIL: without that plugin the
* dashboard, hooks, CLI and MCP all still work, so failing a doctor run over it
* would cry wolf. Every case runs against an injected temp CLAUDE_HOME.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { describe, it, after } = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const TMP_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-doctor-skills-"));
process.env.CLAUDE_HOME = TMP_HOME;
const { diagnose } = require("../../scripts/plugin-doctor");
after(() => {
fs.rmSync(TMP_HOME, { recursive: true, force: true });
delete process.env.CLAUDE_HOME;
});
/** Rewrite the injected Claude home, then read back just the row under test. */
function rowFor({ plugins = {}, enabledPlugins = {}, userSkills = [], installDirs = [] }) {
fs.rmSync(TMP_HOME, { recursive: true, force: true });
fs.mkdirSync(path.join(TMP_HOME, "plugins"), { recursive: true });
fs.mkdirSync(path.join(TMP_HOME, "skills"), { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "plugins", "installed_plugins.json"),
JSON.stringify({ plugins })
);
fs.writeFileSync(path.join(TMP_HOME, "settings.json"), JSON.stringify({ enabledPlugins }));
// Created AFTER the wipe above: readPlugins() only counts an instance whose
// installPath still exists on disk.
for (const dir of installDirs) fs.mkdirSync(dir, { recursive: true });
for (const name of userSkills) {
fs.mkdirSync(path.join(TMP_HOME, "skills", name), { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "skills", name, "SKILL.md"),
`---\nname: ${name}\n---\n\nbody\n`
);
}
const row = diagnose().find((r) => r.label === "Skill plugins");
assert.ok(row, "the doctor must always emit a Skill plugins row");
return row;
}
const SP_DIR = path.join(TMP_HOME, "plugins", "sp");
/** An installed superpowers instance; `enabled` mirrors settings.json. */
function installedSuperpowers(enabled) {
return {
plugins: { "superpowers@official": [{ installPath: SP_DIR, scope: "user", version: "1.0.0" }] },
enabledPlugins: { "superpowers@official": enabled },
installDirs: [SP_DIR],
};
}
/** The skills the built-in templates name, read from the templates themselves. */
function requiredSuperpowersSkills() {
const { listPipelines } = require("../lib/pipelines");
const names = new Set();
for (const p of listPipelines()) {
for (const cmd of [p.skill, ...p.nodes.map((n) => n.command)]) {
const m = /^\/superpowers:([A-Za-z0-9_-]+)/.exec(cmd || "");
if (m) names.add(m[1]);
}
}
return [...names];
}
describe("plugin-doctor: Skill plugins row", () => {
it("warns, never fails, when a plugin the pipelines name is not installed", () => {
const row = rowFor({});
assert.equal(row.level, "warn", "a missing skill plugin must not fail the doctor run");
assert.match(row.detail, /superpowers/);
assert.match(row.detail, /claude plugin install superpowers/);
});
it("names the specific skills that are unavailable, so the reader can verify the claim", () => {
const row = rowFor({});
for (const skill of requiredSuperpowersSkills()) {
assert.match(row.detail, new RegExp(skill.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
}
});
it("passes once the plugin is installed and enabled", () => {
const row = rowFor(installedSuperpowers(true));
assert.equal(row.level, "ok", row.detail);
assert.match(row.detail, /superpowers available/);
});
it("treats an explicitly disabled plugin as missing - Claude Code will not resolve its skills", () => {
const row = rowFor(installedSuperpowers(false));
assert.equal(row.level, "warn", row.detail);
assert.match(row.detail, /superpowers/);
});
it("accepts the skills copied into ~/.claude/skills instead of installed as a plugin", () => {
// A legitimate setup. Reporting it as missing would train the reader to
// ignore this row, which is the only failure mode a warning really has.
const row = rowFor({ userSkills: requiredSuperpowersSkills() });
assert.equal(row.level, "ok", row.detail);
});
it("still warns when only SOME of the required skills are present locally", () => {
const [first, ...rest] = requiredSuperpowersSkills();
const row = rowFor({ userSkills: [first] });
assert.equal(row.level, "warn", row.detail);
assert.ok(!row.detail.includes(`${first},`), `${first} is present and must not be listed`);
for (const skill of rest) assert.match(row.detail, new RegExp(skill));
});
});
@@ -242,21 +242,5 @@ describe("plugin marketplace", () => {
const listed = new Set(manifest.commands.map((rel) => path.basename(rel)));
for (const f of onDisk) assert.ok(listed.has(f), `${f} is not in plugin.json commands`);
});
it("gives every pipeline node of the shipped templates its own slash command", () => {
// /intake, /qc, /gate … are how a node is run from inside a session; a
// node with no command file can only be reached from a terminal.
const { listPipelines } = require("../lib/pipelines");
const listed = new Set(manifest.commands.map((rel) => path.basename(rel, ".md")));
for (const p of listPipelines().filter((x) => ["default", "ship-feature"].includes(x.id))) {
for (const n of p.nodes) {
const names = [n.id, ...(n.aliases || [])];
assert.ok(
names.some((name) => listed.has(name)),
`${p.id}/${n.id} has no slash command (tried ${names.join(", ")})`
);
}
}
});
});
});
+21
View File
@@ -398,6 +398,27 @@ describe("pty-run", () => {
assert.ok(!call.some((a) => String(a).startsWith("--dangerously-bypass")));
});
it("spawnRun runs `agy` for an antigravity lane, dropping flags it has no use for", () => {
const call = captureNewSession(() =>
pty.spawnRun({
laneId: 13,
cwd: "/tmp/repo",
tool: "antigravity",
model: "opus",
effort: "high",
permissionMode: "bypassPermissions",
initialPrompt: "hello",
})
);
assert.deepEqual(paneArgv(call), ["agy", "-i", "hello"]);
tmux.__reset();
const last = captureNewSession(() =>
pty.spawnRun({ laneId: 14, cwd: "/tmp/repo", tool: "antigravity", resumeLast: true })
);
assert.deepEqual(paneArgv(last), ["agy", "--continue"]);
});
// `dashboard_runs.mode` is NOT NULL and recordRun swallows insert errors, so a
// null there persisted nothing at all while every call still looked fine: the
// runs modal rendered a row with no cwd, model, prompt or start time, and a
+82 -29
View File
@@ -8,6 +8,7 @@
const os = require("node:os");
const path = require("node:path");
const fs = require("node:fs");
const { execFileSync } = require("node:child_process");
const SUITE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-router-apply-"));
process.env.CLAUDE_HOME = path.join(SUITE_ROOT, ".claude");
@@ -144,50 +145,84 @@ describe("router-apply — Claude lane", () => {
});
describe("router-apply — the written file must survive a lane reset", () => {
it("excludes settings.local.json from git, so `git clean -fd` cannot delete it", () => {
// Real repos, asserted through `git status`: a fake `.git` dir let a test pass
// while git itself never read the exclude file it checked.
const REPO = path.join(SUITE_ROOT, "repo");
// A pre-commit hook running this suite exports GIT_INDEX_FILE & co., which
// would point these fixture calls at the outer repo.
const git = (cwd, ...args) => {
const env = { ...process.env };
for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR"]) {
delete env[name];
}
return execFileSync("git", args, { cwd, env, encoding: "utf8" });
};
const untracked = (cwd) =>
git(cwd, "status", "--porcelain", "--untracked-files=all", "--ignored=no")
.split("\n")
.filter(Boolean);
// A machine-wide ignore (Claude Code adds one for settings.local.json) would
// hide the very file these tests look for.
beforeEach(() => {
process.env.GIT_CONFIG_GLOBAL = "/dev/null";
process.env.GIT_CONFIG_NOSYSTEM = "1";
fs.rmSync(REPO, { recursive: true, force: true });
fs.mkdirSync(REPO, { recursive: true });
git(REPO, "init", "-q");
git(
REPO,
"-c",
"user.name=t",
"-c",
"user.email=t@t",
"commit",
"-q",
"--allow-empty",
"-m",
"init"
);
});
const laneAt = (cwd) => ({ id: 7, cwd, tool: "claude" });
it("hides settings.local.json and its backups, so `git clean -fd` cannot delete them", () => {
// `agenthub lanes reset` runs `git clean -fd` (server/lib/worktree.js).
// Without -x that spares IGNORED files only — an untracked settings file
// would be deleted, silently detaching the lane from its router. The same
// entry also stops an API key from being committable.
fs.mkdirSync(path.join(LANE_CWD, ".git", "info"), { recursive: true });
const { name } = saveNineRouter();
applyRouterToLane(claudeLane(), name);
const exclude = fs.readFileSync(path.join(LANE_CWD, ".git", "info", "exclude"), "utf8");
assert.match(exclude, /^\.claude\/settings\.local\.json$/m);
applyRouterToLane(laneAt(REPO), name);
applyRouterToLane(laneAt(REPO), "native"); // a second write leaves a backup
assert.deepEqual(untracked(REPO), []);
});
it("excludes it for a native lane too, not only a lane on a router", () => {
// The blanked connection pair is load-bearing in its own right: losing it
// to `git clean -fd` lets a USER-level router take over a lane that
// explicitly asked for native.
fs.mkdirSync(path.join(LANE_CWD, ".git", "info"), { recursive: true });
applyRouterToLane(claudeLane(), "native");
const exclude = fs.readFileSync(path.join(LANE_CWD, ".git", "info", "exclude"), "utf8");
assert.match(exclude, /^\.claude\/settings\.local\.json$/m);
it("hides them in a worktree lane, whose exclude file is the COMMON dir's", () => {
// git reads info/exclude from the common git dir only; a copy under
// .git/worktrees/<name>/info/ is never consulted.
const wt = path.join(SUITE_ROOT, "wt");
fs.rmSync(wt, { recursive: true, force: true });
git(REPO, "worktree", "add", "-q", "-b", "lane1", wt);
const { name } = saveNineRouter();
applyRouterToLane(laneAt(wt), name);
applyRouterToLane(laneAt(wt), "native");
assert.deepEqual(untracked(wt), []);
});
it("resolves the real git dir when .git is a file, as it is in every worktree lane", () => {
// A linked worktree's `.git` is a pointer file; joining ".git/info" onto it
// would be a path that cannot exist.
const gitDir = path.join(SUITE_ROOT, "realgit", "worktrees", "lane1");
fs.mkdirSync(gitDir, { recursive: true });
fs.writeFileSync(path.join(LANE_CWD, ".git"), `gitdir: ${gitDir}\n`);
it("hides them in a lane that is a subdirectory of its repo", () => {
const sub = path.join(REPO, "packages", "app");
fs.mkdirSync(sub, { recursive: true });
const { name } = saveNineRouter();
applyRouterToLane(claudeLane(), name);
const exclude = fs.readFileSync(path.join(gitDir, "info", "exclude"), "utf8");
assert.match(exclude, /^\.claude\/settings\.local\.json$/m);
applyRouterToLane(laneAt(sub), name);
applyRouterToLane(laneAt(sub), "native");
assert.deepEqual(untracked(REPO), []);
});
it("adds the entry once, however many times a router is applied", () => {
fs.mkdirSync(path.join(LANE_CWD, ".git", "info"), { recursive: true });
const { name } = saveNineRouter();
applyRouterToLane(claudeLane(), name);
applyRouterToLane(claudeLane(), "native");
applyRouterToLane(laneAt(REPO), name);
applyRouterToLane(laneAt(REPO), "native");
const exclude = fs.readFileSync(path.join(LANE_CWD, ".git", "info", "exclude"), "utf8");
const exclude = fs.readFileSync(path.join(REPO, ".git", "info", "exclude"), "utf8");
assert.equal(exclude.split("\n").filter((l) => l.includes("settings.local.json")).length, 1);
});
@@ -198,6 +233,24 @@ describe("router-apply — the written file must survive a lane reset", () => {
});
});
describe("router-apply — Antigravity lane", () => {
const agyLane = () => ({ id: 9, cwd: LANE_CWD, tool: "antigravity" });
it("accepts native and writes nothing", () => {
assert.equal(applyRouterToLane(agyLane(), "native").file, null);
assert.equal(fs.existsSync(SETTINGS), false);
});
it("refuses a real router instead of writing Claude's settings file", () => {
const { name } = saveNineRouter();
assert.throws(
() => applyRouterToLane(agyLane(), name),
(err) => err.code === "EUNSUPPORTED"
);
assert.equal(fs.existsSync(SETTINGS), false);
});
});
describe("router-apply — Codex lane", () => {
it("writes a profile layer file, never the base config", () => {
const base = path.join(process.env.CODEX_HOME, "config.toml");
-289
View File
@@ -1,289 +0,0 @@
/**
* @file Tests server/lib/skill-plugins.js — the dependency the ship-feature
* pipelines have on other plugins (`superpowers` today): deriving it from the
* templates, deciding what is actually missing, and the unattended install the
* SessionStart bootstrap performs.
*
* The security-relevant case is covered first: a pipeline template is a file
* anyone may drop into DASHBOARD_PIPELINES_DIR, so a plugin name appearing
* there must be REPORTED but never INSTALLED. Every case injects a fake `run`
* — no test may reach a real `claude plugin install`.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { describe, it, after, beforeEach } = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const TMP_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-skill-plugins-home-"));
const TMP_PIPELINES = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-skill-plugins-tpl-"));
process.env.CLAUDE_HOME = TMP_HOME;
const skillPlugins = require("../lib/skill-plugins");
const pipelines = require("../lib/pipelines");
after(() => {
fs.rmSync(TMP_HOME, { recursive: true, force: true });
fs.rmSync(TMP_PIPELINES, { recursive: true, force: true });
delete process.env.CLAUDE_HOME;
delete process.env.DASHBOARD_PIPELINES_DIR;
pipelines.reload();
});
/** An empty Claude home: no plugins installed, no user skills. */
function emptyHome() {
fs.rmSync(TMP_HOME, { recursive: true, force: true });
fs.mkdirSync(path.join(TMP_HOME, "plugins"), { recursive: true });
fs.mkdirSync(path.join(TMP_HOME, "skills"), { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "plugins", "installed_plugins.json"),
JSON.stringify({ plugins: {} })
);
fs.writeFileSync(path.join(TMP_HOME, "settings.json"), JSON.stringify({}));
}
/** Point the loader at a throwaway template naming `command` on one node. */
function useTemplate(doc) {
fs.writeFileSync(path.join(TMP_PIPELINES, "test.json"), JSON.stringify(doc));
process.env.DASHBOARD_PIPELINES_DIR = TMP_PIPELINES;
pipelines.reload();
}
function forgetTemplate() {
fs.rmSync(path.join(TMP_PIPELINES, "test.json"), { force: true });
delete process.env.DASHBOARD_PIPELINES_DIR;
pipelines.reload();
}
/** Records the argv of every call and answers with a fixed result. */
function fakeRun(results) {
const calls = [];
const queue = [...results];
const run = (args) => {
calls.push(args);
return queue.length > 1 ? queue.shift() : queue[0];
};
run.calls = calls;
return run;
}
const collect = () => {
const lines = [];
const log = (line) => lines.push(line);
log.lines = lines;
return log;
};
beforeEach(() => {
emptyHome();
forgetTemplate();
});
describe("requiredSkillPlugins", () => {
it("collects the plugin behind every /plugin:skill a template names, node or pipeline level", () => {
const required = skillPlugins.requiredSkillPlugins();
assert.ok(required.has("superpowers"), "the built-in templates name superpowers");
assert.ok(required.get("superpowers").has("writing-plans"));
});
it("ignores agenthub's own commands and anything that is not a /plugin:skill", () => {
useTemplate({
id: "tpl-shell",
skill: "/agenthub:ship-feature",
nodes: [
{ id: "a", command: "npm test" },
{ id: "b", command: "/reload-plugins" },
{ id: "c", command: "" },
],
});
const required = skillPlugins.requiredSkillPlugins();
assert.equal(required.has("agenthub"), false, "agenthub is the plugin asking");
// Only the built-ins' superpowers requirement survives.
assert.deepEqual([...required.keys()], ["superpowers"]);
});
});
describe("missingSkillPlugins", () => {
it("reports a required plugin that is absent, with the skills that need it", () => {
const missing = skillPlugins.missingSkillPlugins();
const sp = missing.find((m) => m.name === "superpowers");
assert.ok(sp, "superpowers must be reported missing in an empty home");
assert.ok(sp.skills.includes("writing-plans"));
assert.equal(sp.autoInstall.spec, "superpowers@claude-plugins-official");
});
it("counts the skills as satisfied when they sit in ~/.claude/skills instead", () => {
for (const name of skillPlugins.requiredSkillPlugins().get("superpowers")) {
fs.mkdirSync(path.join(TMP_HOME, "skills", name), { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "skills", name, "SKILL.md"),
`---\nname: ${name}\n---\n\nbody\n`
);
}
assert.deepEqual(skillPlugins.missingSkillPlugins(), []);
});
it("counts an installed but explicitly disabled plugin as missing", () => {
const dir = path.join(TMP_HOME, "plugins", "sp");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "plugins", "installed_plugins.json"),
JSON.stringify({ plugins: { "superpowers@x": [{ installPath: dir, scope: "user" }] } })
);
fs.writeFileSync(
path.join(TMP_HOME, "settings.json"),
JSON.stringify({ enabledPlugins: { "superpowers@x": false } })
);
assert.ok(skillPlugins.missingSkillPlugins().some((m) => m.name === "superpowers"));
});
});
describe("autoInstallSkillPlugins", () => {
it("installs an allowlisted plugin with an argv array, never a shell string", () => {
const run = fakeRun([{ ok: true, output: "" }]);
const log = collect();
const summary = skillPlugins.autoInstallSkillPlugins(log, { run });
assert.deepEqual(summary.installed, ["superpowers"]);
assert.deepEqual(run.calls, [
["plugin", "install", "superpowers@claude-plugins-official", "--scope", "user", "-y"],
]);
assert.ok(
log.lines.some((l) => l.includes("/reload-plugins")),
"the user must be told the current session will not see it yet"
);
});
it("registers the marketplace and retries exactly once when the install fails", () => {
const run = fakeRun([
{ ok: false, output: "unknown marketplace" },
{ ok: true, output: "" },
{ ok: true, output: "" },
]);
const summary = skillPlugins.autoInstallSkillPlugins(collect(), { run });
assert.deepEqual(summary.installed, ["superpowers"]);
assert.equal(run.calls.length, 3);
assert.deepEqual(run.calls[1], [
"plugin",
"marketplace",
"add",
"anthropics/claude-plugins-official",
"--scope",
"user",
]);
});
it("reports a failure with the manual command, and never throws", () => {
const run = fakeRun([{ ok: false, output: "the `claude` CLI is not on PATH" }]);
const log = collect();
const summary = skillPlugins.autoInstallSkillPlugins(log, { run });
assert.deepEqual(summary.failed, ["superpowers"]);
assert.ok(
log.lines.some((l) =>
l.includes("claude plugin install superpowers@claude-plugins-official")
),
"a failed auto-install must leave the user a command to run"
);
});
// The one that matters. A template is a file on disk; if the plugin name in
// it drove the install, dropping a JSON file into DASHBOARD_PIPELINES_DIR
// would run an arbitrary vendor's install command on the next session.
it("REFUSES to install a plugin a template names but the allowlist does not", () => {
useTemplate({
id: "tpl-evil",
name: "Untrusted",
nodes: [{ id: "a", command: "/attacker-plugin:payload" }],
});
const run = fakeRun([{ ok: true, output: "" }]);
const summary = skillPlugins.autoInstallSkillPlugins(collect(), { run });
assert.ok(summary.skipped.includes("attacker-plugin"), "it must be reported as skipped");
assert.equal(
run.calls.some((args) => args.join(" ").includes("attacker-plugin")),
false,
"no claude invocation may ever mention a plugin outside AUTO_INSTALLABLE"
);
// It is still visible to the reader, just never installed.
assert.ok(skillPlugins.missingSkillPlugins().some((m) => m.name === "attacker-plugin"));
});
it("does nothing at all when every requirement already resolves", () => {
for (const name of skillPlugins.requiredSkillPlugins().get("superpowers")) {
fs.mkdirSync(path.join(TMP_HOME, "skills", name), { recursive: true });
fs.writeFileSync(
path.join(TMP_HOME, "skills", name, "SKILL.md"),
`---\nname: ${name}\n---\n\nbody\n`
);
}
const run = fakeRun([{ ok: true, output: "" }]);
const summary = skillPlugins.autoInstallSkillPlugins(collect(), { run });
assert.deepEqual(summary.attempted, []);
assert.deepEqual(run.calls, []);
});
});
describe("runClaudePlugin: the env it spawns with", () => {
// Every other test in this file injects `run`, so nothing exercises the real
// spawn. That gap is how a wrong CLAUDE_CONFIG_DIR pin lived here: the CLI
// writes `.claude.json` INSIDE that dir, while cc-discovery reads it beside
// ~/.claude by default, so pinning it unconditionally aimed writes at a file
// nothing reads. cc-plugin-cli.js's runClaude has the mirror of this test.
const PRINT_ENV = 'printf "%s\\n" "CLAUDE_CONFIG_DIR=${CLAUDE_CONFIG_DIR-<unset>}"';
function stubClaude(body) {
const bin = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-skillplug-bin-"));
const file = path.join(bin, "claude");
fs.writeFileSync(file, `#!/usr/bin/env bash\n${body}\n`);
fs.chmodSync(file, 0o755);
const originalPath = process.env.PATH;
process.env.PATH = `${bin}${path.delimiter}${originalPath}`;
return () => {
process.env.PATH = originalPath;
fs.rmSync(bin, { recursive: true, force: true });
};
}
it("leaves CLAUDE_CONFIG_DIR unset when CLAUDE_HOME is not set", () => {
const original = process.env.CLAUDE_HOME;
delete process.env.CLAUDE_HOME;
const restore = stubClaude(PRINT_ENV);
try {
const res = skillPlugins.runClaudePlugin(["plugin", "list"], 10_000);
assert.equal(res.output.trim(), "CLAUDE_CONFIG_DIR=<unset>");
} finally {
restore();
if (original !== undefined) process.env.CLAUDE_HOME = original;
}
});
it("pins CLAUDE_CONFIG_DIR to CLAUDE_HOME when the operator set it", () => {
const original = process.env.CLAUDE_HOME;
process.env.CLAUDE_HOME = "/tmp/some-other-claude-home";
const restore = stubClaude(PRINT_ENV);
try {
const res = skillPlugins.runClaudePlugin(["plugin", "list"], 10_000);
assert.equal(res.output.trim(), "CLAUDE_CONFIG_DIR=/tmp/some-other-claude-home");
} finally {
restore();
if (original === undefined) delete process.env.CLAUDE_HOME;
else process.env.CLAUDE_HOME = original;
}
});
});
-83
View File
@@ -1,83 +0,0 @@
/**
* @file Tests for skills-install.js: skill-copy path resolution (source:
* repoRoot/skills/ not repoRoot/.claude/skills/) and error handling.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const os = require("node:os");
const path = require("node:path");
const fs = require("node:fs");
const SUITE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-skills-"));
process.env.DASHBOARD_DB_PATH = path.join(SUITE_ROOT, "dashboard.db");
const { describe, it, after } = require("node:test");
const assert = require("node:assert/strict");
const { installShipFeatureLaneSkill } = require("../lib/skills-install");
after(() => fs.rmSync(SUITE_ROOT, { recursive: true, force: true }));
describe("installShipFeatureLaneSkill", () => {
it("resolves source from repoRoot/skills/ (new path), not .claude/skills/", () => {
// Build a fake repoRoot with the skill only under skills/ship-feature-lane/
const repoRoot = path.join(SUITE_ROOT, "mock-repo");
const src = path.join(repoRoot, "skills", "ship-feature-lane");
fs.mkdirSync(src, { recursive: true });
fs.writeFileSync(path.join(src, "SKILL.md"), "# Fake Ship Feature Lane Skill");
// The old path should NOT exist
const oldPath = path.join(repoRoot, ".claude", "skills", "ship-feature-lane", "SKILL.md");
assert.equal(fs.existsSync(oldPath), false);
// Override HOME so we don't touch real ~/.claude
const origHome = process.env.HOME;
const fakeHome = path.join(SUITE_ROOT, "fake-home");
process.env.HOME = fakeHome;
try {
const result = installShipFeatureLaneSkill({ repoRoot });
assert.equal(result.installed, true);
assert.ok(result.path.startsWith(fakeHome));
const installedFile = path.join(result.path, "SKILL.md");
assert.ok(fs.existsSync(installedFile));
assert.equal(fs.readFileSync(installedFile, "utf8"), "# Fake Ship Feature Lane Skill");
} finally {
process.env.HOME = origHome;
}
});
it("throws ENOSKILLSRC when skills/ship-feature-lane/ is missing", () => {
const repoRoot = path.join(SUITE_ROOT, "empty-repo");
fs.mkdirSync(repoRoot, { recursive: true });
assert.throws(
() => installShipFeatureLaneSkill({ repoRoot }),
(err) => err.code === "ENOSKILLSRC"
);
});
it("overwrites an existing installed skill (force: true)", () => {
const repoRoot = path.join(SUITE_ROOT, "mock-repo-overwrite");
const src = path.join(repoRoot, "skills", "ship-feature-lane");
fs.mkdirSync(src, { recursive: true });
fs.writeFileSync(path.join(src, "SKILL.md"), "# Updated skill");
const origHome = process.env.HOME;
const fakeHome = path.join(SUITE_ROOT, "fake-home-overwrite");
process.env.HOME = fakeHome;
try {
// First install
installShipFeatureLaneSkill({ repoRoot });
// Tamper with installed copy
const existing = path.join(fakeHome, ".claude", "skills", "ship-feature-lane", "SKILL.md");
fs.writeFileSync(existing, "# Tampered");
// Reinstall — should overwrite
installShipFeatureLaneSkill({ repoRoot });
assert.equal(fs.readFileSync(existing, "utf8"), "# Updated skill");
} finally {
process.env.HOME = origHome;
}
});
});
+30 -13
View File
@@ -97,7 +97,6 @@ const remoteSourcesRouter = require("./routes/remote-sources");
const metricsRouter = require("./routes/metrics");
const lanesRouter = require("./routes/lanes");
const locksRouter = require("./routes/locks");
const skillsRouter = require("./routes/skills");
const APP_VERSION = (() => {
try {
@@ -141,7 +140,6 @@ function createApp() {
app.use("/api/webhooks", webhooksRouter);
app.use("/api/remote-sources", remoteSourcesRouter);
app.use("/api/metrics", metricsRouter);
app.use("/api/skills", skillsRouter);
app.get("/api/openapi.json", (_req, res) => {
res.json(openApiSpec);
});
@@ -480,9 +478,22 @@ function startBackgroundServices() {
} catch (err) {
console.warn("workflow poll failed to start:", err.message);
}
// Codex lane stage detection. Codex emits no hooks at all, so its rollout
// journals on disk are the only signal a `codex` lane is working — without
// this poll such a lane's pipeline map never moves. `broadcastLane` (not the
// Codex lanes carry no pipeline. Older builds inferred one and wrote a stage
// block into their AGENTS.md; take both back out. Idempotent, every start.
try {
const lanesLib = require("./lib/lanes");
const { removeStageDoc } = require("./lib/lane-agents");
const wiped = lanesLib.clearCodexPipelines();
if (wiped > 0) console.log(`Cleared leftover pipeline data from ${wiped} codex lane(s)`);
for (const lane of lanesLib.listLanes().filter((l) => l.tool === "codex")) {
if (removeStageDoc(lane.cwd))
console.log(`Removed the AgentHub stage block from ${lane.cwd}/AGENTS.md`);
}
} catch (err) {
console.warn("codex pipeline cleanup failed:", err.message);
}
// Codex lane status. Codex emits no hooks at all, so its rollout journals on
// disk are the only signal a `codex` lane is working. `broadcastLane` (not the
// bare `broadcast(type, data)` above) is the single-lane push the hook route
// uses.
try {
@@ -491,14 +502,20 @@ function startBackgroundServices() {
} catch (err) {
console.warn("codex poll failed to start:", err.message);
}
// Safety net: a codex lane only declares stage when the session calls
// `agenthub stage` itself. When auto-detection has clearly moved on without a
// matching declaration, nudge the session's own pane to make the real call
// — never writes stage itself, so the declared-wins invariant is untouched.
try {
require("./lib/codex-nudge").startCodexNudge();
} catch (err) {
console.warn("codex nudge failed to start:", err.message);
// A codex/antigravity pane that exits fires no hook, so release its lane on
// a beat instead (one `tmux has-session` per lane with a run). Off with
// DASHBOARD_RUN_HEAL_MS=0.
const HEAL_MS = Number(process.env.DASHBOARD_RUN_HEAL_MS ?? 10_000);
if (Number.isFinite(HEAL_MS) && HEAL_MS > 0) {
const { healAllRunIds } = require("./routes/lanes");
const healTimer = setInterval(() => {
try {
healAllRunIds();
} catch (err) {
console.warn("run heal failed:", err.message);
}
}, HEAL_MS);
if (healTimer.unref) healTimer.unref();
}
// Continuous discovery of sessions under ~/.claude/projects. The one-time
// legacy backfill above runs only once (marker-gated), so a project added
+22 -222
View File
@@ -1,26 +1,16 @@
/**
* @file Codex stage ingestion. Codex emits no hooks, so the path that infers a
* lane's stage (server/routes/hooks.js → stage-detect.detect) can never see a
* `codex` lane — and it is deliberately pinned to `claude`, because a Claude
* hook must never touch a codex lane sharing the same directory. Codex's
* on-disk equivalent is the rollout journal it appends live, one file per
* thread:
* @file Codex lane status mirror. Codex emits no hooks, so nothing else can
* tell the dashboard that a `codex` lane's agent is working. Its on-disk
* signal is the rollout journal it appends live, one file per thread:
*
* $CODEX_HOME/sessions/<YYYY>/<MM>/<DD>/rollout-<ts>-<threadId>.jsonl
* line 1: {"type":"session_meta","payload":{"cwd":…,"session_id":…}}
* then: {"type":"response_item","payload":{"type":"custom_tool_call",…}}
*
* This module tails those journals for the cwd of every `codex` lane, maps each
* tool-call payload onto the same `{tool_name, tool_input}` shape a Claude hook
* delivers, and feeds the EXISTING detect() + recordDetection() path — so a
* codex lane paints the same amber "detected" badge under the same rules
* (forward-only, declared-wins) and never renders `done`. A written detection
* then ALSO advances the lane's declared `stage` to that node, without
* evidence: codex lanes are the one place where nothing else can move the
* pipeline map, so the node renders `passed-no-evidence` (amber) rather than
* `done`, and codex-nudge.js asks the session for the real evidence. Like
* workflow-ingest.js, everything here is fail-safe: a malformed or partial
* journal throws only locally and is skipped, and a poll pass never throws.
* This module maps each journal to the `codex` lane owning its cwd and mirrors
* idle↔running from how recently the journal was written. It reads nothing but
* the first line (for the cwd) and never touches a lane's stage — codex lanes
* carry no pipeline. Fail-safe like workflow-ingest.js: a malformed journal is
* skipped, and a poll pass never throws.
*
* Codex 0.149 also mirrors threads into version-suffixed SQLite files
* (`state_5.sqlite`, `thread_history_1.sqlite`), but every thread row still
@@ -35,70 +25,10 @@ const path = require("node:path");
const os = require("node:os");
const { getCodexHome } = require("./codex-home");
// `*** Update File: <path>` lines inside an apply_patch heredoc.
const PATCH_FILE_RE = /^\*\*\* (Add|Update|Delete) File: (.+)$/gm;
const SHELL_NAMES = new Set(["exec", "exec_command", "shell", "local_shell", "container.exec"]);
const CODEX_ACTIVE_MS = 120_000; // a journal written within 2 min means the agent is working
const TAIL_BYTES = 64 * 1024; // first sight of a live file: read only its recent tail
const MAX_FILES = 40; // newest-first cap so a years-deep sessions/ tree can't stall a pass
const MAX_READ_BYTES = 4 * 1024 * 1024; // one pass never buffers more than this per journal
const MAX_DEPTH = 4; // sessions/<YYYY>/<MM>/<DD>/<file>
/** The `cmd` of a shell call, whether it arrived as JSON arguments or an exec script. */
function commandFromPayload(payload, text) {
try {
const parsed = JSON.parse(payload.arguments);
if (parsed && typeof parsed.cmd === "string") return parsed.cmd;
if (parsed && Array.isArray(parsed.command)) return parsed.command.join(" ");
} catch {
/* not JSON — an exec script; the detect rules match inside it verbatim */
}
return text;
}
/**
* Hook-shaped events for one rollout payload. A patch script yields one event
* per touched file (Write for a new file, Edit otherwise — the split the
* pipeline templates' detect rules assume); a shell call yields one Bash event.
* Anything else — reasoning, messages, tool OUTPUT, a web search — yields
* nothing, so an unknown Codex tool can never be mistaken for work.
*
* @param {object|null} payload - One rollout line's `payload` object.
* @returns {Array<{tool_name: string, tool_input: object}>}
*/
function eventsFromPayload(payload) {
if (!payload || typeof payload !== "object") return [];
if (payload.type !== "custom_tool_call" && payload.type !== "function_call") return [];
const name = typeof payload.name === "string" ? payload.name : "";
const text = typeof payload.input === "string" ? payload.input : String(payload.arguments || "");
if (name === "update_plan") return [{ tool_name: "TaskCreate", tool_input: {} }];
if (name === "spawn_agent") {
let taskName = "";
try {
taskName = JSON.parse(payload.arguments).task_name || "";
} catch {
/* encrypted or malformed arguments — the tool name alone still matters */
}
return [{ tool_name: "Agent", tool_input: { subagent_type: taskName } }];
}
if (!SHELL_NAMES.has(name)) return [];
// A patch heredoc reaches us inside a JS string literal, so its line breaks
// are usually a literal backslash-n rather than newlines (real rollouts carry
// both forms in the same script). Unescape before scanning or the file list
// comes back empty and a whole edit looks like a plain shell command.
const patched = [...text.replace(/\\n/g, "\n").matchAll(PATCH_FILE_RE)];
if (patched.length) {
return patched.map(([, verb, file]) => ({
tool_name: verb === "Add" ? "Write" : "Edit",
tool_input: { file_path: file.trim() },
}));
}
return [{ tool_name: "Bash", tool_input: { command: commandFromPayload(payload, text) } }];
}
/** Every rollout journal under sessions/, newest mtime first, capped at MAX_FILES. */
function rolloutFiles() {
const out = [];
@@ -151,101 +81,29 @@ function rolloutCwd(file) {
return cwd;
}
const offsets = new Map(); // rollout path → bytes already ingested
/** Test seam: forget every journal's ingest position (and cached cwd). */
function __resetOffsets() {
offsets.clear();
/** Test seam: forget every cached cwd. */
function __resetCache() {
cwdCache.clear();
}
// Both maps are keyed by file path, so in a process that runs for months they
// would otherwise hold one dead entry per journal Codex ever wrote. Pruned only
// once well past the per-pass scan size, so ordinary churn keeps its positions
// and a journal that drops out of the scan behaves exactly as it does after a
// server restart: re-seen as new, and read only if it is being written to.
// Keyed by file path, so in a process that runs for months it would otherwise
// hold one dead entry per journal Codex ever wrote. Pruned only once well past
// the per-pass scan size, so ordinary churn keeps its entries.
const MAX_TRACKED = MAX_FILES * 4;
function pruneTracking(seen) {
for (const map of [offsets, cwdCache]) {
if (map.size <= MAX_TRACKED) continue;
for (const key of map.keys()) if (!seen.has(key)) map.delete(key);
}
}
/** Read `[from, size)` of a file, or an empty buffer when it can't be read. */
function readRange(file, from, size) {
try {
const fd = fs.openSync(file, "r");
try {
const buf = Buffer.alloc(size - from);
const read = fs.readSync(fd, buf, 0, buf.length, from);
return buf.subarray(0, read);
} finally {
fs.closeSync(fd);
}
} catch {
return Buffer.alloc(0);
}
if (cwdCache.size <= MAX_TRACKED) return;
for (const key of cwdCache.keys()) if (!seen.has(key)) cwdCache.delete(key);
}
/**
* The COMPLETE lines in `[from, size)`, plus the offset to resume from.
*
* Two fragments have to be handled, and only one of them is dropped:
* - a tail read (`firstSight` with `from > 0`) starts mid-line, so its leading
* fragment is discarded;
* - a read that catches the writer mid-line ends with a fragment, so the
* returned offset stops at the last newline and that fragment is re-read
* whole on the next pass.
*
* Every non-tail read therefore starts exactly on a line boundary, where the
* first line is a WHOLE record. Dropping it there — the obvious "the offset
* always lands mid-line" shortcut — loses every append that arrives one line at
* a time, which is how a journal actually grows.
*
* All of it is done on the BUFFER, never on a decoded string: a tail offset can
* land inside a multi-byte UTF-8 sequence, where the decoder emits a 3-byte
* U+FFFD for 1-2 consumed bytes. Measuring a decoded slice with
* `Buffer.byteLength` would then move the offset off the real line boundary and
* every later record would fail to parse.
*/
const NEWLINE = 0x0a;
function completeLines(file, from, size, firstSight) {
let chunk = readRange(file, from, size);
let start = from;
if (firstSight && from > 0) {
const firstBreak = chunk.indexOf(NEWLINE);
if (firstBreak === -1) return { lines: [], next: size };
start += firstBreak + 1;
chunk = chunk.subarray(firstBreak + 1);
}
const lastBreak = chunk.lastIndexOf(NEWLINE);
if (lastBreak === -1) return { lines: [], next: start };
return {
lines: chunk.subarray(0, lastBreak).toString("utf8").split("\n"),
next: start + lastBreak + 1,
};
}
/**
* One poll pass. Reads only the bytes appended since the last pass; on the
* first sight of a file, only its recent tail, and nothing at all when the file
* is already idle — replaying a thread that finished days ago would paint
* stages from work nobody is doing.
*
* Detection uses the LAST matching event of the batch, mirroring "one hook, one
* detection"; recordDetection is forward-only, so ordering inside a batch can
* never drag a lane backwards.
* One poll pass: mirror each codex lane's idle↔running from its journals.
*
* @param {{broadcast?: (laneId: number) => void}} [options]
* @returns {number} How many lanes actually changed (and were broadcast).
*/
function ingestCodexOnce({ broadcast } = {}) {
const lanesLib = require("./lanes");
const { detect } = require("./stage-detect");
const { getPipeline } = require("./pipelines");
let codexLanes = [];
try {
@@ -266,67 +124,12 @@ function ingestCodexOnce({ broadcast } = {}) {
.sort((a, b) => b.cwd.length - a.cwd.length)[0];
if (!lane) continue;
const firstSight = !offsets.has(file.path);
// An mtime in the FUTURE (clock stepped back, NTP correction, a restore that
// preserved timestamps) makes the raw difference negative, which reads as
// "written milliseconds ago" and would let a finished thread's journal
// replay as live work. A file that claims to be from the future is not
// evidence of an agent working now, so treat it as idle.
// "written milliseconds ago". A file that claims to be from the future is
// not evidence of an agent working now, so treat it as idle.
const age = Date.now() - file.mtime;
const active = age >= 0 && age < CODEX_ACTIVE_MS;
let from = firstSight ? Math.max(0, file.size - TAIL_BYTES) : offsets.get(file.path);
// A stored offset past EOF means the file was truncated or a new thread took
// the same path. Restart from a bounded tail, never from 0: reading a
// multi-gigabyte journal whole would allocate it all in one buffer.
let tailOnly = firstSight;
if (from > file.size || file.size - from > MAX_READ_BYTES) {
from = Math.max(0, file.size - TAIL_BYTES);
tailOnly = true;
}
let changed = false;
// A journal seen for the first time while already idle is history, not work:
// note where it ends and read nothing.
if (firstSight && !active) {
offsets.set(file.path, file.size);
} else if (file.size > from) {
const { lines, next } = completeLines(file.path, from, file.size, tailOnly);
offsets.set(file.path, next);
const pipeline = getPipeline(lane.pipeline);
let detection = null;
for (const raw of lines) {
if (!raw.trim()) continue;
let payload = null;
try {
payload = JSON.parse(raw).payload;
} catch {
continue; // not a record this module understands
}
for (const event of eventsFromPayload(payload)) {
const hit = detect(pipeline, event);
if (hit) detection = hit;
}
}
if (detection) {
try {
changed = lanesLib.recordDetection(lane.id, detection).written;
// Auto-advance: a codex session has no hook and rarely calls `agenthub
// stage` on its own, so without this its card sits at `idle` forever
// while the amber badge is the only thing that ever moves. Gated on
// recordDetection having WRITTEN, so it inherits that function's
// forward-only + declared-wins + TTL guards for free. Deliberately
// passes NO evidence: the node renders `passed-no-evidence` (amber),
// never `done` — detection sees a tool call, never its outcome. The
// last node has no detect rules in any template, so this can never
// auto-declare a lane `done`.
if (changed) {
lanesLib.setStage(lane.id, { stage: detection.nodeId, keepDetection: true });
}
} catch {
/* lane deleted mid-pass, or sqlite busy — an inference is never worth throwing for */
}
}
}
// Status mirror, under the same guard hook ingestion uses: only idle↔running,
// and only for a lane the dashboard did not launch — provisioning and failed
@@ -340,12 +143,11 @@ function ingestCodexOnce({ broadcast } = {}) {
) {
try {
lanesLib.updateLane(lane.id, { status: next });
changed = true;
touched.add(lane.id);
} catch {
/* as above */
/* lane deleted mid-pass, or sqlite busy — a status mirror is never worth throwing for */
}
}
if (changed) touched.add(lane.id);
}
for (const id of touched) {
@@ -361,8 +163,7 @@ function ingestCodexOnce({ broadcast } = {}) {
/**
* Unref'd interval so it never blocks shutdown; disable with
* DASHBOARD_CODEX_POLL_MS=0. Codex appends its journal continuously, so a 15s
* beat keeps a codex card within one node of live without ever re-reading what
* it has already ingested.
* beat keeps a codex card's running/idle within one beat of live.
*/
function startCodexPoll(broadcast) {
const POLL_MS = process.env.DASHBOARD_CODEX_POLL_MS
@@ -380,9 +181,8 @@ function startCodexPoll(broadcast) {
}
module.exports = {
eventsFromPayload,
rolloutCwd,
ingestCodexOnce,
startCodexPoll,
__resetOffsets,
__resetCache,
};
-103
View File
@@ -1,103 +0,0 @@
/**
* @file Safety-net reminder for codex lanes sitting at a stage nobody has
* backed with evidence. `codex-ingest.js` auto-advances a codex lane's stage
* from its rollout journal — that keeps the pipeline map moving, but an
* inferred stage carries no evidence, so its node renders
* `passed-no-evidence` (amber) rather than `done`. Only the session's own
* `agenthub stage <node> --evidence "..."` call can supply that, and a codex
* session has no hook or wrapper that does it for it.
*
* This module never writes `stage`, `stages` or `detected_stage` itself. It
* only types a plain-text reminder into the lane's own live tmux pane
* (`tmux.sendText`), the same way a human watching the dashboard would nudge
* the agent — so the evidence that results is still a REAL declaration the
* codex session made itself.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const NUDGE_DELAY_MS = 120_000; // give the session 2 min to declare on its own first
// Per-lane memory of the last stage already nudged for, so the 60s sweep
// doesn't retype the same reminder every pass. Cleared implicitly: once the
// session declares with evidence, or the lane moves to another node, the value
// here no longer matches and a fresh nudge is due.
// ponytail: in-memory, resets on server restart — worst case one duplicate
// nudge after a restart, not worth a DB column for.
const nudgedFor = new Map();
/**
* One sweep pass: nudge every codex lane whose CURRENT stage has been held for
* at least NUDGE_DELAY_MS with no evidence recorded, and hasn't already been
* nudged for that exact stage.
* @returns {number} How many lanes were nudged.
*/
function sweepCodexNudges() {
const lanes = require("./lanes");
const tmux = require("./tmux");
const { SHELL_COMMANDS, runIdForLane } = require("./pty-run");
let codexLanes = [];
try {
codexLanes = lanes.listLanes().filter((l) => l.tool === "codex" && l.run_id);
} catch {
return 0;
}
let nudged = 0;
for (const lane of codexLanes) {
try {
// No record under the current stage means the lane never entered a
// pipeline node (a fresh lane sits at `idle`) — nothing to ask about.
const record = (lane.stages || {})[lane.stage];
if (!record || record.evidence) {
nudgedFor.delete(lane.id);
continue;
}
const enteredAt = Date.parse(record.enteredAt);
if (!Number.isFinite(enteredAt) || Date.now() - enteredAt < NUDGE_DELAY_MS) continue;
if (nudgedFor.get(lane.id) === lane.stage) continue;
const runId = runIdForLane(lane.id);
if (!tmux.hasSession(runId)) continue;
// A bare shell prompt has no chat turn to submit into — pressing Enter
// there would run the reminder text as a shell command instead.
if (SHELL_COMMANDS.has(tmux.paneCommand(runId) || "")) continue;
tmux.sendText(
runId,
`[agenthub] Stage "${lane.stage}" was inferred and has no evidence — run: agenthub stage ${lane.stage} --tool codex --evidence "..."`
);
nudgedFor.set(lane.id, lane.stage);
nudged += 1;
} catch {
/* one lane's failure must not abort the sweep */
}
}
return nudged;
}
/** Unref'd so it never blocks shutdown; disable with DASHBOARD_CODEX_NUDGE_MS=0. */
function startCodexNudge() {
const POLL_MS = process.env.DASHBOARD_CODEX_NUDGE_MS
? Number(process.env.DASHBOARD_CODEX_NUDGE_MS)
: 60_000;
if (!Number.isFinite(POLL_MS) || POLL_MS <= 0) return;
const timer = setInterval(() => {
try {
sweepCodexNudges();
} catch {
/* a sweep pass never throws into the event loop */
}
}, POLL_MS);
if (timer.unref) timer.unref();
}
function __resetNudgeState() {
nudgedFor.clear();
}
module.exports = {
sweepCodexNudges,
startCodexNudge,
__resetNudgeState,
};
+1 -1
View File
@@ -89,7 +89,7 @@ function recordRun(handle) {
started_at: startedAt,
ended_at: endedAt,
lane_id: typeof handle.laneId === "number" ? handle.laneId : null,
tool: handle.tool === "codex" ? "codex" : "claude",
tool: handle.tool === "codex" || handle.tool === "antigravity" ? handle.tool : "claude",
});
} catch (err) {
// Best-effort by design (a live run must never fail because sqlite did),
+62 -3
View File
@@ -760,7 +760,9 @@ async function lsFiles(dir, args) {
const all = out.split("\0");
// A complete listing ends in NUL (last token ""); a cut one ends mid-path.
const cut = all.pop() !== "";
return { all: all.filter(Boolean), cut };
// Mid-merge, `ls-files --cached` prints a conflicted path once per stage
// (base, ours, theirs): one path is one file.
return { all: [...new Set(all.filter(Boolean))], cut };
}
/** What the explorer lists: tracked files plus untracked ones git does not
@@ -849,8 +851,13 @@ async function listTree(dir, { subdir = "" } = {}) {
* applied is always git's own text of the current tree — never a patch a
* request carried. Null when no hunk matches (the tree moved on, or the file
* is a secret, binary or too large to read whole).
*
* `block` narrows it to one CHANGE BLOCK of that hunk — a run of consecutive
* +/- lines. git merges changes up to 2×context lines apart into one hunk, so
* without this a single Undo/Keep acted on every nearby edit at once (#50).
* `reverse` says which side the patch will be applied to (see `onlyBlock`).
*/
async function hunkPatch(dir, file, header, context) {
async function hunkPatch(dir, file, header, context, { block, reverse = false } = {}) {
if (!header || (await isSecretOnDisk(dir, file))) return null;
const u = `-U${normalizeContext(context)}`;
const raw = await readCapped(
@@ -869,7 +876,59 @@ async function hunkPatch(dir, file, header, context) {
.slice(at + 1)
.split(/^(?=@@ )/m)
.find((h) => h.slice(0, h.indexOf("\n")) === header);
return hunk ? head + (hunk.endsWith("\n") ? hunk : `${hunk}\n`) : null;
if (!hunk) return null;
const body = block === undefined ? hunk : onlyBlock(hunk, block, reverse);
return body ? head + (body.endsWith("\n") ? body : `${body}\n`) : null;
}
/**
* One hunk's text cut down to its `block`-th change block, the way an edited
* `git add -p` hunk is: every OTHER block is folded into the side the patch
* will be checked against, so that side stays byte-for-byte the hunk's own and
* `git apply` finds it exactly where git put it.
*
* - forward (stage, applied to the index = the OLD side): another block's
* "-" lines become context and its "+" lines are dropped;
* - reverse (undo, `apply -R` on the working tree = the NEW side): its "+"
* lines become context and its "-" lines are dropped.
*
* A "\ No newline" marker follows the line it annotates, kept or dropped with
* it. The header's counts are recomputed; its starts do not move, because the
* checked side is unchanged. Null when the hunk has no such block.
*/
function onlyBlock(hunk, block, reverse) {
if (!Number.isInteger(block) || block < 0) return null;
const [header, ...lines] = hunk.replace(/\n$/, "").split("\n");
const m = header.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/);
if (!m) return null;
const out = [];
let index = -1;
let inBlock = false;
let keptPrev = false;
let oldCount = 0;
let newCount = 0;
for (const line of lines) {
const mark = line[0];
if (mark === "\\") {
if (keptPrev) out.push(line);
continue;
}
const change = mark === "+" || mark === "-";
if (change && !inBlock) index += 1;
inBlock = change;
let kept = line;
if (change && index !== block) {
const fold = reverse ? "+" : "-";
kept = mark === fold ? ` ${line.slice(1)}` : null;
}
keptPrev = kept !== null;
if (kept === null) continue;
out.push(kept);
if (kept[0] !== "+") oldCount += 1;
if (kept[0] !== "-") newCount += 1;
}
if (block > index) return null;
return [`@@ -${m[1]},${oldCount} +${m[2]},${newCount} @@${m[3]}`, ...out].join("\n") + "\n";
}
/**

Some files were not shown because too many files have changed in this diff Show More