@primitive.ai/prim 0.1.0-alpha.115 → 0.1.0-alpha.117
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 +43 -0
- package/SKILL.md +5 -3
- package/dist/{chunk-IZXLH3R5.js → chunk-3TIKBQHV.js} +2584 -821
- package/dist/{chunk-NH3VC7YO.js → chunk-4OEJ2ONG.js} +1 -1
- package/dist/{chunk-DWAXFXDG.js → chunk-4SN5BCIG.js} +1 -1
- package/dist/{chunk-3KKEV7VI.js → chunk-6IRAGUYK.js} +1 -1
- package/dist/chunk-CXMLAWC2.js +96 -0
- package/dist/chunk-D3ZDZZYS.js +449 -0
- package/dist/{chunk-RUUSUF43.js → chunk-I3J344DF.js} +231 -94
- package/dist/{chunk-7DVEH7FO.js → chunk-JKJ22ONL.js} +1 -1
- package/dist/{chunk-PO5QAYD7.js → chunk-JKO6PZWQ.js} +119 -24
- package/dist/{chunk-BXLH4LDU.js → chunk-LEUZDTNT.js} +1 -1
- package/dist/{chunk-PJW6JZMH.js → chunk-LLKJAET2.js} +1 -1
- package/dist/{chunk-IMYELJIV.js → chunk-RLBASQJD.js} +3 -3
- package/dist/{chunk-RTULPLS7.js → chunk-S55JKCHQ.js} +1 -1
- package/dist/daemon/server.js +2583 -822
- package/dist/hook-runtime/daemon/server.js +2583 -822
- package/dist/hook-runtime/hooks/post-commit.js +2581 -820
- package/dist/hook-runtime/hooks/post-rewrite.js +2581 -820
- package/dist/hook-runtime/hooks/post-tool-use.js +2689 -921
- package/dist/hook-runtime/hooks/pre-tool-use.js +2922 -987
- package/dist/hook-runtime/hooks/prim-hook.js +2682 -914
- package/dist/hook-runtime/hooks/session-end.js +19 -12
- package/dist/hook-runtime/hooks/session-start.js +2828 -1060
- package/dist/hook-runtime/index.js +22900 -12209
- package/dist/hooks/post-commit.js +3 -3
- package/dist/hooks/post-rewrite.js +3 -3
- package/dist/hooks/post-tool-use.js +11 -11
- package/dist/hooks/pre-tool-use.js +78 -318
- package/dist/hooks/prim-hook.js +10 -10
- package/dist/hooks/session-end.js +2 -2
- package/dist/hooks/session-start.js +6 -6
- package/dist/index.js +66 -15
- package/package.json +4 -1
- package/dist/chunk-JDIAPBY7.js +0 -233
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
commitAttributionFromEnvironment,
|
|
10
10
|
toCommitMove
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-S55JKCHQ.js";
|
|
12
12
|
import {
|
|
13
13
|
getOrCreateWorkspaceId
|
|
14
14
|
} from "../chunk-EZXEWFDG.js";
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
appendMove,
|
|
17
17
|
resolveOrg
|
|
18
18
|
} from "../chunk-HMD5K6W7.js";
|
|
19
|
-
import "../chunk-
|
|
19
|
+
import "../chunk-6IRAGUYK.js";
|
|
20
20
|
import {
|
|
21
21
|
cachedCollectScopeAdmits
|
|
22
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-3TIKBQHV.js";
|
|
23
23
|
import "../chunk-6JHKKLA2.js";
|
|
24
24
|
import {
|
|
25
25
|
githubRepositoryFullName,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
canonicalRewritePairs,
|
|
7
7
|
toRewriteMove
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-S55JKCHQ.js";
|
|
9
9
|
import {
|
|
10
10
|
getOrCreateWorkspaceId
|
|
11
11
|
} from "../chunk-EZXEWFDG.js";
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
appendMove,
|
|
14
14
|
resolveOrg
|
|
15
15
|
} from "../chunk-HMD5K6W7.js";
|
|
16
|
-
import "../chunk-
|
|
16
|
+
import "../chunk-6IRAGUYK.js";
|
|
17
17
|
import {
|
|
18
18
|
cachedCollectScopeAdmits
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-3TIKBQHV.js";
|
|
20
20
|
import "../chunk-6JHKKLA2.js";
|
|
21
21
|
import {
|
|
22
22
|
githubRepositoryFullName,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
requireDurableIngestAcknowledgement
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-LEUZDTNT.js";
|
|
5
5
|
import {
|
|
6
6
|
enrichHookPayloadWithFileRefs,
|
|
7
7
|
preserveHookFileMetadata
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-RLBASQJD.js";
|
|
9
9
|
import {
|
|
10
10
|
postToolInvocationId,
|
|
11
11
|
toMove,
|
|
12
12
|
toolOutcomeFor
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-S55JKCHQ.js";
|
|
14
14
|
import {
|
|
15
15
|
getOrCreateWorkspaceId
|
|
16
16
|
} from "../chunk-EZXEWFDG.js";
|
|
@@ -20,21 +20,21 @@ import {
|
|
|
20
20
|
} from "../chunk-HMD5K6W7.js";
|
|
21
21
|
import {
|
|
22
22
|
observeDemoInvocation
|
|
23
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-CXMLAWC2.js";
|
|
24
24
|
import {
|
|
25
25
|
appendCodexContext,
|
|
26
26
|
prepareCodexContext
|
|
27
|
-
} from "../chunk-
|
|
28
|
-
import "../chunk-
|
|
29
|
-
import "../chunk-
|
|
27
|
+
} from "../chunk-LLKJAET2.js";
|
|
28
|
+
import "../chunk-I3J344DF.js";
|
|
29
|
+
import "../chunk-4SN5BCIG.js";
|
|
30
30
|
import {
|
|
31
31
|
scrubFromCwd
|
|
32
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-6IRAGUYK.js";
|
|
33
33
|
import {
|
|
34
34
|
bold,
|
|
35
35
|
cachedCollectScopeAdmits,
|
|
36
36
|
color
|
|
37
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-3TIKBQHV.js";
|
|
38
38
|
import {
|
|
39
39
|
getClient,
|
|
40
40
|
terminalSafeLine
|
|
@@ -44,8 +44,8 @@ import {
|
|
|
44
44
|
parseAgent,
|
|
45
45
|
readHookStdin,
|
|
46
46
|
shouldSuppressImportedCursorHandler
|
|
47
|
-
} from "../chunk-
|
|
48
|
-
import "../chunk-
|
|
47
|
+
} from "../chunk-4OEJ2ONG.js";
|
|
48
|
+
import "../chunk-JKO6PZWQ.js";
|
|
49
49
|
import "../chunk-J5HBSRAV.js";
|
|
50
50
|
import {
|
|
51
51
|
currentBranch,
|
|
@@ -1,50 +1,56 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
PREFLIGHT_PROTOCOL_VERSION,
|
|
4
|
+
PREFLIGHT_WAIT_MS,
|
|
5
|
+
PreflightPausedError,
|
|
6
|
+
boundedClientVersion,
|
|
7
|
+
editPreview,
|
|
8
|
+
hasCompleteCoverage,
|
|
9
|
+
pausedResult,
|
|
10
|
+
proposalFor,
|
|
11
|
+
proposalIsTruncated,
|
|
12
|
+
resolvePreflightTargets,
|
|
13
|
+
resultForPreflight,
|
|
14
|
+
toolInputDigest,
|
|
15
|
+
waitForPreflight
|
|
16
|
+
} from "../chunk-D3ZDZZYS.js";
|
|
17
|
+
import {
|
|
18
|
+
observeDemoInvocation
|
|
19
|
+
} from "../chunk-CXMLAWC2.js";
|
|
20
|
+
import {
|
|
21
|
+
appendCodexContext,
|
|
22
|
+
hasVisibleCodexMessage,
|
|
23
|
+
prepareCodexContext
|
|
24
|
+
} from "../chunk-LLKJAET2.js";
|
|
25
|
+
import {
|
|
4
26
|
buildCodexOutput,
|
|
5
27
|
buildCursorOutput,
|
|
6
28
|
buildHermesOutput,
|
|
7
29
|
buildHookOutput,
|
|
8
30
|
demoteForMode,
|
|
9
|
-
extractFileTargets,
|
|
10
31
|
failOpenCodex,
|
|
11
32
|
failOpenCursor,
|
|
12
33
|
failOpenHermes,
|
|
13
34
|
failOpenOutput,
|
|
14
|
-
observeDemoInvocation,
|
|
15
35
|
readHookMode
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
hasVisibleCodexMessage,
|
|
20
|
-
prepareCodexContext
|
|
21
|
-
} from "../chunk-PJW6JZMH.js";
|
|
22
|
-
import "../chunk-JDIAPBY7.js";
|
|
23
|
-
import "../chunk-DWAXFXDG.js";
|
|
36
|
+
} from "../chunk-I3J344DF.js";
|
|
37
|
+
import "../chunk-4SN5BCIG.js";
|
|
38
|
+
import "../chunk-6IRAGUYK.js";
|
|
24
39
|
import {
|
|
25
|
-
DEFAULT_RULES,
|
|
26
|
-
scrub
|
|
27
|
-
} from "../chunk-3KKEV7VI.js";
|
|
28
|
-
import {
|
|
29
|
-
boundedHealthError,
|
|
30
40
|
cachedCollectScopeAdmits
|
|
31
|
-
} from "../chunk-
|
|
41
|
+
} from "../chunk-3TIKBQHV.js";
|
|
32
42
|
import {
|
|
33
|
-
HttpError
|
|
34
|
-
getClient,
|
|
35
|
-
terminalSafeLine
|
|
43
|
+
HttpError
|
|
36
44
|
} from "../chunk-6JHKKLA2.js";
|
|
37
45
|
import {
|
|
38
46
|
normalizeEnvelope,
|
|
39
47
|
parseAgent,
|
|
40
48
|
readHookStdin,
|
|
41
49
|
shouldSuppressImportedCursorHandler
|
|
42
|
-
} from "../chunk-
|
|
43
|
-
import "../chunk-
|
|
50
|
+
} from "../chunk-4OEJ2ONG.js";
|
|
51
|
+
import "../chunk-JKO6PZWQ.js";
|
|
44
52
|
import "../chunk-J5HBSRAV.js";
|
|
45
53
|
import {
|
|
46
|
-
canonicalGitRoot,
|
|
47
|
-
canonicalRepositoryPath,
|
|
48
54
|
currentBranch,
|
|
49
55
|
githubRepositoryFullName,
|
|
50
56
|
isRepoActive,
|
|
@@ -53,246 +59,11 @@ import {
|
|
|
53
59
|
resolveAuthCredential
|
|
54
60
|
} from "../chunk-XG7S3LIL.js";
|
|
55
61
|
|
|
56
|
-
// src/hooks/approval-copy.ts
|
|
57
|
-
var MAX_EXCERPT_CHARS = 80;
|
|
58
|
-
var MAX_TITLE_CHARS = 140;
|
|
59
|
-
var MAX_PATH_CHARS = 120;
|
|
60
|
-
var MAX_VISIBLE_CONFLICTS = 3;
|
|
61
|
-
function displayText(value, maxChars) {
|
|
62
|
-
const redacted = scrub(value, DEFAULT_RULES);
|
|
63
|
-
const clean = terminalSafeLine(typeof redacted === "string" ? redacted : "");
|
|
64
|
-
const characters = Array.from(clean);
|
|
65
|
-
return characters.length > maxChars ? `${characters.slice(0, maxChars - 1).join("")}\u2026` : clean;
|
|
66
|
-
}
|
|
67
|
-
function targetLabel(paths) {
|
|
68
|
-
const shown = paths.slice(0, 2).map((path) => `\u201C${displayText(path, MAX_PATH_CHARS)}\u201D`);
|
|
69
|
-
if (shown.length === 0) return "the requested change";
|
|
70
|
-
const remaining = paths.length - shown.length;
|
|
71
|
-
return `${shown.join(" and ")}${remaining > 0 ? ` and ${remaining} more file(s)` : ""}`;
|
|
72
|
-
}
|
|
73
|
-
function editPreview(toolName, toolInput, paths) {
|
|
74
|
-
const input = toolInput && typeof toolInput === "object" ? toolInput : {};
|
|
75
|
-
const targets = targetLabel(paths);
|
|
76
|
-
if (toolName === "Edit") {
|
|
77
|
-
const before = typeof input.old_string === "string" ? displayText(input.old_string, MAX_EXCERPT_CHARS) : "";
|
|
78
|
-
const after = typeof input.new_string === "string" ? displayText(input.new_string, MAX_EXCERPT_CHARS) : "";
|
|
79
|
-
return before && after ? `Edit ${targets}:
|
|
80
|
-
Current text: \u201C${before}\u201D
|
|
81
|
-
Proposed replacement: \u201C${after}\u201D` : `Edit ${targets}.`;
|
|
82
|
-
}
|
|
83
|
-
if (toolName === "Write" || toolName === "NotebookEdit") return `Write ${targets}.`;
|
|
84
|
-
if (toolName === "Bash" || toolName === "Shell") return `Run a command affecting ${targets}.`;
|
|
85
|
-
return `Change ${targets}.`;
|
|
86
|
-
}
|
|
87
|
-
function decisionLabel(conflict) {
|
|
88
|
-
const id = typeof conflict.shortId === "string" && /^[0-9a-f]{8}$/u.test(conflict.shortId) ? `dec_${conflict.shortId}` : typeof conflict.decisionId === "string" && /^dec_[0-9a-f]{8}$/u.test(conflict.decisionId) ? conflict.decisionId : "unknown";
|
|
89
|
-
const title = typeof conflict.title === "string" ? displayText(conflict.title, MAX_TITLE_CHARS) : "";
|
|
90
|
-
return title ? `Decision ${id}: \u201C${title}\u201D.` : `Decision ${id}: details unavailable; inspect it before approving.`;
|
|
91
|
-
}
|
|
92
|
-
function incomplete(evidence) {
|
|
93
|
-
const coverage = evidence.evaluationCoverage;
|
|
94
|
-
return Array.isArray(coverage?.selectionOmissions) && coverage.selectionOmissions.length > 0 || Array.isArray(coverage?.evidenceOmissions) && coverage.evidenceOmissions.length > 0 || coverage?.status !== void 0 && coverage.status !== "completed" || ["candidate_set_truncated", "evidence_incomplete", "coverage_unverified"].includes(
|
|
95
|
-
evidence.reasonCode
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
function approvalSummary(evidence, preview) {
|
|
99
|
-
const lines = [preview];
|
|
100
|
-
if (evidence.conflicts.length > 0) {
|
|
101
|
-
lines.push("Primitive found a conflict with an existing decision.");
|
|
102
|
-
lines.push(...evidence.conflicts.slice(0, MAX_VISIBLE_CONFLICTS).map(decisionLabel));
|
|
103
|
-
const remaining = evidence.conflicts.length - MAX_VISIBLE_CONFLICTS;
|
|
104
|
-
if (remaining > 0) lines.push(`${remaining} more conflicting decision(s) need inspection.`);
|
|
105
|
-
} else {
|
|
106
|
-
lines.push(
|
|
107
|
-
displayText(evidence.message || "Primitive requires review before this change.", 180)
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if (incomplete(evidence)) {
|
|
111
|
-
lines.push("Some potentially applicable decisions were not fully checked.");
|
|
112
|
-
}
|
|
113
|
-
return lines.filter(Boolean).join("\n");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/hooks/preflight-v3.ts
|
|
117
|
-
import { Buffer } from "buffer";
|
|
118
|
-
var PREFLIGHT_PROTOCOL_VERSION = 3;
|
|
119
|
-
var PREFLIGHT_TIMEOUT_MS = 12e3;
|
|
120
|
-
var MAX_PREFLIGHT_PATHS = 32;
|
|
121
|
-
var MAX_PROPOSAL_BYTES = 6144;
|
|
122
|
-
var MAX_CLIENT_VERSION_CHARS = 32;
|
|
123
|
-
var CLIENT_VERSION_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
124
|
-
var MAX_DECISION_DISCLOSURES = 16;
|
|
125
|
-
var DISCLOSED_DECISION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
126
|
-
var DISCLOSED_DECISION_SHORT_ID_RE = /^[0-9a-f]{8}$/u;
|
|
127
|
-
function boundedClientVersion(raw) {
|
|
128
|
-
return typeof raw === "string" && raw.length <= MAX_CLIENT_VERSION_CHARS && CLIENT_VERSION_RE.test(raw) ? raw : "unknown";
|
|
129
|
-
}
|
|
130
|
-
function resolvePreflightTargets(args) {
|
|
131
|
-
let rawPaths;
|
|
132
|
-
let coverage = "complete";
|
|
133
|
-
let mutation = "present";
|
|
134
|
-
let definite = false;
|
|
135
|
-
const shellTool = (args.agent === "claude_code" || args.agent === "codex") && args.toolName === "Bash" || args.agent === "cursor" && args.toolName === "Shell";
|
|
136
|
-
if (shellTool) {
|
|
137
|
-
const command = typeof args.toolInput === "string" ? args.toolInput : args.toolInput && typeof args.toolInput === "object" ? args.toolInput.command : void 0;
|
|
138
|
-
if (typeof command !== "string") {
|
|
139
|
-
return { paths: [], coverage: "unverified", mutation: "present" };
|
|
140
|
-
}
|
|
141
|
-
const shell = analyzeShellTargets(command);
|
|
142
|
-
rawPaths = shell.paths;
|
|
143
|
-
coverage = shell.coverage;
|
|
144
|
-
mutation = shell.mutation;
|
|
145
|
-
definite = shell.definiteEdit === true;
|
|
146
|
-
} else {
|
|
147
|
-
const extracted = extractFileTargets(args.toolName, args.toolInput, args.agent);
|
|
148
|
-
if (!extracted) return { paths: [], coverage: "complete", mutation: "none" };
|
|
149
|
-
rawPaths = extracted.paths;
|
|
150
|
-
if (!extracted.complete) coverage = "unverified";
|
|
151
|
-
definite = true;
|
|
152
|
-
}
|
|
153
|
-
const root = canonicalGitRoot(args.cwd);
|
|
154
|
-
const paths = /* @__PURE__ */ new Set();
|
|
155
|
-
for (const rawPath of rawPaths) {
|
|
156
|
-
const canonical = canonicalRepositoryPath(rawPath, args.cwd, root);
|
|
157
|
-
if (canonical) paths.add(canonical);
|
|
158
|
-
else coverage = "unverified";
|
|
159
|
-
}
|
|
160
|
-
const bounded = [...paths];
|
|
161
|
-
if (bounded.length > MAX_PREFLIGHT_PATHS) coverage = "unverified";
|
|
162
|
-
const resolved = bounded.slice(0, MAX_PREFLIGHT_PATHS);
|
|
163
|
-
if (definite && resolved.length === 0 && mutation === "present") {
|
|
164
|
-
return { paths: resolved, coverage: "unverified", mutation, definite: true };
|
|
165
|
-
}
|
|
166
|
-
return { paths: resolved, coverage, mutation };
|
|
167
|
-
}
|
|
168
|
-
function truncateUtf8(value, maxBytes) {
|
|
169
|
-
const encoded = Buffer.from(value);
|
|
170
|
-
if (encoded.byteLength <= maxBytes) return value;
|
|
171
|
-
return encoded.subarray(0, maxBytes).toString("utf8").replace(/\uFFFD$/u, "");
|
|
172
|
-
}
|
|
173
|
-
function proposalFor(toolInput) {
|
|
174
|
-
const redacted = scrub(toolInput, DEFAULT_RULES);
|
|
175
|
-
return truncateUtf8(JSON.stringify(redacted) ?? "", MAX_PROPOSAL_BYTES);
|
|
176
|
-
}
|
|
177
|
-
function proposalIsTruncated(toolInput) {
|
|
178
|
-
return Buffer.byteLength(JSON.stringify(scrub(toolInput, DEFAULT_RULES)) ?? "") > MAX_PROPOSAL_BYTES;
|
|
179
|
-
}
|
|
180
|
-
function parsePreflightResponse(value) {
|
|
181
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
182
|
-
const response = value;
|
|
183
|
-
const verdicts = /* @__PURE__ */ new Set(["allow", "warn", "ask", "block", "unavailable"]);
|
|
184
|
-
if (response.protocolVersion !== PREFLIGHT_PROTOCOL_VERSION || typeof response.verdict !== "string" || !verdicts.has(response.verdict) || typeof response.reasonCode !== "string" || typeof response.message !== "string" || !Array.isArray(response.conflicts) || !Array.isArray(response.bypassed)) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
if (response.checkId !== void 0 && (typeof response.checkId !== "string" || !DISCLOSED_DECISION_ID_RE.test(response.checkId)))
|
|
188
|
-
return null;
|
|
189
|
-
const disclosures = response.decisionDisclosures;
|
|
190
|
-
if (disclosures !== void 0) {
|
|
191
|
-
if (!Array.isArray(disclosures) || disclosures.length === 0 || disclosures.length > MAX_DECISION_DISCLOSURES) {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
const seen = /* @__PURE__ */ new Set();
|
|
195
|
-
for (const value2 of disclosures) {
|
|
196
|
-
if (!value2 || typeof value2 !== "object" || Array.isArray(value2)) return null;
|
|
197
|
-
const disclosure = value2;
|
|
198
|
-
if (Object.keys(disclosure).length !== 3 || !Object.hasOwn(disclosure, "decisionId") || !Object.hasOwn(disclosure, "shortId") || !Object.hasOwn(disclosure, "participation") || typeof disclosure.decisionId !== "string" || !DISCLOSED_DECISION_ID_RE.test(disclosure.decisionId) || typeof disclosure.shortId !== "string" || !DISCLOSED_DECISION_SHORT_ID_RE.test(disclosure.shortId) || disclosure.participation !== "candidate" && disclosure.participation !== "reconcile_bypass" || seen.has(disclosure.decisionId)) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
seen.add(disclosure.decisionId);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return response;
|
|
205
|
-
}
|
|
206
|
-
function decisionDisclosureContext(response) {
|
|
207
|
-
return response.decisionDisclosures?.map(({ decisionId }) => `[primitive] hidden Decision: prim decisions show ${decisionId}`).join("\n") ?? "";
|
|
208
|
-
}
|
|
209
|
-
async function requestPreflight(request, signal = AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS)) {
|
|
210
|
-
const response = await getClient().post("/api/cli/decisions/conflict-check", request, {
|
|
211
|
-
signal,
|
|
212
|
-
quietRefresh: true
|
|
213
|
-
});
|
|
214
|
-
return parsePreflightResponse(response);
|
|
215
|
-
}
|
|
216
|
-
function proposedChangeExcerpt(proposal) {
|
|
217
|
-
try {
|
|
218
|
-
const input = JSON.parse(proposal);
|
|
219
|
-
if (input && typeof input === "object") {
|
|
220
|
-
for (const key of ["new_string", "new_str", "content", "command"]) {
|
|
221
|
-
if (typeof input[key] === "string") return boundedHealthError(input[key]);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
} catch {
|
|
225
|
-
}
|
|
226
|
-
return boundedHealthError(proposal);
|
|
227
|
-
}
|
|
228
|
-
function resultForPreflight(response, preview = "Review the requested change.", invocation, proposalTruncated = false) {
|
|
229
|
-
const verdict = response.verdict === "block" ? "deny" : response.verdict;
|
|
230
|
-
const message = boundedHealthError(response.message) ?? "";
|
|
231
|
-
const unavailable = message || boundedHealthError(response.reasonCode);
|
|
232
|
-
const safe = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
233
|
-
const directives = response.conflicts.flatMap((value) => {
|
|
234
|
-
if (!value || typeof value !== "object") return [];
|
|
235
|
-
const { decisionId, shortId, title } = value;
|
|
236
|
-
const id = typeof shortId === "string" && /^[0-9a-f]{8}$/u.test(shortId) ? `dec_${shortId}` : typeof decisionId === "string" && /^dec_[0-9a-f]{8}$/u.test(decisionId) ? decisionId : void 0;
|
|
237
|
-
if (!id) return [];
|
|
238
|
-
return [
|
|
239
|
-
`Governing Decision ${id}${typeof title === "string" && boundedHealthError(title) ? `: ${boundedHealthError(title)}` : ""}.`,
|
|
240
|
-
...response.checkId && safe.test(response.checkId) ? [
|
|
241
|
-
`Check: ${response.checkId}. After resolving, record the confirmed outcome: prim reconcile ${id} --check ${response.checkId} --outcome followed (retained Decision), or --outcome superseded (after replacing it). Recording a resolution does not authorize an override.`
|
|
242
|
-
] : []
|
|
243
|
-
];
|
|
244
|
-
});
|
|
245
|
-
const blocked = response.verdict === "ask" || response.verdict === "block";
|
|
246
|
-
const proposal = invocation ? proposedChangeExcerpt(invocation.proposal) : void 0;
|
|
247
|
-
const editContext = blocked && invocation ? [
|
|
248
|
-
`Proposed edit to: ${invocation.paths.map((path) => boundedHealthError(path)).join(", ")}.`,
|
|
249
|
-
...proposal ? [`Proposed change (excerpt): ${proposal}`] : []
|
|
250
|
-
] : [];
|
|
251
|
-
const approvalContext = blocked ? [
|
|
252
|
-
"Overriding these Decisions requires explicit human approval naming each Decision and the proposed conflicting edit.",
|
|
253
|
-
"Reconcile bypasses are disabled: this host integration cannot provide verifiable human approval for a bypass. Keep the edit blocked and choose a compatible change.",
|
|
254
|
-
"Sandbox escalation, automatic review, prefix permissions, --yes, and an agent's assertion of approval do not authorize an override."
|
|
255
|
-
] : [];
|
|
256
|
-
const guidance = [message, ...editContext, ...new Set(directives), ...approvalContext].filter(Boolean).join("\n");
|
|
257
|
-
const reason = response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
|
|
258
|
-
{
|
|
259
|
-
conflicts: response.conflicts,
|
|
260
|
-
message,
|
|
261
|
-
reasonCode: response.reasonCode,
|
|
262
|
-
evaluationCoverage: response.evaluationCoverage
|
|
263
|
-
},
|
|
264
|
-
preview
|
|
265
|
-
) : message;
|
|
266
|
-
const disclosureContext = decisionDisclosureContext(response);
|
|
267
|
-
const truncationNote = proposalTruncated ? "[primitive] shell proposal was truncated; the complete change was not verified" : "";
|
|
268
|
-
return {
|
|
269
|
-
verdict,
|
|
270
|
-
conflicts: response.conflicts,
|
|
271
|
-
reason: [reason, truncationNote].filter(Boolean).join("\n"),
|
|
272
|
-
additionalContext: [
|
|
273
|
-
disclosureContext,
|
|
274
|
-
truncationNote,
|
|
275
|
-
["warn", "ask", "block"].includes(response.verdict) ? guidance : ""
|
|
276
|
-
].filter(Boolean).join("\n"),
|
|
277
|
-
truncated: false,
|
|
278
|
-
unavailable: response.verdict === "unavailable" ? unavailable : void 0
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function unverifiedResult(message) {
|
|
282
|
-
return {
|
|
283
|
-
verdict: "unavailable",
|
|
284
|
-
conflicts: [],
|
|
285
|
-
reason: "",
|
|
286
|
-
additionalContext: "",
|
|
287
|
-
truncated: false,
|
|
288
|
-
unavailable: message
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
62
|
// src/hooks/pre-tool-use.ts
|
|
293
63
|
var STDIN_TIMEOUT_MS = 1e3;
|
|
64
|
+
var deadline = performance.now() + Math.max(0, PREFLIGHT_WAIT_MS - Math.ceil(process.uptime() * 1e3));
|
|
65
|
+
var activeMutation = false;
|
|
294
66
|
var agent = parseAgent(process.argv);
|
|
295
|
-
var uncheckedMutation;
|
|
296
67
|
async function emit(output) {
|
|
297
68
|
return await new Promise((resolve) => {
|
|
298
69
|
try {
|
|
@@ -337,52 +108,41 @@ function preflightFailure(error) {
|
|
|
337
108
|
}
|
|
338
109
|
return "authentication required; run `prim auth login`; change was not verified";
|
|
339
110
|
}
|
|
340
|
-
async function emitUnverified(message,
|
|
341
|
-
const result =
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
`);
|
|
345
|
-
await emit(failOpenHermes());
|
|
346
|
-
} else if (agent === "cursor") {
|
|
347
|
-
process.stderr.write(`[primitive] ${message}
|
|
348
|
-
`);
|
|
349
|
-
await emit(buildCursorOutput("allow", [result]));
|
|
350
|
-
} else {
|
|
351
|
-
let output = agent === "codex" ? buildCodexOutput("allow", [result]) : buildHookOutput("allow", [result]);
|
|
352
|
-
if (agent === "codex" && typeof envelope?.session_id === "string" && envelope.session_id) {
|
|
353
|
-
try {
|
|
354
|
-
const context = await prepareCodexContext({
|
|
355
|
-
cwd: envelope.cwd ?? process.cwd(),
|
|
356
|
-
sessionId: envelope.session_id,
|
|
357
|
-
includeDigest: false
|
|
358
|
-
});
|
|
359
|
-
output = appendCodexContext(output, context.context);
|
|
360
|
-
await emitWithAcknowledgment(output, context.acknowledge);
|
|
361
|
-
return;
|
|
362
|
-
} catch {
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
await emit(output);
|
|
366
|
-
}
|
|
111
|
+
async function emitUnverified(message, checkId) {
|
|
112
|
+
const result = pausedResult(message, checkId);
|
|
113
|
+
const output = agent === "hermes" ? buildHermesOutput("deny", [result]) : agent === "cursor" ? buildCursorOutput("deny", [result]) : agent === "codex" ? buildCodexOutput("deny", [result]) : buildHookOutput("deny", [result]);
|
|
114
|
+
await emit(output);
|
|
367
115
|
}
|
|
368
116
|
async function main() {
|
|
117
|
+
const mode = readHookMode(process.env);
|
|
118
|
+
if (mode === "off") {
|
|
119
|
+
await emit(failOpen());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
369
122
|
let raw;
|
|
370
123
|
try {
|
|
371
124
|
raw = await readHookStdin(STDIN_TIMEOUT_MS);
|
|
372
125
|
} catch {
|
|
373
|
-
await
|
|
126
|
+
await emitUnverified("The tool input could not be read completely");
|
|
374
127
|
return;
|
|
375
128
|
}
|
|
376
129
|
let envelope;
|
|
377
130
|
try {
|
|
378
131
|
const incoming = JSON.parse(raw);
|
|
379
|
-
if (
|
|
132
|
+
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) {
|
|
133
|
+
throw new Error("The hook envelope must be an object");
|
|
134
|
+
}
|
|
135
|
+
const fields = incoming;
|
|
136
|
+
if (agent !== "cursor" && shouldSuppressImportedCursorHandler(fields, "prim-pre-tool-use")) {
|
|
380
137
|
await emit(failOpenCursor());
|
|
381
138
|
return;
|
|
382
139
|
}
|
|
383
|
-
envelope = normalizeEnvelope(
|
|
140
|
+
envelope = normalizeEnvelope(fields, agent);
|
|
141
|
+
if (typeof envelope.hook_event_name !== "string" || !envelope.hook_event_name) {
|
|
142
|
+
throw new Error("The hook event identity is unavailable");
|
|
143
|
+
}
|
|
384
144
|
} catch {
|
|
385
|
-
await
|
|
145
|
+
await emitUnverified("The tool invocation could not be identified safely");
|
|
386
146
|
return;
|
|
387
147
|
}
|
|
388
148
|
try {
|
|
@@ -396,13 +156,11 @@ async function main() {
|
|
|
396
156
|
await emit(failOpen());
|
|
397
157
|
return;
|
|
398
158
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (mode === "off") {
|
|
402
|
-
await emit(failOpen());
|
|
159
|
+
if (typeof envelope.tool_name !== "string" || !envelope.tool_name) {
|
|
160
|
+
await emitUnverified("The tool invocation is missing its tool identity");
|
|
403
161
|
return;
|
|
404
162
|
}
|
|
405
|
-
const toolName =
|
|
163
|
+
const toolName = envelope.tool_name;
|
|
406
164
|
const cwd = typeof envelope.cwd === "string" && envelope.cwd.length > 0 ? envelope.cwd : process.cwd();
|
|
407
165
|
const targets = resolvePreflightTargets({
|
|
408
166
|
toolName,
|
|
@@ -418,16 +176,13 @@ async function main() {
|
|
|
418
176
|
await emit(failOpen());
|
|
419
177
|
return;
|
|
420
178
|
}
|
|
421
|
-
|
|
179
|
+
activeMutation = true;
|
|
422
180
|
if (targets.paths.length === 0 && !targets.definite) {
|
|
423
|
-
await
|
|
424
|
-
"shell command write targets could not be determined; change was not verified",
|
|
425
|
-
envelope
|
|
426
|
-
);
|
|
181
|
+
await emit(failOpen());
|
|
427
182
|
return;
|
|
428
183
|
}
|
|
429
184
|
if (agent === "cursor" && targets.coverage === "unverified") {
|
|
430
|
-
await emitUnverified("tool targets were ambiguous or outside the active repository"
|
|
185
|
+
await emitUnverified("tool targets were ambiguous or outside the active repository");
|
|
431
186
|
return;
|
|
432
187
|
}
|
|
433
188
|
const binding = repoSyncId(cwd);
|
|
@@ -436,8 +191,7 @@ async function main() {
|
|
|
436
191
|
const callId = invocationId(envelope);
|
|
437
192
|
if (!binding || typeof sessionId !== "string" || !sessionId || !callId) {
|
|
438
193
|
await emitUnverified(
|
|
439
|
-
"GitHub repo connection is required for repository-specific file attribution, Conflict Gate verification, and commit correlation; or tool invocation identity is unavailable"
|
|
440
|
-
envelope
|
|
194
|
+
"GitHub repo connection is required for repository-specific file attribution, Conflict Gate verification, and commit correlation; or tool invocation identity is unavailable"
|
|
441
195
|
);
|
|
442
196
|
return;
|
|
443
197
|
}
|
|
@@ -450,6 +204,8 @@ async function main() {
|
|
|
450
204
|
});
|
|
451
205
|
const request = {
|
|
452
206
|
protocolVersion: PREFLIGHT_PROTOCOL_VERSION,
|
|
207
|
+
operation: "start",
|
|
208
|
+
toolInputDigest: toolInputDigest(toolName, envelope.tool_input),
|
|
453
209
|
agent,
|
|
454
210
|
clientMode: mode,
|
|
455
211
|
clientVersion: boundedClientVersion(packageVersion()),
|
|
@@ -463,9 +219,17 @@ async function main() {
|
|
|
463
219
|
};
|
|
464
220
|
let result;
|
|
465
221
|
try {
|
|
466
|
-
const response = await
|
|
467
|
-
|
|
468
|
-
|
|
222
|
+
const response = await waitForPreflight(request, {
|
|
223
|
+
deadline,
|
|
224
|
+
onProgress: ({ evaluationCoverage: coverage }) => {
|
|
225
|
+
process.stderr.write(
|
|
226
|
+
`[primitive] Checking Decisions: ${coverage.evaluatedCount + coverage.bypassedCount}/${coverage.candidateCount}${coverage.discoveryComplete ? "" : "+"} covered.
|
|
227
|
+
`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
if (!hasCompleteCoverage(response)) {
|
|
232
|
+
await emitUnverified(response.message || response.reasonCode, response.checkId);
|
|
469
233
|
return;
|
|
470
234
|
}
|
|
471
235
|
result = resultForPreflight(
|
|
@@ -475,13 +239,13 @@ async function main() {
|
|
|
475
239
|
collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(envelope.tool_input)
|
|
476
240
|
);
|
|
477
241
|
} catch (error) {
|
|
478
|
-
await emitUnverified(
|
|
242
|
+
await emitUnverified(
|
|
243
|
+
error instanceof PreflightPausedError ? error.message : preflightFailure(error),
|
|
244
|
+
error instanceof PreflightPausedError ? error.checkId : void 0
|
|
245
|
+
);
|
|
479
246
|
return;
|
|
480
247
|
}
|
|
481
|
-
const aggregate = demoteForMode(
|
|
482
|
-
result.verdict === "unavailable" ? "allow" : result.verdict,
|
|
483
|
-
mode
|
|
484
|
-
);
|
|
248
|
+
const aggregate = demoteForMode(result.verdict === "unavailable" ? "deny" : result.verdict, mode);
|
|
485
249
|
if (agent === "hermes" && aggregate !== "deny" && aggregate !== "ask") {
|
|
486
250
|
const advisory = hermesAdvisory(result, aggregate);
|
|
487
251
|
if (advisory) process.stderr.write(`${advisory}
|
|
@@ -500,10 +264,6 @@ async function main() {
|
|
|
500
264
|
await emit(output);
|
|
501
265
|
}
|
|
502
266
|
main().catch(async () => {
|
|
503
|
-
if (
|
|
504
|
-
await emitUnverified(
|
|
505
|
-
"hook failed while checking a possible write; change was not verified",
|
|
506
|
-
uncheckedMutation
|
|
507
|
-
);
|
|
267
|
+
if (activeMutation) await emitUnverified("The Decision check could not complete");
|
|
508
268
|
else await emit(failOpen());
|
|
509
269
|
});
|
package/dist/hooks/prim-hook.js
CHANGED
|
@@ -18,12 +18,12 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
enrichHookPayloadWithFileRefs,
|
|
20
20
|
preserveHookFileMetadata
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-RLBASQJD.js";
|
|
22
22
|
import {
|
|
23
23
|
postToolInvocationId,
|
|
24
24
|
shouldFlushAfter,
|
|
25
25
|
toMove
|
|
26
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-S55JKCHQ.js";
|
|
27
27
|
import {
|
|
28
28
|
getOrCreateWorkspaceId
|
|
29
29
|
} from "../chunk-EZXEWFDG.js";
|
|
@@ -33,27 +33,27 @@ import {
|
|
|
33
33
|
} from "../chunk-HMD5K6W7.js";
|
|
34
34
|
import {
|
|
35
35
|
observeDemoInvocation
|
|
36
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-CXMLAWC2.js";
|
|
37
37
|
import {
|
|
38
38
|
prepareCodexContext
|
|
39
|
-
} from "../chunk-
|
|
40
|
-
import "../chunk-
|
|
41
|
-
import "../chunk-
|
|
39
|
+
} from "../chunk-LLKJAET2.js";
|
|
40
|
+
import "../chunk-I3J344DF.js";
|
|
41
|
+
import "../chunk-4SN5BCIG.js";
|
|
42
42
|
import {
|
|
43
43
|
scrubFromCwd,
|
|
44
44
|
writeHookDebug
|
|
45
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-6IRAGUYK.js";
|
|
46
46
|
import {
|
|
47
47
|
cachedCollectScopeAdmits
|
|
48
|
-
} from "../chunk-
|
|
48
|
+
} from "../chunk-3TIKBQHV.js";
|
|
49
49
|
import "../chunk-6JHKKLA2.js";
|
|
50
50
|
import {
|
|
51
51
|
normalizeEnvelope,
|
|
52
52
|
parseAgent,
|
|
53
53
|
readHookStdin,
|
|
54
54
|
shouldSuppressImportedCursorHandler
|
|
55
|
-
} from "../chunk-
|
|
56
|
-
import "../chunk-
|
|
55
|
+
} from "../chunk-4OEJ2ONG.js";
|
|
56
|
+
import "../chunk-JKO6PZWQ.js";
|
|
57
57
|
import "../chunk-J5HBSRAV.js";
|
|
58
58
|
import {
|
|
59
59
|
currentBranch,
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
parseAgent,
|
|
5
5
|
readHookStdin,
|
|
6
6
|
shouldSuppressImportedCursorHandler
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-4OEJ2ONG.js";
|
|
8
|
+
import "../chunk-JKO6PZWQ.js";
|
|
9
9
|
import {
|
|
10
10
|
daemonRequest
|
|
11
11
|
} from "../chunk-J5HBSRAV.js";
|