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

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.
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  isDemoStatusResponse
3
- } from "./chunk-FFYZ3XMX.js";
3
+ } from "./chunk-GFJ4QIVR.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
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  formatStatusline
3
- } from "./chunk-72CQVK4E.js";
3
+ } from "./chunk-RXD6LFA2.js";
4
4
  import {
5
5
  getSiteUrl,
6
6
  isSessionEnded,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-FFYZ3XMX.js";
3
+ } from "./chunk-GFJ4QIVR.js";
4
4
  import {
5
5
  stripControlChars
6
6
  } from "./chunk-2IRLFOEL.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-FFYZ3XMX.js";
3
+ } from "./chunk-GFJ4QIVR.js";
4
4
  import {
5
5
  terminalSafeLine
6
6
  } from "./chunk-2IRLFOEL.js";