caveat-cli 0.20.1 → 0.20.3

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
@@ -7,6 +7,9 @@ import {
7
7
  CAVEAT_AUTO_SYNC_ENV,
8
8
  KNOWLEDGE_GITIGNORE,
9
9
  PublishScanError,
10
+ SyncError,
11
+ SyncRecoveryError,
12
+ SyncRemoteError,
10
13
  __commonJS,
11
14
  __export,
12
15
  __toESM,
@@ -42,10 +45,12 @@ import {
42
45
  listRecent,
43
46
  listStale,
44
47
  loadConfig,
48
+ localHookDiagnostics,
45
49
  logHookQueryMiss,
46
50
  markHit,
47
51
  maybeSweepPendingDirs,
48
52
  nodeExecutableNames,
53
+ observeHookDiagnostic,
49
54
  observeRuntimeError,
50
55
  openDb,
51
56
  peekPendingRemindersDetailed,
@@ -82,7 +87,7 @@ import {
82
87
  writeDigestMarker,
83
88
  writeJevObservation,
84
89
  writeUserConfigPatch
85
- } from "./chunk-G52CLPRY.js";
90
+ } from "./chunk-TGIVITP4.js";
86
91
 
87
92
  // ../../node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js
88
93
  var require_code = __commonJS({
@@ -7726,17 +7731,19 @@ function diagnoseCursorHookConnector(cursorDir, nodePath, cliScriptPath) {
7726
7731
  // src/ghSetup.ts
7727
7732
  import { spawnSync } from "node:child_process";
7728
7733
  import { readSync } from "node:fs";
7734
+ var RepoSetupError = class extends Error {
7735
+ };
7729
7736
  function runGh(args) {
7730
7737
  const result = spawnSync("gh", args, { encoding: "utf-8" });
7731
7738
  return { status: result.status, stdout: typeof result.stdout === "string" ? result.stdout : "", stderr: typeof result.stderr === "string" ? result.stderr : "" };
7732
7739
  }
7733
7740
  function commandError(result, fallback) {
7734
- return new Error((result.stderr || result.stdout || fallback).trim());
7741
+ return new RepoSetupError((result.stderr || result.stdout || fallback).trim());
7735
7742
  }
7736
7743
  function defaultGitHubRepoUrl(opts) {
7737
7744
  const version2 = opts.ghRunner(["--version"]);
7738
7745
  if (version2.status !== 0) {
7739
- throw new Error(
7746
+ throw new RepoSetupError(
7740
7747
  `gh is not available. create a ${opts.visibility} repository named ${opts.repositoryName} on GitHub, then run:
7741
7748
  ${opts.retryCommand}
7742
7749
  # or install gh and retry`
@@ -7744,7 +7751,7 @@ function defaultGitHubRepoUrl(opts) {
7744
7751
  }
7745
7752
  const user = opts.ghRunner(["api", "user", "-q", ".login"]);
7746
7753
  if (user.status !== 0 || !user.stdout.trim()) {
7747
- throw new Error(`gh is not authenticated; run \`gh auth login\`, then retry \`${opts.retryCommand}\``);
7754
+ throw new RepoSetupError(`gh is not authenticated; run \`gh auth login\`, then retry \`${opts.retryCommand}\``);
7748
7755
  }
7749
7756
  const login = user.stdout.trim();
7750
7757
  const setupGit = opts.ghRunner(["auth", "setup-git"]);
@@ -7757,9 +7764,9 @@ function defaultGitHubRepoUrl(opts) {
7757
7764
  const question = `create ${opts.visibility} repo github.com/${qualifiedName}? [y/N]`;
7758
7765
  if (!opts.yes) {
7759
7766
  if (!opts.isTty()) {
7760
- throw new Error(`${question}; rerun with --yes to approve non-interactively`);
7767
+ throw new RepoSetupError(`${question}; rerun with --yes to approve non-interactively`);
7761
7768
  }
7762
- if (!opts.confirm(question)) throw new Error(`${opts.visibility} repository creation cancelled`);
7769
+ if (!opts.confirm(question)) throw new RepoSetupError(`${opts.visibility} repository creation cancelled`);
7763
7770
  }
7764
7771
  const create = opts.ghRunner(["repo", "create", opts.repositoryName, `--${opts.visibility}`]);
7765
7772
  if (create.status !== 0) throw commandError(create, "gh repo create failed");
@@ -8228,7 +8235,7 @@ async function runIndex(ctx, opts) {
8228
8235
  try {
8229
8236
  db = openDb({ path: ctx.paths.dbPath, logger: ctx.logger });
8230
8237
  } catch (error51) {
8231
- observeRuntimeError("CAVEAT.DATABASE_OPEN_FAILED", { version: CAVEAT_VERSION });
8238
+ observeRuntimeError("CAVEAT.DATABASE_OPEN_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
8232
8239
  throw error51;
8233
8240
  }
8234
8241
  try {
@@ -8246,7 +8253,7 @@ async function runIndex(ctx, opts) {
8246
8253
  }
8247
8254
  writeDigestMarker(ctx.caveatHome, computeEntriesDigest(ctx.paths));
8248
8255
  } catch (error51) {
8249
- observeRuntimeError("CAVEAT.INDEX_FAILED", { version: CAVEAT_VERSION });
8256
+ observeRuntimeError("CAVEAT.INDEX_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
8250
8257
  throw error51;
8251
8258
  } finally {
8252
8259
  db.close();
@@ -8402,7 +8409,7 @@ function runStats(ctx) {
8402
8409
 
8403
8410
  // src/commands/serve.ts
8404
8411
  async function runServe(opts) {
8405
- const { startServer } = await import("./server-2D6JIHWY.js");
8412
+ const { startServer } = await import("./server-A3BKQOHZ.js");
8406
8413
  const { port, host } = startServer({ port: opts.port });
8407
8414
  process.stdout.write(`[caveat] web portal: http://${host}:${port}/
8408
8415
  `);
@@ -32691,12 +32698,12 @@ function expectedControlFlow(error51) {
32691
32698
  const message = error51 instanceof Error ? error51.message : "";
32692
32699
  return /^caveat not found:/.test(message) || /^community エントリは購読物/.test(message) || /^immutable frontmatter key:/.test(message);
32693
32700
  }
32694
- function observeToolFailure(handler, productVersion = "0.0.0") {
32701
+ function observeToolFailure(handler, productVersion = "0.0.0", impact = "operation_failed") {
32695
32702
  return async (args) => {
32696
32703
  try {
32697
32704
  return jsonResult(await handler(args));
32698
32705
  } catch (error51) {
32699
- if (!expectedControlFlow(error51)) observeRuntimeError("CAVEAT.MCP_TOOL_FAILED", { version: productVersion });
32706
+ if (!expectedControlFlow(error51)) observeRuntimeError("CAVEAT.MCP_TOOL_FAILED", { version: productVersion, impact });
32700
32707
  throw error51;
32701
32708
  }
32702
32709
  };
@@ -32727,7 +32734,7 @@ function registerAllTools(server, ctx, productVersion = "0.0.0") {
32727
32734
  description: "Create a new caveat: a reusable record of a time-wasting trap (wrong driver, version mismatch, platform bug, IDE quirk, native-module issue, or repo-specific context) so future sessions can find it via caveat_search. REQUIRED BEFORE CALLING: run caveat_search first to avoid duplicates. Set visibility using this binary criterion: `public` if a third party could reproduce it; `private` if it is repo/workflow-specific or depends on intentional local design; when unclear, prefer `private`; follow an explicit user visibility choice. Qualifies: specific symptom + diagnosed cause (or `outcome: impossible` verdict) + environment fingerprint. Does NOT qualify: ordinary project-internal logic bugs, user preferences, session summaries, or ephemeral task notes; reusable repo-specific traps may be `private`. Auto-fills source_session and environment defaults; source_project is left null by design (shared knowledge must not leak per-user project names).",
32728
32735
  inputSchema: recordInputShape
32729
32736
  },
32730
- observeToolFailure((args) => handleRecord(ctx, args), productVersion)
32737
+ observeToolFailure((args) => handleRecord(ctx, args), productVersion, "mutation_outcome_unverified")
32731
32738
  );
32732
32739
  server.registerTool(
32733
32740
  "caveat_update",
@@ -32736,7 +32743,7 @@ function registerAllTools(server, ctx, productVersion = "0.0.0") {
32736
32743
  description: "Patch an existing caveat \u2014 use when newer evidence extends or corrects one that already exists. Frontmatter shallow-merges, but array fields (tags etc.) REPLACE rather than append \u2014 to add one tag, read the current list first, then patch with the full new array. Sections match by case-insensitive H2 heading. When changing `Symptom`, preserve raw errors verbatim and add stable Japanese/English symptom keywords when known; do not force or guess translations. Immutable keys: id, created_at, source_session, source_project. Common uses: bump `last_verified` after re-confirming, add a resolution when it was `tentative`, flip `outcome` to `impossible`.",
32737
32744
  inputSchema: updateInputShape
32738
32745
  },
32739
- observeToolFailure((args) => handleUpdate(ctx, args), productVersion)
32746
+ observeToolFailure((args) => handleUpdate(ctx, args), productVersion, "mutation_outcome_unverified")
32740
32747
  );
32741
32748
  server.registerTool(
32742
32749
  "caveat_list_recent",
@@ -32794,7 +32801,7 @@ async function runMcpServer() {
32794
32801
  try {
32795
32802
  await startMcpStdioServer({ productVersion: CAVEAT_VERSION });
32796
32803
  } catch (error51) {
32797
- observeRuntimeError("CAVEAT.MCP_SERVER_FAILED", { version: CAVEAT_VERSION });
32804
+ observeRuntimeError("CAVEAT.MCP_SERVER_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
32798
32805
  throw error51;
32799
32806
  }
32800
32807
  }
@@ -32948,7 +32955,11 @@ function errorMessage4(err) {
32948
32955
  return err instanceof Error ? err.message : String(err);
32949
32956
  }
32950
32957
  function reportHookError(host, phase, err) {
32951
- observeRuntimeError(host.errorCode, { version: CAVEAT_VERSION });
32958
+ observeRuntimeError(host.errorCode, {
32959
+ version: CAVEAT_VERSION,
32960
+ impact: phase === "markHit error" || phase === "query log error" || phase === "json parse error" ? "operation_failed" : "feature_unavailable"
32961
+ });
32962
+ observeHookDiagnostic(host.errorCode, phase, err, { version: CAVEAT_VERSION });
32952
32963
  process.stderr.write(`[${host.stderrTag}] ${phase}: ${errorMessage4(err)}
32953
32964
  `);
32954
32965
  try {
@@ -34525,7 +34536,15 @@ async function runSync(ctx, opts, dependencies = {}) {
34525
34536
  }
34526
34537
  }
34527
34538
  } catch (err) {
34528
- observeRuntimeError("CAVEAT.SYNC_FAILED", { version: CAVEAT_VERSION });
34539
+ if (!(err instanceof RepoSetupError || err instanceof SyncError || err instanceof SyncRemoteError)) {
34540
+ observeRuntimeError("CAVEAT.SYNC_FAILED", {
34541
+ version: CAVEAT_VERSION,
34542
+ impact: err instanceof SyncRecoveryError ? "recovery_failed" : "operation_failed"
34543
+ });
34544
+ ctx.logger.warn("sync did not complete; cause and recovery require investigation");
34545
+ }
34546
+ if (err instanceof SyncRemoteError) ctx.logger.warn(`sync remote command failed (${err.phase}); cause unconfirmed; local input retained; retry checks remote state`);
34547
+ if (err instanceof SyncRecoveryError) ctx.logger.warn("sync recovery is unverified; do not retry before inspecting the rebase");
34529
34548
  const message = err instanceof Error ? err.message : String(err);
34530
34549
  ctx.logger.error(message);
34531
34550
  process.exitCode = 1;
@@ -34776,6 +34795,7 @@ function runRuntimeErrors(action, value, opts = {}) {
34776
34795
  const runtime = { version: CAVEAT_VERSION };
34777
34796
  if (action === "snapshot") return runtimeErrorsSnapshot(opts.afterCursor ?? 0, opts.limit ?? 256, runtime);
34778
34797
  if (action === "diagnostics") return runtimeErrorsDiagnostics(runtime);
34798
+ if (action === "hook-details") return localHookDiagnostics(runtime);
34779
34799
  if (action === "report-status") return runtimeErrorReportStatus(runtime);
34780
34800
  if (action === "ack") return acknowledgeRuntimeErrors(parseCursor(value), runtime);
34781
34801
  if (action === "resolve") return setRuntimeErrorStatus(value ?? "", "resolved", runtime);
@@ -34871,7 +34891,7 @@ runtimeErrors.command("snapshot").requiredOption("--json", "emit JSON").option("
34871
34891
  process.stdout.write(`${JSON.stringify(runRuntimeErrors("snapshot", void 0, opts))}
34872
34892
  `);
34873
34893
  });
34874
- for (const action of ["diagnostics", "compact", "report-status"]) runtimeErrors.command(action).requiredOption("--json", "emit JSON").action(() => {
34894
+ for (const action of ["diagnostics", "compact", "report-status", "hook-details"]) runtimeErrors.command(action).requiredOption("--json", "emit JSON").action(() => {
34875
34895
  process.stdout.write(`${JSON.stringify(runRuntimeErrors(action))}
34876
34896
  `);
34877
34897
  });