@primitive.ai/prim 0.1.0-alpha.106 → 0.1.0-alpha.107

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/SKILL.md CHANGED
@@ -155,6 +155,40 @@ commands, read fixtures, or manufacture an acknowledgment. If pending, use the
155
155
  returned isolation reason and diagnostic action. Unknown trust is not proof that
156
156
  hooks are disabled; for Codex, check `/hooks` and approve only if prompted.
157
157
 
158
+ Setup authorization includes following its returned `nextAction`; do not end the
159
+ turn at welcome or ask whether to start the tour. Installation, hook configuration,
160
+ observed hook execution, and verified capture are different states. Preserve
161
+ `health` warnings and `readiness` rather than declaring everything active.
162
+
163
+ If isolation is pending, run `diagnosticAction` once. It is safe before isolation:
164
+ it reports the installed runtime and the last content-free observation for this
165
+ run. The acknowledgment event is **PreToolUse**, with **Bash** for Codex/Claude,
166
+ **Shell** for Cursor, and **terminal** for Hermes. Missing evidence is unknown,
167
+ not proof of disabled hooks or absence of errors. Check the host's hook event/error
168
+ view; do not list the agent's home directory or dump transcripts. After the one
169
+ trust retry, retry only after a concrete repair. Use `resumeAction` for the same
170
+ run, including after an expired npm cache; do not restart the retry budget by
171
+ creating a fresh run. If the host does not execute local command hooks in this
172
+ session, explain that limitation and retain the resume action for a supported
173
+ local session. Never simulate the acknowledgment. Offer skip only as an option,
174
+ not as the diagnosis.
175
+
176
+ Run follow-up actions with the configuration-directory access already authorized
177
+ for setup, subject to host policy. Report EPERM/EACCES with the actual path and
178
+ remedy; never infer sandbox/network failure from a quiet command. While npm is
179
+ starting, give a brief progress update after about 15 seconds and keep polling
180
+ that invocation; do not launch duplicates. Only after an actual npm cache error,
181
+ retry once with a newly allocated temporary `npm_config_cache` directory. Reuse
182
+ that cache for subsequent commands. Do not clear the user's cache or change
183
+ permissions recursively. Bootstrap happens before Primitive can print progress.
184
+ Setup opens the authorization browser itself: surface its URL and let the user
185
+ click Authorize; do not invoke computer-use tools to automate that click.
186
+
187
+ Render the returned presentation once; keep raw JSON, launch paths, UUIDs and
188
+ routine STDERR out of the conversation. Surface actionable warnings verbatim.
189
+ If blocked, end with the observed cause (or explicitly unknown boundary), the
190
+ single next repair, and the command to resume the retained run.
191
+
158
192
  Render each `presentation` once as Markdown, preserving diagrams and file evidence.
159
193
  Do not echo JSON/STDERR, expand the records, or add a prose recap. Keep the
160
194
  **Fictional project · real conflict check** label. This uses the production semantic
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  analyzeShellTargets,
6
6
  extractFileTargets
7
- } from "./chunk-HT2CJ3YD.js";
7
+ } from "./chunk-7NNJ67YN.js";
8
8
  import {
9
9
  scrubEnvironmentPaths
10
10
  } from "./chunk-LVRD562C.js";
@@ -4,50 +4,87 @@ import {
4
4
  demoCommand,
5
5
  exclusionPath,
6
6
  lockRun,
7
+ observeRun,
8
+ readRun,
7
9
  runPath,
8
10
  saveDemoJson,
9
11
  saveRun,
10
12
  sessionExcluded,
11
13
  sessionKey
12
- } from "./chunk-7GSBXHK4.js";
14
+ } from "./chunk-P5I4HGMW.js";
15
+ import {
16
+ packageVersion
17
+ } from "./chunk-XG7S3LIL.js";
13
18
 
14
19
  // src/demo/isolation.ts
15
20
  import { existsSync } from "fs";
16
21
  function observeDemoInvocation(envelope, agent, checkExclusion = true) {
17
22
  const session = typeof envelope.session_id === "string" && envelope.session_id ? envelope.session_id : agent === "hermes" ? envelope.extra?.session_key : void 0;
18
23
  let invocation = false;
19
- if (envelope.hook_event_name === "PreToolUse" && typeof session === "string" && session) {
24
+ if (envelope.hook_event_name === "PreToolUse") {
20
25
  const tool = agent === "cursor" ? "Shell" : agent === "hermes" ? "terminal" : "Bash";
21
26
  const input = envelope.tool_input;
22
- const command = input?.command;
23
- if (envelope.tool_name === tool && typeof command === "string" && command.length < 8192) {
27
+ const command = input?.command ?? input?.cmd;
28
+ if (typeof command === "string" && command.length < 8192) {
24
29
  const argv = demoArgv(command);
25
- const id = argv?.[4];
30
+ const id = argv?.[4] ?? command.match(/\x27([0-9a-f-]{36})\x27/u)?.[1];
26
31
  if (id && RUN_ID.test(id) && existsSync(runPath(id))) {
27
- invocation = lockRun(id, (run) => {
28
- const action = argv?.[3];
29
- const choice = argv?.[6];
30
- const reason = argv?.[8];
31
- const recognized = ["start", "attempt", "resolve", "status", "skip"].includes(action);
32
- const validChoice = action !== "resolve" || choice === "adhere" || choice === "supersede" && typeof reason === "string" && reason.trim().length > 0 && reason.length <= 500;
33
- const match = recognized && validChoice && demoCommand(run, action, choice, reason) === command;
34
- if (run.terminal || !match) {
35
- return false;
36
- }
37
- if (action === "skip") return true;
38
- const key = sessionKey(agent, session);
39
- if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
40
- run.acknowledgment = void 0;
41
- saveRun(run);
42
- return false;
43
- }
44
- saveDemoJson(exclusionPath(key), { runId: run.id });
45
- run.binding = key;
46
- run.agent = agent;
47
- run.acknowledgment = { command, at: Date.now() };
48
- saveRun(run);
49
- return true;
32
+ const identity = typeof session === "string" && session ? sessionKey(agent, session) : void 0;
33
+ const observed = (result, errorCode) => observeRun(id, {
34
+ at: Date.now(),
35
+ agent,
36
+ runtimeVersion: packageVersion() ?? void 0,
37
+ session: identity,
38
+ result,
39
+ ...errorCode ? { errorCode } : {}
50
40
  });
41
+ const action = argv?.[3];
42
+ const choice = argv?.[6];
43
+ const reason = argv?.[8];
44
+ const recognized = ["start", "attempt", "resolve", "status", "skip"].includes(action);
45
+ const validChoice = action !== "resolve" || choice === "adhere" || choice === "supersede" && typeof reason === "string" && reason.trim().length > 0 && reason.length <= 500;
46
+ const matches = (run) => !run.terminal && recognized && validChoice && demoCommand(run, action, choice, reason) === command;
47
+ let candidate;
48
+ try {
49
+ candidate = readRun(id);
50
+ } catch {
51
+ }
52
+ if (envelope.tool_name !== tool || typeof input?.command !== "string") {
53
+ observed("tool-mismatch");
54
+ } else if (!candidate || !matches(candidate)) {
55
+ observed("command-mismatch");
56
+ } else
57
+ try {
58
+ invocation = lockRun(id, (run) => {
59
+ if (!matches(run)) {
60
+ observed("command-mismatch");
61
+ return false;
62
+ }
63
+ if (action === "skip") return true;
64
+ if (!identity) {
65
+ observed("session-missing");
66
+ return false;
67
+ }
68
+ const key = identity;
69
+ if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
70
+ observed("session-mismatch");
71
+ run.acknowledgment = void 0;
72
+ saveRun(run);
73
+ return false;
74
+ }
75
+ saveDemoJson(exclusionPath(key), { runId: run.id });
76
+ run.binding = key;
77
+ run.agent = agent;
78
+ run.acknowledgment = { command, at: Date.now() };
79
+ saveRun(run);
80
+ observed("acknowledged");
81
+ return true;
82
+ });
83
+ } catch (error) {
84
+ const code = error.code;
85
+ observed("write-failed", code && /^[A-Z0-9_]{1,32}$/u.test(code) ? code : void 0);
86
+ throw error;
87
+ }
51
88
  }
52
89
  }
53
90
  }
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  isDemoStatusResponse
3
3
  } from "./chunk-FFYZ3XMX.js";
4
+ import {
5
+ inspectHookRuntime
6
+ } from "./chunk-PO5QAYD7.js";
4
7
  import {
5
8
  atomicWriteFile,
6
9
  primConfigDirectory,
@@ -53,11 +56,15 @@ function prepareRun(agent, terminal = false) {
53
56
  stage: "prepared",
54
57
  terminal,
55
58
  agent,
59
+ preparationKey: preparationKey(agent),
56
60
  launcher: [process.execPath, resolve(process.argv[1])]
57
61
  };
58
62
  saveRun(run);
59
63
  return run;
60
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
+ }
61
68
  var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
62
69
  function demoCommand(run, action, choice, reason) {
63
70
  return [
@@ -80,11 +87,10 @@ function demoWelcomeCommand(run) {
80
87
  ].map(quote).join(" ");
81
88
  }
82
89
  function demoDiagnosticCommand(run) {
83
- return [
84
- process.execPath,
85
- resolve(process.argv[1]),
86
- ...run.agent ? [run.agent === "claude_code" ? "claude" : run.agent, "status"] : ["doctor"]
87
- ].map(quote).join(" ");
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(" ");
88
94
  }
89
95
  function onboardingFinished() {
90
96
  const path = join(demoDirectory(), "onboarding.json");
@@ -147,17 +153,73 @@ function demoArgv(command) {
147
153
  }
148
154
  }
149
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
+
150
209
  export {
151
210
  RUN_ID,
152
211
  runPath,
153
212
  readDemoJson,
154
213
  saveDemoJson,
214
+ readRun,
155
215
  saveRun,
156
216
  lockRun,
157
217
  prepareRun,
218
+ preparationKey,
158
219
  demoCommand,
159
220
  demoWelcomeCommand,
160
221
  demoDiagnosticCommand,
222
+ demoResumeCommand,
161
223
  onboardingFinished,
162
224
  finishOnboarding,
163
225
  pendingRuns,
@@ -165,5 +227,7 @@ export {
165
227
  exclusionPath,
166
228
  sessionExcluded,
167
229
  lockRunAsync,
168
- demoArgv
230
+ demoArgv,
231
+ observeRun,
232
+ isolationDiagnostics
169
233
  };