@foundocs/foundocs-setup 0.3.25 → 0.3.26
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/README.md +7 -1
- package/dist/bridge.mjs +698 -245
- package/package.json +3 -3
- package/skills/foundocs/SKILL.md +1 -1
- package/skills/foundocs/references/effect-measurement.md +21 -1
- package/skills/foundocs/scripts/session-start.mjs +1 -1
- package/src/bridge.mjs +30 -8
- package/src/cli.mjs +2 -2
- package/src/effect-automatic.mjs +184 -0
- package/src/effect-config.mjs +31 -0
- package/src/effect-storage.mjs +2 -0
- package/src/effect.mjs +12 -3
- package/src/runtime.mjs +23 -1
- package/src/setup.mjs +6 -2
package/dist/bridge.mjs
CHANGED
|
@@ -28,8 +28,8 @@ var __exportAll = (all, symbols) => {
|
|
|
28
28
|
};
|
|
29
29
|
var __copyProps = (to, from, except, desc) => {
|
|
30
30
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (var
|
|
32
|
-
key =
|
|
31
|
+
for (var keys2 = __getOwnPropNames(from), i = 0, n = keys2.length, key; i < n; i++) {
|
|
32
|
+
key = keys2[i];
|
|
33
33
|
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
34
34
|
__defProp2(to, key, {
|
|
35
35
|
get: ((k) => from[k]).bind(null, key),
|
|
@@ -227,8 +227,8 @@ function defineLazy(object2, key, getter) {
|
|
|
227
227
|
configurable: true
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
function objectClone(
|
|
231
|
-
return Object.create(Object.getPrototypeOf(
|
|
230
|
+
function objectClone(obj2) {
|
|
231
|
+
return Object.create(Object.getPrototypeOf(obj2), Object.getOwnPropertyDescriptors(obj2));
|
|
232
232
|
}
|
|
233
233
|
function assignProp(target, prop, value) {
|
|
234
234
|
Object.defineProperty(target, prop, {
|
|
@@ -262,9 +262,9 @@ function putProp(target, key, value) {
|
|
|
262
262
|
else
|
|
263
263
|
target[key] = value;
|
|
264
264
|
}
|
|
265
|
-
function mirrorShape(target, source,
|
|
265
|
+
function mirrorShape(target, source, keys2, wrap) {
|
|
266
266
|
const raw = sourceShape(source);
|
|
267
|
-
for (const key of
|
|
267
|
+
for (const key of keys2) {
|
|
268
268
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
269
269
|
if (!desc.enumerable)
|
|
270
270
|
continue;
|
|
@@ -299,18 +299,18 @@ function mergeDefs(...defs) {
|
|
|
299
299
|
function cloneDef(schema) {
|
|
300
300
|
return mergeDefs(schema._zod.def);
|
|
301
301
|
}
|
|
302
|
-
function getElementAtPath(
|
|
302
|
+
function getElementAtPath(obj2, path) {
|
|
303
303
|
if (!path)
|
|
304
|
-
return
|
|
305
|
-
return path.reduce((acc, key) => acc?.[key],
|
|
304
|
+
return obj2;
|
|
305
|
+
return path.reduce((acc, key) => acc?.[key], obj2);
|
|
306
306
|
}
|
|
307
307
|
function promiseAllObject(promisesObj) {
|
|
308
|
-
const
|
|
309
|
-
const promises =
|
|
308
|
+
const keys2 = Object.keys(promisesObj);
|
|
309
|
+
const promises = keys2.map((key) => promisesObj[key]);
|
|
310
310
|
return Promise.all(promises).then((results) => {
|
|
311
311
|
const resolvedObj = {};
|
|
312
|
-
for (let i = 0; i <
|
|
313
|
-
resolvedObj[
|
|
312
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
313
|
+
resolvedObj[keys2[i]] = results[i];
|
|
314
314
|
}
|
|
315
315
|
return resolvedObj;
|
|
316
316
|
});
|
|
@@ -532,15 +532,15 @@ function pick(schema, mask) {
|
|
|
532
532
|
}
|
|
533
533
|
function maskedKeys(schema, mask) {
|
|
534
534
|
const raw = sourceShape(schema);
|
|
535
|
-
const
|
|
535
|
+
const keys2 = [];
|
|
536
536
|
for (const key of Reflect.ownKeys(mask)) {
|
|
537
537
|
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable) {
|
|
538
538
|
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
539
539
|
}
|
|
540
540
|
if (mask[key])
|
|
541
|
-
|
|
541
|
+
keys2.push(key);
|
|
542
542
|
}
|
|
543
|
-
return
|
|
543
|
+
return keys2;
|
|
544
544
|
}
|
|
545
545
|
function omit(schema, mask) {
|
|
546
546
|
const currDef = schema._zod.def;
|
|
@@ -738,9 +738,9 @@ function parsedType(data) {
|
|
|
738
738
|
if (Array.isArray(data)) {
|
|
739
739
|
return "array";
|
|
740
740
|
}
|
|
741
|
-
const
|
|
742
|
-
if (
|
|
743
|
-
return
|
|
741
|
+
const obj2 = data;
|
|
742
|
+
if (obj2 && Object.getPrototypeOf(obj2) !== Object.prototype && "constructor" in obj2 && obj2.constructor) {
|
|
743
|
+
return obj2.constructor.name;
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
}
|
|
@@ -758,8 +758,8 @@ function issue(...args) {
|
|
|
758
758
|
}
|
|
759
759
|
return { ...iss };
|
|
760
760
|
}
|
|
761
|
-
function cleanEnum(
|
|
762
|
-
return Object.entries(
|
|
761
|
+
function cleanEnum(obj2) {
|
|
762
|
+
return Object.entries(obj2).filter(([k, _]) => {
|
|
763
763
|
return Number.isNaN(Number.parseInt(k, 10));
|
|
764
764
|
}).map((el) => el[1]);
|
|
765
765
|
}
|
|
@@ -1083,15 +1083,15 @@ var $ZodError = $constructor("$ZodError", initializer);
|
|
|
1083
1083
|
var $ZodRealError = $constructor("$ZodError", initializer, void 0, {
|
|
1084
1084
|
Parent: Error
|
|
1085
1085
|
});
|
|
1086
|
-
function node(
|
|
1087
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
1086
|
+
function node(obj2, key, make) {
|
|
1087
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
1088
1088
|
if (key === "__proto__") {
|
|
1089
|
-
Object.defineProperty(
|
|
1089
|
+
Object.defineProperty(obj2, key, { value: make(), writable: true, enumerable: true, configurable: true });
|
|
1090
1090
|
} else {
|
|
1091
|
-
|
|
1091
|
+
obj2[key] = make();
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
return
|
|
1094
|
+
return obj2[key];
|
|
1095
1095
|
}
|
|
1096
1096
|
function flattenError(error2, mapper = (issue2) => issue2.message) {
|
|
1097
1097
|
const fieldErrors = {};
|
|
@@ -2450,10 +2450,10 @@ function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
|
2450
2450
|
}
|
|
2451
2451
|
var NO_SYMBOL_KEYS = [];
|
|
2452
2452
|
function normalizeDef(def) {
|
|
2453
|
-
const
|
|
2453
|
+
const keys2 = Object.keys(def.shape);
|
|
2454
2454
|
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
2455
2455
|
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
2456
|
-
const allKeys = symbolKeys.length ? [...
|
|
2456
|
+
const allKeys = symbolKeys.length ? [...keys2, ...symbolKeys] : keys2;
|
|
2457
2457
|
for (const k of allKeys) {
|
|
2458
2458
|
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
|
|
2459
2459
|
throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
@@ -2465,8 +2465,8 @@ function normalizeDef(def) {
|
|
|
2465
2465
|
allKeys,
|
|
2466
2466
|
symbolKeys,
|
|
2467
2467
|
// string-only: handleCatchall matches it against `for...in`, which never yields a symbol
|
|
2468
|
-
keySet: new Set(
|
|
2469
|
-
numKeys:
|
|
2468
|
+
keySet: new Set(keys2),
|
|
2469
|
+
numKeys: keys2.length,
|
|
2470
2470
|
optionalKeys: new Set(okeys)
|
|
2471
2471
|
};
|
|
2472
2472
|
}
|
|
@@ -2939,19 +2939,19 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2939
2939
|
let unrecIssue;
|
|
2940
2940
|
const keyIssues = /* @__PURE__ */ new Map();
|
|
2941
2941
|
const collect = (iss, side) => {
|
|
2942
|
-
let
|
|
2942
|
+
let keys2;
|
|
2943
2943
|
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2944
2944
|
unrecIssue ?? (unrecIssue = iss);
|
|
2945
|
-
|
|
2945
|
+
keys2 = iss.keys;
|
|
2946
2946
|
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
|
|
2947
2947
|
const k = String(iss.path[0]);
|
|
2948
2948
|
if (!keyIssues.has(k))
|
|
2949
2949
|
keyIssues.set(k, iss);
|
|
2950
|
-
|
|
2950
|
+
keys2 = [k];
|
|
2951
2951
|
} else {
|
|
2952
2952
|
return false;
|
|
2953
2953
|
}
|
|
2954
|
-
for (const k of
|
|
2954
|
+
for (const k of keys2) {
|
|
2955
2955
|
if (!unrecKeys.has(k))
|
|
2956
2956
|
unrecKeys.set(k, {});
|
|
2957
2957
|
unrecKeys.get(k)[side] = true;
|
|
@@ -4668,8 +4668,8 @@ function compactTypeUnion(schema) {
|
|
|
4668
4668
|
if (!option || typeof option !== "object")
|
|
4669
4669
|
return;
|
|
4670
4670
|
compactTypeUnion(option);
|
|
4671
|
-
const
|
|
4672
|
-
if (
|
|
4671
|
+
const keys2 = Object.keys(option);
|
|
4672
|
+
if (keys2.length !== 1 || keys2[0] !== "type")
|
|
4673
4673
|
return;
|
|
4674
4674
|
const type = option.type;
|
|
4675
4675
|
for (const member of Array.isArray(type) ? type : [type]) {
|
|
@@ -6576,11 +6576,11 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
6576
6576
|
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
|
|
6577
6577
|
inst.enum = def.entries;
|
|
6578
6578
|
inst.options = [...inst._zod.values];
|
|
6579
|
-
const
|
|
6579
|
+
const keys2 = new Set(Object.keys(def.entries));
|
|
6580
6580
|
inst.extract = (values, params) => {
|
|
6581
6581
|
const newEntries = {};
|
|
6582
6582
|
for (const value of values) {
|
|
6583
|
-
if (
|
|
6583
|
+
if (keys2.has(value)) {
|
|
6584
6584
|
newEntries[value] = def.entries[value];
|
|
6585
6585
|
} else
|
|
6586
6586
|
throw new Error(`Key ${value} not found in enum`);
|
|
@@ -6595,7 +6595,7 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
6595
6595
|
inst.exclude = (values, params) => {
|
|
6596
6596
|
const newEntries = { ...def.entries };
|
|
6597
6597
|
for (const value of values) {
|
|
6598
|
-
if (
|
|
6598
|
+
if (keys2.has(value)) {
|
|
6599
6599
|
delete newEntries[value];
|
|
6600
6600
|
} else
|
|
6601
6601
|
throw new Error(`Key ${value} not found in enum`);
|
|
@@ -12487,7 +12487,7 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12487
12487
|
var index = header.indexOf(";");
|
|
12488
12488
|
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
12489
12489
|
if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type");
|
|
12490
|
-
var
|
|
12490
|
+
var obj2 = new ContentType(type.toLowerCase());
|
|
12491
12491
|
if (index !== -1) {
|
|
12492
12492
|
var key;
|
|
12493
12493
|
var match;
|
|
@@ -12502,16 +12502,16 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12502
12502
|
value = value.slice(1, -1);
|
|
12503
12503
|
if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1");
|
|
12504
12504
|
}
|
|
12505
|
-
|
|
12505
|
+
obj2.parameters[key] = value;
|
|
12506
12506
|
}
|
|
12507
12507
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
12508
12508
|
}
|
|
12509
|
-
return
|
|
12509
|
+
return obj2;
|
|
12510
12510
|
}
|
|
12511
|
-
function getcontenttype(
|
|
12511
|
+
function getcontenttype(obj2) {
|
|
12512
12512
|
var header;
|
|
12513
|
-
if (typeof
|
|
12514
|
-
else if (typeof
|
|
12513
|
+
if (typeof obj2.getHeader === "function") header = obj2.getHeader("content-type");
|
|
12514
|
+
else if (typeof obj2.headers === "object") header = obj2.headers && obj2.headers["content-type"];
|
|
12515
12515
|
if (typeof header !== "string") throw new TypeError("content-type header is missing from object");
|
|
12516
12516
|
return header;
|
|
12517
12517
|
}
|
|
@@ -12994,9 +12994,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12994
12994
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
12995
12995
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
12996
12996
|
}
|
|
12997
|
-
optimizeNames(names,
|
|
12997
|
+
optimizeNames(names, constants3) {
|
|
12998
12998
|
if (!names[this.name.str]) return;
|
|
12999
|
-
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names,
|
|
12999
|
+
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants3);
|
|
13000
13000
|
return this;
|
|
13001
13001
|
}
|
|
13002
13002
|
get names() {
|
|
@@ -13013,9 +13013,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13013
13013
|
render({ _n }) {
|
|
13014
13014
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
13015
13015
|
}
|
|
13016
|
-
optimizeNames(names,
|
|
13016
|
+
optimizeNames(names, constants3) {
|
|
13017
13017
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects) return;
|
|
13018
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
13018
|
+
this.rhs = optimizeExpr(this.rhs, names, constants3);
|
|
13019
13019
|
return this;
|
|
13020
13020
|
}
|
|
13021
13021
|
get names() {
|
|
@@ -13074,8 +13074,8 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13074
13074
|
optimizeNodes() {
|
|
13075
13075
|
return `${this.code}` ? this : void 0;
|
|
13076
13076
|
}
|
|
13077
|
-
optimizeNames(names,
|
|
13078
|
-
this.code = optimizeExpr(this.code, names,
|
|
13077
|
+
optimizeNames(names, constants3) {
|
|
13078
|
+
this.code = optimizeExpr(this.code, names, constants3);
|
|
13079
13079
|
return this;
|
|
13080
13080
|
}
|
|
13081
13081
|
get names() {
|
|
@@ -13101,12 +13101,12 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13101
13101
|
}
|
|
13102
13102
|
return nodes.length > 0 ? this : void 0;
|
|
13103
13103
|
}
|
|
13104
|
-
optimizeNames(names,
|
|
13104
|
+
optimizeNames(names, constants3) {
|
|
13105
13105
|
const { nodes } = this;
|
|
13106
13106
|
let i = nodes.length;
|
|
13107
13107
|
while (i--) {
|
|
13108
13108
|
const n = nodes[i];
|
|
13109
|
-
if (n.optimizeNames(names,
|
|
13109
|
+
if (n.optimizeNames(names, constants3)) continue;
|
|
13110
13110
|
subtractNames(names, n.names);
|
|
13111
13111
|
nodes.splice(i, 1);
|
|
13112
13112
|
}
|
|
@@ -13153,11 +13153,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13153
13153
|
if (cond === false || !this.nodes.length) return void 0;
|
|
13154
13154
|
return this;
|
|
13155
13155
|
}
|
|
13156
|
-
optimizeNames(names,
|
|
13156
|
+
optimizeNames(names, constants3) {
|
|
13157
13157
|
var _a3;
|
|
13158
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
13159
|
-
if (!(super.optimizeNames(names,
|
|
13160
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
13158
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants3);
|
|
13159
|
+
if (!(super.optimizeNames(names, constants3) || this.else)) return;
|
|
13160
|
+
this.condition = optimizeExpr(this.condition, names, constants3);
|
|
13161
13161
|
return this;
|
|
13162
13162
|
}
|
|
13163
13163
|
get names() {
|
|
@@ -13179,9 +13179,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13179
13179
|
render(opts) {
|
|
13180
13180
|
return `for(${this.iteration})` + super.render(opts);
|
|
13181
13181
|
}
|
|
13182
|
-
optimizeNames(names,
|
|
13183
|
-
if (!super.optimizeNames(names,
|
|
13184
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
13182
|
+
optimizeNames(names, constants3) {
|
|
13183
|
+
if (!super.optimizeNames(names, constants3)) return;
|
|
13184
|
+
this.iteration = optimizeExpr(this.iteration, names, constants3);
|
|
13185
13185
|
return this;
|
|
13186
13186
|
}
|
|
13187
13187
|
get names() {
|
|
@@ -13216,9 +13216,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13216
13216
|
render(opts) {
|
|
13217
13217
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
13218
13218
|
}
|
|
13219
|
-
optimizeNames(names,
|
|
13220
|
-
if (!super.optimizeNames(names,
|
|
13221
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
13219
|
+
optimizeNames(names, constants3) {
|
|
13220
|
+
if (!super.optimizeNames(names, constants3)) return;
|
|
13221
|
+
this.iterable = optimizeExpr(this.iterable, names, constants3);
|
|
13222
13222
|
return this;
|
|
13223
13223
|
}
|
|
13224
13224
|
get names() {
|
|
@@ -13257,11 +13257,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13257
13257
|
(_b = this.finally) === null || _b === void 0 || _b.optimizeNodes();
|
|
13258
13258
|
return this;
|
|
13259
13259
|
}
|
|
13260
|
-
optimizeNames(names,
|
|
13260
|
+
optimizeNames(names, constants3) {
|
|
13261
13261
|
var _a3, _b;
|
|
13262
|
-
super.optimizeNames(names,
|
|
13263
|
-
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names,
|
|
13264
|
-
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names,
|
|
13262
|
+
super.optimizeNames(names, constants3);
|
|
13263
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants3);
|
|
13264
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants3);
|
|
13265
13265
|
return this;
|
|
13266
13266
|
}
|
|
13267
13267
|
get names() {
|
|
@@ -13401,10 +13401,10 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13401
13401
|
}
|
|
13402
13402
|
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
13403
13403
|
}
|
|
13404
|
-
forIn(nameOrPrefix,
|
|
13405
|
-
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${
|
|
13404
|
+
forIn(nameOrPrefix, obj2, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
13405
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj2})`, forBody);
|
|
13406
13406
|
const name = this._scope.toName(nameOrPrefix);
|
|
13407
|
-
return this._for(new ForIter("in", varKind, name,
|
|
13407
|
+
return this._for(new ForIter("in", varKind, name, obj2), () => forBody(name));
|
|
13408
13408
|
}
|
|
13409
13409
|
endFor() {
|
|
13410
13410
|
return this._endBlockNode(For);
|
|
@@ -13510,7 +13510,7 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13510
13510
|
function addExprNames(names, from) {
|
|
13511
13511
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
13512
13512
|
}
|
|
13513
|
-
function optimizeExpr(expr, names,
|
|
13513
|
+
function optimizeExpr(expr, names, constants3) {
|
|
13514
13514
|
if (expr instanceof code_1.Name) return replaceName(expr);
|
|
13515
13515
|
if (!canOptimize(expr)) return expr;
|
|
13516
13516
|
return new code_1._Code(expr._items.reduce((items, c) => {
|
|
@@ -13520,13 +13520,13 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13520
13520
|
return items;
|
|
13521
13521
|
}, []));
|
|
13522
13522
|
function replaceName(n) {
|
|
13523
|
-
const c =
|
|
13523
|
+
const c = constants3[n.str];
|
|
13524
13524
|
if (c === void 0 || names[n.str] !== 1) return n;
|
|
13525
13525
|
delete names[n.str];
|
|
13526
13526
|
return c;
|
|
13527
13527
|
}
|
|
13528
13528
|
function canOptimize(e) {
|
|
13529
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
13529
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants3[c.str] !== void 0);
|
|
13530
13530
|
}
|
|
13531
13531
|
}
|
|
13532
13532
|
function subtractNames(names, from) {
|
|
@@ -13559,9 +13559,9 @@ var require_util = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13559
13559
|
const codegen_1 = require_codegen();
|
|
13560
13560
|
const code_1 = require_code$1();
|
|
13561
13561
|
function toHash(arr) {
|
|
13562
|
-
const
|
|
13563
|
-
for (const item of arr)
|
|
13564
|
-
return
|
|
13562
|
+
const hash3 = {};
|
|
13563
|
+
for (const item of arr) hash3[item] = true;
|
|
13564
|
+
return hash3;
|
|
13565
13565
|
}
|
|
13566
13566
|
exports.toHash = toHash;
|
|
13567
13567
|
function alwaysValidSchema(it, schema) {
|
|
@@ -14405,7 +14405,7 @@ var require_fast_deep_equal = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
14405
14405
|
if (a === b) return true;
|
|
14406
14406
|
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
14407
14407
|
if (a.constructor !== b.constructor) return false;
|
|
14408
|
-
var length, i,
|
|
14408
|
+
var length, i, keys2;
|
|
14409
14409
|
if (Array.isArray(a)) {
|
|
14410
14410
|
length = a.length;
|
|
14411
14411
|
if (length != b.length) return false;
|
|
@@ -14415,12 +14415,12 @@ var require_fast_deep_equal = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
14415
14415
|
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
14416
14416
|
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
14417
14417
|
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
14418
|
-
|
|
14419
|
-
length =
|
|
14418
|
+
keys2 = Object.keys(a);
|
|
14419
|
+
length = keys2.length;
|
|
14420
14420
|
if (length !== Object.keys(b).length) return false;
|
|
14421
|
-
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b,
|
|
14421
|
+
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys2[i])) return false;
|
|
14422
14422
|
for (i = length; i-- !== 0; ) {
|
|
14423
|
-
var key =
|
|
14423
|
+
var key = keys2[i];
|
|
14424
14424
|
if (!equal(a[key], b[key])) return false;
|
|
14425
14425
|
}
|
|
14426
14426
|
return true;
|
|
@@ -14932,9 +14932,9 @@ var require_validate = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14932
14932
|
ok(cond) {
|
|
14933
14933
|
if (!this.allErrors) this.gen.if(cond);
|
|
14934
14934
|
}
|
|
14935
|
-
setParams(
|
|
14936
|
-
if (assign) Object.assign(this.params,
|
|
14937
|
-
else this.params =
|
|
14935
|
+
setParams(obj2, assign) {
|
|
14936
|
+
if (assign) Object.assign(this.params, obj2);
|
|
14937
|
+
else this.params = obj2;
|
|
14938
14938
|
}
|
|
14939
14939
|
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
14940
14940
|
this.gen.block(() => {
|
|
@@ -15668,41 +15668,41 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15668
15668
|
schemelessOptions.skipEscape = true;
|
|
15669
15669
|
return serialize(resolved, schemelessOptions);
|
|
15670
15670
|
}
|
|
15671
|
-
function resolveComponent(base,
|
|
15671
|
+
function resolveComponent(base, relative2, options, skipNormalization) {
|
|
15672
15672
|
const target = {};
|
|
15673
15673
|
if (!skipNormalization) {
|
|
15674
15674
|
base = parse2(serialize(base, options), options);
|
|
15675
|
-
|
|
15675
|
+
relative2 = parse2(serialize(relative2, options), options);
|
|
15676
15676
|
}
|
|
15677
15677
|
options = options || {};
|
|
15678
|
-
if (!options.tolerant &&
|
|
15679
|
-
target.scheme =
|
|
15680
|
-
target.userinfo =
|
|
15681
|
-
target.host =
|
|
15682
|
-
target.port =
|
|
15683
|
-
target.path = removeDotSegments(
|
|
15684
|
-
target.query =
|
|
15678
|
+
if (!options.tolerant && relative2.scheme) {
|
|
15679
|
+
target.scheme = relative2.scheme;
|
|
15680
|
+
target.userinfo = relative2.userinfo;
|
|
15681
|
+
target.host = relative2.host;
|
|
15682
|
+
target.port = relative2.port;
|
|
15683
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
15684
|
+
target.query = relative2.query;
|
|
15685
15685
|
} else {
|
|
15686
|
-
if (
|
|
15687
|
-
target.userinfo =
|
|
15688
|
-
target.host =
|
|
15689
|
-
target.port =
|
|
15690
|
-
target.path = removeDotSegments(
|
|
15691
|
-
target.query =
|
|
15686
|
+
if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
|
|
15687
|
+
target.userinfo = relative2.userinfo;
|
|
15688
|
+
target.host = relative2.host;
|
|
15689
|
+
target.port = relative2.port;
|
|
15690
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
15691
|
+
target.query = relative2.query;
|
|
15692
15692
|
} else {
|
|
15693
|
-
if (!
|
|
15693
|
+
if (!relative2.path) {
|
|
15694
15694
|
target.path = base.path;
|
|
15695
|
-
if (
|
|
15695
|
+
if (relative2.query !== void 0) target.query = relative2.query;
|
|
15696
15696
|
else target.query = base.query;
|
|
15697
15697
|
} else {
|
|
15698
|
-
if (
|
|
15698
|
+
if (relative2.path[0] === "/") target.path = removeDotSegments(relative2.path);
|
|
15699
15699
|
else {
|
|
15700
|
-
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" +
|
|
15701
|
-
else if (!base.path) target.path =
|
|
15702
|
-
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
15700
|
+
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" + relative2.path;
|
|
15701
|
+
else if (!base.path) target.path = relative2.path;
|
|
15702
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
|
|
15703
15703
|
target.path = removeDotSegments(target.path);
|
|
15704
15704
|
}
|
|
15705
|
-
target.query =
|
|
15705
|
+
target.query = relative2.query;
|
|
15706
15706
|
}
|
|
15707
15707
|
target.userinfo = base.userinfo;
|
|
15708
15708
|
target.host = base.host;
|
|
@@ -15710,7 +15710,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15710
15710
|
}
|
|
15711
15711
|
target.scheme = base.scheme;
|
|
15712
15712
|
}
|
|
15713
|
-
target.fragment =
|
|
15713
|
+
target.fragment = relative2.fragment;
|
|
15714
15714
|
return target;
|
|
15715
15715
|
}
|
|
15716
15716
|
function equal(uriA, uriB, options) {
|
|
@@ -16234,7 +16234,7 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
16234
16234
|
}
|
|
16235
16235
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
16236
16236
|
if (!errors || errors.length === 0) return "No errors";
|
|
16237
|
-
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((
|
|
16237
|
+
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((text2, msg) => text2 + separator + msg);
|
|
16238
16238
|
}
|
|
16239
16239
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
16240
16240
|
const rules = this.RULES.all;
|
|
@@ -21501,11 +21501,11 @@ function normalizeReply(reply, timeoutMs) {
|
|
|
21501
21501
|
error: error2
|
|
21502
21502
|
};
|
|
21503
21503
|
if (error2 instanceof SdkHttpError) {
|
|
21504
|
-
const
|
|
21504
|
+
const text2 = error2.data?.text;
|
|
21505
21505
|
return {
|
|
21506
21506
|
kind: "http-error",
|
|
21507
21507
|
status: error2.data.status,
|
|
21508
|
-
body: typeof
|
|
21508
|
+
body: typeof text2 === "string" ? text2 : void 0,
|
|
21509
21509
|
statusText: error2.data.statusText
|
|
21510
21510
|
};
|
|
21511
21511
|
}
|
|
@@ -21643,12 +21643,12 @@ function serverInfoFromDiscover(discover) {
|
|
|
21643
21643
|
function applyElicitationDefaults(schema, data) {
|
|
21644
21644
|
if (!schema || data === null || typeof data !== "object") return;
|
|
21645
21645
|
if (schema.type === "object" && schema.properties && typeof schema.properties === "object") {
|
|
21646
|
-
const
|
|
21646
|
+
const obj2 = data;
|
|
21647
21647
|
const props = schema.properties;
|
|
21648
21648
|
for (const key of Object.keys(props)) {
|
|
21649
21649
|
const propSchema = props[key];
|
|
21650
|
-
if (
|
|
21651
|
-
if (
|
|
21650
|
+
if (obj2[key] === void 0 && Object.prototype.hasOwnProperty.call(propSchema, "default")) obj2[key] = propSchema.default;
|
|
21651
|
+
if (obj2[key] !== void 0) applyElicitationDefaults(propSchema, obj2[key]);
|
|
21652
21652
|
}
|
|
21653
21653
|
}
|
|
21654
21654
|
if (Array.isArray(schema.anyOf)) {
|
|
@@ -23259,8 +23259,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
23259
23259
|
}
|
|
23260
23260
|
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
23261
23261
|
_unfollowedRedirect(url2, response) {
|
|
23262
|
-
const
|
|
23263
|
-
return
|
|
23262
|
+
const text2 = this._redirectPolicy === "follow" ? void 0 : unfollowedRedirect(url2, response);
|
|
23263
|
+
return text2 && `${text2} (redirectPolicy: 'same-origin')`;
|
|
23264
23264
|
}
|
|
23265
23265
|
async _commonHeaders() {
|
|
23266
23266
|
const headers = new Headers(this._requestInit?.headers || void 0);
|
|
@@ -23351,13 +23351,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
23351
23351
|
if (response.status === 403) {
|
|
23352
23352
|
const { resourceMetadataUrl, scope, error: error2, errorDescription } = extractWWWAuthenticateParams(response);
|
|
23353
23353
|
if (error2 === "insufficient_scope") {
|
|
23354
|
-
const
|
|
23354
|
+
const text2 = await response.text?.().catch(() => null);
|
|
23355
23355
|
if (await this._stepUpAuthorize({
|
|
23356
23356
|
scope,
|
|
23357
23357
|
resourceMetadataUrl,
|
|
23358
23358
|
errorDescription,
|
|
23359
23359
|
statusText: response.statusText,
|
|
23360
|
-
text
|
|
23360
|
+
text: text2
|
|
23361
23361
|
}, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape(new UnauthorizedError());
|
|
23362
23362
|
return this._startOrAuthSse(options, isAuthRetry, stepUpRetries + 1);
|
|
23363
23363
|
}
|
|
@@ -23589,7 +23589,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
23589
23589
|
}));
|
|
23590
23590
|
throw markAuthSeamEscape(new UnauthorizedError());
|
|
23591
23591
|
}
|
|
23592
|
-
const
|
|
23592
|
+
const text2 = await response.text?.().catch(() => null);
|
|
23593
23593
|
if (response.status === 403) {
|
|
23594
23594
|
const { resourceMetadataUrl, scope, error: error2, errorDescription } = extractWWWAuthenticateParams(response);
|
|
23595
23595
|
if (error2 === "insufficient_scope") {
|
|
@@ -23598,13 +23598,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
23598
23598
|
resourceMetadataUrl,
|
|
23599
23599
|
errorDescription,
|
|
23600
23600
|
statusText: response.statusText,
|
|
23601
|
-
text
|
|
23601
|
+
text: text2
|
|
23602
23602
|
}, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape(new UnauthorizedError());
|
|
23603
23603
|
return this._send(message, options, isAuthRetry, stepUpRetries + 1);
|
|
23604
23604
|
}
|
|
23605
23605
|
}
|
|
23606
|
-
if (response.status === 400 && typeof
|
|
23607
|
-
const parsed = JSONRPCMessageSchema.parse(JSON.parse(
|
|
23606
|
+
if (response.status === 400 && typeof text2 === "string" && this._isModernEnvelopedRequest(message)) try {
|
|
23607
|
+
const parsed = JSONRPCMessageSchema.parse(JSON.parse(text2));
|
|
23608
23608
|
const requests = (Array.isArray(message) ? message : [message]).filter((m) => isJSONRPCRequest(m));
|
|
23609
23609
|
if (isJSONRPCErrorResponse(parsed) && requests.some((r) => r.id === parsed.id)) {
|
|
23610
23610
|
this.onmessage?.(parsed);
|
|
@@ -23612,11 +23612,11 @@ var StreamableHTTPClientTransport = class {
|
|
|
23612
23612
|
}
|
|
23613
23613
|
} catch {
|
|
23614
23614
|
}
|
|
23615
|
-
const reason = this._unfollowedRedirect(this._url, response) ??
|
|
23615
|
+
const reason = this._unfollowedRedirect(this._url, response) ?? text2;
|
|
23616
23616
|
throw new SdkHttpError(SdkErrorCode.ClientHttpNotImplemented, `Error POSTing to endpoint: ${reason}`, {
|
|
23617
23617
|
status: response.status,
|
|
23618
23618
|
statusText: response.statusText,
|
|
23619
|
-
text
|
|
23619
|
+
text: text2
|
|
23620
23620
|
});
|
|
23621
23621
|
}
|
|
23622
23622
|
if (response.status === 202) {
|
|
@@ -23730,8 +23730,8 @@ var __exportAll2 = (all, symbols) => {
|
|
|
23730
23730
|
};
|
|
23731
23731
|
var __copyProps2 = (to, from, except, desc) => {
|
|
23732
23732
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23733
|
-
for (var
|
|
23734
|
-
key =
|
|
23733
|
+
for (var keys2 = __getOwnPropNames2(from), i = 0, n = keys2.length, key; i < n; i++) {
|
|
23734
|
+
key = keys2[i];
|
|
23735
23735
|
if (!__hasOwnProp2.call(to, key) && key !== except) {
|
|
23736
23736
|
__defProp3(to, key, {
|
|
23737
23737
|
get: ((k) => from[k]).bind(null, key),
|
|
@@ -28130,7 +28130,7 @@ var require_content_type2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28130
28130
|
var index = header.indexOf(";");
|
|
28131
28131
|
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
28132
28132
|
if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type");
|
|
28133
|
-
var
|
|
28133
|
+
var obj2 = new ContentType(type.toLowerCase());
|
|
28134
28134
|
if (index !== -1) {
|
|
28135
28135
|
var key;
|
|
28136
28136
|
var match;
|
|
@@ -28145,16 +28145,16 @@ var require_content_type2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28145
28145
|
value = value.slice(1, -1);
|
|
28146
28146
|
if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1");
|
|
28147
28147
|
}
|
|
28148
|
-
|
|
28148
|
+
obj2.parameters[key] = value;
|
|
28149
28149
|
}
|
|
28150
28150
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
28151
28151
|
}
|
|
28152
|
-
return
|
|
28152
|
+
return obj2;
|
|
28153
28153
|
}
|
|
28154
|
-
function getcontenttype(
|
|
28154
|
+
function getcontenttype(obj2) {
|
|
28155
28155
|
var header;
|
|
28156
|
-
if (typeof
|
|
28157
|
-
else if (typeof
|
|
28156
|
+
if (typeof obj2.getHeader === "function") header = obj2.getHeader("content-type");
|
|
28157
|
+
else if (typeof obj2.headers === "object") header = obj2.headers && obj2.headers["content-type"];
|
|
28158
28158
|
if (typeof header !== "string") throw new TypeError("content-type header is missing from object");
|
|
28159
28159
|
return header;
|
|
28160
28160
|
}
|
|
@@ -28585,9 +28585,9 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28585
28585
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
28586
28586
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
28587
28587
|
}
|
|
28588
|
-
optimizeNames(names,
|
|
28588
|
+
optimizeNames(names, constants3) {
|
|
28589
28589
|
if (!names[this.name.str]) return;
|
|
28590
|
-
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names,
|
|
28590
|
+
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants3);
|
|
28591
28591
|
return this;
|
|
28592
28592
|
}
|
|
28593
28593
|
get names() {
|
|
@@ -28604,9 +28604,9 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28604
28604
|
render({ _n }) {
|
|
28605
28605
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
28606
28606
|
}
|
|
28607
|
-
optimizeNames(names,
|
|
28607
|
+
optimizeNames(names, constants3) {
|
|
28608
28608
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects) return;
|
|
28609
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
28609
|
+
this.rhs = optimizeExpr(this.rhs, names, constants3);
|
|
28610
28610
|
return this;
|
|
28611
28611
|
}
|
|
28612
28612
|
get names() {
|
|
@@ -28665,8 +28665,8 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28665
28665
|
optimizeNodes() {
|
|
28666
28666
|
return `${this.code}` ? this : void 0;
|
|
28667
28667
|
}
|
|
28668
|
-
optimizeNames(names,
|
|
28669
|
-
this.code = optimizeExpr(this.code, names,
|
|
28668
|
+
optimizeNames(names, constants3) {
|
|
28669
|
+
this.code = optimizeExpr(this.code, names, constants3);
|
|
28670
28670
|
return this;
|
|
28671
28671
|
}
|
|
28672
28672
|
get names() {
|
|
@@ -28692,12 +28692,12 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28692
28692
|
}
|
|
28693
28693
|
return nodes.length > 0 ? this : void 0;
|
|
28694
28694
|
}
|
|
28695
|
-
optimizeNames(names,
|
|
28695
|
+
optimizeNames(names, constants3) {
|
|
28696
28696
|
const { nodes } = this;
|
|
28697
28697
|
let i = nodes.length;
|
|
28698
28698
|
while (i--) {
|
|
28699
28699
|
const n = nodes[i];
|
|
28700
|
-
if (n.optimizeNames(names,
|
|
28700
|
+
if (n.optimizeNames(names, constants3)) continue;
|
|
28701
28701
|
subtractNames(names, n.names);
|
|
28702
28702
|
nodes.splice(i, 1);
|
|
28703
28703
|
}
|
|
@@ -28744,11 +28744,11 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28744
28744
|
if (cond === false || !this.nodes.length) return void 0;
|
|
28745
28745
|
return this;
|
|
28746
28746
|
}
|
|
28747
|
-
optimizeNames(names,
|
|
28747
|
+
optimizeNames(names, constants3) {
|
|
28748
28748
|
var _a3;
|
|
28749
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
28750
|
-
if (!(super.optimizeNames(names,
|
|
28751
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
28749
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants3);
|
|
28750
|
+
if (!(super.optimizeNames(names, constants3) || this.else)) return;
|
|
28751
|
+
this.condition = optimizeExpr(this.condition, names, constants3);
|
|
28752
28752
|
return this;
|
|
28753
28753
|
}
|
|
28754
28754
|
get names() {
|
|
@@ -28770,9 +28770,9 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28770
28770
|
render(opts) {
|
|
28771
28771
|
return `for(${this.iteration})` + super.render(opts);
|
|
28772
28772
|
}
|
|
28773
|
-
optimizeNames(names,
|
|
28774
|
-
if (!super.optimizeNames(names,
|
|
28775
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
28773
|
+
optimizeNames(names, constants3) {
|
|
28774
|
+
if (!super.optimizeNames(names, constants3)) return;
|
|
28775
|
+
this.iteration = optimizeExpr(this.iteration, names, constants3);
|
|
28776
28776
|
return this;
|
|
28777
28777
|
}
|
|
28778
28778
|
get names() {
|
|
@@ -28807,9 +28807,9 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28807
28807
|
render(opts) {
|
|
28808
28808
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
28809
28809
|
}
|
|
28810
|
-
optimizeNames(names,
|
|
28811
|
-
if (!super.optimizeNames(names,
|
|
28812
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
28810
|
+
optimizeNames(names, constants3) {
|
|
28811
|
+
if (!super.optimizeNames(names, constants3)) return;
|
|
28812
|
+
this.iterable = optimizeExpr(this.iterable, names, constants3);
|
|
28813
28813
|
return this;
|
|
28814
28814
|
}
|
|
28815
28815
|
get names() {
|
|
@@ -28848,11 +28848,11 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28848
28848
|
(_b = this.finally) === null || _b === void 0 || _b.optimizeNodes();
|
|
28849
28849
|
return this;
|
|
28850
28850
|
}
|
|
28851
|
-
optimizeNames(names,
|
|
28851
|
+
optimizeNames(names, constants3) {
|
|
28852
28852
|
var _a3, _b;
|
|
28853
|
-
super.optimizeNames(names,
|
|
28854
|
-
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names,
|
|
28855
|
-
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names,
|
|
28853
|
+
super.optimizeNames(names, constants3);
|
|
28854
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants3);
|
|
28855
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants3);
|
|
28856
28856
|
return this;
|
|
28857
28857
|
}
|
|
28858
28858
|
get names() {
|
|
@@ -28992,10 +28992,10 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28992
28992
|
}
|
|
28993
28993
|
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
28994
28994
|
}
|
|
28995
|
-
forIn(nameOrPrefix,
|
|
28996
|
-
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${
|
|
28995
|
+
forIn(nameOrPrefix, obj2, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
28996
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj2})`, forBody);
|
|
28997
28997
|
const name = this._scope.toName(nameOrPrefix);
|
|
28998
|
-
return this._for(new ForIter("in", varKind, name,
|
|
28998
|
+
return this._for(new ForIter("in", varKind, name, obj2), () => forBody(name));
|
|
28999
28999
|
}
|
|
29000
29000
|
endFor() {
|
|
29001
29001
|
return this._endBlockNode(For);
|
|
@@ -29101,7 +29101,7 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
29101
29101
|
function addExprNames(names, from) {
|
|
29102
29102
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
29103
29103
|
}
|
|
29104
|
-
function optimizeExpr(expr, names,
|
|
29104
|
+
function optimizeExpr(expr, names, constants3) {
|
|
29105
29105
|
if (expr instanceof code_1.Name) return replaceName(expr);
|
|
29106
29106
|
if (!canOptimize(expr)) return expr;
|
|
29107
29107
|
return new code_1._Code(expr._items.reduce((items, c) => {
|
|
@@ -29111,13 +29111,13 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
29111
29111
|
return items;
|
|
29112
29112
|
}, []));
|
|
29113
29113
|
function replaceName(n) {
|
|
29114
|
-
const c =
|
|
29114
|
+
const c = constants3[n.str];
|
|
29115
29115
|
if (c === void 0 || names[n.str] !== 1) return n;
|
|
29116
29116
|
delete names[n.str];
|
|
29117
29117
|
return c;
|
|
29118
29118
|
}
|
|
29119
29119
|
function canOptimize(e) {
|
|
29120
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
29120
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants3[c.str] !== void 0);
|
|
29121
29121
|
}
|
|
29122
29122
|
}
|
|
29123
29123
|
function subtractNames(names, from) {
|
|
@@ -29150,9 +29150,9 @@ var require_util2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
29150
29150
|
const codegen_1 = require_codegen2();
|
|
29151
29151
|
const code_1 = require_code$12();
|
|
29152
29152
|
function toHash(arr) {
|
|
29153
|
-
const
|
|
29154
|
-
for (const item of arr)
|
|
29155
|
-
return
|
|
29153
|
+
const hash3 = {};
|
|
29154
|
+
for (const item of arr) hash3[item] = true;
|
|
29155
|
+
return hash3;
|
|
29156
29156
|
}
|
|
29157
29157
|
exports.toHash = toHash;
|
|
29158
29158
|
function alwaysValidSchema(it, schema) {
|
|
@@ -29996,7 +29996,7 @@ var require_fast_deep_equal2 = /* @__PURE__ */ __commonJSMin2(((exports, module)
|
|
|
29996
29996
|
if (a === b) return true;
|
|
29997
29997
|
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
29998
29998
|
if (a.constructor !== b.constructor) return false;
|
|
29999
|
-
var length, i,
|
|
29999
|
+
var length, i, keys2;
|
|
30000
30000
|
if (Array.isArray(a)) {
|
|
30001
30001
|
length = a.length;
|
|
30002
30002
|
if (length != b.length) return false;
|
|
@@ -30006,12 +30006,12 @@ var require_fast_deep_equal2 = /* @__PURE__ */ __commonJSMin2(((exports, module)
|
|
|
30006
30006
|
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
30007
30007
|
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
30008
30008
|
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
30009
|
-
|
|
30010
|
-
length =
|
|
30009
|
+
keys2 = Object.keys(a);
|
|
30010
|
+
length = keys2.length;
|
|
30011
30011
|
if (length !== Object.keys(b).length) return false;
|
|
30012
|
-
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b,
|
|
30012
|
+
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys2[i])) return false;
|
|
30013
30013
|
for (i = length; i-- !== 0; ) {
|
|
30014
|
-
var key =
|
|
30014
|
+
var key = keys2[i];
|
|
30015
30015
|
if (!equal(a[key], b[key])) return false;
|
|
30016
30016
|
}
|
|
30017
30017
|
return true;
|
|
@@ -30523,9 +30523,9 @@ var require_validate2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
30523
30523
|
ok(cond) {
|
|
30524
30524
|
if (!this.allErrors) this.gen.if(cond);
|
|
30525
30525
|
}
|
|
30526
|
-
setParams(
|
|
30527
|
-
if (assign) Object.assign(this.params,
|
|
30528
|
-
else this.params =
|
|
30526
|
+
setParams(obj2, assign) {
|
|
30527
|
+
if (assign) Object.assign(this.params, obj2);
|
|
30528
|
+
else this.params = obj2;
|
|
30529
30529
|
}
|
|
30530
30530
|
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
30531
30531
|
this.gen.block(() => {
|
|
@@ -31259,41 +31259,41 @@ var require_fast_uri2 = /* @__PURE__ */ __commonJSMin2(((exports, module) => {
|
|
|
31259
31259
|
schemelessOptions.skipEscape = true;
|
|
31260
31260
|
return serialize(resolved, schemelessOptions);
|
|
31261
31261
|
}
|
|
31262
|
-
function resolveComponent(base,
|
|
31262
|
+
function resolveComponent(base, relative2, options, skipNormalization) {
|
|
31263
31263
|
const target = {};
|
|
31264
31264
|
if (!skipNormalization) {
|
|
31265
31265
|
base = parse2(serialize(base, options), options);
|
|
31266
|
-
|
|
31266
|
+
relative2 = parse2(serialize(relative2, options), options);
|
|
31267
31267
|
}
|
|
31268
31268
|
options = options || {};
|
|
31269
|
-
if (!options.tolerant &&
|
|
31270
|
-
target.scheme =
|
|
31271
|
-
target.userinfo =
|
|
31272
|
-
target.host =
|
|
31273
|
-
target.port =
|
|
31274
|
-
target.path = removeDotSegments(
|
|
31275
|
-
target.query =
|
|
31269
|
+
if (!options.tolerant && relative2.scheme) {
|
|
31270
|
+
target.scheme = relative2.scheme;
|
|
31271
|
+
target.userinfo = relative2.userinfo;
|
|
31272
|
+
target.host = relative2.host;
|
|
31273
|
+
target.port = relative2.port;
|
|
31274
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
31275
|
+
target.query = relative2.query;
|
|
31276
31276
|
} else {
|
|
31277
|
-
if (
|
|
31278
|
-
target.userinfo =
|
|
31279
|
-
target.host =
|
|
31280
|
-
target.port =
|
|
31281
|
-
target.path = removeDotSegments(
|
|
31282
|
-
target.query =
|
|
31277
|
+
if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
|
|
31278
|
+
target.userinfo = relative2.userinfo;
|
|
31279
|
+
target.host = relative2.host;
|
|
31280
|
+
target.port = relative2.port;
|
|
31281
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
31282
|
+
target.query = relative2.query;
|
|
31283
31283
|
} else {
|
|
31284
|
-
if (!
|
|
31284
|
+
if (!relative2.path) {
|
|
31285
31285
|
target.path = base.path;
|
|
31286
|
-
if (
|
|
31286
|
+
if (relative2.query !== void 0) target.query = relative2.query;
|
|
31287
31287
|
else target.query = base.query;
|
|
31288
31288
|
} else {
|
|
31289
|
-
if (
|
|
31289
|
+
if (relative2.path[0] === "/") target.path = removeDotSegments(relative2.path);
|
|
31290
31290
|
else {
|
|
31291
|
-
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" +
|
|
31292
|
-
else if (!base.path) target.path =
|
|
31293
|
-
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
31291
|
+
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" + relative2.path;
|
|
31292
|
+
else if (!base.path) target.path = relative2.path;
|
|
31293
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
|
|
31294
31294
|
target.path = removeDotSegments(target.path);
|
|
31295
31295
|
}
|
|
31296
|
-
target.query =
|
|
31296
|
+
target.query = relative2.query;
|
|
31297
31297
|
}
|
|
31298
31298
|
target.userinfo = base.userinfo;
|
|
31299
31299
|
target.host = base.host;
|
|
@@ -31301,7 +31301,7 @@ var require_fast_uri2 = /* @__PURE__ */ __commonJSMin2(((exports, module) => {
|
|
|
31301
31301
|
}
|
|
31302
31302
|
target.scheme = base.scheme;
|
|
31303
31303
|
}
|
|
31304
|
-
target.fragment =
|
|
31304
|
+
target.fragment = relative2.fragment;
|
|
31305
31305
|
return target;
|
|
31306
31306
|
}
|
|
31307
31307
|
function equal(uriA, uriB, options) {
|
|
@@ -31825,7 +31825,7 @@ var require_core$32 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
31825
31825
|
}
|
|
31826
31826
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
31827
31827
|
if (!errors || errors.length === 0) return "No errors";
|
|
31828
|
-
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((
|
|
31828
|
+
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((text2, msg) => text2 + separator + msg);
|
|
31829
31829
|
}
|
|
31830
31830
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
31831
31831
|
const rules = this.RULES.all;
|
|
@@ -36132,17 +36132,439 @@ if (process.argv[1] && process.argv[2] === "--headers" && import.meta.url === pa
|
|
|
36132
36132
|
|
|
36133
36133
|
// src/bridge.mjs
|
|
36134
36134
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
36135
|
-
import { resolve as resolve2, dirname as
|
|
36135
|
+
import { resolve as resolve2, dirname as dirname3 } from "node:path";
|
|
36136
36136
|
|
|
36137
|
-
//
|
|
36137
|
+
// src/effect-automatic.mjs
|
|
36138
|
+
import { readdir as readdir2 } from "node:fs/promises";
|
|
36139
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
36140
|
+
import { join as join2 } from "node:path";
|
|
36141
|
+
|
|
36142
|
+
// src/effect-storage.mjs
|
|
36143
|
+
import { open as open2, mkdir, lstat as lstat2, readdir, readFile as readFile2, rename, rm, realpath } from "node:fs/promises";
|
|
36138
36144
|
import { constants } from "node:fs";
|
|
36139
|
-
import {
|
|
36145
|
+
import { dirname, basename, join, isAbsolute, relative } from "node:path";
|
|
36146
|
+
import { randomUUID } from "node:crypto";
|
|
36147
|
+
|
|
36148
|
+
// src/effect-core.mjs
|
|
36149
|
+
import { createHash } from "node:crypto";
|
|
36150
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
36151
|
+
var sha256 = (value) => createHash("sha256").update(value).digest("hex");
|
|
36152
|
+
function canonical(value) {
|
|
36153
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
36154
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
36155
|
+
return JSON.stringify(value);
|
|
36156
|
+
}
|
|
36157
|
+
var hash = (value) => sha256(canonical(value));
|
|
36158
|
+
var EffectError = class extends Error {
|
|
36159
|
+
constructor(code, message = code, uncertain = false) {
|
|
36160
|
+
super(message);
|
|
36161
|
+
this.code = code;
|
|
36162
|
+
this.uncertain = uncertain;
|
|
36163
|
+
}
|
|
36164
|
+
};
|
|
36165
|
+
var obj = (v) => v && typeof v === "object" && !Array.isArray(v);
|
|
36166
|
+
var text = (v, max) => typeof v === "string" && v.trim().length > 0 && v.length <= max;
|
|
36167
|
+
var keys = (v, expected) => obj(v) && Object.keys(v).length === expected.length && expected.every((k) => k in v);
|
|
36168
|
+
function validateBrief(v) {
|
|
36169
|
+
if (!keys(v, ["taskId", "question", "knownContext", "criteria"]) || !UUID.test(v.taskId) || !text(v.question, 2e3) || typeof v.knownContext !== "string" || v.knownContext.length > 4e3 || !Array.isArray(v.criteria) || v.criteria.length < 1 || v.criteria.length > 10 || new Set(v.criteria.map((c) => c.id)).size !== v.criteria.length || !v.criteria.every((c) => keys(c, ["id", "description"]) && text(c.id, 80) && text(c.description, 1e3))) throw new EffectError("invalid_brief");
|
|
36170
|
+
}
|
|
36171
|
+
|
|
36172
|
+
// src/effect-storage.mjs
|
|
36173
|
+
async function privateDir(path) {
|
|
36174
|
+
let current = path;
|
|
36175
|
+
while (dirname(current) !== current) {
|
|
36176
|
+
const st2 = await lstat2(current).catch((e) => {
|
|
36177
|
+
if (e.code !== "ENOENT") throw e;
|
|
36178
|
+
return null;
|
|
36179
|
+
});
|
|
36180
|
+
if (st2 && (!st2.isDirectory() || st2.isSymbolicLink())) throw new EffectError("unsafe_storage");
|
|
36181
|
+
current = dirname(current);
|
|
36182
|
+
}
|
|
36183
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
36184
|
+
const st = await lstat2(path);
|
|
36185
|
+
if (st.mode & 63 || typeof process.getuid === "function" && st.uid !== process.getuid()) throw new EffectError("unsafe_storage");
|
|
36186
|
+
}
|
|
36187
|
+
async function readJson(path) {
|
|
36188
|
+
const f = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
36189
|
+
try {
|
|
36190
|
+
const st = await f.stat();
|
|
36191
|
+
if (!st.isFile() || st.nlink !== 1 || st.mode & 63) throw new EffectError("unsafe_storage");
|
|
36192
|
+
return JSON.parse(await f.readFile("utf8"));
|
|
36193
|
+
} finally {
|
|
36194
|
+
await f.close();
|
|
36195
|
+
}
|
|
36196
|
+
}
|
|
36197
|
+
async function writeJson(path, value, exclusive = false) {
|
|
36198
|
+
const temporary = exclusive ? path : `${path}.${randomUUID()}.tmp`;
|
|
36199
|
+
const f = await open2(temporary, "wx", 384);
|
|
36200
|
+
try {
|
|
36201
|
+
await f.writeFile(JSON.stringify(value));
|
|
36202
|
+
await f.sync();
|
|
36203
|
+
} finally {
|
|
36204
|
+
await f.close();
|
|
36205
|
+
}
|
|
36206
|
+
if (!exclusive) await rename(temporary, path);
|
|
36207
|
+
const dir = await open2(dirname(path), "r");
|
|
36208
|
+
try {
|
|
36209
|
+
await dir.sync();
|
|
36210
|
+
} finally {
|
|
36211
|
+
await dir.close();
|
|
36212
|
+
}
|
|
36213
|
+
}
|
|
36214
|
+
function stripRaw(state) {
|
|
36215
|
+
const value = { ...state, rawExpired: true };
|
|
36216
|
+
delete value.brief;
|
|
36217
|
+
delete value.prepareInput;
|
|
36218
|
+
delete value.snapshot;
|
|
36219
|
+
if (value.reservation) {
|
|
36220
|
+
value.reservation = { ...value.reservation };
|
|
36221
|
+
delete value.reservation.deliveredContext;
|
|
36222
|
+
}
|
|
36223
|
+
return value;
|
|
36224
|
+
}
|
|
36225
|
+
async function withStateLock(path, operation) {
|
|
36226
|
+
const lock = `${path}.write-lock`;
|
|
36227
|
+
let handle;
|
|
36228
|
+
for (let attempt = 0; !handle && attempt < 500; attempt++) {
|
|
36229
|
+
try {
|
|
36230
|
+
handle = await open2(lock, "wx", 384);
|
|
36231
|
+
await handle.writeFile(String(process.pid));
|
|
36232
|
+
} catch (error2) {
|
|
36233
|
+
if (error2.code !== "EEXIST") throw error2;
|
|
36234
|
+
const owner = await readFile2(lock, "utf8").catch(() => "");
|
|
36235
|
+
let dead = false;
|
|
36236
|
+
if (/^\d+$/.test(owner)) {
|
|
36237
|
+
try {
|
|
36238
|
+
process.kill(Number(owner), 0);
|
|
36239
|
+
} catch (e) {
|
|
36240
|
+
dead = e.code === "ESRCH";
|
|
36241
|
+
}
|
|
36242
|
+
} else {
|
|
36243
|
+
const st = await lstat2(lock).catch(() => null);
|
|
36244
|
+
dead = !!st && Date.now() - st.mtimeMs > 1e4;
|
|
36245
|
+
}
|
|
36246
|
+
if (dead) await rm(lock, { force: true });
|
|
36247
|
+
else await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
36248
|
+
}
|
|
36249
|
+
}
|
|
36250
|
+
if (!handle) throw new EffectError("journal_busy");
|
|
36251
|
+
try {
|
|
36252
|
+
return await operation();
|
|
36253
|
+
} finally {
|
|
36254
|
+
await handle.close();
|
|
36255
|
+
await rm(lock, { force: true });
|
|
36256
|
+
}
|
|
36257
|
+
}
|
|
36258
|
+
async function saveJson(path, value, exclusive = false) {
|
|
36259
|
+
if (basename(path) !== "state.json") return writeJson(path, value, exclusive);
|
|
36260
|
+
return withStateLock(path, async () => {
|
|
36261
|
+
const previous = await readJson(path).catch((e) => {
|
|
36262
|
+
if (e.code !== "ENOENT") throw e;
|
|
36263
|
+
return null;
|
|
36264
|
+
});
|
|
36265
|
+
const expired = previous?.rawExpired || value.rawExpired || Date.parse(value.expiresAt) <= Date.now();
|
|
36266
|
+
await writeJson(path, expired ? stripRaw(value) : value, exclusive);
|
|
36267
|
+
});
|
|
36268
|
+
}
|
|
36269
|
+
|
|
36270
|
+
// src/effect-automatic.mjs
|
|
36271
|
+
var effectReads = /* @__PURE__ */ new Set(["get_project_context", "search_docs", "explore_docs", "get_doc", "get_docs"]);
|
|
36272
|
+
var reasons = /* @__PURE__ */ new Set(["consent_required", "missing_preparation", "late_preparation", "working_model_unavailable", "unsupported_runner", "runner_not_configured", "isolation_unavailable", "connection_unavailable", "permission_denied", "snapshot_unavailable", "context_unavailable", "budget_admission_denied", "concurrency_limit", "daily_run_limit", "not_sampled", "disabled", "no_beneficial_retrieval", "expired_preparation", "duplicate_task", "report_pending", "local_failure", "incomplete_evaluation"]);
|
|
36273
|
+
var safeReason = (e) => reasons.has(e?.reason ?? e?.code?.toLowerCase()) ? e.reason ?? e.code.toLowerCase() : ["EACCES", "EPERM"].includes(e?.code) ? "permission_denied" : "local_failure";
|
|
36274
|
+
var dataOf = (r) => r?.structuredContent ?? (() => {
|
|
36275
|
+
try {
|
|
36276
|
+
return JSON.parse(r?.content?.find((c) => c.type === "text")?.text);
|
|
36277
|
+
} catch {
|
|
36278
|
+
return null;
|
|
36279
|
+
}
|
|
36280
|
+
})();
|
|
36281
|
+
function retrievalIds(value, found = /* @__PURE__ */ new Set()) {
|
|
36282
|
+
if (!value || typeof value !== "object") return found;
|
|
36283
|
+
if (Array.isArray(value.retrievals)) {
|
|
36284
|
+
for (const r of value.retrievals) if (UUID.test(r?.retrievalId)) found.add(r.retrievalId);
|
|
36285
|
+
}
|
|
36286
|
+
for (const [key, child] of Object.entries(value)) if (key !== "retrievals" && child && typeof child === "object") retrievalIds(child, found);
|
|
36287
|
+
return found;
|
|
36288
|
+
}
|
|
36289
|
+
function automaticTool(tool) {
|
|
36290
|
+
if (!effectReads.has(tool.name) && tool.name !== "report_retrieval_evaluation") return tool;
|
|
36291
|
+
const properties = { ...tool.inputSchema.properties };
|
|
36292
|
+
if (effectReads.has(tool.name)) properties.effectTask = {
|
|
36293
|
+
type: "object",
|
|
36294
|
+
additionalProperties: false,
|
|
36295
|
+
description: "Local automatic measurement. First read: pre-exposure brief and current trusted host identity; following reads: same taskId only. Never reconstruct a brief after exposure. Source allowlist and consent come from installation, not this call.",
|
|
36296
|
+
required: ["taskId"],
|
|
36297
|
+
properties: {
|
|
36298
|
+
taskId: { type: "string", format: "uuid" },
|
|
36299
|
+
question: { type: "string", minLength: 1, maxLength: 2e3 },
|
|
36300
|
+
knownContext: { type: "string", maxLength: 4e3 },
|
|
36301
|
+
criteria: { type: "array", minItems: 1, maxItems: 10, items: { type: "object", additionalProperties: false, required: ["id", "description"], properties: { id: { type: "string", maxLength: 80 }, description: { type: "string", maxLength: 500 } } } },
|
|
36302
|
+
host: { type: "object", additionalProperties: false, required: ["client", "sessionId"], properties: { client: { type: "string", enum: ["codex", "claude_code"] }, sessionId: { type: "string", format: "uuid" }, transcriptPath: { type: "string" } } }
|
|
36303
|
+
}
|
|
36304
|
+
};
|
|
36305
|
+
else {
|
|
36306
|
+
properties.effectTaskId = { type: "string", format: "uuid", description: "Same automatic information task identity." };
|
|
36307
|
+
properties.effectTaskComplete = { type: "boolean", description: "True only on the final evaluation after ALL information reads and evaluations for this question. The installer starts at most one comparison automatically, after saved consent. Do not issue measure run." };
|
|
36308
|
+
}
|
|
36309
|
+
return {
|
|
36310
|
+
...tool,
|
|
36311
|
+
description: tool.description + " Installed automatic measurement accepts local task metadata; no shell prepare/run is needed.",
|
|
36312
|
+
inputSchema: { ...tool.inputSchema, properties },
|
|
36313
|
+
annotations: { ...tool.annotations, readOnlyHint: false, openWorldHint: true }
|
|
36314
|
+
};
|
|
36315
|
+
}
|
|
36316
|
+
var AutomaticMeasurement = class {
|
|
36317
|
+
constructor({ projectId, remote, factory, store, warn = () => {
|
|
36318
|
+
} }) {
|
|
36319
|
+
Object.assign(this, { projectId, remote, factory, store, warn });
|
|
36320
|
+
this.queue = Promise.resolve();
|
|
36321
|
+
this.jobs = /* @__PURE__ */ new Set();
|
|
36322
|
+
}
|
|
36323
|
+
call(params) {
|
|
36324
|
+
const next = this.queue.then(() => this.handle(params));
|
|
36325
|
+
this.queue = next.catch(() => {
|
|
36326
|
+
});
|
|
36327
|
+
return next;
|
|
36328
|
+
}
|
|
36329
|
+
async recover() {
|
|
36330
|
+
for (const state of await this.store.list?.() ?? []) {
|
|
36331
|
+
if (state.diagnostic) {
|
|
36332
|
+
try {
|
|
36333
|
+
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36334
|
+
state.diagnostic = null;
|
|
36335
|
+
await this.store.save(state);
|
|
36336
|
+
} catch {
|
|
36337
|
+
this.warn("Foundocs measurement status is pending; no inference was repeated.");
|
|
36338
|
+
}
|
|
36339
|
+
}
|
|
36340
|
+
if (!state.closed || state.settled || !state.preparationId) continue;
|
|
36341
|
+
try {
|
|
36342
|
+
const { coordinator } = await this.factory({ recovery: true });
|
|
36343
|
+
const result = await coordinator.flush(state.taskId);
|
|
36344
|
+
if (result.reason === "coordinator_active") continue;
|
|
36345
|
+
if (result.status === "report_pending") {
|
|
36346
|
+
await this.diagnostic(state, "failed", "report_pending");
|
|
36347
|
+
continue;
|
|
36348
|
+
}
|
|
36349
|
+
state.settled = true;
|
|
36350
|
+
if (["reported", "already_reported"].includes(result.status)) {
|
|
36351
|
+
const failed = result.result && result.result.status !== "completed";
|
|
36352
|
+
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36353
|
+
} else await this.diagnostic(state, "failed", result.status === "nothing_pending" ? "local_failure" : safeReason(result));
|
|
36354
|
+
} catch {
|
|
36355
|
+
this.warn("Foundocs measurement recovery pending; no inference was repeated.");
|
|
36356
|
+
}
|
|
36357
|
+
}
|
|
36358
|
+
}
|
|
36359
|
+
async diagnostic(state, status, reason = null) {
|
|
36360
|
+
state.sequence = (state.sequence ?? 0) + 1;
|
|
36361
|
+
state.diagnostic = { requestId: randomUUID2(), taskId: state.taskId, sequence: state.sequence, status, reason };
|
|
36362
|
+
try {
|
|
36363
|
+
await this.store.save(state);
|
|
36364
|
+
} catch {
|
|
36365
|
+
this.warn("Foundocs measurement status could not be saved locally.");
|
|
36366
|
+
}
|
|
36367
|
+
try {
|
|
36368
|
+
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36369
|
+
state.diagnostic = null;
|
|
36370
|
+
await this.store.save(state);
|
|
36371
|
+
} catch {
|
|
36372
|
+
this.warn("Foundocs measurement status could not be delivered; local status retained.");
|
|
36373
|
+
}
|
|
36374
|
+
}
|
|
36375
|
+
async handle(params) {
|
|
36376
|
+
const { effectTask, effectTaskId, effectTaskComplete, ...args } = params.arguments ?? {};
|
|
36377
|
+
const forward = () => this.remote(params.name, args, true);
|
|
36378
|
+
if (args.project_id !== this.projectId) {
|
|
36379
|
+
if (effectTask || effectTaskId || effectTaskComplete) throw new Error("Automatic measurement project mismatch");
|
|
36380
|
+
return forward();
|
|
36381
|
+
}
|
|
36382
|
+
if (effectReads.has(params.name)) {
|
|
36383
|
+
if (!effectTask) return forward();
|
|
36384
|
+
const taskId = effectTask?.taskId ?? (UUID.test(args.taskId ?? "") ? args.taskId : UUID.test(args.readId ?? "") ? args.readId : randomUUID2());
|
|
36385
|
+
if (!UUID.test(taskId) || args.taskId && args.taskId !== taskId || effectTask && args.effectPreparationId) throw new Error("Conflicting measurement task");
|
|
36386
|
+
let state2;
|
|
36387
|
+
try {
|
|
36388
|
+
state2 = await this.store.load(taskId);
|
|
36389
|
+
} catch (e) {
|
|
36390
|
+
args.taskId = taskId;
|
|
36391
|
+
try {
|
|
36392
|
+
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36393
|
+
} catch {
|
|
36394
|
+
this.warn("Foundocs measurement storage unavailable.");
|
|
36395
|
+
}
|
|
36396
|
+
return forward();
|
|
36397
|
+
}
|
|
36398
|
+
if (!state2) {
|
|
36399
|
+
state2 = { taskId, retrievals: [], evaluated: [], exposed: false, closed: false, expiresAt: new Date(Date.now() + 864e5).toISOString() };
|
|
36400
|
+
try {
|
|
36401
|
+
await this.store.save(state2);
|
|
36402
|
+
} catch (e) {
|
|
36403
|
+
args.taskId = taskId;
|
|
36404
|
+
try {
|
|
36405
|
+
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36406
|
+
} catch {
|
|
36407
|
+
this.warn("Foundocs measurement storage unavailable.");
|
|
36408
|
+
}
|
|
36409
|
+
return forward();
|
|
36410
|
+
}
|
|
36411
|
+
try {
|
|
36412
|
+
const policy = await this.remote("get_effect_measurement_policy", {});
|
|
36413
|
+
if (!policy.enabled) state2.skipped = "disabled";
|
|
36414
|
+
else if (!effectTask?.question || !effectTask?.criteria) state2.skipped = "missing_preparation";
|
|
36415
|
+
else {
|
|
36416
|
+
const brief = { taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria };
|
|
36417
|
+
validateBrief(brief);
|
|
36418
|
+
state2.briefHash = hash(brief);
|
|
36419
|
+
const { coordinator, config: config2 } = await this.factory();
|
|
36420
|
+
if (!config2?.enabled) state2.skipped = "consent_required";
|
|
36421
|
+
else {
|
|
36422
|
+
const result3 = await coordinator.prepare({ policy, brief, allowlist: config2.allowlist, excludePaths: config2.excludePaths, host: effectTask.host });
|
|
36423
|
+
if (result3.status === "prepared") {
|
|
36424
|
+
state2.preparationId = result3.effectPreparationId;
|
|
36425
|
+
state2.consentHash = hash(config2);
|
|
36426
|
+
} else state2.skipped = safeReason(result3);
|
|
36427
|
+
}
|
|
36428
|
+
}
|
|
36429
|
+
} catch (e) {
|
|
36430
|
+
state2.skipped = safeReason(e);
|
|
36431
|
+
}
|
|
36432
|
+
await this.diagnostic(state2, state2.preparationId ? "prepared" : "skipped", state2.preparationId ? null : state2.skipped);
|
|
36433
|
+
} else if (effectTask?.question && state2.briefHash !== hash({ taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria })) {
|
|
36434
|
+
throw new Error("Do not change a frozen information task");
|
|
36435
|
+
}
|
|
36436
|
+
if (!state2.preparationId && !state2.skipped) state2.skipped = "missing_preparation";
|
|
36437
|
+
if (state2.closed && effectTask) throw new Error("Information task is closed; never add later context or relabel the same question.");
|
|
36438
|
+
if (state2.closed || Date.parse(state2.expiresAt) <= Date.now()) {
|
|
36439
|
+
delete args.effectPreparationId;
|
|
36440
|
+
args.taskId = taskId;
|
|
36441
|
+
return forward();
|
|
36442
|
+
}
|
|
36443
|
+
args.taskId = taskId;
|
|
36444
|
+
if (state2.preparationId) args.effectPreparationId = state2.preparationId;
|
|
36445
|
+
state2.exposed = true;
|
|
36446
|
+
try {
|
|
36447
|
+
await this.store.save(state2);
|
|
36448
|
+
} catch (e) {
|
|
36449
|
+
delete args.effectPreparationId;
|
|
36450
|
+
await this.diagnostic(state2, "skipped", safeReason(e));
|
|
36451
|
+
return forward();
|
|
36452
|
+
}
|
|
36453
|
+
const result2 = await forward(), body = dataOf(result2);
|
|
36454
|
+
if (body?.ok) {
|
|
36455
|
+
state2.retrievals = [.../* @__PURE__ */ new Set([...state2.retrievals, ...retrievalIds(body.data)])];
|
|
36456
|
+
try {
|
|
36457
|
+
await this.store.save(state2);
|
|
36458
|
+
} catch {
|
|
36459
|
+
this.warn("Foundocs retrieval tracking could not be saved; no extra reads were requested.");
|
|
36460
|
+
}
|
|
36461
|
+
}
|
|
36462
|
+
return result2;
|
|
36463
|
+
}
|
|
36464
|
+
const result = await forward();
|
|
36465
|
+
if (params.name !== "report_retrieval_evaluation" || !effectTaskId || !dataOf(result)?.ok) return result;
|
|
36466
|
+
if (!UUID.test(effectTaskId)) return result;
|
|
36467
|
+
let state;
|
|
36468
|
+
try {
|
|
36469
|
+
state = await this.store.load(effectTaskId);
|
|
36470
|
+
} catch {
|
|
36471
|
+
this.warn("Foundocs evaluation tracking unavailable.");
|
|
36472
|
+
return result;
|
|
36473
|
+
}
|
|
36474
|
+
if (!state || state.closed || !state.retrievals.includes(args.retrievalId)) return result;
|
|
36475
|
+
state.evaluated = [.../* @__PURE__ */ new Set([...state.evaluated, args.retrievalId])];
|
|
36476
|
+
if (args.verdict === "beneficial") state.beneficial = true;
|
|
36477
|
+
try {
|
|
36478
|
+
await this.store.save(state);
|
|
36479
|
+
} catch {
|
|
36480
|
+
this.warn("Foundocs evaluation tracking could not be saved; no comparison started.");
|
|
36481
|
+
return result;
|
|
36482
|
+
}
|
|
36483
|
+
if (!effectTaskComplete) return result;
|
|
36484
|
+
if (state.retrievals.some((id) => !state.evaluated.includes(id))) {
|
|
36485
|
+
await this.diagnostic(state, "skipped", "incomplete_evaluation");
|
|
36486
|
+
return result;
|
|
36487
|
+
}
|
|
36488
|
+
state.closed = true;
|
|
36489
|
+
try {
|
|
36490
|
+
await this.store.save(state);
|
|
36491
|
+
} catch {
|
|
36492
|
+
this.warn("Foundocs task closure could not be saved; no comparison started.");
|
|
36493
|
+
return result;
|
|
36494
|
+
}
|
|
36495
|
+
if (!state.preparationId || !state.beneficial) {
|
|
36496
|
+
state.settled = true;
|
|
36497
|
+
await this.diagnostic(state, "skipped", state.skipped ?? "no_beneficial_retrieval");
|
|
36498
|
+
return result;
|
|
36499
|
+
}
|
|
36500
|
+
const job = this.run(state).catch(() => this.warn("Foundocs automatic measurement failed; ordinary work continues."));
|
|
36501
|
+
this.jobs.add(job);
|
|
36502
|
+
void job.finally(() => this.jobs.delete(job));
|
|
36503
|
+
return result;
|
|
36504
|
+
}
|
|
36505
|
+
async run(state) {
|
|
36506
|
+
try {
|
|
36507
|
+
const { coordinator, config: config2 } = await this.factory();
|
|
36508
|
+
if (!config2?.enabled || state.consentHash !== hash(config2)) {
|
|
36509
|
+
state.settled = true;
|
|
36510
|
+
await this.diagnostic(state, "skipped", "consent_required");
|
|
36511
|
+
return;
|
|
36512
|
+
}
|
|
36513
|
+
await this.diagnostic(state, "running");
|
|
36514
|
+
const result = await coordinator.run({ taskId: state.taskId, retrievalIds: state.retrievals });
|
|
36515
|
+
state.settled = !["report_pending"].includes(result.status);
|
|
36516
|
+
if (result.status === "reported" || result.status === "already_reported") {
|
|
36517
|
+
const failed = result.result && result.result.status !== "completed";
|
|
36518
|
+
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36519
|
+
} else await this.diagnostic(state, result.status === "report_pending" ? "failed" : "skipped", result.status === "report_pending" ? "report_pending" : safeReason(result));
|
|
36520
|
+
} catch (e) {
|
|
36521
|
+
await this.diagnostic(state, "failed", safeReason(e));
|
|
36522
|
+
}
|
|
36523
|
+
}
|
|
36524
|
+
async drain() {
|
|
36525
|
+
await this.queue;
|
|
36526
|
+
await Promise.allSettled([...this.jobs]);
|
|
36527
|
+
}
|
|
36528
|
+
};
|
|
36529
|
+
function automaticStore(base) {
|
|
36530
|
+
const path = (taskId) => {
|
|
36531
|
+
if (!UUID.test(taskId)) throw new Error("Invalid task");
|
|
36532
|
+
return join2(base, taskId, "automatic.json");
|
|
36533
|
+
};
|
|
36534
|
+
return {
|
|
36535
|
+
async list() {
|
|
36536
|
+
await privateDir(base);
|
|
36537
|
+
const result = [];
|
|
36538
|
+
for (const id of await readdir2(base)) if (UUID.test(id)) {
|
|
36539
|
+
const state = await this.load(id);
|
|
36540
|
+
if (state) result.push(state);
|
|
36541
|
+
}
|
|
36542
|
+
return result;
|
|
36543
|
+
},
|
|
36544
|
+
async load(taskId) {
|
|
36545
|
+
try {
|
|
36546
|
+
return await readJson(path(taskId));
|
|
36547
|
+
} catch (e) {
|
|
36548
|
+
if (e.code === "ENOENT") return null;
|
|
36549
|
+
throw e;
|
|
36550
|
+
}
|
|
36551
|
+
},
|
|
36552
|
+
async save(state) {
|
|
36553
|
+
await privateDir(join2(base, state.taskId));
|
|
36554
|
+
await saveJson(path(state.taskId), state);
|
|
36555
|
+
}
|
|
36556
|
+
};
|
|
36557
|
+
}
|
|
36558
|
+
|
|
36559
|
+
// skills/foundocs/scripts/episode-checkpoint.mjs
|
|
36560
|
+
import { constants as constants2 } from "node:fs";
|
|
36561
|
+
import { open as open3, mkdir as mkdir2, lstat as lstat3, readFile as readFile3, realpath as realpath2, rename as rename2, rm as rm2 } from "node:fs/promises";
|
|
36140
36562
|
import { homedir } from "node:os";
|
|
36141
|
-
import { dirname, isAbsolute, join } from "node:path";
|
|
36142
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
36563
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
36564
|
+
import { createHash as createHash2, randomUUID as randomUUID3 } from "node:crypto";
|
|
36143
36565
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
36144
|
-
var
|
|
36145
|
-
var
|
|
36566
|
+
var hash2 = (value) => createHash2("sha256").update(value).digest("hex");
|
|
36567
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
36146
36568
|
var TTL = 14 * 864e5;
|
|
36147
36569
|
var MAX_CHECKPOINTS = 128;
|
|
36148
36570
|
var MAX_OUTBOX = 32;
|
|
@@ -36154,22 +36576,22 @@ var unavailable = () => {
|
|
|
36154
36576
|
async function privateDirectory(path) {
|
|
36155
36577
|
if (process.platform === "win32") unavailable();
|
|
36156
36578
|
let ancestor = path;
|
|
36157
|
-
while (
|
|
36158
|
-
const st2 = await
|
|
36579
|
+
while (dirname2(ancestor) !== ancestor) {
|
|
36580
|
+
const st2 = await lstat3(ancestor).catch((e) => {
|
|
36159
36581
|
if (e.code !== "ENOENT") throw e;
|
|
36160
36582
|
return null;
|
|
36161
36583
|
});
|
|
36162
36584
|
if (st2 && (!st2.isDirectory() || st2.isSymbolicLink())) unavailable();
|
|
36163
|
-
ancestor =
|
|
36585
|
+
ancestor = dirname2(ancestor);
|
|
36164
36586
|
}
|
|
36165
|
-
await
|
|
36166
|
-
const st = await
|
|
36587
|
+
await mkdir2(path, { recursive: true, mode: 448 });
|
|
36588
|
+
const st = await lstat3(path);
|
|
36167
36589
|
if (st.mode & 63 || st.uid !== process.getuid()) unavailable();
|
|
36168
36590
|
}
|
|
36169
36591
|
async function readState(path) {
|
|
36170
36592
|
let file;
|
|
36171
36593
|
try {
|
|
36172
|
-
file = await
|
|
36594
|
+
file = await open3(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
36173
36595
|
const st = await file.stat();
|
|
36174
36596
|
if (!st.isFile() || st.nlink !== 1 || st.mode & 63 || st.uid !== process.getuid() || st.size > 3 * 1024 * 1024) unavailable();
|
|
36175
36597
|
return JSON.parse(await file.readFile("utf8"));
|
|
@@ -36181,29 +36603,29 @@ async function readState(path) {
|
|
|
36181
36603
|
}
|
|
36182
36604
|
}
|
|
36183
36605
|
async function writeState(path, state) {
|
|
36184
|
-
const temporary = `${path}.${
|
|
36606
|
+
const temporary = `${path}.${randomUUID3()}.tmp`;
|
|
36185
36607
|
let file;
|
|
36186
36608
|
try {
|
|
36187
|
-
file = await
|
|
36609
|
+
file = await open3(temporary, "wx", 384);
|
|
36188
36610
|
await file.writeFile(JSON.stringify(state));
|
|
36189
36611
|
await file.sync();
|
|
36190
36612
|
await file.close();
|
|
36191
36613
|
file = null;
|
|
36192
|
-
await
|
|
36614
|
+
await rename2(temporary, path);
|
|
36193
36615
|
} finally {
|
|
36194
36616
|
await file?.close();
|
|
36195
|
-
await
|
|
36617
|
+
await rm2(temporary, { force: true });
|
|
36196
36618
|
}
|
|
36197
36619
|
}
|
|
36198
36620
|
async function locked(directory, action) {
|
|
36199
|
-
const lock =
|
|
36200
|
-
const file = await
|
|
36621
|
+
const lock = join3(directory, "checkpoint.lock");
|
|
36622
|
+
const file = await open3(lock, "wx", 384);
|
|
36201
36623
|
try {
|
|
36202
36624
|
await file.writeFile(String(process.pid));
|
|
36203
36625
|
return await action();
|
|
36204
36626
|
} finally {
|
|
36205
36627
|
await file.close();
|
|
36206
|
-
await
|
|
36628
|
+
await rm2(lock, { force: true });
|
|
36207
36629
|
}
|
|
36208
36630
|
}
|
|
36209
36631
|
function prune(state, now) {
|
|
@@ -36234,23 +36656,23 @@ function captureInput(input, checkpoint, slot, projectId, now) {
|
|
|
36234
36656
|
if (typeof capture.event.observation !== "string" || capture.event.observation.length > 3e3 || !Array.isArray(capture.event.evidence) || capture.event.evidence.length > 20 || !Array.isArray(capture.event.links) || capture.event.links.length > 20) unavailable();
|
|
36235
36657
|
if (capture.event.evidence.some((e) => typeof e.detail !== "string" || e.detail.length > 1e3)) unavailable();
|
|
36236
36658
|
}
|
|
36237
|
-
return { ...capture, project_id: projectId, requestId:
|
|
36659
|
+
return { ...capture, project_id: projectId, requestId: randomUUID3() };
|
|
36238
36660
|
}
|
|
36239
36661
|
async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
36240
36662
|
if (Buffer.byteLength(JSON.stringify(input)) > 1024 * 1024) unavailable();
|
|
36241
|
-
const root = await
|
|
36242
|
-
if (!
|
|
36243
|
-
const config2 = JSON.parse(await
|
|
36244
|
-
if (!
|
|
36663
|
+
const root = await realpath2(rootPath);
|
|
36664
|
+
if (!isAbsolute2(rootPath)) unavailable();
|
|
36665
|
+
const config2 = JSON.parse(await readFile3(join3(root, "foundocs.json"), "utf8"));
|
|
36666
|
+
if (!UUID2.test(config2.project_id) || options.projectId && config2.project_id !== options.projectId) unavailable();
|
|
36245
36667
|
if (config2.episodes?.enabled === false || process.env.FOUNDOCS_EPISODES === "off") return { status: "disabled" };
|
|
36246
36668
|
const client = options.client;
|
|
36247
36669
|
if (!["codex", "claude"].includes(client)) return { status: "unsupported_host" };
|
|
36248
|
-
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ??
|
|
36249
|
-
if (!
|
|
36250
|
-
const directory =
|
|
36670
|
+
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ?? join3(homedir(), ".local/share/foundocs/setup");
|
|
36671
|
+
if (!isAbsolute2(base)) unavailable();
|
|
36672
|
+
const directory = join3(base, "episodes", hash2(root));
|
|
36251
36673
|
await privateDirectory(directory);
|
|
36252
36674
|
return locked(directory, async () => {
|
|
36253
|
-
const path =
|
|
36675
|
+
const path = join3(directory, "checkpoints.json"), state = await readState(path), now = options.now ?? Date.now();
|
|
36254
36676
|
if (!Array.isArray(state.checkpoints) || !Array.isArray(state.outbox)) unavailable();
|
|
36255
36677
|
const counts = [state.checkpoints.length, state.outbox.length];
|
|
36256
36678
|
prune(state, now);
|
|
@@ -36262,7 +36684,7 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36262
36684
|
let checkpoint = state.checkpoints.findLast((c) => c.sessionId === input.session_id);
|
|
36263
36685
|
if (input.hook_event_name === "UserPromptSubmit") {
|
|
36264
36686
|
if (checkpoint?.fallbackIssued && typeof input.prompt === "string" && input.prompt.startsWith("One bounded Foundocs checkpoint follow-up. ")) return null;
|
|
36265
|
-
const id = client === "codex" && safeId(input.turn_id) ?
|
|
36687
|
+
const id = client === "codex" && safeId(input.turn_id) ? hash2(`${input.session_id}:${input.turn_id}`).slice(0, 40) : randomUUID3();
|
|
36266
36688
|
checkpoint = state.checkpoints.find((c) => c.id === id);
|
|
36267
36689
|
if (!checkpoint) {
|
|
36268
36690
|
checkpoint = { id, sessionId: input.session_id, ...safeId(input.turn_id) ? { turnId: input.turn_id } : {}, client, createdAt: now, acknowledged: false, fallbackIssued: false };
|
|
@@ -36284,25 +36706,25 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36284
36706
|
} else if (command === "prepare") {
|
|
36285
36707
|
if (typeof input.slot !== "string" || !/^[a-z0-9_-]{1,40}$/.test(input.slot)) unavailable();
|
|
36286
36708
|
const settled = checkpoint.settled?.find((entry) => entry.slot === input.slot);
|
|
36287
|
-
if (settled) return { status: settled.inputHash ===
|
|
36709
|
+
if (settled) return { status: settled.inputHash === hash2(JSON.stringify(input.capture)) ? "already_acknowledged" : "payload_conflict", requestId: settled.requestId, disposition: settled.disposition };
|
|
36288
36710
|
if ((checkpoint.settled ?? []).length >= 32) return { status: "checkpoint_full" };
|
|
36289
36711
|
const previous = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.slot === input.slot);
|
|
36290
36712
|
if (previous) {
|
|
36291
|
-
if (previous.inputHash !==
|
|
36713
|
+
if (previous.inputHash !== hash2(JSON.stringify(input.capture))) return { status: "payload_conflict", requestId: previous.payload.requestId };
|
|
36292
36714
|
output = { status: "prepared", payload: previous.payload };
|
|
36293
36715
|
} else {
|
|
36294
36716
|
if (checkpoint.createdAt + TTL <= now) return { status: "checkpoint_expired" };
|
|
36295
36717
|
if (state.outbox.length >= MAX_OUTBOX) return { status: "outbox_full" };
|
|
36296
36718
|
const payload = captureInput(input.capture, checkpoint, input.slot, config2.project_id, now);
|
|
36297
36719
|
if (Buffer.byteLength(JSON.stringify(payload)) > MAX_BYTES) unavailable();
|
|
36298
|
-
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash:
|
|
36720
|
+
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash: hash2(JSON.stringify(input.capture)), payload, createdAt: now });
|
|
36299
36721
|
output = { status: "prepared", payload };
|
|
36300
36722
|
}
|
|
36301
36723
|
checkpoint.acknowledged = true;
|
|
36302
36724
|
} else if (command === "ack") {
|
|
36303
36725
|
const entry = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.payload.requestId === input.requestId);
|
|
36304
36726
|
if (!entry) return { status: "request_unavailable" };
|
|
36305
|
-
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !
|
|
36727
|
+
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !UUID2.test(input.result?.candidate?.id)) unavailable();
|
|
36306
36728
|
checkpoint.settled ??= [];
|
|
36307
36729
|
checkpoint.settled.push({ slot: entry.slot, inputHash: entry.inputHash, requestId: entry.payload.requestId, disposition: input.result.disposition });
|
|
36308
36730
|
state.outbox = state.outbox.filter((e) => e !== entry);
|
|
@@ -36325,15 +36747,15 @@ if (process.argv[1]?.endsWith("episode-checkpoint.mjs") && pathToFileURL2(proces
|
|
|
36325
36747
|
const [command, flag, root] = process.argv.slice(2);
|
|
36326
36748
|
let output;
|
|
36327
36749
|
try {
|
|
36328
|
-
if (flag !== "--root" || !
|
|
36329
|
-
const script = await
|
|
36330
|
-
const client = ["codex", "claude"].find((c) => script ===
|
|
36331
|
-
let
|
|
36750
|
+
if (flag !== "--root" || !isAbsolute2(root)) unavailable();
|
|
36751
|
+
const script = await realpath2(process.argv[1]), canonical2 = await realpath2(root);
|
|
36752
|
+
const client = ["codex", "claude"].find((c) => script === join3(canonical2, c === "codex" ? ".agents" : ".claude", "skills/foundocs/scripts/episode-checkpoint.mjs"));
|
|
36753
|
+
let text2 = "";
|
|
36332
36754
|
for await (const chunk of process.stdin) {
|
|
36333
|
-
|
|
36334
|
-
if (Buffer.byteLength(
|
|
36755
|
+
text2 += chunk;
|
|
36756
|
+
if (Buffer.byteLength(text2) > 1024 * 1024) unavailable();
|
|
36335
36757
|
}
|
|
36336
|
-
output = await episodeCheckpoint(command, root, JSON.parse(
|
|
36758
|
+
output = await episodeCheckpoint(command, root, JSON.parse(text2), { client });
|
|
36337
36759
|
} catch {
|
|
36338
36760
|
output = command === "hook" ? null : { status: "unavailable" };
|
|
36339
36761
|
}
|
|
@@ -36397,7 +36819,8 @@ function requestError(error2, name) {
|
|
|
36397
36819
|
{ code, retryable, ...tool ? { tool } : {}, ...httpStatus !== void 0 ? { httpStatus } : {}, ...remoteCode !== void 0 ? { remoteCode } : {} }
|
|
36398
36820
|
);
|
|
36399
36821
|
}
|
|
36400
|
-
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client }) {
|
|
36822
|
+
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, automaticFactory, automaticBase }) {
|
|
36823
|
+
let automatic, automaticSupported = false, recovered = false;
|
|
36401
36824
|
let remote, local, checkpointRoute = "remote", checkpointWasLocal = false;
|
|
36402
36825
|
let argumentDefaults, inventoryRequest;
|
|
36403
36826
|
const checkpointTool = {
|
|
@@ -36415,6 +36838,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36415
36838
|
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false, idempotentHint: false }
|
|
36416
36839
|
};
|
|
36417
36840
|
async function close() {
|
|
36841
|
+
await automatic?.drain();
|
|
36418
36842
|
await remote?.close().catch(() => {
|
|
36419
36843
|
});
|
|
36420
36844
|
await local?.close().catch(() => {
|
|
@@ -36423,7 +36847,8 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36423
36847
|
function refreshToolInventory() {
|
|
36424
36848
|
if (!inventoryRequest) {
|
|
36425
36849
|
argumentDefaults = void 0;
|
|
36426
|
-
|
|
36850
|
+
automaticSupported = false;
|
|
36851
|
+
inventoryRequest = remote.listTools(void 0, { cacheMode: "refresh" }).then(async ({ tools }) => {
|
|
36427
36852
|
if (tools.length > 2e3) throw new Error("tool inventory exceeds bound");
|
|
36428
36853
|
const defaults = /* @__PURE__ */ new Map();
|
|
36429
36854
|
for (const { name, inputSchema } of tools) {
|
|
@@ -36437,6 +36862,15 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36437
36862
|
if (advertisesUnifiedTree(inputSchema)) options.tree = "unified";
|
|
36438
36863
|
defaults.set(name, options);
|
|
36439
36864
|
}
|
|
36865
|
+
automaticSupported = !!automatic && ["get_effect_measurement_policy", "prepare_effect_measurement", "report_effect_diagnostic", "report_retrieval_evaluation"].every((name) => defaults.has(name));
|
|
36866
|
+
if (automaticSupported && !recovered) {
|
|
36867
|
+
try {
|
|
36868
|
+
await automatic.recover();
|
|
36869
|
+
} catch {
|
|
36870
|
+
process.stderr.write("Foundocs measurement recovery unavailable; ordinary MCP continues.\n");
|
|
36871
|
+
}
|
|
36872
|
+
recovered = true;
|
|
36873
|
+
}
|
|
36440
36874
|
argumentDefaults = defaults;
|
|
36441
36875
|
return tools;
|
|
36442
36876
|
}).finally(() => {
|
|
@@ -36458,6 +36892,23 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36458
36892
|
}
|
|
36459
36893
|
});
|
|
36460
36894
|
await remote.connect(transport, { timeout: 2e4 });
|
|
36895
|
+
if (automaticFactory && automaticBase) automatic = new AutomaticMeasurement({
|
|
36896
|
+
projectId,
|
|
36897
|
+
factory: automaticFactory,
|
|
36898
|
+
store: automaticStore(automaticBase),
|
|
36899
|
+
warn: (message) => process.stderr.write(message + "\n"),
|
|
36900
|
+
remote: async (name, args, raw = false) => {
|
|
36901
|
+
const result = await remote.callTool({ name, arguments: { ...args, project_id: args.project_id ?? projectId } });
|
|
36902
|
+
if (raw) return result;
|
|
36903
|
+
const body = result.structuredContent ?? JSON.parse(result.content.find((c) => c.type === "text").text);
|
|
36904
|
+
if (!body.ok || result.isError) {
|
|
36905
|
+
const error2 = new Error("Measurement request failed");
|
|
36906
|
+
error2.code = body.error?.code;
|
|
36907
|
+
throw error2;
|
|
36908
|
+
}
|
|
36909
|
+
return body.data;
|
|
36910
|
+
}
|
|
36911
|
+
});
|
|
36461
36912
|
local = new Server({ name: "foundocs", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: remote.getInstructions() });
|
|
36462
36913
|
local.setRequestHandler("tools/list", async () => {
|
|
36463
36914
|
try {
|
|
@@ -36465,11 +36916,9 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36465
36916
|
const collision = tools.some((tool) => tool.name === checkpointTool.name);
|
|
36466
36917
|
const supported = !!root && ["codex", "claude"].includes(client) && tools.some((tool) => tool.name === "capture_episode") && !collision;
|
|
36467
36918
|
checkpointRoute = supported ? "local" : checkpointWasLocal ? "blocked" : "remote";
|
|
36468
|
-
if (supported)
|
|
36469
|
-
|
|
36470
|
-
|
|
36471
|
-
}
|
|
36472
|
-
return { tools: checkpointRoute === "blocked" ? tools.filter((tool) => tool.name !== checkpointTool.name) : tools };
|
|
36919
|
+
if (supported) checkpointWasLocal = true;
|
|
36920
|
+
const visible = supported ? [...tools, checkpointTool] : checkpointRoute === "blocked" ? tools.filter((tool) => tool.name !== checkpointTool.name) : tools;
|
|
36921
|
+
return { tools: automaticSupported ? visible.map(automaticTool) : visible };
|
|
36473
36922
|
} catch (error2) {
|
|
36474
36923
|
throw requestError(error2, "tools_list");
|
|
36475
36924
|
}
|
|
@@ -36482,7 +36931,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36482
36931
|
let data;
|
|
36483
36932
|
try {
|
|
36484
36933
|
if (checkpointRoute !== "local" || !["prepare", "ack", "skip", "pending", "discard"].includes(args.operation)) throw new Error();
|
|
36485
|
-
const storageDir =
|
|
36934
|
+
const storageDir = dirname3(dirname3(dirname3(dirname3(dirname3(credentialPath)))));
|
|
36486
36935
|
data = await episodeCheckpoint(args.operation, root, args, { client, storageDir, projectId });
|
|
36487
36936
|
} catch {
|
|
36488
36937
|
data = { status: "unavailable" };
|
|
@@ -36495,8 +36944,12 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36495
36944
|
if (!argumentDefaults) await refreshToolInventory().catch(() => {
|
|
36496
36945
|
});
|
|
36497
36946
|
const defaults = argumentDefaults?.get(name);
|
|
36498
|
-
|
|
36499
|
-
return await
|
|
36947
|
+
const params = defaults ? { ...request.params, arguments: { ...defaults, ...args } } : request.params;
|
|
36948
|
+
if (automaticSupported) return await automatic.call(params);
|
|
36949
|
+
if (args && ["effectTask", "effectTaskId", "effectTaskComplete"].some((key2) => Object.hasOwn(args, key2))) {
|
|
36950
|
+
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Automatic measurement metadata requires the current installer and server.");
|
|
36951
|
+
}
|
|
36952
|
+
return await remote.callTool(params);
|
|
36500
36953
|
} catch (error2) {
|
|
36501
36954
|
throw requestError(error2, request.params.name);
|
|
36502
36955
|
}
|