@primitive.ai/prim 0.1.0-alpha.113 → 0.1.0-alpha.115
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 +34 -0
- 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-IW5HCCOW.js → chunk-IMYELJIV.js} +1 -1
- package/dist/{chunk-XV6C5ZV2.js → chunk-RUUSUF43.js} +245 -2
- package/dist/hook-runtime/hooks/post-tool-use.js +4866 -131
- package/dist/hook-runtime/hooks/pre-tool-use.js +4893 -142
- package/dist/hook-runtime/hooks/prim-hook.js +4867 -132
- package/dist/hook-runtime/index.js +621 -265
- package/dist/hooks/post-tool-use.js +2 -2
- package/dist/hooks/pre-tool-use.js +22 -6
- package/dist/hooks/prim-hook.js +2 -2
- package/dist/index.js +498 -142
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -192,9 +192,9 @@ import {
|
|
|
192
192
|
} from "./chunk-XG7S3LIL.js";
|
|
193
193
|
|
|
194
194
|
// src/index.ts
|
|
195
|
-
import { readFileSync as
|
|
196
|
-
import { dirname as
|
|
197
|
-
import { fileURLToPath as
|
|
195
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
196
|
+
import { dirname as dirname8, resolve as resolve6 } from "path";
|
|
197
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
198
198
|
import { Command } from "commander";
|
|
199
199
|
import updateNotifier from "update-notifier";
|
|
200
200
|
|
|
@@ -315,9 +315,9 @@ async function pollGitHubInstallIntent(client, start, options = {}) {
|
|
|
315
315
|
if (now() >= start.expiresAt) return expiredStatus(start);
|
|
316
316
|
throw error;
|
|
317
317
|
}
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
320
|
-
if (
|
|
318
|
+
const status2 = parseGitHubInstallIntentStatus(raw, start.expiresAt);
|
|
319
|
+
if (!status2) throw new Error("server returned an invalid GitHub install-intent status");
|
|
320
|
+
if (status2.status !== "pending" && status2.status !== "claimed") return status2;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
@@ -431,8 +431,8 @@ function parseRevokeResponse(value) {
|
|
|
431
431
|
const parsed = record(value);
|
|
432
432
|
return parsed !== void 0 && hasExactKeys(parsed, ["apiKeyId", "revoked"]) && isApiKeyId(parsed.apiKeyId) && parsed.revoked === true ? { apiKeyId: parsed.apiKeyId, revoked: true } : void 0;
|
|
433
433
|
}
|
|
434
|
-
function failure(code, exitCode,
|
|
435
|
-
return { code, exitCode, ...
|
|
434
|
+
function failure(code, exitCode, status2) {
|
|
435
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
436
436
|
}
|
|
437
437
|
function classifyHttpError(error, operation, dispatched) {
|
|
438
438
|
if (error.status === 401) {
|
|
@@ -892,12 +892,12 @@ function hasStoredRefreshToken() {
|
|
|
892
892
|
return false;
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
|
-
function authStatusResult(
|
|
895
|
+
function authStatusResult(status2, reason, source, refreshTokenPresent) {
|
|
896
896
|
const expiresAt = source === "token_file" ? getTokenExpiresAt() : void 0;
|
|
897
897
|
const expiresInMs = expiresAt === void 0 ? null : expiresAt - Date.now();
|
|
898
898
|
return {
|
|
899
|
-
authenticated:
|
|
900
|
-
status,
|
|
899
|
+
authenticated: status2 === "valid",
|
|
900
|
+
status: status2,
|
|
901
901
|
reason,
|
|
902
902
|
tokenFile: source === "token_file" ? TOKEN_FILE_PATH : null,
|
|
903
903
|
accessTokenExpiresInMs: expiresInMs,
|
|
@@ -967,9 +967,9 @@ async function verifyAuthStatus() {
|
|
|
967
967
|
);
|
|
968
968
|
}
|
|
969
969
|
}
|
|
970
|
-
function authStatusExitCode(
|
|
971
|
-
if (
|
|
972
|
-
return
|
|
970
|
+
function authStatusExitCode(status2) {
|
|
971
|
+
if (status2 === "valid") return EXIT_OK;
|
|
972
|
+
return status2 === "invalid" ? EXIT_FAIL : EXIT_UNREACHABLE;
|
|
973
973
|
}
|
|
974
974
|
function writeHumanAuthStatus(result) {
|
|
975
975
|
if (result.status === "invalid") {
|
|
@@ -1076,8 +1076,8 @@ ${verificationUrl}`);
|
|
|
1076
1076
|
const state = base64url(randomBytes2(16));
|
|
1077
1077
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
1078
1078
|
let settle;
|
|
1079
|
-
const outcome = new Promise((
|
|
1080
|
-
settle =
|
|
1079
|
+
const outcome = new Promise((resolve7) => {
|
|
1080
|
+
settle = resolve7;
|
|
1081
1081
|
});
|
|
1082
1082
|
const server = createServer((req, res) => {
|
|
1083
1083
|
const url = new URL(req.url ?? "/", `http://${LOCALHOST}`);
|
|
@@ -1091,12 +1091,12 @@ ${verificationUrl}`);
|
|
|
1091
1091
|
res.end(page.html, () => settle(page.result));
|
|
1092
1092
|
});
|
|
1093
1093
|
try {
|
|
1094
|
-
await new Promise((
|
|
1094
|
+
await new Promise((resolve7, reject) => {
|
|
1095
1095
|
const onError = (err) => reject(err);
|
|
1096
1096
|
server.once("error", onError);
|
|
1097
1097
|
server.listen(CALLBACK_PORT, LOCALHOST, () => {
|
|
1098
1098
|
server.removeListener("error", onError);
|
|
1099
|
-
|
|
1099
|
+
resolve7();
|
|
1100
1100
|
});
|
|
1101
1101
|
});
|
|
1102
1102
|
} catch (err) {
|
|
@@ -1289,16 +1289,16 @@ function reportBinding(binding, installAttempted = false) {
|
|
|
1289
1289
|
printJson(binding);
|
|
1290
1290
|
process.exitCode = EXIT_UNBOUND;
|
|
1291
1291
|
}
|
|
1292
|
-
function terminalInstallError(
|
|
1293
|
-
if (
|
|
1294
|
-
if (
|
|
1292
|
+
function terminalInstallError(status2) {
|
|
1293
|
+
if (status2.status === "failed_terminal") {
|
|
1294
|
+
if (status2.failureCode === "repository_identity_migration_required") {
|
|
1295
1295
|
return new Error(
|
|
1296
1296
|
"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
1297
|
);
|
|
1298
1298
|
}
|
|
1299
|
-
return new Error(`GitHub installation failed: ${
|
|
1299
|
+
return new Error(`GitHub installation failed: ${status2.failureCode}`);
|
|
1300
1300
|
}
|
|
1301
|
-
return new Error(`GitHub installation ${
|
|
1301
|
+
return new Error(`GitHub installation ${status2.status}`);
|
|
1302
1302
|
}
|
|
1303
1303
|
async function completeInstallIntent(client, start, dependencies, browser) {
|
|
1304
1304
|
process.stderr.write(`[prim] complete GitHub App installation at:
|
|
@@ -1326,15 +1326,15 @@ async function runGithubConnect(dependencies = defaultDependencies2, options = {
|
|
|
1326
1326
|
signal: AbortSignal.timeout(START_TIMEOUT_MS),
|
|
1327
1327
|
now: dependencies.now
|
|
1328
1328
|
});
|
|
1329
|
-
const
|
|
1329
|
+
const status2 = await completeInstallIntent(
|
|
1330
1330
|
client,
|
|
1331
1331
|
start,
|
|
1332
1332
|
dependencies,
|
|
1333
1333
|
options.browser ?? true
|
|
1334
1334
|
);
|
|
1335
|
-
if (
|
|
1335
|
+
if (status2.status !== "consumed") throw terminalInstallError(status2);
|
|
1336
1336
|
process.stderr.write(
|
|
1337
|
-
`[prim] GitHub installation verified: ${
|
|
1337
|
+
`[prim] GitHub installation verified: ${status2.adminRepositoryCount} admin repositories (${status2.repositoryCount} total)
|
|
1338
1338
|
`
|
|
1339
1339
|
);
|
|
1340
1340
|
const binding = await dependencies.bindRepositoryWithClient(root, client, {
|
|
@@ -2147,7 +2147,7 @@ async function inspectCodexHost(reload = false) {
|
|
|
2147
2147
|
} catch {
|
|
2148
2148
|
return unavailable("host-socket-unavailable");
|
|
2149
2149
|
}
|
|
2150
|
-
return new Promise((
|
|
2150
|
+
return new Promise((resolve7) => {
|
|
2151
2151
|
let finished = false;
|
|
2152
2152
|
let refreshed = false;
|
|
2153
2153
|
let requestId = 0;
|
|
@@ -2163,7 +2163,7 @@ async function inspectCodexHost(reload = false) {
|
|
|
2163
2163
|
finished = true;
|
|
2164
2164
|
clearTimeout(timer);
|
|
2165
2165
|
socket.terminate();
|
|
2166
|
-
|
|
2166
|
+
resolve7(value);
|
|
2167
2167
|
};
|
|
2168
2168
|
const fail = (reason) => finish({ ...unavailable(reason), ...refreshed ? { reload: "refreshed" } : {} });
|
|
2169
2169
|
const timer = setTimeout(() => fail("host-timeout"), TIMEOUT_MS);
|
|
@@ -2368,8 +2368,8 @@ function performStatus3() {
|
|
|
2368
2368
|
};
|
|
2369
2369
|
return { user: statusFor(userScopePath()), project: statusFor(projectScopePath()) };
|
|
2370
2370
|
}
|
|
2371
|
-
function uncoveredWorktreeHooks(
|
|
2372
|
-
if (
|
|
2371
|
+
function uncoveredWorktreeHooks(status2) {
|
|
2372
|
+
if (status2.user.present || status2.project.present) return null;
|
|
2373
2373
|
const main = mainWorktreeRoot();
|
|
2374
2374
|
if (main === null) return null;
|
|
2375
2375
|
const path = join3(main, ".codex", "hooks.json");
|
|
@@ -2472,7 +2472,7 @@ async function runPinnedEnsure(options) {
|
|
|
2472
2472
|
npm_config_fetch_retry_maxtimeout: "5000",
|
|
2473
2473
|
npm_config_fetch_timeout: "15000"
|
|
2474
2474
|
};
|
|
2475
|
-
return await new Promise((
|
|
2475
|
+
return await new Promise((resolve7) => {
|
|
2476
2476
|
let settled = false;
|
|
2477
2477
|
let child;
|
|
2478
2478
|
try {
|
|
@@ -2482,7 +2482,7 @@ async function runPinnedEnsure(options) {
|
|
|
2482
2482
|
{ env, stdio: "ignore" }
|
|
2483
2483
|
);
|
|
2484
2484
|
} catch {
|
|
2485
|
-
|
|
2485
|
+
resolve7(false);
|
|
2486
2486
|
return;
|
|
2487
2487
|
}
|
|
2488
2488
|
const timer = setTimeout(() => {
|
|
@@ -2493,7 +2493,7 @@ async function runPinnedEnsure(options) {
|
|
|
2493
2493
|
if (settled) return;
|
|
2494
2494
|
settled = true;
|
|
2495
2495
|
clearTimeout(timer);
|
|
2496
|
-
|
|
2496
|
+
resolve7(result);
|
|
2497
2497
|
};
|
|
2498
2498
|
timer.unref();
|
|
2499
2499
|
child.once("error", () => finish(false));
|
|
@@ -3755,7 +3755,7 @@ function clearStaleArtifacts() {
|
|
|
3755
3755
|
}
|
|
3756
3756
|
}
|
|
3757
3757
|
function sleep(ms) {
|
|
3758
|
-
return new Promise((
|
|
3758
|
+
return new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
3759
3759
|
}
|
|
3760
3760
|
function spawnDaemon(options) {
|
|
3761
3761
|
const file = binFile(DAEMON_BIN);
|
|
@@ -5113,8 +5113,8 @@ function formatSuccessHuman(operation, request, response) {
|
|
|
5113
5113
|
);
|
|
5114
5114
|
return `[prim] ${identifier} superseded by ${replacement}.`;
|
|
5115
5115
|
}
|
|
5116
|
-
function failure2(code, exitCode,
|
|
5117
|
-
return { code, exitCode, ...
|
|
5116
|
+
function failure2(code, exitCode, status2) {
|
|
5117
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
5118
5118
|
}
|
|
5119
5119
|
function classifyHttpError2(error) {
|
|
5120
5120
|
if (error.status === 401) {
|
|
@@ -5464,8 +5464,8 @@ function parseProposal(value, path) {
|
|
|
5464
5464
|
if (!REPO_FULL_NAME_RE.test(repoFullName)) {
|
|
5465
5465
|
contractError(`${path}.repoFullName`, "must be canonical owner/repository syntax");
|
|
5466
5466
|
}
|
|
5467
|
-
const
|
|
5468
|
-
if (
|
|
5467
|
+
const status2 = record3.status;
|
|
5468
|
+
if (status2 !== "proposed" && status2 !== "confirmed" && status2 !== "verification_failed") {
|
|
5469
5469
|
contractError(`${path}.status`, "is not a review-visible proposal status");
|
|
5470
5470
|
}
|
|
5471
5471
|
if (!Array.isArray(record3.signals) || record3.signals.length > MAX_SIGNALS) {
|
|
@@ -5490,7 +5490,7 @@ function parseProposal(value, path) {
|
|
|
5490
5490
|
_id: asString(record3._id, `${path}._id`, { max: 256, nonempty: true }),
|
|
5491
5491
|
repoFullName,
|
|
5492
5492
|
deadCommitSha: asSha(record3.deadCommitSha, `${path}.deadCommitSha`),
|
|
5493
|
-
status,
|
|
5493
|
+
status: status2,
|
|
5494
5494
|
proposedSha,
|
|
5495
5495
|
proposedTier,
|
|
5496
5496
|
signals,
|
|
@@ -5501,15 +5501,15 @@ function parseProposal(value, path) {
|
|
|
5501
5501
|
function parseDecision(value, path) {
|
|
5502
5502
|
const record3 = asRecord(value, path);
|
|
5503
5503
|
assertKeys(record3, path, ["_id", "intent", "status", "intentTruncated"], ["shortId"]);
|
|
5504
|
-
const
|
|
5505
|
-
if (
|
|
5504
|
+
const status2 = record3.status;
|
|
5505
|
+
if (status2 !== "provisional" && status2 !== "abandoned") {
|
|
5506
5506
|
contractError(`${path}.status`, "is not a repairable decision status");
|
|
5507
5507
|
}
|
|
5508
5508
|
return {
|
|
5509
5509
|
_id: asString(record3._id, `${path}._id`, { max: 256, nonempty: true }),
|
|
5510
5510
|
shortId: optionalString(record3, "shortId", path, 128),
|
|
5511
5511
|
intent: asString(record3.intent, `${path}.intent`, { max: MAX_INTENT_LENGTH }),
|
|
5512
|
-
status,
|
|
5512
|
+
status: status2,
|
|
5513
5513
|
intentTruncated: asBoolean(record3.intentTruncated, `${path}.intentTruncated`)
|
|
5514
5514
|
};
|
|
5515
5515
|
}
|
|
@@ -5940,8 +5940,8 @@ function projectSuccess2(response) {
|
|
|
5940
5940
|
...response.scopeWarnings === void 0 ? {} : { scopeWarnings: response.scopeWarnings }
|
|
5941
5941
|
};
|
|
5942
5942
|
}
|
|
5943
|
-
function failure3(code, exitCode,
|
|
5944
|
-
return { code, exitCode, ...
|
|
5943
|
+
function failure3(code, exitCode, status2) {
|
|
5944
|
+
return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
|
|
5945
5945
|
}
|
|
5946
5946
|
function classifyHttpError3(error) {
|
|
5947
5947
|
if (error.status === 401) {
|
|
@@ -6044,12 +6044,12 @@ async function rescopeDecision(request, dependencies = defaultDependencies4) {
|
|
|
6044
6044
|
|
|
6045
6045
|
// src/decisions/show.ts
|
|
6046
6046
|
var NOT_FOUND_RE4 = /not found/i;
|
|
6047
|
-
function colorStatus(
|
|
6048
|
-
const safeStatus = terminalSafeLine(
|
|
6049
|
-
if (
|
|
6047
|
+
function colorStatus(status2) {
|
|
6048
|
+
const safeStatus = terminalSafeLine(status2);
|
|
6049
|
+
if (status2 === "under_review" || status2 === "provisional") {
|
|
6050
6050
|
return color(safeStatus, "orange");
|
|
6051
6051
|
}
|
|
6052
|
-
if (
|
|
6052
|
+
if (status2 === "active" || status2 === "adopted") {
|
|
6053
6053
|
return color(safeStatus, "green");
|
|
6054
6054
|
}
|
|
6055
6055
|
return color(safeStatus, "gray");
|
|
@@ -8077,10 +8077,10 @@ var CONNECTIVITY_TIMEOUT_MS = 3e3;
|
|
|
8077
8077
|
var STALE_PENDING_MS = 3e4;
|
|
8078
8078
|
var EXIT_UNHEALTHY = 1;
|
|
8079
8079
|
function classifyDoctor(checks) {
|
|
8080
|
-
const
|
|
8080
|
+
const status2 = checks.some((c) => c.status === "fail") ? "fail" : checks.some((c) => c.status === "warn") ? "warn" : "ok";
|
|
8081
8081
|
return {
|
|
8082
|
-
json: { ok:
|
|
8083
|
-
exitCode:
|
|
8082
|
+
json: { ok: status2 !== "fail", status: status2, checks },
|
|
8083
|
+
exitCode: status2 === "fail" ? EXIT_UNHEALTHY : 0
|
|
8084
8084
|
};
|
|
8085
8085
|
}
|
|
8086
8086
|
function classifyAuthCredential(credential, expiresAt, hasRefresh) {
|
|
@@ -8527,15 +8527,15 @@ function checkManagedHook(hookName, firing) {
|
|
|
8527
8527
|
}
|
|
8528
8528
|
function checkFeedbackHooks() {
|
|
8529
8529
|
try {
|
|
8530
|
-
const
|
|
8531
|
-
return classifyClaudeHooks([
|
|
8530
|
+
const status2 = performStatus();
|
|
8531
|
+
return classifyClaudeHooks([status2.project, status2.user]);
|
|
8532
8532
|
} catch (error) {
|
|
8533
8533
|
const message = error instanceof Error ? error.message : String(error);
|
|
8534
8534
|
return { name: "feedback-hooks", status: "warn", detail: message.slice(0, 80) };
|
|
8535
8535
|
}
|
|
8536
8536
|
}
|
|
8537
8537
|
function classifyClaudeHooks(statuses) {
|
|
8538
|
-
const installed = statuses.filter((
|
|
8538
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8539
8539
|
if (installed.length === 0) {
|
|
8540
8540
|
return {
|
|
8541
8541
|
name: "feedback-hooks",
|
|
@@ -8543,7 +8543,7 @@ function classifyClaudeHooks(statuses) {
|
|
|
8543
8543
|
detail: "Claude lifecycle hooks missing \u2014 run `prim claude install`"
|
|
8544
8544
|
};
|
|
8545
8545
|
}
|
|
8546
|
-
if (installed.some((
|
|
8546
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8547
8547
|
return {
|
|
8548
8548
|
name: "feedback-hooks",
|
|
8549
8549
|
status: "fail",
|
|
@@ -8553,7 +8553,7 @@ function classifyClaudeHooks(statuses) {
|
|
|
8553
8553
|
return { name: "feedback-hooks", status: "ok", detail: "complete Claude lifecycle ready" };
|
|
8554
8554
|
}
|
|
8555
8555
|
function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host) {
|
|
8556
|
-
const installed = statuses.filter((
|
|
8556
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8557
8557
|
if (installed.length === 0) {
|
|
8558
8558
|
if (uncoveredWorktree !== null) {
|
|
8559
8559
|
return {
|
|
@@ -8564,7 +8564,7 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
|
|
|
8564
8564
|
}
|
|
8565
8565
|
return { name: "codex-hooks", status: "ok", detail: "not installed" };
|
|
8566
8566
|
}
|
|
8567
|
-
if (installed.some((
|
|
8567
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8568
8568
|
return {
|
|
8569
8569
|
name: "codex-hooks",
|
|
8570
8570
|
status: "fail",
|
|
@@ -8578,17 +8578,17 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
|
|
|
8578
8578
|
};
|
|
8579
8579
|
}
|
|
8580
8580
|
function classifyCursorHooks(statuses) {
|
|
8581
|
-
const installed = statuses.filter((
|
|
8581
|
+
const installed = statuses.filter((status2) => status2.present);
|
|
8582
8582
|
if (installed.length === 0)
|
|
8583
8583
|
return { name: "cursor-hooks", status: "ok", detail: "not installed" };
|
|
8584
|
-
if (installed.some((
|
|
8584
|
+
if (installed.some((status2) => !status2.complete)) {
|
|
8585
8585
|
return {
|
|
8586
8586
|
name: "cursor-hooks",
|
|
8587
8587
|
status: "fail",
|
|
8588
8588
|
detail: "incomplete or drifted native lifecycle \u2014 run `prim cursor install --force`"
|
|
8589
8589
|
};
|
|
8590
8590
|
}
|
|
8591
|
-
const user = statuses.find((
|
|
8591
|
+
const user = statuses.find((status2) => status2.footer !== void 0);
|
|
8592
8592
|
if (user?.present && user.footer === false && !user.footerPreservedCustom) {
|
|
8593
8593
|
return {
|
|
8594
8594
|
name: "cursor-hooks",
|
|
@@ -8596,7 +8596,7 @@ function classifyCursorHooks(statuses) {
|
|
|
8596
8596
|
detail: "native lifecycle ready but Cursor CLI footer is missing \u2014 run `prim cursor install --scope user --force`"
|
|
8597
8597
|
};
|
|
8598
8598
|
}
|
|
8599
|
-
if (statuses.some((
|
|
8599
|
+
if (statuses.some((status2) => status2.footerPreservedCustom)) {
|
|
8600
8600
|
return {
|
|
8601
8601
|
name: "cursor-hooks",
|
|
8602
8602
|
status: "warn",
|
|
@@ -8605,18 +8605,18 @@ function classifyCursorHooks(statuses) {
|
|
|
8605
8605
|
}
|
|
8606
8606
|
return { name: "cursor-hooks", status: "ok", detail: "complete native lifecycle ready" };
|
|
8607
8607
|
}
|
|
8608
|
-
function classifyHermesHooks(
|
|
8609
|
-
if (!
|
|
8608
|
+
function classifyHermesHooks(status2) {
|
|
8609
|
+
if (!status2.present) {
|
|
8610
8610
|
return { name: "hermes-hooks", status: "ok", detail: "not installed" };
|
|
8611
8611
|
}
|
|
8612
|
-
if (!
|
|
8612
|
+
if (!status2.complete) {
|
|
8613
8613
|
return {
|
|
8614
8614
|
name: "hermes-hooks",
|
|
8615
8615
|
status: "fail",
|
|
8616
8616
|
detail: "incomplete or drifted hook lifecycle \u2014 run `prim hermes install --force`"
|
|
8617
8617
|
};
|
|
8618
8618
|
}
|
|
8619
|
-
return
|
|
8619
|
+
return status2.autoAccept ? { name: "hermes-hooks", status: "ok", detail: "installed and pre-authorized" } : {
|
|
8620
8620
|
name: "hermes-hooks",
|
|
8621
8621
|
status: "warn",
|
|
8622
8622
|
detail: "installed; hook consent is not pre-authorized \u2014 run `prim hermes install --auto-accept`"
|
|
@@ -8625,13 +8625,13 @@ function classifyHermesHooks(status) {
|
|
|
8625
8625
|
async function checkAgentHooks() {
|
|
8626
8626
|
const checks = [];
|
|
8627
8627
|
try {
|
|
8628
|
-
const
|
|
8628
|
+
const status2 = performStatus3();
|
|
8629
8629
|
checks.push(
|
|
8630
8630
|
classifyCodexHooks(
|
|
8631
|
-
[
|
|
8632
|
-
uncoveredWorktreeHooks(
|
|
8631
|
+
[status2.project, status2.user],
|
|
8632
|
+
uncoveredWorktreeHooks(status2),
|
|
8633
8633
|
lastConversationCaptured(process.cwd(), "codex"),
|
|
8634
|
-
|
|
8634
|
+
status2.user.present || status2.project.present ? await inspectCodexHost() : void 0
|
|
8635
8635
|
)
|
|
8636
8636
|
);
|
|
8637
8637
|
} catch (error) {
|
|
@@ -8643,8 +8643,8 @@ async function checkAgentHooks() {
|
|
|
8643
8643
|
});
|
|
8644
8644
|
}
|
|
8645
8645
|
try {
|
|
8646
|
-
const
|
|
8647
|
-
checks.push(classifyCursorHooks([
|
|
8646
|
+
const status2 = performStatus2();
|
|
8647
|
+
checks.push(classifyCursorHooks([status2.project, status2.user]));
|
|
8648
8648
|
} catch (error) {
|
|
8649
8649
|
const detail = boundedHealthError(error instanceof Error ? error.message : String(error));
|
|
8650
8650
|
checks.push({
|
|
@@ -8783,26 +8783,26 @@ function parseMovesStatus(value) {
|
|
|
8783
8783
|
if (!value || typeof value !== "object") {
|
|
8784
8784
|
throw new Error("moves status returned a non-object response");
|
|
8785
8785
|
}
|
|
8786
|
-
const
|
|
8786
|
+
const status2 = value;
|
|
8787
8787
|
const nullableNumber = (candidate) => candidate === null || typeof candidate === "number" && Number.isFinite(candidate);
|
|
8788
|
-
if (
|
|
8788
|
+
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
8789
|
throw new Error("moves status returned an invalid response");
|
|
8790
8790
|
}
|
|
8791
|
-
if (
|
|
8791
|
+
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
8792
|
throw new Error("moves status returned invalid pending-age fields");
|
|
8793
8793
|
}
|
|
8794
|
-
return
|
|
8794
|
+
return status2;
|
|
8795
8795
|
}
|
|
8796
|
-
function classifyMovesStatus(
|
|
8796
|
+
function classifyMovesStatus(status2) {
|
|
8797
8797
|
const capture = {
|
|
8798
8798
|
name: "capture",
|
|
8799
8799
|
status: "ok",
|
|
8800
8800
|
detail: "enabled; ingest endpoint durable"
|
|
8801
8801
|
};
|
|
8802
|
-
const correlation =
|
|
8802
|
+
const correlation = status2.pendingCommitCorrelationCount === void 0 ? void 0 : status2.pendingCommitCorrelationCount > 0 ? {
|
|
8803
8803
|
name: "commit-correlation",
|
|
8804
8804
|
status: "warn",
|
|
8805
|
-
detail: `${String(
|
|
8805
|
+
detail: `${String(status2.pendingCommitCorrelationCount)} commit(s) awaiting evidence correlation`
|
|
8806
8806
|
} : {
|
|
8807
8807
|
name: "commit-correlation",
|
|
8808
8808
|
status: "ok",
|
|
@@ -8815,10 +8815,10 @@ async function checkBackend() {
|
|
|
8815
8815
|
const response = await getClient().get("/api/cli/moves/status", {
|
|
8816
8816
|
signal: AbortSignal.timeout(CONNECTIVITY_TIMEOUT_MS)
|
|
8817
8817
|
});
|
|
8818
|
-
const
|
|
8818
|
+
const status2 = parseMovesStatus(response);
|
|
8819
8819
|
return [
|
|
8820
8820
|
{ name: "connectivity", status: "ok", detail: "server reachable and authenticated" },
|
|
8821
|
-
...classifyMovesStatus(
|
|
8821
|
+
...classifyMovesStatus(status2)
|
|
8822
8822
|
];
|
|
8823
8823
|
} catch (err) {
|
|
8824
8824
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8879,8 +8879,8 @@ async function collectChecks(options, probes) {
|
|
|
8879
8879
|
(check) => !(options.agent && options.agent !== "claude" && check.name === "feedback-hooks" && check.detail.startsWith("Claude lifecycle hooks missing"))
|
|
8880
8880
|
);
|
|
8881
8881
|
}
|
|
8882
|
-
function icon(
|
|
8883
|
-
return
|
|
8882
|
+
function icon(status2) {
|
|
8883
|
+
return status2 === "ok" ? "\u2713" : status2 === "warn" ? "\u26A0" : "\u2717";
|
|
8884
8884
|
}
|
|
8885
8885
|
async function runDoctor(options, probes) {
|
|
8886
8886
|
const checks = await collectChecks(options, probes);
|
|
@@ -8909,21 +8909,376 @@ function registerDoctorCommands(program2, dependencies = {}) {
|
|
|
8909
8909
|
});
|
|
8910
8910
|
}
|
|
8911
8911
|
|
|
8912
|
+
// src/commands/gameplan.ts
|
|
8913
|
+
import { createHash as createHash4 } from "crypto";
|
|
8914
|
+
import { existsSync as existsSync8, lstatSync as lstatSync6, readFileSync as readFileSync7, readdirSync as readdirSync4, rmdirSync as rmdirSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
8915
|
+
import { homedir as homedir6 } from "os";
|
|
8916
|
+
import { dirname as dirname3, join as join9, resolve as resolve4 } from "path";
|
|
8917
|
+
import { fileURLToPath } from "url";
|
|
8918
|
+
var __dirname = dirname3(fileURLToPath(import.meta.url));
|
|
8919
|
+
var SKILL_NAME = "primitive-gameplan";
|
|
8920
|
+
var MANIFEST_NAME = ".prim-managed.json";
|
|
8921
|
+
var MANIFEST_OWNER = "@primitive.ai/prim:gameplan:v1";
|
|
8922
|
+
var START = "<!-- BEGIN PRIMITIVE GAMEPLAN v1 -->";
|
|
8923
|
+
var END = "<!-- END PRIMITIVE GAMEPLAN v1 -->";
|
|
8924
|
+
var HOOK_MARKER = "prim-gameplan-hook-v1";
|
|
8925
|
+
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';
|
|
8926
|
+
var ASSET_FILES = ["SKILL.md", "scripts/activate.mjs", "claude-hooks.json"];
|
|
8927
|
+
var AGENTS_BLOCK = `${START}
|
|
8928
|
+
When using $write-gameplan or $write-workstream, read and follow
|
|
8929
|
+
.agents/skills/primitive-gameplan/SKILL.md before architectural discussion.
|
|
8930
|
+
Keep the public planning skills unchanged.
|
|
8931
|
+
${END}`;
|
|
8932
|
+
function packageRoot2() {
|
|
8933
|
+
let directory = __dirname;
|
|
8934
|
+
while (directory !== dirname3(directory)) {
|
|
8935
|
+
if (existsSync8(join9(directory, "assets", SKILL_NAME, "SKILL.md"))) return directory;
|
|
8936
|
+
directory = dirname3(directory);
|
|
8937
|
+
}
|
|
8938
|
+
throw new Error("Primitive gameplan assets are missing from this CLI package");
|
|
8939
|
+
}
|
|
8940
|
+
function packageVersion2(root) {
|
|
8941
|
+
const parsed = JSON.parse(readFileSync7(join9(root, "package.json"), "utf8"));
|
|
8942
|
+
if (typeof parsed.version !== "string") throw new Error("CLI package version is missing");
|
|
8943
|
+
return parsed.version;
|
|
8944
|
+
}
|
|
8945
|
+
function sha256(content) {
|
|
8946
|
+
return createHash4("sha256").update(content).digest("hex");
|
|
8947
|
+
}
|
|
8948
|
+
function pathsFor(cwd) {
|
|
8949
|
+
const root = gitToplevel(cwd);
|
|
8950
|
+
if (root === null) throw new Error("Run prim gameplan from a Git worktree");
|
|
8951
|
+
const skillDir = join9(root, ".agents", "skills", SKILL_NAME);
|
|
8952
|
+
const codexHome = process.env.CODEX_HOME?.trim() ? resolve4(process.env.CODEX_HOME) : join9(homedir6(), ".codex");
|
|
8953
|
+
return {
|
|
8954
|
+
root,
|
|
8955
|
+
skillDir,
|
|
8956
|
+
manifest: join9(skillDir, MANIFEST_NAME),
|
|
8957
|
+
agents: join9(root, "AGENTS.md"),
|
|
8958
|
+
agentsOverride: join9(root, "AGENTS.override.md"),
|
|
8959
|
+
userHooks: join9(codexHome, "hooks.json")
|
|
8960
|
+
};
|
|
8961
|
+
}
|
|
8962
|
+
function readRegularFile(path) {
|
|
8963
|
+
let entry;
|
|
8964
|
+
try {
|
|
8965
|
+
entry = lstatSync6(path);
|
|
8966
|
+
} catch (error) {
|
|
8967
|
+
if (error.code === "ENOENT") return null;
|
|
8968
|
+
throw error;
|
|
8969
|
+
}
|
|
8970
|
+
if (!entry.isFile()) throw new Error(`Refusing non-regular file at ${path}`);
|
|
8971
|
+
return readFileSync7(path, "utf8");
|
|
8972
|
+
}
|
|
8973
|
+
function readManifest(path) {
|
|
8974
|
+
const content = readRegularFile(path);
|
|
8975
|
+
if (content === null) return null;
|
|
8976
|
+
let value;
|
|
8977
|
+
try {
|
|
8978
|
+
value = JSON.parse(content);
|
|
8979
|
+
} catch {
|
|
8980
|
+
throw new Error(`Invalid Primitive gameplan manifest at ${path}`);
|
|
8981
|
+
}
|
|
8982
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
8983
|
+
throw new Error(`Invalid Primitive gameplan manifest at ${path}`);
|
|
8984
|
+
}
|
|
8985
|
+
const record3 = value;
|
|
8986
|
+
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") {
|
|
8987
|
+
throw new Error(`Unknown or incomplete Primitive gameplan manifest at ${path}`);
|
|
8988
|
+
}
|
|
8989
|
+
return record3;
|
|
8990
|
+
}
|
|
8991
|
+
function managedBlock(content) {
|
|
8992
|
+
const begin = content.indexOf(START);
|
|
8993
|
+
const end = content.indexOf(END);
|
|
8994
|
+
if (begin === -1 && end === -1) return null;
|
|
8995
|
+
if (begin === -1 || end < begin || content.indexOf(START, begin + START.length) !== -1 || content.indexOf(END, end + END.length) !== -1) {
|
|
8996
|
+
throw new Error("AGENTS.md has malformed Primitive gameplan markers");
|
|
8997
|
+
}
|
|
8998
|
+
return content.slice(begin, end + END.length);
|
|
8999
|
+
}
|
|
9000
|
+
function blockSeparator(content) {
|
|
9001
|
+
if (content.length === 0 || content.endsWith("\n\n")) return "";
|
|
9002
|
+
return content.endsWith("\n") ? "\n" : "\n\n";
|
|
9003
|
+
}
|
|
9004
|
+
function upsertBlock(content) {
|
|
9005
|
+
const current = managedBlock(content);
|
|
9006
|
+
if (current !== null) return content.replace(current, AGENTS_BLOCK);
|
|
9007
|
+
return `${content}${blockSeparator(content)}${AGENTS_BLOCK}
|
|
9008
|
+
`;
|
|
9009
|
+
}
|
|
9010
|
+
function removeBlock(content, separator) {
|
|
9011
|
+
const block = managedBlock(content);
|
|
9012
|
+
if (block === null) return content;
|
|
9013
|
+
const start = content.indexOf(block);
|
|
9014
|
+
let before = content.slice(0, start);
|
|
9015
|
+
if (separator.length > 0 && before.endsWith(separator)) {
|
|
9016
|
+
before = before.slice(0, -separator.length);
|
|
9017
|
+
}
|
|
9018
|
+
const after = content.slice(start + block.length);
|
|
9019
|
+
return `${before}${after.replace(/^\n/u, "")}`;
|
|
9020
|
+
}
|
|
9021
|
+
function publicSkillPath(paths) {
|
|
9022
|
+
const codexHome = dirname3(paths.userHooks);
|
|
9023
|
+
const candidates = [
|
|
9024
|
+
join9(paths.root, ".agents", "skills", "write-gameplan", "SKILL.md"),
|
|
9025
|
+
join9(codexHome, "skills", "write-gameplan", "SKILL.md"),
|
|
9026
|
+
join9(homedir6(), ".agents", "skills", "write-gameplan", "SKILL.md")
|
|
9027
|
+
];
|
|
9028
|
+
for (const path of candidates) {
|
|
9029
|
+
try {
|
|
9030
|
+
const content = readFileSync7(path, "utf8");
|
|
9031
|
+
if (/^name:\s*write-gameplan\s*$/mu.test(content)) return path;
|
|
9032
|
+
} catch {
|
|
9033
|
+
}
|
|
9034
|
+
}
|
|
9035
|
+
return null;
|
|
9036
|
+
}
|
|
9037
|
+
function assetContents() {
|
|
9038
|
+
const root = packageRoot2();
|
|
9039
|
+
return Object.fromEntries(
|
|
9040
|
+
ASSET_FILES.map((file) => [file, readFileSync7(join9(root, "assets", SKILL_NAME, file), "utf8")])
|
|
9041
|
+
);
|
|
9042
|
+
}
|
|
9043
|
+
function markedHookCommands(settings) {
|
|
9044
|
+
const entries = settings.hooks?.UserPromptSubmit ?? [];
|
|
9045
|
+
if (!Array.isArray(entries)) throw new Error("Codex UserPromptSubmit hooks are not an array");
|
|
9046
|
+
return entries.flatMap(
|
|
9047
|
+
(entry) => (entry.hooks ?? []).flatMap(
|
|
9048
|
+
(hook) => typeof hook.command === "string" && hook.command.includes(HOOK_MARKER) ? [hook.command] : []
|
|
9049
|
+
)
|
|
9050
|
+
);
|
|
9051
|
+
}
|
|
9052
|
+
function ensureUserHook(settings) {
|
|
9053
|
+
const marked = markedHookCommands(settings);
|
|
9054
|
+
if (marked.some((command) => command !== HOOK_COMMAND)) {
|
|
9055
|
+
throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
|
|
9056
|
+
}
|
|
9057
|
+
if (marked.length > 1) throw new Error("Duplicate Primitive gameplan Codex hooks are present");
|
|
9058
|
+
if (marked.length === 1) return settings;
|
|
9059
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
9060
|
+
hooks.UserPromptSubmit = [
|
|
9061
|
+
...hooks.UserPromptSubmit ?? [],
|
|
9062
|
+
{ hooks: [{ type: "command", command: HOOK_COMMAND }] }
|
|
9063
|
+
];
|
|
9064
|
+
return { ...settings, hooks };
|
|
9065
|
+
}
|
|
9066
|
+
function removeUserHook(settings) {
|
|
9067
|
+
const marked = markedHookCommands(settings);
|
|
9068
|
+
if (marked.some((command) => command !== HOOK_COMMAND)) {
|
|
9069
|
+
throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
|
|
9070
|
+
}
|
|
9071
|
+
if (marked.length === 0) return settings;
|
|
9072
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
9073
|
+
hooks.UserPromptSubmit = (hooks.UserPromptSubmit ?? []).flatMap((entry) => {
|
|
9074
|
+
const commands = (entry.hooks ?? []).filter((hook) => hook.command !== HOOK_COMMAND);
|
|
9075
|
+
return commands.length > 0 ? [{ ...entry, hooks: commands }] : [];
|
|
9076
|
+
});
|
|
9077
|
+
if (hooks.UserPromptSubmit.length === 0) hooks.UserPromptSubmit = void 0;
|
|
9078
|
+
return { ...settings, hooks };
|
|
9079
|
+
}
|
|
9080
|
+
function checkOwnedFiles(paths, manifest) {
|
|
9081
|
+
if (existsSync8(paths.skillDir) && !lstatSync6(paths.skillDir).isDirectory()) {
|
|
9082
|
+
throw new Error(`Refusing non-directory companion path at ${paths.skillDir}`);
|
|
9083
|
+
}
|
|
9084
|
+
if (manifest === null && existsSync8(paths.skillDir) && readdirSync4(paths.skillDir).length > 0) {
|
|
9085
|
+
throw new Error(`Refusing unowned companion files at ${paths.skillDir}`);
|
|
9086
|
+
}
|
|
9087
|
+
if (manifest === null) return;
|
|
9088
|
+
for (const file of ASSET_FILES) {
|
|
9089
|
+
const path = join9(paths.skillDir, file);
|
|
9090
|
+
const current = readRegularFile(path);
|
|
9091
|
+
if (current !== null && sha256(current) !== manifest.files[file] && sha256(current) !== manifest.previousFiles?.[file]) {
|
|
9092
|
+
throw new Error(`Refusing modified companion file at ${path}`);
|
|
9093
|
+
}
|
|
9094
|
+
}
|
|
9095
|
+
}
|
|
9096
|
+
function checkAgentsBlock(paths, manifest) {
|
|
9097
|
+
const content = readRegularFile(paths.agents) ?? "";
|
|
9098
|
+
const block = managedBlock(content);
|
|
9099
|
+
if (block !== null && (manifest === null || sha256(block) !== manifest.agentsBlockHash && sha256(block) !== manifest.previousAgentsBlockHash)) {
|
|
9100
|
+
throw new Error(`Refusing modified or unowned Primitive gameplan block in ${paths.agents}`);
|
|
9101
|
+
}
|
|
9102
|
+
return { content, created: manifest?.createdAgents ?? !existsSync8(paths.agents) };
|
|
9103
|
+
}
|
|
9104
|
+
function install(cwd) {
|
|
9105
|
+
const paths = pathsFor(cwd);
|
|
9106
|
+
const publicSkill = publicSkillPath(paths);
|
|
9107
|
+
if (publicSkill === null) {
|
|
9108
|
+
throw new Error(
|
|
9109
|
+
"Codex cannot find $write-gameplan. Install the public skill in .agents/skills/write-gameplan or ~/.codex/skills/write-gameplan, then retry."
|
|
9110
|
+
);
|
|
9111
|
+
}
|
|
9112
|
+
if ((readRegularFile(paths.agentsOverride) ?? "").trim().length > 0) {
|
|
9113
|
+
throw new Error(
|
|
9114
|
+
"AGENTS.override.md shadows AGENTS.md in this repository; remove the override or install the companion manually in the effective rules."
|
|
9115
|
+
);
|
|
9116
|
+
}
|
|
9117
|
+
const assets = assetContents();
|
|
9118
|
+
const manifest = readManifest(paths.manifest);
|
|
9119
|
+
checkOwnedFiles(paths, manifest);
|
|
9120
|
+
const agents = checkAgentsBlock(paths, manifest);
|
|
9121
|
+
const hooksBefore = readSettings(paths.userHooks);
|
|
9122
|
+
const hooksAfter = ensureUserHook(hooksBefore);
|
|
9123
|
+
const nextManifest = {
|
|
9124
|
+
owner: MANIFEST_OWNER,
|
|
9125
|
+
packageVersion: packageVersion2(packageRoot2()),
|
|
9126
|
+
files: Object.fromEntries(ASSET_FILES.map((file) => [file, sha256(assets[file])])),
|
|
9127
|
+
...manifest === null ? {} : { previousFiles: manifest.files },
|
|
9128
|
+
agentsBlockHash: sha256(AGENTS_BLOCK),
|
|
9129
|
+
...manifest === null ? {} : { previousAgentsBlockHash: manifest.agentsBlockHash },
|
|
9130
|
+
createdAgents: agents.created,
|
|
9131
|
+
agentsSeparator: manifest?.agentsSeparator ?? blockSeparator(agents.content)
|
|
9132
|
+
};
|
|
9133
|
+
atomicWriteFile(paths.manifest, `${JSON.stringify(nextManifest, null, 2)}
|
|
9134
|
+
`, {
|
|
9135
|
+
ensureParent: true
|
|
9136
|
+
});
|
|
9137
|
+
for (const file of ASSET_FILES) {
|
|
9138
|
+
const path = join9(paths.skillDir, file);
|
|
9139
|
+
if (readRegularFile(path) !== assets[file]) {
|
|
9140
|
+
atomicWriteFile(path, assets[file], { ensureParent: true });
|
|
9141
|
+
}
|
|
9142
|
+
}
|
|
9143
|
+
const agentsAfter = upsertBlock(agents.content);
|
|
9144
|
+
if (agentsAfter !== agents.content) {
|
|
9145
|
+
atomicWriteFile(paths.agents, agentsAfter, { ensureParent: true });
|
|
9146
|
+
}
|
|
9147
|
+
if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore)) {
|
|
9148
|
+
atomicWrite(paths.userHooks, hooksAfter);
|
|
9149
|
+
}
|
|
9150
|
+
return { installed: true, root: paths.root, publicSkill, userHooks: paths.userHooks };
|
|
9151
|
+
}
|
|
9152
|
+
function status(cwd) {
|
|
9153
|
+
const paths = pathsFor(cwd);
|
|
9154
|
+
const manifest = readManifest(paths.manifest);
|
|
9155
|
+
const publicSkill = publicSkillPath(paths);
|
|
9156
|
+
const files = Object.fromEntries(
|
|
9157
|
+
ASSET_FILES.map((file) => {
|
|
9158
|
+
const current = readRegularFile(join9(paths.skillDir, file));
|
|
9159
|
+
return [
|
|
9160
|
+
file,
|
|
9161
|
+
current !== null && manifest !== null && sha256(current) === manifest.files[file]
|
|
9162
|
+
];
|
|
9163
|
+
})
|
|
9164
|
+
);
|
|
9165
|
+
const agents = readRegularFile(paths.agents) ?? "";
|
|
9166
|
+
const block = managedBlock(agents);
|
|
9167
|
+
const agentsBinding = block !== null && manifest !== null && sha256(block) === manifest.agentsBlockHash;
|
|
9168
|
+
const agentsOverrideShadows = (readRegularFile(paths.agentsOverride) ?? "").trim().length > 0;
|
|
9169
|
+
const hooks = markedHookCommands(readSettings(paths.userHooks));
|
|
9170
|
+
const userHook = hooks.length === 1 && hooks[0] === HOOK_COMMAND;
|
|
9171
|
+
const installed = manifest !== null && Object.values(files).every(Boolean) && agentsBinding && !agentsOverrideShadows && userHook && publicSkill !== null;
|
|
9172
|
+
return {
|
|
9173
|
+
installed,
|
|
9174
|
+
root: paths.root,
|
|
9175
|
+
packageVersion: manifest?.packageVersion ?? null,
|
|
9176
|
+
files,
|
|
9177
|
+
agentsBinding,
|
|
9178
|
+
agentsOverrideShadows,
|
|
9179
|
+
userHook,
|
|
9180
|
+
publicSkill,
|
|
9181
|
+
userHooks: paths.userHooks
|
|
9182
|
+
};
|
|
9183
|
+
}
|
|
9184
|
+
function uninstall(cwd, removeSharedHook) {
|
|
9185
|
+
const paths = pathsFor(cwd);
|
|
9186
|
+
const manifest = readManifest(paths.manifest);
|
|
9187
|
+
if (manifest === null)
|
|
9188
|
+
return { uninstalled: false, reason: "No managed companion in this repository" };
|
|
9189
|
+
checkOwnedFiles(paths, manifest);
|
|
9190
|
+
const expected = /* @__PURE__ */ new Set(["SKILL.md", "claude-hooks.json", "scripts", MANIFEST_NAME]);
|
|
9191
|
+
const extras = readdirSync4(paths.skillDir).filter((entry) => !expected.has(entry));
|
|
9192
|
+
const scriptsPath = join9(paths.skillDir, "scripts");
|
|
9193
|
+
if (existsSync8(scriptsPath)) {
|
|
9194
|
+
extras.push(...readdirSync4(scriptsPath).filter((entry) => entry !== "activate.mjs"));
|
|
9195
|
+
}
|
|
9196
|
+
if (extras.length > 0) {
|
|
9197
|
+
throw new Error(`Refusing to remove unowned companion files: ${extras.join(", ")}`);
|
|
9198
|
+
}
|
|
9199
|
+
const agents = checkAgentsBlock(paths, manifest);
|
|
9200
|
+
const hooksBefore = readSettings(paths.userHooks);
|
|
9201
|
+
const hooksAfter = removeSharedHook ? removeUserHook(hooksBefore) : hooksBefore;
|
|
9202
|
+
const agentsAfter = removeBlock(agents.content, manifest.agentsSeparator);
|
|
9203
|
+
if (agentsAfter !== agents.content) {
|
|
9204
|
+
if (manifest.createdAgents && agentsAfter.trim().length === 0) {
|
|
9205
|
+
unlinkSync4(paths.agents);
|
|
9206
|
+
} else {
|
|
9207
|
+
atomicWriteFile(paths.agents, agentsAfter);
|
|
9208
|
+
}
|
|
9209
|
+
}
|
|
9210
|
+
for (const file of ASSET_FILES) {
|
|
9211
|
+
const path = join9(paths.skillDir, file);
|
|
9212
|
+
if (existsSync8(path)) unlinkSync4(path);
|
|
9213
|
+
}
|
|
9214
|
+
unlinkSync4(paths.manifest);
|
|
9215
|
+
if (existsSync8(scriptsPath)) rmdirSync2(scriptsPath);
|
|
9216
|
+
rmdirSync2(paths.skillDir);
|
|
9217
|
+
if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore))
|
|
9218
|
+
atomicWrite(paths.userHooks, hooksAfter);
|
|
9219
|
+
return { uninstalled: true, root: paths.root, sharedUserHookRetained: !removeSharedHook };
|
|
9220
|
+
}
|
|
9221
|
+
function requireCodex(agent) {
|
|
9222
|
+
if (agent !== "codex") throw new Error(`Unsupported gameplan agent "${agent}" (expected codex)`);
|
|
9223
|
+
}
|
|
9224
|
+
function reportCommandError(error) {
|
|
9225
|
+
console.error(`[prim] ${error instanceof Error ? error.message : String(error)}`);
|
|
9226
|
+
process.exitCode = 1;
|
|
9227
|
+
}
|
|
9228
|
+
function registerGameplanCommands(program2) {
|
|
9229
|
+
const gameplan = program2.command("gameplan").description("Manage the Primitive Codex gameplanning companion");
|
|
9230
|
+
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) => {
|
|
9231
|
+
try {
|
|
9232
|
+
requireCodex(opts.agent);
|
|
9233
|
+
const result = install(process.cwd());
|
|
9234
|
+
console.error(
|
|
9235
|
+
"[prim] Gameplan companion installed. Review Codex /hooks and start a fresh session."
|
|
9236
|
+
);
|
|
9237
|
+
console.log(JSON.stringify(result));
|
|
9238
|
+
} catch (error) {
|
|
9239
|
+
reportCommandError(error);
|
|
9240
|
+
}
|
|
9241
|
+
});
|
|
9242
|
+
gameplan.command("status").description("Check the companion, public skill, AGENTS binding, and user prompt hook").option("--agent <agent>", "agent host", "codex").action((opts) => {
|
|
9243
|
+
try {
|
|
9244
|
+
requireCodex(opts.agent);
|
|
9245
|
+
const result = status(process.cwd());
|
|
9246
|
+
console.error(
|
|
9247
|
+
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."
|
|
9248
|
+
);
|
|
9249
|
+
console.log(JSON.stringify(result));
|
|
9250
|
+
if (!result.installed || result.publicSkill === null) process.exitCode = 1;
|
|
9251
|
+
} catch (error) {
|
|
9252
|
+
reportCommandError(error);
|
|
9253
|
+
}
|
|
9254
|
+
});
|
|
9255
|
+
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) => {
|
|
9256
|
+
try {
|
|
9257
|
+
requireCodex(opts.agent);
|
|
9258
|
+
const result = uninstall(process.cwd(), opts.removeUserHook ?? false);
|
|
9259
|
+
console.error("[prim] Removed this repository's managed gameplan companion.");
|
|
9260
|
+
console.log(JSON.stringify(result));
|
|
9261
|
+
} catch (error) {
|
|
9262
|
+
reportCommandError(error);
|
|
9263
|
+
}
|
|
9264
|
+
});
|
|
9265
|
+
}
|
|
9266
|
+
|
|
8912
9267
|
// src/commands/moves.ts
|
|
8913
|
-
import { existsSync as
|
|
8914
|
-
import { join as
|
|
9268
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync5, unlinkSync as unlinkSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
9269
|
+
import { join as join12 } from "path";
|
|
8915
9270
|
|
|
8916
9271
|
// src/flusher.ts
|
|
8917
|
-
import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as
|
|
8918
|
-
import { dirname as
|
|
9272
|
+
import { createReadStream, renameSync as renameSync3, statSync as statSync3, unlinkSync as unlinkSync5 } from "fs";
|
|
9273
|
+
import { dirname as dirname5, join as join11 } from "path";
|
|
8919
9274
|
|
|
8920
9275
|
// src/dead-letter.ts
|
|
8921
|
-
import { createHash as
|
|
9276
|
+
import { createHash as createHash5, randomBytes as randomBytes4 } from "crypto";
|
|
8922
9277
|
import {
|
|
8923
9278
|
constants as constants3,
|
|
8924
9279
|
chmodSync as chmodSync2,
|
|
8925
9280
|
closeSync as closeSync3,
|
|
8926
|
-
existsSync as
|
|
9281
|
+
existsSync as existsSync9,
|
|
8927
9282
|
fchmodSync,
|
|
8928
9283
|
fsyncSync,
|
|
8929
9284
|
mkdirSync as mkdirSync4,
|
|
@@ -8932,30 +9287,30 @@ import {
|
|
|
8932
9287
|
rmSync as rmSync3,
|
|
8933
9288
|
writeFileSync as writeFileSync3
|
|
8934
9289
|
} from "fs";
|
|
8935
|
-
import { dirname as
|
|
9290
|
+
import { dirname as dirname4, join as join10 } from "path";
|
|
8936
9291
|
var DIRECTORY_MODE = 448;
|
|
8937
9292
|
var FILE_MODE = 384;
|
|
8938
9293
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
8939
9294
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
8940
|
-
return
|
|
9295
|
+
return join10(dirname4(flushingPath), DEAD_LETTER_DIRNAME);
|
|
8941
9296
|
}
|
|
8942
9297
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
8943
|
-
const quarantineId =
|
|
8944
|
-
return
|
|
9298
|
+
const quarantineId = createHash5("sha256").update(rawLine).digest("hex");
|
|
9299
|
+
return join10(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
8945
9300
|
}
|
|
8946
9301
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
8947
9302
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
8948
9303
|
mkdirSync4(directory, { recursive: true, mode: DIRECTORY_MODE });
|
|
8949
9304
|
chmodSync2(directory, DIRECTORY_MODE);
|
|
8950
|
-
persistDirectory(
|
|
9305
|
+
persistDirectory(dirname4(directory));
|
|
8951
9306
|
return directory;
|
|
8952
9307
|
}
|
|
8953
9308
|
function persistDeadLetter(directory, path, quarantineId, record3, persistDirectory) {
|
|
8954
|
-
if (
|
|
9309
|
+
if (existsSync9(path)) {
|
|
8955
9310
|
persistDirectory(directory);
|
|
8956
9311
|
return;
|
|
8957
9312
|
}
|
|
8958
|
-
const temporaryPath =
|
|
9313
|
+
const temporaryPath = join10(
|
|
8959
9314
|
directory,
|
|
8960
9315
|
`.${quarantineId}.${String(process.pid)}.${randomBytes4(8).toString("hex")}.tmp`
|
|
8961
9316
|
);
|
|
@@ -8982,12 +9337,12 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
8982
9337
|
const serializedMove = JSON.stringify(move);
|
|
8983
9338
|
const record3 = {
|
|
8984
9339
|
version: 1,
|
|
8985
|
-
quarantineId:
|
|
9340
|
+
quarantineId: createHash5("sha256").update(serializedMove).digest("hex"),
|
|
8986
9341
|
quarantinedAt: now(),
|
|
8987
9342
|
reason,
|
|
8988
9343
|
move
|
|
8989
9344
|
};
|
|
8990
|
-
const path =
|
|
9345
|
+
const path = join10(directory, `${record3.quarantineId}.json`);
|
|
8991
9346
|
persistDeadLetter(directory, path, record3.quarantineId, record3, persistDirectory);
|
|
8992
9347
|
return record3;
|
|
8993
9348
|
}
|
|
@@ -8998,7 +9353,7 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
|
|
|
8998
9353
|
const record3 = {
|
|
8999
9354
|
version: 1,
|
|
9000
9355
|
recordKind: "raw_line_v1",
|
|
9001
|
-
quarantineId:
|
|
9356
|
+
quarantineId: createHash5("sha256").update(bytes).digest("hex"),
|
|
9002
9357
|
quarantinedAt: now(),
|
|
9003
9358
|
reason: "invalid_move",
|
|
9004
9359
|
rawLineEncoding: "base64",
|
|
@@ -9238,7 +9593,7 @@ async function drainFlushingPath(flushingPath, client, binding, options = {}) {
|
|
|
9238
9593
|
} finally {
|
|
9239
9594
|
input.destroy();
|
|
9240
9595
|
}
|
|
9241
|
-
|
|
9596
|
+
unlinkSync5(flushingPath);
|
|
9242
9597
|
try {
|
|
9243
9598
|
removeDrainCheckpoint(flushingPath);
|
|
9244
9599
|
} catch {
|
|
@@ -9382,7 +9737,7 @@ async function flushOnce() {
|
|
|
9382
9737
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
9383
9738
|
}
|
|
9384
9739
|
var flushInFlight;
|
|
9385
|
-
var FLUSH_LOCK_PATH =
|
|
9740
|
+
var FLUSH_LOCK_PATH = join11(dirname5(JOURNAL_DIR), ".flush.lock");
|
|
9386
9741
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
9387
9742
|
function isFlushLockContended(error) {
|
|
9388
9743
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -9514,23 +9869,23 @@ function registerMovesCommands(program2) {
|
|
|
9514
9869
|
}
|
|
9515
9870
|
});
|
|
9516
9871
|
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 (!
|
|
9872
|
+
const dir = join12(process.cwd(), ".prim");
|
|
9873
|
+
if (!existsSync10(dir)) {
|
|
9519
9874
|
mkdirSync5(dir, { recursive: true, mode: DIR_MODE });
|
|
9520
9875
|
}
|
|
9521
|
-
const file =
|
|
9876
|
+
const file = join12(process.cwd(), WORKSPACE_FILE);
|
|
9522
9877
|
writeFileSync4(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
|
|
9523
9878
|
mode: FILE_MODE2
|
|
9524
9879
|
});
|
|
9525
9880
|
console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
|
|
9526
9881
|
});
|
|
9527
9882
|
moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
|
|
9528
|
-
const file =
|
|
9529
|
-
if (!
|
|
9883
|
+
const file = join12(process.cwd(), WORKSPACE_FILE);
|
|
9884
|
+
if (!existsSync10(file)) {
|
|
9530
9885
|
console.log("[prim] no workspace binding in cwd");
|
|
9531
9886
|
return;
|
|
9532
9887
|
}
|
|
9533
|
-
|
|
9888
|
+
unlinkSync6(file);
|
|
9534
9889
|
console.log(`[prim] dropped workspace binding from ${process.cwd()}`);
|
|
9535
9890
|
});
|
|
9536
9891
|
}
|
|
@@ -9586,10 +9941,10 @@ async function performResolution(idOrShortId, opts) {
|
|
|
9586
9941
|
process.stderr.write(`[prim] recorded ${opts.outcome} for check ${opts.check}
|
|
9587
9942
|
`);
|
|
9588
9943
|
} catch (error) {
|
|
9589
|
-
const
|
|
9590
|
-
process.stderr.write(`[prim] resolution failed${
|
|
9944
|
+
const status2 = error instanceof HttpError ? error.status : void 0;
|
|
9945
|
+
process.stderr.write(`[prim] resolution failed${status2 ? ` (${status2})` : ""}
|
|
9591
9946
|
`);
|
|
9592
|
-
console.log(JSON.stringify({ ok: false, status }));
|
|
9947
|
+
console.log(JSON.stringify({ ok: false, status: status2 }));
|
|
9593
9948
|
process.exitCode = isDomainRejection(error) ? EXIT_USAGE2 : EXIT_SERVER;
|
|
9594
9949
|
}
|
|
9595
9950
|
}
|
|
@@ -9604,23 +9959,23 @@ function registerReconcileCommands(program2) {
|
|
|
9604
9959
|
|
|
9605
9960
|
// src/commands/session.ts
|
|
9606
9961
|
import {
|
|
9607
|
-
existsSync as
|
|
9962
|
+
existsSync as existsSync11,
|
|
9608
9963
|
mkdirSync as mkdirSync6,
|
|
9609
|
-
readFileSync as
|
|
9610
|
-
readdirSync as
|
|
9611
|
-
unlinkSync as
|
|
9964
|
+
readFileSync as readFileSync8,
|
|
9965
|
+
readdirSync as readdirSync5,
|
|
9966
|
+
unlinkSync as unlinkSync7,
|
|
9612
9967
|
writeFileSync as writeFileSync5
|
|
9613
9968
|
} from "fs";
|
|
9614
|
-
import { join as
|
|
9969
|
+
import { join as join13 } from "path";
|
|
9615
9970
|
var DIR_MODE2 = 448;
|
|
9616
9971
|
var FILE_MODE3 = 384;
|
|
9617
9972
|
function ensureDir() {
|
|
9618
|
-
if (!
|
|
9973
|
+
if (!existsSync11(SESSIONS_DIR)) {
|
|
9619
9974
|
mkdirSync6(SESSIONS_DIR, { recursive: true, mode: DIR_MODE2 });
|
|
9620
9975
|
}
|
|
9621
9976
|
}
|
|
9622
9977
|
function markerPath(sessionId) {
|
|
9623
|
-
return
|
|
9978
|
+
return join13(SESSIONS_DIR, `${sessionId}.json`);
|
|
9624
9979
|
}
|
|
9625
9980
|
function registerSessionCommands(program2) {
|
|
9626
9981
|
const session = program2.command("session").description("Decision Event Pipeline \u2014 session binding markers");
|
|
@@ -9636,11 +9991,11 @@ function registerSessionCommands(program2) {
|
|
|
9636
9991
|
console.log(`[prim] session ${sessionId} bound to org ${opts.orgId}`);
|
|
9637
9992
|
});
|
|
9638
9993
|
session.command("list").description("List active session markers").action(() => {
|
|
9639
|
-
if (!
|
|
9994
|
+
if (!existsSync11(SESSIONS_DIR)) {
|
|
9640
9995
|
console.log("[prim] no session markers");
|
|
9641
9996
|
return;
|
|
9642
9997
|
}
|
|
9643
|
-
const files =
|
|
9998
|
+
const files = readdirSync5(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
|
|
9644
9999
|
if (files.length === 0) {
|
|
9645
10000
|
console.log("[prim] no session markers");
|
|
9646
10001
|
return;
|
|
@@ -9648,7 +10003,7 @@ function registerSessionCommands(program2) {
|
|
|
9648
10003
|
for (const f of files) {
|
|
9649
10004
|
const sessionId = f.replace(/\.json$/, "");
|
|
9650
10005
|
try {
|
|
9651
|
-
const m = JSON.parse(
|
|
10006
|
+
const m = JSON.parse(readFileSync8(join13(SESSIONS_DIR, f), "utf-8"));
|
|
9652
10007
|
console.log(`${sessionId} org=${m.orgId}`);
|
|
9653
10008
|
} catch {
|
|
9654
10009
|
}
|
|
@@ -9656,19 +10011,19 @@ function registerSessionCommands(program2) {
|
|
|
9656
10011
|
});
|
|
9657
10012
|
session.command("drop <sessionId>").description("Remove a session marker").action((sessionId) => {
|
|
9658
10013
|
const p = markerPath(sessionId);
|
|
9659
|
-
if (!
|
|
10014
|
+
if (!existsSync11(p)) {
|
|
9660
10015
|
console.log(`[prim] no marker for session ${sessionId}`);
|
|
9661
10016
|
return;
|
|
9662
10017
|
}
|
|
9663
|
-
|
|
10018
|
+
unlinkSync7(p);
|
|
9664
10019
|
console.log(`[prim] dropped session marker ${sessionId}`);
|
|
9665
10020
|
});
|
|
9666
10021
|
}
|
|
9667
10022
|
|
|
9668
10023
|
// src/commands/setup.ts
|
|
9669
10024
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
9670
|
-
import { existsSync as
|
|
9671
|
-
import { join as
|
|
10025
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
|
|
10026
|
+
import { join as join14 } from "path";
|
|
9672
10027
|
var EXIT_INCOMPLETE = 1;
|
|
9673
10028
|
var EXIT_USAGE3 = 2;
|
|
9674
10029
|
var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
|
|
@@ -9806,8 +10161,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
|
9806
10161
|
let preCommit;
|
|
9807
10162
|
try {
|
|
9808
10163
|
const root = gitToplevel();
|
|
9809
|
-
const path = root &&
|
|
9810
|
-
if (path &&
|
|
10164
|
+
const path = root && join14(root, ".git", "hooks", "pre-commit");
|
|
10165
|
+
if (path && existsSync12(path)) preCommit = readFileSync9(path, "utf-8");
|
|
9811
10166
|
} catch {
|
|
9812
10167
|
}
|
|
9813
10168
|
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
@@ -10068,23 +10423,23 @@ function setupChildPayload(stdout) {
|
|
|
10068
10423
|
}
|
|
10069
10424
|
|
|
10070
10425
|
// src/commands/statusline.ts
|
|
10071
|
-
import { readFileSync as
|
|
10072
|
-
import { dirname as
|
|
10073
|
-
import { fileURLToPath } from "url";
|
|
10426
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
10427
|
+
import { dirname as dirname6, resolve as resolve5 } from "path";
|
|
10428
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10074
10429
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
10075
10430
|
function readPackageVersion() {
|
|
10076
10431
|
try {
|
|
10077
|
-
const here =
|
|
10432
|
+
const here = dirname6(fileURLToPath2(import.meta.url));
|
|
10078
10433
|
const candidates = [
|
|
10079
10434
|
// Schema-v2 runtimes staged a manifest beside this standalone bundle.
|
|
10080
10435
|
// Keep resolving it while those legacy launchers transition to schema v3.
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10436
|
+
resolve5(here, "manifest.json"),
|
|
10437
|
+
resolve5(here, "../../package.json"),
|
|
10438
|
+
resolve5(here, "../package.json")
|
|
10084
10439
|
];
|
|
10085
10440
|
for (const path of candidates) {
|
|
10086
10441
|
try {
|
|
10087
|
-
const pkg2 = JSON.parse(
|
|
10442
|
+
const pkg2 = JSON.parse(readFileSync10(path, "utf-8"));
|
|
10088
10443
|
if (pkg2.version) {
|
|
10089
10444
|
return pkg2.version;
|
|
10090
10445
|
}
|
|
@@ -10609,13 +10964,13 @@ function healDaemonDrift(options = {}) {
|
|
|
10609
10964
|
|
|
10610
10965
|
// src/lib/background-flush.ts
|
|
10611
10966
|
import { spawn as spawn3 } from "child_process";
|
|
10612
|
-
import { readFileSync as
|
|
10967
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
10613
10968
|
|
|
10614
10969
|
// src/daemon/health.ts
|
|
10615
|
-
import { chmodSync as chmodSync3, existsSync as
|
|
10616
|
-
import { dirname as
|
|
10970
|
+
import { chmodSync as chmodSync3, existsSync as existsSync13, mkdirSync as mkdirSync7, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
10971
|
+
import { dirname as dirname7, join as join15 } from "path";
|
|
10617
10972
|
var HEARTBEAT_FRESH_MS = 9e4;
|
|
10618
|
-
var DAEMON_HEALTH_PATH =
|
|
10973
|
+
var DAEMON_HEALTH_PATH = join15(primConfigDirectory(), "daemon-health.json");
|
|
10619
10974
|
|
|
10620
10975
|
// src/lib/background-flush.ts
|
|
10621
10976
|
function record2(value) {
|
|
@@ -10626,7 +10981,7 @@ function daemonOwnsDrain(options = {}) {
|
|
|
10626
10981
|
const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
|
|
10627
10982
|
if (!expectedVersion) return false;
|
|
10628
10983
|
const health = record2(
|
|
10629
|
-
JSON.parse(
|
|
10984
|
+
JSON.parse(readFileSync11(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
|
|
10630
10985
|
);
|
|
10631
10986
|
const heartbeat = record2(health?.heartbeat);
|
|
10632
10987
|
const ingestion = record2(health?.ingestion);
|
|
@@ -10733,8 +11088,8 @@ function mayHealDaemon(argv, env) {
|
|
|
10733
11088
|
function runStartupBackgroundWork(argv, env, work) {
|
|
10734
11089
|
const args = commandArguments(argv);
|
|
10735
11090
|
const [command, subcommand] = args;
|
|
10736
|
-
const
|
|
10737
|
-
if (
|
|
11091
|
+
const uninstall2 = command === "uninstall" || env[UNINSTALL_ORCHESTRATOR_ENV] === "1";
|
|
11092
|
+
if (uninstall2 || command === "demo") return;
|
|
10738
11093
|
work.notify();
|
|
10739
11094
|
const setupDaemonDrains = command === "setup" && !args.includes("--no-daemon") || env[SETUP_DAEMON_DRAINS_ENV] === "1";
|
|
10740
11095
|
if (!setupDaemonDrains && (command !== "moves" || subcommand !== "flush")) work.flush();
|
|
@@ -10742,8 +11097,8 @@ function runStartupBackgroundWork(argv, env, work) {
|
|
|
10742
11097
|
}
|
|
10743
11098
|
|
|
10744
11099
|
// src/index.ts
|
|
10745
|
-
var
|
|
10746
|
-
var pkg = JSON.parse(
|
|
11100
|
+
var __dirname2 = dirname8(fileURLToPath3(import.meta.url));
|
|
11101
|
+
var pkg = JSON.parse(readFileSync12(resolve6(__dirname2, "../package.json"), "utf-8"));
|
|
10747
11102
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
10748
11103
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
10749
11104
|
flush: () => startBackgroundFlush(),
|
|
@@ -10758,6 +11113,7 @@ registerAuthCommands(program);
|
|
|
10758
11113
|
registerHooksCommands(program);
|
|
10759
11114
|
registerActivationCommands(program);
|
|
10760
11115
|
registerSkillCommands(program);
|
|
11116
|
+
registerGameplanCommands(program);
|
|
10761
11117
|
registerMovesCommands(program);
|
|
10762
11118
|
registerSessionCommands(program);
|
|
10763
11119
|
registerDecisionsCommands(program);
|