caveat-cli 0.16.2 → 0.16.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/{chunk-3MLJQLWY.js → chunk-PD5E6TFL.js} +387 -69
- package/dist/chunk-PD5E6TFL.js.map +1 -0
- package/dist/index.js +463 -171
- package/dist/index.js.map +1 -1
- package/dist/{server-LAJCQXS3.js → server-ZMIRSFMH.js} +2 -2
- package/package.json +3 -3
- package/dist/chunk-3MLJQLWY.js.map +0 -1
- /package/dist/{server-LAJCQXS3.js.map → server-ZMIRSFMH.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
__commonJS,
|
|
11
11
|
__export,
|
|
12
12
|
__toESM,
|
|
13
|
+
acknowledgeRuntimeErrors,
|
|
13
14
|
acquireReindexLock,
|
|
14
15
|
buildAndPublishPendingReminder,
|
|
15
16
|
buildCodexSidecarDiagnosticsCommand,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
communityList,
|
|
24
25
|
communityPull,
|
|
25
26
|
communityRemove,
|
|
27
|
+
compactRuntimeErrors,
|
|
26
28
|
computeEntriesDigest,
|
|
27
29
|
createKeyserverKeyProvider,
|
|
28
30
|
decideCodexSidecarExecution,
|
|
@@ -41,6 +43,7 @@ import {
|
|
|
41
43
|
logHookQueryMiss,
|
|
42
44
|
markHit,
|
|
43
45
|
maybeSweepPendingDirs,
|
|
46
|
+
observeRuntimeError,
|
|
44
47
|
openDb,
|
|
45
48
|
prewarmSealedKeys,
|
|
46
49
|
publishOwn,
|
|
@@ -54,7 +57,10 @@ import {
|
|
|
54
57
|
resetAutoSyncFailureState,
|
|
55
58
|
resolvePaths,
|
|
56
59
|
runAutoSync,
|
|
60
|
+
runtimeErrorsDiagnostics,
|
|
61
|
+
runtimeErrorsSnapshot,
|
|
57
62
|
search,
|
|
63
|
+
setRuntimeErrorStatus,
|
|
58
64
|
stderrLogger,
|
|
59
65
|
stopReminderText,
|
|
60
66
|
struggleSearchText,
|
|
@@ -64,7 +70,7 @@ import {
|
|
|
64
70
|
userPromptSubmitReminderText,
|
|
65
71
|
writeDigestMarker,
|
|
66
72
|
writeUserConfigPatch
|
|
67
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-PD5E6TFL.js";
|
|
68
74
|
|
|
69
75
|
// ../../node_modules/.pnpm/ajv@8.18.0/node_modules/ajv/dist/compile/codegen/code.js
|
|
70
76
|
var require_code = __commonJS({
|
|
@@ -443,11 +449,11 @@ var require_codegen = __commonJS({
|
|
|
443
449
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
444
450
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
445
451
|
}
|
|
446
|
-
optimizeNames(names,
|
|
452
|
+
optimizeNames(names, constants4) {
|
|
447
453
|
if (!names[this.name.str])
|
|
448
454
|
return;
|
|
449
455
|
if (this.rhs)
|
|
450
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
456
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
451
457
|
return this;
|
|
452
458
|
}
|
|
453
459
|
get names() {
|
|
@@ -464,10 +470,10 @@ var require_codegen = __commonJS({
|
|
|
464
470
|
render({ _n }) {
|
|
465
471
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
466
472
|
}
|
|
467
|
-
optimizeNames(names,
|
|
473
|
+
optimizeNames(names, constants4) {
|
|
468
474
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
|
|
469
475
|
return;
|
|
470
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
476
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
471
477
|
return this;
|
|
472
478
|
}
|
|
473
479
|
get names() {
|
|
@@ -528,8 +534,8 @@ var require_codegen = __commonJS({
|
|
|
528
534
|
optimizeNodes() {
|
|
529
535
|
return `${this.code}` ? this : void 0;
|
|
530
536
|
}
|
|
531
|
-
optimizeNames(names,
|
|
532
|
-
this.code = optimizeExpr(this.code, names,
|
|
537
|
+
optimizeNames(names, constants4) {
|
|
538
|
+
this.code = optimizeExpr(this.code, names, constants4);
|
|
533
539
|
return this;
|
|
534
540
|
}
|
|
535
541
|
get names() {
|
|
@@ -558,12 +564,12 @@ var require_codegen = __commonJS({
|
|
|
558
564
|
}
|
|
559
565
|
return nodes.length > 0 ? this : void 0;
|
|
560
566
|
}
|
|
561
|
-
optimizeNames(names,
|
|
567
|
+
optimizeNames(names, constants4) {
|
|
562
568
|
const { nodes } = this;
|
|
563
569
|
let i = nodes.length;
|
|
564
570
|
while (i--) {
|
|
565
571
|
const n = nodes[i];
|
|
566
|
-
if (n.optimizeNames(names,
|
|
572
|
+
if (n.optimizeNames(names, constants4))
|
|
567
573
|
continue;
|
|
568
574
|
subtractNames(names, n.names);
|
|
569
575
|
nodes.splice(i, 1);
|
|
@@ -616,12 +622,12 @@ var require_codegen = __commonJS({
|
|
|
616
622
|
return void 0;
|
|
617
623
|
return this;
|
|
618
624
|
}
|
|
619
|
-
optimizeNames(names,
|
|
625
|
+
optimizeNames(names, constants4) {
|
|
620
626
|
var _a3;
|
|
621
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
622
|
-
if (!(super.optimizeNames(names,
|
|
627
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants4);
|
|
628
|
+
if (!(super.optimizeNames(names, constants4) || this.else))
|
|
623
629
|
return;
|
|
624
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
630
|
+
this.condition = optimizeExpr(this.condition, names, constants4);
|
|
625
631
|
return this;
|
|
626
632
|
}
|
|
627
633
|
get names() {
|
|
@@ -644,10 +650,10 @@ var require_codegen = __commonJS({
|
|
|
644
650
|
render(opts) {
|
|
645
651
|
return `for(${this.iteration})` + super.render(opts);
|
|
646
652
|
}
|
|
647
|
-
optimizeNames(names,
|
|
648
|
-
if (!super.optimizeNames(names,
|
|
653
|
+
optimizeNames(names, constants4) {
|
|
654
|
+
if (!super.optimizeNames(names, constants4))
|
|
649
655
|
return;
|
|
650
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
656
|
+
this.iteration = optimizeExpr(this.iteration, names, constants4);
|
|
651
657
|
return this;
|
|
652
658
|
}
|
|
653
659
|
get names() {
|
|
@@ -683,10 +689,10 @@ var require_codegen = __commonJS({
|
|
|
683
689
|
render(opts) {
|
|
684
690
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
685
691
|
}
|
|
686
|
-
optimizeNames(names,
|
|
687
|
-
if (!super.optimizeNames(names,
|
|
692
|
+
optimizeNames(names, constants4) {
|
|
693
|
+
if (!super.optimizeNames(names, constants4))
|
|
688
694
|
return;
|
|
689
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
695
|
+
this.iterable = optimizeExpr(this.iterable, names, constants4);
|
|
690
696
|
return this;
|
|
691
697
|
}
|
|
692
698
|
get names() {
|
|
@@ -728,11 +734,11 @@ var require_codegen = __commonJS({
|
|
|
728
734
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
729
735
|
return this;
|
|
730
736
|
}
|
|
731
|
-
optimizeNames(names,
|
|
737
|
+
optimizeNames(names, constants4) {
|
|
732
738
|
var _a3, _b;
|
|
733
|
-
super.optimizeNames(names,
|
|
734
|
-
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
735
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names,
|
|
739
|
+
super.optimizeNames(names, constants4);
|
|
740
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants4);
|
|
741
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants4);
|
|
736
742
|
return this;
|
|
737
743
|
}
|
|
738
744
|
get names() {
|
|
@@ -1033,7 +1039,7 @@ var require_codegen = __commonJS({
|
|
|
1033
1039
|
function addExprNames(names, from) {
|
|
1034
1040
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
1035
1041
|
}
|
|
1036
|
-
function optimizeExpr(expr, names,
|
|
1042
|
+
function optimizeExpr(expr, names, constants4) {
|
|
1037
1043
|
if (expr instanceof code_1.Name)
|
|
1038
1044
|
return replaceName(expr);
|
|
1039
1045
|
if (!canOptimize(expr))
|
|
@@ -1048,14 +1054,14 @@ var require_codegen = __commonJS({
|
|
|
1048
1054
|
return items;
|
|
1049
1055
|
}, []));
|
|
1050
1056
|
function replaceName(n) {
|
|
1051
|
-
const c =
|
|
1057
|
+
const c = constants4[n.str];
|
|
1052
1058
|
if (c === void 0 || names[n.str] !== 1)
|
|
1053
1059
|
return n;
|
|
1054
1060
|
delete names[n.str];
|
|
1055
1061
|
return c;
|
|
1056
1062
|
}
|
|
1057
1063
|
function canOptimize(e) {
|
|
1058
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
1064
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants4[c.str] !== void 0);
|
|
1059
1065
|
}
|
|
1060
1066
|
}
|
|
1061
1067
|
function subtractNames(names, from) {
|
|
@@ -6882,8 +6888,8 @@ import { dirname as dirname4, join as join8 } from "node:path";
|
|
|
6882
6888
|
|
|
6883
6889
|
// src/claudeInstall.ts
|
|
6884
6890
|
import { spawnSync } from "node:child_process";
|
|
6885
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
6886
|
-
import { dirname as dirname2, join as join3 } from "node:path";
|
|
6891
|
+
import { accessSync, constants, copyFileSync, existsSync, mkdirSync, readFileSync as readFileSync2, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
6892
|
+
import { dirname as dirname2, isAbsolute, join as join3 } from "node:path";
|
|
6887
6893
|
var EVENT_USER_PROMPT_SUBMIT = "UserPromptSubmit";
|
|
6888
6894
|
var EVENT_POST_TOOL_USE = "PostToolUse";
|
|
6889
6895
|
var EVENT_POST_TOOL_USE_FAILURE = "PostToolUseFailure";
|
|
@@ -6902,10 +6908,10 @@ function upsertHook(settings, event, command) {
|
|
|
6902
6908
|
const list = settings.hooks[event] ??= [];
|
|
6903
6909
|
const subcommand = command.includes("hook user-prompt-submit") ? "user-prompt-submit" : command.includes("hook post-tool-use") ? "post-tool-use" : command.includes("hook stop") ? "stop" : null;
|
|
6904
6910
|
for (const entry of list) {
|
|
6905
|
-
for (const
|
|
6906
|
-
if (isSameHookCommand(
|
|
6907
|
-
if (subcommand && isCaveatClaudeHookCommand(
|
|
6908
|
-
|
|
6911
|
+
for (const hook2 of entry.hooks ?? []) {
|
|
6912
|
+
if (isSameHookCommand(hook2.command, command)) return "unchanged";
|
|
6913
|
+
if (subcommand && isCaveatClaudeHookCommand(hook2.command, subcommand)) {
|
|
6914
|
+
hook2.command = command;
|
|
6909
6915
|
return "added";
|
|
6910
6916
|
}
|
|
6911
6917
|
}
|
|
@@ -6943,6 +6949,36 @@ function isCaveatClaudeHookCommand(actual, event) {
|
|
|
6943
6949
|
const lower = actual.toLowerCase();
|
|
6944
6950
|
return !isEnvPrefixedCommand(actual) && lower.includes("caveat") && actual.includes(`hook ${event}`);
|
|
6945
6951
|
}
|
|
6952
|
+
function commandTokens(command) {
|
|
6953
|
+
const tokens = [];
|
|
6954
|
+
const pattern = /"([^"]*)"|([^\s"]+)/g;
|
|
6955
|
+
let end = 0;
|
|
6956
|
+
let match;
|
|
6957
|
+
while ((match = pattern.exec(command)) !== null) {
|
|
6958
|
+
if (command.slice(end, match.index).trim()) return null;
|
|
6959
|
+
tokens.push(match[1] ?? match[2]);
|
|
6960
|
+
end = pattern.lastIndex;
|
|
6961
|
+
}
|
|
6962
|
+
return command.slice(end).trim() ? null : tokens;
|
|
6963
|
+
}
|
|
6964
|
+
function isCanonicalAsset(path, expectedPath, mode) {
|
|
6965
|
+
if (typeof path !== "string" || !isAbsolute(path) || !isAbsolute(expectedPath)) return false;
|
|
6966
|
+
try {
|
|
6967
|
+
accessSync(path, mode);
|
|
6968
|
+
return statSync(path).isFile() && realpathSync(path) === realpathSync(expectedPath);
|
|
6969
|
+
} catch {
|
|
6970
|
+
return false;
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6973
|
+
function isCanonicalCaveatClaudeHookCommand(actual, event, nodePath, cliScriptPath) {
|
|
6974
|
+
const tokens = commandTokens(actual);
|
|
6975
|
+
return tokens?.length === 4 && isCanonicalAsset(tokens[0], nodePath, constants.X_OK) && isCanonicalAsset(tokens[1], cliScriptPath, constants.R_OK) && tokens[2] === "hook" && tokens[3] === event;
|
|
6976
|
+
}
|
|
6977
|
+
function isCaveatClaudeMcpRegistration(value, nodePath, cliScriptPath) {
|
|
6978
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
6979
|
+
const server = value;
|
|
6980
|
+
return Object.keys(server).length === 4 && ["args", "command", "env", "type"].every((key) => Object.hasOwn(server, key)) && server.type === "stdio" && isCanonicalAsset(server.command, nodePath, constants.X_OK) && Array.isArray(server.args) && server.args.length === 3 && server.args[0] === "--disable-warning=ExperimentalWarning" && isCanonicalAsset(server.args[1], cliScriptPath, constants.R_OK) && server.args[2] === "mcp-server" && server.env !== null && typeof server.env === "object" && !Array.isArray(server.env) && Object.keys(server.env).length === 0;
|
|
6981
|
+
}
|
|
6946
6982
|
function readSettings(path) {
|
|
6947
6983
|
if (!existsSync(path)) return {};
|
|
6948
6984
|
return JSON.parse(readFileSync2(path, "utf-8"));
|
|
@@ -7074,8 +7110,8 @@ function uninstallClaudeIntegration(opts) {
|
|
|
7074
7110
|
}
|
|
7075
7111
|
|
|
7076
7112
|
// src/codexHookInstall.ts
|
|
7077
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7078
|
-
import { dirname as dirname3, join as join4 } from "node:path";
|
|
7113
|
+
import { accessSync as accessSync2, constants as constants2, copyFileSync as copyFileSync2, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7114
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join4 } from "node:path";
|
|
7079
7115
|
import { parse as parseToml } from "smol-toml";
|
|
7080
7116
|
function quote2(p) {
|
|
7081
7117
|
return p.includes(" ") ? `"${p}"` : p;
|
|
@@ -7093,6 +7129,31 @@ function isCaveatCodexHookCommand(actual, event) {
|
|
|
7093
7129
|
const lower = actual.toLowerCase();
|
|
7094
7130
|
return lower.includes("caveat") && actual.includes(eventCommandFragment(event));
|
|
7095
7131
|
}
|
|
7132
|
+
function commandTokens2(command) {
|
|
7133
|
+
const tokens = [];
|
|
7134
|
+
const pattern = /"([^"]*)"|([^\s"]+)/g;
|
|
7135
|
+
let end = 0;
|
|
7136
|
+
let match;
|
|
7137
|
+
while ((match = pattern.exec(command)) !== null) {
|
|
7138
|
+
if (command.slice(end, match.index).trim()) return null;
|
|
7139
|
+
tokens.push(match[1] ?? match[2]);
|
|
7140
|
+
end = pattern.lastIndex;
|
|
7141
|
+
}
|
|
7142
|
+
return command.slice(end).trim() ? null : tokens;
|
|
7143
|
+
}
|
|
7144
|
+
function isCanonicalAsset2(path, expectedPath, mode) {
|
|
7145
|
+
if (typeof path !== "string" || !isAbsolute2(path) || !isAbsolute2(expectedPath)) return false;
|
|
7146
|
+
try {
|
|
7147
|
+
accessSync2(path, mode);
|
|
7148
|
+
return statSync2(path).isFile() && realpathSync2(path) === realpathSync2(expectedPath);
|
|
7149
|
+
} catch {
|
|
7150
|
+
return false;
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7153
|
+
function isCanonicalCaveatCodexHookCommand(actual, event, nodePath, cliScriptPath) {
|
|
7154
|
+
const tokens = commandTokens2(actual);
|
|
7155
|
+
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
|
+
}
|
|
7096
7157
|
function hasCaveatHook(hooksJson, event, fragment) {
|
|
7097
7158
|
return hooksJson.hooks?.[event]?.some(
|
|
7098
7159
|
(entry) => entry.hooks?.some((h) => h.command.includes(fragment))
|
|
@@ -7118,13 +7179,13 @@ function upsertHook2(hooksJson, event, command, subcommand) {
|
|
|
7118
7179
|
hooksJson.hooks ??= {};
|
|
7119
7180
|
const list = hooksJson.hooks[event] ??= [];
|
|
7120
7181
|
for (const entry of list) {
|
|
7121
|
-
for (const
|
|
7122
|
-
if (isSameHookCommand2(
|
|
7123
|
-
if (isCaveatCodexHookCommand(
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7182
|
+
for (const hook2 of entry.hooks ?? []) {
|
|
7183
|
+
if (isSameHookCommand2(hook2.command, command)) return "unchanged";
|
|
7184
|
+
if (isCaveatCodexHookCommand(hook2.command, subcommand)) {
|
|
7185
|
+
hook2.command = command;
|
|
7186
|
+
hook2.timeoutSec = 5;
|
|
7187
|
+
hook2.async = false;
|
|
7188
|
+
hook2.statusMessage = null;
|
|
7128
7189
|
return "added";
|
|
7129
7190
|
}
|
|
7130
7191
|
}
|
|
@@ -7503,9 +7564,9 @@ function askOnce(question) {
|
|
|
7503
7564
|
}
|
|
7504
7565
|
|
|
7505
7566
|
// src/nodePath.ts
|
|
7506
|
-
import { existsSync as existsSync3, realpathSync } from "node:fs";
|
|
7567
|
+
import { existsSync as existsSync3, realpathSync as realpathSync3 } from "node:fs";
|
|
7507
7568
|
import { delimiter, join as join5 } from "node:path";
|
|
7508
|
-
var defaultRealpath = (path) =>
|
|
7569
|
+
var defaultRealpath = (path) => realpathSync3.native(path);
|
|
7509
7570
|
function safeRealpath(path, realpath = defaultRealpath) {
|
|
7510
7571
|
try {
|
|
7511
7572
|
return realpath(path);
|
|
@@ -8049,7 +8110,13 @@ async function runIndex(ctx, opts) {
|
|
|
8049
8110
|
for (const failure of failures) {
|
|
8050
8111
|
ctx.logger.warn(`${failure.source}: sealed key prewarm failed: ${errorMessage2(failure.error)}`);
|
|
8051
8112
|
}
|
|
8052
|
-
|
|
8113
|
+
let db;
|
|
8114
|
+
try {
|
|
8115
|
+
db = openDb({ path: ctx.paths.dbPath, logger: ctx.logger });
|
|
8116
|
+
} catch (error51) {
|
|
8117
|
+
observeRuntimeError("CAVEAT.DATABASE_OPEN_FAILED", { version: CAVEAT_VERSION });
|
|
8118
|
+
throw error51;
|
|
8119
|
+
}
|
|
8053
8120
|
try {
|
|
8054
8121
|
if (opts.full) {
|
|
8055
8122
|
ctx.logger.info("full rebuild: DELETE FROM entries");
|
|
@@ -8064,6 +8131,9 @@ async function runIndex(ctx, opts) {
|
|
|
8064
8131
|
}
|
|
8065
8132
|
}
|
|
8066
8133
|
writeDigestMarker(ctx.caveatHome, computeEntriesDigest(ctx.paths));
|
|
8134
|
+
} catch (error51) {
|
|
8135
|
+
observeRuntimeError("CAVEAT.INDEX_FAILED", { version: CAVEAT_VERSION });
|
|
8136
|
+
throw error51;
|
|
8067
8137
|
} finally {
|
|
8068
8138
|
db.close();
|
|
8069
8139
|
}
|
|
@@ -8218,7 +8288,7 @@ function runStats(ctx) {
|
|
|
8218
8288
|
|
|
8219
8289
|
// src/commands/serve.ts
|
|
8220
8290
|
async function runServe(opts) {
|
|
8221
|
-
const { startServer } = await import("./server-
|
|
8291
|
+
const { startServer } = await import("./server-ZMIRSFMH.js");
|
|
8222
8292
|
const { port, host } = startServer({ port: opts.port });
|
|
8223
8293
|
process.stdout.write(`[caveat] web portal: http://${host}:${port}/
|
|
8224
8294
|
`);
|
|
@@ -8639,18 +8709,18 @@ var ParseStatus = class _ParseStatus {
|
|
|
8639
8709
|
if (this.value !== "aborted")
|
|
8640
8710
|
this.value = "aborted";
|
|
8641
8711
|
}
|
|
8642
|
-
static mergeArray(
|
|
8712
|
+
static mergeArray(status2, results) {
|
|
8643
8713
|
const arrayValue = [];
|
|
8644
8714
|
for (const s of results) {
|
|
8645
8715
|
if (s.status === "aborted")
|
|
8646
8716
|
return INVALID;
|
|
8647
8717
|
if (s.status === "dirty")
|
|
8648
|
-
|
|
8718
|
+
status2.dirty();
|
|
8649
8719
|
arrayValue.push(s.value);
|
|
8650
8720
|
}
|
|
8651
|
-
return { status:
|
|
8721
|
+
return { status: status2.value, value: arrayValue };
|
|
8652
8722
|
}
|
|
8653
|
-
static async mergeObjectAsync(
|
|
8723
|
+
static async mergeObjectAsync(status2, pairs) {
|
|
8654
8724
|
const syncPairs = [];
|
|
8655
8725
|
for (const pair of pairs) {
|
|
8656
8726
|
const key = await pair.key;
|
|
@@ -8660,9 +8730,9 @@ var ParseStatus = class _ParseStatus {
|
|
|
8660
8730
|
value
|
|
8661
8731
|
});
|
|
8662
8732
|
}
|
|
8663
|
-
return _ParseStatus.mergeObjectSync(
|
|
8733
|
+
return _ParseStatus.mergeObjectSync(status2, syncPairs);
|
|
8664
8734
|
}
|
|
8665
|
-
static mergeObjectSync(
|
|
8735
|
+
static mergeObjectSync(status2, pairs) {
|
|
8666
8736
|
const finalObject = {};
|
|
8667
8737
|
for (const pair of pairs) {
|
|
8668
8738
|
const { key, value } = pair;
|
|
@@ -8671,14 +8741,14 @@ var ParseStatus = class _ParseStatus {
|
|
|
8671
8741
|
if (value.status === "aborted")
|
|
8672
8742
|
return INVALID;
|
|
8673
8743
|
if (key.status === "dirty")
|
|
8674
|
-
|
|
8744
|
+
status2.dirty();
|
|
8675
8745
|
if (value.status === "dirty")
|
|
8676
|
-
|
|
8746
|
+
status2.dirty();
|
|
8677
8747
|
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
8678
8748
|
finalObject[key.value] = value.value;
|
|
8679
8749
|
}
|
|
8680
8750
|
}
|
|
8681
|
-
return { status:
|
|
8751
|
+
return { status: status2.value, value: finalObject };
|
|
8682
8752
|
}
|
|
8683
8753
|
};
|
|
8684
8754
|
var INVALID = Object.freeze({
|
|
@@ -9138,7 +9208,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9138
9208
|
});
|
|
9139
9209
|
return INVALID;
|
|
9140
9210
|
}
|
|
9141
|
-
const
|
|
9211
|
+
const status2 = new ParseStatus();
|
|
9142
9212
|
let ctx = void 0;
|
|
9143
9213
|
for (const check2 of this._def.checks) {
|
|
9144
9214
|
if (check2.kind === "min") {
|
|
@@ -9152,7 +9222,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9152
9222
|
exact: false,
|
|
9153
9223
|
message: check2.message
|
|
9154
9224
|
});
|
|
9155
|
-
|
|
9225
|
+
status2.dirty();
|
|
9156
9226
|
}
|
|
9157
9227
|
} else if (check2.kind === "max") {
|
|
9158
9228
|
if (input.data.length > check2.value) {
|
|
@@ -9165,7 +9235,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9165
9235
|
exact: false,
|
|
9166
9236
|
message: check2.message
|
|
9167
9237
|
});
|
|
9168
|
-
|
|
9238
|
+
status2.dirty();
|
|
9169
9239
|
}
|
|
9170
9240
|
} else if (check2.kind === "length") {
|
|
9171
9241
|
const tooBig = input.data.length > check2.value;
|
|
@@ -9191,7 +9261,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9191
9261
|
message: check2.message
|
|
9192
9262
|
});
|
|
9193
9263
|
}
|
|
9194
|
-
|
|
9264
|
+
status2.dirty();
|
|
9195
9265
|
}
|
|
9196
9266
|
} else if (check2.kind === "email") {
|
|
9197
9267
|
if (!emailRegex.test(input.data)) {
|
|
@@ -9201,7 +9271,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9201
9271
|
code: ZodIssueCode.invalid_string,
|
|
9202
9272
|
message: check2.message
|
|
9203
9273
|
});
|
|
9204
|
-
|
|
9274
|
+
status2.dirty();
|
|
9205
9275
|
}
|
|
9206
9276
|
} else if (check2.kind === "emoji") {
|
|
9207
9277
|
if (!emojiRegex) {
|
|
@@ -9214,7 +9284,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9214
9284
|
code: ZodIssueCode.invalid_string,
|
|
9215
9285
|
message: check2.message
|
|
9216
9286
|
});
|
|
9217
|
-
|
|
9287
|
+
status2.dirty();
|
|
9218
9288
|
}
|
|
9219
9289
|
} else if (check2.kind === "uuid") {
|
|
9220
9290
|
if (!uuidRegex.test(input.data)) {
|
|
@@ -9224,7 +9294,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9224
9294
|
code: ZodIssueCode.invalid_string,
|
|
9225
9295
|
message: check2.message
|
|
9226
9296
|
});
|
|
9227
|
-
|
|
9297
|
+
status2.dirty();
|
|
9228
9298
|
}
|
|
9229
9299
|
} else if (check2.kind === "nanoid") {
|
|
9230
9300
|
if (!nanoidRegex.test(input.data)) {
|
|
@@ -9234,7 +9304,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9234
9304
|
code: ZodIssueCode.invalid_string,
|
|
9235
9305
|
message: check2.message
|
|
9236
9306
|
});
|
|
9237
|
-
|
|
9307
|
+
status2.dirty();
|
|
9238
9308
|
}
|
|
9239
9309
|
} else if (check2.kind === "cuid") {
|
|
9240
9310
|
if (!cuidRegex.test(input.data)) {
|
|
@@ -9244,7 +9314,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9244
9314
|
code: ZodIssueCode.invalid_string,
|
|
9245
9315
|
message: check2.message
|
|
9246
9316
|
});
|
|
9247
|
-
|
|
9317
|
+
status2.dirty();
|
|
9248
9318
|
}
|
|
9249
9319
|
} else if (check2.kind === "cuid2") {
|
|
9250
9320
|
if (!cuid2Regex.test(input.data)) {
|
|
@@ -9254,7 +9324,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9254
9324
|
code: ZodIssueCode.invalid_string,
|
|
9255
9325
|
message: check2.message
|
|
9256
9326
|
});
|
|
9257
|
-
|
|
9327
|
+
status2.dirty();
|
|
9258
9328
|
}
|
|
9259
9329
|
} else if (check2.kind === "ulid") {
|
|
9260
9330
|
if (!ulidRegex.test(input.data)) {
|
|
@@ -9264,7 +9334,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9264
9334
|
code: ZodIssueCode.invalid_string,
|
|
9265
9335
|
message: check2.message
|
|
9266
9336
|
});
|
|
9267
|
-
|
|
9337
|
+
status2.dirty();
|
|
9268
9338
|
}
|
|
9269
9339
|
} else if (check2.kind === "url") {
|
|
9270
9340
|
try {
|
|
@@ -9276,7 +9346,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9276
9346
|
code: ZodIssueCode.invalid_string,
|
|
9277
9347
|
message: check2.message
|
|
9278
9348
|
});
|
|
9279
|
-
|
|
9349
|
+
status2.dirty();
|
|
9280
9350
|
}
|
|
9281
9351
|
} else if (check2.kind === "regex") {
|
|
9282
9352
|
check2.regex.lastIndex = 0;
|
|
@@ -9288,7 +9358,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9288
9358
|
code: ZodIssueCode.invalid_string,
|
|
9289
9359
|
message: check2.message
|
|
9290
9360
|
});
|
|
9291
|
-
|
|
9361
|
+
status2.dirty();
|
|
9292
9362
|
}
|
|
9293
9363
|
} else if (check2.kind === "trim") {
|
|
9294
9364
|
input.data = input.data.trim();
|
|
@@ -9300,7 +9370,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9300
9370
|
validation: { includes: check2.value, position: check2.position },
|
|
9301
9371
|
message: check2.message
|
|
9302
9372
|
});
|
|
9303
|
-
|
|
9373
|
+
status2.dirty();
|
|
9304
9374
|
}
|
|
9305
9375
|
} else if (check2.kind === "toLowerCase") {
|
|
9306
9376
|
input.data = input.data.toLowerCase();
|
|
@@ -9314,7 +9384,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9314
9384
|
validation: { startsWith: check2.value },
|
|
9315
9385
|
message: check2.message
|
|
9316
9386
|
});
|
|
9317
|
-
|
|
9387
|
+
status2.dirty();
|
|
9318
9388
|
}
|
|
9319
9389
|
} else if (check2.kind === "endsWith") {
|
|
9320
9390
|
if (!input.data.endsWith(check2.value)) {
|
|
@@ -9324,7 +9394,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9324
9394
|
validation: { endsWith: check2.value },
|
|
9325
9395
|
message: check2.message
|
|
9326
9396
|
});
|
|
9327
|
-
|
|
9397
|
+
status2.dirty();
|
|
9328
9398
|
}
|
|
9329
9399
|
} else if (check2.kind === "datetime") {
|
|
9330
9400
|
const regex = datetimeRegex(check2);
|
|
@@ -9335,7 +9405,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9335
9405
|
validation: "datetime",
|
|
9336
9406
|
message: check2.message
|
|
9337
9407
|
});
|
|
9338
|
-
|
|
9408
|
+
status2.dirty();
|
|
9339
9409
|
}
|
|
9340
9410
|
} else if (check2.kind === "date") {
|
|
9341
9411
|
const regex = dateRegex;
|
|
@@ -9346,7 +9416,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9346
9416
|
validation: "date",
|
|
9347
9417
|
message: check2.message
|
|
9348
9418
|
});
|
|
9349
|
-
|
|
9419
|
+
status2.dirty();
|
|
9350
9420
|
}
|
|
9351
9421
|
} else if (check2.kind === "time") {
|
|
9352
9422
|
const regex = timeRegex(check2);
|
|
@@ -9357,7 +9427,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9357
9427
|
validation: "time",
|
|
9358
9428
|
message: check2.message
|
|
9359
9429
|
});
|
|
9360
|
-
|
|
9430
|
+
status2.dirty();
|
|
9361
9431
|
}
|
|
9362
9432
|
} else if (check2.kind === "duration") {
|
|
9363
9433
|
if (!durationRegex.test(input.data)) {
|
|
@@ -9367,7 +9437,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9367
9437
|
code: ZodIssueCode.invalid_string,
|
|
9368
9438
|
message: check2.message
|
|
9369
9439
|
});
|
|
9370
|
-
|
|
9440
|
+
status2.dirty();
|
|
9371
9441
|
}
|
|
9372
9442
|
} else if (check2.kind === "ip") {
|
|
9373
9443
|
if (!isValidIP(input.data, check2.version)) {
|
|
@@ -9377,7 +9447,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9377
9447
|
code: ZodIssueCode.invalid_string,
|
|
9378
9448
|
message: check2.message
|
|
9379
9449
|
});
|
|
9380
|
-
|
|
9450
|
+
status2.dirty();
|
|
9381
9451
|
}
|
|
9382
9452
|
} else if (check2.kind === "jwt") {
|
|
9383
9453
|
if (!isValidJWT(input.data, check2.alg)) {
|
|
@@ -9387,7 +9457,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9387
9457
|
code: ZodIssueCode.invalid_string,
|
|
9388
9458
|
message: check2.message
|
|
9389
9459
|
});
|
|
9390
|
-
|
|
9460
|
+
status2.dirty();
|
|
9391
9461
|
}
|
|
9392
9462
|
} else if (check2.kind === "cidr") {
|
|
9393
9463
|
if (!isValidCidr(input.data, check2.version)) {
|
|
@@ -9397,7 +9467,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9397
9467
|
code: ZodIssueCode.invalid_string,
|
|
9398
9468
|
message: check2.message
|
|
9399
9469
|
});
|
|
9400
|
-
|
|
9470
|
+
status2.dirty();
|
|
9401
9471
|
}
|
|
9402
9472
|
} else if (check2.kind === "base64") {
|
|
9403
9473
|
if (!base64Regex.test(input.data)) {
|
|
@@ -9407,7 +9477,7 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9407
9477
|
code: ZodIssueCode.invalid_string,
|
|
9408
9478
|
message: check2.message
|
|
9409
9479
|
});
|
|
9410
|
-
|
|
9480
|
+
status2.dirty();
|
|
9411
9481
|
}
|
|
9412
9482
|
} else if (check2.kind === "base64url") {
|
|
9413
9483
|
if (!base64urlRegex.test(input.data)) {
|
|
@@ -9417,13 +9487,13 @@ var ZodString = class _ZodString2 extends ZodType {
|
|
|
9417
9487
|
code: ZodIssueCode.invalid_string,
|
|
9418
9488
|
message: check2.message
|
|
9419
9489
|
});
|
|
9420
|
-
|
|
9490
|
+
status2.dirty();
|
|
9421
9491
|
}
|
|
9422
9492
|
} else {
|
|
9423
9493
|
util.assertNever(check2);
|
|
9424
9494
|
}
|
|
9425
9495
|
}
|
|
9426
|
-
return { status:
|
|
9496
|
+
return { status: status2.value, value: input.data };
|
|
9427
9497
|
}
|
|
9428
9498
|
_regex(regex, validation, message) {
|
|
9429
9499
|
return this.refinement((data) => regex.test(data), {
|
|
@@ -9699,7 +9769,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9699
9769
|
return INVALID;
|
|
9700
9770
|
}
|
|
9701
9771
|
let ctx = void 0;
|
|
9702
|
-
const
|
|
9772
|
+
const status2 = new ParseStatus();
|
|
9703
9773
|
for (const check2 of this._def.checks) {
|
|
9704
9774
|
if (check2.kind === "int") {
|
|
9705
9775
|
if (!util.isInteger(input.data)) {
|
|
@@ -9710,7 +9780,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9710
9780
|
received: "float",
|
|
9711
9781
|
message: check2.message
|
|
9712
9782
|
});
|
|
9713
|
-
|
|
9783
|
+
status2.dirty();
|
|
9714
9784
|
}
|
|
9715
9785
|
} else if (check2.kind === "min") {
|
|
9716
9786
|
const tooSmall = check2.inclusive ? input.data < check2.value : input.data <= check2.value;
|
|
@@ -9724,7 +9794,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9724
9794
|
exact: false,
|
|
9725
9795
|
message: check2.message
|
|
9726
9796
|
});
|
|
9727
|
-
|
|
9797
|
+
status2.dirty();
|
|
9728
9798
|
}
|
|
9729
9799
|
} else if (check2.kind === "max") {
|
|
9730
9800
|
const tooBig = check2.inclusive ? input.data > check2.value : input.data >= check2.value;
|
|
@@ -9738,7 +9808,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9738
9808
|
exact: false,
|
|
9739
9809
|
message: check2.message
|
|
9740
9810
|
});
|
|
9741
|
-
|
|
9811
|
+
status2.dirty();
|
|
9742
9812
|
}
|
|
9743
9813
|
} else if (check2.kind === "multipleOf") {
|
|
9744
9814
|
if (floatSafeRemainder(input.data, check2.value) !== 0) {
|
|
@@ -9748,7 +9818,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9748
9818
|
multipleOf: check2.value,
|
|
9749
9819
|
message: check2.message
|
|
9750
9820
|
});
|
|
9751
|
-
|
|
9821
|
+
status2.dirty();
|
|
9752
9822
|
}
|
|
9753
9823
|
} else if (check2.kind === "finite") {
|
|
9754
9824
|
if (!Number.isFinite(input.data)) {
|
|
@@ -9757,13 +9827,13 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
9757
9827
|
code: ZodIssueCode.not_finite,
|
|
9758
9828
|
message: check2.message
|
|
9759
9829
|
});
|
|
9760
|
-
|
|
9830
|
+
status2.dirty();
|
|
9761
9831
|
}
|
|
9762
9832
|
} else {
|
|
9763
9833
|
util.assertNever(check2);
|
|
9764
9834
|
}
|
|
9765
9835
|
}
|
|
9766
|
-
return { status:
|
|
9836
|
+
return { status: status2.value, value: input.data };
|
|
9767
9837
|
}
|
|
9768
9838
|
gte(value, message) {
|
|
9769
9839
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
@@ -9928,7 +9998,7 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
9928
9998
|
return this._getInvalidInput(input);
|
|
9929
9999
|
}
|
|
9930
10000
|
let ctx = void 0;
|
|
9931
|
-
const
|
|
10001
|
+
const status2 = new ParseStatus();
|
|
9932
10002
|
for (const check2 of this._def.checks) {
|
|
9933
10003
|
if (check2.kind === "min") {
|
|
9934
10004
|
const tooSmall = check2.inclusive ? input.data < check2.value : input.data <= check2.value;
|
|
@@ -9941,7 +10011,7 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
9941
10011
|
inclusive: check2.inclusive,
|
|
9942
10012
|
message: check2.message
|
|
9943
10013
|
});
|
|
9944
|
-
|
|
10014
|
+
status2.dirty();
|
|
9945
10015
|
}
|
|
9946
10016
|
} else if (check2.kind === "max") {
|
|
9947
10017
|
const tooBig = check2.inclusive ? input.data > check2.value : input.data >= check2.value;
|
|
@@ -9954,7 +10024,7 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
9954
10024
|
inclusive: check2.inclusive,
|
|
9955
10025
|
message: check2.message
|
|
9956
10026
|
});
|
|
9957
|
-
|
|
10027
|
+
status2.dirty();
|
|
9958
10028
|
}
|
|
9959
10029
|
} else if (check2.kind === "multipleOf") {
|
|
9960
10030
|
if (input.data % check2.value !== BigInt(0)) {
|
|
@@ -9964,13 +10034,13 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
9964
10034
|
multipleOf: check2.value,
|
|
9965
10035
|
message: check2.message
|
|
9966
10036
|
});
|
|
9967
|
-
|
|
10037
|
+
status2.dirty();
|
|
9968
10038
|
}
|
|
9969
10039
|
} else {
|
|
9970
10040
|
util.assertNever(check2);
|
|
9971
10041
|
}
|
|
9972
10042
|
}
|
|
9973
|
-
return { status:
|
|
10043
|
+
return { status: status2.value, value: input.data };
|
|
9974
10044
|
}
|
|
9975
10045
|
_getInvalidInput(input) {
|
|
9976
10046
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -10128,7 +10198,7 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
10128
10198
|
});
|
|
10129
10199
|
return INVALID;
|
|
10130
10200
|
}
|
|
10131
|
-
const
|
|
10201
|
+
const status2 = new ParseStatus();
|
|
10132
10202
|
let ctx = void 0;
|
|
10133
10203
|
for (const check2 of this._def.checks) {
|
|
10134
10204
|
if (check2.kind === "min") {
|
|
@@ -10142,7 +10212,7 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
10142
10212
|
minimum: check2.value,
|
|
10143
10213
|
type: "date"
|
|
10144
10214
|
});
|
|
10145
|
-
|
|
10215
|
+
status2.dirty();
|
|
10146
10216
|
}
|
|
10147
10217
|
} else if (check2.kind === "max") {
|
|
10148
10218
|
if (input.data.getTime() > check2.value) {
|
|
@@ -10155,14 +10225,14 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
10155
10225
|
maximum: check2.value,
|
|
10156
10226
|
type: "date"
|
|
10157
10227
|
});
|
|
10158
|
-
|
|
10228
|
+
status2.dirty();
|
|
10159
10229
|
}
|
|
10160
10230
|
} else {
|
|
10161
10231
|
util.assertNever(check2);
|
|
10162
10232
|
}
|
|
10163
10233
|
}
|
|
10164
10234
|
return {
|
|
10165
|
-
status:
|
|
10235
|
+
status: status2.value,
|
|
10166
10236
|
value: new Date(input.data.getTime())
|
|
10167
10237
|
};
|
|
10168
10238
|
}
|
|
@@ -10348,7 +10418,7 @@ ZodVoid.create = (params) => {
|
|
|
10348
10418
|
};
|
|
10349
10419
|
var ZodArray = class _ZodArray extends ZodType {
|
|
10350
10420
|
_parse(input) {
|
|
10351
|
-
const { ctx, status } = this._processInputParams(input);
|
|
10421
|
+
const { ctx, status: status2 } = this._processInputParams(input);
|
|
10352
10422
|
const def = this._def;
|
|
10353
10423
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
10354
10424
|
addIssueToContext(ctx, {
|
|
@@ -10371,7 +10441,7 @@ var ZodArray = class _ZodArray extends ZodType {
|
|
|
10371
10441
|
exact: true,
|
|
10372
10442
|
message: def.exactLength.message
|
|
10373
10443
|
});
|
|
10374
|
-
|
|
10444
|
+
status2.dirty();
|
|
10375
10445
|
}
|
|
10376
10446
|
}
|
|
10377
10447
|
if (def.minLength !== null) {
|
|
@@ -10384,7 +10454,7 @@ var ZodArray = class _ZodArray extends ZodType {
|
|
|
10384
10454
|
exact: false,
|
|
10385
10455
|
message: def.minLength.message
|
|
10386
10456
|
});
|
|
10387
|
-
|
|
10457
|
+
status2.dirty();
|
|
10388
10458
|
}
|
|
10389
10459
|
}
|
|
10390
10460
|
if (def.maxLength !== null) {
|
|
@@ -10397,20 +10467,20 @@ var ZodArray = class _ZodArray extends ZodType {
|
|
|
10397
10467
|
exact: false,
|
|
10398
10468
|
message: def.maxLength.message
|
|
10399
10469
|
});
|
|
10400
|
-
|
|
10470
|
+
status2.dirty();
|
|
10401
10471
|
}
|
|
10402
10472
|
}
|
|
10403
10473
|
if (ctx.common.async) {
|
|
10404
10474
|
return Promise.all([...ctx.data].map((item, i) => {
|
|
10405
10475
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
10406
10476
|
})).then((result2) => {
|
|
10407
|
-
return ParseStatus.mergeArray(
|
|
10477
|
+
return ParseStatus.mergeArray(status2, result2);
|
|
10408
10478
|
});
|
|
10409
10479
|
}
|
|
10410
10480
|
const result = [...ctx.data].map((item, i) => {
|
|
10411
10481
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
10412
10482
|
});
|
|
10413
|
-
return ParseStatus.mergeArray(
|
|
10483
|
+
return ParseStatus.mergeArray(status2, result);
|
|
10414
10484
|
}
|
|
10415
10485
|
get element() {
|
|
10416
10486
|
return this._def.type;
|
|
@@ -10499,7 +10569,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
10499
10569
|
});
|
|
10500
10570
|
return INVALID;
|
|
10501
10571
|
}
|
|
10502
|
-
const { status, ctx } = this._processInputParams(input);
|
|
10572
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
10503
10573
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
10504
10574
|
const extraKeys = [];
|
|
10505
10575
|
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
@@ -10534,7 +10604,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
10534
10604
|
code: ZodIssueCode.unrecognized_keys,
|
|
10535
10605
|
keys: extraKeys
|
|
10536
10606
|
});
|
|
10537
|
-
|
|
10607
|
+
status2.dirty();
|
|
10538
10608
|
}
|
|
10539
10609
|
} else if (unknownKeys === "strip") {
|
|
10540
10610
|
} else {
|
|
@@ -10568,10 +10638,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
10568
10638
|
}
|
|
10569
10639
|
return syncPairs;
|
|
10570
10640
|
}).then((syncPairs) => {
|
|
10571
|
-
return ParseStatus.mergeObjectSync(
|
|
10641
|
+
return ParseStatus.mergeObjectSync(status2, syncPairs);
|
|
10572
10642
|
});
|
|
10573
10643
|
} else {
|
|
10574
|
-
return ParseStatus.mergeObjectSync(
|
|
10644
|
+
return ParseStatus.mergeObjectSync(status2, pairs);
|
|
10575
10645
|
}
|
|
10576
10646
|
}
|
|
10577
10647
|
get shape() {
|
|
@@ -11049,7 +11119,7 @@ function mergeValues(a, b) {
|
|
|
11049
11119
|
}
|
|
11050
11120
|
var ZodIntersection = class extends ZodType {
|
|
11051
11121
|
_parse(input) {
|
|
11052
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11122
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11053
11123
|
const handleParsed = (parsedLeft, parsedRight) => {
|
|
11054
11124
|
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
11055
11125
|
return INVALID;
|
|
@@ -11062,9 +11132,9 @@ var ZodIntersection = class extends ZodType {
|
|
|
11062
11132
|
return INVALID;
|
|
11063
11133
|
}
|
|
11064
11134
|
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
11065
|
-
|
|
11135
|
+
status2.dirty();
|
|
11066
11136
|
}
|
|
11067
|
-
return { status:
|
|
11137
|
+
return { status: status2.value, value: merged.data };
|
|
11068
11138
|
};
|
|
11069
11139
|
if (ctx.common.async) {
|
|
11070
11140
|
return Promise.all([
|
|
@@ -11102,7 +11172,7 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
11102
11172
|
};
|
|
11103
11173
|
var ZodTuple = class _ZodTuple extends ZodType {
|
|
11104
11174
|
_parse(input) {
|
|
11105
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11175
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11106
11176
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
11107
11177
|
addIssueToContext(ctx, {
|
|
11108
11178
|
code: ZodIssueCode.invalid_type,
|
|
@@ -11130,7 +11200,7 @@ var ZodTuple = class _ZodTuple extends ZodType {
|
|
|
11130
11200
|
exact: false,
|
|
11131
11201
|
type: "array"
|
|
11132
11202
|
});
|
|
11133
|
-
|
|
11203
|
+
status2.dirty();
|
|
11134
11204
|
}
|
|
11135
11205
|
const items = [...ctx.data].map((item, itemIndex) => {
|
|
11136
11206
|
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
@@ -11140,10 +11210,10 @@ var ZodTuple = class _ZodTuple extends ZodType {
|
|
|
11140
11210
|
}).filter((x) => !!x);
|
|
11141
11211
|
if (ctx.common.async) {
|
|
11142
11212
|
return Promise.all(items).then((results) => {
|
|
11143
|
-
return ParseStatus.mergeArray(
|
|
11213
|
+
return ParseStatus.mergeArray(status2, results);
|
|
11144
11214
|
});
|
|
11145
11215
|
} else {
|
|
11146
|
-
return ParseStatus.mergeArray(
|
|
11216
|
+
return ParseStatus.mergeArray(status2, items);
|
|
11147
11217
|
}
|
|
11148
11218
|
}
|
|
11149
11219
|
get items() {
|
|
@@ -11175,7 +11245,7 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
|
11175
11245
|
return this._def.valueType;
|
|
11176
11246
|
}
|
|
11177
11247
|
_parse(input) {
|
|
11178
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11248
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11179
11249
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
11180
11250
|
addIssueToContext(ctx, {
|
|
11181
11251
|
code: ZodIssueCode.invalid_type,
|
|
@@ -11195,9 +11265,9 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
|
11195
11265
|
});
|
|
11196
11266
|
}
|
|
11197
11267
|
if (ctx.common.async) {
|
|
11198
|
-
return ParseStatus.mergeObjectAsync(
|
|
11268
|
+
return ParseStatus.mergeObjectAsync(status2, pairs);
|
|
11199
11269
|
} else {
|
|
11200
|
-
return ParseStatus.mergeObjectSync(
|
|
11270
|
+
return ParseStatus.mergeObjectSync(status2, pairs);
|
|
11201
11271
|
}
|
|
11202
11272
|
}
|
|
11203
11273
|
get element() {
|
|
@@ -11228,7 +11298,7 @@ var ZodMap = class extends ZodType {
|
|
|
11228
11298
|
return this._def.valueType;
|
|
11229
11299
|
}
|
|
11230
11300
|
_parse(input) {
|
|
11231
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11301
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11232
11302
|
if (ctx.parsedType !== ZodParsedType.map) {
|
|
11233
11303
|
addIssueToContext(ctx, {
|
|
11234
11304
|
code: ZodIssueCode.invalid_type,
|
|
@@ -11255,11 +11325,11 @@ var ZodMap = class extends ZodType {
|
|
|
11255
11325
|
return INVALID;
|
|
11256
11326
|
}
|
|
11257
11327
|
if (key.status === "dirty" || value.status === "dirty") {
|
|
11258
|
-
|
|
11328
|
+
status2.dirty();
|
|
11259
11329
|
}
|
|
11260
11330
|
finalMap.set(key.value, value.value);
|
|
11261
11331
|
}
|
|
11262
|
-
return { status:
|
|
11332
|
+
return { status: status2.value, value: finalMap };
|
|
11263
11333
|
});
|
|
11264
11334
|
} else {
|
|
11265
11335
|
const finalMap = /* @__PURE__ */ new Map();
|
|
@@ -11270,11 +11340,11 @@ var ZodMap = class extends ZodType {
|
|
|
11270
11340
|
return INVALID;
|
|
11271
11341
|
}
|
|
11272
11342
|
if (key.status === "dirty" || value.status === "dirty") {
|
|
11273
|
-
|
|
11343
|
+
status2.dirty();
|
|
11274
11344
|
}
|
|
11275
11345
|
finalMap.set(key.value, value.value);
|
|
11276
11346
|
}
|
|
11277
|
-
return { status:
|
|
11347
|
+
return { status: status2.value, value: finalMap };
|
|
11278
11348
|
}
|
|
11279
11349
|
}
|
|
11280
11350
|
};
|
|
@@ -11288,7 +11358,7 @@ ZodMap.create = (keyType, valueType, params) => {
|
|
|
11288
11358
|
};
|
|
11289
11359
|
var ZodSet = class _ZodSet extends ZodType {
|
|
11290
11360
|
_parse(input) {
|
|
11291
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11361
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11292
11362
|
if (ctx.parsedType !== ZodParsedType.set) {
|
|
11293
11363
|
addIssueToContext(ctx, {
|
|
11294
11364
|
code: ZodIssueCode.invalid_type,
|
|
@@ -11308,7 +11378,7 @@ var ZodSet = class _ZodSet extends ZodType {
|
|
|
11308
11378
|
exact: false,
|
|
11309
11379
|
message: def.minSize.message
|
|
11310
11380
|
});
|
|
11311
|
-
|
|
11381
|
+
status2.dirty();
|
|
11312
11382
|
}
|
|
11313
11383
|
}
|
|
11314
11384
|
if (def.maxSize !== null) {
|
|
@@ -11321,7 +11391,7 @@ var ZodSet = class _ZodSet extends ZodType {
|
|
|
11321
11391
|
exact: false,
|
|
11322
11392
|
message: def.maxSize.message
|
|
11323
11393
|
});
|
|
11324
|
-
|
|
11394
|
+
status2.dirty();
|
|
11325
11395
|
}
|
|
11326
11396
|
}
|
|
11327
11397
|
const valueType = this._def.valueType;
|
|
@@ -11331,10 +11401,10 @@ var ZodSet = class _ZodSet extends ZodType {
|
|
|
11331
11401
|
if (element.status === "aborted")
|
|
11332
11402
|
return INVALID;
|
|
11333
11403
|
if (element.status === "dirty")
|
|
11334
|
-
|
|
11404
|
+
status2.dirty();
|
|
11335
11405
|
parsedSet.add(element.value);
|
|
11336
11406
|
}
|
|
11337
|
-
return { status:
|
|
11407
|
+
return { status: status2.value, value: parsedSet };
|
|
11338
11408
|
}
|
|
11339
11409
|
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
11340
11410
|
if (ctx.common.async) {
|
|
@@ -11665,15 +11735,15 @@ var ZodEffects = class extends ZodType {
|
|
|
11665
11735
|
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
11666
11736
|
}
|
|
11667
11737
|
_parse(input) {
|
|
11668
|
-
const { status, ctx } = this._processInputParams(input);
|
|
11738
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11669
11739
|
const effect = this._def.effect || null;
|
|
11670
11740
|
const checkCtx = {
|
|
11671
11741
|
addIssue: (arg) => {
|
|
11672
11742
|
addIssueToContext(ctx, arg);
|
|
11673
11743
|
if (arg.fatal) {
|
|
11674
|
-
|
|
11744
|
+
status2.abort();
|
|
11675
11745
|
} else {
|
|
11676
|
-
|
|
11746
|
+
status2.dirty();
|
|
11677
11747
|
}
|
|
11678
11748
|
},
|
|
11679
11749
|
get path() {
|
|
@@ -11685,7 +11755,7 @@ var ZodEffects = class extends ZodType {
|
|
|
11685
11755
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
11686
11756
|
if (ctx.common.async) {
|
|
11687
11757
|
return Promise.resolve(processed).then(async (processed2) => {
|
|
11688
|
-
if (
|
|
11758
|
+
if (status2.value === "aborted")
|
|
11689
11759
|
return INVALID;
|
|
11690
11760
|
const result = await this._def.schema._parseAsync({
|
|
11691
11761
|
data: processed2,
|
|
@@ -11696,12 +11766,12 @@ var ZodEffects = class extends ZodType {
|
|
|
11696
11766
|
return INVALID;
|
|
11697
11767
|
if (result.status === "dirty")
|
|
11698
11768
|
return DIRTY(result.value);
|
|
11699
|
-
if (
|
|
11769
|
+
if (status2.value === "dirty")
|
|
11700
11770
|
return DIRTY(result.value);
|
|
11701
11771
|
return result;
|
|
11702
11772
|
});
|
|
11703
11773
|
} else {
|
|
11704
|
-
if (
|
|
11774
|
+
if (status2.value === "aborted")
|
|
11705
11775
|
return INVALID;
|
|
11706
11776
|
const result = this._def.schema._parseSync({
|
|
11707
11777
|
data: processed,
|
|
@@ -11712,7 +11782,7 @@ var ZodEffects = class extends ZodType {
|
|
|
11712
11782
|
return INVALID;
|
|
11713
11783
|
if (result.status === "dirty")
|
|
11714
11784
|
return DIRTY(result.value);
|
|
11715
|
-
if (
|
|
11785
|
+
if (status2.value === "dirty")
|
|
11716
11786
|
return DIRTY(result.value);
|
|
11717
11787
|
return result;
|
|
11718
11788
|
}
|
|
@@ -11737,17 +11807,17 @@ var ZodEffects = class extends ZodType {
|
|
|
11737
11807
|
if (inner.status === "aborted")
|
|
11738
11808
|
return INVALID;
|
|
11739
11809
|
if (inner.status === "dirty")
|
|
11740
|
-
|
|
11810
|
+
status2.dirty();
|
|
11741
11811
|
executeRefinement(inner.value);
|
|
11742
|
-
return { status:
|
|
11812
|
+
return { status: status2.value, value: inner.value };
|
|
11743
11813
|
} else {
|
|
11744
11814
|
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
11745
11815
|
if (inner.status === "aborted")
|
|
11746
11816
|
return INVALID;
|
|
11747
11817
|
if (inner.status === "dirty")
|
|
11748
|
-
|
|
11818
|
+
status2.dirty();
|
|
11749
11819
|
return executeRefinement(inner.value).then(() => {
|
|
11750
|
-
return { status:
|
|
11820
|
+
return { status: status2.value, value: inner.value };
|
|
11751
11821
|
});
|
|
11752
11822
|
});
|
|
11753
11823
|
}
|
|
@@ -11765,13 +11835,13 @@ var ZodEffects = class extends ZodType {
|
|
|
11765
11835
|
if (result instanceof Promise) {
|
|
11766
11836
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
11767
11837
|
}
|
|
11768
|
-
return { status:
|
|
11838
|
+
return { status: status2.value, value: result };
|
|
11769
11839
|
} else {
|
|
11770
11840
|
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
11771
11841
|
if (!isValid(base))
|
|
11772
11842
|
return INVALID;
|
|
11773
11843
|
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
11774
|
-
status:
|
|
11844
|
+
status: status2.value,
|
|
11775
11845
|
value: result
|
|
11776
11846
|
}));
|
|
11777
11847
|
});
|
|
@@ -11949,7 +12019,7 @@ var ZodBranded = class extends ZodType {
|
|
|
11949
12019
|
};
|
|
11950
12020
|
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
11951
12021
|
_parse(input) {
|
|
11952
|
-
const { status, ctx } = this._processInputParams(input);
|
|
12022
|
+
const { status: status2, ctx } = this._processInputParams(input);
|
|
11953
12023
|
if (ctx.common.async) {
|
|
11954
12024
|
const handleAsync = async () => {
|
|
11955
12025
|
const inResult = await this._def.in._parseAsync({
|
|
@@ -11960,7 +12030,7 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
|
11960
12030
|
if (inResult.status === "aborted")
|
|
11961
12031
|
return INVALID;
|
|
11962
12032
|
if (inResult.status === "dirty") {
|
|
11963
|
-
|
|
12033
|
+
status2.dirty();
|
|
11964
12034
|
return DIRTY(inResult.value);
|
|
11965
12035
|
} else {
|
|
11966
12036
|
return this._def.out._parseAsync({
|
|
@@ -11980,7 +12050,7 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
|
11980
12050
|
if (inResult.status === "aborted")
|
|
11981
12051
|
return INVALID;
|
|
11982
12052
|
if (inResult.status === "dirty") {
|
|
11983
|
-
|
|
12053
|
+
status2.dirty();
|
|
11984
12054
|
return {
|
|
11985
12055
|
status: "dirty",
|
|
11986
12056
|
value: inResult.value
|
|
@@ -28337,8 +28407,8 @@ var UrlElicitationRequiredError = class extends McpError {
|
|
|
28337
28407
|
};
|
|
28338
28408
|
|
|
28339
28409
|
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
|
|
28340
|
-
function isTerminal(
|
|
28341
|
-
return
|
|
28410
|
+
function isTerminal(status2) {
|
|
28411
|
+
return status2 === "completed" || status2 === "failed" || status2 === "cancelled";
|
|
28342
28412
|
}
|
|
28343
28413
|
|
|
28344
28414
|
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
@@ -30557,8 +30627,8 @@ var Protocol = class {
|
|
|
30557
30627
|
}
|
|
30558
30628
|
return task;
|
|
30559
30629
|
},
|
|
30560
|
-
storeTaskResult: async (taskId,
|
|
30561
|
-
await taskStore.storeTaskResult(taskId,
|
|
30630
|
+
storeTaskResult: async (taskId, status2, result) => {
|
|
30631
|
+
await taskStore.storeTaskResult(taskId, status2, result, sessionId);
|
|
30562
30632
|
const task = await taskStore.getTask(taskId, sessionId);
|
|
30563
30633
|
if (task) {
|
|
30564
30634
|
const notification = TaskStatusNotificationSchema.parse({
|
|
@@ -30574,15 +30644,15 @@ var Protocol = class {
|
|
|
30574
30644
|
getTaskResult: (taskId) => {
|
|
30575
30645
|
return taskStore.getTaskResult(taskId, sessionId);
|
|
30576
30646
|
},
|
|
30577
|
-
updateTaskStatus: async (taskId,
|
|
30647
|
+
updateTaskStatus: async (taskId, status2, statusMessage) => {
|
|
30578
30648
|
const task = await taskStore.getTask(taskId, sessionId);
|
|
30579
30649
|
if (!task) {
|
|
30580
30650
|
throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
|
|
30581
30651
|
}
|
|
30582
30652
|
if (isTerminal(task.status)) {
|
|
30583
|
-
throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${
|
|
30653
|
+
throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status2}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
|
|
30584
30654
|
}
|
|
30585
|
-
await taskStore.updateTaskStatus(taskId,
|
|
30655
|
+
await taskStore.updateTaskStatus(taskId, status2, statusMessage, sessionId);
|
|
30586
30656
|
const updatedTask = await taskStore.getTask(taskId, sessionId);
|
|
30587
30657
|
if (updatedTask) {
|
|
30588
30658
|
const notification = TaskStatusNotificationSchema.parse({
|
|
@@ -32483,7 +32553,21 @@ function jsonResult(data) {
|
|
|
32483
32553
|
]
|
|
32484
32554
|
};
|
|
32485
32555
|
}
|
|
32486
|
-
function
|
|
32556
|
+
function expectedControlFlow(error51) {
|
|
32557
|
+
const message = error51 instanceof Error ? error51.message : "";
|
|
32558
|
+
return /^caveat not found:/.test(message) || /^community エントリは購読物/.test(message) || /^immutable frontmatter key:/.test(message);
|
|
32559
|
+
}
|
|
32560
|
+
function observeToolFailure(handler, productVersion = "0.0.0") {
|
|
32561
|
+
return async (args) => {
|
|
32562
|
+
try {
|
|
32563
|
+
return jsonResult(await handler(args));
|
|
32564
|
+
} catch (error51) {
|
|
32565
|
+
if (!expectedControlFlow(error51)) observeRuntimeError("CAVEAT.MCP_TOOL_FAILED", { version: productVersion });
|
|
32566
|
+
throw error51;
|
|
32567
|
+
}
|
|
32568
|
+
};
|
|
32569
|
+
}
|
|
32570
|
+
function registerAllTools(server, ctx, productVersion = "0.0.0") {
|
|
32487
32571
|
server.registerTool(
|
|
32488
32572
|
"caveat_search",
|
|
32489
32573
|
{
|
|
@@ -32491,7 +32575,7 @@ function registerAllTools(server, ctx) {
|
|
|
32491
32575
|
description: 'Search the "caveats" knowledge base \u2014 records of time-wasting traps someone already diagnosed, including external-spec issues (GPU/driver/CUDA versions, native-module builds, IDE/shell quirks, platform-specific behavior, library version incompatibilities) and reusable repo-specific context. Call this FIRST when a problem smells like a known trap \u2014 before reading stack traces top-to-bottom or trying fixes. Query: 3+ chars, plain tokens only (no OR/NEAR/other FTS5 operators). If it returns 0 hits, retry with synonyms and Japanese/English paraphrases. Returns summary rows including `{id, source}` \u2014 pass BOTH to caveat_get for the full body.',
|
|
32492
32576
|
inputSchema: searchInputShape
|
|
32493
32577
|
},
|
|
32494
|
-
|
|
32578
|
+
observeToolFailure((args) => handleSearch(ctx, args), productVersion)
|
|
32495
32579
|
);
|
|
32496
32580
|
server.registerTool(
|
|
32497
32581
|
"caveat_get",
|
|
@@ -32500,7 +32584,7 @@ function registerAllTools(server, ctx) {
|
|
|
32500
32584
|
description: 'Fetch the full body (frontmatter + H2 sections + text) of a caveat by id. IMPORTANT: when the id came from caveat_search, you MUST pass the `source` field from that same result (e.g., "community/Caveat"). The default source is "own" only; omitting source for a community entry returns not-found.',
|
|
32501
32585
|
inputSchema: getInputShape
|
|
32502
32586
|
},
|
|
32503
|
-
|
|
32587
|
+
observeToolFailure((args) => handleGet(ctx, args), productVersion)
|
|
32504
32588
|
);
|
|
32505
32589
|
server.registerTool(
|
|
32506
32590
|
"caveat_record",
|
|
@@ -32509,7 +32593,7 @@ function registerAllTools(server, ctx) {
|
|
|
32509
32593
|
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).",
|
|
32510
32594
|
inputSchema: recordInputShape
|
|
32511
32595
|
},
|
|
32512
|
-
|
|
32596
|
+
observeToolFailure((args) => handleRecord(ctx, args), productVersion)
|
|
32513
32597
|
);
|
|
32514
32598
|
server.registerTool(
|
|
32515
32599
|
"caveat_update",
|
|
@@ -32518,7 +32602,7 @@ function registerAllTools(server, ctx) {
|
|
|
32518
32602
|
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`.",
|
|
32519
32603
|
inputSchema: updateInputShape
|
|
32520
32604
|
},
|
|
32521
|
-
|
|
32605
|
+
observeToolFailure((args) => handleUpdate(ctx, args), productVersion)
|
|
32522
32606
|
);
|
|
32523
32607
|
server.registerTool(
|
|
32524
32608
|
"caveat_list_recent",
|
|
@@ -32527,7 +32611,7 @@ function registerAllTools(server, ctx) {
|
|
|
32527
32611
|
description: "List caveats ordered by updated_at DESC. Use for browsing recent additions \u2014 e.g., showing the user what is new after caveat_pull. Not for search; use caveat_search when you have a query.",
|
|
32528
32612
|
inputSchema: listRecentInputShape
|
|
32529
32613
|
},
|
|
32530
|
-
|
|
32614
|
+
observeToolFailure((args) => handleListRecent(ctx, args), productVersion)
|
|
32531
32615
|
);
|
|
32532
32616
|
server.registerTool(
|
|
32533
32617
|
"caveat_pull",
|
|
@@ -32536,7 +32620,7 @@ function registerAllTools(server, ctx) {
|
|
|
32536
32620
|
description: "git-pull every subscribed community caveat repo (added via `caveat community add`) and re-index. Call when: (a) the user explicitly asks about others' knowledge on a topic, or (b) caveat_search returned empty for a query that feels like it should have hits and a subscribed repo might be stale. Do NOT call reflexively at session start \u2014 it is cheap but not free, and stale-by-minutes is acceptable. Safe and idempotent.",
|
|
32537
32621
|
inputSchema: pullInputShape
|
|
32538
32622
|
},
|
|
32539
|
-
|
|
32623
|
+
observeToolFailure((args) => handlePull(ctx, args), productVersion)
|
|
32540
32624
|
);
|
|
32541
32625
|
}
|
|
32542
32626
|
|
|
@@ -32547,7 +32631,7 @@ async function startMcpStdioServer(overrides = {}) {
|
|
|
32547
32631
|
{ name: "caveat", version: "0.0.0" },
|
|
32548
32632
|
{ capabilities: { tools: {} } }
|
|
32549
32633
|
);
|
|
32550
|
-
registerAllTools(server, ctx);
|
|
32634
|
+
registerAllTools(server, ctx, overrides.productVersion);
|
|
32551
32635
|
const transport = new StdioServerTransport();
|
|
32552
32636
|
await server.connect(transport);
|
|
32553
32637
|
const shutdown = () => {
|
|
@@ -32573,7 +32657,12 @@ if (invokedPath && thisPath && invokedPath.toLowerCase() === thisPath.toLowerCas
|
|
|
32573
32657
|
|
|
32574
32658
|
// src/commands/mcpServer.ts
|
|
32575
32659
|
async function runMcpServer() {
|
|
32576
|
-
|
|
32660
|
+
try {
|
|
32661
|
+
await startMcpStdioServer({ productVersion: CAVEAT_VERSION });
|
|
32662
|
+
} catch (error51) {
|
|
32663
|
+
observeRuntimeError("CAVEAT.MCP_SERVER_FAILED", { version: CAVEAT_VERSION });
|
|
32664
|
+
throw error51;
|
|
32665
|
+
}
|
|
32577
32666
|
}
|
|
32578
32667
|
|
|
32579
32668
|
// src/commands/hookCmd.ts
|
|
@@ -32586,7 +32675,7 @@ import {
|
|
|
32586
32675
|
mkdirSync as mkdirSync5,
|
|
32587
32676
|
readdirSync as readdirSync2,
|
|
32588
32677
|
readFileSync as readFileSync5,
|
|
32589
|
-
realpathSync as
|
|
32678
|
+
realpathSync as realpathSync4,
|
|
32590
32679
|
rmSync as rmSync2,
|
|
32591
32680
|
writeFileSync as writeFileSync5
|
|
32592
32681
|
} from "node:fs";
|
|
@@ -32619,14 +32708,14 @@ function maybeTriggerAutoReindex(ctx) {
|
|
|
32619
32708
|
|
|
32620
32709
|
// src/autoSyncTrigger.ts
|
|
32621
32710
|
import { spawn as spawn2 } from "node:child_process";
|
|
32622
|
-
import { existsSync as existsSync9, statSync } from "node:fs";
|
|
32711
|
+
import { existsSync as existsSync9, statSync as statSync3 } from "node:fs";
|
|
32623
32712
|
import { join as join11 } from "node:path";
|
|
32624
32713
|
function maybeTriggerAutoSync(ctx) {
|
|
32625
32714
|
if (process.env[CAVEAT_AUTO_SYNC_ENV] === "off") return;
|
|
32626
32715
|
const statePath = join11(ctx.caveatHome, "sync", ".last-autosync.json");
|
|
32627
32716
|
const debounceMs = Number(process.env.CAVEAT_AUTO_SYNC_DEBOUNCE_MS ?? AUTO_SYNC_DEBOUNCE_MS);
|
|
32628
32717
|
try {
|
|
32629
|
-
if (existsSync9(statePath) && Date.now() -
|
|
32718
|
+
if (existsSync9(statePath) && Date.now() - statSync3(statePath).mtimeMs < debounceMs) return;
|
|
32630
32719
|
} catch {
|
|
32631
32720
|
}
|
|
32632
32721
|
const cliScript = process.argv[1];
|
|
@@ -32663,6 +32752,7 @@ function parsePayload(raw) {
|
|
|
32663
32752
|
try {
|
|
32664
32753
|
return JSON.parse(raw);
|
|
32665
32754
|
} catch (err) {
|
|
32755
|
+
observeRuntimeError("CAVEAT.CLAUDE_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
32666
32756
|
const msg = err instanceof Error ? err.message : String(err);
|
|
32667
32757
|
process.stderr.write(`[caveat:hook] json parse error: ${msg}
|
|
32668
32758
|
`);
|
|
@@ -32677,6 +32767,7 @@ function buildContextSafely() {
|
|
|
32677
32767
|
try {
|
|
32678
32768
|
return buildContext(silentLogger);
|
|
32679
32769
|
} catch (err) {
|
|
32770
|
+
observeRuntimeError("CAVEAT.CLAUDE_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
32680
32771
|
const msg = err instanceof Error ? err.message : String(err);
|
|
32681
32772
|
process.stderr.write(`[caveat:hook] context error: ${msg}
|
|
32682
32773
|
`);
|
|
@@ -32700,6 +32791,7 @@ function searchCaveatsSafely(input) {
|
|
|
32700
32791
|
};
|
|
32701
32792
|
hits = inputs.length === 1 ? findCaveatsForHook(db, inputs[0], searchOptions) : findCaveatsForHookSegments(db, inputs, searchOptions);
|
|
32702
32793
|
} catch (err) {
|
|
32794
|
+
observeRuntimeError("CAVEAT.CLAUDE_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
32703
32795
|
const msg = err instanceof Error ? err.message : String(err);
|
|
32704
32796
|
process.stderr.write(`[caveat:hook] search error: ${msg}
|
|
32705
32797
|
`);
|
|
@@ -32709,6 +32801,7 @@ function searchCaveatsSafely(input) {
|
|
|
32709
32801
|
try {
|
|
32710
32802
|
markHit(db, hits);
|
|
32711
32803
|
} catch (err) {
|
|
32804
|
+
observeRuntimeError("CAVEAT.CLAUDE_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
32712
32805
|
const msg = err instanceof Error ? err.message : String(err);
|
|
32713
32806
|
process.stderr.write(`[caveat:hook] markHit error: ${msg}
|
|
32714
32807
|
`);
|
|
@@ -32717,6 +32810,7 @@ function searchCaveatsSafely(input) {
|
|
|
32717
32810
|
try {
|
|
32718
32811
|
logHookQueryMiss({ caveatHome, agent: "claude", surface: inputs[0].surface, query: queryForLog });
|
|
32719
32812
|
} catch (err) {
|
|
32813
|
+
observeRuntimeError("CAVEAT.CLAUDE_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
32720
32814
|
const msg = err instanceof Error ? err.message : String(err);
|
|
32721
32815
|
process.stderr.write(`[caveat:hook] query log error: ${msg}
|
|
32722
32816
|
`);
|
|
@@ -32976,8 +33070,8 @@ function isOwnedWorkerDir(path, root = workerRoot()) {
|
|
|
32976
33070
|
try {
|
|
32977
33071
|
const inputStat = lstatSync(path);
|
|
32978
33072
|
if (inputStat.isSymbolicLink()) return false;
|
|
32979
|
-
const tmpRoot =
|
|
32980
|
-
const resolved =
|
|
33073
|
+
const tmpRoot = realpathSync4(root);
|
|
33074
|
+
const resolved = realpathSync4(path);
|
|
32981
33075
|
const stat = lstatSync(resolved);
|
|
32982
33076
|
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
32983
33077
|
return dirname6(resolved) === tmpRoot && basename(resolved).startsWith("job-") && stat.isDirectory() && !stat.isSymbolicLink() && hasPrivateOwnership(stat, uid);
|
|
@@ -33342,6 +33436,7 @@ function parsePayload2(raw) {
|
|
|
33342
33436
|
try {
|
|
33343
33437
|
return JSON.parse(raw);
|
|
33344
33438
|
} catch (err) {
|
|
33439
|
+
observeRuntimeError("CAVEAT.CODEX_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
33345
33440
|
const msg = err instanceof Error ? err.message : String(err);
|
|
33346
33441
|
process.stderr.write(`[caveat:codex-hook] json parse error: ${msg}
|
|
33347
33442
|
`);
|
|
@@ -33352,6 +33447,7 @@ function buildContextSafely2() {
|
|
|
33352
33447
|
try {
|
|
33353
33448
|
return buildContext(silentLogger2);
|
|
33354
33449
|
} catch (err) {
|
|
33450
|
+
observeRuntimeError("CAVEAT.CODEX_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
33355
33451
|
const msg = err instanceof Error ? err.message : String(err);
|
|
33356
33452
|
process.stderr.write(`[caveat:codex-hook] context error: ${msg}
|
|
33357
33453
|
`);
|
|
@@ -33375,6 +33471,7 @@ function searchCaveatsSafely2(input) {
|
|
|
33375
33471
|
};
|
|
33376
33472
|
hits = inputs.length === 1 ? findCaveatsForHook(db, inputs[0], searchOptions) : findCaveatsForHookSegments(db, inputs, searchOptions);
|
|
33377
33473
|
} catch (err) {
|
|
33474
|
+
observeRuntimeError("CAVEAT.CODEX_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
33378
33475
|
const msg = err instanceof Error ? err.message : String(err);
|
|
33379
33476
|
process.stderr.write(`[caveat:codex-hook] search error: ${msg}
|
|
33380
33477
|
`);
|
|
@@ -33384,6 +33481,7 @@ function searchCaveatsSafely2(input) {
|
|
|
33384
33481
|
try {
|
|
33385
33482
|
markHit(db, hits);
|
|
33386
33483
|
} catch (err) {
|
|
33484
|
+
observeRuntimeError("CAVEAT.CODEX_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
33387
33485
|
const msg = err instanceof Error ? err.message : String(err);
|
|
33388
33486
|
process.stderr.write(`[caveat:codex-hook] markHit error: ${msg}
|
|
33389
33487
|
`);
|
|
@@ -33392,6 +33490,7 @@ function searchCaveatsSafely2(input) {
|
|
|
33392
33490
|
try {
|
|
33393
33491
|
logHookQueryMiss({ caveatHome, agent: "codex", surface: inputs[0].surface, query: queryForLog });
|
|
33394
33492
|
} catch (err) {
|
|
33493
|
+
observeRuntimeError("CAVEAT.CODEX_HOOK_FAILED", { version: CAVEAT_VERSION });
|
|
33395
33494
|
const msg = err instanceof Error ? err.message : String(err);
|
|
33396
33495
|
process.stderr.write(`[caveat:codex-hook] query log error: ${msg}
|
|
33397
33496
|
`);
|
|
@@ -33863,6 +33962,11 @@ async function defaultPrivateRepoUrl(opts, deps) {
|
|
|
33863
33962
|
});
|
|
33864
33963
|
}
|
|
33865
33964
|
async function runSync(ctx, opts, dependencies = {}) {
|
|
33965
|
+
if (opts.repo && (opts.init === void 0 || opts.init === false)) {
|
|
33966
|
+
ctx.logger.error("--repo requires --init");
|
|
33967
|
+
process.exitCode = 1;
|
|
33968
|
+
return;
|
|
33969
|
+
}
|
|
33866
33970
|
try {
|
|
33867
33971
|
const ghRunner = dependencies.ghRunner ?? runGh;
|
|
33868
33972
|
const isTty = dependencies.isTty ?? (() => Boolean(process.stdin.isTTY));
|
|
@@ -33883,7 +33987,6 @@ async function runSync(ctx, opts, dependencies = {}) {
|
|
|
33883
33987
|
);
|
|
33884
33988
|
return;
|
|
33885
33989
|
}
|
|
33886
|
-
if (opts.repo) throw new Error("--repo requires --init");
|
|
33887
33990
|
const result = await syncOwn({
|
|
33888
33991
|
ownDir: ctx.paths.knowledgeRepo,
|
|
33889
33992
|
caveatHome: ctx.caveatHome,
|
|
@@ -33905,6 +34008,7 @@ async function runSync(ctx, opts, dependencies = {}) {
|
|
|
33905
34008
|
}
|
|
33906
34009
|
}
|
|
33907
34010
|
} catch (err) {
|
|
34011
|
+
observeRuntimeError("CAVEAT.SYNC_FAILED", { version: CAVEAT_VERSION });
|
|
33908
34012
|
const message = err instanceof Error ? err.message : String(err);
|
|
33909
34013
|
ctx.logger.error(message);
|
|
33910
34014
|
process.exitCode = 1;
|
|
@@ -33913,7 +34017,7 @@ async function runSync(ctx, opts, dependencies = {}) {
|
|
|
33913
34017
|
|
|
33914
34018
|
// src/commands/codexSidecar.ts
|
|
33915
34019
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
33916
|
-
import { closeSync, constants, fstatSync, lstatSync as lstatSync2, mkdirSync as mkdirSync7, mkdtempSync as mkdtempSync3, openSync, readSync as readSync2, realpathSync as
|
|
34020
|
+
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";
|
|
33917
34021
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
33918
34022
|
import { basename as basename2, dirname as dirname7, join as join14 } from "node:path";
|
|
33919
34023
|
import { cwd, exit } from "node:process";
|
|
@@ -33949,7 +34053,7 @@ function runCodexSidecarWithCaveats(ctx, workflow, prompt, opts) {
|
|
|
33949
34053
|
}
|
|
33950
34054
|
const contextDir = mkdtempSync3(join14(tmpdir4(), "caveat-sidecar-context-"));
|
|
33951
34055
|
const contextFile = join14(contextDir, "context.json");
|
|
33952
|
-
let
|
|
34056
|
+
let status2 = 1;
|
|
33953
34057
|
try {
|
|
33954
34058
|
const blocks = collectCaveatContextBlocks(ctx, {
|
|
33955
34059
|
query: opts.query ?? prompt ?? "",
|
|
@@ -33967,11 +34071,11 @@ function runCodexSidecarWithCaveats(ctx, workflow, prompt, opts) {
|
|
|
33967
34071
|
contextFile,
|
|
33968
34072
|
cli: cliSpec(opts)
|
|
33969
34073
|
});
|
|
33970
|
-
|
|
34074
|
+
status2 = executePlan(ctx.logger, plan.command, plan.args, { saveResult: opts.saveResult });
|
|
33971
34075
|
} finally {
|
|
33972
34076
|
rmSync3(contextDir, { recursive: true, force: true });
|
|
33973
34077
|
}
|
|
33974
|
-
exit(
|
|
34078
|
+
exit(status2);
|
|
33975
34079
|
}
|
|
33976
34080
|
var MAX_ADDITIONAL_CONTEXT_BYTES = 4096;
|
|
33977
34081
|
function readHookSignalAdditionalContextFile(path, testProbe) {
|
|
@@ -33981,7 +34085,7 @@ function readHookSignalAdditionalContextFile(path, testProbe) {
|
|
|
33981
34085
|
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
33982
34086
|
assertPrivateRegular(before, uid, platform);
|
|
33983
34087
|
testProbe?.afterLstat?.();
|
|
33984
|
-
const fd = openSync(path,
|
|
34088
|
+
const fd = openSync(path, constants3.O_RDONLY | constants3.O_NONBLOCK | (constants3.O_NOFOLLOW ?? 0));
|
|
33985
34089
|
let raw;
|
|
33986
34090
|
try {
|
|
33987
34091
|
const opened = fstatSync(fd);
|
|
@@ -34020,8 +34124,8 @@ function assertWindowsPrivateTempContainer(path, platform) {
|
|
|
34020
34124
|
if (platform !== "win32") return;
|
|
34021
34125
|
const parent = dirname7(path);
|
|
34022
34126
|
const parentStat = lstatSync2(parent);
|
|
34023
|
-
const resolvedParent =
|
|
34024
|
-
const resolvedTemp =
|
|
34127
|
+
const resolvedParent = realpathSync5(parent);
|
|
34128
|
+
const resolvedTemp = realpathSync5(tmpdir4());
|
|
34025
34129
|
if (parentStat.isSymbolicLink() || !parentStat.isDirectory() || dirname7(resolvedParent) !== resolvedTemp || !basename2(resolvedParent).startsWith("caveat-")) {
|
|
34026
34130
|
throw new Error("additional context file must be inside a reserved per-user Caveat temporary directory");
|
|
34027
34131
|
}
|
|
@@ -34198,12 +34302,200 @@ function runCommunityRemove(ctx, handle, opts) {
|
|
|
34198
34302
|
}
|
|
34199
34303
|
}
|
|
34200
34304
|
|
|
34305
|
+
// src/commands/factoryDiagnostics.ts
|
|
34306
|
+
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";
|
|
34309
|
+
import { DatabaseSync } from "node:sqlite";
|
|
34310
|
+
import { parse as parseToml2 } from "smol-toml";
|
|
34311
|
+
var status = (ok, reason) => ({ status: ok ? "ready" : "not_ready", reason_code: ok ? "ready" : reason });
|
|
34312
|
+
var unverified = (reason) => ({ status: "unverified", reason_code: reason });
|
|
34313
|
+
function hook(present) {
|
|
34314
|
+
return status(present, "not_installed");
|
|
34315
|
+
}
|
|
34316
|
+
function isRecord2(value) {
|
|
34317
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34318
|
+
}
|
|
34319
|
+
function claudeRegistration(home, nodePath, cliScriptPath) {
|
|
34320
|
+
const path = join15(home, ".claude.json");
|
|
34321
|
+
if (!existsSync13(path)) return status(false, "not_registered");
|
|
34322
|
+
try {
|
|
34323
|
+
const value = JSON.parse(readFileSync7(path, "utf8"));
|
|
34324
|
+
if (!isRecord2(value) || !isRecord2(value.mcpServers)) return status(false, "not_registered");
|
|
34325
|
+
return status(isCaveatClaudeMcpRegistration(value.mcpServers.caveat, nodePath, cliScriptPath), "not_registered");
|
|
34326
|
+
} catch {
|
|
34327
|
+
return unverified("config_unreadable");
|
|
34328
|
+
}
|
|
34329
|
+
}
|
|
34330
|
+
function claudeHooks(home, nodePath, cliScriptPath) {
|
|
34331
|
+
try {
|
|
34332
|
+
const settings = JSON.parse(readFileSync7(join15(home, ".claude", "settings.json"), "utf8"));
|
|
34333
|
+
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
|
+
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
|
+
} catch {
|
|
34336
|
+
const bad = unverified("config_unreadable");
|
|
34337
|
+
return { user_prompt_submit: { ...bad }, post_tool_use: { ...bad }, post_tool_use_failure: { ...bad }, stop: { ...bad } };
|
|
34338
|
+
}
|
|
34339
|
+
}
|
|
34340
|
+
var EXPECTED_SEARCH_SQL = /* @__PURE__ */ new Map([
|
|
34341
|
+
["entries_fts", "create virtual table entries_fts using fts5( id unindexed, title, body, tags, content='entries', content_rowid='rowid', tokenize='trigram' )"],
|
|
34342
|
+
["entries_ai", "create trigger entries_ai after insert on entries begin insert into entries_fts(rowid, id, title, body, tags) values (new.rowid, new.id, new.title, new.body, new.tags); end"],
|
|
34343
|
+
["entries_ad", "create trigger entries_ad after delete on entries begin insert into entries_fts(entries_fts, rowid, id, title, body, tags) values('delete', old.rowid, old.id, old.title, old.body, old.tags); end"],
|
|
34344
|
+
["entries_au", "create trigger entries_au after update on entries begin insert into entries_fts(entries_fts, rowid, id, title, body, tags) values('delete', old.rowid, old.id, old.title, old.body, old.tags); insert into entries_fts(rowid, id, title, body, tags) values (new.rowid, new.id, new.title, new.body, new.tags); end"]
|
|
34345
|
+
]);
|
|
34346
|
+
function strictSearchSchema(db) {
|
|
34347
|
+
const normalize = (sql) => (sql ?? "").toLowerCase().replace(/\s+/g, " ");
|
|
34348
|
+
const objects = db.prepare("SELECT name, sql FROM sqlite_master WHERE name = 'entries_fts' OR (type = 'trigger' AND tbl_name = 'entries')").all();
|
|
34349
|
+
if (objects.length !== EXPECTED_SEARCH_SQL.size || objects.some((object3) => normalize(object3.sql) !== EXPECTED_SEARCH_SQL.get(object3.name))) return false;
|
|
34350
|
+
const columns = db.prepare("PRAGMA table_xinfo(entries_fts)").all();
|
|
34351
|
+
return columns.map((column) => `${column.name}:${column.hidden}`).join(",") === "id:0,title:0,body:0,tags:0,entries_fts:1,rank:1";
|
|
34352
|
+
}
|
|
34353
|
+
function database(path) {
|
|
34354
|
+
if (!existsSync13(path)) return { status: "not_ready", reason_code: "missing", schema_version: null, supported_schema_version: 3, migration_status: "unverified" };
|
|
34355
|
+
try {
|
|
34356
|
+
const db = new DatabaseSync(path, { readOnly: true });
|
|
34357
|
+
try {
|
|
34358
|
+
const row = db.prepare("PRAGMA user_version").get();
|
|
34359
|
+
const columns = db.prepare("PRAGMA table_info(entries)").all().map((entry) => entry.name);
|
|
34360
|
+
const expectedColumns = ["rowid", "id", "source", "path", "title", "body", "frontmatter_json", "tags", "confidence", "visibility", "file_mtime", "indexed_at", "last_hit_at", "topical_text", "symptom_text"];
|
|
34361
|
+
const objects = db.prepare("SELECT type, name, tbl_name, sql FROM sqlite_master WHERE name = 'entries_fts' OR (type = 'trigger' AND tbl_name = 'entries')").all();
|
|
34362
|
+
const normalized = (sql) => (sql ?? "").toLowerCase().replace(/\s+/g, " ");
|
|
34363
|
+
const ftsSql = normalized(objects.find((entry) => entry.type === "table" && entry.name === "entries_fts")?.sql ?? null);
|
|
34364
|
+
const fts = ftsSql.startsWith("create virtual table entries_fts using fts5(") && ftsSql.includes("content='entries'") && ftsSql.includes("content_rowid='rowid'") && ftsSql.includes("tokenize='trigram'");
|
|
34365
|
+
const triggers = new Map(objects.filter((entry) => entry.type === "trigger").map((entry) => [entry.name, normalized(entry.sql)]));
|
|
34366
|
+
const triggerShape = triggers.size === 3 && triggers.get("entries_ai")?.includes("after insert on entries") && triggers.get("entries_ai")?.includes("insert into entries_fts") && triggers.get("entries_ad")?.includes("after delete on entries") && triggers.get("entries_ad")?.includes("values('delete'") && triggers.get("entries_au")?.includes("after update on entries") && triggers.get("entries_au")?.includes("values('delete'") && (triggers.get("entries_au")?.match(/insert into entries_fts/g)?.length ?? 0) === 2;
|
|
34367
|
+
const indexes = db.prepare("PRAGMA index_list(entries)").all();
|
|
34368
|
+
const uniqueSourceId = indexes.some((index) => index.unique === 1 && db.prepare(`PRAGMA index_info(${JSON.stringify(index.name)})`).all().map((part) => part.name).join(",") === "source,id");
|
|
34369
|
+
const current = row.user_version === 3 && columns.join(",") === expectedColumns.join(",") && fts && Boolean(triggerShape) && uniqueSourceId && strictSearchSchema(db);
|
|
34370
|
+
return { status: current ? "ready" : "not_ready", reason_code: current ? "ready" : "schema_contract_mismatch", schema_version: row.user_version, supported_schema_version: 3, migration_status: current ? "current" : "failed" };
|
|
34371
|
+
} finally {
|
|
34372
|
+
db.close();
|
|
34373
|
+
}
|
|
34374
|
+
} catch {
|
|
34375
|
+
return { status: "unverified", reason_code: "open_failed", schema_version: null, supported_schema_version: 3, migration_status: "unverified" };
|
|
34376
|
+
}
|
|
34377
|
+
}
|
|
34378
|
+
function codexFeature(codexHome) {
|
|
34379
|
+
const path = join15(codexHome, "config.toml");
|
|
34380
|
+
if (!existsSync13(path)) return status(false, "feature_disabled");
|
|
34381
|
+
try {
|
|
34382
|
+
const config2 = parseToml2(readFileSync7(path, "utf8"));
|
|
34383
|
+
if (!isRecord2(config2.features)) return status(false, "feature_disabled");
|
|
34384
|
+
const features = config2.features;
|
|
34385
|
+
return status(features.hooks === true && features.codex_hooks === void 0, "feature_disabled");
|
|
34386
|
+
} catch {
|
|
34387
|
+
return unverified("config_unreadable");
|
|
34388
|
+
}
|
|
34389
|
+
}
|
|
34390
|
+
function codexHooks(codexHome, nodePath, cliScriptPath) {
|
|
34391
|
+
const value = JSON.parse(readFileSync7(join15(codexHome, "hooks.json"), "utf8"));
|
|
34392
|
+
if (!isRecord2(value) || !isRecord2(value.hooks)) throw Error("config_unreadable");
|
|
34393
|
+
const hooks = value.hooks;
|
|
34394
|
+
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)));
|
|
34395
|
+
return { userPromptSubmit: present("UserPromptSubmit", "user-prompt-submit"), postToolUse: present("PostToolUse", "post-tool-use"), stop: present("Stop", "stop") };
|
|
34396
|
+
}
|
|
34397
|
+
function sync(own) {
|
|
34398
|
+
try {
|
|
34399
|
+
execFileSync("git", ["-C", own, "rev-parse", "--is-inside-work-tree"], { stdio: "ignore" });
|
|
34400
|
+
} catch {
|
|
34401
|
+
return status(false, "not_git_worktree");
|
|
34402
|
+
}
|
|
34403
|
+
try {
|
|
34404
|
+
execFileSync("git", ["-C", own, "remote", "get-url", "origin"], { stdio: "ignore" });
|
|
34405
|
+
} catch {
|
|
34406
|
+
return status(false, "origin_missing");
|
|
34407
|
+
}
|
|
34408
|
+
try {
|
|
34409
|
+
const dirty = execFileSync("git", ["-C", own, "status", "--porcelain=v1", "--untracked-files=normal"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3, env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" } }).trim();
|
|
34410
|
+
if (dirty) return status(false, "worktree_dirty");
|
|
34411
|
+
const upstream = execFileSync("git", ["-C", own, "rev-parse", "--symbolic-full-name", "@{upstream}"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim();
|
|
34412
|
+
if (!upstream.startsWith("refs/remotes/origin/")) return status(false, "upstream_not_origin");
|
|
34413
|
+
const remoteRef = `refs/heads/${upstream.slice("refs/remotes/origin/".length)}`;
|
|
34414
|
+
const remote = execFileSync("git", ["-C", own, "ls-remote", "--exit-code", "origin", remoteRef], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e4, maxBuffer: 16384 }).trim().split(/\s+/)[0];
|
|
34415
|
+
const head = execFileSync("git", ["-C", own, "rev-parse", "HEAD"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim();
|
|
34416
|
+
if (!/^[0-9a-f]{40}$/.test(remote ?? "") || !/^[0-9a-f]{40}$/.test(head)) return unverified("sync_hash_unparseable");
|
|
34417
|
+
if (remote !== head) return status(false, "remote_mismatch");
|
|
34418
|
+
const counts = execFileSync("git", ["-C", own, "rev-list", "--left-right", "--count", "@{upstream}...HEAD"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim().split(/\s+/).map(Number);
|
|
34419
|
+
if (counts.length !== 2 || counts.some((value) => !Number.isSafeInteger(value) || value < 0)) return unverified("sync_count_unparseable");
|
|
34420
|
+
if (counts[0] === 0 && counts[1] === 0) return status(true, "ready");
|
|
34421
|
+
return status(false, counts[0] && counts[1] ? "diverged" : counts[0] ? "behind" : "ahead");
|
|
34422
|
+
} catch {
|
|
34423
|
+
return unverified("upstream_unavailable");
|
|
34424
|
+
}
|
|
34425
|
+
}
|
|
34426
|
+
function factoryDiagnostics(ctx, codexHome = process.env.CODEX_HOME ?? join15(ctx.userHome, ".codex")) {
|
|
34427
|
+
const nodePath = process.execPath;
|
|
34428
|
+
const cliScriptPath = process.argv[1] ?? "";
|
|
34429
|
+
const db = database(ctx.paths.dbPath);
|
|
34430
|
+
const feature = codexFeature(codexHome);
|
|
34431
|
+
let installedCodexHooks = null;
|
|
34432
|
+
try {
|
|
34433
|
+
installedCodexHooks = codexHooks(codexHome, nodePath, cliScriptPath);
|
|
34434
|
+
} catch {
|
|
34435
|
+
}
|
|
34436
|
+
const codexHook2 = (present) => present === void 0 ? unverified("config_unreadable") : !present ? hook(false) : feature.status === "ready" ? hook(true) : { ...feature };
|
|
34437
|
+
const output = { schema: "caveat.native_factory_diagnostics.v1", product: "caveat", version: CAVEAT_VERSION, overall: { status: "unverified" }, database: db, sync: sync(ctx.paths.knowledgeRepo), connectors: { claude: { status: "unverified", mcp: claudeRegistration(ctx.userHome, nodePath, cliScriptPath), hooks: claudeHooks(ctx.userHome, nodePath, cliScriptPath) }, codex: { status: "unverified", hooks: { user_prompt_submit: codexHook2(installedCodexHooks?.userPromptSubmit), post_tool_use: codexHook2(installedCodexHooks?.postToolUse), stop: codexHook2(installedCodexHooks?.stop) } } } };
|
|
34438
|
+
const aggregate = (all) => all.includes("not_ready") ? "not_ready" : all.includes("unverified") ? "unverified" : "ready";
|
|
34439
|
+
const connectorStatus = (connector) => aggregate([...Object.values(connector.hooks), ...connector.mcp ? [connector.mcp] : []].map((v) => v.status));
|
|
34440
|
+
output.connectors.claude.status = connectorStatus(output.connectors.claude);
|
|
34441
|
+
output.connectors.codex.status = connectorStatus(output.connectors.codex);
|
|
34442
|
+
const statuses = [output.database.status, output.sync.status, output.connectors.claude.status, output.connectors.codex.status];
|
|
34443
|
+
output.overall.status = aggregate(statuses);
|
|
34444
|
+
return output;
|
|
34445
|
+
}
|
|
34446
|
+
|
|
34447
|
+
// src/commands/runtimeErrors.ts
|
|
34448
|
+
function runRuntimeErrors(action, value, opts = {}) {
|
|
34449
|
+
const runtime = { version: CAVEAT_VERSION };
|
|
34450
|
+
if (action === "snapshot") return runtimeErrorsSnapshot(opts.afterCursor ?? 0, opts.limit ?? 256, runtime);
|
|
34451
|
+
if (action === "diagnostics") return runtimeErrorsDiagnostics(runtime);
|
|
34452
|
+
if (action === "ack") return acknowledgeRuntimeErrors(parseCursor(value), runtime);
|
|
34453
|
+
if (action === "resolve") return setRuntimeErrorStatus(value ?? "", "resolved", runtime);
|
|
34454
|
+
if (action === "reopen") return setRuntimeErrorStatus(value ?? "", "open", runtime);
|
|
34455
|
+
if (action === "compact") return compactRuntimeErrors(runtime);
|
|
34456
|
+
throw new Error("unknown_runtime_errors_action");
|
|
34457
|
+
}
|
|
34458
|
+
function parseCursor(value) {
|
|
34459
|
+
if (!value || !/^(?:0|[1-9][0-9]*)$/.test(value)) throw Error("invalid_cursor");
|
|
34460
|
+
const parsed = Number(value);
|
|
34461
|
+
if (!Number.isSafeInteger(parsed)) throw Error("invalid_cursor");
|
|
34462
|
+
return parsed;
|
|
34463
|
+
}
|
|
34464
|
+
|
|
34201
34465
|
// src/index.ts
|
|
34202
34466
|
var program = new Command();
|
|
34203
34467
|
function collectRepeatable(value, previous) {
|
|
34204
34468
|
return [...previous, value];
|
|
34205
34469
|
}
|
|
34206
34470
|
program.name("caveat").description("External spec gotcha knowledge base CLI").version(CAVEAT_VERSION);
|
|
34471
|
+
program.command("factory-diagnostics").description("Emit read-only factory diagnostics").requiredOption("--json", "emit the versioned JSON contract").action((opts) => {
|
|
34472
|
+
const output = factoryDiagnostics(buildContext(stdoutLogger));
|
|
34473
|
+
process.stdout.write(`${JSON.stringify(output)}
|
|
34474
|
+
`);
|
|
34475
|
+
if (output.overall.status !== "ready") process.exitCode = 1;
|
|
34476
|
+
});
|
|
34477
|
+
var runtimeErrors = program.command("runtime-errors").description("Inspect Caveat opt-in runtime errors");
|
|
34478
|
+
var parseLimit = (value) => {
|
|
34479
|
+
const parsed = parseCursor(value);
|
|
34480
|
+
if (parsed < 1 || parsed > 256) throw Error("invalid_limit");
|
|
34481
|
+
return parsed;
|
|
34482
|
+
};
|
|
34483
|
+
runtimeErrors.command("snapshot").requiredOption("--json", "emit JSON").option("--after-cursor <n>", "cursor", parseCursor, 0).option("--limit <n>", "limit", parseLimit, 256).action((opts) => {
|
|
34484
|
+
process.stdout.write(`${JSON.stringify(runRuntimeErrors("snapshot", void 0, opts))}
|
|
34485
|
+
`);
|
|
34486
|
+
});
|
|
34487
|
+
for (const action of ["diagnostics", "compact"]) runtimeErrors.command(action).requiredOption("--json", "emit JSON").action(() => {
|
|
34488
|
+
process.stdout.write(`${JSON.stringify(runRuntimeErrors(action))}
|
|
34489
|
+
`);
|
|
34490
|
+
});
|
|
34491
|
+
runtimeErrors.command("ack <cursor>").requiredOption("--json", "emit JSON").action((cursor) => {
|
|
34492
|
+
process.stdout.write(`${JSON.stringify(runRuntimeErrors("ack", cursor))}
|
|
34493
|
+
`);
|
|
34494
|
+
});
|
|
34495
|
+
for (const action of ["resolve", "reopen"]) runtimeErrors.command(`${action} <fingerprint>`).requiredOption("--json", "emit JSON").action((fingerprint) => {
|
|
34496
|
+
process.stdout.write(`${JSON.stringify(runRuntimeErrors(action, fingerprint))}
|
|
34497
|
+
`);
|
|
34498
|
+
});
|
|
34207
34499
|
program.command("init").description(
|
|
34208
34500
|
"Initialize ~/.caveatrc.json, ~/.caveat/, and register Claude Code integration. Add knowledge sources later with `caveat community add <github-url>`."
|
|
34209
34501
|
).option("--skip-claude", "skip Claude Code MCP + hook registration", false).option("--sync [url]", "initialize private sync (optionally with its URL)").option("--publish-target [url]", "configure the sealed public mirror target").option("--yes", "approve creating conventional GitHub repositories", false).option("--skip-codex-hook", "skip Codex hook installation", false).option("--dry-run", "show planned changes without writing", false).option(
|