@leitwerk-dev/watcher-utils 0.1.0
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/LICENSE +13 -0
- package/dist/chunk-3KGAUQIG.js +31 -0
- package/dist/chunk-3KGAUQIG.js.map +1 -0
- package/dist/chunk-IU3L35PC.js +14 -0
- package/dist/chunk-IU3L35PC.js.map +1 -0
- package/dist/chunk-XF2QQLPO.js +63 -0
- package/dist/chunk-XF2QQLPO.js.map +1 -0
- package/dist/chunk-XLVMFO6W.js +160 -0
- package/dist/chunk-XLVMFO6W.js.map +1 -0
- package/dist/duration-parse.d.ts +11 -0
- package/dist/duration-parse.d.ts.map +1 -0
- package/dist/duration-parse.js +16 -0
- package/dist/duration-parse.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/poll-loop.d.ts +24 -0
- package/dist/poll-loop.d.ts.map +1 -0
- package/dist/poll-loop.js +59 -0
- package/dist/poll-loop.js.map +1 -0
- package/dist/process-helpers.d.ts +30 -0
- package/dist/process-helpers.d.ts.map +1 -0
- package/dist/process-helpers.js +33 -0
- package/dist/process-helpers.js.map +1 -0
- package/dist/trigger-files.d.ts +10 -0
- package/dist/trigger-files.d.ts.map +1 -0
- package/dist/trigger-files.js +31 -0
- package/dist/trigger-files.js.map +1 -0
- package/dist/watcher-coordinator.d.ts +99 -0
- package/dist/watcher-coordinator.d.ts.map +1 -0
- package/dist/watcher-coordinator.js +131 -0
- package/dist/watcher-coordinator.js.map +1 -0
- package/package.json +43 -0
- package/src/duration-parse.ts +21 -0
- package/src/index.ts +49 -0
- package/src/poll-loop.ts +81 -0
- package/src/process-helpers.ts +54 -0
- package/src/trigger-files.ts +33 -0
- package/src/watcher-coordinator.ts +280 -0
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Leitwerk contributors.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/process-helpers.ts
|
|
2
|
+
function hasProcessEvent(events, instanceId, eventType) {
|
|
3
|
+
return events.listByInstance(instanceId, 200).some((event) => event.eventType === eventType);
|
|
4
|
+
}
|
|
5
|
+
function processNeedsWorker(process) {
|
|
6
|
+
return process.selectedTurnId !== null && process.lifecycleStatus === "active";
|
|
7
|
+
}
|
|
8
|
+
async function ensureWorkerForActiveAgent(deps, process) {
|
|
9
|
+
if (!processNeedsWorker(process) || deps.supervisor.getWorker(process.id)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
await deps.supervisor.spawnWorker(process.id);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
deps.events.create({
|
|
16
|
+
instanceId: process.id,
|
|
17
|
+
eventType: "worker_spawn_failed",
|
|
18
|
+
data: {
|
|
19
|
+
reason: error instanceof Error ? error.message : "Failed to spawn worker"
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
hasProcessEvent,
|
|
28
|
+
processNeedsWorker,
|
|
29
|
+
ensureWorkerForActiveAgent
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=chunk-3KGAUQIG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/process-helpers.ts"],"sourcesContent":["import type { ProcessInstance } from \"@leitwerk-dev/domain\";\n\nexport interface ProcessEventRepoLike {\n\tcreate(input: { instanceId: string; eventType: string; data?: Record<string, unknown> }): unknown;\n\tlistByInstance(instanceId: string, limit?: number): Array<{ eventType: string }>;\n}\n\nexport interface WorkerSupervisorLike {\n\tspawnWorker(instanceId: string): Promise<unknown>;\n\tgetWorker(instanceId: string): unknown | undefined;\n}\n\n/**\n * Check whether a process already has an event of the given type.\n */\nexport function hasProcessEvent(\n\tevents: ProcessEventRepoLike,\n\tinstanceId: string,\n\teventType: string,\n): boolean {\n\treturn events.listByInstance(instanceId, 200).some((event) => event.eventType === eventType);\n}\n\nexport function processNeedsWorker(\n\tprocess: Pick<ProcessInstance, \"selectedTurnId\" | \"lifecycleStatus\">,\n): boolean {\n\treturn process.selectedTurnId !== null && process.lifecycleStatus === \"active\";\n}\n\n/**\n * Spawn a worker for a process whose selected turn is runnable but currently has\n * no running worker. No-ops when the process is not worker-runnable or already\n * has a worker.\n */\nexport async function ensureWorkerForActiveAgent(\n\tdeps: { events: ProcessEventRepoLike; supervisor: WorkerSupervisorLike },\n\tprocess: ProcessInstance,\n): Promise<void> {\n\tif (!processNeedsWorker(process) || deps.supervisor.getWorker(process.id)) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait deps.supervisor.spawnWorker(process.id);\n\t} catch (error) {\n\t\tdeps.events.create({\n\t\t\tinstanceId: process.id,\n\t\t\teventType: \"worker_spawn_failed\",\n\t\t\tdata: {\n\t\t\t\treason: error instanceof Error ? error.message : \"Failed to spawn worker\",\n\t\t\t},\n\t\t});\n\t\tthrow error;\n\t}\n}\n"],"mappings":";AAeO,SAAS,gBACf,QACA,YACA,WACU;AACV,SAAO,OAAO,eAAe,YAAY,GAAG,EAAE,KAAK,CAAC,UAAU,MAAM,cAAc,SAAS;AAC5F;AAEO,SAAS,mBACf,SACU;AACV,SAAO,QAAQ,mBAAmB,QAAQ,QAAQ,oBAAoB;AACvE;AAOA,eAAsB,2BACrB,MACA,SACgB;AAChB,MAAI,CAAC,mBAAmB,OAAO,KAAK,KAAK,WAAW,UAAU,QAAQ,EAAE,GAAG;AAC1E;AAAA,EACD;AACA,MAAI;AACH,UAAM,KAAK,WAAW,YAAY,QAAQ,EAAE;AAAA,EAC7C,SAAS,OAAO;AACf,SAAK,OAAO,OAAO;AAAA,MAClB,YAAY,QAAQ;AAAA,MACpB,WAAW;AAAA,MACX,MAAM;AAAA,QACL,QAAQ,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACD,CAAC;AACD,UAAM;AAAA,EACP;AACD;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/duration-parse.ts
|
|
2
|
+
import ms from "ms";
|
|
3
|
+
function parseDurationMs(value, defaultMs, _options = {}) {
|
|
4
|
+
const parsed = ms(value.trim());
|
|
5
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
6
|
+
return defaultMs;
|
|
7
|
+
}
|
|
8
|
+
return parsed;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
parseDurationMs
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-IU3L35PC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/duration-parse.ts"],"sourcesContent":["import ms from \"ms\";\n\n/**\n * Parse a human-friendly duration string (e.g. \"150ms\", \"1.5s\", \"2 min\") into\n * milliseconds. Returns `defaultMs` when the input cannot be parsed.\n *\n * `options.allowHours` is retained for existing callers; the underlying `ms`\n * parser supports hours and other common duration units by default.\n */\nexport function parseDurationMs(\n\tvalue: string,\n\tdefaultMs: number,\n\t_options: { allowHours?: boolean } = {},\n): number {\n\tconst parsed = ms(value.trim() as ms.StringValue);\n\tif (!Number.isFinite(parsed) || parsed < 0) {\n\t\treturn defaultMs;\n\t}\n\n\treturn parsed;\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AASR,SAAS,gBACf,OACA,WACA,WAAqC,CAAC,GAC7B;AACT,QAAM,SAAS,GAAG,MAAM,KAAK,CAAmB;AAChD,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,GAAG;AAC3C,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseDurationMs
|
|
3
|
+
} from "./chunk-IU3L35PC.js";
|
|
4
|
+
|
|
5
|
+
// src/poll-loop.ts
|
|
6
|
+
function emptyPollResult() {
|
|
7
|
+
return {
|
|
8
|
+
created: [],
|
|
9
|
+
aborted: [],
|
|
10
|
+
labelExchanged: [],
|
|
11
|
+
skipped: [],
|
|
12
|
+
errors: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function createPollLoop(opts) {
|
|
16
|
+
let timer = null;
|
|
17
|
+
let pollInFlight = null;
|
|
18
|
+
const defaultMs = opts.defaultIntervalMs ?? 6e4;
|
|
19
|
+
async function poll() {
|
|
20
|
+
if (pollInFlight) {
|
|
21
|
+
return pollInFlight;
|
|
22
|
+
}
|
|
23
|
+
const running = (async () => {
|
|
24
|
+
try {
|
|
25
|
+
return await opts.pollOnce();
|
|
26
|
+
} finally {
|
|
27
|
+
pollInFlight = null;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
pollInFlight = running;
|
|
31
|
+
return running;
|
|
32
|
+
}
|
|
33
|
+
function pollAndIgnoreUnhandledRejection() {
|
|
34
|
+
void poll().catch(() => void 0);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
poll,
|
|
38
|
+
start() {
|
|
39
|
+
if (timer) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!opts.isEnabled()) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const ms = parseDurationMs(opts.pollInterval(), defaultMs);
|
|
46
|
+
timer = setInterval(pollAndIgnoreUnhandledRejection, ms);
|
|
47
|
+
pollAndIgnoreUnhandledRejection();
|
|
48
|
+
},
|
|
49
|
+
stop() {
|
|
50
|
+
if (!timer) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
clearInterval(timer);
|
|
54
|
+
timer = null;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
emptyPollResult,
|
|
61
|
+
createPollLoop
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-XF2QQLPO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/poll-loop.ts"],"sourcesContent":["import { parseDurationMs } from \"./duration-parse.js\";\n\nexport interface PollResult {\n\tcreated: string[];\n\taborted: string[];\n\tlabelExchanged: string[];\n\tskipped: string[];\n\terrors: string[];\n}\n\nexport function emptyPollResult(): PollResult {\n\treturn {\n\t\tcreated: [],\n\t\taborted: [],\n\t\tlabelExchanged: [],\n\t\tskipped: [],\n\t\terrors: [],\n\t};\n}\n\nexport interface PollLoop<T extends PollResult = PollResult> {\n\tpoll(): Promise<T>;\n\tstart(): void;\n\tstop(): void;\n}\n\n/**\n * Create a non-overlapping polling loop. `pollOnce` is the actual work;\n * concurrent calls to `poll()` coalesce into the in-flight promise.\n */\nexport function createPollLoop<T extends PollResult>(opts: {\n\tpollOnce: () => Promise<T>;\n\tisEnabled: () => boolean;\n\tpollInterval: () => string;\n\tdefaultIntervalMs?: number;\n}): PollLoop<T> {\n\tlet timer: ReturnType<typeof setInterval> | null = null;\n\tlet pollInFlight: Promise<T> | null = null;\n\tconst defaultMs = opts.defaultIntervalMs ?? 60_000;\n\n\tasync function poll(): Promise<T> {\n\t\tif (pollInFlight) {\n\t\t\treturn pollInFlight;\n\t\t}\n\t\tconst running = (async () => {\n\t\t\ttry {\n\t\t\t\treturn await opts.pollOnce();\n\t\t\t} finally {\n\t\t\t\tpollInFlight = null;\n\t\t\t}\n\t\t})();\n\t\tpollInFlight = running;\n\t\treturn running;\n\t}\n\n\tfunction pollAndIgnoreUnhandledRejection(): void {\n\t\tvoid poll().catch(() => undefined);\n\t}\n\n\treturn {\n\t\tpoll,\n\t\tstart() {\n\t\t\tif (timer) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!opts.isEnabled()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst ms = parseDurationMs(opts.pollInterval(), defaultMs);\n\t\t\ttimer = setInterval(pollAndIgnoreUnhandledRejection, ms);\n\t\t\tpollAndIgnoreUnhandledRejection();\n\t\t},\n\t\tstop() {\n\t\t\tif (!timer) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclearInterval(timer);\n\t\t\ttimer = null;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AAUO,SAAS,kBAA8B;AAC7C,SAAO;AAAA,IACN,SAAS,CAAC;AAAA,IACV,SAAS,CAAC;AAAA,IACV,gBAAgB,CAAC;AAAA,IACjB,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,EACV;AACD;AAYO,SAAS,eAAqC,MAKrC;AACf,MAAI,QAA+C;AACnD,MAAI,eAAkC;AACtC,QAAM,YAAY,KAAK,qBAAqB;AAE5C,iBAAe,OAAmB;AACjC,QAAI,cAAc;AACjB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,YAAY;AAC5B,UAAI;AACH,eAAO,MAAM,KAAK,SAAS;AAAA,MAC5B,UAAE;AACD,uBAAe;AAAA,MAChB;AAAA,IACD,GAAG;AACH,mBAAe;AACf,WAAO;AAAA,EACR;AAEA,WAAS,kCAAwC;AAChD,SAAK,KAAK,EAAE,MAAM,MAAM,MAAS;AAAA,EAClC;AAEA,SAAO;AAAA,IACN;AAAA,IACA,QAAQ;AACP,UAAI,OAAO;AACV;AAAA,MACD;AACA,UAAI,CAAC,KAAK,UAAU,GAAG;AACtB;AAAA,MACD;AACA,YAAM,KAAK,gBAAgB,KAAK,aAAa,GAAG,SAAS;AACzD,cAAQ,YAAY,iCAAiC,EAAE;AACvD,sCAAgC;AAAA,IACjC;AAAA,IACA,OAAO;AACN,UAAI,CAAC,OAAO;AACX;AAAA,MACD;AACA,oBAAc,KAAK;AACnB,cAAQ;AAAA,IACT;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureWorkerForActiveAgent,
|
|
3
|
+
hasProcessEvent,
|
|
4
|
+
processNeedsWorker
|
|
5
|
+
} from "./chunk-3KGAUQIG.js";
|
|
6
|
+
|
|
7
|
+
// src/watcher-coordinator.ts
|
|
8
|
+
import {
|
|
9
|
+
recordWriteIfMissing
|
|
10
|
+
} from "@leitwerk-dev/external-writes";
|
|
11
|
+
function requireWatcherStartTurnId(launchPlan, targetLabel) {
|
|
12
|
+
if (launchPlan.startTurnId) {
|
|
13
|
+
return launchPlan.startTurnId;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Watcher launcher '${launchPlan.launcherId}' did not declare a startTurnId for ${targetLabel}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
async function continueWatcherAgentStartup(deps, opts) {
|
|
20
|
+
const { process } = opts;
|
|
21
|
+
if (!hasProcessEvent(deps.events, process.id, "agent_created")) {
|
|
22
|
+
deps.events.create({
|
|
23
|
+
instanceId: process.id,
|
|
24
|
+
eventType: "agent_created",
|
|
25
|
+
data: opts.createdEventData
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
await opts.afterCreatedEvent?.(process);
|
|
29
|
+
await opts.beforeStart?.(process);
|
|
30
|
+
let currentProcess = deps.processes.getById(process.id) ?? process;
|
|
31
|
+
if (currentProcess.lifecycleStatus === "discovered") {
|
|
32
|
+
const startResult = await deps.commands.startProcess(currentProcess.id, opts.startTurnId);
|
|
33
|
+
if (!startResult.ok) {
|
|
34
|
+
currentProcess = startResult.process ?? currentProcess;
|
|
35
|
+
throw new Error(startResult.message ?? "Failed to start process");
|
|
36
|
+
}
|
|
37
|
+
currentProcess = startResult.process ?? currentProcess;
|
|
38
|
+
if (opts.broadcastCreated !== false) {
|
|
39
|
+
deps.broadcaster.sendDurable(
|
|
40
|
+
"process.created",
|
|
41
|
+
{
|
|
42
|
+
process: currentProcess,
|
|
43
|
+
processId: currentProcess.processId,
|
|
44
|
+
...opts.createdBroadcastData
|
|
45
|
+
},
|
|
46
|
+
currentProcess.id
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await ensureWorkerForActiveAgent(deps, currentProcess);
|
|
51
|
+
return currentProcess.id;
|
|
52
|
+
}
|
|
53
|
+
async function runWatcherDiscoveryPass(opts) {
|
|
54
|
+
for (const item of opts.items) {
|
|
55
|
+
try {
|
|
56
|
+
const existingAgent = opts.findExistingAgent(item);
|
|
57
|
+
if (existingAgent) {
|
|
58
|
+
if (existingAgent.lifecycleStatus === "discovered") {
|
|
59
|
+
const resumeResult = await opts.resumeDiscoveredAgent(existingAgent, item);
|
|
60
|
+
if (resumeResult === "skipped") {
|
|
61
|
+
opts.result.skipped.push(opts.getResultLabel(item));
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (opts.ensureWorkerForExistingAgent) {
|
|
66
|
+
const handled = await opts.ensureWorkerForExistingAgent(existingAgent, item);
|
|
67
|
+
if (handled) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
opts.result.skipped.push(opts.getResultLabel(item));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const createResult = await opts.createAgent(item);
|
|
75
|
+
if (createResult?.outcome === "created") {
|
|
76
|
+
opts.result.created.push(opts.getResultLabel(item));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (createResult?.outcome === "skipped") {
|
|
80
|
+
opts.result.skipped.push(opts.getResultLabel(item));
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
opts.result.errors.push(opts.formatError(item, error));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function runWatcherAbortReconciliation(opts) {
|
|
88
|
+
for (const process of opts.candidates) {
|
|
89
|
+
try {
|
|
90
|
+
const shouldAbort = await opts.shouldAbort(process);
|
|
91
|
+
if (!shouldAbort) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const abortResult = await opts.commands.abortProcess(process.id);
|
|
95
|
+
if (!abortResult.ok) {
|
|
96
|
+
if (abortResult.code === "worker_reconcile_failed") {
|
|
97
|
+
throw new Error(abortResult.message ?? "Failed to abort process");
|
|
98
|
+
}
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const abortedAgent = abortResult.process ?? process;
|
|
102
|
+
if (!hasProcessEvent(opts.events, abortedAgent.id, "aborted_label_removed")) {
|
|
103
|
+
opts.events.create({
|
|
104
|
+
instanceId: abortedAgent.id,
|
|
105
|
+
eventType: "aborted_label_removed",
|
|
106
|
+
data: opts.getAbortedEventData(abortedAgent)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
opts.result.aborted.push(opts.getResultLabel(process));
|
|
110
|
+
} catch (error) {
|
|
111
|
+
opts.result.errors.push(
|
|
112
|
+
`${opts.getErrorLabel(process)}: ${error instanceof Error ? error.message : String(error)}`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function runWatcherCompletionReconciliation(opts) {
|
|
118
|
+
for (const process of opts.candidates) {
|
|
119
|
+
try {
|
|
120
|
+
const reconciliation = await opts.reconcile(process);
|
|
121
|
+
if (!reconciliation.changed) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (reconciliation.writeIdentity) {
|
|
125
|
+
recordWriteIfMissing(
|
|
126
|
+
opts.externalWrites,
|
|
127
|
+
process.id,
|
|
128
|
+
reconciliation.writeIdentity,
|
|
129
|
+
reconciliation.metadata
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
opts.result.labelExchanged.push(opts.getResultLabel(process));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
opts.result.errors.push(
|
|
135
|
+
`${opts.getErrorLabel(process)}: ${error instanceof Error ? error.message : String(error)}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function shouldEnsureWorkerForExistingActiveAgent(deps, process) {
|
|
141
|
+
return processNeedsWorker(process) && !deps.supervisor.getWorker(process.id);
|
|
142
|
+
}
|
|
143
|
+
function deferWatcherLaunchStart(launchPlan) {
|
|
144
|
+
return launchPlan.startTurnId === null ? launchPlan : { ...launchPlan, startTurnId: null };
|
|
145
|
+
}
|
|
146
|
+
function launchFailureMessage(result) {
|
|
147
|
+
return typeof result.body.error === "string" && result.body.error.trim().length > 0 ? result.body.error : `Process launch failed with status ${result.status}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
requireWatcherStartTurnId,
|
|
152
|
+
continueWatcherAgentStartup,
|
|
153
|
+
runWatcherDiscoveryPass,
|
|
154
|
+
runWatcherAbortReconciliation,
|
|
155
|
+
runWatcherCompletionReconciliation,
|
|
156
|
+
shouldEnsureWorkerForExistingActiveAgent,
|
|
157
|
+
deferWatcherLaunchStart,
|
|
158
|
+
launchFailureMessage
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=chunk-XLVMFO6W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/watcher-coordinator.ts"],"sourcesContent":["import type { ProcessInstance, TurnId } from \"@leitwerk-dev/domain\";\nimport {\n\ttype ExternalWriteLogRepoLike,\n\trecordWriteIfMissing,\n\ttype WriteIdentity,\n} from \"@leitwerk-dev/external-writes\";\nimport type { KnownDurableWsFrameType, WsPayloadByType } from \"@leitwerk-dev/protocol\";\nimport type { PollResult } from \"./poll-loop.js\";\nimport {\n\tensureWorkerForActiveAgent,\n\thasProcessEvent,\n\ttype ProcessEventRepoLike,\n\tprocessNeedsWorker,\n\ttype WorkerSupervisorLike,\n} from \"./process-helpers.js\";\n\nexport interface AgentRepoAccessorLike {\n\tgetById(id: string): ProcessInstance | null;\n}\n\nexport interface BroadcasterLike {\n\tsendDurable<T extends KnownDurableWsFrameType>(\n\t\ttype: T,\n\t\tpayload: WsPayloadByType[T],\n\t\tinstanceId?: string,\n\t): void;\n}\n\nexport interface WatcherCommandResult {\n\tok: boolean;\n\tcode?: string;\n\tmessage?: string;\n\tprocess?: ProcessInstance | null;\n}\n\nexport interface WatcherCommandServiceLike {\n\tstartProcess(instanceId: string, startTurnId: TurnId): Promise<WatcherCommandResult>;\n\tabortProcess(instanceId: string): Promise<WatcherCommandResult>;\n}\n\nexport interface WatcherStartupDeps {\n\tprocesses: AgentRepoAccessorLike;\n\tevents: ProcessEventRepoLike;\n\tbroadcaster: BroadcasterLike;\n\tcommands: WatcherCommandServiceLike;\n\tsupervisor: WorkerSupervisorLike;\n}\n\nexport interface ContinueWatcherAgentStartupOptions {\n\tprocess: ProcessInstance;\n\tstartTurnId: TurnId;\n\tcreatedEventData: Record<string, unknown>;\n\tcreatedBroadcastData: Record<string, unknown>;\n\t/** Defaults to true. Set false when the shared launch executor already emitted process.created. */\n\tbroadcastCreated?: boolean;\n\tafterCreatedEvent?: (process: ProcessInstance) => Promise<void> | void;\n\tbeforeStart?: (process: ProcessInstance) => Promise<void>;\n}\n\nexport function requireWatcherStartTurnId(\n\tlaunchPlan: { launcherId: string; startTurnId: TurnId | null },\n\ttargetLabel: string,\n): TurnId {\n\tif (launchPlan.startTurnId) {\n\t\treturn launchPlan.startTurnId;\n\t}\n\tthrow new Error(\n\t\t`Watcher launcher '${launchPlan.launcherId}' did not declare a startTurnId for ${targetLabel}`,\n\t);\n}\n\nexport async function continueWatcherAgentStartup(\n\tdeps: WatcherStartupDeps,\n\topts: ContinueWatcherAgentStartupOptions,\n): Promise<string> {\n\tconst { process } = opts;\n\n\tif (!hasProcessEvent(deps.events, process.id, \"agent_created\")) {\n\t\tdeps.events.create({\n\t\t\tinstanceId: process.id,\n\t\t\teventType: \"agent_created\",\n\t\t\tdata: opts.createdEventData,\n\t\t});\n\t}\n\n\tawait opts.afterCreatedEvent?.(process);\n\tawait opts.beforeStart?.(process);\n\n\tlet currentProcess = deps.processes.getById(process.id) ?? process;\n\tif (currentProcess.lifecycleStatus === \"discovered\") {\n\t\tconst startResult = await deps.commands.startProcess(currentProcess.id, opts.startTurnId);\n\t\tif (!startResult.ok) {\n\t\t\tcurrentProcess = startResult.process ?? currentProcess;\n\t\t\tthrow new Error(startResult.message ?? \"Failed to start process\");\n\t\t}\n\t\tcurrentProcess = startResult.process ?? currentProcess;\n\t\tif (opts.broadcastCreated !== false) {\n\t\t\tdeps.broadcaster.sendDurable(\n\t\t\t\t\"process.created\",\n\t\t\t\t{\n\t\t\t\t\tprocess: currentProcess,\n\t\t\t\t\tprocessId: currentProcess.processId,\n\t\t\t\t\t...opts.createdBroadcastData,\n\t\t\t\t},\n\t\t\t\tcurrentProcess.id,\n\t\t\t);\n\t\t}\n\t}\n\n\tawait ensureWorkerForActiveAgent(deps, currentProcess);\n\treturn currentProcess.id;\n}\n\nexport type DiscoveryResumeResult = \"handled\" | \"skipped\" | undefined;\n\nexport type DiscoveryCreateResult =\n\t| { outcome: \"created\"; instanceId: string }\n\t| { outcome: \"skipped\" }\n\t| { outcome: \"handled\" }\n\t| null\n\t| undefined;\n\nexport interface DiscoveryPassOptions<TItem> {\n\titems: readonly TItem[];\n\tresult: PollResult;\n\tfindExistingAgent(item: TItem): ProcessInstance | null;\n\tgetResultLabel(item: TItem): string;\n\tresumeDiscoveredAgent(process: ProcessInstance, item: TItem): Promise<DiscoveryResumeResult>;\n\tcreateAgent(item: TItem): Promise<DiscoveryCreateResult>;\n\tensureWorkerForExistingAgent?(process: ProcessInstance, item: TItem): Promise<boolean>;\n\tformatError(item: TItem, error: unknown): string;\n}\n\nexport async function runWatcherDiscoveryPass<TItem>(\n\topts: DiscoveryPassOptions<TItem>,\n): Promise<void> {\n\tfor (const item of opts.items) {\n\t\ttry {\n\t\t\tconst existingAgent = opts.findExistingAgent(item);\n\t\t\tif (existingAgent) {\n\t\t\t\tif (existingAgent.lifecycleStatus === \"discovered\") {\n\t\t\t\t\tconst resumeResult = await opts.resumeDiscoveredAgent(existingAgent, item);\n\t\t\t\t\tif (resumeResult === \"skipped\") {\n\t\t\t\t\t\topts.result.skipped.push(opts.getResultLabel(item));\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (opts.ensureWorkerForExistingAgent) {\n\t\t\t\t\tconst handled = await opts.ensureWorkerForExistingAgent(existingAgent, item);\n\t\t\t\t\tif (handled) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\topts.result.skipped.push(opts.getResultLabel(item));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst createResult = await opts.createAgent(item);\n\t\t\tif (createResult?.outcome === \"created\") {\n\t\t\t\topts.result.created.push(opts.getResultLabel(item));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (createResult?.outcome === \"skipped\") {\n\t\t\t\topts.result.skipped.push(opts.getResultLabel(item));\n\t\t\t}\n\t\t} catch (error) {\n\t\t\topts.result.errors.push(opts.formatError(item, error));\n\t\t}\n\t}\n}\n\nexport interface AbortReconciliationOptions {\n\tcandidates: readonly ProcessInstance[];\n\tresult: PollResult;\n\tevents: ProcessEventRepoLike;\n\tcommands: WatcherCommandServiceLike;\n\tshouldAbort(process: ProcessInstance): Promise<boolean>;\n\tgetResultLabel(process: ProcessInstance): string;\n\tgetErrorLabel(process: ProcessInstance): string;\n\tgetAbortedEventData(process: ProcessInstance): Record<string, unknown>;\n}\n\nexport async function runWatcherAbortReconciliation(\n\topts: AbortReconciliationOptions,\n): Promise<void> {\n\tfor (const process of opts.candidates) {\n\t\ttry {\n\t\t\tconst shouldAbort = await opts.shouldAbort(process);\n\t\t\tif (!shouldAbort) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst abortResult = await opts.commands.abortProcess(process.id);\n\t\t\tif (!abortResult.ok) {\n\t\t\t\tif (abortResult.code === \"worker_reconcile_failed\") {\n\t\t\t\t\tthrow new Error(abortResult.message ?? \"Failed to abort process\");\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst abortedAgent = abortResult.process ?? process;\n\t\t\tif (!hasProcessEvent(opts.events, abortedAgent.id, \"aborted_label_removed\")) {\n\t\t\t\topts.events.create({\n\t\t\t\t\tinstanceId: abortedAgent.id,\n\t\t\t\t\teventType: \"aborted_label_removed\",\n\t\t\t\t\tdata: opts.getAbortedEventData(abortedAgent),\n\t\t\t\t});\n\t\t\t}\n\t\t\topts.result.aborted.push(opts.getResultLabel(process));\n\t\t} catch (error) {\n\t\t\topts.result.errors.push(\n\t\t\t\t`${opts.getErrorLabel(process)}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport interface CompletionReconciliationResult {\n\tchanged: boolean;\n\twriteIdentity?: WriteIdentity;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface CompletionReconciliationOptions {\n\tcandidates: readonly ProcessInstance[];\n\tresult: PollResult;\n\texternalWrites: ExternalWriteLogRepoLike;\n\treconcile(process: ProcessInstance): Promise<CompletionReconciliationResult>;\n\tgetResultLabel(process: ProcessInstance): string;\n\tgetErrorLabel(process: ProcessInstance): string;\n}\n\nexport async function runWatcherCompletionReconciliation(\n\topts: CompletionReconciliationOptions,\n): Promise<void> {\n\tfor (const process of opts.candidates) {\n\t\ttry {\n\t\t\tconst reconciliation = await opts.reconcile(process);\n\t\t\tif (!reconciliation.changed) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (reconciliation.writeIdentity) {\n\t\t\t\trecordWriteIfMissing(\n\t\t\t\t\topts.externalWrites,\n\t\t\t\t\tprocess.id,\n\t\t\t\t\treconciliation.writeIdentity,\n\t\t\t\t\treconciliation.metadata,\n\t\t\t\t);\n\t\t\t}\n\t\t\topts.result.labelExchanged.push(opts.getResultLabel(process));\n\t\t} catch (error) {\n\t\t\topts.result.errors.push(\n\t\t\t\t`${opts.getErrorLabel(process)}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function shouldEnsureWorkerForExistingActiveAgent(\n\tdeps: { supervisor: WorkerSupervisorLike },\n\tprocess: ProcessInstance,\n): boolean {\n\treturn processNeedsWorker(process) && !deps.supervisor.getWorker(process.id);\n}\n\nexport function deferWatcherLaunchStart<TLaunchPlan extends { startTurnId: unknown }>(\n\tlaunchPlan: TLaunchPlan,\n): TLaunchPlan {\n\treturn launchPlan.startTurnId === null ? launchPlan : { ...launchPlan, startTurnId: null };\n}\n\nexport function launchFailureMessage(result: {\n\tstatus: number;\n\tbody: Record<string, unknown>;\n}): string {\n\treturn typeof result.body.error === \"string\" && result.body.error.trim().length > 0\n\t\t? result.body.error\n\t\t: `Process launch failed with status ${result.status}`;\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a human-friendly duration string (e.g. "150ms", "1.5s", "2 min") into
|
|
3
|
+
* milliseconds. Returns `defaultMs` when the input cannot be parsed.
|
|
4
|
+
*
|
|
5
|
+
* `options.allowHours` is retained for existing callers; the underlying `ms`
|
|
6
|
+
* parser supports hours and other common duration units by default.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseDurationMs(value: string, defaultMs: number, _options?: {
|
|
9
|
+
allowHours?: boolean;
|
|
10
|
+
}): number;
|
|
11
|
+
//# sourceMappingURL=duration-parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration-parse.d.ts","sourceRoot":"","sources":["../src/duration-parse.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACrC,MAAM,CAOR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ms from "ms";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a human-friendly duration string (e.g. "150ms", "1.5s", "2 min") into
|
|
4
|
+
* milliseconds. Returns `defaultMs` when the input cannot be parsed.
|
|
5
|
+
*
|
|
6
|
+
* `options.allowHours` is retained for existing callers; the underlying `ms`
|
|
7
|
+
* parser supports hours and other common duration units by default.
|
|
8
|
+
*/
|
|
9
|
+
export function parseDurationMs(value, defaultMs, _options = {}) {
|
|
10
|
+
const parsed = ms(value.trim());
|
|
11
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
12
|
+
return defaultMs;
|
|
13
|
+
}
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=duration-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration-parse.js","sourceRoot":"","sources":["../src/duration-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC9B,KAAa,EACb,SAAiB,EACjB,WAAqC,EAAE;IAEvC,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAoB,CAAC,CAAC;IAClD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @deprecated Import external-write idempotency from `@leitwerk-dev/external-writes`. */
|
|
2
|
+
export { createWriteIdentity, type EnsureWriteResult, type ExternalWriteLogRecordInput, type ExternalWriteLogRepoLike, ensureWrite, recordWriteIfMissing, type WriteIdentity, } from "@leitwerk-dev/external-writes";
|
|
3
|
+
export { parseDurationMs } from "./duration-parse.js";
|
|
4
|
+
export { createPollLoop, emptyPollResult, type PollLoop, type PollResult, } from "./poll-loop.js";
|
|
5
|
+
export { ensureWorkerForActiveAgent, hasProcessEvent, type ProcessEventRepoLike, processNeedsWorker, type WorkerSupervisorLike, } from "./process-helpers.js";
|
|
6
|
+
export { consumeTriggerFile, errorCode, readTriggerFile, type TriggerFileReadResult, } from "./trigger-files.js";
|
|
7
|
+
export { type AgentRepoAccessorLike, type BroadcasterLike, type CompletionReconciliationOptions, type CompletionReconciliationResult, type ContinueWatcherAgentStartupOptions, continueWatcherAgentStartup, type DiscoveryPassOptions, deferWatcherLaunchStart, launchFailureMessage, requireWatcherStartTurnId, runWatcherAbortReconciliation, runWatcherCompletionReconciliation, runWatcherDiscoveryPass, shouldEnsureWorkerForExistingActiveAgent, type WatcherCommandResult, type WatcherCommandServiceLike, type WatcherStartupDeps, } from "./watcher-coordinator.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EACN,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,WAAW,EACX,oBAAoB,EACpB,KAAK,aAAa,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,cAAc,EACd,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,UAAU,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,0BAA0B,EAC1B,eAAe,EACf,KAAK,oBAAoB,EACzB,kBAAkB,EAClB,KAAK,oBAAoB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,KAAK,qBAAqB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,+BAA+B,EACpC,KAAK,8BAA8B,EACnC,KAAK,kCAAkC,EACvC,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,kCAAkC,EAClC,uBAAuB,EACvB,wCAAwC,EACxC,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACvB,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @deprecated Import external-write idempotency from `@leitwerk-dev/external-writes`. */
|
|
2
|
+
export { createWriteIdentity, ensureWrite, recordWriteIfMissing, } from "@leitwerk-dev/external-writes";
|
|
3
|
+
export { parseDurationMs } from "./duration-parse.js";
|
|
4
|
+
export { createPollLoop, emptyPollResult, } from "./poll-loop.js";
|
|
5
|
+
export { ensureWorkerForActiveAgent, hasProcessEvent, processNeedsWorker, } from "./process-helpers.js";
|
|
6
|
+
export { consumeTriggerFile, errorCode, readTriggerFile, } from "./trigger-files.js";
|
|
7
|
+
export { continueWatcherAgentStartup, deferWatcherLaunchStart, launchFailureMessage, requireWatcherStartTurnId, runWatcherAbortReconciliation, runWatcherCompletionReconciliation, runWatcherDiscoveryPass, shouldEnsureWorkerForExistingActiveAgent, } from "./watcher-coordinator.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EACN,mBAAmB,EAInB,WAAW,EACX,oBAAoB,GAEpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,cAAc,EACd,eAAe,GAGf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,0BAA0B,EAC1B,eAAe,EAEf,kBAAkB,GAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,eAAe,GAEf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAMN,2BAA2B,EAE3B,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,kCAAkC,EAClC,uBAAuB,EACvB,wCAAwC,GAIxC,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface PollResult {
|
|
2
|
+
created: string[];
|
|
3
|
+
aborted: string[];
|
|
4
|
+
labelExchanged: string[];
|
|
5
|
+
skipped: string[];
|
|
6
|
+
errors: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function emptyPollResult(): PollResult;
|
|
9
|
+
export interface PollLoop<T extends PollResult = PollResult> {
|
|
10
|
+
poll(): Promise<T>;
|
|
11
|
+
start(): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a non-overlapping polling loop. `pollOnce` is the actual work;
|
|
16
|
+
* concurrent calls to `poll()` coalesce into the in-flight promise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createPollLoop<T extends PollResult>(opts: {
|
|
19
|
+
pollOnce: () => Promise<T>;
|
|
20
|
+
isEnabled: () => boolean;
|
|
21
|
+
pollInterval: () => string;
|
|
22
|
+
defaultIntervalMs?: number;
|
|
23
|
+
}): PollLoop<T>;
|
|
24
|
+
//# sourceMappingURL=poll-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll-loop.d.ts","sourceRoot":"","sources":["../src/poll-loop.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,wBAAgB,eAAe,IAAI,UAAU,CAQ5C;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC1D,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE;IAC1D,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,QAAQ,CAAC,CAAC,CAAC,CA6Cd"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { parseDurationMs } from "./duration-parse.js";
|
|
2
|
+
export function emptyPollResult() {
|
|
3
|
+
return {
|
|
4
|
+
created: [],
|
|
5
|
+
aborted: [],
|
|
6
|
+
labelExchanged: [],
|
|
7
|
+
skipped: [],
|
|
8
|
+
errors: [],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a non-overlapping polling loop. `pollOnce` is the actual work;
|
|
13
|
+
* concurrent calls to `poll()` coalesce into the in-flight promise.
|
|
14
|
+
*/
|
|
15
|
+
export function createPollLoop(opts) {
|
|
16
|
+
let timer = null;
|
|
17
|
+
let pollInFlight = null;
|
|
18
|
+
const defaultMs = opts.defaultIntervalMs ?? 60_000;
|
|
19
|
+
async function poll() {
|
|
20
|
+
if (pollInFlight) {
|
|
21
|
+
return pollInFlight;
|
|
22
|
+
}
|
|
23
|
+
const running = (async () => {
|
|
24
|
+
try {
|
|
25
|
+
return await opts.pollOnce();
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
pollInFlight = null;
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
pollInFlight = running;
|
|
32
|
+
return running;
|
|
33
|
+
}
|
|
34
|
+
function pollAndIgnoreUnhandledRejection() {
|
|
35
|
+
void poll().catch(() => undefined);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
poll,
|
|
39
|
+
start() {
|
|
40
|
+
if (timer) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!opts.isEnabled()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const ms = parseDurationMs(opts.pollInterval(), defaultMs);
|
|
47
|
+
timer = setInterval(pollAndIgnoreUnhandledRejection, ms);
|
|
48
|
+
pollAndIgnoreUnhandledRejection();
|
|
49
|
+
},
|
|
50
|
+
stop() {
|
|
51
|
+
if (!timer) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
clearInterval(timer);
|
|
55
|
+
timer = null;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=poll-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll-loop.js","sourceRoot":"","sources":["../src/poll-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAUtD,MAAM,UAAU,eAAe;IAC9B,OAAO;QACN,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;QACX,cAAc,EAAE,EAAE;QAClB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;KACV,CAAC;AACH,CAAC;AAQD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAuB,IAKpD;IACA,IAAI,KAAK,GAA0C,IAAI,CAAC;IACxD,IAAI,YAAY,GAAsB,IAAI,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,IAAI,MAAM,CAAC;IAEnD,KAAK,UAAU,IAAI;QAClB,IAAI,YAAY,EAAE,CAAC;YAClB,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC;gBACJ,OAAO,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9B,CAAC;oBAAS,CAAC;gBACV,YAAY,GAAG,IAAI,CAAC;YACrB,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;QACL,YAAY,GAAG,OAAO,CAAC;QACvB,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,SAAS,+BAA+B;QACvC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACN,IAAI;QACJ,KAAK;YACJ,IAAI,KAAK,EAAE,CAAC;gBACX,OAAO;YACR,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,OAAO;YACR,CAAC;YACD,MAAM,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC;YAC3D,KAAK,GAAG,WAAW,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;YACzD,+BAA+B,EAAE,CAAC;QACnC,CAAC;QACD,IAAI;YACH,IAAI,CAAC,KAAK,EAAE,CAAC;gBACZ,OAAO;YACR,CAAC;YACD,aAAa,CAAC,KAAK,CAAC,CAAC;YACrB,KAAK,GAAG,IAAI,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
|
+
export interface ProcessEventRepoLike {
|
|
3
|
+
create(input: {
|
|
4
|
+
instanceId: string;
|
|
5
|
+
eventType: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
}): unknown;
|
|
8
|
+
listByInstance(instanceId: string, limit?: number): Array<{
|
|
9
|
+
eventType: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerSupervisorLike {
|
|
13
|
+
spawnWorker(instanceId: string): Promise<unknown>;
|
|
14
|
+
getWorker(instanceId: string): unknown | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check whether a process already has an event of the given type.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasProcessEvent(events: ProcessEventRepoLike, instanceId: string, eventType: string): boolean;
|
|
20
|
+
export declare function processNeedsWorker(process: Pick<ProcessInstance, "selectedTurnId" | "lifecycleStatus">): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Spawn a worker for a process whose selected turn is runnable but currently has
|
|
23
|
+
* no running worker. No-ops when the process is not worker-runnable or already
|
|
24
|
+
* has a worker.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ensureWorkerForActiveAgent(deps: {
|
|
27
|
+
events: ProcessEventRepoLike;
|
|
28
|
+
supervisor: WorkerSupervisorLike;
|
|
29
|
+
}, process: ProcessInstance): Promise<void>;
|
|
30
|
+
//# sourceMappingURL=process-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-helpers.d.ts","sourceRoot":"","sources":["../src/process-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,oBAAoB;IACpC,MAAM,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC;IAClG,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,oBAAoB;IACpC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACnD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,oBAAoB,EAC5B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GACf,OAAO,CAET;AAED,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,GAClE,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC/C,IAAI,EAAE;IAAE,MAAM,EAAE,oBAAoB,CAAC;IAAC,UAAU,EAAE,oBAAoB,CAAA;CAAE,EACxE,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a process already has an event of the given type.
|
|
3
|
+
*/
|
|
4
|
+
export function hasProcessEvent(events, instanceId, eventType) {
|
|
5
|
+
return events.listByInstance(instanceId, 200).some((event) => event.eventType === eventType);
|
|
6
|
+
}
|
|
7
|
+
export function processNeedsWorker(process) {
|
|
8
|
+
return process.selectedTurnId !== null && process.lifecycleStatus === "active";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Spawn a worker for a process whose selected turn is runnable but currently has
|
|
12
|
+
* no running worker. No-ops when the process is not worker-runnable or already
|
|
13
|
+
* has a worker.
|
|
14
|
+
*/
|
|
15
|
+
export async function ensureWorkerForActiveAgent(deps, process) {
|
|
16
|
+
if (!processNeedsWorker(process) || deps.supervisor.getWorker(process.id)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await deps.supervisor.spawnWorker(process.id);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
deps.events.create({
|
|
24
|
+
instanceId: process.id,
|
|
25
|
+
eventType: "worker_spawn_failed",
|
|
26
|
+
data: {
|
|
27
|
+
reason: error instanceof Error ? error.message : "Failed to spawn worker",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=process-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-helpers.js","sourceRoot":"","sources":["../src/process-helpers.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,UAAU,eAAe,CAC9B,MAA4B,EAC5B,UAAkB,EAClB,SAAiB;IAEjB,OAAO,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,UAAU,kBAAkB,CACjC,OAAoE;IAEpE,OAAO,OAAO,CAAC,cAAc,KAAK,IAAI,IAAI,OAAO,CAAC,eAAe,KAAK,QAAQ,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC/C,IAAwE,EACxE,OAAwB;IAExB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QAC3E,OAAO;IACR,CAAC;IACD,IAAI,CAAC;QACJ,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YAClB,UAAU,EAAE,OAAO,CAAC,EAAE;YACtB,SAAS,EAAE,qBAAqB;YAChC,IAAI,EAAE;gBACL,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB;aACzE;SACD,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type TriggerFileReadResult = {
|
|
2
|
+
exists: false;
|
|
3
|
+
} | {
|
|
4
|
+
exists: true;
|
|
5
|
+
content: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function errorCode(error: unknown): string | null;
|
|
8
|
+
export declare function readTriggerFile(filePath: string): Promise<TriggerFileReadResult>;
|
|
9
|
+
export declare function consumeTriggerFile(filePath: string): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=trigger-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-files.d.ts","sourceRoot":"","sources":["../src/trigger-files.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMvD;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAStF;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASxE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFile, unlink } from "node:fs/promises";
|
|
2
|
+
export function errorCode(error) {
|
|
3
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const code = error.code;
|
|
7
|
+
return typeof code === "string" ? code : null;
|
|
8
|
+
}
|
|
9
|
+
export async function readTriggerFile(filePath) {
|
|
10
|
+
try {
|
|
11
|
+
return { exists: true, content: await readFile(filePath, "utf8") };
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (errorCode(error) === "ENOENT") {
|
|
15
|
+
return { exists: false };
|
|
16
|
+
}
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function consumeTriggerFile(filePath) {
|
|
21
|
+
try {
|
|
22
|
+
await unlink(filePath);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (errorCode(error) === "ENOENT") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=trigger-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-files.js","sourceRoot":"","sources":["../src/trigger-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,UAAU,SAAS,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,IAAI,GAAI,KAA4B,CAAC,IAAI,CAAC;IAChD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB;IACrD,IAAI,CAAC;QACJ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAAgB;IACxD,IAAI,CAAC;QACJ,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO;QACR,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
|