@yunhozz/arc 0.4.5 → 0.4.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.
- package/MANIFEST.sha256 +16 -16
- package/README.md +2 -2
- package/claude/skill/references/coordination.md +4 -2
- package/codex/skill/references/coordination.md +4 -2
- package/gemini/skill/references/coordination.md +4 -2
- package/grok/skill/references/coordination.md +4 -2
- package/lib/runtime/grok-sandbox.mjs +74 -0
- package/lib/runtime/role-dispatch-policy.mjs +3 -1
- package/lib/runtime/role-observe.mjs +213 -3
- package/lib/runtime/role-routing.mjs +6 -0
- package/lib/runtime/role-supervisor.mjs +21 -14
- package/package.json +1 -1
- package/shared/skill/runtime/grok-sandbox.mjs +74 -0
- package/shared/skill/runtime/role-dispatch-policy.mjs +3 -1
- package/shared/skill/runtime/role-observe.mjs +213 -3
- package/shared/skill/runtime/role-routing.mjs +6 -0
- package/shared/skill/runtime/role-supervisor.mjs +21 -14
package/MANIFEST.sha256
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
01d6dc7d2e595ea480f18b199031e826fffea0558f480d65518e27a3ef58b1e7 README.md
|
|
2
2
|
d41edeb8c6631dee30c67c705d4edad977aa1631627ec9de59c013f8990f4018 bin/arc-upgrade.mjs
|
|
3
3
|
484d9b2002ce542c87589bb719d644d3762706aad28a6ee010024875f8cc00e2 bin/arc.mjs
|
|
4
4
|
b763239df5a8361da783848494218f5fd1f7169a513b729362d0424e3579fca5 claude/agents/arc-implementer.md
|
|
@@ -9,7 +9,7 @@ a61e2f4224efdef60db074d2ff9b55ccfde0c52eae76cd534ece98a203f83426 claude/agents/
|
|
|
9
9
|
a06a8367ca3984124854453387ab082e33c42c5a59962fbef1fc8aad218e04fc claude/skill/SKILL.md
|
|
10
10
|
27c12eefe19f742f2e4a2e600f55249c9a461676f3bf09f3c2cd0499efb1a9b5 claude/skill/references/arc-visual-companion.md
|
|
11
11
|
23ae131ec5dc79435772e782ecabec0c776f82bf97f51eadfb9f4ac79b7173b8 claude/skill/references/commit.md
|
|
12
|
-
|
|
12
|
+
f8e2cf10eabd3441e1a61df0cb567f6602d836fb653b7bdbd575d9c3bb3e4394 claude/skill/references/coordination.md
|
|
13
13
|
1d6745550da04eaf09977026c596fe389ec7a7b6c32ad3970dc958b56b935251 claude/skill/references/git-recovery.md
|
|
14
14
|
a0f8fa528dff79a57f945f27325741f65a2ffe9e2ee72c06dfc3659722b28ca7 claude/skill/references/handoff-prep.md
|
|
15
15
|
2ed6699c82d89176ebbca19b241d130da906748381563c9b697ed117b34540d6 claude/skill/references/handoff.md
|
|
@@ -27,7 +27,7 @@ fde21d68e655a2ed225c8269d63c49a4334577fe67a111ccd02dc3b763cdf44e codex/agents/a
|
|
|
27
27
|
c5d18f189ac8a05989ee893d94b7ecb1d930233711fda690a5ec3488afea5966 codex/skill/SKILL.md
|
|
28
28
|
8e2d085f7fcd7aaebe4ea25d8a5282b22e3150a5053c16ef6417ec023487839c codex/skill/references/arc-visual-companion.md
|
|
29
29
|
b5bdb82c2cb5e67061f3d9a9e37dd8a4305fd034100229914217402a215cfc06 codex/skill/references/commit.md
|
|
30
|
-
|
|
30
|
+
04ab100382d91c27eca288b84d75d4dab34998f3be833c115db52703a674912f codex/skill/references/coordination.md
|
|
31
31
|
c648d9c98c9dee3ecdf7b3a915e69fd67875c6344ee9c4d04cd1de0227a64050 codex/skill/references/git-recovery.md
|
|
32
32
|
9acc6db11009bd5376055d461349e956793e9c933aad96f00b2904ccc9519027 codex/skill/references/handoff-prep.md
|
|
33
33
|
be5c0a6997a5dabc201b2176c5434f3db89a3c6ef47c363e6734e2285333d9fe codex/skill/references/handoff.md
|
|
@@ -47,7 +47,7 @@ d9fff57cf884a2cee6b6bacb309d63d4469bf4ce48e0a2af4678f034577fc5a5 gemini/instruc
|
|
|
47
47
|
6f4f5cc5a0442af3e54ad468ddae27696a117c4f305d5d155781e35c97bc2f36 gemini/skill/SKILL.md
|
|
48
48
|
27c12eefe19f742f2e4a2e600f55249c9a461676f3bf09f3c2cd0499efb1a9b5 gemini/skill/references/arc-visual-companion.md
|
|
49
49
|
b4f1edb90de48a543584d276261d17859d4041e59c38e1dd17e4e7735f051181 gemini/skill/references/commit.md
|
|
50
|
-
|
|
50
|
+
751eb3c70f221cdf251d0a6120a47494e40798503a8169f1124747dc8ee0f747 gemini/skill/references/coordination.md
|
|
51
51
|
ce32077220fa164e5aae50a599776cf9043ac5706add48aae9d3023f3b0d2de1 gemini/skill/references/git-recovery.md
|
|
52
52
|
ac561393c9af397348b09653e4304cfd62beac6e0444ad8c65e8505e3ebc758b gemini/skill/references/handoff-prep.md
|
|
53
53
|
1848862dfca2ae1fad095ac42efff7d9c7132196df54ed4335a88950cf4ce10e gemini/skill/references/handoff.md
|
|
@@ -65,7 +65,7 @@ afe2a540bf89f4099e6db740d32d897a98d6721743d888f4fd6fa379d7e1d97f grok/agents/ar
|
|
|
65
65
|
98d599c41e0b6256aa2344d1ced7a4985fc13b23d756e95921dae24bfce35839 grok/skill/SKILL.md
|
|
66
66
|
27c12eefe19f742f2e4a2e600f55249c9a461676f3bf09f3c2cd0499efb1a9b5 grok/skill/references/arc-visual-companion.md
|
|
67
67
|
93ffa3d70ff4740b59bf614419df38c61a3c1ad2a93ac1777f611ba6cb098161 grok/skill/references/commit.md
|
|
68
|
-
|
|
68
|
+
304ca4b0686ead9a58879c41443955fa0b011a256aad4d91ca84d1f38cc3213c grok/skill/references/coordination.md
|
|
69
69
|
24eb5bf7571001c1127d8a2865bba3bb4fd1091942e9a6a3a610e66078d30b23 grok/skill/references/git-recovery.md
|
|
70
70
|
99849c939119057ee23d6a06a218662c9acfd296090364d8973049a55155f517 grok/skill/references/handoff-prep.md
|
|
71
71
|
755a03072d804ed5ee3844476b2142d0f7a502da24ecea326c9424eb9aede31a grok/skill/references/handoff.md
|
|
@@ -156,7 +156,7 @@ c73244c65aad793559555f7998adfda5b5c2db2831bdb6420861d3564b31ead2 lib/runtime/ex
|
|
|
156
156
|
5d8e7ac39d5e4e08357ef45579be677f4cb578df6302e2407db669885e1f20d1 lib/runtime/gemini-stream.mjs
|
|
157
157
|
f501815eb8adef4582846cb067973e50fc4ece668aa70ae880803c80f39a07df lib/runtime/git-evidence.mjs
|
|
158
158
|
494470cf70121ddac8d716586b0c05b1f0977f3eada8c0323ed34dc157b0db8e lib/runtime/git-query.mjs
|
|
159
|
-
|
|
159
|
+
ae0998af4fb15181e6a2fdd83c84ee865ad3de49c7088cd2a63abdb45dc65560 lib/runtime/grok-sandbox.mjs
|
|
160
160
|
54caa1114367936e1319ed88e5c3d0120fdba75ac5c2621a6293205d00e8238a lib/runtime/grok-stream.mjs
|
|
161
161
|
44a55959292893f484993eb478ea2a143e908a2a11b88e1fa553525918b694d6 lib/runtime/identity.mjs
|
|
162
162
|
0e452e7241e4fc61c798aa07d3bbc62a475f8e3d7c5eb6b29603febb39cda580 lib/runtime/local-cli.mjs
|
|
@@ -164,12 +164,12 @@ f501815eb8adef4582846cb067973e50fc4ece668aa70ae880803c80f39a07df lib/runtime/gi
|
|
|
164
164
|
46978605c519826283ecc091052fb97e6b436ace3c68a1f069ce378397a1df1d lib/runtime/platform-registry.mjs
|
|
165
165
|
404378797844ef7dd94384853acb1cd96b3dd8a4341378bf5fcbfb21c7f7475b lib/runtime/role-bridge-args.mjs
|
|
166
166
|
9f82b681191a1d082414501171769242a551483b08e071871a965fcc366c67a5 lib/runtime/role-bridge.mjs
|
|
167
|
-
|
|
167
|
+
6fb75ec963e856c8292e2c4d46e3f4db1befe159d4f9f8dcfe9f7e6826ce4fac lib/runtime/role-dispatch-policy.mjs
|
|
168
168
|
aab17097ad0e27f747874e1921f0756f441544f9ac44bc76591018e46c4f7320 lib/runtime/role-dispatch-store.mjs
|
|
169
|
-
|
|
169
|
+
2a174bfcb56b7da7596b4f8d6223a248a54f3a78277fcc50193b9fa12b137e46 lib/runtime/role-observe.mjs
|
|
170
170
|
def993a33a56e5c6c8c465a881affdfd70afc8c7192549a3e1a130ed8f2e17b8 lib/runtime/role-routing-config.mjs
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
209e57c1e316b7bfec2d8f29f9ce707dea6267352fcc76b8a9929145cc45860d lib/runtime/role-routing.mjs
|
|
172
|
+
c7bd3678933b196eecce7eb20dfd1beed54f01cdd741822f1f7a6e8ec0dd62b1 lib/runtime/role-supervisor.mjs
|
|
173
173
|
b8c876ad4cb55c93845bd30ae7432c1eed90af41a17f917997ec8dbf536bb4b7 lib/runtime/schema.mjs
|
|
174
174
|
e2e768e62a46c8ef568fc3021ac8415c4dc68fa9843b9ffb3dbbbb2e5fa3a6af lib/runtime/scope.mjs
|
|
175
175
|
2a942884862da5fdb23e17688141f2bf75925a81af6b4f749d443b88c90ec34a lib/runtime/store.mjs
|
|
@@ -204,7 +204,7 @@ d8340e96f53e3c5615a9427934b3fc33d511c533b40d467b98add47273e3995c lib/watch/scop
|
|
|
204
204
|
26cdc499cbb78a3bb647c78b30f96c1ceeb5a49f6621cc70b51262be5d2f2f9c lib/watch/watcher.mjs
|
|
205
205
|
ff9c33c8b3c2bd466d54ffbe4c7139ccd87c79c7de34a6c4cde92e9f6e9b42d2 native/binding.c
|
|
206
206
|
205bedc1dee1a9ffa58124c6e21256a1f0cbe24f06f7c8d7cb0b99524cfab9d0 native/binding.gyp
|
|
207
|
-
|
|
207
|
+
7d6b460502706595121dfd1825ef5108ff993d06a23c0f5a00e7a15a5d3ba8fb package.json
|
|
208
208
|
208c65cfde244d39ce45c3cf1b0acb128f04d21199b6b3fb5466e62db5b64af9 prebuilds/darwin-arm64/arc_safe_fs.node
|
|
209
209
|
572887ac794d10a8b921d8168ea2328e31f05b45987611ff02c83114dba901af prebuilds/darwin-x64/arc_safe_fs.node
|
|
210
210
|
2bb9443021f9d873712b26321de733eddd6794c45f0bc79e2d5dc98669196635 prebuilds/index.json
|
|
@@ -250,7 +250,7 @@ c73244c65aad793559555f7998adfda5b5c2db2831bdb6420861d3564b31ead2 shared/skill/r
|
|
|
250
250
|
5d8e7ac39d5e4e08357ef45579be677f4cb578df6302e2407db669885e1f20d1 shared/skill/runtime/gemini-stream.mjs
|
|
251
251
|
f501815eb8adef4582846cb067973e50fc4ece668aa70ae880803c80f39a07df shared/skill/runtime/git-evidence.mjs
|
|
252
252
|
494470cf70121ddac8d716586b0c05b1f0977f3eada8c0323ed34dc157b0db8e shared/skill/runtime/git-query.mjs
|
|
253
|
-
|
|
253
|
+
ae0998af4fb15181e6a2fdd83c84ee865ad3de49c7088cd2a63abdb45dc65560 shared/skill/runtime/grok-sandbox.mjs
|
|
254
254
|
54caa1114367936e1319ed88e5c3d0120fdba75ac5c2621a6293205d00e8238a shared/skill/runtime/grok-stream.mjs
|
|
255
255
|
44a55959292893f484993eb478ea2a143e908a2a11b88e1fa553525918b694d6 shared/skill/runtime/identity.mjs
|
|
256
256
|
0e452e7241e4fc61c798aa07d3bbc62a475f8e3d7c5eb6b29603febb39cda580 shared/skill/runtime/local-cli.mjs
|
|
@@ -258,13 +258,13 @@ f501815eb8adef4582846cb067973e50fc4ece668aa70ae880803c80f39a07df shared/skill/r
|
|
|
258
258
|
46978605c519826283ecc091052fb97e6b436ace3c68a1f069ce378397a1df1d shared/skill/runtime/platform-registry.mjs
|
|
259
259
|
404378797844ef7dd94384853acb1cd96b3dd8a4341378bf5fcbfb21c7f7475b shared/skill/runtime/role-bridge-args.mjs
|
|
260
260
|
9f82b681191a1d082414501171769242a551483b08e071871a965fcc366c67a5 shared/skill/runtime/role-bridge.mjs
|
|
261
|
-
|
|
261
|
+
6fb75ec963e856c8292e2c4d46e3f4db1befe159d4f9f8dcfe9f7e6826ce4fac shared/skill/runtime/role-dispatch-policy.mjs
|
|
262
262
|
aab17097ad0e27f747874e1921f0756f441544f9ac44bc76591018e46c4f7320 shared/skill/runtime/role-dispatch-store.mjs
|
|
263
|
-
|
|
263
|
+
2a174bfcb56b7da7596b4f8d6223a248a54f3a78277fcc50193b9fa12b137e46 shared/skill/runtime/role-observe.mjs
|
|
264
264
|
fa7d3911df7b38aceae0e18a3d4f78c5fe451c681fc811dd24c02eaca40ca006 shared/skill/runtime/role-policy.json
|
|
265
265
|
def993a33a56e5c6c8c465a881affdfd70afc8c7192549a3e1a130ed8f2e17b8 shared/skill/runtime/role-routing-config.mjs
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
209e57c1e316b7bfec2d8f29f9ce707dea6267352fcc76b8a9929145cc45860d shared/skill/runtime/role-routing.mjs
|
|
267
|
+
c7bd3678933b196eecce7eb20dfd1beed54f01cdd741822f1f7a6e8ec0dd62b1 shared/skill/runtime/role-supervisor.mjs
|
|
268
268
|
b8c876ad4cb55c93845bd30ae7432c1eed90af41a17f917997ec8dbf536bb4b7 shared/skill/runtime/schema.mjs
|
|
269
269
|
e2e768e62a46c8ef568fc3021ac8415c4dc68fa9843b9ffb3dbbbb2e5fa3a6af shared/skill/runtime/scope.mjs
|
|
270
270
|
2a942884862da5fdb23e17688141f2bf75925a81af6b4f749d443b88c90ec34a shared/skill/runtime/store.mjs
|
package/README.md
CHANGED
|
@@ -75,10 +75,10 @@ The package provides the CLI; use the TUI to install the harness. Public command
|
|
|
75
75
|
|
|
76
76
|
| Platform | Host? | Native roles | Bridges to this platform | Authentication |
|
|
77
77
|
|---|---|---|---|---|
|
|
78
|
-
| Claude | Yes | Supported on CLI | Scouter/Planner/Reviewer on Codex after per-call escalation; Implementer/QA held
|
|
78
|
+
| Claude | Yes | Supported on CLI | Scouter/Planner/Reviewer on Codex after per-call escalation; Implementer/QA run with the recorded sandbox settings (`G1` pass) and are held with `permission_scope_unverified` if settings injection fails or the worktree `.claude/settings*.json` would widen their scope | `claude auth status` |
|
|
79
79
|
| Codex | Yes | Supported on CLI | From Claude; permissions claim capped at `operator-attested` | `codex app-server` refresh rotates `auth.json`; network required |
|
|
80
80
|
| Gemini | No | Standalone verified | Read roles verified; write roles held: `permission_scope_unverified` | No probe; `unknown`, `auth unverified` warning |
|
|
81
|
-
| Grok | No | Standalone enabled (not live-verified) | Read roles enabled (not live-verified); write roles
|
|
81
|
+
| Grok | No | Standalone enabled (not live-verified) | Read roles enabled (not live-verified); write roles run with a per-dispatch sandbox profile confirmed by `ProfileApplied` (`GK1` pass, live-verified on Grok 1.0.89 macOS); `~/.grok/config.toml` and `~/.grok/sandbox.toml` are not in the deny list; their security-relevant changes are detected after the run (`permission_violation_observed`); Configure sets `[compat.claude]` agents/skills/rules to false in `~/.grok/config.toml` (session effect unverified) | No probe; `unknown`, `auth unverified` warning |
|
|
82
82
|
|
|
83
83
|
| executionEnvironment | Support and obligations |
|
|
84
84
|
|---|---|
|
|
@@ -176,9 +176,11 @@ GK2 is `approval`.
|
|
|
176
176
|
|
|
177
177
|
### Bridge target rules
|
|
178
178
|
|
|
179
|
+
- Bridge prepare, run and resume hold `permission_scope_unverified` when `allowedPaths` cover `.`, `.git`, `.claude`, `.claude/settings*.json`, `.codex` or `.codex/config.toml`; any change to `.git` config, hooks or info, `.claude/settings*.json` or `.codex/config.toml` fails the dispatch as `permission_violation_observed` regardless of role and `allowedPaths`, and Grok writing roles also fail on changes to the security keys of the Grok home `config.toml` or to its `sandbox.toml`.
|
|
180
|
+
|
|
179
181
|
**Claude**
|
|
180
182
|
|
|
181
|
-
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified`
|
|
183
|
+
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified` when an injected G1 fails or settings are missing (G1). Claude Implementer/QA bridges also deny writes under `.git` (permission rules and sandbox `denyWrite`), and are held as `permission_scope_unverified` when the worktree `.claude/settings.json` or `.claude/settings.local.json` would widen their scope (additional directories, allow rules for tools outside the safe list (Bash, Read, Grep, Glob, WebFetch, WebSearch), hooks, sandbox or defaultMode).
|
|
182
184
|
- Permission claim: Compare the `init` event with the expected tools and permission mode. If `init` is missing, the `permissions` claim is `unverified`. If the tools or permission mode differ, the claim is `unverified` and the reason is `permission_scope_mismatch`.
|
|
183
185
|
- Delegation: Role instructions forbid re-delegation. Claude children expose no Task tool. Apply the shared child guard below.
|
|
184
186
|
- Execution confirmation: Check the stream session identity and model, transcript effort, and the observed terminal result.
|
|
@@ -215,7 +217,7 @@ GK2 is `approval`.
|
|
|
215
217
|
- Active bridge dispatches block publishing the composite configuration (`Active bridge dispatches: <ids>`); finish or cancel them first. Native leases do not block.
|
|
216
218
|
- `execution_identity_unverified` (no session ID was obtained) is recorded by the supervisor after exit and exposed by `observe`; `resume` holds with it for a dispatch without a session ID. The `run-dispatch` response and `prepare-dispatch` never carry it.
|
|
217
219
|
- A leftover orphaned process group after the child leader exits by itself is reaped (SIGTERM, grace, then SIGKILL) before the post-run snapshot is taken, and `orphanGroupReaped` is recorded; if the group cannot be observed gone the dispatch is `unknown` (`terminal_state_unverified`) and keeps its slot.
|
|
218
|
-
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection.
|
|
220
|
+
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection, except the control files listed above.
|
|
219
221
|
- `ARC_BRIDGE_CHILD` is set in the environment of every bridge child; routing commands are denied in a process that has it. Re-running `codex exec`, `claude -p`, `gemini` or `grok` through a shell is outside `delegation_observed` detection.
|
|
220
222
|
- CLI versions are not restricted. `routing-status` and bridge `prepare-dispatch` report the parsed `<cli> --version` result (`cliVersion.version`, or `null` with a `reason`) for information only; no version holds a native or bridge route.
|
|
221
223
|
- There is no automatic fallback, substitution or retry. On any hold, deny or failure, report the reasons and release conditions and DO NOT use another model or platform. Run `routing-status` again only after the condition changed. Bridge dispatches count in the instance ledger; see [limits](limits.md).
|
|
@@ -174,9 +174,11 @@ GK2 is `approval`.
|
|
|
174
174
|
|
|
175
175
|
### Bridge target rules
|
|
176
176
|
|
|
177
|
+
- Bridge prepare, run and resume hold `permission_scope_unverified` when `allowedPaths` cover `.`, `.git`, `.claude`, `.claude/settings*.json`, `.codex` or `.codex/config.toml`; any change to `.git` config, hooks or info, `.claude/settings*.json` or `.codex/config.toml` fails the dispatch as `permission_violation_observed` regardless of role and `allowedPaths`, and Grok writing roles also fail on changes to the security keys of the Grok home `config.toml` or to its `sandbox.toml`.
|
|
178
|
+
|
|
177
179
|
**Claude**
|
|
178
180
|
|
|
179
|
-
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified`
|
|
181
|
+
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified` when an injected G1 fails or settings are missing (G1). Claude Implementer/QA bridges also deny writes under `.git` (permission rules and sandbox `denyWrite`), and are held as `permission_scope_unverified` when the worktree `.claude/settings.json` or `.claude/settings.local.json` would widen their scope (additional directories, allow rules for tools outside the safe list (Bash, Read, Grep, Glob, WebFetch, WebSearch), hooks, sandbox or defaultMode).
|
|
180
182
|
- Permission claim: Compare the `init` event with the expected tools and permission mode. If `init` is missing, the `permissions` claim is `unverified`. If the tools or permission mode differ, the claim is `unverified` and the reason is `permission_scope_mismatch`.
|
|
181
183
|
- Delegation: Role instructions forbid re-delegation. Claude children expose no Task tool. Apply the shared child guard below.
|
|
182
184
|
- Execution confirmation: Check the stream session identity and model, transcript effort, and the observed terminal result.
|
|
@@ -213,7 +215,7 @@ GK2 is `approval`.
|
|
|
213
215
|
- Active bridge dispatches block publishing the composite configuration (`Active bridge dispatches: <ids>`); finish or cancel them first. Native leases do not block.
|
|
214
216
|
- `execution_identity_unverified` (no session ID was obtained) is recorded by the supervisor after exit and exposed by `observe`; `resume` holds with it for a dispatch without a session ID. The `run-dispatch` response and `prepare-dispatch` never carry it.
|
|
215
217
|
- A leftover orphaned process group after the child leader exits by itself is reaped (SIGTERM, grace, then SIGKILL) before the post-run snapshot is taken, and `orphanGroupReaped` is recorded; if the group cannot be observed gone the dispatch is `unknown` (`terminal_state_unverified`) and keeps its slot.
|
|
216
|
-
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection.
|
|
218
|
+
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection, except the control files listed above.
|
|
217
219
|
- `ARC_BRIDGE_CHILD` is set in the environment of every bridge child; routing commands are denied in a process that has it. Re-running `codex exec`, `claude -p`, `gemini` or `grok` through a shell is outside `delegation_observed` detection.
|
|
218
220
|
- CLI versions are not restricted. `routing-status` and bridge `prepare-dispatch` report the parsed `<cli> --version` result (`cliVersion.version`, or `null` with a `reason`) for information only; no version holds a native or bridge route.
|
|
219
221
|
- There is no automatic fallback, substitution or retry. On any hold, deny or failure, report the reasons and release conditions and DO NOT use another model or platform. Run `routing-status` again only after the condition changed. Bridge dispatches count in the instance ledger; see [limits](limits.md).
|
|
@@ -176,9 +176,11 @@ GK2 is `approval`.
|
|
|
176
176
|
|
|
177
177
|
### Bridge target rules
|
|
178
178
|
|
|
179
|
+
- Bridge prepare, run and resume hold `permission_scope_unverified` when `allowedPaths` cover `.`, `.git`, `.claude`, `.claude/settings*.json`, `.codex` or `.codex/config.toml`; any change to `.git` config, hooks or info, `.claude/settings*.json` or `.codex/config.toml` fails the dispatch as `permission_violation_observed` regardless of role and `allowedPaths`, and Grok writing roles also fail on changes to the security keys of the Grok home `config.toml` or to its `sandbox.toml`.
|
|
180
|
+
|
|
179
181
|
**Claude**
|
|
180
182
|
|
|
181
|
-
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified`
|
|
183
|
+
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified` when an injected G1 fails or settings are missing (G1). Claude Implementer/QA bridges also deny writes under `.git` (permission rules and sandbox `denyWrite`), and are held as `permission_scope_unverified` when the worktree `.claude/settings.json` or `.claude/settings.local.json` would widen their scope (additional directories, allow rules for tools outside the safe list (Bash, Read, Grep, Glob, WebFetch, WebSearch), hooks, sandbox or defaultMode).
|
|
182
184
|
- Permission claim: Compare the `init` event with the expected tools and permission mode. If `init` is missing, the `permissions` claim is `unverified`. If the tools or permission mode differ, the claim is `unverified` and the reason is `permission_scope_mismatch`.
|
|
183
185
|
- Delegation: Role instructions forbid re-delegation. Claude children expose no Task tool. Apply the shared child guard below.
|
|
184
186
|
- Execution confirmation: Check the stream session identity and model, transcript effort, and the observed terminal result.
|
|
@@ -215,7 +217,7 @@ GK2 is `approval`.
|
|
|
215
217
|
- Active bridge dispatches block publishing the composite configuration (`Active bridge dispatches: <ids>`); finish or cancel them first. Native leases do not block.
|
|
216
218
|
- `execution_identity_unverified` (no session ID was obtained) is recorded by the supervisor after exit and exposed by `observe`; `resume` holds with it for a dispatch without a session ID. The `run-dispatch` response and `prepare-dispatch` never carry it.
|
|
217
219
|
- A leftover orphaned process group after the child leader exits by itself is reaped (SIGTERM, grace, then SIGKILL) before the post-run snapshot is taken, and `orphanGroupReaped` is recorded; if the group cannot be observed gone the dispatch is `unknown` (`terminal_state_unverified`) and keeps its slot.
|
|
218
|
-
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection.
|
|
220
|
+
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection, except the control files listed above.
|
|
219
221
|
- `ARC_BRIDGE_CHILD` is set in the environment of every bridge child; routing commands are denied in a process that has it. Re-running `codex exec`, `claude -p`, `gemini` or `grok` through a shell is outside `delegation_observed` detection.
|
|
220
222
|
- CLI versions are not restricted. `routing-status` and bridge `prepare-dispatch` report the parsed `<cli> --version` result (`cliVersion.version`, or `null` with a `reason`) for information only; no version holds a native or bridge route.
|
|
221
223
|
- There is no automatic fallback, substitution or retry. On any hold, deny or failure, report the reasons and release conditions and DO NOT use another model or platform. Run `routing-status` again only after the condition changed. Bridge dispatches count in the instance ledger; see [limits](limits.md).
|
|
@@ -176,9 +176,11 @@ GK2 is `approval`.
|
|
|
176
176
|
|
|
177
177
|
### Bridge target rules
|
|
178
178
|
|
|
179
|
+
- Bridge prepare, run and resume hold `permission_scope_unverified` when `allowedPaths` cover `.`, `.git`, `.claude`, `.claude/settings*.json`, `.codex` or `.codex/config.toml`; any change to `.git` config, hooks or info, `.claude/settings*.json` or `.codex/config.toml` fails the dispatch as `permission_violation_observed` regardless of role and `allowedPaths`, and Grok writing roles also fail on changes to the security keys of the Grok home `config.toml` or to its `sandbox.toml`.
|
|
180
|
+
|
|
179
181
|
**Claude**
|
|
180
182
|
|
|
181
|
-
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified`
|
|
183
|
+
- Writing roles: Claude bridge `arc_implementer` and `arc_qa` run with recorded sandbox settings on every host and are held as `permission_scope_unverified` when an injected G1 fails or settings are missing (G1). Claude Implementer/QA bridges also deny writes under `.git` (permission rules and sandbox `denyWrite`), and are held as `permission_scope_unverified` when the worktree `.claude/settings.json` or `.claude/settings.local.json` would widen their scope (additional directories, allow rules for tools outside the safe list (Bash, Read, Grep, Glob, WebFetch, WebSearch), hooks, sandbox or defaultMode).
|
|
182
184
|
- Permission claim: Compare the `init` event with the expected tools and permission mode. If `init` is missing, the `permissions` claim is `unverified`. If the tools or permission mode differ, the claim is `unverified` and the reason is `permission_scope_mismatch`.
|
|
183
185
|
- Delegation: Role instructions forbid re-delegation. Claude children expose no Task tool. Apply the shared child guard below.
|
|
184
186
|
- Execution confirmation: Check the stream session identity and model, transcript effort, and the observed terminal result.
|
|
@@ -215,7 +217,7 @@ GK2 is `approval`.
|
|
|
215
217
|
- Active bridge dispatches block publishing the composite configuration (`Active bridge dispatches: <ids>`); finish or cancel them first. Native leases do not block.
|
|
216
218
|
- `execution_identity_unverified` (no session ID was obtained) is recorded by the supervisor after exit and exposed by `observe`; `resume` holds with it for a dispatch without a session ID. The `run-dispatch` response and `prepare-dispatch` never carry it.
|
|
217
219
|
- A leftover orphaned process group after the child leader exits by itself is reaped (SIGTERM, grace, then SIGKILL) before the post-run snapshot is taken, and `orphanGroupReaped` is recorded; if the group cannot be observed gone the dispatch is `unknown` (`terminal_state_unverified`) and keeps its slot.
|
|
218
|
-
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection.
|
|
220
|
+
- Post-run detection compares the changed paths, `HEAD`, the branch and every Git ref. Branch, tag and other ref creation, deletion or movement during a run is a `permission_violation_observed` for every role, assuming no other Git activity changes refs during the run. Changes to Git-ignored paths are outside post-run detection, except the control files listed above.
|
|
219
221
|
- `ARC_BRIDGE_CHILD` is set in the environment of every bridge child; routing commands are denied in a process that has it. Re-running `codex exec`, `claude -p`, `gemini` or `grok` through a shell is outside `delegation_observed` detection.
|
|
220
222
|
- CLI versions are not restricted. `routing-status` and bridge `prepare-dispatch` report the parsed `<cli> --version` result (`cliVersion.version`, or `null` with a `reason`) for information only; no version holds a native or bridge route.
|
|
221
223
|
- There is no automatic fallback, substitution or retry. On any hold, deny or failure, report the reasons and release conditions and DO NOT use another model or platform. Run `routing-status` again only after the condition changed. Bridge dispatches count in the instance ledger; see [limits](limits.md).
|
|
@@ -19,6 +19,80 @@ const sameEntry = (first, second) => first.dev === second.dev && first.ino === s
|
|
|
19
19
|
const identityOf = ({dev, ino}) => ({dev, ino});
|
|
20
20
|
const sandboxEventsPath = grokHome => path.join(grokHome, 'sessions', 'sandbox-events.jsonl');
|
|
21
21
|
|
|
22
|
+
function parseConfigKeyPath(source) {
|
|
23
|
+
const segment = /\s*(?:"([^"\\]*)"|'([^'\\]*)'|([\w-]+))\s*/y;
|
|
24
|
+
const segments = [];
|
|
25
|
+
for (;;) {
|
|
26
|
+
const match = segment.exec(source);
|
|
27
|
+
if (!match) return null;
|
|
28
|
+
segments.push(match[1] ?? match[2] ?? match[3]);
|
|
29
|
+
if (source[segment.lastIndex] !== '.') return {segments, rest: source.slice(segment.lastIndex)};
|
|
30
|
+
segment.lastIndex += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isGrokSecurityPath(segments) {
|
|
35
|
+
return segments.includes('permission_mode') || (segments[0] === 'compat' && segments[1] === 'claude')
|
|
36
|
+
|| /^sandbox[\w-]*$/.test(segments[0]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function arrayDepthAfterLine(value, depth) {
|
|
40
|
+
let quote = null;
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
const char = value[i];
|
|
43
|
+
if (quote) {
|
|
44
|
+
if (quote === '"' && char === '\\') i += 1;
|
|
45
|
+
else if (char === quote) quote = null;
|
|
46
|
+
} else if (char === '"' || char === "'") {
|
|
47
|
+
quote = char;
|
|
48
|
+
} else if (char === '#') {
|
|
49
|
+
break;
|
|
50
|
+
} else if (char === '[') {
|
|
51
|
+
depth += 1;
|
|
52
|
+
} else if (char === ']') {
|
|
53
|
+
depth -= 1;
|
|
54
|
+
if (depth < 0) return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return quote ? null : depth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function grokConfigSecurityProjection(bytes) {
|
|
61
|
+
let config;
|
|
62
|
+
try { config = new TextDecoder('utf-8', {fatal: true}).decode(bytes); } catch { return null; }
|
|
63
|
+
if (config.includes('"""') || config.includes("'''")) return null;
|
|
64
|
+
|
|
65
|
+
const lines = [];
|
|
66
|
+
let table = [];
|
|
67
|
+
let arrayDepth = 0, securityValue = false;
|
|
68
|
+
for (const raw of config.split('\n')) {
|
|
69
|
+
const line = raw.trim();
|
|
70
|
+
if (!line || line.startsWith('#')) continue;
|
|
71
|
+
if (arrayDepth > 0) {
|
|
72
|
+
arrayDepth = arrayDepthAfterLine(line, arrayDepth);
|
|
73
|
+
if (arrayDepth === null) return null;
|
|
74
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (line.startsWith('[')) {
|
|
78
|
+
const arrayTable = line.startsWith('[[');
|
|
79
|
+
const header = parseConfigKeyPath(line.slice(arrayTable ? 2 : 1));
|
|
80
|
+
const closing = arrayTable ? /^\]\]\s*(?:#.*)?$/ : /^\]\s*(?:#.*)?$/;
|
|
81
|
+
if (!header || !closing.test(header.rest)) return null;
|
|
82
|
+
table = header.segments;
|
|
83
|
+
if (isGrokSecurityPath(table)) lines.push(`${table.join('.')}\t${line}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = parseConfigKeyPath(line);
|
|
87
|
+
if (!key || !key.rest.startsWith('=')) return null;
|
|
88
|
+
arrayDepth = arrayDepthAfterLine(key.rest.slice(1), 0);
|
|
89
|
+
if (arrayDepth === null) return null;
|
|
90
|
+
securityValue = isGrokSecurityPath([...table, ...key.segments]);
|
|
91
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
92
|
+
}
|
|
93
|
+
return arrayDepth === 0 ? lines.join('\n') : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
22
96
|
export function grokSandboxProfileName(dispatchId) {
|
|
23
97
|
const prefix = typeof dispatchId === 'string' ? dispatchId.slice(0, 8) : '';
|
|
24
98
|
return /^[0-9a-f]{8}$/.test(prefix) ? 'arc-bridge-' + prefix : null;
|
|
@@ -14,13 +14,15 @@ function deepFreeze(value) {
|
|
|
14
14
|
return Object.freeze(value);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// Claude 2.1.
|
|
17
|
+
// Claude 2.1.327, 2026-11-20, T0 M-C10/M-C11/M-C12/FINAL
|
|
18
18
|
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
+
permissions: {deny: ['Edit(./.git/**)', 'Write(./.git/**)']},
|
|
19
20
|
sandbox: {
|
|
20
21
|
enabled: true,
|
|
21
22
|
autoAllowBashIfSandboxed: true,
|
|
22
23
|
allowUnsandboxedCommands: false,
|
|
23
24
|
failIfUnavailable: true,
|
|
25
|
+
filesystem: {denyWrite: ['./.git']},
|
|
24
26
|
},
|
|
25
27
|
});
|
|
26
28
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
@@ -7,9 +7,10 @@ import fsp from 'node:fs/promises';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import readline from 'node:readline';
|
|
9
9
|
import zlib from 'node:zlib';
|
|
10
|
-
import {execFile} from 'node:child_process';
|
|
10
|
+
import {execFile, spawnSync} from 'node:child_process';
|
|
11
11
|
import {promisify} from 'node:util';
|
|
12
12
|
import {DEFAULT_POLICY, CATALOG_MODEL_ALIASES} from './role-dispatch-policy.mjs';
|
|
13
|
+
import {observeCooperativeTarget} from './scope.mjs';
|
|
13
14
|
|
|
14
15
|
const execFileAsync = promisify(execFile);
|
|
15
16
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -253,6 +254,14 @@ const git = async (cwd, args, {allowFailure = false} = {}) => {
|
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
const sha256 = value => crypto.createHash('sha256').update(value).digest('hex');
|
|
257
|
+
|
|
258
|
+
/** Resolve the worktree root for a cwd that may be a subdirectory. */
|
|
259
|
+
export async function resolveWorktree(cwd) {
|
|
260
|
+
const result = spawnSync('git', ['--no-pager', 'rev-parse', '--show-toplevel'], {cwd, env: gitEnv(), encoding: 'utf8', timeout: 10000});
|
|
261
|
+
if (result.error || result.status !== 0 || !result.stdout.endsWith('\n')) throw Error('Worktree root unavailable');
|
|
262
|
+
return observeCooperativeTarget(result.stdout.slice(0, -1));
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
async function contentDigest(filename) {
|
|
257
266
|
let stat;
|
|
258
267
|
try { stat = await fsp.lstat(filename); } catch (error) { return error.code === 'ENOENT' ? sha256('deleted') : sha256('unreadable'); }
|
|
@@ -264,6 +273,204 @@ async function contentDigest(filename) {
|
|
|
264
273
|
});
|
|
265
274
|
}
|
|
266
275
|
|
|
276
|
+
const missingTree = error => error.code === 'ENOENT' || error.code === 'ENOTDIR';
|
|
277
|
+
const CONTROL_TREE_LIMIT = 1000;
|
|
278
|
+
const controlStat = filename => fsp.lstat(filename).catch(error => {
|
|
279
|
+
if (missingTree(error)) return null;
|
|
280
|
+
throw error;
|
|
281
|
+
});
|
|
282
|
+
const sameControlEntry = (stat, current) => current?.dev === stat.dev && current?.ino === stat.ino;
|
|
283
|
+
const entryIntact = async (filename, stat) => sameControlEntry(stat, await controlStat(filename));
|
|
284
|
+
const rootIntact = async () => true;
|
|
285
|
+
|
|
286
|
+
async function controlFileState(filename, {project, stat, parentIntact = rootIntact} = {}) {
|
|
287
|
+
let handle, bytes, digest;
|
|
288
|
+
let intact = parentIntact;
|
|
289
|
+
try {
|
|
290
|
+
if (!await parentIntact()) return 'changed';
|
|
291
|
+
stat ??= await controlStat(filename);
|
|
292
|
+
if (!stat) return sha256('deleted');
|
|
293
|
+
intact = async () => await parentIntact() && await entryIntact(filename, stat);
|
|
294
|
+
if (!await intact()) return 'changed';
|
|
295
|
+
if (stat.isSymbolicLink()) {
|
|
296
|
+
const target = await fsp.readlink(filename);
|
|
297
|
+
return await intact() ? `symlink:${target}` : 'changed';
|
|
298
|
+
}
|
|
299
|
+
if (!stat.isFile()) return sha256('directory');
|
|
300
|
+
|
|
301
|
+
// Refuse a replacement symlink and verify the opened file before reading bytes.
|
|
302
|
+
const {O_RDONLY, O_NOFOLLOW, O_NONBLOCK} = fs.constants;
|
|
303
|
+
handle = await fsp.open(filename, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
304
|
+
if (!sameControlEntry(stat, await handle.stat()) || !await intact()) return 'changed';
|
|
305
|
+
if (project) {
|
|
306
|
+
bytes = await handle.readFile();
|
|
307
|
+
} else {
|
|
308
|
+
const hash = crypto.createHash('sha256');
|
|
309
|
+
for await (const chunk of handle.createReadStream({autoClose: false})) hash.update(chunk);
|
|
310
|
+
digest = hash.digest('hex');
|
|
311
|
+
}
|
|
312
|
+
if (!await intact()) return 'changed';
|
|
313
|
+
} catch {
|
|
314
|
+
return await intact().catch(() => true) ? sha256('unreadable') : 'changed';
|
|
315
|
+
} finally {
|
|
316
|
+
if (handle) await handle.close();
|
|
317
|
+
}
|
|
318
|
+
const projection = project ? project(bytes) : null;
|
|
319
|
+
return projection === null ? `${digest ?? sha256(bytes)}:${stat.dev}:${stat.ino}` : sha256('projection:' + projection);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function snapshotControlTree(root, label) {
|
|
323
|
+
const entries = new Map();
|
|
324
|
+
const walk = async (dir, prefix, stat, parentIntact) => {
|
|
325
|
+
const intact = async () => await parentIntact() && await entryIntact(dir, stat);
|
|
326
|
+
const markChanged = () => {
|
|
327
|
+
for (const entry of entries.keys()) if (entry.startsWith(prefix + '/')) entries.delete(entry);
|
|
328
|
+
entries.set(prefix, 'changed');
|
|
329
|
+
};
|
|
330
|
+
if (!await intact()) return markChanged();
|
|
331
|
+
let names;
|
|
332
|
+
try { names = await fsp.readdir(dir); } catch (error) {
|
|
333
|
+
if (missingTree(error)) return markChanged();
|
|
334
|
+
const stillIntact = prefix === label ? await intact() : await intact().catch(() => true);
|
|
335
|
+
if (!stillIntact) return markChanged();
|
|
336
|
+
if (prefix !== label) {
|
|
337
|
+
entries.set(prefix + '/', 'unreadable');
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
if (!await intact()) return markChanged();
|
|
343
|
+
for (const name of names) {
|
|
344
|
+
if (name.endsWith('.lock')) continue;
|
|
345
|
+
if (!await intact()) return markChanged();
|
|
346
|
+
const filename = path.join(dir, name), entry = `${prefix}/${name}`;
|
|
347
|
+
let state;
|
|
348
|
+
try { state = await controlStat(filename); } catch {
|
|
349
|
+
entries.set(entry, sha256('unreadable'));
|
|
350
|
+
}
|
|
351
|
+
if (state?.isDirectory()) {
|
|
352
|
+
entries.set(entry + '/', `directory:${state.dev}:${state.ino}`);
|
|
353
|
+
if (entries.size <= CONTROL_TREE_LIMIT) await walk(filename, entry, state, intact);
|
|
354
|
+
} else if (state) {
|
|
355
|
+
entries.set(entry, await controlFileState(filename, {stat: state, parentIntact: intact}));
|
|
356
|
+
}
|
|
357
|
+
if (entries.size > CONTROL_TREE_LIMIT) break;
|
|
358
|
+
}
|
|
359
|
+
if (!await intact()) markChanged();
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const stat = await controlStat(root);
|
|
363
|
+
if (!stat) return entries;
|
|
364
|
+
if (!stat.isDirectory()) return new Map([[label, await controlFileState(root, {stat})]]);
|
|
365
|
+
await walk(root, label, stat, rootIntact);
|
|
366
|
+
return entries.size > CONTROL_TREE_LIMIT ? new Map([[label, 'overflow']]) : entries;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function snapshotWorktreeControlDirectory(worktree, name, files, entries) {
|
|
370
|
+
const dir = path.join(worktree, name), label = `worktree:${name}/`;
|
|
371
|
+
let stat;
|
|
372
|
+
try { stat = await controlStat(dir); } catch {
|
|
373
|
+
entries.set(label, sha256('unreadable'));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (stat && !stat.isDirectory()) {
|
|
377
|
+
entries.set(label, await controlFileState(dir, {stat}));
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const intact = async () => stat ? await entryIntact(dir, stat) : (await controlStat(dir)) === null;
|
|
381
|
+
const states = [];
|
|
382
|
+
for (const file of files) {
|
|
383
|
+
states.push(stat ? await controlFileState(path.join(dir, file), {parentIntact: intact}) : sha256('deleted'));
|
|
384
|
+
}
|
|
385
|
+
if (!await intact()) entries.set(label, 'changed');
|
|
386
|
+
else files.forEach((file, i) => entries.set(label + file, states[i]));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function extraControlFileState({path: filename, project}) {
|
|
390
|
+
const parent = path.dirname(filename);
|
|
391
|
+
const stat = await controlStat(parent).catch(() => undefined);
|
|
392
|
+
if (stat === undefined) return sha256('unreadable');
|
|
393
|
+
if (!stat) return sha256('deleted');
|
|
394
|
+
|
|
395
|
+
const parentIntact = () => entryIntact(parent, stat).catch(() => false);
|
|
396
|
+
if (stat.isSymbolicLink()) {
|
|
397
|
+
const target = await fsp.readlink(parent).catch(() => null);
|
|
398
|
+
if (!await parentIntact()) return 'parent-changed';
|
|
399
|
+
return target === null ? sha256('unreadable') : `parent-symlink:${target}`;
|
|
400
|
+
}
|
|
401
|
+
if (!stat.isDirectory()) return 'parent-not-directory';
|
|
402
|
+
const state = await controlFileState(filename, {project, parentIntact});
|
|
403
|
+
return await parentIntact() ? state : 'parent-changed';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const CLAUDE_SAFE_ALLOW_TOOLS = new Set(['bash', 'read', 'grep', 'glob', 'webfetch', 'websearch']);
|
|
407
|
+
|
|
408
|
+
function claudeSettingsScopeReason(bytes) {
|
|
409
|
+
let settings;
|
|
410
|
+
try { settings = JSON.parse(bytes.toString('utf8')); } catch { return 'invalid JSON'; }
|
|
411
|
+
if (!isObject(settings)) return null;
|
|
412
|
+
if (Object.hasOwn(settings, 'hooks')) return 'hooks';
|
|
413
|
+
if (Object.hasOwn(settings, 'sandbox')) return 'sandbox';
|
|
414
|
+
const {permissions} = settings;
|
|
415
|
+
if (!isObject(permissions)) return null;
|
|
416
|
+
if (permissions.additionalDirectories?.length > 0) return 'permissions.additionalDirectories';
|
|
417
|
+
if (Object.hasOwn(permissions, 'allow')) {
|
|
418
|
+
const {allow} = permissions;
|
|
419
|
+
if (!Array.isArray(allow) || allow.some(rule =>
|
|
420
|
+
typeof rule !== 'string' || !CLAUDE_SAFE_ALLOW_TOOLS.has(rule.split('(', 1)[0].trim().toLowerCase())
|
|
421
|
+
)) return 'permissions.allow';
|
|
422
|
+
}
|
|
423
|
+
if (Object.hasOwn(permissions, 'defaultMode')) return 'permissions.defaultMode';
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Check Claude project and local settings before starting a writing bridge. */
|
|
428
|
+
export async function claudeProjectSettingsWidenScope(worktree) {
|
|
429
|
+
for (const label of ['.claude/settings.json', '.claude/settings.local.json']) {
|
|
430
|
+
let scopeReason;
|
|
431
|
+
const state = await extraControlFileState({path: path.join(worktree, label), project: bytes => {
|
|
432
|
+
scopeReason = claudeSettingsScopeReason(bytes);
|
|
433
|
+
return 'claude-settings-read';
|
|
434
|
+
}}).catch(() => 'unreadable');
|
|
435
|
+
if (state === sha256('deleted')) continue;
|
|
436
|
+
if (state === sha256('projection:claude-settings-read')) {
|
|
437
|
+
if (scopeReason) return `${label}: ${scopeReason}`;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (state === sha256('directory') || state.startsWith('symlink:')) return `${label}: not a regular file`;
|
|
441
|
+
return `${label}: settings path could not be verified`;
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Snapshot of selected Git, worktree and optional platform control files. */
|
|
447
|
+
export async function snapshotControlFiles({gitCommonDir, gitDir, worktree, extra = []}) {
|
|
448
|
+
if (![gitCommonDir, gitDir, worktree].every(dir => typeof dir === 'string' && path.isAbsolute(dir))) {
|
|
449
|
+
throw Error('Control snapshot requires absolute Git and worktree paths');
|
|
450
|
+
}
|
|
451
|
+
if (!(await fsp.lstat(gitCommonDir)).isDirectory()) throw Error('Git common directory is not a directory');
|
|
452
|
+
const files = [
|
|
453
|
+
{label: 'git:config', path: path.join(gitCommonDir, 'config')},
|
|
454
|
+
{label: 'git:config.worktree', path: path.join(gitDir, 'config.worktree')},
|
|
455
|
+
];
|
|
456
|
+
const entries = new Map();
|
|
457
|
+
for (const file of files) entries.set(file.label, await controlFileState(file.path));
|
|
458
|
+
await snapshotWorktreeControlDirectory(worktree, '.claude', ['settings.json', 'settings.local.json'], entries);
|
|
459
|
+
await snapshotWorktreeControlDirectory(worktree, '.codex', ['config.toml'], entries);
|
|
460
|
+
for (const file of extra) entries.set(file.label, await extraControlFileState(file));
|
|
461
|
+
for (const tree of ['hooks', 'info']) {
|
|
462
|
+
for (const [label, state] of await snapshotControlTree(path.join(gitCommonDir, tree), `git:${tree}`)) entries.set(label, state);
|
|
463
|
+
}
|
|
464
|
+
return entries;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export function allowedPathsCoverControl(allowedPaths) {
|
|
468
|
+
return allowedPaths.some(entry => {
|
|
469
|
+
const normalized = path.posix.normalize(entry).replace(/\/$/, '').toLowerCase();
|
|
470
|
+
return normalized.startsWith('.git/') || ['.', '.git', '.claude', '.claude/settings.json', '.claude/settings.local.json', '.codex', '.codex/config.toml'].includes(normalized);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
267
474
|
/** Snapshot of HEAD, branch, every ref (name and object) and every changed or untracked path; paths are relative to the worktree root even when worktree is a subdirectory. */
|
|
268
475
|
export async function snapshotWorktree(worktree) {
|
|
269
476
|
const root = (await git(worktree, ['rev-parse', '--show-toplevel'])).trim();
|
|
@@ -287,7 +494,7 @@ export async function snapshotWorktree(worktree) {
|
|
|
287
494
|
}
|
|
288
495
|
|
|
289
496
|
const allowedBy = (allowedPaths, file) => allowedPaths.some(entry => entry.endsWith('/') ? file.startsWith(entry) : file === entry);
|
|
290
|
-
/** Implementer and QA may change only allowedPaths (QA: none when empty or missing); read-only roles may change nothing; any HEAD, branch or ref change (created, deleted or moved) is a violation. Git-ignored paths are
|
|
497
|
+
/** Implementer and QA may change only allowedPaths (QA: none when empty or missing); read-only roles may change nothing; any HEAD, branch or ref change (created, deleted or moved) is a violation. Ordinary worktree snapshots omit Git-ignored paths; control files are compared regardless of allowedPaths and role. */
|
|
291
498
|
export function detectViolations({role, allowedPaths, before, after}) {
|
|
292
499
|
const headChanged = before.head !== after.head || before.branch !== after.branch;
|
|
293
500
|
const refsBefore = before.refs ?? {}, refsAfter = after.refs ?? {};
|
|
@@ -296,5 +503,8 @@ export function detectViolations({role, allowedPaths, before, after}) {
|
|
|
296
503
|
const changed = new Set();
|
|
297
504
|
for (const file of new Set([...before.entries.keys(), ...after.entries.keys()])) if (before.entries.get(file) !== after.entries.get(file)) changed.add(file);
|
|
298
505
|
const changedPaths = [...changed].filter(file => !allowedBy(allowed, file)).sort();
|
|
299
|
-
|
|
506
|
+
const controlBefore = before.control ?? new Map(), controlAfter = after.control ?? new Map();
|
|
507
|
+
const controlChanged = [...new Set([...controlBefore.keys(), ...controlAfter.keys()])]
|
|
508
|
+
.filter(label => controlBefore.get(label) !== controlAfter.get(label)).sort();
|
|
509
|
+
return {reason: headChanged || refsChanged || changedPaths.length || controlChanged.length ? 'permission_violation_observed' : null, changedPaths, headChanged, refsChanged, controlChanged};
|
|
300
510
|
}
|
|
@@ -9,6 +9,7 @@ import {resolveConfigHome, resolveLocalCli, probePlatformAuth, probeCodexAuthSta
|
|
|
9
9
|
import {ROUTING_ROLES, parseRoleRoutingConfig} from './role-routing-config.mjs';
|
|
10
10
|
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, revisionTag, hostGateReasons, bridgeGateReasons, environmentReasons, initialClaims, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
11
11
|
import {NON_TERMINAL_STATES, createLease, listLeases, pruneTerminalLeases, readHostLimits} from './role-dispatch-store.mjs';
|
|
12
|
+
import {allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
12
13
|
|
|
13
14
|
const exact=(value,keys)=>value&&typeof value==='object'&&!Array.isArray(value)&&Object.keys(value).length===keys.length&&keys.every(key=>Object.hasOwn(value,key));
|
|
14
15
|
const hash=bytes=>'sha256:'+crypto.createHash('sha256').update(bytes).digest('hex');
|
|
@@ -239,6 +240,11 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
239
240
|
let config;try{config=await readActivation(homes,expectedRevision,{anchorHome,host,runtimePlatforms});}catch{result.reasons=[reason('activation_unverified')];return;}
|
|
240
241
|
const requested=config.roles[role],route=requested.platform===host?'native':'bridge';
|
|
241
242
|
result.requested={...requested};result.route=route;result.profileName=profileName(requested.platform,role,{runtimePlatforms});
|
|
243
|
+
if(route==='bridge'&&allowedPathsCoverControl(assignment.allowedPaths??[])){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
244
|
+
if(route==='bridge'&&requested.platform==='claude'&&(role==='arc_implementer'||role==='arc_qa')){
|
|
245
|
+
const target=typeof context.cwd==='string'?await resolveWorktree(context.cwd).catch(()=>null):null;
|
|
246
|
+
if(!target||await claudeProjectSettingsWidenScope(target.realpath)){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
247
|
+
}
|
|
242
248
|
const capabilities=capabilityReasons({hostPlatform:host,targetPlatform:requested.platform,route,runtimePlatforms});
|
|
243
249
|
if(capabilities.length){result.reasons=capabilities.map(reason);return;}
|
|
244
250
|
await pruneTerminalLeases(anchorHome,{now,retentionMs:policy.leaseRetentionMs,runtimePlatforms});
|
|
@@ -7,15 +7,14 @@ import crypto from 'node:crypto';
|
|
|
7
7
|
import {spawn, spawnSync} from 'node:child_process';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {GROK_CONTRACT, normalizeGrokStreamEvent, evaluateGrokObservation} from './grok-stream.mjs';
|
|
10
|
-
import {GROK_SANDBOX_RELATIVE, grokSandboxProfileName, renderGrokSandboxProfile, grokProfileCovered, inspectGrokProfileSlot, checkGrokHome, createGrokSandboxProfile, verifyGrokSandboxProfile, removeGrokSandboxProfile, grokEventsBaseline, readGrokProfileApplied} from './grok-sandbox.mjs';
|
|
10
|
+
import {GROK_SANDBOX_RELATIVE, grokSandboxProfileName, renderGrokSandboxProfile, grokProfileCovered, inspectGrokProfileSlot, checkGrokHome, createGrokSandboxProfile, verifyGrokSandboxProfile, removeGrokSandboxProfile, grokEventsBaseline, readGrokProfileApplied, grokConfigSecurityProjection} from './grok-sandbox.mjs';
|
|
11
11
|
import {GEMINI_CONTRACT, normalizeGeminiStreamEvent, evaluateGeminiObservation} from './gemini-stream.mjs';
|
|
12
12
|
import {DEFAULT_POLICY, reason, bridgeGateReasons} from './role-dispatch-policy.mjs';
|
|
13
13
|
import {readLease, writeLease, writeHeartbeat, cancelRequested, TERMINAL_STATES} from './role-dispatch-store.mjs';
|
|
14
14
|
import {withRoutingLock, readActivation, resolveRuntimeHomes} from './role-routing.mjs';
|
|
15
|
-
import {observeCooperativeTarget} from './scope.mjs';
|
|
16
15
|
import {resolveLocalCli, localCliEnvironment} from './local-cli.mjs';
|
|
17
16
|
import {parseCompositeProfile, buildBridgeArgs, argsDigest, ROLE_BRIDGE_PERMISSIONS} from './role-bridge-args.mjs';
|
|
18
|
-
import {createLineParser, normalizeClaudeStreamEvent, normalizeCodexStreamEvent, eventRecord, evaluateClaudeInit, evaluateCodexContext, readClaudeTranscriptEffort, readCodexTurnContext, classifyFailure, snapshotWorktree, detectViolations} from './role-observe.mjs';
|
|
17
|
+
import {createLineParser, normalizeClaudeStreamEvent, normalizeCodexStreamEvent, eventRecord, evaluateClaudeInit, evaluateCodexContext, readClaudeTranscriptEffort, readCodexTurnContext, classifyFailure, snapshotWorktree, snapshotControlFiles, detectViolations, allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
19
18
|
import {getPlatform, routingProfileFile} from './platform-registry.mjs';
|
|
20
19
|
|
|
21
20
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -90,13 +89,7 @@ export function processAlive({pid, startTime} = {}) {
|
|
|
90
89
|
return current !== null && current === startTime;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
export async function resolveWorktree(cwd) {
|
|
95
|
-
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith('GIT_')));
|
|
96
|
-
const result = spawnSync('git', ['--no-pager', 'rev-parse', '--show-toplevel'], {cwd, env: {...env, GIT_CONFIG_NOSYSTEM: '1', GIT_OPTIONAL_LOCKS: '0'}, encoding: 'utf8', timeout: 10000});
|
|
97
|
-
if (result.error || result.status !== 0 || !result.stdout.endsWith('\n')) throw Error('Worktree root unavailable');
|
|
98
|
-
return observeCooperativeTarget(result.stdout.slice(0, -1));
|
|
99
|
-
}
|
|
92
|
+
export {resolveWorktree};
|
|
100
93
|
export const artifactDirectory = (target, workflowId, dispatchId) => path.join(target.gitCommonDir, 'arc', 'workflows', workflowId, 'dispatches', dispatchId);
|
|
101
94
|
/** Segment 0 (the first run) keeps its files in the dispatch directory; resumed segments use segments/<n>/. */
|
|
102
95
|
export const segmentDirectory = (target, workflowId, dispatchId, segment) => segment > 0 ? path.join(artifactDirectory(target, workflowId, dispatchId), 'segments', String(segment)) : artifactDirectory(target, workflowId, dispatchId);
|
|
@@ -119,6 +112,11 @@ export async function buildBridgeInvocation({lease, config, homes, worktree, res
|
|
|
119
112
|
if ((platform === 'gemini' || platform === 'grok') && lease.segment > 0 && !['on', 'verified'].includes(implementation?.resume)) throw fail('resume_unverified', platform === 'grok' ? 'Grok resume is not verified' : 'Gemini resume is not verified');
|
|
120
113
|
if (!implementation) throw fail('permission_scope_unverified', 'Invalid composite profile: unknown platform');
|
|
121
114
|
const permissions = ROLE_BRIDGE_PERMISSIONS[platform][lease.role];
|
|
115
|
+
if (Array.isArray(lease.allowedPaths) && allowedPathsCoverControl(lease.allowedPaths)) throw fail('permission_scope_unverified', 'allowedPaths cover a control file');
|
|
116
|
+
if (platform === 'claude' && permissions.sandbox) {
|
|
117
|
+
const scopeReason = await claudeProjectSettingsWidenScope(worktree);
|
|
118
|
+
if (scopeReason) throw fail('permission_scope_unverified', scopeReason);
|
|
119
|
+
}
|
|
122
120
|
let grokSandbox;
|
|
123
121
|
if (platform === 'grok' && permissions.sandbox === 'custom') {
|
|
124
122
|
const name = grokSandboxProfileName(lease.dispatchId);
|
|
@@ -273,8 +271,16 @@ export async function runSupervisor(options) {
|
|
|
273
271
|
const {path, sha256, dirCreated} = createdGrokProfile;
|
|
274
272
|
grokSandboxProfile = {name: invocation.grokSandbox.name, path, sha256, dirCreated, created: true, removed: null, dirRemoved: false, eventsBaseline: null, applied: null};
|
|
275
273
|
}
|
|
274
|
+
const extra = invocation.grokSandbox ? [
|
|
275
|
+
{label: 'grok-home:config.toml', path: path.join(homes.grok, 'config.toml'), project: grokConfigSecurityProjection},
|
|
276
|
+
{label: 'grok-home:sandbox.toml', path: path.join(homes.grok, 'sandbox.toml')},
|
|
277
|
+
] : [];
|
|
278
|
+
const snapshot = async () => ({
|
|
279
|
+
...await snapshotWorktree(target.realpath),
|
|
280
|
+
control: await snapshotControlFiles({gitCommonDir: target.gitCommonDir, gitDir: target.gitDir, worktree: target.realpath, extra}),
|
|
281
|
+
});
|
|
276
282
|
let before;
|
|
277
|
-
try { before = await
|
|
283
|
+
try { before = await snapshot(); } catch { return await failWithProfileCleanup('execution_failed'); }
|
|
278
284
|
|
|
279
285
|
if (invocation.promptFile) {
|
|
280
286
|
let promptFd;
|
|
@@ -444,8 +450,8 @@ export async function runSupervisor(options) {
|
|
|
444
450
|
}
|
|
445
451
|
|
|
446
452
|
let after = null;
|
|
447
|
-
try { after = await
|
|
448
|
-
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false};
|
|
453
|
+
try { after = await snapshot(); } catch { after = null; }
|
|
454
|
+
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false, controlChanged: []};
|
|
449
455
|
const codes = [];
|
|
450
456
|
if (state.mismatch) codes.push(state.mismatch);
|
|
451
457
|
if (state.internal) codes.push(state.internal);
|
|
@@ -495,7 +501,8 @@ export async function runSupervisor(options) {
|
|
|
495
501
|
}
|
|
496
502
|
if (exit.spawnError && !codes.length) { codes.push('execution_failed'); finalState = 'failed'; }
|
|
497
503
|
if ((finalState === 'completed' || finalState === 'cancelled') && codes.includes('permission_scope_mismatch')) finalState = 'failed';
|
|
498
|
-
|
|
504
|
+
const controlFiles = violations.controlChanged.length ? {controlFiles: {changed: violations.controlChanged}} : {};
|
|
505
|
+
await writeRecord({state: finalState, reasons: [...new Set(codes)], exit: {code: exit.code, signal: exit.signal}, terminatedBy: terminating, eventsTruncated, ignoredLines: parser.ignored, lineOverflow: parser.overflow, violations: {changedPaths: violations.changedPaths, headChanged: violations.headChanged, refsChanged: violations.refsChanged}, ...controlFiles, ...(orphanGroupReaped ? {orphanGroupReaped: true} : {}), argsDigest: invocation.argsDigest, resultPath, ...grokProfileRecord(), ...(platform === 'gemini' ? {unverifiedContracts: {delegation: GEMINI_CONTRACT.delegation}} : platform === 'grok' ? {unverifiedContracts: {delegation: GROK_CONTRACT.delegation}} : {})});
|
|
499
506
|
await commit(finalState, codes, claims, {sessionId, resultPath});
|
|
500
507
|
} catch {
|
|
501
508
|
// Unexpected failure after the child started: stop it, then record a failed state if the child is gone.
|
package/package.json
CHANGED
|
@@ -19,6 +19,80 @@ const sameEntry = (first, second) => first.dev === second.dev && first.ino === s
|
|
|
19
19
|
const identityOf = ({dev, ino}) => ({dev, ino});
|
|
20
20
|
const sandboxEventsPath = grokHome => path.join(grokHome, 'sessions', 'sandbox-events.jsonl');
|
|
21
21
|
|
|
22
|
+
function parseConfigKeyPath(source) {
|
|
23
|
+
const segment = /\s*(?:"([^"\\]*)"|'([^'\\]*)'|([\w-]+))\s*/y;
|
|
24
|
+
const segments = [];
|
|
25
|
+
for (;;) {
|
|
26
|
+
const match = segment.exec(source);
|
|
27
|
+
if (!match) return null;
|
|
28
|
+
segments.push(match[1] ?? match[2] ?? match[3]);
|
|
29
|
+
if (source[segment.lastIndex] !== '.') return {segments, rest: source.slice(segment.lastIndex)};
|
|
30
|
+
segment.lastIndex += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isGrokSecurityPath(segments) {
|
|
35
|
+
return segments.includes('permission_mode') || (segments[0] === 'compat' && segments[1] === 'claude')
|
|
36
|
+
|| /^sandbox[\w-]*$/.test(segments[0]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function arrayDepthAfterLine(value, depth) {
|
|
40
|
+
let quote = null;
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
const char = value[i];
|
|
43
|
+
if (quote) {
|
|
44
|
+
if (quote === '"' && char === '\\') i += 1;
|
|
45
|
+
else if (char === quote) quote = null;
|
|
46
|
+
} else if (char === '"' || char === "'") {
|
|
47
|
+
quote = char;
|
|
48
|
+
} else if (char === '#') {
|
|
49
|
+
break;
|
|
50
|
+
} else if (char === '[') {
|
|
51
|
+
depth += 1;
|
|
52
|
+
} else if (char === ']') {
|
|
53
|
+
depth -= 1;
|
|
54
|
+
if (depth < 0) return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return quote ? null : depth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function grokConfigSecurityProjection(bytes) {
|
|
61
|
+
let config;
|
|
62
|
+
try { config = new TextDecoder('utf-8', {fatal: true}).decode(bytes); } catch { return null; }
|
|
63
|
+
if (config.includes('"""') || config.includes("'''")) return null;
|
|
64
|
+
|
|
65
|
+
const lines = [];
|
|
66
|
+
let table = [];
|
|
67
|
+
let arrayDepth = 0, securityValue = false;
|
|
68
|
+
for (const raw of config.split('\n')) {
|
|
69
|
+
const line = raw.trim();
|
|
70
|
+
if (!line || line.startsWith('#')) continue;
|
|
71
|
+
if (arrayDepth > 0) {
|
|
72
|
+
arrayDepth = arrayDepthAfterLine(line, arrayDepth);
|
|
73
|
+
if (arrayDepth === null) return null;
|
|
74
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (line.startsWith('[')) {
|
|
78
|
+
const arrayTable = line.startsWith('[[');
|
|
79
|
+
const header = parseConfigKeyPath(line.slice(arrayTable ? 2 : 1));
|
|
80
|
+
const closing = arrayTable ? /^\]\]\s*(?:#.*)?$/ : /^\]\s*(?:#.*)?$/;
|
|
81
|
+
if (!header || !closing.test(header.rest)) return null;
|
|
82
|
+
table = header.segments;
|
|
83
|
+
if (isGrokSecurityPath(table)) lines.push(`${table.join('.')}\t${line}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = parseConfigKeyPath(line);
|
|
87
|
+
if (!key || !key.rest.startsWith('=')) return null;
|
|
88
|
+
arrayDepth = arrayDepthAfterLine(key.rest.slice(1), 0);
|
|
89
|
+
if (arrayDepth === null) return null;
|
|
90
|
+
securityValue = isGrokSecurityPath([...table, ...key.segments]);
|
|
91
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
92
|
+
}
|
|
93
|
+
return arrayDepth === 0 ? lines.join('\n') : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
22
96
|
export function grokSandboxProfileName(dispatchId) {
|
|
23
97
|
const prefix = typeof dispatchId === 'string' ? dispatchId.slice(0, 8) : '';
|
|
24
98
|
return /^[0-9a-f]{8}$/.test(prefix) ? 'arc-bridge-' + prefix : null;
|
|
@@ -14,13 +14,15 @@ function deepFreeze(value) {
|
|
|
14
14
|
return Object.freeze(value);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// Claude 2.1.
|
|
17
|
+
// Claude 2.1.327, 2026-11-20, T0 M-C10/M-C11/M-C12/FINAL
|
|
18
18
|
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
+
permissions: {deny: ['Edit(./.git/**)', 'Write(./.git/**)']},
|
|
19
20
|
sandbox: {
|
|
20
21
|
enabled: true,
|
|
21
22
|
autoAllowBashIfSandboxed: true,
|
|
22
23
|
allowUnsandboxedCommands: false,
|
|
23
24
|
failIfUnavailable: true,
|
|
25
|
+
filesystem: {denyWrite: ['./.git']},
|
|
24
26
|
},
|
|
25
27
|
});
|
|
26
28
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
@@ -7,9 +7,10 @@ import fsp from 'node:fs/promises';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import readline from 'node:readline';
|
|
9
9
|
import zlib from 'node:zlib';
|
|
10
|
-
import {execFile} from 'node:child_process';
|
|
10
|
+
import {execFile, spawnSync} from 'node:child_process';
|
|
11
11
|
import {promisify} from 'node:util';
|
|
12
12
|
import {DEFAULT_POLICY, CATALOG_MODEL_ALIASES} from './role-dispatch-policy.mjs';
|
|
13
|
+
import {observeCooperativeTarget} from './scope.mjs';
|
|
13
14
|
|
|
14
15
|
const execFileAsync = promisify(execFile);
|
|
15
16
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -253,6 +254,14 @@ const git = async (cwd, args, {allowFailure = false} = {}) => {
|
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
const sha256 = value => crypto.createHash('sha256').update(value).digest('hex');
|
|
257
|
+
|
|
258
|
+
/** Resolve the worktree root for a cwd that may be a subdirectory. */
|
|
259
|
+
export async function resolveWorktree(cwd) {
|
|
260
|
+
const result = spawnSync('git', ['--no-pager', 'rev-parse', '--show-toplevel'], {cwd, env: gitEnv(), encoding: 'utf8', timeout: 10000});
|
|
261
|
+
if (result.error || result.status !== 0 || !result.stdout.endsWith('\n')) throw Error('Worktree root unavailable');
|
|
262
|
+
return observeCooperativeTarget(result.stdout.slice(0, -1));
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
async function contentDigest(filename) {
|
|
257
266
|
let stat;
|
|
258
267
|
try { stat = await fsp.lstat(filename); } catch (error) { return error.code === 'ENOENT' ? sha256('deleted') : sha256('unreadable'); }
|
|
@@ -264,6 +273,204 @@ async function contentDigest(filename) {
|
|
|
264
273
|
});
|
|
265
274
|
}
|
|
266
275
|
|
|
276
|
+
const missingTree = error => error.code === 'ENOENT' || error.code === 'ENOTDIR';
|
|
277
|
+
const CONTROL_TREE_LIMIT = 1000;
|
|
278
|
+
const controlStat = filename => fsp.lstat(filename).catch(error => {
|
|
279
|
+
if (missingTree(error)) return null;
|
|
280
|
+
throw error;
|
|
281
|
+
});
|
|
282
|
+
const sameControlEntry = (stat, current) => current?.dev === stat.dev && current?.ino === stat.ino;
|
|
283
|
+
const entryIntact = async (filename, stat) => sameControlEntry(stat, await controlStat(filename));
|
|
284
|
+
const rootIntact = async () => true;
|
|
285
|
+
|
|
286
|
+
async function controlFileState(filename, {project, stat, parentIntact = rootIntact} = {}) {
|
|
287
|
+
let handle, bytes, digest;
|
|
288
|
+
let intact = parentIntact;
|
|
289
|
+
try {
|
|
290
|
+
if (!await parentIntact()) return 'changed';
|
|
291
|
+
stat ??= await controlStat(filename);
|
|
292
|
+
if (!stat) return sha256('deleted');
|
|
293
|
+
intact = async () => await parentIntact() && await entryIntact(filename, stat);
|
|
294
|
+
if (!await intact()) return 'changed';
|
|
295
|
+
if (stat.isSymbolicLink()) {
|
|
296
|
+
const target = await fsp.readlink(filename);
|
|
297
|
+
return await intact() ? `symlink:${target}` : 'changed';
|
|
298
|
+
}
|
|
299
|
+
if (!stat.isFile()) return sha256('directory');
|
|
300
|
+
|
|
301
|
+
// Refuse a replacement symlink and verify the opened file before reading bytes.
|
|
302
|
+
const {O_RDONLY, O_NOFOLLOW, O_NONBLOCK} = fs.constants;
|
|
303
|
+
handle = await fsp.open(filename, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
304
|
+
if (!sameControlEntry(stat, await handle.stat()) || !await intact()) return 'changed';
|
|
305
|
+
if (project) {
|
|
306
|
+
bytes = await handle.readFile();
|
|
307
|
+
} else {
|
|
308
|
+
const hash = crypto.createHash('sha256');
|
|
309
|
+
for await (const chunk of handle.createReadStream({autoClose: false})) hash.update(chunk);
|
|
310
|
+
digest = hash.digest('hex');
|
|
311
|
+
}
|
|
312
|
+
if (!await intact()) return 'changed';
|
|
313
|
+
} catch {
|
|
314
|
+
return await intact().catch(() => true) ? sha256('unreadable') : 'changed';
|
|
315
|
+
} finally {
|
|
316
|
+
if (handle) await handle.close();
|
|
317
|
+
}
|
|
318
|
+
const projection = project ? project(bytes) : null;
|
|
319
|
+
return projection === null ? `${digest ?? sha256(bytes)}:${stat.dev}:${stat.ino}` : sha256('projection:' + projection);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function snapshotControlTree(root, label) {
|
|
323
|
+
const entries = new Map();
|
|
324
|
+
const walk = async (dir, prefix, stat, parentIntact) => {
|
|
325
|
+
const intact = async () => await parentIntact() && await entryIntact(dir, stat);
|
|
326
|
+
const markChanged = () => {
|
|
327
|
+
for (const entry of entries.keys()) if (entry.startsWith(prefix + '/')) entries.delete(entry);
|
|
328
|
+
entries.set(prefix, 'changed');
|
|
329
|
+
};
|
|
330
|
+
if (!await intact()) return markChanged();
|
|
331
|
+
let names;
|
|
332
|
+
try { names = await fsp.readdir(dir); } catch (error) {
|
|
333
|
+
if (missingTree(error)) return markChanged();
|
|
334
|
+
const stillIntact = prefix === label ? await intact() : await intact().catch(() => true);
|
|
335
|
+
if (!stillIntact) return markChanged();
|
|
336
|
+
if (prefix !== label) {
|
|
337
|
+
entries.set(prefix + '/', 'unreadable');
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
if (!await intact()) return markChanged();
|
|
343
|
+
for (const name of names) {
|
|
344
|
+
if (name.endsWith('.lock')) continue;
|
|
345
|
+
if (!await intact()) return markChanged();
|
|
346
|
+
const filename = path.join(dir, name), entry = `${prefix}/${name}`;
|
|
347
|
+
let state;
|
|
348
|
+
try { state = await controlStat(filename); } catch {
|
|
349
|
+
entries.set(entry, sha256('unreadable'));
|
|
350
|
+
}
|
|
351
|
+
if (state?.isDirectory()) {
|
|
352
|
+
entries.set(entry + '/', `directory:${state.dev}:${state.ino}`);
|
|
353
|
+
if (entries.size <= CONTROL_TREE_LIMIT) await walk(filename, entry, state, intact);
|
|
354
|
+
} else if (state) {
|
|
355
|
+
entries.set(entry, await controlFileState(filename, {stat: state, parentIntact: intact}));
|
|
356
|
+
}
|
|
357
|
+
if (entries.size > CONTROL_TREE_LIMIT) break;
|
|
358
|
+
}
|
|
359
|
+
if (!await intact()) markChanged();
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const stat = await controlStat(root);
|
|
363
|
+
if (!stat) return entries;
|
|
364
|
+
if (!stat.isDirectory()) return new Map([[label, await controlFileState(root, {stat})]]);
|
|
365
|
+
await walk(root, label, stat, rootIntact);
|
|
366
|
+
return entries.size > CONTROL_TREE_LIMIT ? new Map([[label, 'overflow']]) : entries;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function snapshotWorktreeControlDirectory(worktree, name, files, entries) {
|
|
370
|
+
const dir = path.join(worktree, name), label = `worktree:${name}/`;
|
|
371
|
+
let stat;
|
|
372
|
+
try { stat = await controlStat(dir); } catch {
|
|
373
|
+
entries.set(label, sha256('unreadable'));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (stat && !stat.isDirectory()) {
|
|
377
|
+
entries.set(label, await controlFileState(dir, {stat}));
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const intact = async () => stat ? await entryIntact(dir, stat) : (await controlStat(dir)) === null;
|
|
381
|
+
const states = [];
|
|
382
|
+
for (const file of files) {
|
|
383
|
+
states.push(stat ? await controlFileState(path.join(dir, file), {parentIntact: intact}) : sha256('deleted'));
|
|
384
|
+
}
|
|
385
|
+
if (!await intact()) entries.set(label, 'changed');
|
|
386
|
+
else files.forEach((file, i) => entries.set(label + file, states[i]));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function extraControlFileState({path: filename, project}) {
|
|
390
|
+
const parent = path.dirname(filename);
|
|
391
|
+
const stat = await controlStat(parent).catch(() => undefined);
|
|
392
|
+
if (stat === undefined) return sha256('unreadable');
|
|
393
|
+
if (!stat) return sha256('deleted');
|
|
394
|
+
|
|
395
|
+
const parentIntact = () => entryIntact(parent, stat).catch(() => false);
|
|
396
|
+
if (stat.isSymbolicLink()) {
|
|
397
|
+
const target = await fsp.readlink(parent).catch(() => null);
|
|
398
|
+
if (!await parentIntact()) return 'parent-changed';
|
|
399
|
+
return target === null ? sha256('unreadable') : `parent-symlink:${target}`;
|
|
400
|
+
}
|
|
401
|
+
if (!stat.isDirectory()) return 'parent-not-directory';
|
|
402
|
+
const state = await controlFileState(filename, {project, parentIntact});
|
|
403
|
+
return await parentIntact() ? state : 'parent-changed';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const CLAUDE_SAFE_ALLOW_TOOLS = new Set(['bash', 'read', 'grep', 'glob', 'webfetch', 'websearch']);
|
|
407
|
+
|
|
408
|
+
function claudeSettingsScopeReason(bytes) {
|
|
409
|
+
let settings;
|
|
410
|
+
try { settings = JSON.parse(bytes.toString('utf8')); } catch { return 'invalid JSON'; }
|
|
411
|
+
if (!isObject(settings)) return null;
|
|
412
|
+
if (Object.hasOwn(settings, 'hooks')) return 'hooks';
|
|
413
|
+
if (Object.hasOwn(settings, 'sandbox')) return 'sandbox';
|
|
414
|
+
const {permissions} = settings;
|
|
415
|
+
if (!isObject(permissions)) return null;
|
|
416
|
+
if (permissions.additionalDirectories?.length > 0) return 'permissions.additionalDirectories';
|
|
417
|
+
if (Object.hasOwn(permissions, 'allow')) {
|
|
418
|
+
const {allow} = permissions;
|
|
419
|
+
if (!Array.isArray(allow) || allow.some(rule =>
|
|
420
|
+
typeof rule !== 'string' || !CLAUDE_SAFE_ALLOW_TOOLS.has(rule.split('(', 1)[0].trim().toLowerCase())
|
|
421
|
+
)) return 'permissions.allow';
|
|
422
|
+
}
|
|
423
|
+
if (Object.hasOwn(permissions, 'defaultMode')) return 'permissions.defaultMode';
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Check Claude project and local settings before starting a writing bridge. */
|
|
428
|
+
export async function claudeProjectSettingsWidenScope(worktree) {
|
|
429
|
+
for (const label of ['.claude/settings.json', '.claude/settings.local.json']) {
|
|
430
|
+
let scopeReason;
|
|
431
|
+
const state = await extraControlFileState({path: path.join(worktree, label), project: bytes => {
|
|
432
|
+
scopeReason = claudeSettingsScopeReason(bytes);
|
|
433
|
+
return 'claude-settings-read';
|
|
434
|
+
}}).catch(() => 'unreadable');
|
|
435
|
+
if (state === sha256('deleted')) continue;
|
|
436
|
+
if (state === sha256('projection:claude-settings-read')) {
|
|
437
|
+
if (scopeReason) return `${label}: ${scopeReason}`;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (state === sha256('directory') || state.startsWith('symlink:')) return `${label}: not a regular file`;
|
|
441
|
+
return `${label}: settings path could not be verified`;
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Snapshot of selected Git, worktree and optional platform control files. */
|
|
447
|
+
export async function snapshotControlFiles({gitCommonDir, gitDir, worktree, extra = []}) {
|
|
448
|
+
if (![gitCommonDir, gitDir, worktree].every(dir => typeof dir === 'string' && path.isAbsolute(dir))) {
|
|
449
|
+
throw Error('Control snapshot requires absolute Git and worktree paths');
|
|
450
|
+
}
|
|
451
|
+
if (!(await fsp.lstat(gitCommonDir)).isDirectory()) throw Error('Git common directory is not a directory');
|
|
452
|
+
const files = [
|
|
453
|
+
{label: 'git:config', path: path.join(gitCommonDir, 'config')},
|
|
454
|
+
{label: 'git:config.worktree', path: path.join(gitDir, 'config.worktree')},
|
|
455
|
+
];
|
|
456
|
+
const entries = new Map();
|
|
457
|
+
for (const file of files) entries.set(file.label, await controlFileState(file.path));
|
|
458
|
+
await snapshotWorktreeControlDirectory(worktree, '.claude', ['settings.json', 'settings.local.json'], entries);
|
|
459
|
+
await snapshotWorktreeControlDirectory(worktree, '.codex', ['config.toml'], entries);
|
|
460
|
+
for (const file of extra) entries.set(file.label, await extraControlFileState(file));
|
|
461
|
+
for (const tree of ['hooks', 'info']) {
|
|
462
|
+
for (const [label, state] of await snapshotControlTree(path.join(gitCommonDir, tree), `git:${tree}`)) entries.set(label, state);
|
|
463
|
+
}
|
|
464
|
+
return entries;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export function allowedPathsCoverControl(allowedPaths) {
|
|
468
|
+
return allowedPaths.some(entry => {
|
|
469
|
+
const normalized = path.posix.normalize(entry).replace(/\/$/, '').toLowerCase();
|
|
470
|
+
return normalized.startsWith('.git/') || ['.', '.git', '.claude', '.claude/settings.json', '.claude/settings.local.json', '.codex', '.codex/config.toml'].includes(normalized);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
267
474
|
/** Snapshot of HEAD, branch, every ref (name and object) and every changed or untracked path; paths are relative to the worktree root even when worktree is a subdirectory. */
|
|
268
475
|
export async function snapshotWorktree(worktree) {
|
|
269
476
|
const root = (await git(worktree, ['rev-parse', '--show-toplevel'])).trim();
|
|
@@ -287,7 +494,7 @@ export async function snapshotWorktree(worktree) {
|
|
|
287
494
|
}
|
|
288
495
|
|
|
289
496
|
const allowedBy = (allowedPaths, file) => allowedPaths.some(entry => entry.endsWith('/') ? file.startsWith(entry) : file === entry);
|
|
290
|
-
/** Implementer and QA may change only allowedPaths (QA: none when empty or missing); read-only roles may change nothing; any HEAD, branch or ref change (created, deleted or moved) is a violation. Git-ignored paths are
|
|
497
|
+
/** Implementer and QA may change only allowedPaths (QA: none when empty or missing); read-only roles may change nothing; any HEAD, branch or ref change (created, deleted or moved) is a violation. Ordinary worktree snapshots omit Git-ignored paths; control files are compared regardless of allowedPaths and role. */
|
|
291
498
|
export function detectViolations({role, allowedPaths, before, after}) {
|
|
292
499
|
const headChanged = before.head !== after.head || before.branch !== after.branch;
|
|
293
500
|
const refsBefore = before.refs ?? {}, refsAfter = after.refs ?? {};
|
|
@@ -296,5 +503,8 @@ export function detectViolations({role, allowedPaths, before, after}) {
|
|
|
296
503
|
const changed = new Set();
|
|
297
504
|
for (const file of new Set([...before.entries.keys(), ...after.entries.keys()])) if (before.entries.get(file) !== after.entries.get(file)) changed.add(file);
|
|
298
505
|
const changedPaths = [...changed].filter(file => !allowedBy(allowed, file)).sort();
|
|
299
|
-
|
|
506
|
+
const controlBefore = before.control ?? new Map(), controlAfter = after.control ?? new Map();
|
|
507
|
+
const controlChanged = [...new Set([...controlBefore.keys(), ...controlAfter.keys()])]
|
|
508
|
+
.filter(label => controlBefore.get(label) !== controlAfter.get(label)).sort();
|
|
509
|
+
return {reason: headChanged || refsChanged || changedPaths.length || controlChanged.length ? 'permission_violation_observed' : null, changedPaths, headChanged, refsChanged, controlChanged};
|
|
300
510
|
}
|
|
@@ -9,6 +9,7 @@ import {resolveConfigHome, resolveLocalCli, probePlatformAuth, probeCodexAuthSta
|
|
|
9
9
|
import {ROUTING_ROLES, parseRoleRoutingConfig} from './role-routing-config.mjs';
|
|
10
10
|
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, revisionTag, hostGateReasons, bridgeGateReasons, environmentReasons, initialClaims, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
11
11
|
import {NON_TERMINAL_STATES, createLease, listLeases, pruneTerminalLeases, readHostLimits} from './role-dispatch-store.mjs';
|
|
12
|
+
import {allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
12
13
|
|
|
13
14
|
const exact=(value,keys)=>value&&typeof value==='object'&&!Array.isArray(value)&&Object.keys(value).length===keys.length&&keys.every(key=>Object.hasOwn(value,key));
|
|
14
15
|
const hash=bytes=>'sha256:'+crypto.createHash('sha256').update(bytes).digest('hex');
|
|
@@ -239,6 +240,11 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
239
240
|
let config;try{config=await readActivation(homes,expectedRevision,{anchorHome,host,runtimePlatforms});}catch{result.reasons=[reason('activation_unverified')];return;}
|
|
240
241
|
const requested=config.roles[role],route=requested.platform===host?'native':'bridge';
|
|
241
242
|
result.requested={...requested};result.route=route;result.profileName=profileName(requested.platform,role,{runtimePlatforms});
|
|
243
|
+
if(route==='bridge'&&allowedPathsCoverControl(assignment.allowedPaths??[])){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
244
|
+
if(route==='bridge'&&requested.platform==='claude'&&(role==='arc_implementer'||role==='arc_qa')){
|
|
245
|
+
const target=typeof context.cwd==='string'?await resolveWorktree(context.cwd).catch(()=>null):null;
|
|
246
|
+
if(!target||await claudeProjectSettingsWidenScope(target.realpath)){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
247
|
+
}
|
|
242
248
|
const capabilities=capabilityReasons({hostPlatform:host,targetPlatform:requested.platform,route,runtimePlatforms});
|
|
243
249
|
if(capabilities.length){result.reasons=capabilities.map(reason);return;}
|
|
244
250
|
await pruneTerminalLeases(anchorHome,{now,retentionMs:policy.leaseRetentionMs,runtimePlatforms});
|
|
@@ -7,15 +7,14 @@ import crypto from 'node:crypto';
|
|
|
7
7
|
import {spawn, spawnSync} from 'node:child_process';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {GROK_CONTRACT, normalizeGrokStreamEvent, evaluateGrokObservation} from './grok-stream.mjs';
|
|
10
|
-
import {GROK_SANDBOX_RELATIVE, grokSandboxProfileName, renderGrokSandboxProfile, grokProfileCovered, inspectGrokProfileSlot, checkGrokHome, createGrokSandboxProfile, verifyGrokSandboxProfile, removeGrokSandboxProfile, grokEventsBaseline, readGrokProfileApplied} from './grok-sandbox.mjs';
|
|
10
|
+
import {GROK_SANDBOX_RELATIVE, grokSandboxProfileName, renderGrokSandboxProfile, grokProfileCovered, inspectGrokProfileSlot, checkGrokHome, createGrokSandboxProfile, verifyGrokSandboxProfile, removeGrokSandboxProfile, grokEventsBaseline, readGrokProfileApplied, grokConfigSecurityProjection} from './grok-sandbox.mjs';
|
|
11
11
|
import {GEMINI_CONTRACT, normalizeGeminiStreamEvent, evaluateGeminiObservation} from './gemini-stream.mjs';
|
|
12
12
|
import {DEFAULT_POLICY, reason, bridgeGateReasons} from './role-dispatch-policy.mjs';
|
|
13
13
|
import {readLease, writeLease, writeHeartbeat, cancelRequested, TERMINAL_STATES} from './role-dispatch-store.mjs';
|
|
14
14
|
import {withRoutingLock, readActivation, resolveRuntimeHomes} from './role-routing.mjs';
|
|
15
|
-
import {observeCooperativeTarget} from './scope.mjs';
|
|
16
15
|
import {resolveLocalCli, localCliEnvironment} from './local-cli.mjs';
|
|
17
16
|
import {parseCompositeProfile, buildBridgeArgs, argsDigest, ROLE_BRIDGE_PERMISSIONS} from './role-bridge-args.mjs';
|
|
18
|
-
import {createLineParser, normalizeClaudeStreamEvent, normalizeCodexStreamEvent, eventRecord, evaluateClaudeInit, evaluateCodexContext, readClaudeTranscriptEffort, readCodexTurnContext, classifyFailure, snapshotWorktree, detectViolations} from './role-observe.mjs';
|
|
17
|
+
import {createLineParser, normalizeClaudeStreamEvent, normalizeCodexStreamEvent, eventRecord, evaluateClaudeInit, evaluateCodexContext, readClaudeTranscriptEffort, readCodexTurnContext, classifyFailure, snapshotWorktree, snapshotControlFiles, detectViolations, allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
19
18
|
import {getPlatform, routingProfileFile} from './platform-registry.mjs';
|
|
20
19
|
|
|
21
20
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -90,13 +89,7 @@ export function processAlive({pid, startTime} = {}) {
|
|
|
90
89
|
return current !== null && current === startTime;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
export async function resolveWorktree(cwd) {
|
|
95
|
-
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith('GIT_')));
|
|
96
|
-
const result = spawnSync('git', ['--no-pager', 'rev-parse', '--show-toplevel'], {cwd, env: {...env, GIT_CONFIG_NOSYSTEM: '1', GIT_OPTIONAL_LOCKS: '0'}, encoding: 'utf8', timeout: 10000});
|
|
97
|
-
if (result.error || result.status !== 0 || !result.stdout.endsWith('\n')) throw Error('Worktree root unavailable');
|
|
98
|
-
return observeCooperativeTarget(result.stdout.slice(0, -1));
|
|
99
|
-
}
|
|
92
|
+
export {resolveWorktree};
|
|
100
93
|
export const artifactDirectory = (target, workflowId, dispatchId) => path.join(target.gitCommonDir, 'arc', 'workflows', workflowId, 'dispatches', dispatchId);
|
|
101
94
|
/** Segment 0 (the first run) keeps its files in the dispatch directory; resumed segments use segments/<n>/. */
|
|
102
95
|
export const segmentDirectory = (target, workflowId, dispatchId, segment) => segment > 0 ? path.join(artifactDirectory(target, workflowId, dispatchId), 'segments', String(segment)) : artifactDirectory(target, workflowId, dispatchId);
|
|
@@ -119,6 +112,11 @@ export async function buildBridgeInvocation({lease, config, homes, worktree, res
|
|
|
119
112
|
if ((platform === 'gemini' || platform === 'grok') && lease.segment > 0 && !['on', 'verified'].includes(implementation?.resume)) throw fail('resume_unverified', platform === 'grok' ? 'Grok resume is not verified' : 'Gemini resume is not verified');
|
|
120
113
|
if (!implementation) throw fail('permission_scope_unverified', 'Invalid composite profile: unknown platform');
|
|
121
114
|
const permissions = ROLE_BRIDGE_PERMISSIONS[platform][lease.role];
|
|
115
|
+
if (Array.isArray(lease.allowedPaths) && allowedPathsCoverControl(lease.allowedPaths)) throw fail('permission_scope_unverified', 'allowedPaths cover a control file');
|
|
116
|
+
if (platform === 'claude' && permissions.sandbox) {
|
|
117
|
+
const scopeReason = await claudeProjectSettingsWidenScope(worktree);
|
|
118
|
+
if (scopeReason) throw fail('permission_scope_unverified', scopeReason);
|
|
119
|
+
}
|
|
122
120
|
let grokSandbox;
|
|
123
121
|
if (platform === 'grok' && permissions.sandbox === 'custom') {
|
|
124
122
|
const name = grokSandboxProfileName(lease.dispatchId);
|
|
@@ -273,8 +271,16 @@ export async function runSupervisor(options) {
|
|
|
273
271
|
const {path, sha256, dirCreated} = createdGrokProfile;
|
|
274
272
|
grokSandboxProfile = {name: invocation.grokSandbox.name, path, sha256, dirCreated, created: true, removed: null, dirRemoved: false, eventsBaseline: null, applied: null};
|
|
275
273
|
}
|
|
274
|
+
const extra = invocation.grokSandbox ? [
|
|
275
|
+
{label: 'grok-home:config.toml', path: path.join(homes.grok, 'config.toml'), project: grokConfigSecurityProjection},
|
|
276
|
+
{label: 'grok-home:sandbox.toml', path: path.join(homes.grok, 'sandbox.toml')},
|
|
277
|
+
] : [];
|
|
278
|
+
const snapshot = async () => ({
|
|
279
|
+
...await snapshotWorktree(target.realpath),
|
|
280
|
+
control: await snapshotControlFiles({gitCommonDir: target.gitCommonDir, gitDir: target.gitDir, worktree: target.realpath, extra}),
|
|
281
|
+
});
|
|
276
282
|
let before;
|
|
277
|
-
try { before = await
|
|
283
|
+
try { before = await snapshot(); } catch { return await failWithProfileCleanup('execution_failed'); }
|
|
278
284
|
|
|
279
285
|
if (invocation.promptFile) {
|
|
280
286
|
let promptFd;
|
|
@@ -444,8 +450,8 @@ export async function runSupervisor(options) {
|
|
|
444
450
|
}
|
|
445
451
|
|
|
446
452
|
let after = null;
|
|
447
|
-
try { after = await
|
|
448
|
-
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false};
|
|
453
|
+
try { after = await snapshot(); } catch { after = null; }
|
|
454
|
+
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false, controlChanged: []};
|
|
449
455
|
const codes = [];
|
|
450
456
|
if (state.mismatch) codes.push(state.mismatch);
|
|
451
457
|
if (state.internal) codes.push(state.internal);
|
|
@@ -495,7 +501,8 @@ export async function runSupervisor(options) {
|
|
|
495
501
|
}
|
|
496
502
|
if (exit.spawnError && !codes.length) { codes.push('execution_failed'); finalState = 'failed'; }
|
|
497
503
|
if ((finalState === 'completed' || finalState === 'cancelled') && codes.includes('permission_scope_mismatch')) finalState = 'failed';
|
|
498
|
-
|
|
504
|
+
const controlFiles = violations.controlChanged.length ? {controlFiles: {changed: violations.controlChanged}} : {};
|
|
505
|
+
await writeRecord({state: finalState, reasons: [...new Set(codes)], exit: {code: exit.code, signal: exit.signal}, terminatedBy: terminating, eventsTruncated, ignoredLines: parser.ignored, lineOverflow: parser.overflow, violations: {changedPaths: violations.changedPaths, headChanged: violations.headChanged, refsChanged: violations.refsChanged}, ...controlFiles, ...(orphanGroupReaped ? {orphanGroupReaped: true} : {}), argsDigest: invocation.argsDigest, resultPath, ...grokProfileRecord(), ...(platform === 'gemini' ? {unverifiedContracts: {delegation: GEMINI_CONTRACT.delegation}} : platform === 'grok' ? {unverifiedContracts: {delegation: GROK_CONTRACT.delegation}} : {})});
|
|
499
506
|
await commit(finalState, codes, claims, {sessionId, resultPath});
|
|
500
507
|
} catch {
|
|
501
508
|
// Unexpected failure after the child started: stop it, then record a failed state if the child is gone.
|