@primitive.ai/prim 0.1.0-alpha.102 → 0.1.0-alpha.103

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/dist/index.js CHANGED
@@ -57,6 +57,18 @@ import {
57
57
  sweepOrphanedDrainProgress,
58
58
  writeDrainCheckpoint
59
59
  } from "./chunk-JJI7FU24.js";
60
+ import {
61
+ RUN_ID,
62
+ demoCommand,
63
+ exclusionPath,
64
+ finishOnboarding,
65
+ lockRun,
66
+ onboardingFinished,
67
+ pendingRuns,
68
+ prepareRun,
69
+ readDemoJson,
70
+ saveRun
71
+ } from "./chunk-6WCBVSND.js";
60
72
  import {
61
73
  MS_PER_SECOND,
62
74
  deliveryBacklogState,
@@ -167,8 +179,8 @@ import {
167
179
  } from "./chunk-XG7S3LIL.js";
168
180
 
169
181
  // src/index.ts
170
- import { readFileSync as readFileSync10 } from "fs";
171
- import { dirname as dirname6, resolve as resolve4 } from "path";
182
+ import { readFileSync as readFileSync11 } from "fs";
183
+ import { dirname as dirname7, resolve as resolve4 } from "path";
172
184
  import { fileURLToPath as fileURLToPath2 } from "url";
173
185
  import { Command } from "commander";
174
186
  import updateNotifier from "update-notifier";
@@ -6597,8 +6609,488 @@ function registerDecisionsCommands(program2) {
6597
6609
  });
6598
6610
  }
6599
6611
 
6612
+ // src/commands/demo.ts
6613
+ import { createPatch } from "diff";
6614
+
6615
+ // src/demo/sandbox.ts
6616
+ import {
6617
+ existsSync as existsSync5,
6618
+ lstatSync as lstatSync4,
6619
+ mkdtempSync as mkdtempSync2,
6620
+ readFileSync as readFileSync5,
6621
+ readdirSync as readdirSync3,
6622
+ realpathSync as realpathSync2,
6623
+ rmdirSync,
6624
+ unlinkSync as unlinkSync3
6625
+ } from "fs";
6626
+ import { tmpdir } from "os";
6627
+ import { basename as basename2, dirname as dirname2, join as join6 } from "path";
6628
+
6629
+ // src/demo/scenario.ts
6630
+ var SAMPLE_NOTE = [
6631
+ "Fictional engineering conversation:",
6632
+ "Maya: Could we call fetch directly for the order service?",
6633
+ "Ravi: Use the shared HTTP client for service calls. We need retries and request tracing to stay consistent.",
6634
+ "Maya: Agreed. Let's reject direct fetch calls because they duplicate that policy.",
6635
+ "Ravi: Also, the team demo is at three."
6636
+ ].join("\n");
6637
+ var SAMPLE_DECISIONS = [
6638
+ {
6639
+ id: "demo-http-client",
6640
+ decision: "Use the shared HTTP client for service calls",
6641
+ stage: "provisional",
6642
+ source: "Fictional engineering conversation",
6643
+ evidence: [
6644
+ "Use the shared HTTP client for service calls. We need retries and request tracing to stay consistent.",
6645
+ "Let's reject direct fetch calls because they duplicate that policy."
6646
+ ],
6647
+ rationale: "Centralize retries and request tracing.",
6648
+ files: ["service.ts"],
6649
+ scopeBasis: "Demo mapping from service calls to service.ts; the conversation names no file.",
6650
+ alternativesRejected: ["Direct fetch calls with duplicated retry and tracing policy"]
6651
+ },
6652
+ {
6653
+ id: "demo-order-repository",
6654
+ decision: "Persist orders through the shared order repository",
6655
+ stage: "adopted",
6656
+ source: "User confirmation of this fictional proposal",
6657
+ rationale: "Keep validation and persistence consistent across order writers.",
6658
+ files: ["orders.ts"],
6659
+ alternativesRejected: ["Direct local-storage writes that bypass repository validation"]
6660
+ }
6661
+ ];
6662
+ var SAMPLE_FILES = {
6663
+ "service.ts": 'import { http } from "./shared";\nexport const loadOrders = () => http.get("/orders");\n',
6664
+ "orders.ts": "export const saveOrder = (_order: unknown) => {\n // TODO: persist this order.\n};\n",
6665
+ "shared.ts": "// Fictional interfaces; this tour does not execute network or storage operations.\nexport declare const http: { get(path: string): Promise<unknown> };\nexport declare const orders: { save(order: unknown): void };\n"
6666
+ };
6667
+ var WARNING_EDIT = 'export const loadOrders = () => fetch("/orders");\n';
6668
+ var BLOCKED_EDIT = 'export const saveOrder = (order: unknown) => localStorage.setItem("order", JSON.stringify(order));\n';
6669
+ var REPOSITORY_EDIT = 'import { orders } from "./shared";\nexport const saveOrder = (order: unknown) => orders.save(order);\n';
6670
+
6671
+ // src/demo/sandbox.ts
6672
+ var decisionBytes = (adopted) => `${JSON.stringify(adopted ? SAMPLE_DECISIONS : SAMPLE_DECISIONS.slice(0, 1), null, 2)}
6673
+ `;
6674
+ function allowedFiles(run) {
6675
+ return {
6676
+ ".owner": [run.id],
6677
+ "note.md": [SAMPLE_NOTE],
6678
+ "decisions.json": [decisionBytes(false), decisionBytes(true)],
6679
+ ...Object.fromEntries(Object.entries(SAMPLE_FILES).map(([name, value]) => [name, [value]])),
6680
+ "service.ts": [SAMPLE_FILES["service.ts"], WARNING_EDIT],
6681
+ "orders.ts": [SAMPLE_FILES["orders.ts"], REPOSITORY_EDIT]
6682
+ };
6683
+ }
6684
+ function inspectSandbox(run) {
6685
+ const sandbox = run.sandbox;
6686
+ if (!sandbox || dirname2(sandbox.path) !== realpathSync2(tmpdir()) || !basename2(sandbox.path).startsWith("prim-demo-")) {
6687
+ throw new Error("invalid demo sandbox ownership");
6688
+ }
6689
+ const stat = lstatSync4(sandbox.path);
6690
+ if (!stat.isDirectory() || stat.dev !== sandbox.device || stat.ino !== sandbox.inode) {
6691
+ throw new Error(`demo sandbox changed; retained ${sandbox.path}`);
6692
+ }
6693
+ const allowed = allowedFiles(run);
6694
+ for (const name of readdirSync3(sandbox.path)) {
6695
+ const path = join6(sandbox.path, name);
6696
+ const file = lstatSync4(path);
6697
+ if (!Object.hasOwn(allowed, name) || !file.isFile() || file.nlink !== 1 || file.size > 16384 || !allowed[name].includes(readFileSync5(path, "utf8"))) {
6698
+ throw new Error(`unexpected demo contents; retained ${sandbox.path}`);
6699
+ }
6700
+ }
6701
+ return sandbox.path;
6702
+ }
6703
+ function createSandbox(run) {
6704
+ if (!run.sandbox) {
6705
+ const path = mkdtempSync2(join6(realpathSync2(tmpdir()), "prim-demo-"));
6706
+ const stat = lstatSync4(path);
6707
+ run.sandbox = { path, device: stat.dev, inode: stat.ino };
6708
+ saveRun(run);
6709
+ }
6710
+ const root = inspectSandbox(run);
6711
+ for (const [name, content] of Object.entries({
6712
+ ".owner": run.id,
6713
+ "note.md": SAMPLE_NOTE,
6714
+ ...SAMPLE_FILES,
6715
+ "decisions.json": decisionBytes(false)
6716
+ })) {
6717
+ const path = join6(root, name);
6718
+ if (!existsSync5(path)) atomicWriteFile(path, content, { mode: 384 });
6719
+ }
6720
+ }
6721
+ function writeSample(run, name, bytes) {
6722
+ const root = inspectSandbox(run);
6723
+ if (!allowedFiles(run)[name].includes(bytes)) throw new Error("unsupported demo edit");
6724
+ atomicWriteFile(join6(root, name), bytes, { mode: 384 });
6725
+ }
6726
+ function readSample(run, name) {
6727
+ return readFileSync5(join6(inspectSandbox(run), name), "utf8");
6728
+ }
6729
+ function cleanSandbox(run) {
6730
+ if (!run.sandbox) return;
6731
+ try {
6732
+ lstatSync4(run.sandbox.path);
6733
+ } catch (error) {
6734
+ if (error.code !== "ENOENT") throw error;
6735
+ run.sandbox = void 0;
6736
+ return;
6737
+ }
6738
+ const root = inspectSandbox(run);
6739
+ for (const name of readdirSync3(root)) {
6740
+ inspectSandbox(run);
6741
+ unlinkSync3(join6(root, name));
6742
+ }
6743
+ rmdirSync(root);
6744
+ run.sandbox = void 0;
6745
+ }
6746
+
6747
+ // src/commands/demo.ts
6748
+ var intro = "SIMULATED TOUR \u2014 fictional Decisions and scripted verdicts; no live ingestion or enforcement check.";
6749
+ var handoff = "Sample files removed. Next: ask your agent to propose one real Decision from your project's shared memory for your individual approval.";
6750
+ var captureNotice = "Passive Decision capture is excluded for the rest of this agent session, including resumed use. Start a new session for normal capture. Explicitly approved real Decisions can still be created.";
6751
+ var completionReceipt = [
6752
+ "Extracted a Decision with supporting evidence",
6753
+ "Adopted a Decision with your confirmation",
6754
+ "Surfaced a warning and allowed the edit",
6755
+ "Refused a conflicting write",
6756
+ "Applied the compliant implementation"
6757
+ ];
6758
+ function resultFor2(run) {
6759
+ const action = run.stage === "prepared" ? "start" : run.stage === "proposal" ? "confirm" : "resolve";
6760
+ const done = run.stage === "completed" || run.stage === "skipped";
6761
+ return {
6762
+ simulated: true,
6763
+ runId: run.id,
6764
+ stage: run.stage,
6765
+ ...done ? { message: handoff, nextAction: `prim welcome${run.binding ? " --capture-excluded" : ""}` } : {
6766
+ nextAction: demoCommand(run, action, action === "resolve" ? "repository" : void 0),
6767
+ skipAction: demoCommand(run, "skip")
6768
+ },
6769
+ ...run.sandbox ? { sandbox: run.sandbox.path } : {},
6770
+ ...run.stage === "conflict" ? { retryAction: demoCommand(run, "resolve", "local-storage") } : {}
6771
+ };
6772
+ }
6773
+ function demoTrustGuidance(agent) {
6774
+ if (agent === "codex")
6775
+ return "Trust the installed prim hooks with /hooks in Codex, then retry the exact nextAction.";
6776
+ if (agent === "hermes")
6777
+ return "Approve the installed prim hooks when Hermes prompts, then retry the exact nextAction.";
6778
+ if (agent === "cursor")
6779
+ return "Trust this Cursor workspace and activate its installed hooks, then retry the exact nextAction.";
6780
+ return "Activate the installed prim hooks in your agent, then retry the exact nextAction.";
6781
+ }
6782
+ function consumeAcknowledgment(run, action, choice) {
6783
+ if (run.terminal) return Boolean(process.stdin.isTTY && process.stderr.isTTY);
6784
+ const ack = run.acknowledgment;
6785
+ run.acknowledgment = void 0;
6786
+ saveRun(run);
6787
+ if (!run.binding || !ack || ack.command !== demoCommand(run, action, choice)) return false;
6788
+ const age = Date.now() - ack.at;
6789
+ if (!Number.isFinite(age) || age < 0 || age > 3e4) return false;
6790
+ try {
6791
+ const exclusion = readDemoJson(exclusionPath(run.binding));
6792
+ return typeof exclusion.runId === "string" && RUN_ID.test(exclusion.runId);
6793
+ } catch {
6794
+ return false;
6795
+ }
6796
+ }
6797
+ function narrateDecision(index) {
6798
+ const item = SAMPLE_DECISIONS[index];
6799
+ const status = index === 1 ? "proposed adoption, awaiting confirmation" : item.stage;
6800
+ const source = index === 1 ? "Fictional authoring proposal" : item.source;
6801
+ process.stderr.write(
6802
+ `
6803
+ Decision: ${item.decision}
6804
+ Status: ${status} (sample)
6805
+ Source: ${source}
6806
+ Rationale: ${item.rationale}
6807
+ Scope: ${item.files.join(", ")}
6808
+ Alternatives rejected: ${item.alternativesRejected.join("; ")}
6809
+ `
6810
+ );
6811
+ if (index === 0) {
6812
+ const extracted = SAMPLE_DECISIONS[0];
6813
+ process.stderr.write(
6814
+ `Source evidence:
6815
+ ${extracted.evidence.map((quote) => ` "${quote}"`).join("\n")}
6816
+ Scope basis: ${extracted.scopeBasis}
6817
+ `
6818
+ );
6819
+ }
6820
+ }
6821
+ function narrateBlockedAttempt(unchanged) {
6822
+ process.stderr.write(`
6823
+ ${bold(color("BLOCKED \u2014 file unchanged (simulated)", "red"))}
6824
+ `);
6825
+ process.stderr.write(
6826
+ `Attempt: save the order with localStorage.setItem(...).
6827
+ Decision (adopted sample): ${SAMPLE_DECISIONS[1].decision}
6828
+ Conflict: direct storage bypasses the shared repository and its validation.
6829
+ Outcome: this scenario refuses the proposed write.
6830
+ `
6831
+ );
6832
+ process.stderr.write(createPatch("orders.ts (refused proposal)", unchanged, BLOCKED_EDIT));
6833
+ process.stderr.write(
6834
+ `Proof: orders.ts is unchanged. Actual file:
6835
+ ${unchanged}
6836
+ Next: save through orders.save(...) to preserve repository validation.
6837
+ `
6838
+ );
6839
+ }
6840
+ function narrateCompletion(run) {
6841
+ process.stderr.write(`
6842
+ ${bold(color("WALKTHROUGH COMPLETE \u2014 simulated", "green"))}
6843
+ `);
6844
+ process.stderr.write(`${completionReceipt.map((item) => `\u2713 ${item}`).join("\n")}
6845
+ `);
6846
+ process.stderr.write(`${handoff}
6847
+ ${run.terminal ? "" : `${captureNotice}
6848
+ `}`);
6849
+ }
6850
+ function advanceDemo(id, action, choice) {
6851
+ return lockRun(id, (run) => {
6852
+ if (action === "skip") {
6853
+ cleanSandbox(run);
6854
+ run.stage = "skipped";
6855
+ saveRun(run);
6856
+ finishOnboarding("skipped");
6857
+ process.stderr.write(`[prim] ${handoff}
6858
+ `);
6859
+ if (run.binding) process.stderr.write(`${captureNotice}
6860
+ `);
6861
+ return resultFor2(run);
6862
+ }
6863
+ if (!consumeAcknowledgment(run, action, choice)) {
6864
+ const message = `Tour pending: session isolation has not been acknowledged. ${demoTrustGuidance(run.agent)}`;
6865
+ process.stderr.write(`[prim] ${message}
6866
+ `);
6867
+ return {
6868
+ ...resultFor2(run),
6869
+ stage: "pending",
6870
+ message,
6871
+ nextAction: demoCommand(run, action, choice)
6872
+ };
6873
+ }
6874
+ if (action === "confirm" && run.stage === "prepared") {
6875
+ throw new Error("start the demo before confirming its proposal");
6876
+ }
6877
+ if (action === "resolve" && (run.stage === "prepared" || run.stage === "proposal")) {
6878
+ throw new Error("confirm the sample Decision before resolving");
6879
+ }
6880
+ try {
6881
+ process.stderr.write(`${bold(intro)}
6882
+ `);
6883
+ if (!run.terminal && action === "start") process.stderr.write(`${captureNotice}
6884
+ `);
6885
+ if (run.stage === "completed") {
6886
+ narrateCompletion(run);
6887
+ return { ...resultFor2(run), receipt: completionReceipt };
6888
+ }
6889
+ if (run.stage === "skipped") return resultFor2(run);
6890
+ if (action === "start") {
6891
+ if (run.stage === "prepared") {
6892
+ createSandbox(run);
6893
+ run.stage = "proposal";
6894
+ saveRun(run);
6895
+ }
6896
+ if (run.stage === "proposal") {
6897
+ process.stderr.write(
6898
+ `
6899
+ ${bold("YOUR MISSION: add order saving")}
6900
+ Your fictional team discussed how this should work. Watch that context become Decisions, then guide an agent's implementation.
6901
+ Local simulation \xB7 fictional examples \xB7 disposable files
6902
+ `
6903
+ );
6904
+ process.stderr.write(`
6905
+ Sample ingestion (scripted extraction):
6906
+ ${SAMPLE_NOTE}
6907
+ `);
6908
+ process.stderr.write(`
6909
+ ${bold(color("DECISION EXTRACTED \u2014 simulated", "green"))}
6910
+ `);
6911
+ narrateDecision(0);
6912
+ process.stderr.write("The choice, its reason, and its source now travel together.\n");
6913
+ process.stderr.write("\nNow explicitly author another sample Decision:\n");
6914
+ narrateDecision(1);
6915
+ process.stderr.write("Confirm this fictional Decision to adopt it, or skip the tour.\n");
6916
+ }
6917
+ return {
6918
+ ...resultFor2(run),
6919
+ decisions: SAMPLE_DECISIONS.slice(0, run.stage === "proposal" ? 1 : 2)
6920
+ };
6921
+ }
6922
+ if (action === "confirm") {
6923
+ const before2 = SAMPLE_FILES["service.ts"];
6924
+ if (run.stage === "proposal") {
6925
+ writeSample(run, "decisions.json", decisionBytes(true));
6926
+ writeSample(run, "service.ts", WARNING_EDIT);
6927
+ run.stage = "conflict";
6928
+ saveRun(run);
6929
+ process.stderr.write(
6930
+ `
6931
+ ${bold(color("SAMPLE DECISION ADOPTED \u2014 simulated", "green"))}
6932
+ ${SAMPLE_DECISIONS[1].decision}
6933
+ Your confirmation changed this proposal into an adopted sample Decision.
6934
+ `
6935
+ );
6936
+ }
6937
+ const after2 = readSample(run, "service.ts");
6938
+ const unchanged = readSample(run, "orders.ts");
6939
+ process.stderr.write(`
6940
+ ${bold(color("WARNING \u2014 edit allowed (simulated)", "yellow"))}
6941
+ `);
6942
+ process.stderr.write(
6943
+ `Attempt: call fetch("/orders") directly.
6944
+ Decision (provisional sample): ${SAMPLE_DECISIONS[0].decision}
6945
+ Conflict: direct fetch bypasses consistent retries and request tracing.
6946
+ Outcome: this scenario surfaces the conflict and allows the edit.
6947
+ `
6948
+ );
6949
+ process.stderr.write(createPatch("service.ts", before2, after2));
6950
+ process.stderr.write(
6951
+ `Proof: service.ts ${before2 === after2 ? "already matches the shared client" : "changed, as shown above"}.
6952
+ Next: restore the shared HTTP client for consistent retries and tracing.
6953
+ `
6954
+ );
6955
+ narrateBlockedAttempt(unchanged);
6956
+ process.stderr.write(
6957
+ "\nChoose the shared repository correction, or retry direct storage.\nThese verdicts are scripted for this scenario. Live outcomes depend on Decision state and agent behavior; Claude may ask permission where other agents block.\n"
6958
+ );
6959
+ return {
6960
+ ...resultFor2(run),
6961
+ decisions: SAMPLE_DECISIONS,
6962
+ evidence: {
6963
+ warning: { before: before2, after: after2 },
6964
+ block: {
6965
+ before: unchanged,
6966
+ proposed: BLOCKED_EDIT,
6967
+ after: readSample(run, "orders.ts")
6968
+ }
6969
+ }
6970
+ };
6971
+ }
6972
+ if (choice !== "repository" && choice !== "local-storage")
6973
+ throw new Error("choose repository or local-storage");
6974
+ if (choice === "local-storage") {
6975
+ const unchanged = readSample(run, "orders.ts");
6976
+ narrateBlockedAttempt(unchanged);
6977
+ return { ...resultFor2(run), evidence: { unchanged } };
6978
+ }
6979
+ const before = readSample(run, "service.ts");
6980
+ const ordersBefore = readSample(run, "orders.ts");
6981
+ writeSample(run, "service.ts", SAMPLE_FILES["service.ts"]);
6982
+ writeSample(run, "orders.ts", REPOSITORY_EDIT);
6983
+ const after = readSample(run, "service.ts");
6984
+ const orders = readSample(run, "orders.ts");
6985
+ process.stderr.write(createPatch("service.ts", before, after));
6986
+ process.stderr.write(createPatch("orders.ts", ordersBefore, orders));
6987
+ process.stderr.write(
6988
+ `${bold(color("PASS \u2014 compliant implementation written (simulated)", "green"))}
6989
+ Order saving now uses the shared repository. Service calls use the shared HTTP client.
6990
+ The requested change landed while preserving both sample Decisions.
6991
+ `
6992
+ );
6993
+ cleanSandbox(run);
6994
+ run.stage = "completed";
6995
+ saveRun(run);
6996
+ finishOnboarding("completed");
6997
+ narrateCompletion(run);
6998
+ return {
6999
+ ...resultFor2(run),
7000
+ receipt: completionReceipt,
7001
+ evidence: {
7002
+ correction: { before, after },
7003
+ orders,
7004
+ orderCorrection: { before: ordersBefore, after: orders }
7005
+ }
7006
+ };
7007
+ } catch (error) {
7008
+ try {
7009
+ cleanSandbox(run);
7010
+ run.stage = "prepared";
7011
+ saveRun(run);
7012
+ } catch {
7013
+ }
7014
+ throw error;
7015
+ }
7016
+ });
7017
+ }
7018
+ function parseDemoAgent(value) {
7019
+ if (value === "claude") return "claude_code";
7020
+ if (value === void 0 || ["claude_code", "codex", "cursor", "hermes"].includes(value))
7021
+ return value;
7022
+ throw new Error("expected --agent claude, codex, cursor, or hermes");
7023
+ }
7024
+ function reportError(error) {
7025
+ const message = error instanceof Error ? error.message : String(error);
7026
+ process.stderr.write(`[prim] demo: ${message}
7027
+ `);
7028
+ printJson({ simulated: true, stage: "error", message });
7029
+ process.exitCode = 1;
7030
+ }
7031
+ function registerDemoCommands(program2) {
7032
+ const demo = program2.command("demo").description("Try a fictional, local Decision and enforcement walkthrough").option("--agent <agent>", "calling agent; requires hook acknowledgment before samples").action(async (options, command) => {
7033
+ try {
7034
+ const agent = parseDemoAgent(options.agent);
7035
+ const terminal = !agent && !isNonInteractive(command.optsWithGlobals()) && Boolean(process.stdin.isTTY && process.stderr.isTTY) && !process.env.CLAUDECODE && !process.env.CODEX_THREAD_ID && !process.env.CURSOR_AGENT && !process.env.HERMES_INTERACTIVE;
7036
+ const recovery = pendingRuns().map(
7037
+ (id) => lockRun(id, (run2) => ({ runId: id, skipAction: demoCommand(run2, "skip") }))
7038
+ );
7039
+ const run = prepareRun(agent, terminal);
7040
+ if (!terminal) {
7041
+ process.stderr.write(
7042
+ "[prim] Preparing the simulated tour. Run nextAction exactly, as a standalone shell command. No sample content is shown until session isolation is acknowledged.\n"
7043
+ );
7044
+ if (recovery.length)
7045
+ process.stderr.write(
7046
+ "[prim] Earlier unfinished tours are listed in recoverableRuns; use their skipAction to clean up.\n"
7047
+ );
7048
+ printJson({ ...resultFor2(run), recoverableRuns: recovery });
7049
+ return;
7050
+ }
7051
+ advanceDemo(run.id, "start");
7052
+ if (!await askConfirmation("Adopt this fictional Decision?", process.stderr)) {
7053
+ printJson(advanceDemo(run.id, "skip"));
7054
+ return;
7055
+ }
7056
+ advanceDemo(run.id, "confirm");
7057
+ if (await askConfirmation("Apply the shared repository correction?", process.stderr)) {
7058
+ printJson(advanceDemo(run.id, "resolve", "repository"));
7059
+ } else {
7060
+ printJson(advanceDemo(run.id, "skip"));
7061
+ }
7062
+ } catch (error) {
7063
+ reportError(error);
7064
+ }
7065
+ });
7066
+ for (const action of ["start", "confirm", "resolve", "skip"]) {
7067
+ const subcommand = demo.command(`${action} ${action === "skip" ? "[runId]" : "<runId>"}`);
7068
+ if (action === "resolve")
7069
+ subcommand.requiredOption("--choice <choice>", "repository or local-storage");
7070
+ subcommand.action((id, options) => {
7071
+ try {
7072
+ if (action === "skip" && !id) {
7073
+ finishOnboarding("skipped");
7074
+ printJson({
7075
+ simulated: true,
7076
+ stage: "skipped",
7077
+ message: "Tour skipped. Run prim welcome for real Decision seeding."
7078
+ });
7079
+ return;
7080
+ }
7081
+ if (action === "resolve" && options.choice !== "repository" && options.choice !== "local-storage") {
7082
+ throw new Error("choose repository or local-storage");
7083
+ }
7084
+ printJson(advanceDemo(id, action, options.choice));
7085
+ } catch (error) {
7086
+ reportError(error);
7087
+ }
7088
+ });
7089
+ }
7090
+ }
7091
+
6600
7092
  // src/commands/doctor.ts
6601
- import { existsSync as existsSync6 } from "fs";
7093
+ import { existsSync as existsSync7 } from "fs";
6602
7094
  import { Option as Option4 } from "commander";
6603
7095
 
6604
7096
  // src/protocol/decision-lifecycle.ts
@@ -6724,9 +7216,9 @@ async function inspectJournalDelivery(buckets, options = {}) {
6724
7216
  }
6725
7217
 
6726
7218
  // src/commands/hermes-install.ts
6727
- import { existsSync as existsSync5, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync2 } from "fs";
7219
+ import { existsSync as existsSync6, readFileSync as readFileSync6, rmSync as rmSync2, statSync as statSync2 } from "fs";
6728
7220
  import { homedir as homedir4 } from "os";
6729
- import { join as join6 } from "path";
7221
+ import { join as join7 } from "path";
6730
7222
  import { Document, isMap, isSeq, parseAllDocuments, stringify, visit } from "yaml";
6731
7223
  var CAPTURE_BIN2 = "prim-hook";
6732
7224
  var GATE_BIN2 = "prim-pre-tool-use";
@@ -6739,13 +7231,13 @@ var JSON_INDENT2 = 2;
6739
7231
  var CONFIG_MODE = 384;
6740
7232
  var PRIM_BINS2 = [CAPTURE_BIN2, GATE_BIN2, POST_TOOL_USE_BIN2, SESSION_START_BIN2, SESSION_END_BIN];
6741
7233
  function hermesHome() {
6742
- return process.env.HERMES_HOME ?? join6(homedir4(), ".hermes");
7234
+ return process.env.HERMES_HOME ?? join7(homedir4(), ".hermes");
6743
7235
  }
6744
7236
  function configPath() {
6745
- return join6(hermesHome(), "config.yaml");
7237
+ return join7(hermesHome(), "config.yaml");
6746
7238
  }
6747
7239
  function legacyShimPath() {
6748
- return join6(hermesHome(), "agent-hooks", "prim-shim.sh");
7240
+ return join7(hermesHome(), "agent-hooks", "prim-shim.sh");
6749
7241
  }
6750
7242
  function commandFor(bin) {
6751
7243
  return stableHookCommand(bin, HERMES_ARGS);
@@ -6859,8 +7351,8 @@ function hookRuntimeResolutions2(hooks) {
6859
7351
  }
6860
7352
  function inspectHookRuntimeResolutions4() {
6861
7353
  const path = configPath();
6862
- if (!existsSync5(path)) return [];
6863
- return hookRuntimeResolutions2(readHooks(parseHermesDocument(readFileSync5(path, "utf8"))));
7354
+ if (!existsSync6(path)) return [];
7355
+ return hookRuntimeResolutions2(readHooks(parseHermesDocument(readFileSync6(path, "utf8"))));
6864
7356
  }
6865
7357
  function entryMatchesRegistration2(owned, registration) {
6866
7358
  const expected = entryFor(registration);
@@ -7129,11 +7621,11 @@ function assertMergeValid(before, after, expectedHooks) {
7129
7621
  }
7130
7622
  }
7131
7623
  function readConfigSnapshot(path) {
7132
- if (!existsSync5(path)) return { exists: false, mode: CONFIG_MODE, raw: "" };
7624
+ if (!existsSync6(path)) return { exists: false, mode: CONFIG_MODE, raw: "" };
7133
7625
  return {
7134
7626
  exists: true,
7135
7627
  mode: statSync2(path).mode & 511,
7136
- raw: readFileSync5(path, "utf8")
7628
+ raw: readFileSync6(path, "utf8")
7137
7629
  };
7138
7630
  }
7139
7631
  var CONCURRENT_CONFIG_MESSAGE = "Hermes config changed during update; concurrent changes were preserved, retry the command";
@@ -7142,7 +7634,7 @@ function writeHermesConfigSnapshot(path, before, after, expectedHooks) {
7142
7634
  ensureParent: true,
7143
7635
  mode: before.mode,
7144
7636
  validate(temporaryPath) {
7145
- const flushed = readFileSync5(temporaryPath, "utf8");
7637
+ const flushed = readFileSync6(temporaryPath, "utf8");
7146
7638
  if (!mergePreservesHermesSemantics(before.raw, flushed, expectedHooks)) {
7147
7639
  throw new Error(INVALID_MERGE_MESSAGE);
7148
7640
  }
@@ -7195,7 +7687,7 @@ function performInstall2(opts) {
7195
7687
  }
7196
7688
  function performUninstall2() {
7197
7689
  const path = configPath();
7198
- if (!existsSync5(path)) {
7690
+ if (!existsSync6(path)) {
7199
7691
  removeLegacyShim();
7200
7692
  return { path, gate: false, capture: false, autoAccept: false, changed: false };
7201
7693
  }
@@ -7220,7 +7712,7 @@ function performUninstall2() {
7220
7712
  }
7221
7713
  function performStatus4() {
7222
7714
  const path = configPath();
7223
- const raw = existsSync5(path) ? readFileSync5(path, "utf8") : "";
7715
+ const raw = existsSync6(path) ? readFileSync6(path, "utf8") : "";
7224
7716
  const hooks = raw ? readHooks(parseHermesDocument(raw)) : {};
7225
7717
  return {
7226
7718
  path,
@@ -7309,7 +7801,7 @@ function checkAuth() {
7309
7801
  return classifyAuthCredential(
7310
7802
  credential,
7311
7803
  storedCredential ? getTokenExpiresAt() : void 0,
7312
- storedCredential && existsSync6(REFRESH_TOKEN_PATH)
7804
+ storedCredential && existsSync7(REFRESH_TOKEN_PATH)
7313
7805
  );
7314
7806
  }
7315
7807
  function classifyDaemonHealth(snapshot, options = {}) {
@@ -8103,12 +8595,12 @@ function registerDoctorCommands(program2, dependencies = {}) {
8103
8595
  }
8104
8596
 
8105
8597
  // src/commands/moves.ts
8106
- import { existsSync as existsSync8, mkdirSync as mkdirSync5, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "fs";
8107
- import { join as join9 } from "path";
8598
+ import { existsSync as existsSync9, mkdirSync as mkdirSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync4 } from "fs";
8599
+ import { join as join10 } from "path";
8108
8600
 
8109
8601
  // src/flusher.ts
8110
- import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as unlinkSync3 } from "fs";
8111
- import { dirname as dirname3, join as join8 } from "path";
8602
+ import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as unlinkSync4 } from "fs";
8603
+ import { dirname as dirname4, join as join9 } from "path";
8112
8604
 
8113
8605
  // src/dead-letter.ts
8114
8606
  import { createHash as createHash3, randomBytes as randomBytes4 } from "crypto";
@@ -8116,7 +8608,7 @@ import {
8116
8608
  constants as constants3,
8117
8609
  chmodSync as chmodSync2,
8118
8610
  closeSync as closeSync3,
8119
- existsSync as existsSync7,
8611
+ existsSync as existsSync8,
8120
8612
  fchmodSync,
8121
8613
  fsyncSync,
8122
8614
  mkdirSync as mkdirSync4,
@@ -8125,30 +8617,30 @@ import {
8125
8617
  rmSync as rmSync3,
8126
8618
  writeFileSync as writeFileSync3
8127
8619
  } from "fs";
8128
- import { dirname as dirname2, join as join7 } from "path";
8620
+ import { dirname as dirname3, join as join8 } from "path";
8129
8621
  var DIRECTORY_MODE = 448;
8130
8622
  var FILE_MODE = 384;
8131
8623
  var DEAD_LETTER_DIRNAME = "dead-letter";
8132
8624
  function deadLetterDirectoryForRotation(flushingPath) {
8133
- return join7(dirname2(flushingPath), DEAD_LETTER_DIRNAME);
8625
+ return join8(dirname3(flushingPath), DEAD_LETTER_DIRNAME);
8134
8626
  }
8135
8627
  function deadLetterPathForRawLine(flushingPath, rawLine) {
8136
8628
  const quarantineId = createHash3("sha256").update(rawLine).digest("hex");
8137
- return join7(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
8629
+ return join8(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
8138
8630
  }
8139
8631
  function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
8140
8632
  const directory = deadLetterDirectoryForRotation(flushingPath);
8141
8633
  mkdirSync4(directory, { recursive: true, mode: DIRECTORY_MODE });
8142
8634
  chmodSync2(directory, DIRECTORY_MODE);
8143
- persistDirectory(dirname2(directory));
8635
+ persistDirectory(dirname3(directory));
8144
8636
  return directory;
8145
8637
  }
8146
8638
  function persistDeadLetter(directory, path, quarantineId, record3, persistDirectory) {
8147
- if (existsSync7(path)) {
8639
+ if (existsSync8(path)) {
8148
8640
  persistDirectory(directory);
8149
8641
  return;
8150
8642
  }
8151
- const temporaryPath = join7(
8643
+ const temporaryPath = join8(
8152
8644
  directory,
8153
8645
  `.${quarantineId}.${String(process.pid)}.${randomBytes4(8).toString("hex")}.tmp`
8154
8646
  );
@@ -8180,7 +8672,7 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
8180
8672
  reason,
8181
8673
  move
8182
8674
  };
8183
- const path = join7(directory, `${record3.quarantineId}.json`);
8675
+ const path = join8(directory, `${record3.quarantineId}.json`);
8184
8676
  persistDeadLetter(directory, path, record3.quarantineId, record3, persistDirectory);
8185
8677
  return record3;
8186
8678
  }
@@ -8431,7 +8923,7 @@ async function drainFlushingPath(flushingPath, client, binding, options = {}) {
8431
8923
  } finally {
8432
8924
  input.destroy();
8433
8925
  }
8434
- unlinkSync3(flushingPath);
8926
+ unlinkSync4(flushingPath);
8435
8927
  try {
8436
8928
  removeDrainCheckpoint(flushingPath);
8437
8929
  } catch {
@@ -8575,7 +9067,7 @@ async function flushOnce() {
8575
9067
  return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
8576
9068
  }
8577
9069
  var flushInFlight;
8578
- var FLUSH_LOCK_PATH = join8(dirname3(JOURNAL_DIR), ".flush.lock");
9070
+ var FLUSH_LOCK_PATH = join9(dirname4(JOURNAL_DIR), ".flush.lock");
8579
9071
  var FLUSH_LOCK_TIMEOUT_MS = 250;
8580
9072
  function isFlushLockContended(error) {
8581
9073
  return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
@@ -8707,23 +9199,23 @@ function registerMovesCommands(program2) {
8707
9199
  }
8708
9200
  });
8709
9201
  moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
8710
- const dir = join9(process.cwd(), ".prim");
8711
- if (!existsSync8(dir)) {
9202
+ const dir = join10(process.cwd(), ".prim");
9203
+ if (!existsSync9(dir)) {
8712
9204
  mkdirSync5(dir, { recursive: true, mode: DIR_MODE });
8713
9205
  }
8714
- const file = join9(process.cwd(), WORKSPACE_FILE);
9206
+ const file = join10(process.cwd(), WORKSPACE_FILE);
8715
9207
  writeFileSync4(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
8716
9208
  mode: FILE_MODE2
8717
9209
  });
8718
9210
  console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
8719
9211
  });
8720
9212
  moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
8721
- const file = join9(process.cwd(), WORKSPACE_FILE);
8722
- if (!existsSync8(file)) {
9213
+ const file = join10(process.cwd(), WORKSPACE_FILE);
9214
+ if (!existsSync9(file)) {
8723
9215
  console.log("[prim] no workspace binding in cwd");
8724
9216
  return;
8725
9217
  }
8726
- unlinkSync4(file);
9218
+ unlinkSync5(file);
8727
9219
  console.log(`[prim] dropped workspace binding from ${process.cwd()}`);
8728
9220
  });
8729
9221
  }
@@ -8849,23 +9341,23 @@ function registerReconcileCommands(program2) {
8849
9341
 
8850
9342
  // src/commands/session.ts
8851
9343
  import {
8852
- existsSync as existsSync9,
9344
+ existsSync as existsSync10,
8853
9345
  mkdirSync as mkdirSync6,
8854
- readFileSync as readFileSync6,
8855
- readdirSync as readdirSync3,
8856
- unlinkSync as unlinkSync5,
9346
+ readFileSync as readFileSync7,
9347
+ readdirSync as readdirSync4,
9348
+ unlinkSync as unlinkSync6,
8857
9349
  writeFileSync as writeFileSync5
8858
9350
  } from "fs";
8859
- import { join as join10 } from "path";
9351
+ import { join as join11 } from "path";
8860
9352
  var DIR_MODE2 = 448;
8861
9353
  var FILE_MODE3 = 384;
8862
9354
  function ensureDir() {
8863
- if (!existsSync9(SESSIONS_DIR)) {
9355
+ if (!existsSync10(SESSIONS_DIR)) {
8864
9356
  mkdirSync6(SESSIONS_DIR, { recursive: true, mode: DIR_MODE2 });
8865
9357
  }
8866
9358
  }
8867
9359
  function markerPath(sessionId) {
8868
- return join10(SESSIONS_DIR, `${sessionId}.json`);
9360
+ return join11(SESSIONS_DIR, `${sessionId}.json`);
8869
9361
  }
8870
9362
  function registerSessionCommands(program2) {
8871
9363
  const session = program2.command("session").description("Decision Event Pipeline \u2014 session binding markers");
@@ -8881,11 +9373,11 @@ function registerSessionCommands(program2) {
8881
9373
  console.log(`[prim] session ${sessionId} bound to org ${opts.orgId}`);
8882
9374
  });
8883
9375
  session.command("list").description("List active session markers").action(() => {
8884
- if (!existsSync9(SESSIONS_DIR)) {
9376
+ if (!existsSync10(SESSIONS_DIR)) {
8885
9377
  console.log("[prim] no session markers");
8886
9378
  return;
8887
9379
  }
8888
- const files = readdirSync3(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
9380
+ const files = readdirSync4(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
8889
9381
  if (files.length === 0) {
8890
9382
  console.log("[prim] no session markers");
8891
9383
  return;
@@ -8893,7 +9385,7 @@ function registerSessionCommands(program2) {
8893
9385
  for (const f of files) {
8894
9386
  const sessionId = f.replace(/\.json$/, "");
8895
9387
  try {
8896
- const m = JSON.parse(readFileSync6(join10(SESSIONS_DIR, f), "utf-8"));
9388
+ const m = JSON.parse(readFileSync7(join11(SESSIONS_DIR, f), "utf-8"));
8897
9389
  console.log(`${sessionId} org=${m.orgId}`);
8898
9390
  } catch {
8899
9391
  }
@@ -8901,19 +9393,19 @@ function registerSessionCommands(program2) {
8901
9393
  });
8902
9394
  session.command("drop <sessionId>").description("Remove a session marker").action((sessionId) => {
8903
9395
  const p = markerPath(sessionId);
8904
- if (!existsSync9(p)) {
9396
+ if (!existsSync10(p)) {
8905
9397
  console.log(`[prim] no marker for session ${sessionId}`);
8906
9398
  return;
8907
9399
  }
8908
- unlinkSync5(p);
9400
+ unlinkSync6(p);
8909
9401
  console.log(`[prim] dropped session marker ${sessionId}`);
8910
9402
  });
8911
9403
  }
8912
9404
 
8913
9405
  // src/commands/setup.ts
8914
9406
  import { spawnSync as spawnSync2 } from "child_process";
8915
- import { existsSync as existsSync10, readFileSync as readFileSync7 } from "fs";
8916
- import { join as join11 } from "path";
9407
+ import { existsSync as existsSync11, readFileSync as readFileSync8 } from "fs";
9408
+ import { join as join12 } from "path";
8917
9409
  var EXIT_INCOMPLETE = 1;
8918
9410
  var EXIT_USAGE3 = 2;
8919
9411
  var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
@@ -9051,8 +9543,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
9051
9543
  let preCommit;
9052
9544
  try {
9053
9545
  const root = gitToplevel();
9054
- const path = root && join11(root, ".git", "hooks", "pre-commit");
9055
- if (path && existsSync10(path)) preCommit = readFileSync7(path, "utf-8");
9546
+ const path = root && join12(root, ".git", "hooks", "pre-commit");
9547
+ if (path && existsSync11(path)) preCommit = readFileSync8(path, "utf-8");
9056
9548
  } catch {
9057
9549
  }
9058
9550
  if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
@@ -9103,7 +9595,7 @@ function registerSetupCommand(program2, dependencies = {}) {
9103
9595
  ).option(
9104
9596
  "--migrate",
9105
9597
  "with the default user scope, remove any project-scoped prim config in this repo (else just warn)"
9106
- ).option("--no-daemon", "stop and disable the companion daemon").action((opts) => {
9598
+ ).option("--no-daemon", "stop and disable the companion daemon").option("--skip-demo", "skip the local onboarding tour and remember that choice").action((opts) => {
9107
9599
  const { agent: agentInput, detected } = resolveAgent(opts.agent, process.env);
9108
9600
  if (agentInput !== "claude" && agentInput !== "codex" && agentInput !== "cursor" && agentInput !== "hermes") {
9109
9601
  process.stderr.write(
@@ -9220,25 +9712,53 @@ function registerSetupCommand(program2, dependencies = {}) {
9220
9712
  const { code } = run(healthStep.args);
9221
9713
  results[healthStep.key] = code === 0 ? "ok" : healthStep.required ? "failed" : "skipped";
9222
9714
  }
9715
+ const installationSucceeded = !Object.values(results).includes("failed");
9716
+ let tourDue = false;
9717
+ if (installationSucceeded && !opts.skipDemo) {
9718
+ try {
9719
+ tourDue = !onboardingFinished();
9720
+ } catch (error) {
9721
+ tourDue = true;
9722
+ note(
9723
+ `demo \xB7 cannot read onboarding state: ${error instanceof Error ? error.message : String(error)}; use prim demo to retry`
9724
+ );
9725
+ }
9726
+ }
9727
+ if (installationSucceeded && opts.skipDemo) {
9728
+ if (run(["demo", "skip"]).code !== 0)
9729
+ note("demo \xB7 could not remember skip; installation remains configured");
9730
+ }
9223
9731
  note("welcome");
9224
- results.welcome = run(["welcome", "--agent", agent]).code === 0 ? "ok" : "failed";
9732
+ results.welcome = run(["welcome", "--agent", agent, ...tourDue ? ["--defer-seeding"] : []]).code === 0 ? "ok" : "failed";
9225
9733
  const failed = Object.entries(results).filter(([, v]) => v === "failed").map(([k]) => k);
9226
9734
  const trail = Object.entries(results).map(([k, v]) => `${k}:${v}`).join(" \xB7 ");
9227
9735
  note(
9228
9736
  `setup ${failed.length === 0 ? "complete" : `incomplete (failed: ${failed.join(", ")})`} \u2014 ${trail}`
9229
9737
  );
9738
+ if (failed.length === 0 && tourDue) {
9739
+ const agentDriven = Boolean(
9740
+ opts.agent || !process.stdin.isTTY || !process.stderr.isTTY || process.env.CLAUDECODE || process.env.CODEX_THREAD_ID || process.env.CURSOR_AGENT || process.env.HERMES_INTERACTIVE
9741
+ );
9742
+ const demoResult = run([
9743
+ ...globals.nonInteractive ? ["--non-interactive"] : [],
9744
+ "demo",
9745
+ ...agentDriven ? ["--agent", agent] : []
9746
+ ]);
9747
+ if (demoResult.code !== 0)
9748
+ note("demo \xB7 pending after an error; setup succeeded. Run prim demo to retry");
9749
+ }
9230
9750
  exit(failed.length === 0 ? 0 : EXIT_INCOMPLETE);
9231
9751
  });
9232
9752
  }
9233
9753
 
9234
9754
  // src/commands/statusline.ts
9235
- import { readFileSync as readFileSync8 } from "fs";
9236
- import { dirname as dirname4, resolve as resolve3 } from "path";
9755
+ import { readFileSync as readFileSync9 } from "fs";
9756
+ import { dirname as dirname5, resolve as resolve3 } from "path";
9237
9757
  import { fileURLToPath } from "url";
9238
9758
  var STATUSLINE_TIMEOUT_MS = 200;
9239
9759
  function readPackageVersion() {
9240
9760
  try {
9241
- const here = dirname4(fileURLToPath(import.meta.url));
9761
+ const here = dirname5(fileURLToPath(import.meta.url));
9242
9762
  const candidates = [
9243
9763
  // Schema-v2 runtimes staged a manifest beside this standalone bundle.
9244
9764
  // Keep resolving it while those legacy launchers transition to schema v3.
@@ -9248,7 +9768,7 @@ function readPackageVersion() {
9248
9768
  ];
9249
9769
  for (const path of candidates) {
9250
9770
  try {
9251
- const pkg2 = JSON.parse(readFileSync8(path, "utf-8"));
9771
+ const pkg2 = JSON.parse(readFileSync9(path, "utf-8"));
9252
9772
  if (pkg2.version) {
9253
9773
  return pkg2.version;
9254
9774
  }
@@ -9561,10 +10081,11 @@ var GUIDANCE_PASSIVE = {
9561
10081
  hermes: "Otherwise, once you approve the prim hooks when Hermes prompts, Primitive passively captures decisions in the background while you work.",
9562
10082
  generic: "Otherwise, once your agent's prim hooks are active, Primitive passively captures decisions in the background while you work."
9563
10083
  };
9564
- function seedGuidanceFor(agent) {
10084
+ var EXCLUDED_CAPTURE = "Passive capture is excluded for this onboarding session. Start a new session for normal capture; explicitly approved real Decisions can still be created.";
10085
+ function seedGuidanceFor(agent, captureExcluded = false) {
9565
10086
  return [
9566
10087
  "You can tell your agent to add any decision to your Primitive decision graph at any time.",
9567
- GUIDANCE_PASSIVE[agent ?? "generic"],
10088
+ captureExcluded ? EXCLUDED_CAPTURE : GUIDANCE_PASSIVE[agent ?? "generic"],
9568
10089
  "To capture decisions in other repositories, enable Primitive there too: run `prim enable` in each one."
9569
10090
  ].join(" ");
9570
10091
  }
@@ -9579,7 +10100,7 @@ function welcomeStateFromRecent(result) {
9579
10100
  }
9580
10101
  return { org: "active", recent };
9581
10102
  }
9582
- function formatWelcome(state, agent) {
10103
+ function formatWelcome(state, agent, captureExcluded = false) {
9583
10104
  const cmd = (command, desc) => ` ${dim(command.padEnd(CMD_GUTTER))}${desc}`;
9584
10105
  const bullet = (text) => ` ${color("\u2022", "green")} ${text}`;
9585
10106
  const asBullet = ([first, ...rest]) => [
@@ -9594,7 +10115,7 @@ function formatWelcome(state, agent) {
9594
10115
  "shared graph \u2014 automatically, as you work.",
9595
10116
  "",
9596
10117
  bold("How it works"),
9597
- ...asBullet(CAPTURE_LINES[copyKey]),
10118
+ ...asBullet(captureExcluded ? [EXCLUDED_CAPTURE] : CAPTURE_LINES[copyKey]),
9598
10119
  bullet("Conflict Gates can warn, ask, or block edits that conflict"),
9599
10120
  " with a load-bearing decision when Enforcement is enabled.",
9600
10121
  bullet('Occasional yes/no prompts confirm the "why" behind a decision \u2014'),
@@ -9624,7 +10145,7 @@ function formatWelcome(state, agent) {
9624
10145
  "",
9625
10146
  bold("From here on"),
9626
10147
  bullet("Tell your agent to add any decision to Primitive, any time."),
9627
- ...asBullet(PASSIVE_LINES[copyKey]),
10148
+ ...asBullet(captureExcluded ? [EXCLUDED_CAPTURE] : PASSIVE_LINES[copyKey]),
9628
10149
  bullet("Run `prim enable` in each additional repo you want captured.")
9629
10150
  ];
9630
10151
  } else {
@@ -9637,7 +10158,7 @@ function formatWelcome(state, agent) {
9637
10158
  }
9638
10159
  return [...head, ...body, "", dim("App: https://app.getprimitive.ai")].join("\n");
9639
10160
  }
9640
- function welcomeJson(state, agent) {
10161
+ function welcomeJson(state, agent, captureExcluded = false) {
9641
10162
  if (state.org === "active") {
9642
10163
  return { welcomed: true, org: "active", recent: state.recent };
9643
10164
  }
@@ -9645,21 +10166,30 @@ function welcomeJson(state, agent) {
9645
10166
  return {
9646
10167
  welcomed: true,
9647
10168
  org: "seed",
9648
- seedGuidance: seedGuidanceFor(agent),
10169
+ seedGuidance: seedGuidanceFor(agent, captureExcluded),
9649
10170
  recent: state.recent
9650
10171
  };
9651
10172
  }
9652
10173
  return { welcomed: true, org: "unknown" };
9653
10174
  }
9654
10175
  function registerWelcomeCommand(program2, deps = { getClient }) {
9655
- program2.command("welcome").description("Print a brief orientation to Primitive's decision graph").option("--agent <agent>", "claude, codex, cursor, or hermes \u2014 tailors the capture guidance").action(async (options) => {
9656
- const agent = resolveWelcomeAgent(options.agent, process.env);
9657
- const result = await fetchRecent({ limit: RECENT_LIMIT }, deps);
9658
- const state = welcomeStateFromRecent(result);
9659
- process.stderr.write(`${formatWelcome(state, agent)}
10176
+ program2.command("welcome").description("Print a brief orientation to Primitive's decision graph").option("--agent <agent>", "claude, codex, cursor, or hermes \u2014 tailors the capture guidance").option("--defer-seeding", "let setup's local tour finish before proposing real Decisions").option("--capture-excluded", "explain the demo session's passive capture exclusion").action(
10177
+ async (options) => {
10178
+ const agent = resolveWelcomeAgent(options.agent, process.env);
10179
+ if (options.deferSeeding) {
10180
+ process.stderr.write(
10181
+ "Welcome to Primitive. Setup is complete; the optional simulated tour comes before real Decision seeding.\n"
10182
+ );
10183
+ printJson({ welcomed: true, onboarding: "demo", seedingDeferred: true });
10184
+ return;
10185
+ }
10186
+ const result = await fetchRecent({ limit: RECENT_LIMIT }, deps);
10187
+ const state = welcomeStateFromRecent(result);
10188
+ process.stderr.write(`${formatWelcome(state, agent, options.captureExcluded)}
9660
10189
  `);
9661
- printJson(welcomeJson(state, agent));
9662
- });
10190
+ printJson(welcomeJson(state, agent, options.captureExcluded));
10191
+ }
10192
+ );
9663
10193
  }
9664
10194
 
9665
10195
  // src/daemon/drift-heal.ts
@@ -9753,13 +10283,13 @@ function healDaemonDrift(options = {}) {
9753
10283
 
9754
10284
  // src/lib/background-flush.ts
9755
10285
  import { spawn as spawn3 } from "child_process";
9756
- import { readFileSync as readFileSync9 } from "fs";
10286
+ import { readFileSync as readFileSync10 } from "fs";
9757
10287
 
9758
10288
  // src/daemon/health.ts
9759
- import { chmodSync as chmodSync3, existsSync as existsSync11, mkdirSync as mkdirSync7, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "fs";
9760
- import { dirname as dirname5, join as join12 } from "path";
10289
+ import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync7, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "fs";
10290
+ import { dirname as dirname6, join as join13 } from "path";
9761
10291
  var HEARTBEAT_FRESH_MS = 9e4;
9762
- var DAEMON_HEALTH_PATH = join12(primConfigDirectory(), "daemon-health.json");
10292
+ var DAEMON_HEALTH_PATH = join13(primConfigDirectory(), "daemon-health.json");
9763
10293
 
9764
10294
  // src/lib/background-flush.ts
9765
10295
  function record2(value) {
@@ -9770,7 +10300,7 @@ function daemonOwnsDrain(options = {}) {
9770
10300
  const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
9771
10301
  if (!expectedVersion) return false;
9772
10302
  const health = record2(
9773
- JSON.parse(readFileSync9(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
10303
+ JSON.parse(readFileSync10(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
9774
10304
  );
9775
10305
  const heartbeat = record2(health?.heartbeat);
9776
10306
  const ingestion = record2(health?.ingestion);
@@ -9878,7 +10408,7 @@ function runStartupBackgroundWork(argv, env, work) {
9878
10408
  const args = commandArguments(argv);
9879
10409
  const [command, subcommand] = args;
9880
10410
  const uninstall = command === "uninstall" || env[UNINSTALL_ORCHESTRATOR_ENV] === "1";
9881
- if (uninstall) return;
10411
+ if (uninstall || command === "demo") return;
9882
10412
  work.notify();
9883
10413
  const setupDaemonDrains = command === "setup" && !args.includes("--no-daemon") || env[SETUP_DAEMON_DRAINS_ENV] === "1";
9884
10414
  if (!setupDaemonDrains && (command !== "moves" || subcommand !== "flush")) work.flush();
@@ -9886,8 +10416,8 @@ function runStartupBackgroundWork(argv, env, work) {
9886
10416
  }
9887
10417
 
9888
10418
  // src/index.ts
9889
- var __dirname = dirname6(fileURLToPath2(import.meta.url));
9890
- var pkg = JSON.parse(readFileSync10(resolve4(__dirname, "../package.json"), "utf-8"));
10419
+ var __dirname = dirname7(fileURLToPath2(import.meta.url));
10420
+ var pkg = JSON.parse(readFileSync11(resolve4(__dirname, "../package.json"), "utf-8"));
9891
10421
  runStartupBackgroundWork(process.argv.slice(2), process.env, {
9892
10422
  notify: () => updateNotifier({ pkg }).notify(),
9893
10423
  flush: () => startBackgroundFlush(),
@@ -9905,6 +10435,7 @@ registerSkillCommands(program);
9905
10435
  registerMovesCommands(program);
9906
10436
  registerSessionCommands(program);
9907
10437
  registerDecisionsCommands(program);
10438
+ registerDemoCommands(program);
9908
10439
  registerClaudeCommands(program);
9909
10440
  registerCodexCommands(program);
9910
10441
  registerCursorCommands(program);