caveat-cli 0.20.2 → 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,
@@ -84,7 +87,7 @@ import {
84
87
  writeDigestMarker,
85
88
  writeJevObservation,
86
89
  writeUserConfigPatch
87
- } from "./chunk-JYXVT46B.js";
90
+ } from "./chunk-TGIVITP4.js";
88
91
 
89
92
  // ../../node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js
90
93
  var require_code = __commonJS({
@@ -7728,17 +7731,19 @@ function diagnoseCursorHookConnector(cursorDir, nodePath, cliScriptPath) {
7728
7731
  // src/ghSetup.ts
7729
7732
  import { spawnSync } from "node:child_process";
7730
7733
  import { readSync } from "node:fs";
7734
+ var RepoSetupError = class extends Error {
7735
+ };
7731
7736
  function runGh(args) {
7732
7737
  const result = spawnSync("gh", args, { encoding: "utf-8" });
7733
7738
  return { status: result.status, stdout: typeof result.stdout === "string" ? result.stdout : "", stderr: typeof result.stderr === "string" ? result.stderr : "" };
7734
7739
  }
7735
7740
  function commandError(result, fallback) {
7736
- return new Error((result.stderr || result.stdout || fallback).trim());
7741
+ return new RepoSetupError((result.stderr || result.stdout || fallback).trim());
7737
7742
  }
7738
7743
  function defaultGitHubRepoUrl(opts) {
7739
7744
  const version2 = opts.ghRunner(["--version"]);
7740
7745
  if (version2.status !== 0) {
7741
- throw new Error(
7746
+ throw new RepoSetupError(
7742
7747
  `gh is not available. create a ${opts.visibility} repository named ${opts.repositoryName} on GitHub, then run:
7743
7748
  ${opts.retryCommand}
7744
7749
  # or install gh and retry`
@@ -7746,7 +7751,7 @@ function defaultGitHubRepoUrl(opts) {
7746
7751
  }
7747
7752
  const user = opts.ghRunner(["api", "user", "-q", ".login"]);
7748
7753
  if (user.status !== 0 || !user.stdout.trim()) {
7749
- 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}\``);
7750
7755
  }
7751
7756
  const login = user.stdout.trim();
7752
7757
  const setupGit = opts.ghRunner(["auth", "setup-git"]);
@@ -7759,9 +7764,9 @@ function defaultGitHubRepoUrl(opts) {
7759
7764
  const question = `create ${opts.visibility} repo github.com/${qualifiedName}? [y/N]`;
7760
7765
  if (!opts.yes) {
7761
7766
  if (!opts.isTty()) {
7762
- throw new Error(`${question}; rerun with --yes to approve non-interactively`);
7767
+ throw new RepoSetupError(`${question}; rerun with --yes to approve non-interactively`);
7763
7768
  }
7764
- 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`);
7765
7770
  }
7766
7771
  const create = opts.ghRunner(["repo", "create", opts.repositoryName, `--${opts.visibility}`]);
7767
7772
  if (create.status !== 0) throw commandError(create, "gh repo create failed");
@@ -8230,7 +8235,7 @@ async function runIndex(ctx, opts) {
8230
8235
  try {
8231
8236
  db = openDb({ path: ctx.paths.dbPath, logger: ctx.logger });
8232
8237
  } catch (error51) {
8233
- observeRuntimeError("CAVEAT.DATABASE_OPEN_FAILED", { version: CAVEAT_VERSION });
8238
+ observeRuntimeError("CAVEAT.DATABASE_OPEN_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
8234
8239
  throw error51;
8235
8240
  }
8236
8241
  try {
@@ -8248,7 +8253,7 @@ async function runIndex(ctx, opts) {
8248
8253
  }
8249
8254
  writeDigestMarker(ctx.caveatHome, computeEntriesDigest(ctx.paths));
8250
8255
  } catch (error51) {
8251
- observeRuntimeError("CAVEAT.INDEX_FAILED", { version: CAVEAT_VERSION });
8256
+ observeRuntimeError("CAVEAT.INDEX_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
8252
8257
  throw error51;
8253
8258
  } finally {
8254
8259
  db.close();
@@ -8404,7 +8409,7 @@ function runStats(ctx) {
8404
8409
 
8405
8410
  // src/commands/serve.ts
8406
8411
  async function runServe(opts) {
8407
- const { startServer } = await import("./server-XI7ZOMPY.js");
8412
+ const { startServer } = await import("./server-A3BKQOHZ.js");
8408
8413
  const { port, host } = startServer({ port: opts.port });
8409
8414
  process.stdout.write(`[caveat] web portal: http://${host}:${port}/
8410
8415
  `);
@@ -32693,12 +32698,12 @@ function expectedControlFlow(error51) {
32693
32698
  const message = error51 instanceof Error ? error51.message : "";
32694
32699
  return /^caveat not found:/.test(message) || /^community エントリは購読物/.test(message) || /^immutable frontmatter key:/.test(message);
32695
32700
  }
32696
- function observeToolFailure(handler, productVersion = "0.0.0") {
32701
+ function observeToolFailure(handler, productVersion = "0.0.0", impact = "operation_failed") {
32697
32702
  return async (args) => {
32698
32703
  try {
32699
32704
  return jsonResult(await handler(args));
32700
32705
  } catch (error51) {
32701
- if (!expectedControlFlow(error51)) observeRuntimeError("CAVEAT.MCP_TOOL_FAILED", { version: productVersion });
32706
+ if (!expectedControlFlow(error51)) observeRuntimeError("CAVEAT.MCP_TOOL_FAILED", { version: productVersion, impact });
32702
32707
  throw error51;
32703
32708
  }
32704
32709
  };
@@ -32729,7 +32734,7 @@ function registerAllTools(server, ctx, productVersion = "0.0.0") {
32729
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).",
32730
32735
  inputSchema: recordInputShape
32731
32736
  },
32732
- observeToolFailure((args) => handleRecord(ctx, args), productVersion)
32737
+ observeToolFailure((args) => handleRecord(ctx, args), productVersion, "mutation_outcome_unverified")
32733
32738
  );
32734
32739
  server.registerTool(
32735
32740
  "caveat_update",
@@ -32738,7 +32743,7 @@ function registerAllTools(server, ctx, productVersion = "0.0.0") {
32738
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`.",
32739
32744
  inputSchema: updateInputShape
32740
32745
  },
32741
- observeToolFailure((args) => handleUpdate(ctx, args), productVersion)
32746
+ observeToolFailure((args) => handleUpdate(ctx, args), productVersion, "mutation_outcome_unverified")
32742
32747
  );
32743
32748
  server.registerTool(
32744
32749
  "caveat_list_recent",
@@ -32796,7 +32801,7 @@ async function runMcpServer() {
32796
32801
  try {
32797
32802
  await startMcpStdioServer({ productVersion: CAVEAT_VERSION });
32798
32803
  } catch (error51) {
32799
- observeRuntimeError("CAVEAT.MCP_SERVER_FAILED", { version: CAVEAT_VERSION });
32804
+ observeRuntimeError("CAVEAT.MCP_SERVER_FAILED", { version: CAVEAT_VERSION, impact: "feature_unavailable" });
32800
32805
  throw error51;
32801
32806
  }
32802
32807
  }
@@ -32950,7 +32955,10 @@ function errorMessage4(err) {
32950
32955
  return err instanceof Error ? err.message : String(err);
32951
32956
  }
32952
32957
  function reportHookError(host, phase, err) {
32953
- 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
+ });
32954
32962
  observeHookDiagnostic(host.errorCode, phase, err, { version: CAVEAT_VERSION });
32955
32963
  process.stderr.write(`[${host.stderrTag}] ${phase}: ${errorMessage4(err)}
32956
32964
  `);
@@ -34528,7 +34536,15 @@ async function runSync(ctx, opts, dependencies = {}) {
34528
34536
  }
34529
34537
  }
34530
34538
  } catch (err) {
34531
- 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");
34532
34548
  const message = err instanceof Error ? err.message : String(err);
34533
34549
  ctx.logger.error(message);
34534
34550
  process.exitCode = 1;