@brainervirus/workit-cursor 8.22.2 → 8.23.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/.cursor-plugin/plugin.json +1 -1
- package/dist/cursor-session-start.js +517 -1745
- package/dist/mcp-server.js +21 -1644
- package/dist/workit-hook.js +505 -1749
- package/package.json +3 -3
- package/skills/workit-fanout/SKILL.md +4 -4
- package/skills/workit-fanout/references/brief.md +17 -11
- package/skills/workit-fanout/references/orchestration.md +6 -6
- package/skills/workit-implement/SKILL.md +2 -0
|
@@ -967,7 +967,7 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, guid, uuid = (version) => {
|
|
|
967
967
|
if (!version)
|
|
968
968
|
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)$/;
|
|
969
969
|
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})$`);
|
|
970
|
-
}, 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,
|
|
970
|
+
}, 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, lowercase, uppercase;
|
|
971
971
|
var init_regexes = __esm(() => {
|
|
972
972
|
cuid = /^[cC][0-9a-z]{6,}$/;
|
|
973
973
|
cuid2 = /^[0-9a-z]+$/;
|
|
@@ -986,8 +986,6 @@ var init_regexes = __esm(() => {
|
|
|
986
986
|
base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
987
987
|
httpProtocol = /^https?$/;
|
|
988
988
|
e164 = /^\+[1-9]\d{6,14}$/;
|
|
989
|
-
creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
990
|
-
iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
991
989
|
date = /* @__PURE__ */ anchor(dateSource);
|
|
992
990
|
anyString = /^[\s\S]{0,}$/;
|
|
993
991
|
integer = /^-?\d+$/;
|
|
@@ -1472,40 +1470,6 @@ function isValidBase64URL(data) {
|
|
|
1472
1470
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
1473
1471
|
return isValidBase64(padded);
|
|
1474
1472
|
}
|
|
1475
|
-
function isLuhnAlgo(digits) {
|
|
1476
|
-
let length = digits.length;
|
|
1477
|
-
let bit = 1;
|
|
1478
|
-
let sum = 0;
|
|
1479
|
-
while (length) {
|
|
1480
|
-
const value = digits.charCodeAt(--length) - 48;
|
|
1481
|
-
bit ^= 1;
|
|
1482
|
-
sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
|
|
1483
|
-
}
|
|
1484
|
-
return sum % 10 === 0;
|
|
1485
|
-
}
|
|
1486
|
-
function isValidCreditCard(input) {
|
|
1487
|
-
if (!creditCard.test(input))
|
|
1488
|
-
return false;
|
|
1489
|
-
return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
|
|
1490
|
-
}
|
|
1491
|
-
function isIso7064Mod97(iban2) {
|
|
1492
|
-
let remainder = 0;
|
|
1493
|
-
const len = iban2.length;
|
|
1494
|
-
for (let i = 4;i < len; i++) {
|
|
1495
|
-
const code = iban2.charCodeAt(i);
|
|
1496
|
-
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1497
|
-
}
|
|
1498
|
-
for (let i = 0;i < 4; i++) {
|
|
1499
|
-
const code = iban2.charCodeAt(i);
|
|
1500
|
-
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1501
|
-
}
|
|
1502
|
-
return remainder === 1;
|
|
1503
|
-
}
|
|
1504
|
-
function isValidIBAN(input) {
|
|
1505
|
-
if (!iban.test(input))
|
|
1506
|
-
return false;
|
|
1507
|
-
return isIso7064Mod97(input);
|
|
1508
|
-
}
|
|
1509
1473
|
function isValidJWT(token, algorithm = null) {
|
|
1510
1474
|
try {
|
|
1511
1475
|
const tokensParts = token.split(".");
|
|
@@ -1831,7 +1795,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
1831
1795
|
payload.issues.push(issue(_iss));
|
|
1832
1796
|
}
|
|
1833
1797
|
}
|
|
1834
|
-
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,
|
|
1798
|
+
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, $ZodUnknown, $ZodNever, $ZodArray, NO_SYMBOL_KEYS, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodDiscriminatedUnion, $ZodIntersection, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodReadonly, $ZodCustom;
|
|
1835
1799
|
var init_schemas = __esm(() => {
|
|
1836
1800
|
init_checks();
|
|
1837
1801
|
init_core();
|
|
@@ -2186,7 +2150,6 @@ var init_schemas = __esm(() => {
|
|
|
2186
2150
|
def.pattern ?? (def.pattern = e164);
|
|
2187
2151
|
$ZodStringFormat.init(inst, def);
|
|
2188
2152
|
});
|
|
2189
|
-
CC_SANITIZE = /[- ]/g;
|
|
2190
2153
|
$ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
2191
2154
|
$ZodStringFormat.init(inst, def);
|
|
2192
2155
|
inst._zod.check = (payload) => {
|
|
@@ -3164,9 +3127,6 @@ function settle(inst, answer) {
|
|
|
3164
3127
|
recursive.set(inst, answer === PROVEN);
|
|
3165
3128
|
return answer;
|
|
3166
3129
|
}
|
|
3167
|
-
function isRecursiveSchema(inst) {
|
|
3168
|
-
return isRecursive(inst, new Set, true) !== NONE;
|
|
3169
|
-
}
|
|
3170
3130
|
function bucketFor(state, inst) {
|
|
3171
3131
|
let bucket = state.buckets.get(inst);
|
|
3172
3132
|
if (!bucket) {
|
|
@@ -3408,1642 +3368,78 @@ var error = () => {
|
|
|
3408
3368
|
return `Invalid discriminator value. Expected ${opts}`;
|
|
3409
3369
|
}
|
|
3410
3370
|
if (issue.inclusive === false) {
|
|
3411
|
-
return "Invalid input: more than one option matched";
|
|
3412
|
-
}
|
|
3413
|
-
return "Invalid input";
|
|
3414
|
-
case "invalid_element":
|
|
3415
|
-
return `Invalid value in ${issue.origin}`;
|
|
3416
|
-
default:
|
|
3417
|
-
return `Invalid input`;
|
|
3418
|
-
}
|
|
3419
|
-
};
|
|
3420
|
-
};
|
|
3421
|
-
var init_en = __esm(() => {
|
|
3422
|
-
init_util();
|
|
3423
|
-
});
|
|
3424
|
-
|
|
3425
|
-
// node_modules/zod/v4/locales/index.js
|
|
3426
|
-
var init_locales = () => {};
|
|
3427
|
-
|
|
3428
|
-
// node_modules/zod/v4/core/registries.js
|
|
3429
|
-
class $ZodRegistry {
|
|
3430
|
-
constructor() {
|
|
3431
|
-
this._map = new WeakMap;
|
|
3432
|
-
this._idmap = new Map;
|
|
3433
|
-
}
|
|
3434
|
-
add(schema, ..._meta) {
|
|
3435
|
-
const meta = _meta[0];
|
|
3436
|
-
this._map.set(schema, meta);
|
|
3437
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3438
|
-
this._idmap.set(meta.id, schema);
|
|
3439
|
-
}
|
|
3440
|
-
return this;
|
|
3441
|
-
}
|
|
3442
|
-
clear() {
|
|
3443
|
-
this._map = new WeakMap;
|
|
3444
|
-
this._idmap = new Map;
|
|
3445
|
-
return this;
|
|
3446
|
-
}
|
|
3447
|
-
remove(schema) {
|
|
3448
|
-
const meta = this._map.get(schema);
|
|
3449
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3450
|
-
this._idmap.delete(meta.id);
|
|
3451
|
-
}
|
|
3452
|
-
this._map.delete(schema);
|
|
3453
|
-
return this;
|
|
3454
|
-
}
|
|
3455
|
-
get(schema) {
|
|
3456
|
-
const p = schema._zod.parent;
|
|
3457
|
-
if (p) {
|
|
3458
|
-
const pm = { ...this.get(p) ?? {} };
|
|
3459
|
-
delete pm.id;
|
|
3460
|
-
const f = { ...pm, ...this._map.get(schema) };
|
|
3461
|
-
return Object.keys(f).length ? f : undefined;
|
|
3462
|
-
}
|
|
3463
|
-
return this._map.get(schema);
|
|
3464
|
-
}
|
|
3465
|
-
has(schema) {
|
|
3466
|
-
return this._map.has(schema);
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
function registry() {
|
|
3470
|
-
return new $ZodRegistry;
|
|
3471
|
-
}
|
|
3472
|
-
var _a2, globalRegistry;
|
|
3473
|
-
var init_registries = __esm(() => {
|
|
3474
|
-
(_a2 = globalThis).__zod_globalRegistry ?? (_a2.__zod_globalRegistry = registry());
|
|
3475
|
-
globalRegistry = globalThis.__zod_globalRegistry;
|
|
3476
|
-
});
|
|
3477
|
-
|
|
3478
|
-
// node_modules/zod/v4/core/compile.js
|
|
3479
|
-
function compileValidator(schema, parser) {
|
|
3480
|
-
try {
|
|
3481
|
-
return compileFn(schema, { assertOnly: true });
|
|
3482
|
-
} catch {
|
|
3483
|
-
return parser;
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
function compile(schema, options) {
|
|
3487
|
-
try {
|
|
3488
|
-
const parser = compileFn(schema);
|
|
3489
|
-
const clone = withParser(schema, parser);
|
|
3490
|
-
clone._zod.bag.validator = compileValidator(schema, parser);
|
|
3491
|
-
return clone;
|
|
3492
|
-
} catch (err) {
|
|
3493
|
-
if (options?.strict)
|
|
3494
|
-
throw err;
|
|
3495
|
-
return schema;
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
function withParser(schema, parser) {
|
|
3499
|
-
if (isRecursiveSchema(schema)) {
|
|
3500
|
-
throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
|
|
3501
|
-
}
|
|
3502
|
-
const clone2 = clone(schema);
|
|
3503
|
-
const liveRun = schema._zod.run;
|
|
3504
|
-
const originalRun = liveRun.__originalRun ?? liveRun;
|
|
3505
|
-
const wrapped = (payload, ctx) => {
|
|
3506
|
-
if (ctx?.async || ctx?.direction === "backward" || ctx?.skipChecks || ctx?.[FALLBACK_FLAG]) {
|
|
3507
|
-
return originalRun(payload, ctx);
|
|
3508
|
-
}
|
|
3509
|
-
if (ctx && isBackEdge(ctx, payload.value)) {
|
|
3510
|
-
return originalRun(payload, ctx);
|
|
3511
|
-
}
|
|
3512
|
-
const out = parser(payload.value);
|
|
3513
|
-
if (out !== INVALID) {
|
|
3514
|
-
payload.value = out;
|
|
3515
|
-
return payload;
|
|
3516
|
-
}
|
|
3517
|
-
if (ctx)
|
|
3518
|
-
ctx[FALLBACK_FLAG] = true;
|
|
3519
|
-
return originalRun(payload, ctx);
|
|
3520
|
-
};
|
|
3521
|
-
wrapped.__originalRun = originalRun;
|
|
3522
|
-
clone2._zod.bag.fallbackRun = originalRun;
|
|
3523
|
-
clone2._zod.bag.validator = parser;
|
|
3524
|
-
clone2._zod.run = wrapped;
|
|
3525
|
-
if (!liveRun.__originalRun)
|
|
3526
|
-
installCompiledUserMethods(clone2, schema, parser);
|
|
3527
|
-
return clone2;
|
|
3528
|
-
}
|
|
3529
|
-
function installCompiledUserMethods(target, source, parser) {
|
|
3530
|
-
const targetAny = target;
|
|
3531
|
-
const sourceAny = source;
|
|
3532
|
-
if (typeof sourceAny.safeParse === "function") {
|
|
3533
|
-
const originalSafeParse = sourceAny.safeParse;
|
|
3534
|
-
targetAny.safeParse = (data, params) => {
|
|
3535
|
-
const out = parser(data);
|
|
3536
|
-
if (out !== INVALID) {
|
|
3537
|
-
return { success: true, data: out };
|
|
3538
|
-
}
|
|
3539
|
-
return originalSafeParse(data, params);
|
|
3540
|
-
};
|
|
3541
|
-
}
|
|
3542
|
-
if (typeof sourceAny.parse === "function") {
|
|
3543
|
-
const originalParse = sourceAny.parse;
|
|
3544
|
-
targetAny.parse = (data, params) => {
|
|
3545
|
-
const out = parser(data);
|
|
3546
|
-
if (out !== INVALID) {
|
|
3547
|
-
return out;
|
|
3548
|
-
}
|
|
3549
|
-
return originalParse(data, params);
|
|
3550
|
-
};
|
|
3551
|
-
}
|
|
3552
|
-
}
|
|
3553
|
-
function compileFn(schema, options) {
|
|
3554
|
-
let recursive = true;
|
|
3555
|
-
try {
|
|
3556
|
-
recursive = isRecursiveSchema(schema);
|
|
3557
|
-
} catch {}
|
|
3558
|
-
if (recursive) {
|
|
3559
|
-
throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
|
|
3560
|
-
}
|
|
3561
|
-
const ctx = {
|
|
3562
|
-
constants: new Map,
|
|
3563
|
-
constantCounter: 0,
|
|
3564
|
-
varCounter: 0,
|
|
3565
|
-
definite: true
|
|
3566
|
-
};
|
|
3567
|
-
const doc = new Doc(["input"]);
|
|
3568
|
-
const outputAccessor = generateCheck(doc, ctx, schema, "input", !options?.assertOnly);
|
|
3569
|
-
doc.write(outputAccessor === null ? `return true;` : `return ${outputAccessor};`);
|
|
3570
|
-
const constantNames = ["INVALID", ...ctx.constants.keys()];
|
|
3571
|
-
const constantValues = [INVALID, ...ctx.constants.values()];
|
|
3572
|
-
const code = doc.content.join(`
|
|
3573
|
-
`);
|
|
3574
|
-
const fullCode = options?.debug ? constantNames.length > 0 ? `// Constants: ${constantNames.join(", ")}
|
|
3575
|
-
${code}` : code : "";
|
|
3576
|
-
const F = Function;
|
|
3577
|
-
const factoryCode = `return (input) => {
|
|
3578
|
-
${code}
|
|
3579
|
-
}`;
|
|
3580
|
-
let fn;
|
|
3581
|
-
try {
|
|
3582
|
-
const factory = new F(...constantNames, factoryCode);
|
|
3583
|
-
fn = factory(...constantValues);
|
|
3584
|
-
} catch (err) {
|
|
3585
|
-
throw new ZodCompileUnsupportedError(`this schema (generated code failed to evaluate: ${err.message})`);
|
|
3586
|
-
}
|
|
3587
|
-
if (options?.debug) {
|
|
3588
|
-
fn.code = fullCode;
|
|
3589
|
-
}
|
|
3590
|
-
fn.definite = ctx.definite;
|
|
3591
|
-
return fn;
|
|
3592
|
-
}
|
|
3593
|
-
function addConstant(ctx, value) {
|
|
3594
|
-
for (const [name, v] of ctx.constants) {
|
|
3595
|
-
if (v === value)
|
|
3596
|
-
return name;
|
|
3597
|
-
}
|
|
3598
|
-
const name = `c${ctx.constantCounter++}`;
|
|
3599
|
-
ctx.constants.set(name, value);
|
|
3600
|
-
return name;
|
|
3601
|
-
}
|
|
3602
|
-
function addUserConstant(ctx, fn) {
|
|
3603
|
-
ctx.definite = false;
|
|
3604
|
-
return addConstant(ctx, fn);
|
|
3605
|
-
}
|
|
3606
|
-
function newVar(ctx) {
|
|
3607
|
-
return `v${ctx.varCounter++}`;
|
|
3608
|
-
}
|
|
3609
|
-
function runtimeRun(schema, value) {
|
|
3610
|
-
const result = schema._zod.run({ value, issues: [] }, {});
|
|
3611
|
-
if (result && typeof result.then === "function")
|
|
3612
|
-
return INVALID;
|
|
3613
|
-
const r = result;
|
|
3614
|
-
return r.issues.length === 0 ? r.value : INVALID;
|
|
3615
|
-
}
|
|
3616
|
-
function compileChild(doc, ctx, schema, accessor, needsValue = true) {
|
|
3617
|
-
const contentLen = doc.content.length;
|
|
3618
|
-
const constantCount = ctx.constants.size;
|
|
3619
|
-
const constantCounter = ctx.constantCounter;
|
|
3620
|
-
const varCounter = ctx.varCounter;
|
|
3621
|
-
try {
|
|
3622
|
-
return generateCheck(doc, ctx, schema, accessor, needsValue);
|
|
3623
|
-
} catch (err) {
|
|
3624
|
-
if (!(err instanceof ZodCompileUnsupportedError) || !err.islandable)
|
|
3625
|
-
throw err;
|
|
3626
|
-
doc.content.length = contentLen;
|
|
3627
|
-
if (ctx.constants.size > constantCount) {
|
|
3628
|
-
const trailing = Array.from(ctx.constants.keys()).slice(constantCount);
|
|
3629
|
-
for (const k of trailing)
|
|
3630
|
-
ctx.constants.delete(k);
|
|
3631
|
-
}
|
|
3632
|
-
ctx.constantCounter = constantCounter;
|
|
3633
|
-
ctx.varCounter = varCounter;
|
|
3634
|
-
return emitRuntimeIsland(doc, ctx, schema, accessor);
|
|
3635
|
-
}
|
|
3636
|
-
}
|
|
3637
|
-
function emitRuntimeIsland(doc, ctx, schema, accessor) {
|
|
3638
|
-
ctx.definite = false;
|
|
3639
|
-
const schemaConst = addConstant(ctx, schema);
|
|
3640
|
-
const runConst = addConstant(ctx, runtimeRun);
|
|
3641
|
-
const outVar = newVar(ctx);
|
|
3642
|
-
doc.write(`const ${outVar} = ${runConst}(${schemaConst}, ${accessor});`);
|
|
3643
|
-
doc.write(`if (${outVar} === INVALID) return INVALID;`);
|
|
3644
|
-
return outVar;
|
|
3645
|
-
}
|
|
3646
|
-
function generateChecks(doc, ctx, schema, accessor) {
|
|
3647
|
-
const schemaChecks = schema._zod.def.checks;
|
|
3648
|
-
if (!schemaChecks || schemaChecks.length === 0)
|
|
3649
|
-
return accessor;
|
|
3650
|
-
let currentAccessor = accessor;
|
|
3651
|
-
for (const check of schemaChecks) {
|
|
3652
|
-
const def = check._zod.def;
|
|
3653
|
-
if (def.when && !WHEN_DEFAULTED_CHECKS.has(def.check)) {
|
|
3654
|
-
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
3655
|
-
}
|
|
3656
|
-
switch (def.check) {
|
|
3657
|
-
case "greater_than":
|
|
3658
|
-
generateGreaterThanCheck(doc, ctx, def, currentAccessor);
|
|
3659
|
-
break;
|
|
3660
|
-
case "less_than":
|
|
3661
|
-
generateLessThanCheck(doc, ctx, def, currentAccessor);
|
|
3662
|
-
break;
|
|
3663
|
-
case "multiple_of":
|
|
3664
|
-
generateMultipleOfCheck(doc, ctx, def, currentAccessor);
|
|
3665
|
-
break;
|
|
3666
|
-
case "number_format":
|
|
3667
|
-
generateNumberFormatCheck(doc, def, currentAccessor);
|
|
3668
|
-
break;
|
|
3669
|
-
case "min_length": {
|
|
3670
|
-
const min = numericOperand(def.minimum, "min_length");
|
|
3671
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${min} && ${currentAccessor}.length < ${def.minimum * 2}`);
|
|
3672
|
-
doc.write(`if (${len} < ${min}) return INVALID;`);
|
|
3673
|
-
break;
|
|
3674
|
-
}
|
|
3675
|
-
case "max_length": {
|
|
3676
|
-
const max = numericOperand(def.maximum, "max_length");
|
|
3677
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length > ${max}`);
|
|
3678
|
-
doc.write(`if (${len} > ${max}) return INVALID;`);
|
|
3679
|
-
break;
|
|
3680
|
-
}
|
|
3681
|
-
case "length_equals": {
|
|
3682
|
-
const exact = numericOperand(def.length, "length_equals");
|
|
3683
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${exact} && ${currentAccessor}.length <= ${def.length * 2}`);
|
|
3684
|
-
doc.write(`if (${len} !== ${exact}) return INVALID;`);
|
|
3685
|
-
break;
|
|
3686
|
-
}
|
|
3687
|
-
case "min_size":
|
|
3688
|
-
doc.write(`if (${currentAccessor}.size < ${numericOperand(def.minimum, "min_size")}) return INVALID;`);
|
|
3689
|
-
break;
|
|
3690
|
-
case "max_size":
|
|
3691
|
-
doc.write(`if (${currentAccessor}.size > ${numericOperand(def.maximum, "max_size")}) return INVALID;`);
|
|
3692
|
-
break;
|
|
3693
|
-
case "size_equals":
|
|
3694
|
-
doc.write(`if (${currentAccessor}.size !== ${numericOperand(def.size, "size_equals")}) return INVALID;`);
|
|
3695
|
-
break;
|
|
3696
|
-
case "string_format":
|
|
3697
|
-
currentAccessor = generateStringFormatCheck(doc, ctx, def, currentAccessor);
|
|
3698
|
-
break;
|
|
3699
|
-
case "custom":
|
|
3700
|
-
currentAccessor = generateCustomRefineCheck(doc, ctx, check, currentAccessor);
|
|
3701
|
-
break;
|
|
3702
|
-
case "bigint_format":
|
|
3703
|
-
generateBigIntFormatCheck(doc, def, currentAccessor);
|
|
3704
|
-
break;
|
|
3705
|
-
case "mime_type":
|
|
3706
|
-
generateMimeTypeCheck(doc, ctx, def, currentAccessor);
|
|
3707
|
-
break;
|
|
3708
|
-
case "property":
|
|
3709
|
-
generatePropertyCheck(doc, ctx, def, currentAccessor);
|
|
3710
|
-
break;
|
|
3711
|
-
case "properties":
|
|
3712
|
-
generatePropertiesChecks(doc, ctx, def, currentAccessor);
|
|
3713
|
-
break;
|
|
3714
|
-
case "overwrite": {
|
|
3715
|
-
const newAccessor = newVar(ctx);
|
|
3716
|
-
generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor);
|
|
3717
|
-
currentAccessor = newAccessor;
|
|
3718
|
-
break;
|
|
3719
|
-
}
|
|
3720
|
-
default: {
|
|
3721
|
-
throw new ZodCompileUnsupportedError(`check type ${def.check}`);
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
return currentAccessor;
|
|
3726
|
-
}
|
|
3727
|
-
function codePointLengthVar(doc, ctx, accessor, inDoubt) {
|
|
3728
|
-
const cpLen = addConstant(ctx, codePointLength);
|
|
3729
|
-
const v = newVar(ctx);
|
|
3730
|
-
doc.write(`const ${v} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
|
|
3731
|
-
return v;
|
|
3732
|
-
}
|
|
3733
|
-
function numericOperand(value, label) {
|
|
3734
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
3735
|
-
throw new ZodCompileUnsupportedError(`${label} bound of type ${typeof value}`);
|
|
3736
|
-
}
|
|
3737
|
-
return `${value}`;
|
|
3738
|
-
}
|
|
3739
|
-
function comparisonOperand(ctx, value) {
|
|
3740
|
-
if (typeof value === "bigint")
|
|
3741
|
-
return `${value}n`;
|
|
3742
|
-
if (typeof value === "number") {
|
|
3743
|
-
if (Number.isNaN(value))
|
|
3744
|
-
throw new ZodCompileUnsupportedError("comparison check with NaN bound");
|
|
3745
|
-
return `${value}`;
|
|
3746
|
-
}
|
|
3747
|
-
if (value instanceof Date) {
|
|
3748
|
-
if (Number.isNaN(value.getTime())) {
|
|
3749
|
-
throw new ZodCompileUnsupportedError("comparison check with Invalid Date bound");
|
|
3750
|
-
}
|
|
3751
|
-
return addConstant(ctx, value);
|
|
3752
|
-
}
|
|
3753
|
-
throw new ZodCompileUnsupportedError(`comparison check bound of type ${typeof value}`);
|
|
3754
|
-
}
|
|
3755
|
-
function generateGreaterThanCheck(doc, ctx, def, accessor) {
|
|
3756
|
-
const op = def.inclusive ? "<" : "<=";
|
|
3757
|
-
doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
|
|
3758
|
-
}
|
|
3759
|
-
function generateLessThanCheck(doc, ctx, def, accessor) {
|
|
3760
|
-
const op = def.inclusive ? ">" : ">=";
|
|
3761
|
-
doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
|
|
3762
|
-
}
|
|
3763
|
-
function generateMultipleOfCheck(doc, ctx, def, accessor) {
|
|
3764
|
-
if (typeof def.value === "bigint") {
|
|
3765
|
-
if (def.value === BigInt(0))
|
|
3766
|
-
throw new ZodCompileUnsupportedError("multiple_of check with a zero divisor");
|
|
3767
|
-
doc.write(`if (${accessor} % ${def.value}n !== 0n) return INVALID;`);
|
|
3768
|
-
} else {
|
|
3769
|
-
const remainder = addConstant(ctx, floatSafeRemainder);
|
|
3770
|
-
doc.write(`if (${remainder}(${accessor}, ${numericOperand(def.value, "multiple_of")}) !== 0) return INVALID;`);
|
|
3771
|
-
}
|
|
3772
|
-
}
|
|
3773
|
-
function generateNumberFormatCheck(doc, def, accessor) {
|
|
3774
|
-
const format = def.format;
|
|
3775
|
-
switch (format) {
|
|
3776
|
-
case "safeint":
|
|
3777
|
-
doc.write(`if (!Number.isSafeInteger(${accessor})) return INVALID;`);
|
|
3778
|
-
break;
|
|
3779
|
-
case "int32":
|
|
3780
|
-
doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < -2147483648 || ${accessor} > 2147483647) return INVALID;`);
|
|
3781
|
-
break;
|
|
3782
|
-
case "uint32":
|
|
3783
|
-
doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < 0 || ${accessor} > 4294967295) return INVALID;`);
|
|
3784
|
-
break;
|
|
3785
|
-
case "float32":
|
|
3786
|
-
doc.write(`if (!Number.isFinite(${accessor}) || ${accessor} < -3.4028234663852886e38 || ${accessor} > 3.4028234663852886e38) return INVALID;`);
|
|
3787
|
-
break;
|
|
3788
|
-
case "float64":
|
|
3789
|
-
doc.write(`if (!Number.isFinite(${accessor})) return INVALID;`);
|
|
3790
|
-
break;
|
|
3791
|
-
default: {
|
|
3792
|
-
throw new ZodCompileUnsupportedError(`number format ${format}`);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
function generateBigIntFormatCheck(doc, def, accessor) {
|
|
3797
|
-
const format = def.format;
|
|
3798
|
-
if (!format)
|
|
3799
|
-
return;
|
|
3800
|
-
switch (format) {
|
|
3801
|
-
case "int64":
|
|
3802
|
-
doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
|
|
3803
|
-
break;
|
|
3804
|
-
case "uint64":
|
|
3805
|
-
doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
|
|
3806
|
-
break;
|
|
3807
|
-
default: {
|
|
3808
|
-
throw new ZodCompileUnsupportedError(`bigint format ${format}`);
|
|
3809
|
-
}
|
|
3810
|
-
}
|
|
3811
|
-
}
|
|
3812
|
-
function generateMimeTypeCheck(doc, ctx, def, accessor) {
|
|
3813
|
-
const mimeTypes = def.mime;
|
|
3814
|
-
if (mimeTypes && mimeTypes.length > 0) {
|
|
3815
|
-
const mimeSet = addConstant(ctx, new Set(mimeTypes));
|
|
3816
|
-
doc.write(`if (!${mimeSet}.has(${accessor}.type)) return INVALID;`);
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
3820
|
-
if (def.when) {
|
|
3821
|
-
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
3822
|
-
}
|
|
3823
|
-
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
3824
|
-
const shape = def.shape;
|
|
3825
|
-
for (const key of Reflect.ownKeys(shape)) {
|
|
3826
|
-
const keyExpr = typeof key === "symbol" ? addConstant(ctx, key) : esc(key);
|
|
3827
|
-
const inputVar = newVar(ctx);
|
|
3828
|
-
doc.write(`const ${inputVar} = ${accessor}[${keyExpr}];`);
|
|
3829
|
-
compileChild(doc, ctx, shape[key], inputVar, false);
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
|
-
function generatePropertyCheck(doc, ctx, def, accessor) {
|
|
3833
|
-
const propAccessor = `${accessor}[${JSON.stringify(def.property)}]`;
|
|
3834
|
-
generateCheck(doc, ctx, def.schema, propAccessor);
|
|
3835
|
-
}
|
|
3836
|
-
function generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor) {
|
|
3837
|
-
const tx = check._zod.def.tx;
|
|
3838
|
-
if (!tx) {
|
|
3839
|
-
throw new ZodCompileUnsupportedError("overwrite check without a transform function");
|
|
3840
|
-
}
|
|
3841
|
-
if (isAsyncFunction(tx)) {
|
|
3842
|
-
throw new ZodCompileAsyncError("z.compile: async overwrite transforms are not supported");
|
|
3843
|
-
}
|
|
3844
|
-
const txConst = addConstant(ctx, tx);
|
|
3845
|
-
doc.write(`const ${newAccessor} = ${txConst}(${currentAccessor});`);
|
|
3846
|
-
}
|
|
3847
|
-
function throwAsync() {
|
|
3848
|
-
throw new $ZodAsyncError;
|
|
3849
|
-
}
|
|
3850
|
-
function pushIssue(issue) {
|
|
3851
|
-
this.issues.push(issue);
|
|
3852
|
-
}
|
|
3853
|
-
function generateCustomRefineCheck(doc, ctx, check, accessor) {
|
|
3854
|
-
const def = check._zod.def;
|
|
3855
|
-
if (def.fn) {
|
|
3856
|
-
if (isAsyncFunction(def.fn)) {
|
|
3857
|
-
throw new ZodCompileAsyncError("z.compile: async .refine() predicates are not supported");
|
|
3858
|
-
}
|
|
3859
|
-
const fnConst = addUserConstant(ctx, def.fn);
|
|
3860
|
-
const throwAsyncConst = addConstant(ctx, throwAsync);
|
|
3861
|
-
const resVar = newVar(ctx);
|
|
3862
|
-
doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
|
|
3863
|
-
doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
|
|
3864
|
-
doc.write(`if (!${resVar}) return INVALID;`);
|
|
3865
|
-
return accessor;
|
|
3866
|
-
}
|
|
3867
|
-
if (check._zod.check) {
|
|
3868
|
-
if (isAsyncFunction(check._zod.check)) {
|
|
3869
|
-
throw new ZodCompileAsyncError("z.compile: async .superRefine() / check functions are not supported");
|
|
3870
|
-
}
|
|
3871
|
-
const checkFn = check._zod.check;
|
|
3872
|
-
const helperFn = (value) => {
|
|
3873
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
3874
|
-
const result = checkFn(fakePayload);
|
|
3875
|
-
if (result instanceof Promise)
|
|
3876
|
-
throwAsync();
|
|
3877
|
-
return fakePayload.issues.length === 0 ? fakePayload.value : INVALID;
|
|
3878
|
-
};
|
|
3879
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
3880
|
-
const outVar = newVar(ctx);
|
|
3881
|
-
doc.write(`const ${outVar} = ${helperConst}(${accessor});`);
|
|
3882
|
-
doc.write(`if (${outVar} === INVALID) return INVALID;`);
|
|
3883
|
-
return outVar;
|
|
3884
|
-
}
|
|
3885
|
-
throw new ZodCompileUnsupportedError("custom check without a predicate or check function");
|
|
3886
|
-
}
|
|
3887
|
-
function generateStringFormatCheck(doc, ctx, def, accessor, needsValue = true) {
|
|
3888
|
-
const fmt = def.format;
|
|
3889
|
-
if (fmt === "base64") {
|
|
3890
|
-
const validator = addConstant(ctx, isValidBase64);
|
|
3891
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3892
|
-
return accessor;
|
|
3893
|
-
}
|
|
3894
|
-
if (fmt === "base64url") {
|
|
3895
|
-
const validator = addConstant(ctx, isValidBase64URL);
|
|
3896
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3897
|
-
return accessor;
|
|
3898
|
-
}
|
|
3899
|
-
if (fmt === "jwt") {
|
|
3900
|
-
const validator = addConstant(ctx, isValidJWT);
|
|
3901
|
-
const alg = addConstant(ctx, def.alg ?? null);
|
|
3902
|
-
doc.write(`if (!${validator}(${accessor}, ${alg})) return INVALID;`);
|
|
3903
|
-
return accessor;
|
|
3904
|
-
}
|
|
3905
|
-
if (fmt === "ipv6") {
|
|
3906
|
-
const validator = addConstant(ctx, isValidIPv6);
|
|
3907
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3908
|
-
return accessor;
|
|
3909
|
-
}
|
|
3910
|
-
if (fmt === "cidrv6") {
|
|
3911
|
-
const validator = addConstant(ctx, isValidCIDRv6);
|
|
3912
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3913
|
-
return accessor;
|
|
3914
|
-
}
|
|
3915
|
-
if (fmt === "credit_card") {
|
|
3916
|
-
const validator = addConstant(ctx, isValidCreditCard);
|
|
3917
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3918
|
-
return accessor;
|
|
3919
|
-
}
|
|
3920
|
-
if (fmt === "iban") {
|
|
3921
|
-
const validator = addConstant(ctx, isValidIBAN);
|
|
3922
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3923
|
-
return accessor;
|
|
3924
|
-
}
|
|
3925
|
-
const formatDef = def;
|
|
3926
|
-
if (fmt === "url" || fmt === "httpurl" || formatDef.normalize || formatDef.hostname !== undefined || formatDef.protocol !== undefined) {
|
|
3927
|
-
const parseConst = addConstant(ctx, validateURL);
|
|
3928
|
-
const defConst = addConstant(ctx, def);
|
|
3929
|
-
const trimVar = newVar(ctx);
|
|
3930
|
-
const urlVar = newVar(ctx);
|
|
3931
|
-
doc.write(`const ${trimVar} = ${accessor}.trim();`);
|
|
3932
|
-
doc.write(`const ${urlVar} = ${parseConst}(${trimVar}, ${defConst});`);
|
|
3933
|
-
doc.write(`if (typeof ${urlVar} === "number") return INVALID;`);
|
|
3934
|
-
if (formatDef.hostname !== undefined) {
|
|
3935
|
-
const hostnameConst = addConstant(ctx, urlHostnameOk);
|
|
3936
|
-
doc.write(`if (!${hostnameConst}(${urlVar}, ${defConst}.hostname)) return INVALID;`);
|
|
3937
|
-
}
|
|
3938
|
-
if (formatDef.protocol !== undefined) {
|
|
3939
|
-
const protocolConst = addConstant(ctx, urlProtocolOk);
|
|
3940
|
-
doc.write(`if (!${protocolConst}(${urlVar}, ${defConst}.protocol)) return INVALID;`);
|
|
3941
|
-
}
|
|
3942
|
-
if (!needsValue)
|
|
3943
|
-
return null;
|
|
3944
|
-
const outputVar = newVar(ctx);
|
|
3945
|
-
const outputExpr = formatDef.normalize ? `${urlVar}.href` : `${addConstant(ctx, stripTabAndNewline)}(${trimVar})`;
|
|
3946
|
-
doc.write(`const ${outputVar} = ${outputExpr};`);
|
|
3947
|
-
return outputVar;
|
|
3948
|
-
}
|
|
3949
|
-
const customFn = def.fn;
|
|
3950
|
-
if (customFn) {
|
|
3951
|
-
if (isAsyncFunction(customFn))
|
|
3952
|
-
throw new ZodCompileUnsupportedError(`async string format ${fmt}`);
|
|
3953
|
-
const fnConst = addConstant(ctx, customFn);
|
|
3954
|
-
doc.write(`if (!${fnConst}(${accessor})) return INVALID;`);
|
|
3955
|
-
return accessor;
|
|
3956
|
-
}
|
|
3957
|
-
if (PATTERN_IS_COMPLETE.has(fmt) && def.pattern) {
|
|
3958
|
-
const patternConst = addConstant(ctx, def.pattern);
|
|
3959
|
-
doc.write(`${patternConst}.lastIndex = 0;`);
|
|
3960
|
-
doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
|
|
3961
|
-
return accessor;
|
|
3962
|
-
}
|
|
3963
|
-
const format = def.format;
|
|
3964
|
-
switch (format) {
|
|
3965
|
-
case "regex":
|
|
3966
|
-
throw new ZodCompileUnsupportedError("regex format without a pattern");
|
|
3967
|
-
case "lowercase":
|
|
3968
|
-
doc.write(`if (${accessor} !== ${accessor}.toLowerCase()) return INVALID;`);
|
|
3969
|
-
break;
|
|
3970
|
-
case "uppercase":
|
|
3971
|
-
doc.write(`if (${accessor} !== ${accessor}.toUpperCase()) return INVALID;`);
|
|
3972
|
-
break;
|
|
3973
|
-
case "includes":
|
|
3974
|
-
doc.write(`if (!${accessor}.includes(${esc(def.includes)})) return INVALID;`);
|
|
3975
|
-
break;
|
|
3976
|
-
case "starts_with": {
|
|
3977
|
-
const prefix = def.prefix;
|
|
3978
|
-
doc.write(`if (${accessor}.slice(0, ${prefix.length}) !== ${esc(prefix)}) return INVALID;`);
|
|
3979
|
-
break;
|
|
3980
|
-
}
|
|
3981
|
-
case "ends_with": {
|
|
3982
|
-
const suffix = def.suffix;
|
|
3983
|
-
doc.write(`if (${accessor}.slice(-${suffix.length}) !== ${esc(suffix)}) return INVALID;`);
|
|
3984
|
-
break;
|
|
3985
|
-
}
|
|
3986
|
-
default: {
|
|
3987
|
-
throw new ZodCompileUnsupportedError(`string format ${format}`);
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
return accessor;
|
|
3991
|
-
}
|
|
3992
|
-
function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
3993
|
-
const def = schema._zod.def;
|
|
3994
|
-
const type = def.type;
|
|
3995
|
-
if (def.coerce) {
|
|
3996
|
-
throw new ZodCompileUnsupportedError(`coercion (z.coerce.${type}())`);
|
|
3997
|
-
}
|
|
3998
|
-
const buildsValue = needsValue || !!def.checks?.length;
|
|
3999
|
-
let typeAccessor;
|
|
4000
|
-
switch (type) {
|
|
4001
|
-
case "string":
|
|
4002
|
-
typeAccessor = generateStringCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4003
|
-
break;
|
|
4004
|
-
case "number":
|
|
4005
|
-
typeAccessor = generateNumberCheck(doc, schema, accessor);
|
|
4006
|
-
break;
|
|
4007
|
-
case "boolean":
|
|
4008
|
-
typeAccessor = generateBooleanCheck(doc, accessor);
|
|
4009
|
-
break;
|
|
4010
|
-
case "bigint":
|
|
4011
|
-
typeAccessor = generateBigIntCheck(doc, schema, accessor);
|
|
4012
|
-
break;
|
|
4013
|
-
case "symbol":
|
|
4014
|
-
typeAccessor = generateSymbolCheck(doc, accessor);
|
|
4015
|
-
break;
|
|
4016
|
-
case "undefined":
|
|
4017
|
-
typeAccessor = generateUndefinedCheck(doc, accessor);
|
|
4018
|
-
break;
|
|
4019
|
-
case "null":
|
|
4020
|
-
typeAccessor = generateNullCheck(doc, accessor);
|
|
4021
|
-
break;
|
|
4022
|
-
case "any":
|
|
4023
|
-
case "unknown":
|
|
4024
|
-
typeAccessor = accessor;
|
|
4025
|
-
break;
|
|
4026
|
-
case "never":
|
|
4027
|
-
doc.write("return INVALID;");
|
|
4028
|
-
typeAccessor = accessor;
|
|
4029
|
-
break;
|
|
4030
|
-
case "void":
|
|
4031
|
-
typeAccessor = generateVoidCheck(doc, accessor);
|
|
4032
|
-
break;
|
|
4033
|
-
case "nan":
|
|
4034
|
-
typeAccessor = generateNaNCheck(doc, accessor);
|
|
4035
|
-
break;
|
|
4036
|
-
case "date":
|
|
4037
|
-
typeAccessor = generateDateCheck(doc, accessor);
|
|
4038
|
-
break;
|
|
4039
|
-
case "object":
|
|
4040
|
-
typeAccessor = generateObjectCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4041
|
-
break;
|
|
4042
|
-
case "optional":
|
|
4043
|
-
typeAccessor = generateOptionalCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4044
|
-
break;
|
|
4045
|
-
case "nullable":
|
|
4046
|
-
typeAccessor = generateNullableCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4047
|
-
break;
|
|
4048
|
-
case "array":
|
|
4049
|
-
typeAccessor = generateArrayCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4050
|
-
break;
|
|
4051
|
-
case "literal":
|
|
4052
|
-
typeAccessor = generateLiteralCheck(doc, ctx, schema, accessor);
|
|
4053
|
-
break;
|
|
4054
|
-
case "enum":
|
|
4055
|
-
typeAccessor = generateEnumCheck(doc, ctx, schema, accessor);
|
|
4056
|
-
break;
|
|
4057
|
-
case "readonly": {
|
|
4058
|
-
const innerOut = generateWrapperCheck(doc, ctx, schema, accessor);
|
|
4059
|
-
const frozenVar = newVar(ctx);
|
|
4060
|
-
doc.write(`const ${frozenVar} = Object.freeze(${innerOut});`);
|
|
4061
|
-
typeAccessor = frozenVar;
|
|
4062
|
-
break;
|
|
4063
|
-
}
|
|
4064
|
-
case "success":
|
|
4065
|
-
generateWrapperCheck(doc, ctx, schema, accessor);
|
|
4066
|
-
typeAccessor = "true";
|
|
4067
|
-
break;
|
|
4068
|
-
case "default":
|
|
4069
|
-
case "prefault":
|
|
4070
|
-
typeAccessor = generateDefaultCheck(doc, ctx, schema, accessor);
|
|
4071
|
-
break;
|
|
4072
|
-
case "nonoptional":
|
|
4073
|
-
typeAccessor = generateNonOptionalCheck(doc, ctx, schema, accessor);
|
|
4074
|
-
break;
|
|
4075
|
-
case "tuple":
|
|
4076
|
-
typeAccessor = generateTupleCheck(doc, ctx, schema, accessor);
|
|
4077
|
-
break;
|
|
4078
|
-
case "union":
|
|
4079
|
-
typeAccessor = generateUnionCheck(doc, ctx, schema, accessor);
|
|
4080
|
-
break;
|
|
4081
|
-
case "intersection":
|
|
4082
|
-
typeAccessor = generateIntersectionCheck(doc, ctx, schema, accessor);
|
|
4083
|
-
break;
|
|
4084
|
-
case "record":
|
|
4085
|
-
typeAccessor = generateRecordCheck(doc, ctx, schema, accessor);
|
|
4086
|
-
break;
|
|
4087
|
-
case "map":
|
|
4088
|
-
typeAccessor = generateMapCheck(doc, ctx, schema, accessor);
|
|
4089
|
-
break;
|
|
4090
|
-
case "set":
|
|
4091
|
-
typeAccessor = generateSetCheck(doc, ctx, schema, accessor);
|
|
4092
|
-
break;
|
|
4093
|
-
case "file":
|
|
4094
|
-
typeAccessor = generateFileCheck(doc, accessor);
|
|
4095
|
-
break;
|
|
4096
|
-
case "template_literal":
|
|
4097
|
-
typeAccessor = generateTemplateLiteralCheck(doc, ctx, schema, accessor);
|
|
4098
|
-
break;
|
|
4099
|
-
case "lazy":
|
|
4100
|
-
typeAccessor = generateLazyCheck(doc, ctx, schema, accessor);
|
|
4101
|
-
break;
|
|
4102
|
-
case "pipe":
|
|
4103
|
-
typeAccessor = generatePipeCheck(doc, ctx, schema, accessor);
|
|
4104
|
-
break;
|
|
4105
|
-
case "custom":
|
|
4106
|
-
typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
|
|
4107
|
-
break;
|
|
4108
|
-
case "transform":
|
|
4109
|
-
typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
|
|
4110
|
-
break;
|
|
4111
|
-
case "catch":
|
|
4112
|
-
typeAccessor = generateCatchCheck(doc, ctx, schema, accessor);
|
|
4113
|
-
break;
|
|
4114
|
-
default: {
|
|
4115
|
-
throw new ZodCompileUnsupportedError(`schema type ${type}`);
|
|
4116
|
-
}
|
|
4117
|
-
}
|
|
4118
|
-
if (typeAccessor === null)
|
|
4119
|
-
return null;
|
|
4120
|
-
return generateChecks(doc, ctx, schema, typeAccessor);
|
|
4121
|
-
}
|
|
4122
|
-
function generateStringCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
4123
|
-
doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
|
|
4124
|
-
const def = schema._zod.def;
|
|
4125
|
-
if (def.format === undefined)
|
|
4126
|
-
return accessor;
|
|
4127
|
-
return generateStringFormatCheck(doc, ctx, def, accessor, needsValue);
|
|
4128
|
-
}
|
|
4129
|
-
function generateNumberCheck(doc, schema, accessor) {
|
|
4130
|
-
doc.write(`if (typeof ${accessor} !== "number" || !Number.isFinite(${accessor})) return INVALID;`);
|
|
4131
|
-
const def = schema._zod.def;
|
|
4132
|
-
if (def.check === "number_format" && def.format) {
|
|
4133
|
-
generateNumberFormatCheck(doc, { format: def.format }, accessor);
|
|
4134
|
-
}
|
|
4135
|
-
return accessor;
|
|
4136
|
-
}
|
|
4137
|
-
function generateBooleanCheck(doc, accessor) {
|
|
4138
|
-
doc.write(`if (typeof ${accessor} !== "boolean") return INVALID;`);
|
|
4139
|
-
return accessor;
|
|
4140
|
-
}
|
|
4141
|
-
function generateBigIntCheck(doc, schema, accessor) {
|
|
4142
|
-
doc.write(`if (typeof ${accessor} !== "bigint") return INVALID;`);
|
|
4143
|
-
const def = schema._zod.def;
|
|
4144
|
-
if (def.format) {
|
|
4145
|
-
switch (def.format) {
|
|
4146
|
-
case "int64":
|
|
4147
|
-
doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
|
|
4148
|
-
break;
|
|
4149
|
-
case "uint64":
|
|
4150
|
-
doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
|
|
4151
|
-
break;
|
|
4152
|
-
}
|
|
4153
|
-
}
|
|
4154
|
-
return accessor;
|
|
4155
|
-
}
|
|
4156
|
-
function generateSymbolCheck(doc, accessor) {
|
|
4157
|
-
doc.write(`if (typeof ${accessor} !== "symbol") return INVALID;`);
|
|
4158
|
-
return accessor;
|
|
4159
|
-
}
|
|
4160
|
-
function generateUndefinedCheck(doc, accessor) {
|
|
4161
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4162
|
-
return accessor;
|
|
4163
|
-
}
|
|
4164
|
-
function generateNullCheck(doc, accessor) {
|
|
4165
|
-
doc.write(`if (${accessor} !== null) return INVALID;`);
|
|
4166
|
-
return accessor;
|
|
4167
|
-
}
|
|
4168
|
-
function generateVoidCheck(doc, accessor) {
|
|
4169
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4170
|
-
return accessor;
|
|
4171
|
-
}
|
|
4172
|
-
function generateNaNCheck(doc, accessor) {
|
|
4173
|
-
doc.write(`if (typeof ${accessor} !== "number" || !Number.isNaN(${accessor})) return INVALID;`);
|
|
4174
|
-
return accessor;
|
|
4175
|
-
}
|
|
4176
|
-
function generateDateCheck(doc, accessor) {
|
|
4177
|
-
doc.write(`if (!(${accessor} instanceof Date) || Number.isNaN(${accessor}.getTime())) return INVALID;`);
|
|
4178
|
-
return accessor;
|
|
4179
|
-
}
|
|
4180
|
-
function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4181
|
-
const def = schema._zod.def;
|
|
4182
|
-
doc.write(`if (typeof ${accessor} !== "object" || ${accessor} === null || Array.isArray(${accessor})) return INVALID;`);
|
|
4183
|
-
const shape = def.shape;
|
|
4184
|
-
const keys = Object.keys(shape);
|
|
4185
|
-
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
4186
|
-
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
4187
|
-
const keyExpr = (k) => typeof k === "symbol" ? addConstant(ctx, k) : esc(k);
|
|
4188
|
-
const propKey = (k) => typeof k === "symbol" ? `[${keyExpr(k)}]` : esc(k);
|
|
4189
|
-
const propShape = shape;
|
|
4190
|
-
if (keys.includes("__proto__")) {
|
|
4191
|
-
throw new ZodCompileUnsupportedError('object shape key "__proto__"');
|
|
4192
|
-
}
|
|
4193
|
-
const propOutputs = new Map;
|
|
4194
|
-
for (const key of allKeys) {
|
|
4195
|
-
const propSchema = propShape[key];
|
|
4196
|
-
const kx = keyExpr(key);
|
|
4197
|
-
const inputVar = newVar(ctx);
|
|
4198
|
-
doc.write(`const ${inputVar} = ${accessor}[${kx}];`);
|
|
4199
|
-
if (propSchema._zod.optin !== undefined) {
|
|
4200
|
-
const outputVar = newVar(ctx);
|
|
4201
|
-
doc.write(`let ${outputVar} = (() => {`);
|
|
4202
|
-
doc.indented((d) => {
|
|
4203
|
-
const outputAccessor = compileChild(d, ctx, propSchema, inputVar);
|
|
4204
|
-
d.write(`return ${outputAccessor};`);
|
|
4205
|
-
});
|
|
4206
|
-
doc.write(`})();`);
|
|
4207
|
-
if (propSchema._zod.optout === "optional") {
|
|
4208
|
-
doc.write(`if (${outputVar} === INVALID) {`);
|
|
4209
|
-
doc.indented((d) => {
|
|
4210
|
-
d.write(`if (${kx} in ${accessor}) return INVALID;`);
|
|
4211
|
-
d.write(`${outputVar} = undefined;`);
|
|
4212
|
-
});
|
|
4213
|
-
doc.write(`}`);
|
|
4214
|
-
} else {
|
|
4215
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4216
|
-
}
|
|
4217
|
-
propOutputs.set(key, outputVar);
|
|
4218
|
-
} else {
|
|
4219
|
-
if (requiresPresenceCheck(propSchema)) {
|
|
4220
|
-
doc.write(`if (!(${kx} in ${accessor})) return INVALID;`);
|
|
4221
|
-
}
|
|
4222
|
-
const outputAccessor = compileChild(doc, ctx, propSchema, inputVar, buildsValue);
|
|
4223
|
-
if (outputAccessor !== null)
|
|
4224
|
-
propOutputs.set(key, outputAccessor);
|
|
4225
|
-
}
|
|
4226
|
-
}
|
|
4227
|
-
const catchall = def.catchall;
|
|
4228
|
-
let unknownKeysMode = "none";
|
|
4229
|
-
if (catchall) {
|
|
4230
|
-
const catchallType = catchall._zod.def.type;
|
|
4231
|
-
if (catchallType === "never") {
|
|
4232
|
-
const condition = keys.map((k) => `k !== ${esc(k)}`).join(" && ") || "true";
|
|
4233
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4234
|
-
doc.indented((d) => {
|
|
4235
|
-
d.write(`if (${condition}) return INVALID;`);
|
|
4236
|
-
});
|
|
4237
|
-
doc.write(`}`);
|
|
4238
|
-
} else if ((catchallType === "unknown" || catchallType === "any") && !catchall._zod.def.checks?.length) {
|
|
4239
|
-
unknownKeysMode = "passthrough";
|
|
4240
|
-
} else {
|
|
4241
|
-
unknownKeysMode = "schema";
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
const outputVar = newVar(ctx);
|
|
4245
|
-
const hasConditionalKeys = allKeys.some((k) => mayOmitUndefined(propShape[k]) || dropsWhenAbsent(propShape[k]));
|
|
4246
|
-
if (!buildsValue) {
|
|
4247
|
-
if (unknownKeysMode === "schema") {
|
|
4248
|
-
const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
|
|
4249
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4250
|
-
doc.indented((d) => {
|
|
4251
|
-
d.write(`if (k === "__proto__") continue;`);
|
|
4252
|
-
if (knownSet)
|
|
4253
|
-
d.write(`if (${knownSet}.has(k)) continue;`);
|
|
4254
|
-
const valVar = newVar(ctx);
|
|
4255
|
-
d.write(`const ${valVar} = ${accessor}[k];`);
|
|
4256
|
-
compileChild(d, ctx, catchall, valVar, false);
|
|
4257
|
-
});
|
|
4258
|
-
doc.write(`}`);
|
|
4259
|
-
}
|
|
4260
|
-
return null;
|
|
4261
|
-
}
|
|
4262
|
-
if (!hasConditionalKeys) {
|
|
4263
|
-
const propLiterals = allKeys.map((k) => `${propKey(k)}: ${propOutputs.get(k)}`).join(", ");
|
|
4264
|
-
doc.write(`const ${outputVar} = { ${propLiterals} };`);
|
|
4265
|
-
} else {
|
|
4266
|
-
doc.write(`const ${outputVar} = {};`);
|
|
4267
|
-
for (const k of allKeys) {
|
|
4268
|
-
const kx = keyExpr(k);
|
|
4269
|
-
const out = propOutputs.get(k);
|
|
4270
|
-
if (dropsWhenAbsent(propShape[k])) {
|
|
4271
|
-
doc.write(`if (${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
4272
|
-
} else if (mayOmitUndefined(propShape[k])) {
|
|
4273
|
-
doc.write(`if (${out} !== undefined || ${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
4274
|
-
} else {
|
|
4275
|
-
doc.write(`${outputVar}[${kx}] = ${out};`);
|
|
4276
|
-
}
|
|
4277
|
-
}
|
|
4278
|
-
}
|
|
4279
|
-
if (unknownKeysMode !== "none") {
|
|
4280
|
-
const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
|
|
4281
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4282
|
-
doc.indented((d) => {
|
|
4283
|
-
d.write(`if (k === "__proto__") continue;`);
|
|
4284
|
-
if (knownSet)
|
|
4285
|
-
d.write(`if (${knownSet}.has(k)) continue;`);
|
|
4286
|
-
if (unknownKeysMode === "passthrough") {
|
|
4287
|
-
d.write(`${outputVar}[k] = ${accessor}[k];`);
|
|
4288
|
-
} else {
|
|
4289
|
-
const valVar = newVar(ctx);
|
|
4290
|
-
d.write(`const ${valVar} = ${accessor}[k];`);
|
|
4291
|
-
const catchallOut = compileChild(d, ctx, catchall, valVar);
|
|
4292
|
-
d.write(`${outputVar}[k] = ${catchallOut};`);
|
|
4293
|
-
}
|
|
4294
|
-
});
|
|
4295
|
-
doc.write(`}`);
|
|
4296
|
-
}
|
|
4297
|
-
return outputVar;
|
|
4298
|
-
}
|
|
4299
|
-
function generateOptionalCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4300
|
-
const def = schema._zod.def;
|
|
4301
|
-
if (isExactOptional(schema)) {
|
|
4302
|
-
return generateCheck(doc, ctx, def.innerType, accessor, buildsValue);
|
|
4303
|
-
}
|
|
4304
|
-
if (def.innerType._zod.optin === "defaulted") {
|
|
4305
|
-
const outputVar = newVar(ctx);
|
|
4306
|
-
const branchVar = newVar(ctx);
|
|
4307
|
-
doc.write(`let ${outputVar};`);
|
|
4308
|
-
doc.write(`if (${accessor} === undefined) {`);
|
|
4309
|
-
doc.indented((d) => {
|
|
4310
|
-
d.write(`const ${branchVar} = (() => {`);
|
|
4311
|
-
d.indented((d2) => {
|
|
4312
|
-
const innerOutput = generateCheck(d2, ctx, def.innerType, accessor);
|
|
4313
|
-
d2.write(`return ${innerOutput};`);
|
|
4314
|
-
});
|
|
4315
|
-
d.write(`})();`);
|
|
4316
|
-
d.write(`if (${branchVar} !== INVALID) ${outputVar} = ${branchVar};`);
|
|
4317
|
-
});
|
|
4318
|
-
doc.write(`} else {`);
|
|
4319
|
-
doc.indented((d) => {
|
|
4320
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4321
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4322
|
-
});
|
|
4323
|
-
doc.write(`}`);
|
|
4324
|
-
return outputVar;
|
|
4325
|
-
}
|
|
4326
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4327
|
-
if (outputVar)
|
|
4328
|
-
doc.write(`let ${outputVar};`);
|
|
4329
|
-
doc.write(`if (${accessor} !== undefined) {`);
|
|
4330
|
-
doc.indented((d) => {
|
|
4331
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
|
|
4332
|
-
if (outputVar && innerOutput !== null)
|
|
4333
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4334
|
-
});
|
|
4335
|
-
doc.write(`}`);
|
|
4336
|
-
return outputVar;
|
|
4337
|
-
}
|
|
4338
|
-
function isExactOptional(schema) {
|
|
4339
|
-
return schema._zod.traits?.has("$ZodExactOptional") === true;
|
|
4340
|
-
}
|
|
4341
|
-
function requiresPresenceCheck(schema) {
|
|
4342
|
-
return schema._zod.optin === undefined && fastPathAcceptsAbsence(schema);
|
|
4343
|
-
}
|
|
4344
|
-
function fastPathAcceptsAbsence(schema) {
|
|
4345
|
-
if (schema._zod.def.coerce)
|
|
4346
|
-
return true;
|
|
4347
|
-
const def = schema._zod.def;
|
|
4348
|
-
switch (def.type) {
|
|
4349
|
-
case "any":
|
|
4350
|
-
case "unknown":
|
|
4351
|
-
case "undefined":
|
|
4352
|
-
case "void":
|
|
4353
|
-
case "default":
|
|
4354
|
-
case "prefault":
|
|
4355
|
-
case "transform":
|
|
4356
|
-
case "custom":
|
|
4357
|
-
case "lazy":
|
|
4358
|
-
return true;
|
|
4359
|
-
case "string":
|
|
4360
|
-
case "number":
|
|
4361
|
-
case "boolean":
|
|
4362
|
-
case "bigint":
|
|
4363
|
-
case "symbol":
|
|
4364
|
-
case "null":
|
|
4365
|
-
case "never":
|
|
4366
|
-
case "nan":
|
|
4367
|
-
case "date":
|
|
4368
|
-
case "object":
|
|
4369
|
-
case "array":
|
|
4370
|
-
case "tuple":
|
|
4371
|
-
case "record":
|
|
4372
|
-
case "map":
|
|
4373
|
-
case "set":
|
|
4374
|
-
case "file":
|
|
4375
|
-
case "template_literal":
|
|
4376
|
-
return false;
|
|
4377
|
-
case "nonoptional":
|
|
4378
|
-
return def.innerType ? fastPathAcceptsAbsence(def.innerType) : false;
|
|
4379
|
-
case "literal":
|
|
4380
|
-
return !!def.values?.includes(undefined);
|
|
4381
|
-
case "enum":
|
|
4382
|
-
return !!schema._zod.values?.has(undefined);
|
|
4383
|
-
case "optional":
|
|
4384
|
-
case "nullable":
|
|
4385
|
-
case "readonly":
|
|
4386
|
-
case "success":
|
|
4387
|
-
return def.innerType ? fastPathAcceptsAbsence(def.innerType) : true;
|
|
4388
|
-
case "catch":
|
|
4389
|
-
return true;
|
|
4390
|
-
case "union":
|
|
4391
|
-
return def.options ? def.options.some(fastPathAcceptsAbsence) : true;
|
|
4392
|
-
case "intersection":
|
|
4393
|
-
if (!def.left || !def.right)
|
|
4394
|
-
return true;
|
|
4395
|
-
return fastPathAcceptsAbsence(def.left) && fastPathAcceptsAbsence(def.right);
|
|
4396
|
-
case "pipe":
|
|
4397
|
-
return def.in ? fastPathAcceptsAbsence(def.in) : true;
|
|
4398
|
-
default:
|
|
4399
|
-
return true;
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
function dropsWhenAbsent(schema) {
|
|
4403
|
-
return schema._zod.optin === "optional" && schema._zod.optout === "optional";
|
|
4404
|
-
}
|
|
4405
|
-
function mayOmitUndefined(schema) {
|
|
4406
|
-
return (schema._zod.optin !== "defaulted" || schema._zod.optout === "optional") && mayOutputUndefined(schema);
|
|
4407
|
-
}
|
|
4408
|
-
function mayOutputUndefined(schema) {
|
|
4409
|
-
const def = schema._zod.def;
|
|
4410
|
-
switch (def.type) {
|
|
4411
|
-
case "string":
|
|
4412
|
-
case "number":
|
|
4413
|
-
case "boolean":
|
|
4414
|
-
case "bigint":
|
|
4415
|
-
case "symbol":
|
|
4416
|
-
case "null":
|
|
4417
|
-
case "nan":
|
|
4418
|
-
case "date":
|
|
4419
|
-
case "object":
|
|
4420
|
-
case "array":
|
|
4421
|
-
case "tuple":
|
|
4422
|
-
case "record":
|
|
4423
|
-
case "map":
|
|
4424
|
-
case "set":
|
|
4425
|
-
case "file":
|
|
4426
|
-
case "template_literal":
|
|
4427
|
-
case "never":
|
|
4428
|
-
case "success":
|
|
4429
|
-
return false;
|
|
4430
|
-
case "literal":
|
|
4431
|
-
return !!def.values?.includes(undefined);
|
|
4432
|
-
case "enum":
|
|
4433
|
-
return !!schema._zod.values?.has(undefined);
|
|
4434
|
-
case "optional":
|
|
4435
|
-
return true;
|
|
4436
|
-
case "nullable":
|
|
4437
|
-
case "readonly":
|
|
4438
|
-
case "nonoptional":
|
|
4439
|
-
return def.innerType ? mayOutputUndefined(def.innerType) : true;
|
|
4440
|
-
case "union":
|
|
4441
|
-
return def.options ? def.options.some(mayOutputUndefined) : true;
|
|
4442
|
-
case "intersection":
|
|
4443
|
-
return !def.left || !def.right || mayOutputUndefined(def.left) || mayOutputUndefined(def.right);
|
|
4444
|
-
case "pipe":
|
|
4445
|
-
return def.out ? mayOutputUndefined(def.out) : true;
|
|
4446
|
-
default:
|
|
4447
|
-
return true;
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4451
|
-
const def = schema._zod.def;
|
|
4452
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4453
|
-
if (outputVar)
|
|
4454
|
-
doc.write(`let ${outputVar} = null;`);
|
|
4455
|
-
doc.write(`if (${accessor} !== null) {`);
|
|
4456
|
-
doc.indented((d) => {
|
|
4457
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
|
|
4458
|
-
if (outputVar && innerOutput !== null)
|
|
4459
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4460
|
-
});
|
|
4461
|
-
doc.write(`}`);
|
|
4462
|
-
return outputVar;
|
|
4463
|
-
}
|
|
4464
|
-
function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4465
|
-
const def = schema._zod.def;
|
|
4466
|
-
doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
|
|
4467
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4468
|
-
const iVar = newVar(ctx);
|
|
4469
|
-
const elemVar = newVar(ctx);
|
|
4470
|
-
if (outputVar)
|
|
4471
|
-
doc.write(`const ${outputVar} = new Array(${accessor}.length);`);
|
|
4472
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${accessor}.length; ${iVar}++) {`);
|
|
4473
|
-
doc.indented((d) => {
|
|
4474
|
-
d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
|
|
4475
|
-
const elemOutput = compileChild(d, ctx, def.element, elemVar, buildsValue);
|
|
4476
|
-
if (outputVar && elemOutput !== null)
|
|
4477
|
-
d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
|
|
4478
|
-
});
|
|
4479
|
-
doc.write(`}`);
|
|
4480
|
-
return outputVar;
|
|
4481
|
-
}
|
|
4482
|
-
function generateLiteralCheck(doc, ctx, schema, accessor) {
|
|
4483
|
-
const def = schema._zod.def;
|
|
4484
|
-
const values = def.values;
|
|
4485
|
-
if (values.length !== 1) {
|
|
4486
|
-
const literalSet = addConstant(ctx, new Set(values));
|
|
4487
|
-
doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
|
|
4488
|
-
return accessor;
|
|
4489
|
-
}
|
|
4490
|
-
const value = values[0];
|
|
4491
|
-
if (typeof value === "number" && Number.isNaN(value)) {
|
|
4492
|
-
const literalSet = addConstant(ctx, new Set(values));
|
|
4493
|
-
doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
|
|
4494
|
-
return accessor;
|
|
4495
|
-
}
|
|
4496
|
-
if (typeof value === "string") {
|
|
4497
|
-
doc.write(`if (${accessor} !== ${esc(value)}) return INVALID;`);
|
|
4498
|
-
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
4499
|
-
doc.write(`if (${accessor} !== ${value}) return INVALID;`);
|
|
4500
|
-
} else if (value === null) {
|
|
4501
|
-
doc.write(`if (${accessor} !== null) return INVALID;`);
|
|
4502
|
-
} else if (value === undefined) {
|
|
4503
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4504
|
-
} else if (typeof value === "bigint") {
|
|
4505
|
-
doc.write(`if (${accessor} !== ${value}n) return INVALID;`);
|
|
4506
|
-
} else {
|
|
4507
|
-
throw new ZodCompileUnsupportedError(`literal type ${typeof value}`);
|
|
4508
|
-
}
|
|
4509
|
-
return accessor;
|
|
4510
|
-
}
|
|
4511
|
-
function generateEnumCheck(doc, ctx, schema, accessor) {
|
|
4512
|
-
const values = schema._zod.values;
|
|
4513
|
-
if (!values) {
|
|
4514
|
-
throw new ZodCompileUnsupportedError("enum schema without enumerated values");
|
|
4515
|
-
}
|
|
4516
|
-
const enumSet = addConstant(ctx, values);
|
|
4517
|
-
doc.write(`if (!${enumSet}.has(${accessor})) return INVALID;`);
|
|
4518
|
-
return accessor;
|
|
4519
|
-
}
|
|
4520
|
-
function generateWrapperCheck(doc, ctx, schema, accessor) {
|
|
4521
|
-
const def = schema._zod.def;
|
|
4522
|
-
return generateCheck(doc, ctx, def.innerType, accessor);
|
|
4523
|
-
}
|
|
4524
|
-
function generateDefaultCheck(doc, ctx, schema, accessor) {
|
|
4525
|
-
const def = schema._zod.def;
|
|
4526
|
-
const descriptor = Object.getOwnPropertyDescriptor(schema._zod.def, "defaultValue");
|
|
4527
|
-
const defaultGetter = descriptor ? () => schema._zod.def.defaultValue : undefined;
|
|
4528
|
-
if (schema._zod.def.type === "prefault") {
|
|
4529
|
-
if (!defaultGetter) {
|
|
4530
|
-
return generateCheck(doc, ctx, def.innerType, accessor);
|
|
4531
|
-
}
|
|
4532
|
-
const defaultFn = addConstant(ctx, defaultGetter);
|
|
4533
|
-
const inputVar = newVar(ctx);
|
|
4534
|
-
doc.write(`let ${inputVar} = ${accessor};`);
|
|
4535
|
-
doc.write(`if (${accessor} === undefined) ${inputVar} = ${defaultFn}();`);
|
|
4536
|
-
return generateCheck(doc, ctx, def.innerType, inputVar);
|
|
4537
|
-
}
|
|
4538
|
-
const outputVar = newVar(ctx);
|
|
4539
|
-
if (defaultGetter) {
|
|
4540
|
-
const defaultFn = addConstant(ctx, defaultGetter);
|
|
4541
|
-
const cloneFn = addConstant(ctx, shallowClone);
|
|
4542
|
-
doc.write(`let ${outputVar};`);
|
|
4543
|
-
doc.write(`if (${accessor} === undefined) {`);
|
|
4544
|
-
doc.indented((d) => {
|
|
4545
|
-
d.write(`${outputVar} = ${cloneFn}(${defaultFn}());`);
|
|
4546
|
-
});
|
|
4547
|
-
doc.write(`} else {`);
|
|
4548
|
-
doc.indented((d) => {
|
|
4549
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4550
|
-
d.write(`${outputVar} = ${innerOutput} === undefined ? ${cloneFn}(${defaultFn}()) : ${innerOutput};`);
|
|
4551
|
-
});
|
|
4552
|
-
doc.write(`}`);
|
|
4553
|
-
} else {
|
|
4554
|
-
doc.write(`let ${outputVar};`);
|
|
4555
|
-
doc.write(`if (${accessor} !== undefined) {`);
|
|
4556
|
-
doc.indented((d) => {
|
|
4557
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4558
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4559
|
-
});
|
|
4560
|
-
doc.write(`}`);
|
|
4561
|
-
}
|
|
4562
|
-
return outputVar;
|
|
4563
|
-
}
|
|
4564
|
-
function generateNonOptionalCheck(doc, ctx, schema, accessor) {
|
|
4565
|
-
const def = schema._zod.def;
|
|
4566
|
-
const innerOutput = generateCheck(doc, ctx, def.innerType, accessor);
|
|
4567
|
-
const outputVar = newVar(ctx);
|
|
4568
|
-
doc.write(`const ${outputVar} = ${innerOutput};`);
|
|
4569
|
-
doc.write(`if (${outputVar} === undefined) return INVALID;`);
|
|
4570
|
-
return outputVar;
|
|
4571
|
-
}
|
|
4572
|
-
function generateTupleCheck(doc, ctx, schema, accessor) {
|
|
4573
|
-
const def = schema._zod.def;
|
|
4574
|
-
const items = def.items;
|
|
4575
|
-
const rest = def.rest;
|
|
4576
|
-
doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
|
|
4577
|
-
const optinStart = getTupleOptStart(items, "optin");
|
|
4578
|
-
const optoutStart = getTupleOptStart(items, "optout");
|
|
4579
|
-
if (rest) {
|
|
4580
|
-
doc.write(`if (${accessor}.length < ${optinStart}) return INVALID;`);
|
|
4581
|
-
} else {
|
|
4582
|
-
doc.write(`if (${accessor}.length < ${optinStart} || ${accessor}.length > ${items.length}) return INVALID;`);
|
|
4583
|
-
}
|
|
4584
|
-
const outputVar = newVar(ctx);
|
|
4585
|
-
doc.write(`const ${outputVar} = [];`);
|
|
4586
|
-
for (let i = 0;i < items.length; i++) {
|
|
4587
|
-
const itemSchema = items[i];
|
|
4588
|
-
if (i >= optoutStart) {
|
|
4589
|
-
doc.write(`if (${outputVar}.length === ${i}) {`);
|
|
4590
|
-
doc.indented((d) => {
|
|
4591
|
-
d.write(`if (${i} < ${accessor}.length) {`);
|
|
4592
|
-
d.indented((d2) => {
|
|
4593
|
-
const elemVar = newVar(ctx);
|
|
4594
|
-
d2.write(`const ${elemVar} = ${accessor}[${i}];`);
|
|
4595
|
-
const elemOutput = compileChild(d2, ctx, itemSchema, elemVar);
|
|
4596
|
-
d2.write(`${outputVar}[${i}] = ${elemOutput};`);
|
|
4597
|
-
});
|
|
4598
|
-
d.write(`} else {`);
|
|
4599
|
-
d.indented((d2) => {
|
|
4600
|
-
if (dropsWhenAbsent(itemSchema)) {
|
|
4601
|
-
d2.write(`${outputVar}.length = ${i};`);
|
|
4602
|
-
return;
|
|
4603
|
-
}
|
|
4604
|
-
const elemVar = newVar(ctx);
|
|
4605
|
-
const branchVar = newVar(ctx);
|
|
4606
|
-
d2.write(`const ${elemVar} = undefined;`);
|
|
4607
|
-
d2.write(`const ${branchVar} = (() => {`);
|
|
4608
|
-
d2.indented((d3) => {
|
|
4609
|
-
const elemOutput = compileChild(d3, ctx, itemSchema, elemVar);
|
|
4610
|
-
d3.write(`return ${elemOutput};`);
|
|
4611
|
-
});
|
|
4612
|
-
d2.write(`})();`);
|
|
4613
|
-
d2.write(`if (${branchVar} === INVALID || ${branchVar} === undefined) ${outputVar}.length = ${i};`);
|
|
4614
|
-
d2.write(`else ${outputVar}[${i}] = ${branchVar};`);
|
|
4615
|
-
});
|
|
4616
|
-
d.write(`}`);
|
|
4617
|
-
});
|
|
4618
|
-
doc.write(`}`);
|
|
4619
|
-
} else {
|
|
4620
|
-
const elemVar = newVar(ctx);
|
|
4621
|
-
doc.write(`const ${elemVar} = ${accessor}[${i}];`);
|
|
4622
|
-
const elemOutput = compileChild(doc, ctx, itemSchema, elemVar);
|
|
4623
|
-
doc.write(`${outputVar}[${i}] = ${elemOutput};`);
|
|
4624
|
-
}
|
|
4625
|
-
}
|
|
4626
|
-
if (rest) {
|
|
4627
|
-
const iVar = newVar(ctx);
|
|
4628
|
-
const elemVar = newVar(ctx);
|
|
4629
|
-
doc.write(`for (let ${iVar} = ${items.length}; ${iVar} < ${accessor}.length; ${iVar}++) {`);
|
|
4630
|
-
doc.indented((d) => {
|
|
4631
|
-
d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
|
|
4632
|
-
const elemOutput = compileChild(d, ctx, rest, elemVar);
|
|
4633
|
-
d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
|
|
4634
|
-
});
|
|
4635
|
-
doc.write(`}`);
|
|
4636
|
-
}
|
|
4637
|
-
return outputVar;
|
|
4638
|
-
}
|
|
4639
|
-
function getTupleOptStart(items, key) {
|
|
4640
|
-
for (let i = items.length - 1;i >= 0; i--) {
|
|
4641
|
-
const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
|
|
4642
|
-
if (!omittable)
|
|
4643
|
-
return i + 1;
|
|
4644
|
-
}
|
|
4645
|
-
return 0;
|
|
4646
|
-
}
|
|
4647
|
-
function generateUnionCheck(doc, ctx, schema, accessor) {
|
|
4648
|
-
const def = schema._zod.def;
|
|
4649
|
-
const options = def.options;
|
|
4650
|
-
if (def.discriminator) {
|
|
4651
|
-
return generateDiscriminatedUnionCheck(doc, ctx, def, accessor);
|
|
4652
|
-
}
|
|
4653
|
-
if (def.inclusive === false) {
|
|
4654
|
-
throw new ZodCompileUnsupportedError("exclusive unions (z.xor)");
|
|
4655
|
-
}
|
|
4656
|
-
if (options.length === 0) {
|
|
4657
|
-
doc.write("return INVALID;");
|
|
4658
|
-
return accessor;
|
|
4659
|
-
}
|
|
4660
|
-
if (options.length === 1) {
|
|
4661
|
-
return generateCheck(doc, ctx, options[0], accessor);
|
|
4662
|
-
}
|
|
4663
|
-
const allLiterals = options.every((opt) => opt._zod.def.type === "literal" && !opt._zod.def.checks?.length);
|
|
4664
|
-
if (allLiterals) {
|
|
4665
|
-
const values = new Set(options.flatMap((opt) => opt._zod.def.values));
|
|
4666
|
-
const valuesConst = addConstant(ctx, values);
|
|
4667
|
-
doc.write(`if (!${valuesConst}.has(${accessor})) return INVALID;`);
|
|
4668
|
-
return accessor;
|
|
4669
|
-
}
|
|
4670
|
-
const outputVar = newVar(ctx);
|
|
4671
|
-
doc.write(`let ${outputVar};`);
|
|
4672
|
-
for (let i = 0;i < options.length; i++) {
|
|
4673
|
-
const opt = options[i];
|
|
4674
|
-
if (i === 0) {
|
|
4675
|
-
doc.write(`${outputVar} = (() => {`);
|
|
4676
|
-
} else {
|
|
4677
|
-
doc.write(`if (${outputVar} === INVALID) ${outputVar} = (() => {`);
|
|
3371
|
+
return "Invalid input: more than one option matched";
|
|
3372
|
+
}
|
|
3373
|
+
return "Invalid input";
|
|
3374
|
+
case "invalid_element":
|
|
3375
|
+
return `Invalid value in ${issue.origin}`;
|
|
3376
|
+
default:
|
|
3377
|
+
return `Invalid input`;
|
|
4678
3378
|
}
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
doc.write("return INVALID;");
|
|
4694
|
-
return accessor;
|
|
3379
|
+
};
|
|
3380
|
+
};
|
|
3381
|
+
var init_en = __esm(() => {
|
|
3382
|
+
init_util();
|
|
3383
|
+
});
|
|
3384
|
+
|
|
3385
|
+
// node_modules/zod/v4/locales/index.js
|
|
3386
|
+
var init_locales = () => {};
|
|
3387
|
+
|
|
3388
|
+
// node_modules/zod/v4/core/registries.js
|
|
3389
|
+
class $ZodRegistry {
|
|
3390
|
+
constructor() {
|
|
3391
|
+
this._map = new WeakMap;
|
|
3392
|
+
this._idmap = new Map;
|
|
4695
3393
|
}
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
const claimed = new Set;
|
|
4702
|
-
for (const option of def.options) {
|
|
4703
|
-
const values = option._zod.propValues?.[def.discriminator];
|
|
4704
|
-
if (!values || values.size === 0) {
|
|
4705
|
-
throw new ZodCompileUnsupportedError("discriminated union option without static discriminator values");
|
|
3394
|
+
add(schema, ..._meta) {
|
|
3395
|
+
const meta = _meta[0];
|
|
3396
|
+
this._map.set(schema, meta);
|
|
3397
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3398
|
+
this._idmap.set(meta.id, schema);
|
|
4706
3399
|
}
|
|
4707
|
-
|
|
4708
|
-
if (claimed.has(value)) {
|
|
4709
|
-
throw new ZodCompileUnsupportedError(`duplicate discriminator value ${String(value)}`);
|
|
4710
|
-
}
|
|
4711
|
-
claimed.add(value);
|
|
4712
|
-
}
|
|
4713
|
-
const conditions = Array.from(values, (value) => literalEquality(ctx, discVar, value));
|
|
4714
|
-
const prefix = firstBranch ? "if" : "else if";
|
|
4715
|
-
doc.write(`${prefix} (${conditions.join(" || ")}) {`);
|
|
4716
|
-
doc.indented((d) => {
|
|
4717
|
-
const branchOutput = generateCheck(d, ctx, option, accessor);
|
|
4718
|
-
d.write(`${outputVar} = ${branchOutput};`);
|
|
4719
|
-
});
|
|
4720
|
-
doc.write(`}`);
|
|
4721
|
-
firstBranch = false;
|
|
3400
|
+
return this;
|
|
4722
3401
|
}
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
if (typeof value === "string")
|
|
4728
|
-
return `${accessor} === ${esc(value)}`;
|
|
4729
|
-
if (typeof value === "number") {
|
|
4730
|
-
if (Number.isNaN(value))
|
|
4731
|
-
return `Number.isNaN(${accessor})`;
|
|
4732
|
-
return `${accessor} === ${value}`;
|
|
3402
|
+
clear() {
|
|
3403
|
+
this._map = new WeakMap;
|
|
3404
|
+
this._idmap = new Map;
|
|
3405
|
+
return this;
|
|
4733
3406
|
}
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
return `${accessor} === ${value}n`;
|
|
4742
|
-
if (typeof value === "symbol") {
|
|
4743
|
-
const symbolConst = addConstant(ctx, value);
|
|
4744
|
-
return `${accessor} === ${symbolConst}`;
|
|
3407
|
+
remove(schema) {
|
|
3408
|
+
const meta = this._map.get(schema);
|
|
3409
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
3410
|
+
this._idmap.delete(meta.id);
|
|
3411
|
+
}
|
|
3412
|
+
this._map.delete(schema);
|
|
3413
|
+
return this;
|
|
4745
3414
|
}
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
doc.write(`const ${mergedVar} = ${mergeConst}(${leftOutput}, ${rightOutput});`);
|
|
4756
|
-
doc.write(`if (!${mergedVar}.valid) return INVALID;`);
|
|
4757
|
-
return `${mergedVar}.data`;
|
|
4758
|
-
}
|
|
4759
|
-
function generateRecordCheck(doc, ctx, schema, accessor) {
|
|
4760
|
-
const def = schema._zod.def;
|
|
4761
|
-
const isPlainObjectConst = addConstant(ctx, isPlainObject);
|
|
4762
|
-
doc.write(`if (!${isPlainObjectConst}(${accessor})) return INVALID;`);
|
|
4763
|
-
const outputVar = newVar(ctx);
|
|
4764
|
-
const kVar = newVar(ctx);
|
|
4765
|
-
const valVar = newVar(ctx);
|
|
4766
|
-
doc.write(`const ${outputVar} = {};`);
|
|
4767
|
-
const recordDef = def;
|
|
4768
|
-
const keyValues = recordDef.partial ? undefined : def.keyType._zod.values;
|
|
4769
|
-
if (keyValues) {
|
|
4770
|
-
const inputKeys = [];
|
|
4771
|
-
for (const key of keyValues) {
|
|
4772
|
-
if (!(typeof key === "string" || typeof key === "number" || typeof key === "symbol")) {
|
|
4773
|
-
throw new ZodCompileUnsupportedError(`record key value ${String(key)}`);
|
|
4774
|
-
}
|
|
4775
|
-
const inputKey = typeof key === "number" ? key.toString() : key;
|
|
4776
|
-
if (inputKey === "__proto__") {
|
|
4777
|
-
throw new ZodCompileUnsupportedError('record key "__proto__"');
|
|
4778
|
-
}
|
|
4779
|
-
inputKeys.push(inputKey);
|
|
4780
|
-
const keyConst = addConstant(ctx, key);
|
|
4781
|
-
const outKey = generateCheck(doc, ctx, def.keyType, keyConst);
|
|
4782
|
-
const valueVar = newVar(ctx);
|
|
4783
|
-
doc.write(`const ${valueVar} = ${accessor}[${literalPropertyKey(ctx, inputKey)}];`);
|
|
4784
|
-
const valOutput = compileChild(doc, ctx, def.valueType, valueVar);
|
|
4785
|
-
doc.write(`${outputVar}[${outKey}] = ${valOutput};`);
|
|
4786
|
-
}
|
|
4787
|
-
const knownKeysConst = addConstant(ctx, new Set(inputKeys));
|
|
4788
|
-
doc.write(`for (const ${kVar} in ${accessor}) {`);
|
|
4789
|
-
doc.indented((d) => {
|
|
4790
|
-
d.write(`if (${knownKeysConst}.has(${kVar})) continue;`);
|
|
4791
|
-
if (recordDef.mode === "loose") {
|
|
4792
|
-
d.write(`if (${kVar} !== "__proto__") ${outputVar}[${kVar}] = ${accessor}[${kVar}];`);
|
|
4793
|
-
} else {
|
|
4794
|
-
d.write(`return INVALID;`);
|
|
4795
|
-
}
|
|
4796
|
-
});
|
|
4797
|
-
doc.write(`}`);
|
|
4798
|
-
return outputVar;
|
|
4799
|
-
}
|
|
4800
|
-
const keyDef = def.keyType._zod.def;
|
|
4801
|
-
const keyIsBareString = keyDef.type === "string" && keyDef.format === undefined && !keyDef.coerce && (keyDef.checks?.length ?? 0) === 0;
|
|
4802
|
-
if (!keyIsBareString) {
|
|
4803
|
-
const isLoose = def.mode === "loose";
|
|
4804
|
-
const keyFn = compileFn(def.keyType);
|
|
4805
|
-
if (keyFn.definite === false)
|
|
4806
|
-
ctx.definite = false;
|
|
4807
|
-
const keyFast = addConstant(ctx, keyFn);
|
|
4808
|
-
const numericConst = addConstant(ctx, number);
|
|
4809
|
-
const outKeyVar = newVar(ctx);
|
|
4810
|
-
emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
|
|
4811
|
-
d.write(`let ${outKeyVar} = ${keyFast}(${kVar});`);
|
|
4812
|
-
d.write(`if (${outKeyVar} === INVALID && typeof ${kVar} === "string" && ${numericConst}.test(${kVar})) ${outKeyVar} = ${keyFast}(Number(${kVar}));`);
|
|
4813
|
-
if (isLoose) {
|
|
4814
|
-
d.write(`if (${outKeyVar} === INVALID) { ${outputVar}[${kVar}] = ${accessor}[${kVar}]; continue; }`);
|
|
4815
|
-
} else {
|
|
4816
|
-
d.write(`if (${outKeyVar} === INVALID) return INVALID;`);
|
|
4817
|
-
}
|
|
4818
|
-
d.write(`if (${outKeyVar} === "__proto__") continue;`);
|
|
4819
|
-
const valueVar = newVar(ctx);
|
|
4820
|
-
d.write(`const ${valueVar} = ${accessor}[${kVar}];`);
|
|
4821
|
-
const valOutput = compileChild(d, ctx, def.valueType, valueVar);
|
|
4822
|
-
d.write(`${outputVar}[${outKeyVar}] = ${valOutput};`);
|
|
4823
|
-
});
|
|
4824
|
-
return outputVar;
|
|
4825
|
-
}
|
|
4826
|
-
emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
|
|
4827
|
-
d.write(`const ${valVar} = ${accessor}[${kVar}];`);
|
|
4828
|
-
const valOutput = compileChild(d, ctx, def.valueType, valVar);
|
|
4829
|
-
d.write(`${outputVar}[${kVar}] = ${valOutput};`);
|
|
4830
|
-
}, `return INVALID;`);
|
|
4831
|
-
return outputVar;
|
|
4832
|
-
}
|
|
4833
|
-
function emitOwnKeys(doc, ctx, accessor, kVar, body, onSymbol) {
|
|
4834
|
-
const propIsEnumerableConst = addConstant(ctx, Object.prototype.propertyIsEnumerable);
|
|
4835
|
-
const symsVar = newVar(ctx);
|
|
4836
|
-
const keysVar = newVar(ctx);
|
|
4837
|
-
const iVar = newVar(ctx);
|
|
4838
|
-
doc.write(`const ${symsVar} = Object.getOwnPropertySymbols(${accessor});`);
|
|
4839
|
-
doc.write(`const ${keysVar} = Object.getOwnPropertyNames(${accessor});`);
|
|
4840
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${keysVar}.length; ${iVar}++) {`);
|
|
4841
|
-
doc.indented((d) => {
|
|
4842
|
-
d.write(`const ${kVar} = ${keysVar}[${iVar}];`);
|
|
4843
|
-
d.write(`if (${kVar} === "__proto__" || !${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
|
|
4844
|
-
body(d);
|
|
4845
|
-
});
|
|
4846
|
-
doc.write(`}`);
|
|
4847
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${symsVar}.length; ${iVar}++) {`);
|
|
4848
|
-
doc.indented((d) => {
|
|
4849
|
-
d.write(`const ${kVar} = ${symsVar}[${iVar}];`);
|
|
4850
|
-
d.write(`if (!${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
|
|
4851
|
-
if (onSymbol)
|
|
4852
|
-
d.write(onSymbol);
|
|
4853
|
-
else
|
|
4854
|
-
body(d);
|
|
4855
|
-
});
|
|
4856
|
-
doc.write(`}`);
|
|
4857
|
-
}
|
|
4858
|
-
function literalPropertyKey(ctx, key) {
|
|
4859
|
-
if (typeof key === "string")
|
|
4860
|
-
return esc(key);
|
|
4861
|
-
return addConstant(ctx, key);
|
|
4862
|
-
}
|
|
4863
|
-
function generateMapCheck(doc, ctx, schema, accessor) {
|
|
4864
|
-
const def = schema._zod.def;
|
|
4865
|
-
doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
|
|
4866
|
-
const outputVar = newVar(ctx);
|
|
4867
|
-
const kVar = newVar(ctx);
|
|
4868
|
-
const valVar = newVar(ctx);
|
|
4869
|
-
doc.write(`const ${outputVar} = new Map();`);
|
|
4870
|
-
doc.write(`for (const [${kVar}, ${valVar}] of ${accessor}) {`);
|
|
4871
|
-
doc.indented((d) => {
|
|
4872
|
-
const keyOutput = generateCheck(d, ctx, def.keyType, kVar);
|
|
4873
|
-
const valOutput = generateCheck(d, ctx, def.valueType, valVar);
|
|
4874
|
-
d.write(`${outputVar}.set(${keyOutput}, ${valOutput});`);
|
|
4875
|
-
});
|
|
4876
|
-
doc.write(`}`);
|
|
4877
|
-
return outputVar;
|
|
4878
|
-
}
|
|
4879
|
-
function generateSetCheck(doc, ctx, schema, accessor) {
|
|
4880
|
-
const def = schema._zod.def;
|
|
4881
|
-
doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
|
|
4882
|
-
const outputVar = newVar(ctx);
|
|
4883
|
-
const valVar = newVar(ctx);
|
|
4884
|
-
doc.write(`const ${outputVar} = new Set();`);
|
|
4885
|
-
doc.write(`for (const ${valVar} of ${accessor}) {`);
|
|
4886
|
-
doc.indented((d) => {
|
|
4887
|
-
const valOutput = generateCheck(d, ctx, def.valueType, valVar);
|
|
4888
|
-
d.write(`${outputVar}.add(${valOutput});`);
|
|
4889
|
-
});
|
|
4890
|
-
doc.write(`}`);
|
|
4891
|
-
return outputVar;
|
|
4892
|
-
}
|
|
4893
|
-
function generateFileCheck(doc, accessor) {
|
|
4894
|
-
doc.write(`if (!(${accessor} instanceof File)) return INVALID;`);
|
|
4895
|
-
return accessor;
|
|
4896
|
-
}
|
|
4897
|
-
function generateTemplateLiteralCheck(doc, ctx, schema, accessor) {
|
|
4898
|
-
doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
|
|
4899
|
-
const pattern = schema._zod.pattern;
|
|
4900
|
-
if (pattern) {
|
|
4901
|
-
const patternConst = addConstant(ctx, pattern);
|
|
4902
|
-
doc.write(`${patternConst}.lastIndex = 0;`);
|
|
4903
|
-
doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
|
|
4904
|
-
}
|
|
4905
|
-
return accessor;
|
|
4906
|
-
}
|
|
4907
|
-
function generateLazyCheck(doc, ctx, schema, accessor) {
|
|
4908
|
-
const def = schema._zod.def;
|
|
4909
|
-
const getterConst = addUserConstant(ctx, def.getter);
|
|
4910
|
-
const cacheConst = addConstant(ctx, { parser: null });
|
|
4911
|
-
doc.write(`if (!${cacheConst}.parser) {`);
|
|
4912
|
-
doc.indented((d) => {
|
|
4913
|
-
d.write(`const inner = ${getterConst}();`);
|
|
4914
|
-
d.write(`${cacheConst}.parser = function(input) {`);
|
|
4915
|
-
d.indented((d2) => {
|
|
4916
|
-
d2.write(`const result = inner._zod.run({ value: input, issues: [] }, {});`);
|
|
4917
|
-
d2.write(`return result.issues.length === 0 ? result.value : INVALID;`);
|
|
4918
|
-
});
|
|
4919
|
-
d.write(`};`);
|
|
4920
|
-
});
|
|
4921
|
-
doc.write(`}`);
|
|
4922
|
-
const outputVar = newVar(ctx);
|
|
4923
|
-
doc.write(`const ${outputVar} = ${cacheConst}.parser(${accessor});`);
|
|
4924
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4925
|
-
return outputVar;
|
|
4926
|
-
}
|
|
4927
|
-
function generatePipeCheck(doc, ctx, schema, accessor) {
|
|
4928
|
-
const def = schema._zod.def;
|
|
4929
|
-
const inputOutput = generateCheck(doc, ctx, def.in, accessor);
|
|
4930
|
-
if (def.transform) {
|
|
4931
|
-
if (isAsyncFunction(def.transform)) {
|
|
4932
|
-
throw new ZodCompileAsyncError("z.compile: async transforms in pipes are not supported");
|
|
4933
|
-
}
|
|
4934
|
-
const transformFn = def.transform;
|
|
4935
|
-
const helperFn = (value) => {
|
|
4936
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
4937
|
-
const result = transformFn(value, fakePayload);
|
|
4938
|
-
if (result instanceof Promise)
|
|
4939
|
-
return INVALID;
|
|
4940
|
-
return fakePayload.issues.length === 0 ? result : INVALID;
|
|
4941
|
-
};
|
|
4942
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
4943
|
-
const transformedVar = newVar(ctx);
|
|
4944
|
-
doc.write(`const ${transformedVar} = ${helperConst}(${inputOutput});`);
|
|
4945
|
-
doc.write(`if (${transformedVar} === INVALID) return INVALID;`);
|
|
4946
|
-
return generateCheck(doc, ctx, def.out, transformedVar);
|
|
4947
|
-
} else {
|
|
4948
|
-
return generateCheck(doc, ctx, def.out, inputOutput);
|
|
3415
|
+
get(schema) {
|
|
3416
|
+
const p = schema._zod.parent;
|
|
3417
|
+
if (p) {
|
|
3418
|
+
const pm = { ...this.get(p) ?? {} };
|
|
3419
|
+
delete pm.id;
|
|
3420
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
3421
|
+
return Object.keys(f).length ? f : undefined;
|
|
3422
|
+
}
|
|
3423
|
+
return this._map.get(schema);
|
|
4949
3424
|
}
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
return typeof fn === "function" && (fn.constructor.name === "AsyncFunction" || fn[Symbol.toStringTag] === "AsyncFunction");
|
|
4953
|
-
}
|
|
4954
|
-
function generateCustomCheck(doc, ctx, schema, accessor) {
|
|
4955
|
-
const def = schema._zod.def;
|
|
4956
|
-
if (def.fn) {
|
|
4957
|
-
if (isAsyncFunction(def.fn)) {
|
|
4958
|
-
throw new ZodCompileAsyncError("z.compile: async custom predicates are not supported");
|
|
4959
|
-
}
|
|
4960
|
-
const fnConst = addUserConstant(ctx, def.fn);
|
|
4961
|
-
const throwAsyncConst = addConstant(ctx, throwAsync);
|
|
4962
|
-
const resVar = newVar(ctx);
|
|
4963
|
-
doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
|
|
4964
|
-
doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
|
|
4965
|
-
doc.write(`if (!${resVar}) return INVALID;`);
|
|
4966
|
-
} else {
|
|
4967
|
-
throw new ZodCompileUnsupportedError("custom schema without a predicate function");
|
|
3425
|
+
has(schema) {
|
|
3426
|
+
return this._map.has(schema);
|
|
4968
3427
|
}
|
|
4969
|
-
return accessor;
|
|
4970
|
-
}
|
|
4971
|
-
function runtimeCatch(innerSchema, catchValue, value) {
|
|
4972
|
-
const result = innerSchema._zod.run({ value, issues: [] }, {});
|
|
4973
|
-
if (result && typeof result.then === "function")
|
|
4974
|
-
return INVALID;
|
|
4975
|
-
const r = result;
|
|
4976
|
-
if (r.issues.length === 0)
|
|
4977
|
-
return r.value;
|
|
4978
|
-
return catchValue();
|
|
4979
3428
|
}
|
|
4980
|
-
function
|
|
4981
|
-
|
|
4982
|
-
if (!def.catchValue[CONSTANT_CATCH]) {
|
|
4983
|
-
throw new ZodCompileUnsupportedError("catch with a callback (only a constant catch value compiles)", false);
|
|
4984
|
-
}
|
|
4985
|
-
const outputVar = newVar(ctx);
|
|
4986
|
-
doc.write(`let ${outputVar} = (() => {`);
|
|
4987
|
-
doc.indented((d) => {
|
|
4988
|
-
const innerOut = compileChild(d, ctx, def.innerType, accessor);
|
|
4989
|
-
d.write(`return ${innerOut};`);
|
|
4990
|
-
});
|
|
4991
|
-
doc.write(`})();`);
|
|
4992
|
-
const innerConst = addConstant(ctx, def.innerType);
|
|
4993
|
-
const catchConst = addUserConstant(ctx, def.catchValue);
|
|
4994
|
-
const catchHelperConst = addConstant(ctx, runtimeCatch);
|
|
4995
|
-
doc.write(`if (${outputVar} === INVALID) {`);
|
|
4996
|
-
doc.indented((d) => {
|
|
4997
|
-
d.write(`${outputVar} = ${catchHelperConst}(${innerConst}, ${catchConst}, ${accessor});`);
|
|
4998
|
-
d.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4999
|
-
});
|
|
5000
|
-
doc.write(`}`);
|
|
5001
|
-
return outputVar;
|
|
5002
|
-
}
|
|
5003
|
-
function generateTransformCheck(doc, ctx, schema, accessor) {
|
|
5004
|
-
const def = schema._zod.def;
|
|
5005
|
-
if (def.transform) {
|
|
5006
|
-
if (isAsyncFunction(def.transform)) {
|
|
5007
|
-
throw new ZodCompileAsyncError("z.compile: async transforms are not supported");
|
|
5008
|
-
}
|
|
5009
|
-
const transformFn = def.transform;
|
|
5010
|
-
const helperFn = (value) => {
|
|
5011
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
5012
|
-
const result = transformFn(value, fakePayload);
|
|
5013
|
-
if (result instanceof Promise)
|
|
5014
|
-
return INVALID;
|
|
5015
|
-
return fakePayload.issues.length === 0 ? result : INVALID;
|
|
5016
|
-
};
|
|
5017
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
5018
|
-
const outputVar = newVar(ctx);
|
|
5019
|
-
doc.write(`const ${outputVar} = ${helperConst}(${accessor});`);
|
|
5020
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
5021
|
-
return outputVar;
|
|
5022
|
-
}
|
|
5023
|
-
return accessor;
|
|
3429
|
+
function registry() {
|
|
3430
|
+
return new $ZodRegistry;
|
|
5024
3431
|
}
|
|
5025
|
-
var
|
|
3432
|
+
var _a2, globalRegistry;
|
|
3433
|
+
var init_registries = __esm(() => {
|
|
3434
|
+
(_a2 = globalThis).__zod_globalRegistry ?? (_a2.__zod_globalRegistry = registry());
|
|
3435
|
+
globalRegistry = globalThis.__zod_globalRegistry;
|
|
3436
|
+
});
|
|
3437
|
+
|
|
3438
|
+
// node_modules/zod/v4/core/compile.js
|
|
3439
|
+
var INVALID, FALLBACK_FLAG, WHEN_DEFAULTED_CHECKS, PATTERN_IS_COMPLETE;
|
|
5026
3440
|
var init_compile = __esm(() => {
|
|
5027
|
-
init_core();
|
|
5028
|
-
init_memoizer();
|
|
5029
|
-
init_regexes();
|
|
5030
|
-
init_schemas();
|
|
5031
|
-
init_util();
|
|
5032
3441
|
INVALID = Symbol.for("zod.compile.invalid");
|
|
5033
3442
|
FALLBACK_FLAG = Symbol.for("zod.compile.fallback");
|
|
5034
|
-
ZodCompileAsyncError = class ZodCompileAsyncError extends Error {
|
|
5035
|
-
constructor(message = "z.compile does not support async refinements, transforms, or checks") {
|
|
5036
|
-
super(message);
|
|
5037
|
-
this.name = "ZodCompileAsyncError";
|
|
5038
|
-
}
|
|
5039
|
-
};
|
|
5040
|
-
ZodCompileUnsupportedError = class ZodCompileUnsupportedError extends Error {
|
|
5041
|
-
constructor(feature, islandable = true) {
|
|
5042
|
-
super(`z.compile does not support ${feature}; this schema must use the runtime parser`);
|
|
5043
|
-
this.name = "ZodCompileUnsupportedError";
|
|
5044
|
-
this.islandable = islandable;
|
|
5045
|
-
}
|
|
5046
|
-
};
|
|
5047
3443
|
WHEN_DEFAULTED_CHECKS = new Set([
|
|
5048
3444
|
"max_size",
|
|
5049
3445
|
"min_size",
|
|
@@ -7604,7 +6000,6 @@ var init_coerce = () => {};
|
|
|
7604
6000
|
|
|
7605
6001
|
// node_modules/zod/v4/classic/external.js
|
|
7606
6002
|
var init_external = __esm(() => {
|
|
7607
|
-
init_core2();
|
|
7608
6003
|
init_core2();
|
|
7609
6004
|
init_locales();
|
|
7610
6005
|
init_iso();
|
|
@@ -7637,8 +6032,7 @@ function resolveIdRef(kind, ref, ids) {
|
|
|
7637
6032
|
function parseOperation(family, input) {
|
|
7638
6033
|
if (typeof input === "object" && input !== null && "schemaVersion" in input && input.schemaVersion !== SCHEMA_VERSION)
|
|
7639
6034
|
return failure2("unsupported_version", "unsupported schema version", { operation: family });
|
|
7640
|
-
const
|
|
7641
|
-
const parsed = compiled.success ? operationSchemas[family].safeParse(input) : compiled;
|
|
6035
|
+
const parsed = operationSchemas[family].safeParse(input);
|
|
7642
6036
|
if (parsed.success)
|
|
7643
6037
|
return success(null, null, parsed.data);
|
|
7644
6038
|
const fields = parsed.error.issues.map((issue) => ({
|
|
@@ -7724,7 +6118,7 @@ function requirementId(input) {
|
|
|
7724
6118
|
}
|
|
7725
6119
|
});
|
|
7726
6120
|
}
|
|
7727
|
-
var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0",
|
|
6121
|
+
var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", uuidPattern, digestPattern, invalidUnicode = (value) => {
|
|
7728
6122
|
for (let i = 0;i < value.length; i += 1) {
|
|
7729
6123
|
const code = value.charCodeAt(i);
|
|
7730
6124
|
if (code >= 55296 && code <= 56319) {
|
|
@@ -7886,7 +6280,7 @@ var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", OPERATION_FAMILIES, uuidPatter
|
|
|
7886
6280
|
if (critical.length > 0)
|
|
7887
6281
|
return { ...first, critical };
|
|
7888
6282
|
return { success: true, data: parsed.data, stripped: [...new Set(stripped)] };
|
|
7889
|
-
}, workspaceRecordSchema, capabilitySchema, requirementEvaluationSchema, taskViewSchema, taskSummarySchema, taskListItemSchema, exportBundleSchema, callerSchema, base, revisions, taskId, operation = (shape) => object({ ...base, ...shape }).strict(), taskOperations, rawJudgment, policyOperations, evidenceOperations, findingOperations, decisionOperations, workerOperations, stateOperations, operationSchemas, OPERATION_ACTIONS, withImplicitTask = (options) => Object.values(options).map((option) => ("taskId" in option.shape) ? option.extend({ taskId: id.optional() }) : option), advertised = (options) => discriminatedUnion("action", withImplicitTask(options)), advertisedOperationSchemas,
|
|
6283
|
+
}, workspaceRecordSchema, capabilitySchema, requirementEvaluationSchema, taskViewSchema, taskSummarySchema, taskListItemSchema, exportBundleSchema, callerSchema, base, revisions, taskId, operation = (shape) => object({ ...base, ...shape }).strict(), taskOperations, rawJudgment, policyOperations, evidenceOperations, findingOperations, decisionOperations, workerOperations, stateOperations, operationSchemas, OPERATION_ACTIONS, withImplicitTask = (options) => Object.values(options).map((option) => ("taskId" in option.shape) ? option.extend({ taskId: id.optional() }) : option), advertised = (options) => discriminatedUnion("action", withImplicitTask(options)), advertisedOperationSchemas, success = (revisionValue, workspaceRevisionValue, data) => ({
|
|
7890
6284
|
ok: true,
|
|
7891
6285
|
schemaVersion: 1,
|
|
7892
6286
|
revision: revisionValue,
|
|
@@ -7903,15 +6297,6 @@ var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", OPERATION_FAMILIES, uuidPatter
|
|
|
7903
6297
|
}, compareNullableText = (left, right) => left === right ? 0 : left === null ? -1 : right === null ? 1 : compareCodeUnits(left, right), compareBooleanNullable = (left, right) => left === right ? 0 : left === null ? -1 : right === null ? 1 : Number(left) - Number(right);
|
|
7904
6298
|
var init_task_contract = __esm(() => {
|
|
7905
6299
|
init_zod();
|
|
7906
|
-
OPERATION_FAMILIES = [
|
|
7907
|
-
"task",
|
|
7908
|
-
"policy",
|
|
7909
|
-
"evidence",
|
|
7910
|
-
"finding",
|
|
7911
|
-
"decision",
|
|
7912
|
-
"worker",
|
|
7913
|
-
"state"
|
|
7914
|
-
];
|
|
7915
6300
|
uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
7916
6301
|
digestPattern = /^[0-9a-f]{64}$/;
|
|
7917
6302
|
text = string2().check((ctx) => {
|
|
@@ -8469,7 +6854,6 @@ var init_task_contract = __esm(() => {
|
|
|
8469
6854
|
worker: advertised(workerOperations),
|
|
8470
6855
|
state: advertised(stateOperations)
|
|
8471
6856
|
};
|
|
8472
|
-
compiledOperationSchemas = Object.fromEntries(OPERATION_FAMILIES.map((family) => [family, compile(operationSchemas[family])]));
|
|
8473
6857
|
});
|
|
8474
6858
|
|
|
8475
6859
|
// packages/workit-core/src/git/rev.ts
|
|
@@ -19092,6 +17476,23 @@ function workitInvocations(command, dialect = "posix", depth = 0) {
|
|
|
19092
17476
|
}
|
|
19093
17477
|
return found;
|
|
19094
17478
|
}
|
|
17479
|
+
function skipWorkitGlobals(args) {
|
|
17480
|
+
let cwd = null;
|
|
17481
|
+
let at = 0;
|
|
17482
|
+
for (;at < args.length; at++) {
|
|
17483
|
+
const match = WORKIT_GLOBAL.exec(args[at]);
|
|
17484
|
+
if (match?.[1] === "=") {
|
|
17485
|
+
if (args[at].startsWith("--cwd="))
|
|
17486
|
+
cwd = args[at].slice(6);
|
|
17487
|
+
} else if (match && args[at + 1] !== undefined) {
|
|
17488
|
+
if (args[at] === "--cwd")
|
|
17489
|
+
cwd = args[at + 1];
|
|
17490
|
+
at++;
|
|
17491
|
+
} else if (args[at] !== "--json")
|
|
17492
|
+
break;
|
|
17493
|
+
}
|
|
17494
|
+
return { rest: args.slice(at), cwd };
|
|
17495
|
+
}
|
|
19095
17496
|
function rawAction(invocation) {
|
|
19096
17497
|
const args = invocation.args;
|
|
19097
17498
|
if (invocation.tool !== "git" && args[0] === "api")
|
|
@@ -19491,7 +17892,7 @@ var NONE2, SHELLS, POWERSHELLS, EVALS, WRAPPERS, WRAPPER_VALUES, KEYWORDS, DECLA
|
|
|
19491
17892
|
...Object.keys(env).length ? { env } : {},
|
|
19492
17893
|
...stdin === undefined ? {} : { stdin }
|
|
19493
17894
|
};
|
|
19494
|
-
}, RECENT, LAUNCHERS, WORKIT_BIN, WORKIT_PACKAGE, PACKAGE_RUNNERS, PUSH_VALUE_OPTIONS, CURRENT_BRANCH, pushDestination = (destination) => {
|
|
17895
|
+
}, RECENT, LAUNCHERS, WORKIT_BIN, WORKIT_PACKAGE, PACKAGE_RUNNERS, WORKIT_GLOBAL, PUSH_VALUE_OPTIONS, CURRENT_BRANCH, pushDestination = (destination) => {
|
|
19495
17896
|
if (destination === "HEAD" || destination === "@" || CURRENT_BRANCH.test(destination))
|
|
19496
17897
|
return { name: null };
|
|
19497
17898
|
if (destination.startsWith("refs/heads/"))
|
|
@@ -20185,6 +18586,7 @@ var init_raw_git = __esm(() => {
|
|
|
20185
18586
|
WORKIT_BIN = /(?:^|[\\/])workit(?:\.exe)?$|^@brainervirus\/workit-cli$/;
|
|
20186
18587
|
WORKIT_PACKAGE = /^@brainervirus\/workit-cli(?:@\S*)?$/;
|
|
20187
18588
|
PACKAGE_RUNNERS = new Set(["npx", "bunx", "pnpx"]);
|
|
18589
|
+
WORKIT_GLOBAL = /^--(?:cwd|session|token|as)(=|$)/;
|
|
20188
18590
|
PUSH_VALUE_OPTIONS = new Set(["-o", "--push-option", "--receive-pack", "--exec", "--repo"]);
|
|
20189
18591
|
CURRENT_BRANCH = /^\$\(\s*git\s+(?:branch\s+--show-current|rev-parse\s+--abbrev-ref\s+HEAD|symbolic-ref\s+--short\s+HEAD)\s*\)$/;
|
|
20190
18592
|
VALUE_OPTIONS = {
|
|
@@ -21410,7 +19812,7 @@ var init_live_session = __esm(() => {
|
|
|
21410
19812
|
});
|
|
21411
19813
|
|
|
21412
19814
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
21413
|
-
import { realpathSync as realpathSync5 } from "node:fs";
|
|
19815
|
+
import { existsSync as existsSync7, realpathSync as realpathSync5 } from "node:fs";
|
|
21414
19816
|
import os10 from "node:os";
|
|
21415
19817
|
import path27 from "node:path";
|
|
21416
19818
|
function writeGate(cwd, paths, owner, deps) {
|
|
@@ -21436,16 +19838,8 @@ function shellGate(cwd, command, owner, dialect = "posix", deps) {
|
|
|
21436
19838
|
} catch {}
|
|
21437
19839
|
const writes = shellWrites(command);
|
|
21438
19840
|
let targets = [];
|
|
21439
|
-
if (owner)
|
|
21440
|
-
|
|
21441
|
-
targets = [
|
|
21442
|
-
...segmentTargets(cwd, command, dialect),
|
|
21443
|
-
...gitMutationDirs(cwd, command, dialect).map((dir) => path27.join(dir, DIR_TARGET))
|
|
21444
|
-
];
|
|
21445
|
-
} catch {
|
|
21446
|
-
targets = [];
|
|
21447
|
-
}
|
|
21448
|
-
}
|
|
19841
|
+
if (owner)
|
|
19842
|
+
targets = shellMutationTargets(cwd, command, dialect);
|
|
21449
19843
|
if (owner && targets.length) {
|
|
21450
19844
|
const live = liveGate(owner, targets, deps);
|
|
21451
19845
|
if (live.kind !== "none") {
|
|
@@ -21504,9 +19898,9 @@ var NONE3, CASE_INSENSITIVE, canonical2 = (file) => {
|
|
|
21504
19898
|
return null;
|
|
21505
19899
|
if ("script" in tail)
|
|
21506
19900
|
return tail.script;
|
|
21507
|
-
const
|
|
21508
|
-
if (SCRIPT_SHELLS.has((
|
|
21509
|
-
return script
|
|
19901
|
+
const script = shellScript2(tail.argv);
|
|
19902
|
+
if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
|
|
19903
|
+
return script;
|
|
21510
19904
|
return tail.argv.map(quoteWord2).join(" ");
|
|
21511
19905
|
}, editsOf = (input) => {
|
|
21512
19906
|
let words = input;
|
|
@@ -21583,6 +19977,89 @@ var NONE3, CASE_INSENSITIVE, canonical2 = (file) => {
|
|
|
21583
19977
|
default:
|
|
21584
19978
|
return [];
|
|
21585
19979
|
}
|
|
19980
|
+
}, shellScript2 = (words) => {
|
|
19981
|
+
if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
|
|
19982
|
+
return null;
|
|
19983
|
+
for (let index = 1;index < words.length; index++) {
|
|
19984
|
+
const word = words[index];
|
|
19985
|
+
if (/^-[a-z]*c$/.test(word))
|
|
19986
|
+
return words[index + 1] ?? null;
|
|
19987
|
+
if (/^[-+][oO]$/.test(word))
|
|
19988
|
+
index++;
|
|
19989
|
+
else if (!/^[-+]/.test(word))
|
|
19990
|
+
return null;
|
|
19991
|
+
}
|
|
19992
|
+
return null;
|
|
19993
|
+
}, XARGS_VALUE, runsWriter = (words) => {
|
|
19994
|
+
const filled = [...words.filter((word) => word !== "{}" && word !== ";" && word !== "+"), "x"];
|
|
19995
|
+
const edits = editsOf(filled);
|
|
19996
|
+
return edits === null || edits.length > 0 || opaqueWrites(filled) !== null;
|
|
19997
|
+
}, opaqueWrites = (input) => {
|
|
19998
|
+
let words = input;
|
|
19999
|
+
while (words.length && (PREFIXES2.has(words[0]) || /^\w+=/.test(words[0]))) {
|
|
20000
|
+
if (words[0] === "xargs") {
|
|
20001
|
+
let at = 1;
|
|
20002
|
+
while (words[at]?.startsWith("-"))
|
|
20003
|
+
at += XARGS_VALUE.test(words[at]) ? 2 : 1;
|
|
20004
|
+
return runsWriter(words.slice(at)) ? ["."] : null;
|
|
20005
|
+
}
|
|
20006
|
+
words = words.slice(1);
|
|
20007
|
+
}
|
|
20008
|
+
const [verb, ...args] = words;
|
|
20009
|
+
const name = (verb?.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
20010
|
+
const files = operands(args);
|
|
20011
|
+
const has = (pattern) => args.some((arg) => pattern.test(arg));
|
|
20012
|
+
const listed = (named) => named.length ? named : ["."];
|
|
20013
|
+
if (name === "unlink" || name === "shred")
|
|
20014
|
+
return listed(files);
|
|
20015
|
+
if (/^(?:chmod|chown|chgrp|chattr)$/.test(name))
|
|
20016
|
+
return listed(has(/^--reference/) ? files : files.slice(1));
|
|
20017
|
+
if (name === "rsync") {
|
|
20018
|
+
const dest = files.at(-1);
|
|
20019
|
+
const remote = /^[\w.@-]*:/.test(dest ?? "") && !/^[A-Za-z]:[\\/]/.test(dest ?? "");
|
|
20020
|
+
return dest === undefined ? ["."] : remote ? [] : [dest];
|
|
20021
|
+
}
|
|
20022
|
+
if (name === "find") {
|
|
20023
|
+
const exec = args.findIndex((arg) => /^-(?:exec|execdir|ok|okdir)$/.test(arg));
|
|
20024
|
+
const writes = has(/^-(?:delete|fprint\w*|fls)$/) || exec >= 0 && runsWriter(args.slice(exec + 1));
|
|
20025
|
+
const end = args.findIndex((arg) => /^[-(!]/.test(arg));
|
|
20026
|
+
return writes ? listed(end < 0 ? args : args.slice(0, end)) : null;
|
|
20027
|
+
}
|
|
20028
|
+
if (/^g?awk$/.test(name)) {
|
|
20029
|
+
if (!has(/^-i|^--include/))
|
|
20030
|
+
return null;
|
|
20031
|
+
const named = [];
|
|
20032
|
+
let program = !has(/^-f$|^--file/);
|
|
20033
|
+
for (let index = 0;index < args.length; index++)
|
|
20034
|
+
if (/^(?:-[ifvF]|--(?:include|file|assign|field-separator))$/.test(args[index]))
|
|
20035
|
+
index++;
|
|
20036
|
+
else if (args[index].startsWith("-"))
|
|
20037
|
+
continue;
|
|
20038
|
+
else if (program)
|
|
20039
|
+
program = false;
|
|
20040
|
+
else
|
|
20041
|
+
named.push(args[index]);
|
|
20042
|
+
return listed(named);
|
|
20043
|
+
}
|
|
20044
|
+
if (name === "perl")
|
|
20045
|
+
return has(/^-[a-zA-Z]*[eE]/) ? ["."] : null;
|
|
20046
|
+
if (/^(?:python[\d.]*|node|bun|deno|ruby|php)$/.test(name))
|
|
20047
|
+
return has(/^-[a-zA-Z]*[ce]$|^--eval$|^-p$/) ? ["."] : null;
|
|
20048
|
+
return shellScript2(words) === null ? null : ["."];
|
|
20049
|
+
}, linkSources = (args, at) => {
|
|
20050
|
+
const names = operands([...args]);
|
|
20051
|
+
const into = args.indexOf("-t");
|
|
20052
|
+
const dest = into >= 0 ? args[into + 1] : names.length > 1 ? names.at(-1) : ".";
|
|
20053
|
+
const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
|
|
20054
|
+
const target = dest === undefined ? null : at(dest);
|
|
20055
|
+
const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
|
|
20056
|
+
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync7(target) || /[\\/]$/.test(dest ?? "") ? target : path27.dirname(target);
|
|
20057
|
+
return sources.flatMap((source) => {
|
|
20058
|
+
if (symbolic && base !== null && !path27.isAbsolute(homeExpanded(source)))
|
|
20059
|
+
return [path27.resolve(base, source)];
|
|
20060
|
+
const resolved = at(source);
|
|
20061
|
+
return resolved ? [resolved] : [];
|
|
20062
|
+
});
|
|
21586
20063
|
}, shellWrites = (command, depth = 0) => {
|
|
21587
20064
|
const targets = [];
|
|
21588
20065
|
let unknown = false;
|
|
@@ -21660,16 +20137,19 @@ var NONE3, CASE_INSENSITIVE, canonical2 = (file) => {
|
|
|
21660
20137
|
return [];
|
|
21661
20138
|
return [path27.resolve(cwd, invocation.dir ?? ".")];
|
|
21662
20139
|
});
|
|
21663
|
-
}, CD2, PUSHD2, POPD2, cdInto = (dir, words) => {
|
|
20140
|
+
}, CD2, PUSHD2, POPD2, UNKNOWN_DIR, cdInto = (dir, words, strict = false) => {
|
|
20141
|
+
const lost = strict ? UNKNOWN_DIR : undefined;
|
|
21664
20142
|
const named = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
21665
20143
|
const target = named === undefined ? undefined : homeExpanded(named);
|
|
21666
|
-
if (
|
|
21667
|
-
return;
|
|
20144
|
+
if (target === "-" || target && /^~|[$`*?]/.test(target))
|
|
20145
|
+
return lost;
|
|
20146
|
+
if (dir === undefined)
|
|
20147
|
+
return lost;
|
|
21668
20148
|
return target === undefined ? os10.homedir() : path27.resolve(dir, target);
|
|
21669
20149
|
}, quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`, homeExpanded = (file) => {
|
|
21670
20150
|
const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
|
|
21671
20151
|
return match ? (process.env.HOME || os10.homedir()) + file.slice(match[0].length) : file;
|
|
21672
|
-
}, segmentTargets = (cwd, command, dialect, depth = 0) => {
|
|
20152
|
+
}, segmentTargets = (cwd, command, dialect, depth = 0, strict = false) => {
|
|
21673
20153
|
const targets = [];
|
|
21674
20154
|
let dir = cwd;
|
|
21675
20155
|
let stack = [];
|
|
@@ -21693,21 +20173,35 @@ var NONE3, CASE_INSENSITIVE, canonical2 = (file) => {
|
|
|
21693
20173
|
const words = lead < 0 ? [] : segment.words.slice(lead);
|
|
21694
20174
|
const name = (words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
21695
20175
|
if (CD2.has(name)) {
|
|
21696
|
-
dir = cdInto(dir, words);
|
|
20176
|
+
dir = cdInto(dir, words, strict);
|
|
21697
20177
|
continue;
|
|
21698
20178
|
}
|
|
21699
20179
|
if (PUSHD2.has(name)) {
|
|
21700
20180
|
stack.push(dir);
|
|
21701
|
-
dir = cdInto(dir, words);
|
|
20181
|
+
dir = cdInto(dir, words, strict);
|
|
21702
20182
|
continue;
|
|
21703
20183
|
}
|
|
21704
20184
|
if (POPD2.has(name)) {
|
|
21705
|
-
dir = stack.length ? stack.pop() : undefined;
|
|
20185
|
+
dir = stack.length ? stack.pop() : strict ? UNKNOWN_DIR : undefined;
|
|
21706
20186
|
continue;
|
|
21707
20187
|
}
|
|
21708
|
-
const inner = depth < 4 ? wrappedScript(words) : null;
|
|
20188
|
+
const inner = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
|
|
21709
20189
|
if (inner !== null && dir !== undefined)
|
|
21710
|
-
targets.push(...segmentTargets(dir, inner, "posix", depth + 1));
|
|
20190
|
+
targets.push(...segmentTargets(dir, inner, "posix", depth + 1, strict));
|
|
20191
|
+
if (strict && dir !== undefined) {
|
|
20192
|
+
const runIn = dir;
|
|
20193
|
+
for (const sub of depth < 4 ? segment.subs ?? [] : [])
|
|
20194
|
+
targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, true));
|
|
20195
|
+
const opaque = segment.unanalyzable ? ["."] : inner === null ? opaqueWrites(words) : null;
|
|
20196
|
+
for (const file of opaque ?? []) {
|
|
20197
|
+
const resolved = at(file);
|
|
20198
|
+
if (resolved)
|
|
20199
|
+
targets.push(file === "." ? path27.join(resolved, DIR_TARGET) : resolved);
|
|
20200
|
+
}
|
|
20201
|
+
const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
|
|
20202
|
+
if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
|
|
20203
|
+
targets.push(...linkSources(words.slice(ln + 1), at));
|
|
20204
|
+
}
|
|
21711
20205
|
for (const file of segment.redirects)
|
|
21712
20206
|
if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file)) {
|
|
21713
20207
|
const resolved = at(file);
|
|
@@ -21724,10 +20218,26 @@ var NONE3, CASE_INSENSITIVE, canonical2 = (file) => {
|
|
|
21724
20218
|
if (resolved)
|
|
21725
20219
|
targets.push(resolved);
|
|
21726
20220
|
}
|
|
21727
|
-
if (dir !== undefined
|
|
21728
|
-
|
|
20221
|
+
if (dir !== undefined)
|
|
20222
|
+
for (const invocation of workitInvocations(segment.words.map(quoteWord2).join(" "), "posix")) {
|
|
20223
|
+
const { at: runsIn, args } = workitCwd(dir, invocation);
|
|
20224
|
+
if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
|
|
20225
|
+
targets.push(path27.join(runsIn, DIR_TARGET));
|
|
20226
|
+
}
|
|
21729
20227
|
}
|
|
21730
20228
|
return targets;
|
|
20229
|
+
}, workitCwd = (dir, args) => {
|
|
20230
|
+
const { rest, cwd } = skipWorkitGlobals(args);
|
|
20231
|
+
return { at: cwd === null ? dir : path27.resolve(dir, homeExpanded(cwd)), args: rest };
|
|
20232
|
+
}, shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
|
|
20233
|
+
try {
|
|
20234
|
+
return [
|
|
20235
|
+
...segmentTargets(cwd, command, dialect, 0, strict),
|
|
20236
|
+
...gitMutationDirs(cwd, command, dialect).map((dir) => path27.join(dir, DIR_TARGET))
|
|
20237
|
+
];
|
|
20238
|
+
} catch {
|
|
20239
|
+
return [];
|
|
20240
|
+
}
|
|
21731
20241
|
}, overridden = (command, dialect) => {
|
|
21732
20242
|
const segments = segmentsOf(command, dialect);
|
|
21733
20243
|
if (segments.length !== 1 || segments[0].group || segments[0].subs?.length)
|
|
@@ -21815,8 +20325,9 @@ var init_write_gate = __esm(() => {
|
|
|
21815
20325
|
init_shell_words();
|
|
21816
20326
|
NONE3 = { kind: "none" };
|
|
21817
20327
|
CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
|
|
21818
|
-
PREFIXES2 = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs"]);
|
|
20328
|
+
PREFIXES2 = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs", "busybox"]);
|
|
21819
20329
|
SCRIPT_SHELLS = new Set(["sh", "bash", "zsh", "dash", "ksh"]);
|
|
20330
|
+
XARGS_VALUE = /^-[IinLPdsEa]$/;
|
|
21820
20331
|
cache2 = new Map;
|
|
21821
20332
|
MUTATING_GIT = new Set([
|
|
21822
20333
|
"add",
|
|
@@ -21842,6 +20353,7 @@ var init_write_gate = __esm(() => {
|
|
|
21842
20353
|
CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
21843
20354
|
PUSHD2 = new Set(["pushd", "push-location"]);
|
|
21844
20355
|
POPD2 = new Set(["popd", "pop-location"]);
|
|
20356
|
+
UNKNOWN_DIR = path27.resolve(path27.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
21845
20357
|
HOST_LABELS = {
|
|
21846
20358
|
claude_code: "Claude Code",
|
|
21847
20359
|
opencode: "OpenCode",
|
|
@@ -22269,10 +20781,10 @@ var init_skill_nudge = __esm(() => {
|
|
|
22269
20781
|
});
|
|
22270
20782
|
|
|
22271
20783
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
22272
|
-
import { existsSync as
|
|
20784
|
+
import { existsSync as existsSync8, realpathSync as realpathSync6, statSync as statSync2 } from "node:fs";
|
|
22273
20785
|
import path28 from "node:path";
|
|
22274
20786
|
var isRecord6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value), nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "", optionalText = (value) => typeof value === "string" ? value : null, existingDirectory = (value) => {
|
|
22275
|
-
if (!nonEmpty2(value) || !path28.isAbsolute(value) || !
|
|
20787
|
+
if (!nonEmpty2(value) || !path28.isAbsolute(value) || !existsSync8(value))
|
|
22276
20788
|
return null;
|
|
22277
20789
|
try {
|
|
22278
20790
|
return statSync2(value).isDirectory() ? realpathSync6(value) : null;
|
|
@@ -22473,6 +20985,252 @@ var init_cwd_normalize = __esm(() => {
|
|
|
22473
20985
|
FILTERS = new Set(["tail", "head", "grep"]);
|
|
22474
20986
|
});
|
|
22475
20987
|
|
|
20988
|
+
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
20989
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
20990
|
+
import fs23 from "node:fs";
|
|
20991
|
+
import path30 from "node:path";
|
|
20992
|
+
function confineImplementer(input, targets) {
|
|
20993
|
+
try {
|
|
20994
|
+
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
20995
|
+
return NONE5;
|
|
20996
|
+
if (targets.some((target) => within(path30.resolve(target), UNKNOWN_DIR)))
|
|
20997
|
+
return unknownDirDeny(input, boundWorktree(input));
|
|
20998
|
+
const bindings = canonical3(bindingDir());
|
|
20999
|
+
const judged = targets.map((named) => ({ named, real: canonical3(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
|
|
21000
|
+
if (judged.length === 0)
|
|
21001
|
+
return NONE5;
|
|
21002
|
+
let worktree = boundWorktree(input);
|
|
21003
|
+
if (!worktree) {
|
|
21004
|
+
for (const { real } of judged) {
|
|
21005
|
+
worktree = within(real, bindings) ? null : workitWorktreeOf(real);
|
|
21006
|
+
if (worktree)
|
|
21007
|
+
break;
|
|
21008
|
+
}
|
|
21009
|
+
if (!worktree)
|
|
21010
|
+
return unboundDeny(input, judged[0].named);
|
|
21011
|
+
bind(input, worktree);
|
|
21012
|
+
}
|
|
21013
|
+
const root = canonical3(worktree);
|
|
21014
|
+
const outside = judged.find(({ real }) => !within(real, root) || within(real, bindings));
|
|
21015
|
+
return outside ? outsideDeny(input, worktree, outside.named) : NONE5;
|
|
21016
|
+
} catch {
|
|
21017
|
+
return NONE5;
|
|
21018
|
+
}
|
|
21019
|
+
}
|
|
21020
|
+
function confineImplementerShell(input, command, dialect = "posix") {
|
|
21021
|
+
try {
|
|
21022
|
+
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
21023
|
+
return NONE5;
|
|
21024
|
+
if (rawInvocations(command, dialect).some((invocation) => invocation.tool === "git" && leadOwnedGit(invocation.args)) || workitInvocations(command, dialect).some(leadOwnedWorkit))
|
|
21025
|
+
return leadOwnedDeny(input, command);
|
|
21026
|
+
} catch {}
|
|
21027
|
+
return confineImplementer(input, shellMutationTargets(input.cwd, command, dialect, true));
|
|
21028
|
+
}
|
|
21029
|
+
var FANOUT_TOKEN_FILE = "workit-fanout-token", NONE5, CASE_INSENSITIVE2, canonical3 = (file) => {
|
|
21030
|
+
let rest = "";
|
|
21031
|
+
for (let dir = path30.resolve(file);; dir = path30.dirname(dir)) {
|
|
21032
|
+
try {
|
|
21033
|
+
return path30.join(fs23.realpathSync.native(dir), rest);
|
|
21034
|
+
} catch {
|
|
21035
|
+
if (path30.dirname(dir) === dir)
|
|
21036
|
+
return path30.resolve(file);
|
|
21037
|
+
rest = rest ? path30.join(path30.basename(dir), rest) : path30.basename(dir);
|
|
21038
|
+
}
|
|
21039
|
+
}
|
|
21040
|
+
}, within = (child, parent) => {
|
|
21041
|
+
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
21042
|
+
const relative = path30.relative(fold(parent), fold(child));
|
|
21043
|
+
return relative === "" || !relative.startsWith("..") && !path30.isAbsolute(relative);
|
|
21044
|
+
}, checkoutOf2 = (file) => {
|
|
21045
|
+
for (let dir = canonical3(file);; dir = path30.dirname(dir)) {
|
|
21046
|
+
const dotGit = path30.join(dir, ".git");
|
|
21047
|
+
if (fs23.existsSync(dotGit)) {
|
|
21048
|
+
if (!fs23.statSync(dotGit).isFile())
|
|
21049
|
+
return { root: dir, workit: false };
|
|
21050
|
+
const admin = /^gitdir:\s*(.+)$/mu.exec(fs23.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
21051
|
+
return {
|
|
21052
|
+
root: dir,
|
|
21053
|
+
workit: Boolean(admin) && fs23.existsSync(path30.join(path30.resolve(dir, admin), FANOUT_TOKEN_FILE))
|
|
21054
|
+
};
|
|
21055
|
+
}
|
|
21056
|
+
if (path30.dirname(dir) === dir)
|
|
21057
|
+
return null;
|
|
21058
|
+
}
|
|
21059
|
+
}, workitWorktreeOf = (file) => {
|
|
21060
|
+
try {
|
|
21061
|
+
const checkout = checkoutOf2(file);
|
|
21062
|
+
return checkout?.workit ? checkout.root : null;
|
|
21063
|
+
} catch {
|
|
21064
|
+
return null;
|
|
21065
|
+
}
|
|
21066
|
+
}, bindingDir = () => path30.join(resolveStateDir(), "worktree-bind"), bindingFile = (session, agentId) => path30.join(bindingDir(), `${createHash17("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`), readBinding = (file) => {
|
|
21067
|
+
try {
|
|
21068
|
+
const value = JSON.parse(fs23.readFileSync(file, "utf8"));
|
|
21069
|
+
return typeof value.worktree === "string" ? value : null;
|
|
21070
|
+
} catch {
|
|
21071
|
+
return null;
|
|
21072
|
+
}
|
|
21073
|
+
}, boundWorktree = (input) => {
|
|
21074
|
+
const agentId = input.session.agentId;
|
|
21075
|
+
if (!agentId)
|
|
21076
|
+
return null;
|
|
21077
|
+
const binding = readBinding(bindingFile(input.session.id, agentId));
|
|
21078
|
+
return binding && workitWorktreeOf(binding.worktree) === binding.worktree ? binding.worktree : null;
|
|
21079
|
+
}, bind = (input, worktree) => {
|
|
21080
|
+
const agentId = input.session.agentId;
|
|
21081
|
+
const file = bindingFile(input.session.id, agentId);
|
|
21082
|
+
const binding = {
|
|
21083
|
+
worktree,
|
|
21084
|
+
session: input.session.id,
|
|
21085
|
+
agentId,
|
|
21086
|
+
at: new Date().toISOString()
|
|
21087
|
+
};
|
|
21088
|
+
fs23.mkdirSync(path30.dirname(file), { recursive: true });
|
|
21089
|
+
fs23.writeFileSync(file, JSON.stringify(binding));
|
|
21090
|
+
try {
|
|
21091
|
+
if (inWorkitWorkspace(input.cwd))
|
|
21092
|
+
appendHookObserved(input.cwd, {
|
|
21093
|
+
type: "worktree.bound",
|
|
21094
|
+
actor: { host: input.host, session: input.session.id, agentId },
|
|
21095
|
+
agentType: input.session.agentType,
|
|
21096
|
+
worktree
|
|
21097
|
+
});
|
|
21098
|
+
} catch {}
|
|
21099
|
+
}, hostIsolated = (cwd, agentId) => {
|
|
21100
|
+
try {
|
|
21101
|
+
if (agentId === null)
|
|
21102
|
+
return false;
|
|
21103
|
+
const checkout = checkoutOf2(cwd);
|
|
21104
|
+
if (!checkout)
|
|
21105
|
+
return false;
|
|
21106
|
+
const dotGit = path30.join(checkout.root, ".git");
|
|
21107
|
+
if (!fs23.statSync(dotGit).isFile())
|
|
21108
|
+
return false;
|
|
21109
|
+
const admin = /^gitdir:\s*(.+)$/mu.exec(fs23.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
21110
|
+
if (!admin)
|
|
21111
|
+
return false;
|
|
21112
|
+
const adminDir = path30.resolve(checkout.root, admin);
|
|
21113
|
+
const back = fs23.readFileSync(path30.join(adminDir, "gitdir"), "utf8").trim();
|
|
21114
|
+
if (path30.relative(canonical3(path30.resolve(adminDir, back)), canonical3(dotGit)) !== "")
|
|
21115
|
+
return false;
|
|
21116
|
+
const common = path30.join(adminDir, "commondir");
|
|
21117
|
+
const gitDir = fs23.existsSync(common) ? path30.resolve(adminDir, fs23.readFileSync(common, "utf8").trim()) : adminDir;
|
|
21118
|
+
const expected = path30.join(path30.dirname(canonical3(gitDir)), ".claude", "worktrees", `agent-${agentId}`);
|
|
21119
|
+
return path30.relative(canonical3(expected), checkout.root) === "";
|
|
21120
|
+
} catch {
|
|
21121
|
+
return false;
|
|
21122
|
+
}
|
|
21123
|
+
}, shown = (target) => path30.basename(target) === ".workit-live-target" ? path30.dirname(target) : target, unboundDeny = (input, target) => {
|
|
21124
|
+
const unblock = "Work only in the worktree your brief names, which the lead made with `workit fanout worktree create <slice>`: edit files under it and run one verb per call against it (`workit --cwd <worktree> git commit -m … -- <paths>`, `workit --cwd <worktree> check <name>`). If your brief names no worktree, stop and report that to the lead.";
|
|
21125
|
+
return {
|
|
21126
|
+
kind: "deny",
|
|
21127
|
+
reason: `workit worktree confinement: implementer ${input.session.agentId} is not working in a Workit worktree yet, and ${shown(target)} is outside every worktree \`workit fanout worktree create\` made, so it would change the lead's checkout. ${unblock}`,
|
|
21128
|
+
unblock
|
|
21129
|
+
};
|
|
21130
|
+
}, outsideDeny = (input, worktree, target) => {
|
|
21131
|
+
const unblock = `Edit only under ${worktree} and run git there, one verb per call: \`workit --cwd ${worktree} git commit -m … -- <paths>\`, \`workit --cwd ${worktree} check <name>\` (or \`git -C ${worktree} …\`); a command whose writes Workit cannot see is judged by the directory it runs in. Anything outside it is a follow-up for your report.`;
|
|
21132
|
+
return {
|
|
21133
|
+
kind: "deny",
|
|
21134
|
+
reason: `workit worktree confinement: implementer ${input.session.agentId} is bound to the worktree ${worktree}, and ${shown(target)} is outside it. ${unblock}`,
|
|
21135
|
+
unblock
|
|
21136
|
+
};
|
|
21137
|
+
}, unknownDirDeny = (input, worktree) => {
|
|
21138
|
+
const wt = worktree ?? "<worktree>";
|
|
21139
|
+
const unblock = `Workit cannot resolve \`cd -\`, \`cd "$X"\` or \`popd\`: write by absolute path, \`git -C ${wt}\` or \`workit --cwd ${wt}\`.`;
|
|
21140
|
+
return {
|
|
21141
|
+
kind: "deny",
|
|
21142
|
+
reason: `workit worktree confinement: implementer ${input.session.agentId} writes after an unknown directory change. ${unblock}`,
|
|
21143
|
+
unblock
|
|
21144
|
+
};
|
|
21145
|
+
}, MUTATING_REMOTE, CONFIG_READ, CONFIG_WRITE, CONFIG_VALUE, leadOwnedGit = (args) => {
|
|
21146
|
+
const [sub = "", ...rest] = args;
|
|
21147
|
+
if (rest.some((arg) => arg === "--help" || arg === "-h"))
|
|
21148
|
+
return false;
|
|
21149
|
+
const names = rest.filter((arg) => !arg.startsWith("-"));
|
|
21150
|
+
const flag = (pattern) => rest.some((arg) => pattern.test(arg));
|
|
21151
|
+
switch (sub) {
|
|
21152
|
+
case "worktree":
|
|
21153
|
+
return names[0] !== undefined && names[0] !== "list";
|
|
21154
|
+
case "update-ref":
|
|
21155
|
+
return true;
|
|
21156
|
+
case "symbolic-ref":
|
|
21157
|
+
return names.length > 1 || flag(/^(?:-d|--delete)$/);
|
|
21158
|
+
case "branch":
|
|
21159
|
+
return flag(/^-[a-zA-Z]*[dDfmMcC]|^--(?:delete|force|move|copy)$/);
|
|
21160
|
+
case "tag":
|
|
21161
|
+
return flag(/^-[a-zA-Z]*[df]|^--(?:delete|force)$/);
|
|
21162
|
+
case "push": {
|
|
21163
|
+
if (flag(/^(?:-d|--delete|--mirror|--prune)$/))
|
|
21164
|
+
return true;
|
|
21165
|
+
const refspecs = names.slice(1);
|
|
21166
|
+
return refspecs.some((name) => name.includes(":") || name.startsWith("+")) || refspecs.length > 0 && flag(/^-[a-zA-Z]*f|^--force/);
|
|
21167
|
+
}
|
|
21168
|
+
case "replace":
|
|
21169
|
+
case "filter-branch":
|
|
21170
|
+
case "gc":
|
|
21171
|
+
case "prune":
|
|
21172
|
+
case "repack":
|
|
21173
|
+
case "sparse-checkout":
|
|
21174
|
+
return true;
|
|
21175
|
+
case "notes":
|
|
21176
|
+
case "reflog":
|
|
21177
|
+
case "submodule":
|
|
21178
|
+
return !/^(?:list|show|status|exists)$/.test(names[0] ?? "list");
|
|
21179
|
+
case "stash":
|
|
21180
|
+
return names[0] === "drop" || names[0] === "clear";
|
|
21181
|
+
case "remote":
|
|
21182
|
+
return MUTATING_REMOTE.has(names[0] ?? "");
|
|
21183
|
+
case "config": {
|
|
21184
|
+
if (rest.some((arg) => CONFIG_READ.test(arg)))
|
|
21185
|
+
return false;
|
|
21186
|
+
if (rest.some((arg) => CONFIG_WRITE.test(arg)))
|
|
21187
|
+
return true;
|
|
21188
|
+
let operands = 0;
|
|
21189
|
+
for (let index = 0;index < rest.length; index++)
|
|
21190
|
+
if (CONFIG_VALUE.test(rest[index]))
|
|
21191
|
+
index++;
|
|
21192
|
+
else if (!rest[index].startsWith("-"))
|
|
21193
|
+
operands++;
|
|
21194
|
+
return operands > 1;
|
|
21195
|
+
}
|
|
21196
|
+
default:
|
|
21197
|
+
return false;
|
|
21198
|
+
}
|
|
21199
|
+
}, leadOwnedWorkit = (args) => !args.includes("--help") && args.some((_, start) => {
|
|
21200
|
+
if (start > 0 && !/(?:^|[\\/])workit(?:\.exe|\.cmd)?$/.test(args[start - 1]))
|
|
21201
|
+
return false;
|
|
21202
|
+
const [verb, sub] = skipWorkitGlobals(args.slice(start)).rest;
|
|
21203
|
+
return verb === "fanout" && /^(?:plan|worktree)$/.test(sub ?? "");
|
|
21204
|
+
}), leadOwnedDeny = (input, command) => {
|
|
21205
|
+
const unblock = "Worktrees, branches other than your own, refs, tags, remotes, git config, the shared stash and the fan-out plan belong to the lead: report what you need changed as a follow-up instead.";
|
|
21206
|
+
return {
|
|
21207
|
+
kind: "deny",
|
|
21208
|
+
reason: `workit worktree confinement: implementer ${input.session.agentId} may not run \`${command.slice(0, 160)}\`. ${unblock}`,
|
|
21209
|
+
unblock
|
|
21210
|
+
};
|
|
21211
|
+
};
|
|
21212
|
+
var init_worktree_confine = __esm(() => {
|
|
21213
|
+
init_logger();
|
|
21214
|
+
init_ledger();
|
|
21215
|
+
init_raw_git();
|
|
21216
|
+
init_write_gate();
|
|
21217
|
+
NONE5 = { kind: "none" };
|
|
21218
|
+
CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
21219
|
+
MUTATING_REMOTE = new Set([
|
|
21220
|
+
"add",
|
|
21221
|
+
"remove",
|
|
21222
|
+
"rm",
|
|
21223
|
+
"rename",
|
|
21224
|
+
"set-url",
|
|
21225
|
+
"set-head",
|
|
21226
|
+
"set-branches",
|
|
21227
|
+
"prune"
|
|
21228
|
+
]);
|
|
21229
|
+
CONFIG_READ = /^(?:--get(?:-all|-regexp|-urlmatch)?|--list|-l|get|list)$/;
|
|
21230
|
+
CONFIG_WRITE = /^(?:--(?:unset(?:-all)?|add|replace-all|rename-section|remove-section|edit)|-e|set|unset|rename-section|remove-section|edit)$/;
|
|
21231
|
+
CONFIG_VALUE = /^(?:--file|-f|--blob|--type|--default|--comment)$/;
|
|
21232
|
+
});
|
|
21233
|
+
|
|
22476
21234
|
// packages/workit-core/src/hooks/handle.ts
|
|
22477
21235
|
function handleHook(input, deps) {
|
|
22478
21236
|
const decision = decide(input, deps);
|
|
@@ -22490,7 +21248,7 @@ function decide(input, deps) {
|
|
|
22490
21248
|
switch (event.kind) {
|
|
22491
21249
|
case "session.start": {
|
|
22492
21250
|
if (!usable2(descriptor.context.sessionStart))
|
|
22493
|
-
return
|
|
21251
|
+
return NONE6;
|
|
22494
21252
|
const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
|
|
22495
21253
|
const offer = event.source === "startup" && (key === null || !offered.has(key));
|
|
22496
21254
|
if (offer && key !== null)
|
|
@@ -22505,26 +21263,31 @@ function decide(input, deps) {
|
|
|
22505
21263
|
}
|
|
22506
21264
|
case "context.turn": {
|
|
22507
21265
|
if (!usable2(descriptor.context.perTurn))
|
|
22508
|
-
return
|
|
21266
|
+
return NONE6;
|
|
22509
21267
|
const current = turnContextText(input, descriptor);
|
|
22510
21268
|
const text = resendsOnChange(descriptor) ? changedTurnContext(input, current) : current;
|
|
22511
|
-
return withContextLine(text ? { kind: "context", text } :
|
|
21269
|
+
return withContextLine(text ? { kind: "context", text } : NONE6, promptNudge(input, event.prompt));
|
|
22512
21270
|
}
|
|
22513
21271
|
case "shell.pre": {
|
|
22514
21272
|
const skillRead = skillReadIn(event.command, event.dialect);
|
|
22515
21273
|
if (skillRead)
|
|
22516
21274
|
recordSkillLoad(input, skillRead, "read");
|
|
22517
21275
|
const canDeny = usable2(descriptor.shellPolicy.deny);
|
|
22518
|
-
const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) :
|
|
21276
|
+
const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) : NONE6;
|
|
22519
21277
|
if (policy.kind !== "none")
|
|
22520
21278
|
return policy;
|
|
22521
21279
|
const postTool = usable2(descriptor.events["shell.post"].support);
|
|
22522
21280
|
if (!postTool)
|
|
22523
21281
|
settlePendingCommit(input);
|
|
22524
|
-
const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) :
|
|
21282
|
+
const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
|
|
22525
21283
|
if (raw.kind === "deny")
|
|
22526
21284
|
return raw;
|
|
22527
|
-
|
|
21285
|
+
if (canDeny && implementerAgent(input, descriptor)) {
|
|
21286
|
+
const confined = confineImplementerShell(input, event.command, event.dialect);
|
|
21287
|
+
if (confined.kind === "deny")
|
|
21288
|
+
return confined;
|
|
21289
|
+
}
|
|
21290
|
+
const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, liveOwner(input, descriptor.transport), event.dialect) : NONE6;
|
|
22528
21291
|
if (gate.kind === "deny")
|
|
22529
21292
|
return gate;
|
|
22530
21293
|
const plan = heavyGate(input.cwd, event.command, {
|
|
@@ -22547,10 +21310,10 @@ function decide(input, deps) {
|
|
|
22547
21310
|
command: rewrittenTo,
|
|
22548
21311
|
input: event.toolInput ? { ...event.toolInput, command: rewrittenTo } : null,
|
|
22549
21312
|
text
|
|
22550
|
-
} :
|
|
21313
|
+
} : NONE6;
|
|
22551
21314
|
if (descriptor.transport !== "hook-process")
|
|
22552
21315
|
return rewritten(null);
|
|
22553
|
-
const nudged = withContextLine(withContextLine(canDeny ? rawGitPre(input, event.command) :
|
|
21316
|
+
const nudged = withContextLine(withContextLine(canDeny ? rawGitPre(input, event.command) : NONE6, aside), shipNudge(input, event.command));
|
|
22554
21317
|
if (!lease)
|
|
22555
21318
|
return cwdCommand && nudged.kind !== "deny" ? rewritten(nudged.kind === "context" ? nudged.text : null) : nudged;
|
|
22556
21319
|
return rewritten([rewriteNote(lease), nudged.kind === "context" ? nudged.text : null].filter(Boolean).join(`
|
|
@@ -22559,9 +21322,17 @@ function decide(input, deps) {
|
|
|
22559
21322
|
case "shell.post":
|
|
22560
21323
|
if (usable2(descriptor.events["shell.post"].support))
|
|
22561
21324
|
rawGitPost(input, event.command, callKey(event.toolUseId, event.command));
|
|
22562
|
-
return
|
|
22563
|
-
case "write.pre":
|
|
22564
|
-
|
|
21325
|
+
return NONE6;
|
|
21326
|
+
case "write.pre": {
|
|
21327
|
+
if (!usable2(descriptor.events["write.pre"].support))
|
|
21328
|
+
return NONE6;
|
|
21329
|
+
if (implementerAgent(input, descriptor)) {
|
|
21330
|
+
const confined = confineImplementer(input, liveTargets(input.cwd, event.paths));
|
|
21331
|
+
if (confined.kind === "deny")
|
|
21332
|
+
return confined;
|
|
21333
|
+
}
|
|
21334
|
+
return writeGate(input.cwd, event.paths, liveOwner(input, descriptor.transport));
|
|
21335
|
+
}
|
|
22565
21336
|
case "subagent.start":
|
|
22566
21337
|
if (workitRole(descriptor, event.agentType) === "judge")
|
|
22567
21338
|
trackJudge(input, event.agentId, true);
|
|
@@ -22578,25 +21349,25 @@ function decide(input, deps) {
|
|
|
22578
21349
|
case "tool.pre":
|
|
22579
21350
|
if (event.skill)
|
|
22580
21351
|
recordSkillLoad(input, event.skill, "tool");
|
|
22581
|
-
return
|
|
21352
|
+
return NONE6;
|
|
22582
21353
|
case "stop":
|
|
22583
|
-
return usable2(descriptor.events.stop.support) ? stopDecision(input, descriptor) :
|
|
21354
|
+
return usable2(descriptor.events.stop.support) ? stopDecision(input, descriptor) : NONE6;
|
|
22584
21355
|
case "subagent.stop":
|
|
22585
21356
|
trackJudge(input, event.agentId, false);
|
|
22586
|
-
return
|
|
21357
|
+
return NONE6;
|
|
22587
21358
|
case "prompt.submit":
|
|
22588
|
-
return
|
|
21359
|
+
return NONE6;
|
|
22589
21360
|
}
|
|
22590
21361
|
}
|
|
22591
|
-
var usable2 = (value) => value === "native" || value === "partial",
|
|
21362
|
+
var usable2 = (value) => value === "native" || value === "partial", NONE6, resendsOnChange = (descriptor) => descriptor.context.turnResend === "on-change" && usable2(descriptor.context.perTurn), offered, ROLES, workitRole = (descriptor, agentType) => {
|
|
22592
21363
|
const prefix = descriptor.subagents.agentPrefix;
|
|
22593
21364
|
const name = agentType.startsWith(prefix) ? agentType.slice(prefix.length) : "";
|
|
22594
21365
|
return Object.hasOwn(ROLES, name) ? ROLES[name] : null;
|
|
22595
|
-
}, subagentSession = (session, agentId) => [session, agentId].filter((part) => Boolean(part)).join(":").replace(/[^A-Za-z0-9_.:@/+-]/g, "-").slice(0, 128), CLAUDE_WORKTREE, isolatedGit = (cwd) => `Run git as plain, separate commands inside your worktree (\`git switch -c <branch> <base>\`, ${workspaceTrailers(cwd).enabled ? '`git commit --trailer "Workit-Session=<your session>"`, `git push`; `workit doctor --fix` can install a prepare-commit-msg hook that adds the trailer' : "`git commit` (this workspace sets trailers: false: add no Workit-Session trailer), `git push`"}; add Co-Authored-By with \`git commit --trailer\` in the same commit, never by amending), never \`workit git …\`: Claude Code's worktree isolation refuses a command that wraps git and cannot be turned off (https://code.claude.com/docs/en/worktrees#how-claude-code-enforces-isolation). Never dodge that check by renaming or re-wrapping git. Use workit for the non-git verbs (\`workit check\`, \`workit ledger\`, \`workit pr\`).`, subagentStartText = (input, descriptor, event) => {
|
|
21366
|
+
}, implementerAgent = (input, descriptor) => Boolean(input.session.agentId) && input.session.agentType !== null && workitRole(descriptor, input.session.agentType) === "implementer", subagentSession = (session, agentId) => [session, agentId].filter((part) => Boolean(part)).join(":").replace(/[^A-Za-z0-9_.:@/+-]/g, "-").slice(0, 128), CLAUDE_WORKTREE, isolatedGit = (cwd) => `Run git as plain, separate commands inside your worktree (\`git switch -c <branch> <base>\`, ${workspaceTrailers(cwd).enabled ? '`git commit --trailer "Workit-Session=<your session>"`, `git push`; `workit doctor --fix` can install a prepare-commit-msg hook that adds the trailer' : "`git commit` (this workspace sets trailers: false: add no Workit-Session trailer), `git push`"}; add Co-Authored-By with \`git commit --trailer\` in the same commit, never by amending), never \`workit git …\`: Claude Code's worktree isolation refuses a command that wraps git and cannot be turned off (https://code.claude.com/docs/en/worktrees#how-claude-code-enforces-isolation). Never dodge that check by renaming or re-wrapping git. Use workit for the non-git verbs (\`workit check\`, \`workit ledger\`, \`workit pr\`).`, subagentStartText = (input, descriptor, event) => {
|
|
22596
21367
|
const session = input.session.id ?? null;
|
|
22597
21368
|
const role = workitRole(descriptor, event.agentType);
|
|
22598
21369
|
const who = `${descriptor.label} subagent ${event.agentId} (${event.agentType})`;
|
|
22599
|
-
const isolated = descriptor.subagents.worktreeIsolation === "native" && (role === "implementer"
|
|
21370
|
+
const isolated = descriptor.subagents.worktreeIsolation === "native" && (role === "implementer" ? hostIsolated(input.cwd, event.agentId) : CLAUDE_WORKTREE.test(input.cwd));
|
|
22600
21371
|
const guide = role === "implementer" ? branchGuidance(input.cwd) : null;
|
|
22601
21372
|
if (role === "implementer" && isolated)
|
|
22602
21373
|
return `Workit observed ${who} working in its own git worktree: it may edit and commit there, within its brief's scope. ${isolatedGit(input.cwd)} Plain git is expected here, and the branch name is still policy-checked: a raw \`git switch -c\`, \`git checkout -b\`, \`git branch\` or \`git worktree add -b\` onto a protected or non-compliant name is denied, so use a policy-compliant branch.${guide ? ` ${guide}` : " (e.g. feature/<slug>)"} Never record a verdict on your own work. Never push, open a PR, or merge unless the brief asks for it.`;
|
|
@@ -22604,7 +21375,7 @@ var usable2 = (value) => value === "native" || value === "partial", NONE5, resen
|
|
|
22604
21375
|
return `${isolatedGit(input.cwd)}
|
|
22605
21376
|
${subagentStartText({ ...input, cwd: "" }, descriptor, event)}`;
|
|
22606
21377
|
if (role === "implementer")
|
|
22607
|
-
return `Workit observed ${who} as an implementer: it edits and commits only in its own git worktree (the lead makes
|
|
21378
|
+
return `Workit observed ${who} as an implementer: it edits and commits only in its own git worktree, the one its brief names (the lead makes it with \`workit fanout worktree create <slice>\` before spawning), never in the lead's checkout, within its brief's scope. Workit binds it to the first Workit worktree it changes: from then on an edit or a mutating git command outside that worktree is denied, and before then so is one outside every Workit worktree. Run Workit against the worktree one verb per call, never \`cd … &&\` chains or \`$VAR\` paths: \`workit --cwd <worktree> git commit -m "<message>" -- <paths>\`, \`workit --cwd <worktree> check <name>\`. The worktree is on the brief's branch once the lead made it; otherwise switch with \`workit --cwd <worktree> git branch <branch> --base <base>\` (or \`--kind <kind> --slug <slug>\`, which picks the base); branch policy hooks still deny protected or non-compliant branches, raw git included.${guide ? ` ${guide}` : " (e.g. feature/<slug>)"} Never record a verdict on your own work. Never push, open a PR, or merge unless the brief asks for it.`;
|
|
22608
21379
|
const readOnly = `Workit observed ${who} as read-only/agent-guided.`;
|
|
22609
21380
|
if (role !== "judge" || !event.agentId)
|
|
22610
21381
|
return readOnly;
|
|
@@ -22619,10 +21390,10 @@ ${subagentStartText({ ...input, cwd: "" }, descriptor, event)}`;
|
|
|
22619
21390
|
return `${readOnly} Its own Workit session is ${own}, so the ledger tells its verdicts apart from the author's. Record the verdict with exactly this command (pick the result${pick}, name the candidate branch if it differs, say what you ran): \`${line}\`.${token ? " The token is this subagent's alone: never write it into a report, a file or a commit. --token needs a workit CLI at least as new as this plugin; if the CLI answers that --token is an unknown option, update the workit CLI (workit upgrade --cli) and record again." : ""}`;
|
|
22620
21391
|
}, PRE_TOOL, failureDecision = (descriptor, event, error) => {
|
|
22621
21392
|
if (event === "shell.pre" || event === "tool.pre" || event === "write.pre")
|
|
22622
|
-
return descriptor.shellPolicy.failClosed ? { kind: "deny", reason: error, unblock: null } :
|
|
21393
|
+
return descriptor.shellPolicy.failClosed ? { kind: "deny", reason: error, unblock: null } : NONE6;
|
|
22623
21394
|
if (event === "session.start" || event === "subagent.start")
|
|
22624
21395
|
return { kind: "context", text: `[workit diagnostic: ${error}]` };
|
|
22625
|
-
return
|
|
21396
|
+
return NONE6;
|
|
22626
21397
|
}, dispatchHook = (adapter, raw, env = process.env) => {
|
|
22627
21398
|
const parsed = adapter.parse(raw, env);
|
|
22628
21399
|
if (!parsed.ok)
|
|
@@ -22660,7 +21431,8 @@ var init_handle = __esm(() => {
|
|
|
22660
21431
|
init_stop();
|
|
22661
21432
|
init_live_session();
|
|
22662
21433
|
init_write_gate();
|
|
22663
|
-
|
|
21434
|
+
init_worktree_confine();
|
|
21435
|
+
NONE6 = { kind: "none" };
|
|
22664
21436
|
offered = new Set;
|
|
22665
21437
|
ROLES = {
|
|
22666
21438
|
implementer: "implementer",
|
|
@@ -22673,20 +21445,20 @@ var init_handle = __esm(() => {
|
|
|
22673
21445
|
|
|
22674
21446
|
// packages/workit-core/src/hooks/deadline.ts
|
|
22675
21447
|
import { appendFileSync, mkdirSync as mkdirSync3 } from "node:fs";
|
|
22676
|
-
import
|
|
21448
|
+
import path31 from "node:path";
|
|
22677
21449
|
var HOOK_SKIP_TEXT = "workit context skipped: host under load", HOOK_DEADLINE_MS = 8000, HOST_DEADLINES, HOOK_SKIPS_FILE = "hook-skips.jsonl", override = (env) => {
|
|
22678
21450
|
const value = Number(env.WORKIT_HOOK_DEADLINE_MS);
|
|
22679
21451
|
return Number.isFinite(value) && value > 0 ? value : null;
|
|
22680
21452
|
}, hookDeadlineMs = (env, host = "", native) => {
|
|
22681
21453
|
const row = HOST_DEADLINES[host];
|
|
22682
21454
|
return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
|
|
22683
|
-
}, skipsFile = (stateDir) =>
|
|
21455
|
+
}, skipsFile = (stateDir) => path31.join(stateDir, HOOK_SKIPS_FILE), recordHookSkip = (skip, stateDir = resolveStateDir()) => {
|
|
22684
21456
|
try {
|
|
22685
21457
|
mkdirSync3(stateDir, { recursive: true });
|
|
22686
21458
|
appendFileSync(skipsFile(stateDir), `${JSON.stringify(skip)}
|
|
22687
21459
|
`);
|
|
22688
21460
|
} catch {}
|
|
22689
|
-
}, QUIET, skipDecision = (event) => QUIET.has(event) ? { kind: "none" } : { kind: "context", text: HOOK_SKIP_TEXT }, TIMED_OUT,
|
|
21461
|
+
}, QUIET, skipDecision = (event) => QUIET.has(event) ? { kind: "none" } : { kind: "context", text: HOOK_SKIP_TEXT }, TIMED_OUT, within2 = async (work, ms) => {
|
|
22690
21462
|
let timer;
|
|
22691
21463
|
const expired = new Promise((resolve) => {
|
|
22692
21464
|
timer = setTimeout(() => resolve(TIMED_OUT), Math.max(0, ms));
|
|
@@ -22713,7 +21485,7 @@ var HOOK_SKIP_TEXT = "workit context skipped: host under load", HOOK_DEADLINE_MS
|
|
|
22713
21485
|
text += String(chunk);
|
|
22714
21486
|
return text;
|
|
22715
21487
|
})();
|
|
22716
|
-
const text = await
|
|
21488
|
+
const text = await within2(read, budget.startedAt + budget.deadlineMs - budget.now());
|
|
22717
21489
|
return isTimedOut(text) ? null : text;
|
|
22718
21490
|
}, note = (adapter, raw, env, budget, outcome, stage) => {
|
|
22719
21491
|
const parsed = raw === undefined ? null : adapter.parse(raw, env);
|
|
@@ -22739,7 +21511,7 @@ var HOOK_SKIP_TEXT = "workit context skipped: host under load", HOOK_DEADLINE_MS
|
|
|
22739
21511
|
if (budget.host !== null && typeof native === "string")
|
|
22740
21512
|
budget.deadlineMs = hookDeadlineMs(env, budget.host, native);
|
|
22741
21513
|
const remaining = () => budget.startedAt + budget.deadlineMs - budget.now();
|
|
22742
|
-
const result = remaining() > 0 ? await
|
|
21514
|
+
const result = remaining() > 0 ? await within2(Promise.resolve().then(() => dispatch(adapter, raw, env)), remaining()) : TIMED_OUT;
|
|
22743
21515
|
if (isTimedOut(result))
|
|
22744
21516
|
return skippedHook(adapter, raw, env, budget, "dispatch");
|
|
22745
21517
|
if (remaining() < 0)
|
|
@@ -23324,8 +22096,8 @@ var init_codex = __esm(() => {
|
|
|
23324
22096
|
});
|
|
23325
22097
|
|
|
23326
22098
|
// packages/workit-core/src/hooks/hosts/cursor.ts
|
|
23327
|
-
import
|
|
23328
|
-
import
|
|
22099
|
+
import fs24 from "node:fs";
|
|
22100
|
+
import path32 from "node:path";
|
|
23329
22101
|
var undocumented, none, CURSOR_DESCRIPTOR, EVENTS3, parseCursorHookInput = (value) => {
|
|
23330
22102
|
if (!isRecord6(value) || !Object.hasOwn(EVENTS3, String(value.hook_event_name)))
|
|
23331
22103
|
return { ok: false, error: "hook_event_name is required" };
|
|
@@ -23406,17 +22178,17 @@ var undocumented, none, CURSOR_DESCRIPTOR, EVENTS3, parseCursorHookInput = (valu
|
|
|
23406
22178
|
};
|
|
23407
22179
|
}
|
|
23408
22180
|
}, TRANSCRIPT_TAIL_BYTES, lastAssistantText = (file) => {
|
|
23409
|
-
if (!file || !
|
|
22181
|
+
if (!file || !path32.isAbsolute(file))
|
|
23410
22182
|
return null;
|
|
23411
22183
|
try {
|
|
23412
|
-
const size =
|
|
22184
|
+
const size = fs24.statSync(file).size;
|
|
23413
22185
|
const start = Math.max(0, size - TRANSCRIPT_TAIL_BYTES);
|
|
23414
22186
|
const buffer = Buffer.alloc(size - start);
|
|
23415
|
-
const fd =
|
|
22187
|
+
const fd = fs24.openSync(file, "r");
|
|
23416
22188
|
try {
|
|
23417
|
-
|
|
22189
|
+
fs24.readSync(fd, buffer, 0, buffer.length, start);
|
|
23418
22190
|
} finally {
|
|
23419
|
-
|
|
22191
|
+
fs24.closeSync(fd);
|
|
23420
22192
|
}
|
|
23421
22193
|
const lines = buffer.toString("utf8").split(`
|
|
23422
22194
|
`);
|
|
@@ -23442,14 +22214,14 @@ var undocumented, none, CURSOR_DESCRIPTOR, EVENTS3, parseCursorHookInput = (valu
|
|
|
23442
22214
|
} catch {
|
|
23443
22215
|
return null;
|
|
23444
22216
|
}
|
|
23445
|
-
},
|
|
22217
|
+
}, within3 = (root, dir) => dir === root || dir.startsWith(root.endsWith(path32.sep) ? root : `${root}${path32.sep}`), hookCwd = (input) => {
|
|
23446
22218
|
const cwd = existingDirectory(input.cwd);
|
|
23447
22219
|
if (cwd && input.hook_event_name === "beforeShellExecution")
|
|
23448
22220
|
return cwd;
|
|
23449
22221
|
return cursorWorkspaceRoot(input);
|
|
23450
22222
|
}, cursorWorkspaceRoot = (input) => {
|
|
23451
22223
|
const cwd = existingDirectory(input.cwd);
|
|
23452
|
-
return cwd && input.workspace_roots.find((root) =>
|
|
22224
|
+
return cwd && input.workspace_roots.find((root) => within3(root, cwd)) || input.workspace_roots[0];
|
|
23453
22225
|
}, cursorDeny = (reason) => ({
|
|
23454
22226
|
permission: "deny",
|
|
23455
22227
|
user_message: "Workit blocked this action",
|