@kylecheng3146/agent-ops 0.1.5 → 0.1.6

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 (36) hide show
  1. package/README.md +82 -6
  2. package/dist/packages/cli/src/args.js +1 -1
  3. package/dist/packages/cli/src/bin.js +2 -0
  4. package/dist/packages/cli/src/cli.js +1 -1
  5. package/dist/packages/cli/src/codex-loop-process.js +70 -0
  6. package/dist/packages/cli/src/commands/hook.js +16 -1
  7. package/dist/packages/cli/src/commands/update.js +3 -0
  8. package/dist/packages/cli/src/context.js +60 -0
  9. package/dist/packages/cli/src/hook-process.js +128 -15
  10. package/dist/packages/cli/src/loop-entry.js +8 -0
  11. package/dist/packages/cli/src/version.js +1 -1
  12. package/dist/packages/cli/src/wizard.js +9 -4
  13. package/dist/runtime/src/adapters/claude/config.js +57 -11
  14. package/dist/runtime/src/adapters/claude/events.js +7 -0
  15. package/dist/runtime/src/adapters/claude/output.js +2 -1
  16. package/dist/runtime/src/adapters/codex/config.js +39 -4
  17. package/dist/runtime/src/adapters/codex/events.js +7 -0
  18. package/dist/runtime/src/fs/managed-block.js +35 -18
  19. package/dist/runtime/src/hooks/codex-loop.js +439 -0
  20. package/dist/runtime/src/install/codex-loop.js +139 -0
  21. package/dist/runtime/src/install/doctor.js +66 -8
  22. package/dist/runtime/src/install/harness.js +8 -10
  23. package/dist/runtime/src/install/ownership.js +37 -2
  24. package/dist/runtime/src/install/plan.js +70 -4
  25. package/dist/runtime/src/install/profiles.js +5 -3
  26. package/dist/runtime/src/install/uninstall.js +1 -1
  27. package/dist/runtime/src/install/update.js +5 -1
  28. package/dist/runtime/src/logging/local-log.js +25 -0
  29. package/dist/runtime/src/schema/validate.js +8 -1
  30. package/docs/en/guides/configuration.md +78 -2
  31. package/docs/en/spec/harness-adapters.md +50 -12
  32. package/docs/zh-TW/guides/configuration.md +73 -5
  33. package/docs/zh-TW/spec/harness-adapters.md +44 -12
  34. package/package.json +1 -1
  35. package/schemas/config.schema.json +1 -1
  36. package/schemas/manifest.schema.json +12 -1
@@ -21,11 +21,75 @@ User scope 下,Codex 與 opencode 的 routing file 分別位於 `.codex/` 與
21
21
  `$OPENCODE_CONFIG_DIR`,則 plugin 會放在其 `plugins/` 目錄。只有 profile
22
22
  有暗示時才會註冊 advisory 與 guardrail hook。Installer 會 discovery 可寫入的
23
23
  harness surface 並套用選定的 target policy;若不是 managed default,請使用
24
- `--hook-target <harness>=<surface-id>` 明確選擇。Project-local Claude settings
25
- 必須明確指定 target。Advisory 會經由真正的 SessionStart path 執行並 fail-open;
24
+ `--hook-target <harness>=<surface-id>` 明確選擇。Project-local Claude hook 預設
25
+ 使用 `.claude/settings.json`;只有要使用 `.claude/settings.local.json` 時才需
26
+ 明確選擇。Advisory 會經由真正的 SessionStart path 執行並 fail-open;
26
27
  Claude 與 Codex lifecycle support 為 `supported`,OpenCode 從 app initialization
27
28
  開始,因此誠實標示為 `degraded`。
28
29
 
30
+ ### Project-local loop profile
31
+
32
+ `--profile loop` 是明確 opt-in 的 project-scope profile。請選擇 `codex`、
33
+ `claude` 或兩者(例如 `--harness codex,claude`);它需要 POSIX-compatible
34
+ `bash`,目前尚未支援 Windows launcher。建議先 dry run:
35
+
36
+ ```bash
37
+ agent-ops init --dry-run --scope project --harness codex,claude --profile loop --json
38
+ agent-ops init --scope project --harness codex,claude --profile loop --yes
39
+ ```
40
+
41
+ 對每個選定且支援的 harness,agent-ops 只擁有一個小型 launcher:
42
+ `.codex/hooks/agent-ops-loop.sh` 或 `.claude/hooks/agent-ops-loop.sh`。兩個
43
+ launcher 都委派給同一個已安裝的 Node runtime,因此不會複製 project-specific
44
+ loop script。Codex 只會在 `.codex/config.toml` 不存在時建立它。首次安裝會在不
45
+ 覆寫既有內容的前提下,於選定 harness directory 建立 `loop-goal.md`、
46
+ `loop-state.md` 與 `loop-telemetry.jsonl`;並以 hash-commented `.gitignore`
47
+ block 忽略這些 local file。
48
+
49
+ Loop 會執行 `SessionStart`、`UserPromptSubmit`、`PreToolUse`、
50
+ `PermissionRequest`、`PostToolUse`、`PreCompact`、`PostCompact`、
51
+ `SubagentStart` 與 `SubagentStop`,但永遠不加入 `Stop`。它只攔截
52
+ high-confidence 的 literal secret prompt 或 Bash command,以及危險 Bash command
53
+ (包括 broad recursive deletion 與 `git reset --hard`)。Codex 使用原生 exit-code blocking
54
+ mechanism;Claude Code 則取得文件化的 native JSON decision shape。
55
+ `PermissionRequest`(包括 `sandbox_permissions: "require_escalated"`)只記錄
56
+ outcome,不會輸出 allow 或 deny decision,因此 host 原本的 approval flow 保持
57
+ 權威。
58
+
59
+ Session context、telemetry 與 compaction state 都受到明確上限。Telemetry 只含
60
+ timestamp、event、outcome 與 rule identifier,不會存 raw prompt、command 或
61
+ credential,並依 byte size rotation。PreCompact 的 Git-status snapshot 會先
62
+ redact,再寫入 `loop-state.md` 的專用 block,周圍的 user content 保持不變。
63
+ installer update 與 uninstall 只管理 launcher、native handler registration 與
64
+ 精確的 `.gitignore` block;goal、state、telemetry 與 `config.toml` 都保留為 local
65
+ user file。若既有 `.codex/config.toml` 明確寫有 `[features]` 後的
66
+ `hooks = false`,planning 會在任何 write 之前以
67
+ `CODEX_LOOP_HOOKS_DISABLED` 停止。
68
+
69
+ Codex 與 Claude Code 對這些 generated handler 仍須走各自正常的 project-hook
70
+ trust/review flow。Loop 是聚焦的 guardrail,不是完整 sandbox、permission bypass
71
+ 或 Stop-verification feature。啟用前請閱讀 [Codex hook
72
+ 文件](https://developers.openai.com/codex/config-advanced#hooks)與 [Claude Code
73
+ hook 文件](https://code.claude.com/docs/en/hooks)。
74
+
75
+ ### Runtime-failure 保護措施
76
+
77
+ 對一般 `guardrails` profile 而言,只有 `command-policy` 具有 fail-closed failure mode。當已安裝的 config 被分類
78
+ 為無效時,Claude Code 可在原生 `PreToolUse` 輸出文件化的 denial shape。受管理的
79
+ OpenCode `tool.execute.before` plugin 可在其支援的 Bash surface
80
+ 上 throw 文件化的 command-policy denial 或 unavailable-runtime error。Codex 明確
81
+ 不執行強制措施(`unknown`)。這些是 agent-ops 的 output 與 plugin contract,不
82
+ 證明 host 會實際遵守 denial。所有 adapter 的 `SessionStart` 與 `Stop` failure path
83
+ 都維持 fail-open。
84
+
85
+ Claude 的無效 config fallback 有四項防護:(1) 缺少 project configuration 時保持
86
+ fail-open,因此只有無效的 `.agent-ops/config.json` 能進入 fallback;(2) manifest
87
+ 必須安全地證明目前 harness 已安裝;(3) 使用者可在啟動 host 前於 shell export
88
+ `AGENT_OPS_DISABLE=1`,暫時恢復 fail-open;(4) Claude Code denial 會列出 config
89
+ path,並告知使用者修正它或暫時設定該 shell variable。此 variable 只從
90
+ hook-process environment 讀取,不能由 agent-ops configuration、manifest 或
91
+ managed file 設定。
92
+
29
93
  `guardrails` 只安裝 command policy,不會啟用 Stop verification。Stop 是獨立的
30
94
  config v2 feature,必須明確啟用且至少提供一個已確認的 command:
31
95
 
@@ -54,9 +118,13 @@ agent-ops update
54
118
  agent-ops trust grant
55
119
  ```
56
120
 
57
- 未執行 `update` 時,doctor 會回報 `UPDATE_REQUIRED`;未重新 grant trust
58
- 時,trust-gated hook 仍會是 stale。Stop report-only:`PASS`、`FAIL`
59
- `UNKNOWN` 都會讓 harness 繼續,只輸出有界的 command ID、exit code、test-count、
121
+ 未執行 `update` 時,doctor 可因 registration drift 回報 `UPDATE_REQUIRED`。另
122
+ 外,toolkit upgrade effective profile capability change 使完整的
123
+ path-independent managed rules artifact 改變時,`artifact-staleness` 會回報帶有
124
+ `UPDATE_REQUIRED` 的 `DEGRADED`。`agent-ops update` 會重新產生 artifact 並清除
125
+ 這個結果;artifact 缺失或 hash 不符時,`artifacts` check 仍為 `FAIL`。未重新
126
+ grant trust 時,trust-gated hook 仍會是 stale。Stop 是 report-only:`PASS`、`FAIL`
127
+ 與 `UNKNOWN` 都會讓 harness 繼續,只輸出有界的 command ID、exit code、test-count、
60
128
  config-hash 與 timestamp evidence,且永遠不會完成 task。Config v1 會決定性遷移
61
129
  為 Stop disabled 的 v2;舊 binary 無法讀取遷移後的 config,routing migration
62
130
  一旦套用即為單向,降版前請先閱讀 release notes。
@@ -1,8 +1,8 @@
1
1
  # Harness Adapter
2
2
 
3
- English source version: 2026-07-31. Revalidate: when the English specification or either vendor reference changes.
3
+ English source version: 2026-08-03. Revalidate: when the English specification or any vendor reference changes.
4
4
 
5
- 本文件所述 OpenCode plugin 行為已於 2026-07-31 依據[官方 plugin 文件](https://opencode.ai/docs/plugins/)與[Bun shell 文件](https://bun.sh/docs/runtime/shell)檢查。
5
+ 本文件所述 OpenCode plugin 行為已於 2026-07-31 依據[官方 plugin 文件](https://opencode.ai/docs/plugins/)與[Bun shell 文件](https://bun.sh/docs/runtime/shell)檢查;Codex 與 Claude Code loop-hook 行為已於 2026-08-03 依據 [Codex hook 文件](https://developers.openai.com/codex/config-advanced#hooks) 與 [Claude Code hook 文件](https://code.claude.com/docs/en/hooks) 檢查。
6
6
 
7
7
  ## HARNESS-ADAPTER-001
8
8
 
@@ -37,17 +37,17 @@ Adapter MUST 具備冪等性,且 MUST NOT 刪除使用者擁有的 handler。
37
37
 
38
38
  ## HARNESS-ADAPTER-004
39
39
 
40
- OpenCode shim MUST 從選定的 project directory 呼叫 absolute runtime path;runtime 不可用時,MUST 對 advisory event fail open,並對 command-policy event fail closed
40
+ OpenCode shim MUST 從選定的 project directory 呼叫 absolute runtime path;runtime 不可用時,MUST 對 advisory event fail open,並 MUST throw 文件化的 command-policy error
41
41
 
42
42
  - Trigger: 產生的 plugin 呼叫 `agent-ops`,或收到無效的 runtime decision。
43
43
  - Action: 將 normalization 與 native output encoding 留在 runtime adapter;deny
44
- decision 要 throw policy reason;lifecycle-summary 經由 shared advisory
45
- implementation 執行。Plugin initialization 仍是 app-scoped 而非 per-session,
46
- 因此 per-session lifecycle fidelity 仍為 degraded。
47
- - Evidence: shim import 測試涵蓋 allow、deny 與 missing-runtime;doctor
48
- OpenCode lifecycle support 回報 `DEGRADED`。
49
- - Positive: `runtime 不可用時不阻擋 SessionStart,但會在 bash tool 執行前阻擋它。`
50
- - Negative: `退回 PATH-resolved 的 agent-ops executable,或宣稱 app initialization 等同於 per-session Stop。`
44
+ decision 要 throw 文件化的 policy reason;lifecycle-summary 經由 shared
45
+ advisory implementation 執行。Plugin initialization 仍是 app-scoped 而非
46
+ per-session,因此 per-session lifecycle fidelity 仍為 degraded。
47
+ - Evidence: shim import 測試涵蓋 allow、deny 與 missing-runtime;denial fixture
48
+ 只斷言 output shape;doctor 對 OpenCode lifecycle support 回報 `DEGRADED`。
49
+ - Positive: `runtime 不可用時,SessionStart 維持 fail-open,而生成的 plugin 會在 Bash pre-tool hook 中 throw 文件化的 command-policy error。`
50
+ - Negative: `退回 PATH-resolved 的 agent-ops executable、宣稱 OpenCode host 一定會遵守 thrown denial,或宣稱 app initialization 等同於 per-session Stop。`
51
51
 
52
52
  ## HARNESS-ADAPTER-005
53
53
 
@@ -60,10 +60,30 @@ event、native output encode 與 runtime-failure output。
60
60
  - Action: 在所屬 harness 加入 capability-to-native registration,包含 support
61
61
  level 與 runtime-failure mode;不得將 native event 加入 universal union。
62
62
  - Evidence: 每個宣告為 `supported` 的 registration 都經由真實 CLI hook process
63
- 執行,未支援的 Stop/lifecycle registration 不得回報 enforcement success。
64
- - Positive: `Claude command-policy 經由 runHookCommand 抵達 native PreToolUse denial。`
63
+ 執行;denial-shape fixture 只斷言文件化的 wire shape,不證明 host runtime
64
+ enforcement;未支援的 Stop/lifecycle registration 不得回報 enforcement success。
65
+ - Positive: `fail-closed 的 Claude command-policy runtime failure 會透過 runHookCommand 產生文件化的 PreToolUse denial shape。`
65
66
  - Negative: `dispatchHookEvent 尚未提供 advisory implementation 卻將 SessionStart 標為 supported。`
66
67
 
68
+ ## HARNESS-ADAPTER-006
69
+
70
+ Project-local `loop` profile MUST 是 opt-in、project scoped,並在最小的 Codex 與
71
+ Claude Code launcher 後使用同一個 shared runtime。它 MUST NOT 將 policy 複製到
72
+ project-specific script,也不得改變一般 permission request。
73
+
74
+ - Trigger: Project 以 Codex、Claude Code 或兩者選擇 `loop`。
75
+ - Action: 只產生選定的 `.codex/hooks/agent-ops-loop.sh` 與/或
76
+ `.claude/hooks/agent-ops-loop.sh` launcher,註冊文件化的 loop lifecycle event
77
+ (不含 `Stop`),並保留 foreign hook group。只在 `UserPromptSubmit` 或 Bash
78
+ `PreToolUse` 的 high-confidence literal credential,以及 `PreToolUse` 的危險 Bash command 時,使用
79
+ 文件化的 native denial shape 進行 blocking。對 `PermissionRequest`(包括
80
+ escalated permission)不得輸出 decision。
81
+ - Evidence: Install-plan、loop-runtime、update、uninstall 與 doctor test 覆蓋
82
+ generated path、Codex/Claude wire output、privacy bound、configuration conflict
83
+ handling、state preservation 與 registration drift。
84
+ - Positive: `Claude PreToolUse 的危險 Bash command 取得 native deny,而 PermissionRequest 不產生 allow 或 deny decision。`
85
+ - Negative: `將 project loop policy 複製到兩個 shell launcher、auto-approve sandbox escalation,或加入 loop Stop handler。`
86
+
67
87
  目前 registration matrix 刻意不對稱:
68
88
 
69
89
  | Capability | Codex | Claude Code | OpenCode |
@@ -72,6 +92,18 @@ event、native output encode 與 runtime-failure output。
72
92
  | command-policy | unknown | supported | supported |
73
93
  | optional-stop-verify | unsupported | supported | degraded |
74
94
 
95
+ Runtime-failure 處理中,只有 `command-policy` 為 fail-closed。當已安裝的 config
96
+ 被分類為無效時,Claude Code 可輸出文件化的 `PreToolUse` denial shape;受管理的
97
+ OpenCode `tool.execute.before` plugin 可在其支援的 Bash surface 上 throw 文件化的
98
+ denial 或 unavailable-runtime error。Codex 維持 `unknown` 且絕不輸出 denial。
99
+ Fixture test 只斷言這些 wire 與 plugin shape;它們不證明 host 會實際遵守 denial。
100
+ 每個 `SessionStart` 與 `Stop` failure path 都維持 fail-open。
101
+
75
102
  Stop verification 必須明確啟用、具備 trust、為 report-only 且預設 disabled。
76
103
  每個 Stop 結果都會讓 native harness 繼續,最多攜帶有界 command evidence,永遠
77
104
  不是 task-completion evidence。
105
+
106
+ `loop` profile 與上方 ordinary capability matrix 分離。它只保存有界的 local
107
+ event metadata、回傳有界且 redacted 的 session context,並在 update 或 uninstall
108
+ 時保留 local goal、state、telemetry 與 Codex TOML file。既有 Codex configuration
109
+ 中清楚解析出的 `[features]` / `hooks = false` MUST 在任何 write 前拒絕 loop planning。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kylecheng3146/agent-ops",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Evidence-driven development loops for Codex, Claude Code, and opencode",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "type": "array",
21
21
  "uniqueItems": true,
22
22
  "items": {
23
- "enum": ["core", "advisory", "guardrails"]
23
+ "enum": ["core", "advisory", "guardrails", "loop"]
24
24
  }
25
25
  },
26
26
  "verification": {
@@ -134,7 +134,18 @@
134
134
  "minItems": 1,
135
135
  "uniqueItems": true,
136
136
  "items": {
137
- "enum": ["SessionStart", "PreToolUse", "Stop"]
137
+ "enum": [
138
+ "SessionStart",
139
+ "UserPromptSubmit",
140
+ "PreToolUse",
141
+ "PermissionRequest",
142
+ "PostToolUse",
143
+ "PreCompact",
144
+ "PostCompact",
145
+ "SubagentStart",
146
+ "SubagentStop",
147
+ "Stop"
148
+ ]
138
149
  }
139
150
  },
140
151
  "owner": {