agent-valley 2.3.1 → 3.0.0
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 +14 -5
- package/dist/assets/plugin.json +1 -1
- package/dist/assets/turso/migrations/0000_team_ledger.sql +56 -0
- package/dist/assets/turso/migrations/meta/_journal.json +13 -0
- package/dist/index.js +114511 -56313
- package/dist/supervisor.js +798 -267
- package/package.json +8 -4
package/dist/supervisor.js
CHANGED
|
@@ -828,6 +828,35 @@ function formatError(error, mapper = (issue) => issue.message) {
|
|
|
828
828
|
processError(error);
|
|
829
829
|
return fieldErrors;
|
|
830
830
|
}
|
|
831
|
+
function toDotPath(_path) {
|
|
832
|
+
const segs = [];
|
|
833
|
+
const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
834
|
+
for (const seg of path) {
|
|
835
|
+
if (typeof seg === "number")
|
|
836
|
+
segs.push(`[${seg}]`);
|
|
837
|
+
else if (typeof seg === "symbol")
|
|
838
|
+
segs.push(`[${JSON.stringify(String(seg))}]`);
|
|
839
|
+
else if (/[^\w$]/.test(seg))
|
|
840
|
+
segs.push(`[${JSON.stringify(seg)}]`);
|
|
841
|
+
else {
|
|
842
|
+
if (segs.length)
|
|
843
|
+
segs.push(".");
|
|
844
|
+
segs.push(seg);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return segs.join("");
|
|
848
|
+
}
|
|
849
|
+
function prettifyError(error) {
|
|
850
|
+
const lines = [];
|
|
851
|
+
const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
|
852
|
+
for (const issue of issues) {
|
|
853
|
+
lines.push(`✖ ${issue.message}`);
|
|
854
|
+
if (issue.path?.length)
|
|
855
|
+
lines.push(` → at ${toDotPath(issue.path)}`);
|
|
856
|
+
}
|
|
857
|
+
return lines.join(`
|
|
858
|
+
`);
|
|
859
|
+
}
|
|
831
860
|
var _messageDesc, _issuesDesc, _installedToString, initializer = (inst, def) => {
|
|
832
861
|
inst.name = "$ZodError";
|
|
833
862
|
_issuesDesc.value = def;
|
|
@@ -921,7 +950,7 @@ var _parse = (_Err) => {
|
|
|
921
950
|
return result.value;
|
|
922
951
|
};
|
|
923
952
|
return fn;
|
|
924
|
-
}, _parseAsync = (_Err) => {
|
|
953
|
+
}, parse, _parseAsync = (_Err) => {
|
|
925
954
|
const fn = async (schema, value, _ctx, params) => {
|
|
926
955
|
const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
|
|
927
956
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -935,7 +964,7 @@ var _parse = (_Err) => {
|
|
|
935
964
|
return result.value;
|
|
936
965
|
};
|
|
937
966
|
return fn;
|
|
938
|
-
}, _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
967
|
+
}, parseAsync, _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
939
968
|
const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
940
969
|
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
941
970
|
if (result instanceof Promise) {
|
|
@@ -1002,7 +1031,10 @@ var _parse = (_Err) => {
|
|
|
1002
1031
|
};
|
|
1003
1032
|
var init_parse = __esm(() => {
|
|
1004
1033
|
init_core();
|
|
1034
|
+
init_errors();
|
|
1005
1035
|
init_util();
|
|
1036
|
+
parse = /* @__PURE__ */ _parse($ZodRealError);
|
|
1037
|
+
parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
1006
1038
|
COMPILE_INVALID = /* @__PURE__ */ Symbol.for("zod.compile.invalid");
|
|
1007
1039
|
COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
1008
1040
|
});
|
|
@@ -1037,7 +1069,7 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, guid, uuid = (version) => {
|
|
|
1037
1069
|
if (!version)
|
|
1038
1070
|
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
1039
1071
|
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
1040
|
-
}, email, _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`, ipv4, ipv6, cidrv4, cidrv6, base64, base64url, httpProtocol, e164, dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`, date, anyString, integer, number, boolean, _null, lowercase, uppercase;
|
|
1072
|
+
}, email, _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`, ipv4, ipv6, cidrv4, cidrv6, base64, base64url, httpProtocol, e164, dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`, date, anyString, bigint, integer, number, boolean, _null, lowercase, uppercase;
|
|
1041
1073
|
var init_regexes = __esm(() => {
|
|
1042
1074
|
cuid = /^[cC][0-9a-z]{6,}$/;
|
|
1043
1075
|
cuid2 = /^[0-9a-z]+$/;
|
|
@@ -1058,6 +1090,7 @@ var init_regexes = __esm(() => {
|
|
|
1058
1090
|
e164 = /^\+[1-9]\d{6,14}$/;
|
|
1059
1091
|
date = /* @__PURE__ */ anchor(dateSource);
|
|
1060
1092
|
anyString = /^[\s\S]{0,}$/;
|
|
1093
|
+
bigint = /^-?\d+n?$/;
|
|
1061
1094
|
integer = /^-?\d+$/;
|
|
1062
1095
|
number = /^-?\d+(?:\.\d+)?$/;
|
|
1063
1096
|
boolean = /^(?:true|false)$/i;
|
|
@@ -1866,7 +1899,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
1866
1899
|
payload.issues.push(issue(_iss));
|
|
1867
1900
|
}
|
|
1868
1901
|
}
|
|
1869
|
-
var $ZodType, toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value }, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, URL_BAD_FORMAT = 1, URL_UNPARSEABLE = 2, asciiTabOrNewline, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, ipv6Alphabet, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, base64Charset, $ZodBase64, base64urlCharset, $ZodBase64URL, $ZodE164, $ZodJWT, $ZodNumber, $ZodNumberFormat, $ZodBoolean, $ZodNull, $ZodAny, $ZodUnknown, $ZodNever, $ZodArray, NO_SYMBOL_KEYS, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodDiscriminatedUnion, $ZodIntersection, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodPreprocess, $ZodReadonly, $ZodLazy, $ZodCustom;
|
|
1902
|
+
var $ZodType, toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value }, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, URL_BAD_FORMAT = 1, URL_UNPARSEABLE = 2, asciiTabOrNewline, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, ipv6Alphabet, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, base64Charset, $ZodBase64, base64urlCharset, $ZodBase64URL, $ZodE164, $ZodJWT, $ZodNumber, $ZodNumberFormat, $ZodBoolean, $ZodBigInt, $ZodNull, $ZodAny, $ZodUnknown, $ZodNever, $ZodDate, $ZodArray, NO_SYMBOL_KEYS, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodDiscriminatedUnion, $ZodIntersection, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodPreprocess, $ZodReadonly, $ZodLazy, $ZodCustom;
|
|
1870
1903
|
var init_schemas = __esm(() => {
|
|
1871
1904
|
init_checks();
|
|
1872
1905
|
init_core();
|
|
@@ -2282,6 +2315,25 @@ var init_schemas = __esm(() => {
|
|
|
2282
2315
|
return payload;
|
|
2283
2316
|
};
|
|
2284
2317
|
});
|
|
2318
|
+
$ZodBigInt = /* @__PURE__ */ $constructor("$ZodBigInt", (inst, def) => {
|
|
2319
|
+
$ZodType.init(inst, def);
|
|
2320
|
+
inst._zod.pattern = bigint;
|
|
2321
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2322
|
+
if (def.coerce)
|
|
2323
|
+
try {
|
|
2324
|
+
payload.value = BigInt(payload.value);
|
|
2325
|
+
} catch (_) {}
|
|
2326
|
+
if (typeof payload.value === "bigint")
|
|
2327
|
+
return payload;
|
|
2328
|
+
payload.issues.push({
|
|
2329
|
+
expected: "bigint",
|
|
2330
|
+
code: "invalid_type",
|
|
2331
|
+
input: payload.value,
|
|
2332
|
+
inst
|
|
2333
|
+
});
|
|
2334
|
+
return payload;
|
|
2335
|
+
};
|
|
2336
|
+
});
|
|
2285
2337
|
$ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
2286
2338
|
$ZodType.init(inst, def);
|
|
2287
2339
|
inst._zod.pattern = _null;
|
|
@@ -2319,6 +2371,29 @@ var init_schemas = __esm(() => {
|
|
|
2319
2371
|
return payload;
|
|
2320
2372
|
};
|
|
2321
2373
|
});
|
|
2374
|
+
$ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
2375
|
+
$ZodType.init(inst, def);
|
|
2376
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2377
|
+
if (def.coerce) {
|
|
2378
|
+
try {
|
|
2379
|
+
payload.value = new Date(payload.value);
|
|
2380
|
+
} catch (_err) {}
|
|
2381
|
+
}
|
|
2382
|
+
const input = payload.value;
|
|
2383
|
+
const isDate = input instanceof Date;
|
|
2384
|
+
const isValidDate = isDate && !Number.isNaN(input.getTime());
|
|
2385
|
+
if (isValidDate)
|
|
2386
|
+
return payload;
|
|
2387
|
+
payload.issues.push({
|
|
2388
|
+
expected: "date",
|
|
2389
|
+
code: "invalid_type",
|
|
2390
|
+
input,
|
|
2391
|
+
...isDate ? { received: "Invalid Date" } : {},
|
|
2392
|
+
inst
|
|
2393
|
+
});
|
|
2394
|
+
return payload;
|
|
2395
|
+
};
|
|
2396
|
+
});
|
|
2322
2397
|
$ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
2323
2398
|
$ZodType.init(inst, def);
|
|
2324
2399
|
const memo = globalConfig.memoizer;
|
|
@@ -3597,6 +3672,9 @@ function snapshotChecks(def) {
|
|
|
3597
3672
|
function _string(Class, params) {
|
|
3598
3673
|
return new Class(snapshotChecks({ type: "string", ...normalizeParams(params) }));
|
|
3599
3674
|
}
|
|
3675
|
+
function _coercedString(Class, params) {
|
|
3676
|
+
return new Class(snapshotChecks({ type: "string", coerce: true, ...normalizeParams(params) }));
|
|
3677
|
+
}
|
|
3600
3678
|
function _email(Class, params) {
|
|
3601
3679
|
return new Class({
|
|
3602
3680
|
type: "string",
|
|
@@ -3855,6 +3933,20 @@ function _boolean(Class, params) {
|
|
|
3855
3933
|
...normalizeParams(params)
|
|
3856
3934
|
});
|
|
3857
3935
|
}
|
|
3936
|
+
function _coercedBoolean(Class, params) {
|
|
3937
|
+
return new Class({
|
|
3938
|
+
type: "boolean",
|
|
3939
|
+
coerce: true,
|
|
3940
|
+
...normalizeParams(params)
|
|
3941
|
+
});
|
|
3942
|
+
}
|
|
3943
|
+
function _coercedBigint(Class, params) {
|
|
3944
|
+
return new Class({
|
|
3945
|
+
type: "bigint",
|
|
3946
|
+
coerce: true,
|
|
3947
|
+
...normalizeParams(params)
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3858
3950
|
function _null2(Class, params) {
|
|
3859
3951
|
return new Class({
|
|
3860
3952
|
type: "null",
|
|
@@ -3877,6 +3969,13 @@ function _never(Class, params) {
|
|
|
3877
3969
|
...normalizeParams(params)
|
|
3878
3970
|
});
|
|
3879
3971
|
}
|
|
3972
|
+
function _coercedDate(Class, params) {
|
|
3973
|
+
return new Class({
|
|
3974
|
+
type: "date",
|
|
3975
|
+
coerce: true,
|
|
3976
|
+
...normalizeParams(params)
|
|
3977
|
+
});
|
|
3978
|
+
}
|
|
3880
3979
|
function _lt(value, params) {
|
|
3881
3980
|
return new $ZodCheckLessThan({
|
|
3882
3981
|
check: "less_than",
|
|
@@ -4012,6 +4111,17 @@ function _array(Class, element, params) {
|
|
|
4012
4111
|
...normalizeParams(params)
|
|
4013
4112
|
});
|
|
4014
4113
|
}
|
|
4114
|
+
function _custom(Class, fn, _params) {
|
|
4115
|
+
const norm = normalizeParams(_params);
|
|
4116
|
+
norm.abort ?? (norm.abort = true);
|
|
4117
|
+
const schema = new Class({
|
|
4118
|
+
type: "custom",
|
|
4119
|
+
check: "custom",
|
|
4120
|
+
fn,
|
|
4121
|
+
...norm
|
|
4122
|
+
});
|
|
4123
|
+
return schema;
|
|
4124
|
+
}
|
|
4015
4125
|
function _refine(Class, fn, _params) {
|
|
4016
4126
|
const schema = new Class({
|
|
4017
4127
|
type: "custom",
|
|
@@ -5291,6 +5401,7 @@ var init_core2 = __esm(() => {
|
|
|
5291
5401
|
init_util();
|
|
5292
5402
|
init_regexes();
|
|
5293
5403
|
init_locales();
|
|
5404
|
+
init_json_schema_processors();
|
|
5294
5405
|
init_json_schema();
|
|
5295
5406
|
init_core();
|
|
5296
5407
|
init_parse();
|
|
@@ -5361,13 +5472,13 @@ var init_errors2 = __esm(() => {
|
|
|
5361
5472
|
});
|
|
5362
5473
|
|
|
5363
5474
|
// ../../node_modules/.bun/zod@4.6.5/node_modules/zod/v4/classic/parse.js
|
|
5364
|
-
var
|
|
5475
|
+
var parse3, parseAsync2, safeParse, safeParseAsync, encode, decode, encodeAsync, decodeAsync, safeEncode, safeDecode, safeEncodeAsync, safeDecodeAsync;
|
|
5365
5476
|
var init_parse2 = __esm(() => {
|
|
5366
5477
|
init_core2();
|
|
5367
5478
|
init_errors2();
|
|
5368
5479
|
init_core2();
|
|
5369
|
-
|
|
5370
|
-
|
|
5480
|
+
parse3 = /* @__PURE__ */ _parse(ZodRealError);
|
|
5481
|
+
parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
5371
5482
|
safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
5372
5483
|
safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
5373
5484
|
encode = /* @__PURE__ */ _encode(ZodRealError);
|
|
@@ -5395,6 +5506,9 @@ function string2(params) {
|
|
|
5395
5506
|
function email2(params) {
|
|
5396
5507
|
return _email(ZodEmail, params);
|
|
5397
5508
|
}
|
|
5509
|
+
function uuid2(params) {
|
|
5510
|
+
return _uuid(ZodUUID, params);
|
|
5511
|
+
}
|
|
5398
5512
|
function url(params) {
|
|
5399
5513
|
return _url(ZodURL, params);
|
|
5400
5514
|
}
|
|
@@ -5574,6 +5688,9 @@ function lazy(getter) {
|
|
|
5574
5688
|
getter
|
|
5575
5689
|
});
|
|
5576
5690
|
}
|
|
5691
|
+
function custom(fn, _params) {
|
|
5692
|
+
return _custom(ZodCustom, fn ?? (() => true), _params);
|
|
5693
|
+
}
|
|
5577
5694
|
function refine(fn, _params = {}) {
|
|
5578
5695
|
return _refine(ZodCustom, fn, _params);
|
|
5579
5696
|
}
|
|
@@ -5587,7 +5704,7 @@ function preprocess(fn, schema) {
|
|
|
5587
5704
|
out: schema
|
|
5588
5705
|
});
|
|
5589
5706
|
}
|
|
5590
|
-
var ZodType, _ZodString, ZodString, ZodStringFormat, ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration, ZodEmail, ZodGUID, ZodUUID, ZodURL, ZodEmoji, ZodNanoID, ZodCUID, ZodCUID2, ZodULID, ZodXID, ZodKSUID, ZodIPv4, ZodIPv6, ZodCIDRv4, ZodCIDRv6, ZodBase64, ZodBase64URL, ZodE164, ZodJWT, ZodNumber, ZodNumberFormat, ZodBoolean, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodArray, ZodObject, ZodUnion, ZodDiscriminatedUnion, ZodIntersection, ZodRecord, ZodEnum, ZodLiteral, ZodTransform, ZodOptional, ZodExactOptional, ZodNullable, ZodDefault, ZodPrefault, ZodNonOptional, ZodCatch, ZodPipe, ZodPreprocess, ZodReadonly, ZodLazy, ZodCustom;
|
|
5707
|
+
var ZodType, _ZodString, ZodString, ZodStringFormat, ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration, ZodEmail, ZodGUID, ZodUUID, ZodURL, ZodEmoji, ZodNanoID, ZodCUID, ZodCUID2, ZodULID, ZodXID, ZodKSUID, ZodIPv4, ZodIPv6, ZodCIDRv4, ZodCIDRv6, ZodBase64, ZodBase64URL, ZodE164, ZodJWT, ZodNumber, ZodNumberFormat, ZodBoolean, ZodBigInt, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodDate, ZodArray, ZodObject, ZodUnion, ZodDiscriminatedUnion, ZodIntersection, ZodRecord, ZodEnum, ZodLiteral, ZodTransform, ZodOptional, ZodExactOptional, ZodNullable, ZodDefault, ZodPrefault, ZodNonOptional, ZodCatch, ZodPipe, ZodPreprocess, ZodReadonly, ZodLazy, ZodCustom;
|
|
5591
5708
|
var init_schemas2 = __esm(() => {
|
|
5592
5709
|
init_core2();
|
|
5593
5710
|
init_core2();
|
|
@@ -5710,10 +5827,10 @@ var init_schemas2 = __esm(() => {
|
|
|
5710
5827
|
own(this, "~standard", value);
|
|
5711
5828
|
},
|
|
5712
5829
|
parse: function _parse(data, params) {
|
|
5713
|
-
return
|
|
5830
|
+
return parse3(this, data, params, { callee: _parse });
|
|
5714
5831
|
},
|
|
5715
5832
|
parseAsync: async function _parseAsync(data, params) {
|
|
5716
|
-
return await
|
|
5833
|
+
return await parseAsync2(this, data, params, { callee: _parseAsync });
|
|
5717
5834
|
},
|
|
5718
5835
|
safeParse(data, params) {
|
|
5719
5836
|
return safeParse(this, data, params);
|
|
@@ -6076,6 +6193,49 @@ var init_schemas2 = __esm(() => {
|
|
|
6076
6193
|
ZodType.init(inst, def);
|
|
6077
6194
|
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
|
|
6078
6195
|
});
|
|
6196
|
+
ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
|
|
6197
|
+
$ZodBigInt.init(inst, def);
|
|
6198
|
+
ZodType.init(inst, def);
|
|
6199
|
+
inst._zod.processJSONSchema = (ctx, json, params) => bigintProcessor(inst, ctx, json, params);
|
|
6200
|
+
}, /* @__PURE__ */ derived({
|
|
6201
|
+
minValue: (inst) => aggregateChecks(inst).minimum ?? null,
|
|
6202
|
+
maxValue: (inst) => aggregateChecks(inst).maximum ?? null,
|
|
6203
|
+
format: (inst) => aggregateChecks(inst).format ?? null
|
|
6204
|
+
}, {
|
|
6205
|
+
gte(value, params) {
|
|
6206
|
+
return this.check(_gte(value, params));
|
|
6207
|
+
},
|
|
6208
|
+
min(value, params) {
|
|
6209
|
+
return this.check(_gte(value, params));
|
|
6210
|
+
},
|
|
6211
|
+
gt(value, params) {
|
|
6212
|
+
return this.check(_gt(value, params));
|
|
6213
|
+
},
|
|
6214
|
+
lt(value, params) {
|
|
6215
|
+
return this.check(_lt(value, params));
|
|
6216
|
+
},
|
|
6217
|
+
lte(value, params) {
|
|
6218
|
+
return this.check(_lte(value, params));
|
|
6219
|
+
},
|
|
6220
|
+
max(value, params) {
|
|
6221
|
+
return this.check(_lte(value, params));
|
|
6222
|
+
},
|
|
6223
|
+
positive(params) {
|
|
6224
|
+
return this.check(_gt(BigInt(0), params));
|
|
6225
|
+
},
|
|
6226
|
+
negative(params) {
|
|
6227
|
+
return this.check(_lt(BigInt(0), params));
|
|
6228
|
+
},
|
|
6229
|
+
nonpositive(params) {
|
|
6230
|
+
return this.check(_lte(BigInt(0), params));
|
|
6231
|
+
},
|
|
6232
|
+
nonnegative(params) {
|
|
6233
|
+
return this.check(_gte(BigInt(0), params));
|
|
6234
|
+
},
|
|
6235
|
+
multipleOf(value, params) {
|
|
6236
|
+
return this.check(_multipleOf(value, params));
|
|
6237
|
+
}
|
|
6238
|
+
}));
|
|
6079
6239
|
ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
6080
6240
|
$ZodNull.init(inst, def);
|
|
6081
6241
|
ZodType.init(inst, def);
|
|
@@ -6096,6 +6256,22 @@ var init_schemas2 = __esm(() => {
|
|
|
6096
6256
|
ZodType.init(inst, def);
|
|
6097
6257
|
inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
|
|
6098
6258
|
});
|
|
6259
|
+
ZodDate = /* @__PURE__ */ $constructor("ZodDate", (inst, def) => {
|
|
6260
|
+
$ZodDate.init(inst, def);
|
|
6261
|
+
ZodType.init(inst, def);
|
|
6262
|
+
inst._zod.processJSONSchema = (ctx, json, params) => dateProcessor(inst, ctx, json, params);
|
|
6263
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
6264
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
6265
|
+
}, /* @__PURE__ */ derived({
|
|
6266
|
+
minDate: (inst) => {
|
|
6267
|
+
const { minimum } = aggregateChecks(inst);
|
|
6268
|
+
return minimum ? new Date(minimum) : null;
|
|
6269
|
+
},
|
|
6270
|
+
maxDate: (inst) => {
|
|
6271
|
+
const { maximum } = aggregateChecks(inst);
|
|
6272
|
+
return maximum ? new Date(maximum) : null;
|
|
6273
|
+
}
|
|
6274
|
+
}, {}));
|
|
6099
6275
|
ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
6100
6276
|
_ensureDefaultMemoizer();
|
|
6101
6277
|
$ZodArray.init(inst, def);
|
|
@@ -6402,9 +6578,29 @@ var init_iso = __esm(() => {
|
|
|
6402
6578
|
});
|
|
6403
6579
|
|
|
6404
6580
|
// ../../node_modules/.bun/zod@4.6.5/node_modules/zod/v4/classic/coerce.js
|
|
6581
|
+
var exports_coerce = {};
|
|
6582
|
+
__export(exports_coerce, {
|
|
6583
|
+
bigint: () => bigint2,
|
|
6584
|
+
boolean: () => boolean3,
|
|
6585
|
+
date: () => date3,
|
|
6586
|
+
number: () => number3,
|
|
6587
|
+
string: () => string3
|
|
6588
|
+
});
|
|
6589
|
+
function string3(params) {
|
|
6590
|
+
return _coercedString(ZodString, params);
|
|
6591
|
+
}
|
|
6405
6592
|
function number3(params) {
|
|
6406
6593
|
return _coercedNumber(ZodNumber, params);
|
|
6407
6594
|
}
|
|
6595
|
+
function boolean3(params) {
|
|
6596
|
+
return _coercedBoolean(ZodBoolean, params);
|
|
6597
|
+
}
|
|
6598
|
+
function bigint2(params) {
|
|
6599
|
+
return _coercedBigint(ZodBigInt, params);
|
|
6600
|
+
}
|
|
6601
|
+
function date3(params) {
|
|
6602
|
+
return _coercedDate(ZodDate, params);
|
|
6603
|
+
}
|
|
6408
6604
|
var init_coerce = __esm(() => {
|
|
6409
6605
|
init_core2();
|
|
6410
6606
|
init_schemas2();
|
|
@@ -6497,6 +6693,12 @@ var init_skill_matrix_schema = __esm(() => {
|
|
|
6497
6693
|
});
|
|
6498
6694
|
});
|
|
6499
6695
|
|
|
6696
|
+
// ../../packages/core/src/domain/agent.ts
|
|
6697
|
+
var AGENT_IDS;
|
|
6698
|
+
var init_agent = __esm(() => {
|
|
6699
|
+
AGENT_IDS = ["claude", "codex", "qwen", "antigravity", "cursor", "grok", "kimi", "opencode"];
|
|
6700
|
+
});
|
|
6701
|
+
|
|
6500
6702
|
// ../../packages/core/src/config/task-schema.ts
|
|
6501
6703
|
var reportPath, taskSchema, resolvedTaskSchema;
|
|
6502
6704
|
var init_task_schema = __esm(() => {
|
|
@@ -6519,8 +6721,9 @@ function normalizeActorDefaults(config) {
|
|
|
6519
6721
|
var actorTypeSchema, actorDefaultsSchema, routingRuleSchema, scoreRoutingTierSchema, scoreRoutingSchema;
|
|
6520
6722
|
var init_actor_schema = __esm(() => {
|
|
6521
6723
|
init_zod();
|
|
6724
|
+
init_agent();
|
|
6522
6725
|
init_task_schema();
|
|
6523
|
-
actorTypeSchema = _enum(
|
|
6726
|
+
actorTypeSchema = _enum(AGENT_IDS);
|
|
6524
6727
|
actorDefaultsSchema = object({
|
|
6525
6728
|
type: actorTypeSchema.optional(),
|
|
6526
6729
|
model: string2().trim().min(1).max(256).optional(),
|
|
@@ -6758,6 +6961,108 @@ var init_container_observation_policy = __esm(() => {
|
|
|
6758
6961
|
});
|
|
6759
6962
|
});
|
|
6760
6963
|
|
|
6964
|
+
// ../../packages/core/src/chief/usage.ts
|
|
6965
|
+
function startOperatingRun(mission, actor, attempt, stage, taskId, routingReason) {
|
|
6966
|
+
mission.operations ??= { runs: [], routingEvidence: [], reviewDecisions: [] };
|
|
6967
|
+
const entry = {
|
|
6968
|
+
runId: attempt.id,
|
|
6969
|
+
...taskId ? { taskId } : {},
|
|
6970
|
+
stage,
|
|
6971
|
+
actorId: actor.id,
|
|
6972
|
+
actorType: actor.agentType,
|
|
6973
|
+
...actor.model ? { model: actor.model } : {},
|
|
6974
|
+
startedAt: attempt.startedAt,
|
|
6975
|
+
finishedAt: null,
|
|
6976
|
+
elapsedMs: null,
|
|
6977
|
+
inputTokens: null,
|
|
6978
|
+
outputTokens: null,
|
|
6979
|
+
costUsd: null,
|
|
6980
|
+
outcome: "pending",
|
|
6981
|
+
executionState: "running",
|
|
6982
|
+
executionRecovery: "reconcile",
|
|
6983
|
+
...routingReason ? { routingReason } : {}
|
|
6984
|
+
};
|
|
6985
|
+
mission.operations.runs.push(entry);
|
|
6986
|
+
return entry;
|
|
6987
|
+
}
|
|
6988
|
+
function markOperatingRunUnknown(entry, reason) {
|
|
6989
|
+
entry.executionState = "unknown";
|
|
6990
|
+
entry.finishedAt = null;
|
|
6991
|
+
entry.outcome = "pending";
|
|
6992
|
+
const detail = reason?.trim();
|
|
6993
|
+
if (detail)
|
|
6994
|
+
entry.evidence = detail.slice(-2000);
|
|
6995
|
+
}
|
|
6996
|
+
function finishOperatingRun(mission, entry, attempt, failed = false) {
|
|
6997
|
+
entry.finishedAt = attempt.finishedAt ?? new Date().toISOString();
|
|
6998
|
+
const elapsed = Date.parse(entry.finishedAt) - Date.parse(entry.startedAt);
|
|
6999
|
+
entry.elapsedMs = Number.isFinite(elapsed) && elapsed >= 0 ? elapsed : null;
|
|
7000
|
+
const usage = attempt.tokenUsage;
|
|
7001
|
+
entry.costUsd = null;
|
|
7002
|
+
delete entry.actualModel;
|
|
7003
|
+
entry.inputTokens = tokens(usage?.input);
|
|
7004
|
+
entry.outputTokens = tokens(usage?.output);
|
|
7005
|
+
if (usage?.model)
|
|
7006
|
+
entry.actualModel = usage.model.slice(0, 2000);
|
|
7007
|
+
const candidate = mission.operatingPolicy?.routing?.candidates.find((item) => item.actorType === entry.actorType && item.model === entry.model);
|
|
7008
|
+
if (candidate?.inputPerMillionUsd !== undefined && candidate.outputPerMillionUsd !== undefined && entry.inputTokens !== null && entry.outputTokens !== null && (!entry.model || !entry.actualModel || entry.model === entry.actualModel)) {
|
|
7009
|
+
const estimate = (entry.inputTokens * candidate.inputPerMillionUsd + entry.outputTokens * candidate.outputPerMillionUsd) / 1e6;
|
|
7010
|
+
entry.costUsd = Number.isFinite(estimate) ? estimate : null;
|
|
7011
|
+
}
|
|
7012
|
+
if (entry.executionState === "unknown") {
|
|
7013
|
+
entry.finishedAt = null;
|
|
7014
|
+
entry.outcome = "pending";
|
|
7015
|
+
} else {
|
|
7016
|
+
entry.executionState = "settled";
|
|
7017
|
+
entry.outcome = failed ? "failed" : entry.stage === "work" ? "pending" : "passed";
|
|
7018
|
+
}
|
|
7019
|
+
}
|
|
7020
|
+
var tokens = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
7021
|
+
|
|
7022
|
+
// ../../packages/core/src/chief/contracts.ts
|
|
7023
|
+
var executionPolicySchema, executionStateSchema;
|
|
7024
|
+
var init_contracts = __esm(() => {
|
|
7025
|
+
init_zod();
|
|
7026
|
+
executionPolicySchema = strictObject({
|
|
7027
|
+
maxParallel: number2().int().min(1).max(8).default(3),
|
|
7028
|
+
maxDurationSec: number2().int().min(1).max(604800).default(86400),
|
|
7029
|
+
maxRuns: number2().int().min(1).max(2000).default(200),
|
|
7030
|
+
maxEstimatedCostUsd: number2().finite().positive().optional(),
|
|
7031
|
+
maxRetries: number2().int().min(0).max(10).default(3),
|
|
7032
|
+
retryDelayMs: number2().int().min(10).max(300000).default(1000),
|
|
7033
|
+
autoResume: boolean2().default(true)
|
|
7034
|
+
});
|
|
7035
|
+
executionStateSchema = strictObject({
|
|
7036
|
+
startedAt: exports_iso.datetime(),
|
|
7037
|
+
runsStarted: number2().int().nonnegative(),
|
|
7038
|
+
retries: number2().int().nonnegative(),
|
|
7039
|
+
crashRestarts: number2().int().nonnegative().optional(),
|
|
7040
|
+
nextRunAt: exports_iso.datetime().optional(),
|
|
7041
|
+
pauseReason: string2().max(32000).optional(),
|
|
7042
|
+
failureKind: _enum([
|
|
7043
|
+
"authentication",
|
|
7044
|
+
"rate-limit",
|
|
7045
|
+
"provider",
|
|
7046
|
+
"environment",
|
|
7047
|
+
"implementation",
|
|
7048
|
+
"unknown-effect",
|
|
7049
|
+
"budget",
|
|
7050
|
+
"interrupted",
|
|
7051
|
+
"chief-wait",
|
|
7052
|
+
"chief-unavailable",
|
|
7053
|
+
"integrity"
|
|
7054
|
+
]).optional(),
|
|
7055
|
+
progressKey: string2().optional(),
|
|
7056
|
+
interventionAt: exports_iso.datetime().optional(),
|
|
7057
|
+
costReconciliations: array(strictObject({
|
|
7058
|
+
runId: string2().min(1).max(2000),
|
|
7059
|
+
costUsd: number2().finite().nonnegative(),
|
|
7060
|
+
at: exports_iso.datetime(),
|
|
7061
|
+
authority: literal("operator-recorded")
|
|
7062
|
+
})).max(2000).optional()
|
|
7063
|
+
});
|
|
7064
|
+
});
|
|
7065
|
+
|
|
6761
7066
|
// ../../packages/core/src/chief/execution.ts
|
|
6762
7067
|
import { createHash } from "node:crypto";
|
|
6763
7068
|
function chiefRecoveryStopped(mission) {
|
|
@@ -6785,8 +7090,15 @@ function executionState(mission) {
|
|
|
6785
7090
|
}
|
|
6786
7091
|
function finalizeAbandonedRuns(mission) {
|
|
6787
7092
|
for (const run of mission.operations?.runs ?? []) {
|
|
7093
|
+
if (run.executionState === "unknown")
|
|
7094
|
+
continue;
|
|
6788
7095
|
if (run.finishedAt)
|
|
6789
7096
|
continue;
|
|
7097
|
+
if (run.executionState === "running" && run.executionRecovery !== "local-process") {
|
|
7098
|
+
markOperatingRunUnknown(run, "Coordinator ended before the runtime established a terminal outcome. Reconcile this execution before resuming.");
|
|
7099
|
+
continue;
|
|
7100
|
+
}
|
|
7101
|
+
run.executionState = "settled";
|
|
6790
7102
|
run.finishedAt = new Date().toISOString();
|
|
6791
7103
|
run.elapsedMs = Math.max(0, Date.parse(run.finishedAt) - Date.parse(run.startedAt));
|
|
6792
7104
|
run.outcome = "failed";
|
|
@@ -6796,7 +7108,37 @@ function finalizeAbandonedRuns(mission) {
|
|
|
6796
7108
|
run.evidence = "Coordinator process ended before usage could be reconciled; cost remains unknown.";
|
|
6797
7109
|
}
|
|
6798
7110
|
}
|
|
7111
|
+
function assertNoUncertainExecution(mission) {
|
|
7112
|
+
const run = mission.operations?.runs.find((entry) => entry.executionState === "unknown");
|
|
7113
|
+
if (run)
|
|
7114
|
+
throw new MissionPause(`Runtime execution ${run.runId} has an unknown outcome.${run.evidence ? ` Cause: ${run.evidence.slice(0, 1000)}.` : ""} Inspect and reconcile its saved execution record and any task effects before resuming; further Actor calls are stopped.`, "unknown-effect");
|
|
7115
|
+
}
|
|
7116
|
+
function reconcileExecution(mission, runId, evidence, authority = "operator-recorded") {
|
|
7117
|
+
const run = mission.operations?.runs.find((entry) => entry.runId === runId);
|
|
7118
|
+
const proof = evidence.trim();
|
|
7119
|
+
if (run?.executionState !== "unknown" || !proof || proof.length > 2000)
|
|
7120
|
+
throw new Error("Select an uncertain execution and record up to 2,000 characters of evidence that it stopped.");
|
|
7121
|
+
if (authority === "local-process-guard" && run.executionRecovery !== "local-process")
|
|
7122
|
+
throw new Error("A local process guard cannot reconcile a nonlocal execution. Obtain runtime termination proof.");
|
|
7123
|
+
const at = new Date().toISOString();
|
|
7124
|
+
run.executionState = "settled";
|
|
7125
|
+
run.finishedAt = at;
|
|
7126
|
+
const elapsed = Date.parse(at) - Date.parse(run.startedAt);
|
|
7127
|
+
run.elapsedMs = Number.isFinite(elapsed) && elapsed >= 0 ? elapsed : null;
|
|
7128
|
+
run.outcome = "failed";
|
|
7129
|
+
run.evidence = proof;
|
|
7130
|
+
const task = mission.tasks.find((entry) => entry.id === run.taskId);
|
|
7131
|
+
if (task?.effectState === "running")
|
|
7132
|
+
task.effectState = "unknown";
|
|
7133
|
+
mission.history.push({
|
|
7134
|
+
at,
|
|
7135
|
+
stage: "execution-reconciled",
|
|
7136
|
+
...run.taskId ? { taskId: run.taskId } : {},
|
|
7137
|
+
message: JSON.stringify({ runId, authority, evidence: proof })
|
|
7138
|
+
});
|
|
7139
|
+
}
|
|
6799
7140
|
function assertExecutionBudget(mission, now = Date.now()) {
|
|
7141
|
+
assertNoUncertainExecution(mission);
|
|
6800
7142
|
const policy = mission.executionPolicy;
|
|
6801
7143
|
if (!policy)
|
|
6802
7144
|
return;
|
|
@@ -6846,6 +7188,7 @@ function progressKey(mission, fingerprint) {
|
|
|
6846
7188
|
})).digest("hex");
|
|
6847
7189
|
}
|
|
6848
7190
|
function pauseForFailure(mission, reason, taskId) {
|
|
7191
|
+
assertNoUncertainExecution(mission);
|
|
6849
7192
|
if (!mission.executionPolicy)
|
|
6850
7193
|
return;
|
|
6851
7194
|
const task = mission.plan?.tasks.find((entry) => entry.id === taskId);
|
|
@@ -6898,47 +7241,9 @@ function resolveExternalEffect(mission, taskId, result) {
|
|
|
6898
7241
|
message: `Operator reconciled external effect: ${result}.`
|
|
6899
7242
|
});
|
|
6900
7243
|
}
|
|
6901
|
-
var
|
|
7244
|
+
var MissionPause;
|
|
6902
7245
|
var init_execution = __esm(() => {
|
|
6903
|
-
|
|
6904
|
-
executionPolicySchema = strictObject({
|
|
6905
|
-
maxParallel: number2().int().min(1).max(8).default(3),
|
|
6906
|
-
maxDurationSec: number2().int().min(1).max(604800).default(86400),
|
|
6907
|
-
maxRuns: number2().int().min(1).max(2000).default(200),
|
|
6908
|
-
maxEstimatedCostUsd: number2().finite().positive().optional(),
|
|
6909
|
-
maxRetries: number2().int().min(0).max(10).default(3),
|
|
6910
|
-
retryDelayMs: number2().int().min(10).max(300000).default(1000),
|
|
6911
|
-
autoResume: boolean2().default(true)
|
|
6912
|
-
});
|
|
6913
|
-
executionStateSchema = strictObject({
|
|
6914
|
-
startedAt: exports_iso.datetime(),
|
|
6915
|
-
runsStarted: number2().int().nonnegative(),
|
|
6916
|
-
retries: number2().int().nonnegative(),
|
|
6917
|
-
crashRestarts: number2().int().nonnegative().optional(),
|
|
6918
|
-
nextRunAt: exports_iso.datetime().optional(),
|
|
6919
|
-
pauseReason: string2().max(32000).optional(),
|
|
6920
|
-
failureKind: _enum([
|
|
6921
|
-
"authentication",
|
|
6922
|
-
"rate-limit",
|
|
6923
|
-
"provider",
|
|
6924
|
-
"environment",
|
|
6925
|
-
"implementation",
|
|
6926
|
-
"unknown-effect",
|
|
6927
|
-
"budget",
|
|
6928
|
-
"interrupted",
|
|
6929
|
-
"chief-wait",
|
|
6930
|
-
"chief-unavailable",
|
|
6931
|
-
"integrity"
|
|
6932
|
-
]).optional(),
|
|
6933
|
-
progressKey: string2().optional(),
|
|
6934
|
-
interventionAt: exports_iso.datetime().optional(),
|
|
6935
|
-
costReconciliations: array(strictObject({
|
|
6936
|
-
runId: string2().min(1).max(2000),
|
|
6937
|
-
costUsd: number2().finite().nonnegative(),
|
|
6938
|
-
at: exports_iso.datetime(),
|
|
6939
|
-
authority: literal("operator-recorded")
|
|
6940
|
-
})).max(2000).optional()
|
|
6941
|
-
});
|
|
7246
|
+
init_contracts();
|
|
6942
7247
|
MissionPause = class MissionPause extends Error {
|
|
6943
7248
|
kind;
|
|
6944
7249
|
nextRunAt;
|
|
@@ -6950,17 +7255,175 @@ var init_execution = __esm(() => {
|
|
|
6950
7255
|
};
|
|
6951
7256
|
});
|
|
6952
7257
|
|
|
7258
|
+
// ../../packages/core/src/chief/parallel-contract.ts
|
|
7259
|
+
var objectId, imageSchema, parallelBaselineSchema, parallelWorkspaceSchema, taskWorktreeRecordSchema, parallelDeliverySchema, ParallelIntegrationConflict;
|
|
7260
|
+
var init_parallel_contract = __esm(() => {
|
|
7261
|
+
init_zod();
|
|
7262
|
+
objectId = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
7263
|
+
imageSchema = strictObject({ mode: _enum(["100644", "100755", "120000"]), oid: objectId });
|
|
7264
|
+
parallelBaselineSchema = strictObject({ head: objectId, tree: objectId });
|
|
7265
|
+
parallelWorkspaceSchema = strictObject({
|
|
7266
|
+
version: literal(1),
|
|
7267
|
+
missionId: string2().min(1).max(200),
|
|
7268
|
+
taskId: string2().min(1).max(200),
|
|
7269
|
+
attempt: number2().int().min(1),
|
|
7270
|
+
sourceWorkspacePath: string2().min(1),
|
|
7271
|
+
path: string2().min(1),
|
|
7272
|
+
branch: string2().min(1),
|
|
7273
|
+
baselineHead: objectId,
|
|
7274
|
+
baselineTree: objectId
|
|
7275
|
+
});
|
|
7276
|
+
taskWorktreeRecordSchema = parallelWorkspaceSchema;
|
|
7277
|
+
parallelDeliverySchema = strictObject({
|
|
7278
|
+
version: literal(1),
|
|
7279
|
+
workspace: parallelWorkspaceSchema,
|
|
7280
|
+
patchPath: string2().min(1),
|
|
7281
|
+
patchSha256: string2().regex(/^[a-f0-9]{64}$/),
|
|
7282
|
+
deliveryTree: objectId,
|
|
7283
|
+
changes: array(strictObject({ path: string2().min(1), before: imageSchema.nullable(), after: imageSchema.nullable() })).max(20000),
|
|
7284
|
+
status: _enum(["prepared", "applying", "applied"])
|
|
7285
|
+
});
|
|
7286
|
+
ParallelIntegrationConflict = class ParallelIntegrationConflict extends Error {
|
|
7287
|
+
taskId;
|
|
7288
|
+
paths;
|
|
7289
|
+
constructor(taskId, paths, detail = "The shared worktree changed the same files.") {
|
|
7290
|
+
super(`${detail} Task ${taskId}: ${paths.join(", ")}. Its isolated Actor edits were retained; inspect them before Chief recovery.`);
|
|
7291
|
+
this.taskId = taskId;
|
|
7292
|
+
this.paths = paths;
|
|
7293
|
+
}
|
|
7294
|
+
};
|
|
7295
|
+
});
|
|
7296
|
+
|
|
7297
|
+
// ../../packages/core/src/chief/mission-state-schema.ts
|
|
7298
|
+
function refineChiefWaitSchedule(mission, ctx) {
|
|
7299
|
+
if (mission.execution?.failureKind !== "chief-wait")
|
|
7300
|
+
return;
|
|
7301
|
+
const waiting = mission.supervision?.decisions.at(-1);
|
|
7302
|
+
const at = Date.parse(waiting?.at ?? "");
|
|
7303
|
+
if (waiting?.action !== "wait" || !waiting.retryAfterSec || !Number.isFinite(at) || mission.execution.nextRunAt !== new Date(at + waiting.retryAfterSec * 1000).toISOString())
|
|
7304
|
+
ctx.addIssue({
|
|
7305
|
+
code: "custom",
|
|
7306
|
+
path: ["execution", "nextRunAt"],
|
|
7307
|
+
message: "Saved Chief wait schedule does not match its decision. Restore the original wait checkpoint without resetting its budget."
|
|
7308
|
+
});
|
|
7309
|
+
}
|
|
7310
|
+
var id, text, counter, reviewSchema, taskStateSchema, verificationSchema, advisoryReviewSchema, supervisionSchema;
|
|
7311
|
+
var init_mission_state_schema = __esm(() => {
|
|
7312
|
+
init_zod();
|
|
7313
|
+
init_parallel_contract();
|
|
7314
|
+
id = string2().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/);
|
|
7315
|
+
text = string2().trim().min(1).max(32000);
|
|
7316
|
+
counter = number2().int().min(0);
|
|
7317
|
+
reviewSchema = strictObject({
|
|
7318
|
+
passed: boolean2(),
|
|
7319
|
+
summary: text,
|
|
7320
|
+
findings: array(text).max(50),
|
|
7321
|
+
criteria: array(strictObject({ criterion: text, passed: boolean2(), evidence: text })).min(1).max(40).optional()
|
|
7322
|
+
}).superRefine((review, ctx) => {
|
|
7323
|
+
if (review.passed && review.findings.length > 0) {
|
|
7324
|
+
ctx.addIssue({ code: "custom", message: "A passing review must have no unresolved findings." });
|
|
7325
|
+
}
|
|
7326
|
+
if (!review.passed && review.findings.length === 0) {
|
|
7327
|
+
ctx.addIssue({ code: "custom", message: "A rejected review must include actionable findings." });
|
|
7328
|
+
}
|
|
7329
|
+
});
|
|
7330
|
+
taskStateSchema = strictObject({
|
|
7331
|
+
id,
|
|
7332
|
+
reviewerId: id,
|
|
7333
|
+
status: _enum(["pending", "running", "reviewing", "completed"]),
|
|
7334
|
+
attempts: counter,
|
|
7335
|
+
repairRound: counter.optional(),
|
|
7336
|
+
output: string2().max(32000).optional(),
|
|
7337
|
+
review: reviewSchema.optional(),
|
|
7338
|
+
fingerprint: text.optional(),
|
|
7339
|
+
effectState: _enum(["not-started", "running", "unknown", "completed"]).optional(),
|
|
7340
|
+
parallel: taskWorktreeRecordSchema.optional()
|
|
7341
|
+
});
|
|
7342
|
+
verificationSchema = strictObject({
|
|
7343
|
+
ok: boolean2(),
|
|
7344
|
+
output: string2().max(32000).optional(),
|
|
7345
|
+
fingerprint: text
|
|
7346
|
+
});
|
|
7347
|
+
advisoryReviewSchema = strictObject({
|
|
7348
|
+
planKey: text,
|
|
7349
|
+
reviewerId: id,
|
|
7350
|
+
fingerprint: text,
|
|
7351
|
+
review: reviewSchema
|
|
7352
|
+
});
|
|
7353
|
+
supervisionSchema = strictObject({
|
|
7354
|
+
maxRounds: number2().int().min(1).max(50),
|
|
7355
|
+
rounds: counter,
|
|
7356
|
+
stalledRounds: counter,
|
|
7357
|
+
lastFingerprint: text.optional(),
|
|
7358
|
+
originalAcceptance: array(text).min(1).max(240).optional(),
|
|
7359
|
+
operatorGoal: text.optional(),
|
|
7360
|
+
operatorVerifyCommand: string2().trim().max(32000).optional(),
|
|
7361
|
+
pendingRecovery: strictObject({ reason: text, taskId: id.optional() }).optional(),
|
|
7362
|
+
decisions: array(strictObject({
|
|
7363
|
+
round: number2().int().min(1).max(50),
|
|
7364
|
+
at: text,
|
|
7365
|
+
action: _enum(["repair", "reassign", "replan", "stop", "wait"]),
|
|
7366
|
+
retryAfterSec: number2().int().min(1).max(86400).optional(),
|
|
7367
|
+
reason: text,
|
|
7368
|
+
fingerprint: text,
|
|
7369
|
+
taskId: id.optional(),
|
|
7370
|
+
personaId: id.optional(),
|
|
7371
|
+
instructions: text.optional(),
|
|
7372
|
+
previousTasks: array(taskStateSchema).max(12).optional(),
|
|
7373
|
+
evidence: strictObject({ finalReview: reviewSchema.optional(), verification: verificationSchema.optional() }).optional()
|
|
7374
|
+
}).superRefine((decision, ctx) => {
|
|
7375
|
+
if (decision.action === "wait" !== (decision.retryAfterSec !== undefined))
|
|
7376
|
+
ctx.addIssue({
|
|
7377
|
+
code: "custom",
|
|
7378
|
+
path: ["retryAfterSec"],
|
|
7379
|
+
message: "Only a Chief wait decision must carry a bounded retry delay."
|
|
7380
|
+
});
|
|
7381
|
+
if (decision.action === "wait" && !exports_iso.datetime().safeParse(decision.at).success)
|
|
7382
|
+
ctx.addIssue({
|
|
7383
|
+
code: "custom",
|
|
7384
|
+
path: ["at"],
|
|
7385
|
+
message: "Chief wait decisions require their original ISO timestamp."
|
|
7386
|
+
});
|
|
7387
|
+
})).max(50)
|
|
7388
|
+
});
|
|
7389
|
+
});
|
|
7390
|
+
|
|
7391
|
+
// ../../packages/core/src/chief/review-gates.ts
|
|
7392
|
+
var id2, text2, reviewGateSchema, reviewGatesSchema, gateReviewSchema;
|
|
7393
|
+
var init_review_gates = __esm(() => {
|
|
7394
|
+
init_zod();
|
|
7395
|
+
init_mission_state_schema();
|
|
7396
|
+
id2 = string2().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/, "Use 1–64 letters, numbers, underscores or hyphens, starting with a letter or number.");
|
|
7397
|
+
text2 = string2().trim().min(1).max(32000);
|
|
7398
|
+
reviewGateSchema = strictObject({ id: id2, instructions: text2 });
|
|
7399
|
+
reviewGatesSchema = array(reviewGateSchema).max(8).superRefine((gates, ctx) => {
|
|
7400
|
+
if (new Set(gates.map((gate) => gate.id)).size !== gates.length)
|
|
7401
|
+
ctx.addIssue({
|
|
7402
|
+
code: "custom",
|
|
7403
|
+
message: "Chief review gate IDs must be unique. Set distinct chief.review_gates[].id values."
|
|
7404
|
+
});
|
|
7405
|
+
});
|
|
7406
|
+
gateReviewSchema = strictObject({
|
|
7407
|
+
gateId: id2,
|
|
7408
|
+
taskId: id2,
|
|
7409
|
+
reviewerId: id2,
|
|
7410
|
+
fingerprint: text2,
|
|
7411
|
+
review: reviewSchema
|
|
7412
|
+
});
|
|
7413
|
+
});
|
|
7414
|
+
|
|
6953
7415
|
// ../../packages/core/src/chief/operations.ts
|
|
6954
|
-
var actorType,
|
|
7416
|
+
var actorType, text3, amount, routingCandidateSchema, chiefOperatingPolicySchema, operatingRunSchema, routeEvidenceSchema, reviewDecisionSchema, chiefOperationsSchema;
|
|
6955
7417
|
var init_operations = __esm(() => {
|
|
6956
7418
|
init_zod();
|
|
6957
7419
|
init_skill_matrix_schema();
|
|
7420
|
+
init_review_gates();
|
|
6958
7421
|
actorType = string2().regex(/^[a-z0-9][a-z0-9-]{0,127}$/);
|
|
6959
|
-
|
|
7422
|
+
text3 = string2().trim().min(1).max(2000);
|
|
6960
7423
|
amount = number2().finite().nonnegative();
|
|
6961
7424
|
routingCandidateSchema = strictObject({
|
|
6962
7425
|
actorType,
|
|
6963
|
-
model:
|
|
7426
|
+
model: text3.optional(),
|
|
6964
7427
|
inputPerMillionUsd: amount.optional(),
|
|
6965
7428
|
outputPerMillionUsd: amount.optional()
|
|
6966
7429
|
});
|
|
@@ -6971,19 +7434,20 @@ var init_operations = __esm(() => {
|
|
|
6971
7434
|
minSuccessRate: number2().min(0).max(1)
|
|
6972
7435
|
}).optional(),
|
|
6973
7436
|
reviewVendor: _enum(["prefer", "require", "off"]),
|
|
7437
|
+
reviewGates: reviewGatesSchema.optional(),
|
|
6974
7438
|
readyActors: array(actorType).max(20).optional(),
|
|
6975
7439
|
memory: boolean2(),
|
|
6976
7440
|
skillCompatibility: skillCompatibilityPolicySchema.optional(),
|
|
6977
7441
|
metricTargets: array(strictObject({
|
|
6978
|
-
name:
|
|
6979
|
-
unit:
|
|
7442
|
+
name: text3,
|
|
7443
|
+
unit: text3.optional(),
|
|
6980
7444
|
direction: _enum(["increase", "decrease"]),
|
|
6981
7445
|
target: number2().finite().optional()
|
|
6982
7446
|
})).max(20).optional()
|
|
6983
7447
|
});
|
|
6984
7448
|
operatingRunSchema = strictObject({
|
|
6985
|
-
runId:
|
|
6986
|
-
taskId:
|
|
7449
|
+
runId: text3,
|
|
7450
|
+
taskId: text3.optional(),
|
|
6987
7451
|
stage: _enum([
|
|
6988
7452
|
"plan",
|
|
6989
7453
|
"technical-review",
|
|
@@ -6991,42 +7455,46 @@ var init_operations = __esm(() => {
|
|
|
6991
7455
|
"marketing-review",
|
|
6992
7456
|
"work",
|
|
6993
7457
|
"review",
|
|
7458
|
+
"gate-review",
|
|
6994
7459
|
"final-review",
|
|
6995
7460
|
"supervise",
|
|
6996
7461
|
"report"
|
|
6997
7462
|
]),
|
|
6998
|
-
actorId:
|
|
7463
|
+
actorId: text3,
|
|
6999
7464
|
actorType,
|
|
7000
|
-
model:
|
|
7001
|
-
actualModel:
|
|
7002
|
-
startedAt:
|
|
7003
|
-
finishedAt:
|
|
7465
|
+
model: text3.optional(),
|
|
7466
|
+
actualModel: text3.optional(),
|
|
7467
|
+
startedAt: text3,
|
|
7468
|
+
finishedAt: text3.nullable(),
|
|
7004
7469
|
elapsedMs: amount.nullable(),
|
|
7005
7470
|
inputTokens: number2().int().nonnegative().nullable(),
|
|
7006
7471
|
outputTokens: number2().int().nonnegative().nullable(),
|
|
7007
7472
|
costUsd: amount.nullable(),
|
|
7008
7473
|
outcome: _enum(["pending", "passed", "rejected", "failed"]),
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7474
|
+
executionState: _enum(["running", "settled", "unknown"]).optional(),
|
|
7475
|
+
executionRecovery: _enum(["local-process", "reconcile"]).optional(),
|
|
7476
|
+
routingReason: text3.optional(),
|
|
7477
|
+
evidence: text3.optional(),
|
|
7478
|
+
fingerprint: text3.optional()
|
|
7012
7479
|
});
|
|
7013
7480
|
routeEvidenceSchema = strictObject({
|
|
7014
7481
|
actorType,
|
|
7015
|
-
model:
|
|
7482
|
+
model: text3.optional(),
|
|
7016
7483
|
samples: number2().int().nonnegative(),
|
|
7017
7484
|
successes: number2().int().nonnegative(),
|
|
7018
7485
|
totalCostUsd: amount.nullable(),
|
|
7019
7486
|
successfulDeliverableCostUsd: amount.nullable()
|
|
7020
7487
|
}).refine((entry) => entry.successes <= entry.samples, "Route successes cannot exceed actual samples.");
|
|
7021
7488
|
reviewDecisionSchema = strictObject({
|
|
7022
|
-
taskId:
|
|
7023
|
-
|
|
7489
|
+
taskId: text3,
|
|
7490
|
+
gateId: text3.optional(),
|
|
7491
|
+
runId: text3.optional(),
|
|
7024
7492
|
workerActorType: actorType,
|
|
7025
|
-
reviewerId:
|
|
7493
|
+
reviewerId: text3,
|
|
7026
7494
|
reviewerActorType: actorType,
|
|
7027
7495
|
crossVendor: boolean2(),
|
|
7028
7496
|
outcome: _enum(["assigned", "passed", "rejected", "failed"]).optional(),
|
|
7029
|
-
reason:
|
|
7497
|
+
reason: text3
|
|
7030
7498
|
});
|
|
7031
7499
|
chiefOperationsSchema = strictObject({
|
|
7032
7500
|
runs: array(operatingRunSchema).max(20000),
|
|
@@ -7036,55 +7504,55 @@ var init_operations = __esm(() => {
|
|
|
7036
7504
|
});
|
|
7037
7505
|
|
|
7038
7506
|
// ../../packages/core/src/chief/organization-types.ts
|
|
7039
|
-
var
|
|
7507
|
+
var text4 = (maximum) => string2().trim().min(1).max(maximum), organizationTimestampSchema, metricTargetSchema, memoryEvidenceSchema, organizationMemoryInputSchema, organizationMemorySchema, businessMetricInputSchema, metricMeasurementWindowSchema, collectedBusinessMetricInputSchema, businessMetricSampleSchema, metricComparisonSchema, businessExperimentInputSchema, businessExperimentSchema, organizationOutcomeSchema, organizationContextSchema;
|
|
7040
7508
|
var init_organization_types = __esm(() => {
|
|
7041
7509
|
init_zod();
|
|
7042
7510
|
init_operations();
|
|
7043
7511
|
organizationTimestampSchema = exports_iso.datetime({ offset: true });
|
|
7044
7512
|
metricTargetSchema = strictObject({
|
|
7045
|
-
name:
|
|
7046
|
-
unit:
|
|
7513
|
+
name: text4(120),
|
|
7514
|
+
unit: text4(80).optional(),
|
|
7047
7515
|
direction: _enum(["increase", "decrease"]),
|
|
7048
7516
|
target: number2().finite().optional()
|
|
7049
7517
|
});
|
|
7050
7518
|
memoryEvidenceSchema = strictObject({
|
|
7051
|
-
path:
|
|
7519
|
+
path: text4(2000),
|
|
7052
7520
|
sha256: string2().regex(/^[a-f0-9]{64}$/),
|
|
7053
|
-
verification:
|
|
7521
|
+
verification: text4(1000).optional()
|
|
7054
7522
|
});
|
|
7055
7523
|
organizationMemoryInputSchema = strictObject({
|
|
7056
|
-
id:
|
|
7524
|
+
id: text4(120).optional(),
|
|
7057
7525
|
kind: _enum(["lesson", "decision", "stack-standard"]),
|
|
7058
|
-
content:
|
|
7059
|
-
source:
|
|
7060
|
-
tags: array(
|
|
7526
|
+
content: text4(2000),
|
|
7527
|
+
source: text4(500).default("Operator via av memory add"),
|
|
7528
|
+
tags: array(text4(80)).max(20).default([]),
|
|
7061
7529
|
evidence: array(memoryEvidenceSchema).max(20).default([])
|
|
7062
7530
|
});
|
|
7063
7531
|
organizationMemorySchema = organizationMemoryInputSchema.extend({
|
|
7064
|
-
id:
|
|
7532
|
+
id: text4(120),
|
|
7065
7533
|
approval: literal("human-approved"),
|
|
7066
7534
|
createdAt: organizationTimestampSchema
|
|
7067
7535
|
});
|
|
7068
7536
|
businessMetricInputSchema = strictObject({
|
|
7069
|
-
id:
|
|
7070
|
-
name:
|
|
7537
|
+
id: text4(120).optional(),
|
|
7538
|
+
name: text4(120),
|
|
7071
7539
|
value: number2().finite(),
|
|
7072
|
-
unit:
|
|
7073
|
-
source:
|
|
7540
|
+
unit: text4(80),
|
|
7541
|
+
source: text4(500),
|
|
7074
7542
|
timestamp: organizationTimestampSchema,
|
|
7075
7543
|
provenance: literal("operator-recorded").optional(),
|
|
7076
|
-
experimentId:
|
|
7544
|
+
experimentId: text4(120).optional()
|
|
7077
7545
|
});
|
|
7078
7546
|
metricMeasurementWindowSchema = strictObject({ start: organizationTimestampSchema, end: organizationTimestampSchema }).refine((window) => Date.parse(window.start) < Date.parse(window.end), "Measurement window must end after it starts.");
|
|
7079
7547
|
collectedBusinessMetricInputSchema = businessMetricInputSchema.omit({ provenance: true }).extend({
|
|
7080
|
-
sourceId:
|
|
7548
|
+
sourceId: text4(120),
|
|
7081
7549
|
collectedAt: organizationTimestampSchema,
|
|
7082
7550
|
window: metricMeasurementWindowSchema.optional()
|
|
7083
7551
|
});
|
|
7084
7552
|
businessMetricSampleSchema = businessMetricInputSchema.extend({
|
|
7085
|
-
id:
|
|
7553
|
+
id: text4(120),
|
|
7086
7554
|
provenance: _enum(["operator-recorded", "source-collected"]),
|
|
7087
|
-
sourceId:
|
|
7555
|
+
sourceId: text4(120).optional(),
|
|
7088
7556
|
collectedAt: organizationTimestampSchema.optional(),
|
|
7089
7557
|
window: metricMeasurementWindowSchema.optional()
|
|
7090
7558
|
}).superRefine((sample, ctx) => {
|
|
@@ -7108,8 +7576,8 @@ var init_organization_types = __esm(() => {
|
|
|
7108
7576
|
});
|
|
7109
7577
|
});
|
|
7110
7578
|
metricComparisonSchema = strictObject({
|
|
7111
|
-
name:
|
|
7112
|
-
unit:
|
|
7579
|
+
name: text4(120),
|
|
7580
|
+
unit: text4(80).optional(),
|
|
7113
7581
|
direction: _enum(["increase", "decrease"]),
|
|
7114
7582
|
target: number2().finite().optional(),
|
|
7115
7583
|
status: _enum(["improved", "regressed", "unchanged", "missing-evidence", "unit-mismatch"]),
|
|
@@ -7117,58 +7585,58 @@ var init_organization_types = __esm(() => {
|
|
|
7117
7585
|
current: businessMetricSampleSchema.optional(),
|
|
7118
7586
|
delta: number2().finite().optional(),
|
|
7119
7587
|
targetMet: boolean2().optional(),
|
|
7120
|
-
reason:
|
|
7588
|
+
reason: text4(500)
|
|
7121
7589
|
});
|
|
7122
7590
|
businessExperimentInputSchema = strictObject({
|
|
7123
|
-
id:
|
|
7124
|
-
name:
|
|
7125
|
-
hypothesis:
|
|
7591
|
+
id: text4(120),
|
|
7592
|
+
name: text4(200),
|
|
7593
|
+
hypothesis: text4(1000),
|
|
7126
7594
|
targets: array(metricTargetSchema).min(1).max(20),
|
|
7127
|
-
beforeSampleIds: array(
|
|
7128
|
-
afterSampleIds: array(
|
|
7595
|
+
beforeSampleIds: array(text4(120)).max(100),
|
|
7596
|
+
afterSampleIds: array(text4(120)).max(100),
|
|
7129
7597
|
timestamp: organizationTimestampSchema,
|
|
7130
7598
|
adjudication: strictObject({
|
|
7131
7599
|
status: _enum(["supported", "contradicted", "inconclusive"]),
|
|
7132
|
-
reason:
|
|
7133
|
-
source:
|
|
7600
|
+
reason: text4(1000),
|
|
7601
|
+
source: text4(500),
|
|
7134
7602
|
timestamp: organizationTimestampSchema
|
|
7135
7603
|
}).optional()
|
|
7136
7604
|
});
|
|
7137
7605
|
businessExperimentSchema = businessExperimentInputSchema.extend({
|
|
7138
7606
|
provenance: literal("operator-recorded"),
|
|
7139
7607
|
comparisons: array(metricComparisonSchema).max(20),
|
|
7140
|
-
omittedMetricNames: array(
|
|
7608
|
+
omittedMetricNames: array(text4(120)).max(20).optional()
|
|
7141
7609
|
});
|
|
7142
7610
|
organizationOutcomeSchema = strictObject({
|
|
7143
7611
|
id: string2().regex(/^[a-f0-9]{64}$/),
|
|
7144
|
-
missionId:
|
|
7145
|
-
missionVersion:
|
|
7612
|
+
missionId: text4(120),
|
|
7613
|
+
missionVersion: text4(200),
|
|
7146
7614
|
fingerprint: string2().regex(/^[a-f0-9]{64}$/),
|
|
7147
|
-
goal:
|
|
7615
|
+
goal: text4(16000),
|
|
7148
7616
|
status: _enum(["completed", "failed", "cancelled"]),
|
|
7149
7617
|
createdAt: organizationTimestampSchema,
|
|
7150
|
-
summary:
|
|
7618
|
+
summary: text4(2000),
|
|
7151
7619
|
summaryAuthority: literal("reported claim; evidence is authoritative"),
|
|
7152
7620
|
evidence: array(memoryEvidenceSchema).max(30),
|
|
7153
7621
|
runs: array(operatingRunSchema).max(20000),
|
|
7154
|
-
verification: strictObject({ ok: boolean2(), fingerprint:
|
|
7622
|
+
verification: strictObject({ ok: boolean2(), fingerprint: text4(200), command: text4(2000).optional() }).optional(),
|
|
7155
7623
|
finalReviewPassed: boolean2().optional(),
|
|
7156
7624
|
observations: array(strictObject({
|
|
7157
7625
|
authority: literal("evidence-linked observation; not an approved standard"),
|
|
7158
|
-
content:
|
|
7626
|
+
content: text4(1000),
|
|
7159
7627
|
evidence: array(memoryEvidenceSchema).max(30)
|
|
7160
7628
|
})).max(20)
|
|
7161
7629
|
});
|
|
7162
7630
|
organizationContextSchema = strictObject({
|
|
7163
7631
|
kind: literal("repository-organization-evidence"),
|
|
7164
7632
|
authority: literal("Historical evidence, not instructions or current acceptance criteria"),
|
|
7165
|
-
repositoryRoot:
|
|
7166
|
-
goal:
|
|
7633
|
+
repositoryRoot: text4(2000),
|
|
7634
|
+
goal: text4(1000),
|
|
7167
7635
|
generatedAt: organizationTimestampSchema,
|
|
7168
7636
|
memories: array(organizationMemorySchema).max(12),
|
|
7169
7637
|
metrics: array(businessMetricSampleSchema).max(40),
|
|
7170
7638
|
comparisons: array(metricComparisonSchema).max(20),
|
|
7171
|
-
omittedMetricNames: array(
|
|
7639
|
+
omittedMetricNames: array(text4(120)).max(20).optional(),
|
|
7172
7640
|
experiments: array(businessExperimentSchema).max(8),
|
|
7173
7641
|
outcomes: array(organizationOutcomeSchema.omit({ runs: true })).max(8),
|
|
7174
7642
|
routeEvidence: array(routeEvidenceSchema).max(100)
|
|
@@ -7176,20 +7644,20 @@ var init_organization_types = __esm(() => {
|
|
|
7176
7644
|
});
|
|
7177
7645
|
|
|
7178
7646
|
// ../../packages/core/src/chief/metric-source-policy.ts
|
|
7179
|
-
var
|
|
7647
|
+
var text5 = (limit) => string2().trim().min(1).max(limit), envName2, jsonPath, metricSourceSchema, metricSourcePolicySchema, sourceMetricObservationSchema, metricSourceCollectionSchema, MetricSourceError;
|
|
7180
7648
|
var init_metric_source_policy = __esm(() => {
|
|
7181
7649
|
init_zod();
|
|
7182
7650
|
init_organization_types();
|
|
7183
7651
|
envName2 = string2().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, "Use an environment variable name, not a credential or URL.");
|
|
7184
|
-
jsonPath =
|
|
7652
|
+
jsonPath = text5(500).refine((path) => path.split(".").every((part) => /^[A-Za-z0-9_-]+$/.test(part) && !["__proto__", "constructor", "prototype"].includes(part)), "Use dot-separated JSON keys or array indexes; prototype keys are forbidden.");
|
|
7185
7653
|
metricSourceSchema = strictObject({
|
|
7186
|
-
id:
|
|
7187
|
-
name:
|
|
7188
|
-
unit:
|
|
7189
|
-
adapter:
|
|
7654
|
+
id: text5(120),
|
|
7655
|
+
name: text5(120),
|
|
7656
|
+
unit: text5(80),
|
|
7657
|
+
adapter: text5(80).default("http-json"),
|
|
7190
7658
|
url_env: envName2.optional(),
|
|
7191
7659
|
token_env: envName2.optional(),
|
|
7192
|
-
file:
|
|
7660
|
+
file: text5(2000).optional(),
|
|
7193
7661
|
value_path: jsonPath.default("value"),
|
|
7194
7662
|
timestamp_path: jsonPath.default("timestamp"),
|
|
7195
7663
|
unit_path: jsonPath.default("unit"),
|
|
@@ -7233,7 +7701,7 @@ var init_metric_source_policy = __esm(() => {
|
|
|
7233
7701
|
});
|
|
7234
7702
|
sourceMetricObservationSchema = strictObject({
|
|
7235
7703
|
value: number2().finite(),
|
|
7236
|
-
unit:
|
|
7704
|
+
unit: text5(80),
|
|
7237
7705
|
timestamp: organizationTimestampSchema,
|
|
7238
7706
|
window: metricMeasurementWindowSchema.optional()
|
|
7239
7707
|
});
|
|
@@ -7241,11 +7709,11 @@ var init_metric_source_policy = __esm(() => {
|
|
|
7241
7709
|
collectedAt: organizationTimestampSchema,
|
|
7242
7710
|
nextPollAt: organizationTimestampSchema,
|
|
7243
7711
|
results: array(strictObject({
|
|
7244
|
-
sourceId:
|
|
7245
|
-
name:
|
|
7712
|
+
sourceId: text5(120),
|
|
7713
|
+
name: text5(120),
|
|
7246
7714
|
status: _enum(["collected", "unchanged", "unavailable", "failed"]),
|
|
7247
7715
|
sample: businessMetricSampleSchema.optional(),
|
|
7248
|
-
reason:
|
|
7716
|
+
reason: text5(1000).optional()
|
|
7249
7717
|
})).max(20)
|
|
7250
7718
|
});
|
|
7251
7719
|
MetricSourceError = class MetricSourceError extends Error {
|
|
@@ -7305,6 +7773,7 @@ function chiefOperatingPolicy(config, readyActors, automatic = true, skillCompat
|
|
|
7305
7773
|
minSuccessRate: config.routing.min_success_rate
|
|
7306
7774
|
} : automatic && readyActors.length > 1 ? { candidates: readyActors.map((actorType) => ({ actorType })), minSamples: 3, minSuccessRate: 0.8 } : undefined,
|
|
7307
7775
|
reviewVendor: config.review_vendor ?? "prefer",
|
|
7776
|
+
reviewGates: config.review_gates,
|
|
7308
7777
|
memory: config.memory ?? true,
|
|
7309
7778
|
metricTargets: config.metric_targets,
|
|
7310
7779
|
readyActors,
|
|
@@ -7335,6 +7804,7 @@ var init_chief_schema = __esm(() => {
|
|
|
7335
7804
|
init_operations();
|
|
7336
7805
|
init_organization_types();
|
|
7337
7806
|
init_report_delivery_contract();
|
|
7807
|
+
init_review_gates();
|
|
7338
7808
|
init_tool_environment();
|
|
7339
7809
|
price = number2().finite().nonnegative().optional();
|
|
7340
7810
|
chiefConfigSchema = strictObject({
|
|
@@ -7361,6 +7831,7 @@ var init_chief_schema = __esm(() => {
|
|
|
7361
7831
|
min_success_rate: number2().min(0).max(1).default(0.8)
|
|
7362
7832
|
}).optional(),
|
|
7363
7833
|
review_vendor: _enum(["prefer", "require", "off"]).optional(),
|
|
7834
|
+
review_gates: reviewGatesSchema.optional(),
|
|
7364
7835
|
memory: boolean2().optional(),
|
|
7365
7836
|
metric_targets: array(metricTargetSchema).max(20).optional(),
|
|
7366
7837
|
reporting: reportDeliveryPolicySchema.optional(),
|
|
@@ -7448,6 +7919,67 @@ function resolveProjectConfigPath(root) {
|
|
|
7448
7919
|
var PROJECT_CONFIG_FILENAME = "av.yaml";
|
|
7449
7920
|
var init_project_config_path = () => {};
|
|
7450
7921
|
|
|
7922
|
+
// ../../packages/core/src/config/team-schema.ts
|
|
7923
|
+
function normalizeTeamRelayUrl(value) {
|
|
7924
|
+
const input = value.trim();
|
|
7925
|
+
let url;
|
|
7926
|
+
try {
|
|
7927
|
+
url = new URL(input);
|
|
7928
|
+
} catch {
|
|
7929
|
+
throw new Error("Set team.relay_url to an absolute HTTPS URL (HTTP is allowed only on loopback).");
|
|
7930
|
+
}
|
|
7931
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
7932
|
+
if ([...input].some((character) => character.charCodeAt(0) <= 32 || character.charCodeAt(0) === 127) || url.protocol !== "https:" && !(url.protocol === "http:" && loopback) || url.username || url.password || input.includes("?") || input.includes("#")) {
|
|
7933
|
+
throw new Error("Set team.relay_url to HTTPS or loopback HTTP, without credentials, a query or a fragment.");
|
|
7934
|
+
}
|
|
7935
|
+
return url.href.replace(/\/+$/, "");
|
|
7936
|
+
}
|
|
7937
|
+
function assertTeamConfigMigrated(raw, path) {
|
|
7938
|
+
const team = raw.team;
|
|
7939
|
+
if (typeof team !== "object" || team === null)
|
|
7940
|
+
return;
|
|
7941
|
+
const keys = ["supabase_url", "supabase_anon_key"].filter((key) => Object.hasOwn(team, key));
|
|
7942
|
+
if (keys.length)
|
|
7943
|
+
throw new TeamConfigMigrationError(keys, path);
|
|
7944
|
+
}
|
|
7945
|
+
var teamRelayUrlSchema, legacyTeamMigration, teamConfigSchema, TeamConfigMigrationError;
|
|
7946
|
+
var init_team_schema = __esm(() => {
|
|
7947
|
+
init_zod();
|
|
7948
|
+
teamRelayUrlSchema = string2().transform((value, context) => {
|
|
7949
|
+
try {
|
|
7950
|
+
return normalizeTeamRelayUrl(value);
|
|
7951
|
+
} catch (error) {
|
|
7952
|
+
context.addIssue({ code: "custom", message: error.message });
|
|
7953
|
+
return NEVER;
|
|
7954
|
+
}
|
|
7955
|
+
});
|
|
7956
|
+
legacyTeamMigration = "is no longer supported. Remove this key from av.yaml or ~/.config/agent-valley/settings.yaml; " + "set team.relay_url and team.id for clients, and team.turso_url plus team.turso_auth_token_env on the central server. " + "Keep the Turso database token on the server and run 'av login' with a user team token.";
|
|
7957
|
+
teamConfigSchema = object({
|
|
7958
|
+
relay_url: teamRelayUrlSchema.optional(),
|
|
7959
|
+
turso_url: string2().trim().min(1).optional(),
|
|
7960
|
+
turso_auth_token_env: string2().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).optional(),
|
|
7961
|
+
id: uuid2({
|
|
7962
|
+
error: "Set team.id in av.yaml or ~/.config/agent-valley/settings.yaml to the team UUID supplied by your administrator."
|
|
7963
|
+
}).optional(),
|
|
7964
|
+
display_name: string2().min(1).optional(),
|
|
7965
|
+
supabase_url: unknown().optional(),
|
|
7966
|
+
supabase_anon_key: unknown().optional()
|
|
7967
|
+
}).strict().superRefine((team, context) => {
|
|
7968
|
+
for (const key of ["supabase_url", "supabase_anon_key"]) {
|
|
7969
|
+
if (Object.hasOwn(team, key))
|
|
7970
|
+
context.addIssue({ code: "custom", path: [key], message: `team.${key} ${legacyTeamMigration}` });
|
|
7971
|
+
}
|
|
7972
|
+
}).transform(({ supabase_url: _url, supabase_anon_key: _key, ...team }) => team);
|
|
7973
|
+
TeamConfigMigrationError = class TeamConfigMigrationError extends Error {
|
|
7974
|
+
constructor(keys, path) {
|
|
7975
|
+
super(`Team config migration required (${path}):
|
|
7976
|
+
${keys.map((key) => ` - team.${key} ${legacyTeamMigration}`).join(`
|
|
7977
|
+
`)}`);
|
|
7978
|
+
this.name = "TeamConfigMigrationError";
|
|
7979
|
+
}
|
|
7980
|
+
};
|
|
7981
|
+
});
|
|
7982
|
+
|
|
7451
7983
|
// ../../packages/core/src/config/tunnel-schema.ts
|
|
7452
7984
|
function buildTunnelConfig(project) {
|
|
7453
7985
|
const tunnel = project?.tunnel;
|
|
@@ -14540,6 +15072,7 @@ function loadGlobalConfig(configPath) {
|
|
|
14540
15072
|
const raw = readYamlFile(path);
|
|
14541
15073
|
if (!raw)
|
|
14542
15074
|
return null;
|
|
15075
|
+
assertTeamConfigMigrated(raw, path);
|
|
14543
15076
|
const result = globalConfigSchema.safeParse(raw);
|
|
14544
15077
|
if (!result.success) {
|
|
14545
15078
|
const issues = result.error.issues.map((e) => ` - ${e.path.join(".")}: ${e.message}`).join(`
|
|
@@ -14555,6 +15088,7 @@ function loadProjectConfig(projectRoot) {
|
|
|
14555
15088
|
const raw = readYamlFile(path);
|
|
14556
15089
|
if (!raw)
|
|
14557
15090
|
return null;
|
|
15091
|
+
assertTeamConfigMigrated(raw, path);
|
|
14558
15092
|
const result = projectConfigSchema.safeParse(raw);
|
|
14559
15093
|
if (!result.success) {
|
|
14560
15094
|
const issues = result.error.issues.map((e) => ` - ${e.path.join(".")}: ${e.message}`).join(`
|
|
@@ -14585,21 +15119,24 @@ function mergeConfigs(global, project, env) {
|
|
|
14585
15119
|
trackerKind = "github";
|
|
14586
15120
|
}
|
|
14587
15121
|
let githubMerged;
|
|
15122
|
+
let githubWorkflowStates = null;
|
|
14588
15123
|
if (trackerKind === "github" && project?.github) {
|
|
14589
15124
|
const envName = project.github.token_env ?? "GITHUB_TOKEN";
|
|
14590
15125
|
const token = env[envName] ?? "";
|
|
15126
|
+
const labels = {
|
|
15127
|
+
todo: project.github.labels?.todo ?? "",
|
|
15128
|
+
inProgress: project.github.labels?.in_progress ?? "",
|
|
15129
|
+
done: project.github.labels?.done ?? "",
|
|
15130
|
+
cancelled: project.github.labels?.cancelled ?? ""
|
|
15131
|
+
};
|
|
14591
15132
|
githubMerged = {
|
|
14592
15133
|
token,
|
|
14593
15134
|
owner: project.github.owner ?? "",
|
|
14594
15135
|
repo: project.github.repo ?? "",
|
|
14595
15136
|
webhookSecret: project.github.webhook_secret ?? "",
|
|
14596
|
-
labels
|
|
14597
|
-
todo: project.github.labels?.todo ?? "",
|
|
14598
|
-
inProgress: project.github.labels?.in_progress ?? "",
|
|
14599
|
-
done: project.github.labels?.done ?? "",
|
|
14600
|
-
cancelled: project.github.labels?.cancelled ?? ""
|
|
14601
|
-
}
|
|
15137
|
+
labels
|
|
14602
15138
|
};
|
|
15139
|
+
githubWorkflowStates = labels;
|
|
14603
15140
|
}
|
|
14604
15141
|
return {
|
|
14605
15142
|
trackerKind,
|
|
@@ -14607,7 +15144,7 @@ function mergeConfigs(global, project, env) {
|
|
|
14607
15144
|
linearTeamId: project?.linear?.team_id ?? "",
|
|
14608
15145
|
linearTeamUuid: project?.linear?.team_uuid ?? "",
|
|
14609
15146
|
linearWebhookSecret: project?.linear?.webhook_secret ?? "",
|
|
14610
|
-
workflowStates: {
|
|
15147
|
+
workflowStates: githubWorkflowStates ?? {
|
|
14611
15148
|
todo: project?.linear?.workflow_states?.todo ?? "",
|
|
14612
15149
|
inProgress: project?.linear?.workflow_states?.in_progress ?? "",
|
|
14613
15150
|
done: project?.linear?.workflow_states?.done ?? "",
|
|
@@ -14635,8 +15172,9 @@ function mergeConfigs(global, project, env) {
|
|
|
14635
15172
|
})),
|
|
14636
15173
|
scoringModel: project?.scoring?.model ?? undefined,
|
|
14637
15174
|
scoreRouting: project?.scoring?.routes ?? undefined,
|
|
14638
|
-
|
|
14639
|
-
|
|
15175
|
+
teamRelayUrl: project?.team?.relay_url ?? global?.team?.relay_url ?? undefined,
|
|
15176
|
+
tursoUrl: project?.team?.turso_url ?? global?.team?.turso_url ?? undefined,
|
|
15177
|
+
tursoAuthTokenEnv: project?.team?.turso_auth_token_env ?? global?.team?.turso_auth_token_env ?? "TURSO_AUTH_TOKEN",
|
|
14640
15178
|
teamId: project?.team?.id ?? global?.team?.id ?? undefined,
|
|
14641
15179
|
displayName: project?.team?.display_name ?? global?.team?.display_name ?? undefined,
|
|
14642
15180
|
observability: buildObservabilityConfig(project),
|
|
@@ -14690,6 +15228,7 @@ var init_yaml_loader = __esm(() => {
|
|
|
14690
15228
|
init_observability_schema();
|
|
14691
15229
|
init_project_config_path();
|
|
14692
15230
|
init_task_schema();
|
|
15231
|
+
init_team_schema();
|
|
14693
15232
|
init_tunnel_schema();
|
|
14694
15233
|
init_verify_schema();
|
|
14695
15234
|
init_yaml_file();
|
|
@@ -14707,12 +15246,7 @@ var init_yaml_loader = __esm(() => {
|
|
|
14707
15246
|
server: object({
|
|
14708
15247
|
port: number2().int().min(1).max(65535).optional()
|
|
14709
15248
|
}).optional(),
|
|
14710
|
-
team:
|
|
14711
|
-
supabase_url: string2().optional(),
|
|
14712
|
-
supabase_anon_key: string2().optional(),
|
|
14713
|
-
id: string2().optional(),
|
|
14714
|
-
display_name: string2().optional()
|
|
14715
|
-
}).optional()
|
|
15249
|
+
team: teamConfigSchema.optional()
|
|
14716
15250
|
}).strict().overwrite(normalizeActorDefaults);
|
|
14717
15251
|
projectConfigSchema = object({
|
|
14718
15252
|
tracker: object({
|
|
@@ -14765,12 +15299,7 @@ var init_yaml_loader = __esm(() => {
|
|
|
14765
15299
|
model: string2().optional(),
|
|
14766
15300
|
routes: scoreRoutingSchema.optional()
|
|
14767
15301
|
}).optional(),
|
|
14768
|
-
team:
|
|
14769
|
-
supabase_url: string2().optional(),
|
|
14770
|
-
supabase_anon_key: string2().optional(),
|
|
14771
|
-
id: string2().optional(),
|
|
14772
|
-
display_name: string2().optional()
|
|
14773
|
-
}).optional(),
|
|
15302
|
+
team: teamConfigSchema.optional(),
|
|
14774
15303
|
observability: observabilityProjectSchema,
|
|
14775
15304
|
budget: budgetProjectSchema,
|
|
14776
15305
|
tunnel: tunnelProjectSchema,
|
|
@@ -14836,9 +15365,12 @@ var init_yaml_loader = __esm(() => {
|
|
|
14836
15365
|
})),
|
|
14837
15366
|
scoringModel: string2().optional(),
|
|
14838
15367
|
scoreRouting: scoreRoutingSchema.optional(),
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
|
|
15368
|
+
teamRelayUrl: teamRelayUrlSchema.optional(),
|
|
15369
|
+
tursoUrl: string2().min(1).optional(),
|
|
15370
|
+
tursoAuthTokenEnv: string2().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).optional(),
|
|
15371
|
+
teamId: uuid2({
|
|
15372
|
+
error: "Set team.id in av.yaml or ~/.config/agent-valley/settings.yaml to the team UUID supplied by your administrator."
|
|
15373
|
+
}).optional(),
|
|
14842
15374
|
displayName: string2().optional(),
|
|
14843
15375
|
observability: observabilityMergedSchema,
|
|
14844
15376
|
budget: budgetMergedSchema,
|
|
@@ -15038,127 +15570,6 @@ var init_types = __esm(() => {
|
|
|
15038
15570
|
});
|
|
15039
15571
|
});
|
|
15040
15572
|
|
|
15041
|
-
// ../../packages/core/src/tracker/linear-webhook-client.ts
|
|
15042
|
-
function isPermissionErrorMessage(message) {
|
|
15043
|
-
return /permission|forbidden|not authorized|unauthorized|scope/i.test(message);
|
|
15044
|
-
}
|
|
15045
|
-
function webhookPermissionError(action, cause) {
|
|
15046
|
-
return new Error(`Linear API key lacks permission to ${action} webhooks.
|
|
15047
|
-
` + " Fix: regenerate your Linear API key at https://linear.app/settings/api with webhook create/manage " + "scope, update LINEAR_API_KEY, then re-run `av up`.\n" + ` Underlying error: ${cause}`);
|
|
15048
|
-
}
|
|
15049
|
-
async function findExistingWebhook(apiKey, teamId, url, label) {
|
|
15050
|
-
try {
|
|
15051
|
-
const data = await linearGraphQL(apiKey, LIST_WEBHOOKS_QUERY, { teamId });
|
|
15052
|
-
const parsed = listWebhooksDataSchema.safeParse(data);
|
|
15053
|
-
if (!parsed.success) {
|
|
15054
|
-
throw new Error(`Linear webhooks response validation failed: ${parsed.error.message}`);
|
|
15055
|
-
}
|
|
15056
|
-
const nodes = parsed.data.webhooks?.nodes ?? [];
|
|
15057
|
-
return nodes.find((w) => w.label === label) ?? nodes.find((w) => w.url === url);
|
|
15058
|
-
} catch (err) {
|
|
15059
|
-
const msg = err.message;
|
|
15060
|
-
if (isPermissionErrorMessage(msg))
|
|
15061
|
-
throw webhookPermissionError("list", msg);
|
|
15062
|
-
throw err;
|
|
15063
|
-
}
|
|
15064
|
-
}
|
|
15065
|
-
async function upsertWebhook(params) {
|
|
15066
|
-
const label = params.label ?? WEBHOOK_LABEL;
|
|
15067
|
-
const existing = await findExistingWebhook(params.apiKey, params.teamId, params.url, label);
|
|
15068
|
-
if (existing) {
|
|
15069
|
-
try {
|
|
15070
|
-
const data = await linearGraphQL(params.apiKey, UPDATE_WEBHOOK_MUTATION, {
|
|
15071
|
-
id: existing.id,
|
|
15072
|
-
url: params.url,
|
|
15073
|
-
enabled: true
|
|
15074
|
-
});
|
|
15075
|
-
const parsed = webhookUpdateDataSchema.safeParse(data);
|
|
15076
|
-
const webhook = parsed.success ? parsed.data.webhookUpdate?.webhook : undefined;
|
|
15077
|
-
if (!parsed.success || !parsed.data.webhookUpdate?.success || !webhook) {
|
|
15078
|
-
throw new Error(`Failed to update Linear webhook: id=${existing.id}, url=${params.url}
|
|
15079
|
-
` + " Fix: verify LINEAR_API_KEY still has webhook manage permission for this team.");
|
|
15080
|
-
}
|
|
15081
|
-
logger.info("tracker-client", "Updated Linear webhook", { teamId: params.teamId, webhookId: webhook.id });
|
|
15082
|
-
return webhook;
|
|
15083
|
-
} catch (err) {
|
|
15084
|
-
const msg = err.message;
|
|
15085
|
-
if (isPermissionErrorMessage(msg))
|
|
15086
|
-
throw webhookPermissionError("update", msg);
|
|
15087
|
-
throw err;
|
|
15088
|
-
}
|
|
15089
|
-
}
|
|
15090
|
-
try {
|
|
15091
|
-
const data = await linearGraphQL(params.apiKey, CREATE_WEBHOOK_MUTATION, {
|
|
15092
|
-
teamId: params.teamId,
|
|
15093
|
-
url: params.url,
|
|
15094
|
-
secret: params.secret,
|
|
15095
|
-
label
|
|
15096
|
-
});
|
|
15097
|
-
const parsed = webhookCreateDataSchema.safeParse(data);
|
|
15098
|
-
const webhook = parsed.success ? parsed.data.webhookCreate?.webhook : undefined;
|
|
15099
|
-
if (!parsed.success || !parsed.data.webhookCreate?.success || !webhook) {
|
|
15100
|
-
throw new Error(`Failed to create Linear webhook: teamId=${params.teamId}, url=${params.url}
|
|
15101
|
-
` + " Fix: verify LINEAR_API_KEY has webhook create permission for this team. Regenerate at " + "https://linear.app/settings/api if needed.");
|
|
15102
|
-
}
|
|
15103
|
-
logger.info("tracker-client", "Created Linear webhook", { teamId: params.teamId, webhookId: webhook.id });
|
|
15104
|
-
return webhook;
|
|
15105
|
-
} catch (err) {
|
|
15106
|
-
const msg = err.message;
|
|
15107
|
-
if (isPermissionErrorMessage(msg))
|
|
15108
|
-
throw webhookPermissionError("create", msg);
|
|
15109
|
-
throw err;
|
|
15110
|
-
}
|
|
15111
|
-
}
|
|
15112
|
-
var WEBHOOK_LABEL = "agent-valley", webhookNodeSchema, listWebhooksDataSchema, webhookCreateDataSchema, webhookUpdateDataSchema, LIST_WEBHOOKS_QUERY = `
|
|
15113
|
-
query ListWebhooks($teamId: String!) {
|
|
15114
|
-
webhooks(filter: { team: { id: { eq: $teamId } } }) {
|
|
15115
|
-
nodes { id url label enabled }
|
|
15116
|
-
}
|
|
15117
|
-
}
|
|
15118
|
-
`, CREATE_WEBHOOK_MUTATION = `
|
|
15119
|
-
mutation CreateWebhook($teamId: String!, $url: String!, $secret: String!, $label: String!) {
|
|
15120
|
-
webhookCreate(input: { teamId: $teamId, url: $url, secret: $secret, label: $label, resourceTypes: ["Issue"], enabled: true }) {
|
|
15121
|
-
success
|
|
15122
|
-
webhook { id url label enabled }
|
|
15123
|
-
}
|
|
15124
|
-
}
|
|
15125
|
-
`, UPDATE_WEBHOOK_MUTATION = `
|
|
15126
|
-
mutation UpdateWebhook($id: String!, $url: String!, $enabled: Boolean!) {
|
|
15127
|
-
webhookUpdate(id: $id, input: { url: $url, enabled: $enabled }) {
|
|
15128
|
-
success
|
|
15129
|
-
webhook { id url label enabled }
|
|
15130
|
-
}
|
|
15131
|
-
}
|
|
15132
|
-
`;
|
|
15133
|
-
var init_linear_webhook_client = __esm(() => {
|
|
15134
|
-
init_zod();
|
|
15135
|
-
init_logger();
|
|
15136
|
-
init_linear_client();
|
|
15137
|
-
webhookNodeSchema = object({
|
|
15138
|
-
id: string2(),
|
|
15139
|
-
url: string2(),
|
|
15140
|
-
label: string2().nullable().optional(),
|
|
15141
|
-
enabled: boolean2()
|
|
15142
|
-
});
|
|
15143
|
-
listWebhooksDataSchema = object({
|
|
15144
|
-
webhooks: object({
|
|
15145
|
-
nodes: array(webhookNodeSchema)
|
|
15146
|
-
}).optional()
|
|
15147
|
-
});
|
|
15148
|
-
webhookCreateDataSchema = object({
|
|
15149
|
-
webhookCreate: object({
|
|
15150
|
-
success: boolean2(),
|
|
15151
|
-
webhook: webhookNodeSchema.optional()
|
|
15152
|
-
}).optional()
|
|
15153
|
-
});
|
|
15154
|
-
webhookUpdateDataSchema = object({
|
|
15155
|
-
webhookUpdate: object({
|
|
15156
|
-
success: boolean2(),
|
|
15157
|
-
webhook: webhookNodeSchema.optional()
|
|
15158
|
-
}).optional()
|
|
15159
|
-
});
|
|
15160
|
-
});
|
|
15161
|
-
|
|
15162
15573
|
// ../../packages/core/src/tracker/linear-client.ts
|
|
15163
15574
|
import { request as httpsRequest } from "node:https";
|
|
15164
15575
|
function postGraphQLWithNodeHttps(apiKey, query, variables) {
|
|
@@ -15317,7 +15728,6 @@ var init_linear_client = __esm(() => {
|
|
|
15317
15728
|
init_logger();
|
|
15318
15729
|
init_linear_issue_mapper();
|
|
15319
15730
|
init_types();
|
|
15320
|
-
init_linear_webhook_client();
|
|
15321
15731
|
ISSUES_BY_STATE_QUERY = `
|
|
15322
15732
|
query GetIssuesByState($teamId: String!, $stateIds: [ID!]!, $cursor: String) {
|
|
15323
15733
|
team(id: $teamId) {
|
|
@@ -15341,6 +15751,127 @@ query GetIssuesByState($teamId: String!, $stateIds: [ID!]!, $cursor: String) {
|
|
|
15341
15751
|
`;
|
|
15342
15752
|
});
|
|
15343
15753
|
|
|
15754
|
+
// ../../packages/core/src/tracker/linear-webhook-client.ts
|
|
15755
|
+
function isPermissionErrorMessage(message) {
|
|
15756
|
+
return /permission|forbidden|not authorized|unauthorized|scope/i.test(message);
|
|
15757
|
+
}
|
|
15758
|
+
function webhookPermissionError(action, cause) {
|
|
15759
|
+
return new Error(`Linear API key lacks permission to ${action} webhooks.
|
|
15760
|
+
` + " Fix: regenerate your Linear API key at https://linear.app/settings/api with webhook create/manage " + "scope, update LINEAR_API_KEY, then re-run `av up`.\n" + ` Underlying error: ${cause}`);
|
|
15761
|
+
}
|
|
15762
|
+
async function findExistingWebhook(apiKey, teamId, url, label) {
|
|
15763
|
+
try {
|
|
15764
|
+
const data = await linearGraphQL(apiKey, LIST_WEBHOOKS_QUERY, { teamId });
|
|
15765
|
+
const parsed = listWebhooksDataSchema.safeParse(data);
|
|
15766
|
+
if (!parsed.success) {
|
|
15767
|
+
throw new Error(`Linear webhooks response validation failed: ${parsed.error.message}`);
|
|
15768
|
+
}
|
|
15769
|
+
const nodes = parsed.data.webhooks?.nodes ?? [];
|
|
15770
|
+
return nodes.find((w) => w.label === label) ?? nodes.find((w) => w.url === url);
|
|
15771
|
+
} catch (err) {
|
|
15772
|
+
const msg = err.message;
|
|
15773
|
+
if (isPermissionErrorMessage(msg))
|
|
15774
|
+
throw webhookPermissionError("list", msg);
|
|
15775
|
+
throw err;
|
|
15776
|
+
}
|
|
15777
|
+
}
|
|
15778
|
+
async function upsertWebhook(params) {
|
|
15779
|
+
const label = params.label ?? WEBHOOK_LABEL;
|
|
15780
|
+
const existing = await findExistingWebhook(params.apiKey, params.teamId, params.url, label);
|
|
15781
|
+
if (existing) {
|
|
15782
|
+
try {
|
|
15783
|
+
const data = await linearGraphQL(params.apiKey, UPDATE_WEBHOOK_MUTATION, {
|
|
15784
|
+
id: existing.id,
|
|
15785
|
+
url: params.url,
|
|
15786
|
+
enabled: true
|
|
15787
|
+
});
|
|
15788
|
+
const parsed = webhookUpdateDataSchema.safeParse(data);
|
|
15789
|
+
const webhook = parsed.success ? parsed.data.webhookUpdate?.webhook : undefined;
|
|
15790
|
+
if (!parsed.success || !parsed.data.webhookUpdate?.success || !webhook) {
|
|
15791
|
+
throw new Error(`Failed to update Linear webhook: id=${existing.id}, url=${params.url}
|
|
15792
|
+
` + " Fix: verify LINEAR_API_KEY still has webhook manage permission for this team.");
|
|
15793
|
+
}
|
|
15794
|
+
logger.info("tracker-client", "Updated Linear webhook", { teamId: params.teamId, webhookId: webhook.id });
|
|
15795
|
+
return webhook;
|
|
15796
|
+
} catch (err) {
|
|
15797
|
+
const msg = err.message;
|
|
15798
|
+
if (isPermissionErrorMessage(msg))
|
|
15799
|
+
throw webhookPermissionError("update", msg);
|
|
15800
|
+
throw err;
|
|
15801
|
+
}
|
|
15802
|
+
}
|
|
15803
|
+
try {
|
|
15804
|
+
const data = await linearGraphQL(params.apiKey, CREATE_WEBHOOK_MUTATION, {
|
|
15805
|
+
teamId: params.teamId,
|
|
15806
|
+
url: params.url,
|
|
15807
|
+
secret: params.secret,
|
|
15808
|
+
label
|
|
15809
|
+
});
|
|
15810
|
+
const parsed = webhookCreateDataSchema.safeParse(data);
|
|
15811
|
+
const webhook = parsed.success ? parsed.data.webhookCreate?.webhook : undefined;
|
|
15812
|
+
if (!parsed.success || !parsed.data.webhookCreate?.success || !webhook) {
|
|
15813
|
+
throw new Error(`Failed to create Linear webhook: teamId=${params.teamId}, url=${params.url}
|
|
15814
|
+
` + " Fix: verify LINEAR_API_KEY has webhook create permission for this team. Regenerate at " + "https://linear.app/settings/api if needed.");
|
|
15815
|
+
}
|
|
15816
|
+
logger.info("tracker-client", "Created Linear webhook", { teamId: params.teamId, webhookId: webhook.id });
|
|
15817
|
+
return webhook;
|
|
15818
|
+
} catch (err) {
|
|
15819
|
+
const msg = err.message;
|
|
15820
|
+
if (isPermissionErrorMessage(msg))
|
|
15821
|
+
throw webhookPermissionError("create", msg);
|
|
15822
|
+
throw err;
|
|
15823
|
+
}
|
|
15824
|
+
}
|
|
15825
|
+
var WEBHOOK_LABEL = "agent-valley", webhookNodeSchema, listWebhooksDataSchema, webhookCreateDataSchema, webhookUpdateDataSchema, LIST_WEBHOOKS_QUERY = `
|
|
15826
|
+
query ListWebhooks($teamId: String!) {
|
|
15827
|
+
webhooks(filter: { team: { id: { eq: $teamId } } }) {
|
|
15828
|
+
nodes { id url label enabled }
|
|
15829
|
+
}
|
|
15830
|
+
}
|
|
15831
|
+
`, CREATE_WEBHOOK_MUTATION = `
|
|
15832
|
+
mutation CreateWebhook($teamId: String!, $url: String!, $secret: String!, $label: String!) {
|
|
15833
|
+
webhookCreate(input: { teamId: $teamId, url: $url, secret: $secret, label: $label, resourceTypes: ["Issue"], enabled: true }) {
|
|
15834
|
+
success
|
|
15835
|
+
webhook { id url label enabled }
|
|
15836
|
+
}
|
|
15837
|
+
}
|
|
15838
|
+
`, UPDATE_WEBHOOK_MUTATION = `
|
|
15839
|
+
mutation UpdateWebhook($id: String!, $url: String!, $enabled: Boolean!) {
|
|
15840
|
+
webhookUpdate(id: $id, input: { url: $url, enabled: $enabled }) {
|
|
15841
|
+
success
|
|
15842
|
+
webhook { id url label enabled }
|
|
15843
|
+
}
|
|
15844
|
+
}
|
|
15845
|
+
`;
|
|
15846
|
+
var init_linear_webhook_client = __esm(() => {
|
|
15847
|
+
init_zod();
|
|
15848
|
+
init_logger();
|
|
15849
|
+
init_linear_client();
|
|
15850
|
+
webhookNodeSchema = object({
|
|
15851
|
+
id: string2(),
|
|
15852
|
+
url: string2(),
|
|
15853
|
+
label: string2().nullable().optional(),
|
|
15854
|
+
enabled: boolean2()
|
|
15855
|
+
});
|
|
15856
|
+
listWebhooksDataSchema = object({
|
|
15857
|
+
webhooks: object({
|
|
15858
|
+
nodes: array(webhookNodeSchema)
|
|
15859
|
+
}).optional()
|
|
15860
|
+
});
|
|
15861
|
+
webhookCreateDataSchema = object({
|
|
15862
|
+
webhookCreate: object({
|
|
15863
|
+
success: boolean2(),
|
|
15864
|
+
webhook: webhookNodeSchema.optional()
|
|
15865
|
+
}).optional()
|
|
15866
|
+
});
|
|
15867
|
+
webhookUpdateDataSchema = object({
|
|
15868
|
+
webhookUpdate: object({
|
|
15869
|
+
success: boolean2(),
|
|
15870
|
+
webhook: webhookNodeSchema.optional()
|
|
15871
|
+
}).optional()
|
|
15872
|
+
});
|
|
15873
|
+
});
|
|
15874
|
+
|
|
15344
15875
|
// src/supervisor.ts
|
|
15345
15876
|
init_yaml_loader();
|
|
15346
15877
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -15363,7 +15894,7 @@ async function registerLinearWebhook(root, tunnelUrl) {
|
|
|
15363
15894
|
}
|
|
15364
15895
|
const webhookUrl = `${tunnelUrl}/api/webhook`;
|
|
15365
15896
|
try {
|
|
15366
|
-
await Promise.resolve().then(() =>
|
|
15897
|
+
await Promise.resolve().then(() => init_linear_webhook_client());
|
|
15367
15898
|
const result = await upsertWebhook({
|
|
15368
15899
|
apiKey: cfg.linearApiKey,
|
|
15369
15900
|
teamId: cfg.linearTeamUuid,
|