@brainervirus/workit-cursor 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor-plugin/plugin.json +1 -1
- package/dist/cursor-session-start.js +1347 -1199
- package/dist/mcp-server.js +1283 -1001
- package/dist/workit-hook.js +1359 -1213
- package/package.json +3 -3
|
@@ -8956,6 +8956,57 @@ class TaskStore {
|
|
|
8956
8956
|
}
|
|
8957
8957
|
return success(null, null, tasks);
|
|
8958
8958
|
}
|
|
8959
|
+
listTaskIndex() {
|
|
8960
|
+
if (!fs4.existsSync(this.tasksDir))
|
|
8961
|
+
return success(null, null, []);
|
|
8962
|
+
let names;
|
|
8963
|
+
try {
|
|
8964
|
+
names = fs4.readdirSync(this.tasksDir).filter((name) => name.endsWith(".json"));
|
|
8965
|
+
} catch (error) {
|
|
8966
|
+
return failure("storage_error", `unable to list tasks: ${String(error)}`, {
|
|
8967
|
+
path: this.tasksDir
|
|
8968
|
+
});
|
|
8969
|
+
}
|
|
8970
|
+
const workspace = this.readWorkspace();
|
|
8971
|
+
if (!workspace.ok)
|
|
8972
|
+
return workspace;
|
|
8973
|
+
if (!workspace.data)
|
|
8974
|
+
return failure("recovery_required", "task workspace binding is invalid", {
|
|
8975
|
+
path: this.workspacePath
|
|
8976
|
+
});
|
|
8977
|
+
const stored = this.readIndex(workspace.data.id);
|
|
8978
|
+
const entries = [];
|
|
8979
|
+
let changed = Object.keys(stored).length !== names.length;
|
|
8980
|
+
for (const name of names.sort()) {
|
|
8981
|
+
const file = path4.join(this.tasksDir, name);
|
|
8982
|
+
const signature = fileSignature(file);
|
|
8983
|
+
if (signature === null) {
|
|
8984
|
+
changed = true;
|
|
8985
|
+
continue;
|
|
8986
|
+
}
|
|
8987
|
+
const cached = stored[name.slice(0, -5)];
|
|
8988
|
+
if (cached && cached.file === signature && !racySignature(signature)) {
|
|
8989
|
+
entries.push(cached);
|
|
8990
|
+
continue;
|
|
8991
|
+
}
|
|
8992
|
+
const item = this.readRecord(file, taskRecordSchema);
|
|
8993
|
+
if (!item.exists)
|
|
8994
|
+
continue;
|
|
8995
|
+
if (!item.result.ok)
|
|
8996
|
+
return item.result;
|
|
8997
|
+
if (!validId(name.slice(0, -5)) || item.result.data.id !== name.slice(0, -5))
|
|
8998
|
+
return failure("recovery_required", "task filename and record ID differ", { path: name });
|
|
8999
|
+
if (item.result.data.workspaceId !== workspace.data.id)
|
|
9000
|
+
return failure("recovery_required", "task workspace binding is invalid", { path: name });
|
|
9001
|
+
const entry = indexEntry(item.result.data, signature);
|
|
9002
|
+
if (!cached || canonicalJson(cached) !== canonicalJson(entry))
|
|
9003
|
+
changed = true;
|
|
9004
|
+
entries.push(entry);
|
|
9005
|
+
}
|
|
9006
|
+
if (changed)
|
|
9007
|
+
this.writeIndex(workspace.data.id, entries);
|
|
9008
|
+
return success(null, null, entries);
|
|
9009
|
+
}
|
|
8959
9010
|
readWorkspace() {
|
|
8960
9011
|
const item = this.readRecord(this.workspacePath, workspaceRecordSchema);
|
|
8961
9012
|
if (!item.exists)
|
|
@@ -9635,6 +9686,8 @@ class TaskStore {
|
|
|
9635
9686
|
fs4.renameSync(temporary, file);
|
|
9636
9687
|
temporary = undefined;
|
|
9637
9688
|
this.fsyncDirectory(path4.dirname(file));
|
|
9689
|
+
if (path4.dirname(file) === this.tasksDir)
|
|
9690
|
+
this.indexTaskWrite(file, value);
|
|
9638
9691
|
return success(null, null, value);
|
|
9639
9692
|
} catch (error) {
|
|
9640
9693
|
return failure("storage_error", `snapshot replacement failed: ${String(error)}`, {
|
|
@@ -9647,6 +9700,45 @@ class TaskStore {
|
|
|
9647
9700
|
} catch {}
|
|
9648
9701
|
}
|
|
9649
9702
|
}
|
|
9703
|
+
readIndex(workspaceId) {
|
|
9704
|
+
try {
|
|
9705
|
+
const value = JSON.parse(fs4.readFileSync(this.indexPath, "utf8"));
|
|
9706
|
+
if (!isObject2(value) || value.version !== INDEX_VERSION || value.workspaceId !== workspaceId || !isObject2(value.tasks))
|
|
9707
|
+
return {};
|
|
9708
|
+
const tasks = {};
|
|
9709
|
+
for (const [id, entry] of Object.entries(value.tasks))
|
|
9710
|
+
if (isObject2(entry) && entry.id === id && typeof entry.file === "string" && typeof entry.status === "string" && typeof entry.updatedAt === "string" && Array.isArray(entry.sessions) && isObject2(entry.progress) && isObject2(entry.source))
|
|
9711
|
+
tasks[id] = entry;
|
|
9712
|
+
return tasks;
|
|
9713
|
+
} catch {
|
|
9714
|
+
return {};
|
|
9715
|
+
}
|
|
9716
|
+
}
|
|
9717
|
+
writeIndex(workspaceId, entries) {
|
|
9718
|
+
const temporary = `${this.indexPath}.${process.pid}.${randomUUID2()}.tmp`;
|
|
9719
|
+
try {
|
|
9720
|
+
fs4.writeFileSync(temporary, JSON.stringify({
|
|
9721
|
+
version: INDEX_VERSION,
|
|
9722
|
+
workspaceId,
|
|
9723
|
+
tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
|
|
9724
|
+
}), { mode: 384, flag: "wx" });
|
|
9725
|
+
fs4.renameSync(temporary, this.indexPath);
|
|
9726
|
+
} catch {
|
|
9727
|
+
try {
|
|
9728
|
+
fs4.unlinkSync(temporary);
|
|
9729
|
+
} catch {}
|
|
9730
|
+
}
|
|
9731
|
+
}
|
|
9732
|
+
indexTaskWrite(file, task) {
|
|
9733
|
+
try {
|
|
9734
|
+
const signature = fileSignature(file);
|
|
9735
|
+
if (signature === null)
|
|
9736
|
+
return;
|
|
9737
|
+
const tasks = this.readIndex(task.workspaceId);
|
|
9738
|
+
tasks[task.id] = indexEntry(task, signature);
|
|
9739
|
+
this.writeIndex(task.workspaceId, Object.values(tasks));
|
|
9740
|
+
} catch {}
|
|
9741
|
+
}
|
|
9650
9742
|
saveRecovery(file, bytes) {
|
|
9651
9743
|
const target = path4.basename(file) === "workspace.json" ? "workspace" : "task";
|
|
9652
9744
|
const id = target === "task" ? path4.basename(file, ".json") : "workspace";
|
|
@@ -9805,6 +9897,9 @@ class TaskStore {
|
|
|
9805
9897
|
get workspacePath() {
|
|
9806
9898
|
return path4.join(this.workitDir, "workspace.json");
|
|
9807
9899
|
}
|
|
9900
|
+
get indexPath() {
|
|
9901
|
+
return path4.join(this.workitDir, "index.json");
|
|
9902
|
+
}
|
|
9808
9903
|
get lockPath() {
|
|
9809
9904
|
return path4.join(this.workitDir, "metadata.lock");
|
|
9810
9905
|
}
|
|
@@ -9812,7 +9907,40 @@ class TaskStore {
|
|
|
9812
9907
|
return path4.join(this.workitDir, ".gitignore");
|
|
9813
9908
|
}
|
|
9814
9909
|
}
|
|
9815
|
-
var processEvidenceSchema, metadataLockSchema,
|
|
9910
|
+
var processEvidenceSchema, metadataLockSchema, INDEX_VERSION = 1, hostSession = (value) => isObject2(value) && value.kind === "host" && typeof value.host === "string" && typeof value.handle === "string" ? { host: value.host, handle: value.handle } : null, indexEntry = (task, file) => {
|
|
9911
|
+
const sessions = [];
|
|
9912
|
+
const intent = hostSession(task.intent.provenance.session);
|
|
9913
|
+
if (intent)
|
|
9914
|
+
sessions.push({ ...intent, workerId: null });
|
|
9915
|
+
for (const worker of task.workers) {
|
|
9916
|
+
const session = hostSession(worker.data.session);
|
|
9917
|
+
if (session)
|
|
9918
|
+
sessions.push({ ...session, workerId: worker.id });
|
|
9919
|
+
}
|
|
9920
|
+
return {
|
|
9921
|
+
id: task.id,
|
|
9922
|
+
revision: task.revision,
|
|
9923
|
+
status: task.status,
|
|
9924
|
+
createdAt: task.createdAt,
|
|
9925
|
+
updatedAt: task.updatedAt,
|
|
9926
|
+
objective: task.intent.data.objective,
|
|
9927
|
+
source: { host: task.intent.provenance.host, kind: task.intent.provenance.kind },
|
|
9928
|
+
progress: { summary: task.progress.summary, nextAction: task.progress.nextAction },
|
|
9929
|
+
sessions,
|
|
9930
|
+
file
|
|
9931
|
+
};
|
|
9932
|
+
}, fileSignature = (file) => {
|
|
9933
|
+
try {
|
|
9934
|
+
const stat = fs4.statSync(file, { bigint: true });
|
|
9935
|
+
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
9936
|
+
} catch {
|
|
9937
|
+
return null;
|
|
9938
|
+
}
|
|
9939
|
+
}, RACY_WINDOW_NS = 2000000000n, racySignature = (signature) => {
|
|
9940
|
+
const [mtime = 0n, ctime = 0n] = signature.split(":").slice(3, 5).map(BigInt);
|
|
9941
|
+
const changed = mtime > ctime ? mtime : ctime;
|
|
9942
|
+
return BigInt(Date.now()) * 1000000n - changed < RACY_WINDOW_NS;
|
|
9943
|
+
}, now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z"), cachedRuntimeVersion = null, runtimeVersion = () => {
|
|
9816
9944
|
if (cachedRuntimeVersion === null) {
|
|
9817
9945
|
try {
|
|
9818
9946
|
const pkg = JSON.parse(fs4.readFileSync(path4.join(packageRoot(), "package.json"), "utf8"));
|
|
@@ -9892,62 +10020,6 @@ var init_task_store = __esm(() => {
|
|
|
9892
10020
|
externalActionLockRoots = new AsyncLocalStorage;
|
|
9893
10021
|
});
|
|
9894
10022
|
|
|
9895
|
-
// packages/workit-core/src/core/workers.ts
|
|
9896
|
-
function assertProductWriteAllowed(input) {
|
|
9897
|
-
if (!Array.isArray(input.paths) || input.paths.some((path) => !validPath(path)))
|
|
9898
|
-
return failure("invalid_input", "invalid product write path");
|
|
9899
|
-
if (!input.store)
|
|
9900
|
-
return failure("permission_denied", "write authorization requires core state");
|
|
9901
|
-
const task = input.store.readTask(input.task.id);
|
|
9902
|
-
if (!task.ok)
|
|
9903
|
-
return task;
|
|
9904
|
-
const workspace = input.store.readWorkspace();
|
|
9905
|
-
if (!workspace.ok)
|
|
9906
|
-
return workspace;
|
|
9907
|
-
if (!workspace.data)
|
|
9908
|
-
return failure("not_found", "workspace not found");
|
|
9909
|
-
const workspaceRecord = workspace.data;
|
|
9910
|
-
if (task.data.status !== "active")
|
|
9911
|
-
return failure("invalid_transition", "paused or closed tasks cannot own product writes");
|
|
9912
|
-
if (workspaceRecord.id !== task.data.workspaceId || workspaceRecord.root.length === 0)
|
|
9913
|
-
return failure("recovery_required", "task and workspace bindings are invalid");
|
|
9914
|
-
const writer = workspaceRecord.writer;
|
|
9915
|
-
if (!writer)
|
|
9916
|
-
return failure("permission_denied", "checkout has no writer owner");
|
|
9917
|
-
if (writer.state === "uncertain")
|
|
9918
|
-
return failure("recovery_required", "checkout writer requires recovery", {
|
|
9919
|
-
owner: writer.owner
|
|
9920
|
-
});
|
|
9921
|
-
const caller = callerValue(input.caller);
|
|
9922
|
-
const workerId = workerIdOf(input.caller);
|
|
9923
|
-
const owner = writer.owner;
|
|
9924
|
-
if (owner.taskId !== task.data.id || owner.workerId !== workerId || owner.session.host !== caller.host || owner.session.handle !== caller.actor)
|
|
9925
|
-
return failure("writer_conflict", "checkout is owned by another validated actor", { owner });
|
|
9926
|
-
const worker = workerId === null ? null : task.data.workers.find((entry) => entry.id === workerId);
|
|
9927
|
-
if (workerId !== null && (!worker || worker.data.assignment.role !== "implementer"))
|
|
9928
|
-
return failure("permission_denied", "only implementers can own product writes");
|
|
9929
|
-
if (workerId !== null && (!worker?.data.session || worker.data.state === "cancelling" || worker.data.state === "unknown" || worker.data.state === "stopped" || !same(worker.data.session, callerSession(input.caller))))
|
|
9930
|
-
return failure("recovery_required", "worker session is not an active writer");
|
|
9931
|
-
return success(null, workspaceRecord.revision, owner);
|
|
9932
|
-
}
|
|
9933
|
-
var same = (left, right) => {
|
|
9934
|
-
try {
|
|
9935
|
-
return canonicalJson(left) === canonicalJson(right);
|
|
9936
|
-
} catch {
|
|
9937
|
-
return false;
|
|
9938
|
-
}
|
|
9939
|
-
}, UNCERTAIN_WORKER_STATES, isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state), workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state), callerSession = (caller) => caller.session ?? { kind: "host", host: caller.host, handle: caller.actor }, validPath = (value) => typeof value === "string" && value.length > 0 && ![...value].some((char) => {
|
|
9940
|
-
const code = char.charCodeAt(0);
|
|
9941
|
-
return code < 32 || code === 127;
|
|
9942
|
-
}) && !value.split(/[\\/]/).includes(".."), callerValue = (value) => ({ host: value.host, actor: value.actor }), workerIdOf = (value) => value.workerId ?? null, currentWriterOwnsTask = (task, workspace, caller) => {
|
|
9943
|
-
const owner = workspace.writer?.owner;
|
|
9944
|
-
return task.status === "active" && task.workspaceId === workspace.id && owner?.taskId === task.id && owner.session.host === caller.host && owner.session.handle === caller.actor;
|
|
9945
|
-
};
|
|
9946
|
-
var init_workers = __esm(() => {
|
|
9947
|
-
init_task_contract();
|
|
9948
|
-
UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"];
|
|
9949
|
-
});
|
|
9950
|
-
|
|
9951
10023
|
// packages/workit-core/src/core/boundary.ts
|
|
9952
10024
|
var EVENT, errorDetail = (err) => {
|
|
9953
10025
|
if (err instanceof Error) {
|
|
@@ -10693,6 +10765,62 @@ var init_branch = __esm(() => {
|
|
|
10693
10765
|
init_vcs_config();
|
|
10694
10766
|
});
|
|
10695
10767
|
|
|
10768
|
+
// packages/workit-core/src/core/workers.ts
|
|
10769
|
+
function assertProductWriteAllowed(input) {
|
|
10770
|
+
if (!Array.isArray(input.paths) || input.paths.some((path) => !validPath(path)))
|
|
10771
|
+
return failure("invalid_input", "invalid product write path");
|
|
10772
|
+
if (!input.store)
|
|
10773
|
+
return failure("permission_denied", "write authorization requires core state");
|
|
10774
|
+
const task = input.store.readTask(input.task.id);
|
|
10775
|
+
if (!task.ok)
|
|
10776
|
+
return task;
|
|
10777
|
+
const workspace = input.store.readWorkspace();
|
|
10778
|
+
if (!workspace.ok)
|
|
10779
|
+
return workspace;
|
|
10780
|
+
if (!workspace.data)
|
|
10781
|
+
return failure("not_found", "workspace not found");
|
|
10782
|
+
const workspaceRecord = workspace.data;
|
|
10783
|
+
if (task.data.status !== "active")
|
|
10784
|
+
return failure("invalid_transition", "paused or closed tasks cannot own product writes");
|
|
10785
|
+
if (workspaceRecord.id !== task.data.workspaceId || workspaceRecord.root.length === 0)
|
|
10786
|
+
return failure("recovery_required", "task and workspace bindings are invalid");
|
|
10787
|
+
const writer = workspaceRecord.writer;
|
|
10788
|
+
if (!writer)
|
|
10789
|
+
return failure("permission_denied", "checkout has no writer owner");
|
|
10790
|
+
if (writer.state === "uncertain")
|
|
10791
|
+
return failure("recovery_required", "checkout writer requires recovery", {
|
|
10792
|
+
owner: writer.owner
|
|
10793
|
+
});
|
|
10794
|
+
const caller = callerValue(input.caller);
|
|
10795
|
+
const workerId = workerIdOf(input.caller);
|
|
10796
|
+
const owner = writer.owner;
|
|
10797
|
+
if (owner.taskId !== task.data.id || owner.workerId !== workerId || owner.session.host !== caller.host || owner.session.handle !== caller.actor)
|
|
10798
|
+
return failure("writer_conflict", "checkout is owned by another validated actor", { owner });
|
|
10799
|
+
const worker = workerId === null ? null : task.data.workers.find((entry) => entry.id === workerId);
|
|
10800
|
+
if (workerId !== null && (!worker || worker.data.assignment.role !== "implementer"))
|
|
10801
|
+
return failure("permission_denied", "only implementers can own product writes");
|
|
10802
|
+
if (workerId !== null && (!worker?.data.session || worker.data.state === "cancelling" || worker.data.state === "unknown" || worker.data.state === "stopped" || !same(worker.data.session, callerSession(input.caller))))
|
|
10803
|
+
return failure("recovery_required", "worker session is not an active writer");
|
|
10804
|
+
return success(null, workspaceRecord.revision, owner);
|
|
10805
|
+
}
|
|
10806
|
+
var same = (left, right) => {
|
|
10807
|
+
try {
|
|
10808
|
+
return canonicalJson(left) === canonicalJson(right);
|
|
10809
|
+
} catch {
|
|
10810
|
+
return false;
|
|
10811
|
+
}
|
|
10812
|
+
}, UNCERTAIN_WORKER_STATES, isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state), workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state), callerSession = (caller) => caller.session ?? { kind: "host", host: caller.host, handle: caller.actor }, validPath = (value) => typeof value === "string" && value.length > 0 && ![...value].some((char) => {
|
|
10813
|
+
const code = char.charCodeAt(0);
|
|
10814
|
+
return code < 32 || code === 127;
|
|
10815
|
+
}) && !value.split(/[\\/]/).includes(".."), callerValue = (value) => ({ host: value.host, actor: value.actor }), workerIdOf = (value) => value.workerId ?? null, currentWriterOwnsTask = (task, workspace, caller) => {
|
|
10816
|
+
const owner = workspace.writer?.owner;
|
|
10817
|
+
return task.status === "active" && task.workspaceId === workspace.id && owner?.taskId === task.id && owner.session.host === caller.host && owner.session.handle === caller.actor;
|
|
10818
|
+
};
|
|
10819
|
+
var init_workers = __esm(() => {
|
|
10820
|
+
init_task_contract();
|
|
10821
|
+
UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"];
|
|
10822
|
+
});
|
|
10823
|
+
|
|
10696
10824
|
// packages/workit-core/src/core/auto-approval.ts
|
|
10697
10825
|
import { createHash as createHash4 } from "node:crypto";
|
|
10698
10826
|
import { readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
@@ -11372,350 +11500,231 @@ var init_authority = __esm(() => {
|
|
|
11372
11500
|
verifyDecisionContent = verifyContentRefs;
|
|
11373
11501
|
});
|
|
11374
11502
|
|
|
11375
|
-
// packages/workit-core/src/core/
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
uncertain = true;
|
|
11408
|
-
continue;
|
|
11409
|
-
}
|
|
11410
|
-
if (!git.git && stat.isDirectory() && !stat.isSymbolicLink())
|
|
11411
|
-
uncertain = walk(checkout, target, names) || uncertain;
|
|
11412
|
-
}
|
|
11413
|
-
for (const item of git.paths)
|
|
11414
|
-
if (scopeMatches(item, normalizedScope))
|
|
11415
|
-
names.add(item);
|
|
11416
|
-
const files = [];
|
|
11417
|
-
let completeness = uncertain ? "uncertain" : "known";
|
|
11418
|
-
for (const item of [...names].sort()) {
|
|
11419
|
-
if (!scopeMatches(item, normalizedScope))
|
|
11420
|
-
continue;
|
|
11421
|
-
const target = path10.join(checkout, item);
|
|
11422
|
-
try {
|
|
11423
|
-
const stat = fs7.lstatSync(target);
|
|
11424
|
-
if (stat.isSymbolicLink()) {
|
|
11425
|
-
const link = fs7.readlinkSync(target);
|
|
11426
|
-
files.push({ path: item, kind: "symlink", digest: digestBytes3(link), executable: null });
|
|
11427
|
-
} else if (stat.isFile()) {
|
|
11428
|
-
files.push({
|
|
11429
|
-
path: item,
|
|
11430
|
-
kind: "file",
|
|
11431
|
-
digest: digestBytes3(fs7.readFileSync(target)),
|
|
11432
|
-
executable: (stat.mode & 73) !== 0
|
|
11433
|
-
});
|
|
11434
|
-
} else if (!stat.isDirectory()) {
|
|
11435
|
-
completeness = "uncertain";
|
|
11436
|
-
} else if (git.git && git.paths.includes(item)) {
|
|
11437
|
-
completeness = "uncertain";
|
|
11438
|
-
}
|
|
11439
|
-
} catch (error) {
|
|
11440
|
-
if (error?.code === "ENOENT") {
|
|
11441
|
-
files.push({ path: item, kind: "absent", digest: null, executable: null });
|
|
11442
|
-
} else
|
|
11443
|
-
completeness = "uncertain";
|
|
11444
|
-
}
|
|
11445
|
-
}
|
|
11446
|
-
const supplied = Array.isArray(environment) ? environment.map((value) => typeof value === "string" ? { name: value, value: process.env[value] ?? null } : { name: value.name, value: value.value ?? null }) : Object.keys(environment).map((name) => ({
|
|
11447
|
-
name,
|
|
11448
|
-
value: environment[name] ?? null
|
|
11449
|
-
}));
|
|
11450
|
-
const namesByEnvironment = supplied.map(({ name }) => name);
|
|
11451
|
-
if (new Set(namesByEnvironment).size !== namesByEnvironment.length || namesByEnvironment.some((name) => typeof name !== "string" || !name))
|
|
11452
|
-
return failure("invalid_input", "candidate environment names must be unique and non-empty");
|
|
11453
|
-
const values = supplied.sort((left, right) => compareCodeUnits2(left.name, right.name)).map(({ name, value }) => ({ name, value, refs: [] }));
|
|
11454
|
-
if (values.some(({ value }) => value === null))
|
|
11455
|
-
completeness = "uncertain";
|
|
11456
|
-
const headResult = spawnSync2("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
|
|
11457
|
-
if (headResult.status !== 0 && !/not a git repository/i.test(headResult.stderr ?? ""))
|
|
11458
|
-
completeness = "uncertain";
|
|
11459
|
-
const head = headResult.status === 0 ? headResult.stdout.trim() : null;
|
|
11460
|
-
const partial = {
|
|
11461
|
-
id: "0".repeat(64),
|
|
11462
|
-
scope: normalizedScope,
|
|
11463
|
-
completeness,
|
|
11464
|
-
files,
|
|
11465
|
-
environment: values,
|
|
11466
|
-
head
|
|
11503
|
+
// packages/workit-core/src/core/policy-resolver.ts
|
|
11504
|
+
function normalizeResolverInput(input) {
|
|
11505
|
+
const parsed = resolverInputSchema.safeParse(input);
|
|
11506
|
+
if (!parsed.success)
|
|
11507
|
+
return failure("invalid_input", "resolver input is invalid", invalidFields(parsed.error));
|
|
11508
|
+
const value = parsed.data;
|
|
11509
|
+
const signals = value.assessment.signals;
|
|
11510
|
+
if (signals.behaviorChange.value === true && signals.mechanicalLowRisk.value === true)
|
|
11511
|
+
return failure("invalid_input", "behavioral change cannot be wholly mechanical", {
|
|
11512
|
+
fields: [
|
|
11513
|
+
{
|
|
11514
|
+
path: "assessment.signals",
|
|
11515
|
+
reason: "contradictory behaviorChange and mechanicalLowRisk"
|
|
11516
|
+
}
|
|
11517
|
+
]
|
|
11518
|
+
});
|
|
11519
|
+
const ids = value.constraints.map((constraint) => constraint.id);
|
|
11520
|
+
if (new Set(ids).size !== ids.length)
|
|
11521
|
+
return failure("invalid_input", "constraint IDs must be unique", {
|
|
11522
|
+
fields: [{ path: "constraints", reason: "duplicate constraint id" }]
|
|
11523
|
+
});
|
|
11524
|
+
if (value.preferences?.fast && value.preferences.thorough)
|
|
11525
|
+
return failure("invalid_input", "fast and thorough preferences contradict", {
|
|
11526
|
+
fields: [{ path: "preferences", reason: "fast and thorough cannot both be enabled" }]
|
|
11527
|
+
});
|
|
11528
|
+
const normalized = {
|
|
11529
|
+
intent: normalizeIntent(value.intent),
|
|
11530
|
+
assessment: normalizeAssessment(value.assessment),
|
|
11531
|
+
constraints: stableList(value.constraints.map(normalizeConstraint)),
|
|
11532
|
+
prior: normalizePrior(value.prior),
|
|
11533
|
+
...value.preferences ? { preferences: { ...value.preferences } } : {},
|
|
11534
|
+
policyVersion: POLICY_VERSION
|
|
11467
11535
|
};
|
|
11468
|
-
|
|
11469
|
-
const parsed = candidateSchema.safeParse(candidate);
|
|
11470
|
-
return parsed.success ? success(null, null, parsed.data) : failure("invalid_input", "captured candidate is invalid");
|
|
11536
|
+
return success(null, null, normalized);
|
|
11471
11537
|
}
|
|
11472
|
-
function
|
|
11473
|
-
const
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11538
|
+
function resolveRequirements(input) {
|
|
11539
|
+
const { signals } = input.assessment;
|
|
11540
|
+
const scope = input.intent.scope;
|
|
11541
|
+
const requirements = [];
|
|
11542
|
+
const hasUnknownSignal = Object.values(signals).some((signal) => signal.value === "unknown");
|
|
11543
|
+
const hasUnknownFact = [
|
|
11544
|
+
...input.assessment.facts,
|
|
11545
|
+
...input.assessment.consequences.map(({ fact }) => fact)
|
|
11546
|
+
].some((fact) => fact.basis === "unknown");
|
|
11547
|
+
if (hasUnknownSignal || hasUnknownFact)
|
|
11548
|
+
requirements.push(requirement({
|
|
11549
|
+
ruleId: "consequential-unknown",
|
|
11550
|
+
dimension: "investigation",
|
|
11551
|
+
scope,
|
|
11552
|
+
reason: `Resolve consequential uncertainty before the dependent action: ${[
|
|
11553
|
+
...Object.entries(signals).filter(([, signal]) => signal.value === "unknown").map(([name]) => name),
|
|
11554
|
+
...hasUnknownFact ? ["unknown fact"] : []
|
|
11555
|
+
].join(", ")}`,
|
|
11556
|
+
satisfaction: "An observed or inferred fact resolves the uncertainty and records its supporting references.",
|
|
11557
|
+
before: "dependent_action",
|
|
11558
|
+
dependentAction: null,
|
|
11559
|
+
acceptanceAllowed: false
|
|
11560
|
+
}));
|
|
11561
|
+
if (signals.productChoiceOpen.value === true)
|
|
11562
|
+
requirements.push(requirement({
|
|
11563
|
+
ruleId: "product-decision",
|
|
11564
|
+
dimension: "decisions",
|
|
11565
|
+
scope,
|
|
11566
|
+
reason: `A consequential product choice remains open: ${signalReason(input, "productChoiceOpen")}`,
|
|
11567
|
+
satisfaction: "Present the material alternatives and record the user's decision before the dependent action.",
|
|
11568
|
+
before: "dependent_action",
|
|
11569
|
+
dependentAction: null,
|
|
11570
|
+
acceptanceAllowed: false
|
|
11571
|
+
}));
|
|
11572
|
+
const independentBehaviorReview = input.preferences?.thorough === true || input.assessment.consequences.some((consequence) => ["security", "data", "public_contract", "operations"].includes(consequence.area));
|
|
11573
|
+
if (signals.behaviorChange.value === true)
|
|
11574
|
+
requirements.push(requirement({
|
|
11575
|
+
ruleId: "behavioral-verification",
|
|
11576
|
+
dimension: "testing",
|
|
11577
|
+
scope,
|
|
11578
|
+
reason: `Behavior, side effects, permissions, or data handling may change: ${signalReason(input, "behaviorChange")}`,
|
|
11579
|
+
satisfaction: "A useful behavioral check passes against the affected behavior and current candidate.",
|
|
11580
|
+
before: "close",
|
|
11581
|
+
dependentAction: null,
|
|
11582
|
+
acceptanceAllowed: false
|
|
11583
|
+
}), requirement({
|
|
11584
|
+
ruleId: independentBehaviorReview ? "fresh-context-review" : "self-review",
|
|
11585
|
+
dimension: "review",
|
|
11586
|
+
scope,
|
|
11587
|
+
reason: independentBehaviorReview ? "Consequential behavior or the thorough preference requires fresh-context review." : "Bounded behavior changes use self-review unless consequential risks or trusted rules require more.",
|
|
11588
|
+
satisfaction: independentBehaviorReview ? "A separate review context examines the current candidate and records its result." : "The lead reviews the resulting diff and records the relevant scope and checks.",
|
|
11589
|
+
before: "close",
|
|
11590
|
+
dependentAction: null,
|
|
11591
|
+
acceptanceAllowed: !independentBehaviorReview
|
|
11592
|
+
}));
|
|
11593
|
+
else if (signals.mechanicalLowRisk.value === true)
|
|
11594
|
+
requirements.push(requirement({
|
|
11595
|
+
ruleId: "mechanical-existing-checks",
|
|
11596
|
+
dimension: "verification",
|
|
11597
|
+
scope,
|
|
11598
|
+
reason: `The change is demonstrably mechanical and low-risk: ${signalReason(input, "mechanicalLowRisk")}`,
|
|
11599
|
+
satisfaction: "Run the relevant existing checks for affected consumers; do not add tautological tests.",
|
|
11600
|
+
before: "close",
|
|
11601
|
+
dependentAction: null,
|
|
11602
|
+
acceptanceAllowed: true
|
|
11603
|
+
}), requirement({
|
|
11604
|
+
ruleId: input.preferences?.thorough ? "fresh-context-review" : "self-review",
|
|
11605
|
+
dimension: "review",
|
|
11606
|
+
scope,
|
|
11607
|
+
reason: input.preferences?.thorough ? "The thorough preference upgrades mechanical self-review to fresh-context review." : "Mechanical low-risk work uses self-review rather than mandatory fresh-context review.",
|
|
11608
|
+
satisfaction: input.preferences?.thorough ? "A separate review context examines the current candidate and records its result." : "The lead reviews the resulting diff and records the relevant scope and checks.",
|
|
11609
|
+
before: "close",
|
|
11610
|
+
dependentAction: null,
|
|
11611
|
+
acceptanceAllowed: !input.preferences?.thorough
|
|
11612
|
+
}));
|
|
11613
|
+
if (signals.behaviorChange.value === true || signals.mechanicalLowRisk.value === true)
|
|
11614
|
+
requirements.push(requirement({
|
|
11615
|
+
ruleId: "pre-pr-cleanup",
|
|
11616
|
+
dimension: "verification",
|
|
11617
|
+
scope,
|
|
11618
|
+
reason: "Implementation output must be deslopped before it is delivered.",
|
|
11619
|
+
satisfaction: "Run the workit-deslop pass and record passing check evidence, or record an approved limitation decision waiving cleanup.",
|
|
11620
|
+
before: "dependent_action",
|
|
11621
|
+
dependentAction: "hosting.pull_request",
|
|
11622
|
+
acceptanceAllowed: true
|
|
11623
|
+
}));
|
|
11624
|
+
if (signals.durableAgreementNeeded.value === true)
|
|
11625
|
+
requirements.push(requirement({
|
|
11626
|
+
ruleId: "durable-spec",
|
|
11627
|
+
dimension: "artifacts",
|
|
11628
|
+
scope,
|
|
11629
|
+
reason: `The work needs a durable agreement about intended behavior: ${signalReason(input, "durableAgreementNeeded")}`,
|
|
11630
|
+
satisfaction: "Record the agreed behavior in a durable specification before implementation writes.",
|
|
11631
|
+
before: "write",
|
|
11632
|
+
dependentAction: null,
|
|
11633
|
+
acceptanceAllowed: true
|
|
11634
|
+
}));
|
|
11635
|
+
if (signals.coordinationPlanNeeded.value === true)
|
|
11636
|
+
requirements.push(requirement({
|
|
11637
|
+
ruleId: "coordination-plan",
|
|
11638
|
+
dimension: "continuity",
|
|
11639
|
+
scope,
|
|
11640
|
+
reason: `Dependencies, sequencing, or resumption need durable coordination: ${signalReason(input, "coordinationPlanNeeded")}`,
|
|
11641
|
+
satisfaction: "Record useful sequencing, dependencies, and the next action in a compact plan.",
|
|
11642
|
+
before: "dependent_action",
|
|
11643
|
+
dependentAction: null,
|
|
11644
|
+
acceptanceAllowed: true
|
|
11645
|
+
}));
|
|
11646
|
+
if (signals.helperUseful.value === true && !input.preferences?.fast)
|
|
11647
|
+
requirements.push(requirement({
|
|
11648
|
+
ruleId: "helper-usefulness",
|
|
11649
|
+
dimension: "delegation",
|
|
11650
|
+
scope,
|
|
11651
|
+
reason: `Independent judgment or investigation justifies a scoped helper: ${signalReason(input, "helperUseful")}`,
|
|
11652
|
+
satisfaction: "Use a bounded helper only for the independent objective and reconcile its result.",
|
|
11653
|
+
before: "dependent_action",
|
|
11654
|
+
dependentAction: null,
|
|
11655
|
+
acceptanceAllowed: true
|
|
11656
|
+
}));
|
|
11657
|
+
for (const constraint of input.constraints)
|
|
11658
|
+
for (const obligation of constraint.requires) {
|
|
11659
|
+
const dimension = obligation.method ?? (obligation.kind === "check" ? "verification" : obligation.kind === "decision" ? "decisions" : "challenge");
|
|
11660
|
+
requirements.push(requirement({
|
|
11661
|
+
ruleId: `project-constraint:${constraint.id}:${obligation.kind}:${sha256({
|
|
11662
|
+
kind: obligation.kind,
|
|
11663
|
+
scope: normalizedScope(obligation.scope),
|
|
11664
|
+
refs: normalizedRefList(obligation.refs),
|
|
11665
|
+
method: obligation.method,
|
|
11666
|
+
before: obligation.before,
|
|
11667
|
+
dependentAction: obligation.dependentAction
|
|
11668
|
+
})}`,
|
|
11669
|
+
dimension,
|
|
11670
|
+
scope: obligation.scope,
|
|
11671
|
+
reason: `${constraint.kind} constraint requires ${obligation.kind}: ${constraint.statement}`,
|
|
11672
|
+
satisfaction: `Satisfy the constraint obligation using its referenced ${obligation.kind}.`,
|
|
11673
|
+
before: obligation.before,
|
|
11674
|
+
dependentAction: obligation.dependentAction,
|
|
11675
|
+
acceptanceAllowed: constraint.acceptanceAllowed && obligation.kind !== "decision"
|
|
11676
|
+
}));
|
|
11495
11677
|
}
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
const observed = task.candidates.find((item) => item.id === evidence.candidateId) ?? (current.id === evidence.candidateId ? current : undefined);
|
|
11503
|
-
if (!observed || observed.completeness === "uncertain" || current.completeness === "uncertain")
|
|
11504
|
-
return { evidenceId: entry.id, status: "stale", reason: "candidate is missing or uncertain" };
|
|
11505
|
-
if (observed.id === current.id)
|
|
11506
|
-
return { evidenceId: entry.id, status: evidence.result, reason: "candidate is unchanged" };
|
|
11507
|
-
const scopes = evidenceScopes(task, evidence.requirementIds);
|
|
11508
|
-
const changed = changedPaths(observed, current);
|
|
11509
|
-
const environmentChanged = JSON.stringify(observed.environment) !== JSON.stringify(current.environment);
|
|
11510
|
-
if (!scopes.length || environmentChanged || changed.some((item) => scopes.some((scope) => pathRelevant(item, scope))))
|
|
11511
|
-
return { evidenceId: entry.id, status: "stale", reason: "relevant candidate state changed" };
|
|
11512
|
-
return {
|
|
11513
|
-
evidenceId: entry.id,
|
|
11514
|
-
status: evidence.result,
|
|
11515
|
-
reason: "candidate changed outside evidence scope"
|
|
11516
|
-
};
|
|
11678
|
+
const seen = new Set;
|
|
11679
|
+
return requirements.filter((item) => {
|
|
11680
|
+
if (seen.has(item.id))
|
|
11681
|
+
return false;
|
|
11682
|
+
seen.add(item.id);
|
|
11683
|
+
return true;
|
|
11517
11684
|
});
|
|
11518
11685
|
}
|
|
11519
|
-
function
|
|
11520
|
-
const
|
|
11521
|
-
if (
|
|
11522
|
-
return
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
return false;
|
|
11534
|
-
if ((entry.data.kind === "check" || entry.data.kind === "review") && (!entry.data.beforeCandidateId || !entry.data.candidateId || entry.data.beforeCandidateId !== entry.data.candidateId))
|
|
11535
|
-
return false;
|
|
11536
|
-
if (requirement.dimension !== "review")
|
|
11537
|
-
return true;
|
|
11538
|
-
const reviewSession = sessionFromRef(entry.data.reviewContext);
|
|
11539
|
-
const sameImplementation = sameSession(reviewSession, task.intent.provenance.session);
|
|
11540
|
-
const sameEvidenceSession = related.some(({ entry: other }) => other.id !== entry.id && other.data.kind === "review" && other.data.candidateId !== null && other.data.candidateId === entry.data.candidateId && sameSession(reviewSession, other.provenance.session));
|
|
11541
|
-
return entry.data.kind === "review" && reviewSession !== null && sameSession(reviewSession, entry.provenance.session) && (requirement.ruleId === "self-review" || !sameImplementation && !sameEvidenceSession);
|
|
11542
|
-
});
|
|
11543
|
-
if (passed.length) {
|
|
11544
|
-
const currentId = candidate?.id ?? null;
|
|
11545
|
-
const withRed = requirement.dimension === "testing" ? passed.filter(({ entry }) => related.some((other) => other.entry.data.kind === "check" && other.evaluation.status === "failed" && other.entry.data.requirementIds.includes(requirement.id) && other.entry.recordedAt <= entry.recordedAt) || related.some((baseline) => baseline.entry.id !== entry.id && baseline.entry.data.kind === "check" && baseline.entry.data.result === "passed" && baseline.entry.data.candidateId !== null && currentId !== null && baseline.entry.data.candidateId !== currentId)) : passed;
|
|
11546
|
-
if (withRed.length)
|
|
11547
|
-
return {
|
|
11548
|
-
requirementId: requirement.id,
|
|
11549
|
-
status: "satisfied",
|
|
11550
|
-
evidenceIds: withRed.map(({ entry }) => entry.id),
|
|
11551
|
-
decisionIds: [],
|
|
11552
|
-
reason: "fresh applicable evidence passed"
|
|
11553
|
-
};
|
|
11554
|
-
if (requirement.dimension === "testing")
|
|
11555
|
-
return {
|
|
11556
|
-
requirementId: requirement.id,
|
|
11557
|
-
status: "unsatisfied",
|
|
11558
|
-
evidenceIds: [],
|
|
11559
|
-
decisionIds: [],
|
|
11560
|
-
reason: "testing requirement has GREEN evidence but no preceding RED"
|
|
11561
|
-
};
|
|
11562
|
-
}
|
|
11563
|
-
if (requirement.dimension === "delegation") {
|
|
11564
|
-
const dot = (scope) => scope.paths.length > 0 ? scope : { ...scope, paths: ["."] };
|
|
11565
|
-
const reconciled = task.workers.some((worker) => worker.data.report?.outcome === "completed" && (worker.data.assignment.requirementIds.includes(requirement.id) || scopeCovers2(dot(requirement.scope), dot(worker.data.assignment.scope))));
|
|
11566
|
-
if (reconciled)
|
|
11567
|
-
return {
|
|
11568
|
-
requirementId: requirement.id,
|
|
11569
|
-
status: "satisfied",
|
|
11570
|
-
evidenceIds: [],
|
|
11571
|
-
decisionIds: [],
|
|
11572
|
-
reason: "bounded helper completed and its result is recorded"
|
|
11573
|
-
};
|
|
11574
|
-
}
|
|
11575
|
-
const decisions = requirement.dimension === "decisions" ? applicableRequirementDecision(task, workspace, requirement, checkoutRoot) : [];
|
|
11576
|
-
if (decisions.length)
|
|
11577
|
-
return {
|
|
11578
|
-
requirementId: requirement.id,
|
|
11579
|
-
status: "satisfied",
|
|
11580
|
-
evidenceIds: [],
|
|
11581
|
-
decisionIds: decisions.map((decision) => decision.id),
|
|
11582
|
-
reason: "an applicable approved or stated decision satisfies the requirement"
|
|
11583
|
-
};
|
|
11584
|
-
const limitations = requirement.acceptanceAllowed ? applicableDecision2(task, workspace, requirement, checkoutRoot) : [];
|
|
11585
|
-
if (limitations.length)
|
|
11586
|
-
return {
|
|
11587
|
-
requirementId: requirement.id,
|
|
11588
|
-
status: "accepted_limitation",
|
|
11589
|
-
evidenceIds: [],
|
|
11590
|
-
decisionIds: limitations.map((decision) => task.decisions.find((entry) => entry.data === decision).id),
|
|
11591
|
-
reason: "an applicable approved limitation permits the missing evidence"
|
|
11592
|
-
};
|
|
11593
|
-
const unavailable = capabilities.some((capability) => capability.assurance === "unavailable" && (capability.name === requirement.dimension || capability.surface === requirement.dimension));
|
|
11594
|
-
if (!unavailable && related.length > 0 && !passed.length)
|
|
11595
|
-
return {
|
|
11596
|
-
requirementId: requirement.id,
|
|
11597
|
-
status: "unsatisfied",
|
|
11598
|
-
evidenceIds: related.map(({ entry }) => entry.id),
|
|
11599
|
-
decisionIds: [],
|
|
11600
|
-
reason: `no passing evidence (needs kind:${expectedKinds(requirement.dimension, requirement.ruleId)})`
|
|
11601
|
-
};
|
|
11602
|
-
return {
|
|
11603
|
-
requirementId: requirement.id,
|
|
11604
|
-
status: unavailable ? "unavailable" : "unsatisfied",
|
|
11605
|
-
evidenceIds: related.map(({ entry }) => entry.id),
|
|
11606
|
-
decisionIds: [],
|
|
11607
|
-
reason: unavailable ? "required capability is unavailable" : "no fresh passing evidence"
|
|
11608
|
-
};
|
|
11609
|
-
});
|
|
11610
|
-
}
|
|
11611
|
-
function evaluateClosure(requestedOutcome, view) {
|
|
11612
|
-
if (requestedOutcome !== "stopped" && !view.task.policy)
|
|
11613
|
-
return failure("requirements_unsatisfied", "task has not been assessed");
|
|
11614
|
-
if (view.task.policy && view.task.policy.policyVersion !== POLICY_VERSION)
|
|
11615
|
-
return failure("requirements_unsatisfied", "stored policy version is unsupported; reassessment is required");
|
|
11616
|
-
const evaluations = view.requirements;
|
|
11617
|
-
const openFindings = view.task.findings.filter((entry) => entry.data.disposition === "open");
|
|
11618
|
-
if (requestedOutcome !== "stopped" && openFindings.length)
|
|
11619
|
-
return failure("requirements_unsatisfied", "open findings must be resolved before closure");
|
|
11620
|
-
if (requestedOutcome !== "stopped") {
|
|
11621
|
-
const evidenceById = new Map(view.evidence.map((entry) => [entry.evidenceId, entry.status]));
|
|
11622
|
-
for (const entry of view.task.findings) {
|
|
11623
|
-
if (entry.data.disposition === "fixed") {
|
|
11624
|
-
const verified = entry.data.resolution?.evidenceIds.some((id) => {
|
|
11625
|
-
const evidence = view.task.evidence.find((item) => item.id === id);
|
|
11626
|
-
if (!evidence)
|
|
11627
|
-
return false;
|
|
11628
|
-
return findingVerificationPasses(entry.data.candidateId, {
|
|
11629
|
-
kind: evidence.data.kind,
|
|
11630
|
-
candidateId: evidence.data.candidateId,
|
|
11631
|
-
status: evidenceById.get(id) ?? "missing"
|
|
11632
|
-
});
|
|
11633
|
-
});
|
|
11634
|
-
if (!verified)
|
|
11635
|
-
return failure("requirements_unsatisfied", "fixed findings require current verification");
|
|
11636
|
-
}
|
|
11637
|
-
if (entry.data.disposition === "deferred") {
|
|
11638
|
-
const valid = entry.data.resolution?.decisionIds.some((id) => {
|
|
11639
|
-
const decisionEntry = view.task.decisions.find((item) => item.id === id);
|
|
11640
|
-
const decision = decisionEntry?.data;
|
|
11641
|
-
return Boolean(decision && decisionEntry?.provenance.kind !== "imported" && decision.purpose === "limitation" && decision.response === "approved" && decision.revoked === null && decision.digest === decisionDigest(decision) && verifyDecisionContentAtRoot(view.workspace.root, decision.binding).ok && decision.binding.taskId === view.task.id && decision.binding.workspaceId === view.workspace.id && scopeCovers2(decision.binding.scope, entry.data.scope) && decision.requirementIds.some((requirementId) => view.task.policy?.requirements.some((requirement) => requirement.id === requirementId && requirement.acceptanceAllowed)));
|
|
11642
|
-
});
|
|
11643
|
-
if (!valid)
|
|
11644
|
-
return failure("requirements_unsatisfied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
|
|
11645
|
-
}
|
|
11646
|
-
}
|
|
11647
|
-
}
|
|
11648
|
-
const blocking = evaluations.filter((item) => {
|
|
11649
|
-
if (item.status !== "unsatisfied" && item.status !== "unavailable")
|
|
11650
|
-
return false;
|
|
11651
|
-
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
11652
|
-
return !requirement || requirement.before === "close";
|
|
11653
|
-
});
|
|
11654
|
-
if (requestedOutcome !== "stopped" && blocking.length)
|
|
11655
|
-
return failure("requirements_unsatisfied", "applicable requirements are unsatisfied", {
|
|
11656
|
-
requirementIds: blocking.map((item) => item.requirementId),
|
|
11657
|
-
requirements: blocking.map((item) => {
|
|
11658
|
-
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
11659
|
-
return {
|
|
11660
|
-
requirementId: item.requirementId,
|
|
11661
|
-
ruleId: requirement?.ruleId ?? "unknown",
|
|
11662
|
-
reason: item.reason,
|
|
11663
|
-
satisfaction: requirement?.satisfaction ?? "",
|
|
11664
|
-
dependentAction: requirement?.dependentAction ?? null
|
|
11665
|
-
};
|
|
11666
|
-
})
|
|
11667
|
-
});
|
|
11668
|
-
const accepted = evaluations.filter((item) => item.status === "accepted_limitation");
|
|
11669
|
-
if (requestedOutcome === "verified" && accepted.length)
|
|
11670
|
-
return failure("requirements_unsatisfied", "accepted limitations cannot be reported as verified", {
|
|
11671
|
-
requirementIds: accepted.map((item) => item.requirementId)
|
|
11672
|
-
});
|
|
11673
|
-
const evidenceIds = [
|
|
11674
|
-
...new Set([
|
|
11675
|
-
...evaluations.flatMap((item) => item.evidenceIds),
|
|
11676
|
-
...view.task.findings.flatMap((item) => item.data.resolution?.evidenceIds ?? [])
|
|
11677
|
-
])
|
|
11678
|
-
];
|
|
11679
|
-
const decisionIds = [
|
|
11680
|
-
...new Set([
|
|
11681
|
-
...evaluations.flatMap((item) => item.decisionIds),
|
|
11682
|
-
...view.task.findings.flatMap((item) => item.data.resolution?.decisionIds ?? [])
|
|
11683
|
-
])
|
|
11684
|
-
];
|
|
11685
|
-
return success(null, null, {
|
|
11686
|
-
outcome: requestedOutcome === "stopped" ? "stopped" : accepted.length ? "accepted_limitations" : "verified",
|
|
11687
|
-
evidenceIds,
|
|
11688
|
-
decisionIds,
|
|
11689
|
-
requirementIds: evaluations.map((item) => item.requirementId)
|
|
11690
|
-
});
|
|
11686
|
+
function resolvePolicy(input) {
|
|
11687
|
+
const normalized = normalizeResolverInput(input);
|
|
11688
|
+
if (!normalized.ok)
|
|
11689
|
+
return normalized;
|
|
11690
|
+
const requirements = resolveRequirements(normalized.data);
|
|
11691
|
+
const policy = {
|
|
11692
|
+
policyVersion: POLICY_VERSION,
|
|
11693
|
+
inputDigest: sha256(canonicalJson(normalized.data)),
|
|
11694
|
+
requirements
|
|
11695
|
+
};
|
|
11696
|
+
const parsed = policySchema.safeParse(policy);
|
|
11697
|
+
if (!parsed.success)
|
|
11698
|
+
return failure("invalid_input", "resolved policy is invalid", invalidFields(parsed.error));
|
|
11699
|
+
return success(null, null, parsed.data);
|
|
11691
11700
|
}
|
|
11692
|
-
|
|
11693
|
-
if (
|
|
11694
|
-
|
|
11695
|
-
if (
|
|
11696
|
-
|
|
11697
|
-
const
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
const paths = scope.paths.length ? scope.paths : ["."];
|
|
11703
|
-
const normalizedPaths = paths.map(canonicalPath);
|
|
11704
|
-
const normalizedExclusions = scope.exclusions.map(canonicalPath);
|
|
11705
|
-
if (normalizedPaths.some((value) => value === null) || normalizedExclusions.some((value) => value === null))
|
|
11701
|
+
function diffPolicy(previous, next, reason, now) {
|
|
11702
|
+
if (!policySchema.safeParse(previous).success && previous !== null)
|
|
11703
|
+
throw new TypeError("previous policy is invalid");
|
|
11704
|
+
if (!policySchema.safeParse(next).success)
|
|
11705
|
+
throw new TypeError("next policy is invalid");
|
|
11706
|
+
const oldIds = new Set(previous?.requirements.map((requirement) => requirement.id) ?? []);
|
|
11707
|
+
const newIds = new Set(next.requirements.map((requirement) => requirement.id));
|
|
11708
|
+
const added = [...newIds].filter((id) => !oldIds.has(id)).sort(compareCodeUnits2);
|
|
11709
|
+
const retired = [...oldIds].filter((id) => !newIds.has(id)).sort(compareCodeUnits2);
|
|
11710
|
+
if (added.length === 0 && retired.length === 0)
|
|
11706
11711
|
return null;
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11712
|
+
const normalizedReason = reason.trim();
|
|
11713
|
+
const changeReason = retired.length ? `${normalizedReason || "policy reassessed"} (retired: ${retired.join(",")})` : normalizedReason || "policy reassessed";
|
|
11714
|
+
const change = {
|
|
11715
|
+
recordedAt: now,
|
|
11716
|
+
fromInputDigest: previous?.inputDigest ?? null,
|
|
11717
|
+
toInputDigest: next.inputDigest,
|
|
11718
|
+
added,
|
|
11719
|
+
retired,
|
|
11720
|
+
reason: changeReason
|
|
11711
11721
|
};
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
}, pathRelevant = (value, scope) => scopeMatches(value, scope), compareCodeUnits2 = (left, right) => {
|
|
11722
|
+
const parsed = policyChangeSchema.safeParse(change);
|
|
11723
|
+
if (!parsed.success)
|
|
11724
|
+
throw new TypeError("policy change is invalid");
|
|
11725
|
+
return parsed.data;
|
|
11726
|
+
}
|
|
11727
|
+
var resolverInputSchema, compareCodeUnits2 = (left, right) => {
|
|
11719
11728
|
const length = Math.min(left.length, right.length);
|
|
11720
11729
|
for (let index = 0;index < length; index += 1) {
|
|
11721
11730
|
const difference = left.charCodeAt(index) - right.charCodeAt(index);
|
|
@@ -11723,818 +11732,808 @@ var digestBytes3 = (value) => createHash6("sha256").update(value).digest("hex"),
|
|
|
11723
11732
|
return difference;
|
|
11724
11733
|
}
|
|
11725
11734
|
return left.length - right.length;
|
|
11726
|
-
},
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
}
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
|
|
11751
|
-
|
|
11752
|
-
|
|
11753
|
-
}
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11735
|
+
}, stableUnique = (values) => [...new Set(values)].sort(compareCodeUnits2), stableList = (values) => [...values].sort((left, right) => compareCodeUnits2(canonicalJson(left), canonicalJson(right))), normalizedScope = (scope) => ({
|
|
11736
|
+
description: scope.description,
|
|
11737
|
+
paths: stableUnique(scope.paths),
|
|
11738
|
+
exclusions: stableUnique(scope.exclusions)
|
|
11739
|
+
}), normalizedRefList = (values) => stableList(values), normalizeAssessment = (assessment) => ({
|
|
11740
|
+
facts: stableList(assessment.facts.map((fact) => ({ ...fact, refs: normalizedRefList(fact.refs) }))),
|
|
11741
|
+
signals: Object.fromEntries(Object.entries(assessment.signals).map(([name, signal]) => [
|
|
11742
|
+
name,
|
|
11743
|
+
{ ...signal, refs: normalizedRefList(signal.refs) }
|
|
11744
|
+
])),
|
|
11745
|
+
consequences: stableList(assessment.consequences.map((consequence) => ({
|
|
11746
|
+
...consequence,
|
|
11747
|
+
fact: { ...consequence.fact, refs: normalizedRefList(consequence.fact.refs) }
|
|
11748
|
+
}))),
|
|
11749
|
+
verification: stableList(assessment.verification.map((verification) => ({
|
|
11750
|
+
...verification,
|
|
11751
|
+
scope: normalizedScope(verification.scope),
|
|
11752
|
+
availableChecks: normalizedRefList(verification.availableChecks),
|
|
11753
|
+
gaps: stableUnique(verification.gaps)
|
|
11754
|
+
})))
|
|
11755
|
+
}), normalizeConstraint = (constraint) => ({
|
|
11756
|
+
...constraint,
|
|
11757
|
+
source: constraint.source,
|
|
11758
|
+
requires: stableList(constraint.requires.map((requirement) => ({
|
|
11759
|
+
...requirement,
|
|
11760
|
+
scope: normalizedScope(requirement.scope),
|
|
11761
|
+
refs: normalizedRefList(requirement.refs)
|
|
11762
|
+
})))
|
|
11763
|
+
}), normalizeDecision = (decision) => ({
|
|
11764
|
+
...decision,
|
|
11765
|
+
binding: {
|
|
11766
|
+
...decision.binding,
|
|
11767
|
+
scope: normalizedScope(decision.binding.scope),
|
|
11768
|
+
contentRefs: normalizedRefList(decision.binding.contentRefs)
|
|
11769
|
+
},
|
|
11770
|
+
requirementIds: stableUnique(decision.requirementIds)
|
|
11771
|
+
}), normalizeIntent = (intent) => ({
|
|
11772
|
+
...intent,
|
|
11773
|
+
scope: normalizedScope(intent.scope),
|
|
11774
|
+
authorityRefs: normalizedRefList(intent.authorityRefs)
|
|
11775
|
+
}), normalizePrior = (prior) => ({
|
|
11776
|
+
decisions: stableList(prior.decisions.map(normalizeDecision)),
|
|
11777
|
+
findings: stableList(prior.findings.map((finding) => ({
|
|
11778
|
+
...finding,
|
|
11779
|
+
scope: normalizedScope(finding.scope),
|
|
11780
|
+
refs: normalizedRefList(finding.refs),
|
|
11781
|
+
resolution: finding.resolution ? {
|
|
11782
|
+
...finding.resolution,
|
|
11783
|
+
evidenceIds: stableUnique(finding.resolution.evidenceIds),
|
|
11784
|
+
decisionIds: stableUnique(finding.resolution.decisionIds)
|
|
11785
|
+
} : null
|
|
11786
|
+
}))),
|
|
11787
|
+
requirements: stableList(prior.requirements.map((requirement) => ({
|
|
11788
|
+
...requirement,
|
|
11789
|
+
scope: normalizedScope(requirement.scope)
|
|
11790
|
+
})))
|
|
11791
|
+
}), invalidFields = (error) => ({
|
|
11792
|
+
fields: error.issues.map((issue) => ({
|
|
11793
|
+
path: issue.code === "unrecognized_keys" ? issue.keys.join(".") : issue.path.join("."),
|
|
11794
|
+
reason: issue.message
|
|
11795
|
+
}))
|
|
11796
|
+
}), requirement = (spec) => ({
|
|
11797
|
+
...spec,
|
|
11798
|
+
id: requirementId({
|
|
11799
|
+
ruleId: spec.ruleId,
|
|
11800
|
+
scope: spec.scope,
|
|
11801
|
+
satisfaction: spec.satisfaction,
|
|
11802
|
+
before: spec.before,
|
|
11803
|
+
dependentAction: spec.dependentAction
|
|
11804
|
+
})
|
|
11805
|
+
}), signalReason = (input, name) => input.assessment.signals[name].reason;
|
|
11806
|
+
var init_policy_resolver = __esm(() => {
|
|
11807
|
+
init_zod();
|
|
11808
|
+
init_task_contract();
|
|
11809
|
+
resolverInputSchema = object({
|
|
11810
|
+
intent: intentSchema,
|
|
11811
|
+
assessment: assessmentSchema,
|
|
11812
|
+
constraints: array(constraintSchema),
|
|
11813
|
+
prior: object({
|
|
11814
|
+
decisions: array(decisionSchema),
|
|
11815
|
+
findings: array(findingSchema),
|
|
11816
|
+
requirements: array(requirementSchema)
|
|
11817
|
+
}).strict(),
|
|
11818
|
+
preferences: object({ fast: boolean2().optional(), thorough: boolean2().optional() }).strict().optional()
|
|
11819
|
+
}).strict();
|
|
11820
|
+
});
|
|
11821
|
+
|
|
11822
|
+
// packages/workit-core/src/core/task-evaluation.ts
|
|
11823
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
11824
|
+
import * as fs7 from "node:fs";
|
|
11825
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
11826
|
+
import path10 from "node:path";
|
|
11827
|
+
function captureCandidate(root, scope, environment = []) {
|
|
11828
|
+
let checkout;
|
|
11829
|
+
try {
|
|
11830
|
+
checkout = fs7.realpathSync(root);
|
|
11831
|
+
} catch {
|
|
11832
|
+
return failure("invalid_input", "candidate root does not exist");
|
|
11833
|
+
}
|
|
11834
|
+
const normalizedScope = canonicalScope(scope);
|
|
11835
|
+
if (!normalizedScope)
|
|
11836
|
+
return failure("invalid_input", "candidate scope is invalid: paths must be checkout-relative — to work in another repository, keep this task here and coordinate a separate linked task in that checkout", { fields: [{ path: "scope.paths", reason: "must be checkout-relative" }] });
|
|
11837
|
+
const roots = scopeRoots(checkout, normalizedScope);
|
|
11838
|
+
if (!roots.ok)
|
|
11839
|
+
return roots;
|
|
11840
|
+
const git = gitPaths(checkout);
|
|
11841
|
+
const names = new Set;
|
|
11842
|
+
let uncertain = git.uncertain;
|
|
11843
|
+
for (const target of roots.data) {
|
|
11844
|
+
const item = relative(checkout, target);
|
|
11845
|
+
if (item === ".git" || item === ".workit")
|
|
11846
|
+
continue;
|
|
11847
|
+
names.add(item);
|
|
11848
|
+
if (!fs7.existsSync(target))
|
|
11849
|
+
continue;
|
|
11850
|
+
let stat;
|
|
11783
11851
|
try {
|
|
11784
|
-
|
|
11785
|
-
return failure("invalid_input", `candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] });
|
|
11852
|
+
stat = fs7.lstatSync(target);
|
|
11786
11853
|
} catch {
|
|
11787
|
-
|
|
11854
|
+
uncertain = true;
|
|
11855
|
+
continue;
|
|
11788
11856
|
}
|
|
11789
|
-
|
|
11857
|
+
if (!git.git && stat.isDirectory() && !stat.isSymbolicLink())
|
|
11858
|
+
uncertain = walk(checkout, target, names) || uncertain;
|
|
11790
11859
|
}
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
|
|
11794
|
-
const
|
|
11795
|
-
|
|
11796
|
-
const
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
}
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11860
|
+
for (const item of git.paths)
|
|
11861
|
+
if (scopeMatches(item, normalizedScope))
|
|
11862
|
+
names.add(item);
|
|
11863
|
+
const files = [];
|
|
11864
|
+
let completeness = uncertain ? "uncertain" : "known";
|
|
11865
|
+
for (const item of [...names].sort()) {
|
|
11866
|
+
if (!scopeMatches(item, normalizedScope))
|
|
11867
|
+
continue;
|
|
11868
|
+
const target = path10.join(checkout, item);
|
|
11869
|
+
try {
|
|
11870
|
+
const stat = fs7.lstatSync(target);
|
|
11871
|
+
if (stat.isSymbolicLink()) {
|
|
11872
|
+
const link = fs7.readlinkSync(target);
|
|
11873
|
+
files.push({ path: item, kind: "symlink", digest: digestBytes3(link), executable: null });
|
|
11874
|
+
} else if (stat.isFile()) {
|
|
11875
|
+
files.push({
|
|
11876
|
+
path: item,
|
|
11877
|
+
kind: "file",
|
|
11878
|
+
digest: digestBytes3(fs7.readFileSync(target)),
|
|
11879
|
+
executable: (stat.mode & 73) !== 0
|
|
11880
|
+
});
|
|
11881
|
+
} else if (!stat.isDirectory()) {
|
|
11882
|
+
completeness = "uncertain";
|
|
11883
|
+
} else if (git.git && git.paths.includes(item)) {
|
|
11884
|
+
completeness = "uncertain";
|
|
11885
|
+
}
|
|
11886
|
+
} catch (error) {
|
|
11887
|
+
if (error?.code === "ENOENT") {
|
|
11888
|
+
files.push({ path: item, kind: "absent", digest: null, executable: null });
|
|
11889
|
+
} else
|
|
11890
|
+
completeness = "uncertain";
|
|
11891
|
+
}
|
|
11892
|
+
}
|
|
11893
|
+
const supplied = Array.isArray(environment) ? environment.map((value) => typeof value === "string" ? { name: value, value: process.env[value] ?? null } : { name: value.name, value: value.value ?? null }) : Object.keys(environment).map((name) => ({
|
|
11894
|
+
name,
|
|
11895
|
+
value: environment[name] ?? null
|
|
11896
|
+
}));
|
|
11897
|
+
const namesByEnvironment = supplied.map(({ name }) => name);
|
|
11898
|
+
if (new Set(namesByEnvironment).size !== namesByEnvironment.length || namesByEnvironment.some((name) => typeof name !== "string" || !name))
|
|
11899
|
+
return failure("invalid_input", "candidate environment names must be unique and non-empty");
|
|
11900
|
+
const values = supplied.sort((left, right) => compareCodeUnits3(left.name, right.name)).map(({ name, value }) => ({ name, value, refs: [] }));
|
|
11901
|
+
if (values.some(({ value }) => value === null))
|
|
11902
|
+
completeness = "uncertain";
|
|
11903
|
+
const headResult = spawnSync2("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
|
|
11904
|
+
if (headResult.status !== 0 && !/not a git repository/i.test(headResult.stderr ?? ""))
|
|
11905
|
+
completeness = "uncertain";
|
|
11906
|
+
const head = headResult.status === 0 ? headResult.stdout.trim() : null;
|
|
11907
|
+
const partial = {
|
|
11908
|
+
id: "0".repeat(64),
|
|
11909
|
+
scope: normalizedScope,
|
|
11910
|
+
completeness,
|
|
11911
|
+
files,
|
|
11912
|
+
environment: values,
|
|
11913
|
+
head
|
|
11820
11914
|
};
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
if (dimension === "testing" || dimension === "verification")
|
|
11825
|
-
return evidenceKind === "check" || ruleId === "pre-pr-cleanup" && evidenceKind === "artifact";
|
|
11826
|
-
if (dimension === "review")
|
|
11827
|
-
return evidenceKind === "review";
|
|
11828
|
-
if (dimension === "investigation" || dimension === "challenge")
|
|
11829
|
-
return evidenceKind === "investigation";
|
|
11830
|
-
if (dimension === "artifacts" || dimension === "continuity")
|
|
11831
|
-
return evidenceKind === "artifact";
|
|
11832
|
-
return false;
|
|
11833
|
-
}, expectedKinds = (dimension, ruleId) => {
|
|
11834
|
-
if (dimension === "testing")
|
|
11835
|
-
return "check";
|
|
11836
|
-
if (dimension === "verification")
|
|
11837
|
-
return ruleId === "pre-pr-cleanup" ? "check or artifact" : "check";
|
|
11838
|
-
if (dimension === "review")
|
|
11839
|
-
return "review";
|
|
11840
|
-
if (dimension === "investigation" || dimension === "challenge")
|
|
11841
|
-
return "investigation";
|
|
11842
|
-
if (dimension === "artifacts" || dimension === "continuity")
|
|
11843
|
-
return "artifact";
|
|
11844
|
-
if (dimension === "decisions")
|
|
11845
|
-
return "decision";
|
|
11846
|
-
return "worker report";
|
|
11847
|
-
};
|
|
11848
|
-
var init_task_evaluation = __esm(() => {
|
|
11849
|
-
init_task_contract();
|
|
11850
|
-
init_authority();
|
|
11851
|
-
scopeCovers2 = scopeCovers;
|
|
11852
|
-
});
|
|
11853
|
-
|
|
11854
|
-
// packages/workit-core/src/core/methods.ts
|
|
11855
|
-
function selectMethods(policy, capabilities) {
|
|
11856
|
-
return Object.entries(METHODS).flatMap(([id, definition]) => {
|
|
11857
|
-
const requirements = policy.requirements.filter((requirement) => methodMatches(definition, requirement));
|
|
11858
|
-
if (requirements.length === 0)
|
|
11859
|
-
return [];
|
|
11860
|
-
const capability = assuranceFor(id, definition, capabilities);
|
|
11861
|
-
const reasons = [
|
|
11862
|
-
...new Set(requirements.map((requirement) => requirement.reason)),
|
|
11863
|
-
...capability.reasons
|
|
11864
|
-
];
|
|
11865
|
-
if (capability.assurance === "unavailable")
|
|
11866
|
-
reasons.unshift("required capability is unavailable");
|
|
11867
|
-
return [{ id, reason: reasons.join("; "), assurance: capability.assurance }];
|
|
11868
|
-
});
|
|
11915
|
+
const candidate = { ...partial, id: candidateDigest(partial) };
|
|
11916
|
+
const parsed = candidateSchema.safeParse(candidate);
|
|
11917
|
+
return parsed.success ? success(null, null, parsed.data) : failure("invalid_input", "captured candidate is invalid");
|
|
11869
11918
|
}
|
|
11870
|
-
|
|
11871
|
-
const
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
|
|
11878
|
-
|
|
11879
|
-
|
|
11919
|
+
function evaluateEvidence(task, candidate) {
|
|
11920
|
+
const current = candidate ?? task.candidates.at(-1) ?? null;
|
|
11921
|
+
return task.evidence.map((entry) => {
|
|
11922
|
+
const evidence = entry.data;
|
|
11923
|
+
if (evidence.result === "failed")
|
|
11924
|
+
return {
|
|
11925
|
+
evidenceId: entry.id,
|
|
11926
|
+
status: "failed",
|
|
11927
|
+
reason: "failed evidence remains historical"
|
|
11928
|
+
};
|
|
11929
|
+
if (evidence.kind === "check" || evidence.kind === "review") {
|
|
11930
|
+
if (!evidence.beforeCandidateId || !evidence.candidateId)
|
|
11931
|
+
return {
|
|
11932
|
+
evidenceId: entry.id,
|
|
11933
|
+
status: "stale",
|
|
11934
|
+
reason: "check or review evidence lacks start and end candidates"
|
|
11935
|
+
};
|
|
11936
|
+
if (evidence.beforeCandidateId !== evidence.candidateId)
|
|
11937
|
+
return {
|
|
11938
|
+
evidenceId: entry.id,
|
|
11939
|
+
status: "stale",
|
|
11940
|
+
reason: "candidate changed during the check or review"
|
|
11941
|
+
};
|
|
11942
|
+
}
|
|
11943
|
+
if (!evidence.candidateId || !current)
|
|
11944
|
+
return {
|
|
11945
|
+
evidenceId: entry.id,
|
|
11946
|
+
status: evidence.result,
|
|
11947
|
+
reason: "evidence has no candidate binding"
|
|
11948
|
+
};
|
|
11949
|
+
const observed = task.candidates.find((item) => item.id === evidence.candidateId) ?? (current.id === evidence.candidateId ? current : undefined);
|
|
11950
|
+
if (!observed || observed.completeness === "uncertain" || current.completeness === "uncertain")
|
|
11951
|
+
return { evidenceId: entry.id, status: "stale", reason: "candidate is missing or uncertain" };
|
|
11952
|
+
if (observed.id === current.id)
|
|
11953
|
+
return { evidenceId: entry.id, status: evidence.result, reason: "candidate is unchanged" };
|
|
11954
|
+
const scopes = evidenceScopes(task, evidence.requirementIds);
|
|
11955
|
+
const changed = changedPaths(observed, current);
|
|
11956
|
+
const environmentChanged = JSON.stringify(observed.environment) !== JSON.stringify(current.environment);
|
|
11957
|
+
if (!scopes.length || environmentChanged || changed.some((item) => scopes.some((scope) => pathRelevant(item, scope))))
|
|
11958
|
+
return { evidenceId: entry.id, status: "stale", reason: "relevant candidate state changed" };
|
|
11880
11959
|
return {
|
|
11881
|
-
|
|
11882
|
-
|
|
11960
|
+
evidenceId: entry.id,
|
|
11961
|
+
status: evidence.result,
|
|
11962
|
+
reason: "candidate changed outside evidence scope"
|
|
11883
11963
|
};
|
|
11884
|
-
if (matches.some((capability) => capability.assurance === "enforced"))
|
|
11885
|
-
return { assurance: "enforced", reasons: matches.map((capability) => capability.reason) };
|
|
11886
|
-
return { assurance: "agent_guided", reasons: matches.map((capability) => capability.reason) };
|
|
11887
|
-
}, invariantBootstrap = () => `
|
|
11888
|
-
Workit is optional coordination and repository-policy tooling around the host,
|
|
11889
|
-
not a permission system or a mandatory workflow. Native host allow/ask/deny,
|
|
11890
|
-
sandbox, plan/read-only mode, and organization rules remain authoritative.
|
|
11891
|
-
Ordinary investigation, questions, non-Git work, and routine reversible edits
|
|
11892
|
-
need zero Workit task, assessment, or writer calls. Use one compact tracked
|
|
11893
|
-
record only when handoff, dependent steps, concurrent actors, or meaningful
|
|
11894
|
-
decisions make continuity useful; similar titles alone never merge tasks.
|
|
11895
|
-
|
|
11896
|
-
For a routine user-authorized branch or commit, prefer native host Git/shell
|
|
11897
|
-
tools from the outset when managed coordination or outcome reconciliation is
|
|
11898
|
-
not needed. Inspect the actual target checkout and its configured conventions;
|
|
11899
|
-
use Workit's read-only context/policy tools when needed. Do not start a task,
|
|
11900
|
-
acquire a writer, or mint a decision receipt solely for a native Git action.
|
|
11901
|
-
Native permissions still apply. Never switch execution paths to evade a denial
|
|
11902
|
-
or repeat an uncertain managed effect. A local-commit endpoint does not imply
|
|
11903
|
-
PR readiness, a fresh review, or post-commit assessment/closure paperwork.
|
|
11904
|
-
|
|
11905
|
-
For tracked work, inspect its current state and use the shared operations for
|
|
11906
|
-
task, policy, evidence, finding, decision, worker, writer, and state changes.
|
|
11907
|
-
Start a record once for an explicit tracked objective; assess or reassess only
|
|
11908
|
-
when policy selection or changed evidence/constraints requires it. Omitted
|
|
11909
|
-
expectedRevision and expectedWorkspaceRevision use current values; explicit
|
|
11910
|
-
values are still concurrency-checked, so never copy revisions between calls.
|
|
11911
|
-
A solo edit does not need writer acquisition; use it when concurrent checkout
|
|
11912
|
-
writers need coordination. Record only observed facts and checks. Evidence can
|
|
11913
|
-
become stale when its bound candidate changes; reconcile findings against the
|
|
11914
|
-
current candidate before recording completion.
|
|
11915
|
-
|
|
11916
|
-
Workit validates domain policy against the actual action target, configured
|
|
11917
|
-
account, branch and commit conventions, protected refs, and current repository
|
|
11918
|
-
state. The task directory is coordination state, not a boundary on which
|
|
11919
|
-
repository may be changed. Use an action-time cwd target where a managed
|
|
11920
|
-
Git/hosting action supports it; a non-Git directory remains valid for OS work.
|
|
11921
|
-
GitHub/GitLab use the active gh/glab CLI identity; YouTrack uses its own token.
|
|
11922
|
-
Preserve uncertain external outcomes and reconcile repository/provider state
|
|
11923
|
-
before retrying. Internal reservations prevent duplicate or ambiguous effects;
|
|
11924
|
-
they are not permission tickets for every edit.
|
|
11925
|
-
|
|
11926
|
-
On OpenCode V1 and V2, use native host tools for external mutations. Workit
|
|
11927
|
-
provides read-only workit_context; it has no managed external-action executor.
|
|
11928
|
-
Do not create proposals or request Workit approvals merely to invoke native
|
|
11929
|
-
tools. Old uncertain managed effects still require evidence before any retry.
|
|
11930
|
-
|
|
11931
|
-
Use host-native authorization through the host's supported path. A native
|
|
11932
|
-
question receipt records an actual question interaction; it is not automatic
|
|
11933
|
-
host permission. Record a meaningful user choice once with provenance when
|
|
11934
|
-
future retrieval helps. Never fabricate a receipt, re-ask only to mint one, or
|
|
11935
|
-
let imported decisions grant authority. Never turn a host deny into allow or
|
|
11936
|
-
claim enforcement/evidence a host cannot provide. A precise request with settled
|
|
11937
|
-
constraints does not need an interview. Present genuine unresolved options with
|
|
11938
|
-
evidence and a recommendation, then continue toward the requested delivery
|
|
11939
|
-
endpoint: investigation, implementation, branch/commit/push, PR/MR-ready,
|
|
11940
|
-
merge, or release. Run
|
|
11941
|
-
applicable checks and safe repairs without repeated continuation questions;
|
|
11942
|
-
stop for missing host authority, a new consequential choice, a conflicting edit,
|
|
11943
|
-
or an unresolved blocker. A tracked record may close when actual evidence
|
|
11944
|
-
supports its outcome; no final human closure ceremony is required.
|
|
11945
|
-
|
|
11946
|
-
A completed native subagent run stops its bound worker by itself; if a worker
|
|
11947
|
-
strands in cancelling with its run verifiably over, repeat worker.cancel to
|
|
11948
|
-
confirm the stop. Preserve unresolved requirements, gaps, and uncertain workers.
|
|
11949
|
-
When context changes, distinguish a quick question, same-task adjustment, and
|
|
11950
|
-
separate request. Answer a quick question without pausing/resuming task state;
|
|
11951
|
-
park a concise checkpoint only when substantial work needs to continue later.
|
|
11952
|
-
For work spanning repositories, bind each unfinished item to its actual checkout,
|
|
11953
|
-
branch, requested deliverables, and delivery endpoint. Preserve held items with
|
|
11954
|
-
an explicit resume condition. Resolve competing plausible targets before a
|
|
11955
|
-
mutation; ask only when available context cannot settle that consequential choice.
|
|
11956
|
-
Before reporting delivery, reconcile every requested item and observe the actual
|
|
11957
|
-
target result; a local commit alone is not evidence of a requested remote push.
|
|
11958
|
-
|
|
11959
|
-
Skill routing: slash aliases /wk-* load on demand. Use workit-steer for a
|
|
11960
|
-
substantial interruption or change of direction, workit-deslop when relevant
|
|
11961
|
-
to a PR-ready endpoint, workit-green-run for failing CI, workit-blast-radius
|
|
11962
|
-
when impact is uncertain, and workit-challenge for genuinely open consequential
|
|
11963
|
-
choices. Load workit-plan when dependencies or handoff need durable next actions.
|
|
11964
|
-
Load the skill; never act from memory of it.
|
|
11965
|
-
`.trim();
|
|
11966
|
-
var init_methods = __esm(() => {
|
|
11967
|
-
METHODS = {
|
|
11968
|
-
"workit-challenge": { dimensions: ["challenge", "decisions"] },
|
|
11969
|
-
"workit-behavioral-tdd": { dimensions: ["testing"], ruleIds: ["mechanical-existing-checks"] },
|
|
11970
|
-
"workit-review": { dimensions: ["review"], ruleIds: ["fresh-context-review", "self-review"] },
|
|
11971
|
-
"workit-plan": { dimensions: ["artifacts", "continuity"] },
|
|
11972
|
-
"workit-implement": { dimensions: ["delegation"] },
|
|
11973
|
-
"workit-debug": {},
|
|
11974
|
-
"workit-handoff": {},
|
|
11975
|
-
"workit-deslop": { ruleIds: ["pre-pr-cleanup"] }
|
|
11976
|
-
};
|
|
11977
|
-
});
|
|
11978
|
-
|
|
11979
|
-
// packages/workit-core/src/core/task-context.ts
|
|
11980
|
-
function reconcileResume(view, observations = []) {
|
|
11981
|
-
if (observations.length > 0)
|
|
11982
|
-
return failure("permission_denied", "worker observations require native host verification");
|
|
11983
|
-
const candidate = captureCandidate(view.workspace.root, view.task.intent.data.scope, []);
|
|
11984
|
-
if (!candidate.ok)
|
|
11985
|
-
return candidate;
|
|
11986
|
-
const staleEvidenceIds = evaluateEvidence(view.task, candidate.data).filter((entry) => entry.status === "stale").map((entry) => entry.evidenceId);
|
|
11987
|
-
const blockers = [...view.task.progress.blockers];
|
|
11988
|
-
if (view.task.workers.some((entry) => isUncertainWorker(entry.data.state)))
|
|
11989
|
-
blockers.push({
|
|
11990
|
-
reason: "worker state requires reconciliation",
|
|
11991
|
-
dependentAction: "resume",
|
|
11992
|
-
refs: []
|
|
11993
|
-
});
|
|
11994
|
-
return success(null, null, {
|
|
11995
|
-
candidate: candidate.data,
|
|
11996
|
-
staleEvidenceIds,
|
|
11997
|
-
workerUpdates: [],
|
|
11998
|
-
blockers,
|
|
11999
|
-
reassessmentRequired: view.task.policy?.policyVersion !== POLICY_VERSION
|
|
12000
11964
|
});
|
|
12001
11965
|
}
|
|
12002
|
-
function
|
|
12003
|
-
const
|
|
12004
|
-
|
|
12005
|
-
|
|
12006
|
-
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
|
|
12011
|
-
purpose: entry.data.purpose,
|
|
12012
|
-
status: entry.data.response,
|
|
12013
|
-
digest: entry.data.digest,
|
|
12014
|
-
choice: compactDecisionChoice(entry) || `task.inspect taskId=${view.task.id} view=full; decision=${entry.id}`,
|
|
12015
|
-
references: entry.data.binding.contentRefs.slice(0, 1).map(compactReference)
|
|
12016
|
-
}));
|
|
12017
|
-
const methods = view.task.policy ? selectMethods(view.task.policy, view.capabilities).map((method) => ({
|
|
12018
|
-
id: method.id,
|
|
12019
|
-
assurance: method.assurance,
|
|
12020
|
-
reason: compactText(method.reason, COMPACT_TEXT_BYTES) ?? ""
|
|
12021
|
-
})) : [];
|
|
12022
|
-
const gaps = Array.from(new Set([
|
|
12023
|
-
...view.evidence.filter((entry) => entry.status === "stale").map((entry) => `stale evidence: ${entry.evidenceId}`),
|
|
12024
|
-
...view.requirements.filter((entry) => entry.status !== "satisfied").map((entry) => entry.reason),
|
|
12025
|
-
...view.task.progress.blockers.map((entry) => entry.reason)
|
|
12026
|
-
])).sort().slice(0, COMPACT_MAX_ITEMS).map((gap) => compactText(gap, COMPACT_TEXT_BYTES));
|
|
12027
|
-
const context = {
|
|
12028
|
-
objective: compactText(view.task.intent.data.objective, COMPACT_TEXT_BYTES) ?? "",
|
|
12029
|
-
status: view.task.status,
|
|
12030
|
-
decisions,
|
|
12031
|
-
methods,
|
|
12032
|
-
gaps,
|
|
12033
|
-
nextAction: compactText(view.task.progress.nextAction, COMPACT_TEXT_BYTES)
|
|
12034
|
-
};
|
|
12035
|
-
let encoded = JSON.stringify(context);
|
|
12036
|
-
while (compactBytes(encoded) > COMPACT_MAX_BYTES && (context.decisions.length || context.methods.length || context.gaps.length)) {
|
|
12037
|
-
if (context.gaps.length)
|
|
12038
|
-
context.gaps.pop();
|
|
12039
|
-
else if (context.decisions.length)
|
|
12040
|
-
context.decisions.pop();
|
|
12041
|
-
else
|
|
12042
|
-
context.methods.pop();
|
|
12043
|
-
encoded = JSON.stringify(context);
|
|
12044
|
-
}
|
|
12045
|
-
if (compactBytes(encoded) > COMPACT_MAX_BYTES) {
|
|
12046
|
-
context.objective = compactText(context.objective, 64) ?? "";
|
|
12047
|
-
context.nextAction = compactText(context.nextAction, 64);
|
|
12048
|
-
encoded = JSON.stringify(context);
|
|
12049
|
-
}
|
|
12050
|
-
return encoded;
|
|
12051
|
-
}
|
|
12052
|
-
var COMPACT_MAX_BYTES = 4096, COMPACT_MAX_ITEMS = 8, COMPACT_TEXT_BYTES = 128, sensitiveUrl, sensitiveValue, privateKey, compactText = (value, limit) => value === null ? null : value.replace(privateKey, "<redacted-private-key>").replace(sensitiveUrl, "<redacted-url>").replace(sensitiveValue, (match) => {
|
|
12053
|
-
const separator = match.search(/[:=]/u);
|
|
12054
|
-
if (separator >= 0)
|
|
12055
|
-
return `${match.slice(0, separator)}=<redacted>`;
|
|
12056
|
-
const space = match.search(/\s/u);
|
|
12057
|
-
return `${match.slice(0, space)} <redacted>`;
|
|
12058
|
-
}).slice(0, limit), compactBytes = (value) => new TextEncoder().encode(value).byteLength, compactTimestamp = (value) => `${value.slice(0, 19)}.${value.slice(20, -1).padEnd(9, "0")}`, compactDecisionChoice = (entry) => {
|
|
12059
|
-
const stated = entry.data.binding.statedChoice?.text;
|
|
12060
|
-
const approved = entry.data.response === "approved" ? entry.data.binding.approvedContent : "";
|
|
12061
|
-
const source = stated?.trim() || approved.trim() || null;
|
|
12062
|
-
return compactText(source, COMPACT_TEXT_BYTES);
|
|
12063
|
-
}, compactReference = (ref) => {
|
|
12064
|
-
if (ref.kind === "file")
|
|
12065
|
-
return {
|
|
12066
|
-
kind: "file",
|
|
12067
|
-
path: compactText(ref.path, COMPACT_TEXT_BYTES) ?? ""
|
|
12068
|
-
};
|
|
12069
|
-
if (ref.kind === "record")
|
|
12070
|
-
return {
|
|
12071
|
-
kind: "record",
|
|
12072
|
-
collection: ref.collection,
|
|
12073
|
-
id: ref.id
|
|
12074
|
-
};
|
|
12075
|
-
return { kind: ref.kind };
|
|
12076
|
-
}, exportDigest = (bundle) => sha256({
|
|
12077
|
-
schemaVersion: bundle.schemaVersion,
|
|
12078
|
-
exportedAt: bundle.exportedAt,
|
|
12079
|
-
sourceWorkspaceId: bundle.sourceWorkspaceId,
|
|
12080
|
-
task: bundle.task
|
|
12081
|
-
});
|
|
12082
|
-
var init_task_context = __esm(() => {
|
|
12083
|
-
init_workers();
|
|
12084
|
-
init_task_contract();
|
|
12085
|
-
init_task_evaluation();
|
|
12086
|
-
init_methods();
|
|
12087
|
-
sensitiveUrl = /\bhttps?:\/\/[^/\s:@]+:[^@\s]+@/gi;
|
|
12088
|
-
sensitiveValue = /(?:token|secret|password|passwd|api[-_ ]?key|private[-_ ]?key|authorization)\s*[:=]\s*(?:bearer\s+)?\S+|\bbearer\s+\S+/gi;
|
|
12089
|
-
privateKey = /-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi;
|
|
12090
|
-
});
|
|
12091
|
-
|
|
12092
|
-
// packages/workit-core/src/core/route-intent.ts
|
|
12093
|
-
var init_route_intent = __esm(() => {
|
|
12094
|
-
init_branch();
|
|
12095
|
-
});
|
|
12096
|
-
|
|
12097
|
-
// packages/workit-core/src/core/runtime-identity.ts
|
|
12098
|
-
var init_runtime_identity = () => {};
|
|
12099
|
-
|
|
12100
|
-
// packages/workit-core/src/core/external-action.ts
|
|
12101
|
-
var chainStepSchema, externalActionSchema;
|
|
12102
|
-
var init_external_action = __esm(() => {
|
|
12103
|
-
init_task_contract();
|
|
12104
|
-
init_task_store();
|
|
12105
|
-
init_authority();
|
|
12106
|
-
init_zod();
|
|
12107
|
-
chainStepSchema = union([
|
|
12108
|
-
string2().min(1),
|
|
12109
|
-
object({ branch: string2().min(1) }).strict(),
|
|
12110
|
-
object({ pr: literal(true) }).strict()
|
|
12111
|
-
]);
|
|
12112
|
-
externalActionSchema = discriminatedUnion("operation", [
|
|
12113
|
-
object({
|
|
12114
|
-
operation: literal("git.branch_setup"),
|
|
12115
|
-
payload: object({
|
|
12116
|
-
action: _enum(["setup", "reapply_stash"]).optional(),
|
|
12117
|
-
sdd_dir: string2().optional(),
|
|
12118
|
-
target_branch: string2().optional(),
|
|
12119
|
-
stash: _enum(["yes", "no"]).optional(),
|
|
12120
|
-
cwd: string2().min(1).optional()
|
|
12121
|
-
}).strict()
|
|
12122
|
-
}).strict(),
|
|
12123
|
-
object({
|
|
12124
|
-
operation: literal("git.commit"),
|
|
12125
|
-
payload: object({
|
|
12126
|
-
message: string2().min(1).optional(),
|
|
12127
|
-
plan_steps: array(chainStepSchema).min(1).max(32).optional(),
|
|
12128
|
-
plan_branch: string2().min(1).optional(),
|
|
12129
|
-
cwd: string2().min(1).optional()
|
|
12130
|
-
}).strict()
|
|
12131
|
-
}).strict(),
|
|
12132
|
-
object({
|
|
12133
|
-
operation: literal("git.push"),
|
|
12134
|
-
payload: object({ branch: string2().min(1).optional(), cwd: string2().min(1).optional() }).strict()
|
|
12135
|
-
}).strict(),
|
|
12136
|
-
object({
|
|
12137
|
-
operation: literal("hosting.pull_request"),
|
|
12138
|
-
payload: object({
|
|
12139
|
-
title: string2().min(1),
|
|
12140
|
-
body: string2().optional(),
|
|
12141
|
-
draft: boolean2().optional(),
|
|
12142
|
-
target_branch: string2().optional(),
|
|
12143
|
-
babysit: boolean2().optional(),
|
|
12144
|
-
cwd: string2().min(1).optional()
|
|
12145
|
-
}).strict()
|
|
12146
|
-
}).strict(),
|
|
12147
|
-
object({
|
|
12148
|
-
operation: literal("hosting.merge"),
|
|
12149
|
-
payload: object({
|
|
12150
|
-
target_branch: string2().min(1).optional(),
|
|
12151
|
-
source_branch: string2().min(1).optional(),
|
|
12152
|
-
cwd: string2().min(1).optional()
|
|
12153
|
-
}).strict()
|
|
12154
|
-
}).strict(),
|
|
12155
|
-
object({
|
|
12156
|
-
operation: literal("hosting.delete_branch"),
|
|
12157
|
-
payload: object({ branch: string2().min(1), cwd: string2().min(1).optional() }).strict()
|
|
12158
|
-
}).strict(),
|
|
12159
|
-
object({
|
|
12160
|
-
operation: literal("youtrack.update"),
|
|
12161
|
-
payload: object({
|
|
12162
|
-
issueId: string2().min(1),
|
|
12163
|
-
markdown: string2().min(1),
|
|
12164
|
-
minutes: number2().positive().optional()
|
|
12165
|
-
}).strict()
|
|
12166
|
-
}).strict(),
|
|
12167
|
-
object({
|
|
12168
|
-
operation: literal("youtrack.time"),
|
|
12169
|
-
payload: object({
|
|
12170
|
-
issueId: string2().min(1),
|
|
12171
|
-
minutes: number2().positive(),
|
|
12172
|
-
text: string2().optional(),
|
|
12173
|
-
dateMs: number2().finite().optional()
|
|
12174
|
-
}).strict()
|
|
12175
|
-
}).strict(),
|
|
12176
|
-
object({
|
|
12177
|
-
operation: literal("youtrack.meeting"),
|
|
12178
|
-
payload: object({
|
|
12179
|
-
issueId: string2().min(1),
|
|
12180
|
-
minutes: number2().positive(),
|
|
12181
|
-
text: string2().min(1)
|
|
12182
|
-
}).strict()
|
|
12183
|
-
}).strict(),
|
|
12184
|
-
object({
|
|
12185
|
-
operation: literal("changelog.apply"),
|
|
12186
|
-
payload: object({
|
|
12187
|
-
entries: union([
|
|
12188
|
-
record(string2(), array(string2())),
|
|
12189
|
-
array(object({ category: string2().min(1), text: string2().min(1) }).strict())
|
|
12190
|
-
]).optional(),
|
|
12191
|
-
path: string2().optional(),
|
|
12192
|
-
normalize_only: boolean2().optional()
|
|
12193
|
-
}).strict()
|
|
12194
|
-
}).strict(),
|
|
12195
|
-
object({
|
|
12196
|
-
operation: literal("context.read"),
|
|
12197
|
-
payload: object({
|
|
12198
|
-
kind: _enum([
|
|
12199
|
-
"git",
|
|
12200
|
-
"pr",
|
|
12201
|
-
"youtrack",
|
|
12202
|
-
"github_issue",
|
|
12203
|
-
"gitlab_issue",
|
|
12204
|
-
"changelog",
|
|
12205
|
-
"release",
|
|
12206
|
-
"affected"
|
|
12207
|
-
]),
|
|
12208
|
-
range: string2().optional(),
|
|
12209
|
-
issueId: string2().optional(),
|
|
12210
|
-
issueUrl: string2().optional(),
|
|
12211
|
-
issueRef: string2().optional(),
|
|
12212
|
-
mode: string2().optional(),
|
|
12213
|
-
specPath: string2().optional(),
|
|
12214
|
-
planPath: string2().optional(),
|
|
12215
|
-
cwd: string2().min(1).optional()
|
|
12216
|
-
}).strict()
|
|
12217
|
-
}).strict()
|
|
12218
|
-
]);
|
|
12219
|
-
});
|
|
12220
|
-
|
|
12221
|
-
// packages/workit-core/src/core/policy-resolver.ts
|
|
12222
|
-
function normalizeResolverInput(input) {
|
|
12223
|
-
const parsed = resolverInputSchema.safeParse(input);
|
|
12224
|
-
if (!parsed.success)
|
|
12225
|
-
return failure("invalid_input", "resolver input is invalid", invalidFields(parsed.error));
|
|
12226
|
-
const value = parsed.data;
|
|
12227
|
-
const signals = value.assessment.signals;
|
|
12228
|
-
if (signals.behaviorChange.value === true && signals.mechanicalLowRisk.value === true)
|
|
12229
|
-
return failure("invalid_input", "behavioral change cannot be wholly mechanical", {
|
|
12230
|
-
fields: [
|
|
12231
|
-
{
|
|
12232
|
-
path: "assessment.signals",
|
|
12233
|
-
reason: "contradictory behaviorChange and mechanicalLowRisk"
|
|
12234
|
-
}
|
|
12235
|
-
]
|
|
12236
|
-
});
|
|
12237
|
-
const ids = value.constraints.map((constraint) => constraint.id);
|
|
12238
|
-
if (new Set(ids).size !== ids.length)
|
|
12239
|
-
return failure("invalid_input", "constraint IDs must be unique", {
|
|
12240
|
-
fields: [{ path: "constraints", reason: "duplicate constraint id" }]
|
|
12241
|
-
});
|
|
12242
|
-
if (value.preferences?.fast && value.preferences.thorough)
|
|
12243
|
-
return failure("invalid_input", "fast and thorough preferences contradict", {
|
|
12244
|
-
fields: [{ path: "preferences", reason: "fast and thorough cannot both be enabled" }]
|
|
12245
|
-
});
|
|
12246
|
-
const normalized = {
|
|
12247
|
-
intent: normalizeIntent(value.intent),
|
|
12248
|
-
assessment: normalizeAssessment(value.assessment),
|
|
12249
|
-
constraints: stableList(value.constraints.map(normalizeConstraint)),
|
|
12250
|
-
prior: normalizePrior(value.prior),
|
|
12251
|
-
...value.preferences ? { preferences: { ...value.preferences } } : {},
|
|
12252
|
-
policyVersion: POLICY_VERSION
|
|
12253
|
-
};
|
|
12254
|
-
return success(null, null, normalized);
|
|
12255
|
-
}
|
|
12256
|
-
function resolveRequirements(input) {
|
|
12257
|
-
const { signals } = input.assessment;
|
|
12258
|
-
const scope = input.intent.scope;
|
|
12259
|
-
const requirements = [];
|
|
12260
|
-
const hasUnknownSignal = Object.values(signals).some((signal) => signal.value === "unknown");
|
|
12261
|
-
const hasUnknownFact = [
|
|
12262
|
-
...input.assessment.facts,
|
|
12263
|
-
...input.assessment.consequences.map(({ fact }) => fact)
|
|
12264
|
-
].some((fact) => fact.basis === "unknown");
|
|
12265
|
-
if (hasUnknownSignal || hasUnknownFact)
|
|
12266
|
-
requirements.push(requirement({
|
|
12267
|
-
ruleId: "consequential-unknown",
|
|
12268
|
-
dimension: "investigation",
|
|
12269
|
-
scope,
|
|
12270
|
-
reason: `Resolve consequential uncertainty before the dependent action: ${[
|
|
12271
|
-
...Object.entries(signals).filter(([, signal]) => signal.value === "unknown").map(([name]) => name),
|
|
12272
|
-
...hasUnknownFact ? ["unknown fact"] : []
|
|
12273
|
-
].join(", ")}`,
|
|
12274
|
-
satisfaction: "An observed or inferred fact resolves the uncertainty and records its supporting references.",
|
|
12275
|
-
before: "dependent_action",
|
|
12276
|
-
dependentAction: null,
|
|
12277
|
-
acceptanceAllowed: false
|
|
12278
|
-
}));
|
|
12279
|
-
if (signals.productChoiceOpen.value === true)
|
|
12280
|
-
requirements.push(requirement({
|
|
12281
|
-
ruleId: "product-decision",
|
|
12282
|
-
dimension: "decisions",
|
|
12283
|
-
scope,
|
|
12284
|
-
reason: `A consequential product choice remains open: ${signalReason(input, "productChoiceOpen")}`,
|
|
12285
|
-
satisfaction: "Present the material alternatives and record the user's decision before the dependent action.",
|
|
12286
|
-
before: "dependent_action",
|
|
12287
|
-
dependentAction: null,
|
|
12288
|
-
acceptanceAllowed: false
|
|
12289
|
-
}));
|
|
12290
|
-
const independentBehaviorReview = input.preferences?.thorough === true || input.assessment.consequences.some((consequence) => ["security", "data", "public_contract", "operations"].includes(consequence.area));
|
|
12291
|
-
if (signals.behaviorChange.value === true)
|
|
12292
|
-
requirements.push(requirement({
|
|
12293
|
-
ruleId: "behavioral-verification",
|
|
12294
|
-
dimension: "testing",
|
|
12295
|
-
scope,
|
|
12296
|
-
reason: `Behavior, side effects, permissions, or data handling may change: ${signalReason(input, "behaviorChange")}`,
|
|
12297
|
-
satisfaction: "A useful behavioral check passes against the affected behavior and current candidate.",
|
|
12298
|
-
before: "close",
|
|
12299
|
-
dependentAction: null,
|
|
12300
|
-
acceptanceAllowed: false
|
|
12301
|
-
}), requirement({
|
|
12302
|
-
ruleId: independentBehaviorReview ? "fresh-context-review" : "self-review",
|
|
12303
|
-
dimension: "review",
|
|
12304
|
-
scope,
|
|
12305
|
-
reason: independentBehaviorReview ? "Consequential behavior or the thorough preference requires fresh-context review." : "Bounded behavior changes use self-review unless consequential risks or trusted rules require more.",
|
|
12306
|
-
satisfaction: independentBehaviorReview ? "A separate review context examines the current candidate and records its result." : "The lead reviews the resulting diff and records the relevant scope and checks.",
|
|
12307
|
-
before: "close",
|
|
12308
|
-
dependentAction: null,
|
|
12309
|
-
acceptanceAllowed: !independentBehaviorReview
|
|
12310
|
-
}));
|
|
12311
|
-
else if (signals.mechanicalLowRisk.value === true)
|
|
12312
|
-
requirements.push(requirement({
|
|
12313
|
-
ruleId: "mechanical-existing-checks",
|
|
12314
|
-
dimension: "verification",
|
|
12315
|
-
scope,
|
|
12316
|
-
reason: `The change is demonstrably mechanical and low-risk: ${signalReason(input, "mechanicalLowRisk")}`,
|
|
12317
|
-
satisfaction: "Run the relevant existing checks for affected consumers; do not add tautological tests.",
|
|
12318
|
-
before: "close",
|
|
12319
|
-
dependentAction: null,
|
|
12320
|
-
acceptanceAllowed: true
|
|
12321
|
-
}), requirement({
|
|
12322
|
-
ruleId: input.preferences?.thorough ? "fresh-context-review" : "self-review",
|
|
12323
|
-
dimension: "review",
|
|
12324
|
-
scope,
|
|
12325
|
-
reason: input.preferences?.thorough ? "The thorough preference upgrades mechanical self-review to fresh-context review." : "Mechanical low-risk work uses self-review rather than mandatory fresh-context review.",
|
|
12326
|
-
satisfaction: input.preferences?.thorough ? "A separate review context examines the current candidate and records its result." : "The lead reviews the resulting diff and records the relevant scope and checks.",
|
|
12327
|
-
before: "close",
|
|
12328
|
-
dependentAction: null,
|
|
12329
|
-
acceptanceAllowed: !input.preferences?.thorough
|
|
12330
|
-
}));
|
|
12331
|
-
if (signals.behaviorChange.value === true || signals.mechanicalLowRisk.value === true)
|
|
12332
|
-
requirements.push(requirement({
|
|
12333
|
-
ruleId: "pre-pr-cleanup",
|
|
12334
|
-
dimension: "verification",
|
|
12335
|
-
scope,
|
|
12336
|
-
reason: "Implementation output must be deslopped before it is delivered.",
|
|
12337
|
-
satisfaction: "Run the workit-deslop pass and record passing check evidence, or record an approved limitation decision waiving cleanup.",
|
|
12338
|
-
before: "dependent_action",
|
|
12339
|
-
dependentAction: "hosting.pull_request",
|
|
12340
|
-
acceptanceAllowed: true
|
|
12341
|
-
}));
|
|
12342
|
-
if (signals.durableAgreementNeeded.value === true)
|
|
12343
|
-
requirements.push(requirement({
|
|
12344
|
-
ruleId: "durable-spec",
|
|
12345
|
-
dimension: "artifacts",
|
|
12346
|
-
scope,
|
|
12347
|
-
reason: `The work needs a durable agreement about intended behavior: ${signalReason(input, "durableAgreementNeeded")}`,
|
|
12348
|
-
satisfaction: "Record the agreed behavior in a durable specification before implementation writes.",
|
|
12349
|
-
before: "write",
|
|
12350
|
-
dependentAction: null,
|
|
12351
|
-
acceptanceAllowed: true
|
|
12352
|
-
}));
|
|
12353
|
-
if (signals.coordinationPlanNeeded.value === true)
|
|
12354
|
-
requirements.push(requirement({
|
|
12355
|
-
ruleId: "coordination-plan",
|
|
12356
|
-
dimension: "continuity",
|
|
12357
|
-
scope,
|
|
12358
|
-
reason: `Dependencies, sequencing, or resumption need durable coordination: ${signalReason(input, "coordinationPlanNeeded")}`,
|
|
12359
|
-
satisfaction: "Record useful sequencing, dependencies, and the next action in a compact plan.",
|
|
12360
|
-
before: "dependent_action",
|
|
12361
|
-
dependentAction: null,
|
|
12362
|
-
acceptanceAllowed: true
|
|
12363
|
-
}));
|
|
12364
|
-
if (signals.helperUseful.value === true && !input.preferences?.fast)
|
|
12365
|
-
requirements.push(requirement({
|
|
12366
|
-
ruleId: "helper-usefulness",
|
|
12367
|
-
dimension: "delegation",
|
|
12368
|
-
scope,
|
|
12369
|
-
reason: `Independent judgment or investigation justifies a scoped helper: ${signalReason(input, "helperUseful")}`,
|
|
12370
|
-
satisfaction: "Use a bounded helper only for the independent objective and reconcile its result.",
|
|
12371
|
-
before: "dependent_action",
|
|
12372
|
-
dependentAction: null,
|
|
12373
|
-
acceptanceAllowed: true
|
|
11966
|
+
function evaluateRequirements(task, workspace, capabilities, candidate, checkoutRoot, _caller) {
|
|
11967
|
+
const evidence = evaluateEvidence(task, candidate);
|
|
11968
|
+
if (task.policy && task.policy.policyVersion !== POLICY_VERSION)
|
|
11969
|
+
return task.policy.requirements.map((requirement) => ({
|
|
11970
|
+
requirementId: requirement.id,
|
|
11971
|
+
status: "unsatisfied",
|
|
11972
|
+
evidenceIds: [],
|
|
11973
|
+
decisionIds: [],
|
|
11974
|
+
reason: "stored policy version is unsupported; reassessment is required"
|
|
12374
11975
|
}));
|
|
12375
|
-
|
|
12376
|
-
|
|
12377
|
-
|
|
12378
|
-
|
|
12379
|
-
|
|
12380
|
-
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
|
|
12394
|
-
|
|
11976
|
+
return (task.policy?.requirements ?? []).map((requirement) => {
|
|
11977
|
+
const related = task.evidence.map((entry, index) => ({ entry, evaluation: evidence[index] })).filter(({ entry }) => entry.data.requirementIds.includes(requirement.id));
|
|
11978
|
+
const passed = related.filter(({ entry, evaluation }) => {
|
|
11979
|
+
if (!evidenceMatchesRequirement(evaluation.status, entry.data.kind, requirement.dimension, requirement.ruleId))
|
|
11980
|
+
return false;
|
|
11981
|
+
if ((entry.data.kind === "check" || entry.data.kind === "review") && (!entry.data.beforeCandidateId || !entry.data.candidateId || entry.data.beforeCandidateId !== entry.data.candidateId))
|
|
11982
|
+
return false;
|
|
11983
|
+
if (requirement.dimension !== "review")
|
|
11984
|
+
return true;
|
|
11985
|
+
const reviewSession = sessionFromRef(entry.data.reviewContext);
|
|
11986
|
+
const sameImplementation = sameSession(reviewSession, task.intent.provenance.session);
|
|
11987
|
+
const sameEvidenceSession = related.some(({ entry: other }) => other.id !== entry.id && other.data.kind === "review" && other.data.candidateId !== null && other.data.candidateId === entry.data.candidateId && sameSession(reviewSession, other.provenance.session));
|
|
11988
|
+
return entry.data.kind === "review" && reviewSession !== null && sameSession(reviewSession, entry.provenance.session) && (requirement.ruleId === "self-review" || !sameImplementation && !sameEvidenceSession);
|
|
11989
|
+
});
|
|
11990
|
+
if (passed.length) {
|
|
11991
|
+
const currentId = candidate?.id ?? null;
|
|
11992
|
+
const withRed = requirement.dimension === "testing" ? passed.filter(({ entry }) => related.some((other) => other.entry.data.kind === "check" && other.evaluation.status === "failed" && other.entry.data.requirementIds.includes(requirement.id) && other.entry.recordedAt <= entry.recordedAt) || related.some((baseline) => baseline.entry.id !== entry.id && baseline.entry.data.kind === "check" && baseline.entry.data.result === "passed" && baseline.entry.data.candidateId !== null && currentId !== null && baseline.entry.data.candidateId !== currentId)) : passed;
|
|
11993
|
+
if (withRed.length)
|
|
11994
|
+
return {
|
|
11995
|
+
requirementId: requirement.id,
|
|
11996
|
+
status: "satisfied",
|
|
11997
|
+
evidenceIds: withRed.map(({ entry }) => entry.id),
|
|
11998
|
+
decisionIds: [],
|
|
11999
|
+
reason: "fresh applicable evidence passed"
|
|
12000
|
+
};
|
|
12001
|
+
if (requirement.dimension === "testing")
|
|
12002
|
+
return {
|
|
12003
|
+
requirementId: requirement.id,
|
|
12004
|
+
status: "unsatisfied",
|
|
12005
|
+
evidenceIds: [],
|
|
12006
|
+
decisionIds: [],
|
|
12007
|
+
reason: "testing requirement has GREEN evidence but no preceding RED"
|
|
12008
|
+
};
|
|
12009
|
+
}
|
|
12010
|
+
if (requirement.dimension === "delegation") {
|
|
12011
|
+
const dot = (scope) => scope.paths.length > 0 ? scope : { ...scope, paths: ["."] };
|
|
12012
|
+
const reconciled = task.workers.some((worker) => worker.data.report?.outcome === "completed" && (worker.data.assignment.requirementIds.includes(requirement.id) || scopeCovers2(dot(requirement.scope), dot(worker.data.assignment.scope))));
|
|
12013
|
+
if (reconciled)
|
|
12014
|
+
return {
|
|
12015
|
+
requirementId: requirement.id,
|
|
12016
|
+
status: "satisfied",
|
|
12017
|
+
evidenceIds: [],
|
|
12018
|
+
decisionIds: [],
|
|
12019
|
+
reason: "bounded helper completed and its result is recorded"
|
|
12020
|
+
};
|
|
12021
|
+
}
|
|
12022
|
+
const decisions = requirement.dimension === "decisions" ? applicableRequirementDecision(task, workspace, requirement, checkoutRoot) : [];
|
|
12023
|
+
if (decisions.length)
|
|
12024
|
+
return {
|
|
12025
|
+
requirementId: requirement.id,
|
|
12026
|
+
status: "satisfied",
|
|
12027
|
+
evidenceIds: [],
|
|
12028
|
+
decisionIds: decisions.map((decision) => decision.id),
|
|
12029
|
+
reason: "an applicable approved or stated decision satisfies the requirement"
|
|
12030
|
+
};
|
|
12031
|
+
const limitations = requirement.acceptanceAllowed ? applicableDecision2(task, workspace, requirement, checkoutRoot) : [];
|
|
12032
|
+
if (limitations.length)
|
|
12033
|
+
return {
|
|
12034
|
+
requirementId: requirement.id,
|
|
12035
|
+
status: "accepted_limitation",
|
|
12036
|
+
evidenceIds: [],
|
|
12037
|
+
decisionIds: limitations.map((decision) => task.decisions.find((entry) => entry.data === decision).id),
|
|
12038
|
+
reason: "an applicable approved limitation permits the missing evidence"
|
|
12039
|
+
};
|
|
12040
|
+
const unavailable = capabilities.some((capability) => capability.assurance === "unavailable" && (capability.name === requirement.dimension || capability.surface === requirement.dimension));
|
|
12041
|
+
if (!unavailable && related.length > 0 && !passed.length)
|
|
12042
|
+
return {
|
|
12043
|
+
requirementId: requirement.id,
|
|
12044
|
+
status: "unsatisfied",
|
|
12045
|
+
evidenceIds: related.map(({ entry }) => entry.id),
|
|
12046
|
+
decisionIds: [],
|
|
12047
|
+
reason: `no passing evidence (needs kind:${expectedKinds(requirement.dimension, requirement.ruleId)})`
|
|
12048
|
+
};
|
|
12049
|
+
return {
|
|
12050
|
+
requirementId: requirement.id,
|
|
12051
|
+
status: unavailable ? "unavailable" : "unsatisfied",
|
|
12052
|
+
evidenceIds: related.map(({ entry }) => entry.id),
|
|
12053
|
+
decisionIds: [],
|
|
12054
|
+
reason: unavailable ? "required capability is unavailable" : "no fresh passing evidence"
|
|
12055
|
+
};
|
|
12056
|
+
});
|
|
12057
|
+
}
|
|
12058
|
+
function evaluateClosure(requestedOutcome, view) {
|
|
12059
|
+
if (requestedOutcome !== "stopped" && !view.task.policy)
|
|
12060
|
+
return failure("requirements_unsatisfied", "task has not been assessed");
|
|
12061
|
+
if (view.task.policy && view.task.policy.policyVersion !== POLICY_VERSION)
|
|
12062
|
+
return failure("requirements_unsatisfied", "stored policy version is unsupported; reassessment is required");
|
|
12063
|
+
const evaluations = view.requirements;
|
|
12064
|
+
const openFindings = view.task.findings.filter((entry) => entry.data.disposition === "open");
|
|
12065
|
+
if (requestedOutcome !== "stopped" && openFindings.length)
|
|
12066
|
+
return failure("requirements_unsatisfied", "open findings must be resolved before closure");
|
|
12067
|
+
if (requestedOutcome !== "stopped") {
|
|
12068
|
+
const evidenceById = new Map(view.evidence.map((entry) => [entry.evidenceId, entry.status]));
|
|
12069
|
+
for (const entry of view.task.findings) {
|
|
12070
|
+
if (entry.data.disposition === "fixed") {
|
|
12071
|
+
const verified = entry.data.resolution?.evidenceIds.some((id) => {
|
|
12072
|
+
const evidence = view.task.evidence.find((item) => item.id === id);
|
|
12073
|
+
if (!evidence)
|
|
12074
|
+
return false;
|
|
12075
|
+
return findingVerificationPasses(entry.data.candidateId, {
|
|
12076
|
+
kind: evidence.data.kind,
|
|
12077
|
+
candidateId: evidence.data.candidateId,
|
|
12078
|
+
status: evidenceById.get(id) ?? "missing"
|
|
12079
|
+
});
|
|
12080
|
+
});
|
|
12081
|
+
if (!verified)
|
|
12082
|
+
return failure("requirements_unsatisfied", "fixed findings require current verification");
|
|
12083
|
+
}
|
|
12084
|
+
if (entry.data.disposition === "deferred") {
|
|
12085
|
+
const valid = entry.data.resolution?.decisionIds.some((id) => {
|
|
12086
|
+
const decisionEntry = view.task.decisions.find((item) => item.id === id);
|
|
12087
|
+
const decision = decisionEntry?.data;
|
|
12088
|
+
return Boolean(decision && decisionEntry?.provenance.kind !== "imported" && decision.purpose === "limitation" && decision.response === "approved" && decision.revoked === null && decision.digest === decisionDigest(decision) && verifyDecisionContentAtRoot(view.workspace.root, decision.binding).ok && decision.binding.taskId === view.task.id && decision.binding.workspaceId === view.workspace.id && scopeCovers2(decision.binding.scope, entry.data.scope) && decision.requirementIds.some((requirementId) => view.task.policy?.requirements.some((requirement) => requirement.id === requirementId && requirement.acceptanceAllowed)));
|
|
12089
|
+
});
|
|
12090
|
+
if (!valid)
|
|
12091
|
+
return failure("requirements_unsatisfied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
|
|
12092
|
+
}
|
|
12395
12093
|
}
|
|
12396
|
-
|
|
12397
|
-
|
|
12398
|
-
if (
|
|
12094
|
+
}
|
|
12095
|
+
const blocking = evaluations.filter((item) => {
|
|
12096
|
+
if (item.status !== "unsatisfied" && item.status !== "unavailable")
|
|
12399
12097
|
return false;
|
|
12400
|
-
|
|
12098
|
+
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
12099
|
+
return !requirement || requirement.before === "close";
|
|
12100
|
+
});
|
|
12101
|
+
if (requestedOutcome !== "stopped" && blocking.length)
|
|
12102
|
+
return failure("requirements_unsatisfied", "applicable requirements are unsatisfied", {
|
|
12103
|
+
requirementIds: blocking.map((item) => item.requirementId),
|
|
12104
|
+
requirements: blocking.map((item) => {
|
|
12105
|
+
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
12106
|
+
return {
|
|
12107
|
+
requirementId: item.requirementId,
|
|
12108
|
+
ruleId: requirement?.ruleId ?? "unknown",
|
|
12109
|
+
reason: item.reason,
|
|
12110
|
+
satisfaction: requirement?.satisfaction ?? "",
|
|
12111
|
+
dependentAction: requirement?.dependentAction ?? null
|
|
12112
|
+
};
|
|
12113
|
+
})
|
|
12114
|
+
});
|
|
12115
|
+
const accepted = evaluations.filter((item) => item.status === "accepted_limitation");
|
|
12116
|
+
if (requestedOutcome === "verified" && accepted.length)
|
|
12117
|
+
return failure("requirements_unsatisfied", "accepted limitations cannot be reported as verified", {
|
|
12118
|
+
requirementIds: accepted.map((item) => item.requirementId)
|
|
12119
|
+
});
|
|
12120
|
+
const evidenceIds = [
|
|
12121
|
+
...new Set([
|
|
12122
|
+
...evaluations.flatMap((item) => item.evidenceIds),
|
|
12123
|
+
...view.task.findings.flatMap((item) => item.data.resolution?.evidenceIds ?? [])
|
|
12124
|
+
])
|
|
12125
|
+
];
|
|
12126
|
+
const decisionIds = [
|
|
12127
|
+
...new Set([
|
|
12128
|
+
...evaluations.flatMap((item) => item.decisionIds),
|
|
12129
|
+
...view.task.findings.flatMap((item) => item.data.resolution?.decisionIds ?? [])
|
|
12130
|
+
])
|
|
12131
|
+
];
|
|
12132
|
+
return success(null, null, {
|
|
12133
|
+
outcome: requestedOutcome === "stopped" ? "stopped" : accepted.length ? "accepted_limitations" : "verified",
|
|
12134
|
+
evidenceIds,
|
|
12135
|
+
decisionIds,
|
|
12136
|
+
requirementIds: evaluations.map((item) => item.requirementId)
|
|
12137
|
+
});
|
|
12138
|
+
}
|
|
12139
|
+
var digestBytes3 = (value) => createHash6("sha256").update(value).digest("hex"), inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path10.sep}`), relative = (root, candidate) => path10.relative(root, candidate).split(path10.sep).join("/") || ".", canonicalPath = (value) => {
|
|
12140
|
+
if (typeof value !== "string" || !value)
|
|
12141
|
+
return null;
|
|
12142
|
+
if (value.includes("\\") || value.split("/").includes(".."))
|
|
12143
|
+
return null;
|
|
12144
|
+
const normalized = path10.posix.normalize(value);
|
|
12145
|
+
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
12146
|
+
return null;
|
|
12147
|
+
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
12148
|
+
}, canonicalScope = (scope) => {
|
|
12149
|
+
const paths = scope.paths.length ? scope.paths : ["."];
|
|
12150
|
+
const normalizedPaths = paths.map(canonicalPath);
|
|
12151
|
+
const normalizedExclusions = scope.exclusions.map(canonicalPath);
|
|
12152
|
+
if (normalizedPaths.some((value) => value === null) || normalizedExclusions.some((value) => value === null))
|
|
12153
|
+
return null;
|
|
12154
|
+
return {
|
|
12155
|
+
description: scope.description,
|
|
12156
|
+
paths: [...new Set(normalizedPaths)],
|
|
12157
|
+
exclusions: [...new Set(normalizedExclusions)]
|
|
12158
|
+
};
|
|
12159
|
+
}, excluded = (value, exclusions) => exclusions.some((item) => item === value || item !== "." && value.startsWith(`${item}/`)), scopeMatches = (value, scope) => {
|
|
12160
|
+
const normalized = canonicalScope(scope);
|
|
12161
|
+
if (!normalized)
|
|
12162
|
+
return false;
|
|
12163
|
+
const paths = normalized.paths;
|
|
12164
|
+
return paths.some((item) => item === "." || value === item || value.startsWith(`${item}/`)) && !excluded(value, normalized.exclusions);
|
|
12165
|
+
}, pathRelevant = (value, scope) => scopeMatches(value, scope), compareCodeUnits3 = (left, right) => {
|
|
12166
|
+
const length = Math.min(left.length, right.length);
|
|
12167
|
+
for (let index = 0;index < length; index += 1) {
|
|
12168
|
+
const difference = left.charCodeAt(index) - right.charCodeAt(index);
|
|
12169
|
+
if (difference !== 0)
|
|
12170
|
+
return difference;
|
|
12171
|
+
}
|
|
12172
|
+
return left.length - right.length;
|
|
12173
|
+
}, gitPaths = (root) => {
|
|
12174
|
+
const result = spawnSync2("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
|
|
12175
|
+
cwd: root,
|
|
12176
|
+
encoding: "buffer"
|
|
12177
|
+
});
|
|
12178
|
+
if (result.status !== 0) {
|
|
12179
|
+
const stderr = result.stderr?.toString("utf8") ?? "";
|
|
12180
|
+
return {
|
|
12181
|
+
paths: [],
|
|
12182
|
+
uncertain: !/not a git repository/i.test(stderr),
|
|
12183
|
+
git: /not a git repository/i.test(stderr) ? false : true
|
|
12184
|
+
};
|
|
12185
|
+
}
|
|
12186
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")) : [];
|
|
12187
|
+
const stagedDeleted = spawnSync2("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
12188
|
+
if (stagedDeleted.status !== 0) {
|
|
12189
|
+
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
12190
|
+
if (!/not a git repository/i.test(stderr))
|
|
12191
|
+
return { paths, uncertain: true, git: true };
|
|
12192
|
+
} else if (stagedDeleted.stdout) {
|
|
12193
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")));
|
|
12194
|
+
}
|
|
12195
|
+
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
12196
|
+
}, walk = (root, directory, output) => {
|
|
12197
|
+
let names;
|
|
12198
|
+
try {
|
|
12199
|
+
names = fs7.readdirSync(directory);
|
|
12200
|
+
} catch {
|
|
12201
|
+
return true;
|
|
12202
|
+
}
|
|
12203
|
+
let uncertain = false;
|
|
12204
|
+
for (const name of names) {
|
|
12205
|
+
if (name === ".git" || name === ".workit")
|
|
12206
|
+
continue;
|
|
12207
|
+
const target = path10.join(directory, name);
|
|
12208
|
+
let stat;
|
|
12209
|
+
try {
|
|
12210
|
+
stat = fs7.lstatSync(target);
|
|
12211
|
+
} catch {
|
|
12212
|
+
uncertain = true;
|
|
12213
|
+
continue;
|
|
12214
|
+
}
|
|
12215
|
+
const item = relative(root, target);
|
|
12216
|
+
output.add(item);
|
|
12217
|
+
if (stat.isDirectory() && !stat.isSymbolicLink())
|
|
12218
|
+
uncertain = walk(root, target, output) || uncertain;
|
|
12219
|
+
}
|
|
12220
|
+
return uncertain;
|
|
12221
|
+
}, scopeRoots = (root, scope) => {
|
|
12222
|
+
const roots = [];
|
|
12223
|
+
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
12224
|
+
const target = path10.resolve(root, item);
|
|
12225
|
+
if (!inside(root, target))
|
|
12226
|
+
return failure("invalid_input", `candidate scope escapes checkout: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} is outside the checkout` }] });
|
|
12227
|
+
let ancestor = target;
|
|
12228
|
+
while (!fs7.existsSync(ancestor) && ancestor !== root)
|
|
12229
|
+
ancestor = path10.dirname(ancestor);
|
|
12230
|
+
try {
|
|
12231
|
+
if (!inside(root, fs7.realpathSync(ancestor)))
|
|
12232
|
+
return failure("invalid_input", `candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] });
|
|
12233
|
+
} catch {
|
|
12234
|
+
return failure("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
12235
|
+
}
|
|
12236
|
+
roots.push(target);
|
|
12237
|
+
}
|
|
12238
|
+
return success(null, null, roots);
|
|
12239
|
+
}, fileMap = (candidate) => new Map(candidate.files.map((file) => [file.path, file])), changedPaths = (before, after) => {
|
|
12240
|
+
const paths = new Set([...before.files, ...after.files].map((file) => file.path));
|
|
12241
|
+
const left = fileMap(before);
|
|
12242
|
+
const right = fileMap(after);
|
|
12243
|
+
const changed = [...paths].filter((item) => JSON.stringify(left.get(item) ?? null) !== JSON.stringify(right.get(item) ?? null));
|
|
12244
|
+
if (before.head !== after.head)
|
|
12245
|
+
changed.push(".");
|
|
12246
|
+
if (JSON.stringify(before.environment) !== JSON.stringify(after.environment))
|
|
12247
|
+
changed.push(".");
|
|
12248
|
+
return changed;
|
|
12249
|
+
}, sessionFromRef = (value) => {
|
|
12250
|
+
if (typeof value !== "object" || value === null || value.kind !== "host")
|
|
12251
|
+
return null;
|
|
12252
|
+
return typeof value.host === "string" && typeof value.handle === "string" ? { host: value.host, handle: value.handle } : null;
|
|
12253
|
+
}, sameSession = (left, right) => {
|
|
12254
|
+
const other = sessionFromRef(right);
|
|
12255
|
+
return left !== null && other !== null && left.host === other.host && left.handle === other.handle;
|
|
12256
|
+
}, evidenceScopes = (task, ids) => (task.policy?.requirements ?? []).filter((requirement) => ids.includes(requirement.id)).map((requirement) => requirement.scope), scopeCovers2, checkPin = (assignment, beforeCandidateId, candidateId) => {
|
|
12257
|
+
const pin = assignment.candidateId ?? null;
|
|
12258
|
+
if (pin === null)
|
|
12401
12259
|
return true;
|
|
12260
|
+
return (beforeCandidateId ?? null) === pin || (candidateId ?? null) === pin;
|
|
12261
|
+
}, resolveBinding = (evidence, pin, currentCandidateId) => {
|
|
12262
|
+
const bound = evidence.kind === "check" || evidence.kind === "review";
|
|
12263
|
+
const fallback = bound ? pin ?? currentCandidateId : null;
|
|
12264
|
+
return {
|
|
12265
|
+
beforeCandidateId: evidence.beforeCandidateId ?? fallback,
|
|
12266
|
+
candidateId: evidence.candidateId ?? fallback
|
|
12267
|
+
};
|
|
12268
|
+
}, findingVerificationPasses = (findingCandidateId, evidence) => evidence.status === "passed" && (evidence.kind === "check" || evidence.kind === "review") && ((findingCandidateId ?? null) === null || evidence.candidateId != null), applicableDecision2 = (task, workspace, requirement, checkoutRoot) => task.decisions.filter((entry) => entry.provenance.kind !== "imported").map((entry) => entry.data).filter((decision) => decision.purpose === "limitation" && decision.response === "approved" && decision.revoked === null && decision.binding.taskId === task.id && decision.binding.workspaceId === workspace.id && decision.requirementIds.includes(requirement.id) && decision.binding.scope && scopeCovers2(decision.binding.scope, requirement.scope) && decision.digest === decisionDigest(decision) && (checkoutRoot ? verifyDecisionContentAtRoot(checkoutRoot, decision.binding).ok : decision.binding.contentRefs.every((reference) => reference.kind !== "file"))), applicableRequirementDecision = (task, workspace, requirement, checkoutRoot) => task.decisions.filter(({ data, provenance }) => provenance.kind !== "imported" && data.purpose !== "limitation" && (data.response === "approved" || data.response === "stated") && data.revoked === null && data.binding.taskId === task.id && data.binding.workspaceId === workspace.id && data.requirementIds.includes(requirement.id) && scopeCovers2(data.binding.scope, requirement.scope) && data.digest === decisionDigest(data) && (checkoutRoot ? verifyDecisionContentAtRoot(checkoutRoot, data.binding).ok : data.binding.contentRefs.every((reference) => reference.kind !== "file"))).map(({ id }) => ({ id })), evidenceMatchesRequirement = (kind, evidenceKind, dimension, ruleId) => {
|
|
12269
|
+
if (kind !== "passed")
|
|
12270
|
+
return false;
|
|
12271
|
+
if (dimension === "testing" || dimension === "verification")
|
|
12272
|
+
return evidenceKind === "check" || ruleId === "pre-pr-cleanup" && evidenceKind === "artifact";
|
|
12273
|
+
if (dimension === "review")
|
|
12274
|
+
return evidenceKind === "review";
|
|
12275
|
+
if (dimension === "investigation" || dimension === "challenge")
|
|
12276
|
+
return evidenceKind === "investigation";
|
|
12277
|
+
if (dimension === "artifacts" || dimension === "continuity")
|
|
12278
|
+
return evidenceKind === "artifact";
|
|
12279
|
+
return false;
|
|
12280
|
+
}, expectedKinds = (dimension, ruleId) => {
|
|
12281
|
+
if (dimension === "testing")
|
|
12282
|
+
return "check";
|
|
12283
|
+
if (dimension === "verification")
|
|
12284
|
+
return ruleId === "pre-pr-cleanup" ? "check or artifact" : "check";
|
|
12285
|
+
if (dimension === "review")
|
|
12286
|
+
return "review";
|
|
12287
|
+
if (dimension === "investigation" || dimension === "challenge")
|
|
12288
|
+
return "investigation";
|
|
12289
|
+
if (dimension === "artifacts" || dimension === "continuity")
|
|
12290
|
+
return "artifact";
|
|
12291
|
+
if (dimension === "decisions")
|
|
12292
|
+
return "decision";
|
|
12293
|
+
return "worker report";
|
|
12294
|
+
};
|
|
12295
|
+
var init_task_evaluation = __esm(() => {
|
|
12296
|
+
init_task_contract();
|
|
12297
|
+
init_authority();
|
|
12298
|
+
scopeCovers2 = scopeCovers;
|
|
12299
|
+
});
|
|
12300
|
+
|
|
12301
|
+
// packages/workit-core/src/core/methods.ts
|
|
12302
|
+
function selectMethods(policy, capabilities) {
|
|
12303
|
+
return Object.entries(METHODS).flatMap(([id, definition]) => {
|
|
12304
|
+
const requirements = policy.requirements.filter((requirement) => methodMatches(definition, requirement));
|
|
12305
|
+
if (requirements.length === 0)
|
|
12306
|
+
return [];
|
|
12307
|
+
const capability = assuranceFor(id, definition, capabilities);
|
|
12308
|
+
const reasons = [
|
|
12309
|
+
...new Set(requirements.map((requirement) => requirement.reason)),
|
|
12310
|
+
...capability.reasons
|
|
12311
|
+
];
|
|
12312
|
+
if (capability.assurance === "unavailable")
|
|
12313
|
+
reasons.unshift("required capability is unavailable");
|
|
12314
|
+
return [{ id, reason: reasons.join("; "), assurance: capability.assurance }];
|
|
12402
12315
|
});
|
|
12403
12316
|
}
|
|
12404
|
-
|
|
12405
|
-
const
|
|
12406
|
-
|
|
12407
|
-
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
|
|
12431
|
-
|
|
12432
|
-
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12317
|
+
var METHODS, methodMatches = (definition, requirement) => definition.dimensions?.includes(requirement.dimension) === true || definition.ruleIds?.includes(requirement.ruleId) === true, assuranceFor = (id, definition, capabilities) => {
|
|
12318
|
+
const keys = new Set([
|
|
12319
|
+
id,
|
|
12320
|
+
...definition.dimensions ?? [],
|
|
12321
|
+
...definition.ruleIds ?? []
|
|
12322
|
+
]);
|
|
12323
|
+
const matches = capabilities.filter((capability) => keys.has(capability.name) || keys.has(capability.surface));
|
|
12324
|
+
if (id === "workit-review" && matches.length === 0)
|
|
12325
|
+
return { assurance: "unavailable", reasons: ["independent review capability is unavailable"] };
|
|
12326
|
+
if (matches.some((capability) => capability.assurance === "unavailable"))
|
|
12327
|
+
return {
|
|
12328
|
+
assurance: "unavailable",
|
|
12329
|
+
reasons: matches.filter((capability) => capability.assurance === "unavailable").map((capability) => capability.reason)
|
|
12330
|
+
};
|
|
12331
|
+
if (matches.some((capability) => capability.assurance === "enforced"))
|
|
12332
|
+
return { assurance: "enforced", reasons: matches.map((capability) => capability.reason) };
|
|
12333
|
+
return { assurance: "agent_guided", reasons: matches.map((capability) => capability.reason) };
|
|
12334
|
+
}, invariantBootstrap = () => `
|
|
12335
|
+
Workit is optional coordination and repository-policy tooling around the host,
|
|
12336
|
+
not a permission system or a mandatory workflow. Native host allow/ask/deny,
|
|
12337
|
+
sandbox, plan/read-only mode, and organization rules remain authoritative.
|
|
12338
|
+
Ordinary investigation, questions, non-Git work, and routine reversible edits
|
|
12339
|
+
need zero Workit task, assessment, or writer calls. Use one compact tracked
|
|
12340
|
+
record only when handoff, dependent steps, concurrent actors, or meaningful
|
|
12341
|
+
decisions make continuity useful; similar titles alone never merge tasks.
|
|
12342
|
+
|
|
12343
|
+
For a routine user-authorized branch or commit, prefer native host Git/shell
|
|
12344
|
+
tools from the outset when managed coordination or outcome reconciliation is
|
|
12345
|
+
not needed. Inspect the actual target checkout and its configured conventions;
|
|
12346
|
+
use Workit's read-only context/policy tools when needed. Do not start a task,
|
|
12347
|
+
acquire a writer, or mint a decision receipt solely for a native Git action.
|
|
12348
|
+
Native permissions still apply. Never switch execution paths to evade a denial
|
|
12349
|
+
or repeat an uncertain managed effect. A local-commit endpoint does not imply
|
|
12350
|
+
PR readiness, a fresh review, or post-commit assessment/closure paperwork.
|
|
12351
|
+
|
|
12352
|
+
For tracked work, inspect its current state and use the shared operations for
|
|
12353
|
+
task, policy, evidence, finding, decision, worker, writer, and state changes.
|
|
12354
|
+
Start a record once for an explicit tracked objective; assess or reassess only
|
|
12355
|
+
when policy selection or changed evidence/constraints requires it. Omitted
|
|
12356
|
+
expectedRevision and expectedWorkspaceRevision use current values; explicit
|
|
12357
|
+
values are still concurrency-checked, so never copy revisions between calls.
|
|
12358
|
+
A solo edit does not need writer acquisition; use it when concurrent checkout
|
|
12359
|
+
writers need coordination. Record only observed facts and checks. Evidence can
|
|
12360
|
+
become stale when its bound candidate changes; reconcile findings against the
|
|
12361
|
+
current candidate before recording completion.
|
|
12362
|
+
|
|
12363
|
+
Workit validates domain policy against the actual action target, configured
|
|
12364
|
+
account, branch and commit conventions, protected refs, and current repository
|
|
12365
|
+
state. The task directory is coordination state, not a boundary on which
|
|
12366
|
+
repository may be changed. Use an action-time cwd target where a managed
|
|
12367
|
+
Git/hosting action supports it; a non-Git directory remains valid for OS work.
|
|
12368
|
+
GitHub/GitLab use the active gh/glab CLI identity; YouTrack uses its own token.
|
|
12369
|
+
Preserve uncertain external outcomes and reconcile repository/provider state
|
|
12370
|
+
before retrying. Internal reservations prevent duplicate or ambiguous effects;
|
|
12371
|
+
they are not permission tickets for every edit.
|
|
12372
|
+
|
|
12373
|
+
On OpenCode V1 and V2, use native host tools for external mutations. Workit
|
|
12374
|
+
provides read-only workit_context; it has no managed external-action executor.
|
|
12375
|
+
Do not create proposals or request Workit approvals merely to invoke native
|
|
12376
|
+
tools. Old uncertain managed effects still require evidence before any retry.
|
|
12377
|
+
|
|
12378
|
+
Use host-native authorization through the host's supported path. A native
|
|
12379
|
+
question receipt records an actual question interaction; it is not automatic
|
|
12380
|
+
host permission. Record a meaningful user choice once with provenance when
|
|
12381
|
+
future retrieval helps. Never fabricate a receipt, re-ask only to mint one, or
|
|
12382
|
+
let imported decisions grant authority. Never turn a host deny into allow or
|
|
12383
|
+
claim enforcement/evidence a host cannot provide. A precise request with settled
|
|
12384
|
+
constraints does not need an interview. Present genuine unresolved options with
|
|
12385
|
+
evidence and a recommendation, then continue toward the requested delivery
|
|
12386
|
+
endpoint: investigation, implementation, branch/commit/push, PR/MR-ready,
|
|
12387
|
+
merge, or release. Run
|
|
12388
|
+
applicable checks and safe repairs without repeated continuation questions;
|
|
12389
|
+
stop for missing host authority, a new consequential choice, a conflicting edit,
|
|
12390
|
+
or an unresolved blocker. A tracked record may close when actual evidence
|
|
12391
|
+
supports its outcome; no final human closure ceremony is required.
|
|
12392
|
+
|
|
12393
|
+
A completed native subagent run stops its bound worker by itself; if a worker
|
|
12394
|
+
strands in cancelling with its run verifiably over, repeat worker.cancel to
|
|
12395
|
+
confirm the stop. Preserve unresolved requirements, gaps, and uncertain workers.
|
|
12396
|
+
When context changes, distinguish a quick question, same-task adjustment, and
|
|
12397
|
+
separate request. Answer a quick question without pausing/resuming task state;
|
|
12398
|
+
park a concise checkpoint only when substantial work needs to continue later.
|
|
12399
|
+
For work spanning repositories, bind each unfinished item to its actual checkout,
|
|
12400
|
+
branch, requested deliverables, and delivery endpoint. Preserve held items with
|
|
12401
|
+
an explicit resume condition. Resolve competing plausible targets before a
|
|
12402
|
+
mutation; ask only when available context cannot settle that consequential choice.
|
|
12403
|
+
Before reporting delivery, reconcile every requested item and observe the actual
|
|
12404
|
+
target result; a local commit alone is not evidence of a requested remote push.
|
|
12405
|
+
|
|
12406
|
+
Skill routing: slash aliases /wk-* load on demand. Use workit-steer for a
|
|
12407
|
+
substantial interruption or change of direction, workit-deslop when relevant
|
|
12408
|
+
to a PR-ready endpoint, workit-green-run for failing CI, workit-blast-radius
|
|
12409
|
+
when impact is uncertain, and workit-challenge for genuinely open consequential
|
|
12410
|
+
choices. Load workit-plan when dependencies or handoff need durable next actions.
|
|
12411
|
+
Load the skill; never act from memory of it.
|
|
12412
|
+
`.trim();
|
|
12413
|
+
var init_methods = __esm(() => {
|
|
12414
|
+
METHODS = {
|
|
12415
|
+
"workit-challenge": { dimensions: ["challenge", "decisions"] },
|
|
12416
|
+
"workit-behavioral-tdd": { dimensions: ["testing"], ruleIds: ["mechanical-existing-checks"] },
|
|
12417
|
+
"workit-review": { dimensions: ["review"], ruleIds: ["fresh-context-review", "self-review"] },
|
|
12418
|
+
"workit-plan": { dimensions: ["artifacts", "continuity"] },
|
|
12419
|
+
"workit-implement": { dimensions: ["delegation"] },
|
|
12420
|
+
"workit-debug": {},
|
|
12421
|
+
"workit-handoff": {},
|
|
12422
|
+
"workit-deslop": { ruleIds: ["pre-pr-cleanup"] }
|
|
12439
12423
|
};
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
const
|
|
12447
|
-
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
})))
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
}
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12424
|
+
});
|
|
12425
|
+
|
|
12426
|
+
// packages/workit-core/src/core/task-context.ts
|
|
12427
|
+
function reconcileResume(view, observations = []) {
|
|
12428
|
+
if (observations.length > 0)
|
|
12429
|
+
return failure("permission_denied", "worker observations require native host verification");
|
|
12430
|
+
const candidate = captureCandidate(view.workspace.root, view.task.intent.data.scope, []);
|
|
12431
|
+
if (!candidate.ok)
|
|
12432
|
+
return candidate;
|
|
12433
|
+
const staleEvidenceIds = evaluateEvidence(view.task, candidate.data).filter((entry) => entry.status === "stale").map((entry) => entry.evidenceId);
|
|
12434
|
+
const blockers = [...view.task.progress.blockers];
|
|
12435
|
+
if (view.task.workers.some((entry) => isUncertainWorker(entry.data.state)))
|
|
12436
|
+
blockers.push({
|
|
12437
|
+
reason: "worker state requires reconciliation",
|
|
12438
|
+
dependentAction: "resume",
|
|
12439
|
+
refs: []
|
|
12440
|
+
});
|
|
12441
|
+
return success(null, null, {
|
|
12442
|
+
candidate: candidate.data,
|
|
12443
|
+
staleEvidenceIds,
|
|
12444
|
+
workerUpdates: [],
|
|
12445
|
+
blockers,
|
|
12446
|
+
reassessmentRequired: view.task.policy?.policyVersion !== POLICY_VERSION
|
|
12447
|
+
});
|
|
12448
|
+
}
|
|
12449
|
+
function compactTaskContext(view) {
|
|
12450
|
+
const decisions = view.task.decisions.slice().sort((left, right) => {
|
|
12451
|
+
const leftAt = compactTimestamp(left.recordedAt);
|
|
12452
|
+
const rightAt = compactTimestamp(right.recordedAt);
|
|
12453
|
+
if (leftAt !== rightAt)
|
|
12454
|
+
return leftAt > rightAt ? -1 : 1;
|
|
12455
|
+
return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
|
|
12456
|
+
}).slice(0, COMPACT_MAX_ITEMS).map((entry) => ({
|
|
12457
|
+
id: entry.id,
|
|
12458
|
+
purpose: entry.data.purpose,
|
|
12459
|
+
status: entry.data.response,
|
|
12460
|
+
digest: entry.data.digest,
|
|
12461
|
+
choice: compactDecisionChoice(entry) || `task.inspect taskId=${view.task.id} view=full; decision=${entry.id}`,
|
|
12462
|
+
references: entry.data.binding.contentRefs.slice(0, 1).map(compactReference)
|
|
12463
|
+
}));
|
|
12464
|
+
const methods = view.task.policy ? selectMethods(view.task.policy, view.capabilities).map((method) => ({
|
|
12465
|
+
id: method.id,
|
|
12466
|
+
assurance: method.assurance,
|
|
12467
|
+
reason: compactText(method.reason, COMPACT_TEXT_BYTES) ?? ""
|
|
12468
|
+
})) : [];
|
|
12469
|
+
const gaps = Array.from(new Set([
|
|
12470
|
+
...view.evidence.filter((entry) => entry.status === "stale").map((entry) => `stale evidence: ${entry.evidenceId}`),
|
|
12471
|
+
...view.requirements.filter((entry) => entry.status !== "satisfied").map((entry) => entry.reason),
|
|
12472
|
+
...view.task.progress.blockers.map((entry) => entry.reason)
|
|
12473
|
+
])).sort().slice(0, COMPACT_MAX_ITEMS).map((gap) => compactText(gap, COMPACT_TEXT_BYTES));
|
|
12474
|
+
const context = {
|
|
12475
|
+
objective: compactText(view.task.intent.data.objective, COMPACT_TEXT_BYTES) ?? "",
|
|
12476
|
+
status: view.task.status,
|
|
12477
|
+
decisions,
|
|
12478
|
+
methods,
|
|
12479
|
+
gaps,
|
|
12480
|
+
nextAction: compactText(view.task.progress.nextAction, COMPACT_TEXT_BYTES)
|
|
12481
|
+
};
|
|
12482
|
+
let encoded = JSON.stringify(context);
|
|
12483
|
+
while (compactBytes(encoded) > COMPACT_MAX_BYTES && (context.decisions.length || context.methods.length || context.gaps.length)) {
|
|
12484
|
+
if (context.gaps.length)
|
|
12485
|
+
context.gaps.pop();
|
|
12486
|
+
else if (context.decisions.length)
|
|
12487
|
+
context.decisions.pop();
|
|
12488
|
+
else
|
|
12489
|
+
context.methods.pop();
|
|
12490
|
+
encoded = JSON.stringify(context);
|
|
12491
|
+
}
|
|
12492
|
+
if (compactBytes(encoded) > COMPACT_MAX_BYTES) {
|
|
12493
|
+
context.objective = compactText(context.objective, 64) ?? "";
|
|
12494
|
+
context.nextAction = compactText(context.nextAction, 64);
|
|
12495
|
+
encoded = JSON.stringify(context);
|
|
12496
|
+
}
|
|
12497
|
+
return encoded;
|
|
12498
|
+
}
|
|
12499
|
+
var COMPACT_MAX_BYTES = 4096, COMPACT_MAX_ITEMS = 8, COMPACT_TEXT_BYTES = 128, sensitiveUrl, sensitiveValue, privateKey, compactText = (value, limit) => value === null ? null : value.replace(privateKey, "<redacted-private-key>").replace(sensitiveUrl, "<redacted-url>").replace(sensitiveValue, (match) => {
|
|
12500
|
+
const separator = match.search(/[:=]/u);
|
|
12501
|
+
if (separator >= 0)
|
|
12502
|
+
return `${match.slice(0, separator)}=<redacted>`;
|
|
12503
|
+
const space = match.search(/\s/u);
|
|
12504
|
+
return `${match.slice(0, space)} <redacted>`;
|
|
12505
|
+
}).slice(0, limit), compactBytes = (value) => new TextEncoder().encode(value).byteLength, compactTimestamp = (value) => `${value.slice(0, 19)}.${value.slice(20, -1).padEnd(9, "0")}`, compactDecisionChoice = (entry) => {
|
|
12506
|
+
const stated = entry.data.binding.statedChoice?.text;
|
|
12507
|
+
const approved = entry.data.response === "approved" ? entry.data.binding.approvedContent : "";
|
|
12508
|
+
const source = stated?.trim() || approved.trim() || null;
|
|
12509
|
+
return compactText(source, COMPACT_TEXT_BYTES);
|
|
12510
|
+
}, compactReference = (ref) => {
|
|
12511
|
+
if (ref.kind === "file")
|
|
12512
|
+
return {
|
|
12513
|
+
kind: "file",
|
|
12514
|
+
path: compactText(ref.path, COMPACT_TEXT_BYTES) ?? ""
|
|
12515
|
+
};
|
|
12516
|
+
if (ref.kind === "record")
|
|
12517
|
+
return {
|
|
12518
|
+
kind: "record",
|
|
12519
|
+
collection: ref.collection,
|
|
12520
|
+
id: ref.id
|
|
12521
|
+
};
|
|
12522
|
+
return { kind: ref.kind };
|
|
12523
|
+
}, exportDigest = (bundle) => sha256({
|
|
12524
|
+
schemaVersion: bundle.schemaVersion,
|
|
12525
|
+
exportedAt: bundle.exportedAt,
|
|
12526
|
+
sourceWorkspaceId: bundle.sourceWorkspaceId,
|
|
12527
|
+
task: bundle.task
|
|
12528
|
+
});
|
|
12529
|
+
var init_task_context = __esm(() => {
|
|
12530
|
+
init_workers();
|
|
12526
12531
|
init_task_contract();
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
decisions: array(decisionSchema),
|
|
12533
|
-
findings: array(findingSchema),
|
|
12534
|
-
requirements: array(requirementSchema)
|
|
12535
|
-
}).strict(),
|
|
12536
|
-
preferences: object({ fast: boolean2().optional(), thorough: boolean2().optional() }).strict().optional()
|
|
12537
|
-
}).strict();
|
|
12532
|
+
init_task_evaluation();
|
|
12533
|
+
init_methods();
|
|
12534
|
+
sensitiveUrl = /\bhttps?:\/\/[^/\s:@]+:[^@\s]+@/gi;
|
|
12535
|
+
sensitiveValue = /(?:token|secret|password|passwd|api[-_ ]?key|private[-_ ]?key|authorization)\s*[:=]\s*(?:bearer\s+)?\S+|\bbearer\s+\S+/gi;
|
|
12536
|
+
privateKey = /-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi;
|
|
12538
12537
|
});
|
|
12539
12538
|
|
|
12540
12539
|
// packages/workit-core/src/core/task-engine.ts
|
|
@@ -13840,14 +13839,29 @@ class WorkitCore {
|
|
|
13840
13839
|
writer: evaluationWorkspace.writer
|
|
13841
13840
|
});
|
|
13842
13841
|
}
|
|
13843
|
-
|
|
13842
|
+
compactContext(taskId) {
|
|
13843
|
+
const root = this.contextRootError();
|
|
13844
|
+
if (!root.ok)
|
|
13845
|
+
return root;
|
|
13846
|
+
const task = this.store.readTask(taskId);
|
|
13847
|
+
if (!task.ok)
|
|
13848
|
+
return task;
|
|
13849
|
+
const helper = this.helperTaskGuard(task.data, true);
|
|
13850
|
+
if (!helper.ok)
|
|
13851
|
+
return helper;
|
|
13852
|
+
const view = this.view(task.data, false);
|
|
13853
|
+
if (!view.ok)
|
|
13854
|
+
return view;
|
|
13855
|
+
return success(view.revision, view.workspaceRevision, compactTaskContext(view.data));
|
|
13856
|
+
}
|
|
13857
|
+
view(task, capture = true) {
|
|
13844
13858
|
const workspace = this.store.readWorkspace();
|
|
13845
13859
|
if (!workspace.ok)
|
|
13846
13860
|
return workspace;
|
|
13847
13861
|
if (!workspace.data)
|
|
13848
13862
|
return failure("not_found", "workspace not found");
|
|
13849
13863
|
const historical = task.status === "closed" ? task.candidates.at(-1) : undefined;
|
|
13850
|
-
const current = historical ? success(null, null, historical) : captureCandidate(this.store.root, task.intent.data.scope, environment());
|
|
13864
|
+
const current = historical ? success(null, null, historical) : capture ? captureCandidate(this.store.root, task.intent.data.scope, environment()) : success(null, null, task.candidates.at(-1) ?? null);
|
|
13851
13865
|
if (!current.ok)
|
|
13852
13866
|
return current;
|
|
13853
13867
|
const evaluationWorkspace = task.status === "closed" ? { ...workspace.data, writer: null } : workspace.data;
|
|
@@ -14493,10 +14507,149 @@ var init_task_engine = __esm(() => {
|
|
|
14493
14507
|
dispatchReservations = new WeakMap;
|
|
14494
14508
|
});
|
|
14495
14509
|
|
|
14510
|
+
// packages/workit-core/src/core/session-context.ts
|
|
14511
|
+
var cache;
|
|
14512
|
+
var init_session_context = __esm(() => {
|
|
14513
|
+
init_task_contract();
|
|
14514
|
+
init_task_engine();
|
|
14515
|
+
init_task_store();
|
|
14516
|
+
cache = new Map;
|
|
14517
|
+
});
|
|
14518
|
+
|
|
14519
|
+
// packages/workit-core/src/core/route-intent.ts
|
|
14520
|
+
var init_route_intent = __esm(() => {
|
|
14521
|
+
init_branch();
|
|
14522
|
+
});
|
|
14523
|
+
|
|
14524
|
+
// packages/workit-core/src/core/runtime-identity.ts
|
|
14525
|
+
var init_runtime_identity = () => {};
|
|
14526
|
+
|
|
14527
|
+
// packages/workit-core/src/core/external-action.ts
|
|
14528
|
+
var chainStepSchema, externalActionSchema;
|
|
14529
|
+
var init_external_action = __esm(() => {
|
|
14530
|
+
init_task_contract();
|
|
14531
|
+
init_task_store();
|
|
14532
|
+
init_authority();
|
|
14533
|
+
init_zod();
|
|
14534
|
+
chainStepSchema = union([
|
|
14535
|
+
string2().min(1),
|
|
14536
|
+
object({ branch: string2().min(1) }).strict(),
|
|
14537
|
+
object({ pr: literal(true) }).strict()
|
|
14538
|
+
]);
|
|
14539
|
+
externalActionSchema = discriminatedUnion("operation", [
|
|
14540
|
+
object({
|
|
14541
|
+
operation: literal("git.branch_setup"),
|
|
14542
|
+
payload: object({
|
|
14543
|
+
action: _enum(["setup", "reapply_stash"]).optional(),
|
|
14544
|
+
sdd_dir: string2().optional(),
|
|
14545
|
+
target_branch: string2().optional(),
|
|
14546
|
+
stash: _enum(["yes", "no"]).optional(),
|
|
14547
|
+
cwd: string2().min(1).optional()
|
|
14548
|
+
}).strict()
|
|
14549
|
+
}).strict(),
|
|
14550
|
+
object({
|
|
14551
|
+
operation: literal("git.commit"),
|
|
14552
|
+
payload: object({
|
|
14553
|
+
message: string2().min(1).optional(),
|
|
14554
|
+
plan_steps: array(chainStepSchema).min(1).max(32).optional(),
|
|
14555
|
+
plan_branch: string2().min(1).optional(),
|
|
14556
|
+
cwd: string2().min(1).optional()
|
|
14557
|
+
}).strict()
|
|
14558
|
+
}).strict(),
|
|
14559
|
+
object({
|
|
14560
|
+
operation: literal("git.push"),
|
|
14561
|
+
payload: object({ branch: string2().min(1).optional(), cwd: string2().min(1).optional() }).strict()
|
|
14562
|
+
}).strict(),
|
|
14563
|
+
object({
|
|
14564
|
+
operation: literal("hosting.pull_request"),
|
|
14565
|
+
payload: object({
|
|
14566
|
+
title: string2().min(1),
|
|
14567
|
+
body: string2().optional(),
|
|
14568
|
+
draft: boolean2().optional(),
|
|
14569
|
+
target_branch: string2().optional(),
|
|
14570
|
+
babysit: boolean2().optional(),
|
|
14571
|
+
cwd: string2().min(1).optional()
|
|
14572
|
+
}).strict()
|
|
14573
|
+
}).strict(),
|
|
14574
|
+
object({
|
|
14575
|
+
operation: literal("hosting.merge"),
|
|
14576
|
+
payload: object({
|
|
14577
|
+
target_branch: string2().min(1).optional(),
|
|
14578
|
+
source_branch: string2().min(1).optional(),
|
|
14579
|
+
cwd: string2().min(1).optional()
|
|
14580
|
+
}).strict()
|
|
14581
|
+
}).strict(),
|
|
14582
|
+
object({
|
|
14583
|
+
operation: literal("hosting.delete_branch"),
|
|
14584
|
+
payload: object({ branch: string2().min(1), cwd: string2().min(1).optional() }).strict()
|
|
14585
|
+
}).strict(),
|
|
14586
|
+
object({
|
|
14587
|
+
operation: literal("youtrack.update"),
|
|
14588
|
+
payload: object({
|
|
14589
|
+
issueId: string2().min(1),
|
|
14590
|
+
markdown: string2().min(1),
|
|
14591
|
+
minutes: number2().positive().optional()
|
|
14592
|
+
}).strict()
|
|
14593
|
+
}).strict(),
|
|
14594
|
+
object({
|
|
14595
|
+
operation: literal("youtrack.time"),
|
|
14596
|
+
payload: object({
|
|
14597
|
+
issueId: string2().min(1),
|
|
14598
|
+
minutes: number2().positive(),
|
|
14599
|
+
text: string2().optional(),
|
|
14600
|
+
dateMs: number2().finite().optional()
|
|
14601
|
+
}).strict()
|
|
14602
|
+
}).strict(),
|
|
14603
|
+
object({
|
|
14604
|
+
operation: literal("youtrack.meeting"),
|
|
14605
|
+
payload: object({
|
|
14606
|
+
issueId: string2().min(1),
|
|
14607
|
+
minutes: number2().positive(),
|
|
14608
|
+
text: string2().min(1)
|
|
14609
|
+
}).strict()
|
|
14610
|
+
}).strict(),
|
|
14611
|
+
object({
|
|
14612
|
+
operation: literal("changelog.apply"),
|
|
14613
|
+
payload: object({
|
|
14614
|
+
entries: union([
|
|
14615
|
+
record(string2(), array(string2())),
|
|
14616
|
+
array(object({ category: string2().min(1), text: string2().min(1) }).strict())
|
|
14617
|
+
]).optional(),
|
|
14618
|
+
path: string2().optional(),
|
|
14619
|
+
normalize_only: boolean2().optional()
|
|
14620
|
+
}).strict()
|
|
14621
|
+
}).strict(),
|
|
14622
|
+
object({
|
|
14623
|
+
operation: literal("context.read"),
|
|
14624
|
+
payload: object({
|
|
14625
|
+
kind: _enum([
|
|
14626
|
+
"git",
|
|
14627
|
+
"pr",
|
|
14628
|
+
"youtrack",
|
|
14629
|
+
"github_issue",
|
|
14630
|
+
"gitlab_issue",
|
|
14631
|
+
"changelog",
|
|
14632
|
+
"release",
|
|
14633
|
+
"affected"
|
|
14634
|
+
]),
|
|
14635
|
+
range: string2().optional(),
|
|
14636
|
+
issueId: string2().optional(),
|
|
14637
|
+
issueUrl: string2().optional(),
|
|
14638
|
+
issueRef: string2().optional(),
|
|
14639
|
+
mode: string2().optional(),
|
|
14640
|
+
specPath: string2().optional(),
|
|
14641
|
+
planPath: string2().optional(),
|
|
14642
|
+
cwd: string2().min(1).optional()
|
|
14643
|
+
}).strict()
|
|
14644
|
+
}).strict()
|
|
14645
|
+
]);
|
|
14646
|
+
});
|
|
14647
|
+
|
|
14496
14648
|
// packages/workit-core/src/core.ts
|
|
14497
14649
|
var init_core3 = __esm(() => {
|
|
14498
14650
|
init_task_contract();
|
|
14499
14651
|
init_task_store();
|
|
14652
|
+
init_session_context();
|
|
14500
14653
|
init_task_context();
|
|
14501
14654
|
init_methods();
|
|
14502
14655
|
init_route_intent();
|
|
@@ -14627,7 +14780,7 @@ var hostRef = (handle) => ({ kind: "host", host: "cursor", handle }), cursorCapa
|
|
|
14627
14780
|
reason: tasks.length ? "task state is ambiguous" : "no active task"
|
|
14628
14781
|
};
|
|
14629
14782
|
return { ok: true, workspace: workspace.data, task: tasks[0] };
|
|
14630
|
-
}, historyOfferSessions,
|
|
14783
|
+
}, historyOfferSessions, unfinishedTaskOffer2 = (root, session, excludedTaskId) => {
|
|
14631
14784
|
try {
|
|
14632
14785
|
const listed = new TaskStore(root).listTasks();
|
|
14633
14786
|
if (!listed.ok)
|
|
@@ -14731,18 +14884,13 @@ ${tasks.map((task) => `- ${task.id} [${task.status}; source ${task.intent.proven
|
|
|
14731
14884
|
let compact = "";
|
|
14732
14885
|
const store = new TaskStore(root);
|
|
14733
14886
|
const state = activeTask(store);
|
|
14734
|
-
const offer = historyOfferSessions.has(actor) ? null :
|
|
14887
|
+
const offer = historyOfferSessions.has(actor) ? null : unfinishedTaskOffer2(root, actor, state.ok ? state.task.id : undefined);
|
|
14735
14888
|
historyOfferSessions.add(actor);
|
|
14736
14889
|
if (state.ok) {
|
|
14737
|
-
const
|
|
14738
|
-
|
|
14739
|
-
action: "inspect",
|
|
14740
|
-
taskId: state.task.id,
|
|
14741
|
-
view: "full"
|
|
14742
|
-
});
|
|
14743
|
-
if (view.ok)
|
|
14890
|
+
const context = new WorkitCore(store, contextFor(root, actor, null, { sessionStart: true })).compactContext(state.task.id);
|
|
14891
|
+
if (context.ok)
|
|
14744
14892
|
compact = `
|
|
14745
|
-
<workit-task-context>${
|
|
14893
|
+
<workit-task-context>${context.data}</workit-task-context>`;
|
|
14746
14894
|
}
|
|
14747
14895
|
return {
|
|
14748
14896
|
additional_context: `<workit-contract>
|