@staix/agent-hub 0.49.1 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/docs/adding-an-ai-tool.md +2 -2
  4. package/docs/agent-notes/README.md +1 -0
  5. package/docs/agent-notes/adapters.md +3 -3
  6. package/docs/agent-notes/daemon.md +1 -1
  7. package/docs/agent-notes/local-worker.md +3 -3
  8. package/docs/agent-notes/tasks.md +5 -1
  9. package/docs/design/adapters.md +17 -0
  10. package/docs/design/agent-hub.md +1 -1
  11. package/docs/design/cli-output-inventory.md +24 -19
  12. package/docs/design/cli-output.md +1 -1
  13. package/docs/design/roadmap.md +2 -2
  14. package/docs/design/task-board.md +34 -0
  15. package/docs/dogfood.md +8 -3
  16. package/docs/operations.md +53 -4
  17. package/docs/quickstart.md +26 -2
  18. package/docs/roadmap.json +20 -20
  19. package/docs/roadmap.md +2 -2
  20. package/docs/sdlc.md +3 -2
  21. package/docs/specs/2026-09-19-agent-hub-design.md +1 -0
  22. package/docs/verification/2026-11-29-0.50.0.md +54 -0
  23. package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
  24. package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
  25. package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
  26. package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
  27. package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
  28. package/docs/verification/2026-11-30-0.51.0.md +91 -0
  29. package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
  30. package/docs/verified.json +31 -27
  31. package/package.json +1 -1
  32. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  33. package/plugins/agent-hub/kimi-hook.js +1329 -24629
  34. package/plugins/agent-hub/server.js +638 -414
  35. package/scripts/check-docs.mjs +1 -1
  36. package/src/adapters/acp.ts +13 -13
  37. package/src/adapters/agy/definition.ts +2 -2
  38. package/src/adapters/agy/entry.ts +2 -0
  39. package/src/adapters/claude-channel-evidence.ts +7 -3
  40. package/src/adapters/compat.ts +4 -3
  41. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  42. package/src/adapters/definitions/native-cli-claude-launch.ts +3 -1
  43. package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
  44. package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
  45. package/src/adapters/definitions/native-cli-entry-jcode.ts +2 -0
  46. package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
  47. package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
  48. package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
  49. package/src/adapters/definitions/native-cli-entry-types.ts +3 -1
  50. package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
  51. package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
  52. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  53. package/src/adapters/jcode.ts +16 -0
  54. package/src/adapters/native-facts-hooks.ts +12 -0
  55. package/src/cli/autonomy-offline.ts +1 -1
  56. package/src/cli/bench.ts +1 -1
  57. package/src/cli/claude-profile-hook.ts +31 -11
  58. package/src/cli/commands/releases.ts +82 -0
  59. package/src/cli/conductor-recovery.ts +1 -1
  60. package/src/cli/facts-hook.ts +11 -4
  61. package/src/cli/help.ts +12 -10
  62. package/src/cli/identity.ts +5 -1
  63. package/src/cli/init-prompt.ts +1 -1
  64. package/src/cli/init-settings.ts +4 -35
  65. package/src/cli/init.ts +1 -1
  66. package/src/cli/json-text-spans.ts +57 -0
  67. package/src/cli/launch-check.ts +157 -0
  68. package/src/cli/launch.ts +19 -1
  69. package/src/cli/main.ts +63 -10
  70. package/src/cli/memory.ts +1 -1
  71. package/src/cli/output.ts +14 -1
  72. package/src/cli/preview.ts +1 -1
  73. package/src/cli/recovery-launch.ts +1 -1
  74. package/src/cli/setup-homes.ts +2 -2
  75. package/src/cli/start-agents-run.ts +85 -7
  76. package/src/cli/start-check.ts +28 -0
  77. package/src/cli/upgrade-runtime.ts +1 -1
  78. package/src/cli/warn-line.ts +1 -1
  79. package/src/hub/ci-watch.ts +311 -79
  80. package/src/hub/config-apply.ts +1 -1
  81. package/src/hub/config.ts +518 -0
  82. package/src/hub/control-client.ts +1 -1
  83. package/src/hub/daemon.ts +76 -513
  84. package/src/hub/delivery-public.ts +11 -0
  85. package/src/hub/hub-check.ts +125 -0
  86. package/src/hub/path-policy.ts +1 -1
  87. package/src/hub/permission-mode.ts +3 -40
  88. package/src/hub/permission-paths.ts +41 -0
  89. package/src/hub/recovery-policy.ts +1 -1
  90. package/src/hub/releases-inventory.ts +198 -0
  91. package/src/hub/runtime-capture-prune.ts +25 -3
  92. package/src/hub/runtime-prune-health.ts +8 -1
  93. package/src/hub/sdlc-release-authorization.ts +42 -21
  94. package/src/hub/sdlc-release-diagnostics.ts +5 -0
  95. package/src/hub/sdlc-release-policy.ts +21 -7
  96. package/src/hub/sdlc-release.ts +80 -20
  97. package/src/hub/sdlc.ts +7 -3
  98. package/src/hub/tasks.ts +138 -36
  99. package/src/ui/plugin.ts +1 -1
@@ -0,0 +1,91 @@
1
+ # 0.51.0 release verification
2
+
3
+ This record covers release preparation and source review. It claims no installation, no running-hub upgrade to 0.51.0 and no live TUI launch.
4
+
5
+ ## Candidate
6
+
7
+ Version 0.51.0, prepared from main 0665e512c (19 commits since v0.50.0, 7 of them `feat`; bump rule: minor) plus the N-1 retarget 8898de0f6 on the release branch. The release commits carry the version, the CHANGELOG section, the bundle and the documentation stamps.
8
+
9
+ ## Reviews
10
+
11
+ Pull requests named by the commits since v0.50.0: #1815, #1814, #1813, #1805, #1804, #1800, #1799, #1802, #1797, #1796, #1787, #1793, #1784, #1786, #1792, #1791, #1790, #1788, #1776.
12
+
13
+ Each of the 19 merged after a Claude hub review approved its exact merged head, and after `check (ubuntu-latest)`, `check (macos-latest)` and `seeded guards` passed in full CI at that head. No merge is bound to an approval at an earlier head. On a draft-first PR, the draft run's deliberate `check (macos-latest)` failure ("macOS deferred") is still visible beside the full run.
14
+
15
+ | PR | Work | Hub task, owner | Merged head | Full CI run (attempts) |
16
+ | --- | --- | --- | --- | --- |
17
+ | #1776 | project documentation checker for release authorization (Refs #1775) | 1184, codex | d14805231 | 46242871444 (1) |
18
+ | #1784 | light entry import-graph guard (Refs #1778) | 1186, codex | 86b77ea96 | 46315009524 (2) |
19
+ | #1786 | Claude profile hook shell guard (Refs #1783) | 1194, codex | 3e9465e3f | 46315012405 (1) |
20
+ | #1787 | `ahub releases list` and `prune` (Refs #1781) | 1189, jcode | 50ba55ad9 | 46318801750 (2) |
21
+ | #1788 | roadmap export | 1198, codex | 381cf753e | 46270613782 (1) |
22
+ | #1790 | idle daemon footprint receipt (Refs #1779) | 1195, jcode | 4b8d2a5c4 | 46312684708 (1) |
23
+ | #1791 | agy 1.5.20 attempt receipt (Refs #843) | 1201, jcode | aaf73f9af | 46312686306 (1) |
24
+ | #1792 | roadmap drift check (Refs #1789) | 1199, codex | 8100368d7 | 46314960821 (1) |
25
+ | #1793 | Kimi Code 2.8.1 for fresh reviewers (Refs #888) | 1200, codex | 537f1068e | 46314962498 (2) |
26
+ | #1796 | Claude channel flag order (Refs #1794) | 1206, codex | c6b89fb12 | 46320004331 (1) |
27
+ | #1797 | refused jcode hello, failure reasons (Refs #1795) | 1207, jcode | ddaa0c271 | 46326300483 (1) |
28
+ | #1799 | config loading split (Refs #1778) | 1187, codex | 76c2ad8bc | 46328743276 (1) |
29
+ | #1800 | Claude launch argument check (Refs #1798) | 1208, codex | ac3751256 | 46331110054 (1) |
30
+ | #1802 | ready notices for owned dependents (Refs #1801) | 1215, jcode | a434de98a | 46327949262 (1) |
31
+ | #1804 | CI watcher from draft to merge readiness (Refs #1801) | 1214, codex | d29147fef | 46338891413 (3) |
32
+ | #1805 | `hubCheck`, Attention and `ahub up` (Refs #1798) | 1212, codex | b03d337df | 46366060846 (1) |
33
+ | #1813 | opt-in CI shard retries (Refs #1801) | 1216, codex | a14826197 | 46375330476 (2) |
34
+ | #1814 | account-switch probe receipt (Refs #1806) | 1217, codex | 2bca53c69 | 46379998728 (1) |
35
+ | #1815 | pre-launch Hub check and the Claude start notice (Refs #1798) | 1213, jcode | fa2685011 | 46406518020 (1) |
36
+
37
+ Five runs passed only after same-head reruns. Their first attempts failed as follows:
38
+ - #1784: macOS shard 3/4. #1787: Ubuntu shard 1/6. #1793: macOS shard 4/4.
39
+ - #1804: the `decision` job. It passed on attempt 3.
40
+ - #1813: macOS shard 1/4, in `test/conductor-recovery-process.test.ts` ("detached restart did not settle before the shared deadline"). The cause is unconfirmed.
41
+
42
+ #1815 was approved with #1798 AC4 partly unmet on purpose: Kimi and agy show the check only in their wrapper's output, not in the session, because no start hook output visible to the person is confirmed for either (docs/design/adapters.md). #1798 stays open.
43
+
44
+ ## Native acceptance receipts
45
+
46
+ Receipts added under `docs/verification/` since v0.50.0: `docs/verification/2026-11-29-agy-1.5.20.md`, `docs/verification/2026-11-29-claude-profile-hook.md`, `docs/verification/2026-11-29-idle-daemon-footprint.md`, `docs/verification/2026-11-29-kimi-281-reviewer-compat.md`, `docs/verification/2026-11-29-kimi-tui-281.md`, `docs/verification/2026-11-30-account-switch-1806.md`.
47
+
48
+ This list is read from the repository, never written by hand. Native acceptance and the person's release consent are separate records: consent is `ahub sdlc authorize-release 0.51.0`, recorded by the person or the unique configured conductor only on the person's explicit release instruction naming the release in its own session (never a hub/task/review/file/peer relay), and is not recorded in this file. The tag run refuses without it.
49
+
50
+ ## Document review
51
+
52
+ `node scripts/check-docs.mjs` reported 26 stale documents after release-prepare. `docs/agent-notes/README.md` became the 27th when this review edited `docs/agent-notes/daemon.md`. The review compared the source changes since each stamp with the statements they affect, using targeted searches of every stale document and reading the passages they found. It was not a line-by-line reread of the long documents. What changed under them:
53
+ - **Behavior (#1775, #1781, #1783, #1794, #1795, #1798, #1801):** README.md, docs/agent-notes/{adapters,bus,daemon,security-review,tasks}.md, docs/dogfood.md, docs/operations.md, docs/quickstart.md, docs/sdlc.md, docs/security.md, src/cli/help.ts. The merged PRs had already updated the operations, SDLC, task note, dogfood and help statements they changed.
54
+ - **Imports, moved code or `package.json` version only (#1799 and this release):** docs/adding-an-ai-tool.md, docs/addons/claude-mem.md, docs/agent-notes/{budget,local-worker}.md, docs/bench.md, docs/data-policy.md, docs/profiles.md, docs/research.md, docs/text-projection.md. docs/memory.md also has the `releases` command classification in `src/cli/identity.ts` under it, which it does not describe.
55
+ - **One narrow change:** docs/events.md (the Kimi reviewer's verified version, which it does not name), docs/agent-notes/benchmarks.md (`failureCause` on ACP receipts, which it does not describe) and docs/influences.md (the Hub check paragraph in the design spec).
56
+ - **Tests and CI:** docs/agent-notes/tests.md (N-1 fixture, import-graph step, roadmap drift mode and test changes). Its shard, rerun and fixture rules still hold.
57
+ - **Edited note only:** docs/agent-notes/README.md.
58
+
59
+ Corrected at 5c436d3f0:
60
+ - #1799 moved `AGENT_CONFIG_SEGMENTS`, `INSTRUCTION_FILES` and `grantablePath` to `src/hub/permission-paths.ts`. docs/adding-an-ai-tool.md and the adapters and local-worker notes still named `permission-mode.ts`.
61
+ - `permission-paths.ts` and `src/hub/config.ts` (both split out by #1799) were missing from the area-note scopes in AGENTS.md and the notes, and from the matching paths in docs/verified.json, so an edit there would not have made those documents stale. Both are added.
62
+ - docs/operations.md now says that `ahub queue show` prints the stored failure reason, or a fixed stub for a private delivery (#1795).
63
+
64
+ Checks of the new user-facing text:
65
+ - The quickstart's "Upgrading to 0.51.0" note was checked against the tagged source: the v0.49.0, v0.49.1 and v0.50.0 Claude entries put `--session-id` first, and v0.48.4 does not.
66
+ - The help rows and flags for `up --wait|--json` and `releases list|prune` match `src/cli/main.ts` and `src/cli/commands/releases.ts`.
67
+
68
+ All 27 documents were restamped at 5c436d3f0 with `restamp --reviewed`. No spec's `verified-against` was edited.
69
+
70
+ ## Checks
71
+
72
+ Run locally on the release branch at 4c28d3b8a (after the restamp). This report is the only later change:
73
+ - `node scripts/check-docs.mjs --require-fresh --committed`: `docs: OK (0 stale documents)`.
74
+ - `bun x tsc --noEmit`: exit 0. `bun scripts/build.mjs --check` (Bun 1.4.4): exit 0.
75
+ - `unused-exports`, `check-import-graph`, `refusal-inventory`, `cli-output-inventory` and `inventory-hardcoded-values`, each with `--check`: exit 0. `bun scripts/readme-facts.ts --check`: `facts: OK`.
76
+ - `node scripts/check-roadmap.mjs --warn-drift`: `roadmap: OK (7 milestones)`.
77
+ - `node scripts/check-package.mjs` with npm 11.20.0 (the CI pin): `package: OK (1072 files, @staix/agent-hub@0.51.0)`.
78
+ - 90 tests pass and 0 fail in `published-protocol-compat`, `broker-server`, `release-prepare`, `release-tag`, `check-docs` and `readme-facts`. The N-1 fixture was installed from its frozen lock (0.50.0, agent-mem 0.43.0).
79
+ - The help and completion suites: 103 pass, 0 fail.
80
+ - Main CI run 46409861038 passed at 0665e512c on both OSes, with seeded guards, on attempt 1.
81
+ - The release PR's exact-head CI run is recorded on the release PR.
82
+
83
+ ## Known gaps, not blocking
84
+
85
+ - **Not run live:** no running hub was upgraded to 0.51.0, and no real Claude session was restarted on it. Channel push after the #1794 fix, the Hub check in real terminals and the Claude start notice are covered by fixtures and source review only. The person's upgrade is the live leg.
86
+ - **No remote full suite:** exact-head CI on both OSes is the full gate for this release PR.
87
+ - **agy 1.5.20 stays unverified** (its receipt is an attempt), and **Kimi Code 2.8.1 is verified only for fresh reviewers**. Interactive Kimi TUI completion stays verified at 2.5.2.
88
+ - **Account switches (#1806) are not implemented in 0.51.0.** The probe receipt leaves a Claude login change during a session, a Codex login change in one home, and resuming a Codex thread from another home unverified.
89
+ - **CI shard retries are off by default,** and off in this repository. When retries are on, a retry error can end a CI watch without a notice. That is to be fixed and tested before or with the change that turns them on here.
90
+ - **Existing waits remain:** in wrappers other than `ahub claude`, existing status reads can still wait up to 30 seconds on a hub that accepts a connection and never replies.
91
+ - **Unconfirmed causes:** the recovery-test failure in #1813's first attempt and the `decision` failure in #1804's. Investigate a repeat before rerunning it.
@@ -0,0 +1,445 @@
1
+ # Claude and Codex account-switch probe
2
+
3
+ Refs #1806 AC1. Measured 2026-11-30 using Claude Code 2.1.332 and the
4
+ fnm-managed npm installation of Codex CLI 0.172.0. The Codex binary's
5
+ installation bin directory was placed first in the cleared probe environment,
6
+ and `codex --version` confirmed 0.172.0. The Homebrew installation was excluded.
7
+ All CLI probes used fresh temporary `HOME`, `CODEX_HOME`, `CLAUDE_CONFIG_DIR`
8
+ and `AGENTHUB_HOME` with a scratch working directory. No real provider
9
+ account or credential was used. No existing session, app-server or hub was used.
10
+
11
+ ## Model-free results
12
+
13
+ | AC1 | Evidence collected | Native result |
14
+ | --- | --- | --- |
15
+ | (a) Claude in-session login change | `claude --version`, `claude --help` and `claude auth --help` ran successfully. The hub's `statusline-tee.ts` consumes Claude's `rate_limits` from stdin and records a measurement when the `rate_limits` object is present. A new timestamp describes the render, and the quota fields carry no proof of an account switch. | Unverified. Which quota windows render before the first response after switching, and whether the channel stays attached, need the live observation below. |
16
+ | (b) Codex login change in one home | `codex app-server generate-ts --out "$scratch/protocol"` generated the installed wire types. `ServerNotification.ts` declares `account/updated` and `account/rateLimits/updated`. `AccountUpdatedNotification` carries nullable `authMode` and `planType`. `ClientRequest.ts` declares `account/rateLimits/read`. The hub's adapter sends that read on its current connection. | Unverified. A supported notification does not establish that a running process reloads login changes made by a separate CLI or emits the notification. |
17
+ | (c) Codex thread resume from another home | `codex resume --help` accepts a session ID. The generated `ThreadResumeParams` describes disk lookup by ID and describes protocol alternatives using an explicit rollout path or history. Those are different requests from an ordinary resume by ID. | Unverified. The schema does not establish visibility of a thread from another home or under another account. |
18
+
19
+ In the 0.172.0 native source, the app-server's own successful ChatGPT login
20
+ reloads its authentication manager and emits `account/updated`. The rate-limit
21
+ read asks that manager for authentication. The source also has a separate
22
+ login notification path that neither identifies a particular account nor
23
+ attests to a switch made by an external CLI. Those paths do not establish
24
+ what happens when a different process changes the scratch home's login. See
25
+ [the tagged account processor](https://github.com/openai/codex/blob/rust-v0.172.0/codex-rs/app-server/src/request_processors/account_processor.rs).
26
+
27
+ The command `bun test test/codex-budget-reset.test.ts` passed both tests under
28
+ the same isolation. Its fake app-server demonstrated a quota read through the
29
+ existing hub proxy and stopping its poll on detach. It simulated a reset. It did
30
+ not simulate or observe a native account switch, an `account/updated` event or
31
+ cross-home thread discovery.
32
+
33
+ Keep the proposed fail-closed behavior until the corresponding live case is
34
+ verified. For Claude, quota stays unknown after a switch until safe session
35
+ evidence exists. For Codex, an `account/updated` event can trigger a quota read
36
+ without attesting to a different account. A different home needs an explicit
37
+ restart and a checkpoint or new-thread path when continuation is unverified.
38
+ No model-free result contradicted these decisions.
39
+
40
+ The first scratch rehearsal in a fresh worktree without its frozen
41
+ dependencies reached `up` and exited 1 with
42
+ `ahub: memory runtime dependency identity/version mismatch`. After
43
+ `bun install --frozen-lockfile` in that worktree, the no-agent rehearsal ran
44
+ `init --yes --no-jcode-home --no-memory`, `up --no-agents --no-console`,
45
+ `status --json` and `kill` successfully. The filter returned the hub version
46
+ and null Claude attachment fields.
47
+
48
+ The documented Claude block was rehearsed in a pseudoterminal using a fake
49
+ `claude`. The fake received the scratch `HOME` and `CLAUDE_CONFIG_DIR`.
50
+ Normal exit, a short rehearsal timeout (exit 124), nonzero exit and a failed
51
+ status sample followed by a successful one all left the shell and the
52
+ observations available. In each case the observer and scratch hub stopped,
53
+ and explicit cleanup removed only the marked scratch folder. A failed fake
54
+ Codex command also left the shell and the Claude observations in place.
55
+ These checks cover the scripts, the hub launcher and environment forwarding.
56
+ Claude's use of the Keychain rests on the official documentation below.
57
+
58
+ ## Person-run observations (not run)
59
+
60
+ Run these only with disposable A and B accounts from a terminal you control.
61
+ Keep login details, device codes, raw provider replies and thread IDs out of
62
+ the receipt. Where quotas differ, record only the selected percentages and
63
+ reset timestamps needed to tell A and B apart. Equal values are inconclusive.
64
+
65
+ ### Credential isolation
66
+
67
+ Anthropic documents that on macOS a custom `CLAUDE_CONFIG_DIR` keys the login
68
+ Keychain entry to that directory. Its file fallback also lives in that
69
+ directory. The Claude probe requires a new directory and the expected version.
70
+ This is documented isolation. No Keychain item was inspected.
71
+ [Claude Code authentication](https://code.claude.com/docs/en/authentication#credential-management)
72
+
73
+ Codex documents `cli_auth_credentials_store = "file"` as storing CLI auth in
74
+ `CODEX_HOME/auth.json`. The tagged 0.172.0 file backend removes only that
75
+ home's auth file. Managed workstation requirements can force a different
76
+ store. Run the live Codex blocks only where there is no such override and no
77
+ managed enterprise or config-server login route. If uncertain, stop and leave
78
+ the result unverified, or use a disposable OS user or VM without existing
79
+ credentials. The blocks pin file mode in the scratch config and supply it on
80
+ each Codex command. They switch by logging into the scratch home, without
81
+ running the separate logout operation.
82
+ [Codex configuration reference](https://developers.openai.com/codex/config-reference)
83
+ [Tagged credential storage](https://github.com/openai/codex/blob/rust-v0.172.0/codex-rs/login/src/auth/storage.rs)
84
+ [Tagged CLI login and logout](https://github.com/openai/codex/blob/rust-v0.172.0/codex-rs/cli/src/login.rs)
85
+
86
+ ### Start the probe shell
87
+
88
+ The blocks use Bash. After the coordinator's single repository `cd`, run
89
+ `bash` and paste the following. Activate the fnm environment before starting
90
+ Bash if needed. Success is the isolated binary paths and exact versions,
91
+ Claude `2.1.332 (Claude Code)` and Codex `codex-cli 0.172.0`. The block stops
92
+ before any probe on an absent prerequisite or a version mismatch. The paths
93
+ printed at the terminal are for the person and stay out of the receipt.
94
+ Each probe runs in its own subshell. A failed block keeps the interactive
95
+ shell and scratch results available. Run each block separately, reviewing its
96
+ exit report before starting another. The checkout must have its frozen Bun
97
+ dependencies installed.
98
+
99
+ ```bash
100
+ set +e
101
+ repo="$(pwd -P)"
102
+ probe_parent="$(cd "${TMPDIR:-/tmp}" && pwd -P)"
103
+ probe=
104
+ if [ -n "$probe_parent" ]; then
105
+ probe="$(mktemp -d "$probe_parent/ahub-1806.XXXXXX")"
106
+ fi
107
+ clean() {
108
+ local codex_home="$1"
109
+ shift
110
+ env -i PATH="$PATH" TERM="${TERM:-xterm}" HOME="$probe/home" \
111
+ CODEX_HOME="$codex_home" CLAUDE_CONFIG_DIR="$probe/claude" \
112
+ AGENTHUB_HOME="$probe/hub" "$@"
113
+ }
114
+ probe_ready() {
115
+ test -n "$probe" && test -f "$probe/.ahub-1806-ready" ||
116
+ { printf 'Scratch setup or version check did not pass. Stop.\n' >&2; return 1; }
117
+ }
118
+ (
119
+ set -euo pipefail
120
+ test -n "$probe"
121
+ touch "$probe/.ahub-1806-owned"
122
+ test -f "$repo/src/cli/main.js" && test -f "$repo/plugins/agent-hub/server.js" || exit 1
123
+ for bin in bun git jq python3 timeout; do
124
+ command -v "$bin" >/dev/null || { printf 'Missing %s; stop.\n' "$bin"; exit 1; }
125
+ done
126
+ mkdir -p "$probe"/{project,home,claude,hub,codex-a,codex-b}
127
+ timeout -k 5s 20s git -C "$probe/project" init -q
128
+ for scratch_codex in "$probe/codex-a" "$probe/codex-b"; do
129
+ printf 'cli_auth_credentials_store = "file"\n' > "$scratch_codex/config.toml"
130
+ done
131
+ cd "$probe/project"
132
+ clean "$probe/codex-a" timeout -k 5s 20s bash -c '
133
+ set -eu
134
+ command -v codex
135
+ command -v claude
136
+ codex_version="$(codex --version)"
137
+ claude_version="$(claude --version)"
138
+ printf "%s\n%s\n" "$codex_version" "$claude_version"
139
+ test "$codex_version" = "codex-cli 0.172.0"
140
+ test "$claude_version" = "2.1.332 (Claude Code)"
141
+ '
142
+ touch "$probe/.ahub-1806-ready"
143
+ )
144
+ printf 'Scratch setup exit %s. Run a probe only after exit 0.\n' "$?"
145
+ ```
146
+
147
+ ### Claude statusline and channel
148
+
149
+ Success is a distinguishable pre-response quota observation and a recorded
150
+ channel state at each stage. Stop if startup, login, or channel attachment
151
+ fails, or if the two accounts cannot be distinguished. The bounded observer
152
+ captures selected fields only. The trap stops it and the newly started scratch
153
+ hub even if the launcher fails. The scratch project and empty hub registry from
154
+ the setup block are required.
155
+
156
+ ```bash
157
+ (
158
+ set -euo pipefail
159
+ probe_ready
160
+ cd "$probe/project"
161
+ test ! -e "$probe/.ahub-1806-hub-running"
162
+ observer=
163
+ finish() {
164
+ local result=$?
165
+ trap - EXIT
166
+ if [ -n "$observer" ]; then
167
+ kill "$observer" 2>/dev/null || true
168
+ wait "$observer" 2>/dev/null || true
169
+ fi
170
+ if [ -f "$probe/.ahub-1806-hub-running" ]; then
171
+ clean "$probe/codex-a" timeout -k 5s 30s bun "$repo/src/cli/main.js" kill ||
172
+ { printf 'Scratch hub stop failed. Keep the marker and check this scratch project with status.\n' >&2; exit 1; }
173
+ unlink "$probe/.ahub-1806-hub-running"
174
+ fi
175
+ exit "$result"
176
+ }
177
+ trap finish EXIT
178
+ trap 'exit 130' INT
179
+ trap 'exit 143' TERM
180
+ clean "$probe/codex-a" timeout -k 5s 30s bun "$repo/src/cli/main.js" init --yes --no-jcode-home --no-memory
181
+ touch "$probe/.ahub-1806-hub-running"
182
+ clean "$probe/codex-a" timeout -k 5s 30s bun "$repo/src/cli/main.js" up --no-agents --no-console
183
+ jq -n --arg bundle "$repo/plugins/agent-hub/server.js" \
184
+ '{mcpServers:{"agent-hub":{command:"bun",args:[$bundle]}}}' > "$probe/claude-mcp.json"
185
+
186
+ duration=900
187
+ deadline=$((SECONDS + duration))
188
+ (
189
+ trap 'exit 0' TERM
190
+ sample_error() {
191
+ jq -cn --argjson at "$sampled_at" --arg reason "$1" \
192
+ '{kind:"sample_error",sampledAt:$at,reason:$reason}'
193
+ }
194
+ while (( SECONDS < deadline )); do
195
+ sampled_at="$(date +%s)"
196
+ if raw="$(clean "$probe/codex-a" timeout -k 1s 5s bun "$repo/src/cli/main.js" status --json 2>/dev/null)"; then
197
+ if filtered="$(printf '%s\n' "$raw" | jq -ces --argjson at "$sampled_at" '
198
+ if length == 1 and (.[0].peers|type) == "object" and (.[0].hubCheck.version|type) == "string"
199
+ then .[0] | {kind:"status",sampledAt:$at,claude:(.peers.claude | {state,attachMode,attachEvidence}),hubCheck:(.hubCheck|{version})}
200
+ else error("unexpected status shape") end' 2>/dev/null)"; then
201
+ printf '%s\n' "$filtered"
202
+ else
203
+ sample_error 'unexpected status shape'
204
+ fi
205
+ else
206
+ sample_error 'status call failed or timed out'
207
+ fi
208
+ if [ -f "$probe/project/.agenthub/state/claude-usage.json" ]; then
209
+ jq -c --argjson at "$sampled_at" '{kind:"quota",sampledAt:$at,measuredAt:.at,
210
+ five_hour:(.rate_limits.five_hour | {used_percentage,resets_at}),
211
+ seven_day:(.rate_limits.seven_day | {used_percentage,resets_at})}' \
212
+ "$probe/project/.agenthub/state/claude-usage.json" 2>/dev/null ||
213
+ sample_error 'quota sample unreadable'
214
+ fi
215
+ sleep 2
216
+ done
217
+ ) > "$probe/claude-observations.jsonl" &
218
+ observer=$!
219
+ set -m
220
+ result=0
221
+ clean "$probe/codex-a" timeout -k 5s "${duration}s" bun "$repo/src/cli/main.js" claude --mcp-config "$probe/claude-mcp.json" || result=$?
222
+ case "$result" in
223
+ 0) printf 'Claude exited normally. Keeping observations.\n' ;;
224
+ 124) printf 'Claude hit the 15-minute limit. Keeping observations.\n' ;;
225
+ *) printf 'Claude exited with status %s. Keeping observations.\n' "$result" ;;
226
+ esac
227
+ exit "$result"
228
+ )
229
+ printf 'Claude probe exit %s. Inspect the observations before another block.\n' "$?"
230
+ ```
231
+
232
+ In the scratch TUI, authenticate A and send one neutral prompt. Confirm channel
233
+ attachment. Run `/login` in the same TUI and select B. Wait for a statusline
234
+ render before sending another prompt. Compare samples before login, after login
235
+ but before a response, and after the first response. To prove uninterrupted
236
+ attachment rather than sampling an attached peer after a reconnect, check only
237
+ scratch attach/detach evidence for that interval. No live login or channel
238
+ continuity check was run for this receipt. A failed or missing sample is a gap
239
+ in evidence and does not establish uninterrupted attachment. The 15-minute
240
+ observer keeps sampling after a recorded status failure or unexpected shape.
241
+
242
+ ### Codex login change with the same app-server
243
+
244
+ Success is a distinct post-switch quota from the same app-server, with the
245
+ presence or absence of `account/updated` recorded separately. Stop on an
246
+ initialization, login or quota read failure. The script labels each
247
+ notification by when it was received relative to the switch starting.
248
+ A notification alone is not proof that the quota reflects B.
249
+
250
+ ```bash
251
+ (
252
+ set -euo pipefail
253
+ probe_ready
254
+ cat > "$probe/switch.py" <<'PYCODE'
255
+ import json
256
+ import queue
257
+ import select
258
+ import signal
259
+ import subprocess
260
+ import sys
261
+ import threading
262
+ import time
263
+
264
+ codex = ["codex", "-c", 'cli_auth_credentials_store="file"']
265
+ frames = queue.Queue()
266
+ switch_started = threading.Event()
267
+
268
+ def stop(signum, _frame):
269
+ raise SystemExit(128 + signum)
270
+
271
+ signal.signal(signal.SIGTERM, stop)
272
+ signal.signal(signal.SIGINT, stop)
273
+ app = subprocess.Popen(
274
+ codex + ["app-server", "--listen", "stdio://"],
275
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
276
+ text=True, bufsize=1,
277
+ )
278
+
279
+ def read_frames():
280
+ try:
281
+ for line in app.stdout:
282
+ try:
283
+ frame = json.loads(line)
284
+ except ValueError:
285
+ continue
286
+ if isinstance(frame, dict):
287
+ frames.put((switch_started.is_set(), frame))
288
+ finally:
289
+ frames.put((False, None))
290
+
291
+ def take_frame(timeout):
292
+ try:
293
+ after, frame = frames.get(timeout=timeout)
294
+ except queue.Empty:
295
+ return None
296
+ if frame is None:
297
+ raise SystemExit("app-server closed its output")
298
+ if frame.get("method") == "account/updated":
299
+ phase = "after switch began" if after else "before switch"
300
+ print(f"observed account/updated: {phase}", flush=True)
301
+ return frame
302
+
303
+ def send(message):
304
+ app.stdin.write(json.dumps(message) + "\n")
305
+ app.stdin.flush()
306
+
307
+ def wait_for_reply(request_id):
308
+ deadline = time.monotonic() + 30
309
+ while (remaining := deadline - time.monotonic()) > 0:
310
+ frame = take_frame(remaining)
311
+ if frame is None:
312
+ break
313
+ if frame.get("id") == request_id:
314
+ if "error" in frame:
315
+ raise SystemExit("app-server request failed")
316
+ return frame.get("result") or {}
317
+ raise SystemExit("app-server request timed out")
318
+
319
+ def limits(request_id):
320
+ send({"id": request_id, "method": "account/rateLimits/read"})
321
+ data = wait_for_reply(request_id).get("rateLimits") or {}
322
+ print({key: {field: (data.get(key) or {}).get(field)
323
+ for field in ("usedPercent", "resetsAt")}
324
+ for key in ("primary", "secondary")}, flush=True)
325
+
326
+ threading.Thread(target=read_frames, daemon=True).start()
327
+ try:
328
+ send({"id": 1, "method": "initialize",
329
+ "params": {"clientInfo": {"name": "quota-probe", "version": "0.1.0"}}})
330
+ wait_for_reply(1)
331
+ send({"method": "initialized"})
332
+ limits(2)
333
+ print("Press Enter to switch only the scratch account to B: ", end="", flush=True)
334
+ if not select.select([sys.stdin], [], [], 120)[0] or not sys.stdin.readline():
335
+ raise SystemExit("no confirmation from the terminal")
336
+ switch_started.set()
337
+ subprocess.run(codex + ["login", "--device-auth"], check=True, timeout=180)
338
+ limits(3)
339
+ deadline = time.monotonic() + 5
340
+ while (remaining := deadline - time.monotonic()) > 0:
341
+ if take_frame(remaining) is None:
342
+ break
343
+ finally:
344
+ if app.poll() is None:
345
+ app.terminate()
346
+ try:
347
+ app.wait(timeout=10)
348
+ except subprocess.TimeoutExpired:
349
+ app.kill()
350
+ app.wait(timeout=5)
351
+ PYCODE
352
+ (cd "$probe/project" && clean "$probe/codex-a" timeout --foreground -k 5s 190s codex -c 'cli_auth_credentials_store="file"' login --device-auth)
353
+ (cd "$probe/project" && clean "$probe/codex-a" timeout --foreground -k 15s 405s python3 "$probe/switch.py")
354
+ )
355
+ printf 'Codex switch probe exit %s. Stop this case on a nonzero exit.\n' "$?"
356
+ ```
357
+
358
+ Choose A on the first device login and B when the script prompts. After the
359
+ switch, a quota matching A suggests the running process kept A for that read.
360
+ A missing notification establishes only that none arrived during the sample.
361
+ A failed read leaves the switch result unknown. The complete script was
362
+ rehearsed through a pseudoterminal with a fake Codex. Passing cases covered
363
+ a pre-switch notification plus two after the switch started, no post-switch
364
+ notification, a failed RPC and a timed-out RPC. Each case reaped its fake
365
+ app-server. The rehearsal checks the harness only.
366
+
367
+ ### Codex resume by thread ID in a different home
368
+
369
+ Success requires the second TUI to continue the same thread under scratch
370
+ home B. If creating the thread or capturing exactly one ID fails, stop before
371
+ opening the second TUI. If resume is refused or opens a fresh thread, record
372
+ that result without exporting credentials, raw output or the fixture ID.
373
+
374
+ ```bash
375
+ (
376
+ set -euo pipefail
377
+ probe_ready
378
+ (cd "$probe/project" && clean "$probe/codex-a" timeout --foreground -k 5s 190s codex -c 'cli_auth_credentials_store="file"' login --device-auth)
379
+ (cd "$probe/project" && clean "$probe/codex-b" timeout --foreground -k 5s 190s codex -c 'cli_auth_credentials_store="file"' login --device-auth)
380
+ (
381
+ set -o pipefail
382
+ cd "$probe/project" || exit 1
383
+ clean "$probe/codex-a" timeout -k 5s 90s codex -c 'cli_auth_credentials_store="file"' exec --json 'Reply with the single word fixture.' |
384
+ jq -r 'select(.type == "thread.started") | .thread_id // empty' > "$probe/thread-id"
385
+ )
386
+ test "$(wc -l < "$probe/thread-id" | tr -d ' ')" = 1
387
+ thread="$(cat "$probe/thread-id")"
388
+ test -n "$thread"
389
+ (cd "$probe/project" && clean "$probe/codex-b" timeout --foreground -k 5s 90s codex -c 'cli_auth_credentials_store="file"' resume "$thread")
390
+ )
391
+ printf 'Codex resume probe exit %s. Stop this case on a nonzero exit.\n' "$?"
392
+ ```
393
+
394
+ ### Read the observations and remove the scratch directory
395
+
396
+ Run the summary before cleanup. It prints the last sampled time, the failure
397
+ count and the selected records only.
398
+
399
+ ```bash
400
+ (
401
+ set -euo pipefail
402
+ test -n "$probe"
403
+ jq -s '{lastSampleAt:(map(.sampledAt)|max), failureCount:(map(select(.kind=="sample_error"))|length),
404
+ observations:map({kind,sampledAt,reason,claude,hubCheck,measuredAt,five_hour,seven_day})}' \
405
+ "$probe/claude-observations.jsonl"
406
+ )
407
+ printf 'Observation summary exit %s.\n' "$?"
408
+ ```
409
+
410
+ Closing the shell leaves the folder and observations. To recover it in a new
411
+ Bash shell, list the marked scratch directories and paste one printed directory
412
+ at the prompt. Use the same temporary parent as the setup.
413
+
414
+ ```bash
415
+ probe_parent="$(cd "${TMPDIR:-/tmp}" && pwd -P)"
416
+ (find "$probe_parent" -mindepth 2 -maxdepth 2 -type f -name .ahub-1806-owned -exec dirname {} \;)
417
+ IFS= read -r -p 'Paste the scratch directory from the list: ' probe
418
+ ```
419
+
420
+ Use the final command after all probe processes have stopped and after reading
421
+ the summary. Success is an absent scratch directory. If the hub marker remains,
422
+ keep the directory and inspect the scratch hub's status, process ownership and
423
+ logs before retrying its stop. Never remove the marker to bypass that check.
424
+ Cleanup removes the marked scratch directory and its local Codex files. It
425
+ leaves the checkout, existing agent homes, macOS Keychain entries and remote
426
+ sign-ins alone.
427
+
428
+ ```bash
429
+ (
430
+ set -euo pipefail
431
+ python3 -c 'import os, pathlib, shutil, sys
432
+ p = pathlib.Path(sys.argv[1])
433
+ parent = pathlib.Path(sys.argv[2])
434
+ marker = p / ".ahub-1806-owned"
435
+ if (p.is_symlink() or p.parent != parent or not p.name.startswith("ahub-1806.")
436
+ or not p.is_dir() or p.stat().st_uid != os.getuid() or marker.is_symlink() or not marker.is_file()):
437
+ raise SystemExit("refuse to remove an unmarked scratch directory")
438
+ hub_marker = p / ".ahub-1806-hub-running"
439
+ if hub_marker.exists() or hub_marker.is_symlink():
440
+ raise SystemExit("scratch hub stop is unconfirmed; keep the directory")
441
+ shutil.rmtree(p)' "$probe" "$probe_parent"
442
+ test ! -e "$probe"
443
+ )
444
+ printf 'Scratch cleanup exit %s.\n' "$?"
445
+ ```