@brainervirus/workit-codex 2.1.0 → 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/.codex-plugin/plugin.json +1 -1
- package/dist/launch-mcp.js +1283 -1001
- package/dist/workit-hook.js +1372 -1226
- package/package.json +3 -3
package/dist/launch-mcp.js
CHANGED
|
@@ -15731,6 +15731,45 @@ var metadataLockSchema = object({
|
|
|
15731
15731
|
nonce: string2().min(1),
|
|
15732
15732
|
externalAction: literal(true).optional()
|
|
15733
15733
|
}).strict();
|
|
15734
|
+
var INDEX_VERSION = 1;
|
|
15735
|
+
var hostSession = (value) => isObject2(value) && value.kind === "host" && typeof value.host === "string" && typeof value.handle === "string" ? { host: value.host, handle: value.handle } : null;
|
|
15736
|
+
var indexEntry = (task, file) => {
|
|
15737
|
+
const sessions = [];
|
|
15738
|
+
const intent = hostSession(task.intent.provenance.session);
|
|
15739
|
+
if (intent)
|
|
15740
|
+
sessions.push({ ...intent, workerId: null });
|
|
15741
|
+
for (const worker of task.workers) {
|
|
15742
|
+
const session = hostSession(worker.data.session);
|
|
15743
|
+
if (session)
|
|
15744
|
+
sessions.push({ ...session, workerId: worker.id });
|
|
15745
|
+
}
|
|
15746
|
+
return {
|
|
15747
|
+
id: task.id,
|
|
15748
|
+
revision: task.revision,
|
|
15749
|
+
status: task.status,
|
|
15750
|
+
createdAt: task.createdAt,
|
|
15751
|
+
updatedAt: task.updatedAt,
|
|
15752
|
+
objective: task.intent.data.objective,
|
|
15753
|
+
source: { host: task.intent.provenance.host, kind: task.intent.provenance.kind },
|
|
15754
|
+
progress: { summary: task.progress.summary, nextAction: task.progress.nextAction },
|
|
15755
|
+
sessions,
|
|
15756
|
+
file
|
|
15757
|
+
};
|
|
15758
|
+
};
|
|
15759
|
+
var fileSignature = (file) => {
|
|
15760
|
+
try {
|
|
15761
|
+
const stat = fs4.statSync(file, { bigint: true });
|
|
15762
|
+
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
15763
|
+
} catch {
|
|
15764
|
+
return null;
|
|
15765
|
+
}
|
|
15766
|
+
};
|
|
15767
|
+
var RACY_WINDOW_NS = 2000000000n;
|
|
15768
|
+
var racySignature = (signature) => {
|
|
15769
|
+
const [mtime = 0n, ctime = 0n] = signature.split(":").slice(3, 5).map(BigInt);
|
|
15770
|
+
const changed = mtime > ctime ? mtime : ctime;
|
|
15771
|
+
return BigInt(Date.now()) * 1000000n - changed < RACY_WINDOW_NS;
|
|
15772
|
+
};
|
|
15734
15773
|
var now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
15735
15774
|
var cachedRuntimeVersion = null;
|
|
15736
15775
|
var runtimeVersion = () => {
|
|
@@ -15859,6 +15898,57 @@ class TaskStore {
|
|
|
15859
15898
|
}
|
|
15860
15899
|
return success(null, null, tasks);
|
|
15861
15900
|
}
|
|
15901
|
+
listTaskIndex() {
|
|
15902
|
+
if (!fs4.existsSync(this.tasksDir))
|
|
15903
|
+
return success(null, null, []);
|
|
15904
|
+
let names;
|
|
15905
|
+
try {
|
|
15906
|
+
names = fs4.readdirSync(this.tasksDir).filter((name) => name.endsWith(".json"));
|
|
15907
|
+
} catch (error) {
|
|
15908
|
+
return failure("storage_error", `unable to list tasks: ${String(error)}`, {
|
|
15909
|
+
path: this.tasksDir
|
|
15910
|
+
});
|
|
15911
|
+
}
|
|
15912
|
+
const workspace = this.readWorkspace();
|
|
15913
|
+
if (!workspace.ok)
|
|
15914
|
+
return workspace;
|
|
15915
|
+
if (!workspace.data)
|
|
15916
|
+
return failure("recovery_required", "task workspace binding is invalid", {
|
|
15917
|
+
path: this.workspacePath
|
|
15918
|
+
});
|
|
15919
|
+
const stored = this.readIndex(workspace.data.id);
|
|
15920
|
+
const entries = [];
|
|
15921
|
+
let changed = Object.keys(stored).length !== names.length;
|
|
15922
|
+
for (const name of names.sort()) {
|
|
15923
|
+
const file = path4.join(this.tasksDir, name);
|
|
15924
|
+
const signature = fileSignature(file);
|
|
15925
|
+
if (signature === null) {
|
|
15926
|
+
changed = true;
|
|
15927
|
+
continue;
|
|
15928
|
+
}
|
|
15929
|
+
const cached = stored[name.slice(0, -5)];
|
|
15930
|
+
if (cached && cached.file === signature && !racySignature(signature)) {
|
|
15931
|
+
entries.push(cached);
|
|
15932
|
+
continue;
|
|
15933
|
+
}
|
|
15934
|
+
const item = this.readRecord(file, taskRecordSchema);
|
|
15935
|
+
if (!item.exists)
|
|
15936
|
+
continue;
|
|
15937
|
+
if (!item.result.ok)
|
|
15938
|
+
return item.result;
|
|
15939
|
+
if (!validId(name.slice(0, -5)) || item.result.data.id !== name.slice(0, -5))
|
|
15940
|
+
return failure("recovery_required", "task filename and record ID differ", { path: name });
|
|
15941
|
+
if (item.result.data.workspaceId !== workspace.data.id)
|
|
15942
|
+
return failure("recovery_required", "task workspace binding is invalid", { path: name });
|
|
15943
|
+
const entry = indexEntry(item.result.data, signature);
|
|
15944
|
+
if (!cached || canonicalJson(cached) !== canonicalJson(entry))
|
|
15945
|
+
changed = true;
|
|
15946
|
+
entries.push(entry);
|
|
15947
|
+
}
|
|
15948
|
+
if (changed)
|
|
15949
|
+
this.writeIndex(workspace.data.id, entries);
|
|
15950
|
+
return success(null, null, entries);
|
|
15951
|
+
}
|
|
15862
15952
|
readWorkspace() {
|
|
15863
15953
|
const item = this.readRecord(this.workspacePath, workspaceRecordSchema);
|
|
15864
15954
|
if (!item.exists)
|
|
@@ -16538,6 +16628,8 @@ class TaskStore {
|
|
|
16538
16628
|
fs4.renameSync(temporary, file);
|
|
16539
16629
|
temporary = undefined;
|
|
16540
16630
|
this.fsyncDirectory(path4.dirname(file));
|
|
16631
|
+
if (path4.dirname(file) === this.tasksDir)
|
|
16632
|
+
this.indexTaskWrite(file, value);
|
|
16541
16633
|
return success(null, null, value);
|
|
16542
16634
|
} catch (error) {
|
|
16543
16635
|
return failure("storage_error", `snapshot replacement failed: ${String(error)}`, {
|
|
@@ -16550,6 +16642,45 @@ class TaskStore {
|
|
|
16550
16642
|
} catch {}
|
|
16551
16643
|
}
|
|
16552
16644
|
}
|
|
16645
|
+
readIndex(workspaceId) {
|
|
16646
|
+
try {
|
|
16647
|
+
const value = JSON.parse(fs4.readFileSync(this.indexPath, "utf8"));
|
|
16648
|
+
if (!isObject2(value) || value.version !== INDEX_VERSION || value.workspaceId !== workspaceId || !isObject2(value.tasks))
|
|
16649
|
+
return {};
|
|
16650
|
+
const tasks = {};
|
|
16651
|
+
for (const [id, entry] of Object.entries(value.tasks))
|
|
16652
|
+
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))
|
|
16653
|
+
tasks[id] = entry;
|
|
16654
|
+
return tasks;
|
|
16655
|
+
} catch {
|
|
16656
|
+
return {};
|
|
16657
|
+
}
|
|
16658
|
+
}
|
|
16659
|
+
writeIndex(workspaceId, entries) {
|
|
16660
|
+
const temporary = `${this.indexPath}.${process.pid}.${randomUUID2()}.tmp`;
|
|
16661
|
+
try {
|
|
16662
|
+
fs4.writeFileSync(temporary, JSON.stringify({
|
|
16663
|
+
version: INDEX_VERSION,
|
|
16664
|
+
workspaceId,
|
|
16665
|
+
tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
|
|
16666
|
+
}), { mode: 384, flag: "wx" });
|
|
16667
|
+
fs4.renameSync(temporary, this.indexPath);
|
|
16668
|
+
} catch {
|
|
16669
|
+
try {
|
|
16670
|
+
fs4.unlinkSync(temporary);
|
|
16671
|
+
} catch {}
|
|
16672
|
+
}
|
|
16673
|
+
}
|
|
16674
|
+
indexTaskWrite(file, task) {
|
|
16675
|
+
try {
|
|
16676
|
+
const signature = fileSignature(file);
|
|
16677
|
+
if (signature === null)
|
|
16678
|
+
return;
|
|
16679
|
+
const tasks = this.readIndex(task.workspaceId);
|
|
16680
|
+
tasks[task.id] = indexEntry(task, signature);
|
|
16681
|
+
this.writeIndex(task.workspaceId, Object.values(tasks));
|
|
16682
|
+
} catch {}
|
|
16683
|
+
}
|
|
16553
16684
|
saveRecovery(file, bytes) {
|
|
16554
16685
|
const target = path4.basename(file) === "workspace.json" ? "workspace" : "task";
|
|
16555
16686
|
const id = target === "task" ? path4.basename(file, ".json") : "workspace";
|
|
@@ -16708,6 +16839,9 @@ class TaskStore {
|
|
|
16708
16839
|
get workspacePath() {
|
|
16709
16840
|
return path4.join(this.workitDir, "workspace.json");
|
|
16710
16841
|
}
|
|
16842
|
+
get indexPath() {
|
|
16843
|
+
return path4.join(this.workitDir, "index.json");
|
|
16844
|
+
}
|
|
16711
16845
|
get lockPath() {
|
|
16712
16846
|
return path4.join(this.workitDir, "metadata.lock");
|
|
16713
16847
|
}
|
|
@@ -16715,71 +16849,8 @@ class TaskStore {
|
|
|
16715
16849
|
return path4.join(this.workitDir, ".gitignore");
|
|
16716
16850
|
}
|
|
16717
16851
|
}
|
|
16718
|
-
// packages/workit-core/src/core/
|
|
16719
|
-
|
|
16720
|
-
try {
|
|
16721
|
-
return canonicalJson(left) === canonicalJson(right);
|
|
16722
|
-
} catch {
|
|
16723
|
-
return false;
|
|
16724
|
-
}
|
|
16725
|
-
};
|
|
16726
|
-
var UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"];
|
|
16727
|
-
var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
|
|
16728
|
-
var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
|
|
16729
|
-
var callerSession = (caller) => caller.session ?? { kind: "host", host: caller.host, handle: caller.actor };
|
|
16730
|
-
var validPath = (value) => typeof value === "string" && value.length > 0 && ![...value].some((char) => {
|
|
16731
|
-
const code = char.charCodeAt(0);
|
|
16732
|
-
return code < 32 || code === 127;
|
|
16733
|
-
}) && !value.split(/[\\/]/).includes("..");
|
|
16734
|
-
var callerValue = (value) => ({ host: value.host, actor: value.actor });
|
|
16735
|
-
var workerIdOf = (value) => value.workerId ?? null;
|
|
16736
|
-
var currentWriterOwnsTask = (task, workspace, caller) => {
|
|
16737
|
-
const owner = workspace.writer?.owner;
|
|
16738
|
-
return task.status === "active" && task.workspaceId === workspace.id && owner?.taskId === task.id && owner.session.host === caller.host && owner.session.handle === caller.actor;
|
|
16739
|
-
};
|
|
16740
|
-
function assertProductWriteAllowed(input) {
|
|
16741
|
-
if (!Array.isArray(input.paths) || input.paths.some((path) => !validPath(path)))
|
|
16742
|
-
return failure("invalid_input", "invalid product write path");
|
|
16743
|
-
if (!input.store)
|
|
16744
|
-
return failure("permission_denied", "write authorization requires core state");
|
|
16745
|
-
const task = input.store.readTask(input.task.id);
|
|
16746
|
-
if (!task.ok)
|
|
16747
|
-
return task;
|
|
16748
|
-
const workspace = input.store.readWorkspace();
|
|
16749
|
-
if (!workspace.ok)
|
|
16750
|
-
return workspace;
|
|
16751
|
-
if (!workspace.data)
|
|
16752
|
-
return failure("not_found", "workspace not found");
|
|
16753
|
-
const workspaceRecord = workspace.data;
|
|
16754
|
-
if (task.data.status !== "active")
|
|
16755
|
-
return failure("invalid_transition", "paused or closed tasks cannot own product writes");
|
|
16756
|
-
if (workspaceRecord.id !== task.data.workspaceId || workspaceRecord.root.length === 0)
|
|
16757
|
-
return failure("recovery_required", "task and workspace bindings are invalid");
|
|
16758
|
-
const writer = workspaceRecord.writer;
|
|
16759
|
-
if (!writer)
|
|
16760
|
-
return failure("permission_denied", "checkout has no writer owner");
|
|
16761
|
-
if (writer.state === "uncertain")
|
|
16762
|
-
return failure("recovery_required", "checkout writer requires recovery", {
|
|
16763
|
-
owner: writer.owner
|
|
16764
|
-
});
|
|
16765
|
-
const caller = callerValue(input.caller);
|
|
16766
|
-
const workerId = workerIdOf(input.caller);
|
|
16767
|
-
const owner = writer.owner;
|
|
16768
|
-
if (owner.taskId !== task.data.id || owner.workerId !== workerId || owner.session.host !== caller.host || owner.session.handle !== caller.actor)
|
|
16769
|
-
return failure("writer_conflict", "checkout is owned by another validated actor", { owner });
|
|
16770
|
-
const worker = workerId === null ? null : task.data.workers.find((entry) => entry.id === workerId);
|
|
16771
|
-
if (workerId !== null && (!worker || worker.data.assignment.role !== "implementer"))
|
|
16772
|
-
return failure("permission_denied", "only implementers can own product writes");
|
|
16773
|
-
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))))
|
|
16774
|
-
return failure("recovery_required", "worker session is not an active writer");
|
|
16775
|
-
return success(null, workspaceRecord.revision, owner);
|
|
16776
|
-
}
|
|
16777
|
-
|
|
16778
|
-
// packages/workit-core/src/core/task-evaluation.ts
|
|
16779
|
-
import { createHash as createHash6 } from "node:crypto";
|
|
16780
|
-
import * as fs7 from "node:fs";
|
|
16781
|
-
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
16782
|
-
import path10 from "node:path";
|
|
16852
|
+
// packages/workit-core/src/core/task-engine.ts
|
|
16853
|
+
import { realpathSync as realpathSync6 } from "node:fs";
|
|
16783
16854
|
|
|
16784
16855
|
// packages/workit-core/src/core/authority.ts
|
|
16785
16856
|
import { createHash as createHash5 } from "node:crypto";
|
|
@@ -17786,6 +17857,66 @@ var verifyPushIdentity = (root, provider, account) => {
|
|
|
17786
17857
|
return { ok: true };
|
|
17787
17858
|
};
|
|
17788
17859
|
|
|
17860
|
+
// packages/workit-core/src/core/workers.ts
|
|
17861
|
+
var same = (left, right) => {
|
|
17862
|
+
try {
|
|
17863
|
+
return canonicalJson(left) === canonicalJson(right);
|
|
17864
|
+
} catch {
|
|
17865
|
+
return false;
|
|
17866
|
+
}
|
|
17867
|
+
};
|
|
17868
|
+
var UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"];
|
|
17869
|
+
var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
|
|
17870
|
+
var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
|
|
17871
|
+
var callerSession = (caller) => caller.session ?? { kind: "host", host: caller.host, handle: caller.actor };
|
|
17872
|
+
var validPath = (value) => typeof value === "string" && value.length > 0 && ![...value].some((char) => {
|
|
17873
|
+
const code = char.charCodeAt(0);
|
|
17874
|
+
return code < 32 || code === 127;
|
|
17875
|
+
}) && !value.split(/[\\/]/).includes("..");
|
|
17876
|
+
var callerValue = (value) => ({ host: value.host, actor: value.actor });
|
|
17877
|
+
var workerIdOf = (value) => value.workerId ?? null;
|
|
17878
|
+
var currentWriterOwnsTask = (task, workspace, caller) => {
|
|
17879
|
+
const owner = workspace.writer?.owner;
|
|
17880
|
+
return task.status === "active" && task.workspaceId === workspace.id && owner?.taskId === task.id && owner.session.host === caller.host && owner.session.handle === caller.actor;
|
|
17881
|
+
};
|
|
17882
|
+
function assertProductWriteAllowed(input) {
|
|
17883
|
+
if (!Array.isArray(input.paths) || input.paths.some((path) => !validPath(path)))
|
|
17884
|
+
return failure("invalid_input", "invalid product write path");
|
|
17885
|
+
if (!input.store)
|
|
17886
|
+
return failure("permission_denied", "write authorization requires core state");
|
|
17887
|
+
const task = input.store.readTask(input.task.id);
|
|
17888
|
+
if (!task.ok)
|
|
17889
|
+
return task;
|
|
17890
|
+
const workspace = input.store.readWorkspace();
|
|
17891
|
+
if (!workspace.ok)
|
|
17892
|
+
return workspace;
|
|
17893
|
+
if (!workspace.data)
|
|
17894
|
+
return failure("not_found", "workspace not found");
|
|
17895
|
+
const workspaceRecord = workspace.data;
|
|
17896
|
+
if (task.data.status !== "active")
|
|
17897
|
+
return failure("invalid_transition", "paused or closed tasks cannot own product writes");
|
|
17898
|
+
if (workspaceRecord.id !== task.data.workspaceId || workspaceRecord.root.length === 0)
|
|
17899
|
+
return failure("recovery_required", "task and workspace bindings are invalid");
|
|
17900
|
+
const writer = workspaceRecord.writer;
|
|
17901
|
+
if (!writer)
|
|
17902
|
+
return failure("permission_denied", "checkout has no writer owner");
|
|
17903
|
+
if (writer.state === "uncertain")
|
|
17904
|
+
return failure("recovery_required", "checkout writer requires recovery", {
|
|
17905
|
+
owner: writer.owner
|
|
17906
|
+
});
|
|
17907
|
+
const caller = callerValue(input.caller);
|
|
17908
|
+
const workerId = workerIdOf(input.caller);
|
|
17909
|
+
const owner = writer.owner;
|
|
17910
|
+
if (owner.taskId !== task.data.id || owner.workerId !== workerId || owner.session.host !== caller.host || owner.session.handle !== caller.actor)
|
|
17911
|
+
return failure("writer_conflict", "checkout is owned by another validated actor", { owner });
|
|
17912
|
+
const worker = workerId === null ? null : task.data.workers.find((entry) => entry.id === workerId);
|
|
17913
|
+
if (workerId !== null && (!worker || worker.data.assignment.role !== "implementer"))
|
|
17914
|
+
return failure("permission_denied", "only implementers can own product writes");
|
|
17915
|
+
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))))
|
|
17916
|
+
return failure("recovery_required", "worker session is not an active writer");
|
|
17917
|
+
return success(null, workspaceRecord.revision, owner);
|
|
17918
|
+
}
|
|
17919
|
+
|
|
17789
17920
|
// packages/workit-core/src/core/auto-approval.ts
|
|
17790
17921
|
var AUTO_CLASSES = ["branch", "commit", "push", "pr", "merge"];
|
|
17791
17922
|
var OPERATION_CLASS = {
|
|
@@ -18476,41 +18607,18 @@ function reconcileAction(input) {
|
|
|
18476
18607
|
var bindingCovers = scopeCovers;
|
|
18477
18608
|
var verifyDecisionContent = verifyContentRefs;
|
|
18478
18609
|
|
|
18479
|
-
// packages/workit-core/src/core/
|
|
18480
|
-
var
|
|
18481
|
-
|
|
18482
|
-
|
|
18483
|
-
|
|
18484
|
-
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18488
|
-
|
|
18489
|
-
|
|
18490
|
-
|
|
18491
|
-
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
18492
|
-
};
|
|
18493
|
-
var canonicalScope = (scope) => {
|
|
18494
|
-
const paths = scope.paths.length ? scope.paths : ["."];
|
|
18495
|
-
const normalizedPaths = paths.map(canonicalPath);
|
|
18496
|
-
const normalizedExclusions = scope.exclusions.map(canonicalPath);
|
|
18497
|
-
if (normalizedPaths.some((value) => value === null) || normalizedExclusions.some((value) => value === null))
|
|
18498
|
-
return null;
|
|
18499
|
-
return {
|
|
18500
|
-
description: scope.description,
|
|
18501
|
-
paths: [...new Set(normalizedPaths)],
|
|
18502
|
-
exclusions: [...new Set(normalizedExclusions)]
|
|
18503
|
-
};
|
|
18504
|
-
};
|
|
18505
|
-
var excluded = (value, exclusions) => exclusions.some((item) => item === value || item !== "." && value.startsWith(`${item}/`));
|
|
18506
|
-
var scopeMatches = (value, scope) => {
|
|
18507
|
-
const normalized = canonicalScope(scope);
|
|
18508
|
-
if (!normalized)
|
|
18509
|
-
return false;
|
|
18510
|
-
const paths = normalized.paths;
|
|
18511
|
-
return paths.some((item) => item === "." || value === item || value.startsWith(`${item}/`)) && !excluded(value, normalized.exclusions);
|
|
18512
|
-
};
|
|
18513
|
-
var pathRelevant = (value, scope) => scopeMatches(value, scope);
|
|
18610
|
+
// packages/workit-core/src/core/policy-resolver.ts
|
|
18611
|
+
var resolverInputSchema = object({
|
|
18612
|
+
intent: intentSchema,
|
|
18613
|
+
assessment: assessmentSchema,
|
|
18614
|
+
constraints: array(constraintSchema),
|
|
18615
|
+
prior: object({
|
|
18616
|
+
decisions: array(decisionSchema),
|
|
18617
|
+
findings: array(findingSchema),
|
|
18618
|
+
requirements: array(requirementSchema)
|
|
18619
|
+
}).strict(),
|
|
18620
|
+
preferences: object({ fast: boolean2().optional(), thorough: boolean2().optional() }).strict().optional()
|
|
18621
|
+
}).strict();
|
|
18514
18622
|
var compareCodeUnits2 = (left, right) => {
|
|
18515
18623
|
const length = Math.min(left.length, right.length);
|
|
18516
18624
|
for (let index = 0;index < length; index += 1) {
|
|
@@ -18520,927 +18628,970 @@ var compareCodeUnits2 = (left, right) => {
|
|
|
18520
18628
|
}
|
|
18521
18629
|
return left.length - right.length;
|
|
18522
18630
|
};
|
|
18523
|
-
var
|
|
18524
|
-
|
|
18525
|
-
|
|
18526
|
-
|
|
18527
|
-
|
|
18528
|
-
|
|
18529
|
-
|
|
18530
|
-
|
|
18531
|
-
|
|
18532
|
-
|
|
18533
|
-
|
|
18534
|
-
};
|
|
18535
|
-
}
|
|
18536
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")) : [];
|
|
18537
|
-
const stagedDeleted = spawnSync2("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
18538
|
-
if (stagedDeleted.status !== 0) {
|
|
18539
|
-
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
18540
|
-
if (!/not a git repository/i.test(stderr))
|
|
18541
|
-
return { paths, uncertain: true, git: true };
|
|
18542
|
-
} else if (stagedDeleted.stdout) {
|
|
18543
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")));
|
|
18544
|
-
}
|
|
18545
|
-
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
18546
|
-
};
|
|
18547
|
-
var walk = (root, directory, output) => {
|
|
18548
|
-
let names;
|
|
18549
|
-
try {
|
|
18550
|
-
names = fs7.readdirSync(directory);
|
|
18551
|
-
} catch {
|
|
18552
|
-
return true;
|
|
18553
|
-
}
|
|
18554
|
-
let uncertain = false;
|
|
18555
|
-
for (const name of names) {
|
|
18556
|
-
if (name === ".git" || name === ".workit")
|
|
18557
|
-
continue;
|
|
18558
|
-
const target = path10.join(directory, name);
|
|
18559
|
-
let stat;
|
|
18560
|
-
try {
|
|
18561
|
-
stat = fs7.lstatSync(target);
|
|
18562
|
-
} catch {
|
|
18563
|
-
uncertain = true;
|
|
18564
|
-
continue;
|
|
18565
|
-
}
|
|
18566
|
-
const item = relative(root, target);
|
|
18567
|
-
output.add(item);
|
|
18568
|
-
if (stat.isDirectory() && !stat.isSymbolicLink())
|
|
18569
|
-
uncertain = walk(root, target, output) || uncertain;
|
|
18570
|
-
}
|
|
18571
|
-
return uncertain;
|
|
18572
|
-
};
|
|
18573
|
-
var scopeRoots = (root, scope) => {
|
|
18574
|
-
const roots = [];
|
|
18575
|
-
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
18576
|
-
const target = path10.resolve(root, item);
|
|
18577
|
-
if (!inside(root, target))
|
|
18578
|
-
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` }] });
|
|
18579
|
-
let ancestor = target;
|
|
18580
|
-
while (!fs7.existsSync(ancestor) && ancestor !== root)
|
|
18581
|
-
ancestor = path10.dirname(ancestor);
|
|
18582
|
-
try {
|
|
18583
|
-
if (!inside(root, fs7.realpathSync(ancestor)))
|
|
18584
|
-
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` }] });
|
|
18585
|
-
} catch {
|
|
18586
|
-
return failure("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
18587
|
-
}
|
|
18588
|
-
roots.push(target);
|
|
18589
|
-
}
|
|
18590
|
-
return success(null, null, roots);
|
|
18591
|
-
};
|
|
18592
|
-
function captureCandidate(root, scope, environment = []) {
|
|
18593
|
-
let checkout;
|
|
18594
|
-
try {
|
|
18595
|
-
checkout = fs7.realpathSync(root);
|
|
18596
|
-
} catch {
|
|
18597
|
-
return failure("invalid_input", "candidate root does not exist");
|
|
18598
|
-
}
|
|
18599
|
-
const normalizedScope = canonicalScope(scope);
|
|
18600
|
-
if (!normalizedScope)
|
|
18601
|
-
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" }] });
|
|
18602
|
-
const roots = scopeRoots(checkout, normalizedScope);
|
|
18603
|
-
if (!roots.ok)
|
|
18604
|
-
return roots;
|
|
18605
|
-
const git = gitPaths(checkout);
|
|
18606
|
-
const names = new Set;
|
|
18607
|
-
let uncertain = git.uncertain;
|
|
18608
|
-
for (const target of roots.data) {
|
|
18609
|
-
const item = relative(checkout, target);
|
|
18610
|
-
if (item === ".git" || item === ".workit")
|
|
18611
|
-
continue;
|
|
18612
|
-
names.add(item);
|
|
18613
|
-
if (!fs7.existsSync(target))
|
|
18614
|
-
continue;
|
|
18615
|
-
let stat;
|
|
18616
|
-
try {
|
|
18617
|
-
stat = fs7.lstatSync(target);
|
|
18618
|
-
} catch {
|
|
18619
|
-
uncertain = true;
|
|
18620
|
-
continue;
|
|
18621
|
-
}
|
|
18622
|
-
if (!git.git && stat.isDirectory() && !stat.isSymbolicLink())
|
|
18623
|
-
uncertain = walk(checkout, target, names) || uncertain;
|
|
18624
|
-
}
|
|
18625
|
-
for (const item of git.paths)
|
|
18626
|
-
if (scopeMatches(item, normalizedScope))
|
|
18627
|
-
names.add(item);
|
|
18628
|
-
const files = [];
|
|
18629
|
-
let completeness = uncertain ? "uncertain" : "known";
|
|
18630
|
-
for (const item of [...names].sort()) {
|
|
18631
|
-
if (!scopeMatches(item, normalizedScope))
|
|
18632
|
-
continue;
|
|
18633
|
-
const target = path10.join(checkout, item);
|
|
18634
|
-
try {
|
|
18635
|
-
const stat = fs7.lstatSync(target);
|
|
18636
|
-
if (stat.isSymbolicLink()) {
|
|
18637
|
-
const link = fs7.readlinkSync(target);
|
|
18638
|
-
files.push({ path: item, kind: "symlink", digest: digestBytes3(link), executable: null });
|
|
18639
|
-
} else if (stat.isFile()) {
|
|
18640
|
-
files.push({
|
|
18641
|
-
path: item,
|
|
18642
|
-
kind: "file",
|
|
18643
|
-
digest: digestBytes3(fs7.readFileSync(target)),
|
|
18644
|
-
executable: (stat.mode & 73) !== 0
|
|
18645
|
-
});
|
|
18646
|
-
} else if (!stat.isDirectory()) {
|
|
18647
|
-
completeness = "uncertain";
|
|
18648
|
-
} else if (git.git && git.paths.includes(item)) {
|
|
18649
|
-
completeness = "uncertain";
|
|
18650
|
-
}
|
|
18651
|
-
} catch (error) {
|
|
18652
|
-
if (error?.code === "ENOENT") {
|
|
18653
|
-
files.push({ path: item, kind: "absent", digest: null, executable: null });
|
|
18654
|
-
} else
|
|
18655
|
-
completeness = "uncertain";
|
|
18656
|
-
}
|
|
18657
|
-
}
|
|
18658
|
-
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) => ({
|
|
18631
|
+
var stableUnique = (values) => [...new Set(values)].sort(compareCodeUnits2);
|
|
18632
|
+
var stableList = (values) => [...values].sort((left, right) => compareCodeUnits2(canonicalJson(left), canonicalJson(right)));
|
|
18633
|
+
var normalizedScope = (scope) => ({
|
|
18634
|
+
description: scope.description,
|
|
18635
|
+
paths: stableUnique(scope.paths),
|
|
18636
|
+
exclusions: stableUnique(scope.exclusions)
|
|
18637
|
+
});
|
|
18638
|
+
var normalizedRefList = (values) => stableList(values);
|
|
18639
|
+
var normalizeAssessment = (assessment) => ({
|
|
18640
|
+
facts: stableList(assessment.facts.map((fact) => ({ ...fact, refs: normalizedRefList(fact.refs) }))),
|
|
18641
|
+
signals: Object.fromEntries(Object.entries(assessment.signals).map(([name, signal]) => [
|
|
18659
18642
|
name,
|
|
18660
|
-
|
|
18661
|
-
|
|
18662
|
-
|
|
18663
|
-
|
|
18664
|
-
|
|
18665
|
-
|
|
18666
|
-
|
|
18667
|
-
|
|
18668
|
-
|
|
18669
|
-
|
|
18670
|
-
|
|
18671
|
-
|
|
18672
|
-
|
|
18673
|
-
|
|
18674
|
-
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18643
|
+
{ ...signal, refs: normalizedRefList(signal.refs) }
|
|
18644
|
+
])),
|
|
18645
|
+
consequences: stableList(assessment.consequences.map((consequence) => ({
|
|
18646
|
+
...consequence,
|
|
18647
|
+
fact: { ...consequence.fact, refs: normalizedRefList(consequence.fact.refs) }
|
|
18648
|
+
}))),
|
|
18649
|
+
verification: stableList(assessment.verification.map((verification) => ({
|
|
18650
|
+
...verification,
|
|
18651
|
+
scope: normalizedScope(verification.scope),
|
|
18652
|
+
availableChecks: normalizedRefList(verification.availableChecks),
|
|
18653
|
+
gaps: stableUnique(verification.gaps)
|
|
18654
|
+
})))
|
|
18655
|
+
});
|
|
18656
|
+
var normalizeConstraint = (constraint) => ({
|
|
18657
|
+
...constraint,
|
|
18658
|
+
source: constraint.source,
|
|
18659
|
+
requires: stableList(constraint.requires.map((requirement) => ({
|
|
18660
|
+
...requirement,
|
|
18661
|
+
scope: normalizedScope(requirement.scope),
|
|
18662
|
+
refs: normalizedRefList(requirement.refs)
|
|
18663
|
+
})))
|
|
18664
|
+
});
|
|
18665
|
+
var normalizeDecision = (decision) => ({
|
|
18666
|
+
...decision,
|
|
18667
|
+
binding: {
|
|
18668
|
+
...decision.binding,
|
|
18669
|
+
scope: normalizedScope(decision.binding.scope),
|
|
18670
|
+
contentRefs: normalizedRefList(decision.binding.contentRefs)
|
|
18671
|
+
},
|
|
18672
|
+
requirementIds: stableUnique(decision.requirementIds)
|
|
18673
|
+
});
|
|
18674
|
+
var normalizeIntent = (intent) => ({
|
|
18675
|
+
...intent,
|
|
18676
|
+
scope: normalizedScope(intent.scope),
|
|
18677
|
+
authorityRefs: normalizedRefList(intent.authorityRefs)
|
|
18678
|
+
});
|
|
18679
|
+
var normalizePrior = (prior) => ({
|
|
18680
|
+
decisions: stableList(prior.decisions.map(normalizeDecision)),
|
|
18681
|
+
findings: stableList(prior.findings.map((finding) => ({
|
|
18682
|
+
...finding,
|
|
18683
|
+
scope: normalizedScope(finding.scope),
|
|
18684
|
+
refs: normalizedRefList(finding.refs),
|
|
18685
|
+
resolution: finding.resolution ? {
|
|
18686
|
+
...finding.resolution,
|
|
18687
|
+
evidenceIds: stableUnique(finding.resolution.evidenceIds),
|
|
18688
|
+
decisionIds: stableUnique(finding.resolution.decisionIds)
|
|
18689
|
+
} : null
|
|
18690
|
+
}))),
|
|
18691
|
+
requirements: stableList(prior.requirements.map((requirement) => ({
|
|
18692
|
+
...requirement,
|
|
18693
|
+
scope: normalizedScope(requirement.scope)
|
|
18694
|
+
})))
|
|
18695
|
+
});
|
|
18696
|
+
var invalidFields = (error) => ({
|
|
18697
|
+
fields: error.issues.map((issue) => ({
|
|
18698
|
+
path: issue.code === "unrecognized_keys" ? issue.keys.join(".") : issue.path.join("."),
|
|
18699
|
+
reason: issue.message
|
|
18700
|
+
}))
|
|
18701
|
+
});
|
|
18702
|
+
function normalizeResolverInput(input) {
|
|
18703
|
+
const parsed = resolverInputSchema.safeParse(input);
|
|
18704
|
+
if (!parsed.success)
|
|
18705
|
+
return failure("invalid_input", "resolver input is invalid", invalidFields(parsed.error));
|
|
18706
|
+
const value = parsed.data;
|
|
18707
|
+
const signals = value.assessment.signals;
|
|
18708
|
+
if (signals.behaviorChange.value === true && signals.mechanicalLowRisk.value === true)
|
|
18709
|
+
return failure("invalid_input", "behavioral change cannot be wholly mechanical", {
|
|
18710
|
+
fields: [
|
|
18711
|
+
{
|
|
18712
|
+
path: "assessment.signals",
|
|
18713
|
+
reason: "contradictory behaviorChange and mechanicalLowRisk"
|
|
18714
|
+
}
|
|
18715
|
+
]
|
|
18716
|
+
});
|
|
18717
|
+
const ids = value.constraints.map((constraint) => constraint.id);
|
|
18718
|
+
if (new Set(ids).size !== ids.length)
|
|
18719
|
+
return failure("invalid_input", "constraint IDs must be unique", {
|
|
18720
|
+
fields: [{ path: "constraints", reason: "duplicate constraint id" }]
|
|
18721
|
+
});
|
|
18722
|
+
if (value.preferences?.fast && value.preferences.thorough)
|
|
18723
|
+
return failure("invalid_input", "fast and thorough preferences contradict", {
|
|
18724
|
+
fields: [{ path: "preferences", reason: "fast and thorough cannot both be enabled" }]
|
|
18725
|
+
});
|
|
18726
|
+
const normalized = {
|
|
18727
|
+
intent: normalizeIntent(value.intent),
|
|
18728
|
+
assessment: normalizeAssessment(value.assessment),
|
|
18729
|
+
constraints: stableList(value.constraints.map(normalizeConstraint)),
|
|
18730
|
+
prior: normalizePrior(value.prior),
|
|
18731
|
+
...value.preferences ? { preferences: { ...value.preferences } } : {},
|
|
18732
|
+
policyVersion: POLICY_VERSION
|
|
18679
18733
|
};
|
|
18680
|
-
|
|
18681
|
-
const parsed = candidateSchema.safeParse(candidate);
|
|
18682
|
-
return parsed.success ? success(null, null, parsed.data) : failure("invalid_input", "captured candidate is invalid");
|
|
18734
|
+
return success(null, null, normalized);
|
|
18683
18735
|
}
|
|
18684
|
-
var
|
|
18685
|
-
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18692
|
-
|
|
18693
|
-
|
|
18694
|
-
|
|
18695
|
-
|
|
18696
|
-
|
|
18697
|
-
|
|
18698
|
-
|
|
18699
|
-
|
|
18700
|
-
|
|
18701
|
-
|
|
18702
|
-
|
|
18703
|
-
|
|
18704
|
-
|
|
18705
|
-
|
|
18706
|
-
|
|
18707
|
-
|
|
18708
|
-
|
|
18709
|
-
|
|
18710
|
-
|
|
18711
|
-
|
|
18712
|
-
|
|
18713
|
-
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
|
|
18719
|
-
|
|
18720
|
-
|
|
18721
|
-
|
|
18722
|
-
|
|
18723
|
-
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
18736
|
+
var requirement = (spec) => ({
|
|
18737
|
+
...spec,
|
|
18738
|
+
id: requirementId({
|
|
18739
|
+
ruleId: spec.ruleId,
|
|
18740
|
+
scope: spec.scope,
|
|
18741
|
+
satisfaction: spec.satisfaction,
|
|
18742
|
+
before: spec.before,
|
|
18743
|
+
dependentAction: spec.dependentAction
|
|
18744
|
+
})
|
|
18745
|
+
});
|
|
18746
|
+
var signalReason = (input, name) => input.assessment.signals[name].reason;
|
|
18747
|
+
function resolveRequirements(input) {
|
|
18748
|
+
const { signals } = input.assessment;
|
|
18749
|
+
const scope = input.intent.scope;
|
|
18750
|
+
const requirements = [];
|
|
18751
|
+
const hasUnknownSignal = Object.values(signals).some((signal) => signal.value === "unknown");
|
|
18752
|
+
const hasUnknownFact = [
|
|
18753
|
+
...input.assessment.facts,
|
|
18754
|
+
...input.assessment.consequences.map(({ fact }) => fact)
|
|
18755
|
+
].some((fact) => fact.basis === "unknown");
|
|
18756
|
+
if (hasUnknownSignal || hasUnknownFact)
|
|
18757
|
+
requirements.push(requirement({
|
|
18758
|
+
ruleId: "consequential-unknown",
|
|
18759
|
+
dimension: "investigation",
|
|
18760
|
+
scope,
|
|
18761
|
+
reason: `Resolve consequential uncertainty before the dependent action: ${[
|
|
18762
|
+
...Object.entries(signals).filter(([, signal]) => signal.value === "unknown").map(([name]) => name),
|
|
18763
|
+
...hasUnknownFact ? ["unknown fact"] : []
|
|
18764
|
+
].join(", ")}`,
|
|
18765
|
+
satisfaction: "An observed or inferred fact resolves the uncertainty and records its supporting references.",
|
|
18766
|
+
before: "dependent_action",
|
|
18767
|
+
dependentAction: null,
|
|
18768
|
+
acceptanceAllowed: false
|
|
18769
|
+
}));
|
|
18770
|
+
if (signals.productChoiceOpen.value === true)
|
|
18771
|
+
requirements.push(requirement({
|
|
18772
|
+
ruleId: "product-decision",
|
|
18773
|
+
dimension: "decisions",
|
|
18774
|
+
scope,
|
|
18775
|
+
reason: `A consequential product choice remains open: ${signalReason(input, "productChoiceOpen")}`,
|
|
18776
|
+
satisfaction: "Present the material alternatives and record the user's decision before the dependent action.",
|
|
18777
|
+
before: "dependent_action",
|
|
18778
|
+
dependentAction: null,
|
|
18779
|
+
acceptanceAllowed: false
|
|
18780
|
+
}));
|
|
18781
|
+
const independentBehaviorReview = input.preferences?.thorough === true || input.assessment.consequences.some((consequence) => ["security", "data", "public_contract", "operations"].includes(consequence.area));
|
|
18782
|
+
if (signals.behaviorChange.value === true)
|
|
18783
|
+
requirements.push(requirement({
|
|
18784
|
+
ruleId: "behavioral-verification",
|
|
18785
|
+
dimension: "testing",
|
|
18786
|
+
scope,
|
|
18787
|
+
reason: `Behavior, side effects, permissions, or data handling may change: ${signalReason(input, "behaviorChange")}`,
|
|
18788
|
+
satisfaction: "A useful behavioral check passes against the affected behavior and current candidate.",
|
|
18789
|
+
before: "close",
|
|
18790
|
+
dependentAction: null,
|
|
18791
|
+
acceptanceAllowed: false
|
|
18792
|
+
}), requirement({
|
|
18793
|
+
ruleId: independentBehaviorReview ? "fresh-context-review" : "self-review",
|
|
18794
|
+
dimension: "review",
|
|
18795
|
+
scope,
|
|
18796
|
+
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.",
|
|
18797
|
+
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.",
|
|
18798
|
+
before: "close",
|
|
18799
|
+
dependentAction: null,
|
|
18800
|
+
acceptanceAllowed: !independentBehaviorReview
|
|
18801
|
+
}));
|
|
18802
|
+
else if (signals.mechanicalLowRisk.value === true)
|
|
18803
|
+
requirements.push(requirement({
|
|
18804
|
+
ruleId: "mechanical-existing-checks",
|
|
18805
|
+
dimension: "verification",
|
|
18806
|
+
scope,
|
|
18807
|
+
reason: `The change is demonstrably mechanical and low-risk: ${signalReason(input, "mechanicalLowRisk")}`,
|
|
18808
|
+
satisfaction: "Run the relevant existing checks for affected consumers; do not add tautological tests.",
|
|
18809
|
+
before: "close",
|
|
18810
|
+
dependentAction: null,
|
|
18811
|
+
acceptanceAllowed: true
|
|
18812
|
+
}), requirement({
|
|
18813
|
+
ruleId: input.preferences?.thorough ? "fresh-context-review" : "self-review",
|
|
18814
|
+
dimension: "review",
|
|
18815
|
+
scope,
|
|
18816
|
+
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.",
|
|
18817
|
+
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.",
|
|
18818
|
+
before: "close",
|
|
18819
|
+
dependentAction: null,
|
|
18820
|
+
acceptanceAllowed: !input.preferences?.thorough
|
|
18821
|
+
}));
|
|
18822
|
+
if (signals.behaviorChange.value === true || signals.mechanicalLowRisk.value === true)
|
|
18823
|
+
requirements.push(requirement({
|
|
18824
|
+
ruleId: "pre-pr-cleanup",
|
|
18825
|
+
dimension: "verification",
|
|
18826
|
+
scope,
|
|
18827
|
+
reason: "Implementation output must be deslopped before it is delivered.",
|
|
18828
|
+
satisfaction: "Run the workit-deslop pass and record passing check evidence, or record an approved limitation decision waiving cleanup.",
|
|
18829
|
+
before: "dependent_action",
|
|
18830
|
+
dependentAction: "hosting.pull_request",
|
|
18831
|
+
acceptanceAllowed: true
|
|
18832
|
+
}));
|
|
18833
|
+
if (signals.durableAgreementNeeded.value === true)
|
|
18834
|
+
requirements.push(requirement({
|
|
18835
|
+
ruleId: "durable-spec",
|
|
18836
|
+
dimension: "artifacts",
|
|
18837
|
+
scope,
|
|
18838
|
+
reason: `The work needs a durable agreement about intended behavior: ${signalReason(input, "durableAgreementNeeded")}`,
|
|
18839
|
+
satisfaction: "Record the agreed behavior in a durable specification before implementation writes.",
|
|
18840
|
+
before: "write",
|
|
18841
|
+
dependentAction: null,
|
|
18842
|
+
acceptanceAllowed: true
|
|
18843
|
+
}));
|
|
18844
|
+
if (signals.coordinationPlanNeeded.value === true)
|
|
18845
|
+
requirements.push(requirement({
|
|
18846
|
+
ruleId: "coordination-plan",
|
|
18847
|
+
dimension: "continuity",
|
|
18848
|
+
scope,
|
|
18849
|
+
reason: `Dependencies, sequencing, or resumption need durable coordination: ${signalReason(input, "coordinationPlanNeeded")}`,
|
|
18850
|
+
satisfaction: "Record useful sequencing, dependencies, and the next action in a compact plan.",
|
|
18851
|
+
before: "dependent_action",
|
|
18852
|
+
dependentAction: null,
|
|
18853
|
+
acceptanceAllowed: true
|
|
18854
|
+
}));
|
|
18855
|
+
if (signals.helperUseful.value === true && !input.preferences?.fast)
|
|
18856
|
+
requirements.push(requirement({
|
|
18857
|
+
ruleId: "helper-usefulness",
|
|
18858
|
+
dimension: "delegation",
|
|
18859
|
+
scope,
|
|
18860
|
+
reason: `Independent judgment or investigation justifies a scoped helper: ${signalReason(input, "helperUseful")}`,
|
|
18861
|
+
satisfaction: "Use a bounded helper only for the independent objective and reconcile its result.",
|
|
18862
|
+
before: "dependent_action",
|
|
18863
|
+
dependentAction: null,
|
|
18864
|
+
acceptanceAllowed: true
|
|
18865
|
+
}));
|
|
18866
|
+
for (const constraint of input.constraints)
|
|
18867
|
+
for (const obligation of constraint.requires) {
|
|
18868
|
+
const dimension = obligation.method ?? (obligation.kind === "check" ? "verification" : obligation.kind === "decision" ? "decisions" : "challenge");
|
|
18869
|
+
requirements.push(requirement({
|
|
18870
|
+
ruleId: `project-constraint:${constraint.id}:${obligation.kind}:${sha256({
|
|
18871
|
+
kind: obligation.kind,
|
|
18872
|
+
scope: normalizedScope(obligation.scope),
|
|
18873
|
+
refs: normalizedRefList(obligation.refs),
|
|
18874
|
+
method: obligation.method,
|
|
18875
|
+
before: obligation.before,
|
|
18876
|
+
dependentAction: obligation.dependentAction
|
|
18877
|
+
})}`,
|
|
18878
|
+
dimension,
|
|
18879
|
+
scope: obligation.scope,
|
|
18880
|
+
reason: `${constraint.kind} constraint requires ${obligation.kind}: ${constraint.statement}`,
|
|
18881
|
+
satisfaction: `Satisfy the constraint obligation using its referenced ${obligation.kind}.`,
|
|
18882
|
+
before: obligation.before,
|
|
18883
|
+
dependentAction: obligation.dependentAction,
|
|
18884
|
+
acceptanceAllowed: constraint.acceptanceAllowed && obligation.kind !== "decision"
|
|
18885
|
+
}));
|
|
18729
18886
|
}
|
|
18730
|
-
|
|
18731
|
-
|
|
18732
|
-
|
|
18733
|
-
|
|
18734
|
-
|
|
18735
|
-
|
|
18736
|
-
const observed = task.candidates.find((item) => item.id === evidence.candidateId) ?? (current.id === evidence.candidateId ? current : undefined);
|
|
18737
|
-
if (!observed || observed.completeness === "uncertain" || current.completeness === "uncertain")
|
|
18738
|
-
return { evidenceId: entry.id, status: "stale", reason: "candidate is missing or uncertain" };
|
|
18739
|
-
if (observed.id === current.id)
|
|
18740
|
-
return { evidenceId: entry.id, status: evidence.result, reason: "candidate is unchanged" };
|
|
18741
|
-
const scopes = evidenceScopes(task, evidence.requirementIds);
|
|
18742
|
-
const changed = changedPaths(observed, current);
|
|
18743
|
-
const environmentChanged = JSON.stringify(observed.environment) !== JSON.stringify(current.environment);
|
|
18744
|
-
if (!scopes.length || environmentChanged || changed.some((item) => scopes.some((scope) => pathRelevant(item, scope))))
|
|
18745
|
-
return { evidenceId: entry.id, status: "stale", reason: "relevant candidate state changed" };
|
|
18746
|
-
return {
|
|
18747
|
-
evidenceId: entry.id,
|
|
18748
|
-
status: evidence.result,
|
|
18749
|
-
reason: "candidate changed outside evidence scope"
|
|
18750
|
-
};
|
|
18887
|
+
const seen = new Set;
|
|
18888
|
+
return requirements.filter((item) => {
|
|
18889
|
+
if (seen.has(item.id))
|
|
18890
|
+
return false;
|
|
18891
|
+
seen.add(item.id);
|
|
18892
|
+
return true;
|
|
18751
18893
|
});
|
|
18752
18894
|
}
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
const fallback = bound ? pin ?? currentCandidateId : null;
|
|
18763
|
-
return {
|
|
18764
|
-
beforeCandidateId: evidence.beforeCandidateId ?? fallback,
|
|
18765
|
-
candidateId: evidence.candidateId ?? fallback
|
|
18895
|
+
function resolvePolicy(input) {
|
|
18896
|
+
const normalized = normalizeResolverInput(input);
|
|
18897
|
+
if (!normalized.ok)
|
|
18898
|
+
return normalized;
|
|
18899
|
+
const requirements = resolveRequirements(normalized.data);
|
|
18900
|
+
const policy = {
|
|
18901
|
+
policyVersion: POLICY_VERSION,
|
|
18902
|
+
inputDigest: sha256(canonicalJson(normalized.data)),
|
|
18903
|
+
requirements
|
|
18766
18904
|
};
|
|
18767
|
-
|
|
18768
|
-
|
|
18769
|
-
|
|
18770
|
-
|
|
18771
|
-
|
|
18772
|
-
|
|
18773
|
-
|
|
18774
|
-
|
|
18775
|
-
|
|
18776
|
-
|
|
18777
|
-
|
|
18778
|
-
|
|
18779
|
-
|
|
18780
|
-
|
|
18781
|
-
|
|
18782
|
-
|
|
18783
|
-
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
|
|
18787
|
-
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
|
|
18799
|
-
|
|
18800
|
-
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
|
|
18805
|
-
|
|
18806
|
-
|
|
18807
|
-
|
|
18808
|
-
|
|
18809
|
-
|
|
18810
|
-
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
18821
|
-
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18827
|
-
|
|
18828
|
-
|
|
18829
|
-
|
|
18830
|
-
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
18838
|
-
|
|
18839
|
-
|
|
18840
|
-
|
|
18841
|
-
|
|
18842
|
-
|
|
18843
|
-
|
|
18844
|
-
|
|
18845
|
-
|
|
18846
|
-
|
|
18847
|
-
|
|
18848
|
-
|
|
18849
|
-
|
|
18850
|
-
|
|
18851
|
-
|
|
18852
|
-
|
|
18853
|
-
|
|
18854
|
-
}
|
|
18855
|
-
const decisions = requirement.dimension === "decisions" ? applicableRequirementDecision(task, workspace, requirement, checkoutRoot) : [];
|
|
18856
|
-
if (decisions.length)
|
|
18857
|
-
return {
|
|
18858
|
-
requirementId: requirement.id,
|
|
18859
|
-
status: "satisfied",
|
|
18860
|
-
evidenceIds: [],
|
|
18861
|
-
decisionIds: decisions.map((decision) => decision.id),
|
|
18862
|
-
reason: "an applicable approved or stated decision satisfies the requirement"
|
|
18863
|
-
};
|
|
18864
|
-
const limitations = requirement.acceptanceAllowed ? applicableDecision2(task, workspace, requirement, checkoutRoot) : [];
|
|
18865
|
-
if (limitations.length)
|
|
18866
|
-
return {
|
|
18867
|
-
requirementId: requirement.id,
|
|
18868
|
-
status: "accepted_limitation",
|
|
18869
|
-
evidenceIds: [],
|
|
18870
|
-
decisionIds: limitations.map((decision) => task.decisions.find((entry) => entry.data === decision).id),
|
|
18871
|
-
reason: "an applicable approved limitation permits the missing evidence"
|
|
18872
|
-
};
|
|
18873
|
-
const unavailable = capabilities.some((capability) => capability.assurance === "unavailable" && (capability.name === requirement.dimension || capability.surface === requirement.dimension));
|
|
18874
|
-
if (!unavailable && related.length > 0 && !passed.length)
|
|
18875
|
-
return {
|
|
18876
|
-
requirementId: requirement.id,
|
|
18877
|
-
status: "unsatisfied",
|
|
18878
|
-
evidenceIds: related.map(({ entry }) => entry.id),
|
|
18879
|
-
decisionIds: [],
|
|
18880
|
-
reason: `no passing evidence (needs kind:${expectedKinds(requirement.dimension, requirement.ruleId)})`
|
|
18881
|
-
};
|
|
18905
|
+
const parsed = policySchema.safeParse(policy);
|
|
18906
|
+
if (!parsed.success)
|
|
18907
|
+
return failure("invalid_input", "resolved policy is invalid", invalidFields(parsed.error));
|
|
18908
|
+
return success(null, null, parsed.data);
|
|
18909
|
+
}
|
|
18910
|
+
function diffPolicy(previous, next, reason, now) {
|
|
18911
|
+
if (!policySchema.safeParse(previous).success && previous !== null)
|
|
18912
|
+
throw new TypeError("previous policy is invalid");
|
|
18913
|
+
if (!policySchema.safeParse(next).success)
|
|
18914
|
+
throw new TypeError("next policy is invalid");
|
|
18915
|
+
const oldIds = new Set(previous?.requirements.map((requirement) => requirement.id) ?? []);
|
|
18916
|
+
const newIds = new Set(next.requirements.map((requirement) => requirement.id));
|
|
18917
|
+
const added = [...newIds].filter((id) => !oldIds.has(id)).sort(compareCodeUnits2);
|
|
18918
|
+
const retired = [...oldIds].filter((id) => !newIds.has(id)).sort(compareCodeUnits2);
|
|
18919
|
+
if (added.length === 0 && retired.length === 0)
|
|
18920
|
+
return null;
|
|
18921
|
+
const normalizedReason = reason.trim();
|
|
18922
|
+
const changeReason = retired.length ? `${normalizedReason || "policy reassessed"} (retired: ${retired.join(",")})` : normalizedReason || "policy reassessed";
|
|
18923
|
+
const change = {
|
|
18924
|
+
recordedAt: now,
|
|
18925
|
+
fromInputDigest: previous?.inputDigest ?? null,
|
|
18926
|
+
toInputDigest: next.inputDigest,
|
|
18927
|
+
added,
|
|
18928
|
+
retired,
|
|
18929
|
+
reason: changeReason
|
|
18930
|
+
};
|
|
18931
|
+
const parsed = policyChangeSchema.safeParse(change);
|
|
18932
|
+
if (!parsed.success)
|
|
18933
|
+
throw new TypeError("policy change is invalid");
|
|
18934
|
+
return parsed.data;
|
|
18935
|
+
}
|
|
18936
|
+
|
|
18937
|
+
// packages/workit-core/src/core/task-evaluation.ts
|
|
18938
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
18939
|
+
import * as fs7 from "node:fs";
|
|
18940
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
18941
|
+
import path10 from "node:path";
|
|
18942
|
+
var digestBytes3 = (value) => createHash6("sha256").update(value).digest("hex");
|
|
18943
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path10.sep}`);
|
|
18944
|
+
var relative = (root, candidate) => path10.relative(root, candidate).split(path10.sep).join("/") || ".";
|
|
18945
|
+
var canonicalPath = (value) => {
|
|
18946
|
+
if (typeof value !== "string" || !value)
|
|
18947
|
+
return null;
|
|
18948
|
+
if (value.includes("\\") || value.split("/").includes(".."))
|
|
18949
|
+
return null;
|
|
18950
|
+
const normalized = path10.posix.normalize(value);
|
|
18951
|
+
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
18952
|
+
return null;
|
|
18953
|
+
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
18954
|
+
};
|
|
18955
|
+
var canonicalScope = (scope) => {
|
|
18956
|
+
const paths = scope.paths.length ? scope.paths : ["."];
|
|
18957
|
+
const normalizedPaths = paths.map(canonicalPath);
|
|
18958
|
+
const normalizedExclusions = scope.exclusions.map(canonicalPath);
|
|
18959
|
+
if (normalizedPaths.some((value) => value === null) || normalizedExclusions.some((value) => value === null))
|
|
18960
|
+
return null;
|
|
18961
|
+
return {
|
|
18962
|
+
description: scope.description,
|
|
18963
|
+
paths: [...new Set(normalizedPaths)],
|
|
18964
|
+
exclusions: [...new Set(normalizedExclusions)]
|
|
18965
|
+
};
|
|
18966
|
+
};
|
|
18967
|
+
var excluded = (value, exclusions) => exclusions.some((item) => item === value || item !== "." && value.startsWith(`${item}/`));
|
|
18968
|
+
var scopeMatches = (value, scope) => {
|
|
18969
|
+
const normalized = canonicalScope(scope);
|
|
18970
|
+
if (!normalized)
|
|
18971
|
+
return false;
|
|
18972
|
+
const paths = normalized.paths;
|
|
18973
|
+
return paths.some((item) => item === "." || value === item || value.startsWith(`${item}/`)) && !excluded(value, normalized.exclusions);
|
|
18974
|
+
};
|
|
18975
|
+
var pathRelevant = (value, scope) => scopeMatches(value, scope);
|
|
18976
|
+
var compareCodeUnits3 = (left, right) => {
|
|
18977
|
+
const length = Math.min(left.length, right.length);
|
|
18978
|
+
for (let index = 0;index < length; index += 1) {
|
|
18979
|
+
const difference = left.charCodeAt(index) - right.charCodeAt(index);
|
|
18980
|
+
if (difference !== 0)
|
|
18981
|
+
return difference;
|
|
18982
|
+
}
|
|
18983
|
+
return left.length - right.length;
|
|
18984
|
+
};
|
|
18985
|
+
var gitPaths = (root) => {
|
|
18986
|
+
const result = spawnSync2("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
|
|
18987
|
+
cwd: root,
|
|
18988
|
+
encoding: "buffer"
|
|
18989
|
+
});
|
|
18990
|
+
if (result.status !== 0) {
|
|
18991
|
+
const stderr = result.stderr?.toString("utf8") ?? "";
|
|
18882
18992
|
return {
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
|
|
18886
|
-
decisionIds: [],
|
|
18887
|
-
reason: unavailable ? "required capability is unavailable" : "no fresh passing evidence"
|
|
18993
|
+
paths: [],
|
|
18994
|
+
uncertain: !/not a git repository/i.test(stderr),
|
|
18995
|
+
git: /not a git repository/i.test(stderr) ? false : true
|
|
18888
18996
|
};
|
|
18889
|
-
}
|
|
18890
|
-
|
|
18891
|
-
|
|
18892
|
-
if (
|
|
18893
|
-
|
|
18894
|
-
|
|
18895
|
-
|
|
18896
|
-
|
|
18897
|
-
|
|
18898
|
-
|
|
18899
|
-
|
|
18900
|
-
|
|
18901
|
-
|
|
18902
|
-
|
|
18903
|
-
|
|
18904
|
-
|
|
18905
|
-
|
|
18906
|
-
|
|
18907
|
-
|
|
18908
|
-
|
|
18909
|
-
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
|
|
18913
|
-
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
const decisionEntry = view.task.decisions.find((item) => item.id === id);
|
|
18920
|
-
const decision = decisionEntry?.data;
|
|
18921
|
-
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)));
|
|
18922
|
-
});
|
|
18923
|
-
if (!valid)
|
|
18924
|
-
return failure("requirements_unsatisfied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
|
|
18925
|
-
}
|
|
18997
|
+
}
|
|
18998
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")) : [];
|
|
18999
|
+
const stagedDeleted = spawnSync2("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
19000
|
+
if (stagedDeleted.status !== 0) {
|
|
19001
|
+
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
19002
|
+
if (!/not a git repository/i.test(stderr))
|
|
19003
|
+
return { paths, uncertain: true, git: true };
|
|
19004
|
+
} else if (stagedDeleted.stdout) {
|
|
19005
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path10.sep).join("/")));
|
|
19006
|
+
}
|
|
19007
|
+
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
19008
|
+
};
|
|
19009
|
+
var walk = (root, directory, output) => {
|
|
19010
|
+
let names;
|
|
19011
|
+
try {
|
|
19012
|
+
names = fs7.readdirSync(directory);
|
|
19013
|
+
} catch {
|
|
19014
|
+
return true;
|
|
19015
|
+
}
|
|
19016
|
+
let uncertain = false;
|
|
19017
|
+
for (const name of names) {
|
|
19018
|
+
if (name === ".git" || name === ".workit")
|
|
19019
|
+
continue;
|
|
19020
|
+
const target = path10.join(directory, name);
|
|
19021
|
+
let stat;
|
|
19022
|
+
try {
|
|
19023
|
+
stat = fs7.lstatSync(target);
|
|
19024
|
+
} catch {
|
|
19025
|
+
uncertain = true;
|
|
19026
|
+
continue;
|
|
18926
19027
|
}
|
|
19028
|
+
const item = relative(root, target);
|
|
19029
|
+
output.add(item);
|
|
19030
|
+
if (stat.isDirectory() && !stat.isSymbolicLink())
|
|
19031
|
+
uncertain = walk(root, target, output) || uncertain;
|
|
18927
19032
|
}
|
|
18928
|
-
|
|
18929
|
-
|
|
18930
|
-
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
19033
|
+
return uncertain;
|
|
19034
|
+
};
|
|
19035
|
+
var scopeRoots = (root, scope) => {
|
|
19036
|
+
const roots = [];
|
|
19037
|
+
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
19038
|
+
const target = path10.resolve(root, item);
|
|
19039
|
+
if (!inside(root, target))
|
|
19040
|
+
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` }] });
|
|
19041
|
+
let ancestor = target;
|
|
19042
|
+
while (!fs7.existsSync(ancestor) && ancestor !== root)
|
|
19043
|
+
ancestor = path10.dirname(ancestor);
|
|
19044
|
+
try {
|
|
19045
|
+
if (!inside(root, fs7.realpathSync(ancestor)))
|
|
19046
|
+
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` }] });
|
|
19047
|
+
} catch {
|
|
19048
|
+
return failure("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
19049
|
+
}
|
|
19050
|
+
roots.push(target);
|
|
19051
|
+
}
|
|
19052
|
+
return success(null, null, roots);
|
|
19053
|
+
};
|
|
19054
|
+
function captureCandidate(root, scope, environment = []) {
|
|
19055
|
+
let checkout;
|
|
19056
|
+
try {
|
|
19057
|
+
checkout = fs7.realpathSync(root);
|
|
19058
|
+
} catch {
|
|
19059
|
+
return failure("invalid_input", "candidate root does not exist");
|
|
19060
|
+
}
|
|
19061
|
+
const normalizedScope = canonicalScope(scope);
|
|
19062
|
+
if (!normalizedScope)
|
|
19063
|
+
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" }] });
|
|
19064
|
+
const roots = scopeRoots(checkout, normalizedScope);
|
|
19065
|
+
if (!roots.ok)
|
|
19066
|
+
return roots;
|
|
19067
|
+
const git = gitPaths(checkout);
|
|
19068
|
+
const names = new Set;
|
|
19069
|
+
let uncertain = git.uncertain;
|
|
19070
|
+
for (const target of roots.data) {
|
|
19071
|
+
const item = relative(checkout, target);
|
|
19072
|
+
if (item === ".git" || item === ".workit")
|
|
19073
|
+
continue;
|
|
19074
|
+
names.add(item);
|
|
19075
|
+
if (!fs7.existsSync(target))
|
|
19076
|
+
continue;
|
|
19077
|
+
let stat;
|
|
19078
|
+
try {
|
|
19079
|
+
stat = fs7.lstatSync(target);
|
|
19080
|
+
} catch {
|
|
19081
|
+
uncertain = true;
|
|
19082
|
+
continue;
|
|
19083
|
+
}
|
|
19084
|
+
if (!git.git && stat.isDirectory() && !stat.isSymbolicLink())
|
|
19085
|
+
uncertain = walk(checkout, target, names) || uncertain;
|
|
19086
|
+
}
|
|
19087
|
+
for (const item of git.paths)
|
|
19088
|
+
if (scopeMatches(item, normalizedScope))
|
|
19089
|
+
names.add(item);
|
|
19090
|
+
const files = [];
|
|
19091
|
+
let completeness = uncertain ? "uncertain" : "known";
|
|
19092
|
+
for (const item of [...names].sort()) {
|
|
19093
|
+
if (!scopeMatches(item, normalizedScope))
|
|
19094
|
+
continue;
|
|
19095
|
+
const target = path10.join(checkout, item);
|
|
19096
|
+
try {
|
|
19097
|
+
const stat = fs7.lstatSync(target);
|
|
19098
|
+
if (stat.isSymbolicLink()) {
|
|
19099
|
+
const link = fs7.readlinkSync(target);
|
|
19100
|
+
files.push({ path: item, kind: "symlink", digest: digestBytes3(link), executable: null });
|
|
19101
|
+
} else if (stat.isFile()) {
|
|
19102
|
+
files.push({
|
|
19103
|
+
path: item,
|
|
19104
|
+
kind: "file",
|
|
19105
|
+
digest: digestBytes3(fs7.readFileSync(target)),
|
|
19106
|
+
executable: (stat.mode & 73) !== 0
|
|
19107
|
+
});
|
|
19108
|
+
} else if (!stat.isDirectory()) {
|
|
19109
|
+
completeness = "uncertain";
|
|
19110
|
+
} else if (git.git && git.paths.includes(item)) {
|
|
19111
|
+
completeness = "uncertain";
|
|
19112
|
+
}
|
|
19113
|
+
} catch (error) {
|
|
19114
|
+
if (error?.code === "ENOENT") {
|
|
19115
|
+
files.push({ path: item, kind: "absent", digest: null, executable: null });
|
|
19116
|
+
} else
|
|
19117
|
+
completeness = "uncertain";
|
|
19118
|
+
}
|
|
19119
|
+
}
|
|
19120
|
+
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) => ({
|
|
19121
|
+
name,
|
|
19122
|
+
value: environment[name] ?? null
|
|
19123
|
+
}));
|
|
19124
|
+
const namesByEnvironment = supplied.map(({ name }) => name);
|
|
19125
|
+
if (new Set(namesByEnvironment).size !== namesByEnvironment.length || namesByEnvironment.some((name) => typeof name !== "string" || !name))
|
|
19126
|
+
return failure("invalid_input", "candidate environment names must be unique and non-empty");
|
|
19127
|
+
const values = supplied.sort((left, right) => compareCodeUnits3(left.name, right.name)).map(({ name, value }) => ({ name, value, refs: [] }));
|
|
19128
|
+
if (values.some(({ value }) => value === null))
|
|
19129
|
+
completeness = "uncertain";
|
|
19130
|
+
const headResult = spawnSync2("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
|
|
19131
|
+
if (headResult.status !== 0 && !/not a git repository/i.test(headResult.stderr ?? ""))
|
|
19132
|
+
completeness = "uncertain";
|
|
19133
|
+
const head = headResult.status === 0 ? headResult.stdout.trim() : null;
|
|
19134
|
+
const partial = {
|
|
19135
|
+
id: "0".repeat(64),
|
|
19136
|
+
scope: normalizedScope,
|
|
19137
|
+
completeness,
|
|
19138
|
+
files,
|
|
19139
|
+
environment: values,
|
|
19140
|
+
head
|
|
19141
|
+
};
|
|
19142
|
+
const candidate = { ...partial, id: candidateDigest(partial) };
|
|
19143
|
+
const parsed = candidateSchema.safeParse(candidate);
|
|
19144
|
+
return parsed.success ? success(null, null, parsed.data) : failure("invalid_input", "captured candidate is invalid");
|
|
19145
|
+
}
|
|
19146
|
+
var fileMap = (candidate) => new Map(candidate.files.map((file) => [file.path, file]));
|
|
19147
|
+
var changedPaths = (before, after) => {
|
|
19148
|
+
const paths = new Set([...before.files, ...after.files].map((file) => file.path));
|
|
19149
|
+
const left = fileMap(before);
|
|
19150
|
+
const right = fileMap(after);
|
|
19151
|
+
const changed = [...paths].filter((item) => JSON.stringify(left.get(item) ?? null) !== JSON.stringify(right.get(item) ?? null));
|
|
19152
|
+
if (before.head !== after.head)
|
|
19153
|
+
changed.push(".");
|
|
19154
|
+
if (JSON.stringify(before.environment) !== JSON.stringify(after.environment))
|
|
19155
|
+
changed.push(".");
|
|
19156
|
+
return changed;
|
|
19157
|
+
};
|
|
19158
|
+
var sessionFromRef = (value) => {
|
|
19159
|
+
if (typeof value !== "object" || value === null || value.kind !== "host")
|
|
19160
|
+
return null;
|
|
19161
|
+
return typeof value.host === "string" && typeof value.handle === "string" ? { host: value.host, handle: value.handle } : null;
|
|
19162
|
+
};
|
|
19163
|
+
var sameSession = (left, right) => {
|
|
19164
|
+
const other = sessionFromRef(right);
|
|
19165
|
+
return left !== null && other !== null && left.host === other.host && left.handle === other.handle;
|
|
19166
|
+
};
|
|
19167
|
+
var evidenceScopes = (task, ids) => (task.policy?.requirements ?? []).filter((requirement) => ids.includes(requirement.id)).map((requirement) => requirement.scope);
|
|
19168
|
+
function evaluateEvidence(task, candidate) {
|
|
19169
|
+
const current = candidate ?? task.candidates.at(-1) ?? null;
|
|
19170
|
+
return task.evidence.map((entry) => {
|
|
19171
|
+
const evidence = entry.data;
|
|
19172
|
+
if (evidence.result === "failed")
|
|
19173
|
+
return {
|
|
19174
|
+
evidenceId: entry.id,
|
|
19175
|
+
status: "failed",
|
|
19176
|
+
reason: "failed evidence remains historical"
|
|
19177
|
+
};
|
|
19178
|
+
if (evidence.kind === "check" || evidence.kind === "review") {
|
|
19179
|
+
if (!evidence.beforeCandidateId || !evidence.candidateId)
|
|
18939
19180
|
return {
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
reason:
|
|
18943
|
-
satisfaction: requirement?.satisfaction ?? "",
|
|
18944
|
-
dependentAction: requirement?.dependentAction ?? null
|
|
19181
|
+
evidenceId: entry.id,
|
|
19182
|
+
status: "stale",
|
|
19183
|
+
reason: "check or review evidence lacks start and end candidates"
|
|
18945
19184
|
};
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
}
|
|
18953
|
-
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
18966
|
-
|
|
18967
|
-
|
|
18968
|
-
|
|
18969
|
-
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
|
|
18974
|
-
function reconcileResume(view, observations = []) {
|
|
18975
|
-
if (observations.length > 0)
|
|
18976
|
-
return failure("permission_denied", "worker observations require native host verification");
|
|
18977
|
-
const candidate = captureCandidate(view.workspace.root, view.task.intent.data.scope, []);
|
|
18978
|
-
if (!candidate.ok)
|
|
18979
|
-
return candidate;
|
|
18980
|
-
const staleEvidenceIds = evaluateEvidence(view.task, candidate.data).filter((entry) => entry.status === "stale").map((entry) => entry.evidenceId);
|
|
18981
|
-
const blockers = [...view.task.progress.blockers];
|
|
18982
|
-
if (view.task.workers.some((entry) => isUncertainWorker(entry.data.state)))
|
|
18983
|
-
blockers.push({
|
|
18984
|
-
reason: "worker state requires reconciliation",
|
|
18985
|
-
dependentAction: "resume",
|
|
18986
|
-
refs: []
|
|
18987
|
-
});
|
|
18988
|
-
return success(null, null, {
|
|
18989
|
-
candidate: candidate.data,
|
|
18990
|
-
staleEvidenceIds,
|
|
18991
|
-
workerUpdates: [],
|
|
18992
|
-
blockers,
|
|
18993
|
-
reassessmentRequired: view.task.policy?.policyVersion !== POLICY_VERSION
|
|
19185
|
+
if (evidence.beforeCandidateId !== evidence.candidateId)
|
|
19186
|
+
return {
|
|
19187
|
+
evidenceId: entry.id,
|
|
19188
|
+
status: "stale",
|
|
19189
|
+
reason: "candidate changed during the check or review"
|
|
19190
|
+
};
|
|
19191
|
+
}
|
|
19192
|
+
if (!evidence.candidateId || !current)
|
|
19193
|
+
return {
|
|
19194
|
+
evidenceId: entry.id,
|
|
19195
|
+
status: evidence.result,
|
|
19196
|
+
reason: "evidence has no candidate binding"
|
|
19197
|
+
};
|
|
19198
|
+
const observed = task.candidates.find((item) => item.id === evidence.candidateId) ?? (current.id === evidence.candidateId ? current : undefined);
|
|
19199
|
+
if (!observed || observed.completeness === "uncertain" || current.completeness === "uncertain")
|
|
19200
|
+
return { evidenceId: entry.id, status: "stale", reason: "candidate is missing or uncertain" };
|
|
19201
|
+
if (observed.id === current.id)
|
|
19202
|
+
return { evidenceId: entry.id, status: evidence.result, reason: "candidate is unchanged" };
|
|
19203
|
+
const scopes = evidenceScopes(task, evidence.requirementIds);
|
|
19204
|
+
const changed = changedPaths(observed, current);
|
|
19205
|
+
const environmentChanged = JSON.stringify(observed.environment) !== JSON.stringify(current.environment);
|
|
19206
|
+
if (!scopes.length || environmentChanged || changed.some((item) => scopes.some((scope) => pathRelevant(item, scope))))
|
|
19207
|
+
return { evidenceId: entry.id, status: "stale", reason: "relevant candidate state changed" };
|
|
19208
|
+
return {
|
|
19209
|
+
evidenceId: entry.id,
|
|
19210
|
+
status: evidence.result,
|
|
19211
|
+
reason: "candidate changed outside evidence scope"
|
|
19212
|
+
};
|
|
18994
19213
|
});
|
|
18995
19214
|
}
|
|
18996
|
-
var
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
|
|
19002
|
-
|
|
19003
|
-
var
|
|
19004
|
-
|
|
19005
|
-
|
|
19006
|
-
|
|
19007
|
-
|
|
19008
|
-
|
|
19009
|
-
|
|
19010
|
-
|
|
19011
|
-
|
|
19012
|
-
|
|
19013
|
-
|
|
19014
|
-
|
|
19015
|
-
|
|
19016
|
-
|
|
19017
|
-
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
19039
|
-
|
|
19040
|
-
|
|
19041
|
-
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
|
|
19047
|
-
|
|
19048
|
-
|
|
19049
|
-
|
|
19050
|
-
|
|
19051
|
-
object({
|
|
19052
|
-
operation: literal("hosting.delete_branch"),
|
|
19053
|
-
payload: object({ branch: string2().min(1), cwd: string2().min(1).optional() }).strict()
|
|
19054
|
-
}).strict(),
|
|
19055
|
-
object({
|
|
19056
|
-
operation: literal("youtrack.update"),
|
|
19057
|
-
payload: object({
|
|
19058
|
-
issueId: string2().min(1),
|
|
19059
|
-
markdown: string2().min(1),
|
|
19060
|
-
minutes: number2().positive().optional()
|
|
19061
|
-
}).strict()
|
|
19062
|
-
}).strict(),
|
|
19063
|
-
object({
|
|
19064
|
-
operation: literal("youtrack.time"),
|
|
19065
|
-
payload: object({
|
|
19066
|
-
issueId: string2().min(1),
|
|
19067
|
-
minutes: number2().positive(),
|
|
19068
|
-
text: string2().optional(),
|
|
19069
|
-
dateMs: number2().finite().optional()
|
|
19070
|
-
}).strict()
|
|
19071
|
-
}).strict(),
|
|
19072
|
-
object({
|
|
19073
|
-
operation: literal("youtrack.meeting"),
|
|
19074
|
-
payload: object({
|
|
19075
|
-
issueId: string2().min(1),
|
|
19076
|
-
minutes: number2().positive(),
|
|
19077
|
-
text: string2().min(1)
|
|
19078
|
-
}).strict()
|
|
19079
|
-
}).strict(),
|
|
19080
|
-
object({
|
|
19081
|
-
operation: literal("changelog.apply"),
|
|
19082
|
-
payload: object({
|
|
19083
|
-
entries: union([
|
|
19084
|
-
record(string2(), array(string2())),
|
|
19085
|
-
array(object({ category: string2().min(1), text: string2().min(1) }).strict())
|
|
19086
|
-
]).optional(),
|
|
19087
|
-
path: string2().optional(),
|
|
19088
|
-
normalize_only: boolean2().optional()
|
|
19089
|
-
}).strict()
|
|
19090
|
-
}).strict(),
|
|
19091
|
-
object({
|
|
19092
|
-
operation: literal("context.read"),
|
|
19093
|
-
payload: object({
|
|
19094
|
-
kind: _enum([
|
|
19095
|
-
"git",
|
|
19096
|
-
"pr",
|
|
19097
|
-
"youtrack",
|
|
19098
|
-
"github_issue",
|
|
19099
|
-
"gitlab_issue",
|
|
19100
|
-
"changelog",
|
|
19101
|
-
"release",
|
|
19102
|
-
"affected"
|
|
19103
|
-
]),
|
|
19104
|
-
range: string2().optional(),
|
|
19105
|
-
issueId: string2().optional(),
|
|
19106
|
-
issueUrl: string2().optional(),
|
|
19107
|
-
issueRef: string2().optional(),
|
|
19108
|
-
mode: string2().optional(),
|
|
19109
|
-
specPath: string2().optional(),
|
|
19110
|
-
planPath: string2().optional(),
|
|
19111
|
-
cwd: string2().min(1).optional()
|
|
19112
|
-
}).strict()
|
|
19113
|
-
}).strict()
|
|
19114
|
-
]);
|
|
19115
|
-
// packages/workit-core/src/core/task-engine.ts
|
|
19116
|
-
import { realpathSync as realpathSync6 } from "node:fs";
|
|
19117
|
-
|
|
19118
|
-
// packages/workit-core/src/core/policy-resolver.ts
|
|
19119
|
-
var resolverInputSchema = object({
|
|
19120
|
-
intent: intentSchema,
|
|
19121
|
-
assessment: assessmentSchema,
|
|
19122
|
-
constraints: array(constraintSchema),
|
|
19123
|
-
prior: object({
|
|
19124
|
-
decisions: array(decisionSchema),
|
|
19125
|
-
findings: array(findingSchema),
|
|
19126
|
-
requirements: array(requirementSchema)
|
|
19127
|
-
}).strict(),
|
|
19128
|
-
preferences: object({ fast: boolean2().optional(), thorough: boolean2().optional() }).strict().optional()
|
|
19129
|
-
}).strict();
|
|
19130
|
-
var compareCodeUnits3 = (left, right) => {
|
|
19131
|
-
const length = Math.min(left.length, right.length);
|
|
19132
|
-
for (let index = 0;index < length; index += 1) {
|
|
19133
|
-
const difference = left.charCodeAt(index) - right.charCodeAt(index);
|
|
19134
|
-
if (difference !== 0)
|
|
19135
|
-
return difference;
|
|
19136
|
-
}
|
|
19137
|
-
return left.length - right.length;
|
|
19138
|
-
};
|
|
19139
|
-
var stableUnique = (values) => [...new Set(values)].sort(compareCodeUnits3);
|
|
19140
|
-
var stableList = (values) => [...values].sort((left, right) => compareCodeUnits3(canonicalJson(left), canonicalJson(right)));
|
|
19141
|
-
var normalizedScope = (scope) => ({
|
|
19142
|
-
description: scope.description,
|
|
19143
|
-
paths: stableUnique(scope.paths),
|
|
19144
|
-
exclusions: stableUnique(scope.exclusions)
|
|
19145
|
-
});
|
|
19146
|
-
var normalizedRefList = (values) => stableList(values);
|
|
19147
|
-
var normalizeAssessment = (assessment) => ({
|
|
19148
|
-
facts: stableList(assessment.facts.map((fact) => ({ ...fact, refs: normalizedRefList(fact.refs) }))),
|
|
19149
|
-
signals: Object.fromEntries(Object.entries(assessment.signals).map(([name, signal]) => [
|
|
19150
|
-
name,
|
|
19151
|
-
{ ...signal, refs: normalizedRefList(signal.refs) }
|
|
19152
|
-
])),
|
|
19153
|
-
consequences: stableList(assessment.consequences.map((consequence) => ({
|
|
19154
|
-
...consequence,
|
|
19155
|
-
fact: { ...consequence.fact, refs: normalizedRefList(consequence.fact.refs) }
|
|
19156
|
-
}))),
|
|
19157
|
-
verification: stableList(assessment.verification.map((verification) => ({
|
|
19158
|
-
...verification,
|
|
19159
|
-
scope: normalizedScope(verification.scope),
|
|
19160
|
-
availableChecks: normalizedRefList(verification.availableChecks),
|
|
19161
|
-
gaps: stableUnique(verification.gaps)
|
|
19162
|
-
})))
|
|
19163
|
-
});
|
|
19164
|
-
var normalizeConstraint = (constraint) => ({
|
|
19165
|
-
...constraint,
|
|
19166
|
-
source: constraint.source,
|
|
19167
|
-
requires: stableList(constraint.requires.map((requirement) => ({
|
|
19168
|
-
...requirement,
|
|
19169
|
-
scope: normalizedScope(requirement.scope),
|
|
19170
|
-
refs: normalizedRefList(requirement.refs)
|
|
19171
|
-
})))
|
|
19172
|
-
});
|
|
19173
|
-
var normalizeDecision = (decision) => ({
|
|
19174
|
-
...decision,
|
|
19175
|
-
binding: {
|
|
19176
|
-
...decision.binding,
|
|
19177
|
-
scope: normalizedScope(decision.binding.scope),
|
|
19178
|
-
contentRefs: normalizedRefList(decision.binding.contentRefs)
|
|
19179
|
-
},
|
|
19180
|
-
requirementIds: stableUnique(decision.requirementIds)
|
|
19181
|
-
});
|
|
19182
|
-
var normalizeIntent = (intent) => ({
|
|
19183
|
-
...intent,
|
|
19184
|
-
scope: normalizedScope(intent.scope),
|
|
19185
|
-
authorityRefs: normalizedRefList(intent.authorityRefs)
|
|
19186
|
-
});
|
|
19187
|
-
var normalizePrior = (prior) => ({
|
|
19188
|
-
decisions: stableList(prior.decisions.map(normalizeDecision)),
|
|
19189
|
-
findings: stableList(prior.findings.map((finding) => ({
|
|
19190
|
-
...finding,
|
|
19191
|
-
scope: normalizedScope(finding.scope),
|
|
19192
|
-
refs: normalizedRefList(finding.refs),
|
|
19193
|
-
resolution: finding.resolution ? {
|
|
19194
|
-
...finding.resolution,
|
|
19195
|
-
evidenceIds: stableUnique(finding.resolution.evidenceIds),
|
|
19196
|
-
decisionIds: stableUnique(finding.resolution.decisionIds)
|
|
19197
|
-
} : null
|
|
19198
|
-
}))),
|
|
19199
|
-
requirements: stableList(prior.requirements.map((requirement) => ({
|
|
19200
|
-
...requirement,
|
|
19201
|
-
scope: normalizedScope(requirement.scope)
|
|
19202
|
-
})))
|
|
19203
|
-
});
|
|
19204
|
-
var invalidFields = (error) => ({
|
|
19205
|
-
fields: error.issues.map((issue) => ({
|
|
19206
|
-
path: issue.code === "unrecognized_keys" ? issue.keys.join(".") : issue.path.join("."),
|
|
19207
|
-
reason: issue.message
|
|
19208
|
-
}))
|
|
19209
|
-
});
|
|
19210
|
-
function normalizeResolverInput(input) {
|
|
19211
|
-
const parsed = resolverInputSchema.safeParse(input);
|
|
19212
|
-
if (!parsed.success)
|
|
19213
|
-
return failure("invalid_input", "resolver input is invalid", invalidFields(parsed.error));
|
|
19214
|
-
const value = parsed.data;
|
|
19215
|
-
const signals = value.assessment.signals;
|
|
19216
|
-
if (signals.behaviorChange.value === true && signals.mechanicalLowRisk.value === true)
|
|
19217
|
-
return failure("invalid_input", "behavioral change cannot be wholly mechanical", {
|
|
19218
|
-
fields: [
|
|
19219
|
-
{
|
|
19220
|
-
path: "assessment.signals",
|
|
19221
|
-
reason: "contradictory behaviorChange and mechanicalLowRisk"
|
|
19222
|
-
}
|
|
19223
|
-
]
|
|
19224
|
-
});
|
|
19225
|
-
const ids = value.constraints.map((constraint) => constraint.id);
|
|
19226
|
-
if (new Set(ids).size !== ids.length)
|
|
19227
|
-
return failure("invalid_input", "constraint IDs must be unique", {
|
|
19228
|
-
fields: [{ path: "constraints", reason: "duplicate constraint id" }]
|
|
19229
|
-
});
|
|
19230
|
-
if (value.preferences?.fast && value.preferences.thorough)
|
|
19231
|
-
return failure("invalid_input", "fast and thorough preferences contradict", {
|
|
19232
|
-
fields: [{ path: "preferences", reason: "fast and thorough cannot both be enabled" }]
|
|
19233
|
-
});
|
|
19234
|
-
const normalized = {
|
|
19235
|
-
intent: normalizeIntent(value.intent),
|
|
19236
|
-
assessment: normalizeAssessment(value.assessment),
|
|
19237
|
-
constraints: stableList(value.constraints.map(normalizeConstraint)),
|
|
19238
|
-
prior: normalizePrior(value.prior),
|
|
19239
|
-
...value.preferences ? { preferences: { ...value.preferences } } : {},
|
|
19240
|
-
policyVersion: POLICY_VERSION
|
|
19241
|
-
};
|
|
19242
|
-
return success(null, null, normalized);
|
|
19243
|
-
}
|
|
19244
|
-
var requirement = (spec) => ({
|
|
19245
|
-
...spec,
|
|
19246
|
-
id: requirementId({
|
|
19247
|
-
ruleId: spec.ruleId,
|
|
19248
|
-
scope: spec.scope,
|
|
19249
|
-
satisfaction: spec.satisfaction,
|
|
19250
|
-
before: spec.before,
|
|
19251
|
-
dependentAction: spec.dependentAction
|
|
19252
|
-
})
|
|
19253
|
-
});
|
|
19254
|
-
var signalReason = (input, name) => input.assessment.signals[name].reason;
|
|
19255
|
-
function resolveRequirements(input) {
|
|
19256
|
-
const { signals } = input.assessment;
|
|
19257
|
-
const scope = input.intent.scope;
|
|
19258
|
-
const requirements = [];
|
|
19259
|
-
const hasUnknownSignal = Object.values(signals).some((signal) => signal.value === "unknown");
|
|
19260
|
-
const hasUnknownFact = [
|
|
19261
|
-
...input.assessment.facts,
|
|
19262
|
-
...input.assessment.consequences.map(({ fact }) => fact)
|
|
19263
|
-
].some((fact) => fact.basis === "unknown");
|
|
19264
|
-
if (hasUnknownSignal || hasUnknownFact)
|
|
19265
|
-
requirements.push(requirement({
|
|
19266
|
-
ruleId: "consequential-unknown",
|
|
19267
|
-
dimension: "investigation",
|
|
19268
|
-
scope,
|
|
19269
|
-
reason: `Resolve consequential uncertainty before the dependent action: ${[
|
|
19270
|
-
...Object.entries(signals).filter(([, signal]) => signal.value === "unknown").map(([name]) => name),
|
|
19271
|
-
...hasUnknownFact ? ["unknown fact"] : []
|
|
19272
|
-
].join(", ")}`,
|
|
19273
|
-
satisfaction: "An observed or inferred fact resolves the uncertainty and records its supporting references.",
|
|
19274
|
-
before: "dependent_action",
|
|
19275
|
-
dependentAction: null,
|
|
19276
|
-
acceptanceAllowed: false
|
|
19277
|
-
}));
|
|
19278
|
-
if (signals.productChoiceOpen.value === true)
|
|
19279
|
-
requirements.push(requirement({
|
|
19280
|
-
ruleId: "product-decision",
|
|
19281
|
-
dimension: "decisions",
|
|
19282
|
-
scope,
|
|
19283
|
-
reason: `A consequential product choice remains open: ${signalReason(input, "productChoiceOpen")}`,
|
|
19284
|
-
satisfaction: "Present the material alternatives and record the user's decision before the dependent action.",
|
|
19285
|
-
before: "dependent_action",
|
|
19286
|
-
dependentAction: null,
|
|
19287
|
-
acceptanceAllowed: false
|
|
19288
|
-
}));
|
|
19289
|
-
const independentBehaviorReview = input.preferences?.thorough === true || input.assessment.consequences.some((consequence) => ["security", "data", "public_contract", "operations"].includes(consequence.area));
|
|
19290
|
-
if (signals.behaviorChange.value === true)
|
|
19291
|
-
requirements.push(requirement({
|
|
19292
|
-
ruleId: "behavioral-verification",
|
|
19293
|
-
dimension: "testing",
|
|
19294
|
-
scope,
|
|
19295
|
-
reason: `Behavior, side effects, permissions, or data handling may change: ${signalReason(input, "behaviorChange")}`,
|
|
19296
|
-
satisfaction: "A useful behavioral check passes against the affected behavior and current candidate.",
|
|
19297
|
-
before: "close",
|
|
19298
|
-
dependentAction: null,
|
|
19299
|
-
acceptanceAllowed: false
|
|
19300
|
-
}), requirement({
|
|
19301
|
-
ruleId: independentBehaviorReview ? "fresh-context-review" : "self-review",
|
|
19302
|
-
dimension: "review",
|
|
19303
|
-
scope,
|
|
19304
|
-
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.",
|
|
19305
|
-
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.",
|
|
19306
|
-
before: "close",
|
|
19307
|
-
dependentAction: null,
|
|
19308
|
-
acceptanceAllowed: !independentBehaviorReview
|
|
19309
|
-
}));
|
|
19310
|
-
else if (signals.mechanicalLowRisk.value === true)
|
|
19311
|
-
requirements.push(requirement({
|
|
19312
|
-
ruleId: "mechanical-existing-checks",
|
|
19313
|
-
dimension: "verification",
|
|
19314
|
-
scope,
|
|
19315
|
-
reason: `The change is demonstrably mechanical and low-risk: ${signalReason(input, "mechanicalLowRisk")}`,
|
|
19316
|
-
satisfaction: "Run the relevant existing checks for affected consumers; do not add tautological tests.",
|
|
19317
|
-
before: "close",
|
|
19318
|
-
dependentAction: null,
|
|
19319
|
-
acceptanceAllowed: true
|
|
19320
|
-
}), requirement({
|
|
19321
|
-
ruleId: input.preferences?.thorough ? "fresh-context-review" : "self-review",
|
|
19322
|
-
dimension: "review",
|
|
19323
|
-
scope,
|
|
19324
|
-
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.",
|
|
19325
|
-
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.",
|
|
19326
|
-
before: "close",
|
|
19327
|
-
dependentAction: null,
|
|
19328
|
-
acceptanceAllowed: !input.preferences?.thorough
|
|
19329
|
-
}));
|
|
19330
|
-
if (signals.behaviorChange.value === true || signals.mechanicalLowRisk.value === true)
|
|
19331
|
-
requirements.push(requirement({
|
|
19332
|
-
ruleId: "pre-pr-cleanup",
|
|
19333
|
-
dimension: "verification",
|
|
19334
|
-
scope,
|
|
19335
|
-
reason: "Implementation output must be deslopped before it is delivered.",
|
|
19336
|
-
satisfaction: "Run the workit-deslop pass and record passing check evidence, or record an approved limitation decision waiving cleanup.",
|
|
19337
|
-
before: "dependent_action",
|
|
19338
|
-
dependentAction: "hosting.pull_request",
|
|
19339
|
-
acceptanceAllowed: true
|
|
19340
|
-
}));
|
|
19341
|
-
if (signals.durableAgreementNeeded.value === true)
|
|
19342
|
-
requirements.push(requirement({
|
|
19343
|
-
ruleId: "durable-spec",
|
|
19344
|
-
dimension: "artifacts",
|
|
19345
|
-
scope,
|
|
19346
|
-
reason: `The work needs a durable agreement about intended behavior: ${signalReason(input, "durableAgreementNeeded")}`,
|
|
19347
|
-
satisfaction: "Record the agreed behavior in a durable specification before implementation writes.",
|
|
19348
|
-
before: "write",
|
|
19349
|
-
dependentAction: null,
|
|
19350
|
-
acceptanceAllowed: true
|
|
19351
|
-
}));
|
|
19352
|
-
if (signals.coordinationPlanNeeded.value === true)
|
|
19353
|
-
requirements.push(requirement({
|
|
19354
|
-
ruleId: "coordination-plan",
|
|
19355
|
-
dimension: "continuity",
|
|
19356
|
-
scope,
|
|
19357
|
-
reason: `Dependencies, sequencing, or resumption need durable coordination: ${signalReason(input, "coordinationPlanNeeded")}`,
|
|
19358
|
-
satisfaction: "Record useful sequencing, dependencies, and the next action in a compact plan.",
|
|
19359
|
-
before: "dependent_action",
|
|
19360
|
-
dependentAction: null,
|
|
19361
|
-
acceptanceAllowed: true
|
|
19362
|
-
}));
|
|
19363
|
-
if (signals.helperUseful.value === true && !input.preferences?.fast)
|
|
19364
|
-
requirements.push(requirement({
|
|
19365
|
-
ruleId: "helper-usefulness",
|
|
19366
|
-
dimension: "delegation",
|
|
19367
|
-
scope,
|
|
19368
|
-
reason: `Independent judgment or investigation justifies a scoped helper: ${signalReason(input, "helperUseful")}`,
|
|
19369
|
-
satisfaction: "Use a bounded helper only for the independent objective and reconcile its result.",
|
|
19370
|
-
before: "dependent_action",
|
|
19371
|
-
dependentAction: null,
|
|
19372
|
-
acceptanceAllowed: true
|
|
19215
|
+
var scopeCovers2 = scopeCovers;
|
|
19216
|
+
var checkPin = (assignment, beforeCandidateId, candidateId) => {
|
|
19217
|
+
const pin = assignment.candidateId ?? null;
|
|
19218
|
+
if (pin === null)
|
|
19219
|
+
return true;
|
|
19220
|
+
return (beforeCandidateId ?? null) === pin || (candidateId ?? null) === pin;
|
|
19221
|
+
};
|
|
19222
|
+
var resolveBinding = (evidence, pin, currentCandidateId) => {
|
|
19223
|
+
const bound = evidence.kind === "check" || evidence.kind === "review";
|
|
19224
|
+
const fallback = bound ? pin ?? currentCandidateId : null;
|
|
19225
|
+
return {
|
|
19226
|
+
beforeCandidateId: evidence.beforeCandidateId ?? fallback,
|
|
19227
|
+
candidateId: evidence.candidateId ?? fallback
|
|
19228
|
+
};
|
|
19229
|
+
};
|
|
19230
|
+
var findingVerificationPasses = (findingCandidateId, evidence) => evidence.status === "passed" && (evidence.kind === "check" || evidence.kind === "review") && ((findingCandidateId ?? null) === null || evidence.candidateId != null);
|
|
19231
|
+
var 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")));
|
|
19232
|
+
var 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 }));
|
|
19233
|
+
var evidenceMatchesRequirement = (kind, evidenceKind, dimension, ruleId) => {
|
|
19234
|
+
if (kind !== "passed")
|
|
19235
|
+
return false;
|
|
19236
|
+
if (dimension === "testing" || dimension === "verification")
|
|
19237
|
+
return evidenceKind === "check" || ruleId === "pre-pr-cleanup" && evidenceKind === "artifact";
|
|
19238
|
+
if (dimension === "review")
|
|
19239
|
+
return evidenceKind === "review";
|
|
19240
|
+
if (dimension === "investigation" || dimension === "challenge")
|
|
19241
|
+
return evidenceKind === "investigation";
|
|
19242
|
+
if (dimension === "artifacts" || dimension === "continuity")
|
|
19243
|
+
return evidenceKind === "artifact";
|
|
19244
|
+
return false;
|
|
19245
|
+
};
|
|
19246
|
+
var expectedKinds = (dimension, ruleId) => {
|
|
19247
|
+
if (dimension === "testing")
|
|
19248
|
+
return "check";
|
|
19249
|
+
if (dimension === "verification")
|
|
19250
|
+
return ruleId === "pre-pr-cleanup" ? "check or artifact" : "check";
|
|
19251
|
+
if (dimension === "review")
|
|
19252
|
+
return "review";
|
|
19253
|
+
if (dimension === "investigation" || dimension === "challenge")
|
|
19254
|
+
return "investigation";
|
|
19255
|
+
if (dimension === "artifacts" || dimension === "continuity")
|
|
19256
|
+
return "artifact";
|
|
19257
|
+
if (dimension === "decisions")
|
|
19258
|
+
return "decision";
|
|
19259
|
+
return "worker report";
|
|
19260
|
+
};
|
|
19261
|
+
function evaluateRequirements(task, workspace, capabilities, candidate, checkoutRoot, _caller) {
|
|
19262
|
+
const evidence = evaluateEvidence(task, candidate);
|
|
19263
|
+
if (task.policy && task.policy.policyVersion !== POLICY_VERSION)
|
|
19264
|
+
return task.policy.requirements.map((requirement) => ({
|
|
19265
|
+
requirementId: requirement.id,
|
|
19266
|
+
status: "unsatisfied",
|
|
19267
|
+
evidenceIds: [],
|
|
19268
|
+
decisionIds: [],
|
|
19269
|
+
reason: "stored policy version is unsupported; reassessment is required"
|
|
19373
19270
|
}));
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19388
|
-
|
|
19389
|
-
|
|
19390
|
-
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19271
|
+
return (task.policy?.requirements ?? []).map((requirement) => {
|
|
19272
|
+
const related = task.evidence.map((entry, index) => ({ entry, evaluation: evidence[index] })).filter(({ entry }) => entry.data.requirementIds.includes(requirement.id));
|
|
19273
|
+
const passed = related.filter(({ entry, evaluation }) => {
|
|
19274
|
+
if (!evidenceMatchesRequirement(evaluation.status, entry.data.kind, requirement.dimension, requirement.ruleId))
|
|
19275
|
+
return false;
|
|
19276
|
+
if ((entry.data.kind === "check" || entry.data.kind === "review") && (!entry.data.beforeCandidateId || !entry.data.candidateId || entry.data.beforeCandidateId !== entry.data.candidateId))
|
|
19277
|
+
return false;
|
|
19278
|
+
if (requirement.dimension !== "review")
|
|
19279
|
+
return true;
|
|
19280
|
+
const reviewSession = sessionFromRef(entry.data.reviewContext);
|
|
19281
|
+
const sameImplementation = sameSession(reviewSession, task.intent.provenance.session);
|
|
19282
|
+
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));
|
|
19283
|
+
return entry.data.kind === "review" && reviewSession !== null && sameSession(reviewSession, entry.provenance.session) && (requirement.ruleId === "self-review" || !sameImplementation && !sameEvidenceSession);
|
|
19284
|
+
});
|
|
19285
|
+
if (passed.length) {
|
|
19286
|
+
const currentId = candidate?.id ?? null;
|
|
19287
|
+
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;
|
|
19288
|
+
if (withRed.length)
|
|
19289
|
+
return {
|
|
19290
|
+
requirementId: requirement.id,
|
|
19291
|
+
status: "satisfied",
|
|
19292
|
+
evidenceIds: withRed.map(({ entry }) => entry.id),
|
|
19293
|
+
decisionIds: [],
|
|
19294
|
+
reason: "fresh applicable evidence passed"
|
|
19295
|
+
};
|
|
19296
|
+
if (requirement.dimension === "testing")
|
|
19297
|
+
return {
|
|
19298
|
+
requirementId: requirement.id,
|
|
19299
|
+
status: "unsatisfied",
|
|
19300
|
+
evidenceIds: [],
|
|
19301
|
+
decisionIds: [],
|
|
19302
|
+
reason: "testing requirement has GREEN evidence but no preceding RED"
|
|
19303
|
+
};
|
|
19394
19304
|
}
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19305
|
+
if (requirement.dimension === "delegation") {
|
|
19306
|
+
const dot = (scope) => scope.paths.length > 0 ? scope : { ...scope, paths: ["."] };
|
|
19307
|
+
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))));
|
|
19308
|
+
if (reconciled)
|
|
19309
|
+
return {
|
|
19310
|
+
requirementId: requirement.id,
|
|
19311
|
+
status: "satisfied",
|
|
19312
|
+
evidenceIds: [],
|
|
19313
|
+
decisionIds: [],
|
|
19314
|
+
reason: "bounded helper completed and its result is recorded"
|
|
19315
|
+
};
|
|
19316
|
+
}
|
|
19317
|
+
const decisions = requirement.dimension === "decisions" ? applicableRequirementDecision(task, workspace, requirement, checkoutRoot) : [];
|
|
19318
|
+
if (decisions.length)
|
|
19319
|
+
return {
|
|
19320
|
+
requirementId: requirement.id,
|
|
19321
|
+
status: "satisfied",
|
|
19322
|
+
evidenceIds: [],
|
|
19323
|
+
decisionIds: decisions.map((decision) => decision.id),
|
|
19324
|
+
reason: "an applicable approved or stated decision satisfies the requirement"
|
|
19325
|
+
};
|
|
19326
|
+
const limitations = requirement.acceptanceAllowed ? applicableDecision2(task, workspace, requirement, checkoutRoot) : [];
|
|
19327
|
+
if (limitations.length)
|
|
19328
|
+
return {
|
|
19329
|
+
requirementId: requirement.id,
|
|
19330
|
+
status: "accepted_limitation",
|
|
19331
|
+
evidenceIds: [],
|
|
19332
|
+
decisionIds: limitations.map((decision) => task.decisions.find((entry) => entry.data === decision).id),
|
|
19333
|
+
reason: "an applicable approved limitation permits the missing evidence"
|
|
19334
|
+
};
|
|
19335
|
+
const unavailable = capabilities.some((capability) => capability.assurance === "unavailable" && (capability.name === requirement.dimension || capability.surface === requirement.dimension));
|
|
19336
|
+
if (!unavailable && related.length > 0 && !passed.length)
|
|
19337
|
+
return {
|
|
19338
|
+
requirementId: requirement.id,
|
|
19339
|
+
status: "unsatisfied",
|
|
19340
|
+
evidenceIds: related.map(({ entry }) => entry.id),
|
|
19341
|
+
decisionIds: [],
|
|
19342
|
+
reason: `no passing evidence (needs kind:${expectedKinds(requirement.dimension, requirement.ruleId)})`
|
|
19343
|
+
};
|
|
19344
|
+
return {
|
|
19345
|
+
requirementId: requirement.id,
|
|
19346
|
+
status: unavailable ? "unavailable" : "unsatisfied",
|
|
19347
|
+
evidenceIds: related.map(({ entry }) => entry.id),
|
|
19348
|
+
decisionIds: [],
|
|
19349
|
+
reason: unavailable ? "required capability is unavailable" : "no fresh passing evidence"
|
|
19350
|
+
};
|
|
19351
|
+
});
|
|
19352
|
+
}
|
|
19353
|
+
function evaluateClosure(requestedOutcome, view) {
|
|
19354
|
+
if (requestedOutcome !== "stopped" && !view.task.policy)
|
|
19355
|
+
return failure("requirements_unsatisfied", "task has not been assessed");
|
|
19356
|
+
if (view.task.policy && view.task.policy.policyVersion !== POLICY_VERSION)
|
|
19357
|
+
return failure("requirements_unsatisfied", "stored policy version is unsupported; reassessment is required");
|
|
19358
|
+
const evaluations = view.requirements;
|
|
19359
|
+
const openFindings = view.task.findings.filter((entry) => entry.data.disposition === "open");
|
|
19360
|
+
if (requestedOutcome !== "stopped" && openFindings.length)
|
|
19361
|
+
return failure("requirements_unsatisfied", "open findings must be resolved before closure");
|
|
19362
|
+
if (requestedOutcome !== "stopped") {
|
|
19363
|
+
const evidenceById = new Map(view.evidence.map((entry) => [entry.evidenceId, entry.status]));
|
|
19364
|
+
for (const entry of view.task.findings) {
|
|
19365
|
+
if (entry.data.disposition === "fixed") {
|
|
19366
|
+
const verified = entry.data.resolution?.evidenceIds.some((id) => {
|
|
19367
|
+
const evidence = view.task.evidence.find((item) => item.id === id);
|
|
19368
|
+
if (!evidence)
|
|
19369
|
+
return false;
|
|
19370
|
+
return findingVerificationPasses(entry.data.candidateId, {
|
|
19371
|
+
kind: evidence.data.kind,
|
|
19372
|
+
candidateId: evidence.data.candidateId,
|
|
19373
|
+
status: evidenceById.get(id) ?? "missing"
|
|
19374
|
+
});
|
|
19375
|
+
});
|
|
19376
|
+
if (!verified)
|
|
19377
|
+
return failure("requirements_unsatisfied", "fixed findings require current verification");
|
|
19378
|
+
}
|
|
19379
|
+
if (entry.data.disposition === "deferred") {
|
|
19380
|
+
const valid = entry.data.resolution?.decisionIds.some((id) => {
|
|
19381
|
+
const decisionEntry = view.task.decisions.find((item) => item.id === id);
|
|
19382
|
+
const decision = decisionEntry?.data;
|
|
19383
|
+
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)));
|
|
19384
|
+
});
|
|
19385
|
+
if (!valid)
|
|
19386
|
+
return failure("requirements_unsatisfied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
|
|
19387
|
+
}
|
|
19388
|
+
}
|
|
19389
|
+
}
|
|
19390
|
+
const blocking = evaluations.filter((item) => {
|
|
19391
|
+
if (item.status !== "unsatisfied" && item.status !== "unavailable")
|
|
19398
19392
|
return false;
|
|
19399
|
-
|
|
19400
|
-
return
|
|
19393
|
+
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
19394
|
+
return !requirement || requirement.before === "close";
|
|
19395
|
+
});
|
|
19396
|
+
if (requestedOutcome !== "stopped" && blocking.length)
|
|
19397
|
+
return failure("requirements_unsatisfied", "applicable requirements are unsatisfied", {
|
|
19398
|
+
requirementIds: blocking.map((item) => item.requirementId),
|
|
19399
|
+
requirements: blocking.map((item) => {
|
|
19400
|
+
const requirement = view.task.policy?.requirements.find((candidate) => candidate.id === item.requirementId);
|
|
19401
|
+
return {
|
|
19402
|
+
requirementId: item.requirementId,
|
|
19403
|
+
ruleId: requirement?.ruleId ?? "unknown",
|
|
19404
|
+
reason: item.reason,
|
|
19405
|
+
satisfaction: requirement?.satisfaction ?? "",
|
|
19406
|
+
dependentAction: requirement?.dependentAction ?? null
|
|
19407
|
+
};
|
|
19408
|
+
})
|
|
19409
|
+
});
|
|
19410
|
+
const accepted = evaluations.filter((item) => item.status === "accepted_limitation");
|
|
19411
|
+
if (requestedOutcome === "verified" && accepted.length)
|
|
19412
|
+
return failure("requirements_unsatisfied", "accepted limitations cannot be reported as verified", {
|
|
19413
|
+
requirementIds: accepted.map((item) => item.requirementId)
|
|
19414
|
+
});
|
|
19415
|
+
const evidenceIds = [
|
|
19416
|
+
...new Set([
|
|
19417
|
+
...evaluations.flatMap((item) => item.evidenceIds),
|
|
19418
|
+
...view.task.findings.flatMap((item) => item.data.resolution?.evidenceIds ?? [])
|
|
19419
|
+
])
|
|
19420
|
+
];
|
|
19421
|
+
const decisionIds = [
|
|
19422
|
+
...new Set([
|
|
19423
|
+
...evaluations.flatMap((item) => item.decisionIds),
|
|
19424
|
+
...view.task.findings.flatMap((item) => item.data.resolution?.decisionIds ?? [])
|
|
19425
|
+
])
|
|
19426
|
+
];
|
|
19427
|
+
return success(null, null, {
|
|
19428
|
+
outcome: requestedOutcome === "stopped" ? "stopped" : accepted.length ? "accepted_limitations" : "verified",
|
|
19429
|
+
evidenceIds,
|
|
19430
|
+
decisionIds,
|
|
19431
|
+
requirementIds: evaluations.map((item) => item.requirementId)
|
|
19401
19432
|
});
|
|
19402
19433
|
}
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
}
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19434
|
+
|
|
19435
|
+
// packages/workit-core/src/core/methods.ts
|
|
19436
|
+
var METHODS = {
|
|
19437
|
+
"workit-challenge": { dimensions: ["challenge", "decisions"] },
|
|
19438
|
+
"workit-behavioral-tdd": { dimensions: ["testing"], ruleIds: ["mechanical-existing-checks"] },
|
|
19439
|
+
"workit-review": { dimensions: ["review"], ruleIds: ["fresh-context-review", "self-review"] },
|
|
19440
|
+
"workit-plan": { dimensions: ["artifacts", "continuity"] },
|
|
19441
|
+
"workit-implement": { dimensions: ["delegation"] },
|
|
19442
|
+
"workit-debug": {},
|
|
19443
|
+
"workit-handoff": {},
|
|
19444
|
+
"workit-deslop": { ruleIds: ["pre-pr-cleanup"] }
|
|
19445
|
+
};
|
|
19446
|
+
var methodMatches = (definition, requirement) => definition.dimensions?.includes(requirement.dimension) === true || definition.ruleIds?.includes(requirement.ruleId) === true;
|
|
19447
|
+
var assuranceFor = (id, definition, capabilities) => {
|
|
19448
|
+
const keys = new Set([
|
|
19449
|
+
id,
|
|
19450
|
+
...definition.dimensions ?? [],
|
|
19451
|
+
...definition.ruleIds ?? []
|
|
19452
|
+
]);
|
|
19453
|
+
const matches = capabilities.filter((capability) => keys.has(capability.name) || keys.has(capability.surface));
|
|
19454
|
+
if (id === "workit-review" && matches.length === 0)
|
|
19455
|
+
return { assurance: "unavailable", reasons: ["independent review capability is unavailable"] };
|
|
19456
|
+
if (matches.some((capability) => capability.assurance === "unavailable"))
|
|
19457
|
+
return {
|
|
19458
|
+
assurance: "unavailable",
|
|
19459
|
+
reasons: matches.filter((capability) => capability.assurance === "unavailable").map((capability) => capability.reason)
|
|
19460
|
+
};
|
|
19461
|
+
if (matches.some((capability) => capability.assurance === "enforced"))
|
|
19462
|
+
return { assurance: "enforced", reasons: matches.map((capability) => capability.reason) };
|
|
19463
|
+
return { assurance: "agent_guided", reasons: matches.map((capability) => capability.reason) };
|
|
19464
|
+
};
|
|
19465
|
+
function selectMethods(policy, capabilities) {
|
|
19466
|
+
return Object.entries(METHODS).flatMap(([id, definition]) => {
|
|
19467
|
+
const requirements = policy.requirements.filter((requirement) => methodMatches(definition, requirement));
|
|
19468
|
+
if (requirements.length === 0)
|
|
19469
|
+
return [];
|
|
19470
|
+
const capability = assuranceFor(id, definition, capabilities);
|
|
19471
|
+
const reasons = [
|
|
19472
|
+
...new Set(requirements.map((requirement) => requirement.reason)),
|
|
19473
|
+
...capability.reasons
|
|
19474
|
+
];
|
|
19475
|
+
if (capability.assurance === "unavailable")
|
|
19476
|
+
reasons.unshift("required capability is unavailable");
|
|
19477
|
+
return [{ id, reason: reasons.join("; "), assurance: capability.assurance }];
|
|
19478
|
+
});
|
|
19417
19479
|
}
|
|
19418
|
-
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
if (
|
|
19422
|
-
|
|
19423
|
-
const
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
const
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
|
|
19430
|
-
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19480
|
+
|
|
19481
|
+
// packages/workit-core/src/core/task-context.ts
|
|
19482
|
+
function reconcileResume(view, observations = []) {
|
|
19483
|
+
if (observations.length > 0)
|
|
19484
|
+
return failure("permission_denied", "worker observations require native host verification");
|
|
19485
|
+
const candidate = captureCandidate(view.workspace.root, view.task.intent.data.scope, []);
|
|
19486
|
+
if (!candidate.ok)
|
|
19487
|
+
return candidate;
|
|
19488
|
+
const staleEvidenceIds = evaluateEvidence(view.task, candidate.data).filter((entry) => entry.status === "stale").map((entry) => entry.evidenceId);
|
|
19489
|
+
const blockers = [...view.task.progress.blockers];
|
|
19490
|
+
if (view.task.workers.some((entry) => isUncertainWorker(entry.data.state)))
|
|
19491
|
+
blockers.push({
|
|
19492
|
+
reason: "worker state requires reconciliation",
|
|
19493
|
+
dependentAction: "resume",
|
|
19494
|
+
refs: []
|
|
19495
|
+
});
|
|
19496
|
+
return success(null, null, {
|
|
19497
|
+
candidate: candidate.data,
|
|
19498
|
+
staleEvidenceIds,
|
|
19499
|
+
workerUpdates: [],
|
|
19500
|
+
blockers,
|
|
19501
|
+
reassessmentRequired: view.task.policy?.policyVersion !== POLICY_VERSION
|
|
19502
|
+
});
|
|
19503
|
+
}
|
|
19504
|
+
var COMPACT_MAX_BYTES = 4096;
|
|
19505
|
+
var COMPACT_MAX_ITEMS = 8;
|
|
19506
|
+
var COMPACT_TEXT_BYTES = 128;
|
|
19507
|
+
var sensitiveUrl = /\bhttps?:\/\/[^/\s:@]+:[^@\s]+@/gi;
|
|
19508
|
+
var sensitiveValue = /(?:token|secret|password|passwd|api[-_ ]?key|private[-_ ]?key|authorization)\s*[:=]\s*(?:bearer\s+)?\S+|\bbearer\s+\S+/gi;
|
|
19509
|
+
var privateKey = /-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi;
|
|
19510
|
+
var compactText = (value, limit) => value === null ? null : value.replace(privateKey, "<redacted-private-key>").replace(sensitiveUrl, "<redacted-url>").replace(sensitiveValue, (match) => {
|
|
19511
|
+
const separator = match.search(/[:=]/u);
|
|
19512
|
+
if (separator >= 0)
|
|
19513
|
+
return `${match.slice(0, separator)}=<redacted>`;
|
|
19514
|
+
const space = match.search(/\s/u);
|
|
19515
|
+
return `${match.slice(0, space)} <redacted>`;
|
|
19516
|
+
}).slice(0, limit);
|
|
19517
|
+
var compactBytes = (value) => new TextEncoder().encode(value).byteLength;
|
|
19518
|
+
var compactTimestamp = (value) => `${value.slice(0, 19)}.${value.slice(20, -1).padEnd(9, "0")}`;
|
|
19519
|
+
var compactDecisionChoice = (entry) => {
|
|
19520
|
+
const stated = entry.data.binding.statedChoice?.text;
|
|
19521
|
+
const approved = entry.data.response === "approved" ? entry.data.binding.approvedContent : "";
|
|
19522
|
+
const source = stated?.trim() || approved.trim() || null;
|
|
19523
|
+
return compactText(source, COMPACT_TEXT_BYTES);
|
|
19524
|
+
};
|
|
19525
|
+
var compactReference = (ref) => {
|
|
19526
|
+
if (ref.kind === "file")
|
|
19527
|
+
return {
|
|
19528
|
+
kind: "file",
|
|
19529
|
+
path: compactText(ref.path, COMPACT_TEXT_BYTES) ?? ""
|
|
19530
|
+
};
|
|
19531
|
+
if (ref.kind === "record")
|
|
19532
|
+
return {
|
|
19533
|
+
kind: "record",
|
|
19534
|
+
collection: ref.collection,
|
|
19535
|
+
id: ref.id
|
|
19536
|
+
};
|
|
19537
|
+
return { kind: ref.kind };
|
|
19538
|
+
};
|
|
19539
|
+
function compactTaskContext(view) {
|
|
19540
|
+
const decisions = view.task.decisions.slice().sort((left, right) => {
|
|
19541
|
+
const leftAt = compactTimestamp(left.recordedAt);
|
|
19542
|
+
const rightAt = compactTimestamp(right.recordedAt);
|
|
19543
|
+
if (leftAt !== rightAt)
|
|
19544
|
+
return leftAt > rightAt ? -1 : 1;
|
|
19545
|
+
return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
|
|
19546
|
+
}).slice(0, COMPACT_MAX_ITEMS).map((entry) => ({
|
|
19547
|
+
id: entry.id,
|
|
19548
|
+
purpose: entry.data.purpose,
|
|
19549
|
+
status: entry.data.response,
|
|
19550
|
+
digest: entry.data.digest,
|
|
19551
|
+
choice: compactDecisionChoice(entry) || `task.inspect taskId=${view.task.id} view=full; decision=${entry.id}`,
|
|
19552
|
+
references: entry.data.binding.contentRefs.slice(0, 1).map(compactReference)
|
|
19553
|
+
}));
|
|
19554
|
+
const methods = view.task.policy ? selectMethods(view.task.policy, view.capabilities).map((method) => ({
|
|
19555
|
+
id: method.id,
|
|
19556
|
+
assurance: method.assurance,
|
|
19557
|
+
reason: compactText(method.reason, COMPACT_TEXT_BYTES) ?? ""
|
|
19558
|
+
})) : [];
|
|
19559
|
+
const gaps = Array.from(new Set([
|
|
19560
|
+
...view.evidence.filter((entry) => entry.status === "stale").map((entry) => `stale evidence: ${entry.evidenceId}`),
|
|
19561
|
+
...view.requirements.filter((entry) => entry.status !== "satisfied").map((entry) => entry.reason),
|
|
19562
|
+
...view.task.progress.blockers.map((entry) => entry.reason)
|
|
19563
|
+
])).sort().slice(0, COMPACT_MAX_ITEMS).map((gap) => compactText(gap, COMPACT_TEXT_BYTES));
|
|
19564
|
+
const context = {
|
|
19565
|
+
objective: compactText(view.task.intent.data.objective, COMPACT_TEXT_BYTES) ?? "",
|
|
19566
|
+
status: view.task.status,
|
|
19567
|
+
decisions,
|
|
19568
|
+
methods,
|
|
19569
|
+
gaps,
|
|
19570
|
+
nextAction: compactText(view.task.progress.nextAction, COMPACT_TEXT_BYTES)
|
|
19571
|
+
};
|
|
19572
|
+
let encoded = JSON.stringify(context);
|
|
19573
|
+
while (compactBytes(encoded) > COMPACT_MAX_BYTES && (context.decisions.length || context.methods.length || context.gaps.length)) {
|
|
19574
|
+
if (context.gaps.length)
|
|
19575
|
+
context.gaps.pop();
|
|
19576
|
+
else if (context.decisions.length)
|
|
19577
|
+
context.decisions.pop();
|
|
19578
|
+
else
|
|
19579
|
+
context.methods.pop();
|
|
19580
|
+
encoded = JSON.stringify(context);
|
|
19581
|
+
}
|
|
19582
|
+
if (compactBytes(encoded) > COMPACT_MAX_BYTES) {
|
|
19583
|
+
context.objective = compactText(context.objective, 64) ?? "";
|
|
19584
|
+
context.nextAction = compactText(context.nextAction, 64);
|
|
19585
|
+
encoded = JSON.stringify(context);
|
|
19586
|
+
}
|
|
19587
|
+
return encoded;
|
|
19443
19588
|
}
|
|
19589
|
+
var exportDigest = (bundle) => sha256({
|
|
19590
|
+
schemaVersion: bundle.schemaVersion,
|
|
19591
|
+
exportedAt: bundle.exportedAt,
|
|
19592
|
+
sourceWorkspaceId: bundle.sourceWorkspaceId,
|
|
19593
|
+
task: bundle.task
|
|
19594
|
+
});
|
|
19444
19595
|
|
|
19445
19596
|
// packages/workit-core/src/core/task-engine.ts
|
|
19446
19597
|
var provenance = (context, kind = context.provenanceKind ?? "host_observed") => ({
|
|
@@ -21128,14 +21279,29 @@ class WorkitCore {
|
|
|
21128
21279
|
writer: evaluationWorkspace.writer
|
|
21129
21280
|
});
|
|
21130
21281
|
}
|
|
21131
|
-
|
|
21282
|
+
compactContext(taskId) {
|
|
21283
|
+
const root = this.contextRootError();
|
|
21284
|
+
if (!root.ok)
|
|
21285
|
+
return root;
|
|
21286
|
+
const task = this.store.readTask(taskId);
|
|
21287
|
+
if (!task.ok)
|
|
21288
|
+
return task;
|
|
21289
|
+
const helper = this.helperTaskGuard(task.data, true);
|
|
21290
|
+
if (!helper.ok)
|
|
21291
|
+
return helper;
|
|
21292
|
+
const view = this.view(task.data, false);
|
|
21293
|
+
if (!view.ok)
|
|
21294
|
+
return view;
|
|
21295
|
+
return success(view.revision, view.workspaceRevision, compactTaskContext(view.data));
|
|
21296
|
+
}
|
|
21297
|
+
view(task, capture = true) {
|
|
21132
21298
|
const workspace = this.store.readWorkspace();
|
|
21133
21299
|
if (!workspace.ok)
|
|
21134
21300
|
return workspace;
|
|
21135
21301
|
if (!workspace.data)
|
|
21136
21302
|
return failure("not_found", "workspace not found");
|
|
21137
21303
|
const historical = task.status === "closed" ? task.candidates.at(-1) : undefined;
|
|
21138
|
-
const current = historical ? success(null, null, historical) : captureCandidate(this.store.root, task.intent.data.scope, environment());
|
|
21304
|
+
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);
|
|
21139
21305
|
if (!current.ok)
|
|
21140
21306
|
return current;
|
|
21141
21307
|
const evaluationWorkspace = task.status === "closed" ? { ...workspace.data, writer: null } : workspace.data;
|
|
@@ -21407,6 +21573,122 @@ class WorkitCore {
|
|
|
21407
21573
|
return this.summary(changed.data.task);
|
|
21408
21574
|
}
|
|
21409
21575
|
}
|
|
21576
|
+
|
|
21577
|
+
// packages/workit-core/src/core/session-context.ts
|
|
21578
|
+
var cache = new Map;
|
|
21579
|
+
// packages/workit-core/src/core/external-action.ts
|
|
21580
|
+
var chainStepSchema = union([
|
|
21581
|
+
string2().min(1),
|
|
21582
|
+
object({ branch: string2().min(1) }).strict(),
|
|
21583
|
+
object({ pr: literal(true) }).strict()
|
|
21584
|
+
]);
|
|
21585
|
+
var externalActionSchema = discriminatedUnion("operation", [
|
|
21586
|
+
object({
|
|
21587
|
+
operation: literal("git.branch_setup"),
|
|
21588
|
+
payload: object({
|
|
21589
|
+
action: _enum(["setup", "reapply_stash"]).optional(),
|
|
21590
|
+
sdd_dir: string2().optional(),
|
|
21591
|
+
target_branch: string2().optional(),
|
|
21592
|
+
stash: _enum(["yes", "no"]).optional(),
|
|
21593
|
+
cwd: string2().min(1).optional()
|
|
21594
|
+
}).strict()
|
|
21595
|
+
}).strict(),
|
|
21596
|
+
object({
|
|
21597
|
+
operation: literal("git.commit"),
|
|
21598
|
+
payload: object({
|
|
21599
|
+
message: string2().min(1).optional(),
|
|
21600
|
+
plan_steps: array(chainStepSchema).min(1).max(32).optional(),
|
|
21601
|
+
plan_branch: string2().min(1).optional(),
|
|
21602
|
+
cwd: string2().min(1).optional()
|
|
21603
|
+
}).strict()
|
|
21604
|
+
}).strict(),
|
|
21605
|
+
object({
|
|
21606
|
+
operation: literal("git.push"),
|
|
21607
|
+
payload: object({ branch: string2().min(1).optional(), cwd: string2().min(1).optional() }).strict()
|
|
21608
|
+
}).strict(),
|
|
21609
|
+
object({
|
|
21610
|
+
operation: literal("hosting.pull_request"),
|
|
21611
|
+
payload: object({
|
|
21612
|
+
title: string2().min(1),
|
|
21613
|
+
body: string2().optional(),
|
|
21614
|
+
draft: boolean2().optional(),
|
|
21615
|
+
target_branch: string2().optional(),
|
|
21616
|
+
babysit: boolean2().optional(),
|
|
21617
|
+
cwd: string2().min(1).optional()
|
|
21618
|
+
}).strict()
|
|
21619
|
+
}).strict(),
|
|
21620
|
+
object({
|
|
21621
|
+
operation: literal("hosting.merge"),
|
|
21622
|
+
payload: object({
|
|
21623
|
+
target_branch: string2().min(1).optional(),
|
|
21624
|
+
source_branch: string2().min(1).optional(),
|
|
21625
|
+
cwd: string2().min(1).optional()
|
|
21626
|
+
}).strict()
|
|
21627
|
+
}).strict(),
|
|
21628
|
+
object({
|
|
21629
|
+
operation: literal("hosting.delete_branch"),
|
|
21630
|
+
payload: object({ branch: string2().min(1), cwd: string2().min(1).optional() }).strict()
|
|
21631
|
+
}).strict(),
|
|
21632
|
+
object({
|
|
21633
|
+
operation: literal("youtrack.update"),
|
|
21634
|
+
payload: object({
|
|
21635
|
+
issueId: string2().min(1),
|
|
21636
|
+
markdown: string2().min(1),
|
|
21637
|
+
minutes: number2().positive().optional()
|
|
21638
|
+
}).strict()
|
|
21639
|
+
}).strict(),
|
|
21640
|
+
object({
|
|
21641
|
+
operation: literal("youtrack.time"),
|
|
21642
|
+
payload: object({
|
|
21643
|
+
issueId: string2().min(1),
|
|
21644
|
+
minutes: number2().positive(),
|
|
21645
|
+
text: string2().optional(),
|
|
21646
|
+
dateMs: number2().finite().optional()
|
|
21647
|
+
}).strict()
|
|
21648
|
+
}).strict(),
|
|
21649
|
+
object({
|
|
21650
|
+
operation: literal("youtrack.meeting"),
|
|
21651
|
+
payload: object({
|
|
21652
|
+
issueId: string2().min(1),
|
|
21653
|
+
minutes: number2().positive(),
|
|
21654
|
+
text: string2().min(1)
|
|
21655
|
+
}).strict()
|
|
21656
|
+
}).strict(),
|
|
21657
|
+
object({
|
|
21658
|
+
operation: literal("changelog.apply"),
|
|
21659
|
+
payload: object({
|
|
21660
|
+
entries: union([
|
|
21661
|
+
record(string2(), array(string2())),
|
|
21662
|
+
array(object({ category: string2().min(1), text: string2().min(1) }).strict())
|
|
21663
|
+
]).optional(),
|
|
21664
|
+
path: string2().optional(),
|
|
21665
|
+
normalize_only: boolean2().optional()
|
|
21666
|
+
}).strict()
|
|
21667
|
+
}).strict(),
|
|
21668
|
+
object({
|
|
21669
|
+
operation: literal("context.read"),
|
|
21670
|
+
payload: object({
|
|
21671
|
+
kind: _enum([
|
|
21672
|
+
"git",
|
|
21673
|
+
"pr",
|
|
21674
|
+
"youtrack",
|
|
21675
|
+
"github_issue",
|
|
21676
|
+
"gitlab_issue",
|
|
21677
|
+
"changelog",
|
|
21678
|
+
"release",
|
|
21679
|
+
"affected"
|
|
21680
|
+
]),
|
|
21681
|
+
range: string2().optional(),
|
|
21682
|
+
issueId: string2().optional(),
|
|
21683
|
+
issueUrl: string2().optional(),
|
|
21684
|
+
issueRef: string2().optional(),
|
|
21685
|
+
mode: string2().optional(),
|
|
21686
|
+
specPath: string2().optional(),
|
|
21687
|
+
planPath: string2().optional(),
|
|
21688
|
+
cwd: string2().min(1).optional()
|
|
21689
|
+
}).strict()
|
|
21690
|
+
}).strict()
|
|
21691
|
+
]);
|
|
21410
21692
|
// packages/workit-core/src/core.ts
|
|
21411
21693
|
var revision2 = /^[A-Za-z0-9@][A-Za-z0-9@._/~^{}-]*$/;
|
|
21412
21694
|
function gitRevisionParts(value) {
|