@evomap/evolver-cli 2.0.42 → 2.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autoRecall.d.ts +24 -5
- package/dist/autoRecall.js +233 -12
- package/dist/autoexec.d.ts +69 -10
- package/dist/autoexec.js +847 -137
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +71 -26
- package/dist/cliContracts.js +29 -7
- package/dist/cliEntry.d.ts +3 -0
- package/dist/cliEntry.js +63 -0
- package/dist/commandCatalog.d.ts +1 -0
- package/dist/commandCatalog.js +1 -0
- package/dist/contextDelivery.d.ts +12 -0
- package/dist/contextDelivery.js +139 -0
- package/dist/cycleConsumer.js +9 -1
- package/dist/dispatch.js +6 -0
- package/dist/feedbackOutbox.d.ts +96 -0
- package/dist/feedbackOutbox.js +510 -0
- package/dist/feedbackOutboxCli.d.ts +7 -0
- package/dist/feedbackOutboxCli.js +208 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +286 -69
- package/dist/lifecycle.d.ts +18 -0
- package/dist/lifecycle.js +130 -3
- package/dist/lifecycleBootstrapTransaction.js +1 -6
- package/dist/liveStatus.d.ts +27 -0
- package/dist/liveStatus.js +197 -0
- package/dist/outboxLock.d.ts +7 -0
- package/dist/outboxLock.js +141 -0
- package/dist/promptRecallHook.d.ts +7 -22
- package/dist/promptRecallHook.js +20 -489
- package/dist/promptRecallRuntime.d.ts +24 -0
- package/dist/promptRecallRuntime.js +678 -0
- package/dist/promptRecallShared.d.ts +18 -0
- package/dist/promptRecallShared.js +119 -0
- package/dist/recall.js +27 -6
- package/dist/runtimeTelemetry.d.ts +9 -0
- package/dist/runtimeTelemetry.js +16 -0
- package/dist/sessionIngest.d.ts +25 -2
- package/dist/sessionIngest.js +196 -32
- package/dist/setupHooks.js +63 -13
- package/dist/setupHooksLifecycle.js +39 -17
- package/dist/skill2gep.d.ts +11 -0
- package/dist/skill2gep.js +23 -3
- package/dist/solo/mode.js +4 -0
- package/dist/taskCommitments.d.ts +4 -2
- package/dist/taskCommitments.js +208 -114
- package/dist/taskOutcomeOutbox.d.ts +83 -0
- package/dist/taskOutcomeOutbox.js +553 -0
- package/dist/workflowRuntime.js +12 -0
- package/package.json +11 -7
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable task-wide Hub outcome delivery. One committed queue claim owns one
|
|
3
|
+
* operation, independently of its task id or any exact-asset reuse-result. A
|
|
4
|
+
* network send is marked ambiguous on disk before it begins and is never
|
|
5
|
+
* replayed without independent reconciliation evidence.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
8
|
+
import { closeSync, constants, existsSync, fsyncSync, lstatSync, openSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
9
|
+
import { basename, dirname, join } from 'node:path';
|
|
10
|
+
import { hub } from '@evomap/evolver-core';
|
|
11
|
+
import { prepareOutboxDirectory, withOutboxLock } from './outboxLock.js';
|
|
12
|
+
import { FeedbackNotDispatchedError } from './feedbackOutbox.js';
|
|
13
|
+
const SCHEMA_VERSION = 'autoexec-task-outcome-outbox.v1';
|
|
14
|
+
const OPERATION_PREFIX = 'autoexec-task-outcome:';
|
|
15
|
+
const OPERATION_ID = /^autoexec-task-outcome:[a-f0-9]{64}$/;
|
|
16
|
+
const SHA256_ID = /^sha256:[a-f0-9]{64}$/;
|
|
17
|
+
const ROW_NAME = /^[a-f0-9]{64}\.json$/;
|
|
18
|
+
const MAX_ROW_BYTES = 64 * 1024;
|
|
19
|
+
const MAX_SIGNALS = 32;
|
|
20
|
+
const MAX_SIGNAL_CHARS = 160;
|
|
21
|
+
export class TaskOutcomeOutboxError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'TaskOutcomeOutboxError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function digest(value) {
|
|
28
|
+
return createHash('sha256').update(value, 'utf8').digest('hex');
|
|
29
|
+
}
|
|
30
|
+
function hasControlCharacter(value) {
|
|
31
|
+
return [...value].some((character) => {
|
|
32
|
+
const code = character.charCodeAt(0);
|
|
33
|
+
return code < 32 || code === 127;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function exactString(value, label, maxLength = 256) {
|
|
37
|
+
if (typeof value !== 'string' || !value || value.length > maxLength || hasControlCharacter(value)) {
|
|
38
|
+
throw new TaskOutcomeOutboxError(`invalid ${label}`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function safeReason(value, label) {
|
|
43
|
+
if (typeof value !== 'string' || !value || value.length > 1024) {
|
|
44
|
+
throw new TaskOutcomeOutboxError(`invalid ${label}`);
|
|
45
|
+
}
|
|
46
|
+
const cleaned = [...hub.redactString(value)].map((character) => {
|
|
47
|
+
const code = character.charCodeAt(0);
|
|
48
|
+
return code < 32 || code === 127 ? ' ' : character;
|
|
49
|
+
}).join('').trim();
|
|
50
|
+
if (!cleaned)
|
|
51
|
+
throw new TaskOutcomeOutboxError(`invalid ${label}`);
|
|
52
|
+
return cleaned.slice(0, 256);
|
|
53
|
+
}
|
|
54
|
+
function receiptReason(value) {
|
|
55
|
+
try {
|
|
56
|
+
return safeReason(value, 'terminal reason');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return 'outcome_not_recorded';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function safeSignals(signals) {
|
|
63
|
+
if (!Array.isArray(signals))
|
|
64
|
+
throw new TaskOutcomeOutboxError('invalid task signals');
|
|
65
|
+
const out = [];
|
|
66
|
+
const seen = new Set();
|
|
67
|
+
for (const item of signals) {
|
|
68
|
+
if (out.length >= MAX_SIGNALS)
|
|
69
|
+
break;
|
|
70
|
+
if (typeof item !== 'string')
|
|
71
|
+
continue;
|
|
72
|
+
const cleaned = [...hub.redactString(item)].map((character) => {
|
|
73
|
+
const code = character.charCodeAt(0);
|
|
74
|
+
return code < 32 || code === 127 ? ' ' : character;
|
|
75
|
+
}).join('').trim().slice(0, MAX_SIGNAL_CHARS);
|
|
76
|
+
if (!cleaned || seen.has(cleaned))
|
|
77
|
+
continue;
|
|
78
|
+
seen.add(cleaned);
|
|
79
|
+
out.push(cleaned);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function copyUse(use) {
|
|
84
|
+
if (use.schemaVersion !== 'applied-use.v1'
|
|
85
|
+
|| !SHA256_ID.test(use.assetId)
|
|
86
|
+
|| !exactString(use.geneId, 'gene id')
|
|
87
|
+
|| !exactString(use.cycleId, 'cycle id')
|
|
88
|
+
|| !['hub', 'local', 'migrated', 'unknown'].includes(use.source)
|
|
89
|
+
|| !['success', 'failed', 'inert', 'inconclusive'].includes(use.outcome)
|
|
90
|
+
|| (use.producedValue !== null && typeof use.producedValue !== 'boolean')
|
|
91
|
+
|| use.applicationBinding !== 'selected_execution'
|
|
92
|
+
|| use.verification !== 'unverified') {
|
|
93
|
+
throw new TaskOutcomeOutboxError('invalid applied-use evidence');
|
|
94
|
+
}
|
|
95
|
+
if (use.outcome === 'success' && use.producedValue !== true)
|
|
96
|
+
throw new TaskOutcomeOutboxError('success lacks produced value');
|
|
97
|
+
if (use.outcome === 'inert' && use.producedValue !== false)
|
|
98
|
+
throw new TaskOutcomeOutboxError('inert outcome has produced value');
|
|
99
|
+
if (use.hubOriginDestinationId !== undefined) {
|
|
100
|
+
if (!SHA256_ID.test(use.hubOriginDestinationId))
|
|
101
|
+
throw new TaskOutcomeOutboxError('invalid Hub origin destination id');
|
|
102
|
+
if (use.source !== 'hub')
|
|
103
|
+
throw new TaskOutcomeOutboxError('non-Hub use has Hub origin');
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
schemaVersion: 'applied-use.v1', assetId: use.assetId, geneId: use.geneId,
|
|
107
|
+
cycleId: use.cycleId, source: use.source, outcome: use.outcome,
|
|
108
|
+
producedValue: use.producedValue, applicationBinding: 'selected_execution',
|
|
109
|
+
verification: 'unverified',
|
|
110
|
+
...(use.hubOriginDestinationId ? { hubOriginDestinationId: use.hubOriginDestinationId } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function outcomeStatus(verdictStatus, producedValue, use) {
|
|
114
|
+
if (use?.outcome === 'inert' || use?.outcome === 'inconclusive')
|
|
115
|
+
return null;
|
|
116
|
+
if (verdictStatus === 'solidified') {
|
|
117
|
+
// A legacy verdict without a production result has no positive evidence.
|
|
118
|
+
if (producedValue !== true)
|
|
119
|
+
return null;
|
|
120
|
+
if (use?.outcome === 'failed')
|
|
121
|
+
throw new TaskOutcomeOutboxError('success verdict/applied-use mismatch');
|
|
122
|
+
return 'success';
|
|
123
|
+
}
|
|
124
|
+
if (verdictStatus === 'failed') {
|
|
125
|
+
if (use?.outcome === 'success')
|
|
126
|
+
throw new TaskOutcomeOutboxError('failure verdict/applied-use mismatch');
|
|
127
|
+
return 'failed';
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
function reportFor(signals, verdictStatus, producedValue, use, score, destinationId) {
|
|
132
|
+
const status = outcomeStatus(verdictStatus, producedValue, use);
|
|
133
|
+
if (status === null)
|
|
134
|
+
return null;
|
|
135
|
+
if (score !== undefined && (!Number.isFinite(score) || score < 0 || score > 1)) {
|
|
136
|
+
throw new TaskOutcomeOutboxError('invalid outcome score');
|
|
137
|
+
}
|
|
138
|
+
const exactHubAsset = use?.source === 'hub' && use.hubOriginDestinationId === destinationId
|
|
139
|
+
&& use.outcome === status
|
|
140
|
+
&& use.applicationBinding === 'selected_execution' && use.verification === 'unverified'
|
|
141
|
+
? use.assetId : undefined;
|
|
142
|
+
return {
|
|
143
|
+
signals: [...signals], status,
|
|
144
|
+
...(score !== undefined ? { score } : {}),
|
|
145
|
+
...(exactHubAsset ? { usedAssetIds: [exactHubAsset] } : {}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function taskOutcomeIdentity(claimRoot) {
|
|
149
|
+
const claimRootDigest = digest(exactString(claimRoot, 'claim root', 1024));
|
|
150
|
+
return { operationId: `${OPERATION_PREFIX}${claimRootDigest}`, claimRootDigest };
|
|
151
|
+
}
|
|
152
|
+
function immutablePayload(row) {
|
|
153
|
+
return {
|
|
154
|
+
schemaVersion: row.schemaVersion, operationId: row.operationId,
|
|
155
|
+
claimRootDigest: row.claimRootDigest, taskId: row.taskId,
|
|
156
|
+
...(row.generation ? { generation: row.generation } : {}),
|
|
157
|
+
destinationId: row.destinationId, verdictStatus: row.verdictStatus, agentInvoked: row.agentInvoked,
|
|
158
|
+
...(row.producedValue !== undefined ? { producedValue: row.producedValue } : {}),
|
|
159
|
+
...(row.appliedUse ? { appliedUse: row.appliedUse } : {}),
|
|
160
|
+
report: row.report,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** A recovered queue claim keeps its original destination when the report and verdict agree. */
|
|
164
|
+
function committedEvidencePayload(row) {
|
|
165
|
+
const payload = immutablePayload(row);
|
|
166
|
+
delete payload['destinationId'];
|
|
167
|
+
// usedAssetIds is a destination-specific projection of immutable use evidence.
|
|
168
|
+
// A restarted claim may see a different destination but retains the saved row.
|
|
169
|
+
const report = { ...row.report };
|
|
170
|
+
delete report.usedAssetIds;
|
|
171
|
+
payload['report'] = report;
|
|
172
|
+
return payload;
|
|
173
|
+
}
|
|
174
|
+
function payloadDigest(row) {
|
|
175
|
+
return digest(JSON.stringify(immutablePayload(row)));
|
|
176
|
+
}
|
|
177
|
+
function frozen(value) {
|
|
178
|
+
if (value && typeof value === 'object') {
|
|
179
|
+
for (const child of Object.values(value))
|
|
180
|
+
frozen(child);
|
|
181
|
+
Object.freeze(value);
|
|
182
|
+
}
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
function validateRecord(value, expectedOperationId) {
|
|
186
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
187
|
+
throw new TaskOutcomeOutboxError('invalid task outcome record');
|
|
188
|
+
}
|
|
189
|
+
const row = value;
|
|
190
|
+
if (row.schemaVersion !== SCHEMA_VERSION || row.operationId !== expectedOperationId
|
|
191
|
+
|| !OPERATION_ID.test(row.operationId)
|
|
192
|
+
|| row.operationId !== `${OPERATION_PREFIX}${row.claimRootDigest}`
|
|
193
|
+
|| !/^[a-f0-9]{64}$/.test(row.claimRootDigest)
|
|
194
|
+
|| !SHA256_ID.test(row.destinationId)
|
|
195
|
+
|| row.agentInvoked !== true
|
|
196
|
+
|| !Number.isSafeInteger(row.revision) || row.revision < 1
|
|
197
|
+
|| !['pending', 'acknowledged'].includes(row.localStatus)
|
|
198
|
+
|| !['pending', 'ambiguous', 'acknowledged', 'terminal'].includes(row.networkStatus)
|
|
199
|
+
|| typeof row.preparedAt !== 'string') {
|
|
200
|
+
throw new TaskOutcomeOutboxError('invalid task outcome record');
|
|
201
|
+
}
|
|
202
|
+
exactString(row.taskId, 'task id');
|
|
203
|
+
if (row.generation !== undefined)
|
|
204
|
+
exactString(row.generation, 'generation');
|
|
205
|
+
if (row.producedValue !== undefined && typeof row.producedValue !== 'boolean') {
|
|
206
|
+
throw new TaskOutcomeOutboxError('invalid produced value');
|
|
207
|
+
}
|
|
208
|
+
const use = row.appliedUse ? copyUse(row.appliedUse) : undefined;
|
|
209
|
+
if (!row.report || !Array.isArray(row.report.signals)
|
|
210
|
+
|| row.report.signals.length > MAX_SIGNALS
|
|
211
|
+
|| row.report.signals.some((signal) => typeof signal !== 'string' || !signal
|
|
212
|
+
|| signal.length > MAX_SIGNAL_CHARS || hasControlCharacter(signal))) {
|
|
213
|
+
throw new TaskOutcomeOutboxError('invalid task outcome report');
|
|
214
|
+
}
|
|
215
|
+
if (JSON.stringify(safeSignals(row.report.signals)) !== JSON.stringify(row.report.signals)) {
|
|
216
|
+
throw new TaskOutcomeOutboxError('unsafe task outcome signals');
|
|
217
|
+
}
|
|
218
|
+
const expected = reportFor(row.report.signals, row.verdictStatus, row.producedValue, use, row.report.score, row.destinationId);
|
|
219
|
+
if (!expected || JSON.stringify(row.report) !== JSON.stringify(expected)) {
|
|
220
|
+
throw new TaskOutcomeOutboxError('task outcome report/evidence mismatch');
|
|
221
|
+
}
|
|
222
|
+
if (row.localStatus === 'acknowledged' && !row.localAcknowledgedAt) {
|
|
223
|
+
throw new TaskOutcomeOutboxError('acknowledged local outcome has no timestamp');
|
|
224
|
+
}
|
|
225
|
+
if (row.networkStatus !== 'pending' && row.localStatus !== 'acknowledged') {
|
|
226
|
+
throw new TaskOutcomeOutboxError('invalid task outcome dispatch state');
|
|
227
|
+
}
|
|
228
|
+
if ((row.networkStatus === 'ambiguous' || row.networkStatus === 'acknowledged'
|
|
229
|
+
|| (row.networkStatus === 'terminal' && !row.reconciliationEvidence)) && !row.dispatchStartedAt) {
|
|
230
|
+
throw new TaskOutcomeOutboxError('invalid task outcome dispatch state');
|
|
231
|
+
}
|
|
232
|
+
if (row.networkStatus === 'terminal' && !row.dispatchStartedAt
|
|
233
|
+
&& (!row.reconciliationEvidence || !row.terminalReason)) {
|
|
234
|
+
throw new TaskOutcomeOutboxError('invalid task outcome reconciliation state');
|
|
235
|
+
}
|
|
236
|
+
if ((row.networkStatus === 'acknowledged' || row.networkStatus === 'terminal') && !row.settledAt) {
|
|
237
|
+
throw new TaskOutcomeOutboxError('settled task outcome has no timestamp');
|
|
238
|
+
}
|
|
239
|
+
if (row.payloadDigest !== payloadDigest(row)) {
|
|
240
|
+
throw new TaskOutcomeOutboxError('task outcome payload digest mismatch');
|
|
241
|
+
}
|
|
242
|
+
return row;
|
|
243
|
+
}
|
|
244
|
+
function fsyncDirectory(path) {
|
|
245
|
+
if (process.platform === 'win32')
|
|
246
|
+
return;
|
|
247
|
+
const fd = openSync(path, constants.O_RDONLY);
|
|
248
|
+
try {
|
|
249
|
+
fsyncSync(fd);
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
closeSync(fd);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function writeAtomic(path, row) {
|
|
256
|
+
const dir = dirname(path);
|
|
257
|
+
const temp = join(dir, `.${basename(path)}.${randomUUID()}.tmp`);
|
|
258
|
+
let fd;
|
|
259
|
+
try {
|
|
260
|
+
fd = openSync(temp, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 0o600);
|
|
261
|
+
writeFileSync(fd, `${JSON.stringify(row)}\n`, 'utf8');
|
|
262
|
+
fsyncSync(fd);
|
|
263
|
+
closeSync(fd);
|
|
264
|
+
fd = undefined;
|
|
265
|
+
renameSync(temp, path);
|
|
266
|
+
fsyncDirectory(dir);
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
if (fd !== undefined)
|
|
270
|
+
closeSync(fd);
|
|
271
|
+
try {
|
|
272
|
+
unlinkSync(temp);
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// Preserve the original write error; an ignored temp file can be swept later.
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export class TaskOutcomeOutbox {
|
|
280
|
+
dir;
|
|
281
|
+
directory;
|
|
282
|
+
reportedUnreadable = new Set();
|
|
283
|
+
constructor(dir) {
|
|
284
|
+
try {
|
|
285
|
+
this.directory = prepareOutboxDirectory(dir);
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
throw new TaskOutcomeOutboxError('unsafe task outcome outbox directory');
|
|
289
|
+
}
|
|
290
|
+
this.dir = this.directory.path;
|
|
291
|
+
}
|
|
292
|
+
path(operationId) {
|
|
293
|
+
if (!OPERATION_ID.test(operationId))
|
|
294
|
+
throw new TaskOutcomeOutboxError('invalid task outcome operation id');
|
|
295
|
+
return join(this.dir, `${operationId.slice(OPERATION_PREFIX.length)}.json`);
|
|
296
|
+
}
|
|
297
|
+
get(operationId) {
|
|
298
|
+
this.directory.assertTrusted();
|
|
299
|
+
const path = this.path(operationId);
|
|
300
|
+
if (!existsSync(path)) {
|
|
301
|
+
this.directory.assertTrusted();
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
const stat = lstatSync(path);
|
|
305
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_ROW_BYTES) {
|
|
306
|
+
throw new TaskOutcomeOutboxError('unsafe task outcome outbox record');
|
|
307
|
+
}
|
|
308
|
+
let parsed;
|
|
309
|
+
try {
|
|
310
|
+
parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
throw new TaskOutcomeOutboxError('corrupt task outcome outbox record');
|
|
314
|
+
}
|
|
315
|
+
const row = frozen(validateRecord(parsed, operationId));
|
|
316
|
+
this.directory.assertTrusted();
|
|
317
|
+
return row;
|
|
318
|
+
}
|
|
319
|
+
save(row) {
|
|
320
|
+
row.payloadDigest = payloadDigest(row);
|
|
321
|
+
writeAtomic(this.path(row.operationId), row);
|
|
322
|
+
return frozen(row);
|
|
323
|
+
}
|
|
324
|
+
/** Called after the queue claim receipt is durable and before the claim is archived. */
|
|
325
|
+
prepare(input) {
|
|
326
|
+
if (input.task.id !== input.verdict.taskId
|
|
327
|
+
|| input.task.generation !== input.verdict.generation) {
|
|
328
|
+
throw new TaskOutcomeOutboxError('task/verdict claim mismatch');
|
|
329
|
+
}
|
|
330
|
+
const taskId = exactString(input.task.id, 'task id');
|
|
331
|
+
const identity = taskOutcomeIdentity(input.claimRoot);
|
|
332
|
+
const failureKind = input.verdict.failureKind;
|
|
333
|
+
const disposition = input.verdict.execution_terminal?.disposition;
|
|
334
|
+
if (input.verdict.agentInvoked !== true
|
|
335
|
+
|| failureKind === 'cancelled' || failureKind === 'timeout'
|
|
336
|
+
|| failureKind === 'spawn_failed' || failureKind === 'permission_denied'
|
|
337
|
+
|| disposition === 'cancelled' || disposition === 'timed_out' || disposition === 'denied'
|
|
338
|
+
|| disposition === 'unsafe_to_replay' || disposition === 'crashed'
|
|
339
|
+
|| input.verdict.appliedUse?.outcome === 'inconclusive') {
|
|
340
|
+
return withOutboxLock(this.directory, () => {
|
|
341
|
+
if (this.get(identity.operationId))
|
|
342
|
+
throw new TaskOutcomeOutboxError('task outcome operation payload conflict');
|
|
343
|
+
return null;
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
const use = input.verdict.appliedUse ? copyUse(input.verdict.appliedUse) : undefined;
|
|
347
|
+
if (input.verdict.status === 'failed') {
|
|
348
|
+
if (use?.outcome === 'success')
|
|
349
|
+
throw new TaskOutcomeOutboxError('failure verdict/applied-use mismatch');
|
|
350
|
+
// The queue can produce a failed verdict before any cycle runs. Only a
|
|
351
|
+
// recorded failed cycle outcome is evidence for Hub failure learning.
|
|
352
|
+
if (input.verdict.outcome?.status !== 'failed') {
|
|
353
|
+
return withOutboxLock(this.directory, () => {
|
|
354
|
+
if (this.get(identity.operationId)) {
|
|
355
|
+
throw new TaskOutcomeOutboxError('task outcome operation payload conflict');
|
|
356
|
+
}
|
|
357
|
+
return null;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const signals = safeSignals(input.task.signals);
|
|
362
|
+
const report = reportFor(signals, input.verdict.status, input.verdict.producedValue, use, input.verdict.outcome?.score, input.destinationId);
|
|
363
|
+
if (!report) {
|
|
364
|
+
return withOutboxLock(this.directory, () => {
|
|
365
|
+
if (this.get(identity.operationId))
|
|
366
|
+
throw new TaskOutcomeOutboxError('task outcome operation payload conflict');
|
|
367
|
+
return null;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (!SHA256_ID.test(input.destinationId)) {
|
|
371
|
+
throw new TaskOutcomeOutboxError('task outcome destination id required');
|
|
372
|
+
}
|
|
373
|
+
const candidate = {
|
|
374
|
+
schemaVersion: SCHEMA_VERSION, ...identity, taskId,
|
|
375
|
+
...(input.task.generation ? { generation: exactString(input.task.generation, 'generation') } : {}),
|
|
376
|
+
destinationId: input.destinationId, verdictStatus: input.verdict.status, agentInvoked: true,
|
|
377
|
+
...(input.verdict.producedValue !== undefined ? { producedValue: input.verdict.producedValue } : {}),
|
|
378
|
+
...(use ? { appliedUse: use } : {}), report, payloadDigest: '',
|
|
379
|
+
localStatus: 'pending', networkStatus: 'pending', revision: 1,
|
|
380
|
+
preparedAt: new Date().toISOString(),
|
|
381
|
+
};
|
|
382
|
+
candidate.payloadDigest = payloadDigest(candidate);
|
|
383
|
+
return withOutboxLock(this.directory, () => {
|
|
384
|
+
const existing = this.get(identity.operationId);
|
|
385
|
+
if (existing) {
|
|
386
|
+
if (existing.payloadDigest !== candidate.payloadDigest
|
|
387
|
+
&& digest(JSON.stringify(committedEvidencePayload(existing)))
|
|
388
|
+
!== digest(JSON.stringify(committedEvidencePayload(candidate)))) {
|
|
389
|
+
throw new TaskOutcomeOutboxError('task outcome operation payload conflict');
|
|
390
|
+
}
|
|
391
|
+
return existing;
|
|
392
|
+
}
|
|
393
|
+
return this.save(candidate);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
rows() {
|
|
397
|
+
this.directory.assertTrusted();
|
|
398
|
+
const rows = [];
|
|
399
|
+
for (const name of readdirSync(this.dir).filter((item) => ROW_NAME.test(item)).sort()) {
|
|
400
|
+
const operationId = `${OPERATION_PREFIX}${name.slice(0, -5)}`;
|
|
401
|
+
try {
|
|
402
|
+
const row = this.get(operationId);
|
|
403
|
+
if (row)
|
|
404
|
+
rows.push(row);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
if (!(error instanceof TaskOutcomeOutboxError))
|
|
408
|
+
throw error;
|
|
409
|
+
if (!this.reportedUnreadable.has(operationId)) {
|
|
410
|
+
this.reportedUnreadable.add(operationId);
|
|
411
|
+
try {
|
|
412
|
+
process.stderr.write(`[autoexec] task_outcome_outbox_record_unreadable operation=${operationId}\n`);
|
|
413
|
+
}
|
|
414
|
+
catch { /* A closed diagnostic stream cannot block healthy outcomes. */ }
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
this.directory.assertTrusted();
|
|
419
|
+
return rows;
|
|
420
|
+
}
|
|
421
|
+
localPending() {
|
|
422
|
+
return this.rows().filter((row) => row.localStatus === 'pending');
|
|
423
|
+
}
|
|
424
|
+
/** Acknowledge only after the queue's local receipt is committed. */
|
|
425
|
+
acknowledgeLocal(operationId) {
|
|
426
|
+
return withOutboxLock(this.directory, () => {
|
|
427
|
+
const row = this.get(operationId);
|
|
428
|
+
if (!row)
|
|
429
|
+
throw new TaskOutcomeOutboxError('task outcome operation not found');
|
|
430
|
+
if (row.localStatus === 'acknowledged')
|
|
431
|
+
return row;
|
|
432
|
+
return this.save({ ...row, localStatus: 'acknowledged',
|
|
433
|
+
localAcknowledgedAt: new Date().toISOString(), revision: row.revision + 1 });
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
pending(destinationId) {
|
|
437
|
+
return this.rows().filter((row) => row.localStatus === 'acknowledged'
|
|
438
|
+
&& row.networkStatus === 'pending' && (!destinationId || row.destinationId === destinationId));
|
|
439
|
+
}
|
|
440
|
+
/** An explicit false receipt is terminal; an indeterminate send remains ambiguous. */
|
|
441
|
+
async deliver(operationId, destinationId, sender) {
|
|
442
|
+
const started = withOutboxLock(this.directory, () => {
|
|
443
|
+
const row = this.get(operationId);
|
|
444
|
+
if (!row)
|
|
445
|
+
throw new TaskOutcomeOutboxError('task outcome operation not found');
|
|
446
|
+
if (row.localStatus !== 'acknowledged')
|
|
447
|
+
throw new TaskOutcomeOutboxError('local task outcome is pending');
|
|
448
|
+
if (row.networkStatus !== 'pending')
|
|
449
|
+
throw new TaskOutcomeOutboxError('task outcome dispatch is not pending');
|
|
450
|
+
if (!SHA256_ID.test(destinationId) || destinationId !== row.destinationId) {
|
|
451
|
+
throw new TaskOutcomeOutboxError('task outcome destination mismatch');
|
|
452
|
+
}
|
|
453
|
+
return this.save({ ...row, networkStatus: 'ambiguous',
|
|
454
|
+
dispatchStartedAt: new Date().toISOString(), revision: row.revision + 1 });
|
|
455
|
+
});
|
|
456
|
+
let receipt;
|
|
457
|
+
let notDispatched = false;
|
|
458
|
+
try {
|
|
459
|
+
receipt = await sender(started.report);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
if (error instanceof FeedbackNotDispatchedError)
|
|
463
|
+
notDispatched = true;
|
|
464
|
+
// Any other error may have reached Hub, so leave the started operation ambiguous.
|
|
465
|
+
}
|
|
466
|
+
return withOutboxLock(this.directory, () => {
|
|
467
|
+
const current = this.get(operationId);
|
|
468
|
+
if (!current || current.payloadDigest !== started.payloadDigest) {
|
|
469
|
+
throw new TaskOutcomeOutboxError('task outcome dispatch owner changed');
|
|
470
|
+
}
|
|
471
|
+
// Evidence-based operator reconciliation can complete while the original
|
|
472
|
+
// sender is still waiting. A late reply cannot overwrite that evidence.
|
|
473
|
+
if (current.revision !== started.revision || current.networkStatus !== 'ambiguous')
|
|
474
|
+
return current;
|
|
475
|
+
if (notDispatched) {
|
|
476
|
+
const pending = { ...current, networkStatus: 'pending', revision: current.revision + 1 };
|
|
477
|
+
delete pending.dispatchStartedAt;
|
|
478
|
+
delete pending.ambiguousReason;
|
|
479
|
+
return this.save(pending);
|
|
480
|
+
}
|
|
481
|
+
if (receipt?.recorded === true) {
|
|
482
|
+
return this.save({ ...current, networkStatus: 'acknowledged',
|
|
483
|
+
settledAt: new Date().toISOString(), revision: current.revision + 1 });
|
|
484
|
+
}
|
|
485
|
+
if (receipt?.recorded === false) {
|
|
486
|
+
return this.save({ ...current, networkStatus: 'terminal',
|
|
487
|
+
terminalReason: receiptReason(receipt.reason),
|
|
488
|
+
settledAt: new Date().toISOString(), revision: current.revision + 1 });
|
|
489
|
+
}
|
|
490
|
+
return this.save({ ...current, ambiguousReason: 'indeterminate_response', revision: current.revision + 1 });
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
/** A later receipt or operator evidence can settle ambiguity without resending. */
|
|
494
|
+
reconcile(operationId, resolution) {
|
|
495
|
+
return withOutboxLock(this.directory, () => {
|
|
496
|
+
const row = this.get(operationId);
|
|
497
|
+
if (!row)
|
|
498
|
+
throw new TaskOutcomeOutboxError('task outcome operation not found');
|
|
499
|
+
if (row.networkStatus === 'pending') {
|
|
500
|
+
if (resolution.status !== 'terminal')
|
|
501
|
+
throw new TaskOutcomeOutboxError('task outcome operation is not ambiguous');
|
|
502
|
+
if (row.localStatus !== 'acknowledged')
|
|
503
|
+
throw new TaskOutcomeOutboxError('local task outcome is pending');
|
|
504
|
+
}
|
|
505
|
+
else if (row.networkStatus !== 'ambiguous') {
|
|
506
|
+
throw new TaskOutcomeOutboxError('task outcome operation is not ambiguous');
|
|
507
|
+
}
|
|
508
|
+
const evidence = safeReason(resolution.evidence, 'reconciliation evidence');
|
|
509
|
+
const reconciled = { ...row };
|
|
510
|
+
delete reconciled.ambiguousReason;
|
|
511
|
+
if (resolution.status === 'acknowledged') {
|
|
512
|
+
return this.save({ ...reconciled, networkStatus: 'acknowledged', settledAt: new Date().toISOString(),
|
|
513
|
+
reconciliationEvidence: evidence, revision: row.revision + 1 });
|
|
514
|
+
}
|
|
515
|
+
return this.save({ ...reconciled, networkStatus: 'terminal', settledAt: new Date().toISOString(),
|
|
516
|
+
terminalReason: safeReason(resolution.reason, 'terminal reason'),
|
|
517
|
+
reconciliationEvidence: evidence, revision: row.revision + 1 });
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
/** Skip rows bound to another destination; never retry started or settled sends. */
|
|
521
|
+
async flush(destinationId, sender) {
|
|
522
|
+
if (!SHA256_ID.test(destinationId))
|
|
523
|
+
throw new TaskOutcomeOutboxError('invalid task outcome destination id');
|
|
524
|
+
let delivered = 0;
|
|
525
|
+
let terminal = 0;
|
|
526
|
+
let ambiguous = 0;
|
|
527
|
+
for (const row of this.pending(destinationId)) {
|
|
528
|
+
let result;
|
|
529
|
+
try {
|
|
530
|
+
result = await this.deliver(row.operationId, destinationId, sender);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
// The pending list is a snapshot. A second process can begin or settle a later row
|
|
534
|
+
// while this process awaits a prior send. Only that observed state change is safe
|
|
535
|
+
// to skip; corruption, destination drift, and other delivery errors still fail closed.
|
|
536
|
+
if (error instanceof TaskOutcomeOutboxError && error.message === 'task outcome dispatch is not pending') {
|
|
537
|
+
const current = this.get(row.operationId);
|
|
538
|
+
if (current?.localStatus === 'acknowledged' && current.destinationId === destinationId
|
|
539
|
+
&& current.networkStatus !== 'pending')
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
if (result.networkStatus === 'acknowledged')
|
|
545
|
+
delivered++;
|
|
546
|
+
else if (result.networkStatus === 'terminal')
|
|
547
|
+
terminal++;
|
|
548
|
+
else if (result.networkStatus === 'ambiguous')
|
|
549
|
+
ambiguous++;
|
|
550
|
+
}
|
|
551
|
+
return { delivered, terminal, ambiguous };
|
|
552
|
+
}
|
|
553
|
+
}
|
package/dist/workflowRuntime.js
CHANGED
|
@@ -311,6 +311,14 @@ export function createProductionWorkflowAgentBridge(config, options = {}, expect
|
|
|
311
311
|
function createProductionWorkflowAgentBridgeFromSnapshot(config, options, policyContext, allowedRoots) {
|
|
312
312
|
const assetsDir = resolveWorkflowAssetsDir(options);
|
|
313
313
|
const store = options.store ?? new assetstore.LocalJsonlProvider(assetsDir);
|
|
314
|
+
assetstore.assertPromptProviderNotProxy(store);
|
|
315
|
+
// Execution context can be attached only by a provider whose prompt V1
|
|
316
|
+
// operation is owned by the built-in reader tree. A benchmark store without
|
|
317
|
+
// prompt V1 remains usable for execution without supplemental cases.
|
|
318
|
+
if (!assetstore.isBuiltInPromptProvider(store)
|
|
319
|
+
&& [store.beginPromptGeneSnapshotV1, store.beginGeneScanV1, store.beginPromptRelatedCapsulesV1,
|
|
320
|
+
store.beginPromptAssetGetV1, store.beginPromptLogicalGeneLookupV1].some(capability => capability !== undefined))
|
|
321
|
+
throw classified('safety', 'unsupported_unsupervised_prompt_provider_v1');
|
|
314
322
|
const provenance = options.provenance ?? new assetstore.ProvenanceStore(assetsDir);
|
|
315
323
|
const review = options.review ?? new assetstore.ReviewLedger(assetsDir);
|
|
316
324
|
const runValidation = options.runValidation ?? verify.runSandboxedValidation;
|
|
@@ -361,6 +369,10 @@ function createProductionWorkflowAgentBridgeFromSnapshot(config, options, policy
|
|
|
361
369
|
requireTrustedGene: true,
|
|
362
370
|
...(bridgeOptions?.signal ? { signal: bridgeOptions.signal } : {}),
|
|
363
371
|
}, {
|
|
372
|
+
assertPromptAdapter: () => {
|
|
373
|
+
if (!assetstore.isBuiltInPromptProvider(store))
|
|
374
|
+
throw classified('safety', 'unsupported_unsupervised_prompt_provider_v1');
|
|
375
|
+
},
|
|
364
376
|
provenance,
|
|
365
377
|
review,
|
|
366
378
|
...(benchmark ? { benchmark } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,18 +17,22 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"default": "./dist/index.js"
|
|
19
19
|
},
|
|
20
|
+
"./entry": {
|
|
21
|
+
"types": "./dist/cliEntry.d.ts",
|
|
22
|
+
"default": "./dist/cliEntry.js"
|
|
23
|
+
},
|
|
20
24
|
"./dispatch": {
|
|
21
25
|
"types": "./dist/dispatch.d.ts",
|
|
22
26
|
"default": "./dist/dispatch.js"
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"@evomap/evolver-core": "2.0.
|
|
27
|
-
"@evomap/evolver-adapter-public": "2.0.
|
|
28
|
-
"@evomap/evolver-mcp": "2.0.
|
|
29
|
-
"@evomap/evolver-proxy": "2.0.
|
|
30
|
-
"@evomap/evolver-runtime-adapters": "2.0.
|
|
31
|
-
"@evomap/evolver-webui": "2.0.
|
|
30
|
+
"@evomap/evolver-core": "2.0.44",
|
|
31
|
+
"@evomap/evolver-adapter-public": "2.0.44",
|
|
32
|
+
"@evomap/evolver-mcp": "2.0.44",
|
|
33
|
+
"@evomap/evolver-proxy": "2.0.44",
|
|
34
|
+
"@evomap/evolver-runtime-adapters": "2.0.44",
|
|
35
|
+
"@evomap/evolver-webui": "2.0.44"
|
|
32
36
|
},
|
|
33
37
|
"repository": {
|
|
34
38
|
"type": "git",
|