@leitwerk-dev/watcher-utils 0.2.0 → 0.2.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.
Files changed (44) hide show
  1. package/dist/{chunk-HG5TEBHZ.js → chunk-BO52GPAV.js} +5 -7
  2. package/dist/chunk-BO52GPAV.js.map +1 -0
  3. package/dist/{chunk-IU3L35PC.js → chunk-D57H46H7.js} +1 -1
  4. package/dist/chunk-D57H46H7.js.map +1 -0
  5. package/dist/{chunk-3KGAUQIG.js → chunk-EWA6E2ZM.js} +1 -1
  6. package/dist/chunk-EWA6E2ZM.js.map +1 -0
  7. package/dist/{chunk-USTHXEZJ.js → chunk-ZW3LXDBX.js} +6 -4
  8. package/dist/chunk-ZW3LXDBX.js.map +1 -0
  9. package/dist/duration-parse.d.ts +2 -0
  10. package/dist/duration-parse.d.ts.map +1 -1
  11. package/dist/duration-parse.js +1 -1
  12. package/dist/index.d.ts +3 -5
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -33
  15. package/dist/index.js.map +1 -1
  16. package/dist/poll-loop.d.ts +22 -2
  17. package/dist/poll-loop.d.ts.map +1 -1
  18. package/dist/poll-loop.js +2 -2
  19. package/dist/polling-coordinator.d.ts +17 -1
  20. package/dist/polling-coordinator.d.ts.map +1 -1
  21. package/dist/polling-coordinator.js +3 -3
  22. package/dist/process-helpers.d.ts +15 -0
  23. package/dist/process-helpers.d.ts.map +1 -1
  24. package/dist/process-helpers.js +1 -1
  25. package/dist/trigger-files.d.ts +7 -0
  26. package/dist/trigger-files.d.ts.map +1 -1
  27. package/dist/watcher-coordinator.d.ts +77 -2
  28. package/dist/watcher-coordinator.d.ts.map +1 -1
  29. package/dist/watcher-coordinator.js +147 -10
  30. package/dist/watcher-coordinator.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/duration-parse.ts +5 -1
  33. package/src/index.ts +1 -38
  34. package/src/poll-loop.ts +25 -7
  35. package/src/polling-coordinator.ts +23 -3
  36. package/src/process-helpers.ts +30 -3
  37. package/src/trigger-files.ts +15 -1
  38. package/src/watcher-coordinator.ts +99 -11
  39. package/dist/chunk-3KGAUQIG.js.map +0 -1
  40. package/dist/chunk-HG5TEBHZ.js.map +0 -1
  41. package/dist/chunk-IU3L35PC.js.map +0 -1
  42. package/dist/chunk-USTHXEZJ.js.map +0 -1
  43. package/dist/chunk-XLVMFO6W.js +0 -160
  44. package/dist/chunk-XLVMFO6W.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseDurationMs
3
- } from "./chunk-IU3L35PC.js";
3
+ } from "./chunk-D57H46H7.js";
4
4
 
5
5
  // src/poll-loop.ts
6
6
  function createPollSchedule(now = () => Date.now()) {
@@ -58,12 +58,10 @@ function createPollLoop(opts) {
58
58
  timer = setInterval(pollScheduled, ms);
59
59
  pollScheduled();
60
60
  },
61
- stop() {
62
- if (!timer) {
63
- return;
64
- }
65
- clearInterval(timer);
61
+ async stop() {
62
+ if (timer) clearInterval(timer);
66
63
  timer = null;
64
+ await pollInFlight;
67
65
  }
68
66
  };
69
67
  }
@@ -73,4 +71,4 @@ export {
73
71
  emptyPollResult,
74
72
  createPollLoop
75
73
  };
76
- //# sourceMappingURL=chunk-HG5TEBHZ.js.map
74
+ //# sourceMappingURL=chunk-BO52GPAV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/poll-loop.ts"],"sourcesContent":["import { parseDurationMs } from \"./duration-parse.js\";\n\n/** Reserve the next poll time for a caller-owned key, before starting its work. @internal */\nexport function createPollSchedule(now: () => number = () => Date.now()) {\n\tconst dueAt = new Map<string, number>();\n\treturn (key: string, interval = \"30s\", timestamp = now()): boolean => {\n\t\tif ((dueAt.get(key) ?? 0) > timestamp) return false;\n\t\tdueAt.set(key, timestamp + parseDurationMs(interval, 30_000));\n\t\treturn true;\n\t};\n}\n\n/** @public */\nexport interface PollResult {\n\t/** @public */\n\tcreated: string[];\n\t/** @internal */\n\taborted: string[];\n\t/** @internal */\n\tlabelExchanged: string[];\n\t/** @public */\n\tskipped: string[];\n\t/** @public */\n\terrors: string[];\n}\n\n/** @public */\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\n/** @internal */\nexport interface PollResultWithErrors {\n\t/** @internal */\n\treadonly errors: readonly string[];\n}\n\n/** @internal */\nexport interface PollLoop<T extends PollResultWithErrors = PollResult> {\n\t/** @internal */\n\tpoll(): Promise<T>;\n\t/** @internal */\n\tstart(): void;\n\t/** @internal */\n\tstop(): Promise<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 */\n/** @internal */\nexport function createPollLoop<T extends PollResultWithErrors>(opts: {\n\t/** @internal */\n\tpollOnce: () => Promise<T>;\n\t/** @internal */\n\tisEnabled: () => boolean;\n\t/** @internal */\n\tpollInterval: () => string;\n\t/** @internal */\n\tdefaultIntervalMs?: number;\n\t/** @internal */\n\tonScheduledResult: (result: T, durationMs: number) => void;\n\t/** @internal */\n\tonScheduledError: (error: unknown, durationMs: number) => void;\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 pollScheduled(): void {\n\t\tconst startedAt = Date.now();\n\t\tvoid poll().then(\n\t\t\t(result) => opts.onScheduledResult(result, Date.now() - startedAt),\n\t\t\t(error: unknown) => opts.onScheduledError(error, Date.now() - startedAt),\n\t\t);\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(pollScheduled, ms);\n\t\t\tpollScheduled();\n\t\t},\n\t\tasync stop() {\n\t\t\tif (timer) clearInterval(timer);\n\t\t\ttimer = null;\n\t\t\tawait pollInFlight;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AAGO,SAAS,mBAAmB,MAAoB,MAAM,KAAK,IAAI,GAAG;AACxE,QAAM,QAAQ,oBAAI,IAAoB;AACtC,SAAO,CAAC,KAAa,WAAW,OAAO,YAAY,IAAI,MAAe;AACrE,SAAK,MAAM,IAAI,GAAG,KAAK,KAAK,UAAW,QAAO;AAC9C,UAAM,IAAI,KAAK,YAAY,gBAAgB,UAAU,GAAM,CAAC;AAC5D,WAAO;AAAA,EACR;AACD;AAiBO,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;AAuBO,SAAS,eAA+C,MAa/C;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,gBAAsB;AAC9B,UAAM,YAAY,KAAK,IAAI;AAC3B,SAAK,KAAK,EAAE;AAAA,MACX,CAAC,WAAW,KAAK,kBAAkB,QAAQ,KAAK,IAAI,IAAI,SAAS;AAAA,MACjE,CAAC,UAAmB,KAAK,iBAAiB,OAAO,KAAK,IAAI,IAAI,SAAS;AAAA,IACxE;AAAA,EACD;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,eAAe,EAAE;AACrC,oBAAc;AAAA,IACf;AAAA,IACA,MAAM,OAAO;AACZ,UAAI,MAAO,eAAc,KAAK;AAC9B,cAAQ;AACR,YAAM;AAAA,IACP;AAAA,EACD;AACD;","names":[]}
@@ -11,4 +11,4 @@ function parseDurationMs(value, defaultMs, _options = {}) {
11
11
  export {
12
12
  parseDurationMs
13
13
  };
14
- //# sourceMappingURL=chunk-IU3L35PC.js.map
14
+ //# sourceMappingURL=chunk-D57H46H7.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 */\n/** @public */\nexport function parseDurationMs(\n\tvalue: string,\n\tdefaultMs: number,\n\t_options: {\n\t\t/** @public */\n\t\tallowHours?: boolean;\n\t} = {},\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;AAUR,SAAS,gBACf,OACA,WACA,WAGI,CAAC,GACI;AACT,QAAM,SAAS,GAAG,MAAM,KAAK,CAAmB;AAChD,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,GAAG;AAC3C,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
@@ -28,4 +28,4 @@ export {
28
28
  processNeedsWorker,
29
29
  ensureWorkerForActiveAgent
30
30
  };
31
- //# sourceMappingURL=chunk-3KGAUQIG.js.map
31
+ //# sourceMappingURL=chunk-EWA6E2ZM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/process-helpers.ts"],"sourcesContent":["import type { ProcessInstance } from \"@leitwerk-dev/domain\";\n\n/** @internal */\nexport interface ProcessEventRepoLike {\n\t/** @internal */\n\tcreate(input: {\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\teventType: string;\n\t\t/** @internal */\n\t\tdata?: Record<string, unknown>;\n\t}): unknown;\n\t/** @internal */\n\tlistByInstance(\n\t\tinstanceId: string,\n\t\tlimit?: number,\n\t): Array<{\n\t\t/** @internal */\n\t\teventType: string;\n\t}>;\n}\n\n/** @internal */\nexport interface WorkerSupervisorLike {\n\t/** @internal */\n\tspawnWorker(instanceId: string): Promise<unknown>;\n\t/** @internal */\n\tgetWorker(instanceId: string): unknown | undefined;\n}\n\n/**\n * Check whether a process already has an event of the given type.\n */\n/** @internal */\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\n/** @internal */\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 */\n/** @internal */\nexport async function ensureWorkerForActiveAgent(\n\tdeps: {\n\t\t/** @internal */\n\t\tevents: ProcessEventRepoLike;\n\t\t/** @internal */\n\t\tsupervisor: WorkerSupervisorLike;\n\t},\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":";AAmCO,SAAS,gBACf,QACA,YACA,WACU;AACV,SAAO,OAAO,eAAe,YAAY,GAAG,EAAE,KAAK,CAAC,UAAU,MAAM,cAAc,SAAS;AAC5F;AAGO,SAAS,mBACf,SACU;AACV,SAAO,QAAQ,mBAAmB,QAAQ,QAAQ,oBAAoB;AACvE;AAQA,eAAsB,2BACrB,MAMA,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":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPollLoop
3
- } from "./chunk-HG5TEBHZ.js";
3
+ } from "./chunk-BO52GPAV.js";
4
4
 
5
5
  // src/polling-coordinator.ts
6
6
  function createPollingCoordinator(logger) {
@@ -32,8 +32,10 @@ function createPollingCoordinator(logger) {
32
32
  sealed = true;
33
33
  for (const loop of loops.values()) loop.start();
34
34
  },
35
- stop() {
36
- for (const loop of loops.values()) loop.stop();
35
+ async stop() {
36
+ const results = await Promise.allSettled([...loops.values()].map((loop) => loop.stop()));
37
+ const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
38
+ if (errors.length) throw new AggregateError(errors, "Polling shutdown failed");
37
39
  }
38
40
  };
39
41
  }
@@ -41,4 +43,4 @@ function createPollingCoordinator(logger) {
41
43
  export {
42
44
  createPollingCoordinator
43
45
  };
44
- //# sourceMappingURL=chunk-USTHXEZJ.js.map
46
+ //# sourceMappingURL=chunk-ZW3LXDBX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/polling-coordinator.ts"],"sourcesContent":["import { createPollLoop, type PollResult, type PollResultWithErrors } from \"./poll-loop.js\";\n\n/** @internal */\nexport interface PollingLogger {\n\t/** @internal */\n\twarn(payload: Record<string, unknown>, message?: string): void;\n\t/** @internal */\n\terror(payload: Record<string, unknown>, message?: string): void;\n}\n\n/** @internal */\nexport interface PollingRegistration<T extends PollResultWithErrors> {\n\t/** @internal */\n\tid: string;\n\t/** @internal */\n\tpollOnce(): Promise<T>;\n\t/** @internal */\n\tisEnabled(): boolean;\n\t/** @internal */\n\tpollInterval(): string;\n\t/** @internal */\n\tdefaultIntervalMs?: number;\n}\n\n/** @internal */\nexport interface RegisteredPoller<T extends PollResultWithErrors = PollResult> {\n\t/** @internal */\n\tpoll(): Promise<T>;\n}\n\n/** @internal */\nexport interface PollingCoordinator {\n\t/** @internal */\n\tcreate<T extends PollResultWithErrors>(registration: PollingRegistration<T>): RegisteredPoller<T>;\n\t/** @internal */\n\tstart(): void;\n\t/** @internal */\n\tstop(): Promise<void>;\n}\n\n/** @internal */\nexport function createPollingCoordinator(logger: PollingLogger): PollingCoordinator {\n\tconst loops = new Map<string, ReturnType<typeof createPollLoop>>();\n\tlet sealed = false;\n\n\treturn {\n\t\tcreate<T extends PollResultWithErrors>(\n\t\t\tregistration: PollingRegistration<T>,\n\t\t): RegisteredPoller<T> {\n\t\t\tconst id = registration.id.trim();\n\t\t\tif (!id) throw new Error(\"Polling registration id must not be empty\");\n\t\t\tif (sealed) throw new Error(`Cannot register poller '${id}' after polling has started`);\n\t\t\tif (loops.has(id)) throw new Error(`Duplicate poller '${id}'`);\n\n\t\t\tconst loop = createPollLoop({\n\t\t\t\tpollOnce: registration.pollOnce,\n\t\t\t\tisEnabled: registration.isEnabled,\n\t\t\t\tpollInterval: registration.pollInterval,\n\t\t\t\tdefaultIntervalMs: registration.defaultIntervalMs,\n\t\t\t\tonScheduledResult(result, durationMs) {\n\t\t\t\t\tif (result.errors.length === 0) return;\n\t\t\t\t\tlogger.warn({ pollerId: id, durationMs, result }, \"Poll completed with errors\");\n\t\t\t\t},\n\t\t\t\tonScheduledError(error, durationMs) {\n\t\t\t\t\tlogger.error({ pollerId: id, durationMs, err: error }, \"Poll failed\");\n\t\t\t\t},\n\t\t\t});\n\t\t\tloops.set(id, loop);\n\t\t\treturn { poll: loop.poll };\n\t\t},\n\t\tstart() {\n\t\t\tsealed = true;\n\t\t\tfor (const loop of loops.values()) loop.start();\n\t\t},\n\t\tasync stop() {\n\t\t\tconst results = await Promise.allSettled([...loops.values()].map((loop) => loop.stop()));\n\t\t\tconst errors = results\n\t\t\t\t.filter((result) => result.status === \"rejected\")\n\t\t\t\t.map((result) => result.reason);\n\t\t\tif (errors.length) throw new AggregateError(errors, \"Polling shutdown failed\");\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AAyCO,SAAS,yBAAyB,QAA2C;AACnF,QAAM,QAAQ,oBAAI,IAA+C;AACjE,MAAI,SAAS;AAEb,SAAO;AAAA,IACN,OACC,cACsB;AACtB,YAAM,KAAK,aAAa,GAAG,KAAK;AAChC,UAAI,CAAC,GAAI,OAAM,IAAI,MAAM,2CAA2C;AACpE,UAAI,OAAQ,OAAM,IAAI,MAAM,2BAA2B,EAAE,6BAA6B;AACtF,UAAI,MAAM,IAAI,EAAE,EAAG,OAAM,IAAI,MAAM,qBAAqB,EAAE,GAAG;AAE7D,YAAM,OAAO,eAAe;AAAA,QAC3B,UAAU,aAAa;AAAA,QACvB,WAAW,aAAa;AAAA,QACxB,cAAc,aAAa;AAAA,QAC3B,mBAAmB,aAAa;AAAA,QAChC,kBAAkB,QAAQ,YAAY;AACrC,cAAI,OAAO,OAAO,WAAW,EAAG;AAChC,iBAAO,KAAK,EAAE,UAAU,IAAI,YAAY,OAAO,GAAG,4BAA4B;AAAA,QAC/E;AAAA,QACA,iBAAiB,OAAO,YAAY;AACnC,iBAAO,MAAM,EAAE,UAAU,IAAI,YAAY,KAAK,MAAM,GAAG,aAAa;AAAA,QACrE;AAAA,MACD,CAAC;AACD,YAAM,IAAI,IAAI,IAAI;AAClB,aAAO,EAAE,MAAM,KAAK,KAAK;AAAA,IAC1B;AAAA,IACA,QAAQ;AACP,eAAS;AACT,iBAAW,QAAQ,MAAM,OAAO,EAAG,MAAK,MAAM;AAAA,IAC/C;AAAA,IACA,MAAM,OAAO;AACZ,YAAM,UAAU,MAAM,QAAQ,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC;AACvF,YAAM,SAAS,QACb,OAAO,CAAC,WAAW,OAAO,WAAW,UAAU,EAC/C,IAAI,CAAC,WAAW,OAAO,MAAM;AAC/B,UAAI,OAAO,OAAQ,OAAM,IAAI,eAAe,QAAQ,yBAAyB;AAAA,IAC9E;AAAA,EACD;AACD;","names":[]}
@@ -5,7 +5,9 @@
5
5
  * `options.allowHours` is retained for existing callers; the underlying `ms`
6
6
  * parser supports hours and other common duration units by default.
7
7
  */
8
+ /** @public */
8
9
  export declare function parseDurationMs(value: string, defaultMs: number, _options?: {
10
+ /** @public */
9
11
  allowHours?: boolean;
10
12
  }): number;
11
13
  //# sourceMappingURL=duration-parse.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"duration-parse.d.ts","sourceRoot":"","sources":["../src/duration-parse.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,cAAc;AACd,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE;IACT,cAAc;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CAChB,GACJ,MAAM,CAOR"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseDurationMs
3
- } from "./chunk-IU3L35PC.js";
3
+ } from "./chunk-D57H46H7.js";
4
4
  export {
5
5
  parseDurationMs
6
6
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export { parseDurationMs } from "./duration-parse.js";
2
- export { createPollLoop, createPollSchedule, emptyPollResult, type PollLoop, type PollResult, type PollResultWithErrors, } from "./poll-loop.js";
3
- export { createPollingCoordinator, type PollingCoordinator, type PollingLogger, type PollingRegistration, type RegisteredPoller, } from "./polling-coordinator.js";
4
- export { ensureWorkerForActiveAgent, hasProcessEvent, type ProcessEventRepoLike, processNeedsWorker, type WorkerSupervisorLike, } from "./process-helpers.js";
5
- export { consumeTriggerFile, errorCode, readTriggerFile, type TriggerFileReadResult, } from "./trigger-files.js";
6
- 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";
2
+ export { createPollSchedule, emptyPollResult, type PollResult, } from "./poll-loop.js";
3
+ export { createPollingCoordinator } from "./polling-coordinator.js";
4
+ export { consumeTriggerFile, readTriggerFile, } from "./trigger-files.js";
7
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,oBAAoB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACrB,MAAM,0BAA0B,CAAC;AAClC,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,KAAK,UAAU,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACN,kBAAkB,EAClB,eAAe,GACf,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,29 +1,13 @@
1
1
  import {
2
2
  createPollingCoordinator
3
- } from "./chunk-USTHXEZJ.js";
3
+ } from "./chunk-ZW3LXDBX.js";
4
4
  import {
5
- createPollLoop,
6
5
  createPollSchedule,
7
6
  emptyPollResult
8
- } from "./chunk-HG5TEBHZ.js";
7
+ } from "./chunk-BO52GPAV.js";
9
8
  import {
10
9
  parseDurationMs
11
- } from "./chunk-IU3L35PC.js";
12
- import {
13
- continueWatcherAgentStartup,
14
- deferWatcherLaunchStart,
15
- launchFailureMessage,
16
- requireWatcherStartTurnId,
17
- runWatcherAbortReconciliation,
18
- runWatcherCompletionReconciliation,
19
- runWatcherDiscoveryPass,
20
- shouldEnsureWorkerForExistingActiveAgent
21
- } from "./chunk-XLVMFO6W.js";
22
- import {
23
- ensureWorkerForActiveAgent,
24
- hasProcessEvent,
25
- processNeedsWorker
26
- } from "./chunk-3KGAUQIG.js";
10
+ } from "./chunk-D57H46H7.js";
27
11
 
28
12
  // src/trigger-files.ts
29
13
  import { readFile, unlink } from "fs/promises";
@@ -56,23 +40,10 @@ async function consumeTriggerFile(filePath) {
56
40
  }
57
41
  export {
58
42
  consumeTriggerFile,
59
- continueWatcherAgentStartup,
60
- createPollLoop,
61
43
  createPollSchedule,
62
44
  createPollingCoordinator,
63
- deferWatcherLaunchStart,
64
45
  emptyPollResult,
65
- ensureWorkerForActiveAgent,
66
- errorCode,
67
- hasProcessEvent,
68
- launchFailureMessage,
69
46
  parseDurationMs,
70
- processNeedsWorker,
71
- readTriggerFile,
72
- requireWatcherStartTurnId,
73
- runWatcherAbortReconciliation,
74
- runWatcherCompletionReconciliation,
75
- runWatcherDiscoveryPass,
76
- shouldEnsureWorkerForExistingActiveAgent
47
+ readTriggerFile
77
48
  };
78
49
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/trigger-files.ts"],"sourcesContent":["import { readFile, unlink } from \"node:fs/promises\";\n\nexport type TriggerFileReadResult = { exists: false } | { exists: true; content: string };\n\nexport function errorCode(error: unknown): string | null {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) {\n\t\treturn null;\n\t}\n\tconst code = (error as { code?: unknown }).code;\n\treturn typeof code === \"string\" ? code : null;\n}\n\nexport async function readTriggerFile(filePath: string): Promise<TriggerFileReadResult> {\n\ttry {\n\t\treturn { exists: true, content: await readFile(filePath, \"utf8\") };\n\t} catch (error) {\n\t\tif (errorCode(error) === \"ENOENT\") {\n\t\t\treturn { exists: false };\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function consumeTriggerFile(filePath: string): Promise<void> {\n\ttry {\n\t\tawait unlink(filePath);\n\t} catch (error) {\n\t\tif (errorCode(error) === \"ENOENT\") {\n\t\t\treturn;\n\t\t}\n\t\tthrow error;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,UAAU,cAAc;AAI1B,SAAS,UAAU,OAA+B;AACxD,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAAQ;AACtE,WAAO;AAAA,EACR;AACA,QAAM,OAAQ,MAA6B;AAC3C,SAAO,OAAO,SAAS,WAAW,OAAO;AAC1C;AAEA,eAAsB,gBAAgB,UAAkD;AACvF,MAAI;AACH,WAAO,EAAE,QAAQ,MAAM,SAAS,MAAM,SAAS,UAAU,MAAM,EAAE;AAAA,EAClE,SAAS,OAAO;AACf,QAAI,UAAU,KAAK,MAAM,UAAU;AAClC,aAAO,EAAE,QAAQ,MAAM;AAAA,IACxB;AACA,UAAM;AAAA,EACP;AACD;AAEA,eAAsB,mBAAmB,UAAiC;AACzE,MAAI;AACH,UAAM,OAAO,QAAQ;AAAA,EACtB,SAAS,OAAO;AACf,QAAI,UAAU,KAAK,MAAM,UAAU;AAClC;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/trigger-files.ts"],"sourcesContent":["import { readFile, unlink } from \"node:fs/promises\";\n\n/** @internal */\nexport type TriggerFileReadResult =\n\t| {\n\t\t\t/** @internal */\n\t\t\texists: false;\n\t }\n\t| {\n\t\t\t/** @internal */\n\t\t\texists: true;\n\t\t\t/** @internal */\n\t\t\tcontent: string;\n\t };\n\n/** @internal */\nexport function errorCode(error: unknown): string | null {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) {\n\t\treturn null;\n\t}\n\tconst code = (error as { code?: unknown }).code;\n\treturn typeof code === \"string\" ? code : null;\n}\n\n/** @internal */\nexport async function readTriggerFile(filePath: string): Promise<TriggerFileReadResult> {\n\ttry {\n\t\treturn { exists: true, content: await readFile(filePath, \"utf8\") };\n\t} catch (error) {\n\t\tif (errorCode(error) === \"ENOENT\") {\n\t\t\treturn { exists: false };\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** @internal */\nexport async function consumeTriggerFile(filePath: string): Promise<void> {\n\ttry {\n\t\tawait unlink(filePath);\n\t} catch (error) {\n\t\tif (errorCode(error) === \"ENOENT\") {\n\t\t\treturn;\n\t\t}\n\t\tthrow error;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,UAAU,cAAc;AAgB1B,SAAS,UAAU,OAA+B;AACxD,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAAQ;AACtE,WAAO;AAAA,EACR;AACA,QAAM,OAAQ,MAA6B;AAC3C,SAAO,OAAO,SAAS,WAAW,OAAO;AAC1C;AAGA,eAAsB,gBAAgB,UAAkD;AACvF,MAAI;AACH,WAAO,EAAE,QAAQ,MAAM,SAAS,MAAM,SAAS,UAAU,MAAM,EAAE;AAAA,EAClE,SAAS,OAAO;AACf,QAAI,UAAU,KAAK,MAAM,UAAU;AAClC,aAAO,EAAE,QAAQ,MAAM;AAAA,IACxB;AACA,UAAM;AAAA,EACP;AACD;AAGA,eAAsB,mBAAmB,UAAiC;AACzE,MAAI;AACH,UAAM,OAAO,QAAQ;AAAA,EACtB,SAAS,OAAO;AACf,QAAI,UAAU,KAAK,MAAM,UAAU;AAClC;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;","names":[]}
@@ -1,31 +1,51 @@
1
- /** Reserve the next poll time for a caller-owned key, before starting its work. */
1
+ /** Reserve the next poll time for a caller-owned key, before starting its work. @internal */
2
2
  export declare function createPollSchedule(now?: () => number): (key: string, interval?: string, timestamp?: number) => boolean;
3
+ /** @public */
3
4
  export interface PollResult {
5
+ /** @public */
4
6
  created: string[];
7
+ /** @internal */
5
8
  aborted: string[];
9
+ /** @internal */
6
10
  labelExchanged: string[];
11
+ /** @public */
7
12
  skipped: string[];
13
+ /** @public */
8
14
  errors: string[];
9
15
  }
16
+ /** @public */
10
17
  export declare function emptyPollResult(): PollResult;
18
+ /** @internal */
11
19
  export interface PollResultWithErrors {
20
+ /** @internal */
12
21
  readonly errors: readonly string[];
13
22
  }
23
+ /** @internal */
14
24
  export interface PollLoop<T extends PollResultWithErrors = PollResult> {
25
+ /** @internal */
15
26
  poll(): Promise<T>;
27
+ /** @internal */
16
28
  start(): void;
17
- stop(): void;
29
+ /** @internal */
30
+ stop(): Promise<void>;
18
31
  }
19
32
  /**
20
33
  * Create a non-overlapping polling loop. `pollOnce` is the actual work;
21
34
  * concurrent calls to `poll()` coalesce into the in-flight promise.
22
35
  */
36
+ /** @internal */
23
37
  export declare function createPollLoop<T extends PollResultWithErrors>(opts: {
38
+ /** @internal */
24
39
  pollOnce: () => Promise<T>;
40
+ /** @internal */
25
41
  isEnabled: () => boolean;
42
+ /** @internal */
26
43
  pollInterval: () => string;
44
+ /** @internal */
27
45
  defaultIntervalMs?: number;
46
+ /** @internal */
28
47
  onScheduledResult: (result: T, durationMs: number) => void;
48
+ /** @internal */
29
49
  onScheduledError: (error: unknown, durationMs: number) => void;
30
50
  }): PollLoop<T>;
31
51
  //# sourceMappingURL=poll-loop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"poll-loop.d.ts","sourceRoot":"","sources":["../src/poll-loop.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,MAAyB,IAE9D,KAAK,MAAM,EAAE,iBAAgB,EAAE,kBAAiB,KAAG,OAAO,CAKlE;AAED,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,oBAAoB;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,oBAAoB,GAAG,UAAU;IACpE,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,oBAAoB,EAAE,IAAI,EAAE;IACpE,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;IAC3B,iBAAiB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,gBAAgB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAA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CAAC;IAC3B,gBAAgB;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB;IAChB,iBAAiB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,gBAAgB;IAChB,gBAAgB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D,GAAG,QAAQ,CAAC,CAAC,CAAC,CA+Cd"}
package/dist/poll-loop.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  createPollLoop,
3
3
  createPollSchedule,
4
4
  emptyPollResult
5
- } from "./chunk-HG5TEBHZ.js";
6
- import "./chunk-IU3L35PC.js";
5
+ } from "./chunk-BO52GPAV.js";
6
+ import "./chunk-D57H46H7.js";
7
7
  export {
8
8
  createPollLoop,
9
9
  createPollSchedule,
@@ -1,22 +1,38 @@
1
1
  import { type PollResult, type PollResultWithErrors } from "./poll-loop.js";
2
+ /** @internal */
2
3
  export interface PollingLogger {
4
+ /** @internal */
3
5
  warn(payload: Record<string, unknown>, message?: string): void;
6
+ /** @internal */
4
7
  error(payload: Record<string, unknown>, message?: string): void;
5
8
  }
9
+ /** @internal */
6
10
  export interface PollingRegistration<T extends PollResultWithErrors> {
11
+ /** @internal */
7
12
  id: string;
13
+ /** @internal */
8
14
  pollOnce(): Promise<T>;
15
+ /** @internal */
9
16
  isEnabled(): boolean;
17
+ /** @internal */
10
18
  pollInterval(): string;
19
+ /** @internal */
11
20
  defaultIntervalMs?: number;
12
21
  }
22
+ /** @internal */
13
23
  export interface RegisteredPoller<T extends PollResultWithErrors = PollResult> {
24
+ /** @internal */
14
25
  poll(): Promise<T>;
15
26
  }
27
+ /** @internal */
16
28
  export interface PollingCoordinator {
29
+ /** @internal */
17
30
  create<T extends PollResultWithErrors>(registration: PollingRegistration<T>): RegisteredPoller<T>;
31
+ /** @internal */
18
32
  start(): void;
19
- stop(): void;
33
+ /** @internal */
34
+ stop(): Promise<void>;
20
35
  }
36
+ /** @internal */
21
37
  export declare function createPollingCoordinator(logger: PollingLogger): PollingCoordinator;
22
38
  //# sourceMappingURL=polling-coordinator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polling-coordinator.d.ts","sourceRoot":"","sources":["../src/polling-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE5F,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,oBAAoB;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACvB,SAAS,IAAI,OAAO,CAAC;IACrB,YAAY,IAAI,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,oBAAoB,GAAG,UAAU;IAC5E,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IAClC,MAAM,CAAC,CAAC,SAAS,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAClG,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;CACb;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,CAqClF"}
1
+ {"version":3,"file":"polling-coordinator.d.ts","source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,EAAE,aAAa,GAAG,kBAAkB,CAyClF"}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createPollingCoordinator
3
- } from "./chunk-USTHXEZJ.js";
4
- import "./chunk-HG5TEBHZ.js";
5
- import "./chunk-IU3L35PC.js";
3
+ } from "./chunk-ZW3LXDBX.js";
4
+ import "./chunk-BO52GPAV.js";
5
+ import "./chunk-D57H46H7.js";
6
6
  export {
7
7
  createPollingCoordinator
8
8
  };
@@ -1,30 +1,45 @@
1
1
  import type { ProcessInstance } from "@leitwerk-dev/domain";
2
+ /** @internal */
2
3
  export interface ProcessEventRepoLike {
4
+ /** @internal */
3
5
  create(input: {
6
+ /** @internal */
4
7
  instanceId: string;
8
+ /** @internal */
5
9
  eventType: string;
10
+ /** @internal */
6
11
  data?: Record<string, unknown>;
7
12
  }): unknown;
13
+ /** @internal */
8
14
  listByInstance(instanceId: string, limit?: number): Array<{
15
+ /** @internal */
9
16
  eventType: string;
10
17
  }>;
11
18
  }
19
+ /** @internal */
12
20
  export interface WorkerSupervisorLike {
21
+ /** @internal */
13
22
  spawnWorker(instanceId: string): Promise<unknown>;
23
+ /** @internal */
14
24
  getWorker(instanceId: string): unknown | undefined;
15
25
  }
16
26
  /**
17
27
  * Check whether a process already has an event of the given type.
18
28
  */
29
+ /** @internal */
19
30
  export declare function hasProcessEvent(events: ProcessEventRepoLike, instanceId: string, eventType: string): boolean;
31
+ /** @internal */
20
32
  export declare function processNeedsWorker(process: Pick<ProcessInstance, "selectedTurnId" | "lifecycleStatus">): boolean;
21
33
  /**
22
34
  * Spawn a worker for a process whose selected turn is runnable but currently has
23
35
  * no running worker. No-ops when the process is not worker-runnable or already
24
36
  * has a worker.
25
37
  */
38
+ /** @internal */
26
39
  export declare function ensureWorkerForActiveAgent(deps: {
40
+ /** @internal */
27
41
  events: ProcessEventRepoLike;
42
+ /** @internal */
28
43
  supervisor: WorkerSupervisorLike;
29
44
  }, process: ProcessInstance): Promise<void>;
30
45
  //# sourceMappingURL=process-helpers.d.ts.map
@@ -1 +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"}
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;AAE5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- } from "./chunk-3KGAUQIG.js";
5
+ } from "./chunk-EWA6E2ZM.js";
6
6
  export {
7
7
  ensureWorkerForActiveAgent,
8
8
  hasProcessEvent,
@@ -1,10 +1,17 @@
1
+ /** @internal */
1
2
  export type TriggerFileReadResult = {
3
+ /** @internal */
2
4
  exists: false;
3
5
  } | {
6
+ /** @internal */
4
7
  exists: true;
8
+ /** @internal */
5
9
  content: string;
6
10
  };
11
+ /** @internal */
7
12
  export declare function errorCode(error: unknown): string | null;
13
+ /** @internal */
8
14
  export declare function readTriggerFile(filePath: string): Promise<TriggerFileReadResult>;
15
+ /** @internal */
9
16
  export declare function consumeTriggerFile(filePath: string): Promise<void>;
10
17
  //# sourceMappingURL=trigger-files.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"trigger-files.d.ts","sourceRoot":"","sources":["../src/trigger-files.ts"],"names":[],"mappings":"AAEA,gBAAgB;AAChB,MAAM,MAAM,qBAAqB,GAC9B;IACA,gBAAgB;IAChB,MAAM,EAAE,KAAK,CAAC;CACb,GACD;IACA,gBAAgB;IAChB,MAAM,EAAE,IAAI,CAAC;IACb,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;CACf,CAAC;AAEL,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMvD;AAED,gBAAgB;AAChB,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAStF;AAED,gBAAgB;AAChB,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASxE"}
@@ -1,99 +1,174 @@
1
1
  import type { ProcessInstance, TurnId } from "@leitwerk-dev/domain";
2
- import { type ExternalWriteLogRepoLike, type WriteIdentity } from "@leitwerk-dev/external-writes";
2
+ import type { WriteIdentity } from "@leitwerk-dev/external-writes";
3
+ import { type ExternalWriteLogRepoLike } from "@leitwerk-dev/external-writes/internal";
3
4
  import type { KnownDurableWsFrameType, WsPayloadByType } from "@leitwerk-dev/protocol";
4
5
  import type { PollResult } from "./poll-loop.js";
5
6
  import { type ProcessEventRepoLike, type WorkerSupervisorLike } from "./process-helpers.js";
7
+ /** @internal */
6
8
  export interface AgentRepoAccessorLike {
9
+ /** @internal */
7
10
  getById(id: string): ProcessInstance | null;
8
11
  }
12
+ /** @internal */
9
13
  export interface BroadcasterLike {
14
+ /** @internal */
10
15
  sendDurable<T extends KnownDurableWsFrameType>(type: T, payload: WsPayloadByType[T], instanceId?: string): void;
11
16
  }
17
+ /** @internal */
12
18
  export interface WatcherCommandResult {
19
+ /** @internal */
13
20
  ok: boolean;
21
+ /** @internal */
14
22
  code?: string;
23
+ /** @internal */
15
24
  message?: string;
25
+ /** @internal */
16
26
  process?: ProcessInstance | null;
17
27
  }
28
+ /** @internal */
18
29
  export interface WatcherCommandServiceLike {
30
+ /** @internal */
19
31
  startProcess(instanceId: string, startTurnId: TurnId): Promise<WatcherCommandResult>;
32
+ /** @internal */
20
33
  abortProcess(instanceId: string): Promise<WatcherCommandResult>;
21
34
  }
35
+ /** @internal */
22
36
  export interface WatcherStartupDeps {
37
+ /** @internal */
23
38
  processes: AgentRepoAccessorLike;
39
+ /** @internal */
24
40
  events: ProcessEventRepoLike;
41
+ /** @internal */
25
42
  broadcaster: BroadcasterLike;
43
+ /** @internal */
26
44
  commands: WatcherCommandServiceLike;
45
+ /** @internal */
27
46
  supervisor: WorkerSupervisorLike;
28
47
  }
48
+ /** @internal */
29
49
  export interface ContinueWatcherAgentStartupOptions {
50
+ /** @internal */
30
51
  process: ProcessInstance;
52
+ /** @internal */
31
53
  startTurnId: TurnId;
54
+ /** @internal */
32
55
  createdEventData: Record<string, unknown>;
56
+ /** @internal */
33
57
  createdBroadcastData: Record<string, unknown>;
34
- /** Defaults to true. Set false when the shared launch executor already emitted process.created. */
58
+ /** Defaults to true. Set false when the shared launch executor already emitted process.created. @internal */
35
59
  broadcastCreated?: boolean;
60
+ /** @internal */
36
61
  afterCreatedEvent?: (process: ProcessInstance) => Promise<void> | void;
62
+ /** @internal */
37
63
  beforeStart?: (process: ProcessInstance) => Promise<void>;
38
64
  }
65
+ /** @internal */
39
66
  export declare function requireWatcherStartTurnId(launchPlan: {
67
+ /** @internal */
40
68
  launcherId: string;
69
+ /** @internal */
41
70
  startTurnId: TurnId | null;
42
71
  }, targetLabel: string): TurnId;
72
+ /** @internal */
43
73
  export declare function continueWatcherAgentStartup(deps: WatcherStartupDeps, opts: ContinueWatcherAgentStartupOptions): Promise<string>;
74
+ /** @internal */
44
75
  export type DiscoveryResumeResult = "handled" | "skipped" | undefined;
76
+ /** @internal */
45
77
  export type DiscoveryCreateResult = {
78
+ /** @internal */
46
79
  outcome: "created";
80
+ /** @internal */
47
81
  instanceId: string;
48
82
  } | {
83
+ /** @internal */
49
84
  outcome: "skipped";
50
85
  } | {
86
+ /** @internal */
51
87
  outcome: "handled";
52
88
  } | null | undefined;
89
+ /** @internal */
53
90
  export interface DiscoveryPassOptions<TItem> {
91
+ /** @internal */
54
92
  items: readonly TItem[];
93
+ /** @internal */
55
94
  result: PollResult;
95
+ /** @internal */
56
96
  findExistingAgent(item: TItem): ProcessInstance | null;
97
+ /** @internal */
57
98
  getResultLabel(item: TItem): string;
99
+ /** @internal */
58
100
  resumeDiscoveredAgent(process: ProcessInstance, item: TItem): Promise<DiscoveryResumeResult>;
101
+ /** @internal */
59
102
  createAgent(item: TItem): Promise<DiscoveryCreateResult>;
103
+ /** @internal */
60
104
  ensureWorkerForExistingAgent?(process: ProcessInstance, item: TItem): Promise<boolean>;
105
+ /** @internal */
61
106
  formatError(item: TItem, error: unknown): string;
62
107
  }
108
+ /** @internal */
63
109
  export declare function runWatcherDiscoveryPass<TItem>(opts: DiscoveryPassOptions<TItem>): Promise<void>;
110
+ /** @internal */
64
111
  export interface AbortReconciliationOptions {
112
+ /** @internal */
65
113
  candidates: readonly ProcessInstance[];
114
+ /** @internal */
66
115
  result: PollResult;
116
+ /** @internal */
67
117
  events: ProcessEventRepoLike;
118
+ /** @internal */
68
119
  commands: WatcherCommandServiceLike;
120
+ /** @internal */
69
121
  shouldAbort(process: ProcessInstance): Promise<boolean>;
122
+ /** @internal */
70
123
  getResultLabel(process: ProcessInstance): string;
124
+ /** @internal */
71
125
  getErrorLabel(process: ProcessInstance): string;
126
+ /** @internal */
72
127
  getAbortedEventData(process: ProcessInstance): Record<string, unknown>;
73
128
  }
129
+ /** @internal */
74
130
  export declare function runWatcherAbortReconciliation(opts: AbortReconciliationOptions): Promise<void>;
131
+ /** @internal */
75
132
  export interface CompletionReconciliationResult {
133
+ /** @internal */
76
134
  changed: boolean;
135
+ /** @internal */
77
136
  writeIdentity?: WriteIdentity;
137
+ /** @internal */
78
138
  metadata?: Record<string, unknown>;
79
139
  }
140
+ /** @internal */
80
141
  export interface CompletionReconciliationOptions {
142
+ /** @internal */
81
143
  candidates: readonly ProcessInstance[];
144
+ /** @internal */
82
145
  result: PollResult;
146
+ /** @internal */
83
147
  externalWrites: ExternalWriteLogRepoLike;
148
+ /** @internal */
84
149
  reconcile(process: ProcessInstance): Promise<CompletionReconciliationResult>;
150
+ /** @internal */
85
151
  getResultLabel(process: ProcessInstance): string;
152
+ /** @internal */
86
153
  getErrorLabel(process: ProcessInstance): string;
87
154
  }
155
+ /** @internal */
88
156
  export declare function runWatcherCompletionReconciliation(opts: CompletionReconciliationOptions): Promise<void>;
157
+ /** @internal */
89
158
  export declare function shouldEnsureWorkerForExistingActiveAgent(deps: {
159
+ /** @internal */
90
160
  supervisor: WorkerSupervisorLike;
91
161
  }, process: ProcessInstance): boolean;
162
+ /** @internal */
92
163
  export declare function deferWatcherLaunchStart<TLaunchPlan extends {
164
+ /** @internal */
93
165
  startTurnId: unknown;
94
166
  }>(launchPlan: TLaunchPlan): TLaunchPlan;
167
+ /** @internal */
95
168
  export declare function launchFailureMessage(result: {
169
+ /** @internal */
96
170
  status: number;
171
+ /** @internal */
97
172
  body: Record<string, unknown>;
98
173
  }): string;
99
174
  //# sourceMappingURL=watcher-coordinator.d.ts.map