@brainervirus/workit-pi 8.28.0 → 8.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.js +1 -0
- package/dist/workit.js +100 -7
- package/package.json +1 -1
package/dist/worker.js
CHANGED
package/dist/workit.js
CHANGED
|
@@ -7105,8 +7105,9 @@ function flatOperationJsonSchema(family, options = {}) {
|
|
|
7105
7105
|
};
|
|
7106
7106
|
const properties = { action: { type: "string", enum: actions } };
|
|
7107
7107
|
const readField = (name) => name === "taskId" || (family === "task" ? READ_TASK_FIELDS.has(name) : family === "policy");
|
|
7108
|
+
const taken = (name) => family === "policy" || actions.some((action) => actionKeys(family, action)?.accepted.has(name));
|
|
7108
7109
|
for (const [name, field] of Object.entries({ ...COMMON, ...spec.fields }))
|
|
7109
|
-
if (options.readOnly ? readField(name) :
|
|
7110
|
+
if (options.readOnly ? readField(name) : taken(name))
|
|
7110
7111
|
properties[name] = property(field);
|
|
7111
7112
|
return {
|
|
7112
7113
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
@@ -7348,6 +7349,98 @@ function normalizeOperationInput(family, input, host) {
|
|
|
7348
7349
|
request[key] = strings(request[key]);
|
|
7349
7350
|
return request;
|
|
7350
7351
|
}
|
|
7352
|
+
var defOf = (node) => node._zod.def;
|
|
7353
|
+
var unwrap = (node) => {
|
|
7354
|
+
let inner = node;
|
|
7355
|
+
while (["optional", "nullable"].includes(defOf(inner).type) && defOf(inner).innerType)
|
|
7356
|
+
inner = defOf(inner).innerType;
|
|
7357
|
+
return inner;
|
|
7358
|
+
};
|
|
7359
|
+
var FLAT_NAME = {
|
|
7360
|
+
authorityRefs: "refs",
|
|
7361
|
+
contentRefs: "refs",
|
|
7362
|
+
statedChoice: "choice",
|
|
7363
|
+
reviewContext: "reviewSession"
|
|
7364
|
+
};
|
|
7365
|
+
var NOT_FLAT = new Set(["schemaVersion", "action", "workspaceId"]);
|
|
7366
|
+
function actionKeys(family, action) {
|
|
7367
|
+
const options = advertisedOperationSchemas[family].options;
|
|
7368
|
+
const option = options.find((item) => {
|
|
7369
|
+
const literal = defOf(item).shape?.action;
|
|
7370
|
+
return literal._zod.def.values.includes(action);
|
|
7371
|
+
});
|
|
7372
|
+
if (!option)
|
|
7373
|
+
return null;
|
|
7374
|
+
const out = { accepted: new Set, required: [] };
|
|
7375
|
+
const walk = (shape, nested) => {
|
|
7376
|
+
for (const [key, node] of Object.entries(shape)) {
|
|
7377
|
+
if (NOT_FLAT.has(key) || nested && key === "taskId")
|
|
7378
|
+
continue;
|
|
7379
|
+
const inner = unwrap(node);
|
|
7380
|
+
const type = defOf(inner).type;
|
|
7381
|
+
const needed = !["optional", "nullable"].includes(defOf(node).type);
|
|
7382
|
+
if (key === "scope")
|
|
7383
|
+
for (const name of ["scope", "paths", "exclusions"])
|
|
7384
|
+
out.accepted.add(name);
|
|
7385
|
+
else if (type === "object" && key !== "bundle" && !(key in FLAT_NAME)) {
|
|
7386
|
+
out.accepted.add(key);
|
|
7387
|
+
walk(defOf(inner).shape, true);
|
|
7388
|
+
} else {
|
|
7389
|
+
const name = FLAT_NAME[key] ?? key;
|
|
7390
|
+
out.accepted.add(name);
|
|
7391
|
+
if (needed && type !== "array" && type !== "record" && !out.required.includes(name))
|
|
7392
|
+
out.required.push(name);
|
|
7393
|
+
}
|
|
7394
|
+
}
|
|
7395
|
+
};
|
|
7396
|
+
walk(defOf(option).shape, false);
|
|
7397
|
+
return out;
|
|
7398
|
+
}
|
|
7399
|
+
function exampleOperation(family, action) {
|
|
7400
|
+
const keys = actionKeys(family, action);
|
|
7401
|
+
const example = { action };
|
|
7402
|
+
for (const name of keys?.required ?? [])
|
|
7403
|
+
example[name] = FLAT[family].fields[name]?.enum?.[0] ?? `<${name}>`;
|
|
7404
|
+
if (family === "policy" && !keys?.required.length && action !== "explain")
|
|
7405
|
+
example.riskTier = "normal";
|
|
7406
|
+
return example;
|
|
7407
|
+
}
|
|
7408
|
+
var oneOf = (values) => values.join(" | ");
|
|
7409
|
+
function invalidOperation(family, input, error) {
|
|
7410
|
+
const request = isObject2(input) ? input : {};
|
|
7411
|
+
const action = typeof request.action === "string" ? request.action : "";
|
|
7412
|
+
const actions = OPERATION_ACTIONS[family];
|
|
7413
|
+
if (!actions.includes(action))
|
|
7414
|
+
return failure2("invalid_input", `${family}: action must be one of ${oneOf(actions)}`, {
|
|
7415
|
+
fields: [{ path: "action", reason: `got ${JSON.stringify(request.action ?? null)}` }]
|
|
7416
|
+
});
|
|
7417
|
+
const own = actionKeys(family, action);
|
|
7418
|
+
const fields = [];
|
|
7419
|
+
const sentence = [];
|
|
7420
|
+
for (const issue of error.issues) {
|
|
7421
|
+
if (issue.code === "unrecognized_keys") {
|
|
7422
|
+
for (const key of issue.keys) {
|
|
7423
|
+
const home = actions.find((other) => other !== action && actionKeys(family, other).accepted.has(key));
|
|
7424
|
+
const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; it takes ${[...own.accepted].join(", ")}`;
|
|
7425
|
+
fields.push({ path: key, reason });
|
|
7426
|
+
sentence.push(reason);
|
|
7427
|
+
}
|
|
7428
|
+
continue;
|
|
7429
|
+
}
|
|
7430
|
+
const last = String(issue.path.at(-1) ?? "");
|
|
7431
|
+
const name = Object.entries(FLAT_NAME).find(([contract]) => contract === last)?.[1] ?? last;
|
|
7432
|
+
const missing = issue.code === "invalid_type" && /received undefined/.test(issue.message);
|
|
7433
|
+
const absent = own.required.filter((key) => !(key in request));
|
|
7434
|
+
const needs = missing && issue.path.length === 1 && absent.length ? absent.join(", ") : name;
|
|
7435
|
+
const reason = missing ? `${family} ${action} requires ${needs}` : `${name}: ${issue.message}`;
|
|
7436
|
+
fields.push({ path: issue.path.join("."), reason });
|
|
7437
|
+
sentence.push(reason);
|
|
7438
|
+
}
|
|
7439
|
+
const example = JSON.stringify(exampleOperation(family, action));
|
|
7440
|
+
return failure2("invalid_input", `${[...new Set(sentence)].join("; ")}. Example: ${example}`, {
|
|
7441
|
+
fields
|
|
7442
|
+
});
|
|
7443
|
+
}
|
|
7351
7444
|
function parseAdvertisedOperation(family, input, host) {
|
|
7352
7445
|
const request = normalizeOperationInput(family, input, host);
|
|
7353
7446
|
if (isObject2(request) && request.schemaVersion !== SCHEMA_VERSION)
|
|
@@ -7355,12 +7448,7 @@ function parseAdvertisedOperation(family, input, host) {
|
|
|
7355
7448
|
const parsed = advertisedOperationSchemas[family].safeParse(request);
|
|
7356
7449
|
if (parsed.success)
|
|
7357
7450
|
return success(null, null, request);
|
|
7358
|
-
return
|
|
7359
|
-
fields: parsed.error.issues.map((issue) => ({
|
|
7360
|
-
path: issue.code === "unrecognized_keys" ? issue.keys.join(".") : issue.path.join("."),
|
|
7361
|
-
reason: issue.message
|
|
7362
|
-
}))
|
|
7363
|
-
});
|
|
7451
|
+
return invalidOperation(family, request, parsed.error);
|
|
7364
7452
|
}
|
|
7365
7453
|
// packages/workit-core/src/core/task-store.ts
|
|
7366
7454
|
import { createHash as createHash9, randomUUID as randomUUID3 } from "node:crypto";
|
|
@@ -10013,11 +10101,16 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
|
|
|
10013
10101
|
fingerprint
|
|
10014
10102
|
};
|
|
10015
10103
|
};
|
|
10104
|
+
var rethrowRuntimeBug = (error) => {
|
|
10105
|
+
if (error instanceof TypeError || error instanceof ReferenceError)
|
|
10106
|
+
throw error;
|
|
10107
|
+
};
|
|
10016
10108
|
var validateBranchNameFor = (workspaceRoot, name) => {
|
|
10017
10109
|
try {
|
|
10018
10110
|
const resolved = branchPolicySnapshotFor(workspaceRoot);
|
|
10019
10111
|
return validateBranchNamePolicy(name, resolved.namePolicy, resolved.source);
|
|
10020
10112
|
} catch (error) {
|
|
10113
|
+
rethrowRuntimeBug(error);
|
|
10021
10114
|
const correction = "repair or select a valid workspace policy before creating a branch";
|
|
10022
10115
|
return {
|
|
10023
10116
|
ok: false,
|