@earendil-works/pi-durable 0.99.2 → 1.0.1
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/CHANGELOG.md +9 -0
- package/README.md +196 -74
- package/dist/env/index.d.ts +5 -0
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/env/node.d.ts +2 -0
- package/dist/env/node.d.ts.map +1 -1
- package/dist/env/node.js +2 -0
- package/dist/env/node.js.map +1 -1
- package/dist/harness/agent.d.ts +31 -0
- package/dist/harness/agent.d.ts.map +1 -0
- package/dist/harness/agent.js +209 -0
- package/dist/harness/agent.js.map +1 -0
- package/dist/harness/compaction.d.ts.map +1 -1
- package/dist/harness/compaction.js +8 -11
- package/dist/harness/compaction.js.map +1 -1
- package/dist/harness/define.d.ts +18 -0
- package/dist/harness/define.d.ts.map +1 -0
- package/dist/harness/define.js +25 -0
- package/dist/harness/define.js.map +1 -0
- package/dist/harness/events.d.ts +5 -5
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +6 -6
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/generation.d.ts +2 -4
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +39 -43
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +68 -154
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +4 -2
- package/dist/harness/inbox.d.ts.map +1 -1
- package/dist/harness/inbox.js +3 -5
- package/dist/harness/inbox.js.map +1 -1
- package/dist/harness/prompt.d.ts +1 -3
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js +1 -11
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/registry.d.ts +2 -3
- package/dist/harness/registry.d.ts.map +1 -1
- package/dist/harness/registry.js +66 -283
- package/dist/harness/registry.js.map +1 -1
- package/dist/harness/scheduler.d.ts +7 -2
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +41 -27
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +4 -4
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +7 -4
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/task-graph.d.ts +49 -0
- package/dist/harness/task-graph.d.ts.map +1 -0
- package/dist/harness/task-graph.js +163 -0
- package/dist/harness/task-graph.js.map +1 -0
- package/dist/harness/tool.d.ts +1 -1
- package/dist/harness/tool.d.ts.map +1 -1
- package/dist/harness/tool.js +9 -6
- package/dist/harness/tool.js.map +1 -1
- package/dist/harness/types.d.ts +171 -140
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/view.d.ts +1 -1
- package/dist/harness/view.d.ts.map +1 -1
- package/dist/harness/view.js +2 -7
- package/dist/harness/view.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +5 -1
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts +2 -2
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +7 -4
- package/dist/session/transaction.js.map +1 -1
- package/dist/storage/sqlite/database.d.ts +26 -19
- package/dist/storage/sqlite/database.d.ts.map +1 -1
- package/dist/storage/sqlite/database.js.map +1 -1
- package/dist/storage/sqlite/index.d.ts +1 -1
- package/dist/storage/sqlite/index.d.ts.map +1 -1
- package/dist/storage/sqlite/index.js.map +1 -1
- package/dist/storage/sqlite/migrations.js +6 -6
- package/dist/storage/sqlite/migrations.js.map +1 -1
- package/dist/storage/sqlite/node.d.ts +23 -7
- package/dist/storage/sqlite/node.d.ts.map +1 -1
- package/dist/storage/sqlite/node.js +129 -47
- package/dist/storage/sqlite/node.js.map +1 -1
- package/dist/storage/sqlite/storage.d.ts +12 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +121 -129
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +3 -2
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts +3 -3
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +5 -4
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/file-mutation-queue.d.ts +5 -1
- package/dist/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/tools/file-mutation-queue.js +39 -33
- package/dist/tools/file-mutation-queue.js.map +1 -1
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read.d.ts +3 -3
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +4 -3
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.d.ts +1 -1
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +3 -2
- package/dist/tools/write.js.map +1 -1
- package/dist/types.d.ts +15 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +25 -15
- package/dist/harness/config.d.ts +0 -29
- package/dist/harness/config.d.ts.map +0 -1
- package/dist/harness/config.js +0 -24
- package/dist/harness/config.js.map +0 -1
- package/docs/chord-delta-findings.md +0 -358
- package/docs/pico-v5-chord-usage.md +0 -373
- package/docs/pico-v5-handoff.md +0 -861
- package/docs/pico-v5.md +0 -4174
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/harness/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,KAAK,E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SAAS,CAAC,CAAC;IAC7C,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAa;;IAwCzB,YAAY,OAAO,EAAE,oBAAoB,EAcxC;IAED,kGAAkG;IAC5F,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB1C;IAED,yEAAyE;IACzE,MAAM,IAAI,IAAI,CAGb;IAED,wEAAwE;IAClE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;IAED;;;;OAIG;IACG,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC,CAsBxE;IAEK,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAU/E;IAED;;;OAGG;IACH,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAKvF;IAED;;;;OAIG;IACG,iBAAiB,CAAC,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB5G;IAubD;;;;OAIG;IACG,OAAO,CACZ,QAAQ,EAAE,gBAAgB,GACxB,OAAO,CAAC;QAAE,UAAU,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAAC,KAAK,EAAE,cAAc,EAAE,CAAA;KAAE,CAAC,CASnF;CAybD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { copyJson } from "@earendil-works/chord";
|
|
2
2
|
import { awaitWithContext, withAbortSignal } from "@earendil-works/chord/context";
|
|
3
|
+
import { agentHooks } from "./agent.js";
|
|
3
4
|
import { readContext } from "./context.js";
|
|
4
5
|
import { closedError, scanAll, Waiters } from "./util.js";
|
|
5
6
|
const SCAN_PAGE_SIZE = 256;
|
|
@@ -26,6 +27,8 @@ export class TaskScheduler {
|
|
|
26
27
|
#storage;
|
|
27
28
|
#registry;
|
|
28
29
|
#models;
|
|
30
|
+
#agent;
|
|
31
|
+
#settings;
|
|
29
32
|
#env;
|
|
30
33
|
#now;
|
|
31
34
|
#report;
|
|
@@ -63,6 +66,8 @@ export class TaskScheduler {
|
|
|
63
66
|
this.#storage = options.storage;
|
|
64
67
|
this.#registry = options.registry;
|
|
65
68
|
this.#models = options.models;
|
|
69
|
+
this.#agent = options.agent;
|
|
70
|
+
this.#settings = options.settings;
|
|
66
71
|
this.#env = options.env;
|
|
67
72
|
this.#now = options.now;
|
|
68
73
|
this.#report = options.report;
|
|
@@ -741,7 +746,8 @@ export class TaskScheduler {
|
|
|
741
746
|
async #run(reservation) {
|
|
742
747
|
const invocation = reservation.invocation;
|
|
743
748
|
const state = { task: reservation.task, snapshot: reservation.snapshot, reported: undefined };
|
|
744
|
-
const
|
|
749
|
+
const phase = { snapshot: () => state.snapshot, task: () => state.task, agent: undefined };
|
|
750
|
+
const runtime = this.#runtime(invocation, phase);
|
|
745
751
|
let previous;
|
|
746
752
|
for (;;) {
|
|
747
753
|
const current = await this.#step(invocation, (tx, current) => this.#decide(tx, current, previous, state));
|
|
@@ -749,6 +755,8 @@ export class TaskScheduler {
|
|
|
749
755
|
if (current === undefined || this.#closing)
|
|
750
756
|
return;
|
|
751
757
|
const checkpoint = current.state.checkpoint;
|
|
758
|
+
// Each phase handler resolves its agent afresh, at first use.
|
|
759
|
+
phase.agent = undefined;
|
|
752
760
|
try {
|
|
753
761
|
await erased(state.task).phases[checkpoint.phase](current, runtime, invocation.context);
|
|
754
762
|
previous = { checkpoint };
|
|
@@ -800,7 +808,8 @@ export class TaskScheduler {
|
|
|
800
808
|
return;
|
|
801
809
|
let failure;
|
|
802
810
|
try {
|
|
803
|
-
const
|
|
811
|
+
const phase = { snapshot: () => reservation.snapshot, task: () => reservation.task, agent: undefined };
|
|
812
|
+
const runtime = this.#runtime(invocation, phase);
|
|
804
813
|
await erased(reservation.task).abort(current, runtime, invocation.context);
|
|
805
814
|
}
|
|
806
815
|
catch (error) {
|
|
@@ -918,17 +927,24 @@ export class TaskScheduler {
|
|
|
918
927
|
return true;
|
|
919
928
|
}
|
|
920
929
|
// ─── Invocation runtime ──────────────────────────────────────────────────
|
|
921
|
-
#runtime(invocation,
|
|
930
|
+
#runtime(invocation, phase) {
|
|
931
|
+
// Resolved at most once per phase handler, at first use, with the invocation's context; fixed for the phase.
|
|
932
|
+
const agent = () => {
|
|
933
|
+
if (invocation.ended)
|
|
934
|
+
return Promise.reject(endedError(invocation));
|
|
935
|
+
if (phase.agent === undefined) {
|
|
936
|
+
phase.agent = this.#agent(invocation.conversationId, phase.snapshot(), invocation.context);
|
|
937
|
+
// A caller that stops waiting must not leave the shared resolution's failure unobserved.
|
|
938
|
+
phase.agent.catch(() => { });
|
|
939
|
+
}
|
|
940
|
+
return phase.agent;
|
|
941
|
+
};
|
|
922
942
|
const hooks = {
|
|
923
943
|
each: async (name, invoke) => {
|
|
924
|
-
|
|
925
|
-
throw endedError(invocation);
|
|
926
|
-
for (const { handlers, scope } of snapshot().hooks(task())) {
|
|
944
|
+
for (const handlers of agentHooks(await agent(), phase.task().definition.name)) {
|
|
927
945
|
const handler = handlers[name];
|
|
928
946
|
if (typeof handler !== "function")
|
|
929
947
|
continue;
|
|
930
|
-
if (scope !== undefined && !(await this.#hookMatches(invocation, scope)))
|
|
931
|
-
continue;
|
|
932
948
|
try {
|
|
933
949
|
await invoke(handler.bind(handlers));
|
|
934
950
|
}
|
|
@@ -940,15 +956,20 @@ export class TaskScheduler {
|
|
|
940
956
|
}
|
|
941
957
|
},
|
|
942
958
|
};
|
|
959
|
+
const settings = this.#settings;
|
|
943
960
|
return {
|
|
944
961
|
taskId: invocation.taskId,
|
|
945
962
|
conversationId: invocation.conversationId,
|
|
946
963
|
signal: invocation.controller.signal,
|
|
947
964
|
models: this.#models,
|
|
948
|
-
|
|
965
|
+
agent: (context) => invocation.ended ? Promise.reject(endedError(invocation)) : awaitWithContext(agent(), context),
|
|
966
|
+
get settings() {
|
|
967
|
+
return settings();
|
|
968
|
+
},
|
|
969
|
+
env: (context) => this.#read(invocation, () => this.#env(invocation.conversationId, context)),
|
|
949
970
|
hooks: hooks,
|
|
950
971
|
get registry() {
|
|
951
|
-
return snapshot();
|
|
972
|
+
return phase.snapshot();
|
|
952
973
|
},
|
|
953
974
|
commit: (change, context) => this.#gated(invocation, async (tx, current) => {
|
|
954
975
|
const next = await change(tx, current);
|
|
@@ -1002,25 +1023,18 @@ export class TaskScheduler {
|
|
|
1002
1023
|
});
|
|
1003
1024
|
}),
|
|
1004
1025
|
context: (conversationId, context, at) => this.#read(invocation, () => readContext(this.#session, this.#storage, conversationId, context, at)),
|
|
1005
|
-
now: () =>
|
|
1006
|
-
|
|
1026
|
+
now: () => {
|
|
1027
|
+
if (invocation.ended)
|
|
1028
|
+
throw endedError(invocation);
|
|
1029
|
+
return this.#now();
|
|
1030
|
+
},
|
|
1031
|
+
report: (error) => {
|
|
1032
|
+
if (invocation.ended)
|
|
1033
|
+
throw endedError(invocation);
|
|
1034
|
+
this.#report(error);
|
|
1035
|
+
},
|
|
1007
1036
|
};
|
|
1008
1037
|
}
|
|
1009
|
-
/** Whether a scoped hook registration matches the invocation's conversation: itself, or an owner for `subtree`. */
|
|
1010
|
-
async #hookMatches(invocation, scope) {
|
|
1011
|
-
if (scope.conversationId === invocation.conversationId)
|
|
1012
|
-
return true;
|
|
1013
|
-
if (scope.subtree !== true)
|
|
1014
|
-
return false;
|
|
1015
|
-
const start = { conversation: invocation.conversationId };
|
|
1016
|
-
if (!this.#chainKnown(start))
|
|
1017
|
-
await this.#session.readOnLine(() => this.#loadChain(start));
|
|
1018
|
-
for (const step of this.#above(start)) {
|
|
1019
|
-
if ("conversation" in step && step.conversation === scope.conversationId)
|
|
1020
|
-
return true;
|
|
1021
|
-
}
|
|
1022
|
-
return false;
|
|
1023
|
-
}
|
|
1024
1038
|
/** Run a committed-state read unless the invocation has ended. */
|
|
1025
1039
|
async #read(invocation, read) {
|
|
1026
1040
|
if (invocation.ended)
|