@staix/agent-hub 0.50.0 → 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.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +2 -2
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +3 -3
- package/docs/agent-notes/daemon.md +1 -1
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/tasks.md +5 -1
- package/docs/design/adapters.md +17 -0
- package/docs/design/cli-output-inventory.md +22 -17
- package/docs/design/roadmap.md +1 -1
- package/docs/design/task-board.md +34 -0
- package/docs/dogfood.md +7 -3
- package/docs/operations.md +49 -3
- package/docs/quickstart.md +18 -1
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/sdlc.md +3 -2
- package/docs/specs/2026-09-19-agent-hub-design.md +1 -0
- package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
- package/docs/verified.json +31 -27
- package/package.json +1 -1
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +1329 -24654
- package/plugins/agent-hub/server.js +612 -413
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +2 -2
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/claude-channel-evidence.ts +7 -3
- package/src/adapters/compat.ts +4 -3
- package/src/adapters/definitions/builtin-metadata.ts +2 -2
- package/src/adapters/definitions/native-cli-claude-launch.ts +3 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +3 -1
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/jcode.ts +16 -0
- package/src/adapters/native-facts-hooks.ts +12 -0
- package/src/cli/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/claude-profile-hook.ts +31 -11
- package/src/cli/commands/releases.ts +82 -0
- package/src/cli/conductor-recovery.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +8 -6
- package/src/cli/identity.ts +5 -1
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +157 -0
- package/src/cli/launch.ts +19 -1
- package/src/cli/main.ts +44 -3
- package/src/cli/memory.ts +1 -1
- package/src/cli/output.ts +14 -1
- package/src/cli/preview.ts +1 -1
- package/src/cli/recovery-launch.ts +1 -1
- package/src/cli/setup-homes.ts +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- package/src/cli/upgrade-runtime.ts +1 -1
- package/src/cli/warn-line.ts +1 -1
- package/src/hub/ci-watch.ts +311 -79
- package/src/hub/config-apply.ts +1 -1
- package/src/hub/config.ts +518 -0
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +76 -513
- package/src/hub/delivery-public.ts +11 -0
- package/src/hub/hub-check.ts +125 -0
- package/src/hub/path-policy.ts +1 -1
- package/src/hub/permission-mode.ts +3 -40
- package/src/hub/permission-paths.ts +41 -0
- package/src/hub/recovery-policy.ts +1 -1
- package/src/hub/releases-inventory.ts +198 -0
- package/src/hub/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc.ts +7 -3
- package/src/hub/tasks.ts +138 -36
- package/src/ui/plugin.ts +1 -1
|
@@ -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
|
+
```
|