clinkx 1.3.0 → 1.4.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/CHANGELOG.md +28 -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-DSOtuS0p.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 +1285 -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.js +50 -1
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/protocol.js +17 -0
- package/dist/dashboard-companion/protocol.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/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/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/package.json +2 -2
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +0 -119
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +0 -1
package/dist/index.js
CHANGED
|
@@ -1,346 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { realpathSync } from "node:fs";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
-
import { serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
|
|
6
|
-
import { createServer } from "./server.js";
|
|
7
|
-
import { latchVerificationAdmissionForShutdown, shutdownVerificationTools } from "./verification-tools.js";
|
|
8
|
-
import { logger, assertStderrLogger } from "./logger.js";
|
|
9
|
-
import { assertNotRootDir } from "./paths.js";
|
|
10
|
-
import { activeProcesses, killAllActive, latchSubprocessAdmissionForShutdown, } from "./runner.js";
|
|
11
|
-
import { latchAppServerAdmissionForShutdown, setAppServerActivityObserver, shutdownAppServerRegistry, } from "./codex/app-server-registry.js";
|
|
12
|
-
import { createRootStdioActivity } from "./stdio-activity.js";
|
|
13
|
-
import { setWorkflowActivityObserver, } from "../clinkx-workflows/dist/workflow-tools.js";
|
|
14
|
-
import { shutdownCoordinator } from "../clinkx-workflows/dist/shutdown.js";
|
|
15
|
-
import { createStdioWatchdog } from "../clinkx-workflows/dist/stdio-watchdog.js";
|
|
16
|
-
const SHUTDOWN_DEADLINE_MS = 10_000;
|
|
17
|
-
const SEND_TIMEOUT_MS = 30_000;
|
|
18
|
-
const patchedTransports = new WeakSet();
|
|
19
2
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
3
|
+
* ClinkX bin entry (dist/index.js) — startup bootstrap shim (A2-1).
|
|
4
|
+
*
|
|
5
|
+
* The ONLY static import is the settings bootstrap, whose import closure is
|
|
6
|
+
* logger/config/pino-free (loader-import-graph.test.ts walks it). Everything
|
|
7
|
+
* else — the logger, the server, the pipeline — is loaded dynamically after
|
|
8
|
+
* applyStartupSettings(process.env) has overlaid dashboard settings file
|
|
9
|
+
* values, so module-load env readers (CLINKX_LOG_LEVEL, the concurrency
|
|
10
|
+
* singleton) observe the overlay. This file deliberately exports nothing: a
|
|
11
|
+
* static re-export of the stdio-main helpers would pull the runtime graph
|
|
12
|
+
* ahead of the bootstrap and silently defeat the overlay. Library consumers
|
|
13
|
+
* import the package main (dist/lib.js — src/lib.ts), which re-exports those
|
|
14
|
+
* helpers side-effect-free; only the bin path runs this shim.
|
|
15
|
+
*
|
|
16
|
+
* Behavior:
|
|
17
|
+
* - library import (main: dist/lib.js): nothing runs — importing the package
|
|
18
|
+
* never starts a server and never mutates env;
|
|
19
|
+
* - `clinkx settings …`: dynamic-imports the settings CLI (A3-1 replaces its
|
|
20
|
+
* body); no server starts and no settings file is read;
|
|
21
|
+
* - otherwise: applyStartupSettings, then dynamic-import ./stdio-main.js.
|
|
23
22
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name: "shutdownVerificationTools",
|
|
28
|
-
run: options.shutdownVerificationToolsFn ?? shutdownVerificationTools,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "killAllActive",
|
|
32
|
-
run: options.killAllActiveFn ?? (async () => {
|
|
33
|
-
await killAllActive();
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "shutdownAppServerRegistry",
|
|
38
|
-
run: options.shutdownAppServerRegistryFn ?? shutdownAppServerRegistry,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "shutdownWorkflowCoordinator",
|
|
42
|
-
run: options.shutdownWorkflowCoordinatorFn ?? ((reason) => shutdownCoordinator.shutdown(reason)),
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
return async (reason) => {
|
|
46
|
-
let failed = false;
|
|
47
|
-
let firstError;
|
|
48
|
-
const recordFailure = (cleanupName, err) => {
|
|
49
|
-
failed = true;
|
|
50
|
-
firstError ??= err;
|
|
51
|
-
try {
|
|
52
|
-
logger.error({
|
|
53
|
-
reason,
|
|
54
|
-
cleanup: cleanupName,
|
|
55
|
-
err: err instanceof Error ? err.message : String(err),
|
|
56
|
-
}, "shutdown cleanup surface failed");
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// A broken logger must not prevent the remaining cleanup surfaces from
|
|
60
|
-
// settling or replace the cleanup failure being reported.
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const pending = [];
|
|
64
|
-
for (const cleanup of cleanups) {
|
|
65
|
-
try {
|
|
66
|
-
// Invoke each surface before awaiting any result. Workflow shutdown
|
|
67
|
-
// must latch active runs even if generic process cleanup is draining.
|
|
68
|
-
pending.push(Promise.resolve(cleanup.run(reason)).catch((err) => {
|
|
69
|
-
recordFailure(cleanup.name, err);
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
recordFailure(cleanup.name, err);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
await Promise.all(pending);
|
|
77
|
-
if (failed) {
|
|
78
|
-
throw firstError instanceof Error
|
|
79
|
-
? firstError
|
|
80
|
-
: new Error("one or more shutdown cleanup surfaces failed");
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
export function createShutdownOnce(server, options = {}) {
|
|
85
|
-
let shuttingDown = false;
|
|
86
|
-
const killAllActiveFn = options.killAllActiveFn ?? killAllActive;
|
|
87
|
-
const latchSubprocessAdmissionFn = options.latchSubprocessAdmissionFn ?? latchSubprocessAdmissionForShutdown;
|
|
88
|
-
const exitFn = options.exitFn ?? ((exitCode) => {
|
|
89
|
-
process.exit(exitCode);
|
|
90
|
-
});
|
|
91
|
-
return async function shutdownOnce(reason, exitCode) {
|
|
92
|
-
if (shuttingDown)
|
|
93
|
-
return;
|
|
94
|
-
shuttingDown = true;
|
|
95
|
-
// Synchronous and first: no generic request may cross into spawn while
|
|
96
|
-
// cleanup drains the registry or before server.close stops new requests.
|
|
97
|
-
latchSubprocessAdmissionFn();
|
|
98
|
-
(options.latchVerificationAdmissionFn ?? latchVerificationAdmissionForShutdown)();
|
|
99
|
-
try {
|
|
100
|
-
// Close singleton app-server admission before any asynchronous cleanup
|
|
101
|
-
// can observe or replace the current registry.
|
|
102
|
-
options.latchAppServerAdmissionFn?.(reason);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
logger.error({
|
|
106
|
-
reason,
|
|
107
|
-
err: err instanceof Error ? err.message : String(err),
|
|
108
|
-
}, "app-server shutdown latch failed");
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
// The workflow coordinator must latch its own admission before any
|
|
112
|
-
// asynchronous cleanup surface begins to drain.
|
|
113
|
-
options.beginWorkflowShutdownFn?.(reason);
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
logger.error({
|
|
117
|
-
reason,
|
|
118
|
-
err: err instanceof Error ? err.message : String(err),
|
|
119
|
-
}, "workflow shutdown latch failed");
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
options.clearWorkflowActivityObserverFn?.();
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
logger.error({
|
|
126
|
-
reason,
|
|
127
|
-
err: err instanceof Error ? err.message : String(err),
|
|
128
|
-
}, "workflow activity observer clear failed");
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
options.clearAppServerActivityObserverFn?.();
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
logger.error({
|
|
135
|
-
reason,
|
|
136
|
-
err: err instanceof Error ? err.message : String(err),
|
|
137
|
-
}, "app-server activity observer clear failed");
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
options.stopWatchdogFn?.();
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
logger.error({
|
|
144
|
-
reason,
|
|
145
|
-
err: err instanceof Error ? err.message : String(err),
|
|
146
|
-
}, "shutdown watchdog stop failed");
|
|
147
|
-
}
|
|
148
|
-
const deadline = new Promise((_, reject) => {
|
|
149
|
-
setTimeout(() => reject(new Error("shutdown deadline exceeded")), SHUTDOWN_DEADLINE_MS).unref();
|
|
150
|
-
});
|
|
151
|
-
try {
|
|
152
|
-
await Promise.race([
|
|
153
|
-
(async () => {
|
|
154
|
-
let effectiveExitCode = exitCode;
|
|
155
|
-
logger.info({ reason, activeProcesses: activeProcesses.size, writableLength: process.stdout.writableLength }, "clinkx:shutdown");
|
|
156
|
-
logger.info({ reason, exit_code: exitCode }, "shutdown requested, cleaning up");
|
|
157
|
-
try {
|
|
158
|
-
await killAllActiveFn(reason);
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
effectiveExitCode = 1;
|
|
162
|
-
logger.error({ reason, err: err instanceof Error ? err.message : String(err) }, "killAllActive failed during shutdown");
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
await server.close();
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
effectiveExitCode = 1;
|
|
169
|
-
logger.error({ reason, err: err instanceof Error ? err.message : String(err) }, "server close failed during shutdown");
|
|
170
|
-
}
|
|
171
|
-
if (process.stdout.writableLength > 0 && process.stdout.writable) {
|
|
172
|
-
await new Promise((resolve) => {
|
|
173
|
-
const onDrain = () => {
|
|
174
|
-
clearTimeout(timer);
|
|
175
|
-
resolve();
|
|
176
|
-
};
|
|
177
|
-
const timer = setTimeout(() => {
|
|
178
|
-
process.stdout.off("drain", onDrain);
|
|
179
|
-
resolve();
|
|
180
|
-
}, 2_000);
|
|
181
|
-
timer.unref();
|
|
182
|
-
process.stdout.once("drain", onDrain);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
exitFn(effectiveExitCode);
|
|
186
|
-
})(),
|
|
187
|
-
deadline,
|
|
188
|
-
]);
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
try {
|
|
192
|
-
logger.error({ reason }, "shutdown deadline exceeded, forcing exit");
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
// stderr may be broken
|
|
196
|
-
}
|
|
197
|
-
process.exit(1);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function runShutdown(shutdownOnce, reason, exitCode) {
|
|
202
|
-
void shutdownOnce(reason, exitCode).catch((err) => {
|
|
203
|
-
try {
|
|
204
|
-
logger.fatal({ err, reason }, "shutdown failed");
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
// stderr may already be broken
|
|
208
|
-
}
|
|
209
|
-
process.exit(1);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function logFatal(reason, err) {
|
|
213
|
-
try {
|
|
214
|
-
logger.fatal({ err, reason }, "fatal process event");
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
// stderr may already be broken
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function toError(err) {
|
|
221
|
-
return err instanceof Error ? err : new Error(String(err));
|
|
222
|
-
}
|
|
223
|
-
function extractRpcMeta(msg) {
|
|
224
|
-
if ("method" in msg) {
|
|
225
|
-
return "id" in msg && msg.id !== undefined ? { id: msg.id, method: msg.method } : { method: msg.method };
|
|
226
|
-
}
|
|
227
|
-
if ("id" in msg && msg.id !== undefined)
|
|
228
|
-
return { id: msg.id };
|
|
229
|
-
return {};
|
|
230
|
-
}
|
|
231
|
-
export function patchTransportSend(transport, stdout = process.stdout, onBrokenStdout, activity) {
|
|
232
|
-
if (patchedTransports.has(transport))
|
|
233
|
-
return;
|
|
234
|
-
patchedTransports.add(transport);
|
|
235
|
-
let brokenError;
|
|
236
|
-
let sendChain = Promise.resolve();
|
|
237
|
-
const pendingRejects = [];
|
|
238
|
-
let shuttingDown = false;
|
|
239
|
-
function markBroken(err) {
|
|
240
|
-
brokenError ??= err;
|
|
241
|
-
const rejects = pendingRejects.splice(0);
|
|
242
|
-
for (const reject of rejects) {
|
|
243
|
-
reject(brokenError);
|
|
244
|
-
}
|
|
245
|
-
if (!shuttingDown) {
|
|
246
|
-
shuttingDown = true;
|
|
247
|
-
stdout.off("error", onError);
|
|
248
|
-
onBrokenStdout?.();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function onError(err) {
|
|
252
|
-
markBroken(err);
|
|
253
|
-
}
|
|
254
|
-
stdout.on("error", onError);
|
|
255
|
-
function sendOne(message) {
|
|
256
|
-
if (brokenError !== undefined) {
|
|
257
|
-
return Promise.reject(brokenError);
|
|
258
|
-
}
|
|
259
|
-
const json = serializeMessage(message);
|
|
260
|
-
const payloadBytes = Buffer.byteLength(json, "utf8");
|
|
261
|
-
const { id: rpcId, method: rpcMethod } = extractRpcMeta(message);
|
|
262
|
-
return new Promise((resolve, reject) => {
|
|
263
|
-
if (brokenError !== undefined) {
|
|
264
|
-
reject(brokenError);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
let settled = false;
|
|
268
|
-
let drainAttached = false;
|
|
269
|
-
let drainStartedAt = 0;
|
|
270
|
-
const timeout = setTimeout(() => {
|
|
271
|
-
logger.error({ rpcId, rpcMethod, payloadBytes }, "transport:send:timeout");
|
|
272
|
-
markBroken(new Error(`stdout write timed out after ${SEND_TIMEOUT_MS}ms`));
|
|
273
|
-
}, SEND_TIMEOUT_MS);
|
|
274
|
-
timeout.unref();
|
|
275
|
-
function cleanup() {
|
|
276
|
-
clearTimeout(timeout);
|
|
277
|
-
const index = pendingRejects.indexOf(onStdoutError);
|
|
278
|
-
if (index !== -1) {
|
|
279
|
-
pendingRejects.splice(index, 1);
|
|
280
|
-
}
|
|
281
|
-
if (drainAttached) {
|
|
282
|
-
stdout.off("drain", onDrain);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
function settleResolve() {
|
|
286
|
-
if (settled)
|
|
287
|
-
return;
|
|
288
|
-
settled = true;
|
|
289
|
-
const drainMs = drainStartedAt === 0 ? 0 : Date.now() - drainStartedAt;
|
|
290
|
-
cleanup();
|
|
291
|
-
logger.debug({ rpcId, rpcMethod, payloadBytes, drainMs }, "transport:send:ok");
|
|
292
|
-
resolve();
|
|
293
|
-
}
|
|
294
|
-
function settleReject(err) {
|
|
295
|
-
if (settled)
|
|
296
|
-
return;
|
|
297
|
-
settled = true;
|
|
298
|
-
cleanup();
|
|
299
|
-
reject(err);
|
|
300
|
-
}
|
|
301
|
-
function onStdoutError(err) {
|
|
302
|
-
settleReject(err);
|
|
303
|
-
}
|
|
304
|
-
function onDrain() {
|
|
305
|
-
settleResolve();
|
|
306
|
-
}
|
|
307
|
-
pendingRejects.push(onStdoutError);
|
|
308
|
-
try {
|
|
309
|
-
logger.debug({ rpcId, rpcMethod, payloadBytes, writableLength: stdout.writableLength }, "transport:send:start");
|
|
310
|
-
if (stdout.write(json)) {
|
|
311
|
-
settleResolve();
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
drainAttached = true;
|
|
315
|
-
drainStartedAt = Date.now();
|
|
316
|
-
stdout.once("drain", onDrain);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
catch (err) {
|
|
320
|
-
const error = toError(err);
|
|
321
|
-
const nodeError = error;
|
|
322
|
-
logger.error({
|
|
323
|
-
rpcId,
|
|
324
|
-
rpcMethod,
|
|
325
|
-
payloadBytes,
|
|
326
|
-
errCode: nodeError.code,
|
|
327
|
-
errSyscall: nodeError.syscall,
|
|
328
|
-
}, "transport:send:error");
|
|
329
|
-
markBroken(error);
|
|
330
|
-
settleReject(error);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
transport.send = (message) => {
|
|
335
|
-
const releaseSend = activity?.beginSend();
|
|
336
|
-
const send = sendChain.then(() => sendOne(message), () => sendOne(message));
|
|
337
|
-
sendChain = send.catch(() => undefined);
|
|
338
|
-
if (releaseSend !== undefined) {
|
|
339
|
-
void send.then(() => releaseSend(), () => releaseSend());
|
|
340
|
-
}
|
|
341
|
-
return send;
|
|
342
|
-
};
|
|
343
|
-
}
|
|
23
|
+
import { realpathSync } from "node:fs";
|
|
24
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
25
|
+
import { applyStartupSettings } from "../clinkx-workflows/dist/settings/bootstrap.js";
|
|
344
26
|
function isEntrypoint() {
|
|
345
27
|
const entry = process.argv[1];
|
|
346
28
|
if (entry == null)
|
|
@@ -352,72 +34,27 @@ function isEntrypoint() {
|
|
|
352
34
|
return import.meta.url === pathToFileURL(entry).href;
|
|
353
35
|
}
|
|
354
36
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
assertStderrLogger();
|
|
365
|
-
// Startup safety guard: refuse running from filesystem root unless explicitly allowlisted
|
|
366
|
-
assertNotRootDir();
|
|
367
|
-
const activity = createRootStdioActivity();
|
|
368
|
-
const server = createServer({ activity });
|
|
369
|
-
const transport = new StdioServerTransport();
|
|
370
|
-
logger.info("ClinkX MCP server starting (STDIO transport)");
|
|
371
|
-
logger.info({ pid: process.pid, ppid: process.ppid }, "clinkx:startup");
|
|
372
|
-
let watchdog;
|
|
373
|
-
const shutdownOnce = createShutdownOnce(server, {
|
|
374
|
-
killAllActiveFn: createRootCleanup(),
|
|
375
|
-
latchAppServerAdmissionFn: (reason) => latchAppServerAdmissionForShutdown(reason),
|
|
376
|
-
beginWorkflowShutdownFn: (reason) => shutdownCoordinator.beginShutdown(reason),
|
|
377
|
-
clearWorkflowActivityObserverFn: () => setWorkflowActivityObserver(undefined),
|
|
378
|
-
clearAppServerActivityObserverFn: () => setAppServerActivityObserver(undefined),
|
|
379
|
-
stopWatchdogFn: () => watchdog?.stop(),
|
|
380
|
-
});
|
|
381
|
-
watchdog = createStdioWatchdog({
|
|
382
|
-
isBusy: activity.isBusy,
|
|
383
|
-
onShutdown: (reason, exitCode) => {
|
|
384
|
-
runShutdown(shutdownOnce, reason, exitCode);
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
activity.attachWatchdog(watchdog.recordActivity);
|
|
388
|
-
setWorkflowActivityObserver(activity.recordActivity);
|
|
389
|
-
setAppServerActivityObserver(activity.recordActivity);
|
|
390
|
-
const previousOnMessage = transport.onmessage;
|
|
391
|
-
transport.onmessage = (message) => {
|
|
392
|
-
activity.recordActivity();
|
|
393
|
-
previousOnMessage?.(message);
|
|
394
|
-
};
|
|
395
|
-
// The transport patch must retain activity until the SDK's response send or
|
|
396
|
-
// stdout drain settles; otherwise an idle timer can race the handler return.
|
|
397
|
-
patchTransportSend(transport, process.stdout, () => {
|
|
398
|
-
runShutdown(shutdownOnce, "stdout:error", 1);
|
|
399
|
-
}, activity);
|
|
400
|
-
process.on("SIGTERM", () => runShutdown(shutdownOnce, "SIGTERM", 0));
|
|
401
|
-
process.once("SIGINT", () => runShutdown(shutdownOnce, "SIGINT", 0));
|
|
402
|
-
process.on("SIGHUP", () => runShutdown(shutdownOnce, "SIGHUP", 0));
|
|
403
|
-
process.stdin.once("end", () => runShutdown(shutdownOnce, "stdin:end", 0));
|
|
404
|
-
process.stdin.once("close", () => runShutdown(shutdownOnce, "stdin:close", 0));
|
|
405
|
-
process.stdin.once("error", () => runShutdown(shutdownOnce, "stdin:error", 1));
|
|
406
|
-
process.stderr.on("error", () => runShutdown(shutdownOnce, "stderr:error", 0));
|
|
407
|
-
process.on("uncaughtException", (err) => {
|
|
408
|
-
logFatal("uncaughtException", err);
|
|
409
|
-
runShutdown(shutdownOnce, "uncaughtException", 1);
|
|
410
|
-
});
|
|
411
|
-
process.on("unhandledRejection", (reason) => {
|
|
412
|
-
logFatal("unhandledRejection", reason);
|
|
413
|
-
runShutdown(shutdownOnce, "unhandledRejection", 1);
|
|
414
|
-
});
|
|
415
|
-
await server.connect(transport);
|
|
416
|
-
logger.info("ClinkX MCP server connected and ready");
|
|
37
|
+
async function runEntry() {
|
|
38
|
+
if (process.argv[2] === "settings") {
|
|
39
|
+
const cli = await import("./settings-cli/main.js");
|
|
40
|
+
process.exitCode = await cli.runSettingsCli(process.argv.slice(3));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const application = applyStartupSettings(process.env);
|
|
44
|
+
const stdioMain = await import("./stdio-main.js");
|
|
45
|
+
await stdioMain.runStdioMain(application);
|
|
417
46
|
}
|
|
418
47
|
if (isEntrypoint()) {
|
|
419
|
-
|
|
420
|
-
logger
|
|
48
|
+
runEntry().catch(async (err) => {
|
|
49
|
+
// The logger lives in the dynamically imported graph; load it lazily so
|
|
50
|
+
// this failure path still honors the (possibly file-sourced) log level.
|
|
51
|
+
try {
|
|
52
|
+
const { logger } = await import("./logger.js");
|
|
53
|
+
logger.fatal({ err }, "ClinkX failed to start");
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
process.stderr.write(`clinkx: failed to start: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
57
|
+
}
|
|
421
58
|
process.exitCode = 1;
|
|
422
59
|
});
|
|
423
60
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect-free library entry — package.json `main` points here
|
|
3
|
+
* (dist/lib.js, R3/A2#10).
|
|
4
|
+
*
|
|
5
|
+
* `dist/index.js` must stay the bin shim: clients launch it directly, and its
|
|
6
|
+
* ONLY static import is the settings bootstrap so the startup overlay applies
|
|
7
|
+
* before any module-load env reader. That makes it a poor library entry — a
|
|
8
|
+
* library consumer would drag the bootstrap closure and the whole runtime
|
|
9
|
+
* graph through an entry shaped for process launch. This module re-exports
|
|
10
|
+
* the 1.3.0 `import "clinkx"` API from stdio-main instead. stdio-main has no
|
|
11
|
+
* top-level side effects beyond the import graph 1.3.0's index already
|
|
12
|
+
* loaded (its only module-scope state is two constants and a WeakSet; the
|
|
13
|
+
* sole module-scope env access anywhere in that graph is a read), so
|
|
14
|
+
* importing the package as a library starts no server and mutates no env.
|
|
15
|
+
*/
|
|
16
|
+
export { createRootCleanup, createShutdownOnce, patchTransportSend } from "./stdio-main.js";
|
|
17
|
+
export type { RootCleanupOptions } from "./stdio-main.js";
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect-free library entry — package.json `main` points here
|
|
3
|
+
* (dist/lib.js, R3/A2#10).
|
|
4
|
+
*
|
|
5
|
+
* `dist/index.js` must stay the bin shim: clients launch it directly, and its
|
|
6
|
+
* ONLY static import is the settings bootstrap so the startup overlay applies
|
|
7
|
+
* before any module-load env reader. That makes it a poor library entry — a
|
|
8
|
+
* library consumer would drag the bootstrap closure and the whole runtime
|
|
9
|
+
* graph through an entry shaped for process launch. This module re-exports
|
|
10
|
+
* the 1.3.0 `import "clinkx"` API from stdio-main instead. stdio-main has no
|
|
11
|
+
* top-level side effects beyond the import graph 1.3.0's index already
|
|
12
|
+
* loaded (its only module-scope state is two constants and a WeakSet; the
|
|
13
|
+
* sole module-scope env access anywhere in that graph is a read), so
|
|
14
|
+
* importing the package as a library starts no server and mutates no env.
|
|
15
|
+
*/
|
|
16
|
+
export { createRootCleanup, createShutdownOnce, patchTransportSend } from "./stdio-main.js";
|
|
17
|
+
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
/** Give up rather than block an MCP request forever on a contended session. */
|
|
3
|
-
export declare const LOCK_ACQUIRE_TIMEOUT_MS = 10000;
|
|
4
|
-
/**
|
|
5
|
-
* How often a holder refreshes its own lock's mtime. This is what makes a lock
|
|
6
|
-
* observably ALIVE to a reader that cannot probe our PID, and it is also what
|
|
7
|
-
* lets a stolen-from holder notice and abort. Matches the interval the workflow
|
|
8
|
-
* `run.lock` and the dashboard credential store already use.
|
|
9
|
-
*/
|
|
10
|
-
export declare const LOCK_HEARTBEAT_MS = 10000;
|
|
11
|
-
/**
|
|
12
|
-
* Floor for the foreign-host staleness window. A lock is only judged abandoned
|
|
13
|
-
* on heartbeat evidence once it has missed several beats AND at least this long
|
|
14
|
-
* has passed, so ordinary scheduling jitter never looks like death.
|
|
15
|
-
*/
|
|
16
|
-
export declare const LOCK_HEARTBEAT_STALE_FLOOR_MS = 60000;
|
|
1
|
+
export { LOCK_FILENAME, LOCK_ACQUIRE_TIMEOUT_MS } from "../../clinkx-workflows/dist/settings/lock.js";
|
|
17
2
|
/**
|
|
18
3
|
* A holder's live claim on the critical section.
|
|
19
4
|
*
|
|
20
|
-
* `assertHeld` is not decoration
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* which a stolen-from holder can still commit down to the syscall that follows.
|
|
5
|
+
* `assertHeld` is not decoration: callers that are about to make a durable
|
|
6
|
+
* change must re-establish ownership immediately beforehand. See the shared
|
|
7
|
+
* lock core for the full rationale.
|
|
24
8
|
*/
|
|
25
9
|
export interface SessionLockGuard {
|
|
26
10
|
assertHeld(): Promise<void>;
|
|
@@ -28,46 +12,20 @@ export interface SessionLockGuard {
|
|
|
28
12
|
/**
|
|
29
13
|
* Run `fn` while holding an exclusive cross-process lock on `sessionDir`.
|
|
30
14
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* RECLAMATION REQUIRES PROOF, NOT AGE. `O_EXCL` arbitrates creation only, so an
|
|
40
|
-
* unconditional unlink of a lock merely judged old is unsafe: two contenders can
|
|
41
|
-
* both judge the same abandoned lock, the first can unlink-recreate-and-enter,
|
|
42
|
-
* and the second's already-justified unlink then deletes the FIRST's live lock
|
|
43
|
-
* and lets it enter too. Both would then read the same revision, both pass the
|
|
44
|
-
* CAS, and one write would be silently lost. So a lock is reclaimed only on
|
|
45
|
-
* positive evidence of death: a dead PID on this host, or — for a lock written
|
|
46
|
-
* on another host, where no probe is possible — a heartbeat that has been
|
|
47
|
-
* missing for several declared intervals. Every other case waits. A holder that
|
|
48
|
-
* declared no heartbeat is never reclaimed on silence, which is what keeps a
|
|
49
|
-
* lock written by an older producer safe. Evidence alone is still not enough to
|
|
50
|
-
* make two simultaneous reclaimers safe, so the unlink itself is serialized
|
|
51
|
-
* behind a second `O_EXCL` file (`reclaimAbandonedLock`).
|
|
52
|
-
*
|
|
53
|
-
* Release is ownership-checked: the holder re-reads the lock body and unlinks
|
|
54
|
-
* only if the token is still its own, so a holder that was stolen from does not
|
|
55
|
-
* normally delete the new owner's lock. Node exposes no atomic
|
|
56
|
-
* compare-and-unlink, so that check is read-then-unlink and a steal landing
|
|
57
|
-
* inside that window is still possible; the guarantee is "will not", not
|
|
58
|
-
* "cannot".
|
|
15
|
+
* Thin wrapper (P9/R1): the exclusion primitive, the fail-closed foreign-host
|
|
16
|
+
* rule, the link-published atomic lock body and the steal-lock-serialized
|
|
17
|
+
* reclaim all live in ONE place — the settings lock in clinkx-workflows — so
|
|
18
|
+
* the two surfaces cannot drift apart again. This module only adapts that core
|
|
19
|
+
* to the progress-report surface: `warn` goes to the root logger, and
|
|
20
|
+
* `SettingsLockError` (the cw package must not import root error classes)
|
|
21
|
+
* maps onto `ExecutionError` with the message kept verbatim, including the
|
|
22
|
+
* lock path and the manual `rm` recovery step a foreign-host timeout names.
|
|
59
23
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* the repo already accepts for `run.lock` and `contained-file.ts`. The steal
|
|
66
|
-
* lock adds one of its own: a process that dies while holding `.lock.steal`
|
|
67
|
-
* leaves it behind, which disables AUTOMATIC RECLAMATION for that session —
|
|
68
|
-
* normal acquisition and release are unaffected — until an operator removes the
|
|
69
|
-
* file. That is strictly the better failure mode: a session that needs a manual
|
|
70
|
-
* unwedge, rather than two writers in the critical section.
|
|
24
|
+
* A legacy lock body written by an older build of THIS module is still
|
|
25
|
+
* reclaimed: lock identity is `token`/`pid`/`hostname`, which the old
|
|
26
|
+
* snake_case body (`acquired_at`, `heartbeat_interval_ms`) already carries,
|
|
27
|
+
* and the shared core tolerates the missing camelCase `startedAt` — pinned by
|
|
28
|
+
* a test so same-host dead-PID reclaim keeps working across an upgrade.
|
|
71
29
|
*/
|
|
72
30
|
export declare function withSessionLock<T>(sessionDir: string, fn: (guard: SessionLockGuard) => Promise<T>, options?: {
|
|
73
31
|
readonly acquireTimeoutMs?: number;
|