@primitive.ai/prim 0.1.0-alpha.114 → 0.1.0-alpha.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +62 -0
  2. package/SKILL.md +5 -3
  3. package/assets/primitive-gameplan/SKILL.md +134 -0
  4. package/assets/primitive-gameplan/claude-hooks.json +28 -0
  5. package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
  6. package/dist/{chunk-IZXLH3R5.js → chunk-3TIKBQHV.js} +2584 -821
  7. package/dist/{chunk-NH3VC7YO.js → chunk-4OEJ2ONG.js} +1 -1
  8. package/dist/{chunk-DWAXFXDG.js → chunk-4SN5BCIG.js} +1 -1
  9. package/dist/{chunk-3KKEV7VI.js → chunk-6IRAGUYK.js} +1 -1
  10. package/dist/chunk-CXMLAWC2.js +96 -0
  11. package/dist/chunk-D3ZDZZYS.js +449 -0
  12. package/dist/{chunk-RUUSUF43.js → chunk-I3J344DF.js} +231 -94
  13. package/dist/{chunk-7DVEH7FO.js → chunk-JKJ22ONL.js} +1 -1
  14. package/dist/{chunk-PO5QAYD7.js → chunk-JKO6PZWQ.js} +119 -24
  15. package/dist/{chunk-BXLH4LDU.js → chunk-LEUZDTNT.js} +1 -1
  16. package/dist/{chunk-PJW6JZMH.js → chunk-LLKJAET2.js} +1 -1
  17. package/dist/{chunk-IMYELJIV.js → chunk-RLBASQJD.js} +3 -3
  18. package/dist/{chunk-RTULPLS7.js → chunk-S55JKCHQ.js} +1 -1
  19. package/dist/daemon/server.js +2583 -822
  20. package/dist/hook-runtime/daemon/server.js +2583 -822
  21. package/dist/hook-runtime/hooks/post-commit.js +2581 -820
  22. package/dist/hook-runtime/hooks/post-rewrite.js +2581 -820
  23. package/dist/hook-runtime/hooks/post-tool-use.js +2689 -921
  24. package/dist/hook-runtime/hooks/pre-tool-use.js +2922 -985
  25. package/dist/hook-runtime/hooks/prim-hook.js +2682 -914
  26. package/dist/hook-runtime/hooks/session-end.js +19 -12
  27. package/dist/hook-runtime/hooks/session-start.js +2828 -1060
  28. package/dist/hook-runtime/index.js +23395 -12348
  29. package/dist/hooks/post-commit.js +3 -3
  30. package/dist/hooks/post-rewrite.js +3 -3
  31. package/dist/hooks/post-tool-use.js +11 -11
  32. package/dist/hooks/pre-tool-use.js +78 -316
  33. package/dist/hooks/prim-hook.js +10 -10
  34. package/dist/hooks/session-end.js +2 -2
  35. package/dist/hooks/session-start.js +6 -6
  36. package/dist/index.js +564 -157
  37. package/package.json +8 -1
  38. package/dist/chunk-JDIAPBY7.js +0 -233
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitive.ai/prim",
3
- "version": "0.1.0-alpha.114",
3
+ "version": "0.1.0-alpha.116",
4
4
  "description": "CLI for Primitive's decision graph — passive decision capture, conflict gate, and team presence",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "main": "./dist/index.js",
44
44
  "files": [
45
45
  "dist",
46
+ "assets",
46
47
  "LICENSE",
47
48
  "README.md",
48
49
  "SKILL.md"
@@ -53,6 +54,9 @@
53
54
  "contracts:check": "node scripts/generate-cli-contract.mjs --check",
54
55
  "contracts:provenance": "node scripts/update-cli-contract.mjs --check",
55
56
  "check:decision-identity-golden": "node scripts/check-decision-identity-golden.mjs",
57
+ "check:gameplan-companion": "node scripts/check-gameplan-companion.mjs",
58
+ "check:gameplan-e2e": "node scripts/check-gameplan-e2e.mjs",
59
+ "check:gameplan-package": "node scripts/check-gameplan-package.mjs",
56
60
  "check:approval-copy-golden": "node scripts/check-approval-copy-golden.mjs",
57
61
  "contracts:update": "node scripts/update-cli-contract.mjs",
58
62
  "postbuild": "chmod +x ./dist/index.js ./dist/statusline-main.js ./dist/hooks/pre-commit.js ./dist/hooks/post-commit.js ./dist/hooks/post-rewrite.js ./dist/hooks/prim-hook.js ./dist/hooks/pre-tool-use.js ./dist/hooks/post-tool-use.js ./dist/hooks/session-start.js ./dist/hooks/session-end.js ./dist/daemon/server.js && node scripts/check-hook-runtime.mjs",
@@ -64,6 +68,9 @@
64
68
  "typecheck": "tsc --noEmit",
65
69
  "check:reconcile-golden": "node scripts/check-reconcile-golden.mjs",
66
70
  "test": "vitest run",
71
+ "test:preflight-host": "node scripts/check-codex-preflight-host.mjs",
72
+ "test:preflight-host:claude": "node scripts/check-claude-preflight-host.mjs",
73
+ "test:preflight-v4": "node scripts/check-preflight-v4-e2e.mjs",
67
74
  "test:watch": "vitest",
68
75
  "test:coverage": "vitest run --coverage",
69
76
  "check:shell-targets-golden": "node scripts/check-shell-targets-golden.mjs"
@@ -1,233 +0,0 @@
1
- import {
2
- isDemoStatusResponse
3
- } from "./chunk-IZXLH3R5.js";
4
- import {
5
- inspectHookRuntime
6
- } from "./chunk-PO5QAYD7.js";
7
- import {
8
- atomicWriteFile,
9
- primConfigDirectory,
10
- withFileLock,
11
- withFileLockSync
12
- } from "./chunk-XG7S3LIL.js";
13
-
14
- // src/demo/state.ts
15
- import { createHash, randomUUID } from "crypto";
16
- import { existsSync, lstatSync, readFileSync, readdirSync } from "fs";
17
- import { join, resolve } from "path";
18
- var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
19
- var demoDirectory = () => join(primConfigDirectory(), "demo");
20
- var runPath = (id) => {
21
- if (!RUN_ID.test(id)) throw new Error("invalid demo run ID");
22
- return join(demoDirectory(), "runs", `${id}.json`);
23
- };
24
- function readDemoJson(path) {
25
- const stat = lstatSync(path);
26
- if (!stat.isFile() || stat.size > 16384) throw new Error(`invalid demo state: ${path}`);
27
- return JSON.parse(readFileSync(path, "utf8"));
28
- }
29
- function saveDemoJson(path, value) {
30
- atomicWriteFile(path, `${JSON.stringify(value)}
31
- `, { mode: 384, ensureParent: true });
32
- }
33
- function readRun(id) {
34
- const run = readDemoJson(runPath(id));
35
- if (![1, 2].includes(run.version) || run.id !== id || ![
36
- "prepared",
37
- "proposal",
38
- "conflict",
39
- "prompt",
40
- "approved",
41
- "applied",
42
- "cleanup",
43
- "completed",
44
- "skipped"
45
- ].includes(run.stage) || run.needsStatus !== void 0 && typeof run.needsStatus !== "boolean" || run.server !== void 0 && !isDemoStatusResponse(run.server) || run.receipt !== void 0 && (!Number.isSafeInteger(run.receipt.revision) || run.receipt.revision < 0 || !/^[a-f0-9]{64}$/u.test(run.receipt.appliedDigest)) || typeof run.terminal !== "boolean" || !Array.isArray(run.launcher) || run.launcher.length !== 2 || run.launcher.some((value) => typeof value !== "string" || !value.startsWith("/")) || run.agent !== void 0 && !["claude_code", "codex", "cursor", "hermes"].includes(run.agent)) {
46
- throw new Error("invalid demo run state");
47
- }
48
- return run;
49
- }
50
- var saveRun = (run) => saveDemoJson(runPath(run.id), run);
51
- var lockRun = (id, action) => withFileLockSync(`${runPath(id)}.lock`, () => action(readRun(id)), { timeoutMs: 500 });
52
- function prepareRun(agent, terminal = false) {
53
- const run = {
54
- version: 2,
55
- id: randomUUID(),
56
- stage: "prepared",
57
- terminal,
58
- agent,
59
- preparationKey: preparationKey(agent),
60
- launcher: [process.execPath, resolve(process.argv[1])]
61
- };
62
- saveRun(run);
63
- return run;
64
- }
65
- function preparationKey(agent) {
66
- return agent === "codex" && process.env.CODEX_THREAD_ID ? sessionKey(agent, `${process.env.CODEX_THREAD_ID}\0${process.cwd()}`) : void 0;
67
- }
68
- var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
69
- function demoCommand(run, action, choice, reason) {
70
- return [
71
- ...run.launcher,
72
- "demo",
73
- action,
74
- run.id,
75
- ...choice === void 0 ? [] : ["--choice", choice],
76
- ...reason === void 0 ? [] : ["--reason", reason]
77
- ].map(quote).join(" ");
78
- }
79
- function demoWelcomeCommand(run) {
80
- return [
81
- process.execPath,
82
- resolve(process.argv[1]),
83
- "welcome",
84
- "--after-demo",
85
- ...run.agent ? ["--agent", run.agent === "claude_code" ? "claude" : run.agent] : [],
86
- ...run.binding ? ["--capture-excluded"] : []
87
- ].map(quote).join(" ");
88
- }
89
- function demoDiagnosticCommand(run) {
90
- return [process.execPath, resolve(process.argv[1]), "demo", "status", run.id].map(quote).join(" ");
91
- }
92
- function demoResumeCommand(run) {
93
- return [process.execPath, resolve(process.argv[1]), "demo", "resume", run.id].map(quote).join(" ");
94
- }
95
- function onboardingFinished() {
96
- const path = join(demoDirectory(), "onboarding.json");
97
- if (!existsSync(path)) return false;
98
- const value = readDemoJson(path);
99
- if (value.outcome !== "completed" && value.outcome !== "skipped") {
100
- throw new Error("invalid local onboarding outcome");
101
- }
102
- return true;
103
- }
104
- function finishOnboarding(outcome) {
105
- saveDemoJson(join(demoDirectory(), "onboarding.json"), { outcome });
106
- }
107
- function pendingRuns() {
108
- const path = join(demoDirectory(), "runs");
109
- if (!existsSync(path)) return [];
110
- return readdirSync(path).filter((name) => name.endsWith(".json") && RUN_ID.test(name.slice(0, -5))).map((name) => name.slice(0, -5)).filter((id) => !["completed", "skipped"].includes(readRun(id).stage));
111
- }
112
- function sessionKey(agent, session) {
113
- return createHash("sha256").update(`${agent}\0${session}`).digest("hex");
114
- }
115
- function exclusionPath(key) {
116
- if (!/^[0-9a-f]{64}$/u.test(key)) throw new Error("invalid demo session identity");
117
- return join(demoDirectory(), "excluded-sessions", `${key}.json`);
118
- }
119
- function sessionExcluded(agent, session) {
120
- if (typeof session !== "string" || !session) return false;
121
- const path = exclusionPath(sessionKey(agent, session));
122
- if (!existsSync(path)) return false;
123
- const record = readDemoJson(path);
124
- if (typeof record.runId !== "string" || !RUN_ID.test(record.runId)) {
125
- throw new Error("invalid demo capture exclusion");
126
- }
127
- return true;
128
- }
129
- var lockRunAsync = (id, action) => withFileLock(`${runPath(id)}.lock`, () => action(readRun(id)), { timeoutMs: 500 });
130
- function demoArgv(command) {
131
- const result = [];
132
- let i = 0;
133
- while (i < command.length) {
134
- if (command[i++] !== "'") return;
135
- let value = "";
136
- let closed = false;
137
- while (i < command.length) {
138
- if (command.slice(i, i + 4) === "'\\''") {
139
- value += "'";
140
- i += 4;
141
- } else if (command[i] === "'") {
142
- i++;
143
- closed = true;
144
- break;
145
- } else {
146
- value += command[i++];
147
- }
148
- }
149
- if (!closed) return;
150
- result.push(value);
151
- if (i === command.length) return result;
152
- if (command[i++] !== " " || i === command.length) return;
153
- }
154
- }
155
-
156
- // src/demo/diagnostics.ts
157
- import { existsSync as existsSync2 } from "fs";
158
- import { join as join2 } from "path";
159
- var observationPath = (id) => join2(demoDirectory(), "observations", `${id}.json`);
160
- function observeRun(id, observation) {
161
- try {
162
- saveDemoJson(observationPath(id), observation);
163
- } catch {
164
- process.stderr.write(
165
- "[prim] demo isolation diagnostic could not be saved; check access to Primitive's configuration directory.\n"
166
- );
167
- }
168
- }
169
- function isolationDiagnostics(run) {
170
- let observation;
171
- let observationError;
172
- try {
173
- if (existsSync2(observationPath(run.id))) {
174
- const value = readDemoJson(observationPath(run.id));
175
- if (!value || !Number.isFinite(value.at) || !["claude_code", "codex", "cursor", "hermes"].includes(value.agent ?? "") || ![
176
- "acknowledged",
177
- "tool-mismatch",
178
- "command-mismatch",
179
- "session-mismatch",
180
- "session-missing",
181
- "write-failed"
182
- ].includes(value.result ?? "") || value.runtimeVersion !== void 0 && !/^[a-zA-Z0-9.+-]{1,80}$/u.test(value.runtimeVersion) || value.session !== void 0 && !/^[a-f0-9]{64}$/u.test(value.session) || value.errorCode !== void 0 && !/^[A-Z0-9_]{1,32}$/u.test(value.errorCode))
183
- throw new Error("invalid demo observation");
184
- observation = value;
185
- }
186
- } catch {
187
- observationError = "unreadable";
188
- }
189
- const expected = run.agent === "codex" && process.env.CODEX_THREAD_ID ? sessionKey(run.agent, process.env.CODEX_THREAD_ID) : void 0;
190
- return {
191
- runtime: inspectHookRuntime(),
192
- expectedEvent: "PreToolUse",
193
- expectedTool: run.agent === "cursor" ? "Shell" : run.agent === "hermes" ? "terminal" : "Bash",
194
- hookObservation: observation ? {
195
- at: observation.at,
196
- agent: observation.agent,
197
- runtimeVersion: observation.runtimeVersion ?? "unknown",
198
- result: observation.result,
199
- ageMs: Math.max(0, Date.now() - observation.at),
200
- sessionMatches: expected ? observation.session === expected : "unknown",
201
- ...observation.errorCode ? { errorCode: observation.errorCode } : {}
202
- } : null,
203
- ...observationError ? { observationError } : {},
204
- trust: "unknown",
205
- capture: run.binding ? "excluded-for-bound-session" : "not-verified"
206
- };
207
- }
208
-
209
- export {
210
- RUN_ID,
211
- runPath,
212
- readDemoJson,
213
- saveDemoJson,
214
- readRun,
215
- saveRun,
216
- lockRun,
217
- prepareRun,
218
- preparationKey,
219
- demoCommand,
220
- demoWelcomeCommand,
221
- demoDiagnosticCommand,
222
- demoResumeCommand,
223
- onboardingFinished,
224
- finishOnboarding,
225
- pendingRuns,
226
- sessionKey,
227
- exclusionPath,
228
- sessionExcluded,
229
- lockRunAsync,
230
- demoArgv,
231
- observeRun,
232
- isolationDiagnostics
233
- };