@primitive.ai/prim 0.1.0-alpha.114 → 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.
@@ -4963,7 +4963,7 @@ var require_rc = __commonJS({
4963
4963
  "node_modules/.pnpm/rc@1.2.8/node_modules/rc/index.js"(exports, module) {
4964
4964
  "use strict";
4965
4965
  var cc = require_utils();
4966
- var join37 = __require("path").join;
4966
+ var join38 = __require("path").join;
4967
4967
  var deepExtend = require_deep_extend();
4968
4968
  var etc = "/etc";
4969
4969
  var win = process.platform === "win32";
@@ -4988,15 +4988,15 @@ var require_rc = __commonJS({
4988
4988
  }
4989
4989
  if (!win)
4990
4990
  [
4991
- join37(etc, name, "config"),
4992
- join37(etc, name + "rc")
4991
+ join38(etc, name, "config"),
4992
+ join38(etc, name + "rc")
4993
4993
  ].forEach(addConfigFile);
4994
4994
  if (home)
4995
4995
  [
4996
- join37(home, ".config", name, "config"),
4997
- join37(home, ".config", name),
4998
- join37(home, "." + name, "config"),
4999
- join37(home, "." + name + "rc")
4996
+ join38(home, ".config", name, "config"),
4997
+ join38(home, ".config", name),
4998
+ join38(home, "." + name, "config"),
4999
+ join38(home, "." + name + "rc")
5000
5000
  ].forEach(addConfigFile);
5001
5001
  addConfigFile(cc.find("." + name + "rc"));
5002
5002
  if (env4.config) addConfigFile(env4.config);
@@ -6340,11 +6340,11 @@ var require_util = __commonJS({
6340
6340
  if (files.includes("node_modules") || files.includes("package.json") || files.includes("package.json5") || files.includes("package.yaml") || files.includes("pnpm-workspace.yaml")) {
6341
6341
  return name2;
6342
6342
  }
6343
- const dirname22 = path9.dirname(name2);
6344
- if (dirname22 === name2) {
6343
+ const dirname23 = path9.dirname(name2);
6344
+ if (dirname23 === name2) {
6345
6345
  return original;
6346
6346
  }
6347
- return find(dirname22, original);
6347
+ return find(dirname23, original);
6348
6348
  } catch (error) {
6349
6349
  if (name2 === original) {
6350
6350
  if (error.code === "ENOENT") {
@@ -11143,7 +11143,7 @@ var require_websocket = __commonJS({
11143
11143
  var http = __require("http");
11144
11144
  var net = __require("net");
11145
11145
  var tls = __require("tls");
11146
- var { randomBytes: randomBytes8, createHash: createHash14 } = __require("crypto");
11146
+ var { randomBytes: randomBytes8, createHash: createHash15 } = __require("crypto");
11147
11147
  var { Duplex, Readable: Readable2 } = __require("stream");
11148
11148
  var { URL: URL2 } = __require("url");
11149
11149
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -11811,7 +11811,7 @@ var require_websocket = __commonJS({
11811
11811
  abortHandshake(websocket, socket, "Invalid Upgrade header");
11812
11812
  return;
11813
11813
  }
11814
- const digest2 = createHash14("sha1").update(key + GUID).digest("base64");
11814
+ const digest2 = createHash15("sha1").update(key + GUID).digest("base64");
11815
11815
  if (res.headers["sec-websocket-accept"] !== digest2) {
11816
11816
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
11817
11817
  return;
@@ -12180,7 +12180,7 @@ var require_websocket_server = __commonJS({
12180
12180
  var EventEmitter = __require("events");
12181
12181
  var http = __require("http");
12182
12182
  var { Duplex } = __require("stream");
12183
- var { createHash: createHash14 } = __require("crypto");
12183
+ var { createHash: createHash15 } = __require("crypto");
12184
12184
  var extension2 = require_extension();
12185
12185
  var PerMessageDeflate2 = require_permessage_deflate();
12186
12186
  var subprotocol2 = require_subprotocol();
@@ -12487,7 +12487,7 @@ var require_websocket_server = __commonJS({
12487
12487
  );
12488
12488
  }
12489
12489
  if (this._state > RUNNING) return abortHandshake(socket, 503);
12490
- const digest2 = createHash14("sha1").update(key + GUID).digest("base64");
12490
+ const digest2 = createHash15("sha1").update(key + GUID).digest("base64");
12491
12491
  const headers = [
12492
12492
  "HTTP/1.1 101 Switching Protocols",
12493
12493
  "Upgrade: websocket",
@@ -12575,9 +12575,9 @@ var require_websocket_server = __commonJS({
12575
12575
  });
12576
12576
 
12577
12577
  // src/index.ts
12578
- import { readFileSync as readFileSync28 } from "fs";
12579
- import { dirname as dirname21, resolve as resolve13 } from "path";
12580
- import { fileURLToPath as fileURLToPath7 } from "url";
12578
+ import { readFileSync as readFileSync29 } from "fs";
12579
+ import { dirname as dirname22, resolve as resolve14 } from "path";
12580
+ import { fileURLToPath as fileURLToPath8 } from "url";
12581
12581
 
12582
12582
  // node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
12583
12583
  var import_index = __toESM(require_commander(), 1);
@@ -12677,7 +12677,7 @@ var retryifyAsync = (fn, options) => {
12677
12677
  throw error;
12678
12678
  const delay2 = Math.round(interval * Math.random());
12679
12679
  if (delay2 > 0) {
12680
- const delayPromise = new Promise((resolve14) => setTimeout(resolve14, delay2));
12680
+ const delayPromise = new Promise((resolve15) => setTimeout(resolve15, delay2));
12681
12681
  return delayPromise.then(() => attempt.apply(void 0, args));
12682
12682
  } else {
12683
12683
  return attempt.apply(void 0, args);
@@ -13836,8 +13836,8 @@ var HTTPError = class extends Error {
13836
13836
  constructor(response, request2, options) {
13837
13837
  const code = response.status || response.status === 0 ? response.status : "";
13838
13838
  const title = response.statusText ?? "";
13839
- const status = `${code} ${title}`.trim();
13840
- const reason = status ? `status code ${status}` : "an unknown error";
13839
+ const status2 = `${code} ${title}`.trim();
13840
+ const reason = status2 ? `status code ${status2}` : "an unknown error";
13841
13841
  super(`Request failed with ${reason}: ${request2.method} ${request2.url}`);
13842
13842
  this.name = "HTTPError";
13843
13843
  this.response = response;
@@ -14243,14 +14243,14 @@ var TimeoutError = class extends Error {
14243
14243
 
14244
14244
  // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/timeout.js
14245
14245
  async function timeout(request2, init, abortController, options) {
14246
- return new Promise((resolve14, reject) => {
14246
+ return new Promise((resolve15, reject) => {
14247
14247
  const timeoutId = setTimeout(() => {
14248
14248
  if (abortController) {
14249
14249
  abortController.abort();
14250
14250
  }
14251
14251
  reject(new TimeoutError(request2));
14252
14252
  }, options.timeout);
14253
- void options.fetch(request2, init).then(resolve14).catch(reject).then(() => {
14253
+ void options.fetch(request2, init).then(resolve15).catch(reject).then(() => {
14254
14254
  clearTimeout(timeoutId);
14255
14255
  });
14256
14256
  });
@@ -14258,7 +14258,7 @@ async function timeout(request2, init, abortController, options) {
14258
14258
 
14259
14259
  // node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/delay.js
14260
14260
  async function delay(ms, { signal }) {
14261
- return new Promise((resolve14, reject) => {
14261
+ return new Promise((resolve15, reject) => {
14262
14262
  if (signal) {
14263
14263
  signal.throwIfAborted();
14264
14264
  signal.addEventListener("abort", abortHandler, { once: true });
@@ -14269,7 +14269,7 @@ async function delay(ms, { signal }) {
14269
14269
  }
14270
14270
  const timeoutId = setTimeout(() => {
14271
14271
  signal?.removeEventListener("abort", abortHandler);
14272
- resolve14();
14272
+ resolve15();
14273
14273
  }, ms);
14274
14274
  });
14275
14275
  }
@@ -16239,7 +16239,7 @@ function providerError(value) {
16239
16239
  return exactString(error, "error", MAX_USER_CODE_LENGTH);
16240
16240
  }
16241
16241
  async function defaultSleep(milliseconds, signal) {
16242
- await new Promise((resolve14, reject) => {
16242
+ await new Promise((resolve15, reject) => {
16243
16243
  if (signal.aborted) {
16244
16244
  reject(signal.reason);
16245
16245
  return;
@@ -16250,7 +16250,7 @@ async function defaultSleep(milliseconds, signal) {
16250
16250
  };
16251
16251
  const timer = setTimeout(() => {
16252
16252
  signal.removeEventListener("abort", abort);
16253
- resolve14();
16253
+ resolve15();
16254
16254
  }, milliseconds);
16255
16255
  signal.addEventListener("abort", abort, { once: true });
16256
16256
  });
@@ -16499,7 +16499,7 @@ function daemonRequest(method, params = {}, opts = {}) {
16499
16499
  ...caller ? { caller } : {}
16500
16500
  };
16501
16501
  const timeoutMs2 = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
16502
- return new Promise((resolve14) => {
16502
+ return new Promise((resolve15) => {
16503
16503
  let settled = false;
16504
16504
  let socket;
16505
16505
  let buffer = Buffer.alloc(0);
@@ -16514,7 +16514,7 @@ function daemonRequest(method, params = {}, opts = {}) {
16514
16514
  } catch {
16515
16515
  }
16516
16516
  }
16517
- resolve14(value);
16517
+ resolve15(value);
16518
16518
  };
16519
16519
  const timer = setTimeout(() => settle(null), timeoutMs2);
16520
16520
  timer.unref();
@@ -17117,14 +17117,14 @@ function throwIfAborted(signal) {
17117
17117
  }
17118
17118
  async function defaultSleep2(ms, signal) {
17119
17119
  if (!signal) {
17120
- await new Promise((resolve14) => setTimeout(resolve14, ms));
17120
+ await new Promise((resolve15) => setTimeout(resolve15, ms));
17121
17121
  return;
17122
17122
  }
17123
17123
  throwIfAborted(signal);
17124
- await new Promise((resolve14, reject) => {
17124
+ await new Promise((resolve15, reject) => {
17125
17125
  const timer = setTimeout(() => {
17126
17126
  signal.removeEventListener("abort", onAbort);
17127
- resolve14();
17127
+ resolve15();
17128
17128
  }, ms);
17129
17129
  const onAbort = () => {
17130
17130
  clearTimeout(timer);
@@ -17944,10 +17944,10 @@ function refreshToken(options = {}) {
17944
17944
  var HttpError = class extends Error {
17945
17945
  status;
17946
17946
  body;
17947
- constructor(status, message, body) {
17947
+ constructor(status2, message, body) {
17948
17948
  super(message);
17949
17949
  this.name = "HttpError";
17950
- this.status = status;
17950
+ this.status = status2;
17951
17951
  this.body = body;
17952
17952
  }
17953
17953
  };
@@ -38938,12 +38938,12 @@ fi
38938
38938
  }
38939
38939
  function legacyGlobalHookScript(spec) {
38940
38940
  const chainExit = spec.hookName === PRE_COMMIT.hookName ? "|| exit $?" : "|| true";
38941
- const managedBlock = spec.hookName === POST_COMMIT.hookName ? legacyPostCommitBlock() : spec.hookName === POST_REWRITE.hookName ? legacyPostRewriteBlock() : void 0;
38942
- const invocation = managedBlock ?? gatedShim(spec.binName);
38943
- const managedRepoGuard = managedBlock ? ` && ! grep -Fq '${blockMarkers2(spec).start.slice(0, -3)}'">>>" "$repo_hook" 2>/dev/null` : "";
38944
- const beforeComments = managedBlock ? `${invocation}
38941
+ const managedBlock2 = spec.hookName === POST_COMMIT.hookName ? legacyPostCommitBlock() : spec.hookName === POST_REWRITE.hookName ? legacyPostRewriteBlock() : void 0;
38942
+ const invocation = managedBlock2 ?? gatedShim(spec.binName);
38943
+ const managedRepoGuard = managedBlock2 ? ` && ! grep -Fq '${blockMarkers2(spec).start.slice(0, -3)}'">>>" "$repo_hook" 2>/dev/null` : "";
38944
+ const beforeComments = managedBlock2 ? `${invocation}
38945
38945
  ` : "";
38946
- const afterComments = managedBlock ? "" : `${invocation}
38946
+ const afterComments = managedBlock2 ? "" : `${invocation}
38947
38947
  `;
38948
38948
  return `#!/bin/sh
38949
38949
  ${beforeComments}# prim global ${spec.hookName} hook (core.hooksPath) \u2014 managed by prim; do not edit.
@@ -40678,9 +40678,9 @@ async function pollGitHubInstallIntent(client, start, options = {}) {
40678
40678
  if (now() >= start.expiresAt) return expiredStatus(start);
40679
40679
  throw error;
40680
40680
  }
40681
- const status = parseGitHubInstallIntentStatus(raw, start.expiresAt);
40682
- if (!status) throw new Error("server returned an invalid GitHub install-intent status");
40683
- if (status.status !== "pending" && status.status !== "claimed") return status;
40681
+ const status2 = parseGitHubInstallIntentStatus(raw, start.expiresAt);
40682
+ if (!status2) throw new Error("server returned an invalid GitHub install-intent status");
40683
+ if (status2.status !== "pending" && status2.status !== "claimed") return status2;
40684
40684
  }
40685
40685
  }
40686
40686
 
@@ -40794,8 +40794,8 @@ function parseRevokeResponse(value) {
40794
40794
  const parsed = record(value);
40795
40795
  return parsed !== void 0 && hasExactKeys(parsed, ["apiKeyId", "revoked"]) && isApiKeyId(parsed.apiKeyId) && parsed.revoked === true ? { apiKeyId: parsed.apiKeyId, revoked: true } : void 0;
40796
40796
  }
40797
- function failure(code, exitCode, status) {
40798
- return { code, exitCode, ...status === void 0 ? {} : { status } };
40797
+ function failure(code, exitCode, status2) {
40798
+ return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
40799
40799
  }
40800
40800
  function classifyHttpError(error, operation, dispatched) {
40801
40801
  if (error.status === 401) {
@@ -41255,12 +41255,12 @@ function hasStoredRefreshToken() {
41255
41255
  return false;
41256
41256
  }
41257
41257
  }
41258
- function authStatusResult(status, reason, source, refreshTokenPresent) {
41258
+ function authStatusResult(status2, reason, source, refreshTokenPresent) {
41259
41259
  const expiresAt = source === "token_file" ? getTokenExpiresAt() : void 0;
41260
41260
  const expiresInMs = expiresAt === void 0 ? null : expiresAt - Date.now();
41261
41261
  return {
41262
- authenticated: status === "valid",
41263
- status,
41262
+ authenticated: status2 === "valid",
41263
+ status: status2,
41264
41264
  reason,
41265
41265
  tokenFile: source === "token_file" ? TOKEN_FILE_PATH : null,
41266
41266
  accessTokenExpiresInMs: expiresInMs,
@@ -41330,9 +41330,9 @@ async function verifyAuthStatus() {
41330
41330
  );
41331
41331
  }
41332
41332
  }
41333
- function authStatusExitCode(status) {
41334
- if (status === "valid") return EXIT_OK;
41335
- return status === "invalid" ? EXIT_FAIL : EXIT_UNREACHABLE;
41333
+ function authStatusExitCode(status2) {
41334
+ if (status2 === "valid") return EXIT_OK;
41335
+ return status2 === "invalid" ? EXIT_FAIL : EXIT_UNREACHABLE;
41336
41336
  }
41337
41337
  function writeHumanAuthStatus(result) {
41338
41338
  if (result.status === "invalid") {
@@ -41439,8 +41439,8 @@ ${verificationUrl}`);
41439
41439
  const state = base64url(randomBytes5(16));
41440
41440
  const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
41441
41441
  let settle;
41442
- const outcome = new Promise((resolve14) => {
41443
- settle = resolve14;
41442
+ const outcome = new Promise((resolve15) => {
41443
+ settle = resolve15;
41444
41444
  });
41445
41445
  const server = createServer((req, res) => {
41446
41446
  const url = new URL(req.url ?? "/", `http://${LOCALHOST}`);
@@ -41454,12 +41454,12 @@ ${verificationUrl}`);
41454
41454
  res.end(page.html, () => settle(page.result));
41455
41455
  });
41456
41456
  try {
41457
- await new Promise((resolve14, reject) => {
41457
+ await new Promise((resolve15, reject) => {
41458
41458
  const onError = (err) => reject(err);
41459
41459
  server.once("error", onError);
41460
41460
  server.listen(CALLBACK_PORT, LOCALHOST, () => {
41461
41461
  server.removeListener("error", onError);
41462
- resolve14();
41462
+ resolve15();
41463
41463
  });
41464
41464
  });
41465
41465
  } catch (err) {
@@ -41652,16 +41652,16 @@ function reportBinding(binding, installAttempted = false) {
41652
41652
  printJson(binding);
41653
41653
  process.exitCode = EXIT_UNBOUND;
41654
41654
  }
41655
- function terminalInstallError(status) {
41656
- if (status.status === "failed_terminal") {
41657
- if (status.failureCode === "repository_identity_migration_required") {
41655
+ function terminalInstallError(status2) {
41656
+ if (status2.status === "failed_terminal") {
41657
+ if (status2.failureCode === "repository_identity_migration_required") {
41658
41658
  return new Error(
41659
41659
  "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."
41660
41660
  );
41661
41661
  }
41662
- return new Error(`GitHub installation failed: ${status.failureCode}`);
41662
+ return new Error(`GitHub installation failed: ${status2.failureCode}`);
41663
41663
  }
41664
- return new Error(`GitHub installation ${status.status}`);
41664
+ return new Error(`GitHub installation ${status2.status}`);
41665
41665
  }
41666
41666
  async function completeInstallIntent(client, start, dependencies, browser) {
41667
41667
  process.stderr.write(`[prim] complete GitHub App installation at:
@@ -41689,15 +41689,15 @@ async function runGithubConnect(dependencies = defaultDependencies3, options = {
41689
41689
  signal: AbortSignal.timeout(START_TIMEOUT_MS),
41690
41690
  now: dependencies.now
41691
41691
  });
41692
- const status = await completeInstallIntent(
41692
+ const status2 = await completeInstallIntent(
41693
41693
  client,
41694
41694
  start,
41695
41695
  dependencies,
41696
41696
  options.browser ?? true
41697
41697
  );
41698
- if (status.status !== "consumed") throw terminalInstallError(status);
41698
+ if (status2.status !== "consumed") throw terminalInstallError(status2);
41699
41699
  process.stderr.write(
41700
- `[prim] GitHub installation verified: ${status.adminRepositoryCount} admin repositories (${status.repositoryCount} total)
41700
+ `[prim] GitHub installation verified: ${status2.adminRepositoryCount} admin repositories (${status2.repositoryCount} total)
41701
41701
  `
41702
41702
  );
41703
41703
  const binding = await dependencies.bindRepositoryWithClient(root, client, {
@@ -42967,7 +42967,7 @@ async function inspectCodexHost(reload = false) {
42967
42967
  } catch {
42968
42968
  return unavailable("host-socket-unavailable");
42969
42969
  }
42970
- return new Promise((resolve14) => {
42970
+ return new Promise((resolve15) => {
42971
42971
  let finished = false;
42972
42972
  let refreshed = false;
42973
42973
  let requestId = 0;
@@ -42983,7 +42983,7 @@ async function inspectCodexHost(reload = false) {
42983
42983
  finished = true;
42984
42984
  clearTimeout(timer);
42985
42985
  socket.terminate();
42986
- resolve14(value);
42986
+ resolve15(value);
42987
42987
  };
42988
42988
  const fail = (reason) => finish({ ...unavailable(reason), ...refreshed ? { reload: "refreshed" } : {} });
42989
42989
  const timer = setTimeout(() => fail("host-timeout"), TIMEOUT_MS);
@@ -43188,8 +43188,8 @@ function performStatus2() {
43188
43188
  };
43189
43189
  return { user: statusFor2(userScopePath()), project: statusFor2(projectScopePath2()) };
43190
43190
  }
43191
- function uncoveredWorktreeHooks(status) {
43192
- if (status.user.present || status.project.present) return null;
43191
+ function uncoveredWorktreeHooks(status2) {
43192
+ if (status2.user.present || status2.project.present) return null;
43193
43193
  const main = mainWorktreeRoot();
43194
43194
  if (main === null) return null;
43195
43195
  const path9 = join16(main, ".codex", "hooks.json");
@@ -43579,7 +43579,7 @@ async function runPinnedEnsure(options) {
43579
43579
  npm_config_fetch_retry_maxtimeout: "5000",
43580
43580
  npm_config_fetch_timeout: "15000"
43581
43581
  };
43582
- return await new Promise((resolve14) => {
43582
+ return await new Promise((resolve15) => {
43583
43583
  let settled = false;
43584
43584
  let child;
43585
43585
  try {
@@ -43589,7 +43589,7 @@ async function runPinnedEnsure(options) {
43589
43589
  { env: env4, stdio: "ignore" }
43590
43590
  );
43591
43591
  } catch {
43592
- resolve14(false);
43592
+ resolve15(false);
43593
43593
  return;
43594
43594
  }
43595
43595
  const timer = setTimeout(() => {
@@ -43600,7 +43600,7 @@ async function runPinnedEnsure(options) {
43600
43600
  if (settled) return;
43601
43601
  settled = true;
43602
43602
  clearTimeout(timer);
43603
- resolve14(result);
43603
+ resolve15(result);
43604
43604
  };
43605
43605
  timer.unref();
43606
43606
  child.once("error", () => finish(false));
@@ -44900,7 +44900,7 @@ function repositoryBindingDiagnosticLabel(state) {
44900
44900
  }
44901
44901
  var STATUSLINE_NAME_CAP = 3;
44902
44902
  function formatStatusline(version, snapshot, resolveIngestionStatus, options = {}) {
44903
- const ingestionSuffix = (status) => status === void 0 ? "" : ` \xB7 Decision ingestion ${status}`;
44903
+ const ingestionSuffix = (status2) => status2 === void 0 ? "" : ` \xB7 Decision ingestion ${status2}`;
44904
44904
  const ingestionStatus = snapshot === null || snapshot.healthy === false ? options.includeIngestionWhenUnavailable ? resolveIngestionStatus() : void 0 : resolveIngestionStatus();
44905
44905
  if (snapshot?.healthy === false && snapshot.needsReauth) {
44906
44906
  return `primitive ${version} (daemon: paused \xB7 run \`prim auth login\`${ingestionSuffix(ingestionStatus)})`;
@@ -45014,7 +45014,7 @@ function clearStaleArtifacts() {
45014
45014
  }
45015
45015
  }
45016
45016
  function sleep(ms) {
45017
- return new Promise((resolve14) => setTimeout(resolve14, ms));
45017
+ return new Promise((resolve15) => setTimeout(resolve15, ms));
45018
45018
  }
45019
45019
  function spawnDaemon(options) {
45020
45020
  const file = binFile(DAEMON_BIN);
@@ -46393,8 +46393,8 @@ function formatSuccessHuman(operation, request2, response) {
46393
46393
  );
46394
46394
  return `[prim] ${identifier} superseded by ${replacement}.`;
46395
46395
  }
46396
- function failure2(code, exitCode, status) {
46397
- return { code, exitCode, ...status === void 0 ? {} : { status } };
46396
+ function failure2(code, exitCode, status2) {
46397
+ return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
46398
46398
  }
46399
46399
  function classifyHttpError2(error) {
46400
46400
  if (error.status === 401) {
@@ -46744,8 +46744,8 @@ function parseProposal(value, path9) {
46744
46744
  if (!REPO_FULL_NAME_RE.test(repoFullName)) {
46745
46745
  contractError(`${path9}.repoFullName`, "must be canonical owner/repository syntax");
46746
46746
  }
46747
- const status = record3.status;
46748
- if (status !== "proposed" && status !== "confirmed" && status !== "verification_failed") {
46747
+ const status2 = record3.status;
46748
+ if (status2 !== "proposed" && status2 !== "confirmed" && status2 !== "verification_failed") {
46749
46749
  contractError(`${path9}.status`, "is not a review-visible proposal status");
46750
46750
  }
46751
46751
  if (!Array.isArray(record3.signals) || record3.signals.length > MAX_SIGNALS) {
@@ -46770,7 +46770,7 @@ function parseProposal(value, path9) {
46770
46770
  _id: asString(record3._id, `${path9}._id`, { max: 256, nonempty: true }),
46771
46771
  repoFullName,
46772
46772
  deadCommitSha: asSha(record3.deadCommitSha, `${path9}.deadCommitSha`),
46773
- status,
46773
+ status: status2,
46774
46774
  proposedSha,
46775
46775
  proposedTier,
46776
46776
  signals,
@@ -46781,15 +46781,15 @@ function parseProposal(value, path9) {
46781
46781
  function parseDecision(value, path9) {
46782
46782
  const record3 = asRecord(value, path9);
46783
46783
  assertKeys(record3, path9, ["_id", "intent", "status", "intentTruncated"], ["shortId"]);
46784
- const status = record3.status;
46785
- if (status !== "provisional" && status !== "abandoned") {
46784
+ const status2 = record3.status;
46785
+ if (status2 !== "provisional" && status2 !== "abandoned") {
46786
46786
  contractError(`${path9}.status`, "is not a repairable decision status");
46787
46787
  }
46788
46788
  return {
46789
46789
  _id: asString(record3._id, `${path9}._id`, { max: 256, nonempty: true }),
46790
46790
  shortId: optionalString(record3, "shortId", path9, 128),
46791
46791
  intent: asString(record3.intent, `${path9}.intent`, { max: MAX_INTENT_LENGTH }),
46792
- status,
46792
+ status: status2,
46793
46793
  intentTruncated: asBoolean(record3.intentTruncated, `${path9}.intentTruncated`)
46794
46794
  };
46795
46795
  }
@@ -47220,8 +47220,8 @@ function projectSuccess2(response) {
47220
47220
  ...response.scopeWarnings === void 0 ? {} : { scopeWarnings: response.scopeWarnings }
47221
47221
  };
47222
47222
  }
47223
- function failure3(code, exitCode, status) {
47224
- return { code, exitCode, ...status === void 0 ? {} : { status } };
47223
+ function failure3(code, exitCode, status2) {
47224
+ return { code, exitCode, ...status2 === void 0 ? {} : { status: status2 } };
47225
47225
  }
47226
47226
  function classifyHttpError3(error) {
47227
47227
  if (error.status === 401) {
@@ -47324,12 +47324,12 @@ async function rescopeDecision(request2, dependencies = defaultDependencies5) {
47324
47324
 
47325
47325
  // src/decisions/show.ts
47326
47326
  var NOT_FOUND_RE4 = /not found/i;
47327
- function colorStatus(status) {
47328
- const safeStatus = terminalSafeLine(status);
47329
- if (status === "under_review" || status === "provisional") {
47327
+ function colorStatus(status2) {
47328
+ const safeStatus = terminalSafeLine(status2);
47329
+ if (status2 === "under_review" || status2 === "provisional") {
47330
47330
  return color(safeStatus, "orange");
47331
47331
  }
47332
- if (status === "active" || status === "adopted") {
47332
+ if (status2 === "active" || status2 === "adopted") {
47333
47333
  return color(safeStatus, "green");
47334
47334
  }
47335
47335
  return color(safeStatus, "gray");
@@ -56751,10 +56751,10 @@ var CONNECTIVITY_TIMEOUT_MS = 3e3;
56751
56751
  var STALE_PENDING_MS = 3e4;
56752
56752
  var EXIT_UNHEALTHY = 1;
56753
56753
  function classifyDoctor(checks) {
56754
- const status = checks.some((c) => c.status === "fail") ? "fail" : checks.some((c) => c.status === "warn") ? "warn" : "ok";
56754
+ const status2 = checks.some((c) => c.status === "fail") ? "fail" : checks.some((c) => c.status === "warn") ? "warn" : "ok";
56755
56755
  return {
56756
- json: { ok: status !== "fail", status, checks },
56757
- exitCode: status === "fail" ? EXIT_UNHEALTHY : 0
56756
+ json: { ok: status2 !== "fail", status: status2, checks },
56757
+ exitCode: status2 === "fail" ? EXIT_UNHEALTHY : 0
56758
56758
  };
56759
56759
  }
56760
56760
  function classifyAuthCredential(credential, expiresAt, hasRefresh) {
@@ -57201,15 +57201,15 @@ function checkManagedHook(hookName, firing) {
57201
57201
  }
57202
57202
  function checkFeedbackHooks() {
57203
57203
  try {
57204
- const status = performStatus();
57205
- return classifyClaudeHooks([status.project, status.user]);
57204
+ const status2 = performStatus();
57205
+ return classifyClaudeHooks([status2.project, status2.user]);
57206
57206
  } catch (error) {
57207
57207
  const message = error instanceof Error ? error.message : String(error);
57208
57208
  return { name: "feedback-hooks", status: "warn", detail: message.slice(0, 80) };
57209
57209
  }
57210
57210
  }
57211
57211
  function classifyClaudeHooks(statuses) {
57212
- const installed = statuses.filter((status) => status.present);
57212
+ const installed = statuses.filter((status2) => status2.present);
57213
57213
  if (installed.length === 0) {
57214
57214
  return {
57215
57215
  name: "feedback-hooks",
@@ -57217,7 +57217,7 @@ function classifyClaudeHooks(statuses) {
57217
57217
  detail: "Claude lifecycle hooks missing \u2014 run `prim claude install`"
57218
57218
  };
57219
57219
  }
57220
- if (installed.some((status) => !status.complete)) {
57220
+ if (installed.some((status2) => !status2.complete)) {
57221
57221
  return {
57222
57222
  name: "feedback-hooks",
57223
57223
  status: "fail",
@@ -57227,7 +57227,7 @@ function classifyClaudeHooks(statuses) {
57227
57227
  return { name: "feedback-hooks", status: "ok", detail: "complete Claude lifecycle ready" };
57228
57228
  }
57229
57229
  function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host) {
57230
- const installed = statuses.filter((status) => status.present);
57230
+ const installed = statuses.filter((status2) => status2.present);
57231
57231
  if (installed.length === 0) {
57232
57232
  if (uncoveredWorktree !== null) {
57233
57233
  return {
@@ -57238,7 +57238,7 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
57238
57238
  }
57239
57239
  return { name: "codex-hooks", status: "ok", detail: "not installed" };
57240
57240
  }
57241
- if (installed.some((status) => !status.complete)) {
57241
+ if (installed.some((status2) => !status2.complete)) {
57242
57242
  return {
57243
57243
  name: "codex-hooks",
57244
57244
  status: "fail",
@@ -57252,17 +57252,17 @@ function classifyCodexHooks(statuses, uncoveredWorktree = null, capturedAt, host
57252
57252
  };
57253
57253
  }
57254
57254
  function classifyCursorHooks(statuses) {
57255
- const installed = statuses.filter((status) => status.present);
57255
+ const installed = statuses.filter((status2) => status2.present);
57256
57256
  if (installed.length === 0)
57257
57257
  return { name: "cursor-hooks", status: "ok", detail: "not installed" };
57258
- if (installed.some((status) => !status.complete)) {
57258
+ if (installed.some((status2) => !status2.complete)) {
57259
57259
  return {
57260
57260
  name: "cursor-hooks",
57261
57261
  status: "fail",
57262
57262
  detail: "incomplete or drifted native lifecycle \u2014 run `prim cursor install --force`"
57263
57263
  };
57264
57264
  }
57265
- const user = statuses.find((status) => status.footer !== void 0);
57265
+ const user = statuses.find((status2) => status2.footer !== void 0);
57266
57266
  if (user?.present && user.footer === false && !user.footerPreservedCustom) {
57267
57267
  return {
57268
57268
  name: "cursor-hooks",
@@ -57270,7 +57270,7 @@ function classifyCursorHooks(statuses) {
57270
57270
  detail: "native lifecycle ready but Cursor CLI footer is missing \u2014 run `prim cursor install --scope user --force`"
57271
57271
  };
57272
57272
  }
57273
- if (statuses.some((status) => status.footerPreservedCustom)) {
57273
+ if (statuses.some((status2) => status2.footerPreservedCustom)) {
57274
57274
  return {
57275
57275
  name: "cursor-hooks",
57276
57276
  status: "warn",
@@ -57279,18 +57279,18 @@ function classifyCursorHooks(statuses) {
57279
57279
  }
57280
57280
  return { name: "cursor-hooks", status: "ok", detail: "complete native lifecycle ready" };
57281
57281
  }
57282
- function classifyHermesHooks(status) {
57283
- if (!status.present) {
57282
+ function classifyHermesHooks(status2) {
57283
+ if (!status2.present) {
57284
57284
  return { name: "hermes-hooks", status: "ok", detail: "not installed" };
57285
57285
  }
57286
- if (!status.complete) {
57286
+ if (!status2.complete) {
57287
57287
  return {
57288
57288
  name: "hermes-hooks",
57289
57289
  status: "fail",
57290
57290
  detail: "incomplete or drifted hook lifecycle \u2014 run `prim hermes install --force`"
57291
57291
  };
57292
57292
  }
57293
- return status.autoAccept ? { name: "hermes-hooks", status: "ok", detail: "installed and pre-authorized" } : {
57293
+ return status2.autoAccept ? { name: "hermes-hooks", status: "ok", detail: "installed and pre-authorized" } : {
57294
57294
  name: "hermes-hooks",
57295
57295
  status: "warn",
57296
57296
  detail: "installed; hook consent is not pre-authorized \u2014 run `prim hermes install --auto-accept`"
@@ -57299,13 +57299,13 @@ function classifyHermesHooks(status) {
57299
57299
  async function checkAgentHooks() {
57300
57300
  const checks = [];
57301
57301
  try {
57302
- const status = performStatus2();
57302
+ const status2 = performStatus2();
57303
57303
  checks.push(
57304
57304
  classifyCodexHooks(
57305
- [status.project, status.user],
57306
- uncoveredWorktreeHooks(status),
57305
+ [status2.project, status2.user],
57306
+ uncoveredWorktreeHooks(status2),
57307
57307
  lastConversationCaptured(process.cwd(), "codex"),
57308
- status.user.present || status.project.present ? await inspectCodexHost() : void 0
57308
+ status2.user.present || status2.project.present ? await inspectCodexHost() : void 0
57309
57309
  )
57310
57310
  );
57311
57311
  } catch (error) {
@@ -57317,8 +57317,8 @@ async function checkAgentHooks() {
57317
57317
  });
57318
57318
  }
57319
57319
  try {
57320
- const status = performStatus3();
57321
- checks.push(classifyCursorHooks([status.project, status.user]));
57320
+ const status2 = performStatus3();
57321
+ checks.push(classifyCursorHooks([status2.project, status2.user]));
57322
57322
  } catch (error) {
57323
57323
  const detail = boundedHealthError(error instanceof Error ? error.message : String(error));
57324
57324
  checks.push({
@@ -57457,26 +57457,26 @@ function parseMovesStatus(value) {
57457
57457
  if (!value || typeof value !== "object") {
57458
57458
  throw new Error("moves status returned a non-object response");
57459
57459
  }
57460
- const status = value;
57460
+ const status2 = value;
57461
57461
  const nullableNumber = (candidate) => candidate === null || typeof candidate === "number" && Number.isFinite(candidate);
57462
- if (status.captureState !== "enabled" || !nullableNumber(status.latestIngestAt) || !nullableNumber(status.latestClassificationAt) || !nullableNumber(status.highWaterMark) || typeof status.pendingSessionCount !== "number" || !Number.isInteger(status.pendingSessionCount) || status.pendingSessionCount < 0 || typeof status.sampled !== "boolean") {
57462
+ 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") {
57463
57463
  throw new Error("moves status returned an invalid response");
57464
57464
  }
57465
- if (status.oldestPendingAt !== void 0 && !nullableNumber(status.oldestPendingAt) || status.oldestPendingAgeMs !== void 0 && !nullableNumber(status.oldestPendingAgeMs) || typeof status.oldestPendingAgeMs === "number" && status.oldestPendingAgeMs < 0 || status.pendingCommitCorrelationCount !== void 0 && (!Number.isInteger(status.pendingCommitCorrelationCount) || status.pendingCommitCorrelationCount < 0)) {
57465
+ 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)) {
57466
57466
  throw new Error("moves status returned invalid pending-age fields");
57467
57467
  }
57468
- return status;
57468
+ return status2;
57469
57469
  }
57470
- function classifyMovesStatus(status) {
57470
+ function classifyMovesStatus(status2) {
57471
57471
  const capture = {
57472
57472
  name: "capture",
57473
57473
  status: "ok",
57474
57474
  detail: "enabled; ingest endpoint durable"
57475
57475
  };
57476
- const correlation = status.pendingCommitCorrelationCount === void 0 ? void 0 : status.pendingCommitCorrelationCount > 0 ? {
57476
+ const correlation = status2.pendingCommitCorrelationCount === void 0 ? void 0 : status2.pendingCommitCorrelationCount > 0 ? {
57477
57477
  name: "commit-correlation",
57478
57478
  status: "warn",
57479
- detail: `${String(status.pendingCommitCorrelationCount)} commit(s) awaiting evidence correlation`
57479
+ detail: `${String(status2.pendingCommitCorrelationCount)} commit(s) awaiting evidence correlation`
57480
57480
  } : {
57481
57481
  name: "commit-correlation",
57482
57482
  status: "ok",
@@ -57489,10 +57489,10 @@ async function checkBackend() {
57489
57489
  const response = await getClient().get("/api/cli/moves/status", {
57490
57490
  signal: AbortSignal.timeout(CONNECTIVITY_TIMEOUT_MS)
57491
57491
  });
57492
- const status = parseMovesStatus(response);
57492
+ const status2 = parseMovesStatus(response);
57493
57493
  return [
57494
57494
  { name: "connectivity", status: "ok", detail: "server reachable and authenticated" },
57495
- ...classifyMovesStatus(status)
57495
+ ...classifyMovesStatus(status2)
57496
57496
  ];
57497
57497
  } catch (err) {
57498
57498
  const message = err instanceof Error ? err.message : String(err);
@@ -57553,8 +57553,8 @@ async function collectChecks(options, probes) {
57553
57553
  (check) => !(options.agent && options.agent !== "claude" && check.name === "feedback-hooks" && check.detail.startsWith("Claude lifecycle hooks missing"))
57554
57554
  );
57555
57555
  }
57556
- function icon(status) {
57557
- return status === "ok" ? "\u2713" : status === "warn" ? "\u26A0" : "\u2717";
57556
+ function icon(status2) {
57557
+ return status2 === "ok" ? "\u2713" : status2 === "warn" ? "\u26A0" : "\u2717";
57558
57558
  }
57559
57559
  async function runDoctor(options, probes) {
57560
57560
  const checks = await collectChecks(options, probes);
@@ -57583,21 +57583,376 @@ function registerDoctorCommands(program3, dependencies = {}) {
57583
57583
  });
57584
57584
  }
57585
57585
 
57586
+ // src/commands/gameplan.ts
57587
+ import { createHash as createHash11 } from "crypto";
57588
+ import { existsSync as existsSync20, lstatSync as lstatSync11, readFileSync as readFileSync21, readdirSync as readdirSync9, rmdirSync as rmdirSync3, unlinkSync as unlinkSync6 } from "fs";
57589
+ import { homedir as homedir11 } from "os";
57590
+ import { dirname as dirname14, join as join28, resolve as resolve10 } from "path";
57591
+ import { fileURLToPath as fileURLToPath4 } from "url";
57592
+ var __dirname4 = dirname14(fileURLToPath4(import.meta.url));
57593
+ var SKILL_NAME = "primitive-gameplan";
57594
+ var MANIFEST_NAME = ".prim-managed.json";
57595
+ var MANIFEST_OWNER = "@primitive.ai/prim:gameplan:v1";
57596
+ var START = "<!-- BEGIN PRIMITIVE GAMEPLAN v1 -->";
57597
+ var END = "<!-- END PRIMITIVE GAMEPLAN v1 -->";
57598
+ var HOOK_MARKER = "prim-gameplan-hook-v1";
57599
+ 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';
57600
+ var ASSET_FILES = ["SKILL.md", "scripts/activate.mjs", "claude-hooks.json"];
57601
+ var AGENTS_BLOCK = `${START}
57602
+ When using $write-gameplan or $write-workstream, read and follow
57603
+ .agents/skills/primitive-gameplan/SKILL.md before architectural discussion.
57604
+ Keep the public planning skills unchanged.
57605
+ ${END}`;
57606
+ function packageRoot2() {
57607
+ let directory = __dirname4;
57608
+ while (directory !== dirname14(directory)) {
57609
+ if (existsSync20(join28(directory, "assets", SKILL_NAME, "SKILL.md"))) return directory;
57610
+ directory = dirname14(directory);
57611
+ }
57612
+ throw new Error("Primitive gameplan assets are missing from this CLI package");
57613
+ }
57614
+ function packageVersion2(root) {
57615
+ const parsed = JSON.parse(readFileSync21(join28(root, "package.json"), "utf8"));
57616
+ if (typeof parsed.version !== "string") throw new Error("CLI package version is missing");
57617
+ return parsed.version;
57618
+ }
57619
+ function sha2563(content) {
57620
+ return createHash11("sha256").update(content).digest("hex");
57621
+ }
57622
+ function pathsFor(cwd) {
57623
+ const root = gitToplevel(cwd);
57624
+ if (root === null) throw new Error("Run prim gameplan from a Git worktree");
57625
+ const skillDir = join28(root, ".agents", "skills", SKILL_NAME);
57626
+ const codexHome = process.env.CODEX_HOME?.trim() ? resolve10(process.env.CODEX_HOME) : join28(homedir11(), ".codex");
57627
+ return {
57628
+ root,
57629
+ skillDir,
57630
+ manifest: join28(skillDir, MANIFEST_NAME),
57631
+ agents: join28(root, "AGENTS.md"),
57632
+ agentsOverride: join28(root, "AGENTS.override.md"),
57633
+ userHooks: join28(codexHome, "hooks.json")
57634
+ };
57635
+ }
57636
+ function readRegularFile(path9) {
57637
+ let entry;
57638
+ try {
57639
+ entry = lstatSync11(path9);
57640
+ } catch (error) {
57641
+ if (error.code === "ENOENT") return null;
57642
+ throw error;
57643
+ }
57644
+ if (!entry.isFile()) throw new Error(`Refusing non-regular file at ${path9}`);
57645
+ return readFileSync21(path9, "utf8");
57646
+ }
57647
+ function readManifest(path9) {
57648
+ const content = readRegularFile(path9);
57649
+ if (content === null) return null;
57650
+ let value;
57651
+ try {
57652
+ value = JSON.parse(content);
57653
+ } catch {
57654
+ throw new Error(`Invalid Primitive gameplan manifest at ${path9}`);
57655
+ }
57656
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
57657
+ throw new Error(`Invalid Primitive gameplan manifest at ${path9}`);
57658
+ }
57659
+ const record3 = value;
57660
+ 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") {
57661
+ throw new Error(`Unknown or incomplete Primitive gameplan manifest at ${path9}`);
57662
+ }
57663
+ return record3;
57664
+ }
57665
+ function managedBlock(content) {
57666
+ const begin = content.indexOf(START);
57667
+ const end = content.indexOf(END);
57668
+ if (begin === -1 && end === -1) return null;
57669
+ if (begin === -1 || end < begin || content.indexOf(START, begin + START.length) !== -1 || content.indexOf(END, end + END.length) !== -1) {
57670
+ throw new Error("AGENTS.md has malformed Primitive gameplan markers");
57671
+ }
57672
+ return content.slice(begin, end + END.length);
57673
+ }
57674
+ function blockSeparator(content) {
57675
+ if (content.length === 0 || content.endsWith("\n\n")) return "";
57676
+ return content.endsWith("\n") ? "\n" : "\n\n";
57677
+ }
57678
+ function upsertBlock(content) {
57679
+ const current = managedBlock(content);
57680
+ if (current !== null) return content.replace(current, AGENTS_BLOCK);
57681
+ return `${content}${blockSeparator(content)}${AGENTS_BLOCK}
57682
+ `;
57683
+ }
57684
+ function removeBlock(content, separator) {
57685
+ const block = managedBlock(content);
57686
+ if (block === null) return content;
57687
+ const start = content.indexOf(block);
57688
+ let before = content.slice(0, start);
57689
+ if (separator.length > 0 && before.endsWith(separator)) {
57690
+ before = before.slice(0, -separator.length);
57691
+ }
57692
+ const after = content.slice(start + block.length);
57693
+ return `${before}${after.replace(/^\n/u, "")}`;
57694
+ }
57695
+ function publicSkillPath(paths) {
57696
+ const codexHome = dirname14(paths.userHooks);
57697
+ const candidates = [
57698
+ join28(paths.root, ".agents", "skills", "write-gameplan", "SKILL.md"),
57699
+ join28(codexHome, "skills", "write-gameplan", "SKILL.md"),
57700
+ join28(homedir11(), ".agents", "skills", "write-gameplan", "SKILL.md")
57701
+ ];
57702
+ for (const path9 of candidates) {
57703
+ try {
57704
+ const content = readFileSync21(path9, "utf8");
57705
+ if (/^name:\s*write-gameplan\s*$/mu.test(content)) return path9;
57706
+ } catch {
57707
+ }
57708
+ }
57709
+ return null;
57710
+ }
57711
+ function assetContents() {
57712
+ const root = packageRoot2();
57713
+ return Object.fromEntries(
57714
+ ASSET_FILES.map((file) => [file, readFileSync21(join28(root, "assets", SKILL_NAME, file), "utf8")])
57715
+ );
57716
+ }
57717
+ function markedHookCommands(settings) {
57718
+ const entries = settings.hooks?.UserPromptSubmit ?? [];
57719
+ if (!Array.isArray(entries)) throw new Error("Codex UserPromptSubmit hooks are not an array");
57720
+ return entries.flatMap(
57721
+ (entry) => (entry.hooks ?? []).flatMap(
57722
+ (hook) => typeof hook.command === "string" && hook.command.includes(HOOK_MARKER) ? [hook.command] : []
57723
+ )
57724
+ );
57725
+ }
57726
+ function ensureUserHook(settings) {
57727
+ const marked = markedHookCommands(settings);
57728
+ if (marked.some((command) => command !== HOOK_COMMAND)) {
57729
+ throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
57730
+ }
57731
+ if (marked.length > 1) throw new Error("Duplicate Primitive gameplan Codex hooks are present");
57732
+ if (marked.length === 1) return settings;
57733
+ const hooks = { ...settings.hooks ?? {} };
57734
+ hooks.UserPromptSubmit = [
57735
+ ...hooks.UserPromptSubmit ?? [],
57736
+ { hooks: [{ type: "command", command: HOOK_COMMAND }] }
57737
+ ];
57738
+ return { ...settings, hooks };
57739
+ }
57740
+ function removeUserHook(settings) {
57741
+ const marked = markedHookCommands(settings);
57742
+ if (marked.some((command) => command !== HOOK_COMMAND)) {
57743
+ throw new Error("A modified Primitive gameplan Codex hook is present; resolve it manually");
57744
+ }
57745
+ if (marked.length === 0) return settings;
57746
+ const hooks = { ...settings.hooks ?? {} };
57747
+ hooks.UserPromptSubmit = (hooks.UserPromptSubmit ?? []).flatMap((entry) => {
57748
+ const commands = (entry.hooks ?? []).filter((hook) => hook.command !== HOOK_COMMAND);
57749
+ return commands.length > 0 ? [{ ...entry, hooks: commands }] : [];
57750
+ });
57751
+ if (hooks.UserPromptSubmit.length === 0) hooks.UserPromptSubmit = void 0;
57752
+ return { ...settings, hooks };
57753
+ }
57754
+ function checkOwnedFiles(paths, manifest) {
57755
+ if (existsSync20(paths.skillDir) && !lstatSync11(paths.skillDir).isDirectory()) {
57756
+ throw new Error(`Refusing non-directory companion path at ${paths.skillDir}`);
57757
+ }
57758
+ if (manifest === null && existsSync20(paths.skillDir) && readdirSync9(paths.skillDir).length > 0) {
57759
+ throw new Error(`Refusing unowned companion files at ${paths.skillDir}`);
57760
+ }
57761
+ if (manifest === null) return;
57762
+ for (const file of ASSET_FILES) {
57763
+ const path9 = join28(paths.skillDir, file);
57764
+ const current = readRegularFile(path9);
57765
+ if (current !== null && sha2563(current) !== manifest.files[file] && sha2563(current) !== manifest.previousFiles?.[file]) {
57766
+ throw new Error(`Refusing modified companion file at ${path9}`);
57767
+ }
57768
+ }
57769
+ }
57770
+ function checkAgentsBlock(paths, manifest) {
57771
+ const content = readRegularFile(paths.agents) ?? "";
57772
+ const block = managedBlock(content);
57773
+ if (block !== null && (manifest === null || sha2563(block) !== manifest.agentsBlockHash && sha2563(block) !== manifest.previousAgentsBlockHash)) {
57774
+ throw new Error(`Refusing modified or unowned Primitive gameplan block in ${paths.agents}`);
57775
+ }
57776
+ return { content, created: manifest?.createdAgents ?? !existsSync20(paths.agents) };
57777
+ }
57778
+ function install(cwd) {
57779
+ const paths = pathsFor(cwd);
57780
+ const publicSkill = publicSkillPath(paths);
57781
+ if (publicSkill === null) {
57782
+ throw new Error(
57783
+ "Codex cannot find $write-gameplan. Install the public skill in .agents/skills/write-gameplan or ~/.codex/skills/write-gameplan, then retry."
57784
+ );
57785
+ }
57786
+ if ((readRegularFile(paths.agentsOverride) ?? "").trim().length > 0) {
57787
+ throw new Error(
57788
+ "AGENTS.override.md shadows AGENTS.md in this repository; remove the override or install the companion manually in the effective rules."
57789
+ );
57790
+ }
57791
+ const assets = assetContents();
57792
+ const manifest = readManifest(paths.manifest);
57793
+ checkOwnedFiles(paths, manifest);
57794
+ const agents = checkAgentsBlock(paths, manifest);
57795
+ const hooksBefore = readSettings(paths.userHooks);
57796
+ const hooksAfter = ensureUserHook(hooksBefore);
57797
+ const nextManifest = {
57798
+ owner: MANIFEST_OWNER,
57799
+ packageVersion: packageVersion2(packageRoot2()),
57800
+ files: Object.fromEntries(ASSET_FILES.map((file) => [file, sha2563(assets[file])])),
57801
+ ...manifest === null ? {} : { previousFiles: manifest.files },
57802
+ agentsBlockHash: sha2563(AGENTS_BLOCK),
57803
+ ...manifest === null ? {} : { previousAgentsBlockHash: manifest.agentsBlockHash },
57804
+ createdAgents: agents.created,
57805
+ agentsSeparator: manifest?.agentsSeparator ?? blockSeparator(agents.content)
57806
+ };
57807
+ atomicWriteFile(paths.manifest, `${JSON.stringify(nextManifest, null, 2)}
57808
+ `, {
57809
+ ensureParent: true
57810
+ });
57811
+ for (const file of ASSET_FILES) {
57812
+ const path9 = join28(paths.skillDir, file);
57813
+ if (readRegularFile(path9) !== assets[file]) {
57814
+ atomicWriteFile(path9, assets[file], { ensureParent: true });
57815
+ }
57816
+ }
57817
+ const agentsAfter = upsertBlock(agents.content);
57818
+ if (agentsAfter !== agents.content) {
57819
+ atomicWriteFile(paths.agents, agentsAfter, { ensureParent: true });
57820
+ }
57821
+ if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore)) {
57822
+ atomicWrite3(paths.userHooks, hooksAfter);
57823
+ }
57824
+ return { installed: true, root: paths.root, publicSkill, userHooks: paths.userHooks };
57825
+ }
57826
+ function status(cwd) {
57827
+ const paths = pathsFor(cwd);
57828
+ const manifest = readManifest(paths.manifest);
57829
+ const publicSkill = publicSkillPath(paths);
57830
+ const files = Object.fromEntries(
57831
+ ASSET_FILES.map((file) => {
57832
+ const current = readRegularFile(join28(paths.skillDir, file));
57833
+ return [
57834
+ file,
57835
+ current !== null && manifest !== null && sha2563(current) === manifest.files[file]
57836
+ ];
57837
+ })
57838
+ );
57839
+ const agents = readRegularFile(paths.agents) ?? "";
57840
+ const block = managedBlock(agents);
57841
+ const agentsBinding = block !== null && manifest !== null && sha2563(block) === manifest.agentsBlockHash;
57842
+ const agentsOverrideShadows = (readRegularFile(paths.agentsOverride) ?? "").trim().length > 0;
57843
+ const hooks = markedHookCommands(readSettings(paths.userHooks));
57844
+ const userHook = hooks.length === 1 && hooks[0] === HOOK_COMMAND;
57845
+ const installed = manifest !== null && Object.values(files).every(Boolean) && agentsBinding && !agentsOverrideShadows && userHook && publicSkill !== null;
57846
+ return {
57847
+ installed,
57848
+ root: paths.root,
57849
+ packageVersion: manifest?.packageVersion ?? null,
57850
+ files,
57851
+ agentsBinding,
57852
+ agentsOverrideShadows,
57853
+ userHook,
57854
+ publicSkill,
57855
+ userHooks: paths.userHooks
57856
+ };
57857
+ }
57858
+ function uninstall(cwd, removeSharedHook) {
57859
+ const paths = pathsFor(cwd);
57860
+ const manifest = readManifest(paths.manifest);
57861
+ if (manifest === null)
57862
+ return { uninstalled: false, reason: "No managed companion in this repository" };
57863
+ checkOwnedFiles(paths, manifest);
57864
+ const expected = /* @__PURE__ */ new Set(["SKILL.md", "claude-hooks.json", "scripts", MANIFEST_NAME]);
57865
+ const extras = readdirSync9(paths.skillDir).filter((entry) => !expected.has(entry));
57866
+ const scriptsPath = join28(paths.skillDir, "scripts");
57867
+ if (existsSync20(scriptsPath)) {
57868
+ extras.push(...readdirSync9(scriptsPath).filter((entry) => entry !== "activate.mjs"));
57869
+ }
57870
+ if (extras.length > 0) {
57871
+ throw new Error(`Refusing to remove unowned companion files: ${extras.join(", ")}`);
57872
+ }
57873
+ const agents = checkAgentsBlock(paths, manifest);
57874
+ const hooksBefore = readSettings(paths.userHooks);
57875
+ const hooksAfter = removeSharedHook ? removeUserHook(hooksBefore) : hooksBefore;
57876
+ const agentsAfter = removeBlock(agents.content, manifest.agentsSeparator);
57877
+ if (agentsAfter !== agents.content) {
57878
+ if (manifest.createdAgents && agentsAfter.trim().length === 0) {
57879
+ unlinkSync6(paths.agents);
57880
+ } else {
57881
+ atomicWriteFile(paths.agents, agentsAfter);
57882
+ }
57883
+ }
57884
+ for (const file of ASSET_FILES) {
57885
+ const path9 = join28(paths.skillDir, file);
57886
+ if (existsSync20(path9)) unlinkSync6(path9);
57887
+ }
57888
+ unlinkSync6(paths.manifest);
57889
+ if (existsSync20(scriptsPath)) rmdirSync3(scriptsPath);
57890
+ rmdirSync3(paths.skillDir);
57891
+ if (JSON.stringify(hooksAfter) !== JSON.stringify(hooksBefore))
57892
+ atomicWrite3(paths.userHooks, hooksAfter);
57893
+ return { uninstalled: true, root: paths.root, sharedUserHookRetained: !removeSharedHook };
57894
+ }
57895
+ function requireCodex(agent) {
57896
+ if (agent !== "codex") throw new Error(`Unsupported gameplan agent "${agent}" (expected codex)`);
57897
+ }
57898
+ function reportCommandError(error) {
57899
+ console.error(`[prim] ${error instanceof Error ? error.message : String(error)}`);
57900
+ process.exitCode = 1;
57901
+ }
57902
+ function registerGameplanCommands(program3) {
57903
+ const gameplan = program3.command("gameplan").description("Manage the Primitive Codex gameplanning companion");
57904
+ 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) => {
57905
+ try {
57906
+ requireCodex(opts.agent);
57907
+ const result = install(process.cwd());
57908
+ console.error(
57909
+ "[prim] Gameplan companion installed. Review Codex /hooks and start a fresh session."
57910
+ );
57911
+ console.log(JSON.stringify(result));
57912
+ } catch (error) {
57913
+ reportCommandError(error);
57914
+ }
57915
+ });
57916
+ gameplan.command("status").description("Check the companion, public skill, AGENTS binding, and user prompt hook").option("--agent <agent>", "agent host", "codex").action((opts) => {
57917
+ try {
57918
+ requireCodex(opts.agent);
57919
+ const result = status(process.cwd());
57920
+ console.error(
57921
+ 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."
57922
+ );
57923
+ console.log(JSON.stringify(result));
57924
+ if (!result.installed || result.publicSkill === null) process.exitCode = 1;
57925
+ } catch (error) {
57926
+ reportCommandError(error);
57927
+ }
57928
+ });
57929
+ 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) => {
57930
+ try {
57931
+ requireCodex(opts.agent);
57932
+ const result = uninstall(process.cwd(), opts.removeUserHook ?? false);
57933
+ console.error("[prim] Removed this repository's managed gameplan companion.");
57934
+ console.log(JSON.stringify(result));
57935
+ } catch (error) {
57936
+ reportCommandError(error);
57937
+ }
57938
+ });
57939
+ }
57940
+
57586
57941
  // src/commands/moves.ts
57587
- import { existsSync as existsSync21, mkdirSync as mkdirSync13, unlinkSync as unlinkSync7, writeFileSync as writeFileSync9 } from "fs";
57588
- import { join as join30 } from "path";
57942
+ import { existsSync as existsSync22, mkdirSync as mkdirSync13, unlinkSync as unlinkSync8, writeFileSync as writeFileSync9 } from "fs";
57943
+ import { join as join31 } from "path";
57589
57944
 
57590
57945
  // src/flusher.ts
57591
- import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as unlinkSync6 } from "fs";
57592
- import { dirname as dirname15, join as join29 } from "path";
57946
+ import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as unlinkSync7 } from "fs";
57947
+ import { dirname as dirname16, join as join30 } from "path";
57593
57948
 
57594
57949
  // src/dead-letter.ts
57595
- import { createHash as createHash11, randomBytes as randomBytes7 } from "crypto";
57950
+ import { createHash as createHash12, randomBytes as randomBytes7 } from "crypto";
57596
57951
  import {
57597
57952
  constants as constants6,
57598
57953
  chmodSync as chmodSync7,
57599
57954
  closeSync as closeSync6,
57600
- existsSync as existsSync20,
57955
+ existsSync as existsSync21,
57601
57956
  fchmodSync as fchmodSync3,
57602
57957
  fsyncSync as fsyncSync3,
57603
57958
  mkdirSync as mkdirSync12,
@@ -57606,30 +57961,30 @@ import {
57606
57961
  rmSync as rmSync8,
57607
57962
  writeFileSync as writeFileSync8
57608
57963
  } from "fs";
57609
- import { dirname as dirname14, join as join28 } from "path";
57964
+ import { dirname as dirname15, join as join29 } from "path";
57610
57965
  var DIRECTORY_MODE4 = 448;
57611
57966
  var FILE_MODE3 = 384;
57612
57967
  var DEAD_LETTER_DIRNAME = "dead-letter";
57613
57968
  function deadLetterDirectoryForRotation(flushingPath) {
57614
- return join28(dirname14(flushingPath), DEAD_LETTER_DIRNAME);
57969
+ return join29(dirname15(flushingPath), DEAD_LETTER_DIRNAME);
57615
57970
  }
57616
57971
  function deadLetterPathForRawLine(flushingPath, rawLine) {
57617
- const quarantineId = createHash11("sha256").update(rawLine).digest("hex");
57618
- return join28(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
57972
+ const quarantineId = createHash12("sha256").update(rawLine).digest("hex");
57973
+ return join29(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
57619
57974
  }
57620
57975
  function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
57621
57976
  const directory = deadLetterDirectoryForRotation(flushingPath);
57622
57977
  mkdirSync12(directory, { recursive: true, mode: DIRECTORY_MODE4 });
57623
57978
  chmodSync7(directory, DIRECTORY_MODE4);
57624
- persistDirectory(dirname14(directory));
57979
+ persistDirectory(dirname15(directory));
57625
57980
  return directory;
57626
57981
  }
57627
57982
  function persistDeadLetter(directory, path9, quarantineId, record3, persistDirectory) {
57628
- if (existsSync20(path9)) {
57983
+ if (existsSync21(path9)) {
57629
57984
  persistDirectory(directory);
57630
57985
  return;
57631
57986
  }
57632
- const temporaryPath = join28(
57987
+ const temporaryPath = join29(
57633
57988
  directory,
57634
57989
  `.${quarantineId}.${String(process.pid)}.${randomBytes7(8).toString("hex")}.tmp`
57635
57990
  );
@@ -57656,12 +58011,12 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
57656
58011
  const serializedMove = JSON.stringify(move);
57657
58012
  const record3 = {
57658
58013
  version: 1,
57659
- quarantineId: createHash11("sha256").update(serializedMove).digest("hex"),
58014
+ quarantineId: createHash12("sha256").update(serializedMove).digest("hex"),
57660
58015
  quarantinedAt: now(),
57661
58016
  reason,
57662
58017
  move
57663
58018
  };
57664
- const path9 = join28(directory, `${record3.quarantineId}.json`);
58019
+ const path9 = join29(directory, `${record3.quarantineId}.json`);
57665
58020
  persistDeadLetter(directory, path9, record3.quarantineId, record3, persistDirectory);
57666
58021
  return record3;
57667
58022
  }
@@ -57672,7 +58027,7 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
57672
58027
  const record3 = {
57673
58028
  version: 1,
57674
58029
  recordKind: "raw_line_v1",
57675
- quarantineId: createHash11("sha256").update(bytes).digest("hex"),
58030
+ quarantineId: createHash12("sha256").update(bytes).digest("hex"),
57676
58031
  quarantinedAt: now(),
57677
58032
  reason: "invalid_move",
57678
58033
  rawLineEncoding: "base64",
@@ -57941,7 +58296,7 @@ async function drainFlushingPath(flushingPath, client, binding, options = {}) {
57941
58296
  } finally {
57942
58297
  input.destroy();
57943
58298
  }
57944
- unlinkSync6(flushingPath);
58299
+ unlinkSync7(flushingPath);
57945
58300
  try {
57946
58301
  removeDrainCheckpoint(flushingPath);
57947
58302
  } catch {
@@ -58085,7 +58440,7 @@ async function flushOnce() {
58085
58440
  return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
58086
58441
  }
58087
58442
  var flushInFlight;
58088
- var FLUSH_LOCK_PATH = join29(dirname15(JOURNAL_DIR), ".flush.lock");
58443
+ var FLUSH_LOCK_PATH = join30(dirname16(JOURNAL_DIR), ".flush.lock");
58089
58444
  var FLUSH_LOCK_TIMEOUT_MS = 250;
58090
58445
  function isFlushLockContended(error) {
58091
58446
  return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
@@ -58217,23 +58572,23 @@ function registerMovesCommands(program3) {
58217
58572
  }
58218
58573
  });
58219
58574
  moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
58220
- const dir = join30(process.cwd(), ".prim");
58221
- if (!existsSync21(dir)) {
58575
+ const dir = join31(process.cwd(), ".prim");
58576
+ if (!existsSync22(dir)) {
58222
58577
  mkdirSync13(dir, { recursive: true, mode: DIR_MODE });
58223
58578
  }
58224
- const file = join30(process.cwd(), WORKSPACE_FILE);
58579
+ const file = join31(process.cwd(), WORKSPACE_FILE);
58225
58580
  writeFileSync9(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
58226
58581
  mode: FILE_MODE4
58227
58582
  });
58228
58583
  console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
58229
58584
  });
58230
58585
  moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
58231
- const file = join30(process.cwd(), WORKSPACE_FILE);
58232
- if (!existsSync21(file)) {
58586
+ const file = join31(process.cwd(), WORKSPACE_FILE);
58587
+ if (!existsSync22(file)) {
58233
58588
  console.log("[prim] no workspace binding in cwd");
58234
58589
  return;
58235
58590
  }
58236
- unlinkSync7(file);
58591
+ unlinkSync8(file);
58237
58592
  console.log(`[prim] dropped workspace binding from ${process.cwd()}`);
58238
58593
  });
58239
58594
  }
@@ -58289,10 +58644,10 @@ async function performResolution(idOrShortId, opts) {
58289
58644
  process.stderr.write(`[prim] recorded ${opts.outcome} for check ${opts.check}
58290
58645
  `);
58291
58646
  } catch (error) {
58292
- const status = error instanceof HttpError ? error.status : void 0;
58293
- process.stderr.write(`[prim] resolution failed${status ? ` (${status})` : ""}
58647
+ const status2 = error instanceof HttpError ? error.status : void 0;
58648
+ process.stderr.write(`[prim] resolution failed${status2 ? ` (${status2})` : ""}
58294
58649
  `);
58295
- console.log(JSON.stringify({ ok: false, status }));
58650
+ console.log(JSON.stringify({ ok: false, status: status2 }));
58296
58651
  process.exitCode = isDomainRejection(error) ? EXIT_USAGE2 : EXIT_SERVER;
58297
58652
  }
58298
58653
  }
@@ -58307,31 +58662,31 @@ function registerReconcileCommands(program3) {
58307
58662
 
58308
58663
  // src/commands/session.ts
58309
58664
  import {
58310
- existsSync as existsSync23,
58665
+ existsSync as existsSync24,
58311
58666
  mkdirSync as mkdirSync14,
58312
- readFileSync as readFileSync22,
58313
- readdirSync as readdirSync9,
58314
- unlinkSync as unlinkSync8,
58667
+ readFileSync as readFileSync23,
58668
+ readdirSync as readdirSync10,
58669
+ unlinkSync as unlinkSync9,
58315
58670
  writeFileSync as writeFileSync10
58316
58671
  } from "fs";
58317
- import { join as join32 } from "path";
58672
+ import { join as join33 } from "path";
58318
58673
 
58319
58674
  // src/binding.ts
58320
- import { existsSync as existsSync22, readFileSync as readFileSync21 } from "fs";
58321
- import { dirname as dirname16, join as join31 } from "path";
58675
+ import { existsSync as existsSync23, readFileSync as readFileSync22 } from "fs";
58676
+ import { dirname as dirname17, join as join32 } from "path";
58322
58677
  var PRIM_CONFIG_DIR = primConfigDirectory();
58323
- var SESSIONS_DIR = join31(PRIM_CONFIG_DIR, "sessions");
58678
+ var SESSIONS_DIR = join32(PRIM_CONFIG_DIR, "sessions");
58324
58679
 
58325
58680
  // src/commands/session.ts
58326
58681
  var DIR_MODE2 = 448;
58327
58682
  var FILE_MODE5 = 384;
58328
58683
  function ensureDir() {
58329
- if (!existsSync23(SESSIONS_DIR)) {
58684
+ if (!existsSync24(SESSIONS_DIR)) {
58330
58685
  mkdirSync14(SESSIONS_DIR, { recursive: true, mode: DIR_MODE2 });
58331
58686
  }
58332
58687
  }
58333
58688
  function markerPath(sessionId) {
58334
- return join32(SESSIONS_DIR, `${sessionId}.json`);
58689
+ return join33(SESSIONS_DIR, `${sessionId}.json`);
58335
58690
  }
58336
58691
  function registerSessionCommands(program3) {
58337
58692
  const session = program3.command("session").description("Decision Event Pipeline \u2014 session binding markers");
@@ -58347,11 +58702,11 @@ function registerSessionCommands(program3) {
58347
58702
  console.log(`[prim] session ${sessionId} bound to org ${opts.orgId}`);
58348
58703
  });
58349
58704
  session.command("list").description("List active session markers").action(() => {
58350
- if (!existsSync23(SESSIONS_DIR)) {
58705
+ if (!existsSync24(SESSIONS_DIR)) {
58351
58706
  console.log("[prim] no session markers");
58352
58707
  return;
58353
58708
  }
58354
- const files = readdirSync9(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
58709
+ const files = readdirSync10(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
58355
58710
  if (files.length === 0) {
58356
58711
  console.log("[prim] no session markers");
58357
58712
  return;
@@ -58359,7 +58714,7 @@ function registerSessionCommands(program3) {
58359
58714
  for (const f of files) {
58360
58715
  const sessionId = f.replace(/\.json$/, "");
58361
58716
  try {
58362
- const m = JSON.parse(readFileSync22(join32(SESSIONS_DIR, f), "utf-8"));
58717
+ const m = JSON.parse(readFileSync23(join33(SESSIONS_DIR, f), "utf-8"));
58363
58718
  console.log(`${sessionId} org=${m.orgId}`);
58364
58719
  } catch {
58365
58720
  }
@@ -58367,19 +58722,19 @@ function registerSessionCommands(program3) {
58367
58722
  });
58368
58723
  session.command("drop <sessionId>").description("Remove a session marker").action((sessionId) => {
58369
58724
  const p = markerPath(sessionId);
58370
- if (!existsSync23(p)) {
58725
+ if (!existsSync24(p)) {
58371
58726
  console.log(`[prim] no marker for session ${sessionId}`);
58372
58727
  return;
58373
58728
  }
58374
- unlinkSync8(p);
58729
+ unlinkSync9(p);
58375
58730
  console.log(`[prim] dropped session marker ${sessionId}`);
58376
58731
  });
58377
58732
  }
58378
58733
 
58379
58734
  // src/commands/setup.ts
58380
58735
  import { spawnSync as spawnSync2 } from "child_process";
58381
- import { existsSync as existsSync24, readFileSync as readFileSync23 } from "fs";
58382
- import { join as join33 } from "path";
58736
+ import { existsSync as existsSync25, readFileSync as readFileSync24 } from "fs";
58737
+ import { join as join34 } from "path";
58383
58738
  var EXIT_INCOMPLETE = 1;
58384
58739
  var EXIT_USAGE3 = 2;
58385
58740
  var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
@@ -58517,8 +58872,8 @@ function detectProjectConflicts(agent, run, globalHooksActive) {
58517
58872
  let preCommit;
58518
58873
  try {
58519
58874
  const root = gitToplevel();
58520
- const path9 = root && join33(root, ".git", "hooks", "pre-commit");
58521
- if (path9 && existsSync24(path9)) preCommit = readFileSync23(path9, "utf-8");
58875
+ const path9 = root && join34(root, ".git", "hooks", "pre-commit");
58876
+ if (path9 && existsSync25(path9)) preCommit = readFileSync24(path9, "utf-8");
58522
58877
  } catch {
58523
58878
  }
58524
58879
  if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
@@ -58779,51 +59134,51 @@ function setupChildPayload(stdout) {
58779
59134
  }
58780
59135
 
58781
59136
  // src/commands/skill.ts
58782
- import { createHash as createHash13 } from "crypto";
59137
+ import { createHash as createHash14 } from "crypto";
58783
59138
  import {
58784
59139
  constants as constants8,
58785
59140
  closeSync as closeSync8,
58786
- existsSync as existsSync26,
59141
+ existsSync as existsSync27,
58787
59142
  fstatSync as fstatSync4,
58788
- lstatSync as lstatSync12,
59143
+ lstatSync as lstatSync13,
58789
59144
  openSync as openSync8,
58790
- readFileSync as readFileSync25,
59145
+ readFileSync as readFileSync26,
58791
59146
  readSync as readSync4,
58792
- readdirSync as readdirSync11,
58793
- rmdirSync as rmdirSync4,
58794
- unlinkSync as unlinkSync9
59147
+ readdirSync as readdirSync12,
59148
+ rmdirSync as rmdirSync5,
59149
+ unlinkSync as unlinkSync10
58795
59150
  } from "fs";
58796
- import { homedir as homedir12 } from "os";
58797
- import { dirname as dirname18, join as join35, resolve as resolve11 } from "path";
58798
- import { fileURLToPath as fileURLToPath5 } from "url";
59151
+ import { homedir as homedir13 } from "os";
59152
+ import { dirname as dirname19, join as join36, resolve as resolve12 } from "path";
59153
+ import { fileURLToPath as fileURLToPath6 } from "url";
58799
59154
 
58800
59155
  // src/commands/claude-plugin.ts
58801
- import { createHash as createHash12 } from "crypto";
59156
+ import { createHash as createHash13 } from "crypto";
58802
59157
  import {
58803
59158
  constants as constants7,
58804
59159
  closeSync as closeSync7,
58805
- existsSync as existsSync25,
59160
+ existsSync as existsSync26,
58806
59161
  fstatSync as fstatSync3,
58807
- lstatSync as lstatSync11,
59162
+ lstatSync as lstatSync12,
58808
59163
  mkdirSync as mkdirSync15,
58809
59164
  openSync as openSync7,
58810
- readFileSync as readFileSync24,
59165
+ readFileSync as readFileSync25,
58811
59166
  readSync as readSync3,
58812
- readdirSync as readdirSync10,
59167
+ readdirSync as readdirSync11,
58813
59168
  realpathSync as realpathSync7,
58814
59169
  rmSync as rmSync9,
58815
- rmdirSync as rmdirSync3
59170
+ rmdirSync as rmdirSync4
58816
59171
  } from "fs";
58817
- import { homedir as homedir11 } from "os";
58818
- import { dirname as dirname17, isAbsolute as isAbsolute10, join as join34, relative as relative3, resolve as resolve10, sep as sep3 } from "path";
58819
- import { fileURLToPath as fileURLToPath4 } from "url";
58820
- var __dirname4 = dirname17(fileURLToPath4(import.meta.url));
59172
+ import { homedir as homedir12 } from "os";
59173
+ import { dirname as dirname18, isAbsolute as isAbsolute10, join as join35, relative as relative3, resolve as resolve11, sep as sep3 } from "path";
59174
+ import { fileURLToPath as fileURLToPath5 } from "url";
59175
+ var __dirname5 = dirname18(fileURLToPath5(import.meta.url));
58821
59176
  var PLUGIN_DESCRIPTION = "Primitive decision-graph guidance for the prim CLI \u2014 a model-invoked skill installed by prim skill install.";
58822
59177
  var MAX_MANIFEST_BYTES2 = 64 * 1024;
58823
59178
  var MAX_SKILL_BYTES = 1024 * 1024;
58824
59179
  function pluginDirFor(cwd, scope) {
58825
- const base = scope === "user" ? join34(homedir11(), ".claude") : join34(gitToplevel(cwd) ?? cwd, ".claude");
58826
- return join34(base, "skills", "prim");
59180
+ const base = scope === "user" ? join35(homedir12(), ".claude") : join35(gitToplevel(cwd) ?? cwd, ".claude");
59181
+ return join35(base, "skills", "prim");
58827
59182
  }
58828
59183
  function resolvePluginDir(cwd, scope) {
58829
59184
  if (scope && scope !== "user" && scope !== "project") {
@@ -58832,12 +59187,12 @@ function resolvePluginDir(cwd, scope) {
58832
59187
  }
58833
59188
  return pluginDirFor(cwd, scope === "user" ? "user" : "project");
58834
59189
  }
58835
- function packageVersion2() {
58836
- let dir = __dirname4;
58837
- while (dir !== dirname17(dir)) {
58838
- const p = resolve10(dir, "package.json");
58839
- if (existsSync25(p)) return JSON.parse(readFileSync24(p, "utf-8")).version;
58840
- dir = dirname17(dir);
59190
+ function packageVersion3() {
59191
+ let dir = __dirname5;
59192
+ while (dir !== dirname18(dir)) {
59193
+ const p = resolve11(dir, "package.json");
59194
+ if (existsSync26(p)) return JSON.parse(readFileSync25(p, "utf-8")).version;
59195
+ dir = dirname18(dir);
58841
59196
  }
58842
59197
  return "0.0.0";
58843
59198
  }
@@ -58847,16 +59202,16 @@ function pluginManifest(version) {
58847
59202
  `;
58848
59203
  }
58849
59204
  function renderClaudePlugin() {
58850
- const version = packageVersion2();
59205
+ const version = packageVersion3();
58851
59206
  return { manifest: pluginManifest(version), skill: loadSkill(), version };
58852
59207
  }
58853
59208
  function removeDirIfEmpty(dir) {
58854
- if (existsSync25(dir) && readdirSync10(dir).length === 0) rmdirSync3(dir);
59209
+ if (existsSync26(dir) && readdirSync11(dir).length === 0) rmdirSync4(dir);
58855
59210
  }
58856
59211
  function pluginPaths(dir) {
58857
59212
  return {
58858
- manifestPath: join34(dir, ".claude-plugin", "plugin.json"),
58859
- skillPath: join34(dir, "SKILL.md")
59213
+ manifestPath: join35(dir, ".claude-plugin", "plugin.json"),
59214
+ skillPath: join35(dir, "SKILL.md")
58860
59215
  };
58861
59216
  }
58862
59217
  function installClaudePlugin(cwd, opts) {
@@ -58864,8 +59219,8 @@ function installClaudePlugin(cwd, opts) {
58864
59219
  if (dir === null) return 1;
58865
59220
  const { manifestPath, skillPath } = pluginPaths(dir);
58866
59221
  const { manifest, skill } = renderClaudePlugin();
58867
- const manifestCurrent = existsSync25(manifestPath) ? readFileSync24(manifestPath, "utf-8") : null;
58868
- const skillCurrent = existsSync25(skillPath) ? readFileSync24(skillPath, "utf-8") : null;
59222
+ const manifestCurrent = existsSync26(manifestPath) ? readFileSync25(manifestPath, "utf-8") : null;
59223
+ const skillCurrent = existsSync26(skillPath) ? readFileSync25(skillPath, "utf-8") : null;
58869
59224
  if (manifestCurrent === manifest && skillCurrent === skill) {
58870
59225
  console.log("No changes \u2014 prim skill plugin already up to date.");
58871
59226
  return 0;
@@ -58874,7 +59229,7 @@ function installClaudePlugin(cwd, opts) {
58874
59229
  console.log(`Would write plugin to ${dir} (.claude-plugin/plugin.json + SKILL.md)`);
58875
59230
  return 0;
58876
59231
  }
58877
- mkdirSync15(join34(dir, ".claude-plugin"), { recursive: true });
59232
+ mkdirSync15(join35(dir, ".claude-plugin"), { recursive: true });
58878
59233
  atomicWrite5(manifestPath, manifest);
58879
59234
  atomicWrite5(skillPath, skill);
58880
59235
  console.log(`Installed prim skill plugin at ${dir}`);
@@ -58888,13 +59243,13 @@ function uninstallClaudePlugin(cwd, opts) {
58888
59243
  const dir = resolvePluginDir(cwd, opts.scope);
58889
59244
  if (dir === null) return 1;
58890
59245
  const { manifestPath, skillPath } = pluginPaths(dir);
58891
- if (!existsSync25(manifestPath) && !existsSync25(skillPath)) {
59246
+ if (!existsSync26(manifestPath) && !existsSync26(skillPath)) {
58892
59247
  console.log(`prim skill plugin not present at ${dir}`);
58893
59248
  return 0;
58894
59249
  }
58895
59250
  rmSync9(manifestPath, { force: true });
58896
59251
  rmSync9(skillPath, { force: true });
58897
- removeDirIfEmpty(join34(dir, ".claude-plugin"));
59252
+ removeDirIfEmpty(join35(dir, ".claude-plugin"));
58898
59253
  removeDirIfEmpty(dir);
58899
59254
  console.log(`Removed prim skill plugin from ${dir}`);
58900
59255
  return 0;
@@ -58903,7 +59258,7 @@ function statusClaudePlugin(cwd, opts) {
58903
59258
  const dir = resolvePluginDir(cwd, opts.scope);
58904
59259
  if (dir === null) return 1;
58905
59260
  const { skillPath } = pluginPaths(dir);
58906
- const installed = existsSync25(skillPath);
59261
+ const installed = existsSync26(skillPath);
58907
59262
  if (opts.json) {
58908
59263
  printJson({ installed, target: dir });
58909
59264
  return installed ? 0 : 1;
@@ -58917,7 +59272,7 @@ function statusClaudePlugin(cwd, opts) {
58917
59272
  }
58918
59273
 
58919
59274
  // src/commands/skill.ts
58920
- var __dirname5 = dirname18(fileURLToPath5(import.meta.url));
59275
+ var __dirname6 = dirname19(fileURLToPath6(import.meta.url));
58921
59276
  var SKILL_BEGIN = "<!-- BEGIN PRIM SKILL v1 -->";
58922
59277
  var SKILL_END = "<!-- END PRIM SKILL v1 -->";
58923
59278
  var CODEX_GUIDANCE_LIMIT_BYTES = 1024 * 1024;
@@ -58940,24 +59295,24 @@ var AGENT_TARGET = {
58940
59295
  };
58941
59296
  var CURSOR_SKILL_OWNER = "@primitive.ai/prim";
58942
59297
  var CURSOR_SKILL_MANIFEST = ".prim-owned.json";
58943
- function sha2563(content) {
58944
- return createHash13("sha256").update(content).digest("hex");
59298
+ function sha2564(content) {
59299
+ return createHash14("sha256").update(content).digest("hex");
58945
59300
  }
58946
59301
  function cursorSkillDirectory(cwd, scope) {
58947
59302
  const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
58948
- return join35(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
59303
+ return join36(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
58949
59304
  }
58950
59305
  function cursorSkillPaths(cwd, scope) {
58951
59306
  const directory = cursorSkillDirectory(cwd, scope);
58952
59307
  return {
58953
59308
  directory,
58954
- skill: join35(directory, "SKILL.md"),
58955
- manifest: join35(directory, CURSOR_SKILL_MANIFEST)
59309
+ skill: join36(directory, "SKILL.md"),
59310
+ manifest: join36(directory, CURSOR_SKILL_MANIFEST)
58956
59311
  };
58957
59312
  }
58958
59313
  function readCursorSkillManifest(path9) {
58959
59314
  try {
58960
- const value = JSON.parse(readFileSync25(path9, "utf8"));
59315
+ const value = JSON.parse(readFileSync26(path9, "utf8"));
58961
59316
  if (!value || typeof value !== "object" || Array.isArray(value)) return;
58962
59317
  const record3 = value;
58963
59318
  if (record3.version !== 1 || record3.owner !== CURSOR_SKILL_OWNER || typeof record3.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record3.contentSha256)) {
@@ -58971,9 +59326,9 @@ function readCursorSkillManifest(path9) {
58971
59326
  function cursorSkillStatus(cwd, scope) {
58972
59327
  const paths = cursorSkillPaths(cwd, scope);
58973
59328
  const manifest = readCursorSkillManifest(paths.manifest);
58974
- const content = existsSync26(paths.skill) ? readFileSync25(paths.skill, "utf8") : void 0;
59329
+ const content = existsSync27(paths.skill) ? readFileSync26(paths.skill, "utf8") : void 0;
58975
59330
  const owned = manifest !== void 0;
58976
- const installed = owned && content !== void 0 && sha2563(content) === manifest.contentSha256;
59331
+ const installed = owned && content !== void 0 && sha2564(content) === manifest.contentSha256;
58977
59332
  return {
58978
59333
  installed,
58979
59334
  owned,
@@ -58988,10 +59343,10 @@ function validCursorSkillScope(scope) {
58988
59343
  }
58989
59344
  function installCursorSkill(cwd, opts) {
58990
59345
  const paths = cursorSkillPaths(cwd, opts.scope);
58991
- const status = cursorSkillStatus(cwd, opts.scope);
58992
- const manifestExists = existsSync26(paths.manifest);
58993
- const skillExists = existsSync26(paths.skill);
58994
- if (manifestExists && !status.owned || !manifestExists && skillExists || status.edited) {
59346
+ const status2 = cursorSkillStatus(cwd, opts.scope);
59347
+ const manifestExists = existsSync27(paths.manifest);
59348
+ const skillExists = existsSync27(paths.skill);
59349
+ if (manifestExists && !status2.owned || !manifestExists && skillExists || status2.edited) {
58995
59350
  console.error(`Refusing to overwrite a foreign or edited Cursor skill at ${paths.skill}`);
58996
59351
  return 1;
58997
59352
  }
@@ -58999,14 +59354,14 @@ function installCursorSkill(cwd, opts) {
58999
59354
  const manifest = {
59000
59355
  version: 1,
59001
59356
  owner: CURSOR_SKILL_OWNER,
59002
- contentSha256: sha2563(content)
59357
+ contentSha256: sha2564(content)
59003
59358
  };
59004
- if (status.installed && readFileSync25(paths.skill, "utf8") === content) {
59359
+ if (status2.installed && readFileSync26(paths.skill, "utf8") === content) {
59005
59360
  console.log(`No changes \u2014 Cursor skill already up to date at ${paths.skill}`);
59006
59361
  return 0;
59007
59362
  }
59008
59363
  if (opts.dryRun) {
59009
- const existing = skillExists ? readFileSync25(paths.skill, "utf8") : "";
59364
+ const existing = skillExists ? readFileSync26(paths.skill, "utf8") : "";
59010
59365
  process.stdout.write(createPatch(paths.skill, existing, content, "current", "proposed"));
59011
59366
  return 0;
59012
59367
  }
@@ -59018,43 +59373,43 @@ function installCursorSkill(cwd, opts) {
59018
59373
  }
59019
59374
  function uninstallCursorSkill(cwd, scope) {
59020
59375
  const paths = cursorSkillPaths(cwd, scope);
59021
- const status = cursorSkillStatus(cwd, scope);
59022
- if (!status.owned) {
59376
+ const status2 = cursorSkillStatus(cwd, scope);
59377
+ if (!status2.owned) {
59023
59378
  console.log(`No Primitive-owned Cursor skill at ${paths.skill}`);
59024
59379
  return 0;
59025
59380
  }
59026
- if (status.edited) {
59381
+ if (status2.edited) {
59027
59382
  console.error(`Refusing to remove an edited Cursor skill at ${paths.skill}`);
59028
59383
  return 1;
59029
59384
  }
59030
- if (existsSync26(paths.skill)) unlinkSync9(paths.skill);
59031
- if (existsSync26(paths.manifest)) unlinkSync9(paths.manifest);
59385
+ if (existsSync27(paths.skill)) unlinkSync10(paths.skill);
59386
+ if (existsSync27(paths.manifest)) unlinkSync10(paths.manifest);
59032
59387
  try {
59033
- if (readdirSync11(paths.directory).length === 0) rmdirSync4(paths.directory);
59388
+ if (readdirSync12(paths.directory).length === 0) rmdirSync5(paths.directory);
59034
59389
  } catch {
59035
59390
  }
59036
59391
  console.log(`Removed Primitive-owned Cursor skill from ${paths.skill}`);
59037
59392
  return 0;
59038
59393
  }
59039
59394
  function userTargetFor(agent) {
59040
- if (agent === "claude") return join35(homedir12(), ".claude", "CLAUDE.md");
59041
- if (agent === "codex") return join35(homedir12(), ".codex", "AGENTS.md");
59395
+ if (agent === "claude") return join36(homedir13(), ".claude", "CLAUDE.md");
59396
+ if (agent === "codex") return join36(homedir13(), ".codex", "AGENTS.md");
59042
59397
  if (agent === "hermes") {
59043
- return join35(process.env.HERMES_HOME ?? join35(homedir12(), ".hermes"), ".hermes.md");
59398
+ return join36(process.env.HERMES_HOME ?? join36(homedir13(), ".hermes"), ".hermes.md");
59044
59399
  }
59045
59400
  return null;
59046
59401
  }
59047
59402
  function loadSkill() {
59048
- let dir = __dirname5;
59049
- while (dir !== dirname18(dir)) {
59050
- const p = resolve11(dir, "SKILL.md");
59051
- if (existsSync26(p)) return readFileSync25(p, "utf-8");
59052
- dir = dirname18(dir);
59403
+ let dir = __dirname6;
59404
+ while (dir !== dirname19(dir)) {
59405
+ const p = resolve12(dir, "SKILL.md");
59406
+ if (existsSync27(p)) return readFileSync26(p, "utf-8");
59407
+ dir = dirname19(dir);
59053
59408
  }
59054
59409
  throw new Error("SKILL.md not found in package");
59055
59410
  }
59056
59411
  function detectTargets(cwd) {
59057
- return TARGET_CANDIDATES.filter((p) => existsSync26(resolve11(cwd, p)));
59412
+ return TARGET_CANDIDATES.filter((p) => existsSync27(resolve12(cwd, p)));
59058
59413
  }
59059
59414
  function detectNewline(content) {
59060
59415
  return content.includes("\r\n") ? "\r\n" : "\n";
@@ -59073,7 +59428,7 @@ function applyBlock(existing, block, eol) {
59073
59428
  const sep4 = existing.endsWith(eol) ? "" : eol;
59074
59429
  return `${existing}${sep4}${block}${eol}`;
59075
59430
  }
59076
- function removeBlock(existing) {
59431
+ function removeBlock2(existing) {
59077
59432
  const b = existing.indexOf(SKILL_BEGIN);
59078
59433
  const e = existing.indexOf(SKILL_END);
59079
59434
  if (b === -1 || e === -1) return null;
@@ -59088,7 +59443,7 @@ function resolveTarget(cwd, opts) {
59088
59443
  console.error(`Unknown --scope "${opts.scope}" (expected user or project)`);
59089
59444
  return null;
59090
59445
  }
59091
- if (opts.target) return resolve11(cwd, opts.target);
59446
+ if (opts.target) return resolve12(cwd, opts.target);
59092
59447
  if (opts.scope === "user") {
59093
59448
  if (!opts.agent) {
59094
59449
  console.error("--scope user requires --agent (claude, codex, cursor, or hermes)");
@@ -59101,13 +59456,13 @@ function resolveTarget(cwd, opts) {
59101
59456
  }
59102
59457
  if (opts.agent) {
59103
59458
  const mapped = AGENT_TARGET[opts.agent];
59104
- if (typeof mapped === "string") return resolve11(cwd, mapped);
59459
+ if (typeof mapped === "string") return resolve12(cwd, mapped);
59105
59460
  console.error(`Unknown --agent "${opts.agent}" (expected claude, codex, cursor, or hermes)`);
59106
59461
  return null;
59107
59462
  }
59108
59463
  const matches = detectTargets(cwd);
59109
- if (matches.length === 0) return resolve11(cwd, DEFAULT_TARGET);
59110
- if (matches.length === 1) return resolve11(cwd, matches[0]);
59464
+ if (matches.length === 0) return resolve12(cwd, DEFAULT_TARGET);
59465
+ if (matches.length === 1) return resolve12(cwd, matches[0]);
59111
59466
  console.error("Multiple rules files detected. Use --target to disambiguate:");
59112
59467
  for (const m of matches) console.error(` ${m}`);
59113
59468
  return null;
@@ -59120,7 +59475,7 @@ function runInstall(cwd, opts) {
59120
59475
  }
59121
59476
  const target = resolveTarget(cwd, opts);
59122
59477
  if (target === null) return 1;
59123
- const existing = existsSync26(target) ? readFileSync25(target, "utf-8") : "";
59478
+ const existing = existsSync27(target) ? readFileSync26(target, "utf-8") : "";
59124
59479
  const eol = existing ? detectNewline(existing) : "\n";
59125
59480
  const block = composeBlock(loadSkill(), eol);
59126
59481
  const next = applyBlock(existing, block, eol);
@@ -59144,12 +59499,12 @@ function runUninstall(cwd, opts) {
59144
59499
  }
59145
59500
  const target = resolveTarget(cwd, opts);
59146
59501
  if (target === null) return 1;
59147
- if (!existsSync26(target)) {
59502
+ if (!existsSync27(target)) {
59148
59503
  console.log(`Skill block not present at ${target}`);
59149
59504
  return 0;
59150
59505
  }
59151
- const existing = readFileSync25(target, "utf-8");
59152
- const next = removeBlock(existing);
59506
+ const existing = readFileSync26(target, "utf-8");
59507
+ const next = removeBlock2(existing);
59153
59508
  if (next === null) {
59154
59509
  console.log(`Skill block not present at ${target}`);
59155
59510
  return 0;
@@ -59162,20 +59517,20 @@ function runStatus(cwd, opts) {
59162
59517
  if (opts.agent === "claude" && !opts.target) return statusClaudePlugin(cwd, opts);
59163
59518
  if (opts.agent === "cursor" && !opts.target) {
59164
59519
  if (!validCursorSkillScope(opts.scope)) return 1;
59165
- const status = cursorSkillStatus(cwd, opts.scope);
59166
- if (opts.json) printJson(status);
59520
+ const status2 = cursorSkillStatus(cwd, opts.scope);
59521
+ if (opts.json) printJson(status2);
59167
59522
  else
59168
59523
  console.log(
59169
- status.installed ? `Primitive Cursor skill installed at ${status.target}` : `No intact Primitive-owned Cursor skill at ${status.target}`
59524
+ status2.installed ? `Primitive Cursor skill installed at ${status2.target}` : `No intact Primitive-owned Cursor skill at ${status2.target}`
59170
59525
  );
59171
- return status.installed ? 0 : 1;
59526
+ return status2.installed ? 0 : 1;
59172
59527
  }
59173
59528
  const target = resolveTarget(cwd, opts);
59174
59529
  if (target === null) return 1;
59175
- const fileExists = existsSync26(target);
59530
+ const fileExists = existsSync27(target);
59176
59531
  let installed = false;
59177
59532
  if (fileExists) {
59178
- const content = readFileSync25(target, "utf-8");
59533
+ const content = readFileSync26(target, "utf-8");
59179
59534
  installed = content.includes(SKILL_BEGIN) && content.includes(SKILL_END);
59180
59535
  }
59181
59536
  if (opts.json) {
@@ -59212,23 +59567,23 @@ function registerSkillCommands(program3) {
59212
59567
  }
59213
59568
 
59214
59569
  // src/commands/statusline.ts
59215
- import { readFileSync as readFileSync26 } from "fs";
59216
- import { dirname as dirname19, resolve as resolve12 } from "path";
59217
- import { fileURLToPath as fileURLToPath6 } from "url";
59570
+ import { readFileSync as readFileSync27 } from "fs";
59571
+ import { dirname as dirname20, resolve as resolve13 } from "path";
59572
+ import { fileURLToPath as fileURLToPath7 } from "url";
59218
59573
  var STATUSLINE_TIMEOUT_MS = 200;
59219
59574
  function readPackageVersion() {
59220
59575
  try {
59221
- const here = dirname19(fileURLToPath6(import.meta.url));
59576
+ const here = dirname20(fileURLToPath7(import.meta.url));
59222
59577
  const candidates = [
59223
59578
  // Schema-v2 runtimes staged a manifest beside this standalone bundle.
59224
59579
  // Keep resolving it while those legacy launchers transition to schema v3.
59225
- resolve12(here, "manifest.json"),
59226
- resolve12(here, "../../package.json"),
59227
- resolve12(here, "../package.json")
59580
+ resolve13(here, "manifest.json"),
59581
+ resolve13(here, "../../package.json"),
59582
+ resolve13(here, "../package.json")
59228
59583
  ];
59229
59584
  for (const path9 of candidates) {
59230
59585
  try {
59231
- const pkg2 = JSON.parse(readFileSync26(path9, "utf-8"));
59586
+ const pkg2 = JSON.parse(readFileSync27(path9, "utf-8"));
59232
59587
  if (pkg2.version) {
59233
59588
  return pkg2.version;
59234
59589
  }
@@ -59792,13 +60147,13 @@ function healDaemonDrift(options = {}) {
59792
60147
 
59793
60148
  // src/lib/background-flush.ts
59794
60149
  import { spawn as spawn5 } from "child_process";
59795
- import { readFileSync as readFileSync27 } from "fs";
60150
+ import { readFileSync as readFileSync28 } from "fs";
59796
60151
 
59797
60152
  // src/daemon/health.ts
59798
- import { chmodSync as chmodSync8, existsSync as existsSync27, mkdirSync as mkdirSync16, renameSync as renameSync7, writeFileSync as writeFileSync11 } from "fs";
59799
- import { dirname as dirname20, join as join36 } from "path";
60153
+ import { chmodSync as chmodSync8, existsSync as existsSync28, mkdirSync as mkdirSync16, renameSync as renameSync7, writeFileSync as writeFileSync11 } from "fs";
60154
+ import { dirname as dirname21, join as join37 } from "path";
59800
60155
  var HEARTBEAT_FRESH_MS = 9e4;
59801
- var DAEMON_HEALTH_PATH = join36(primConfigDirectory(), "daemon-health.json");
60156
+ var DAEMON_HEALTH_PATH = join37(primConfigDirectory(), "daemon-health.json");
59802
60157
 
59803
60158
  // src/lib/background-flush.ts
59804
60159
  function record2(value) {
@@ -59809,7 +60164,7 @@ function daemonOwnsDrain(options = {}) {
59809
60164
  const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
59810
60165
  if (!expectedVersion) return false;
59811
60166
  const health = record2(
59812
- JSON.parse(readFileSync27(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
60167
+ JSON.parse(readFileSync28(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
59813
60168
  );
59814
60169
  const heartbeat = record2(health?.heartbeat);
59815
60170
  const ingestion = record2(health?.ingestion);
@@ -59916,8 +60271,8 @@ function mayHealDaemon(argv, env4) {
59916
60271
  function runStartupBackgroundWork(argv, env4, work) {
59917
60272
  const args = commandArguments(argv);
59918
60273
  const [command, subcommand] = args;
59919
- const uninstall = command === "uninstall" || env4[UNINSTALL_ORCHESTRATOR_ENV] === "1";
59920
- if (uninstall || command === "demo") return;
60274
+ const uninstall2 = command === "uninstall" || env4[UNINSTALL_ORCHESTRATOR_ENV] === "1";
60275
+ if (uninstall2 || command === "demo") return;
59921
60276
  work.notify();
59922
60277
  const setupDaemonDrains = command === "setup" && !args.includes("--no-daemon") || env4[SETUP_DAEMON_DRAINS_ENV] === "1";
59923
60278
  if (!setupDaemonDrains && (command !== "moves" || subcommand !== "flush")) work.flush();
@@ -59925,8 +60280,8 @@ function runStartupBackgroundWork(argv, env4, work) {
59925
60280
  }
59926
60281
 
59927
60282
  // src/index.ts
59928
- var __dirname6 = dirname21(fileURLToPath7(import.meta.url));
59929
- var pkg = JSON.parse(readFileSync28(resolve13(__dirname6, "../package.json"), "utf-8"));
60283
+ var __dirname7 = dirname22(fileURLToPath8(import.meta.url));
60284
+ var pkg = JSON.parse(readFileSync29(resolve14(__dirname7, "../package.json"), "utf-8"));
59930
60285
  runStartupBackgroundWork(process.argv.slice(2), process.env, {
59931
60286
  notify: () => updateNotifier({ pkg }).notify(),
59932
60287
  flush: () => startBackgroundFlush(),
@@ -59941,6 +60296,7 @@ registerAuthCommands(program2);
59941
60296
  registerHooksCommands(program2);
59942
60297
  registerActivationCommands(program2);
59943
60298
  registerSkillCommands(program2);
60299
+ registerGameplanCommands(program2);
59944
60300
  registerMovesCommands(program2);
59945
60301
  registerSessionCommands(program2);
59946
60302
  registerDecisionsCommands(program2);