Repository navigation
v6.9.0 — same-project jobs are picked up automatically
English
New install:
claude mcp add ai-cli -s user -- npx -y @tkflyc/ai-cli-mcpExisting installs: restart Claude Code (or reconnect with /mcp) to load 6.9.0.
Same-project jobs are picked up automatically
A job is dispatched by one session. When that session ends, the detached runner keeps going, but a new session could not see the job because jobs are isolated by principal (the session that dispatched them). Rewriting the job's meta identity by hand was tried as a workaround. Claude Code's auto-mode classifier blocked it as forging a process identity.
From 6.9.0 the server adopts these orphaned jobs on its own. You don't need to give a prompt or run a command.
- Same project only. The server records
projectDirfrom its cwd at construction and adopts only jobs from the same project, so an active session in another project cannot take someone else's orphaned job. New jobs must matchprojectDirexactly; for older jobs, the match is the directory boundary ofworkFolder. If the project directory is a filesystem root or the home directory, older jobs are matched only on an identical path, with no prefix match. - Verified on one client only. "The MCP cwd equals the session working directory" was measured on Claude Code 2.1.296. Other clients have not been verified.
- Adoption window. The whole time the job is running, plus 30 minutes after it finishes (also subject to the shared capacity limits). Adoption does not re-run the job and does not extend its retention.
- When it runs. In the background right after startup (usually within a few seconds, without delaying ready), then every 60 seconds on the GC cycle. The original principal lookup is folded into the GC batch.
- Safety checks. The server first confirms the original principal is dead. It then takes a lock synchronously, re-reads the job, compares principal and server, updates both atomically, and appends the full adoption history. If a lock already exists, adoption is refused with a manual-cleanup hint. This avoids a race where two sides each reclaim the old lock, delete the other's new lock, and both "succeed".
- Workers do not adopt. An ai-cli MCP running under a worker (the
AI_CLI_WORKERmarker, or a runner/worker of a job on its ancestor chain) adopts nothing, automatically or manually. - Jobs with no principal. If the principal is null, the server looks at the server that dispatched the job. If both are null, only manual adoption works.
- Turn it off. Set
AI_CLI_AUTO_ADOPTtooff,0,falseorno. Put it in theenvof the MCP server's configuration, for exampleclaude mcp add ai-cli -s user -e AI_CLI_AUTO_ADOPT=off -- npx -y @tkflyc/ai-cli-mcp. A shell export may not reach the server (Codex forwards only allow-listed variables to MCP servers). - What you see. After adoption, list and result carry
adopted: true. List also carries the model, and verbose result carriesadoptedFrom. - Manual fallback for cross-project cases. The MCP
adopttool stays available. The read-onlyai-cli adoptcommand only lists candidates. It does not choose the receiving session.
ai-cli-jobs panel 0.1.2
Version 0.1.0 → 0.1.2. (The version was bumped because claude plugin update reports "already at the latest version" when the number is unchanged.)
Existing installs:
- Run
claude plugin update ai-cli-jobs@tkflyc-ai-cli. - In
autopermission mode, addmcp__ai-cli__list_processestopermissions.allow. - Restart Claude Code.
- Adopted jobs are shown. Jobs the server adopted (
adopted: true) appear marked "adopted from the previous session", with the model. The panel checks once 5 seconds after the session starts, then every 60 seconds while idle. During normal polling it also picks them up when jobs are running. EachjobIdis shown once.seenis not cleared onsession.end, because/clearsends only an end event and no new start. Rows without ajobIdare not shown as adopted. - Refused polls now say what to do. A refused poll shows the full sentence instead of a 28-character truncation. For a permission refusal, it says to add
mcp__ai-cli__list_processestopermissions.allowand keeps the reason (adding an allow rule does not help against a deny rule or a hook refusal). For "no connected MCP tool", it says to reconnect with/mcp. Both message formats were checked against the Claude Code 2.1.296 binary strings. - Polling failures are no longer swallowed. Timeouts,
isError, unparseable output and exceptions show "polling failed: " on the row, and the status stays running. Before, a barecatch {}hid every error and the panel just kept spinning. - Other panel changes.
list_processescalls have a 10-second timeout. Testing showed this was not the cause of the spinning, and it is kept as a safeguard. The polling interval goes from 3 seconds to 0.5 seconds. Grok jobs were labelleddirect-apibecauseinferAgenthad nogrok-*rule; it now maps togrok. - Docs: the cause of the endless spinner. In
autopermission mode, addmcp__ai-cli__list_processestopermissions.allow(README, both languages). The plugin's background$.mcp.callgoes through permission checks too, and auto mode has no classifier available in the background. The debug log readsAuto mode classifier unavailable, denying with retry guidance (fail closed). Measured on 2026-10-10: all 199 polls were refused before the rule, and the first poll after the settings reloaded succeeded and the panel turned to done. - A read-only review by sonnet raised 11 points. 9 were valid and fixed (including when
seenis registered,/clear, an updater side effect, asession.endrace, a timer left behind). 2 were not changed: showing a finished adopted job for 120 seconds is intentional, and whether a long hint wraps needs checking on a real terminal.
Codex read-only mode on Windows
In strict (read-only) mode, codex could not read files on Windows. Strict passes --ignore-user-config, so [windows] sandbox is not loaded either. codex then falls back to a safe-command list, and | Select-Object or cmd /c are rejected before running (blocked by policy). If the model picked one, it could not read the file and still exited 0 with a "could not complete" report. A read-only review on 2026-10-10 failed this way.
- Checked on 2026-10-12 with codex-cli 0.162.1, one pattern at a time, plus a comparison: asked to read lines 50–60, the run without a hint gave up after a pipeline was refused. With the hint it used
rgand succeeded on the first try. - Passing
-c windows.sandbox=...does not work: unelevated, every command exits -1; elevated, it returnshelper_unknown_error. - Fix: on Windows, strict adds a file-reading hint at the start of stdin (
CODEX_WINDOWS_READ_ONLY_HINT). Thepromptfield is unchanged. One assertion and one mutation were added.
Grok dispatch guidance
The Grok row in dispatchGuidance now describes measured positioning: use grok-4.7 at medium effort for a second-vendor view in reviews, knowledge extraction and documentation checks.
- Basis: six tasks × two rounds on 2026-10-10, and a second round on 2026-10-12 (a cross-9-file feature in a real repo, and web verification). On objective scoring, grok-4.7 tied with gpt-6.1-sol and sonnet in every case. Only speed and cost differed, so it is not a replacement for everyday coding.
- Caveat: Grok reads your global CLAUDE.md and MCP configuration, and once sent a knowledge-base entry to xAI. If you don't want data to leave, say in the prompt not to use the knowledge base or MCP.
- Audit / second opinion row:
grok-4.7was added (zero false positives on two rounds of review tasks, 3–5 minutes each).
Tests and mutations
verify-durable-jobsoccasionally failed withUnexpected end of JSON input. The test observer wroteheap.jsonandio-<pid>.jsonwith plain writes, and the reader parsed the file as soon as it existed, sometimes mid-write. It now waits for the next round if the JSON is incomplete. A fullnpm teston 2026-10-12 reported a false failure in the 50 × 1 MiB stress test because of this; a rerun passed. Only the test side changed.- The mutation "recommendation table recommends a known-bad model (kimi-k3)" had been surviving since 3c0ae2f moved kimi-k3 out of
KNOWN_BAD_MODELS(slow but usable), so it tested nothing. It showed up on 2026-10-12 when all 43 mutations of verify-alias-config were run. It now usesnv-meta/llama-3.2-11b-vision-instruct, which is still on the list; applying it by hand confirmed the intended assertion catches it. This is the same kind of problem as red line 7: nobody normally runs a whole script's mutations. - The existing mutation "everyday dispatch effort back to high" matched two places after the Grok row was rewritten, so it is now bound to the
model: 'gpt-6.1-sol'row.
Audit
The automatic adoption was implemented by Codex gpt-6.1-sol (high). Two other models, opus (high) and sonnet (high), audited it independently in read-only mode. Fixes were made by a separate opus (high) in an independent clone, and sonnet's re-review judged it mergeable. Its 6 suggestions went in with the same batch.
- Codex's own first pass rejected the original design: automatically reclaiming a leftover lock had a double-adoption race (a repro script succeeded 2 times out of 2 attempts, and the history was overwritten). An existing lock is now always refused.
- High, valid, fixed (found independently by both audits): an ai-cli MCP under a worker adopted automatically and took same-project orphans before the user's new session could.
- Medium, valid, fixed: a null principal was always treated as dead; the prefix rule for root or home-directory jobs adopted across projects; two "concurrent adoption" tests ran in one process with a synchronous critical section, so they passed even with
wxremoved and did not test the lock. - Low, valid, fixed: an unreadable cwd or homedir could break the MCP or the check; the switch accepted only lowercase
off; a failed lock delete overwrote a successful result; the liveness query read command lines;wait/peekbypassed throttling when GC was due; auto-adoption read a shared cache racily; the candidate list re-read whole logs; inconsistent fields; a misleading lock message. - Found afterwards by running it: with auto-adoption on, verify-liveness failed intermittently (off: 6/6 passed; on: 2 of 4 failed). Moving adoption after ready and capping the ancestor walk at 4 levels did not fix it. Instrumentation showed ready sometimes took 7.6–8.3 s instead of about 1.9 s: the GC timer could fire during startup and open a collection pass that included adoption, and startup joined that same single-flight promise. Collection no longer includes adoption, and the timer stays idle until startup finishes; afterwards 5/5 runs passed with ready at 1.9–3.2 s. A third read-only review by sonnet confirmed the root cause.
- Rejected: the claim that a child process in
verify-adopt.mjs:288-291reads the real store. The importedcatalog-test-env.mjsalready setsAI_CLI_STATE_DIRand the child inherits it. - Not changed: after a
/mcpreconnectalreadyOwneddoes not update the server. That is the existing 6.8.0 restart-recovery behaviour, andlostis decided by the global GC.
Full details: CHANGELOG.
繁體中文
新安裝:
claude mcp add ai-cli -s user -- npx -y @tkflyc/ai-cli-mcp已安裝的使用者:重啟 Claude Code(或 /mcp 重連)即可載入 6.9.0。
同專案的 job 自動接管
job 由某個 session 派出。該 session 結束後,detached runner 仍繼續執行,但新 session 因 principal(派工者)隔離看不到這些 job。曾試過直接改寫 job 的 meta 身分,被 Claude Code 自動模式分類器當成偽造行程身分擋下。
6.9.0 起,server 會自己接管這些孤兒 job,不必再下 prompt 或指令。
- 只限同專案。 server 以建構時的 cwd 記錄
projectDir,只自動接同專案的 job,避免其他專案的活躍 session 搶走別人的孤兒 job。新 job 須與projectDir完全相同;舊 job 以workFolder的目錄邊界判定。專案目錄是根目錄或家目錄時,舊 job 只接路徑完全相同的,不套前綴。 - 只在一個 client 上驗證過。「MCP 的 cwd 等於 session 工作目錄」只在 Claude Code 2.1.296 實測,其他 client 未驗證。
- 可接管時間。 執行期間全程,加上結束後 30 分鐘(另受共用容量上限限制)。接管不重跑,也不延長保留期。
- 執行時機。 啟動後在背景立刻進行(通常幾秒內,不拖慢 ready),之後每 60 秒一次,跟著 GC 週期。原 principal 的查詢併入 GC 批次。
- 安全檢查。 先確認原 principal 已死,再同步鎖定、重讀 job,比對 principal 與 server,原子更新兩者,並追加完整接管歷史。若已有 lock 一律拒絕,並給手動清理提示,避免兩方各自回收舊鎖、刪掉對方新鎖、同時接管成功的競態。
- worker 底下不接管。 在 worker 底下的 ai-cli MCP(有
AI_CLI_WORKER標記,或祖先鏈上有 job 的 runner/worker)不論自動或手動都不接管。 - 沒有 principal 的 job。 principal 為 null 時改看派工的 server;兩者皆 null 就只能手動接管。
- 停用。 把
AI_CLI_AUTO_ADOPT設為off、0、false或no,要寫在 MCP server 設定的env裡,例如claude mcp add ai-cli -s user -e AI_CLI_AUTO_ADOPT=off -- npx -y @tkflyc/ai-cli-mcp。在 shell 裡 export 不一定傳得到 server(Codex 只把白名單內的變數轉給 MCP server)。 - 看得到什麼。 接管後 list/result 帶
adopted: true,list 另帶 model,verbose result 帶adoptedFrom。 - 跨專案備援。 MCP
adopt工具保留。唯讀的ai-cli adopt只列出候選清單,不決定接收的 session。
ai-cli-jobs 面板 0.1.2
版本 0.1.0 → 0.1.2。(版本號有調整,是因為號碼不變時 claude plugin update 會回「already at the latest version」。)
已安裝的使用者:
- 執行
claude plugin update ai-cli-jobs@tkflyc-ai-cli。 auto權限模式下,把mcp__ai-cli__list_processes加進permissions.allow。- 重啟 Claude Code。
- 顯示接管來的 job。 server 接管的 job(
adopted: true)會標「接管自前一個 session」並帶 model。面板在 session 開始 5 秒後探查一次,之後閒置時每 60 秒一次;有 job 執行中時,一般輪詢也會帶到。同一個jobId只顯示一次。seen不在session.end清掉,因為/clear只送 end、不再送 start。沒有jobId的列不顯示為接管。 - 被拒的提示可以照做。 輪詢被拒時整句顯示,不再截成 28 字。權限被拒會提示「把
mcp__ai-cli__list_processes加進permissions.allow」並附原因(遇到 deny 規則或 hook 拒絕時加 allow 沒用,所以原因要留著);沒連上(no connected MCP tool)則提示用/mcp重連。兩種格式都從 Claude Code 2.1.296 執行檔字串核對。 - 輪詢失敗不再靜默吞掉。 逾時、
isError、格式無法解析、例外都會在該列顯示「輪詢失敗:<原因>」,狀態維持執行中。以前catch {}把錯誤全吞掉,面板只會一直轉圈。 - 其他面板變更。
list_processes呼叫加 10 秒逾時,實測這不是轉圈的原因,留著當保險。輪詢間隔由 3 秒改為 0.5 秒。Grok job 原本被標成direct-api,因為inferAgent沒有grok-*規則,現在對應到grok。 - 文件:一直轉圈的根因。
auto權限模式下要把mcp__ai-cli__list_processes加進permissions.allow(README 中英都已補)。plugin 的背景$.mcp.call一樣要走權限檢查,而 auto 模式在背景沒有分類器可用,debug log 記為Auto mode classifier unavailable, denying with retry guidance (fail closed)。2026-10-10 實測:加規則前 199 次輪詢全數被拒,設定重新載入後的下一次輪詢就成功、面板轉為完成。 - sonnet 唯讀審查提出 11 條,成立並已修 9 條(含
seen登錄時機、/clear、updater 副作用、session.end競態、計時器殘留)。不修 2 條:已完成的接管 job 顯示 120 秒是刻意的;提示太長會不會換行需實機確認。
codex 唯讀模式在 Windows 的修正
codex 的唯讀(strict)模式在 Windows 讀不到檔。strict 帶 --ignore-user-config,連 [windows] sandbox 也不載,codex 改用安全指令清單把關,| Select-Object、cmd /c 會在執行前被拒(blocked by policy)。模型挑到這類寫法就讀不到檔,還會 exit 0 交一份「無法完成」。2026-10-10 一次唯讀審查就這樣落空。
- 2026-10-12 實測(codex-cli 0.162.1):逐一確認哪些寫法被拒,並做對照。要求讀第 50–60 行,沒有提示的那次用管線被拒後放棄;加上提示後改用
rg,一次成功。 - 改帶
-c windows.sandbox=...不可行: unelevated 每個指令 exit -1,elevated 回helper_unknown_error。 - 修法: Windows 上 strict 在 stdin 開頭補讀檔提示(
CODEX_WINDOWS_READ_ONLY_HINT),prompt欄位不動。新增 1 筆斷言與 1 筆突變。
Grok 派工建議
dispatchGuidance 的 Grok 那列改寫成實測定位:換一家視角的審查、知識萃取與文件查證,用 grok-4.7 medium。
- 依據: 2026-10-10 六項 × 兩輪,以及 2026-10-12 第二回(真實 repo 跨 9 檔功能、網路查證)。客觀判分上 grok-4.7 與 gpt-6.1-sol、sonnet 全部平手,差別只在速度與成本,所以日常 coding 不換。
- 注意: Grok 會讀你的全域 CLAUDE.md 與 MCP 設定,曾把知識庫條目送進 xAI。不希望外送時,prompt 要寫明不要用知識庫或 MCP。
- 「稽核/第二意見」列: 加入
grok-4.7(兩輪審查題零誤報,每次 3–5 分鐘)。
測試與突變
verify-durable-jobs偶發Unexpected end of JSON input:測試觀測器以一般寫入產生heap.json、io-<pid>.json,讀端一看到檔案存在就JSON.parse,讀到寫一半。改成讀不到完整 JSON 就等下一輪。2026-10-12 一次完整npm test因此在 50 個 1 MiB job 的壓力測試誤報失敗,重跑即過。只動測試端。- 突變「建議表推薦了已知不能用的模型(kimi-k3)」,從 3c0ae2f 把 kimi-k3 移出
KNOWN_BAD_MODELS(慢但可用)起就一直 SURVIVED,什麼都沒測到。2026-10-12 跑 verify-alias-config 全部 43 筆突變時現形。改用仍在清單上的nv-meta/llama-3.2-11b-vision-instruct,手動套用確認由指定斷言抓到。與紅線 7 同型:平常沒人跑整支腳本的突變。 - 既有突變「日常派工 effort 改回 high」在 Grok 那列改寫後命中兩處,改綁
model: 'gpt-6.1-sol'那一列。
稽核
自動接管由 Codex gpt-6.1-sol(high)實作。opus(high)與 sonnet(high)兩路以唯讀模式獨立稽核;修正由另一個 opus(high)在獨立 clone 完成,sonnet 複審判定可合併,複審建議的 6 點同批補上。
- Codex 第一輪先自己擋下原設計:殘留 lock 的自動回收有雙重接管競態(重現腳本 2 次嘗試 2 次成功,歷史被覆寫),改為既有 lock 一律拒絕。
- 高、成立、已修(兩路各自找到):worker 底下的 ai-cli MCP 會自動接管,搶在使用者的新 session 之前把同專案孤兒接走。
- 中、成立、已修:principal 為 null 一律判已死;根目錄/家目錄的舊 job 前綴規則會跨專案誤接;兩條「並行接管」測試在同一行程、臨界區同步,拿掉
wx也會過,沒測到 lock。 - 低、成立、已修:cwd/homedir 取不到會讓 MCP 或 check 失敗;開關只認小寫 off;刪 lock 失敗蓋掉成功結果;存活查詢抓了命令列;GC 到期時 wait/peek 繞過節流;自動接管讀共用快取有競態;候選清單整檔重讀 log;欄位不一致;lock 訊息誤導。
- 實跑追加發現:自動接管開啟時 verify-liveness 偶發失敗(關閉 6/6 過、開啟 4 次敗 2)。把接管移到 ready 之後、祖先鏈限 4 層並沒有修好;插樁量測 ready 有時要 7.6–8.3 秒(正常約 1.9 秒):GC 計時器若在啟動期間觸發,會先開一輪含接管的回收,啟動流程等的是同一個 single-flight promise。改為回收不含接管、啟動完成前計時器不跑,之後 5/5 通過、ready 1.9–3.2 秒。sonnet 第三次唯讀複核確認根因成立。
- 不成立:「
verify-adopt.mjs:288-291的子行程讀正式 store」。測試檔 import 的catalog-test-env.mjs已設AI_CLI_STATE_DIR,子行程會繼承。 - 不修:「
/mcp重連後 alreadyOwned 不更新 server」屬 6.8.0 重啟接回的既有語意,lost 由全域 GC 判定。
完整內容見 CHANGELOG。