caveat-cli 0.16.3 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { createRequire as __caveat_createRequire } from 'node:module';
3
3
  const require = __caveat_createRequire(import.meta.url);
4
4
  import {
5
5
  AUTO_SYNC_DEBOUNCE_MS,
6
+ AUTO_SYNC_RECORD_DEBOUNCE_MS,
6
7
  CAVEAT_AUTO_SYNC_ENV,
7
8
  KNOWLEDGE_GITIGNORE,
8
9
  PublishScanError,
@@ -66,11 +67,12 @@ import {
66
67
  struggleSearchText,
67
68
  syncOwn,
68
69
  toolErrorReminderText,
70
+ triggerAutoSync,
69
71
  updateEntry,
70
72
  userPromptSubmitReminderText,
71
73
  writeDigestMarker,
72
74
  writeUserConfigPatch
73
- } from "./chunk-PD5E6TFL.js";
75
+ } from "./chunk-TRIQ5WFY.js";
74
76
 
75
77
  // ../../node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js
76
78
  var require_code = __commonJS({
@@ -7116,8 +7118,9 @@ import { parse as parseToml } from "smol-toml";
7116
7118
  function quote2(p) {
7117
7119
  return p.includes(" ") ? `"${p}"` : p;
7118
7120
  }
7119
- function hookCommand2(nodePath, cliScriptPath, event) {
7120
- return `${quote2(nodePath)} ${quote2(cliScriptPath)} codex-hook ${event}`;
7121
+ function hookCommand2(nodePath, cliScriptPath, event, platform = process.platform) {
7122
+ const prefix = platform === "win32" ? "& " : "";
7123
+ return `${prefix}${quote2(nodePath)} ${quote2(cliScriptPath)} codex-hook ${event}`;
7121
7124
  }
7122
7125
  function eventCommandFragment(event) {
7123
7126
  return `codex-hook ${event}`;
@@ -7151,7 +7154,8 @@ function isCanonicalAsset2(path, expectedPath, mode) {
7151
7154
  }
7152
7155
  }
7153
7156
  function isCanonicalCaveatCodexHookCommand(actual, event, nodePath, cliScriptPath) {
7154
- const tokens = commandTokens2(actual);
7157
+ const parsed = commandTokens2(actual);
7158
+ const tokens = parsed?.[0] === "&" ? parsed.slice(1) : parsed;
7155
7159
  return tokens?.length === 4 && isCanonicalAsset2(tokens[0], nodePath, constants2.X_OK) && isCanonicalAsset2(tokens[1], cliScriptPath, constants2.R_OK) && tokens[2] === "codex-hook" && tokens[3] === event;
7156
7160
  }
7157
7161
  function hasCaveatHook(hooksJson, event, fragment) {
@@ -7421,19 +7425,19 @@ function installCodexHooks(opts) {
7421
7425
  const userPromptSubmit = upsertHook2(
7422
7426
  hooksJson,
7423
7427
  "UserPromptSubmit",
7424
- hookCommand2(opts.nodePath, opts.cliScriptPath, "user-prompt-submit"),
7428
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "user-prompt-submit", opts.platform),
7425
7429
  "user-prompt-submit"
7426
7430
  );
7427
7431
  const postToolUse = upsertHook2(
7428
7432
  hooksJson,
7429
7433
  "PostToolUse",
7430
- hookCommand2(opts.nodePath, opts.cliScriptPath, "post-tool-use"),
7434
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "post-tool-use", opts.platform),
7431
7435
  "post-tool-use"
7432
7436
  );
7433
7437
  const stop = upsertHook2(
7434
7438
  hooksJson,
7435
7439
  "Stop",
7436
- hookCommand2(opts.nodePath, opts.cliScriptPath, "stop"),
7440
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "stop", opts.platform),
7437
7441
  "stop"
7438
7442
  );
7439
7443
  const anyHookAdded = userPromptSubmit === "added" || postToolUse === "added" || stop === "added";
@@ -7465,19 +7469,19 @@ function uninstallCodexHooks(opts) {
7465
7469
  const userPromptSubmitRemoved = removeHook2(
7466
7470
  hooksJson,
7467
7471
  "UserPromptSubmit",
7468
- hookCommand2(opts.nodePath, opts.cliScriptPath, "user-prompt-submit"),
7472
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "user-prompt-submit", opts.platform),
7469
7473
  "user-prompt-submit"
7470
7474
  );
7471
7475
  const postToolUseRemoved = removeHook2(
7472
7476
  hooksJson,
7473
7477
  "PostToolUse",
7474
- hookCommand2(opts.nodePath, opts.cliScriptPath, "post-tool-use"),
7478
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "post-tool-use", opts.platform),
7475
7479
  "post-tool-use"
7476
7480
  );
7477
7481
  const stopRemoved = removeHook2(
7478
7482
  hooksJson,
7479
7483
  "Stop",
7480
- hookCommand2(opts.nodePath, opts.cliScriptPath, "stop"),
7484
+ hookCommand2(opts.nodePath, opts.cliScriptPath, "stop", opts.platform),
7481
7485
  "stop"
7482
7486
  );
7483
7487
  let backupPath;
@@ -8288,7 +8292,7 @@ function runStats(ctx) {
8288
8292
 
8289
8293
  // src/commands/serve.ts
8290
8294
  async function runServe(opts) {
8291
- const { startServer } = await import("./server-ZMIRSFMH.js");
8295
+ const { startServer } = await import("./server-FUWTRVRZ.js");
8292
8296
  const { port, host } = startServer({ port: opts.port });
8293
8297
  process.stdout.write(`[caveat] web portal: http://${host}:${port}/
8294
8298
  `);
@@ -32361,6 +32365,21 @@ var StdioServerTransport = class {
32361
32365
  // ../mcp/dist/context.js
32362
32366
  import { homedir as homedir2 } from "node:os";
32363
32367
  import { join as join9 } from "node:path";
32368
+
32369
+ // ../mcp/dist/autoSyncTrigger.js
32370
+ function triggerAutoSyncAfterWrite(caveatHome, logger) {
32371
+ try {
32372
+ triggerAutoSync({
32373
+ caveatHome,
32374
+ cliScript: process.argv[1] ?? "",
32375
+ debounceMs: AUTO_SYNC_RECORD_DEBOUNCE_MS
32376
+ });
32377
+ } catch (err) {
32378
+ logger.warn(`auto sync trigger failed: ${err instanceof Error ? err.message : String(err)}`);
32379
+ }
32380
+ }
32381
+
32382
+ // ../mcp/dist/context.js
32364
32383
  function buildMcpContext(overrides = {}) {
32365
32384
  const userHome = overrides.userHome ?? homedir2();
32366
32385
  const caveatHome = overrides.caveatHome ?? findCaveatHome(userHome);
@@ -32369,7 +32388,8 @@ function buildMcpContext(overrides = {}) {
32369
32388
  const config2 = loadConfig(userConfigPath);
32370
32389
  const paths = resolvePaths(caveatHome, config2.knowledgeRepo, userHome);
32371
32390
  const db = openDb({ path: paths.dbPath, logger });
32372
- return { caveatHome, userHome, userConfigPath, config: config2, paths, logger, db };
32391
+ const onEntryWritten = overrides.onEntryWritten ?? (() => triggerAutoSyncAfterWrite(caveatHome, logger));
32392
+ return { caveatHome, userHome, userConfigPath, config: config2, paths, logger, db, onEntryWritten };
32373
32393
  }
32374
32394
 
32375
32395
  // ../mcp/dist/tools/search.js
@@ -32452,10 +32472,12 @@ var recordInputShape = {
32452
32472
  category: external_exports.string().optional().describe("Directory under entries/ (e.g., gpu, claude-code). Default: misc")
32453
32473
  };
32454
32474
  function handleRecord(ctx, args) {
32455
- return recordEntry(args, {
32475
+ const result = recordEntry(args, {
32456
32476
  db: ctx.db,
32457
32477
  entriesRoot: ctx.paths.entriesDir
32458
32478
  });
32479
+ ctx.onEntryWritten();
32480
+ return result;
32459
32481
  }
32460
32482
 
32461
32483
  // ../mcp/dist/tools/update.js
@@ -32492,11 +32514,13 @@ function handleUpdate(ctx, args) {
32492
32514
  if (source !== "own") {
32493
32515
  throw new Error("community \u30A8\u30F3\u30C8\u30EA\u306F\u8CFC\u8AAD\u7269\u3067\u3059; \u7DE8\u96C6\u306F\u4E0A\u6D41\u3067\u884C\u3063\u3066\u304F\u3060\u3055\u3044");
32494
32516
  }
32495
- return updateEntry(args.id, args.patch, {
32517
+ const result = updateEntry(args.id, args.patch, {
32496
32518
  db: ctx.db,
32497
32519
  entriesRoot: ctx.paths.entriesDir,
32498
32520
  source
32499
32521
  });
32522
+ ctx.onEntryWritten();
32523
+ return result;
32500
32524
  }
32501
32525
 
32502
32526
  // ../mcp/dist/tools/listRecent.js
@@ -32666,10 +32690,10 @@ async function runMcpServer() {
32666
32690
  }
32667
32691
 
32668
32692
  // src/commands/hookCmd.ts
32669
- import { spawn as spawn3 } from "node:child_process";
32693
+ import { spawn as spawn2 } from "node:child_process";
32670
32694
  import {
32671
32695
  chmodSync,
32672
- existsSync as existsSync10,
32696
+ existsSync as existsSync9,
32673
32697
  lstatSync,
32674
32698
  mkdtempSync as mkdtempSync2,
32675
32699
  mkdirSync as mkdirSync5,
@@ -32680,7 +32704,7 @@ import {
32680
32704
  writeFileSync as writeFileSync5
32681
32705
  } from "node:fs";
32682
32706
  import { tmpdir as tmpdir2 } from "node:os";
32683
- import { basename, dirname as dirname6, join as join12 } from "node:path";
32707
+ import { basename, dirname as dirname6, join as join11 } from "node:path";
32684
32708
  import { createHash, randomBytes } from "node:crypto";
32685
32709
 
32686
32710
  // src/autoReindexTrigger.ts
@@ -32707,25 +32731,12 @@ function maybeTriggerAutoReindex(ctx) {
32707
32731
  }
32708
32732
 
32709
32733
  // src/autoSyncTrigger.ts
32710
- import { spawn as spawn2 } from "node:child_process";
32711
- import { existsSync as existsSync9, statSync as statSync3 } from "node:fs";
32712
- import { join as join11 } from "node:path";
32713
- function maybeTriggerAutoSync(ctx) {
32714
- if (process.env[CAVEAT_AUTO_SYNC_ENV] === "off") return;
32715
- const statePath = join11(ctx.caveatHome, "sync", ".last-autosync.json");
32716
- const debounceMs = Number(process.env.CAVEAT_AUTO_SYNC_DEBOUNCE_MS ?? AUTO_SYNC_DEBOUNCE_MS);
32717
- try {
32718
- if (existsSync9(statePath) && Date.now() - statSync3(statePath).mtimeMs < debounceMs) return;
32719
- } catch {
32720
- }
32721
- const cliScript = process.argv[1];
32722
- if (!cliScript) throw new Error("current Caveat CLI script path is unavailable");
32723
- const child = spawn2(
32724
- process.execPath,
32725
- [...process.execArgv, "--disable-warning=ExperimentalWarning", cliScript, "hook", "autosync"],
32726
- { detached: true, stdio: "ignore", windowsHide: true }
32727
- );
32728
- child.unref();
32734
+ function maybeTriggerAutoSync(ctx, debounceMs = AUTO_SYNC_DEBOUNCE_MS) {
32735
+ triggerAutoSync({
32736
+ caveatHome: ctx.caveatHome,
32737
+ cliScript: process.argv[1] ?? "",
32738
+ debounceMs
32739
+ });
32729
32740
  }
32730
32741
 
32731
32742
  // src/commands/hookCmd.ts
@@ -32783,7 +32794,7 @@ function searchCaveatsSafely(input) {
32783
32794
  let hits;
32784
32795
  try {
32785
32796
  const ctx = buildContextSafely();
32786
- if (!ctx || !existsSync10(ctx.paths.dbPath)) return [];
32797
+ if (!ctx || !existsSync9(ctx.paths.dbPath)) return [];
32787
32798
  caveatHome = ctx.caveatHome;
32788
32799
  db = openDb({ path: ctx.paths.dbPath });
32789
32800
  const searchOptions = {
@@ -32891,7 +32902,7 @@ function stopSignalKey(signals, related) {
32891
32902
  return createHash("sha256").update(body).digest("hex");
32892
32903
  }
32893
32904
  function stopStatePath(caveatHome, sessionId) {
32894
- return join12(caveatHome, CLAUDE_STOP_STATE_DIR, `${sanitizeClaudeStateId(sessionId)}.txt`);
32905
+ return join11(caveatHome, CLAUDE_STOP_STATE_DIR, `${sanitizeClaudeStateId(sessionId)}.txt`);
32895
32906
  }
32896
32907
  function wasStopReminderQueued(caveatHome, sessionId, key) {
32897
32908
  const path = stopStatePath(caveatHome, sessionId);
@@ -32903,7 +32914,7 @@ function wasStopReminderQueued(caveatHome, sessionId, key) {
32903
32914
  }
32904
32915
  function markStopReminderQueued(caveatHome, sessionId, key) {
32905
32916
  const path = stopStatePath(caveatHome, sessionId);
32906
- mkdirSync5(join12(caveatHome, CLAUDE_STOP_STATE_DIR), { recursive: true });
32917
+ mkdirSync5(join11(caveatHome, CLAUDE_STOP_STATE_DIR), { recursive: true });
32907
32918
  writeFileSync5(path, key, "utf-8");
32908
32919
  }
32909
32920
  function queueStopForSession(sessionId, signals, related) {
@@ -32989,9 +33000,9 @@ function spawnWorker(job) {
32989
33000
  try {
32990
33001
  root = workerRoot();
32991
33002
  sweepStaleWorkerDirs(Date.now(), root);
32992
- workDir = mkdtempSync2(join12(root, "job-"));
33003
+ workDir = mkdtempSync2(join11(root, "job-"));
32993
33004
  chmodSync(workDir, 448);
32994
- workFile = join12(workDir, `${randomBytes(4).toString("hex")}.json`);
33005
+ workFile = join11(workDir, `${randomBytes(4).toString("hex")}.json`);
32995
33006
  writeFileSync5(workFile, JSON.stringify({ ...job, schemaVersion: "caveat-worker-job/v2" }), { encoding: "utf-8", mode: 384, flag: "wx" });
32996
33007
  } catch (err) {
32997
33008
  const msg = err instanceof Error ? err.message : String(err);
@@ -33006,7 +33017,7 @@ function spawnWorker(job) {
33006
33017
  return;
33007
33018
  }
33008
33019
  try {
33009
- const child = spawn3(
33020
+ const child = spawn2(
33010
33021
  process.execPath,
33011
33022
  ["--disable-warning=ExperimentalWarning", cliScript, "hook", "worker", workFile],
33012
33023
  { detached: true, stdio: "ignore", windowsHide: true }
@@ -33089,7 +33100,7 @@ function sweepStaleWorkerDirs(now = Date.now(), root = workerRoot()) {
33089
33100
  }
33090
33101
  for (const entry of entries) {
33091
33102
  if (!entry.startsWith("job-")) continue;
33092
- const path = join12(root, entry);
33103
+ const path = join11(root, entry);
33093
33104
  try {
33094
33105
  if (!isOwnedWorkerDir(path, root)) continue;
33095
33106
  const stat = lstatSync(path);
@@ -33101,12 +33112,12 @@ function sweepStaleWorkerDirs(now = Date.now(), root = workerRoot()) {
33101
33112
  }
33102
33113
  }
33103
33114
  function workerRoot(base = tmpdir2()) {
33104
- const root = join12(base, WORKER_ROOT);
33115
+ const root = join11(base, WORKER_ROOT);
33105
33116
  mkdirSync5(root, { recursive: true, mode: 448 });
33106
33117
  const stat = lstatSync(root);
33107
33118
  const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
33108
33119
  if (!stat.isDirectory() || stat.isSymbolicLink() || !hasPrivateOwnership(stat, uid)) throw new Error("worker root is unsafe");
33109
- const marker = join12(root, WORKER_MARKER);
33120
+ const marker = join11(root, WORKER_MARKER);
33110
33121
  try {
33111
33122
  writeFileSync5(marker, "caveat-worker/v1\n", { mode: 384, flag: "wx" });
33112
33123
  } catch (error51) {
@@ -33119,7 +33130,7 @@ function workerRoot(base = tmpdir2()) {
33119
33130
  function isStaleWorkerJobDir(path) {
33120
33131
  const entries = readdirSync2(path);
33121
33132
  if (entries.length !== 1 || !entries[0].endsWith(".json")) return false;
33122
- const file2 = join12(path, entries[0]);
33133
+ const file2 = join11(path, entries[0]);
33123
33134
  const stat = lstatSync(file2);
33124
33135
  const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
33125
33136
  if (!stat.isFile() || stat.isSymbolicLink() || !hasPrivateOwnership(stat, uid)) return false;
@@ -33145,7 +33156,7 @@ function isKnownStaleWorkerJob(value) {
33145
33156
  }
33146
33157
  function writeLastReindex(caveatHome, value) {
33147
33158
  try {
33148
- writeFileSync5(join12(caveatHome, "index", ".last-reindex.json"), JSON.stringify(value), "utf-8");
33159
+ writeFileSync5(join11(caveatHome, "index", ".last-reindex.json"), JSON.stringify(value), "utf-8");
33149
33160
  } catch (err) {
33150
33161
  const msg = err instanceof Error ? err.message : String(err);
33151
33162
  process.stderr.write(`[caveat:hook] reindex status write error: ${msg}
@@ -33161,7 +33172,7 @@ async function runReindexWorker() {
33161
33172
  return;
33162
33173
  }
33163
33174
  const ctx = buildContextSafely();
33164
- if (!ctx || !existsSync10(ctx.paths.dbPath)) {
33175
+ if (!ctx || !existsSync9(ctx.paths.dbPath)) {
33165
33176
  process.stderr.write("[caveat:hook] auto reindex skipped: index database does not exist\n");
33166
33177
  return;
33167
33178
  }
@@ -33229,7 +33240,7 @@ function buildToolErrorReminder(job, hits) {
33229
33240
  const mode = hookCodexSidecarMode();
33230
33241
  if (mode === "off") return base;
33231
33242
  const projectRoot = process.cwd();
33232
- const hasSidecarConfig = existsSync10(join12(projectRoot, ".codex-sidecar.yml"));
33243
+ const hasSidecarConfig = existsSync9(join11(projectRoot, ".codex-sidecar.yml"));
33233
33244
  if (mode === "auto" && !hasSidecarConfig) return base;
33234
33245
  const advisory = runCodexSidecarAdvisory({
33235
33246
  searchText: job.failureText,
@@ -33265,7 +33276,7 @@ function buildStopReminder(signals, related) {
33265
33276
  const mode = hookCodexSidecarMode();
33266
33277
  if (mode === "off") return base;
33267
33278
  const projectRoot = process.cwd();
33268
- const hasSidecarConfig = existsSync10(join12(projectRoot, ".codex-sidecar.yml"));
33279
+ const hasSidecarConfig = existsSync9(join11(projectRoot, ".codex-sidecar.yml"));
33269
33280
  if (mode === "auto" && !hasSidecarConfig) return base;
33270
33281
  const advisory = runCodexSidecarAdvisory({
33271
33282
  searchText: struggleSearchText(signals),
@@ -33408,10 +33419,10 @@ async function runHook(name, arg) {
33408
33419
  }
33409
33420
 
33410
33421
  // src/commands/codexHookCmd.ts
33411
- import { spawn as spawn4, spawnSync as spawnSync5 } from "node:child_process";
33412
- import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync6, unlinkSync, writeFileSync as writeFileSync6 } from "node:fs";
33422
+ import { spawn as spawn3, spawnSync as spawnSync5 } from "node:child_process";
33423
+ import { existsSync as existsSync10, mkdirSync as mkdirSync6, readFileSync as readFileSync6, unlinkSync, writeFileSync as writeFileSync6 } from "node:fs";
33413
33424
  import { homedir as homedir3, tmpdir as tmpdir3 } from "node:os";
33414
- import { join as join13 } from "node:path";
33425
+ import { join as join12 } from "node:path";
33415
33426
  import { createHash as createHash2, randomBytes as randomBytes2 } from "node:crypto";
33416
33427
  var silentLogger2 = {
33417
33428
  info: () => {
@@ -33463,7 +33474,7 @@ function searchCaveatsSafely2(input) {
33463
33474
  let hits;
33464
33475
  try {
33465
33476
  const ctx = buildContextSafely2();
33466
- if (!ctx || !existsSync11(ctx.paths.dbPath)) return [];
33477
+ if (!ctx || !existsSync10(ctx.paths.dbPath)) return [];
33467
33478
  caveatHome = ctx.caveatHome;
33468
33479
  db = openDb({ path: ctx.paths.dbPath });
33469
33480
  const searchOptions = {
@@ -33547,7 +33558,7 @@ function processExitCodeFromText(text) {
33547
33558
  return m ? Number(m[1]) : null;
33548
33559
  }
33549
33560
  function transcriptToolOutput(transcriptPath, toolUseId) {
33550
- if (!transcriptPath || !toolUseId || !existsSync11(transcriptPath)) return null;
33561
+ if (!transcriptPath || !toolUseId || !existsSync10(transcriptPath)) return null;
33551
33562
  let raw = "";
33552
33563
  try {
33553
33564
  raw = readFileSync6(transcriptPath, "utf-8");
@@ -33699,7 +33710,7 @@ function stopSignalKey2(signals, related) {
33699
33710
  return createHash2("sha256").update(body).digest("hex");
33700
33711
  }
33701
33712
  function stopStatePath2(caveatHome, sessionId) {
33702
- return join13(caveatHome, CODEX_STOP_STATE_DIR, `${sanitizeCodexStateId(sessionId)}.txt`);
33713
+ return join12(caveatHome, CODEX_STOP_STATE_DIR, `${sanitizeCodexStateId(sessionId)}.txt`);
33703
33714
  }
33704
33715
  function wasStopReminderQueued2(caveatHome, sessionId, key) {
33705
33716
  const path = stopStatePath2(caveatHome, sessionId);
@@ -33711,7 +33722,7 @@ function wasStopReminderQueued2(caveatHome, sessionId, key) {
33711
33722
  }
33712
33723
  function markStopReminderQueued2(caveatHome, sessionId, key) {
33713
33724
  const path = stopStatePath2(caveatHome, sessionId);
33714
- mkdirSync6(join13(caveatHome, CODEX_STOP_STATE_DIR), { recursive: true });
33725
+ mkdirSync6(join12(caveatHome, CODEX_STOP_STATE_DIR), { recursive: true });
33715
33726
  writeFileSync6(path, key, "utf-8");
33716
33727
  }
33717
33728
  function queueStopForSession2(sessionId, signals, related) {
@@ -33806,7 +33817,7 @@ async function runCodexWorker(workFile) {
33806
33817
  await processCodexWorkerJob(job);
33807
33818
  process.exit(0);
33808
33819
  }
33809
- function runDiagnostics(codexHome = process.env.CODEX_HOME ?? join13(homedir3(), ".codex")) {
33820
+ function runDiagnostics(codexHome = process.env.CODEX_HOME ?? join12(homedir3(), ".codex")) {
33810
33821
  const features = spawnSync5("codex", ["features", "list"], {
33811
33822
  encoding: "utf-8",
33812
33823
  maxBuffer: 1024 * 1024,
@@ -33915,9 +33926,9 @@ async function runCodexHook(name, arg) {
33915
33926
  }
33916
33927
 
33917
33928
  // src/commands/pull.ts
33918
- import { existsSync as existsSync12 } from "node:fs";
33929
+ import { existsSync as existsSync11 } from "node:fs";
33919
33930
  async function runPull(ctx) {
33920
- const hasCommunityDir = existsSync12(ctx.paths.communityDir);
33931
+ const hasCommunityDir = existsSync11(ctx.paths.communityDir);
33921
33932
  if (!hasCommunityDir) {
33922
33933
  ctx.logger.info(
33923
33934
  "no community repos yet \u2014 add one with `caveat community add <github-url>`."
@@ -34019,7 +34030,7 @@ async function runSync(ctx, opts, dependencies = {}) {
34019
34030
  import { spawnSync as spawnSync6 } from "node:child_process";
34020
34031
  import { closeSync, constants as constants3, fstatSync, lstatSync as lstatSync2, mkdirSync as mkdirSync7, mkdtempSync as mkdtempSync3, openSync, readSync as readSync2, realpathSync as realpathSync5, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
34021
34032
  import { tmpdir as tmpdir4 } from "node:os";
34022
- import { basename as basename2, dirname as dirname7, join as join14 } from "node:path";
34033
+ import { basename as basename2, dirname as dirname7, join as join13 } from "node:path";
34023
34034
  import { cwd, exit } from "node:process";
34024
34035
  function runCodexSidecarDiagnostics(logger, opts) {
34025
34036
  const plan = buildCodexSidecarDiagnosticsCommand({
@@ -34051,8 +34062,8 @@ function runCodexSidecarWithCaveats(ctx, workflow, prompt, opts) {
34051
34062
  process.stdout.write(JSON.stringify({ status: "skipped", decision }, null, 2) + "\n");
34052
34063
  exit(0);
34053
34064
  }
34054
- const contextDir = mkdtempSync3(join14(tmpdir4(), "caveat-sidecar-context-"));
34055
- const contextFile = join14(contextDir, "context.json");
34065
+ const contextDir = mkdtempSync3(join13(tmpdir4(), "caveat-sidecar-context-"));
34066
+ const contextFile = join13(contextDir, "context.json");
34056
34067
  let status2 = 1;
34057
34068
  try {
34058
34069
  const blocks = collectCaveatContextBlocks(ctx, {
@@ -34304,8 +34315,8 @@ function runCommunityRemove(ctx, handle, opts) {
34304
34315
 
34305
34316
  // src/commands/factoryDiagnostics.ts
34306
34317
  import { execFileSync } from "node:child_process";
34307
- import { existsSync as existsSync13, readFileSync as readFileSync7 } from "node:fs";
34308
- import { join as join15 } from "node:path";
34318
+ import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
34319
+ import { join as join14 } from "node:path";
34309
34320
  import { DatabaseSync } from "node:sqlite";
34310
34321
  import { parse as parseToml2 } from "smol-toml";
34311
34322
  var status = (ok, reason) => ({ status: ok ? "ready" : "not_ready", reason_code: ok ? "ready" : reason });
@@ -34317,8 +34328,8 @@ function isRecord2(value) {
34317
34328
  return typeof value === "object" && value !== null && !Array.isArray(value);
34318
34329
  }
34319
34330
  function claudeRegistration(home, nodePath, cliScriptPath) {
34320
- const path = join15(home, ".claude.json");
34321
- if (!existsSync13(path)) return status(false, "not_registered");
34331
+ const path = join14(home, ".claude.json");
34332
+ if (!existsSync12(path)) return status(false, "not_registered");
34322
34333
  try {
34323
34334
  const value = JSON.parse(readFileSync7(path, "utf8"));
34324
34335
  if (!isRecord2(value) || !isRecord2(value.mcpServers)) return status(false, "not_registered");
@@ -34329,7 +34340,7 @@ function claudeRegistration(home, nodePath, cliScriptPath) {
34329
34340
  }
34330
34341
  function claudeHooks(home, nodePath, cliScriptPath) {
34331
34342
  try {
34332
- const settings = JSON.parse(readFileSync7(join15(home, ".claude", "settings.json"), "utf8"));
34343
+ const settings = JSON.parse(readFileSync7(join14(home, ".claude", "settings.json"), "utf8"));
34333
34344
  const present = (event, subcommand) => settings.hooks?.[event]?.some((entry) => entry.hooks?.some((item) => typeof item.command === "string" && isCanonicalCaveatClaudeHookCommand(item.command, subcommand, nodePath, cliScriptPath))) ?? false;
34334
34345
  return { user_prompt_submit: hook(present("UserPromptSubmit", "user-prompt-submit")), post_tool_use: hook(present("PostToolUse", "post-tool-use")), post_tool_use_failure: hook(present("PostToolUseFailure", "post-tool-use")), stop: hook(present("Stop", "stop")) };
34335
34346
  } catch {
@@ -34351,7 +34362,7 @@ function strictSearchSchema(db) {
34351
34362
  return columns.map((column) => `${column.name}:${column.hidden}`).join(",") === "id:0,title:0,body:0,tags:0,entries_fts:1,rank:1";
34352
34363
  }
34353
34364
  function database(path) {
34354
- if (!existsSync13(path)) return { status: "not_ready", reason_code: "missing", schema_version: null, supported_schema_version: 3, migration_status: "unverified" };
34365
+ if (!existsSync12(path)) return { status: "not_ready", reason_code: "missing", schema_version: null, supported_schema_version: 3, migration_status: "unverified" };
34355
34366
  try {
34356
34367
  const db = new DatabaseSync(path, { readOnly: true });
34357
34368
  try {
@@ -34376,8 +34387,8 @@ function database(path) {
34376
34387
  }
34377
34388
  }
34378
34389
  function codexFeature(codexHome) {
34379
- const path = join15(codexHome, "config.toml");
34380
- if (!existsSync13(path)) return status(false, "feature_disabled");
34390
+ const path = join14(codexHome, "config.toml");
34391
+ if (!existsSync12(path)) return status(false, "feature_disabled");
34381
34392
  try {
34382
34393
  const config2 = parseToml2(readFileSync7(path, "utf8"));
34383
34394
  if (!isRecord2(config2.features)) return status(false, "feature_disabled");
@@ -34388,7 +34399,7 @@ function codexFeature(codexHome) {
34388
34399
  }
34389
34400
  }
34390
34401
  function codexHooks(codexHome, nodePath, cliScriptPath) {
34391
- const value = JSON.parse(readFileSync7(join15(codexHome, "hooks.json"), "utf8"));
34402
+ const value = JSON.parse(readFileSync7(join14(codexHome, "hooks.json"), "utf8"));
34392
34403
  if (!isRecord2(value) || !isRecord2(value.hooks)) throw Error("config_unreadable");
34393
34404
  const hooks = value.hooks;
34394
34405
  const present = (event, subcommand) => Array.isArray(hooks[event]) && hooks[event].some((entry) => isRecord2(entry) && Array.isArray(entry.hooks) && entry.hooks.some((item) => isRecord2(item) && typeof item.command === "string" && isCanonicalCaveatCodexHookCommand(item.command, subcommand, nodePath, cliScriptPath)));
@@ -34423,7 +34434,7 @@ function sync(own) {
34423
34434
  return unverified("upstream_unavailable");
34424
34435
  }
34425
34436
  }
34426
- function factoryDiagnostics(ctx, codexHome = process.env.CODEX_HOME ?? join15(ctx.userHome, ".codex")) {
34437
+ function factoryDiagnostics(ctx, codexHome = process.env.CODEX_HOME ?? join14(ctx.userHome, ".codex")) {
34427
34438
  const nodePath = process.execPath;
34428
34439
  const cliScriptPath = process.argv[1] ?? "";
34429
34440
  const db = database(ctx.paths.dbPath);