@brainervirus/workit-core 1.0.8 → 1.0.10
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/package.json +1 -1
- package/skills/workit-babysit/SKILL.md +3 -1
- package/skills/workit-plan/SKILL.md +14 -2
- package/src/core/authority.ts +21 -2
- package/src/core/branch.ts +45 -14
- package/src/core/external-action-effects.ts +192 -9
- package/src/core/external-action.ts +190 -2
- package/src/core/methods.ts +13 -2
- package/src/core/policy-resolver.ts +2 -2
- package/src/core/route-intent.ts +51 -0
- package/src/core/task-context.ts +16 -7
- package/src/core/task-contract.ts +57 -3
- package/src/core/task-engine.ts +40 -27
- package/src/core/task-evaluation.ts +34 -5
- package/src/core/task-store.ts +97 -17
- package/src/core/workers.ts +6 -0
- package/src/core.ts +10 -1
package/src/core/task-engine.ts
CHANGED
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
} from "./task-context";
|
|
59
59
|
import {
|
|
60
60
|
assertProductWriteAllowed,
|
|
61
|
+
isUncertainWorker,
|
|
61
62
|
type CallerContext,
|
|
62
63
|
type NativeWorkerObservation,
|
|
63
64
|
type NativeWorkerVerification,
|
|
@@ -343,10 +344,10 @@ const applyWorkerLifecycle = (input: ObserveWorkerLifecycleInput): Result<Entry<
|
|
|
343
344
|
const notStarted = input.dispatch === true;
|
|
344
345
|
if (notStarted && (input.state !== "stopped" || input.session !== null))
|
|
345
346
|
return failure("invalid_input", "a never-dispatched worker stops with no session");
|
|
346
|
-
if (notStarted &&
|
|
347
|
-
return failure("invalid_transition", "worker is no longer awaiting dispatch");
|
|
348
|
-
if (notStarted && (entry.data.session !== null || entry.data.state === "running"))
|
|
347
|
+
if (notStarted && entry.data.session !== null)
|
|
349
348
|
return failure("invalid_transition", "worker already has an observed session");
|
|
349
|
+
if (notStarted && !["dispatching", "cancelling"].includes(entry.data.state))
|
|
350
|
+
return failure("invalid_transition", "worker launch was not claimed");
|
|
350
351
|
if (
|
|
351
352
|
(input.state === "running" ||
|
|
352
353
|
input.state === "cancelling" ||
|
|
@@ -360,11 +361,16 @@ const applyWorkerLifecycle = (input: ObserveWorkerLifecycleInput): Result<Entry<
|
|
|
360
361
|
return failure("invalid_transition", "worker has not started");
|
|
361
362
|
if (input.state === "running" && entry.data.state === "stopped")
|
|
362
363
|
return failure("invalid_transition", "stopped worker cannot run again");
|
|
364
|
+
const terminalCancel = entry.data.state === "cancelling" && input.state === "running";
|
|
363
365
|
const nextEntry = {
|
|
364
366
|
...entry,
|
|
365
367
|
recordedAt: input.now ?? entry.recordedAt,
|
|
366
368
|
provenance: authority.provenance,
|
|
367
|
-
data: {
|
|
369
|
+
data: {
|
|
370
|
+
...entry.data,
|
|
371
|
+
state: terminalCancel ? ("cancelling" as const) : input.state,
|
|
372
|
+
session: input.session,
|
|
373
|
+
},
|
|
368
374
|
} satisfies Entry<Worker>;
|
|
369
375
|
const shouldClear =
|
|
370
376
|
input.state === "stopped" &&
|
|
@@ -381,7 +387,7 @@ const applyWorkerLifecycle = (input: ObserveWorkerLifecycleInput): Result<Entry<
|
|
|
381
387
|
// revision bump per event livelocks worker sessions — each call would
|
|
382
388
|
// invalidate the revision the previous call returned.
|
|
383
389
|
if (
|
|
384
|
-
entry.data.state ===
|
|
390
|
+
entry.data.state === nextEntry.data.state &&
|
|
385
391
|
sameValue(entry.data.session, input.session) &&
|
|
386
392
|
!shouldClear &&
|
|
387
393
|
!shouldUncertain
|
|
@@ -823,9 +829,7 @@ export class WorkitCore {
|
|
|
823
829
|
) {
|
|
824
830
|
if (workspace.writer)
|
|
825
831
|
return failure("recovery_required", "writer ownership must be released first");
|
|
826
|
-
if (
|
|
827
|
-
task.workers.some((entry) => ["running", "cancelling", "unknown"].includes(entry.data.state))
|
|
828
|
-
)
|
|
832
|
+
if (task.workers.some((entry) => isUncertainWorker(entry.data.state)))
|
|
829
833
|
return failure("recovery_required", "worker state requires reconciliation");
|
|
830
834
|
return null;
|
|
831
835
|
}
|
|
@@ -1061,18 +1065,6 @@ export class WorkitCore {
|
|
|
1061
1065
|
(this.context.workerId ?? null) === null ? null : this.helperEntry(task.data, true, true);
|
|
1062
1066
|
if (helper && !helper.ok) return helper as Result<never>;
|
|
1063
1067
|
const evidence = input.evidence as Evidence;
|
|
1064
|
-
if (helper?.ok) {
|
|
1065
|
-
const assignment = helper.data.data.assignment;
|
|
1066
|
-
if (
|
|
1067
|
-
evidence.requirementIds.some((id: string) => !assignment.requirementIds.includes(id)) ||
|
|
1068
|
-
(assignment.candidateId !== null &&
|
|
1069
|
-
evidence.candidateId !== assignment.candidateId &&
|
|
1070
|
-
evidence.beforeCandidateId !== assignment.candidateId) ||
|
|
1071
|
-
!refsWithinScope(evidence.refs, assignment.scope) ||
|
|
1072
|
-
!refsWithinScope(evidence.refs, task.data.intent.data.scope)
|
|
1073
|
-
)
|
|
1074
|
-
return failure("permission_denied", "evidence is outside the worker assignment");
|
|
1075
|
-
}
|
|
1076
1068
|
if (
|
|
1077
1069
|
(evidence.result === "missing" || evidence.result === "skipped") &&
|
|
1078
1070
|
!evidence.summary.trim()
|
|
@@ -1098,6 +1090,18 @@ export class WorkitCore {
|
|
|
1098
1090
|
evidence.beforeCandidateId ??= null;
|
|
1099
1091
|
evidence.candidateId ??= null;
|
|
1100
1092
|
}
|
|
1093
|
+
if (helper?.ok) {
|
|
1094
|
+
const assignment = helper.data.data.assignment;
|
|
1095
|
+
if (
|
|
1096
|
+
evidence.requirementIds.some((id: string) => !assignment.requirementIds.includes(id)) ||
|
|
1097
|
+
(assignment.candidateId !== null &&
|
|
1098
|
+
evidence.candidateId !== assignment.candidateId &&
|
|
1099
|
+
evidence.beforeCandidateId !== assignment.candidateId) ||
|
|
1100
|
+
!refsWithinScope(evidence.refs, assignment.scope) ||
|
|
1101
|
+
!refsWithinScope(evidence.refs, task.data.intent.data.scope)
|
|
1102
|
+
)
|
|
1103
|
+
return failure("permission_denied", "evidence is outside the worker assignment");
|
|
1104
|
+
}
|
|
1101
1105
|
const knownCandidates = new Set(task.data.candidates.map((candidate) => candidate.id));
|
|
1102
1106
|
for (const candidateId of [evidence.beforeCandidateId, evidence.candidateId]) {
|
|
1103
1107
|
if (
|
|
@@ -1776,7 +1780,12 @@ export class WorkitCore {
|
|
|
1776
1780
|
...current,
|
|
1777
1781
|
workers: current.workers.map((item) =>
|
|
1778
1782
|
item.id === input.workerId
|
|
1779
|
-
? {
|
|
1783
|
+
? {
|
|
1784
|
+
...item,
|
|
1785
|
+
recordedAt: mutation.now,
|
|
1786
|
+
provenance: attested.data,
|
|
1787
|
+
data: { ...item.data, state: "dispatching" as const },
|
|
1788
|
+
}
|
|
1780
1789
|
: item,
|
|
1781
1790
|
),
|
|
1782
1791
|
});
|
|
@@ -2235,6 +2244,9 @@ export class WorkitCore {
|
|
|
2235
2244
|
id: task.id,
|
|
2236
2245
|
revision: task.revision,
|
|
2237
2246
|
workspaceRevision: workspace.data.revision,
|
|
2247
|
+
createdAt: task.createdAt,
|
|
2248
|
+
updatedAt: task.updatedAt,
|
|
2249
|
+
runtime: task.runtime ?? null,
|
|
2238
2250
|
objective: task.intent.data.objective,
|
|
2239
2251
|
status: task.status,
|
|
2240
2252
|
closure: task.closure,
|
|
@@ -2337,9 +2349,7 @@ export class WorkitCore {
|
|
|
2337
2349
|
const base = reconcileResumeContext(effectiveView);
|
|
2338
2350
|
if (!base.ok) return base;
|
|
2339
2351
|
const needsReconciliation = view.task.workers.some((entry) =>
|
|
2340
|
-
|
|
2341
|
-
observedStates.get(entry.id) ?? entry.data.state,
|
|
2342
|
-
),
|
|
2352
|
+
isUncertainWorker(observedStates.get(entry.id) ?? entry.data.state),
|
|
2343
2353
|
);
|
|
2344
2354
|
const blockers = [...base.data.blockers];
|
|
2345
2355
|
if (
|
|
@@ -2431,8 +2441,8 @@ export class WorkitCore {
|
|
|
2431
2441
|
!current.candidates.some((candidate) => candidate.id === resumeCandidate!.id)
|
|
2432
2442
|
? [...current.candidates, resumeCandidate]
|
|
2433
2443
|
: current.candidates,
|
|
2434
|
-
progress:
|
|
2435
|
-
|
|
2444
|
+
progress: current.progress,
|
|
2445
|
+
pauseReason: status === "paused" ? (input.reason ?? null) : null,
|
|
2436
2446
|
}),
|
|
2437
2447
|
});
|
|
2438
2448
|
if (!changed.ok) return changed as Result<never>;
|
|
@@ -2468,7 +2478,10 @@ export class WorkitCore {
|
|
|
2468
2478
|
const workspace = this.store.readWorkspace();
|
|
2469
2479
|
if (!workspace.ok) return workspace as Result<never>;
|
|
2470
2480
|
if (!workspace.data) return failure("not_found", "workspace not found");
|
|
2471
|
-
if (
|
|
2481
|
+
if (
|
|
2482
|
+
workspace.data.writer ||
|
|
2483
|
+
task.data.workers.some((entry) => isUncertainWorker(entry.data.state))
|
|
2484
|
+
)
|
|
2472
2485
|
return failure(
|
|
2473
2486
|
"recovery_required",
|
|
2474
2487
|
"scope revision requires worker ownership reconciliation",
|
|
@@ -154,14 +154,23 @@ const scopeRoots = (root: string, scope: Scope): Result<string[]> => {
|
|
|
154
154
|
const roots: string[] = [];
|
|
155
155
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
156
156
|
const target = path.resolve(root, item);
|
|
157
|
-
if (!inside(root, target))
|
|
157
|
+
if (!inside(root, target))
|
|
158
|
+
return failure(
|
|
159
|
+
"invalid_input",
|
|
160
|
+
`candidate scope escapes checkout: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`,
|
|
161
|
+
{ fields: [{ path: "scope.paths", reason: `${item} is outside the checkout` }] },
|
|
162
|
+
);
|
|
158
163
|
let ancestor = target;
|
|
159
164
|
while (!fs.existsSync(ancestor) && ancestor !== root) ancestor = path.dirname(ancestor);
|
|
160
165
|
try {
|
|
161
166
|
if (!inside(root, fs.realpathSync(ancestor)))
|
|
162
|
-
return failure(
|
|
167
|
+
return failure(
|
|
168
|
+
"invalid_input",
|
|
169
|
+
`candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`,
|
|
170
|
+
{ fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] },
|
|
171
|
+
);
|
|
163
172
|
} catch {
|
|
164
|
-
return failure("invalid_input",
|
|
173
|
+
return failure("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
165
174
|
}
|
|
166
175
|
roots.push(target);
|
|
167
176
|
}
|
|
@@ -180,7 +189,12 @@ export function captureCandidate(
|
|
|
180
189
|
return failure("invalid_input", "candidate root does not exist");
|
|
181
190
|
}
|
|
182
191
|
const normalizedScope = canonicalScope(scope);
|
|
183
|
-
if (!normalizedScope)
|
|
192
|
+
if (!normalizedScope)
|
|
193
|
+
return failure(
|
|
194
|
+
"invalid_input",
|
|
195
|
+
"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",
|
|
196
|
+
{ fields: [{ path: "scope.paths", reason: "must be checkout-relative" }] },
|
|
197
|
+
);
|
|
184
198
|
const roots = scopeRoots(checkout, normalizedScope);
|
|
185
199
|
if (!roots.ok) return roots;
|
|
186
200
|
const git = gitPaths(checkout);
|
|
@@ -461,7 +475,10 @@ export function evaluateRequirements(
|
|
|
461
475
|
const reviewSession = sessionFromRef(entry.data.reviewContext);
|
|
462
476
|
const sameImplementation = sameSession(reviewSession, task.intent.provenance.session);
|
|
463
477
|
const sameEvidenceSession = task.evidence.some(
|
|
464
|
-
(other) =>
|
|
478
|
+
(other) =>
|
|
479
|
+
other.id !== entry.id &&
|
|
480
|
+
other.data.kind === "review" &&
|
|
481
|
+
sameSession(reviewSession, other.provenance.session),
|
|
465
482
|
);
|
|
466
483
|
return (
|
|
467
484
|
entry.data.kind === "review" &&
|
|
@@ -641,6 +658,18 @@ export function evaluateClosure(
|
|
|
641
658
|
if (requestedOutcome !== "stopped" && blocking.length)
|
|
642
659
|
return failure("requirements_unsatisfied", "applicable requirements are unsatisfied", {
|
|
643
660
|
requirementIds: blocking.map((item) => item.requirementId),
|
|
661
|
+
requirements: blocking.map((item) => {
|
|
662
|
+
const requirement = view.task.policy?.requirements.find(
|
|
663
|
+
(candidate) => candidate.id === item.requirementId,
|
|
664
|
+
);
|
|
665
|
+
return {
|
|
666
|
+
requirementId: item.requirementId,
|
|
667
|
+
ruleId: requirement?.ruleId ?? "unknown",
|
|
668
|
+
reason: item.reason,
|
|
669
|
+
satisfaction: requirement?.satisfaction ?? "",
|
|
670
|
+
dependentAction: requirement?.dependentAction ?? null,
|
|
671
|
+
};
|
|
672
|
+
}),
|
|
644
673
|
});
|
|
645
674
|
const accepted = evaluations.filter((item) => item.status === "accepted_limitation");
|
|
646
675
|
if (requestedOutcome === "verified" && accepted.length)
|
package/src/core/task-store.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import { hostname } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import * as z from "zod";
|
|
6
|
+
import { packageRoot } from "./package-root";
|
|
6
7
|
import {
|
|
7
8
|
acquireFileLockSync,
|
|
8
9
|
type FileLockSyncHandle,
|
|
@@ -109,6 +110,43 @@ export type RecoveryCandidate = {
|
|
|
109
110
|
};
|
|
110
111
|
|
|
111
112
|
const now = (): Utc => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
113
|
+
|
|
114
|
+
let cachedRuntimeVersion: string | null = null;
|
|
115
|
+
/** Version of the package that hosts this runtime; recorded with state so a
|
|
116
|
+
* bug report can identify the writer version without reading raw .workit. */
|
|
117
|
+
export const runtimeVersion = (): string => {
|
|
118
|
+
if (cachedRuntimeVersion === null) {
|
|
119
|
+
try {
|
|
120
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot(), "package.json"), "utf8")) as {
|
|
121
|
+
version?: unknown;
|
|
122
|
+
};
|
|
123
|
+
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
124
|
+
} catch {
|
|
125
|
+
cachedRuntimeVersion = "0.0.0";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return cachedRuntimeVersion;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const stampNew = (record: { runtime?: { createdWith: string | null } }) => ({
|
|
132
|
+
createdWith: record.runtime?.createdWith ?? null,
|
|
133
|
+
updatedWith: runtimeVersion(),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const isNewerVersion = (candidate: string, current: string): boolean => {
|
|
137
|
+
const parts = (value: string) =>
|
|
138
|
+
value
|
|
139
|
+
.split("-")[0]
|
|
140
|
+
.split(".")
|
|
141
|
+
.map((item) => Number.parseInt(item, 10) || 0);
|
|
142
|
+
const [next, now] = [parts(candidate), parts(current)];
|
|
143
|
+
for (let index = 0; index < 3; index += 1) {
|
|
144
|
+
const left = next[index] ?? 0;
|
|
145
|
+
const right = now[index] ?? 0;
|
|
146
|
+
if (left !== right) return left > right;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
};
|
|
112
150
|
const jsonBytes = (value: unknown): string => `${canonicalJson(value)}\n`;
|
|
113
151
|
const digestBytes = (value: string | Buffer): string =>
|
|
114
152
|
createHash("sha256").update(value).digest("hex");
|
|
@@ -221,10 +259,14 @@ export class TaskStore {
|
|
|
221
259
|
? value.expectedWorkspaceRevision !== current.data.revision
|
|
222
260
|
: value.expectedWorkspaceRevision !== null
|
|
223
261
|
) {
|
|
224
|
-
return failure(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
262
|
+
return failure(
|
|
263
|
+
"revision_conflict",
|
|
264
|
+
"workspace revision does not match; omit expectedWorkspaceRevision to use the current record",
|
|
265
|
+
{
|
|
266
|
+
expectedWorkspaceRevision: value.expectedWorkspaceRevision,
|
|
267
|
+
actualWorkspaceRevision: current.data?.revision ?? null,
|
|
268
|
+
},
|
|
269
|
+
);
|
|
228
270
|
}
|
|
229
271
|
if (!value.provenance) return failure("invalid_input", "provenance is required");
|
|
230
272
|
if (
|
|
@@ -236,12 +278,18 @@ export class TaskStore {
|
|
|
236
278
|
if (current.data && !previousWorkspaceBytes)
|
|
237
279
|
return failure("storage_error", "workspace snapshot disappeared during creation");
|
|
238
280
|
const workspace: WorkspaceRecord = current.data
|
|
239
|
-
? {
|
|
281
|
+
? {
|
|
282
|
+
...current.data,
|
|
283
|
+
revision: newRevision(),
|
|
284
|
+
root: this.root,
|
|
285
|
+
runtime: stampNew(current.data),
|
|
286
|
+
}
|
|
240
287
|
: {
|
|
241
288
|
schemaVersion: SCHEMA_VERSION,
|
|
242
289
|
id: newId(),
|
|
243
290
|
revision: newRevision(),
|
|
244
291
|
root: this.root,
|
|
292
|
+
runtime: { createdWith: runtimeVersion(), updatedWith: runtimeVersion() },
|
|
245
293
|
writer: null,
|
|
246
294
|
};
|
|
247
295
|
const timestamp = value.now ?? now();
|
|
@@ -263,6 +311,7 @@ export class TaskStore {
|
|
|
263
311
|
status: "active",
|
|
264
312
|
closure: null,
|
|
265
313
|
progress: { summary: "", nextAction: null, blockers: [] },
|
|
314
|
+
runtime: { createdWith: runtimeVersion(), updatedWith: runtimeVersion() },
|
|
266
315
|
assessments: [],
|
|
267
316
|
policy: null,
|
|
268
317
|
policyChanges: [],
|
|
@@ -312,21 +361,31 @@ export class TaskStore {
|
|
|
312
361
|
? input.expectedWorkspaceRevision !== current.data.revision
|
|
313
362
|
: input.expectedWorkspaceRevision !== null
|
|
314
363
|
)
|
|
315
|
-
return failure(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
364
|
+
return failure(
|
|
365
|
+
"revision_conflict",
|
|
366
|
+
"workspace revision does not match; omit expectedWorkspaceRevision to use the current record",
|
|
367
|
+
{
|
|
368
|
+
expectedWorkspaceRevision: input.expectedWorkspaceRevision,
|
|
369
|
+
actualWorkspaceRevision: current.data?.revision ?? null,
|
|
370
|
+
},
|
|
371
|
+
);
|
|
319
372
|
const previousWorkspaceBytes = current.data ? this.snapshotBytes(this.workspacePath) : null;
|
|
320
373
|
if (current.data && !previousWorkspaceBytes)
|
|
321
374
|
return failure("storage_error", "workspace snapshot disappeared during import");
|
|
322
375
|
const timestamp = input.now ?? now();
|
|
323
376
|
const workspace: WorkspaceRecord = current.data
|
|
324
|
-
? {
|
|
377
|
+
? {
|
|
378
|
+
...current.data,
|
|
379
|
+
revision: newRevision(),
|
|
380
|
+
root: this.root,
|
|
381
|
+
runtime: stampNew(current.data),
|
|
382
|
+
}
|
|
325
383
|
: {
|
|
326
384
|
schemaVersion: SCHEMA_VERSION,
|
|
327
385
|
id: input.workspaceId ?? newId(),
|
|
328
386
|
revision: newRevision(),
|
|
329
387
|
root: this.root,
|
|
388
|
+
runtime: { createdWith: runtimeVersion(), updatedWith: runtimeVersion() },
|
|
330
389
|
writer: null,
|
|
331
390
|
};
|
|
332
391
|
const task = {
|
|
@@ -335,6 +394,10 @@ export class TaskStore {
|
|
|
335
394
|
revision: newRevision(),
|
|
336
395
|
createdAt: timestamp,
|
|
337
396
|
updatedAt: timestamp,
|
|
397
|
+
runtime: {
|
|
398
|
+
createdWith: input.task.runtime?.createdWith ?? null,
|
|
399
|
+
updatedWith: runtimeVersion(),
|
|
400
|
+
},
|
|
338
401
|
};
|
|
339
402
|
const validTask = taskRecordSchema.safeParse(task);
|
|
340
403
|
if (!validTask.success)
|
|
@@ -402,6 +465,7 @@ export class TaskStore {
|
|
|
402
465
|
createdAt: current.data.createdAt,
|
|
403
466
|
revision: context.revision,
|
|
404
467
|
updatedAt: context.now,
|
|
468
|
+
runtime: stampNew(current.data),
|
|
405
469
|
};
|
|
406
470
|
const valid = taskRecordSchema.safeParse(record);
|
|
407
471
|
if (!valid.success)
|
|
@@ -433,6 +497,7 @@ export class TaskStore {
|
|
|
433
497
|
id: current.data.id,
|
|
434
498
|
root: this.root,
|
|
435
499
|
revision: context.revision,
|
|
500
|
+
runtime: stampNew(current.data),
|
|
436
501
|
};
|
|
437
502
|
const valid = workspaceRecordSchema.safeParse(record);
|
|
438
503
|
if (!valid.success)
|
|
@@ -472,6 +537,7 @@ export class TaskStore {
|
|
|
472
537
|
id: workspace.data.id,
|
|
473
538
|
root: this.root,
|
|
474
539
|
revision: workspaceContext.revision,
|
|
540
|
+
runtime: stampNew(workspace.data),
|
|
475
541
|
});
|
|
476
542
|
if (!nextWorkspace.success)
|
|
477
543
|
return failure("invalid_input", "workspace mutation produced an invalid record");
|
|
@@ -508,6 +574,7 @@ export class TaskStore {
|
|
|
508
574
|
createdAt: task.data.createdAt,
|
|
509
575
|
revision: taskContext.revision,
|
|
510
576
|
updatedAt: taskContext.now,
|
|
577
|
+
runtime: stampNew(task.data),
|
|
511
578
|
});
|
|
512
579
|
if (!nextTask.success) {
|
|
513
580
|
this.markUncertain(nextWorkspace.data);
|
|
@@ -785,6 +852,7 @@ export class TaskStore {
|
|
|
785
852
|
...workspace,
|
|
786
853
|
writer: { ...workspace.writer, state: "uncertain" as const },
|
|
787
854
|
revision: newRevision(),
|
|
855
|
+
runtime: stampNew(workspace),
|
|
788
856
|
};
|
|
789
857
|
this.replaceSnapshot(this.workspacePath, value, workspace);
|
|
790
858
|
}
|
|
@@ -1027,9 +1095,17 @@ export class TaskStore {
|
|
|
1027
1095
|
if (isObject(value) && "schemaVersion" in value && value.schemaVersion !== SCHEMA_VERSION)
|
|
1028
1096
|
return failure("unsupported_version", "unsupported snapshot schema version");
|
|
1029
1097
|
const parsed = schema.safeParse(value);
|
|
1030
|
-
return parsed.
|
|
1031
|
-
|
|
1032
|
-
|
|
1098
|
+
if (parsed.success) return success(null, null, parsed.data);
|
|
1099
|
+
const writerVersion =
|
|
1100
|
+
isObject(value) && isObject((value as { runtime?: unknown }).runtime)
|
|
1101
|
+
? (value as { runtime: { updatedWith?: unknown } }).runtime.updatedWith
|
|
1102
|
+
: null;
|
|
1103
|
+
if (typeof writerVersion === "string" && isNewerVersion(writerVersion, runtimeVersion()))
|
|
1104
|
+
return failure(
|
|
1105
|
+
"recovery_required",
|
|
1106
|
+
`snapshot was written by workit ${writerVersion}; upgrade Workit before mutating this checkout`,
|
|
1107
|
+
);
|
|
1108
|
+
return failure("recovery_required", "snapshot does not satisfy its schema");
|
|
1033
1109
|
}
|
|
1034
1110
|
|
|
1035
1111
|
private processStart(pid: number): string | null {
|
|
@@ -1041,10 +1117,14 @@ export class TaskStore {
|
|
|
1041
1117
|
}
|
|
1042
1118
|
|
|
1043
1119
|
private conflict(expected: Revision, actual: Revision): Result<never> {
|
|
1044
|
-
return failure(
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1120
|
+
return failure(
|
|
1121
|
+
"revision_conflict",
|
|
1122
|
+
"snapshot revision does not match; omit expectedRevision to use the current record",
|
|
1123
|
+
{
|
|
1124
|
+
expectedRevision: expected,
|
|
1125
|
+
actualRevision: actual,
|
|
1126
|
+
},
|
|
1127
|
+
);
|
|
1048
1128
|
}
|
|
1049
1129
|
|
|
1050
1130
|
private taskPath(taskId: Id) {
|
package/src/core/workers.ts
CHANGED
|
@@ -93,6 +93,12 @@ const same = (left: unknown, right: unknown): boolean => {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
/** The one shared definition of active or uncertain worker state used by
|
|
97
|
+
* close, revise, resume, and replacement-launch checks. */
|
|
98
|
+
export const UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"] as const;
|
|
99
|
+
export const isUncertainWorker = (state: string): boolean =>
|
|
100
|
+
(UNCERTAIN_WORKER_STATES as readonly string[]).includes(state);
|
|
101
|
+
|
|
96
102
|
const callerSession = (caller: CallerContext): HostSession =>
|
|
97
103
|
caller.session ?? { kind: "host", host: caller.host, handle: caller.actor };
|
|
98
104
|
|
package/src/core.ts
CHANGED
|
@@ -22,6 +22,8 @@ export {
|
|
|
22
22
|
decisionDigest,
|
|
23
23
|
candidateDigest,
|
|
24
24
|
requirementId,
|
|
25
|
+
BINDING_QUESTION_BUDGET,
|
|
26
|
+
workitBindingQuestionIssue,
|
|
25
27
|
} from "./core/task-contract";
|
|
26
28
|
export type {
|
|
27
29
|
OperationFamily,
|
|
@@ -55,7 +57,7 @@ export type {
|
|
|
55
57
|
ExportBundle,
|
|
56
58
|
Result as ContractResult,
|
|
57
59
|
} from "./core/task-contract";
|
|
58
|
-
export { TaskStore } from "./core/task-store";
|
|
60
|
+
export { TaskStore, runtimeVersion } from "./core/task-store";
|
|
59
61
|
export type { MetadataLock, ProcessEvidence, RecoveryInput } from "./core/task-store";
|
|
60
62
|
export { compactTaskContext, reconcileResume } from "./core/task-context";
|
|
61
63
|
export type {
|
|
@@ -66,6 +68,8 @@ export type {
|
|
|
66
68
|
} from "./core/task-context";
|
|
67
69
|
export { METHODS, invariantBootstrap, selectMethods } from "./core/methods";
|
|
68
70
|
export type { MethodId, SelectedMethod } from "./core/methods";
|
|
71
|
+
export { shellRouteIntent } from "./core/route-intent";
|
|
72
|
+
export type { ShellRouteIntent } from "./core/route-intent";
|
|
69
73
|
export { applicableDecision, reserveAction, settleAction, reconcileAction } from "./core/authority";
|
|
70
74
|
export {
|
|
71
75
|
createAuthorizedExternalActionRunner,
|
|
@@ -83,8 +87,13 @@ export type {
|
|
|
83
87
|
} from "./core/external-action";
|
|
84
88
|
export {
|
|
85
89
|
approvedExternalAction,
|
|
90
|
+
approvedPlanCommit,
|
|
91
|
+
planCommitDescriptor,
|
|
92
|
+
planCommitBinding,
|
|
93
|
+
commitMessageFromDescriptor,
|
|
86
94
|
externalActionState,
|
|
87
95
|
priorExternalAction,
|
|
96
|
+
priorResolvedDrift,
|
|
88
97
|
externalActionRef,
|
|
89
98
|
externalActionDescriptor,
|
|
90
99
|
externalActionHelp,
|