@primitive.ai/prim 0.1.0-alpha.105 → 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/README.md CHANGED
@@ -45,24 +45,38 @@ skill, and the welcome:
45
45
  prim setup # add --agent cursor, codex, or hermes; --no-daemon explicitly opts out
46
46
  ```
47
47
 
48
- After successful setup, a first-run, 2–3 minute **simulated tour** demonstrates
49
- sample ingestion, Decision creation, a warning, a blocked write, and a correction.
50
- Your agent guides two choices; no sample Decisions enter the real graph.
51
- The tour follows one order-saving task and ends with a receipt of the demonstrated
52
- lifecycle, then offers one real project Decision for your individual approval.
53
- Use `prim setup --skip-demo` to skip and remember that choice, or
54
- `prim demo --agent <claude|codex|cursor|hermes>` to replay.
55
- For a person at a terminal, `prim demo` prompts directly with compact Decision
56
- cards, write outcomes, and file diffs. Use `prim demo --details` for the full source
57
- and supporting detail. Interactive terminal output omits the completion JSON;
58
- redirected STDOUT and agent commands retain machine-readable JSON.
59
-
60
- The agent tour waits for trusted hooks before showing samples and excludes
61
- passive capture for the remainder of that agent session, including resumes.
62
- Start a new session afterward for normal capture. Explicitly approved real
63
- Decisions can still be created, and other sessions continue capturing.
64
- The tour uses disposable local files and scripted verdicts; it does not test
65
- production ingestion or Enforcement. It offers real-memory seeding afterward.
48
+ After successful setup, the optional **author story** puts you in a new engineer's
49
+ shoes in a disposable project:
50
+
51
+ ```text
52
+ Implement CSV export → Your earlier Decision blocks email → Adhere or supersede
53
+ → Real outcome email
54
+ ```
55
+
56
+ Enter the feature prompt in the same agent chat. The real semantic evaluator checks
57
+ it against your private, fictional prior Decision. Choose a name-only export or
58
+ approve the displayed replacement with your own short reason. A real email explains
59
+ what your Decision protected or why it changed. Continue once that email is queued;
60
+ queued and provider-accepted do not mean delivered to your inbox.
61
+
62
+ The compact diagrams and actual file evidence live in each JSON `presentation`.
63
+ Your agent renders them once. After owned-file cleanup, participants without real
64
+ Decisions enter the existing individually approved creation flow. Existing Decisions
65
+ remain intact; unavailable history is not treated as an empty graph.
66
+
67
+ Use `prim setup --skip-demo` to remember a skip, or
68
+ `prim demo --agent <claude|codex|cursor|hermes>` to replay. Direct terminal `prim demo`
69
+ uses the same prompts. Setup defaults to compact diagnostics; `prim setup --details`
70
+ shows full child output. Default agent setup returns one JSON result with `welcome`,
71
+ `onboarding`, and its `nextAction`. Existing completed tours do not replay automatically.
72
+
73
+ Agent hooks must acknowledge isolation before any sample is shown. Passive capture
74
+ then stays excluded for this session, including resumes; start a new session to
75
+ resume it. Other sessions, real-work enforcement and explicitly approved real
76
+ Decision creation remain available. Synthetic records never join the team's graph.
77
+ This exercises a real evaluator and demo-only blocking policy, not native production
78
+ Enforcement or live ingestion. Backend/email unavailability leaves the optional
79
+ story pending while successful setup remains successful.
66
80
 
67
81
  Or run the steps individually:
68
82
 
package/SKILL.md CHANGED
@@ -144,63 +144,94 @@ Treat changes to shared agent instructions and standards—such as `AGENTS.md`,
144
144
 
145
145
  Apply the same attention during non-code deliberation: planning or “grill me” workflows, spec refinement, behavior design, PR planning or review, and conversations imported from Granola or other connected sources. These workflows can settle important forks before any code changes. Accumulate the confirmed decisions and record them at a natural phase or task boundary; do not interrupt or call Primitive after every answer.
146
146
 
147
- ### Onboarding: run the local tour before memory seeding
148
-
149
- After successful `prim setup`, follow any demo `nextAction` automatically. Setup
150
- starts this optional tour once per local OS-user configuration; `setup --skip-demo`
151
- remembers a skip, and `prim demo --agent <claude|codex|cursor|hermes>` replays it.
152
- Pass your agent explicitly, including when your shell tool allocates a terminal.
153
-
154
- The tour is entirely fictional: extraction, Decisions, and verdicts are simulated.
155
- Execute each generated command **exactly as a standalone shell invocation**; do not
156
- wrap it, append another command, substitute another executable, or use a subagent.
157
- Its hook acknowledgment establishes session isolation before any sample is shown.
158
- If the result is pending, surface its hook-trust instruction and retry only after
159
- trust is established. Never fabricate the missing output or read sample fixtures
160
- yourself to bypass isolation.
161
-
162
- Render each result once. Consume the JSON; do not dump it, echo the CLI narration,
163
- or add a second prose recap. Use compact Markdown, short code blocks, and visible
164
- state changes. Aim for at most 120 narrative words per choice, excluding code;
165
- do not fill the budget. Keep a short **Simulated tour** label on each response.
166
-
167
- Once isolated, lead with **Add order saving**. Show one supporting quote flowing
168
- into the extracted Decision: `Source → Decision [provisional]`. Give each Decision
169
- only its headline, one-line **Why**, and file scope; label the extracted scope as
170
- a demo mapping. The JSON's `sourceNote`, `decisions`, and `proposal` retain the
171
- full source, evidence, rationale, and rejected alternatives for questions.
172
-
173
- Pause for only two teaching choices: adopt the proposal, then choose the shared
174
- repository correction or retry direct storage. Use `confirm` only after the user's
175
- confirmation; a setup request or `--yes` is not that answer. Follow `skipAction`
176
- if the user declines or stops. Acknowledge approval with **Proposed → Adopted**.
177
-
178
- Present **WARNING — edit allowed** and **BLOCKED — file unchanged** separately.
179
- For each, show the governing Decision, one reason, and compact file evidence.
180
- Use the returned before/after bytes: show the warning's changed lines, and the
181
- blocked write stopping before `orders.ts` with its actual contents unchanged.
182
- Omit diff transport headers and hunk metadata. On retry, repeat only the block,
183
- its reason, unchanged-file evidence, and correction choice. These are scripted
184
- verdicts, not universal rules for Decision states; live gates vary by agent and
185
- state (Claude may request permission where other agents block).
186
-
187
- On correction, show both actual diffs and **PASS — order saving added**. Finish
188
- with `✓ Extracted · ✓ Adopted · ✓ Warned · ✓ Blocked · ✓ Corrected`, sample cleanup,
189
- and the new-session reminder. Never show completion for a skip, pending tour, or
190
- error. Offer one real Decision for individual approval; continue one at a time
191
- only if the user wants to proceed. Keep supporting detail on request instead of
192
- expanding every record. Direct terminal users can replay with `prim demo --details`.
193
-
194
- Never record these examples with `decisions create`, save them to shared memory,
195
- or include them in later seeding candidates. The tour excludes passive capture
196
- for the remainder of this agent session, including resumes; tell the user to start
197
- a new session for normal capture. Other sessions and real-work enforcement remain
198
- active, and explicitly approved real Decisions can still be created here.
199
-
200
- After completion or skip, offer memory seeding and run `prim welcome --agent <your
201
- agent>` with `--capture-excluded` when this session ran the tour. An unfinished
202
- tour is listed in `recoverableRuns`; use its skip command for cleanup before replay.
203
- Do not begin real-memory proposals while the tour is pending.
147
+ ### Onboarding: experience your Decision protecting a teammate
148
+
149
+ After successful `prim setup`, follow its `nextAction` automatically; the `onboarding`
150
+ object contains the preparation instructions.
151
+ Pass your agent explicitly: Claude, Codex, Cursor and Hermes use the same sequence.
152
+ Run each generated command exactly as a standalone invocation. The first action
153
+ establishes capture isolation before the story is revealed. Do not delegate, wrap
154
+ commands, read fixtures, or manufacture an acknowledgment. If pending, use the
155
+ returned isolation reason and diagnostic action. Unknown trust is not proof that
156
+ hooks are disabled; for Codex, check `/hooks` and approve only if prompted.
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
+
192
+ Render each `presentation` once as Markdown, preserving diagrams and file evidence.
193
+ Do not echo JSON/STDERR, expand the records, or add a prose recap. Keep the
194
+ **Fictional project · real conflict check** label. This uses the production semantic
195
+ evaluator on private demo records and a demo-only blocking policy; native production
196
+ hooks did not supply the verdict. Production outcomes still vary by agent and
197
+ Decision state, including Claude's permission prompt.
198
+
199
+ The participant is the fictional earlier author, now playing a new engineer in this
200
+ same chat. At `awaitUserPrompt`, show the copyable CSV-export task and **wait for the
201
+ user to enter it**. Only then run `attemptAction`. Do not auto-submit it, ask them to
202
+ adopt the prior Decision, or implement the feature yourself.
203
+
204
+ At the actual block, show the unchanged file and ask **Adhere or Supersede?**
205
+ Adhere uses `choices.adhere`. Supersede approves the displayed replacement,
206
+ **Allow customer names and email addresses in CSV exports**, and requires a short
207
+ reason in the user's own words. Append `'--reason'` and their single-quoted reason
208
+ to `choices.supersede.command`; escape any apostrophe as `'\''`, matching the
209
+ command's existing shell quoting. Never invent a reason or execute a placeholder.
210
+ Do not call production `reconcile` or `decisions create` for these samples.
211
+
212
+ An unavailable or uncertain judgment remains pending; never invent a block or pass.
213
+ Use `statusAction` for diagnosis and the returned action for recovery. A resolution
214
+ retry uses the same approved bytes and completion receipt. Show success **before**
215
+ following welcome. Continue when the real outcome email is durably queued; provider
216
+ acceptance is not inbox delivery. Cleanup errors retain the path and defer seeding.
217
+
218
+ After completion or explicit skip, follow the exact welcome `nextAction` once.
219
+ It preserves the executable and agent and requests `--after-demo`. Its viewer-based
220
+ `org` result governs the transition: `seed` proposes one real Decision for individual
221
+ approval; `active` continues real work; `unknown` reports unavailable history and
222
+ must never be treated as empty. Do not repeat the feed or seed from fictional data.
223
+
224
+ Passive capture stays excluded for this session, including resumes. Start a new
225
+ session to resume capture; other sessions and real-work enforcement stay active.
226
+ Explicitly approved real Decisions remain available here. Never save this story,
227
+ its Decisions, reason or outcome to repository memory or the real Decision graph.
228
+
229
+ Setup runs the optional story once per local OS-user configuration. `setup --skip-demo`
230
+ remembers a skip; `prim demo --agent <claude|codex|cursor|hermes>` explicitly replays.
231
+ Old completion markers do not force a replay. `recoverableRuns` offers cleanup of
232
+ unfinished runs, including legacy local tours; it does not gate a fresh tour.
233
+ A missing backend/email configuration leaves the optional story pending while setup
234
+ remains successful. Surface the returned remedy or offer its skip action.
204
235
 
205
236
  ### Onboarding: seed the graph from memory, one proposal at a time
206
237
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  scheduleCollectScopeRefresh
3
- } from "./chunk-GSBHBU7N.js";
3
+ } from "./chunk-FFYZ3XMX.js";
4
4
 
5
5
  // src/ingest-response.ts
6
6
  var IngestAcknowledgementError = class extends Error {
@@ -4,13 +4,13 @@ import {
4
4
  import {
5
5
  analyzeShellTargets,
6
6
  extractFileTargets
7
- } from "./chunk-LNFWFYSN.js";
7
+ } from "./chunk-7NNJ67YN.js";
8
8
  import {
9
9
  scrubEnvironmentPaths
10
- } from "./chunk-MZEVEPL3.js";
10
+ } from "./chunk-LVRD562C.js";
11
11
  import {
12
12
  cachedCollectScopeAdmits
13
- } from "./chunk-GSBHBU7N.js";
13
+ } from "./chunk-FFYZ3XMX.js";
14
14
  import {
15
15
  canonicalRepositoryPath,
16
16
  currentBranch,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-EZXEWFDG.js";
4
4
  import {
5
5
  scrubEnvironmentPaths
6
- } from "./chunk-MZEVEPL3.js";
6
+ } from "./chunk-LVRD562C.js";
7
7
  import {
8
8
  isValidRepoSyncId
9
9
  } from "./chunk-XG7S3LIL.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-GSBHBU7N.js";
3
+ } from "./chunk-FFYZ3XMX.js";
4
4
  import {
5
5
  stripControlChars
6
6
  } from "./chunk-2IRLFOEL.js";
@@ -1,56 +1,90 @@
1
1
  import {
2
+ RUN_ID,
3
+ demoArgv,
2
4
  demoCommand,
3
5
  exclusionPath,
4
6
  lockRun,
7
+ observeRun,
8
+ readRun,
5
9
  runPath,
6
10
  saveDemoJson,
7
11
  saveRun,
8
12
  sessionExcluded,
9
13
  sessionKey
10
- } from "./chunk-6WCBVSND.js";
14
+ } from "./chunk-P5I4HGMW.js";
15
+ import {
16
+ packageVersion
17
+ } from "./chunk-XG7S3LIL.js";
11
18
 
12
19
  // src/demo/isolation.ts
13
20
  import { existsSync } from "fs";
14
21
  function observeDemoInvocation(envelope, agent, checkExclusion = true) {
15
22
  const session = typeof envelope.session_id === "string" && envelope.session_id ? envelope.session_id : agent === "hermes" ? envelope.extra?.session_key : void 0;
16
23
  let invocation = false;
17
- if (envelope.hook_event_name === "PreToolUse" && typeof session === "string" && session) {
24
+ if (envelope.hook_event_name === "PreToolUse") {
18
25
  const tool = agent === "cursor" ? "Shell" : agent === "hermes" ? "terminal" : "Bash";
19
26
  const input = envelope.tool_input;
20
- const command = input?.command;
21
- if (envelope.tool_name === tool && typeof command === "string" && command.length < 8192) {
22
- const ids = command.match(
23
- /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gu
24
- );
25
- if (ids?.length === 1 && existsSync(runPath(ids[0]))) {
26
- invocation = lockRun(ids[0], (run) => {
27
- const actions = [
28
- ["start"],
29
- ["confirm"],
30
- ["resolve", "repository"],
31
- ["resolve", "local-storage"],
32
- ["skip"]
33
- ];
34
- const match = actions.find(
35
- ([action, choice]) => demoCommand(run, action, choice) === command
36
- );
37
- if (run.terminal || !match) {
38
- return false;
39
- }
40
- if (match[0] === "skip") return true;
41
- const key = sessionKey(agent, session);
42
- if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
43
- run.acknowledgment = void 0;
44
- saveRun(run);
45
- return false;
46
- }
47
- saveDemoJson(exclusionPath(key), { runId: run.id });
48
- run.binding = key;
49
- run.agent = agent;
50
- run.acknowledgment = { command, at: Date.now() };
51
- saveRun(run);
52
- return true;
27
+ const command = input?.command ?? input?.cmd;
28
+ if (typeof command === "string" && command.length < 8192) {
29
+ const argv = demoArgv(command);
30
+ const id = argv?.[4] ?? command.match(/\x27([0-9a-f-]{36})\x27/u)?.[1];
31
+ if (id && RUN_ID.test(id) && existsSync(runPath(id))) {
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 } : {}
53
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
+ }
54
88
  }
55
89
  }
56
90
  }