@melra/runtime-core 0.3.0-alpha.14 → 0.3.0-alpha.15
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/README.md +3 -2
- package/dist/task-controller.d.ts +89 -1
- package/dist/task-controller.d.ts.map +1 -1
- package/dist/task-controller.js +351 -73
- package/dist/task-controller.js.map +1 -1
- package/dist/workflow-controller.d.ts +87 -0
- package/dist/workflow-controller.d.ts.map +1 -1
- package/dist/workflow-controller.js +1062 -258
- package/dist/workflow-controller.js.map +1 -1
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -17,7 +17,8 @@ under an `AbortSignal` armed with the duration budget, then verifies.
|
|
|
17
17
|
Verification decides success, not the adapter. A task reaches
|
|
18
18
|
`verified_success` only when the adapter succeeded *and* every declared evidence
|
|
19
19
|
predicate passed; an adapter that reported success with failing evidence is
|
|
20
|
-
`partial
|
|
20
|
+
`partial`, unless the only unmet evidence is a `semantic` question, which waits
|
|
21
|
+
in `waiting_user` and settles closed at expiry (#54). Retries apply to `read` effects only — mutations and destructive
|
|
21
22
|
operations run at most once, because a retried delete is a second delete.
|
|
22
23
|
|
|
23
24
|
`WorkflowController` layers a bounded graph over that same pipeline. Nine node
|
|
@@ -40,7 +41,7 @@ Workflow durability, briefly:
|
|
|
40
41
|
- Definitions and adapter results are sealed with AES-256-GCM bound to record
|
|
41
42
|
identity and purpose.
|
|
42
43
|
|
|
43
|
-
Requires Node.js 22 or newer. Full documentation:
|
|
44
|
+
Requires Node.js 22.13 or newer, or 23.4 or newer. Full documentation:
|
|
44
45
|
[github.com/XAGI-Lab/melra](https://github.com/XAGI-Lab/melra)
|
|
45
46
|
|
|
46
47
|
Apache-2.0
|
|
@@ -25,6 +25,16 @@ export interface TaskPlanOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
stored?: boolean;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Fill in `requiredEvidence` for a mutation that declared none.
|
|
30
|
+
*
|
|
31
|
+
* Applied once, where the request is normalized, so the derived predicates flow
|
|
32
|
+
* identically into the policy decision, the sealed payload, the persisted task
|
|
33
|
+
* record, and verification. A caller that declared its own evidence is left
|
|
34
|
+
* untouched — this only replaces an empty list. Exported for `melra policy
|
|
35
|
+
* test`, whose preview must decide on the request the server would.
|
|
36
|
+
*/
|
|
37
|
+
export declare function withDefaultEvidence(request: TaskRequest): TaskRequest;
|
|
28
38
|
/**
|
|
29
39
|
* A grant's durable draw-down, the way policy wants to read it.
|
|
30
40
|
*
|
|
@@ -40,6 +50,8 @@ export declare class TaskController {
|
|
|
40
50
|
private readonly verifier;
|
|
41
51
|
private readonly payloadCipher;
|
|
42
52
|
private readonly active;
|
|
53
|
+
/** Each task running here, settled once it has ended (see `settled`). */
|
|
54
|
+
private readonly running;
|
|
43
55
|
private readonly breaker;
|
|
44
56
|
/** Whether approvals come only from an operator, out of band. */
|
|
45
57
|
get enforced(): boolean;
|
|
@@ -55,7 +67,8 @@ export declare class TaskController {
|
|
|
55
67
|
private readonly capabilityUsage;
|
|
56
68
|
/**
|
|
57
69
|
* Draws by tasks between their re-check and their record, per grant and
|
|
58
|
-
* task. The durable draw is written only once work
|
|
70
|
+
* task. The durable draw is written only once work has passed every check
|
|
71
|
+
* the kernel can make (#54: verified, or waiting on a semantic verdict), so without
|
|
59
72
|
* this two tasks running at once both saw the grant unspent: two operations
|
|
60
73
|
* against `maxOperations: 1`, a parallel workflow node overspending
|
|
61
74
|
* `dailyMax`.
|
|
@@ -71,9 +84,25 @@ export declare class TaskController {
|
|
|
71
84
|
preflight(request: TaskRequest, options?: {
|
|
72
85
|
stored?: boolean;
|
|
73
86
|
}): PolicyDecision;
|
|
87
|
+
/** Refuses a predicate no registered verifier can check, or that it would refuse to. */
|
|
88
|
+
assertVerifiable(predicates: EvidencePredicate[], options?: {
|
|
89
|
+
stored?: boolean;
|
|
90
|
+
}): void;
|
|
74
91
|
status(taskId: string): TaskRecord;
|
|
75
92
|
execute(taskId: string, approval?: ApprovalResponse): Promise<ExecutionResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Resolves once a task this controller is running has ended, its outcome
|
|
95
|
+
* recorded: a cancel only signals the adapter to stop. At once for one it
|
|
96
|
+
* is not running.
|
|
97
|
+
*/
|
|
98
|
+
settled(taskId: string): Promise<void>;
|
|
76
99
|
cancel(taskId: string): TaskRecord;
|
|
100
|
+
/**
|
|
101
|
+
* Writes a task out of planned or awaiting_approval, unless a deny or an
|
|
102
|
+
* execute in another process got there after this one read it: that one
|
|
103
|
+
* stands, and this one is refused as it would have been had it read later.
|
|
104
|
+
*/
|
|
105
|
+
private leaveUnstarted;
|
|
77
106
|
verifyPersisted(taskId: string, predicates: EvidencePredicate[]): Promise<{
|
|
78
107
|
verified: boolean;
|
|
79
108
|
evidence: EvidenceItem[];
|
|
@@ -96,6 +125,16 @@ export declare class TaskController {
|
|
|
96
125
|
* provider could not be reached and the task stays exactly where it was.
|
|
97
126
|
*/
|
|
98
127
|
reconcile(taskId: string): Promise<ExecutionResult>;
|
|
128
|
+
/**
|
|
129
|
+
* Writes a reconcile's answer in one transaction, and only while the task
|
|
130
|
+
* still waits for one. Two reconciles of one task (two melra_execute calls,
|
|
131
|
+
* or the sweep's recovery beside an agent's) each read it parked and ask
|
|
132
|
+
* the provider; written unconditionally, the slower answer, even one that
|
|
133
|
+
* could not reach the provider, overwrote a settle the other had recorded
|
|
134
|
+
* and dropped its receipt. Now the first stands, and the other writes
|
|
135
|
+
* nothing, not even a receipt, and returns the task as it now stands.
|
|
136
|
+
*/
|
|
137
|
+
private settleParked;
|
|
99
138
|
/**
|
|
100
139
|
* Settle a task as done on evidence gathered after the fact.
|
|
101
140
|
*
|
|
@@ -105,11 +144,50 @@ export declare class TaskController {
|
|
|
105
144
|
* or an effect settled this way would be free to run again and free to spend.
|
|
106
145
|
*/
|
|
107
146
|
private resolveAsVerified;
|
|
147
|
+
/**
|
|
148
|
+
* Draws the grant behind an effect already done, once per task however
|
|
149
|
+
* often asked. Policy is read for the grant id only: this is accounting
|
|
150
|
+
* rather than permission, so a grant that has since run out still pays for
|
|
151
|
+
* what it authorised. Asked as if nothing were drawn, because policy names
|
|
152
|
+
* no grant at all for one that is now exhausted, and the effect then went
|
|
153
|
+
* uncharged. A task that drew one already is left alone: policy read now
|
|
154
|
+
* names the first grant that matches, not the one execute drew once that
|
|
155
|
+
* was spent, and charging it too drew the task twice.
|
|
156
|
+
*/
|
|
157
|
+
private drawGrant;
|
|
158
|
+
/**
|
|
159
|
+
* Settle a task whose idempotency key is committed to it. A key is
|
|
160
|
+
* committed only once every kernel check held, so whatever stopped the
|
|
161
|
+
* task came after the effect: an interruption, or a write that failed. One
|
|
162
|
+
* with a semantic question commits on entering `waiting_user`, so its
|
|
163
|
+
* commit never says the question was answered: it settles closed, as at
|
|
164
|
+
* expiry (#54).
|
|
165
|
+
*/
|
|
166
|
+
private settleCommitted;
|
|
108
167
|
/**
|
|
109
168
|
* With `failed`, each task that could not be recovered is recorded there by
|
|
110
169
|
* id instead of the first failure being thrown at the end.
|
|
111
170
|
*/
|
|
112
171
|
recoverInterrupted(failed?: Map<string, unknown>): Promise<TaskRecord[]>;
|
|
172
|
+
/**
|
|
173
|
+
* A waiting task whose judgements are past their `expiresAt` settles
|
|
174
|
+
* closed. Re-read and written in one transaction, so a peer settling the
|
|
175
|
+
* same task wins once.
|
|
176
|
+
*
|
|
177
|
+
* ponytail: runs on the startup pass and the 30 s recovery sweep, so a wait
|
|
178
|
+
* can outlive its `expiresAt` by one interval, or until a runtime next opens
|
|
179
|
+
* this data directory; a verdict tool must check `expiresAt` itself.
|
|
180
|
+
*/
|
|
181
|
+
private expireJudgements;
|
|
182
|
+
/**
|
|
183
|
+
* No answer is not a yes (#54). A task whose semantic question went
|
|
184
|
+
* unanswered, at expiry or cut off after its commit, settles closed: its
|
|
185
|
+
* effect ran, so a change is `recovery_required` (never `failed`) and a
|
|
186
|
+
* read is `partial`. Nothing runs here, so it writes no receipt: the
|
|
187
|
+
* certificate, replaced, carries the evidence of the task's last one, the
|
|
188
|
+
* live path's or the one recovery wrote.
|
|
189
|
+
*/
|
|
190
|
+
private settleUnanswered;
|
|
113
191
|
private recoverTask;
|
|
114
192
|
/**
|
|
115
193
|
* What an approver is shown: the effect contract, minus the challenge and
|
|
@@ -163,6 +241,16 @@ export declare class TaskController {
|
|
|
163
241
|
receipts: ActionReceipt[];
|
|
164
242
|
certificate?: ExecutionCertificate;
|
|
165
243
|
};
|
|
244
|
+
/**
|
|
245
|
+
* A task's certificate, written now for a `verified_success` task whose
|
|
246
|
+
* certificate failed to write after it was recorded: a workflow counts a
|
|
247
|
+
* step done only on its certificate. For a writer of the run, never a
|
|
248
|
+
* read. Only that status, because every other path to it writes the
|
|
249
|
+
* certificate before the task, and `execute`, which does not, writes it
|
|
250
|
+
* only if none is stored: whoever writes first, both hand out the same one.
|
|
251
|
+
* A write that fails again is left for the next writer.
|
|
252
|
+
*/
|
|
253
|
+
certify(taskId: string): ExecutionCertificate | undefined;
|
|
166
254
|
/**
|
|
167
255
|
* The mode a task's effect ran under: recorded when it started running, or,
|
|
168
256
|
* for a task that started before that was recorded, the mode on its first
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-controller.d.ts","sourceRoot":"","sources":["../src/task-controller.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAML,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAEjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAOL,KAAK,aAAa,EAElB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,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