@hasna/hooks 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -15
- package/bin/hooks/stop-review.js +53 -17
- package/bin/hooks-mcp.js +4787 -1415
- package/bin/index.js +5250 -2337
- package/bin/native-safety-entry.js +15 -37
- package/bin/native-safety-worker.cjs +38 -36
- package/bin/serve.js +34 -11
- package/dist/index.js +4970 -1579
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-trust.d.ts +2 -2
- package/dist/lib/native-safety-registration.d.ts +2 -2
- package/dist/lib/native-safety.d.ts +1 -1
- package/dist/lib/registry.d.ts +3 -1
- package/dist/native-safety.d.ts +4 -2
- package/dist/native-safety.js +21 -2
- package/dist/sdk/index.js +9 -53
- package/hooks/hook-job-folder-guard/README.md +61 -0
- package/hooks/hook-job-folder-guard/package.json +12 -0
- package/hooks/hook-job-folder-guard/src/classify.ts +398 -0
- package/hooks/hook-job-folder-guard/src/hook.ts +96 -0
- package/hooks/hook-protected-delete-guard/README.md +114 -0
- package/hooks/hook-protected-delete-guard/package.json +12 -0
- package/hooks/hook-protected-delete-guard/src/hook.ts +539 -0
- package/hooks/hook-signed-link-guard/src/classify.ts +41 -2
- package/hooks/hook-stop-review/README.md +16 -0
- package/hooks/hook-stop-review/manifest.json +1 -1
- package/hooks/hook-stop-review/package.json +1 -1
- package/hooks/hook-stop-review/src/hook.ts +1 -1
- package/hooks/hook-stop-review/src/native.ts +44 -8
- package/hooks/hook-stop-review/src/policy.ts +20 -8
- package/hooks/hook-stop-review/src/runtime.ts +16 -13
- package/hooks/hook-stop-review/src/types.ts +12 -2
- package/hooks/hook-trash-guard/README.md +130 -13
- package/hooks/hook-trash-guard/src/hook.ts +518 -71
- package/hooks/local-executors.ts +33 -0
- package/hooks/native-safety-composite.ts +19 -8
- package/package.json +3 -3
- package/scripts/build-native-entry.ts +123 -0
- package/scripts/build-native-worker.ts +11 -4
- package/scripts/validate-package.ts +8 -2
- package/hooks/native-safety-entry.ts +0 -11
package/README.md
CHANGED
|
@@ -11,12 +11,14 @@ Open source hooks library for AI coding agents - Install safety, quality, and au
|
|
|
11
11
|
|
|
12
12
|
- **Agents.** Claude Code (the default target) and Codex. Compatible OpenCode and Sumi builds are supported for the stop-review hook. Gemini CLI is an install target (`--target gemini`), but the bundled shell guards do not yet recognise Gemini's tool names (`run_shell_command` rather than `Bash`), so do not rely on them there yet. Codewith targets remain for existing setups, but Codewith is deprecated.
|
|
13
13
|
- **Install targets.** `--target` also accepts `qwen`, `muse`, `kimi`, `pi` and `cursor`, each writing that harness's own config with an entry that calls `hooks run <hook> --target <name>`. They are not interchangeable: Muse hands over the final message as a quoted JSON string, which `hooks run --target muse` parses once; Kimi's stop payload carries no assistant text and Kimi blocks with exit 2 and stderr; Pi runs hooks through the `hasna-pi-hooks` bridge and receives no assistant text; Cursor's stop hook can neither block the turn nor carry the assistant text. A hook whose manifest sets `requires_final_message` or `requires_block` is refused at install on a target that cannot honour it, with the measured reason, instead of being installed to do nothing. `opencode` and `sumi` have no generic install path and are refused by name; their stop review is registered through `hooks install stop-review --target <opencode|sumi>`.
|
|
14
|
-
- **Catalog.**
|
|
14
|
+
- **Catalog.** 58 bundled hooks in 10 categories, listed below. You can also install your own hooks from a local directory, a git URL or a manifest URL.
|
|
15
15
|
- **Safety core.** Guards that:
|
|
16
16
|
- block destructive git commands (gitguard);
|
|
17
17
|
- send `rm` to a recoverable trash store instead of deleting (trash-guard). It needs the
|
|
18
18
|
`trash` CLI from `@hasna/trash` on PATH; without it, trash-guard refuses the `rm`;
|
|
19
19
|
- protect repository checkouts (workspace-repos-guard);
|
|
20
|
+
- refuse a delete of `/`, the home directory, `~/.hasna`, `~/.ssh`, `~/.aws` and of coding-agent
|
|
21
|
+
session and history stores, without Trash (protected-delete-guard);
|
|
20
22
|
- keep signed links out of agent transcripts (signed-link-guard).
|
|
21
23
|
|
|
22
24
|
scanoutput is detection only: it warns about a secret in tool output after the output is already in the transcript, and cannot prevent or redact it.
|
|
@@ -91,12 +93,12 @@ Run `hooks list --all --verbose` for each hook's description, or `hooks info <na
|
|
|
91
93
|
|
|
92
94
|
| Category | Hooks |
|
|
93
95
|
|---|---|
|
|
94
|
-
| Git safety | gitguard, branchprotect, checkpoint, worktree-guard, workspace-repos-guard, trash-guard, conflict-detect |
|
|
96
|
+
| Git safety | gitguard, branchprotect, checkpoint, worktree-guard, workspace-repos-guard, protected-delete-guard, trash-guard, conflict-detect |
|
|
95
97
|
| Code quality | checktests, checklint, checkfiles, checkbugs, checkdocs, checktasks, stylescheck, typecheck-gate, affected-tests |
|
|
96
98
|
| Security | checksecurity, packageage, pre-bash, scanoutput, signed-link-guard, signed-link-output |
|
|
97
99
|
| Permissions | permissionguard, protectfiles, promptguard, prompt-guard |
|
|
98
100
|
| Context management | contextrefresh, precompact, knowledge-context, mementos-context |
|
|
99
|
-
| Workflow automation | autoformat, autostage, tddguard, failure-to-task |
|
|
101
|
+
| Workflow automation | autoformat, autostage, tddguard, failure-to-task, job-folder-guard |
|
|
100
102
|
| Environment | envsetup |
|
|
101
103
|
| Notifications | phonenotify, agentmessages, desktopnotify, slacknotify, soundnotify |
|
|
102
104
|
| Observability | sessionlog, commandlog, costwatch, errornotify, spiral-detector, scratch-lifecycle |
|
|
@@ -362,14 +364,22 @@ hooks safety registration-apply --target codex --expected-plan-digest PLAN_SHA25
|
|
|
362
364
|
```
|
|
363
365
|
|
|
364
366
|
Both commands, and `trust-plan`/`trust-apply` below, take
|
|
365
|
-
`--guard trash-guard|workspace-repos-guard` (default
|
|
366
|
-
selected guard's own entry is rendered and written;
|
|
367
|
-
disabled one included, keeps its exact bytes. A plan digest
|
|
368
|
-
never accepted by an apply for
|
|
369
|
-
supervisor rewrite a synthetic removal into Trash;
|
|
370
|
-
never rewrites, by having its supervisor refuse a
|
|
371
|
-
`~/.hasna/repos/clones` with the guard's exact reason
|
|
372
|
-
|
|
367
|
+
`--guard trash-guard|workspace-repos-guard|protected-delete-guard` (default
|
|
368
|
+
`trash-guard`). Only the selected guard's own entry is rendered and written;
|
|
369
|
+
every other entry, a disabled one included, keeps its exact bytes. A plan digest
|
|
370
|
+
for one guard is never accepted by an apply for another. trash-guard is verified
|
|
371
|
+
by having its supervisor rewrite a synthetic removal into Trash;
|
|
372
|
+
workspace-repos-guard, which never rewrites, by having its supervisor refuse a
|
|
373
|
+
synthetic removal below `~/.hasna/repos/clones` with the guard's exact reason;
|
|
374
|
+
protected-delete-guard, which never rewrites either, by having its supervisor
|
|
375
|
+
refuse a synthetic removal of the home's `~/.ssh` and let a synthetic removal of
|
|
376
|
+
an ordinary name pass. No removal is run, and no path is created.
|
|
377
|
+
|
|
378
|
+
protected-delete-guard needs no Trash and is registered on its own: a first
|
|
379
|
+
registration appends its entry after the existing handlers, so no other
|
|
380
|
+
handler's position or Codex trusted hash changes, and removing or disabling
|
|
381
|
+
that one entry switches it off. What it refuses, and its limits, are in
|
|
382
|
+
[`hooks/hook-protected-delete-guard/README.md`](hooks/hook-protected-delete-guard/README.md).
|
|
373
383
|
|
|
374
384
|
Apply checks the exact predecessor, retains an owner-only original and intent,
|
|
375
385
|
and reads back the result. An identical registration returns unchanged without
|
|
@@ -479,10 +489,15 @@ so every old registration keeps verifying its own tree until it is moved. If
|
|
|
479
489
|
an in-place global upgrade cannot be avoided, re-register all three targets
|
|
480
490
|
straight after it.
|
|
481
491
|
|
|
482
|
-
The supervisor passes
|
|
483
|
-
Linux limits a single argument to 131,072 bytes (32 pages
|
|
484
|
-
|
|
485
|
-
worker
|
|
492
|
+
The supervisor passes `bin/native-safety-entry.js` to the runtime as one
|
|
493
|
+
`--eval` argument, and Linux limits a single argument to 131,072 bytes (32 pages
|
|
494
|
+
of 4 KiB). The entry therefore carries the guard code, the minified v2 worker
|
|
495
|
+
`bin/native-safety-worker.cjs`, deflated and base64-encoded. It inflates those
|
|
496
|
+
bytes, refuses unless their SHA-256 equals the one built into it, and evaluates
|
|
497
|
+
exactly them with a `require` that serves only `node:` builtins. The pinned
|
|
498
|
+
entry digest still fixes the code that runs. The build and the package
|
|
499
|
+
validation refuse an entry at or above the limit; the guard code itself may
|
|
500
|
+
grow to roughly twice the limit before the entry reaches it.
|
|
486
501
|
|
|
487
502
|
Known limits of the native entry:
|
|
488
503
|
|
package/bin/hooks/stop-review.js
CHANGED
|
@@ -134,6 +134,19 @@ function requestsStop(prompt) {
|
|
|
134
134
|
return /^(?:\s*(?:please\s+)?(?:stop|pause|cancel|quit|exit|abort|hold\s+on|wait|don't\s+continue|do\s+not\s+continue|nu\s+continua|opre\u0219te|opreste)\b|\s*\/(?:stop|pause|cancel|exit|quit|clear|goal)\b)/i.test(prompt);
|
|
135
135
|
}
|
|
136
136
|
var nativeGoalRevision = Symbol("nativeGoalRevision");
|
|
137
|
+
var nativeGoalAccounting = Symbol("nativeGoalAccounting");
|
|
138
|
+
function parseCodexNativeGoalStopReview(value) {
|
|
139
|
+
const count = (x) => Number.isSafeInteger(x) && x >= 0;
|
|
140
|
+
if (!object(value) || Object.keys(value).sort().join(",") !== "goal_id,objective,revision,status_source,time_used_seconds,token_budget,tokens_used,turn_id" || !id(value.goal_id) || !id(value.turn_id) || !count(value.revision) || !text(value.objective) || !["active", "agent_blocked"].includes(String(value.status_source)) || !(value.token_budget === null || count(value.token_budget)) || !count(value.tokens_used) || !count(value.time_used_seconds))
|
|
141
|
+
return;
|
|
142
|
+
return { ...value };
|
|
143
|
+
}
|
|
144
|
+
function nativeSnapshotMatches(snapshot, goal) {
|
|
145
|
+
if (!goal || goal.objective !== snapshot.objective || goal.status !== (snapshot.status_source === "active" ? "active" : "blocked"))
|
|
146
|
+
return false;
|
|
147
|
+
const accounting = goal[nativeGoalAccounting];
|
|
148
|
+
return !!accounting && accounting.tokenBudget === snapshot.token_budget && accounting.tokensUsed === snapshot.tokens_used && accounting.timeUsedSeconds === snapshot.time_used_seconds;
|
|
149
|
+
}
|
|
137
150
|
function goalFreshness(goal) {
|
|
138
151
|
if (goal === undefined)
|
|
139
152
|
return { state: "unreadable" };
|
|
@@ -155,6 +168,10 @@ async function prepareNativeStop(raw, options) {
|
|
|
155
168
|
}
|
|
156
169
|
if (options.harness === "codex" && !id(raw.turn_id))
|
|
157
170
|
return unavailable("missing_native_turn");
|
|
171
|
+
const hasNativeSnapshot = Object.hasOwn(raw, "native_goal_stop_review");
|
|
172
|
+
const nativeSnapshot = hasNativeSnapshot ? parseCodexNativeGoalStopReview(raw.native_goal_stop_review) : undefined;
|
|
173
|
+
if (hasNativeSnapshot && (options.harness !== "codex" || !nativeSnapshot || nativeSnapshot.turn_id !== raw.turn_id))
|
|
174
|
+
return unavailable("invalid_native_goal_snapshot");
|
|
158
175
|
const { session_id: sessionId, transcript_path: path, last_assistant_message: assistant } = raw;
|
|
159
176
|
const readPrompt = async () => {
|
|
160
177
|
let windowBytes = 2000000;
|
|
@@ -172,13 +189,15 @@ async function prepareNativeStop(raw, options) {
|
|
|
172
189
|
const snapshot = async () => {
|
|
173
190
|
const prompt = await readPrompt();
|
|
174
191
|
const goal = options.harness === "codex" ? await options.readGoal?.(sessionId) : undefined;
|
|
175
|
-
|
|
192
|
+
if (nativeSnapshot && !nativeSnapshotMatches(nativeSnapshot, goal))
|
|
193
|
+
throw new Error("native_goal_snapshot_changed");
|
|
194
|
+
return { prompt, goal, revision: digest([prompt.revision, options.harness === "codex" ? goalFreshness(goal) : "optional-goal-unavailable", assistant, ...nativeSnapshot ? [nativeSnapshot] : []]) };
|
|
176
195
|
};
|
|
177
196
|
try {
|
|
178
197
|
const current = await snapshot();
|
|
179
198
|
if (current.prompt.interrupted || requestsStop(current.prompt.prompt))
|
|
180
199
|
return unavailable("user_stop");
|
|
181
|
-
const goal = current.goal;
|
|
200
|
+
const goal = nativeSnapshot?.status_source === "agent_blocked" && current.goal ? { ...current.goal, statusSource: "agent_blocked", activationEpoch: nativeSnapshot.revision } : current.goal;
|
|
182
201
|
const envelope = {
|
|
183
202
|
schema: "hooks.stop-review.v1",
|
|
184
203
|
sessionId,
|
|
@@ -199,10 +218,11 @@ async function prepareNativeStop(raw, options) {
|
|
|
199
218
|
awaitingApproval: false,
|
|
200
219
|
nativeContinuationAllowed: true,
|
|
201
220
|
stopHookActive: false,
|
|
202
|
-
continuationCount: 0
|
|
221
|
+
continuationCount: 0,
|
|
222
|
+
...nativeSnapshot?.status_source === "agent_blocked" ? { agentBlockedAdmission: "parent_final_cas" } : {}
|
|
203
223
|
}
|
|
204
224
|
};
|
|
205
|
-
return { ok: true, envelope, isCurrent: async (candidate) => {
|
|
225
|
+
return { ok: true, envelope, ...nativeSnapshot ? { nativeAdmission: { mode: "parent_final_cas", harness: "codex" } } : {}, isCurrent: async (candidate) => {
|
|
206
226
|
if (candidate.sessionId !== sessionId || candidate.turnId !== envelope.turnId || candidate.inputRevision !== envelope.inputRevision)
|
|
207
227
|
return false;
|
|
208
228
|
try {
|
|
@@ -235,8 +255,11 @@ function codexGoalFromResponse(value, sessionId) {
|
|
|
235
255
|
return;
|
|
236
256
|
if (!Number.isSafeInteger(goal.createdAt) || goal.createdAt < 0 || !Number.isSafeInteger(goal.updatedAt) || goal.updatedAt < goal.createdAt)
|
|
237
257
|
return;
|
|
258
|
+
if (goal.timeUsedSeconds !== undefined && (!Number.isSafeInteger(goal.timeUsedSeconds) || goal.timeUsedSeconds < 0))
|
|
259
|
+
return;
|
|
238
260
|
const projected = { id: sessionId, objective: goal.objective, status: goal.tokenBudget !== null && goal.tokensUsed >= goal.tokenBudget ? "budget_limited" : status };
|
|
239
|
-
Object.defineProperty(projected, nativeGoalRevision, { value: digest([goal.createdAt, goal.updatedAt, goal.tokenBudget, goal.tokensUsed]), enumerable: false });
|
|
261
|
+
Object.defineProperty(projected, nativeGoalRevision, { value: digest([goal.createdAt, goal.updatedAt, goal.tokenBudget, goal.tokensUsed, goal.timeUsedSeconds]), enumerable: false });
|
|
262
|
+
Object.defineProperty(projected, nativeGoalAccounting, { value: { tokenBudget: goal.tokenBudget, tokensUsed: goal.tokensUsed, timeUsedSeconds: goal.timeUsedSeconds }, enumerable: false });
|
|
240
263
|
return projected;
|
|
241
264
|
}
|
|
242
265
|
function resolveControlSocket(path) {
|
|
@@ -323,7 +346,7 @@ async function runNativeStop(raw, options, review) {
|
|
|
323
346
|
if (!prepared.ok)
|
|
324
347
|
return { output: {}, reason: prepared.reason };
|
|
325
348
|
try {
|
|
326
|
-
const result = await review(prepared.envelope, prepared.isCurrent);
|
|
349
|
+
const result = await review(prepared.envelope, prepared.isCurrent, prepared.nativeAdmission);
|
|
327
350
|
const output = await nativeStopOutput(result, prepared);
|
|
328
351
|
return { output, reason: result.action === "continue" && !output.decision ? "stale_input" : result.reason };
|
|
329
352
|
} catch {
|
|
@@ -706,6 +729,9 @@ function hasTruthfulSumiAgentPause(envelope, admission) {
|
|
|
706
729
|
const goal = envelope.goal;
|
|
707
730
|
return admission?.mode === "parent_final_cas" && admission.harness === "sumi" && goal?.status === "paused" && goal.statusSource === "agent" && goal.pauseReason === "agent" && Number.isSafeInteger(goal.activationEpoch) && goal.activationEpoch >= 0 && envelope.runtime.paused === true && envelope.runtime.agentPauseAdmission === "parent_final_cas";
|
|
708
731
|
}
|
|
732
|
+
function hasNativeCodexAgentBlock(envelope, admission) {
|
|
733
|
+
return admission?.mode === "parent_final_cas" && admission.harness === "codex" && envelope.goal?.status === "blocked" && envelope.goal.statusSource === "agent_blocked" && Number.isSafeInteger(envelope.goal.activationEpoch) && envelope.goal.activationEpoch >= 0 && envelope.runtime.agentBlockedAdmission === "parent_final_cas";
|
|
734
|
+
}
|
|
709
735
|
function isStopReviewEnvelope(value) {
|
|
710
736
|
if (!record(value) || value.schema !== "hooks.stop-review.v1" || !identifier(value.sessionId) || !identifier(value.turnId) || !identifier(value.inputRevision) || typeof value.capturedAt !== "string" || !Number.isFinite(Date.parse(value.capturedAt)) || !text2(value.lastUserPrompt) || !text2(value.lastAssistantMessage) || !record(value.runtime))
|
|
711
737
|
return false;
|
|
@@ -714,15 +740,23 @@ function isStopReviewEnvelope(value) {
|
|
|
714
740
|
return false;
|
|
715
741
|
if (runtime.agentPauseAdmission !== undefined && runtime.agentPauseAdmission !== "parent_final_cas")
|
|
716
742
|
return false;
|
|
743
|
+
if (runtime.agentBlockedAdmission !== undefined && runtime.agentBlockedAdmission !== "parent_final_cas")
|
|
744
|
+
return false;
|
|
745
|
+
if (runtime.agentPauseAdmission !== undefined && runtime.agentBlockedAdmission !== undefined)
|
|
746
|
+
return false;
|
|
717
747
|
if (value.goal !== undefined && value.goal !== null && (!record(value.goal) || !identifier(value.goal.id) || !text2(value.goal.objective) || !goalStatuses.includes(value.goal.status)))
|
|
718
748
|
return false;
|
|
719
749
|
if (record(value.goal)) {
|
|
720
750
|
const pauseFacts = [value.goal.statusSource, value.goal.pauseReason, value.goal.activationEpoch];
|
|
721
751
|
const hasPauseFact = pauseFacts.some((fact) => fact !== undefined);
|
|
722
752
|
const exactPauseFacts = value.goal.status === "paused" && value.goal.statusSource === "agent" && value.goal.pauseReason === "agent" && Number.isSafeInteger(value.goal.activationEpoch) && value.goal.activationEpoch >= 0;
|
|
723
|
-
|
|
753
|
+
const exactBlockedFacts = value.goal.status === "blocked" && value.goal.statusSource === "agent_blocked" && value.goal.pauseReason === undefined && Number.isSafeInteger(value.goal.activationEpoch) && value.goal.activationEpoch >= 0;
|
|
754
|
+
if (runtime.agentBlockedAdmission !== undefined) {
|
|
755
|
+
if (!exactBlockedFacts)
|
|
756
|
+
return false;
|
|
757
|
+
} else if (hasPauseFact !== (runtime.agentPauseAdmission !== undefined) || hasPauseFact && !exactPauseFacts)
|
|
724
758
|
return false;
|
|
725
|
-
} else if (runtime.agentPauseAdmission !== undefined)
|
|
759
|
+
} else if (runtime.agentPauseAdmission !== undefined || runtime.agentBlockedAdmission !== undefined)
|
|
726
760
|
return false;
|
|
727
761
|
if (value.goalAvailability !== undefined && !["known", "unavailable"].includes(value.goalAvailability))
|
|
728
762
|
return false;
|
|
@@ -760,7 +794,7 @@ function stopPolicyGate(envelope, now, maxContinuations = 1, options = {}) {
|
|
|
760
794
|
return "runtime_failure";
|
|
761
795
|
if (runtime.stopReason !== "end_turn" || envelope.goal === undefined && envelope.goalAvailability !== "unavailable" || envelope.goal?.status === "unknown")
|
|
762
796
|
return "unknown_runtime";
|
|
763
|
-
if (envelope.goal && envelope.goal.status !== "active" && !agentPause)
|
|
797
|
+
if (envelope.goal && envelope.goal.status !== "active" && !agentPause && !hasNativeCodexAgentBlock(envelope, options.admission))
|
|
764
798
|
return "goal_not_active";
|
|
765
799
|
if (runtime.stopHookActive || runtime.continuationCount > maxContinuations || runtime.continuationCount === maxContinuations && !options.assessmentOnlyAtCap)
|
|
766
800
|
return "recursion_guard";
|
|
@@ -770,7 +804,7 @@ function stopPolicyGate(envelope, now, maxContinuations = 1, options = {}) {
|
|
|
770
804
|
return null;
|
|
771
805
|
}
|
|
772
806
|
async function reviewStop(input, options) {
|
|
773
|
-
return assessStop(input, options, options.isCurrent);
|
|
807
|
+
return assessStop(input, options, options.isCurrent, options.nativeAdmission);
|
|
774
808
|
}
|
|
775
809
|
async function recommendStop(input, options) {
|
|
776
810
|
if (options.admission?.mode !== "parent_final_cas" || !["sumi", "opencode"].includes(options.admission.harness)) {
|
|
@@ -1075,7 +1109,7 @@ async function runJevProviderChild(raw, env = process.env) {
|
|
|
1075
1109
|
if (!["codex", "claude", "sumi", "opencode"].includes(raw.nativeTarget) || config.harness !== undefined && config.harness !== raw.nativeTarget)
|
|
1076
1110
|
return { ok: false, reason: "invalid_configuration" };
|
|
1077
1111
|
const nativeTarget = raw.nativeTarget;
|
|
1078
|
-
if (raw.admission !== undefined && (!record2(raw.admission) || raw.admission.mode !== "parent_final_cas" || !["sumi", "opencode"].includes(raw.admission.harness) || Object.keys(raw.admission).sort().join(",") !== "harness,mode" || nativeTarget !== raw.admission.harness))
|
|
1112
|
+
if (raw.admission !== undefined && (!record2(raw.admission) || raw.admission.mode !== "parent_final_cas" || !["sumi", "opencode", "codex"].includes(raw.admission.harness) || Object.keys(raw.admission).sort().join(",") !== "harness,mode" || nativeTarget !== raw.admission.harness))
|
|
1079
1113
|
return { ok: false, reason: "invalid_configuration" };
|
|
1080
1114
|
const admission = raw.admission;
|
|
1081
1115
|
const gate = stopPolicyGate(raw.envelope, Date.now(), 1, { assessmentOnlyAtCap: !!admission, admission });
|
|
@@ -1151,20 +1185,22 @@ async function evaluateThroughSecrets(envelope, instruction, config, env, entryp
|
|
|
1151
1185
|
return { ok: false, reason: "invalid_provider_response" };
|
|
1152
1186
|
}
|
|
1153
1187
|
}
|
|
1154
|
-
async function reviewNativeEnvelope(envelope, isCurrent, env = process.env, entrypoint = process.argv[1], nativeTarget) {
|
|
1155
|
-
return reviewRuntimeEnvelope(envelope, env, entrypoint, nativeTarget, isCurrent);
|
|
1188
|
+
async function reviewNativeEnvelope(envelope, isCurrent, env = process.env, entrypoint = process.argv[1], nativeTarget, nativeAdmission) {
|
|
1189
|
+
return reviewRuntimeEnvelope(envelope, env, entrypoint, nativeTarget, isCurrent, nativeAdmission);
|
|
1156
1190
|
}
|
|
1157
1191
|
async function reviewParentGuardedEnvelope(raw, env = process.env, entrypoint = process.argv[1], nativeTarget = "sumi") {
|
|
1158
1192
|
const result = await reviewRuntimeEnvelope(raw, env, entrypoint, nativeTarget);
|
|
1159
1193
|
return { ...result, admission: result.admission ?? { mode: "parent_final_cas", harness: nativeTarget, settlement: "none" } };
|
|
1160
1194
|
}
|
|
1161
|
-
async function reviewRuntimeEnvelope(raw, env, entrypoint, nativeTarget, isCurrent) {
|
|
1195
|
+
async function reviewRuntimeEnvelope(raw, env, entrypoint, nativeTarget, isCurrent, nativeAdmission) {
|
|
1162
1196
|
if (!isStopReviewEnvelope(raw))
|
|
1163
1197
|
return { schema: "hooks.stop-review-result.v1", action: "unavailable", reason: "invalid_input" };
|
|
1164
1198
|
const envelope = structuredClone(raw);
|
|
1165
1199
|
const base = { schema: "hooks.stop-review-result.v1", sessionId: envelope.sessionId, turnId: envelope.turnId, inputRevision: envelope.inputRevision };
|
|
1166
1200
|
const unavailable2 = (reason) => ({ ...base, action: "unavailable", reason });
|
|
1167
|
-
|
|
1201
|
+
if (nativeAdmission && (!isCurrent || nativeTarget !== "codex" || nativeAdmission.mode !== "parent_final_cas" || nativeAdmission.harness !== "codex"))
|
|
1202
|
+
return unavailable2("invalid_configuration");
|
|
1203
|
+
const admission = nativeAdmission ?? (isCurrent || !nativeTarget || !["sumi", "opencode"].includes(nativeTarget) ? undefined : { mode: "parent_final_cas", harness: nativeTarget });
|
|
1168
1204
|
const gate = stopPolicyGate(envelope, Date.now(), 1, { assessmentOnlyAtCap: !isCurrent, admission });
|
|
1169
1205
|
if (gate)
|
|
1170
1206
|
return { ...base, action: "allow_stop", reason: gate };
|
|
@@ -1193,7 +1229,7 @@ async function reviewRuntimeEnvelope(raw, env, entrypoint, nativeTarget, isCurre
|
|
|
1193
1229
|
timeoutMs: 8000,
|
|
1194
1230
|
evaluate: () => evaluateThroughSecrets(envelope, instruction, config, env, entrypoint, runRuntimeCommand, admission, nativeTarget)
|
|
1195
1231
|
};
|
|
1196
|
-
return isCurrent ? reviewStop(envelope, { ...options, isCurrent }) : recommendStop(envelope, { ...options, admission });
|
|
1232
|
+
return isCurrent ? reviewStop(envelope, { ...options, isCurrent, nativeAdmission }) : recommendStop(envelope, { ...options, admission });
|
|
1197
1233
|
}
|
|
1198
1234
|
|
|
1199
1235
|
// hooks/hook-stop-review/src/hook.ts
|
|
@@ -1261,7 +1297,7 @@ async function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
1261
1297
|
codexHome: config.codexHome ?? env.CODEX_HOME ?? join4(env.HOME || homedir2(), ".codex"),
|
|
1262
1298
|
socketPath: config.codexSocketPath
|
|
1263
1299
|
})
|
|
1264
|
-
}, (envelope, isCurrent) => reviewNativeEnvelope(envelope, isCurrent, env, undefined, harness));
|
|
1300
|
+
}, (envelope, isCurrent, nativeAdmission) => reviewNativeEnvelope(envelope, isCurrent, env, undefined, harness, nativeAdmission));
|
|
1265
1301
|
output = result.output;
|
|
1266
1302
|
reason = result.reason;
|
|
1267
1303
|
}
|