@primitive.ai/prim 0.1.0-alpha.114 → 0.1.0-alpha.116
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 +62 -0
- package/SKILL.md +5 -3
- package/assets/primitive-gameplan/SKILL.md +134 -0
- package/assets/primitive-gameplan/claude-hooks.json +28 -0
- package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
- package/dist/{chunk-IZXLH3R5.js → chunk-3TIKBQHV.js} +2584 -821
- package/dist/{chunk-NH3VC7YO.js → chunk-4OEJ2ONG.js} +1 -1
- package/dist/{chunk-DWAXFXDG.js → chunk-4SN5BCIG.js} +1 -1
- package/dist/{chunk-3KKEV7VI.js → chunk-6IRAGUYK.js} +1 -1
- package/dist/chunk-CXMLAWC2.js +96 -0
- package/dist/chunk-D3ZDZZYS.js +449 -0
- package/dist/{chunk-RUUSUF43.js → chunk-I3J344DF.js} +231 -94
- package/dist/{chunk-7DVEH7FO.js → chunk-JKJ22ONL.js} +1 -1
- package/dist/{chunk-PO5QAYD7.js → chunk-JKO6PZWQ.js} +119 -24
- package/dist/{chunk-BXLH4LDU.js → chunk-LEUZDTNT.js} +1 -1
- package/dist/{chunk-PJW6JZMH.js → chunk-LLKJAET2.js} +1 -1
- package/dist/{chunk-IMYELJIV.js → chunk-RLBASQJD.js} +3 -3
- package/dist/{chunk-RTULPLS7.js → chunk-S55JKCHQ.js} +1 -1
- package/dist/daemon/server.js +2583 -822
- package/dist/hook-runtime/daemon/server.js +2583 -822
- package/dist/hook-runtime/hooks/post-commit.js +2581 -820
- package/dist/hook-runtime/hooks/post-rewrite.js +2581 -820
- package/dist/hook-runtime/hooks/post-tool-use.js +2689 -921
- package/dist/hook-runtime/hooks/pre-tool-use.js +2922 -985
- package/dist/hook-runtime/hooks/prim-hook.js +2682 -914
- package/dist/hook-runtime/hooks/session-end.js +19 -12
- package/dist/hook-runtime/hooks/session-start.js +2828 -1060
- package/dist/hook-runtime/index.js +23395 -12348
- package/dist/hooks/post-commit.js +3 -3
- package/dist/hooks/post-rewrite.js +3 -3
- package/dist/hooks/post-tool-use.js +11 -11
- package/dist/hooks/pre-tool-use.js +78 -316
- package/dist/hooks/prim-hook.js +10 -10
- package/dist/hooks/session-end.js +2 -2
- package/dist/hooks/session-start.js +6 -6
- package/dist/index.js +564 -157
- package/package.json +8 -1
- package/dist/chunk-JDIAPBY7.js +0 -233
package/dist/index.js
CHANGED
|
@@ -19,15 +19,20 @@ import {
|
|
|
19
19
|
resolveRepositoryBinding,
|
|
20
20
|
uninstallGitHookAtPath,
|
|
21
21
|
uninstallProjectGitHook
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JKJ22ONL.js";
|
|
23
23
|
import {
|
|
24
24
|
requireDurableIngestAcknowledgement
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-LEUZDTNT.js";
|
|
26
26
|
import {
|
|
27
27
|
checkAffectedDecisions,
|
|
28
28
|
daemonOrDirectGet,
|
|
29
29
|
formatDecisionsWarning
|
|
30
30
|
} from "./chunk-NEQI2VLM.js";
|
|
31
|
+
import {
|
|
32
|
+
hasCompleteCoverage,
|
|
33
|
+
requestPreflight,
|
|
34
|
+
waitForPreflight
|
|
35
|
+
} from "./chunk-D3ZDZZYS.js";
|
|
31
36
|
import {
|
|
32
37
|
fetchFeedbackCapability
|
|
33
38
|
} from "./chunk-FTW4ZCBA.js";
|
|
@@ -75,7 +80,7 @@ import {
|
|
|
75
80
|
readDemoJson,
|
|
76
81
|
readRun,
|
|
77
82
|
saveRun
|
|
78
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-I3J344DF.js";
|
|
79
84
|
import {
|
|
80
85
|
MS_PER_SECOND,
|
|
81
86
|
deliveryBacklogState,
|
|
@@ -84,7 +89,8 @@ import {
|
|
|
84
89
|
formatStatusline,
|
|
85
90
|
formatTeammates,
|
|
86
91
|
repositoryBindingDiagnosticLabel
|
|
87
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-4SN5BCIG.js";
|
|
93
|
+
import "./chunk-6IRAGUYK.js";
|
|
88
94
|
import {
|
|
89
95
|
bold,
|
|
90
96
|
boundedHealthError,
|
|
@@ -109,7 +115,7 @@ import {
|
|
|
109
115
|
isMoveIngestRequest,
|
|
110
116
|
isReconcileResolutionResponse,
|
|
111
117
|
stripAnsi
|
|
112
|
-
} from "./chunk-
|
|
118
|
+
} from "./chunk-3TIKBQHV.js";
|
|
113
119
|
import {
|
|
114
120
|
CliManagementResponseError,
|
|
115
121
|
HttpError,
|
|
@@ -135,6 +141,7 @@ import {
|
|
|
135
141
|
ensureRegistration,
|
|
136
142
|
entryHasCommand,
|
|
137
143
|
hookRuntimePaths,
|
|
144
|
+
inspectFailureProtection,
|
|
138
145
|
inspectGitHookEntrypoint,
|
|
139
146
|
inspectHookRuntime,
|
|
140
147
|
inspectHookRuntimeResolutions,
|
|
@@ -148,10 +155,11 @@ import {
|
|
|
148
155
|
registerClaudeCommands,
|
|
149
156
|
registerCursorCommands,
|
|
150
157
|
removeHookRuntime,
|
|
158
|
+
reportFailureProtection,
|
|
151
159
|
stableNodePath,
|
|
152
160
|
stageHookRuntime,
|
|
153
161
|
stripCommand
|
|
154
|
-
} from "./chunk-
|
|
162
|
+
} from "./chunk-JKO6PZWQ.js";
|
|
155
163
|
import {
|
|
156
164
|
daemonIsLive,
|
|
157
165
|
daemonRequest
|
|
@@ -192,9 +200,9 @@ import {
|
|
|
192
200
|
} from "./chunk-XG7S3LIL.js";
|
|
193
201
|
|
|
194
202
|
// src/index.ts
|
|
195
|
-
import { readFileSync as
|
|
196
|
-
import { dirname as
|
|
197
|
-
import { fileURLToPath as
|
|
203
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
204
|
+
import { dirname as dirname8, resolve as resolve6 } from "path";
|
|
205
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
198
206
|
import { Command } from "commander";
|
|
199
207
|
import updateNotifier from "update-notifier";
|
|
200
208
|
|
|
@@ -315,9 +323,9 @@ async function pollGitHubInstallIntent(client, start, options = {}) {
|
|
|
315
323
|
if (now() >= start.expiresAt) return expiredStatus(start);
|
|
316
324
|
throw error;
|
|
317
325
|
}
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
320
|
-
if (
|
|
326
|
+
const status2 = parseGitHubInstallIntentStatus(raw, start.expiresAt);
|
|
327
|
+
if (!status2) throw new Error("server returned an invalid GitHub install-intent status");
|
|
328
|
+
if (status2.status !== "pending" && status2.status !== "claimed") return status2;
|
|
321
329
|
}
|
|
322
330
|
}
|
|
323
331
|
|
|
@@ -431,8 +439,8 @@ function parseRevokeResponse(value) {
|
|
|
431
439
|
const parsed = record(value);
|
|
432
440
|
return parsed !== void 0 && hasExactKeys(parsed, ["apiKeyId", "revoked"]) && isApiKeyId(parsed.apiKeyId) && parsed.revoked === true ? { apiKeyId: parsed.apiKeyId, revoked: true } : void 0;
|
|
433
441
|
}
|
|
434
|
-
function failure(code, exitCode,
|
|
435
|
-
return { code, exitCode, ...
|
|
442
|
+
function failure(code, exitCode, status2) {
|
|
443
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
436
444
|
}
|
|
437
445
|
function classifyHttpError(error, operation, dispatched) {
|
|
438
446
|
if (error.status === 401) {
|
|
@@ -892,12 +900,12 @@ function hasStoredRefreshToken() {
|
|
|
892
900
|
return false;
|
|
893
901
|
}
|
|
894
902
|
}
|
|
895
|
-
function authStatusResult(
|
|
903
|
+
function authStatusResult(status2, reason, source, refreshTokenPresent) {
|
|
896
904
|
const expiresAt = source === "token_file" ? getTokenExpiresAt() : void 0;
|
|
897
905
|
const expiresInMs = expiresAt === void 0 ? null : expiresAt - Date.now();
|
|
898
906
|
return {
|
|
899
|
-
authenticated:
|
|
900
|
-
status,
|
|
907
|
+
authenticated: status2 === "valid",
|
|
908
|
+
status: status2,
|
|
901
909
|
reason,
|
|
902
910
|
tokenFile: source === "token_file" ? TOKEN_FILE_PATH : null,
|
|
903
911
|
accessTokenExpiresInMs: expiresInMs,
|
|
@@ -967,9 +975,9 @@ async function verifyAuthStatus() {
|
|
|
967
975
|
);
|
|
968
976
|
}
|
|
969
977
|
}
|
|
970
|
-
function authStatusExitCode(
|
|
971
|
-
if (
|
|
972
|
-
return
|
|
978
|
+
function authStatusExitCode(status2) {
|
|
979
|
+
if (status2 === "valid") return EXIT_OK;
|
|
980
|
+
return status2 === "invalid" ? EXIT_FAIL : EXIT_UNREACHABLE;
|
|
973
981
|
}
|
|
974
982
|
function writeHumanAuthStatus(result) {
|
|
975
983
|
if (result.status === "invalid") {
|
|
@@ -1076,8 +1084,8 @@ ${verificationUrl}`);
|
|
|
1076
1084
|
const state = base64url(randomBytes2(16));
|
|
1077
1085
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
1078
1086
|
let settle;
|
|
1079
|
-
const outcome = new Promise((
|
|
1080
|
-
settle =
|
|
1087
|
+
const outcome = new Promise((resolve7) => {
|
|
1088
|
+
settle = resolve7;
|
|
1081
1089
|
});
|
|
1082
1090
|
const server = createServer((req, res) => {
|
|
1083
1091
|
const url = new URL(req.url ?? "/", `http://${LOCALHOST}`);
|
|
@@ -1091,12 +1099,12 @@ ${verificationUrl}`);
|
|
|
1091
1099
|
res.end(page.html, () => settle(page.result));
|
|
1092
1100
|
});
|
|
1093
1101
|
try {
|
|
1094
|
-
await new Promise((
|
|
1102
|
+
await new Promise((resolve7, reject) => {
|
|
1095
1103
|
const onError = (err) => reject(err);
|
|
1096
1104
|
server.once("error", onError);
|
|
1097
1105
|
server.listen(CALLBACK_PORT, LOCALHOST, () => {
|
|
1098
1106
|
server.removeListener("error", onError);
|
|
1099
|
-
|
|
1107
|
+
resolve7();
|
|
1100
1108
|
});
|
|
1101
1109
|
});
|
|
1102
1110
|
} catch (err) {
|
|
@@ -1289,16 +1297,16 @@ function reportBinding(binding, installAttempted = false) {
|
|
|
1289
1297
|
printJson(binding);
|
|
1290
1298
|
process.exitCode = EXIT_UNBOUND;
|
|
1291
1299
|
}
|
|
1292
|
-
function terminalInstallError(
|
|
1293
|
-
if (
|
|
1294
|
-
if (
|
|
1300
|
+
function terminalInstallError(status2) {
|
|
1301
|
+
if (status2.status === "failed_terminal") {
|
|
1302
|
+
if (status2.failureCode === "repository_identity_migration_required") {
|
|
1295
1303
|
return new Error(
|
|
1296
1304
|
"Selected repos include an older Primitive connection needing a one-time repair; none changed. In GitHub App settings, exclude that existing repo to connect others, or retry after repair. If it persists, contact an admin or support."
|
|
1297
1305
|
);
|
|
1298
1306
|
}
|
|
1299
|
-
return new Error(`GitHub installation failed: ${
|
|
1307
|
+
return new Error(`GitHub installation failed: ${status2.failureCode}`);
|
|
1300
1308
|
}
|
|
1301
|
-
return new Error(`GitHub installation ${
|
|
1309
|
+
return new Error(`GitHub installation ${status2.status}`);
|
|
1302
1310
|
}
|
|
1303
1311
|
async function completeInstallIntent(client, start, dependencies, browser) {
|
|
1304
1312
|
process.stderr.write(`[prim] complete GitHub App installation at:
|
|
@@ -1326,15 +1334,15 @@ async function runGithubConnect(dependencies = defaultDependencies2, options = {
|
|
|
1326
1334
|
signal: AbortSignal.timeout(START_TIMEOUT_MS),
|
|
1327
1335
|
now: dependencies.now
|
|
1328
1336
|
});
|
|
1329
|
-
const
|
|
1337
|
+
const status2 = await completeInstallIntent(
|
|
1330
1338
|
client,
|
|
1331
1339
|
start,
|
|
1332
1340
|
dependencies,
|
|
1333
1341
|
options.browser ?? true
|
|
1334
1342
|
);
|
|
1335
|
-
if (
|
|
1343
|
+
if (status2.status !== "consumed") throw terminalInstallError(status2);
|
|
1336
1344
|
process.stderr.write(
|
|
1337
|
-
`[prim] GitHub installation verified: ${
|
|
1345
|
+
`[prim] GitHub installation verified: ${status2.adminRepositoryCount} admin repositories (${status2.repositoryCount} total)
|
|
1338
1346
|
`
|
|
1339
1347
|
);
|
|
1340
1348
|
const binding = await dependencies.bindRepositoryWithClient(root, client, {
|
|
@@ -2147,7 +2155,7 @@ async function inspectCodexHost(reload = false) {
|
|
|
2147
2155
|
} catch {
|
|
2148
2156
|
return unavailable("host-socket-unavailable");
|
|
2149
2157
|
}
|
|
2150
|
-
return new Promise((
|
|
2158
|
+
return new Promise((resolve7) => {
|
|
2151
2159
|
let finished = false;
|
|
2152
2160
|
let refreshed = false;
|
|
2153
2161
|
let requestId = 0;
|
|
@@ -2163,7 +2171,7 @@ async function inspectCodexHost(reload = false) {
|
|
|
2163
2171
|
finished = true;
|
|
2164
2172
|
clearTimeout(timer);
|
|
2165
2173
|
socket.terminate();
|
|
2166
|
-
|
|
2174
|
+
resolve7(value);
|
|
2167
2175
|
};
|
|
2168
2176
|
const fail = (reason) => finish({ ...unavailable(reason), ...refreshed ? { reload: "refreshed" } : {} });
|
|
2169
2177
|
const timer = setTimeout(() => fail("host-timeout"), TIMEOUT_MS);
|
|
@@ -2314,7 +2322,7 @@ function inspectHookRuntimeResolutions3() {
|
|
|
2314
2322
|
];
|
|
2315
2323
|
}
|
|
2316
2324
|
function entryMatchesRegistration(owned, registration) {
|
|
2317
|
-
return owned.event === registration.event && owned.entry.matcher === registration.matcher && owned.entry.hooks?.length === 1 && owned.entry.hooks[0].type === "command" && owned.entry.hooks[0].command === registration.command;
|
|
2325
|
+
return owned.event === registration.event && owned.entry.matcher === registration.matcher && owned.entry.hooks?.length === 1 && owned.entry.hooks[0].type === "command" && owned.entry.hooks[0].command === registration.command && owned.entry.hooks[0].timeout === registration.timeout && owned.entry.hooks[0].onFailure === registration.onFailure && (registration.bin !== GATE_BIN || owned.entry.hooks[0].async !== true);
|
|
2318
2326
|
}
|
|
2319
2327
|
function hasCompleteHookRegistration(settings) {
|
|
2320
2328
|
const owned = ownedRegistrationEntries(settings);
|
|
@@ -2368,8 +2376,8 @@ function performStatus3() {
|
|
|
2368
2376
|
};
|
|
2369
2377
|
return { user: statusFor(userScopePath()), project: statusFor(projectScopePath()) };
|
|
2370
2378
|
}
|
|
2371
|
-
function uncoveredWorktreeHooks(
|
|
2372
|
-
if (
|
|
2379
|
+
function uncoveredWorktreeHooks(status2) {
|
|
2380
|
+
if (status2.user.present || status2.project.present) return null;
|
|
2373
2381
|
const main = mainWorktreeRoot();
|
|
2374
2382
|
if (main === null) return null;
|
|
2375
2383
|
const path = join3(main, ".codex", "hooks.json");
|
|
@@ -2397,6 +2405,7 @@ function registerCodexCommands(program2) {
|
|
|
2397
2405
|
).option("--force", "Replace any drifted prim hook entries").action(async (opts) => {
|
|
2398
2406
|
const scope = resolveScope(opts.scope);
|
|
2399
2407
|
const result = performInstall(scope, opts.force ?? false);
|
|
2408
|
+
const failureProtection = reportFailureProtection("codex");
|
|
2400
2409
|
if (result.changed) {
|
|
2401
2410
|
console.error(`[prim] Codex integration installed (${scope} scope) at ${result.path}`);
|
|
2402
2411
|
} else {
|
|
@@ -2405,7 +2414,7 @@ function registerCodexCommands(program2) {
|
|
|
2405
2414
|
console.error(TRUST_NOTICE);
|
|
2406
2415
|
const host = await inspectCodexHost(Boolean(process.env.CODEX_THREAD_ID));
|
|
2407
2416
|
console.error(`[prim] ${codexHostGuidance(host)}`);
|
|
2408
|
-
console.log(JSON.stringify({ ...result, host }, null, JSON_INDENT));
|
|
2417
|
+
console.log(JSON.stringify({ ...result, host, failureProtection }, null, JSON_INDENT));
|
|
2409
2418
|
});
|
|
2410
2419
|
codex.command("refresh").description("Reload installed hooks in the calling Codex session without changing trust").action(async () => {
|
|
2411
2420
|
const host = await inspectCodexHost(true);
|
|
@@ -2429,6 +2438,7 @@ function registerCodexCommands(program2) {
|
|
|
2429
2438
|
});
|
|
2430
2439
|
codex.command("status").description("Report whether each prim surface (gate, capture) is installed per scope").action(async () => {
|
|
2431
2440
|
const result = performStatus3();
|
|
2441
|
+
const failureProtection = result.user.gate || result.project.gate ? reportFailureProtection("codex") : void 0;
|
|
2432
2442
|
const host = await inspectCodexHost();
|
|
2433
2443
|
const readiness = {
|
|
2434
2444
|
configured: result.user.complete || result.project.complete,
|
|
@@ -2448,7 +2458,7 @@ ${line("project", result.project)}`);
|
|
|
2448
2458
|
console.error(
|
|
2449
2459
|
"[prim] Configuration is not proof of hook execution or capture. Use the pending tour\u2019s diagnosticAction to check isolation."
|
|
2450
2460
|
);
|
|
2451
|
-
console.log(JSON.stringify({ ...result, readiness }, null, JSON_INDENT));
|
|
2461
|
+
console.log(JSON.stringify({ ...result, readiness, failureProtection }, null, JSON_INDENT));
|
|
2452
2462
|
});
|
|
2453
2463
|
}
|
|
2454
2464
|
|
|
@@ -2472,7 +2482,7 @@ async function runPinnedEnsure(options) {
|
|
|
2472
2482
|
npm_config_fetch_retry_maxtimeout: "5000",
|
|
2473
2483
|
npm_config_fetch_timeout: "15000"
|
|
2474
2484
|
};
|
|
2475
|
-
return await new Promise((
|
|
2485
|
+
return await new Promise((resolve7) => {
|
|
2476
2486
|
let settled = false;
|
|
2477
2487
|
let child;
|
|
2478
2488
|
try {
|
|
@@ -2482,7 +2492,7 @@ async function runPinnedEnsure(options) {
|
|
|
2482
2492
|
{ env, stdio: "ignore" }
|
|
2483
2493
|
);
|
|
2484
2494
|
} catch {
|
|
2485
|
-
|
|
2495
|
+
resolve7(false);
|
|
2486
2496
|
return;
|
|
2487
2497
|
}
|
|
2488
2498
|
const timer = setTimeout(() => {
|
|
@@ -2493,7 +2503,7 @@ async function runPinnedEnsure(options) {
|
|
|
2493
2503
|
if (settled) return;
|
|
2494
2504
|
settled = true;
|
|
2495
2505
|
clearTimeout(timer);
|
|
2496
|
-
|
|
2506
|
+
resolve7(result);
|
|
2497
2507
|
};
|
|
2498
2508
|
timer.unref();
|
|
2499
2509
|
child.once("error", () => finish(false));
|
|
@@ -3755,7 +3765,7 @@ function clearStaleArtifacts() {
|
|
|
3755
3765
|
}
|
|
3756
3766
|
}
|
|
3757
3767
|
function sleep(ms) {
|
|
3758
|
-
return new Promise((
|
|
3768
|
+
return new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
3759
3769
|
}
|
|
3760
3770
|
function spawnDaemon(options) {
|
|
3761
3771
|
const file = binFile(DAEMON_BIN);
|
|
@@ -5113,8 +5123,8 @@ function formatSuccessHuman(operation, request, response) {
|
|
|
5113
5123
|
);
|
|
5114
5124
|
return `[prim] ${identifier} superseded by ${replacement}.`;
|
|
5115
5125
|
}
|
|
5116
|
-
function failure2(code, exitCode,
|
|
5117
|
-
return { code, exitCode, ...
|
|
5126
|
+
function failure2(code, exitCode, status2) {
|
|
5127
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
5118
5128
|
}
|
|
5119
5129
|
function classifyHttpError2(error) {
|
|
5120
5130
|
if (error.status === 401) {
|
|
@@ -5464,8 +5474,8 @@ function parseProposal(value, path) {
|
|
|
5464
5474
|
if (!REPO_FULL_NAME_RE.test(repoFullName)) {
|
|
5465
5475
|
contractError(`${path}.repoFullName`, "must be canonical owner/repository syntax");
|
|
5466
5476
|
}
|
|
5467
|
-
const
|
|
5468
|
-
if (
|
|
5477
|
+
const status2 = record3.status;
|
|
5478
|
+
if (status2 !== "proposed" && status2 !== "confirmed" && status2 !== "verification_failed") {
|
|
5469
5479
|
contractError(`${path}.status`, "is not a review-visible proposal status");
|
|
5470
5480
|
}
|
|
5471
5481
|
if (!Array.isArray(record3.signals) || record3.signals.length > MAX_SIGNALS) {
|
|
@@ -5490,7 +5500,7 @@ function parseProposal(value, path) {
|
|
|
5490
5500
|
_id: asString(record3._id, `${path}._id`, { max: 256, nonempty: true }),
|
|
5491
5501
|
repoFullName,
|
|
5492
5502
|
deadCommitSha: asSha(record3.deadCommitSha, `${path}.deadCommitSha`),
|
|
5493
|
-
status,
|
|
5503
|
+
status: status2,
|
|
5494
5504
|
proposedSha,
|
|
5495
5505
|
proposedTier,
|
|
5496
5506
|
signals,
|
|
@@ -5501,15 +5511,15 @@ function parseProposal(value, path) {
|
|
|
5501
5511
|
function parseDecision(value, path) {
|
|
5502
5512
|
const record3 = asRecord(value, path);
|
|
5503
5513
|
assertKeys(record3, path, ["_id", "intent", "status", "intentTruncated"], ["shortId"]);
|
|
5504
|
-
const
|
|
5505
|
-
if (
|
|
5514
|
+
const status2 = record3.status;
|
|
5515
|
+
if (status2 !== "provisional" && status2 !== "abandoned") {
|
|
5506
5516
|
contractError(`${path}.status`, "is not a repairable decision status");
|
|
5507
5517
|
}
|
|
5508
5518
|
return {
|
|
5509
5519
|
_id: asString(record3._id, `${path}._id`, { max: 256, nonempty: true }),
|
|
5510
5520
|
shortId: optionalString(record3, "shortId", path, 128),
|
|
5511
5521
|
intent: asString(record3.intent, `${path}.intent`, { max: MAX_INTENT_LENGTH }),
|
|
5512
|
-
status,
|
|
5522
|
+
status: status2,
|
|
5513
5523
|
intentTruncated: asBoolean(record3.intentTruncated, `${path}.intentTruncated`)
|
|
5514
5524
|
};
|
|
5515
5525
|
}
|
|
@@ -5940,8 +5950,8 @@ function projectSuccess2(response) {
|
|
|
5940
5950
|
...response.scopeWarnings === void 0 ? {} : { scopeWarnings: response.scopeWarnings }
|
|
5941
5951
|
};
|
|
5942
5952
|
}
|
|
5943
|
-
function failure3(code, exitCode,
|
|
5944
|
-
return { code, exitCode, ...
|
|
5953
|
+
function failure3(code, exitCode, status2) {
|
|
5954
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
5945
5955
|
}
|
|
5946
5956
|
function classifyHttpError3(error) {
|
|
5947
5957
|
if (error.status === 401) {
|
|
@@ -6044,12 +6054,12 @@ async function rescopeDecision(request, dependencies = defaultDependencies4) {
|
|
|
6044
6054
|
|
|
6045
6055
|
// src/decisions/show.ts
|
|
6046
6056
|
var NOT_FOUND_RE4 = /not found/i;
|
|
6047
|
-
function colorStatus(
|
|
6048
|
-
const safeStatus = terminalSafeLine(
|
|
6049
|
-
if (
|
|
6057
|
+
function colorStatus(status2) {
|
|
6058
|
+
const safeStatus = terminalSafeLine(status2);
|
|
6059
|
+
if (status2 === "under_review" || status2 === "provisional") {
|
|
6050
6060
|
return color(safeStatus, "orange");
|
|
6051
6061
|
}
|
|
6052
|
-
if (
|
|
6062
|
+
if (status2 === "active" || status2 === "adopted") {
|
|
6053
6063
|
return color(safeStatus, "green");
|
|
6054
6064
|
}
|
|
6055
6065
|
return color(safeStatus, "gray");
|
|
@@ -6347,6 +6357,28 @@ function locationScopeFromOptions(options) {
|
|
|
6347
6357
|
}
|
|
6348
6358
|
function registerDecisionsCommands(program2) {
|
|
6349
6359
|
const decisions = program2.command("decisions").description("Inspect the project Decision Graph");
|
|
6360
|
+
const preflight = decisions.command("preflight").description("Inspect or resume a paused Decision check");
|
|
6361
|
+
preflight.command("status <checkId>").description("Show the current state without restarting work").action(async (checkId) => {
|
|
6362
|
+
const result = await requestPreflight({ protocolVersion: 4, operation: "status", checkId });
|
|
6363
|
+
printJson(result);
|
|
6364
|
+
console.error(`[prim] Decision check ${result.state}: ${terminalSafeLine(result.message)}`);
|
|
6365
|
+
if (!hasCompleteCoverage(result)) process.exitCode = EXIT_FAILURE2;
|
|
6366
|
+
});
|
|
6367
|
+
preflight.command("resume <checkId>").description("Resume evaluation and wait up to 240 seconds; then retry the original tool call").action(async (checkId) => {
|
|
6368
|
+
const result = await waitForPreflight(
|
|
6369
|
+
{ protocolVersion: 4, operation: "resume", checkId },
|
|
6370
|
+
{
|
|
6371
|
+
onProgress: ({ evaluationCoverage: coverage }) => console.error(
|
|
6372
|
+
`[prim] Checking Decisions: ${coverage.evaluatedCount + coverage.bypassedCount}/${coverage.candidateCount}${coverage.discoveryComplete ? "" : "+"} covered.`
|
|
6373
|
+
)
|
|
6374
|
+
}
|
|
6375
|
+
);
|
|
6376
|
+
printJson(result);
|
|
6377
|
+
console.error(
|
|
6378
|
+
`[prim] Decision check ${result.state}: ${terminalSafeLine(result.message)}${hasCompleteCoverage(result) ? "; retry the original tool call" : "; operation remains paused"}`
|
|
6379
|
+
);
|
|
6380
|
+
if (!hasCompleteCoverage(result)) process.exitCode = EXIT_FAILURE2;
|
|
6381
|
+
});
|
|
6350
6382
|
decisions.command("check").description("Look up active decisions scoped to file paths in the connected repository").requiredOption(
|
|
6351
6383
|
"--files <files>",
|
|
6352
6384
|
"Comma-separated repository-relative paths to check against the Decision Graph (repeatable)",
|
|
@@ -7565,7 +7597,7 @@ var CAPTURE_EVENTS = [
|
|
|
7565
7597
|
"on_session_end",
|
|
7566
7598
|
"subagent_stop"
|
|
7567
7599
|
];
|
|
7568
|
-
var GATE_TIMEOUT_SECONDS =
|
|
7600
|
+
var GATE_TIMEOUT_SECONDS = 300;
|
|
7569
7601
|
var REGISTRATIONS = [
|
|
7570
7602
|
...CAPTURE_EVENTS.map((event) => ({ event, bin: CAPTURE_BIN2 })),
|
|
7571
7603
|
{ event: "pre_tool_call", matcher: EDIT_MATCHER, bin: GATE_BIN2, timeout: GATE_TIMEOUT_SECONDS },
|
|
@@ -7587,6 +7619,7 @@ function entryFor(reg) {
|
|
|
7587
7619
|
if (reg.timeout !== void 0) {
|
|
7588
7620
|
entry.timeout = reg.timeout;
|
|
7589
7621
|
}
|
|
7622
|
+
if (reg.bin === GATE_BIN2) entry.fail_closed = true;
|
|
7590
7623
|
return entry;
|
|
7591
7624
|
}
|
|
7592
7625
|
function stripBin(list, bin) {
|
|
@@ -7595,9 +7628,9 @@ function stripBin(list, bin) {
|
|
|
7595
7628
|
function ensureReg(list, reg, force) {
|
|
7596
7629
|
const entry = entryFor(reg);
|
|
7597
7630
|
const present2 = list.some(
|
|
7598
|
-
(e) => e.command === entry.command && (e.matcher ?? "") === (entry.matcher ?? "") && (e.timeout ?? null) === (entry.timeout ?? null)
|
|
7631
|
+
(e) => e.command === entry.command && (e.matcher ?? "") === (entry.matcher ?? "") && (e.timeout ?? null) === (entry.timeout ?? null) && e.fail_closed === entry.fail_closed
|
|
7599
7632
|
);
|
|
7600
|
-
if (present2 && !force) {
|
|
7633
|
+
if (present2 && !force && (reg.bin !== GATE_BIN2 || list.filter((e) => commandUsesBin(e.command, reg.bin)).length === 1)) {
|
|
7601
7634
|
return list;
|
|
7602
7635
|
}
|
|
7603
7636
|
return [...stripBin(list, reg.bin), entry];
|
|
@@ -7664,7 +7697,7 @@ function inspectHookRuntimeResolutions4() {
|
|
|
7664
7697
|
}
|
|
7665
7698
|
function entryMatchesRegistration2(owned, registration) {
|
|
7666
7699
|
const expected = entryFor(registration);
|
|
7667
|
-
return owned.event === registration.event && owned.entry.command === expected.command && (owned.entry.matcher ?? "") === (expected.matcher ?? "") && (owned.entry.timeout ?? null) === (expected.timeout ?? null);
|
|
7700
|
+
return owned.event === registration.event && owned.entry.command === expected.command && (owned.entry.matcher ?? "") === (expected.matcher ?? "") && (owned.entry.timeout ?? null) === (expected.timeout ?? null) && owned.entry.fail_closed === expected.fail_closed;
|
|
7668
7701
|
}
|
|
7669
7702
|
function hasCompleteHookRegistration2(hooks) {
|
|
7670
7703
|
const owned = ownedRegistrationEntries2(hooks);
|
|
@@ -8048,11 +8081,12 @@ function registerHermesCommands(program2) {
|
|
|
8048
8081
|
force: opts.force ?? false,
|
|
8049
8082
|
autoAccept: opts.autoAccept ?? false
|
|
8050
8083
|
});
|
|
8084
|
+
const failureProtection = reportFailureProtection("hermes");
|
|
8051
8085
|
console.error(
|
|
8052
8086
|
result.changed ? `[prim] Hermes integration installed at ${result.path}` : `[prim] Hermes integration already present at ${result.path} (no changes)`
|
|
8053
8087
|
);
|
|
8054
8088
|
console.error(TRUST_NOTICE2);
|
|
8055
|
-
console.log(JSON.stringify(result, null, JSON_INDENT2));
|
|
8089
|
+
console.log(JSON.stringify({ ...result, failureProtection }, null, JSON_INDENT2));
|
|
8056
8090
|
});
|
|
8057
8091
|
hermes.command("uninstall").description("Remove all prim hooks from Hermes's ~/.hermes/config.yaml").action(() => {
|
|
8058
8092
|
const result = performUninstall2();
|
|
@@ -8063,11 +8097,12 @@ function registerHermesCommands(program2) {
|
|
|
8063
8097
|
});
|
|
8064
8098
|
hermes.command("status").description("Report whether each prim surface (gate, capture) is installed").action(() => {
|
|
8065
8099
|
const result = performStatus4();
|
|
8100
|
+
const failureProtection = result.gate ? reportFailureProtection("hermes") : void 0;
|
|
8066
8101
|
const mark = (b) => b ? "\u2713" : "\u2717";
|
|
8067
8102
|
console.error(
|
|
8068
8103
|
`[prim] hermes: gate ${mark(result.gate)} \xB7 capture ${mark(result.capture)} (${result.path})`
|
|
8069
8104
|
);
|
|
8070
|
-
console.log(JSON.stringify(result, null, JSON_INDENT2));
|
|
8105
|
+
console.log(JSON.stringify({ ...result, failureProtection }, null, JSON_INDENT2));
|
|
8071
8106
|
});
|
|
8072
8107
|
}
|
|
8073
8108
|
|
|
@@ -8077,10 +8112,10 @@ var CONNECTIVITY_TIMEOUT_MS = 3e3;
|
|
|
8077
8112
|
var STALE_PENDING_MS = 3e4;
|
|
8078
8113
|
var EXIT_UNHEALTHY = 1;
|
|
8079
8114
|
function classifyDoctor(checks) {
|
|
8080
|
-
const
|
|
8115
|
+
const status2 = checks.some((c) => c.status === "fail") ? "fail" : checks.some((c) => c.status === "warn") ? "warn" : "ok";
|
|
8081
8116
|
return {
|
|
8082
|
-
json: { ok:
|
|
8083
|
-
exitCode:
|
|
8117
|
+
json: { ok: status2 !== "fail", status: status2, checks },
|
|
8118
|
+
exitCode: status2 === "fail" ? EXIT_UNHEALTHY : 0
|
|
8084
8119
|
};
|
|
8085
8120
|
}
|
|
8086
8121
|
function classifyAuthCredential(credential, expiresAt, hasRefresh) {
|
|
@@ -8527,15 +8562,15 @@ function checkManagedHook(hookName, firing) {
|
|
|
8527
8562
|
}
|
|
8528
8563
|
function checkFeedbackHooks() {
|
|
8529
8564
|
try {
|
|
8530
|
-
const
|
|
8531
|
-
return classifyClaudeHooks([
|
|
8565
|
+
const status2 = performStatus();
|
|
8566
|
+
return classifyClaudeHooks([status2.project, status2.user]);
|
|
8532
8567
|
} catch (error) {
|
|
8533
8568
|
const message = error instanceof Error ? error.message : String(error);
|
|
8534
8569
|
return { name: "feedback-hooks", status: "warn", detail: message.slice(0, 80) };
|
|
8535
8570
|
}
|
|
8536
8571
|
}
|
|
8537
8572
|
function classifyClaudeHooks(statuses) {
|
|
8538
|
-
const installed = statuses.filter((
|
|
8573
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8539
8574
|
if (installed.length === 0) {
|
|
8540
8575
|
return {
|
|
8541
8576
|
name: "feedback-hooks",
|
|
@@ -8543,7 +8578,7 @@ function classifyClaudeHooks(statuses) {
|
|
|
8543
8578
|
detail: "Claude lifecycle hooks missing \u2014 run `prim claude install`"
|
|
8544
8579
|
};
|
|
8545
8580
|
}
|
|
8546
|
-
if (installed.some((
|
|
8581
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8547
8582
|
return {
|
|
8548
8583
|
name: "feedback-hooks",
|
|
8549
8584
|
status: "fail",
|
|
@@ -8553,7 +8588,7 @@ function classifyClaudeHooks(statuses) {
|
|
|
8553
8588
|
return { name: "feedback-hooks", status: "ok", detail: "complete Claude lifecycle ready" };
|
|
8554
8589
|
}
|
|
8555
8590
|
function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host) {
|
|
8556
|
-
const installed = statuses.filter((
|
|
8591
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8557
8592
|
if (installed.length === 0) {
|
|
8558
8593
|
if (uncoveredWorktree !== null) {
|
|
8559
8594
|
return {
|
|
@@ -8564,7 +8599,7 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
|
|
|
8564
8599
|
}
|
|
8565
8600
|
return { name: "codex-hooks", status: "ok", detail: "not installed" };
|
|
8566
8601
|
}
|
|
8567
|
-
if (installed.some((
|
|
8602
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8568
8603
|
return {
|
|
8569
8604
|
name: "codex-hooks",
|
|
8570
8605
|
status: "fail",
|
|
@@ -8578,17 +8613,17 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
|
|
|
8578
8613
|
};
|
|
8579
8614
|
}
|
|
8580
8615
|
function classifyCursorHooks(statuses) {
|
|
8581
|
-
const installed = statuses.filter((
|
|
8616
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8582
8617
|
if (installed.length === 0)
|
|
8583
8618
|
return { name: "cursor-hooks", status: "ok", detail: "not installed" };
|
|
8584
|
-
if (installed.some((
|
|
8619
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8585
8620
|
return {
|
|
8586
8621
|
name: "cursor-hooks",
|
|
8587
8622
|
status: "fail",
|
|
8588
8623
|
detail: "incomplete or drifted native lifecycle \u2014 run `prim cursor install --force`"
|
|
8589
8624
|
};
|
|
8590
8625
|
}
|
|
8591
|
-
const user = statuses.find((
|
|
8626
|
+
const user = statuses.find((status2) => status2.footer !== void 0);
|
|
8592
8627
|
if (user?.present && user.footer === false && !user.footerPreservedCustom) {
|
|
8593
8628
|
return {
|
|
8594
8629
|
name: "cursor-hooks",
|
|
@@ -8596,7 +8631,7 @@ function classifyCursorHooks(statuses) {
|
|
|
8596
8631
|
detail: "native lifecycle ready but Cursor CLI footer is missing \u2014 run `prim cursor install --scope user --force`"
|
|
8597
8632
|
};
|
|
8598
8633
|
}
|
|
8599
|
-
if (statuses.some((
|
|
8634
|
+
if (statuses.some((status2) => status2.footerPreservedCustom)) {
|
|
8600
8635
|
return {
|
|
8601
8636
|
name: "cursor-hooks",
|
|
8602
8637
|
status: "warn",
|
|
@@ -8605,18 +8640,18 @@ function classifyCursorHooks(statuses) {
|
|
|
8605
8640
|
}
|
|
8606
8641
|
return { name: "cursor-hooks", status: "ok", detail: "complete native lifecycle ready" };
|
|
8607
8642
|
}
|
|
8608
|
-
function classifyHermesHooks(
|
|
8609
|
-
if (!
|
|
8643
|
+
function classifyHermesHooks(status2) {
|
|
8644
|
+
if (!status2.present) {
|
|
8610
8645
|
return { name: "hermes-hooks", status: "ok", detail: "not installed" };
|
|
8611
8646
|
}
|
|
8612
|
-
if (!
|
|
8647
|
+
if (!status2.complete) {
|
|
8613
8648
|
return {
|
|
8614
8649
|
name: "hermes-hooks",
|
|
8615
8650
|
status: "fail",
|
|
8616
8651
|
detail: "incomplete or drifted hook lifecycle \u2014 run `prim hermes install --force`"
|
|
8617
8652
|
};
|
|
8618
8653
|
}
|
|
8619
|
-
return
|
|
8654
|
+
return status2.autoAccept ? { name: "hermes-hooks", status: "ok", detail: "installed and pre-authorized" } : {
|
|
8620
8655
|
name: "hermes-hooks",
|
|
8621
8656
|
status: "warn",
|
|
8622
8657
|
detail: "installed; hook consent is not pre-authorized \u2014 run `prim hermes install --auto-accept`"
|
|
@@ -8625,13 +8660,13 @@ function classifyHermesHooks(status) {
|
|
|
8625
8660
|
async function checkAgentHooks() {
|
|
8626
8661
|
const checks = [];
|
|
8627
8662
|
try {
|
|
8628
|
-
const
|
|
8663
|
+
const status2 = performStatus3();
|
|
8629
8664
|
checks.push(
|
|
8630
8665
|
classifyCodexHooks(
|
|
8631
|
-
[
|
|
8632
|
-
uncoveredWorktreeHooks(
|
|
8666
|
+
[status2.project, status2.user],
|
|
8667
|
+
uncoveredWorktreeHooks(status2),
|
|
8633
8668
|
lastConversationCaptured(process.cwd(), "codex"),
|
|
8634
|
-
|
|
8669
|
+
status2.user.present || status2.project.present ? await inspectCodexHost() : void 0
|
|
8635
8670
|
)
|
|
8636
8671
|
);
|
|
8637
8672
|
} catch (error) {
|
|
@@ -8643,8 +8678,8 @@ async function checkAgentHooks() {
|
|
|
8643
8678
|
});
|
|
8644
8679
|
}
|
|
8645
8680
|
try {
|
|
8646
|
-
const
|
|
8647
|
-
checks.push(classifyCursorHooks([
|
|
8681
|
+
const status2 = performStatus2();
|
|
8682
|
+
checks.push(classifyCursorHooks([status2.project, status2.user]));
|
|
8648
8683
|
} catch (error) {
|
|
8649
8684
|
const detail = boundedHealthError(error instanceof Error ? error.message : String(error));
|
|
8650
8685
|
checks.push({
|
|
@@ -8783,26 +8818,26 @@ function parseMovesStatus(value) {
|
|
|
8783
8818
|
if (!value || typeof value !== "object") {
|
|
8784
8819
|
throw new Error("moves status returned a non-object response");
|
|
8785
8820
|
}
|
|
8786
|
-
const
|
|
8821
|
+
const status2 = value;
|
|
8787
8822
|
const nullableNumber = (candidate) => candidate === null || typeof candidate === "number" && Number.isFinite(candidate);
|
|
8788
|
-
if (
|
|
8823
|
+
if (status2.captureState !== "enabled" || !nullableNumber(status2.latestIngestAt) || !nullableNumber(status2.latestClassificationAt) || !nullableNumber(status2.highWaterMark) || typeof status2.pendingSessionCount !== "number" || !Number.isInteger(status2.pendingSessionCount) || status2.pendingSessionCount < 0 || typeof status2.sampled !== "boolean") {
|
|
8789
8824
|
throw new Error("moves status returned an invalid response");
|
|
8790
8825
|
}
|
|
8791
|
-
if (
|
|
8826
|
+
if (status2.oldestPendingAt !== void 0 && !nullableNumber(status2.oldestPendingAt) || status2.oldestPendingAgeMs !== void 0 && !nullableNumber(status2.oldestPendingAgeMs) || typeof status2.oldestPendingAgeMs === "number" && status2.oldestPendingAgeMs < 0 || status2.pendingCommitCorrelationCount !== void 0 && (!Number.isInteger(status2.pendingCommitCorrelationCount) || status2.pendingCommitCorrelationCount < 0)) {
|
|
8792
8827
|
throw new Error("moves status returned invalid pending-age fields");
|
|
8793
8828
|
}
|
|
8794
|
-
return
|
|
8829
|
+
return status2;
|
|
8795
8830
|
}
|
|
8796
|
-
function classifyMovesStatus(
|
|
8831
|
+
function classifyMovesStatus(status2) {
|
|
8797
8832
|
const capture = {
|
|
8798
8833
|
name: "capture",
|
|
8799
8834
|
status: "ok",
|
|
8800
8835
|
detail: "enabled; ingest endpoint durable"
|
|
8801
8836
|
};
|
|
8802
|
-
const correlation =
|
|
8837
|
+
const correlation = status2.pendingCommitCorrelationCount === void 0 ? void 0 : status2.pendingCommitCorrelationCount > 0 ? {
|
|
8803
8838
|
name: "commit-correlation",
|
|
8804
8839
|
status: "warn",
|
|
8805
|
-
detail: `${String(
|
|
8840
|
+
detail: `${String(status2.pendingCommitCorrelationCount)} commit(s) awaiting evidence correlation`
|
|
8806
8841
|
} : {
|
|
8807
8842
|
name: "commit-correlation",
|
|
8808
8843
|
status: "ok",
|
|
@@ -8815,10 +8850,10 @@ async function checkBackend() {
|
|
|
8815
8850
|
const response = await getClient().get("/api/cli/moves/status", {
|
|
8816
8851
|
signal: AbortSignal.timeout(CONNECTIVITY_TIMEOUT_MS)
|
|
8817
8852
|
});
|
|
8818
|
-
const
|
|
8853
|
+
const status2 = parseMovesStatus(response);
|
|
8819
8854
|
return [
|
|
8820
8855
|
{ name: "connectivity", status: "ok", detail: "server reachable and authenticated" },
|
|
8821
|
-
...classifyMovesStatus(
|
|
8856
|
+
...classifyMovesStatus(status2)
|
|
8822
8857
|
];
|
|
8823
8858
|
} catch (err) {
|
|
8824
8859
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8848,6 +8883,21 @@ async function checkFeedbackCapability() {
|
|
|
8848
8883
|
return { name: "feedback-api", status: "warn", detail: message.slice(0, 80) };
|
|
8849
8884
|
}
|
|
8850
8885
|
}
|
|
8886
|
+
function checkPreflightHosts() {
|
|
8887
|
+
const hosts = [];
|
|
8888
|
+
if (Object.values(performStatus()).some((scope) => scope.gate)) hosts.push("claude");
|
|
8889
|
+
if (Object.values(performStatus3()).some((scope) => scope.gate)) hosts.push("codex");
|
|
8890
|
+
if (Object.values(performStatus2()).some((scope) => scope.gate)) hosts.push("cursor");
|
|
8891
|
+
if (performStatus4().gate) hosts.push("hermes");
|
|
8892
|
+
return hosts.map((host) => {
|
|
8893
|
+
const protection = inspectFailureProtection(host);
|
|
8894
|
+
return {
|
|
8895
|
+
name: `${host} gate failure protection`,
|
|
8896
|
+
status: protection.status === "supported" ? "ok" : protection.status === "limited" ? "warn" : "fail",
|
|
8897
|
+
detail: protection.detail
|
|
8898
|
+
};
|
|
8899
|
+
});
|
|
8900
|
+
}
|
|
8851
8901
|
async function independentChecks() {
|
|
8852
8902
|
const backend = await checkBackend();
|
|
8853
8903
|
const firing = inspectFiringHere();
|
|
@@ -8858,6 +8908,7 @@ async function independentChecks() {
|
|
|
8858
8908
|
checkFeedbackHooks(),
|
|
8859
8909
|
...await checkAgentHooks(),
|
|
8860
8910
|
checkHookRuntime(),
|
|
8911
|
+
...checkPreflightHosts(),
|
|
8861
8912
|
await checkRepositoryBinding(),
|
|
8862
8913
|
checkManagedHook("pre-commit"),
|
|
8863
8914
|
checkManagedHook("post-commit", firing),
|
|
@@ -8879,8 +8930,8 @@ async function collectChecks(options, probes) {
|
|
|
8879
8930
|
(check) => !(options.agent && options.agent !== "claude" && check.name === "feedback-hooks" && check.detail.startsWith("Claude lifecycle hooks missing"))
|
|
8880
8931
|
);
|
|
8881
8932
|
}
|
|
8882
|
-
function icon(
|
|
8883
|
-
return
|
|
8933
|
+
function icon(status2) {
|
|
8934
|
+
return status2 === "ok" ? "\u2713" : status2 === "warn" ? "\u26A0" : "\u2717";
|
|
8884
8935
|
}
|
|
8885
8936
|
async function runDoctor(options, probes) {
|
|
8886
8937
|
const checks = await collectChecks(options, probes);
|
|
@@ -8909,21 +8960,376 @@ function registerDoctorCommands(program2, dependencies = {}) {
|
|
|
8909
8960
|
});
|
|
8910
8961
|
}
|
|
8911
8962
|
|
|
8963
|
+
// src/commands/gameplan.ts
|
|
8964
|
+
import { createHash as createHash4 } from "crypto";
|
|
8965
|
+
import { existsSync as existsSync8, lstatSync as lstatSync6, readFileSync as readFileSync7, readdirSync as readdirSync4, rmdirSync as rmdirSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
8966
|
+
import { homedir as homedir6 } from "os";
|
|
8967
|
+
import { dirname as dirname3, join as join9, resolve as resolve4 } from "path";
|
|
8968
|
+
import { fileURLToPath } from "url";
|
|
8969
|
+
var __dirname = dirname3(fileURLToPath(import.meta.url));
|
|
8970
|
+
var SKILL_NAME = "primitive-gameplan";
|
|
8971
|
+
var MANIFEST_NAME = ".prim-managed.json";
|
|
8972
|
+
var MANIFEST_OWNER = "@primitive.ai/prim:gameplan:v1";
|
|
8973
|
+
var START = "<!-- BEGIN PRIMITIVE GAMEPLAN v1 -->";
|
|
8974
|
+
var END = "<!-- END PRIMITIVE GAMEPLAN v1 -->";
|
|
8975
|
+
var HOOK_MARKER = "prim-gameplan-hook-v1";
|
|
8976
|
+
var HOOK_COMMAND = 'primitive_gameplan_hook="$(git rev-parse --show-toplevel 2>/dev/null)/.agents/skills/primitive-gameplan/scripts/activate.mjs"; if [ -f "$primitive_gameplan_hook" ]; then node "$primitive_gameplan_hook"; fi # prim-gameplan-hook-v1';
|
|
8977
|
+
var ASSET_FILES = ["SKILL.md", "scripts/activate.mjs", "claude-hooks.json"];
|
|
8978
|
+
var AGENTS_BLOCK = `${START}
|
|
8979
|
+
When using $write-gameplan or $write-workstream, read and follow
|
|
8980
|
+
.agents/skills/primitive-gameplan/SKILL.md before architectural discussion.
|
|
8981
|
+
Keep the public planning skills unchanged.
|
|
8982
|
+
${END}`;
|
|
8983
|
+
function packageRoot2() {
|
|
8984
|
+
let directory = __dirname;
|
|
8985
|
+
while (directory !== dirname3(directory)) {
|
|
8986
|
+
if (existsSync8(join9(directory, "assets", SKILL_NAME, "SKILL.md"))) return directory;
|
|
8987
|
+
directory = dirname3(directory);
|
|
8988
|
+
}
|
|
8989
|
+
throw new Error("Primitive gameplan assets are missing from this CLI package");
|
|
8990
|
+
}
|
|
8991
|
+
function packageVersion2(root) {
|
|
8992
|
+
const parsed = JSON.parse(readFileSync7(join9(root, "package.json"), "utf8"));
|
|
8993
|
+
if (typeof parsed.version !== "string") throw new Error("CLI package version is missing");
|
|
8994
|
+
return parsed.version;
|
|
8995
|
+
}
|
|
8996
|
+
function sha256(content) {
|
|
8997
|
+
return createHash4("sha256").update(content).digest("hex");
|
|
8998
|
+
}
|
|
8999
|
+
function pathsFor(cwd) {
|
|
9000
|
+
const root = gitToplevel(cwd);
|
|
9001
|
+
if (root === null) throw new Error("Run prim gameplan from a Git worktree");
|
|
9002
|
+
const skillDir = join9(root, ".agents", "skills", SKILL_NAME);
|
|
9003
|
+
const codexHome = process.env.CODEX_HOME?.trim() ? resolve4(process.env.CODEX_HOME) : join9(homedir6(), ".codex");
|
|
9004
|
+
return {
|
|
9005
|
+
root,
|
|
9006
|
+
skillDir,
|
|
9007
|
+
manifest: join9(skillDir, MANIFEST_NAME),
|
|
9008
|
+
agents: join9(root, "AGENTS.md"),
|
|
9009
|
+
agentsOverride: join9(root, "AGENTS.override.md"),
|
|
9010
|
+
userHooks: join9(codexHome, "hooks.json")
|
|
9011
|
+
};
|
|
9012
|
+
}
|
|
9013
|
+
function readRegularFile(path) {
|
|
9014
|
+
let entry;
|
|
9015
|
+
try {
|
|
9016
|
+
entry = lstatSync6(path);
|
|
9017
|
+
} catch (error) {
|
|
9018
|
+
if (error.code === "ENOENT") return null;
|
|
9019
|
+
throw error;
|
|
9020
|
+
}
|
|
9021
|
+
if (!entry.isFile()) throw new Error(`Refusing non-regular file at ${path}`);
|
|
9022
|
+
return readFileSync7(path, "utf8");
|
|
9023
|
+
}
|
|
9024
|
+
function readManifest(path) {
|
|
9025
|
+
const content = readRegularFile(path);
|
|
9026
|
+
if (content === null) return null;
|
|
9027
|
+
let value;
|
|
9028
|
+
try {
|
|
9029
|
+
value = JSON.parse(content);
|
|
9030
|
+
} catch {
|
|
9031
|
+
throw new Error(`Invalid Primitive gameplan manifest at ${path}`);
|
|
9032
|
+
}
|
|
9033
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
9034
|
+
throw new Error(`Invalid Primitive gameplan manifest at ${path}`);
|
|
9035
|
+
}
|
|
9036
|
+
const record3 = value;
|
|
9037
|
+
if (record3.owner !== MANIFEST_OWNER || typeof record3.packageVersion !== "string" || typeof record3.agentsBlockHash !== "string" || typeof record3.createdAgents !== "boolean" || !["", "\n", "\n\n"].includes(record3.agentsSeparator ?? "invalid") || typeof record3.files !== "object" || record3.files === null || ASSET_FILES.some((file) => typeof record3.files?.[file] !== "string") || record3.previousFiles !== void 0 && ASSET_FILES.some((file) => typeof record3.previousFiles?.[file] !== "string") || record3.previousAgentsBlockHash !== void 0 && typeof record3.previousAgentsBlockHash !== "string") {
|
|
9038
|
+
throw new Error(`Unknown or incomplete Primitive gameplan manifest at ${path}`);
|
|
9039
|
+
}
|
|
9040
|
+
return record3;
|
|
9041
|
+
}
|
|
9042
|
+
function managedBlock(content) {
|
|
9043
|
+
const begin = content.indexOf(START);
|
|
9044
|
+
const end = content.indexOf(END);
|
|
9045
|
+
if (begin === -1 && end === -1) return null;
|
|
9046
|
+
if (begin === -1 || end < begin || content.indexOf(START, begin + START.length) !== -1 || content.indexOf(END, end + END.length) !== -1) {
|
|
9047
|
+
throw new Error("AGENTS.md has malformed Primitive gameplan markers");
|
|
9048
|
+
}
|
|
9049
|
+
return content.slice(begin, end + END.length);
|
|
9050
|
+
}
|
|
9051
|
+
function blockSeparator(content) {
|
|
9052
|
+
if (content.length === 0 || content.endsWith("\n\n")) return "";
|
|
9053
|
+
return content.endsWith("\n") ? "\n" : "\n\n";
|
|
9054
|
+
}
|
|
9055
|
+
function upsertBlock(content) {
|
|
9056
|
+
const current = managedBlock(content);
|
|
9057
|
+
if (current !== null) return content.replace(current, AGENTS_BLOCK);
|
|
9058
|
+
return `${content}${blockSeparator(content)}${AGENTS_BLOCK}
|
|
9059
|
+
`;
|
|
9060
|
+
}
|
|
9061
|
+
function removeBlock(content, separator) {
|
|
9062
|
+
const block = managedBlock(content);
|
|
9063
|
+
if (block === null) return content;
|
|
9064
|
+
const start = content.indexOf(block);
|
|
9065
|
+
let before = content.slice(0, start);
|
|
9066
|
+
if (separator.length > 0 && before.endsWith(separator)) {
|
|
9067
|
+
before = before.slice(0, -separator.length);
|
|
9068
|
+
}
|
|
9069
|
+
const after = content.slice(start + block.length);
|
|
9070
|
+
return `${before}${after.replace(/^\n/u, "")}`;
|
|
9071
|
+
}
|
|
9072
|
+
function publicSkillPath(paths) {
|
|
9073
|
+
const codexHome = dirname3(paths.userHooks);
|
|
9074
|
+
const candidates = [
|
|
9075
|
+
join9(paths.root, ".agents", "skills", "write-gameplan", "SKILL.md"),
|
|
9076
|
+
join9(codexHome, "skills", "write-gameplan", "SKILL.md"),
|
|
9077
|
+
join9(homedir6(), ".agents", "skills", "write-gameplan", "SKILL.md")
|
|
9078
|
+
];
|
|
9079
|
+
for (const path of candidates) {
|
|
9080
|
+
try {
|
|
9081
|
+
const content = readFileSync7(path, "utf8");
|
|
9082
|
+
if (/^name:\s*write-gameplan\s*$/mu.test(content)) return path;
|
|
9083
|
+
} catch {
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
return null;
|
|
9087
|
+
}
|
|
9088
|
+
function assetContents() {
|
|
9089
|
+
const root = packageRoot2();
|
|
9090
|
+
return Object.fromEntries(
|
|
9091
|
+
ASSET_FILES.map((file) => [file, readFileSync7(join9(root, "assets", SKILL_NAME, file), "utf8")])
|
|
9092
|
+
);
|
|
9093
|
+
}
|
|
9094
|
+
function markedHookCommands(settings) {
|
|
9095
|
+
const entries = settings.hooks?.UserPromptSubmit ?? [];
|
|
9096
|
+
if (!Array.isArray(entries)) throw new Error("Codex UserPromptSubmit hooks are not an array");
|
|
9097
|
+
return entries.flatMap(
|
|
9098
|
+
(entry) => (entry.hooks ?? []).flatMap(
|
|
9099
|
+
(hook) => typeof hook.command === "string" && hook.command.includes(HOOK_MARKER) ? [hook.command] : []
|
|
9100
|
+
)
|
|
9101
|
+
);
|
|
9102
|
+
}
|
|
9103
|
+
function ensureUserHook(settings) {
|
|
9104
|
+
const marked = markedHookCommands(settings);
|
|
9105
|
+
if (marked.some((command) => command !== HOOK_COMMAND)) {
|
|
9106
|
+
throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
|
|
9107
|
+
}
|
|
9108
|
+
if (marked.length > 1) throw new Error("Duplicate Primitive gameplan Codex hooks are present");
|
|
9109
|
+
if (marked.length === 1) return settings;
|
|
9110
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
9111
|
+
hooks.UserPromptSubmit = [
|
|
9112
|
+
...hooks.UserPromptSubmit ?? [],
|
|
9113
|
+
{ hooks: [{ type: "command", command: HOOK_COMMAND }] }
|
|
9114
|
+
];
|
|
9115
|
+
return { ...settings, hooks };
|
|
9116
|
+
}
|
|
9117
|
+
function removeUserHook(settings) {
|
|
9118
|
+
const marked = markedHookCommands(settings);
|
|
9119
|
+
if (marked.some((command) => command !== HOOK_COMMAND)) {
|
|
9120
|
+
throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
|
|
9121
|
+
}
|
|
9122
|
+
if (marked.length === 0) return settings;
|
|
9123
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
9124
|
+
hooks.UserPromptSubmit = (hooks.UserPromptSubmit ?? []).flatMap((entry) => {
|
|
9125
|
+
const commands = (entry.hooks ?? []).filter((hook) => hook.command !== HOOK_COMMAND);
|
|
9126
|
+
return commands.length > 0 ? [{ ...entry, hooks: commands }] : [];
|
|
9127
|
+
});
|
|
9128
|
+
if (hooks.UserPromptSubmit.length === 0) hooks.UserPromptSubmit = void 0;
|
|
9129
|
+
return { ...settings, hooks };
|
|
9130
|
+
}
|
|
9131
|
+
function checkOwnedFiles(paths, manifest) {
|
|
9132
|
+
if (existsSync8(paths.skillDir) && !lstatSync6(paths.skillDir).isDirectory()) {
|
|
9133
|
+
throw new Error(`Refusing non-directory companion path at ${paths.skillDir}`);
|
|
9134
|
+
}
|
|
9135
|
+
if (manifest === null && existsSync8(paths.skillDir) && readdirSync4(paths.skillDir).length > 0) {
|
|
9136
|
+
throw new Error(`Refusing unowned companion files at ${paths.skillDir}`);
|
|
9137
|
+
}
|
|
9138
|
+
if (manifest === null) return;
|
|
9139
|
+
for (const file of ASSET_FILES) {
|
|
9140
|
+
const path = join9(paths.skillDir, file);
|
|
9141
|
+
const current = readRegularFile(path);
|
|
9142
|
+
if (current !== null && sha256(current) !== manifest.files[file] && sha256(current) !== manifest.previousFiles?.[file]) {
|
|
9143
|
+
throw new Error(`Refusing modified companion file at ${path}`);
|
|
9144
|
+
}
|
|
9145
|
+
}
|
|
9146
|
+
}
|
|
9147
|
+
function checkAgentsBlock(paths, manifest) {
|
|
9148
|
+
const content = readRegularFile(paths.agents) ?? "";
|
|
9149
|
+
const block = managedBlock(content);
|
|
9150
|
+
if (block !== null && (manifest === null || sha256(block) !== manifest.agentsBlockHash && sha256(block) !== manifest.previousAgentsBlockHash)) {
|
|
9151
|
+
throw new Error(`Refusing modified or unowned Primitive gameplan block in ${paths.agents}`);
|
|
9152
|
+
}
|
|
9153
|
+
return { content, created: manifest?.createdAgents ?? !existsSync8(paths.agents) };
|
|
9154
|
+
}
|
|
9155
|
+
function install(cwd) {
|
|
9156
|
+
const paths = pathsFor(cwd);
|
|
9157
|
+
const publicSkill = publicSkillPath(paths);
|
|
9158
|
+
if (publicSkill === null) {
|
|
9159
|
+
throw new Error(
|
|
9160
|
+
"Codex cannot find $write-gameplan. Install the public skill in .agents/skills/write-gameplan or ~/.codex/skills/write-gameplan, then retry."
|
|
9161
|
+
);
|
|
9162
|
+
}
|
|
9163
|
+
if ((readRegularFile(paths.agentsOverride) ?? "").trim().length > 0) {
|
|
9164
|
+
throw new Error(
|
|
9165
|
+
"AGENTS.override.md shadows AGENTS.md in this repository; remove the override or install the companion manually in the effective rules."
|
|
9166
|
+
);
|
|
9167
|
+
}
|
|
9168
|
+
const assets = assetContents();
|
|
9169
|
+
const manifest = readManifest(paths.manifest);
|
|
9170
|
+
checkOwnedFiles(paths, manifest);
|
|
9171
|
+
const agents = checkAgentsBlock(paths, manifest);
|
|
9172
|
+
const hooksBefore = readSettings(paths.userHooks);
|
|
9173
|
+
const hooksAfter = ensureUserHook(hooksBefore);
|
|
9174
|
+
const nextManifest = {
|
|
9175
|
+
owner: MANIFEST_OWNER,
|
|
9176
|
+
packageVersion: packageVersion2(packageRoot2()),
|
|
9177
|
+
files: Object.fromEntries(ASSET_FILES.map((file) => [file, sha256(assets[file])])),
|
|
9178
|
+
...manifest === null ? {} : { previousFiles: manifest.files },
|
|
9179
|
+
agentsBlockHash: sha256(AGENTS_BLOCK),
|
|
9180
|
+
...manifest === null ? {} : { previousAgentsBlockHash: manifest.agentsBlockHash },
|
|
9181
|
+
createdAgents: agents.created,
|
|
9182
|
+
agentsSeparator: manifest?.agentsSeparator ?? blockSeparator(agents.content)
|
|
9183
|
+
};
|
|
9184
|
+
atomicWriteFile(paths.manifest, `${JSON.stringify(nextManifest, null, 2)}
|
|
9185
|
+
`, {
|
|
9186
|
+
ensureParent: true
|
|
9187
|
+
});
|
|
9188
|
+
for (const file of ASSET_FILES) {
|
|
9189
|
+
const path = join9(paths.skillDir, file);
|
|
9190
|
+
if (readRegularFile(path) !== assets[file]) {
|
|
9191
|
+
atomicWriteFile(path, assets[file], { ensureParent: true });
|
|
9192
|
+
}
|
|
9193
|
+
}
|
|
9194
|
+
const agentsAfter = upsertBlock(agents.content);
|
|
9195
|
+
if (agentsAfter !== agents.content) {
|
|
9196
|
+
atomicWriteFile(paths.agents, agentsAfter, { ensureParent: true });
|
|
9197
|
+
}
|
|
9198
|
+
if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore)) {
|
|
9199
|
+
atomicWrite(paths.userHooks, hooksAfter);
|
|
9200
|
+
}
|
|
9201
|
+
return { installed: true, root: paths.root, publicSkill, userHooks: paths.userHooks };
|
|
9202
|
+
}
|
|
9203
|
+
function status(cwd) {
|
|
9204
|
+
const paths = pathsFor(cwd);
|
|
9205
|
+
const manifest = readManifest(paths.manifest);
|
|
9206
|
+
const publicSkill = publicSkillPath(paths);
|
|
9207
|
+
const files = Object.fromEntries(
|
|
9208
|
+
ASSET_FILES.map((file) => {
|
|
9209
|
+
const current = readRegularFile(join9(paths.skillDir, file));
|
|
9210
|
+
return [
|
|
9211
|
+
file,
|
|
9212
|
+
current !== null && manifest !== null && sha256(current) === manifest.files[file]
|
|
9213
|
+
];
|
|
9214
|
+
})
|
|
9215
|
+
);
|
|
9216
|
+
const agents = readRegularFile(paths.agents) ?? "";
|
|
9217
|
+
const block = managedBlock(agents);
|
|
9218
|
+
const agentsBinding = block !== null && manifest !== null && sha256(block) === manifest.agentsBlockHash;
|
|
9219
|
+
const agentsOverrideShadows = (readRegularFile(paths.agentsOverride) ?? "").trim().length > 0;
|
|
9220
|
+
const hooks = markedHookCommands(readSettings(paths.userHooks));
|
|
9221
|
+
const userHook = hooks.length === 1 && hooks[0] === HOOK_COMMAND;
|
|
9222
|
+
const installed = manifest !== null && Object.values(files).every(Boolean) && agentsBinding && !agentsOverrideShadows && userHook && publicSkill !== null;
|
|
9223
|
+
return {
|
|
9224
|
+
installed,
|
|
9225
|
+
root: paths.root,
|
|
9226
|
+
packageVersion: manifest?.packageVersion ?? null,
|
|
9227
|
+
files,
|
|
9228
|
+
agentsBinding,
|
|
9229
|
+
agentsOverrideShadows,
|
|
9230
|
+
userHook,
|
|
9231
|
+
publicSkill,
|
|
9232
|
+
userHooks: paths.userHooks
|
|
9233
|
+
};
|
|
9234
|
+
}
|
|
9235
|
+
function uninstall(cwd, removeSharedHook) {
|
|
9236
|
+
const paths = pathsFor(cwd);
|
|
9237
|
+
const manifest = readManifest(paths.manifest);
|
|
9238
|
+
if (manifest === null)
|
|
9239
|
+
return { uninstalled: false, reason: "No managed companion in this repository" };
|
|
9240
|
+
checkOwnedFiles(paths, manifest);
|
|
9241
|
+
const expected = /* @__PURE__ */ new Set(["SKILL.md", "claude-hooks.json", "scripts", MANIFEST_NAME]);
|
|
9242
|
+
const extras = readdirSync4(paths.skillDir).filter((entry) => !expected.has(entry));
|
|
9243
|
+
const scriptsPath = join9(paths.skillDir, "scripts");
|
|
9244
|
+
if (existsSync8(scriptsPath)) {
|
|
9245
|
+
extras.push(...readdirSync4(scriptsPath).filter((entry) => entry !== "activate.mjs"));
|
|
9246
|
+
}
|
|
9247
|
+
if (extras.length > 0) {
|
|
9248
|
+
throw new Error(`Refusing to remove unowned companion files: ${extras.join(", ")}`);
|
|
9249
|
+
}
|
|
9250
|
+
const agents = checkAgentsBlock(paths, manifest);
|
|
9251
|
+
const hooksBefore = readSettings(paths.userHooks);
|
|
9252
|
+
const hooksAfter = removeSharedHook ? removeUserHook(hooksBefore) : hooksBefore;
|
|
9253
|
+
const agentsAfter = removeBlock(agents.content, manifest.agentsSeparator);
|
|
9254
|
+
if (agentsAfter !== agents.content) {
|
|
9255
|
+
if (manifest.createdAgents && agentsAfter.trim().length === 0) {
|
|
9256
|
+
unlinkSync4(paths.agents);
|
|
9257
|
+
} else {
|
|
9258
|
+
atomicWriteFile(paths.agents, agentsAfter);
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9261
|
+
for (const file of ASSET_FILES) {
|
|
9262
|
+
const path = join9(paths.skillDir, file);
|
|
9263
|
+
if (existsSync8(path)) unlinkSync4(path);
|
|
9264
|
+
}
|
|
9265
|
+
unlinkSync4(paths.manifest);
|
|
9266
|
+
if (existsSync8(scriptsPath)) rmdirSync2(scriptsPath);
|
|
9267
|
+
rmdirSync2(paths.skillDir);
|
|
9268
|
+
if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore))
|
|
9269
|
+
atomicWrite(paths.userHooks, hooksAfter);
|
|
9270
|
+
return { uninstalled: true, root: paths.root, sharedUserHookRetained: !removeSharedHook };
|
|
9271
|
+
}
|
|
9272
|
+
function requireCodex(agent) {
|
|
9273
|
+
if (agent !== "codex") throw new Error(`Unsupported gameplan agent "${agent}" (expected codex)`);
|
|
9274
|
+
}
|
|
9275
|
+
function reportCommandError(error) {
|
|
9276
|
+
console.error(`[prim] ${error instanceof Error ? error.message : String(error)}`);
|
|
9277
|
+
process.exitCode = 1;
|
|
9278
|
+
}
|
|
9279
|
+
function registerGameplanCommands(program2) {
|
|
9280
|
+
const gameplan = program2.command("gameplan").description("Manage the Primitive Codex gameplanning companion");
|
|
9281
|
+
gameplan.command("install").description("Install the companion in this repo and its dispatcher in user Codex hooks").option("--agent <agent>", "agent host", "codex").action((opts) => {
|
|
9282
|
+
try {
|
|
9283
|
+
requireCodex(opts.agent);
|
|
9284
|
+
const result = install(process.cwd());
|
|
9285
|
+
console.error(
|
|
9286
|
+
"[prim] Gameplan companion installed. Review Codex /hooks and start a fresh session."
|
|
9287
|
+
);
|
|
9288
|
+
console.log(JSON.stringify(result));
|
|
9289
|
+
} catch (error) {
|
|
9290
|
+
reportCommandError(error);
|
|
9291
|
+
}
|
|
9292
|
+
});
|
|
9293
|
+
gameplan.command("status").description("Check the companion, public skill, AGENTS binding, and user prompt hook").option("--agent <agent>", "agent host", "codex").action((opts) => {
|
|
9294
|
+
try {
|
|
9295
|
+
requireCodex(opts.agent);
|
|
9296
|
+
const result = status(process.cwd());
|
|
9297
|
+
console.error(
|
|
9298
|
+
result.installed && result.publicSkill !== null ? "[prim] Gameplan companion is configured; actual hook execution is not verified." : "[prim] Gameplan companion is incomplete; inspect the JSON status and run prim gameplan install."
|
|
9299
|
+
);
|
|
9300
|
+
console.log(JSON.stringify(result));
|
|
9301
|
+
if (!result.installed || result.publicSkill === null) process.exitCode = 1;
|
|
9302
|
+
} catch (error) {
|
|
9303
|
+
reportCommandError(error);
|
|
9304
|
+
}
|
|
9305
|
+
});
|
|
9306
|
+
gameplan.command("uninstall").description("Remove this repo's companion; keep the shared user hook unless requested").option("--agent <agent>", "agent host", "codex").option("--remove-user-hook", "Also remove the hook shared with other repositories").action((opts) => {
|
|
9307
|
+
try {
|
|
9308
|
+
requireCodex(opts.agent);
|
|
9309
|
+
const result = uninstall(process.cwd(), opts.removeUserHook ?? false);
|
|
9310
|
+
console.error("[prim] Removed this repository's managed gameplan companion.");
|
|
9311
|
+
console.log(JSON.stringify(result));
|
|
9312
|
+
} catch (error) {
|
|
9313
|
+
reportCommandError(error);
|
|
9314
|
+
}
|
|
9315
|
+
});
|
|
9316
|
+
}
|
|
9317
|
+
|
|
8912
9318
|
// src/commands/moves.ts
|
|
8913
|
-
import { existsSync as
|
|
8914
|
-
import { join as
|
|
9319
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync5, unlinkSync as unlinkSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
9320
|
+
import { join as join12 } from "path";
|
|
8915
9321
|
|
|
8916
9322
|
// src/flusher.ts
|
|
8917
|
-
import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as
|
|
8918
|
-
import { dirname as
|
|
9323
|
+
import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as unlinkSync5 } from "fs";
|
|
9324
|
+
import { dirname as dirname5, join as join11 } from "path";
|
|
8919
9325
|
|
|
8920
9326
|
// src/dead-letter.ts
|
|
8921
|
-
import { createHash as
|
|
9327
|
+
import { createHash as createHash5, randomBytes as randomBytes4 } from "crypto";
|
|
8922
9328
|
import {
|
|
8923
9329
|
constants as constants3,
|
|
8924
9330
|
chmodSync as chmodSync2,
|
|
8925
9331
|
closeSync as closeSync3,
|
|
8926
|
-
existsSync as
|
|
9332
|
+
existsSync as existsSync9,
|
|
8927
9333
|
fchmodSync,
|
|
8928
9334
|
fsyncSync,
|
|
8929
9335
|
mkdirSync as mkdirSync4,
|
|
@@ -8932,30 +9338,30 @@ import {
|
|
|
8932
9338
|
rmSync as rmSync3,
|
|
8933
9339
|
writeFileSync as writeFileSync3
|
|
8934
9340
|
} from "fs";
|
|
8935
|
-
import { dirname as
|
|
9341
|
+
import { dirname as dirname4, join as join10 } from "path";
|
|
8936
9342
|
var DIRECTORY_MODE = 448;
|
|
8937
9343
|
var FILE_MODE = 384;
|
|
8938
9344
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
8939
9345
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
8940
|
-
return
|
|
9346
|
+
return join10(dirname4(flushingPath), DEAD_LETTER_DIRNAME);
|
|
8941
9347
|
}
|
|
8942
9348
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
8943
|
-
const quarantineId =
|
|
8944
|
-
return
|
|
9349
|
+
const quarantineId = createHash5("sha256").update(rawLine).digest("hex");
|
|
9350
|
+
return join10(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
8945
9351
|
}
|
|
8946
9352
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
8947
9353
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
8948
9354
|
mkdirSync4(directory, { recursive: true, mode: DIRECTORY_MODE });
|
|
8949
9355
|
chmodSync2(directory, DIRECTORY_MODE);
|
|
8950
|
-
persistDirectory(
|
|
9356
|
+
persistDirectory(dirname4(directory));
|
|
8951
9357
|
return directory;
|
|
8952
9358
|
}
|
|
8953
9359
|
function persistDeadLetter(directory, path, quarantineId, record3, persistDirectory) {
|
|
8954
|
-
if (
|
|
9360
|
+
if (existsSync9(path)) {
|
|
8955
9361
|
persistDirectory(directory);
|
|
8956
9362
|
return;
|
|
8957
9363
|
}
|
|
8958
|
-
const temporaryPath =
|
|
9364
|
+
const temporaryPath = join10(
|
|
8959
9365
|
directory,
|
|
8960
9366
|
`.${quarantineId}.${String(process.pid)}.${randomBytes4(8).toString("hex")}.tmp`
|
|
8961
9367
|
);
|
|
@@ -8982,12 +9388,12 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
8982
9388
|
const serializedMove = JSON.stringify(move);
|
|
8983
9389
|
const record3 = {
|
|
8984
9390
|
version: 1,
|
|
8985
|
-
quarantineId:
|
|
9391
|
+
quarantineId: createHash5("sha256").update(serializedMove).digest("hex"),
|
|
8986
9392
|
quarantinedAt: now(),
|
|
8987
9393
|
reason,
|
|
8988
9394
|
move
|
|
8989
9395
|
};
|
|
8990
|
-
const path =
|
|
9396
|
+
const path = join10(directory, `${record3.quarantineId}.json`);
|
|
8991
9397
|
persistDeadLetter(directory, path, record3.quarantineId, record3, persistDirectory);
|
|
8992
9398
|
return record3;
|
|
8993
9399
|
}
|
|
@@ -8998,7 +9404,7 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
|
|
|
8998
9404
|
const record3 = {
|
|
8999
9405
|
version: 1,
|
|
9000
9406
|
recordKind: "raw_line_v1",
|
|
9001
|
-
quarantineId:
|
|
9407
|
+
quarantineId: createHash5("sha256").update(bytes).digest("hex"),
|
|
9002
9408
|
quarantinedAt: now(),
|
|
9003
9409
|
reason: "invalid_move",
|
|
9004
9410
|
rawLineEncoding: "base64",
|
|
@@ -9238,7 +9644,7 @@ async function drainFlushingPath(flushingPath, client, binding, options = {}) {
|
|
|
9238
9644
|
} finally {
|
|
9239
9645
|
input.destroy();
|
|
9240
9646
|
}
|
|
9241
|
-
|
|
9647
|
+
unlinkSync5(flushingPath);
|
|
9242
9648
|
try {
|
|
9243
9649
|
removeDrainCheckpoint(flushingPath);
|
|
9244
9650
|
} catch {
|
|
@@ -9382,7 +9788,7 @@ async function flushOnce() {
|
|
|
9382
9788
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
9383
9789
|
}
|
|
9384
9790
|
var flushInFlight;
|
|
9385
|
-
var FLUSH_LOCK_PATH =
|
|
9791
|
+
var FLUSH_LOCK_PATH = join11(dirname5(JOURNAL_DIR), ".flush.lock");
|
|
9386
9792
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
9387
9793
|
function isFlushLockContended(error) {
|
|
9388
9794
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -9514,23 +9920,23 @@ function registerMovesCommands(program2) {
|
|
|
9514
9920
|
}
|
|
9515
9921
|
});
|
|
9516
9922
|
moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
|
|
9517
|
-
const dir =
|
|
9518
|
-
if (!
|
|
9923
|
+
const dir = join12(process.cwd(), ".prim");
|
|
9924
|
+
if (!existsSync10(dir)) {
|
|
9519
9925
|
mkdirSync5(dir, { recursive: true, mode: DIR_MODE });
|
|
9520
9926
|
}
|
|
9521
|
-
const file =
|
|
9927
|
+
const file = join12(process.cwd(), WORKSPACE_FILE);
|
|
9522
9928
|
writeFileSync4(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
|
|
9523
9929
|
mode: FILE_MODE2
|
|
9524
9930
|
});
|
|
9525
9931
|
console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
|
|
9526
9932
|
});
|
|
9527
9933
|
moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
|
|
9528
|
-
const file =
|
|
9529
|
-
if (!
|
|
9934
|
+
const file = join12(process.cwd(), WORKSPACE_FILE);
|
|
9935
|
+
if (!existsSync10(file)) {
|
|
9530
9936
|
console.log("[prim] no workspace binding in cwd");
|
|
9531
9937
|
return;
|
|
9532
9938
|
}
|
|
9533
|
-
|
|
9939
|
+
unlinkSync6(file);
|
|
9534
9940
|
console.log(`[prim] dropped workspace binding from ${process.cwd()}`);
|
|
9535
9941
|
});
|
|
9536
9942
|
}
|
|
@@ -9586,10 +9992,10 @@ async function performResolution(idOrShortId, opts) {
|
|
|
9586
9992
|
process.stderr.write(`[prim] recorded ${opts.outcome} for check ${opts.check}
|
|
9587
9993
|
`);
|
|
9588
9994
|
} catch (error) {
|
|
9589
|
-
const
|
|
9590
|
-
process.stderr.write(`[prim] resolution failed${
|
|
9995
|
+
const status2 = error instanceof HttpError ? error.status : void 0;
|
|
9996
|
+
process.stderr.write(`[prim] resolution failed${status2 ? ` (${status2})` : ""}
|
|
9591
9997
|
`);
|
|
9592
|
-
console.log(JSON.stringify({ ok: false, status }));
|
|
9998
|
+
console.log(JSON.stringify({ ok: false, status: status2 }));
|
|
9593
9999
|
process.exitCode = isDomainRejection(error) ? EXIT_USAGE2 : EXIT_SERVER;
|
|
9594
10000
|
}
|
|
9595
10001
|
}
|
|
@@ -9604,23 +10010,23 @@ function registerReconcileCommands(program2) {
|
|
|
9604
10010
|
|
|
9605
10011
|
// src/commands/session.ts
|
|
9606
10012
|
import {
|
|
9607
|
-
existsSync as
|
|
10013
|
+
existsSync as existsSync11,
|
|
9608
10014
|
mkdirSync as mkdirSync6,
|
|
9609
|
-
readFileSync as
|
|
9610
|
-
readdirSync as
|
|
9611
|
-
unlinkSync as
|
|
10015
|
+
readFileSync as readFileSync8,
|
|
10016
|
+
readdirSync as readdirSync5,
|
|
10017
|
+
unlinkSync as unlinkSync7,
|
|
9612
10018
|
writeFileSync as writeFileSync5
|
|
9613
10019
|
} from "fs";
|
|
9614
|
-
import { join as
|
|
10020
|
+
import { join as join13 } from "path";
|
|
9615
10021
|
var DIR_MODE2 = 448;
|
|
9616
10022
|
var FILE_MODE3 = 384;
|
|
9617
10023
|
function ensureDir() {
|
|
9618
|
-
if (!
|
|
10024
|
+
if (!existsSync11(SESSIONS_DIR)) {
|
|
9619
10025
|
mkdirSync6(SESSIONS_DIR, { recursive: true, mode: DIR_MODE2 });
|
|
9620
10026
|
}
|
|
9621
10027
|
}
|
|
9622
10028
|
function markerPath(sessionId) {
|
|
9623
|
-
return
|
|
10029
|
+
return join13(SESSIONS_DIR, `${sessionId}.json`);
|
|
9624
10030
|
}
|
|
9625
10031
|
function registerSessionCommands(program2) {
|
|
9626
10032
|
const session = program2.command("session").description("Decision Event Pipeline \u2014 session binding markers");
|
|
@@ -9636,11 +10042,11 @@ function registerSessionCommands(program2) {
|
|
|
9636
10042
|
console.log(`[prim] session ${sessionId} bound to org ${opts.orgId}`);
|
|
9637
10043
|
});
|
|
9638
10044
|
session.command("list").description("List active session markers").action(() => {
|
|
9639
|
-
if (!
|
|
10045
|
+
if (!existsSync11(SESSIONS_DIR)) {
|
|
9640
10046
|
console.log("[prim] no session markers");
|
|
9641
10047
|
return;
|
|
9642
10048
|
}
|
|
9643
|
-
const files =
|
|
10049
|
+
const files = readdirSync5(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
|
|
9644
10050
|
if (files.length === 0) {
|
|
9645
10051
|
console.log("[prim] no session markers");
|
|
9646
10052
|
return;
|
|
@@ -9648,7 +10054,7 @@ function registerSessionCommands(program2) {
|
|
|
9648
10054
|
for (const f of files) {
|
|
9649
10055
|
const sessionId = f.replace(/\.json$/, "");
|
|
9650
10056
|
try {
|
|
9651
|
-
const m = JSON.parse(
|
|
10057
|
+
const m = JSON.parse(readFileSync8(join13(SESSIONS_DIR, f), "utf-8"));
|
|
9652
10058
|
console.log(`${sessionId} org=${m.orgId}`);
|
|
9653
10059
|
} catch {
|
|
9654
10060
|
}
|
|
@@ -9656,19 +10062,19 @@ function registerSessionCommands(program2) {
|
|
|
9656
10062
|
});
|
|
9657
10063
|
session.command("drop <sessionId>").description("Remove a session marker").action((sessionId) => {
|
|
9658
10064
|
const p = markerPath(sessionId);
|
|
9659
|
-
if (!
|
|
10065
|
+
if (!existsSync11(p)) {
|
|
9660
10066
|
console.log(`[prim] no marker for session ${sessionId}`);
|
|
9661
10067
|
return;
|
|
9662
10068
|
}
|
|
9663
|
-
|
|
10069
|
+
unlinkSync7(p);
|
|
9664
10070
|
console.log(`[prim] dropped session marker ${sessionId}`);
|
|
9665
10071
|
});
|
|
9666
10072
|
}
|
|
9667
10073
|
|
|
9668
10074
|
// src/commands/setup.ts
|
|
9669
10075
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
9670
|
-
import { existsSync as
|
|
9671
|
-
import { join as
|
|
10076
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
|
|
10077
|
+
import { join as join14 } from "path";
|
|
9672
10078
|
var EXIT_INCOMPLETE = 1;
|
|
9673
10079
|
var EXIT_USAGE3 = 2;
|
|
9674
10080
|
var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
|
|
@@ -9806,8 +10212,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
|
9806
10212
|
let preCommit;
|
|
9807
10213
|
try {
|
|
9808
10214
|
const root = gitToplevel();
|
|
9809
|
-
const path = root &&
|
|
9810
|
-
if (path &&
|
|
10215
|
+
const path = root && join14(root, ".git", "hooks", "pre-commit");
|
|
10216
|
+
if (path && existsSync12(path)) preCommit = readFileSync9(path, "utf-8");
|
|
9811
10217
|
} catch {
|
|
9812
10218
|
}
|
|
9813
10219
|
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
@@ -10068,23 +10474,23 @@ function setupChildPayload(stdout) {
|
|
|
10068
10474
|
}
|
|
10069
10475
|
|
|
10070
10476
|
// src/commands/statusline.ts
|
|
10071
|
-
import { readFileSync as
|
|
10072
|
-
import { dirname as
|
|
10073
|
-
import { fileURLToPath } from "url";
|
|
10477
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
10478
|
+
import { dirname as dirname6, resolve as resolve5 } from "path";
|
|
10479
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10074
10480
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
10075
10481
|
function readPackageVersion() {
|
|
10076
10482
|
try {
|
|
10077
|
-
const here =
|
|
10483
|
+
const here = dirname6(fileURLToPath2(import.meta.url));
|
|
10078
10484
|
const candidates = [
|
|
10079
10485
|
// Schema-v2 runtimes staged a manifest beside this standalone bundle.
|
|
10080
10486
|
// Keep resolving it while those legacy launchers transition to schema v3.
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10487
|
+
resolve5(here, "manifest.json"),
|
|
10488
|
+
resolve5(here, "../../package.json"),
|
|
10489
|
+
resolve5(here, "../package.json")
|
|
10084
10490
|
];
|
|
10085
10491
|
for (const path of candidates) {
|
|
10086
10492
|
try {
|
|
10087
|
-
const pkg2 = JSON.parse(
|
|
10493
|
+
const pkg2 = JSON.parse(readFileSync10(path, "utf-8"));
|
|
10088
10494
|
if (pkg2.version) {
|
|
10089
10495
|
return pkg2.version;
|
|
10090
10496
|
}
|
|
@@ -10609,13 +11015,13 @@ function healDaemonDrift(options = {}) {
|
|
|
10609
11015
|
|
|
10610
11016
|
// src/lib/background-flush.ts
|
|
10611
11017
|
import { spawn as spawn3 } from "child_process";
|
|
10612
|
-
import { readFileSync as
|
|
11018
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
10613
11019
|
|
|
10614
11020
|
// src/daemon/health.ts
|
|
10615
|
-
import { chmodSync as chmodSync3, existsSync as
|
|
10616
|
-
import { dirname as
|
|
11021
|
+
import { chmodSync as chmodSync3, existsSync as existsSync13, mkdirSync as mkdirSync7, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
11022
|
+
import { dirname as dirname7, join as join15 } from "path";
|
|
10617
11023
|
var HEARTBEAT_FRESH_MS = 9e4;
|
|
10618
|
-
var DAEMON_HEALTH_PATH =
|
|
11024
|
+
var DAEMON_HEALTH_PATH = join15(primConfigDirectory(), "daemon-health.json");
|
|
10619
11025
|
|
|
10620
11026
|
// src/lib/background-flush.ts
|
|
10621
11027
|
function record2(value) {
|
|
@@ -10626,7 +11032,7 @@ function daemonOwnsDrain(options = {}) {
|
|
|
10626
11032
|
const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
|
|
10627
11033
|
if (!expectedVersion) return false;
|
|
10628
11034
|
const health = record2(
|
|
10629
|
-
JSON.parse(
|
|
11035
|
+
JSON.parse(readFileSync11(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
|
|
10630
11036
|
);
|
|
10631
11037
|
const heartbeat = record2(health?.heartbeat);
|
|
10632
11038
|
const ingestion = record2(health?.ingestion);
|
|
@@ -10733,8 +11139,8 @@ function mayHealDaemon(argv, env) {
|
|
|
10733
11139
|
function runStartupBackgroundWork(argv, env, work) {
|
|
10734
11140
|
const args = commandArguments(argv);
|
|
10735
11141
|
const [command, subcommand] = args;
|
|
10736
|
-
const
|
|
10737
|
-
if (
|
|
11142
|
+
const uninstall2 = command === "uninstall" || env[UNINSTALL_ORCHESTRATOR_ENV] === "1";
|
|
11143
|
+
if (uninstall2 || command === "demo") return;
|
|
10738
11144
|
work.notify();
|
|
10739
11145
|
const setupDaemonDrains = command === "setup" && !args.includes("--no-daemon") || env[SETUP_DAEMON_DRAINS_ENV] === "1";
|
|
10740
11146
|
if (!setupDaemonDrains && (command !== "moves" || subcommand !== "flush")) work.flush();
|
|
@@ -10742,8 +11148,8 @@ function runStartupBackgroundWork(argv, env, work) {
|
|
|
10742
11148
|
}
|
|
10743
11149
|
|
|
10744
11150
|
// src/index.ts
|
|
10745
|
-
var
|
|
10746
|
-
var pkg = JSON.parse(
|
|
11151
|
+
var __dirname2 = dirname8(fileURLToPath3(import.meta.url));
|
|
11152
|
+
var pkg = JSON.parse(readFileSync12(resolve6(__dirname2, "../package.json"), "utf-8"));
|
|
10747
11153
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
10748
11154
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
10749
11155
|
flush: () => startBackgroundFlush(),
|
|
@@ -10758,6 +11164,7 @@ registerAuthCommands(program);
|
|
|
10758
11164
|
registerHooksCommands(program);
|
|
10759
11165
|
registerActivationCommands(program);
|
|
10760
11166
|
registerSkillCommands(program);
|
|
11167
|
+
registerGameplanCommands(program);
|
|
10761
11168
|
registerMovesCommands(program);
|
|
10762
11169
|
registerSessionCommands(program);
|
|
10763
11170
|
registerDecisionsCommands(program);
|