clinkx 1.3.0 → 1.4.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 +57 -0
- package/README.md +13 -6
- package/clinkx-workflows/dist/child-env.d.ts +3 -0
- package/clinkx-workflows/dist/child-env.js +11 -0
- package/clinkx-workflows/dist/child-env.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
- package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/index-CX4FrhYN.js +122 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
- package/clinkx-workflows/dist/durable-file-core.js +146 -0
- package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
- package/clinkx-workflows/dist/durable-file.d.ts +8 -64
- package/clinkx-workflows/dist/durable-file.js +14 -137
- package/clinkx-workflows/dist/durable-file.js.map +1 -1
- package/clinkx-workflows/dist/index.js +68 -2
- package/clinkx-workflows/dist/index.js.map +1 -1
- package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
- package/clinkx-workflows/dist/settings/audit.js +318 -0
- package/clinkx-workflows/dist/settings/audit.js.map +1 -0
- package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
- package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
- package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
- package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
- package/clinkx-workflows/dist/settings/codec.js +410 -0
- package/clinkx-workflows/dist/settings/codec.js.map +1 -0
- package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
- package/clinkx-workflows/dist/settings/durable-write.js +31 -0
- package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
- package/clinkx-workflows/dist/settings/index.d.ts +20 -0
- package/clinkx-workflows/dist/settings/index.js +23 -0
- package/clinkx-workflows/dist/settings/index.js.map +1 -0
- package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
- package/clinkx-workflows/dist/settings/loader.js +577 -0
- package/clinkx-workflows/dist/settings/loader.js.map +1 -0
- package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
- package/clinkx-workflows/dist/settings/lock.js +344 -0
- package/clinkx-workflows/dist/settings/lock.js.map +1 -0
- package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
- package/clinkx-workflows/dist/settings/paths.js +173 -0
- package/clinkx-workflows/dist/settings/paths.js.map +1 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
- package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
- package/clinkx-workflows/dist/settings/registry.js +1290 -0
- package/clinkx-workflows/dist/settings/registry.js.map +1 -0
- package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
- package/clinkx-workflows/dist/settings/schema.js +415 -0
- package/clinkx-workflows/dist/settings/schema.js.map +1 -0
- package/clinkx-workflows/dist/settings/store.d.ts +157 -0
- package/clinkx-workflows/dist/settings/store.js +842 -0
- package/clinkx-workflows/dist/settings/store.js.map +1 -0
- package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
- package/clinkx-workflows/dist/stdio-entry.js +52 -0
- package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
- package/dist/dashboard-cli.d.ts +11 -3
- package/dist/dashboard-cli.js +199 -33
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/client.d.ts +14 -0
- package/dist/dashboard-companion/client.js +16 -0
- package/dist/dashboard-companion/client.js.map +1 -1
- package/dist/dashboard-companion/credential-expectation.d.ts +23 -0
- package/dist/dashboard-companion/credential-expectation.js +50 -0
- package/dist/dashboard-companion/credential-expectation.js.map +1 -0
- package/dist/dashboard-companion/host-channel.d.ts +36 -0
- package/dist/dashboard-companion/host-channel.js +78 -0
- package/dist/dashboard-companion/host-channel.js.map +1 -0
- package/dist/dashboard-companion/host-status.d.ts +179 -0
- package/dist/dashboard-companion/host-status.js +122 -0
- package/dist/dashboard-companion/host-status.js.map +1 -0
- package/dist/dashboard-companion/protocol.js +17 -0
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-companion/standalone-assets.d.ts +8 -0
- package/dist/dashboard-companion/standalone-assets.js +7 -1
- package/dist/dashboard-companion/standalone-assets.js.map +1 -1
- package/dist/dashboard-companion/standalone-entry.js +34 -13
- package/dist/dashboard-companion/standalone-entry.js.map +1 -1
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +38 -38
- package/dist/dashboard-gateway/tunnel-http.js +20 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -1
- package/dist/desktop-host/child-env.d.ts +23 -0
- package/dist/desktop-host/child-env.js +70 -0
- package/dist/desktop-host/child-env.js.map +1 -0
- package/dist/desktop-host/daemon-entry.d.ts +2 -0
- package/dist/desktop-host/daemon-entry.js +50 -0
- package/dist/desktop-host/daemon-entry.js.map +1 -0
- package/dist/desktop-host/daemon-env.d.ts +12 -0
- package/dist/desktop-host/daemon-env.js +35 -0
- package/dist/desktop-host/daemon-env.js.map +1 -0
- package/dist/desktop-host/daemon-protocol.d.ts +210 -0
- package/dist/desktop-host/daemon-protocol.js +56 -0
- package/dist/desktop-host/daemon-protocol.js.map +1 -0
- package/dist/desktop-host/daemon.d.ts +50 -0
- package/dist/desktop-host/daemon.js +441 -0
- package/dist/desktop-host/daemon.js.map +1 -0
- package/dist/desktop-host/enrollment.d.ts +17 -0
- package/dist/desktop-host/enrollment.js +25 -0
- package/dist/desktop-host/enrollment.js.map +1 -0
- package/dist/desktop-host/import.d.ts +14 -0
- package/dist/desktop-host/import.js +95 -0
- package/dist/desktop-host/import.js.map +1 -0
- package/dist/desktop-host/profile.d.ts +130 -0
- package/dist/desktop-host/profile.js +176 -0
- package/dist/desktop-host/profile.js.map +1 -0
- package/dist/desktop-host/service.d.ts +6 -0
- package/dist/desktop-host/service.js +7 -0
- package/dist/desktop-host/service.js.map +1 -0
- package/dist/desktop-host/supervisor.d.ts +57 -0
- package/dist/desktop-host/supervisor.js +256 -0
- package/dist/desktop-host/supervisor.js.map +1 -0
- package/dist/desktop-host/view-state.d.ts +138 -0
- package/dist/desktop-host/view-state.js +27 -0
- package/dist/desktop-host/view-state.js.map +1 -0
- package/dist/elaris/config.d.ts +10 -0
- package/dist/elaris/config.js +27 -1
- package/dist/elaris/config.js.map +1 -1
- package/dist/elaris/tools.js +4 -1
- package/dist/elaris/tools.js.map +1 -1
- package/dist/index.d.ts +0 -31
- package/dist/index.js +41 -404
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +17 -0
- package/dist/lib.js +17 -0
- package/dist/lib.js.map +1 -0
- package/dist/progress-report/lock.d.ts +17 -59
- package/dist/progress-report/lock.js +25 -329
- package/dist/progress-report/lock.js.map +1 -1
- package/dist/registry.d.ts +7 -0
- package/dist/registry.js +21 -7
- package/dist/registry.js.map +1 -1
- package/dist/server.js +75 -4
- package/dist/server.js.map +1 -1
- package/dist/settings-cli/clients.d.ts +137 -0
- package/dist/settings-cli/clients.js +1124 -0
- package/dist/settings-cli/clients.js.map +1 -0
- package/dist/settings-cli/commands.d.ts +67 -0
- package/dist/settings-cli/commands.js +726 -0
- package/dist/settings-cli/commands.js.map +1 -0
- package/dist/settings-cli/format.d.ts +34 -0
- package/dist/settings-cli/format.js +40 -0
- package/dist/settings-cli/format.js.map +1 -0
- package/dist/settings-cli/main.d.ts +18 -0
- package/dist/settings-cli/main.js +256 -0
- package/dist/settings-cli/main.js.map +1 -0
- package/dist/stdio-main.d.ts +73 -0
- package/dist/stdio-main.js +455 -0
- package/dist/stdio-main.js.map +1 -0
- package/docs/configuration.md +340 -39
- package/docs/security.md +150 -6
- package/docs/verification/README.md +28 -2
- package/docs/verification/workflow-handoff.md +86 -0
- package/package.json +3 -3
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +0 -119
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +0 -1
|
@@ -1,343 +1,39 @@
|
|
|
1
|
-
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { open, readFile, stat, unlink, utimes } from "node:fs/promises";
|
|
3
|
-
import { hostname } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
1
|
import { ExecutionError } from "../errors.js";
|
|
6
2
|
import { logger } from "../logger.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const LOCK_ACQUIRE_TIMEOUT_MS = 10_000;
|
|
10
|
-
/**
|
|
11
|
-
* How often a holder refreshes its own lock's mtime. This is what makes a lock
|
|
12
|
-
* observably ALIVE to a reader that cannot probe our PID, and it is also what
|
|
13
|
-
* lets a stolen-from holder notice and abort. Matches the interval the workflow
|
|
14
|
-
* `run.lock` and the dashboard credential store already use.
|
|
15
|
-
*/
|
|
16
|
-
export const LOCK_HEARTBEAT_MS = 10_000;
|
|
17
|
-
/**
|
|
18
|
-
* Floor for the foreign-host staleness window. A lock is only judged abandoned
|
|
19
|
-
* on heartbeat evidence once it has missed several beats AND at least this long
|
|
20
|
-
* has passed, so ordinary scheduling jitter never looks like death.
|
|
21
|
-
*/
|
|
22
|
-
export const LOCK_HEARTBEAT_STALE_FLOOR_MS = 60_000;
|
|
23
|
-
/** An mtime this far in the future means clock skew, not liveness evidence. */
|
|
24
|
-
const LOCK_FUTURE_MTIME_TOLERANCE_MS = 60_000;
|
|
25
|
-
const RETRY_BASE_MS = 15;
|
|
26
|
-
const RETRY_JITTER_MS = 20;
|
|
27
|
-
function sleep(ms) {
|
|
28
|
-
return new Promise((resolve) => {
|
|
29
|
-
setTimeout(resolve, ms);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
async function readLockBody(lockPath) {
|
|
33
|
-
try {
|
|
34
|
-
const raw = await readFile(lockPath, "utf8");
|
|
35
|
-
const parsed = JSON.parse(raw);
|
|
36
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
37
|
-
return null;
|
|
38
|
-
const record = parsed;
|
|
39
|
-
const token = record["token"];
|
|
40
|
-
const pid = record["pid"];
|
|
41
|
-
const host = record["hostname"];
|
|
42
|
-
if (typeof token !== "string" || token === "")
|
|
43
|
-
return null;
|
|
44
|
-
const interval = record["heartbeat_interval_ms"];
|
|
45
|
-
return {
|
|
46
|
-
token,
|
|
47
|
-
pid: typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : 0,
|
|
48
|
-
hostname: typeof host === "string" ? host : "",
|
|
49
|
-
acquired_at: typeof record["acquired_at"] === "string" ? record["acquired_at"] : "",
|
|
50
|
-
heartbeat_interval_ms: typeof interval === "number" && Number.isFinite(interval) && interval > 0 ? interval : 0,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// Absent, unreadable, or unparseable: never provably ours, never provably dead.
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function readLockToken(lockPath) {
|
|
59
|
-
return (await readLockBody(lockPath))?.token ?? null;
|
|
60
|
-
}
|
|
61
|
-
/** Serializes the one destructive step in this module. See `reclaimAbandonedLock`. */
|
|
62
|
-
const STEAL_LOCK_SUFFIX = ".steal";
|
|
63
|
-
function stealPathFor(lockPath) {
|
|
64
|
-
return `${lockPath}${STEAL_LOCK_SUFFIX}`;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Delete an abandoned lock, but only ever one contender at a time.
|
|
68
|
-
*
|
|
69
|
-
* Reclamation is the one destructive step here, so it gets its own `O_EXCL`
|
|
70
|
-
* file. Without it two contenders can both observe the SAME dead lock and both
|
|
71
|
-
* authorize an unlink; the first unlinks, recreates and enters, and the second's
|
|
72
|
-
* already-authorized unlink then lands on the winner's LIVE lock and lets it
|
|
73
|
-
* enter too. Both would read the same revision, both pass the CAS, and one
|
|
74
|
-
* update would be silently lost. Re-reading the token narrows that window but
|
|
75
|
-
* cannot close it, because the winner's unlink+create can land between the
|
|
76
|
-
* loser's read and its unlink. Holding the steal lock across the re-read makes
|
|
77
|
-
* the check-and-delete indivisible with respect to other reclaimers.
|
|
78
|
-
*
|
|
79
|
-
* Reports the REAL outcome, which is also the caller's "progress was made"
|
|
80
|
-
* signal. Reporting success on an unlink that did not happen would be worse
|
|
81
|
-
* than useless: the caller skips its backoff and immediately re-observes the
|
|
82
|
-
* same undeletable lock, so a lock that is readable but cannot be removed spins
|
|
83
|
-
* for the whole deadline at full CPU, emitting one untruthful "reclaiming"
|
|
84
|
-
* warn per iteration into the MCP client's captured stderr.
|
|
85
|
-
*/
|
|
86
|
-
async function reclaimAbandonedLock(lockPath, observedToken) {
|
|
87
|
-
const stealPath = stealPathFor(lockPath);
|
|
88
|
-
let handle;
|
|
89
|
-
try {
|
|
90
|
-
handle = await open(stealPath, "wx", 0o600);
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
// Another contender is already reclaiming (or the steal lock is stranded);
|
|
94
|
-
// either way this contender waits rather than racing it. The errno is
|
|
95
|
-
// carried out because EEXIST (a real contender) and EACCES/EROFS/ENOSPC/
|
|
96
|
-
// ENOENT (the steal lock was never created at all) need different operator
|
|
97
|
-
// advice, and only the former makes "remove that file" sound guidance.
|
|
98
|
-
return {
|
|
99
|
-
kind: "steal_lock_unavailable",
|
|
100
|
-
code: err.code ?? "unknown",
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
// Re-read UNDER the steal lock: if the winner already replaced the dead
|
|
105
|
-
// lock, the token no longer matches and we must not touch it.
|
|
106
|
-
if ((await readLockToken(lockPath)) !== observedToken)
|
|
107
|
-
return { kind: "superseded" };
|
|
108
|
-
try {
|
|
109
|
-
await unlink(lockPath);
|
|
110
|
-
return { kind: "reclaimed" };
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
// ENOENT means somebody else already removed it, which IS progress.
|
|
114
|
-
// Anything else (an immutable flag, EPERM, a read-only mount) is a
|
|
115
|
-
// failure and must not be dressed up as a reclamation.
|
|
116
|
-
const code = err.code;
|
|
117
|
-
return code === "ENOENT" ? { kind: "reclaimed" } : { kind: "unlink_failed", code: code ?? "unknown" };
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
// A close() that rejects (EIO, ENOSPC) must not skip the unlink: stranding
|
|
122
|
-
// our OWN steal lock would trigger by accident the exact residual this
|
|
123
|
-
// design documents as its worst failure mode, and would escape
|
|
124
|
-
// `withSessionLock` as a raw unwrapped errno.
|
|
125
|
-
await handle.close().catch(() => undefined);
|
|
126
|
-
await unlink(stealPath).catch((err) => {
|
|
127
|
-
// Stranding this file disables automatic reclamation for the session until
|
|
128
|
-
// an operator removes it. That residual is documented, but swallowing it
|
|
129
|
-
// silently means it only ever surfaces to a LATER contender's timeout.
|
|
130
|
-
logger.warn({ stealPath, err: err.message }, "progress-report: could not remove the reclaim lock; automatic reclamation is disabled for this session until it is deleted");
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/** Alive unless the OS positively says the process is gone. */
|
|
135
|
-
function sameHostProcessIsDead(pid) {
|
|
136
|
-
if (pid <= 0)
|
|
137
|
-
return false;
|
|
138
|
-
try {
|
|
139
|
-
process.kill(pid, 0);
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
// EPERM means it exists and belongs to someone else — alive, not dead.
|
|
144
|
-
return err.code === "ESRCH";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Decide whether the lock on disk may be reclaimed. Reclamation requires
|
|
149
|
-
* POSITIVE EVIDENCE OF DEATH; every ambiguity resolves to "unknown", which
|
|
150
|
-
* waits. A bare mtime age is never sufficient on its own.
|
|
151
|
-
*/
|
|
152
|
-
async function observeLock(lockPath) {
|
|
153
|
-
const body = await readLockBody(lockPath);
|
|
154
|
-
if (body === null) {
|
|
155
|
-
return { kind: "unknown", why: "lock body is absent, unreadable, or malformed" };
|
|
156
|
-
}
|
|
157
|
-
// Same host: the PID probe is the strongest possible evidence, so it wins
|
|
158
|
-
// outright and no heartbeat is consulted.
|
|
159
|
-
if (body.hostname !== "" && body.hostname === hostname()) {
|
|
160
|
-
return sameHostProcessIsDead(body.pid)
|
|
161
|
-
? { kind: "abandoned", token: body.token, why: `owner pid ${String(body.pid)} is gone` }
|
|
162
|
-
: { kind: "live" };
|
|
163
|
-
}
|
|
164
|
-
// Foreign host (or an unrecorded one): we cannot probe the process, so the
|
|
165
|
-
// only admissible evidence is a heartbeat the holder promised to send.
|
|
166
|
-
if (body.heartbeat_interval_ms <= 0) {
|
|
167
|
-
return { kind: "unknown", why: "holder declared no heartbeat, so silence proves nothing" };
|
|
168
|
-
}
|
|
169
|
-
const stats = await stat(lockPath).catch(() => null);
|
|
170
|
-
if (stats === null) {
|
|
171
|
-
return { kind: "unknown", why: "lock vanished while being observed" };
|
|
172
|
-
}
|
|
173
|
-
const ageMs = Date.now() - stats.mtimeMs;
|
|
174
|
-
if (ageMs < -LOCK_FUTURE_MTIME_TOLERANCE_MS) {
|
|
175
|
-
return { kind: "unknown", why: "lock mtime is in the future; clocks disagree" };
|
|
176
|
-
}
|
|
177
|
-
const staleAfterMs = Math.max(LOCK_HEARTBEAT_STALE_FLOOR_MS, body.heartbeat_interval_ms * 6);
|
|
178
|
-
return ageMs > staleAfterMs
|
|
179
|
-
? {
|
|
180
|
-
kind: "abandoned",
|
|
181
|
-
token: body.token,
|
|
182
|
-
why: `no heartbeat for ${String(Math.round(ageMs))}ms (stale after ${String(staleAfterMs)}ms)`,
|
|
183
|
-
}
|
|
184
|
-
: { kind: "live" };
|
|
185
|
-
}
|
|
3
|
+
import { SettingsLockError, withSettingsLock, } from "../../clinkx-workflows/dist/settings/lock.js";
|
|
4
|
+
export { LOCK_FILENAME, LOCK_ACQUIRE_TIMEOUT_MS } from "../../clinkx-workflows/dist/settings/lock.js";
|
|
186
5
|
/**
|
|
187
6
|
* Run `fn` while holding an exclusive cross-process lock on `sessionDir`.
|
|
188
7
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
8
|
+
* Thin wrapper (P9/R1): the exclusion primitive, the fail-closed foreign-host
|
|
9
|
+
* rule, the link-published atomic lock body and the steal-lock-serialized
|
|
10
|
+
* reclaim all live in ONE place — the settings lock in clinkx-workflows — so
|
|
11
|
+
* the two surfaces cannot drift apart again. This module only adapts that core
|
|
12
|
+
* to the progress-report surface: `warn` goes to the root logger, and
|
|
13
|
+
* `SettingsLockError` (the cw package must not import root error classes)
|
|
14
|
+
* maps onto `ExecutionError` with the message kept verbatim, including the
|
|
15
|
+
* lock path and the manual `rm` recovery step a foreign-host timeout names.
|
|
196
16
|
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* and the
|
|
201
|
-
*
|
|
202
|
-
* CAS, and one write would be silently lost. So a lock is reclaimed only on
|
|
203
|
-
* positive evidence of death: a dead PID on this host, or — for a lock written
|
|
204
|
-
* on another host, where no probe is possible — a heartbeat that has been
|
|
205
|
-
* missing for several declared intervals. Every other case waits. A holder that
|
|
206
|
-
* declared no heartbeat is never reclaimed on silence, which is what keeps a
|
|
207
|
-
* lock written by an older producer safe. Evidence alone is still not enough to
|
|
208
|
-
* make two simultaneous reclaimers safe, so the unlink itself is serialized
|
|
209
|
-
* behind a second `O_EXCL` file (`reclaimAbandonedLock`).
|
|
210
|
-
*
|
|
211
|
-
* Release is ownership-checked: the holder re-reads the lock body and unlinks
|
|
212
|
-
* only if the token is still its own, so a holder that was stolen from does not
|
|
213
|
-
* normally delete the new owner's lock. Node exposes no atomic
|
|
214
|
-
* compare-and-unlink, so that check is read-then-unlink and a steal landing
|
|
215
|
-
* inside that window is still possible; the guarantee is "will not", not
|
|
216
|
-
* "cannot".
|
|
217
|
-
*
|
|
218
|
-
* Honest residuals, all accepted under a single-user local-filesystem model:
|
|
219
|
-
* `O_EXCL` is not reliable on some network filesystems (NFSv2/v3); a PID can be
|
|
220
|
-
* recycled, so a probe can report a live process that is not the original
|
|
221
|
-
* holder; and a holder suspended (SIGSTOP, a paused container) stops beating and
|
|
222
|
-
* looks abandoned to a foreign-host reader. These are the same class of residual
|
|
223
|
-
* the repo already accepts for `run.lock` and `contained-file.ts`. The steal
|
|
224
|
-
* lock adds one of its own: a process that dies while holding `.lock.steal`
|
|
225
|
-
* leaves it behind, which disables AUTOMATIC RECLAMATION for that session —
|
|
226
|
-
* normal acquisition and release are unaffected — until an operator removes the
|
|
227
|
-
* file. That is strictly the better failure mode: a session that needs a manual
|
|
228
|
-
* unwedge, rather than two writers in the critical section.
|
|
17
|
+
* A legacy lock body written by an older build of THIS module is still
|
|
18
|
+
* reclaimed: lock identity is `token`/`pid`/`hostname`, which the old
|
|
19
|
+
* snake_case body (`acquired_at`, `heartbeat_interval_ms`) already carries,
|
|
20
|
+
* and the shared core tolerates the missing camelCase `startedAt` — pinned by
|
|
21
|
+
* a test so same-host dead-PID reclaim keeps working across an upgrade.
|
|
229
22
|
*/
|
|
230
23
|
export async function withSessionLock(sessionDir, fn, options = {}) {
|
|
231
|
-
const lockPath = join(sessionDir, LOCK_FILENAME);
|
|
232
|
-
const token = randomBytes(16).toString("hex");
|
|
233
|
-
const acquireTimeoutMs = options.acquireTimeoutMs ?? LOCK_ACQUIRE_TIMEOUT_MS;
|
|
234
|
-
const deadline = Date.now() + acquireTimeoutMs;
|
|
235
|
-
// Carried into the timeout message. Without it every failure reads "locked by
|
|
236
|
-
// another writer", including the one case where there provably is no other
|
|
237
|
-
// writer — a stranded `.lock.steal` blocking the reclamation of a dead
|
|
238
|
-
// holder's lock — which points the operator at the wrong file for the single
|
|
239
|
-
// failure mode this design introduces.
|
|
240
|
-
let lastObservation = "the lock was not observed before the deadline";
|
|
241
|
-
for (;;) {
|
|
242
|
-
if (Date.now() >= deadline) {
|
|
243
|
-
throw new ExecutionError(`progress report session is locked by another writer and did not release within ${String(acquireTimeoutMs)}ms; ${lastObservation}`);
|
|
244
|
-
}
|
|
245
|
-
let created = false;
|
|
246
|
-
try {
|
|
247
|
-
const handle = await open(lockPath, "wx", 0o600);
|
|
248
|
-
try {
|
|
249
|
-
const body = {
|
|
250
|
-
token,
|
|
251
|
-
pid: process.pid,
|
|
252
|
-
hostname: hostname(),
|
|
253
|
-
acquired_at: new Date().toISOString(),
|
|
254
|
-
heartbeat_interval_ms: LOCK_HEARTBEAT_MS,
|
|
255
|
-
};
|
|
256
|
-
created = true;
|
|
257
|
-
await handle.writeFile(JSON.stringify(body), "utf8");
|
|
258
|
-
}
|
|
259
|
-
finally {
|
|
260
|
-
await handle.close();
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
catch (err) {
|
|
265
|
-
const code = err.code;
|
|
266
|
-
if (code !== "EEXIST") {
|
|
267
|
-
// We created the lock but could not write its body (ENOSPC, EIO). Leaving
|
|
268
|
-
// it behind would strand every future writer behind a fresh-looking lock
|
|
269
|
-
// that nobody owns and no PID probe can ever clear.
|
|
270
|
-
if (created)
|
|
271
|
-
await unlink(lockPath).catch(() => undefined);
|
|
272
|
-
throw err;
|
|
273
|
-
}
|
|
274
|
-
const observation = await observeLock(lockPath);
|
|
275
|
-
if (observation.kind === "abandoned") {
|
|
276
|
-
const outcome = await reclaimAbandonedLock(lockPath, observation.token);
|
|
277
|
-
if (outcome.kind === "reclaimed") {
|
|
278
|
-
lastObservation = `the lock was abandoned (${observation.why}) and was reclaimed`;
|
|
279
|
-
logger.warn({ lockPath, reason: observation.why }, "progress-report: reclaiming abandoned session lock");
|
|
280
|
-
// Real progress was made, so retry immediately rather than sleeping.
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
// Reclamation was declined or lost: fall through to the backoff, so a
|
|
284
|
-
// repeatedly-failing reclaim waits out the deadline instead of spinning.
|
|
285
|
-
lastObservation =
|
|
286
|
-
outcome.kind === "steal_lock_unavailable"
|
|
287
|
-
? outcome.code === "EEXIST"
|
|
288
|
-
? `the lock looks abandoned (${observation.why}) but reclamation was declined because the reclaim lock ${stealPathFor(lockPath)} already exists — if no writer is running, remove that file`
|
|
289
|
-
: `the lock looks abandoned (${observation.why}) but the reclaim lock ${stealPathFor(lockPath)} could not be created (${outcome.code})`
|
|
290
|
-
: outcome.kind === "superseded"
|
|
291
|
-
? `the lock looked abandoned (${observation.why}) but another writer replaced it first`
|
|
292
|
-
: `the lock looks abandoned (${observation.why}) but it could not be deleted (${outcome.code})`;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
lastObservation =
|
|
296
|
-
observation.kind === "live"
|
|
297
|
-
? "the lock is held by a writer that still looks alive"
|
|
298
|
-
: `the lock could not be judged abandoned: ${observation.why}`;
|
|
299
|
-
}
|
|
300
|
-
await sleep(RETRY_BASE_MS + Math.floor(Math.random() * RETRY_JITTER_MS));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
let ownershipLost = false;
|
|
304
|
-
let beating;
|
|
305
|
-
const heartbeat = setInterval(() => {
|
|
306
|
-
if (ownershipLost || beating !== undefined)
|
|
307
|
-
return;
|
|
308
|
-
const beat = (async () => {
|
|
309
|
-
const current = await readLockToken(lockPath);
|
|
310
|
-
if (current !== null && current !== token) {
|
|
311
|
-
// PROVEN loss: a complete, readable body whose token is not ours. An
|
|
312
|
-
// unreadable or absent lock is NOT proof and must not revoke our claim.
|
|
313
|
-
ownershipLost = true;
|
|
314
|
-
logger.warn({ lockPath }, "progress-report: session lock was taken from us");
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const at = new Date();
|
|
318
|
-
await utimes(lockPath, at, at).catch(() => undefined);
|
|
319
|
-
})().finally(() => {
|
|
320
|
-
beating = undefined;
|
|
321
|
-
});
|
|
322
|
-
beating = beat;
|
|
323
|
-
}, LOCK_HEARTBEAT_MS);
|
|
324
|
-
heartbeat.unref();
|
|
325
|
-
const guard = {
|
|
326
|
-
async assertHeld() {
|
|
327
|
-
if (ownershipLost || (await readLockToken(lockPath)) !== token) {
|
|
328
|
-
throw new ExecutionError("progress report session lock was reclaimed by another writer mid-update; nothing was written — re-read the report and retry");
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
24
|
try {
|
|
333
|
-
return await fn
|
|
25
|
+
return await withSettingsLock(sessionDir, fn, {
|
|
26
|
+
acquireTimeoutMs: options.acquireTimeoutMs,
|
|
27
|
+
warn: (fields, message) => {
|
|
28
|
+
logger.warn({ ...fields, component: "progress-report-lock" }, message);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
334
31
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if ((await readLockToken(lockPath)) === token) {
|
|
339
|
-
await unlink(lockPath).catch(() => undefined);
|
|
32
|
+
catch (err) {
|
|
33
|
+
if (err instanceof SettingsLockError) {
|
|
34
|
+
throw new ExecutionError(err.message);
|
|
340
35
|
}
|
|
36
|
+
throw err;
|
|
341
37
|
}
|
|
342
38
|
}
|
|
343
39
|
//# sourceMappingURL=lock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/progress-report/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/progress-report/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAatG;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAkB,EAClB,EAA2C,EAC3C,UAAkD,EAAE;IAEpD,IAAI,CAAC;QACH,OAAO,MAAM,gBAAgB,CAAC,UAAU,EAAE,EAAE,EAAE;YAC5C,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;gBACxB,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,OAAO,CAAC,CAAC;YACzE,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,IAAI,GAAG,YAAY,iBAAiB,EAAE,CAAC;YACrC,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type CliAdapterConfig } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* A packaged runtime whose modules do not sit beside the package's `conf/`
|
|
4
|
+
* (the Node SEA dashboard extracts it elsewhere) registers the shipped adapter
|
|
5
|
+
* directory here, so discovery tiers and the prompt_file fallback match an
|
|
6
|
+
* npm install. `undefined` restores the package-relative default.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setBuiltinAdaptersDirectory(directory: string | undefined): void;
|
|
2
9
|
export declare class AdapterRegistry {
|
|
3
10
|
private readonly adapters;
|
|
4
11
|
private readonly configSources;
|
package/dist/registry.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, statSync, existsSync, } from "node:fs";
|
|
2
|
-
import { join, dirname } from "node:path";
|
|
2
|
+
import { join, dirname, isAbsolute } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { getClinkxHome } from "../clinkx-workflows/dist/config.js";
|
|
6
6
|
import { CliAdapterConfigSchema } from "./config.js";
|
|
7
7
|
import { InvalidParamsError } from "./errors.js";
|
|
8
8
|
import { logger } from "./logger.js";
|
|
9
|
+
let builtinAdaptersDirectoryOverride;
|
|
10
|
+
/**
|
|
11
|
+
* A packaged runtime whose modules do not sit beside the package's `conf/`
|
|
12
|
+
* (the Node SEA dashboard extracts it elsewhere) registers the shipped adapter
|
|
13
|
+
* directory here, so discovery tiers and the prompt_file fallback match an
|
|
14
|
+
* npm install. `undefined` restores the package-relative default.
|
|
15
|
+
*/
|
|
16
|
+
export function setBuiltinAdaptersDirectory(directory) {
|
|
17
|
+
if (directory !== undefined && !isAbsolute(directory)) {
|
|
18
|
+
throw new Error(`built-in adapters directory must be absolute; got ${JSON.stringify(directory)}`);
|
|
19
|
+
}
|
|
20
|
+
builtinAdaptersDirectoryOverride = directory;
|
|
21
|
+
}
|
|
22
|
+
function builtinAdaptersDirectory() {
|
|
23
|
+
return builtinAdaptersDirectoryOverride
|
|
24
|
+
?? join(dirname(fileURLToPath(import.meta.url)), "..", "conf", "adapters");
|
|
25
|
+
}
|
|
9
26
|
function discoverConfigPaths() {
|
|
10
27
|
const envPath = process.env["CLINKX_CONFIG_PATH"];
|
|
11
28
|
if (envPath != null && envPath !== "") {
|
|
@@ -19,10 +36,8 @@ function discoverConfigPaths() {
|
|
|
19
36
|
const xdgHome = process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
|
|
20
37
|
const xdgDir = join(xdgHome, "clinkx", "adapters");
|
|
21
38
|
paths.push(...listJsonFiles(xdgDir));
|
|
22
|
-
// Built-in: conf/adapters/*.json
|
|
23
|
-
|
|
24
|
-
const builtinDir = join(__dirname, "..", "conf", "adapters");
|
|
25
|
-
paths.push(...listJsonFiles(builtinDir));
|
|
39
|
+
// Built-in: conf/adapters/*.json shipped with this runtime
|
|
40
|
+
paths.push(...listJsonFiles(builtinAdaptersDirectory()));
|
|
26
41
|
return paths;
|
|
27
42
|
}
|
|
28
43
|
function resolveConfigPath(configPath) {
|
|
@@ -56,8 +71,7 @@ export class AdapterRegistry {
|
|
|
56
71
|
configSources = new Map();
|
|
57
72
|
builtinAdaptersDir;
|
|
58
73
|
constructor() {
|
|
59
|
-
|
|
60
|
-
this.builtinAdaptersDir = join(__dirname, "..", "conf", "adapters");
|
|
74
|
+
this.builtinAdaptersDir = builtinAdaptersDirectory();
|
|
61
75
|
}
|
|
62
76
|
/**
|
|
63
77
|
* Load adapters from config files discovered via the standard precedence:
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,UAAU,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,UAAU,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAyB,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,IAAI,gCAAoD,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,SAA6B;IACvE,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,qDAAqD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACpG,CAAC;IACD,gCAAgC,GAAG,SAAS,CAAC;AAC/C,CAAC;AAED,SAAS,wBAAwB;IAC/B,OAAO,gCAAg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AO,CAAC;IACjB,CAAC;IAED,kFAAkF;IAClF,eAAe;QACb,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,oEAAoE;IACpE,gBAAgB,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,eAAe;QACb,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9C,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/server.js
CHANGED
|
@@ -30,6 +30,7 @@ import { getWorkflowToolDefinitions, handleWorkflowToolCall, resolveWorkflowAsyn
|
|
|
30
30
|
import { WorkflowCancellationError } from "../clinkx-workflows/dist/errors.js";
|
|
31
31
|
import { getChildMaxConcurrent, getChildConfigPath, getChildMaxResponseChars, getMaxParallel, getWorkflowsAllowUnsafeAsyncCap, getWorkflowsMaxConcurrentAsync, getWorkflowsContextDefault, getWorkflowsContextDefaultCurator, getStateDir, getClinkxHome, getArtifactsDir, hasExplicitWorkspaceRoot, homeTreeStorageRootWarnings, invocationAuditV2PersistenceEnabled, resolveWorkspaceRoot, } from "../clinkx-workflows/dist/config.js";
|
|
32
32
|
import { reconcileStaleRunDirectories, setRecipeRunPrePruneObserver } from "../clinkx-workflows/dist/state.js";
|
|
33
|
+
import { getSettingsApplication } from "../clinkx-workflows/dist/settings/bootstrap.js";
|
|
33
34
|
import { reconcileStaleContextBuilderJournals } from "./context-builder/lifecycle-reconcile.js";
|
|
34
35
|
import { defaultFullDelegateProviders } from "../clinkx-workflows/dist/context-mode-resolver.js";
|
|
35
36
|
import { createWorkflowContextBuilderLifecycleRouter, } from "../clinkx-workflows/dist/context-builder-lifecycle-router.js";
|
|
@@ -222,9 +223,25 @@ export function createServer(options = {}) {
|
|
|
222
223
|
// disabled (the documented total-bypass / hard kill), a malformed
|
|
223
224
|
// CLINKX_WORKFLOWS_CONTEXT_DEFAULT or empty CLINKX_WORKFLOWS_CONTEXT_DEFAULT_CURATOR
|
|
224
225
|
// must NOT throw and block createServer — pass inert safe defaults instead.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
//
|
|
227
|
+
// A2-2: a context-default value that came from the dashboard settings FILE
|
|
228
|
+
// gets a non-fatal fallback (warn + built-in default) at BOTH the getter and
|
|
229
|
+
// the delegate-validation layer. The loader validates file values against
|
|
230
|
+
// the registry, but the registry cannot know which adapters are configured
|
|
231
|
+
// on this machine, so a file-sourced curator can still fail startup
|
|
232
|
+
// validation — an operator editing the Settings page must not be able to
|
|
233
|
+
// kill every server on the workstation. Env-sourced values keep today's
|
|
234
|
+
// fatal contract (explicit operator intent).
|
|
235
|
+
const settingsApplication = getSettingsApplication();
|
|
236
|
+
const fileSourcedContextDefault = settingsApplication?.perKey["CLINKX_WORKFLOWS_CONTEXT_DEFAULT"]?.source ===
|
|
237
|
+
"file";
|
|
238
|
+
const fileSourcedDefaultCurator = settingsApplication?.perKey["CLINKX_WORKFLOWS_CONTEXT_DEFAULT_CURATOR"]
|
|
239
|
+
?.source === "file";
|
|
240
|
+
const contextDefault = workflowContextPreflightEnabled
|
|
241
|
+
? readContextDefaultWithFileFallback(fileSourcedContextDefault)
|
|
242
|
+
: "off";
|
|
243
|
+
let defaultCurator = workflowContextPreflightEnabled
|
|
244
|
+
? readDefaultCuratorWithFileFallback(fileSourcedDefaultCurator)
|
|
228
245
|
: "";
|
|
229
246
|
// The context runner needs an adapter registry to validate AND run the
|
|
230
247
|
// default-on context delegate (curator/finalizer) and to resolve
|
|
@@ -244,7 +261,24 @@ export function createServer(options = {}) {
|
|
|
244
261
|
"the default-on context delegate cannot be validated. Fix the adapter config or " +
|
|
245
262
|
"set CLINKX_WORKFLOWS_CONTEXT_PREFLIGHT_ENABLED=false to disable preflight.");
|
|
246
263
|
}
|
|
247
|
-
|
|
264
|
+
try {
|
|
265
|
+
validateWorkflowDefaultDelegate(contextRunnerRegistry, defaultCurator);
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
if (!fileSourcedDefaultCurator)
|
|
269
|
+
throw err;
|
|
270
|
+
// A2-2: the file-sourced curator is unusable on this machine (unknown
|
|
271
|
+
// adapter, missing role, app_server backend). Warn and fall back to the
|
|
272
|
+
// built-in default curator so the server still starts; if the built-in
|
|
273
|
+
// default itself cannot validate, that is a registry problem and stays
|
|
274
|
+
// fatal exactly as before.
|
|
275
|
+
logger.warn({
|
|
276
|
+
curator: defaultCurator,
|
|
277
|
+
err: err instanceof Error ? err.message : String(err),
|
|
278
|
+
}, "settings_file_default_curator_invalid_using_builtin");
|
|
279
|
+
defaultCurator = DEFAULT_CONTEXT_CURATOR;
|
|
280
|
+
validateWorkflowDefaultDelegate(contextRunnerRegistry, defaultCurator);
|
|
281
|
+
}
|
|
248
282
|
workflowContextBuilderLifecycleRouter =
|
|
249
283
|
createWorkflowContextBuilderLifecycleRouter();
|
|
250
284
|
workflowContextBuilderRunner = createWorkflowContextBuilderRunner({
|
|
@@ -659,6 +693,43 @@ function warnOnWorkflowAsyncConcurrencyConfig(input) {
|
|
|
659
693
|
}, "workflow_async_stage_seat_fanout");
|
|
660
694
|
}
|
|
661
695
|
}
|
|
696
|
+
/** Built-in default curator (clinkx-workflows config default). */
|
|
697
|
+
const DEFAULT_CONTEXT_CURATOR = "codex";
|
|
698
|
+
/**
|
|
699
|
+
* A2-2 getter wrapper: a FILE-sourced CLINKX_WORKFLOWS_CONTEXT_DEFAULT that
|
|
700
|
+
* the consumer grammar rejects falls back to the built-in default with a
|
|
701
|
+
* warning instead of killing createServer. Env-sourced values rethrow
|
|
702
|
+
* unchanged (today's fatal contract).
|
|
703
|
+
*/
|
|
704
|
+
function readContextDefaultWithFileFallback(fileSourced) {
|
|
705
|
+
try {
|
|
706
|
+
return getWorkflowsContextDefault();
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
if (!fileSourced)
|
|
710
|
+
throw err;
|
|
711
|
+
logger.warn({
|
|
712
|
+
env_var: "CLINKX_WORKFLOWS_CONTEXT_DEFAULT",
|
|
713
|
+
err: err instanceof Error ? err.message : String(err),
|
|
714
|
+
}, "settings_file_context_default_invalid_using_builtin");
|
|
715
|
+
return "full";
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/** A2-2 getter wrapper for CLINKX_WORKFLOWS_CONTEXT_DEFAULT_CURATOR (see above). */
|
|
719
|
+
function readDefaultCuratorWithFileFallback(fileSourced) {
|
|
720
|
+
try {
|
|
721
|
+
return getWorkflowsContextDefaultCurator();
|
|
722
|
+
}
|
|
723
|
+
catch (err) {
|
|
724
|
+
if (!fileSourced)
|
|
725
|
+
throw err;
|
|
726
|
+
logger.warn({
|
|
727
|
+
env_var: "CLINKX_WORKFLOWS_CONTEXT_DEFAULT_CURATOR",
|
|
728
|
+
err: err instanceof Error ? err.message : String(err),
|
|
729
|
+
}, "settings_file_default_curator_invalid_using_builtin");
|
|
730
|
+
return DEFAULT_CONTEXT_CURATOR;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
662
733
|
function validateWorkflowDefaultDelegate(registry, defaultCurator) {
|
|
663
734
|
// Single source of truth: validate EVERY enabled provider the injected default
|
|
664
735
|
// full delegate actually uses (curator AND finalizer), so a config can't pass
|