@foundocs/foundocs-setup 0.5.0 → 0.5.2
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 +1 -19
- package/dist/bridge.mjs +239 -700
- package/package.json +3 -3
- package/skills/foundocs/SKILL.md +2 -6
- package/skills/foundocs/references/dreaming.md +4 -3
- package/skills/foundocs/scripts/session-start.mjs +5 -15
- package/src/bridge.mjs +3 -26
- package/src/cli.mjs +1 -9
- package/src/runtime.mjs +7 -29
- package/src/setup.mjs +13 -6
- package/src/skill-assets.mjs +1 -1
- package/skills/foundocs/references/effect-measurement.md +0 -55
- package/src/effect-automatic.mjs +0 -190
- package/src/effect-config.mjs +0 -31
- package/src/effect-host.mjs +0 -86
- package/src/effect-remote.mjs +0 -28
- package/src/effect.mjs +0 -209
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 keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
32
|
+
key = keys[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(obj) {
|
|
231
|
+
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
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, keys, wrap) {
|
|
266
266
|
const raw = sourceShape(source);
|
|
267
|
-
for (const key of
|
|
267
|
+
for (const key of keys) {
|
|
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(obj, path) {
|
|
303
303
|
if (!path)
|
|
304
|
-
return
|
|
305
|
-
return path.reduce((acc, key) => acc?.[key],
|
|
304
|
+
return obj;
|
|
305
|
+
return path.reduce((acc, key) => acc?.[key], obj);
|
|
306
306
|
}
|
|
307
307
|
function promiseAllObject(promisesObj) {
|
|
308
|
-
const
|
|
309
|
-
const promises =
|
|
308
|
+
const keys = Object.keys(promisesObj);
|
|
309
|
+
const promises = keys.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 < keys.length; i++) {
|
|
313
|
+
resolvedObj[keys[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 keys = [];
|
|
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
|
+
keys.push(key);
|
|
542
542
|
}
|
|
543
|
-
return
|
|
543
|
+
return keys;
|
|
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 obj = data;
|
|
742
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) {
|
|
743
|
+
return obj.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(obj) {
|
|
762
|
+
return Object.entries(obj).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(obj, key, make) {
|
|
1087
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1088
1088
|
if (key === "__proto__") {
|
|
1089
|
-
Object.defineProperty(
|
|
1089
|
+
Object.defineProperty(obj, key, { value: make(), writable: true, enumerable: true, configurable: true });
|
|
1090
1090
|
} else {
|
|
1091
|
-
|
|
1091
|
+
obj[key] = make();
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
return
|
|
1094
|
+
return obj[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 keys = 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 ? [...keys, ...symbolKeys] : keys;
|
|
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(keys),
|
|
2469
|
+
numKeys: keys.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 keys;
|
|
2943
2943
|
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2944
2944
|
unrecIssue ?? (unrecIssue = iss);
|
|
2945
|
-
|
|
2945
|
+
keys = 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
|
+
keys = [k];
|
|
2951
2951
|
} else {
|
|
2952
2952
|
return false;
|
|
2953
2953
|
}
|
|
2954
|
-
for (const k of
|
|
2954
|
+
for (const k of keys) {
|
|
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 keys = Object.keys(option);
|
|
4672
|
+
if (keys.length !== 1 || keys[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 keys = 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 (keys.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 (keys.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 obj = 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
|
+
obj.parameters[key] = value;
|
|
12506
12506
|
}
|
|
12507
12507
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
12508
12508
|
}
|
|
12509
|
-
return
|
|
12509
|
+
return obj;
|
|
12510
12510
|
}
|
|
12511
|
-
function getcontenttype(
|
|
12511
|
+
function getcontenttype(obj) {
|
|
12512
12512
|
var header;
|
|
12513
|
-
if (typeof
|
|
12514
|
-
else if (typeof
|
|
12513
|
+
if (typeof obj.getHeader === "function") header = obj.getHeader("content-type");
|
|
12514
|
+
else if (typeof obj.headers === "object") header = obj.headers && obj.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, constants2) {
|
|
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, constants2);
|
|
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, constants2) {
|
|
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, constants2);
|
|
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, constants2) {
|
|
13078
|
+
this.code = optimizeExpr(this.code, names, constants2);
|
|
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, constants2) {
|
|
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, constants2)) 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, constants2) {
|
|
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, constants2);
|
|
13159
|
+
if (!(super.optimizeNames(names, constants2) || this.else)) return;
|
|
13160
|
+
this.condition = optimizeExpr(this.condition, names, constants2);
|
|
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, constants2) {
|
|
13183
|
+
if (!super.optimizeNames(names, constants2)) return;
|
|
13184
|
+
this.iteration = optimizeExpr(this.iteration, names, constants2);
|
|
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, constants2) {
|
|
13220
|
+
if (!super.optimizeNames(names, constants2)) return;
|
|
13221
|
+
this.iterable = optimizeExpr(this.iterable, names, constants2);
|
|
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, constants2) {
|
|
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, constants2);
|
|
13263
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants2);
|
|
13264
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants2);
|
|
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, obj, 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(${obj})`, 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, obj), () => 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, constants2) {
|
|
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 = constants2[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 && constants2[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 hash2 = {};
|
|
13563
|
+
for (const item of arr) hash2[item] = true;
|
|
13564
|
+
return hash2;
|
|
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, keys;
|
|
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
|
+
keys = Object.keys(a);
|
|
14419
|
+
length = keys.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, keys[i])) return false;
|
|
14422
14422
|
for (i = length; i-- !== 0; ) {
|
|
14423
|
-
var key =
|
|
14423
|
+
var key = keys[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(obj, assign) {
|
|
14936
|
+
if (assign) Object.assign(this.params, obj);
|
|
14937
|
+
else this.params = obj;
|
|
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, relative, options, skipNormalization) {
|
|
15672
15672
|
const target = {};
|
|
15673
15673
|
if (!skipNormalization) {
|
|
15674
15674
|
base = parse2(serialize(base, options), options);
|
|
15675
|
-
|
|
15675
|
+
relative = parse2(serialize(relative, 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 && relative.scheme) {
|
|
15679
|
+
target.scheme = relative.scheme;
|
|
15680
|
+
target.userinfo = relative.userinfo;
|
|
15681
|
+
target.host = relative.host;
|
|
15682
|
+
target.port = relative.port;
|
|
15683
|
+
target.path = removeDotSegments(relative.path || "");
|
|
15684
|
+
target.query = relative.query;
|
|
15685
15685
|
} else {
|
|
15686
|
-
if (
|
|
15687
|
-
target.userinfo =
|
|
15688
|
-
target.host =
|
|
15689
|
-
target.port =
|
|
15690
|
-
target.path = removeDotSegments(
|
|
15691
|
-
target.query =
|
|
15686
|
+
if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
|
|
15687
|
+
target.userinfo = relative.userinfo;
|
|
15688
|
+
target.host = relative.host;
|
|
15689
|
+
target.port = relative.port;
|
|
15690
|
+
target.path = removeDotSegments(relative.path || "");
|
|
15691
|
+
target.query = relative.query;
|
|
15692
15692
|
} else {
|
|
15693
|
-
if (!
|
|
15693
|
+
if (!relative.path) {
|
|
15694
15694
|
target.path = base.path;
|
|
15695
|
-
if (
|
|
15695
|
+
if (relative.query !== void 0) target.query = relative.query;
|
|
15696
15696
|
else target.query = base.query;
|
|
15697
15697
|
} else {
|
|
15698
|
-
if (
|
|
15698
|
+
if (relative.path[0] === "/") target.path = removeDotSegments(relative.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 = "/" + relative.path;
|
|
15701
|
+
else if (!base.path) target.path = relative.path;
|
|
15702
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
|
|
15703
15703
|
target.path = removeDotSegments(target.path);
|
|
15704
15704
|
}
|
|
15705
|
-
target.query =
|
|
15705
|
+
target.query = relative.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 = relative.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((text, msg) => text + 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 text = error2.data?.text;
|
|
21505
21505
|
return {
|
|
21506
21506
|
kind: "http-error",
|
|
21507
21507
|
status: error2.data.status,
|
|
21508
|
-
body: typeof
|
|
21508
|
+
body: typeof text === "string" ? text : 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 obj = 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 (obj[key] === void 0 && Object.prototype.hasOwnProperty.call(propSchema, "default")) obj[key] = propSchema.default;
|
|
21651
|
+
if (obj[key] !== void 0) applyElicitationDefaults(propSchema, obj[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 text = this._redirectPolicy === "follow" ? void 0 : unfollowedRedirect(url2, response);
|
|
23263
|
+
return text && `${text} (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 text = 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
|
|
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 text = 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
|
|
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 text === "string" && this._isModernEnvelopedRequest(message)) try {
|
|
23607
|
+
const parsed = JSONRPCMessageSchema.parse(JSON.parse(text));
|
|
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) ?? text;
|
|
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
|
|
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 keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
23734
|
+
key = keys[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 obj = 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
|
+
obj.parameters[key] = value;
|
|
28149
28149
|
}
|
|
28150
28150
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
28151
28151
|
}
|
|
28152
|
-
return
|
|
28152
|
+
return obj;
|
|
28153
28153
|
}
|
|
28154
|
-
function getcontenttype(
|
|
28154
|
+
function getcontenttype(obj) {
|
|
28155
28155
|
var header;
|
|
28156
|
-
if (typeof
|
|
28157
|
-
else if (typeof
|
|
28156
|
+
if (typeof obj.getHeader === "function") header = obj.getHeader("content-type");
|
|
28157
|
+
else if (typeof obj.headers === "object") header = obj.headers && obj.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, constants2) {
|
|
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, constants2);
|
|
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, constants2) {
|
|
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, constants2);
|
|
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, constants2) {
|
|
28669
|
+
this.code = optimizeExpr(this.code, names, constants2);
|
|
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, constants2) {
|
|
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, constants2)) 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, constants2) {
|
|
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, constants2);
|
|
28750
|
+
if (!(super.optimizeNames(names, constants2) || this.else)) return;
|
|
28751
|
+
this.condition = optimizeExpr(this.condition, names, constants2);
|
|
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, constants2) {
|
|
28774
|
+
if (!super.optimizeNames(names, constants2)) return;
|
|
28775
|
+
this.iteration = optimizeExpr(this.iteration, names, constants2);
|
|
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, constants2) {
|
|
28811
|
+
if (!super.optimizeNames(names, constants2)) return;
|
|
28812
|
+
this.iterable = optimizeExpr(this.iterable, names, constants2);
|
|
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, constants2) {
|
|
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, constants2);
|
|
28854
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants2);
|
|
28855
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants2);
|
|
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, obj, 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(${obj})`, 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, obj), () => 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, constants2) {
|
|
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 = constants2[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 && constants2[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 hash2 = {};
|
|
29154
|
+
for (const item of arr) hash2[item] = true;
|
|
29155
|
+
return hash2;
|
|
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, keys;
|
|
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
|
+
keys = Object.keys(a);
|
|
30010
|
+
length = keys.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, keys[i])) return false;
|
|
30013
30013
|
for (i = length; i-- !== 0; ) {
|
|
30014
|
-
var key =
|
|
30014
|
+
var key = keys[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(obj, assign) {
|
|
30527
|
+
if (assign) Object.assign(this.params, obj);
|
|
30528
|
+
else this.params = obj;
|
|
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, relative, options, skipNormalization) {
|
|
31263
31263
|
const target = {};
|
|
31264
31264
|
if (!skipNormalization) {
|
|
31265
31265
|
base = parse2(serialize(base, options), options);
|
|
31266
|
-
|
|
31266
|
+
relative = parse2(serialize(relative, 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 && relative.scheme) {
|
|
31270
|
+
target.scheme = relative.scheme;
|
|
31271
|
+
target.userinfo = relative.userinfo;
|
|
31272
|
+
target.host = relative.host;
|
|
31273
|
+
target.port = relative.port;
|
|
31274
|
+
target.path = removeDotSegments(relative.path || "");
|
|
31275
|
+
target.query = relative.query;
|
|
31276
31276
|
} else {
|
|
31277
|
-
if (
|
|
31278
|
-
target.userinfo =
|
|
31279
|
-
target.host =
|
|
31280
|
-
target.port =
|
|
31281
|
-
target.path = removeDotSegments(
|
|
31282
|
-
target.query =
|
|
31277
|
+
if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
|
|
31278
|
+
target.userinfo = relative.userinfo;
|
|
31279
|
+
target.host = relative.host;
|
|
31280
|
+
target.port = relative.port;
|
|
31281
|
+
target.path = removeDotSegments(relative.path || "");
|
|
31282
|
+
target.query = relative.query;
|
|
31283
31283
|
} else {
|
|
31284
|
-
if (!
|
|
31284
|
+
if (!relative.path) {
|
|
31285
31285
|
target.path = base.path;
|
|
31286
|
-
if (
|
|
31286
|
+
if (relative.query !== void 0) target.query = relative.query;
|
|
31287
31287
|
else target.query = base.query;
|
|
31288
31288
|
} else {
|
|
31289
|
-
if (
|
|
31289
|
+
if (relative.path[0] === "/") target.path = removeDotSegments(relative.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 = "/" + relative.path;
|
|
31292
|
+
else if (!base.path) target.path = relative.path;
|
|
31293
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
|
|
31294
31294
|
target.path = removeDotSegments(target.path);
|
|
31295
31295
|
}
|
|
31296
|
-
target.query =
|
|
31296
|
+
target.query = relative.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 = relative.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((text, msg) => text + separator + msg);
|
|
31829
31829
|
}
|
|
31830
31830
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
31831
31831
|
const rules = this.RULES.all;
|
|
@@ -36132,445 +36132,17 @@ 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
|
|
36136
|
-
|
|
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";
|
|
36144
|
-
import { constants } from "node:fs";
|
|
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 evaluationTools = /* @__PURE__ */ new Set(["report_retrieval_evaluation", "report_retrieval_evaluations"]);
|
|
36273
|
-
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"]);
|
|
36274
|
-
var safeReason = (e) => reasons.has(e?.reason ?? e?.code?.toLowerCase()) ? e.reason ?? e.code.toLowerCase() : ["EACCES", "EPERM"].includes(e?.code) ? "permission_denied" : "local_failure";
|
|
36275
|
-
var dataOf = (r) => r?.structuredContent ?? (() => {
|
|
36276
|
-
try {
|
|
36277
|
-
return JSON.parse(r?.content?.find((c) => c.type === "text")?.text);
|
|
36278
|
-
} catch {
|
|
36279
|
-
return null;
|
|
36280
|
-
}
|
|
36281
|
-
})();
|
|
36282
|
-
function retrievalIds(value, found = /* @__PURE__ */ new Set()) {
|
|
36283
|
-
if (!value || typeof value !== "object") return found;
|
|
36284
|
-
if (Array.isArray(value.retrievals)) {
|
|
36285
|
-
for (const r of value.retrievals) if (UUID.test(r?.retrievalId)) found.add(r.retrievalId);
|
|
36286
|
-
}
|
|
36287
|
-
for (const [key, child] of Object.entries(value)) if (key !== "retrievals" && child && typeof child === "object") retrievalIds(child, found);
|
|
36288
|
-
return found;
|
|
36289
|
-
}
|
|
36290
|
-
function automaticTool(tool) {
|
|
36291
|
-
if (!effectReads.has(tool.name) && !evaluationTools.has(tool.name)) return tool;
|
|
36292
|
-
const properties = { ...tool.inputSchema.properties };
|
|
36293
|
-
if (effectReads.has(tool.name)) properties.effectTask = {
|
|
36294
|
-
type: "object",
|
|
36295
|
-
additionalProperties: false,
|
|
36296
|
-
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.",
|
|
36297
|
-
required: ["taskId"],
|
|
36298
|
-
properties: {
|
|
36299
|
-
taskId: { type: "string", format: "uuid" },
|
|
36300
|
-
question: { type: "string", minLength: 1, maxLength: 2e3 },
|
|
36301
|
-
knownContext: { type: "string", maxLength: 4e3 },
|
|
36302
|
-
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 } } } },
|
|
36303
|
-
host: { type: "object", additionalProperties: false, required: ["client", "sessionId"], properties: { client: { type: "string", enum: ["codex", "claude_code"] }, sessionId: { type: "string", format: "uuid" }, transcriptPath: { type: "string" } } }
|
|
36304
|
-
}
|
|
36305
|
-
};
|
|
36306
|
-
else {
|
|
36307
|
-
properties.effectTaskId = { type: "string", format: "uuid", description: "Same automatic information task identity." };
|
|
36308
|
-
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." };
|
|
36309
|
-
}
|
|
36310
|
-
return {
|
|
36311
|
-
...tool,
|
|
36312
|
-
description: tool.description + " Installed automatic measurement accepts local task metadata; no shell prepare/run is needed.",
|
|
36313
|
-
inputSchema: { ...tool.inputSchema, properties },
|
|
36314
|
-
annotations: { ...tool.annotations, readOnlyHint: false, openWorldHint: true }
|
|
36315
|
-
};
|
|
36316
|
-
}
|
|
36317
|
-
var AutomaticMeasurement = class {
|
|
36318
|
-
constructor({ projectId, remote, factory, store, warn = () => {
|
|
36319
|
-
} }) {
|
|
36320
|
-
Object.assign(this, { projectId, remote, factory, store, warn });
|
|
36321
|
-
this.queue = Promise.resolve();
|
|
36322
|
-
this.jobs = /* @__PURE__ */ new Set();
|
|
36323
|
-
}
|
|
36324
|
-
call(params) {
|
|
36325
|
-
const next = this.queue.then(() => this.handle(params));
|
|
36326
|
-
this.queue = next.catch(() => {
|
|
36327
|
-
});
|
|
36328
|
-
return next;
|
|
36329
|
-
}
|
|
36330
|
-
async recover() {
|
|
36331
|
-
for (const state of await this.store.list?.() ?? []) {
|
|
36332
|
-
if (state.diagnostic) {
|
|
36333
|
-
try {
|
|
36334
|
-
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36335
|
-
state.diagnostic = null;
|
|
36336
|
-
await this.store.save(state);
|
|
36337
|
-
} catch {
|
|
36338
|
-
this.warn("Foundocs measurement status is pending; no inference was repeated.");
|
|
36339
|
-
}
|
|
36340
|
-
}
|
|
36341
|
-
if (!state.closed || state.settled || !state.preparationId) continue;
|
|
36342
|
-
try {
|
|
36343
|
-
const { coordinator } = await this.factory({ recovery: true });
|
|
36344
|
-
const result = await coordinator.flush(state.taskId);
|
|
36345
|
-
if (result.reason === "coordinator_active") continue;
|
|
36346
|
-
if (result.status === "report_pending") {
|
|
36347
|
-
await this.diagnostic(state, "failed", "report_pending");
|
|
36348
|
-
continue;
|
|
36349
|
-
}
|
|
36350
|
-
state.settled = true;
|
|
36351
|
-
if (["reported", "already_reported"].includes(result.status)) {
|
|
36352
|
-
const failed = result.result && result.result.status !== "completed";
|
|
36353
|
-
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36354
|
-
} else await this.diagnostic(state, "failed", result.status === "nothing_pending" ? "local_failure" : safeReason(result));
|
|
36355
|
-
} catch {
|
|
36356
|
-
this.warn("Foundocs measurement recovery pending; no inference was repeated.");
|
|
36357
|
-
}
|
|
36358
|
-
}
|
|
36359
|
-
}
|
|
36360
|
-
async diagnostic(state, status, reason = null) {
|
|
36361
|
-
state.sequence = (state.sequence ?? 0) + 1;
|
|
36362
|
-
state.diagnostic = { requestId: randomUUID2(), taskId: state.taskId, sequence: state.sequence, status, reason };
|
|
36363
|
-
try {
|
|
36364
|
-
await this.store.save(state);
|
|
36365
|
-
} catch {
|
|
36366
|
-
this.warn("Foundocs measurement status could not be saved locally.");
|
|
36367
|
-
}
|
|
36368
|
-
try {
|
|
36369
|
-
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36370
|
-
state.diagnostic = null;
|
|
36371
|
-
await this.store.save(state);
|
|
36372
|
-
} catch {
|
|
36373
|
-
this.warn("Foundocs measurement status could not be delivered; local status retained.");
|
|
36374
|
-
}
|
|
36375
|
-
}
|
|
36376
|
-
async handle(params) {
|
|
36377
|
-
const { effectTask, effectTaskId, effectTaskComplete, ...args } = params.arguments ?? {};
|
|
36378
|
-
const forward = () => this.remote(params.name, args, true);
|
|
36379
|
-
if (args.project_id !== this.projectId) {
|
|
36380
|
-
if (effectTask || effectTaskId || effectTaskComplete) throw new Error("Automatic measurement project mismatch");
|
|
36381
|
-
return forward();
|
|
36382
|
-
}
|
|
36383
|
-
if (effectReads.has(params.name)) {
|
|
36384
|
-
if (!effectTask) return forward();
|
|
36385
|
-
const taskId = effectTask?.taskId ?? (UUID.test(args.taskId ?? "") ? args.taskId : UUID.test(args.readId ?? "") ? args.readId : randomUUID2());
|
|
36386
|
-
if (!UUID.test(taskId) || args.taskId && args.taskId !== taskId || effectTask && args.effectPreparationId) throw new Error("Conflicting measurement task");
|
|
36387
|
-
let state2;
|
|
36388
|
-
try {
|
|
36389
|
-
state2 = await this.store.load(taskId);
|
|
36390
|
-
} catch (e) {
|
|
36391
|
-
args.taskId = taskId;
|
|
36392
|
-
try {
|
|
36393
|
-
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36394
|
-
} catch {
|
|
36395
|
-
this.warn("Foundocs measurement storage unavailable.");
|
|
36396
|
-
}
|
|
36397
|
-
return forward();
|
|
36398
|
-
}
|
|
36399
|
-
if (!state2) {
|
|
36400
|
-
state2 = { taskId, retrievals: [], evaluated: [], exposed: false, closed: false, expiresAt: new Date(Date.now() + 864e5).toISOString() };
|
|
36401
|
-
try {
|
|
36402
|
-
await this.store.save(state2);
|
|
36403
|
-
} catch (e) {
|
|
36404
|
-
args.taskId = taskId;
|
|
36405
|
-
try {
|
|
36406
|
-
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36407
|
-
} catch {
|
|
36408
|
-
this.warn("Foundocs measurement storage unavailable.");
|
|
36409
|
-
}
|
|
36410
|
-
return forward();
|
|
36411
|
-
}
|
|
36412
|
-
try {
|
|
36413
|
-
const policy = await this.remote("get_effect_measurement_policy", {});
|
|
36414
|
-
if (!policy.enabled) state2.skipped = "disabled";
|
|
36415
|
-
else if (!effectTask?.question || !effectTask?.criteria) state2.skipped = "missing_preparation";
|
|
36416
|
-
else {
|
|
36417
|
-
const brief = { taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria };
|
|
36418
|
-
validateBrief(brief);
|
|
36419
|
-
state2.briefHash = hash(brief);
|
|
36420
|
-
const { coordinator, config: config2 } = await this.factory();
|
|
36421
|
-
if (!config2?.enabled) state2.skipped = "consent_required";
|
|
36422
|
-
else {
|
|
36423
|
-
const result3 = await coordinator.prepare({ policy, brief, allowlist: config2.allowlist, excludePaths: config2.excludePaths, host: effectTask.host });
|
|
36424
|
-
if (result3.status === "prepared") {
|
|
36425
|
-
state2.preparationId = result3.effectPreparationId;
|
|
36426
|
-
state2.consentHash = hash(config2);
|
|
36427
|
-
} else state2.skipped = safeReason(result3);
|
|
36428
|
-
}
|
|
36429
|
-
}
|
|
36430
|
-
} catch (e) {
|
|
36431
|
-
state2.skipped = safeReason(e);
|
|
36432
|
-
}
|
|
36433
|
-
await this.diagnostic(state2, state2.preparationId ? "prepared" : "skipped", state2.preparationId ? null : state2.skipped);
|
|
36434
|
-
} else if (effectTask?.question && state2.briefHash !== hash({ taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria })) {
|
|
36435
|
-
throw new Error("Do not change a frozen information task");
|
|
36436
|
-
}
|
|
36437
|
-
if (!state2.preparationId && !state2.skipped) state2.skipped = "missing_preparation";
|
|
36438
|
-
if (state2.closed && effectTask) throw new Error("Information task is closed; never add later context or relabel the same question.");
|
|
36439
|
-
if (state2.closed || Date.parse(state2.expiresAt) <= Date.now()) {
|
|
36440
|
-
delete args.effectPreparationId;
|
|
36441
|
-
args.taskId = taskId;
|
|
36442
|
-
return forward();
|
|
36443
|
-
}
|
|
36444
|
-
args.taskId = taskId;
|
|
36445
|
-
if (state2.preparationId) args.effectPreparationId = state2.preparationId;
|
|
36446
|
-
state2.exposed = true;
|
|
36447
|
-
try {
|
|
36448
|
-
await this.store.save(state2);
|
|
36449
|
-
} catch (e) {
|
|
36450
|
-
delete args.effectPreparationId;
|
|
36451
|
-
await this.diagnostic(state2, "skipped", safeReason(e));
|
|
36452
|
-
return forward();
|
|
36453
|
-
}
|
|
36454
|
-
const result2 = await forward(), body = dataOf(result2);
|
|
36455
|
-
if (body?.ok) {
|
|
36456
|
-
state2.retrievals = [.../* @__PURE__ */ new Set([...state2.retrievals, ...retrievalIds(body.data)])];
|
|
36457
|
-
try {
|
|
36458
|
-
await this.store.save(state2);
|
|
36459
|
-
} catch {
|
|
36460
|
-
this.warn("Foundocs retrieval tracking could not be saved; no extra reads were requested.");
|
|
36461
|
-
}
|
|
36462
|
-
}
|
|
36463
|
-
return result2;
|
|
36464
|
-
}
|
|
36465
|
-
const isBatch = params.name === "report_retrieval_evaluations";
|
|
36466
|
-
if (isBatch && effectTaskId && args.taskId !== effectTaskId) throw new Error("Conflicting measurement task");
|
|
36467
|
-
const result = await forward();
|
|
36468
|
-
if (!evaluationTools.has(params.name) || !effectTaskId || !dataOf(result)?.ok) return result;
|
|
36469
|
-
if (!UUID.test(effectTaskId)) return result;
|
|
36470
|
-
let state;
|
|
36471
|
-
try {
|
|
36472
|
-
state = await this.store.load(effectTaskId);
|
|
36473
|
-
} catch {
|
|
36474
|
-
this.warn("Foundocs evaluation tracking unavailable.");
|
|
36475
|
-
return result;
|
|
36476
|
-
}
|
|
36477
|
-
if (!state || state.closed) return result;
|
|
36478
|
-
const submitted = isBatch ? args.items : [args];
|
|
36479
|
-
const tracked = submitted.filter((item) => state.retrievals.includes(item.retrievalId));
|
|
36480
|
-
if (!tracked.length) return result;
|
|
36481
|
-
state.evaluated = [.../* @__PURE__ */ new Set([...state.evaluated, ...tracked.map((item) => item.retrievalId)])];
|
|
36482
|
-
if (tracked.some((item) => item.verdict === "beneficial")) state.beneficial = true;
|
|
36483
|
-
try {
|
|
36484
|
-
await this.store.save(state);
|
|
36485
|
-
} catch {
|
|
36486
|
-
this.warn("Foundocs evaluation tracking could not be saved; no comparison started.");
|
|
36487
|
-
return result;
|
|
36488
|
-
}
|
|
36489
|
-
if (!effectTaskComplete) return result;
|
|
36490
|
-
if (state.retrievals.some((id) => !state.evaluated.includes(id))) {
|
|
36491
|
-
await this.diagnostic(state, "skipped", "incomplete_evaluation");
|
|
36492
|
-
return result;
|
|
36493
|
-
}
|
|
36494
|
-
state.closed = true;
|
|
36495
|
-
try {
|
|
36496
|
-
await this.store.save(state);
|
|
36497
|
-
} catch {
|
|
36498
|
-
this.warn("Foundocs task closure could not be saved; no comparison started.");
|
|
36499
|
-
return result;
|
|
36500
|
-
}
|
|
36501
|
-
if (!state.preparationId || !state.beneficial) {
|
|
36502
|
-
state.settled = true;
|
|
36503
|
-
await this.diagnostic(state, "skipped", state.skipped ?? "no_beneficial_retrieval");
|
|
36504
|
-
return result;
|
|
36505
|
-
}
|
|
36506
|
-
const job = this.run(state).catch(() => this.warn("Foundocs automatic measurement failed; ordinary work continues."));
|
|
36507
|
-
this.jobs.add(job);
|
|
36508
|
-
void job.finally(() => this.jobs.delete(job));
|
|
36509
|
-
return result;
|
|
36510
|
-
}
|
|
36511
|
-
async run(state) {
|
|
36512
|
-
try {
|
|
36513
|
-
const { coordinator, config: config2 } = await this.factory();
|
|
36514
|
-
if (!config2?.enabled || state.consentHash !== hash(config2)) {
|
|
36515
|
-
state.settled = true;
|
|
36516
|
-
await this.diagnostic(state, "skipped", "consent_required");
|
|
36517
|
-
return;
|
|
36518
|
-
}
|
|
36519
|
-
await this.diagnostic(state, "running");
|
|
36520
|
-
const result = await coordinator.run({ taskId: state.taskId, retrievalIds: state.retrievals });
|
|
36521
|
-
state.settled = !["report_pending"].includes(result.status);
|
|
36522
|
-
if (result.status === "reported" || result.status === "already_reported") {
|
|
36523
|
-
const failed = result.result && result.result.status !== "completed";
|
|
36524
|
-
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36525
|
-
} else await this.diagnostic(state, result.status === "report_pending" ? "failed" : "skipped", result.status === "report_pending" ? "report_pending" : safeReason(result));
|
|
36526
|
-
} catch (e) {
|
|
36527
|
-
await this.diagnostic(state, "failed", safeReason(e));
|
|
36528
|
-
}
|
|
36529
|
-
}
|
|
36530
|
-
async drain() {
|
|
36531
|
-
await this.queue;
|
|
36532
|
-
await Promise.allSettled([...this.jobs]);
|
|
36533
|
-
}
|
|
36534
|
-
};
|
|
36535
|
-
function automaticStore(base) {
|
|
36536
|
-
const path = (taskId) => {
|
|
36537
|
-
if (!UUID.test(taskId)) throw new Error("Invalid task");
|
|
36538
|
-
return join2(base, taskId, "automatic.json");
|
|
36539
|
-
};
|
|
36540
|
-
return {
|
|
36541
|
-
async list() {
|
|
36542
|
-
await privateDir(base);
|
|
36543
|
-
const result = [];
|
|
36544
|
-
for (const id of await readdir2(base)) if (UUID.test(id)) {
|
|
36545
|
-
const state = await this.load(id);
|
|
36546
|
-
if (state) result.push(state);
|
|
36547
|
-
}
|
|
36548
|
-
return result;
|
|
36549
|
-
},
|
|
36550
|
-
async load(taskId) {
|
|
36551
|
-
try {
|
|
36552
|
-
return await readJson(path(taskId));
|
|
36553
|
-
} catch (e) {
|
|
36554
|
-
if (e.code === "ENOENT") return null;
|
|
36555
|
-
throw e;
|
|
36556
|
-
}
|
|
36557
|
-
},
|
|
36558
|
-
async save(state) {
|
|
36559
|
-
await privateDir(join2(base, state.taskId));
|
|
36560
|
-
await saveJson(path(state.taskId), state);
|
|
36561
|
-
}
|
|
36562
|
-
};
|
|
36563
|
-
}
|
|
36135
|
+
import { resolve as resolve2, dirname as dirname2 } from "node:path";
|
|
36564
36136
|
|
|
36565
36137
|
// skills/foundocs/scripts/episode-checkpoint.mjs
|
|
36566
|
-
import { constants
|
|
36567
|
-
import { open as
|
|
36138
|
+
import { constants } from "node:fs";
|
|
36139
|
+
import { open as open2, mkdir, lstat as lstat2, readFile as readFile2, realpath, rename, rm } from "node:fs/promises";
|
|
36568
36140
|
import { homedir } from "node:os";
|
|
36569
|
-
import { dirname
|
|
36570
|
-
import { createHash
|
|
36141
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
36142
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
36571
36143
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
36572
|
-
var
|
|
36573
|
-
var
|
|
36144
|
+
var hash = (value) => createHash("sha256").update(value).digest("hex");
|
|
36145
|
+
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}$/i;
|
|
36574
36146
|
var TTL = 14 * 864e5;
|
|
36575
36147
|
var MAX_CHECKPOINTS = 128;
|
|
36576
36148
|
var MAX_OUTBOX = 32;
|
|
@@ -36582,22 +36154,22 @@ var unavailable = () => {
|
|
|
36582
36154
|
async function privateDirectory(path) {
|
|
36583
36155
|
if (process.platform === "win32") unavailable();
|
|
36584
36156
|
let ancestor = path;
|
|
36585
|
-
while (
|
|
36586
|
-
const st2 = await
|
|
36157
|
+
while (dirname(ancestor) !== ancestor) {
|
|
36158
|
+
const st2 = await lstat2(ancestor).catch((e) => {
|
|
36587
36159
|
if (e.code !== "ENOENT") throw e;
|
|
36588
36160
|
return null;
|
|
36589
36161
|
});
|
|
36590
36162
|
if (st2 && (!st2.isDirectory() || st2.isSymbolicLink())) unavailable();
|
|
36591
|
-
ancestor =
|
|
36163
|
+
ancestor = dirname(ancestor);
|
|
36592
36164
|
}
|
|
36593
|
-
await
|
|
36594
|
-
const st = await
|
|
36165
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
36166
|
+
const st = await lstat2(path);
|
|
36595
36167
|
if (st.mode & 63 || st.uid !== process.getuid()) unavailable();
|
|
36596
36168
|
}
|
|
36597
36169
|
async function readState(path) {
|
|
36598
36170
|
let file;
|
|
36599
36171
|
try {
|
|
36600
|
-
file = await
|
|
36172
|
+
file = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
36601
36173
|
const st = await file.stat();
|
|
36602
36174
|
if (!st.isFile() || st.nlink !== 1 || st.mode & 63 || st.uid !== process.getuid() || st.size > 3 * 1024 * 1024) unavailable();
|
|
36603
36175
|
return JSON.parse(await file.readFile("utf8"));
|
|
@@ -36609,29 +36181,29 @@ async function readState(path) {
|
|
|
36609
36181
|
}
|
|
36610
36182
|
}
|
|
36611
36183
|
async function writeState(path, state) {
|
|
36612
|
-
const temporary = `${path}.${
|
|
36184
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
36613
36185
|
let file;
|
|
36614
36186
|
try {
|
|
36615
|
-
file = await
|
|
36187
|
+
file = await open2(temporary, "wx", 384);
|
|
36616
36188
|
await file.writeFile(JSON.stringify(state));
|
|
36617
36189
|
await file.sync();
|
|
36618
36190
|
await file.close();
|
|
36619
36191
|
file = null;
|
|
36620
|
-
await
|
|
36192
|
+
await rename(temporary, path);
|
|
36621
36193
|
} finally {
|
|
36622
36194
|
await file?.close();
|
|
36623
|
-
await
|
|
36195
|
+
await rm(temporary, { force: true });
|
|
36624
36196
|
}
|
|
36625
36197
|
}
|
|
36626
36198
|
async function locked(directory, action) {
|
|
36627
|
-
const lock =
|
|
36628
|
-
const file = await
|
|
36199
|
+
const lock = join(directory, "checkpoint.lock");
|
|
36200
|
+
const file = await open2(lock, "wx", 384);
|
|
36629
36201
|
try {
|
|
36630
36202
|
await file.writeFile(String(process.pid));
|
|
36631
36203
|
return await action();
|
|
36632
36204
|
} finally {
|
|
36633
36205
|
await file.close();
|
|
36634
|
-
await
|
|
36206
|
+
await rm(lock, { force: true });
|
|
36635
36207
|
}
|
|
36636
36208
|
}
|
|
36637
36209
|
function prune(state, now) {
|
|
@@ -36662,23 +36234,23 @@ function captureInput(input, checkpoint, slot, projectId, now) {
|
|
|
36662
36234
|
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();
|
|
36663
36235
|
if (capture.event.evidence.some((e) => typeof e.detail !== "string" || e.detail.length > 1e3)) unavailable();
|
|
36664
36236
|
}
|
|
36665
|
-
return { ...capture, project_id: projectId, requestId:
|
|
36237
|
+
return { ...capture, project_id: projectId, requestId: randomUUID() };
|
|
36666
36238
|
}
|
|
36667
36239
|
async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
36668
36240
|
if (Buffer.byteLength(JSON.stringify(input)) > 1024 * 1024) unavailable();
|
|
36669
|
-
const root = await
|
|
36670
|
-
if (!
|
|
36671
|
-
const config2 = JSON.parse(await
|
|
36672
|
-
if (!
|
|
36241
|
+
const root = await realpath(rootPath);
|
|
36242
|
+
if (!isAbsolute(rootPath)) unavailable();
|
|
36243
|
+
const config2 = JSON.parse(await readFile2(join(root, "foundocs.json"), "utf8"));
|
|
36244
|
+
if (!UUID.test(config2.project_id) || options.projectId && config2.project_id !== options.projectId) unavailable();
|
|
36673
36245
|
if (config2.episodes?.enabled === false || process.env.FOUNDOCS_EPISODES === "off") return { status: "disabled" };
|
|
36674
36246
|
const client = options.client;
|
|
36675
36247
|
if (!["codex", "claude"].includes(client)) return { status: "unsupported_host" };
|
|
36676
|
-
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ??
|
|
36677
|
-
if (!
|
|
36678
|
-
const directory =
|
|
36248
|
+
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ?? join(homedir(), ".local/share/foundocs/setup");
|
|
36249
|
+
if (!isAbsolute(base)) unavailable();
|
|
36250
|
+
const directory = join(base, "episodes", hash(root));
|
|
36679
36251
|
await privateDirectory(directory);
|
|
36680
36252
|
return locked(directory, async () => {
|
|
36681
|
-
const path =
|
|
36253
|
+
const path = join(directory, "checkpoints.json"), state = await readState(path), now = options.now ?? Date.now();
|
|
36682
36254
|
if (!Array.isArray(state.checkpoints) || !Array.isArray(state.outbox)) unavailable();
|
|
36683
36255
|
const counts = [state.checkpoints.length, state.outbox.length];
|
|
36684
36256
|
prune(state, now);
|
|
@@ -36690,7 +36262,7 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36690
36262
|
let checkpoint = state.checkpoints.findLast((c) => c.sessionId === input.session_id);
|
|
36691
36263
|
if (input.hook_event_name === "UserPromptSubmit") {
|
|
36692
36264
|
if (checkpoint?.fallbackIssued && typeof input.prompt === "string" && input.prompt.startsWith("One bounded Foundocs checkpoint follow-up. ")) return null;
|
|
36693
|
-
const id = client === "codex" && safeId(input.turn_id) ?
|
|
36265
|
+
const id = client === "codex" && safeId(input.turn_id) ? hash(`${input.session_id}:${input.turn_id}`).slice(0, 40) : randomUUID();
|
|
36694
36266
|
checkpoint = state.checkpoints.find((c) => c.id === id);
|
|
36695
36267
|
if (!checkpoint) {
|
|
36696
36268
|
checkpoint = { id, sessionId: input.session_id, ...safeId(input.turn_id) ? { turnId: input.turn_id } : {}, client, createdAt: now, acknowledged: false, fallbackIssued: false };
|
|
@@ -36712,25 +36284,25 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36712
36284
|
} else if (command === "prepare") {
|
|
36713
36285
|
if (typeof input.slot !== "string" || !/^[a-z0-9_-]{1,40}$/.test(input.slot)) unavailable();
|
|
36714
36286
|
const settled = checkpoint.settled?.find((entry) => entry.slot === input.slot);
|
|
36715
|
-
if (settled) return { status: settled.inputHash ===
|
|
36287
|
+
if (settled) return { status: settled.inputHash === hash(JSON.stringify(input.capture)) ? "already_acknowledged" : "payload_conflict", requestId: settled.requestId, disposition: settled.disposition };
|
|
36716
36288
|
if ((checkpoint.settled ?? []).length >= 32) return { status: "checkpoint_full" };
|
|
36717
36289
|
const previous = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.slot === input.slot);
|
|
36718
36290
|
if (previous) {
|
|
36719
|
-
if (previous.inputHash !==
|
|
36291
|
+
if (previous.inputHash !== hash(JSON.stringify(input.capture))) return { status: "payload_conflict", requestId: previous.payload.requestId };
|
|
36720
36292
|
output = { status: "prepared", payload: previous.payload };
|
|
36721
36293
|
} else {
|
|
36722
36294
|
if (checkpoint.createdAt + TTL <= now) return { status: "checkpoint_expired" };
|
|
36723
36295
|
if (state.outbox.length >= MAX_OUTBOX) return { status: "outbox_full" };
|
|
36724
36296
|
const payload = captureInput(input.capture, checkpoint, input.slot, config2.project_id, now);
|
|
36725
36297
|
if (Buffer.byteLength(JSON.stringify(payload)) > MAX_BYTES) unavailable();
|
|
36726
|
-
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash:
|
|
36298
|
+
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash: hash(JSON.stringify(input.capture)), payload, createdAt: now });
|
|
36727
36299
|
output = { status: "prepared", payload };
|
|
36728
36300
|
}
|
|
36729
36301
|
checkpoint.acknowledged = true;
|
|
36730
36302
|
} else if (command === "ack") {
|
|
36731
36303
|
const entry = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.payload.requestId === input.requestId);
|
|
36732
36304
|
if (!entry) return { status: "request_unavailable" };
|
|
36733
|
-
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !
|
|
36305
|
+
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !UUID.test(input.result?.candidate?.id)) unavailable();
|
|
36734
36306
|
checkpoint.settled ??= [];
|
|
36735
36307
|
checkpoint.settled.push({ slot: entry.slot, inputHash: entry.inputHash, requestId: entry.payload.requestId, disposition: input.result.disposition });
|
|
36736
36308
|
state.outbox = state.outbox.filter((e) => e !== entry);
|
|
@@ -36753,15 +36325,15 @@ if (process.argv[1]?.endsWith("episode-checkpoint.mjs") && pathToFileURL2(proces
|
|
|
36753
36325
|
const [command, flag, root] = process.argv.slice(2);
|
|
36754
36326
|
let output;
|
|
36755
36327
|
try {
|
|
36756
|
-
if (flag !== "--root" || !
|
|
36757
|
-
const script = await
|
|
36758
|
-
const client = ["codex", "claude"].find((c) => script ===
|
|
36759
|
-
let
|
|
36328
|
+
if (flag !== "--root" || !isAbsolute(root)) unavailable();
|
|
36329
|
+
const script = await realpath(process.argv[1]), canonical = await realpath(root);
|
|
36330
|
+
const client = ["codex", "claude"].find((c) => script === join(canonical, c === "codex" ? ".agents" : ".claude", "skills/foundocs/scripts/episode-checkpoint.mjs"));
|
|
36331
|
+
let text = "";
|
|
36760
36332
|
for await (const chunk of process.stdin) {
|
|
36761
|
-
|
|
36762
|
-
if (Buffer.byteLength(
|
|
36333
|
+
text += chunk;
|
|
36334
|
+
if (Buffer.byteLength(text) > 1024 * 1024) unavailable();
|
|
36763
36335
|
}
|
|
36764
|
-
output = await episodeCheckpoint(command, root, JSON.parse(
|
|
36336
|
+
output = await episodeCheckpoint(command, root, JSON.parse(text), { client });
|
|
36765
36337
|
} catch {
|
|
36766
36338
|
output = command === "hook" ? null : { status: "unavailable" };
|
|
36767
36339
|
}
|
|
@@ -36831,8 +36403,7 @@ function requestError(error2, name) {
|
|
|
36831
36403
|
{ code, retryable, ...tool ? { tool } : {}, ...httpStatus !== void 0 ? { httpStatus } : {}, ...remoteCode !== void 0 ? { remoteCode } : {} }
|
|
36832
36404
|
);
|
|
36833
36405
|
}
|
|
36834
|
-
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client,
|
|
36835
|
-
let automatic, automaticSupported = false, recovered = false;
|
|
36406
|
+
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, folderProject }) {
|
|
36836
36407
|
let remote, local, checkpointRoute = "remote", checkpointWasLocal = false;
|
|
36837
36408
|
let argumentDefaults, inventoryRequest;
|
|
36838
36409
|
const checkpointTool = {
|
|
@@ -36850,7 +36421,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36850
36421
|
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false, idempotentHint: false }
|
|
36851
36422
|
};
|
|
36852
36423
|
async function close() {
|
|
36853
|
-
await automatic?.drain();
|
|
36854
36424
|
await remote?.close().catch(() => {
|
|
36855
36425
|
});
|
|
36856
36426
|
await local?.close().catch(() => {
|
|
@@ -36859,8 +36429,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36859
36429
|
function refreshToolInventory() {
|
|
36860
36430
|
if (!inventoryRequest) {
|
|
36861
36431
|
argumentDefaults = void 0;
|
|
36862
|
-
|
|
36863
|
-
inventoryRequest = remote.listTools(void 0, { cacheMode: "refresh" }).then(async ({ tools }) => {
|
|
36432
|
+
inventoryRequest = remote.listTools(void 0, { cacheMode: "refresh" }).then(({ tools }) => {
|
|
36864
36433
|
if (tools.length > 2e3) throw new Error("tool inventory exceeds bound");
|
|
36865
36434
|
const defaults = /* @__PURE__ */ new Map();
|
|
36866
36435
|
for (const { name, inputSchema } of tools) {
|
|
@@ -36875,15 +36444,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36875
36444
|
if (name === "get_project_context" && advertisesRetrievalContext(inputSchema)) options.includeRetrievalContext = true;
|
|
36876
36445
|
defaults.set(name, options);
|
|
36877
36446
|
}
|
|
36878
|
-
automaticSupported = !!automatic && ["get_effect_measurement_policy", "prepare_effect_measurement", "report_effect_diagnostic", "report_retrieval_evaluation"].every((name) => defaults.has(name));
|
|
36879
|
-
if (automaticSupported && !recovered) {
|
|
36880
|
-
try {
|
|
36881
|
-
await automatic.recover();
|
|
36882
|
-
} catch {
|
|
36883
|
-
process.stderr.write("Foundocs measurement recovery unavailable; ordinary MCP continues.\n");
|
|
36884
|
-
}
|
|
36885
|
-
recovered = true;
|
|
36886
|
-
}
|
|
36887
36447
|
argumentDefaults = defaults;
|
|
36888
36448
|
return tools;
|
|
36889
36449
|
}).finally(() => {
|
|
@@ -36920,23 +36480,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36920
36480
|
connecting = void 0;
|
|
36921
36481
|
}));
|
|
36922
36482
|
if (!folderProject) await ensureConnected();
|
|
36923
|
-
if (automaticFactory && automaticBase) automatic = new AutomaticMeasurement({
|
|
36924
|
-
projectId,
|
|
36925
|
-
factory: automaticFactory,
|
|
36926
|
-
store: automaticStore(automaticBase),
|
|
36927
|
-
warn: (message) => process.stderr.write(message + "\n"),
|
|
36928
|
-
remote: async (name, args, raw = false) => {
|
|
36929
|
-
const result = await remote.callTool({ name, arguments: { ...args, project_id: args.project_id ?? projectId } });
|
|
36930
|
-
if (raw) return result;
|
|
36931
|
-
const body = result.structuredContent ?? JSON.parse(result.content.find((c) => c.type === "text").text);
|
|
36932
|
-
if (!body.ok || result.isError) {
|
|
36933
|
-
const error2 = new Error("Measurement request failed");
|
|
36934
|
-
error2.code = body.error?.code;
|
|
36935
|
-
throw error2;
|
|
36936
|
-
}
|
|
36937
|
-
return body.data;
|
|
36938
|
-
}
|
|
36939
|
-
});
|
|
36940
36483
|
local = new Server({ name: "foundocs", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: remote?.getInstructions() });
|
|
36941
36484
|
local.setRequestHandler("tools/list", async () => {
|
|
36942
36485
|
try {
|
|
@@ -36950,7 +36493,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36950
36493
|
checkpointRoute = supported ? "local" : checkpointWasLocal ? "blocked" : "remote";
|
|
36951
36494
|
if (supported) checkpointWasLocal = true;
|
|
36952
36495
|
const visible = supported ? [...tools, checkpointTool] : checkpointRoute === "blocked" ? tools.filter((tool) => tool.name !== checkpointTool.name) : tools;
|
|
36953
|
-
return { tools:
|
|
36496
|
+
return { tools: visible };
|
|
36954
36497
|
} catch (error2) {
|
|
36955
36498
|
throw requestError(error2, "tools_list");
|
|
36956
36499
|
}
|
|
@@ -36969,7 +36512,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36969
36512
|
let data;
|
|
36970
36513
|
try {
|
|
36971
36514
|
if (checkpointRoute !== "local" || !["prepare", "ack", "skip", "pending", "discard"].includes(args.operation)) throw new Error();
|
|
36972
|
-
const storageDir =
|
|
36515
|
+
const storageDir = dirname2(dirname2(dirname2(dirname2(dirname2(credentialPath)))));
|
|
36973
36516
|
data = await episodeCheckpoint(args.operation, root, args, { client, storageDir, projectId });
|
|
36974
36517
|
} catch {
|
|
36975
36518
|
data = { status: "unavailable" };
|
|
@@ -36984,10 +36527,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36984
36527
|
const defaults = { ...argumentDefaults?.get(name) };
|
|
36985
36528
|
if (args?.view !== "index") delete defaults.includeRetrievalContext;
|
|
36986
36529
|
const params = Object.keys(defaults).length > 0 ? { ...request.params, arguments: { ...defaults, ...args } } : request.params;
|
|
36987
|
-
if (automaticSupported) return await automatic.call(params);
|
|
36988
|
-
if (args && ["effectTask", "effectTaskId", "effectTaskComplete"].some((key) => Object.hasOwn(args, key))) {
|
|
36989
|
-
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Automatic measurement metadata requires the current installer and server.");
|
|
36990
|
-
}
|
|
36991
36530
|
return await remote.callTool(params);
|
|
36992
36531
|
} catch (error2) {
|
|
36993
36532
|
throw requestError(error2, request.params.name);
|