caveat-cli 0.19.3 → 0.19.6

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
@@ -74,7 +74,7 @@ import {
74
74
  userPromptSubmitReminderText,
75
75
  writeDigestMarker,
76
76
  writeUserConfigPatch
77
- } from "./chunk-RO2ZVJMX.js";
77
+ } from "./chunk-EMGYSGFX.js";
78
78
 
79
79
  // ../../node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js
80
80
  var require_code = __commonJS({
@@ -8390,7 +8390,7 @@ function runStats(ctx) {
8390
8390
 
8391
8391
  // src/commands/serve.ts
8392
8392
  async function runServe(opts) {
8393
- const { startServer } = await import("./server-INQI6ANK.js");
8393
+ const { startServer } = await import("./server-RSDQNLWE.js");
8394
8394
  const { port, host } = startServer({ port: opts.port });
8395
8395
  process.stdout.write(`[caveat] web portal: http://${host}:${port}/
8396
8396
  `);
@@ -32988,7 +32988,7 @@ ${failureText}`).join("\n");
32988
32988
  function pendingCleanupFailureText(host) {
32989
32989
  return `[${host.stderrTag}] pending reminder cleanup failed`;
32990
32990
  }
32991
- function peekForSession(host, sessionId) {
32991
+ function peekForSession(host, sessionId, discardSession = false) {
32992
32992
  const ctx = buildContextSafely(host);
32993
32993
  if (!ctx) return { contexts: [], paths: [], caveatHome: null };
32994
32994
  const local = peekPendingRemindersDetailed(ctx.caveatHome, sessionId);
@@ -32997,7 +32997,15 @@ function peekForSession(host, sessionId) {
32997
32997
  process.stderr.write(`${pendingCleanupFailureText(host)}
32998
32998
  `);
32999
32999
  }
33000
- const reminders = [...local.reminders, ...global.reminders];
33000
+ if (discardSession) {
33001
+ try {
33002
+ acknowledgePendingReminders(ctx.caveatHome, local.reminders.map(({ path }) => path));
33003
+ } catch (error51) {
33004
+ process.stderr.write(`[${host.stderrTag}] pending reminder cleanup failed: ${errorMessage4(error51)}
33005
+ `);
33006
+ }
33007
+ }
33008
+ const reminders = discardSession ? global.reminders : [...local.reminders, ...global.reminders];
33001
33009
  return { contexts: reminders.map(({ text }) => text), paths: reminders.map(({ path }) => path), caveatHome: ctx.caveatHome };
33002
33010
  }
33003
33011
  function acknowledgeSessionReminders(host, peeked) {
@@ -33275,17 +33283,21 @@ async function rankKnowledge(key, turns, candidates, ask = callJev) {
33275
33283
  const state = {
33276
33284
  turns,
33277
33285
  currentHostOs: fingerprint().os,
33278
- candidates: candidates.map(({ hit, entry }) => ({
33279
- title: hit.title,
33280
- symptom: hit.symptomExcerpt,
33281
- cause: entry.sections.Cause?.slice(0, 300) ?? "",
33282
- resolution: entry.sections.Resolution?.slice(0, 600) ?? "",
33283
- environment: hit.environment
33284
- }))
33286
+ candidates: candidates.map(({ hit, entry }) => {
33287
+ const { applies_to_os: appliesToOs = null, ...recordedEnvironment } = hit.environment;
33288
+ return {
33289
+ title: hit.title,
33290
+ symptom: hit.symptomExcerpt,
33291
+ cause: entry.sections.Cause?.slice(0, 300) ?? "",
33292
+ resolution: entry.sections.Resolution?.slice(0, 600) ?? "",
33293
+ recordedEnvironment,
33294
+ appliesToOs
33295
+ };
33296
+ })
33285
33297
  };
33286
33298
  const questions = Object.fromEntries(candidates.map((_, index) => [`candidate_${index}`, {
33287
33299
  type: "noul",
33288
- instructions: `Does candidates[${index}] directly apply to the unresolved problem shown in the turns and offer a useful resolution? Check the described environment against the task's target environment; currentHostOs is the host OS, which may differ from the target OS.`
33300
+ instructions: `Does candidates[${index}] directly apply to the unresolved problem shown in the turns and offer a useful resolution? A recordedEnvironment value is where the entry was observed, not a restriction. Only appliesToOs restricts the target OS; null means any OS. currentHostOs may differ from the task's target OS.`
33289
33301
  }]));
33290
33302
  const response = await ask(key, state, questions);
33291
33303
  let best = null;
@@ -33513,6 +33525,7 @@ async function runWorker(workFile) {
33513
33525
  process.exit(0);
33514
33526
  }
33515
33527
  if (!job.failureText || !job.sessionId) process.exit(0);
33528
+ if (buildContextSafely(CLAUDE_HOST)?.config.jevEnabled) process.exit(0);
33516
33529
  const hits = searchCaveatsSafely(CLAUDE_HOST, {
33517
33530
  topicText: job.topicText,
33518
33531
  failureText: job.failureText,
@@ -33724,10 +33737,10 @@ async function runHook(name, arg) {
33724
33737
  }
33725
33738
  const payload = parsePayload(CLAUDE_HOST, raw);
33726
33739
  const sessionId = getSessionId(payload);
33727
- const pending = name === "stop" ? null : peekForSession(CLAUDE_HOST, sessionId);
33728
- const contexts = pending?.contexts ?? [];
33729
33740
  if (name === "user-prompt-submit") {
33730
33741
  const ctx = buildContextSafely(CLAUDE_HOST);
33742
+ const pending = peekForSession(CLAUDE_HOST, sessionId, ctx?.config.jevEnabled === true);
33743
+ const contexts = pending.contexts;
33731
33744
  let jevNotice = null;
33732
33745
  if (ctx?.config.jevEnabled) {
33733
33746
  try {
@@ -33738,10 +33751,10 @@ async function runHook(name, arg) {
33738
33751
  `);
33739
33752
  }
33740
33753
  }
33741
- const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
33742
- const hits = searchCaveatsSafely(CLAUDE_HOST, { topicText: prompt, failureText: prompt, surface: "user_prompt" });
33743
- if (hits.length > 0) {
33744
- contexts.push(userPromptSubmitReminderText(hits));
33754
+ if (ctx && !ctx.config.jevEnabled) {
33755
+ const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
33756
+ const hits = searchCaveatsSafely(CLAUDE_HOST, { topicText: prompt, failureText: prompt, surface: "user_prompt" });
33757
+ if (hits.length > 0) contexts.push(userPromptSubmitReminderText(hits));
33745
33758
  }
33746
33759
  if (ctx) {
33747
33760
  try {
@@ -33762,6 +33775,9 @@ async function runHook(name, arg) {
33762
33775
  }
33763
33776
  if (name === "post-tool-use") {
33764
33777
  const ctx = buildContextSafely(CLAUDE_HOST);
33778
+ if (ctx?.config.jevEnabled) process.exit(0);
33779
+ const pending = peekForSession(CLAUDE_HOST, sessionId);
33780
+ const contexts = pending.contexts;
33765
33781
  if (ctx) {
33766
33782
  try {
33767
33783
  const prepared = prepareSessionDelivery(ctx.caveatHome, sessionId, contexts);
@@ -33906,26 +33922,28 @@ function toolInputText(input) {
33906
33922
  const command = r.command ?? r.cmd;
33907
33923
  return typeof command === "string" ? command : "";
33908
33924
  }
33909
- function isCodexToolError(payload) {
33910
- if (payload.is_error === true) return true;
33911
- const topExit = numericExitCode(payload.exit_code ?? payload.exitCode);
33912
- if (topExit !== null) return topExit !== 0;
33925
+ function codexToolStatus(payload) {
33926
+ if (payload.is_error === true) return "failed";
33913
33927
  const resp = payload.tool_response ?? payload.toolResponse;
33928
+ if (resp !== null && typeof resp === "object" && !Array.isArray(resp) && resp.is_error === true) return "failed";
33929
+ const topExit = numericExitCode(payload.exit_code ?? payload.exitCode);
33930
+ if (topExit !== null) return topExit === 0 ? "succeeded" : "failed";
33914
33931
  if (resp !== null && typeof resp === "object" && !Array.isArray(resp)) {
33915
33932
  const r = resp;
33916
- if (r.is_error === true) return true;
33917
33933
  const exit = numericExitCode(r.exit_code ?? r.exitCode);
33918
- if (exit !== null) return exit !== 0;
33934
+ if (exit !== null) return exit === 0 ? "succeeded" : "failed";
33919
33935
  }
33920
33936
  const responseExit = processExitCodeFromText(extractToolResponseText(resp));
33921
- if (responseExit !== null) return responseExit !== 0;
33937
+ if (responseExit !== null) return responseExit === 0 ? "succeeded" : "failed";
33922
33938
  const transcriptExit = transcriptExitCode(payload);
33923
- if (transcriptExit !== null) return transcriptExit !== 0;
33924
- return false;
33939
+ if (transcriptExit !== null) return transcriptExit === 0 ? "succeeded" : "failed";
33940
+ return "unknown";
33925
33941
  }
33926
33942
  function buildCodexPostToolUseWorkerJob(payload) {
33927
33943
  const sessionId = codexSessionId(payload);
33928
33944
  if (!sessionId) return null;
33945
+ const status2 = codexToolStatus(payload);
33946
+ if (status2 === "succeeded") return null;
33929
33947
  const transcriptPath = typeof payload.transcript_path === "string" ? payload.transcript_path : void 0;
33930
33948
  const toolUseId = typeof payload.tool_use_id === "string" ? payload.tool_use_id : void 0;
33931
33949
  const responseText = extractToolResponseText(payload.tool_response ?? payload.toolResponse);
@@ -33933,8 +33951,7 @@ function buildCodexPostToolUseWorkerJob(payload) {
33933
33951
  const transcriptOutput = transcriptPath && toolUseId ? transcriptToolOutput(transcriptPath, toolUseId) : null;
33934
33952
  const topicText = inputText.trim();
33935
33953
  const failureText = [responseText, transcriptOutput ?? ""].map((s) => s.trim()).filter(Boolean).join("\n");
33936
- const knownError = isCodexToolError(payload);
33937
- if (knownError) {
33954
+ if (status2 === "failed") {
33938
33955
  return { sessionId, topicText, failureText, knownError: true, transcriptPath, toolUseId };
33939
33956
  }
33940
33957
  if (transcriptPath && toolUseId && isShellLikeTool(payload) && (topicText || failureText)) {
@@ -33968,6 +33985,7 @@ async function waitForTranscriptOutput(transcriptPath, toolUseId) {
33968
33985
  return null;
33969
33986
  }
33970
33987
  async function processCodexWorkerJob(job, opts = { waitForTranscript: true }) {
33988
+ if (buildContextSafely(CODEX_HOST)?.config.jevEnabled) return;
33971
33989
  if (!job.topicText && !job.failureText || !job.sessionId) return;
33972
33990
  let failureText = job.failureText;
33973
33991
  let knownError = job.knownError === true;
@@ -34072,9 +34090,9 @@ async function runCodexHook(name, arg) {
34072
34090
  const sessionId = codexSessionId(payload);
34073
34091
  if (!sessionId) process.stderr.write("[caveat:codex-hook] missing session_id; pending drain disabled\n");
34074
34092
  if (name === "user-prompt-submit") {
34075
- const pending = sessionId ? peekForSession(CODEX_HOST, sessionId) : null;
34076
- const contexts = pending?.contexts ?? [];
34077
34093
  const ctx = buildContextSafely(CODEX_HOST);
34094
+ const pending = sessionId ? peekForSession(CODEX_HOST, sessionId, ctx?.config.jevEnabled === true) : null;
34095
+ const contexts = pending?.contexts ?? [];
34078
34096
  let jevNotice = null;
34079
34097
  if (ctx?.config.jevEnabled) {
34080
34098
  try {
@@ -34085,10 +34103,10 @@ async function runCodexHook(name, arg) {
34085
34103
  `);
34086
34104
  }
34087
34105
  }
34088
- const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
34089
- const hits = searchCaveatsSafely(CODEX_HOST, { topicText: prompt, failureText: prompt, surface: "user_prompt" });
34090
- if (hits.length > 0) {
34091
- contexts.push(userPromptSubmitReminderText(hits, "native-cli"));
34106
+ if (ctx && !ctx.config.jevEnabled) {
34107
+ const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
34108
+ const hits = searchCaveatsSafely(CODEX_HOST, { topicText: prompt, failureText: prompt, surface: "user_prompt" });
34109
+ if (hits.length > 0) contexts.push(userPromptSubmitReminderText(hits, "native-cli"));
34092
34110
  }
34093
34111
  if (ctx) {
34094
34112
  try {
@@ -34108,6 +34126,7 @@ async function runCodexHook(name, arg) {
34108
34126
  process.exit(0);
34109
34127
  }
34110
34128
  if (name === "post-tool-use") {
34129
+ if (buildContextSafely(CODEX_HOST)?.config.jevEnabled) process.exit(0);
34111
34130
  const job = buildCodexPostToolUseWorkerJob(payload);
34112
34131
  if (job) await processCodexWorkerJob(job, { waitForTranscript: false });
34113
34132
  process.exit(0);