@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 +32 -18
- package/SKILL.md +88 -57
- package/dist/{chunk-IDMLJ4TM.js → chunk-4CO4A6NR.js} +1 -1
- package/dist/{chunk-RCFDZ4DY.js → chunk-6L7EYXVF.js} +3 -3
- package/dist/{chunk-H6JAQVW4.js → chunk-6VFUHQ4J.js} +1 -1
- package/dist/{chunk-5HFTJEA6.js → chunk-72CQVK4E.js} +1 -1
- package/dist/{chunk-LNFWFYSN.js → chunk-7NNJ67YN.js} +69 -35
- package/dist/{chunk-GSBHBU7N.js → chunk-FFYZ3XMX.js} +1469 -533
- package/dist/{chunk-MZEVEPL3.js → chunk-LVRD562C.js} +1 -1
- package/dist/chunk-P5I4HGMW.js +233 -0
- package/dist/{chunk-C4D2LMTS.js → chunk-TPWJQD5E.js} +1 -1
- package/dist/daemon/server.js +1457 -531
- package/dist/hook-runtime/daemon/server.js +1457 -531
- package/dist/hook-runtime/hooks/post-commit.js +1454 -528
- package/dist/hook-runtime/hooks/post-rewrite.js +1454 -528
- package/dist/hook-runtime/hooks/post-tool-use.js +7201 -6195
- package/dist/hook-runtime/hooks/pre-tool-use.js +3359 -2351
- package/dist/hook-runtime/hooks/prim-hook.js +3390 -2382
- package/dist/hook-runtime/hooks/session-start.js +1454 -528
- package/dist/hook-runtime/index.js +2319 -1122
- package/dist/hooks/post-commit.js +3 -3
- package/dist/hooks/post-rewrite.js +3 -3
- package/dist/hooks/post-tool-use.js +9 -9
- package/dist/hooks/pre-tool-use.js +6 -6
- package/dist/hooks/prim-hook.js +8 -8
- package/dist/hooks/session-start.js +3 -3
- package/dist/index.js +575 -380
- package/package.json +1 -1
- package/dist/chunk-6WCBVSND.js +0 -107
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from "./chunk-2EKPBZNA.js";
|
|
23
23
|
import {
|
|
24
24
|
requireDurableIngestAcknowledgement
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-4CO4A6NR.js";
|
|
26
26
|
import {
|
|
27
27
|
checkAffectedDecisions,
|
|
28
28
|
daemonOrDirectGet,
|
|
@@ -60,15 +60,22 @@ import {
|
|
|
60
60
|
import {
|
|
61
61
|
RUN_ID,
|
|
62
62
|
demoCommand,
|
|
63
|
+
demoDiagnosticCommand,
|
|
64
|
+
demoResumeCommand,
|
|
65
|
+
demoWelcomeCommand,
|
|
63
66
|
exclusionPath,
|
|
64
67
|
finishOnboarding,
|
|
68
|
+
isolationDiagnostics,
|
|
65
69
|
lockRun,
|
|
70
|
+
lockRunAsync,
|
|
66
71
|
onboardingFinished,
|
|
67
72
|
pendingRuns,
|
|
73
|
+
preparationKey,
|
|
68
74
|
prepareRun,
|
|
69
75
|
readDemoJson,
|
|
76
|
+
readRun,
|
|
70
77
|
saveRun
|
|
71
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-P5I4HGMW.js";
|
|
72
79
|
import {
|
|
73
80
|
MS_PER_SECOND,
|
|
74
81
|
deliveryBacklogState,
|
|
@@ -77,7 +84,7 @@ import {
|
|
|
77
84
|
formatStatusline,
|
|
78
85
|
formatTeammates,
|
|
79
86
|
repositoryBindingDiagnosticLabel
|
|
80
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-72CQVK4E.js";
|
|
81
88
|
import {
|
|
82
89
|
bold,
|
|
83
90
|
boundedHealthError,
|
|
@@ -91,13 +98,18 @@ import {
|
|
|
91
98
|
isDecisionRescopeResponse,
|
|
92
99
|
isDecisionStageSuccessResponse,
|
|
93
100
|
isDecisionSupersedeRequest,
|
|
101
|
+
isDemoCompleteRequest,
|
|
102
|
+
isDemoResolveRequest,
|
|
103
|
+
isDemoRunRequest,
|
|
104
|
+
isDemoStartRequest,
|
|
105
|
+
isDemoStatusResponse,
|
|
94
106
|
isGitHubInstallIntentStartErrorResponse,
|
|
95
107
|
isGitHubInstallIntentStartResponse,
|
|
96
108
|
isGitHubInstallIntentStatusResponse,
|
|
97
109
|
isMoveIngestRequest,
|
|
98
110
|
isReconcileResolutionResponse,
|
|
99
111
|
stripAnsi
|
|
100
|
-
} from "./chunk-
|
|
112
|
+
} from "./chunk-FFYZ3XMX.js";
|
|
101
113
|
import {
|
|
102
114
|
CliManagementResponseError,
|
|
103
115
|
HttpError,
|
|
@@ -180,7 +192,7 @@ import {
|
|
|
180
192
|
|
|
181
193
|
// src/index.ts
|
|
182
194
|
import { readFileSync as readFileSync11 } from "fs";
|
|
183
|
-
import { dirname as dirname7, resolve as
|
|
195
|
+
import { dirname as dirname7, resolve as resolve5 } from "path";
|
|
184
196
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
185
197
|
import { Command } from "commander";
|
|
186
198
|
import updateNotifier from "update-notifier";
|
|
@@ -191,8 +203,8 @@ function isNonInteractive(globals) {
|
|
|
191
203
|
}
|
|
192
204
|
async function askConfirmation(question, output = process.stdout) {
|
|
193
205
|
if (!process.stdin.isTTY) return false;
|
|
194
|
-
const { createInterface } = await import("readline/promises");
|
|
195
|
-
const rl =
|
|
206
|
+
const { createInterface: createInterface2 } = await import("readline/promises");
|
|
207
|
+
const rl = createInterface2({ input: process.stdin, output });
|
|
196
208
|
try {
|
|
197
209
|
const answer = await rl.question(`${question} [y/N] `);
|
|
198
210
|
const normalized = answer.trim().toLowerCase();
|
|
@@ -1063,8 +1075,8 @@ ${verificationUrl}`);
|
|
|
1063
1075
|
const state = base64url(randomBytes2(16));
|
|
1064
1076
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
1065
1077
|
let settle;
|
|
1066
|
-
const outcome = new Promise((
|
|
1067
|
-
settle =
|
|
1078
|
+
const outcome = new Promise((resolve6) => {
|
|
1079
|
+
settle = resolve6;
|
|
1068
1080
|
});
|
|
1069
1081
|
const server = createServer((req, res) => {
|
|
1070
1082
|
const url = new URL(req.url ?? "/", `http://${LOCALHOST}`);
|
|
@@ -1078,12 +1090,12 @@ ${verificationUrl}`);
|
|
|
1078
1090
|
res.end(page.html, () => settle(page.result));
|
|
1079
1091
|
});
|
|
1080
1092
|
try {
|
|
1081
|
-
await new Promise((
|
|
1093
|
+
await new Promise((resolve6, reject) => {
|
|
1082
1094
|
const onError = (err) => reject(err);
|
|
1083
1095
|
server.once("error", onError);
|
|
1084
1096
|
server.listen(CALLBACK_PORT, LOCALHOST, () => {
|
|
1085
1097
|
server.removeListener("error", onError);
|
|
1086
|
-
|
|
1098
|
+
resolve6();
|
|
1087
1099
|
});
|
|
1088
1100
|
});
|
|
1089
1101
|
} catch (err) {
|
|
@@ -1908,11 +1920,12 @@ function registerHooksCommands(program2) {
|
|
|
1908
1920
|
"Note: Husky detected but stdin is not a TTY \u2014 falling back to .git/hooks. Pass --yes for Husky or --non-interactive to fail fast."
|
|
1909
1921
|
);
|
|
1910
1922
|
} else if (await askConfirmation(
|
|
1911
|
-
"Husky detected. Install prim hooks into .husky/ instead of .git/hooks/?"
|
|
1923
|
+
"Husky detected. Install prim hooks into .husky/ instead of .git/hooks/?",
|
|
1924
|
+
process.stderr
|
|
1912
1925
|
)) {
|
|
1913
1926
|
return installHooks(gitRoot, "husky");
|
|
1914
1927
|
} else {
|
|
1915
|
-
console.
|
|
1928
|
+
console.error("Falling back to .git/hooks install.");
|
|
1916
1929
|
}
|
|
1917
1930
|
return installHooks(gitRoot, "git-hooks");
|
|
1918
1931
|
}
|
|
@@ -2254,7 +2267,7 @@ function resolveScope(input) {
|
|
|
2254
2267
|
console.error(`[prim] unknown --scope "${input}" (expected: user or project)`);
|
|
2255
2268
|
process.exit(1);
|
|
2256
2269
|
}
|
|
2257
|
-
var TRUST_NOTICE = "[prim] Codex
|
|
2270
|
+
var TRUST_NOTICE = "[prim] Codex hooks installed. The tour's nextAction checks whether this session can run them. If pending, inspect /hooks; approve only if a trust action is offered. Active hooks need no additional approval.";
|
|
2258
2271
|
function registerCodexCommands(program2) {
|
|
2259
2272
|
const codex = program2.command("codex").description("Manage the prim Codex integration (capture, gate, ingest, presence)");
|
|
2260
2273
|
codex.command("install").description("Register the prim hooks in Codex's hooks.json (user scope by default)").option(
|
|
@@ -2286,14 +2299,24 @@ function registerCodexCommands(program2) {
|
|
|
2286
2299
|
});
|
|
2287
2300
|
codex.command("status").description("Report whether each prim surface (gate, capture) is installed per scope").action(() => {
|
|
2288
2301
|
const result = performStatus3();
|
|
2302
|
+
const readiness = {
|
|
2303
|
+
configured: result.user.complete || result.project.complete,
|
|
2304
|
+
runtime: inspectHookRuntime(),
|
|
2305
|
+
trust: "unknown",
|
|
2306
|
+
hookExecution: "not-verified",
|
|
2307
|
+
passiveCapture: "not-verified"
|
|
2308
|
+
};
|
|
2289
2309
|
const mark = (b) => b ? "\u2713" : "\u2717";
|
|
2290
|
-
const line = (
|
|
2310
|
+
const line = (label2, s) => `[prim] ${label2}: ${!s.present ? "not installed (optional when another scope is complete)" : `configured gate ${mark(s.gate)} \xB7 capture ${mark(s.capture)}`} (${s.path})`;
|
|
2291
2311
|
console.error(`${line("user", result.user)}
|
|
2292
2312
|
${line("project", result.project)}`);
|
|
2293
2313
|
const uncovered = uncoveredWorktreeHooks(result);
|
|
2294
2314
|
if (uncovered !== null)
|
|
2295
2315
|
console.error(`[prim] warning: ${uncoveredWorktreeAdvice(uncovered)}`);
|
|
2296
|
-
console.
|
|
2316
|
+
console.error(
|
|
2317
|
+
"[prim] Configuration is not proof of hook execution or capture. Use the pending tour\u2019s diagnosticAction to check isolation."
|
|
2318
|
+
);
|
|
2319
|
+
console.log(JSON.stringify({ ...result, readiness }, null, JSON_INDENT));
|
|
2297
2320
|
});
|
|
2298
2321
|
}
|
|
2299
2322
|
|
|
@@ -2317,7 +2340,7 @@ async function runPinnedEnsure(options) {
|
|
|
2317
2340
|
npm_config_fetch_retry_maxtimeout: "5000",
|
|
2318
2341
|
npm_config_fetch_timeout: "15000"
|
|
2319
2342
|
};
|
|
2320
|
-
return await new Promise((
|
|
2343
|
+
return await new Promise((resolve6) => {
|
|
2321
2344
|
let settled = false;
|
|
2322
2345
|
let child;
|
|
2323
2346
|
try {
|
|
@@ -2327,7 +2350,7 @@ async function runPinnedEnsure(options) {
|
|
|
2327
2350
|
{ env, stdio: "ignore" }
|
|
2328
2351
|
);
|
|
2329
2352
|
} catch {
|
|
2330
|
-
|
|
2353
|
+
resolve6(false);
|
|
2331
2354
|
return;
|
|
2332
2355
|
}
|
|
2333
2356
|
const timer = setTimeout(() => {
|
|
@@ -2338,7 +2361,7 @@ async function runPinnedEnsure(options) {
|
|
|
2338
2361
|
if (settled) return;
|
|
2339
2362
|
settled = true;
|
|
2340
2363
|
clearTimeout(timer);
|
|
2341
|
-
|
|
2364
|
+
resolve6(result);
|
|
2342
2365
|
};
|
|
2343
2366
|
timer.unref();
|
|
2344
2367
|
child.once("error", () => finish(false));
|
|
@@ -2695,10 +2718,10 @@ else
|
|
|
2695
2718
|
fi
|
|
2696
2719
|
`;
|
|
2697
2720
|
}
|
|
2698
|
-
function assertRegularFile(path,
|
|
2721
|
+
function assertRegularFile(path, label2) {
|
|
2699
2722
|
const stat = lstatIfPresent2(path);
|
|
2700
2723
|
if (stat && !stat.isFile()) {
|
|
2701
|
-
throw new Error(`refusing to remove non-file ${
|
|
2724
|
+
throw new Error(`refusing to remove non-file ${label2} at ${path}`);
|
|
2702
2725
|
}
|
|
2703
2726
|
}
|
|
2704
2727
|
function lstatIfPresent2(path) {
|
|
@@ -2727,11 +2750,11 @@ function assertDriftHealClaim(path) {
|
|
|
2727
2750
|
}
|
|
2728
2751
|
assertRegularFile(join4(path, DRIFT_HEAL_CLAIM_OWNER), "daemon drift-heal claim owner");
|
|
2729
2752
|
}
|
|
2730
|
-
function assertExactFile(path, expected,
|
|
2753
|
+
function assertExactFile(path, expected, label2) {
|
|
2731
2754
|
if (!lstatIfPresent2(path)) return;
|
|
2732
|
-
assertRegularFile(path,
|
|
2755
|
+
assertRegularFile(path, label2);
|
|
2733
2756
|
if (readFileSync3(path, "utf8") !== expected) {
|
|
2734
|
-
throw new Error(`refusing to remove unrecognized ${
|
|
2757
|
+
throw new Error(`refusing to remove unrecognized ${label2} at ${path}`);
|
|
2735
2758
|
}
|
|
2736
2759
|
}
|
|
2737
2760
|
function assertOwnedDaemonRuntime(options) {
|
|
@@ -2985,12 +3008,12 @@ function launchdPaths(options = {}) {
|
|
|
2985
3008
|
const home = options.homeDir ?? homedir3();
|
|
2986
3009
|
const configDir = primConfigDirectory(options);
|
|
2987
3010
|
const uid = options.uid ?? process.getuid?.();
|
|
2988
|
-
const
|
|
3011
|
+
const label2 = options.label ?? LAUNCHD_LABEL;
|
|
2989
3012
|
if (uid === void 0) throw new Error("cannot determine uid for launchd user domain");
|
|
2990
3013
|
return {
|
|
2991
3014
|
domainTarget: `gui/${uid}`,
|
|
2992
|
-
serviceTarget: `gui/${uid}/${
|
|
2993
|
-
plistPath: join4(home, "Library", "LaunchAgents", `${
|
|
3015
|
+
serviceTarget: `gui/${uid}/${label2}`,
|
|
3016
|
+
plistPath: join4(home, "Library", "LaunchAgents", `${label2}.plist`),
|
|
2994
3017
|
logPath: join4(configDir, "daemon.log")
|
|
2995
3018
|
};
|
|
2996
3019
|
}
|
|
@@ -3022,11 +3045,11 @@ function getLaunchdService(options = {}) {
|
|
|
3022
3045
|
)
|
|
3023
3046
|
);
|
|
3024
3047
|
}
|
|
3025
|
-
function atomicWrite2(path, content, mode,
|
|
3048
|
+
function atomicWrite2(path, content, mode, validate2) {
|
|
3026
3049
|
try {
|
|
3027
3050
|
if (readFileSync3(path, "utf8") === content) {
|
|
3028
3051
|
chmodSync(path, mode);
|
|
3029
|
-
|
|
3052
|
+
validate2?.(path, COMMAND_TIMEOUT_MS);
|
|
3030
3053
|
return false;
|
|
3031
3054
|
}
|
|
3032
3055
|
} catch {
|
|
@@ -3035,7 +3058,7 @@ function atomicWrite2(path, content, mode, validate) {
|
|
|
3035
3058
|
const temp = `${path}.tmp-${process.pid}-${Date.now()}`;
|
|
3036
3059
|
writeFileSync2(temp, content, { encoding: "utf8", mode, flag: "wx" });
|
|
3037
3060
|
try {
|
|
3038
|
-
|
|
3061
|
+
validate2?.(temp, COMMAND_TIMEOUT_MS);
|
|
3039
3062
|
renameSync(temp, path);
|
|
3040
3063
|
} catch (error) {
|
|
3041
3064
|
rmSync(temp, { force: true });
|
|
@@ -3322,10 +3345,10 @@ function launchAgentProgram(plist) {
|
|
|
3322
3345
|
if (plist.split(PLIST_LABEL_KEY).length !== 2 || plist.split(PLIST_PROGRAM_KEY).length !== 2) {
|
|
3323
3346
|
return void 0;
|
|
3324
3347
|
}
|
|
3325
|
-
const
|
|
3348
|
+
const label2 = PLIST_LABEL_RE.exec(plist)?.[1];
|
|
3326
3349
|
const program2 = PLIST_PROGRAM_RE.exec(plist)?.[1];
|
|
3327
|
-
if (
|
|
3328
|
-
const decodedLabel = xmlUnescape(
|
|
3350
|
+
if (label2 === void 0 || program2 === void 0) return void 0;
|
|
3351
|
+
const decodedLabel = xmlUnescape(label2);
|
|
3329
3352
|
const decodedProgram = xmlUnescape(program2);
|
|
3330
3353
|
return decodedLabel === void 0 || decodedProgram === void 0 ? void 0 : { label: decodedLabel, program: decodedProgram };
|
|
3331
3354
|
}
|
|
@@ -3600,7 +3623,7 @@ function clearStaleArtifacts() {
|
|
|
3600
3623
|
}
|
|
3601
3624
|
}
|
|
3602
3625
|
function sleep(ms) {
|
|
3603
|
-
return new Promise((
|
|
3626
|
+
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
3604
3627
|
}
|
|
3605
3628
|
function spawnDaemon(options) {
|
|
3606
3629
|
const file = binFile(DAEMON_BIN);
|
|
@@ -4321,8 +4344,8 @@ function truncate(s, max) {
|
|
|
4321
4344
|
}
|
|
4322
4345
|
return `${safe.slice(0, max - 1)}\u2026`;
|
|
4323
4346
|
}
|
|
4324
|
-
function bracketed(
|
|
4325
|
-
return `[${terminalSafeLine(
|
|
4347
|
+
function bracketed(label2) {
|
|
4348
|
+
return `[${terminalSafeLine(label2)}]`;
|
|
4326
4349
|
}
|
|
4327
4350
|
function knowledgeRow(files, contexts, triggerFile, triggerContextName) {
|
|
4328
4351
|
const tokens = [];
|
|
@@ -4642,11 +4665,11 @@ function formatRecentHuman(result) {
|
|
|
4642
4665
|
}
|
|
4643
4666
|
return `[prim] recent \xB7 ${terminalSafeLine(result.author.name)} \xB7 0 decisions`;
|
|
4644
4667
|
}
|
|
4645
|
-
const
|
|
4668
|
+
const label2 = result.author === void 0 ? "recent" : `recent \xB7 ${terminalSafeLine(result.author.name)}`;
|
|
4646
4669
|
if (result.decisions.length === 0) {
|
|
4647
4670
|
return "[prim] recent \xB7 0 decisions";
|
|
4648
4671
|
}
|
|
4649
|
-
const header = `[prim] ${
|
|
4672
|
+
const header = `[prim] ${label2} \xB7 ${String(result.decisions.length)} decision(s)`;
|
|
4650
4673
|
const hint = remainingHint(result);
|
|
4651
4674
|
const lines = [hint === void 0 ? header : `${header} \xB7 ${hint}`];
|
|
4652
4675
|
for (const row of result.decisions) {
|
|
@@ -5971,11 +5994,11 @@ function pushContexts(lines, contexts) {
|
|
|
5971
5994
|
lines.push(` - ${terminalSafeLine(ctx.name)}`);
|
|
5972
5995
|
}
|
|
5973
5996
|
}
|
|
5974
|
-
function pushEdges(lines,
|
|
5997
|
+
function pushEdges(lines, label2, arrow, nodes) {
|
|
5975
5998
|
if (nodes.length === 0) {
|
|
5976
5999
|
return;
|
|
5977
6000
|
}
|
|
5978
|
-
lines.push(` ${
|
|
6001
|
+
lines.push(` ${label2} (${String(nodes.length)}):`);
|
|
5979
6002
|
for (const node of nodes) {
|
|
5980
6003
|
lines.push(` ${arrow} ${describeNode(node)}`);
|
|
5981
6004
|
}
|
|
@@ -6610,8 +6633,33 @@ function registerDecisionsCommands(program2) {
|
|
|
6610
6633
|
}
|
|
6611
6634
|
|
|
6612
6635
|
// src/commands/demo.ts
|
|
6636
|
+
import { createHash as createHash3 } from "crypto";
|
|
6637
|
+
import { resolve as resolve3 } from "path";
|
|
6638
|
+
import { createInterface } from "readline/promises";
|
|
6613
6639
|
import { diffLines } from "diff";
|
|
6614
6640
|
|
|
6641
|
+
// src/demo/api.ts
|
|
6642
|
+
async function demoApi(action, body) {
|
|
6643
|
+
const valid = action === "start" ? isDemoStartRequest : action === "resolve" ? isDemoResolveRequest : action === "complete" ? isDemoCompleteRequest : isDemoRunRequest;
|
|
6644
|
+
if (!valid(body)) throw new Error("Invalid demo request");
|
|
6645
|
+
return validate(
|
|
6646
|
+
await getClient().post(`/api/cli/demo/${action}`, body, {
|
|
6647
|
+
signal: AbortSignal.timeout(2e4)
|
|
6648
|
+
})
|
|
6649
|
+
);
|
|
6650
|
+
}
|
|
6651
|
+
async function demoStatus(runId) {
|
|
6652
|
+
if (!/^[a-zA-Z0-9]{1,64}$/u.test(runId)) throw new Error("Invalid server demo identity");
|
|
6653
|
+
return validate(
|
|
6654
|
+
await getClient().get(`/api/cli/demo/${runId}`, { signal: AbortSignal.timeout(2e4) })
|
|
6655
|
+
);
|
|
6656
|
+
}
|
|
6657
|
+
function validate(value) {
|
|
6658
|
+
if (!isDemoStatusResponse(value))
|
|
6659
|
+
throw new Error("Invalid demo response; no sample write applied");
|
|
6660
|
+
return value;
|
|
6661
|
+
}
|
|
6662
|
+
|
|
6615
6663
|
// src/demo/sandbox.ts
|
|
6616
6664
|
import {
|
|
6617
6665
|
existsSync as existsSync5,
|
|
@@ -6665,13 +6713,22 @@ var SAMPLE_FILES = {
|
|
|
6665
6713
|
"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
6714
|
};
|
|
6667
6715
|
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
6716
|
var REPOSITORY_EDIT = 'import { orders } from "./shared";\nexport const saveOrder = (order: unknown) => orders.save(order);\n';
|
|
6670
6717
|
|
|
6718
|
+
// src/demo/story.ts
|
|
6719
|
+
var DEMO_TASK = "Implement CSV export for customer records, including name and email.";
|
|
6720
|
+
var DEMO_ORIGINAL = "Exclude customer email addresses from CSV exports";
|
|
6721
|
+
var DEMO_REPLACEMENT = "Allow customer names and email addresses in CSV exports";
|
|
6722
|
+
var DEMO_INITIAL = '// Fictional customer export project.\nexport const customerCsv = "";\n';
|
|
6723
|
+
var DEMO_ADHERE = '// Fictional customer export project.\nexport const customerCsv = "name\\nAvery";\n';
|
|
6724
|
+
var DEMO_SUPERSEDE = '// Fictional customer export project.\nexport const customerCsv = "name,email\\nAvery,avery@example.invalid";\n';
|
|
6725
|
+
|
|
6671
6726
|
// src/demo/sandbox.ts
|
|
6672
6727
|
var decisionBytes = (adopted) => `${JSON.stringify(adopted ? SAMPLE_DECISIONS : SAMPLE_DECISIONS.slice(0, 1), null, 2)}
|
|
6673
6728
|
`;
|
|
6674
6729
|
function allowedFiles(run) {
|
|
6730
|
+
if (run.version === 2)
|
|
6731
|
+
return { ".owner": [run.id], "customers.ts": [DEMO_INITIAL, DEMO_ADHERE, DEMO_SUPERSEDE] };
|
|
6675
6732
|
return {
|
|
6676
6733
|
".owner": [run.id],
|
|
6677
6734
|
"note.md": [SAMPLE_NOTE],
|
|
@@ -6708,12 +6765,13 @@ function createSandbox(run) {
|
|
|
6708
6765
|
saveRun(run);
|
|
6709
6766
|
}
|
|
6710
6767
|
const root = inspectSandbox(run);
|
|
6711
|
-
|
|
6768
|
+
const files = run.version === 2 ? { ".owner": run.id, "customers.ts": DEMO_INITIAL } : {
|
|
6712
6769
|
".owner": run.id,
|
|
6713
6770
|
"note.md": SAMPLE_NOTE,
|
|
6714
6771
|
...SAMPLE_FILES,
|
|
6715
6772
|
"decisions.json": decisionBytes(false)
|
|
6716
|
-
}
|
|
6773
|
+
};
|
|
6774
|
+
for (const [name, content] of Object.entries(files)) {
|
|
6717
6775
|
const path = join6(root, name);
|
|
6718
6776
|
if (!existsSync5(path)) atomicWriteFile(path, content, { mode: 384 });
|
|
6719
6777
|
}
|
|
@@ -6745,373 +6803,441 @@ function cleanSandbox(run) {
|
|
|
6745
6803
|
}
|
|
6746
6804
|
|
|
6747
6805
|
// src/commands/demo.ts
|
|
6748
|
-
var
|
|
6749
|
-
|
|
6750
|
-
var
|
|
6751
|
-
var
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
},
|
|
6763
|
-
...run.sandbox ? { sandbox: run.sandbox.path } : {},
|
|
6764
|
-
...run.stage === "conflict" ? { retryAction: demoCommand(run, "resolve", "local-storage") } : {}
|
|
6765
|
-
};
|
|
6806
|
+
var printJson2 = (value) => process.stdout.write(`${JSON.stringify(value)}
|
|
6807
|
+
`);
|
|
6808
|
+
var digest = (bytes) => createHash3("sha256").update(bytes).digest("hex");
|
|
6809
|
+
var captureNotice = "Start a new agent session to resume passive capture. Explicitly approved real Decisions still work here.";
|
|
6810
|
+
var label = "**Fictional project \xB7 real conflict check**";
|
|
6811
|
+
var diagram = (value) => `
|
|
6812
|
+
\`\`\`text
|
|
6813
|
+
${value}
|
|
6814
|
+
\`\`\``;
|
|
6815
|
+
var safeMarkdown = (value) => terminalSafeLine(value).replace(/[\\`*_{}[\]<>]/gu, "\\$&");
|
|
6816
|
+
function compactDiff(before, after) {
|
|
6817
|
+
return diffLines(before, after).filter((part) => part.added || part.removed).map(
|
|
6818
|
+
(part) => part.value.trimEnd().split("\n").map((line) => `${part.added ? "+" : "-"} ${line}`).join("\n")
|
|
6819
|
+
).join("\n");
|
|
6766
6820
|
}
|
|
6767
6821
|
function demoTrustGuidance(agent) {
|
|
6768
6822
|
if (agent === "codex")
|
|
6769
|
-
return "
|
|
6823
|
+
return "Check /hooks in Codex. Approve only if a trust action is offered. If hooks are already active, retry the exact standalone command once; do not keep asking for trust or a new session. If still pending, run diagnosticAction once. Inspect its expected PreToolUse/Bash event and runtime; UserPromptSubmit does not acknowledge the tour. Do not prepare a new run.";
|
|
6770
6824
|
if (agent === "hermes")
|
|
6771
6825
|
return "Approve the installed prim hooks when Hermes prompts, then retry the exact nextAction.";
|
|
6772
6826
|
if (agent === "cursor")
|
|
6773
6827
|
return "Trust this Cursor workspace and activate its installed hooks, then retry the exact nextAction.";
|
|
6774
6828
|
return "Activate the installed prim hooks in your agent, then retry the exact nextAction.";
|
|
6775
6829
|
}
|
|
6776
|
-
function consumeAcknowledgment(run, action, choice) {
|
|
6777
|
-
if (run.terminal)
|
|
6830
|
+
function consumeAcknowledgment(run, action, choice, reason) {
|
|
6831
|
+
if (run.terminal)
|
|
6832
|
+
return process.stdin.isTTY && process.stderr.isTTY ? void 0 : "terminal-required";
|
|
6778
6833
|
const ack = run.acknowledgment;
|
|
6779
6834
|
run.acknowledgment = void 0;
|
|
6780
6835
|
saveRun(run);
|
|
6781
|
-
if (!run.binding || !ack
|
|
6836
|
+
if (!run.binding || !ack) return "acknowledgment-missing";
|
|
6837
|
+
if (ack.command !== demoCommand(run, action, choice, reason)) return "command-mismatch";
|
|
6782
6838
|
const age = Date.now() - ack.at;
|
|
6783
|
-
if (!Number.isFinite(age) || age < 0 || age > 3e4) return
|
|
6839
|
+
if (!Number.isFinite(age) || age < 0 || age > 3e4) return "acknowledgment-expired";
|
|
6784
6840
|
try {
|
|
6785
6841
|
const exclusion = readDemoJson(exclusionPath(run.binding));
|
|
6786
|
-
return typeof exclusion.runId === "string" && RUN_ID.test(exclusion.runId);
|
|
6842
|
+
return typeof exclusion.runId === "string" && RUN_ID.test(exclusion.runId) ? void 0 : "exclusion-invalid";
|
|
6787
6843
|
} catch {
|
|
6788
|
-
return
|
|
6844
|
+
return "exclusion-missing";
|
|
6789
6845
|
}
|
|
6790
6846
|
}
|
|
6791
|
-
function
|
|
6792
|
-
const
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
`Source: ${source}
|
|
6805
|
-
Alternatives rejected: ${item.alternativesRejected.join("; ")}
|
|
6806
|
-
`
|
|
6807
|
-
);
|
|
6808
|
-
if (index === 0) process.stderr.write(`Scope basis: ${SAMPLE_DECISIONS[0].scopeBasis}
|
|
6809
|
-
`);
|
|
6810
|
-
}
|
|
6847
|
+
function resultFor2(run) {
|
|
6848
|
+
const complete = run.stage === "completed" || run.stage === "skipped";
|
|
6849
|
+
return {
|
|
6850
|
+
fictional: true,
|
|
6851
|
+
evaluation: "live",
|
|
6852
|
+
runId: run.id,
|
|
6853
|
+
stage: run.stage,
|
|
6854
|
+
...run.server && run.stage !== "skipped" ? { server: run.server } : {},
|
|
6855
|
+
...run.sandbox ? { sandbox: run.sandbox.path } : {},
|
|
6856
|
+
skipAction: demoCommand(run, "skip"),
|
|
6857
|
+
statusAction: demoCommand(run, "status"),
|
|
6858
|
+
...complete ? { nextAction: demoWelcomeCommand(run) } : {}
|
|
6859
|
+
};
|
|
6811
6860
|
}
|
|
6812
|
-
function
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6861
|
+
function present(run) {
|
|
6862
|
+
if (run.stage === "prepared") return "Tour prepared \u2192 Isolation pending \u2192 Story not started.";
|
|
6863
|
+
if (run.stage === "skipped") return "Tour skipped. Owned sample files removed.";
|
|
6864
|
+
if (run.stage === "prompt")
|
|
6865
|
+
return `${label}
|
|
6866
|
+
|
|
6867
|
+
Imagine you\u2019re a new engineer joining a team. In this story, you previously authored a Decision; now experience it as the new engineer. We\u2019ll email the outcome to your signed-in address.
|
|
6868
|
+
${diagram("[1 Enter task] \u2192 [2 Your Decision stops it] \u2192 [3 Choose \u2192 Email]")}
|
|
6869
|
+
|
|
6870
|
+
Enter this prompt in this chat:
|
|
6871
|
+
|
|
6872
|
+
\`\`\`text
|
|
6873
|
+
${DEMO_TASK}
|
|
6874
|
+
\`\`\``;
|
|
6875
|
+
if (run.stage === "conflict")
|
|
6876
|
+
return `${label}
|
|
6877
|
+
|
|
6878
|
+
**YOUR DECISION STOPPED THIS**
|
|
6879
|
+
${diagram("CSV export [name, email]\n \u2502\n \u2715 email excluded\n \u2502\n customers.ts unchanged")}
|
|
6880
|
+
|
|
6881
|
+
**${DEMO_ORIGINAL}**
|
|
6882
|
+
Fictional prior author: ${safeMarkdown(run.server?.authorName ?? "you")}
|
|
6883
|
+
|
|
6884
|
+
\`\`\`ts
|
|
6885
|
+
${readSample(run, "customers.ts").trimEnd()}
|
|
6886
|
+
\`\`\`
|
|
6887
|
+
|
|
6888
|
+
Choose **Adhere** (export names only) or **Supersede** with **${DEMO_REPLACEMENT}** and your short reason.`;
|
|
6889
|
+
if (run.stage === "completed" || run.stage === "cleanup") {
|
|
6890
|
+
const choice = run.server?.choice;
|
|
6891
|
+
const after = choice === "adhere" ? DEMO_ADHERE : DEMO_SUPERSEDE;
|
|
6892
|
+
return `${label}
|
|
6893
|
+
|
|
6894
|
+
**PASS \u2014 CSV export implemented**
|
|
6895
|
+
${diagram(`CSV [${choice === "adhere" ? "name" : "name, email"}] \u2192 CHECK PASSED \u2192 IMPLEMENTED
|
|
6896
|
+
Your Decision \u2192 ${choice === "adhere" ? "preserved" : "replacement + your reason"} \u2192 EMAIL ${run.server?.email.toUpperCase()}`)}
|
|
6897
|
+
|
|
6898
|
+
\`\`\`diff
|
|
6899
|
+
${compactDiff(DEMO_INITIAL, after)}
|
|
6900
|
+
\`\`\`
|
|
6901
|
+
|
|
6902
|
+
${run.stage === "cleanup" ? "Sample cleanup still needs attention." : "Owned sample files removed."} ${run.server?.email === "accepted" ? "The provider accepted the email; inbox delivery is not confirmed." : "Queued is not inbox delivery."}
|
|
6903
|
+
|
|
6904
|
+
${run.binding ? captureNotice : "Ready for your real Decisions."}`;
|
|
6905
|
+
}
|
|
6906
|
+
return `${label}
|
|
6907
|
+
|
|
6908
|
+
Checked edit saved; email finalization is pending. Retry the same resolution to finish. No second email will be queued.`;
|
|
6909
|
+
}
|
|
6910
|
+
function handoff(run) {
|
|
6911
|
+
const result = { ...resultFor2(run), presentation: present(run) };
|
|
6912
|
+
if (run.stage === "prepared") return { ...result, nextAction: demoCommand(run, "start") };
|
|
6913
|
+
if (run.stage === "prompt")
|
|
6914
|
+
return { ...result, awaitUserPrompt: DEMO_TASK, attemptAction: demoCommand(run, "attempt") };
|
|
6915
|
+
if (run.stage === "conflict")
|
|
6916
|
+
return {
|
|
6917
|
+
...result,
|
|
6918
|
+
choices: {
|
|
6919
|
+
adhere: demoCommand(run, "resolve", "adhere"),
|
|
6920
|
+
supersede: {
|
|
6921
|
+
command: demoCommand(run, "resolve", "supersede"),
|
|
6922
|
+
requiredArgument: "--reason <user-provided reason>",
|
|
6923
|
+
replacement: DEMO_REPLACEMENT
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
};
|
|
6927
|
+
if (run.server?.choice && !["completed", "skipped"].includes(run.stage))
|
|
6928
|
+
return {
|
|
6929
|
+
...result,
|
|
6930
|
+
nextAction: demoCommand(run, "resolve", run.server.choice, run.server.reason)
|
|
6931
|
+
};
|
|
6932
|
+
return result;
|
|
6933
|
+
}
|
|
6934
|
+
function requireResolution(choice, reason) {
|
|
6935
|
+
if (choice !== "adhere" && choice !== "supersede") throw new Error("Choose adhere or supersede");
|
|
6936
|
+
if (choice === "supersede" && (!reason?.trim() || reason.length > 500))
|
|
6937
|
+
throw new Error("Supersession requires your short reason (1\u2013500 characters)");
|
|
6938
|
+
if (choice === "adhere" && reason !== void 0)
|
|
6939
|
+
throw new Error("A supersession reason only applies to supersede");
|
|
6940
|
+
}
|
|
6941
|
+
async function finishResolution(run, choice, reason) {
|
|
6942
|
+
if (!run.server) throw new Error("Start the story first");
|
|
6943
|
+
if (run.stage !== "conflict" && run.server.choice && (run.server.choice !== choice || run.server.reason !== reason))
|
|
6944
|
+
throw new Error("This run already has a different approved resolution");
|
|
6945
|
+
if (run.stage === "conflict") {
|
|
6946
|
+
run.server = await demoApi("resolve", {
|
|
6947
|
+
runId: run.server.runId,
|
|
6948
|
+
revision: run.server.revision,
|
|
6949
|
+
choice,
|
|
6950
|
+
...reason === void 0 ? {} : { reason }
|
|
6951
|
+
});
|
|
6952
|
+
if (run.server.stage !== "approved" || run.server.verdict !== "pass") {
|
|
6953
|
+
saveRun(run);
|
|
6954
|
+
return;
|
|
6824
6955
|
}
|
|
6956
|
+
run.stage = "approved";
|
|
6957
|
+
saveRun(run);
|
|
6958
|
+
}
|
|
6959
|
+
if (run.stage === "approved") {
|
|
6960
|
+
const after = choice === "adhere" ? DEMO_ADHERE : DEMO_SUPERSEDE;
|
|
6961
|
+
if (digest(after) !== run.server.approvedDigest)
|
|
6962
|
+
throw new Error("Server approved unexpected sample bytes");
|
|
6963
|
+
const before = readSample(run, "customers.ts");
|
|
6964
|
+
if (before !== DEMO_INITIAL && before !== after)
|
|
6965
|
+
throw new Error("Sample changed; retained for inspection");
|
|
6966
|
+
writeSample(run, "customers.ts", after);
|
|
6967
|
+
if (readSample(run, "customers.ts") !== after) throw new Error("Sample write was not verified");
|
|
6968
|
+
run.receipt = { revision: run.server.revision, appliedDigest: digest(after) };
|
|
6969
|
+
run.stage = "applied";
|
|
6970
|
+
saveRun(run);
|
|
6971
|
+
}
|
|
6972
|
+
if (run.stage === "applied") {
|
|
6973
|
+
if (!run.receipt || digest(readSample(run, "customers.ts")) !== run.receipt.appliedDigest)
|
|
6974
|
+
throw new Error("Applied sample receipt no longer matches");
|
|
6975
|
+
run.server = await demoApi("complete", { runId: run.server.runId, ...run.receipt });
|
|
6976
|
+
if (run.server.stage !== "completed" || run.server.email === "not_queued")
|
|
6977
|
+
throw new Error("Email was not durably queued");
|
|
6978
|
+
run.stage = "cleanup";
|
|
6979
|
+
saveRun(run);
|
|
6980
|
+
}
|
|
6981
|
+
if (run.stage === "cleanup") {
|
|
6982
|
+
cleanSandbox(run);
|
|
6983
|
+
run.stage = "completed";
|
|
6984
|
+
saveRun(run);
|
|
6985
|
+
finishOnboarding("completed");
|
|
6825
6986
|
}
|
|
6826
6987
|
}
|
|
6827
|
-
function
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
${
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
}
|
|
6845
|
-
function narrateCompletion(run) {
|
|
6846
|
-
process.stderr.write(`
|
|
6847
|
-
${bold(color("WALKTHROUGH COMPLETE \u2014 simulated", "green"))}
|
|
6848
|
-
`);
|
|
6849
|
-
process.stderr.write(`${completionReceipt.map((item) => `\u2713 ${item}`).join(" \xB7 ")}
|
|
6850
|
-
`);
|
|
6851
|
-
process.stderr.write(`${handoff}
|
|
6852
|
-
${run.terminal ? "" : `${captureNotice}
|
|
6853
|
-
`}`);
|
|
6988
|
+
function pendingIsolation(run, isolation, action, choice, reason) {
|
|
6989
|
+
return {
|
|
6990
|
+
fictional: true,
|
|
6991
|
+
evaluation: "live",
|
|
6992
|
+
runId: run.id,
|
|
6993
|
+
stage: "pending",
|
|
6994
|
+
isolation,
|
|
6995
|
+
...action === "status" ? { resumeAction: demoResumeCommand(run) } : { nextAction: demoCommand(run, action, choice, reason) },
|
|
6996
|
+
diagnostics: isolationDiagnostics(run),
|
|
6997
|
+
...action === "status" ? {} : { diagnosticAction: demoDiagnosticCommand(run) },
|
|
6998
|
+
skipAction: demoCommand(run, "skip"),
|
|
6999
|
+
presentation: `Tour prepared \u2192 **Isolation pending** \u2192 ${run.stage === "prepared" ? "Story not started" : "Story paused"}.
|
|
7000
|
+
|
|
7001
|
+
${isolation}. Checking the installed pre-tool hook before continuing.`,
|
|
7002
|
+
guidance: demoTrustGuidance(run.agent),
|
|
7003
|
+
recovery: `${action === "status" ? "Use this evidence to repair the hook before resumeAction." : "Run diagnosticAction once."} If no hook observation exists, the CLI has no evidence this command reached its installed pre-tool hook. Check the host hook event/error view and configuration-directory access; absence of a log is not proof of healthy hooks. Retry only after a repair, using this run. Never fabricate acknowledgment or read sample files.`
|
|
7004
|
+
};
|
|
6854
7005
|
}
|
|
6855
|
-
function advanceDemo(id, action, choice,
|
|
6856
|
-
|
|
7006
|
+
async function advanceDemo(id, action, choice, reason) {
|
|
7007
|
+
if (action === "status") {
|
|
7008
|
+
const run = readRun(id);
|
|
7009
|
+
if (!run.terminal && !run.acknowledgment)
|
|
7010
|
+
return pendingIsolation(run, "acknowledgment-missing", action);
|
|
7011
|
+
}
|
|
7012
|
+
return await lockRunAsync(id, async (run) => {
|
|
7013
|
+
if (action === "resolve") requireResolution(choice, reason);
|
|
6857
7014
|
if (action === "skip") {
|
|
7015
|
+
if (run.server && !["completed", "skipped"].includes(run.server.stage)) {
|
|
7016
|
+
const latest = await demoStatus(run.server.runId);
|
|
7017
|
+
run.server = await demoApi("skip", { runId: latest.runId, revision: latest.revision });
|
|
7018
|
+
}
|
|
6858
7019
|
cleanSandbox(run);
|
|
6859
7020
|
run.stage = "skipped";
|
|
6860
7021
|
saveRun(run);
|
|
6861
7022
|
finishOnboarding("skipped");
|
|
6862
|
-
|
|
6863
|
-
`);
|
|
6864
|
-
if (run.binding) process.stderr.write(`${captureNotice}
|
|
6865
|
-
`);
|
|
6866
|
-
return resultFor2(run);
|
|
6867
|
-
}
|
|
6868
|
-
if (!consumeAcknowledgment(run, action, choice)) {
|
|
6869
|
-
const message = `Tour pending: session isolation has not been acknowledged. ${demoTrustGuidance(run.agent)}`;
|
|
6870
|
-
process.stderr.write(`[prim] ${message}
|
|
6871
|
-
`);
|
|
6872
|
-
return {
|
|
6873
|
-
...resultFor2(run),
|
|
6874
|
-
stage: "pending",
|
|
6875
|
-
message,
|
|
6876
|
-
nextAction: demoCommand(run, action, choice)
|
|
6877
|
-
};
|
|
6878
|
-
}
|
|
6879
|
-
if (action === "confirm" && run.stage === "prepared") {
|
|
6880
|
-
throw new Error("start the demo before confirming its proposal");
|
|
6881
|
-
}
|
|
6882
|
-
if (action === "resolve" && (run.stage === "prepared" || run.stage === "proposal")) {
|
|
6883
|
-
throw new Error("confirm the sample Decision before resolving");
|
|
7023
|
+
return handoff(run);
|
|
6884
7024
|
}
|
|
7025
|
+
if (run.version === 1)
|
|
7026
|
+
throw new Error(
|
|
7027
|
+
`Legacy tour: clean up with ${demoCommand(run, "skip")}, then run prim demo again`
|
|
7028
|
+
);
|
|
7029
|
+
const isolation = action === "status" && !run.terminal && !run.acknowledgment ? "acknowledgment-missing" : consumeAcknowledgment(run, action, choice, reason);
|
|
7030
|
+
if (isolation) return pendingIsolation(run, isolation, action, choice, reason);
|
|
7031
|
+
if (action === "status") {
|
|
7032
|
+
const server = run.server ? await demoStatus(run.server.runId) : void 0;
|
|
7033
|
+
return { ...handoff(run), ...server ? { server } : {} };
|
|
7034
|
+
}
|
|
7035
|
+
if (["completed", "skipped"].includes(run.stage)) return handoff(run);
|
|
7036
|
+
const allowed = action === "start" ? ["prepared", "prompt"] : action === "attempt" ? ["prompt", "conflict"] : ["conflict", "approved", "applied", "cleanup"];
|
|
7037
|
+
if (!allowed.includes(run.stage)) throw new Error("Invalid demo transition");
|
|
6885
7038
|
try {
|
|
6886
|
-
if (
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
if (action === "start") {
|
|
6894
|
-
if (run.stage === "prepared") {
|
|
6895
|
-
createSandbox(run);
|
|
6896
|
-
run.stage = "proposal";
|
|
6897
|
-
saveRun(run);
|
|
6898
|
-
}
|
|
6899
|
-
if (run.stage === "proposal") {
|
|
6900
|
-
process.stderr.write(`${bold("Add order saving")}
|
|
6901
|
-
${intro}
|
|
6902
|
-
`);
|
|
6903
|
-
process.stderr.write(
|
|
6904
|
-
`
|
|
6905
|
-
${bold("1/4 \xB7 Extract")}
|
|
6906
|
-
Team conversation
|
|
6907
|
-
\u201C${SAMPLE_DECISIONS[0].evidence[0]}\u201D
|
|
6908
|
-
\u2193 scripted extraction
|
|
6909
|
-
`
|
|
6910
|
-
);
|
|
6911
|
-
process.stderr.write(`${bold(color("\u2713 DECISION EXTRACTED", "green"))}
|
|
6912
|
-
`);
|
|
6913
|
-
narrateDecision(0, details);
|
|
6914
|
-
if (details) process.stderr.write(`
|
|
6915
|
-
Full source:
|
|
6916
|
-
${SAMPLE_NOTE}
|
|
6917
|
-
`);
|
|
6918
|
-
process.stderr.write(`
|
|
6919
|
-
${bold("2/4 \xB7 Adopt")}
|
|
6920
|
-
`);
|
|
6921
|
-
narrateDecision(1, details);
|
|
6922
|
-
process.stderr.write("Proposed \u2500\u2500 your approval \u2500\u2500\u2192 Adopted\n");
|
|
6923
|
-
}
|
|
6924
|
-
return {
|
|
6925
|
-
...resultFor2(run),
|
|
6926
|
-
decisions: SAMPLE_DECISIONS.slice(0, run.stage === "proposal" ? 1 : 2),
|
|
6927
|
-
...run.stage === "proposal" ? {
|
|
6928
|
-
sourceNote: SAMPLE_NOTE,
|
|
6929
|
-
proposal: {
|
|
6930
|
-
...SAMPLE_DECISIONS[1],
|
|
6931
|
-
stage: "proposed",
|
|
6932
|
-
source: "Fictional authoring proposal"
|
|
6933
|
-
}
|
|
6934
|
-
} : {}
|
|
6935
|
-
};
|
|
7039
|
+
if (run.needsStatus && run.server) {
|
|
7040
|
+
const latest = await demoStatus(run.server.runId);
|
|
7041
|
+
if (latest.runId !== run.server.runId)
|
|
7042
|
+
throw new Error("Server returned a different demo run");
|
|
7043
|
+
run.server = latest;
|
|
7044
|
+
run.needsStatus = false;
|
|
7045
|
+
saveRun(run);
|
|
6936
7046
|
}
|
|
6937
|
-
if (action === "
|
|
6938
|
-
|
|
6939
|
-
if (run.stage
|
|
6940
|
-
|
|
6941
|
-
|
|
7047
|
+
if (action === "start" && run.stage === "prepared") {
|
|
7048
|
+
run.server = await demoApi("start", { scenarioVersion: 1, localRunId: run.id });
|
|
7049
|
+
if (run.server.stage !== "ready")
|
|
7050
|
+
throw new Error("Existing backend run needs recovery; inspect status");
|
|
7051
|
+
saveRun(run);
|
|
7052
|
+
createSandbox(run);
|
|
7053
|
+
run.stage = "prompt";
|
|
7054
|
+
saveRun(run);
|
|
7055
|
+
} else if (action === "attempt" && run.stage === "prompt") {
|
|
7056
|
+
if (!run.server || readSample(run, "customers.ts") !== DEMO_INITIAL)
|
|
7057
|
+
throw new Error("Initial sample changed");
|
|
7058
|
+
run.server = await demoApi("check", {
|
|
7059
|
+
runId: run.server.runId,
|
|
7060
|
+
revision: run.server.revision
|
|
7061
|
+
});
|
|
7062
|
+
if (run.server.stage === "blocked" && run.server.verdict === "block")
|
|
6942
7063
|
run.stage = "conflict";
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
const unchanged = readSample(run, "orders.ts");
|
|
6953
|
-
process.stderr.write(`
|
|
6954
|
-
${bold("3/4 \xB7 Protect \xB7 simulated")}
|
|
6955
|
-
`);
|
|
6956
|
-
process.stderr.write(`${bold(color("! WARNING \u2014 edit allowed", "yellow"))}
|
|
6957
|
-
`);
|
|
6958
|
-
process.stderr.write(
|
|
6959
|
-
`${SAMPLE_DECISIONS[0].decision} [provisional]
|
|
6960
|
-
Bypasses shared retries and tracing.
|
|
6961
|
-
`
|
|
6962
|
-
);
|
|
6963
|
-
narrateDiff("service.ts \xB7 changed", before2, after2);
|
|
6964
|
-
narrateBlockedAttempt(unchanged, details);
|
|
6965
|
-
if (!run.terminal)
|
|
6966
|
-
process.stderr.write("\nChoose: shared repository \xB7 retry direct storage\n");
|
|
6967
|
-
process.stderr.write(
|
|
6968
|
-
"\nScripted verdicts. Live gates vary; Claude may ask where other agents block.\n"
|
|
6969
|
-
);
|
|
7064
|
+
saveRun(run);
|
|
7065
|
+
} else if (action === "resolve") {
|
|
7066
|
+
if (!["conflict", "approved", "applied", "cleanup"].includes(run.stage))
|
|
7067
|
+
throw new Error("Enter the task and see its conflict before resolving");
|
|
7068
|
+
await finishResolution(run, choice, reason);
|
|
7069
|
+
} else if (!(action === "start" && run.stage === "prompt" || action === "attempt" && run.stage === "conflict")) {
|
|
7070
|
+
throw new Error("Invalid demo transition");
|
|
7071
|
+
}
|
|
7072
|
+
if (run.server?.verdict === "pending")
|
|
6970
7073
|
return {
|
|
6971
7074
|
...resultFor2(run),
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
proposed: BLOCKED_EDIT,
|
|
6978
|
-
after: readSample(run, "orders.ts")
|
|
6979
|
-
}
|
|
6980
|
-
}
|
|
7075
|
+
stage: "pending",
|
|
7076
|
+
nextAction: demoCommand(run, action, choice, reason),
|
|
7077
|
+
presentation: `${label}
|
|
7078
|
+
|
|
7079
|
+
Check pending (${run.server.reasonCode ?? "evaluation in progress"}). File unchanged; retry or skip.`
|
|
6981
7080
|
};
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
if (choice === "local-storage") {
|
|
6986
|
-
const unchanged = readSample(run, "orders.ts");
|
|
6987
|
-
process.stderr.write(`${bold("3/4 \xB7 Retry \xB7 simulated")}
|
|
6988
|
-
`);
|
|
6989
|
-
narrateBlockedAttempt(unchanged, details);
|
|
6990
|
-
return { ...resultFor2(run), evidence: { unchanged } };
|
|
6991
|
-
}
|
|
6992
|
-
const before = readSample(run, "service.ts");
|
|
6993
|
-
const ordersBefore = readSample(run, "orders.ts");
|
|
6994
|
-
writeSample(run, "service.ts", SAMPLE_FILES["service.ts"]);
|
|
6995
|
-
writeSample(run, "orders.ts", REPOSITORY_EDIT);
|
|
6996
|
-
const after = readSample(run, "service.ts");
|
|
6997
|
-
const orders = readSample(run, "orders.ts");
|
|
6998
|
-
process.stderr.write(`
|
|
6999
|
-
${bold("4/4 \xB7 Correct \xB7 simulated")}
|
|
7000
|
-
`);
|
|
7001
|
-
narrateDiff("orders.ts", ordersBefore, orders);
|
|
7002
|
-
narrateDiff("service.ts", before, after);
|
|
7003
|
-
process.stderr.write(
|
|
7004
|
-
`${bold(color("\u2713 PASS \u2014 order saving added", "green"))}
|
|
7005
|
-
Both sample Decisions respected.
|
|
7006
|
-
`
|
|
7007
|
-
);
|
|
7008
|
-
cleanSandbox(run);
|
|
7009
|
-
run.stage = "completed";
|
|
7081
|
+
return handoff(run);
|
|
7082
|
+
} catch (error) {
|
|
7083
|
+
run.needsStatus = true;
|
|
7010
7084
|
saveRun(run);
|
|
7011
|
-
finishOnboarding("completed");
|
|
7012
|
-
narrateCompletion(run);
|
|
7013
7085
|
return {
|
|
7014
7086
|
...resultFor2(run),
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
orderCorrection: { before: ordersBefore, after: orders }
|
|
7020
|
-
}
|
|
7087
|
+
stage: "pending",
|
|
7088
|
+
nextAction: demoCommand(run, action, choice, reason),
|
|
7089
|
+
presentation: `Tour pending: ${terminalSafeLine(error instanceof Error ? error.message : String(error))}`,
|
|
7090
|
+
...run.stage === "cleanup" ? { outcomePresentation: present(run) } : {}
|
|
7021
7091
|
};
|
|
7022
|
-
} catch (error) {
|
|
7023
|
-
try {
|
|
7024
|
-
cleanSandbox(run);
|
|
7025
|
-
run.stage = "prepared";
|
|
7026
|
-
saveRun(run);
|
|
7027
|
-
} catch {
|
|
7028
|
-
}
|
|
7029
|
-
throw error;
|
|
7030
7092
|
}
|
|
7031
7093
|
});
|
|
7032
7094
|
}
|
|
7033
|
-
function
|
|
7095
|
+
function parseAgent(value) {
|
|
7034
7096
|
if (value === "claude") return "claude_code";
|
|
7035
7097
|
if (value === void 0 || ["claude_code", "codex", "cursor", "hermes"].includes(value))
|
|
7036
7098
|
return value;
|
|
7037
|
-
throw new Error("
|
|
7099
|
+
throw new Error("Expected --agent claude, codex, cursor, or hermes");
|
|
7038
7100
|
}
|
|
7039
|
-
function reportError(error
|
|
7040
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
7101
|
+
function reportError(error) {
|
|
7102
|
+
const message = terminalSafeLine(error instanceof Error ? error.message : String(error));
|
|
7103
|
+
const code = error?.code;
|
|
7041
7104
|
process.stderr.write(`[prim] demo: ${message}
|
|
7042
7105
|
`);
|
|
7043
|
-
|
|
7106
|
+
printJson2({
|
|
7107
|
+
fictional: true,
|
|
7108
|
+
evaluation: "live",
|
|
7109
|
+
stage: "error",
|
|
7110
|
+
message,
|
|
7111
|
+
...code === "EPERM" || code === "EACCES" ? {
|
|
7112
|
+
code,
|
|
7113
|
+
recovery: "The host denied access to Primitive local state. Run the same action with the configuration-directory access authorized for setup, within host policy. Do not create another run or change permissions recursively."
|
|
7114
|
+
} : {}
|
|
7115
|
+
});
|
|
7044
7116
|
process.exitCode = 1;
|
|
7045
7117
|
}
|
|
7118
|
+
async function terminalTour(run) {
|
|
7119
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
7120
|
+
const show = (result) => {
|
|
7121
|
+
const text = result.presentation.replace(/^```(?:text|ts|diff)?\n/gmu, "").replace(/```/gu, "").replace(/\*\*(.*?)\*\*/gu, (_match, title) => bold(title));
|
|
7122
|
+
process.stderr.write(
|
|
7123
|
+
`${text.replace("YOUR DECISION STOPPED THIS", color("YOUR DECISION STOPPED THIS", "red")).replace("PASS \u2014 CSV export implemented", color("PASS \u2014 CSV export implemented", "green"))}
|
|
7124
|
+
`
|
|
7125
|
+
);
|
|
7126
|
+
if (["completed", "skipped"].includes(result.stage) && "nextAction" in result) {
|
|
7127
|
+
process.stderr.write(`Next: ${result.nextAction}
|
|
7128
|
+
`);
|
|
7129
|
+
}
|
|
7130
|
+
return result;
|
|
7131
|
+
};
|
|
7132
|
+
try {
|
|
7133
|
+
const started = show(await advanceDemo(run.id, "start"));
|
|
7134
|
+
if (started.stage !== "prompt") return started;
|
|
7135
|
+
const task = await rl.question("Enter the task above (or skip): ");
|
|
7136
|
+
if (task.trim() !== DEMO_TASK) return show(await advanceDemo(run.id, "skip"));
|
|
7137
|
+
const blocked = show(await advanceDemo(run.id, "attempt"));
|
|
7138
|
+
if (blocked.stage !== "conflict") return blocked;
|
|
7139
|
+
const choice = (await rl.question("Adhere or supersede? [adhere/supersede/skip] ")).trim().toLowerCase();
|
|
7140
|
+
if (choice !== "adhere" && choice !== "supersede")
|
|
7141
|
+
return show(await advanceDemo(run.id, "skip"));
|
|
7142
|
+
const reason = choice === "supersede" ? await rl.question("Your reason for the replacement: ") : void 0;
|
|
7143
|
+
return show(await advanceDemo(run.id, "resolve", choice, reason));
|
|
7144
|
+
} finally {
|
|
7145
|
+
rl.close();
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7046
7148
|
function registerDemoCommands(program2) {
|
|
7047
|
-
const demo = program2.command("demo").description("
|
|
7048
|
-
"--details",
|
|
7049
|
-
"show the full source and supporting detail in the interactive terminal tour"
|
|
7050
|
-
).action(async (options, command) => {
|
|
7051
|
-
let terminal = false;
|
|
7052
|
-
const output = (result) => {
|
|
7053
|
-
if (!terminal || !process.stdout.isTTY) printJson(result);
|
|
7054
|
-
};
|
|
7149
|
+
const demo = program2.command("demo").description("Experience your Decision protecting a fictional teammate change").option("--agent <agent>", "calling agent; requires session isolation").option("--details", "include supporting story detail").option("--resume-pending", "reuse a pending tour prepared in this Codex session").action(async (options, command) => {
|
|
7055
7150
|
try {
|
|
7056
|
-
const agent =
|
|
7057
|
-
terminal = !agent && !isNonInteractive(command.optsWithGlobals()) &&
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
)
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
)
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
return;
|
|
7076
|
-
}
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7151
|
+
const agent = parseAgent(options.agent);
|
|
7152
|
+
const terminal = !agent && !isNonInteractive(command.optsWithGlobals()) && !!process.stdin.isTTY && !!process.stderr.isTTY && !process.env.CLAUDECODE && !process.env.CODEX_THREAD_ID && !process.env.CURSOR_AGENT && !process.env.HERMES_INTERACTIVE;
|
|
7153
|
+
const runs = pendingRuns().map(readRun);
|
|
7154
|
+
const recovery = runs.map((run2) => ({
|
|
7155
|
+
runId: run2.id,
|
|
7156
|
+
resumeAction: run2.version === 2 ? demoResumeCommand(run2) : void 0,
|
|
7157
|
+
skipAction: demoCommand(
|
|
7158
|
+
{ ...run2, launcher: [process.execPath, resolve3(process.argv[1])] },
|
|
7159
|
+
"skip"
|
|
7160
|
+
)
|
|
7161
|
+
}));
|
|
7162
|
+
const key = preparationKey(agent);
|
|
7163
|
+
const pending = options.resumePending && key ? runs.find(
|
|
7164
|
+
(run2) => run2.version === 2 && run2.preparationKey === key && run2.agent === agent
|
|
7165
|
+
) : void 0;
|
|
7166
|
+
const run = pending ? lockRun(pending.id, (run2) => {
|
|
7167
|
+
run2.launcher = [process.execPath, resolve3(process.argv[1])];
|
|
7168
|
+
run2.acknowledgment = void 0;
|
|
7169
|
+
saveRun(run2);
|
|
7170
|
+
return run2;
|
|
7171
|
+
}) : prepareRun(agent, terminal);
|
|
7172
|
+
if (terminal) {
|
|
7173
|
+
const result = await terminalTour(run);
|
|
7174
|
+
if (!process.stdout.isTTY) printJson2(result);
|
|
7080
7175
|
return;
|
|
7081
7176
|
}
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7177
|
+
process.stderr.write(
|
|
7178
|
+
"[prim] Tour prepared \u2192 verify isolation to continue. Follow nextAction.\n"
|
|
7179
|
+
);
|
|
7180
|
+
printJson2({
|
|
7181
|
+
fictional: true,
|
|
7182
|
+
evaluation: "live",
|
|
7183
|
+
runId: run.id,
|
|
7184
|
+
stage: run.stage,
|
|
7185
|
+
nextAction: demoCommand(run, run.stage === "prepared" ? "start" : "status"),
|
|
7186
|
+
skipAction: demoCommand(run, "skip"),
|
|
7187
|
+
statusAction: demoDiagnosticCommand(run),
|
|
7188
|
+
presentation: `Tour prepared \u2192 Isolation pending \u2192 ${run.stage === "prepared" ? "Story not started" : "Story paused"}.`,
|
|
7189
|
+
instructions: "Continue nextAction now within the authorized setup request; do not stop at welcome or ask whether to begin. Run nextAction exactly as a standalone command with the same authorized local-state access as setup. Render presentation once, preserving diagrams. At awaitUserPrompt, wait for the user to enter that task before running attemptAction. At the block, wait for adhere or supersede; supersede requires the user's own reason and approval of the displayed replacement. Append --reason and the reason using the same single-quoted argv format (escape an apostrophe as '\\''). Never invent a reason, delegate this tour, or save fictional samples to memory or real Decisions. On completion display success before following welcome. A new session resumes passive capture.",
|
|
7190
|
+
recoverableRuns: recovery
|
|
7191
|
+
});
|
|
7088
7192
|
} catch (error) {
|
|
7089
|
-
reportError(error
|
|
7193
|
+
reportError(error);
|
|
7090
7194
|
}
|
|
7091
7195
|
});
|
|
7092
|
-
|
|
7093
|
-
|
|
7196
|
+
demo.command("resume <runId>").description("Recover this run's launcher without revealing story content").action((id) => {
|
|
7197
|
+
try {
|
|
7198
|
+
printJson2(
|
|
7199
|
+
lockRun(id, (run) => {
|
|
7200
|
+
if (run.version !== 2) throw new Error("Legacy tour must be skipped before replay");
|
|
7201
|
+
run.launcher = [process.execPath, resolve3(process.argv[1])];
|
|
7202
|
+
run.acknowledgment = void 0;
|
|
7203
|
+
saveRun(run);
|
|
7204
|
+
return {
|
|
7205
|
+
fictional: true,
|
|
7206
|
+
evaluation: "live",
|
|
7207
|
+
runId: id,
|
|
7208
|
+
stage: "pending",
|
|
7209
|
+
nextAction: demoCommand(run, run.stage === "prepared" ? "start" : "status"),
|
|
7210
|
+
diagnosticAction: demoDiagnosticCommand(run),
|
|
7211
|
+
presentation: "Run nextAction to verify isolation and resume this tour."
|
|
7212
|
+
};
|
|
7213
|
+
})
|
|
7214
|
+
);
|
|
7215
|
+
} catch (error) {
|
|
7216
|
+
reportError(error);
|
|
7217
|
+
}
|
|
7218
|
+
});
|
|
7219
|
+
for (const action of ["start", "attempt", "resolve", "status", "skip"]) {
|
|
7220
|
+
const sub = demo.command(`${action} ${action === "skip" ? "[runId]" : "<runId>"}`);
|
|
7094
7221
|
if (action === "resolve")
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7222
|
+
sub.requiredOption("--choice <choice>", "adhere or supersede").option("--reason <reason>", "your reason for the displayed replacement");
|
|
7223
|
+
sub.action(
|
|
7224
|
+
async (id, options) => {
|
|
7225
|
+
try {
|
|
7226
|
+
if (action === "skip" && !id) {
|
|
7227
|
+
finishOnboarding("skipped");
|
|
7228
|
+
printJson2({
|
|
7229
|
+
fictional: true,
|
|
7230
|
+
stage: "skipped",
|
|
7231
|
+
message: "Tour skipped. Run prim welcome for real Decisions."
|
|
7232
|
+
});
|
|
7233
|
+
return;
|
|
7234
|
+
}
|
|
7235
|
+
printJson2(await advanceDemo(id, action, options.choice, options.reason));
|
|
7236
|
+
} catch (error) {
|
|
7237
|
+
reportError(error);
|
|
7109
7238
|
}
|
|
7110
|
-
printJson(advanceDemo(id, action, options.choice));
|
|
7111
|
-
} catch (error) {
|
|
7112
|
-
reportError(error);
|
|
7113
7239
|
}
|
|
7114
|
-
|
|
7240
|
+
);
|
|
7115
7241
|
}
|
|
7116
7242
|
}
|
|
7117
7243
|
|
|
@@ -7312,10 +7438,10 @@ function stripBin(list, bin) {
|
|
|
7312
7438
|
}
|
|
7313
7439
|
function ensureReg(list, reg, force) {
|
|
7314
7440
|
const entry = entryFor(reg);
|
|
7315
|
-
const
|
|
7441
|
+
const present2 = list.some(
|
|
7316
7442
|
(e) => e.command === entry.command && (e.matcher ?? "") === (entry.matcher ?? "") && (e.timeout ?? null) === (entry.timeout ?? null)
|
|
7317
7443
|
);
|
|
7318
|
-
if (
|
|
7444
|
+
if (present2 && !force) {
|
|
7319
7445
|
return list;
|
|
7320
7446
|
}
|
|
7321
7447
|
return [...stripBin(list, reg.bin), entry];
|
|
@@ -8146,6 +8272,8 @@ function managedHookRemedy(inspection) {
|
|
|
8146
8272
|
return `outside this repository \u2014 ${externalHookRemedy(inspection.hookName, inspection.gitRoot)}`;
|
|
8147
8273
|
}
|
|
8148
8274
|
return "run `prim hooks install`";
|
|
8275
|
+
case "unsupported_interpreter":
|
|
8276
|
+
return "existing hook preserved: add a supported shebang (for example #!/bin/sh) to a direct shell hook, or run the repository\u2019s Husky prepare script so Husky v9 selects .husky/_; then rerun prim setup. Primitive does not rewrite an unknown interpreter or change core.hooksPath silently";
|
|
8149
8277
|
case "entrypoint_missing":
|
|
8150
8278
|
return "run `prim enable` to stage the hook runtime";
|
|
8151
8279
|
default:
|
|
@@ -8589,7 +8717,10 @@ var DEFAULT_DOCTOR_PROBES = {
|
|
|
8589
8717
|
};
|
|
8590
8718
|
async function collectChecks(options, probes) {
|
|
8591
8719
|
const { before, after } = await probes.independent();
|
|
8592
|
-
|
|
8720
|
+
const checks = [...before, ...classifyDelivery(await probes.delivery(), options), ...after];
|
|
8721
|
+
return checks.filter(
|
|
8722
|
+
(check) => !(options.agent && options.agent !== "claude" && check.name === "feedback-hooks" && check.detail.startsWith("Claude lifecycle hooks missing"))
|
|
8723
|
+
);
|
|
8593
8724
|
}
|
|
8594
8725
|
function icon(status) {
|
|
8595
8726
|
return status === "ok" ? "\u2713" : status === "warn" ? "\u26A0" : "\u2717";
|
|
@@ -8601,6 +8732,7 @@ async function runDoctor(options, probes) {
|
|
|
8601
8732
|
process.stderr.write(`[prim] doctor: ${headline}
|
|
8602
8733
|
`);
|
|
8603
8734
|
for (const c of checks) {
|
|
8735
|
+
if (options.compact && c.status === "ok") continue;
|
|
8604
8736
|
process.stderr.write(` ${icon(c.status)} ${c.name.padEnd(13)} ${c.detail}
|
|
8605
8737
|
`);
|
|
8606
8738
|
}
|
|
@@ -8612,9 +8744,9 @@ async function runDoctor(options, probes) {
|
|
|
8612
8744
|
function registerDoctorCommands(program2, dependencies = {}) {
|
|
8613
8745
|
program2.command("doctor").description(
|
|
8614
8746
|
"Check capture and feedback health end to end (auth, supervisor, delivery, server)"
|
|
8615
|
-
).addOption(new Option4("--expect-backlog").hideHelp()).action(async (opts) => {
|
|
8747
|
+
).addOption(new Option4("--expect-backlog").hideHelp()).addOption(new Option4("--agent <agent>").choices(["claude", "codex", "cursor", "hermes"])).option("--compact", "show only health warnings and failures on STDERR").action(async (opts) => {
|
|
8616
8748
|
await runDoctor(
|
|
8617
|
-
{ backlogExpected: opts.expectBacklog === true },
|
|
8749
|
+
{ backlogExpected: opts.expectBacklog === true, agent: opts.agent, compact: opts.compact },
|
|
8618
8750
|
dependencies.probes ?? DEFAULT_DOCTOR_PROBES
|
|
8619
8751
|
);
|
|
8620
8752
|
});
|
|
@@ -8629,7 +8761,7 @@ import { createReadStream, renameSync as renameSync3, statSync as statSync3, unl
|
|
|
8629
8761
|
import { dirname as dirname4, join as join9 } from "path";
|
|
8630
8762
|
|
|
8631
8763
|
// src/dead-letter.ts
|
|
8632
|
-
import { createHash as
|
|
8764
|
+
import { createHash as createHash4, randomBytes as randomBytes4 } from "crypto";
|
|
8633
8765
|
import {
|
|
8634
8766
|
constants as constants3,
|
|
8635
8767
|
chmodSync as chmodSync2,
|
|
@@ -8651,7 +8783,7 @@ function deadLetterDirectoryForRotation(flushingPath) {
|
|
|
8651
8783
|
return join8(dirname3(flushingPath), DEAD_LETTER_DIRNAME);
|
|
8652
8784
|
}
|
|
8653
8785
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
8654
|
-
const quarantineId =
|
|
8786
|
+
const quarantineId = createHash4("sha256").update(rawLine).digest("hex");
|
|
8655
8787
|
return join8(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
8656
8788
|
}
|
|
8657
8789
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
@@ -8693,7 +8825,7 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
8693
8825
|
const serializedMove = JSON.stringify(move);
|
|
8694
8826
|
const record3 = {
|
|
8695
8827
|
version: 1,
|
|
8696
|
-
quarantineId:
|
|
8828
|
+
quarantineId: createHash4("sha256").update(serializedMove).digest("hex"),
|
|
8697
8829
|
quarantinedAt: now(),
|
|
8698
8830
|
reason,
|
|
8699
8831
|
move
|
|
@@ -8709,7 +8841,7 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
|
|
|
8709
8841
|
const record3 = {
|
|
8710
8842
|
version: 1,
|
|
8711
8843
|
recordKind: "raw_line_v1",
|
|
8712
|
-
quarantineId:
|
|
8844
|
+
quarantineId: createHash4("sha256").update(bytes).digest("hex"),
|
|
8713
8845
|
quarantinedAt: now(),
|
|
8714
8846
|
reason: "invalid_move",
|
|
8715
8847
|
rawLineEncoding: "base64",
|
|
@@ -9444,7 +9576,7 @@ function setupStepSpawnOptions(capture, env = process.env, options = {}) {
|
|
|
9444
9576
|
// Unset rather than inherited when this setup starts no daemon.
|
|
9445
9577
|
[SETUP_DAEMON_DRAINS_ENV]: options.startsDaemon === true ? "1" : void 0
|
|
9446
9578
|
},
|
|
9447
|
-
stdio: capture ? ["inherit", "pipe", "ignore"] : "inherit",
|
|
9579
|
+
stdio: capture ? ["inherit", "pipe", "ignore"] : options.compact ? ["inherit", "pipe", "inherit"] : "inherit",
|
|
9448
9580
|
encoding: "utf-8"
|
|
9449
9581
|
};
|
|
9450
9582
|
}
|
|
@@ -9502,7 +9634,7 @@ function planSetupSteps(opts) {
|
|
|
9502
9634
|
steps.push({
|
|
9503
9635
|
key: "health",
|
|
9504
9636
|
label: "Capture health",
|
|
9505
|
-
args: ["doctor", "--expect-backlog"],
|
|
9637
|
+
args: ["doctor", "--expect-backlog", "--agent", opts.agent, "--compact"],
|
|
9506
9638
|
required: true
|
|
9507
9639
|
});
|
|
9508
9640
|
}
|
|
@@ -9587,6 +9719,7 @@ function detectAgent(env) {
|
|
|
9587
9719
|
if (env.HERMES_INTERACTIVE) {
|
|
9588
9720
|
return "hermes";
|
|
9589
9721
|
}
|
|
9722
|
+
if (env.CODEX_THREAD_ID) return "codex";
|
|
9590
9723
|
if (env.CURSOR_AGENT) {
|
|
9591
9724
|
return "cursor";
|
|
9592
9725
|
}
|
|
@@ -9621,7 +9754,7 @@ function registerSetupCommand(program2, dependencies = {}) {
|
|
|
9621
9754
|
).option(
|
|
9622
9755
|
"--migrate",
|
|
9623
9756
|
"with the default user scope, remove any project-scoped prim config in this repo (else just warn)"
|
|
9624
|
-
).option("--no-daemon", "stop and disable the companion daemon").option("--skip-demo", "skip the
|
|
9757
|
+
).option("--no-daemon", "stop and disable the companion daemon").option("--details", "show full human installation diagnostics on STDERR").option("--skip-demo", "skip the optional author story and remember that choice").action((opts) => {
|
|
9625
9758
|
const { agent: agentInput, detected } = resolveAgent(opts.agent, process.env);
|
|
9626
9759
|
if (agentInput !== "claude" && agentInput !== "codex" && agentInput !== "cursor" && agentInput !== "hermes") {
|
|
9627
9760
|
process.stderr.write(
|
|
@@ -9647,12 +9780,22 @@ function registerSetupCommand(program2, dependencies = {}) {
|
|
|
9647
9780
|
const self = process.argv[1];
|
|
9648
9781
|
const globals = program2.optsWithGlobals();
|
|
9649
9782
|
const run = dependencies.run ?? ((args, capture = false) => {
|
|
9783
|
+
const childArgs = opts.details ? args.filter((arg) => arg !== "--compact") : args;
|
|
9650
9784
|
const r = spawnSync2(
|
|
9651
9785
|
process.execPath,
|
|
9652
|
-
[self, ...
|
|
9653
|
-
setupStepSpawnOptions(capture, process.env, {
|
|
9786
|
+
[self, ...childArgs],
|
|
9787
|
+
setupStepSpawnOptions(capture, process.env, {
|
|
9788
|
+
startsDaemon: opts.daemon,
|
|
9789
|
+
compact: true
|
|
9790
|
+
})
|
|
9654
9791
|
);
|
|
9655
|
-
|
|
9792
|
+
if (!capture && r.status !== 0 && r.stdout) process.stderr.write(r.stdout);
|
|
9793
|
+
if (r.error) process.stderr.write(`[prim] ${r.error.message}
|
|
9794
|
+
`);
|
|
9795
|
+
return {
|
|
9796
|
+
code: r.status ?? 1,
|
|
9797
|
+
stdout: r.stdout ?? ""
|
|
9798
|
+
};
|
|
9656
9799
|
});
|
|
9657
9800
|
const results = {};
|
|
9658
9801
|
const note = dependencies.note ?? ((msg) => {
|
|
@@ -9732,11 +9875,13 @@ function registerSetupCommand(program2, dependencies = {}) {
|
|
|
9732
9875
|
const { code } = run(enableArgs);
|
|
9733
9876
|
results[enableStep.key] = code === 0 ? "ok" : enableStep.required ? "failed" : "skipped";
|
|
9734
9877
|
}
|
|
9878
|
+
let health;
|
|
9735
9879
|
const healthStep = setupSteps.find((candidate) => candidate.key === "health");
|
|
9736
9880
|
if (healthStep) {
|
|
9737
9881
|
note(`${healthStep.label} \xB7 verifying\u2026`);
|
|
9738
|
-
const { code } = run(healthStep.args);
|
|
9739
|
-
|
|
9882
|
+
const { code, stdout } = run(healthStep.args);
|
|
9883
|
+
health = setupChildPayload(stdout);
|
|
9884
|
+
results[healthStep.key] = code !== 0 || health?.status === "fail" ? healthStep.required ? "failed" : "skipped" : health?.status === "warn" ? "warn" : "ok";
|
|
9740
9885
|
}
|
|
9741
9886
|
const installationSucceeded = !Object.values(results).includes("failed");
|
|
9742
9887
|
let tourDue = false;
|
|
@@ -9755,12 +9900,19 @@ function registerSetupCommand(program2, dependencies = {}) {
|
|
|
9755
9900
|
note("demo \xB7 could not remember skip; installation remains configured");
|
|
9756
9901
|
}
|
|
9757
9902
|
note("welcome");
|
|
9758
|
-
|
|
9903
|
+
const welcomeResult = run([
|
|
9904
|
+
"welcome",
|
|
9905
|
+
"--agent",
|
|
9906
|
+
agent,
|
|
9907
|
+
...tourDue ? ["--defer-seeding"] : []
|
|
9908
|
+
]);
|
|
9909
|
+
results.welcome = welcomeResult.code === 0 ? "ok" : "failed";
|
|
9759
9910
|
const failed = Object.entries(results).filter(([, v]) => v === "failed").map(([k]) => k);
|
|
9760
9911
|
const trail = Object.entries(results).map(([k, v]) => `${k}:${v}`).join(" \xB7 ");
|
|
9761
9912
|
note(
|
|
9762
9913
|
`setup ${failed.length === 0 ? "complete" : `incomplete (failed: ${failed.join(", ")})`} \u2014 ${trail}`
|
|
9763
9914
|
);
|
|
9915
|
+
let onboarding;
|
|
9764
9916
|
if (failed.length === 0 && tourDue) {
|
|
9765
9917
|
const agentDriven = Boolean(
|
|
9766
9918
|
opts.agent || !process.stdin.isTTY || !process.stderr.isTTY || process.env.CLAUDECODE || process.env.CODEX_THREAD_ID || process.env.CURSOR_AGENT || process.env.HERMES_INTERACTIVE
|
|
@@ -9768,18 +9920,51 @@ function registerSetupCommand(program2, dependencies = {}) {
|
|
|
9768
9920
|
const demoResult = run([
|
|
9769
9921
|
...globals.nonInteractive ? ["--non-interactive"] : [],
|
|
9770
9922
|
"demo",
|
|
9923
|
+
"--resume-pending",
|
|
9771
9924
|
...agentDriven ? ["--agent", agent] : []
|
|
9772
9925
|
]);
|
|
9773
|
-
|
|
9926
|
+
onboarding = setupChildPayload(demoResult.stdout) ?? {
|
|
9927
|
+
stage: "pending",
|
|
9928
|
+
message: "Run prim demo to recover the optional story"
|
|
9929
|
+
};
|
|
9930
|
+
if (demoResult.code !== 0) {
|
|
9931
|
+
onboarding = { ...onboarding, stage: "pending" };
|
|
9774
9932
|
note("demo \xB7 pending after an error; setup succeeded. Run prim demo to retry");
|
|
9933
|
+
}
|
|
9775
9934
|
}
|
|
9935
|
+
if (!process.stdout.isTTY || opts.agent || globals.nonInteractive || process.env.CLAUDECODE || process.env.CODEX_THREAD_ID || process.env.CURSOR_AGENT || process.env.HERMES_INTERACTIVE)
|
|
9936
|
+
printJson({
|
|
9937
|
+
setup: true,
|
|
9938
|
+
status: failed.length ? "incomplete" : "complete",
|
|
9939
|
+
steps: results,
|
|
9940
|
+
...health ? { health } : {},
|
|
9941
|
+
readiness: {
|
|
9942
|
+
installation: failed.length ? "incomplete" : "installed",
|
|
9943
|
+
health: results.health ?? "not-checked",
|
|
9944
|
+
passiveCapture: "not-verified",
|
|
9945
|
+
onboarding: onboarding?.stage ?? (opts.skipDemo ? "skipped" : "not-due")
|
|
9946
|
+
},
|
|
9947
|
+
...onboarding?.nextAction ? {
|
|
9948
|
+
instructions: "Setup installation is complete. Continue nextAction now; onboarding is pending. Render each presentation once. Do not stop at welcome, repeat raw output, or claim passive capture is verified."
|
|
9949
|
+
} : {},
|
|
9950
|
+
welcome: setupChildPayload(welcomeResult.stdout),
|
|
9951
|
+
...onboarding ? { onboarding, nextAction: onboarding.nextAction } : {}
|
|
9952
|
+
});
|
|
9776
9953
|
exit(failed.length === 0 ? 0 : EXIT_INCOMPLETE);
|
|
9777
9954
|
});
|
|
9778
9955
|
}
|
|
9956
|
+
function setupChildPayload(stdout) {
|
|
9957
|
+
try {
|
|
9958
|
+
const value = JSON.parse(stdout);
|
|
9959
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
9960
|
+
} catch {
|
|
9961
|
+
return void 0;
|
|
9962
|
+
}
|
|
9963
|
+
}
|
|
9779
9964
|
|
|
9780
9965
|
// src/commands/statusline.ts
|
|
9781
9966
|
import { readFileSync as readFileSync9 } from "fs";
|
|
9782
|
-
import { dirname as dirname5, resolve as
|
|
9967
|
+
import { dirname as dirname5, resolve as resolve4 } from "path";
|
|
9783
9968
|
import { fileURLToPath } from "url";
|
|
9784
9969
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
9785
9970
|
function readPackageVersion() {
|
|
@@ -9788,9 +9973,9 @@ function readPackageVersion() {
|
|
|
9788
9973
|
const candidates = [
|
|
9789
9974
|
// Schema-v2 runtimes staged a manifest beside this standalone bundle.
|
|
9790
9975
|
// Keep resolving it while those legacy launchers transition to schema v3.
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9976
|
+
resolve4(here, "manifest.json"),
|
|
9977
|
+
resolve4(here, "../../package.json"),
|
|
9978
|
+
resolve4(here, "../package.json")
|
|
9794
9979
|
];
|
|
9795
9980
|
for (const path of candidates) {
|
|
9796
9981
|
try {
|
|
@@ -10071,8 +10256,8 @@ function resolveWelcomeAgent(agentFlag, env) {
|
|
|
10071
10256
|
var CAPTURE_LINES = {
|
|
10072
10257
|
claude: ["Capture is automatic \u2014 keep coding; your decisions are recorded for you."],
|
|
10073
10258
|
codex: [
|
|
10074
|
-
"Capture starts once
|
|
10075
|
-
"
|
|
10259
|
+
"Capture starts once the prim hooks are active \u2014 check /hooks in Codex;",
|
|
10260
|
+
"approve them only if prompted."
|
|
10076
10261
|
],
|
|
10077
10262
|
cursor: ["Capture is automatic in trusted Cursor workspaces; restart Cursor CLI for the footer."],
|
|
10078
10263
|
hermes: [
|
|
@@ -10087,7 +10272,7 @@ var CAPTURE_LINES = {
|
|
|
10087
10272
|
var PASSIVE_LINES = {
|
|
10088
10273
|
claude: ["Otherwise Primitive captures decisions passively while you work."],
|
|
10089
10274
|
codex: [
|
|
10090
|
-
"Once
|
|
10275
|
+
"Once the prim hooks are active (/hooks in Codex), Primitive captures",
|
|
10091
10276
|
"decisions passively while you work."
|
|
10092
10277
|
],
|
|
10093
10278
|
cursor: ["In trusted Cursor workspaces, Primitive captures decisions passively while you work."],
|
|
@@ -10102,7 +10287,7 @@ var PASSIVE_LINES = {
|
|
|
10102
10287
|
};
|
|
10103
10288
|
var GUIDANCE_PASSIVE = {
|
|
10104
10289
|
claude: "Otherwise, Primitive passively captures decisions in the background while you work.",
|
|
10105
|
-
codex: "Otherwise, once
|
|
10290
|
+
codex: "Otherwise, once the prim hooks are active (check /hooks in Codex), Primitive passively captures decisions in the background while you work.",
|
|
10106
10291
|
cursor: "Otherwise, Primitive passively captures decisions in trusted Cursor workspaces while you work.",
|
|
10107
10292
|
hermes: "Otherwise, once you approve the prim hooks when Hermes prompts, Primitive passively captures decisions in the background while you work.",
|
|
10108
10293
|
generic: "Otherwise, once your agent's prim hooks are active, Primitive passively captures decisions in the background while you work."
|
|
@@ -10199,18 +10384,28 @@ function welcomeJson(state, agent, captureExcluded = false) {
|
|
|
10199
10384
|
return { welcomed: true, org: "unknown" };
|
|
10200
10385
|
}
|
|
10201
10386
|
function registerWelcomeCommand(program2, deps = { getClient }) {
|
|
10202
|
-
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
|
|
10387
|
+
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 author story finish before proposing real Decisions").option("--after-demo", "return a short transition after the author story").option("--capture-excluded", "explain the demo session's passive capture exclusion").action(
|
|
10203
10388
|
async (options) => {
|
|
10204
10389
|
const agent = resolveWelcomeAgent(options.agent, process.env);
|
|
10205
10390
|
if (options.deferSeeding) {
|
|
10206
10391
|
process.stderr.write(
|
|
10207
|
-
"
|
|
10392
|
+
"Primitive installed \u2192 session isolation next \u2192 story \u2192 real Decisions. Follow setup\u2019s nextAction.\n"
|
|
10208
10393
|
);
|
|
10209
10394
|
printJson({ welcomed: true, onboarding: "demo", seedingDeferred: true });
|
|
10210
10395
|
return;
|
|
10211
10396
|
}
|
|
10212
10397
|
const result = await fetchRecent({ limit: RECENT_LIMIT }, deps);
|
|
10213
10398
|
const state = welcomeStateFromRecent(result);
|
|
10399
|
+
if (options.afterDemo) {
|
|
10400
|
+
printJson({
|
|
10401
|
+
welcomed: true,
|
|
10402
|
+
org: state.org,
|
|
10403
|
+
presentation: state.org === "seed" ? "Ready for your first real Decision? I can propose one from shared repository memory for your approval. Approved Decisions are visible to your team." : state.org === "active" ? "Ready for real work. Ask your agent to add a Decision whenever you need one." : "Your Decision history is unavailable; no seeding assumptions were made. Retry welcome when the connection is available.",
|
|
10404
|
+
...state.org === "seed" ? { seedGuidance: seedGuidanceFor(agent, options.captureExcluded) } : {},
|
|
10405
|
+
captureExcluded: options.captureExcluded === true
|
|
10406
|
+
});
|
|
10407
|
+
return;
|
|
10408
|
+
}
|
|
10214
10409
|
process.stderr.write(`${formatWelcome(state, agent, options.captureExcluded)}
|
|
10215
10410
|
`);
|
|
10216
10411
|
printJson(welcomeJson(state, agent, options.captureExcluded));
|
|
@@ -10443,7 +10638,7 @@ function runStartupBackgroundWork(argv, env, work) {
|
|
|
10443
10638
|
|
|
10444
10639
|
// src/index.ts
|
|
10445
10640
|
var __dirname = dirname7(fileURLToPath2(import.meta.url));
|
|
10446
|
-
var pkg = JSON.parse(readFileSync11(
|
|
10641
|
+
var pkg = JSON.parse(readFileSync11(resolve5(__dirname, "../package.json"), "utf-8"));
|
|
10447
10642
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
10448
10643
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
10449
10644
|
flush: () => startBackgroundFlush(),
|