@1mcp/agent 0.33.0 → 0.34.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/build/commands/serve/index.d.ts +25 -0
- package/build/commands/serve/index.d.ts.map +1 -1
- package/build/commands/serve/index.js +39 -0
- package/build/commands/serve/index.js.map +1 -1
- package/build/commands/serve/runtimeScope.d.ts +13 -0
- package/build/commands/serve/runtimeScope.d.ts.map +1 -0
- package/build/commands/serve/runtimeScope.js +24 -0
- package/build/commands/serve/runtimeScope.js.map +1 -0
- package/build/commands/serve/serve.d.ts +10 -0
- package/build/commands/serve/serve.d.ts.map +1 -1
- package/build/commands/serve/serve.js +64 -28
- package/build/commands/serve/serve.js.map +1 -1
- package/build/commands/serve/serveBackground.d.ts +89 -0
- package/build/commands/serve/serveBackground.d.ts.map +1 -0
- package/build/commands/serve/serveBackground.js +299 -0
- package/build/commands/serve/serveBackground.js.map +1 -0
- package/build/commands/serve/serveRestart.d.ts +24 -0
- package/build/commands/serve/serveRestart.d.ts.map +1 -0
- package/build/commands/serve/serveRestart.js +22 -0
- package/build/commands/serve/serveRestart.js.map +1 -0
- package/build/commands/serve/serveStatus.d.ts +39 -0
- package/build/commands/serve/serveStatus.d.ts.map +1 -0
- package/build/commands/serve/serveStatus.js +58 -0
- package/build/commands/serve/serveStatus.js.map +1 -0
- package/build/commands/serve/serveStop.d.ts +36 -0
- package/build/commands/serve/serveStop.d.ts.map +1 -0
- package/build/commands/serve/serveStop.js +93 -0
- package/build/commands/serve/serveStop.js.map +1 -0
- package/build/constants/mcp.d.ts +1 -1
- package/build/constants/mcp.js +1 -1
- package/build/core/server/pidFileManager.d.ts +35 -4
- package/build/core/server/pidFileManager.d.ts.map +1 -1
- package/build/core/server/pidFileManager.js +105 -25
- package/build/core/server/pidFileManager.js.map +1 -1
- package/build/core/server/runtimeLifecycle.d.ts +69 -0
- package/build/core/server/runtimeLifecycle.d.ts.map +1 -0
- package/build/core/server/runtimeLifecycle.js +100 -0
- package/build/core/server/runtimeLifecycle.js.map +1 -0
- package/build/core/types/transport.d.ts +25 -0
- package/build/core/types/transport.d.ts.map +1 -1
- package/build/core/types/transport.js +23 -2
- package/build/core/types/transport.js.map +1 -1
- package/build/logger/configureGlobalLogger.d.ts +7 -2
- package/build/logger/configureGlobalLogger.d.ts.map +1 -1
- package/build/logger/configureGlobalLogger.js +5 -1
- package/build/logger/configureGlobalLogger.js.map +1 -1
- package/build/logger/logger.d.ts +4 -0
- package/build/logger/logger.d.ts.map +1 -1
- package/build/logger/logger.js +5 -1
- package/build/logger/logger.js.map +1 -1
- package/build/logger/loggingConfig.d.ts +66 -0
- package/build/logger/loggingConfig.d.ts.map +1 -0
- package/build/logger/loggingConfig.js +59 -0
- package/build/logger/loggingConfig.js.map +1 -0
- package/build/utils/validation/urlDetection.d.ts +4 -0
- package/build/utils/validation/urlDetection.d.ts.map +1 -1
- package/build/utils/validation/urlDetection.js +31 -22
- package/build/utils/validation/urlDetection.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { ConfigManager } from '../../config/configManager.js';
|
|
5
|
+
import { readPidFile } from '../../core/server/pidFileManager.js';
|
|
6
|
+
import { discoverScopedRuntime, probeLoadingSummary, probeReadiness, } from '../../core/server/runtimeLifecycle.js';
|
|
7
|
+
import logger from '../../logger/logger.js';
|
|
8
|
+
import { resolveLoggingConfig } from '../../logger/loggingConfig.js';
|
|
9
|
+
import { normalizedArgv } from '../../utils/cli/normalizedArgv.js';
|
|
10
|
+
import { resolveServeConfigPaths } from './runtimeScope.js';
|
|
11
|
+
/**
|
|
12
|
+
* `serve --background`: start the HTTP Aggregated Runtime as a detached child
|
|
13
|
+
* for the selected Runtime Scope, then return once it is ready.
|
|
14
|
+
*
|
|
15
|
+
* The parent never serves; it spawns a detached copy of this executable running
|
|
16
|
+
* the normal serve path (marked with an internal guard flag so it does not
|
|
17
|
+
* recursively background itself), waits for the child's PID file and
|
|
18
|
+
* `/health/ready`, and reports the result.
|
|
19
|
+
*/
|
|
20
|
+
/** Internal guard flag name; mirrors the hidden yargs option in `index.ts`. */
|
|
21
|
+
export const BACKGROUND_GUARD_FLAG = 'background-bootstrap';
|
|
22
|
+
/** Default log file for a background runtime when none is configured. */
|
|
23
|
+
export function defaultBackgroundLogFile(configDir) {
|
|
24
|
+
return path.join(configDir, 'logs', 'server.log');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build the child's serve arguments: strip flags the parent overrides
|
|
28
|
+
* (`--background`, `--transport`/`-t`, `--log-file`, and the guard — including
|
|
29
|
+
* their `=`-joined forms) and re-append the HTTP transport, the resolved log
|
|
30
|
+
* file, and the guard flag. Background is HTTP-only, so the child is always
|
|
31
|
+
* forced onto `--transport http`.
|
|
32
|
+
*/
|
|
33
|
+
export function buildBackgroundChildArgs(serveArgs, opts) {
|
|
34
|
+
const stripWithValue = new Set(['--transport', '-t', '--log-file']);
|
|
35
|
+
const out = [];
|
|
36
|
+
for (let i = 0; i < serveArgs.length; i++) {
|
|
37
|
+
const token = serveArgs[i];
|
|
38
|
+
if (token === '--background' || token === `--${BACKGROUND_GUARD_FLAG}`) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (/^--(transport|log-file)=/.test(token) || /^-t=/.test(token)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (stripWithValue.has(token)) {
|
|
45
|
+
i++; // also skip the following value
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
out.push(token);
|
|
49
|
+
}
|
|
50
|
+
out.push('--transport', 'http', '--log-file', opts.logFile, `--${BACKGROUND_GUARD_FLAG}`);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve how to re-invoke this executable cross-platform.
|
|
55
|
+
* - Under Node: `process.execPath` (node) + the JS entry script.
|
|
56
|
+
* - As a packaged SEA binary: `process.execPath` is the binary itself, no script.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveSelfInvocation(argv = process.argv) {
|
|
59
|
+
const script = argv[1];
|
|
60
|
+
if (script && /\.(c|m)?js$/.test(script)) {
|
|
61
|
+
return { command: process.execPath, baseArgs: [script] };
|
|
62
|
+
}
|
|
63
|
+
return { command: process.execPath, baseArgs: [] };
|
|
64
|
+
}
|
|
65
|
+
/** Strip the single `serve` command token (it is re-added explicitly on spawn). */
|
|
66
|
+
function stripServeToken(args) {
|
|
67
|
+
const index = args.indexOf('serve');
|
|
68
|
+
if (index === -1) {
|
|
69
|
+
return [...args];
|
|
70
|
+
}
|
|
71
|
+
return [...args.slice(0, index), ...args.slice(index + 1)];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wait until the child's PID file identifies the spawned child AND
|
|
75
|
+
* `/health/ready` succeeds, or until timeout / child death.
|
|
76
|
+
*/
|
|
77
|
+
export async function waitForBackgroundReady(configDir, childPid, options = {}) {
|
|
78
|
+
const timeoutMs = options.timeoutMs ?? 30000;
|
|
79
|
+
const intervalMs = options.intervalMs ?? 250;
|
|
80
|
+
const probe = options.readinessProbe ?? probeReadiness;
|
|
81
|
+
const now = options.now ?? (() => Date.now());
|
|
82
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
83
|
+
const start = now();
|
|
84
|
+
while (now() - start < timeoutMs) {
|
|
85
|
+
if (options.isChildAlive && !options.isChildAlive()) {
|
|
86
|
+
return { ready: false, reason: 'background process exited before becoming ready' };
|
|
87
|
+
}
|
|
88
|
+
const info = readPidFile(configDir);
|
|
89
|
+
options.onProgress?.({ elapsedMs: now() - start, info: info ?? undefined });
|
|
90
|
+
if (info && info.pid === childPid && (await probe(info))) {
|
|
91
|
+
return { ready: true, info };
|
|
92
|
+
}
|
|
93
|
+
await sleep(intervalMs);
|
|
94
|
+
}
|
|
95
|
+
return { ready: false, reason: `timed out after ${timeoutMs}ms waiting for readiness` };
|
|
96
|
+
}
|
|
97
|
+
function defaultLoadAppConfig(parsedArgv) {
|
|
98
|
+
const { configFilePath } = resolveServeConfigPaths(parsedArgv);
|
|
99
|
+
return ConfigManager.getInstance(configFilePath).getAppConfig();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Parent routine for `serve --background`. Sets `process.exitCode` and returns;
|
|
103
|
+
* never starts a server in-process.
|
|
104
|
+
*/
|
|
105
|
+
export async function runServeBackground(parsedArgv, deps = {}) {
|
|
106
|
+
const { runtimeScope: configDir } = resolveServeConfigPaths(parsedArgv);
|
|
107
|
+
const loadAppConfig = deps.loadAppConfig ?? defaultLoadAppConfig;
|
|
108
|
+
const appConfig = loadAppConfig(parsedArgv);
|
|
109
|
+
// Mirror the async-loading precedence from serve.ts so the started report can
|
|
110
|
+
// hint at the fast-detach path when the runtime is in the (default) sync mode.
|
|
111
|
+
const asyncEnabled = parsedArgv['enable-async-loading'] ?? appConfig.asyncLoading?.enabled ?? false;
|
|
112
|
+
// HTTP-only: reject stdio; sse normalizes to http.
|
|
113
|
+
const effectiveTransport = parsedArgv.transport ?? appConfig.transport ?? 'http';
|
|
114
|
+
if (effectiveTransport === 'stdio') {
|
|
115
|
+
process.stderr.write('Error: `serve --background --transport stdio` is not supported.\n' +
|
|
116
|
+
'stdio uses the invoking process stdin/stdout and cannot be detached. Use HTTP transport.\n');
|
|
117
|
+
process.exitCode = 1;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Idempotency: do not start a second runtime if the scope is already occupied.
|
|
121
|
+
const existing = await discoverScopedRuntime(configDir);
|
|
122
|
+
if (existing.status === 'running' && existing.info) {
|
|
123
|
+
process.stdout.write(`A runtime is already running in this Runtime Scope; not starting another.\n` +
|
|
124
|
+
formatStartedReport(existing.info));
|
|
125
|
+
process.exitCode = 0;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (existing.status === 'unreachable' && existing.info) {
|
|
129
|
+
process.stderr.write(`A runtime already occupies this Runtime Scope (PID ${existing.info.pid}) but is not ready yet.\n` +
|
|
130
|
+
`Refusing to start a second runtime. Check 'serve --status' or stop it first.\n`);
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (existing.status === 'error') {
|
|
135
|
+
process.stderr.write(`Cannot inspect Runtime Scope ${configDir}: ${existing.error ?? 'PID file could not be read'}.\n` +
|
|
136
|
+
`Refusing to start a second runtime until the PID file problem is fixed.\n`);
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Resolve the effective log file, defaulting to <configDir>/logs/server.log.
|
|
141
|
+
// Only `resolved.file` is consumed here — the detached child re-resolves its
|
|
142
|
+
// own level on the normal serve path, so no env tier is needed (and reading
|
|
143
|
+
// process.env directly would bypass the yargs-based ONE_MCP_* loading).
|
|
144
|
+
const { resolved } = resolveLoggingConfig({
|
|
145
|
+
cli: { level: parsedArgv['log-level'], file: parsedArgv['log-file'] },
|
|
146
|
+
structured: appConfig.logging,
|
|
147
|
+
flat: { level: appConfig.logLevel, file: appConfig.logFile },
|
|
148
|
+
});
|
|
149
|
+
const logFile = resolved.file ?? defaultBackgroundLogFile(configDir);
|
|
150
|
+
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
|
151
|
+
// Build the detached child invocation.
|
|
152
|
+
const rawArgv = deps.rawArgv ?? normalizedArgv;
|
|
153
|
+
const childServeArgs = buildBackgroundChildArgs(stripServeToken(rawArgv), { logFile });
|
|
154
|
+
const { command, baseArgs } = resolveSelfInvocation();
|
|
155
|
+
const spawnArgs = [...baseArgs, 'serve', ...childServeArgs];
|
|
156
|
+
const spawnChild = deps.spawnChild ??
|
|
157
|
+
((cmd, args, options) => spawn(cmd, args, options));
|
|
158
|
+
const child = spawnChild(command, spawnArgs, { detached: true, stdio: 'ignore' });
|
|
159
|
+
if (!child.pid) {
|
|
160
|
+
process.stderr.write('Error: failed to spawn background runtime process.\n');
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Allow the parent to exit independently of the child.
|
|
165
|
+
child.unref();
|
|
166
|
+
// Acknowledge the spawn immediately so the wait is never silent.
|
|
167
|
+
process.stderr.write(`Starting background runtime (PID ${child.pid})…\n`);
|
|
168
|
+
process.stderr.write(`Log file: ${logFile}\n`);
|
|
169
|
+
let childExited = false;
|
|
170
|
+
child.once('exit', () => {
|
|
171
|
+
childExited = true;
|
|
172
|
+
});
|
|
173
|
+
const renderer = createProgressRenderer(logFile);
|
|
174
|
+
const waitForReady = deps.waitForReady ?? waitForBackgroundReady;
|
|
175
|
+
const result = await waitForReady(configDir, child.pid, {
|
|
176
|
+
isChildAlive: () => !childExited,
|
|
177
|
+
onProgress: renderer.render,
|
|
178
|
+
});
|
|
179
|
+
renderer.clear();
|
|
180
|
+
if (result.ready && result.info) {
|
|
181
|
+
// One final probe so the report can show how many servers are already up.
|
|
182
|
+
const summary = await probeLoadingSummary(result.info);
|
|
183
|
+
process.stdout.write(`Background runtime started.\n${formatStartedReport(result.info, { summary, asyncEnabled })}`);
|
|
184
|
+
process.exitCode = 0;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// Failure: report log path, terminate the child, exit non-zero.
|
|
188
|
+
process.stderr.write(`Error: background runtime did not become ready (${result.reason ?? 'unknown error'}).\n` +
|
|
189
|
+
`See the log for details: ${logFile}\n`);
|
|
190
|
+
const killChild = deps.killChild ?? defaultKillChild;
|
|
191
|
+
if (!childExited && child.pid) {
|
|
192
|
+
killChild(child.pid);
|
|
193
|
+
}
|
|
194
|
+
process.exitCode = 1;
|
|
195
|
+
}
|
|
196
|
+
function defaultKillChild(pid) {
|
|
197
|
+
try {
|
|
198
|
+
process.kill(pid, 'SIGTERM');
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
logger.warn(`Failed to terminate background child (PID: ${pid}): ${error}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function formatStartedReport(info, opts = {}) {
|
|
205
|
+
let report = `PID: ${info.pid}\n` + `URL: ${info.url}\n` + `Log file: ${info.logFile ?? '(console only)'}\n`;
|
|
206
|
+
if (opts.summary) {
|
|
207
|
+
report += `Servers: ${opts.summary.ready}/${opts.summary.total} ready\n`;
|
|
208
|
+
}
|
|
209
|
+
// In the default sync mode the wait is bounded by upstream connection time;
|
|
210
|
+
// point users at the fast-detach path. Omitted when async is already on, or
|
|
211
|
+
// when the caller does not supply the flag (e.g. the idempotency report).
|
|
212
|
+
if (opts.asyncEnabled === false) {
|
|
213
|
+
report += `Tip: run with --enable-async-loading for near-instant background detach.\n`;
|
|
214
|
+
}
|
|
215
|
+
return report;
|
|
216
|
+
}
|
|
217
|
+
/** Truncate a single line so progress output stays on one terminal row. */
|
|
218
|
+
function truncate(text, max) {
|
|
219
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
220
|
+
}
|
|
221
|
+
/** Best-effort read of the last non-empty line of a (possibly absent) log file. */
|
|
222
|
+
function tailLastLine(filePath) {
|
|
223
|
+
try {
|
|
224
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
225
|
+
const lines = content.split('\n');
|
|
226
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
227
|
+
const trimmed = lines[i].trim();
|
|
228
|
+
if (trimmed.length > 0) {
|
|
229
|
+
return trimmed;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return '';
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return '';
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Build a stderr progress renderer for the background wait. Throttles to ~1s and
|
|
240
|
+
* uses an in-place line on a TTY, plain lines otherwise. Two phases:
|
|
241
|
+
* - before the PID file appears (sync mode's blocking window): elapsed time plus
|
|
242
|
+
* the latest child log line;
|
|
243
|
+
* - once the runtime is up: aggregate `/health/mcp` loading counts.
|
|
244
|
+
*/
|
|
245
|
+
function createProgressRenderer(logFile) {
|
|
246
|
+
const isTty = Boolean(process.stderr.isTTY);
|
|
247
|
+
let lastRenderMs = -1;
|
|
248
|
+
let lastSummary = null;
|
|
249
|
+
let summaryProbeInFlight = false;
|
|
250
|
+
let lineActive = false;
|
|
251
|
+
const render = (progress) => {
|
|
252
|
+
// Throttle to roughly one update per second; always render the first tick.
|
|
253
|
+
if (progress.elapsedMs !== 0 && progress.elapsedMs - lastRenderMs < 900) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
lastRenderMs = progress.elapsedMs;
|
|
257
|
+
const seconds = Math.floor(progress.elapsedMs / 1000);
|
|
258
|
+
// Refresh the loading summary out of band so rendering stays synchronous.
|
|
259
|
+
if (progress.info && !summaryProbeInFlight) {
|
|
260
|
+
summaryProbeInFlight = true;
|
|
261
|
+
void probeLoadingSummary(progress.info)
|
|
262
|
+
.then((summary) => {
|
|
263
|
+
lastSummary = summary;
|
|
264
|
+
})
|
|
265
|
+
.catch(() => { })
|
|
266
|
+
.finally(() => {
|
|
267
|
+
summaryProbeInFlight = false;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
let detail;
|
|
271
|
+
if (progress.info && lastSummary) {
|
|
272
|
+
const s = lastSummary;
|
|
273
|
+
detail = `${s.ready}/${s.total} servers ready (${s.loading} loading, ${s.failed} failed)`;
|
|
274
|
+
}
|
|
275
|
+
else if (progress.info) {
|
|
276
|
+
detail = 'runtime starting…';
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
const lastLogLine = tailLastLine(logFile);
|
|
280
|
+
detail = lastLogLine ? truncate(lastLogLine, 100) : 'waiting for runtime to start…';
|
|
281
|
+
}
|
|
282
|
+
const line = `[${seconds}s] ${detail}`;
|
|
283
|
+
if (isTty) {
|
|
284
|
+
process.stderr.write(`\x1b[2K\r${line}`);
|
|
285
|
+
lineActive = true;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
process.stderr.write(`${line}\n`);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const clear = () => {
|
|
292
|
+
if (isTty && lineActive) {
|
|
293
|
+
process.stderr.write('\x1b[2K\r');
|
|
294
|
+
lineActive = false;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
return { render, clear };
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=serveBackground.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveBackground.js","sourceRoot":"","sources":["../../../src/commands/serve/serveBackground.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAiB,MAAM,oCAAoC,CAAC;AAChF,OAAO,EACL,qBAAqB,EAErB,mBAAmB,EACnB,cAAc,GAEf,MAAM,sCAAsC,CAAC;AAC9C,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAE5D,yEAAyE;AACzE,MAAM,UAAU,wBAAwB,CAAC,SAAiB;IACxD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAmB,EAAE,IAAyB;IACrF,MAAM,cAAc,GAAG,IAA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IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;YACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAClC,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ServeOptions } from './serve.js';
|
|
2
|
+
import { runServeBackground } from './serveBackground.js';
|
|
3
|
+
import { runServeStop } from './serveStop.js';
|
|
4
|
+
/**
|
|
5
|
+
* `serve --restart`: stop the runtime in the selected Runtime Scope (if any),
|
|
6
|
+
* then start a fresh detached background runtime.
|
|
7
|
+
*
|
|
8
|
+
* Semantics mirror `systemctl restart`: when nothing is running the stop is a
|
|
9
|
+
* clean no-op and a background runtime is still started, so a successful restart
|
|
10
|
+
* always ends in a running runtime. This is a thin composition of the existing
|
|
11
|
+
* `--stop` and `--background` handlers; staleness handling, signal escalation,
|
|
12
|
+
* detached spawn, readiness wait, and idempotency all come from them unchanged.
|
|
13
|
+
*
|
|
14
|
+
* Both handlers communicate via `process.exitCode` (the established lifecycle
|
|
15
|
+
* pattern), so this routine inspects it between the two phases: if the stop
|
|
16
|
+
* genuinely failed (runtime still alive after SIGKILL) it aborts before starting
|
|
17
|
+
* to avoid two runtimes contending for the same scope/port.
|
|
18
|
+
*/
|
|
19
|
+
export interface RunRestartDeps {
|
|
20
|
+
runStop?: typeof runServeStop;
|
|
21
|
+
runBackground?: typeof runServeBackground;
|
|
22
|
+
}
|
|
23
|
+
export declare function runServeRestart(parsedArgv: ServeOptions, deps?: RunRestartDeps): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=serveRestart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveRestart.d.ts","sourceRoot":"","sources":["../../../src/commands/serve/serveRestart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,OAAO,YAAY,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,kBAAkB,CAAC;CAC3C;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBxG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { resolveServeConfigPaths } from './runtimeScope.js';
|
|
2
|
+
import { runServeBackground } from './serveBackground.js';
|
|
3
|
+
import { runServeStop } from './serveStop.js';
|
|
4
|
+
export async function runServeRestart(parsedArgv, deps = {}) {
|
|
5
|
+
const runStop = deps.runStop ?? runServeStop;
|
|
6
|
+
const runBackground = deps.runBackground ?? runServeBackground;
|
|
7
|
+
const { runtimeScope } = resolveServeConfigPaths(parsedArgv);
|
|
8
|
+
process.stderr.write('Restarting background runtime…\n');
|
|
9
|
+
// Phase 1: stop. A "nothing running" or stale-PID scope exits 0 here.
|
|
10
|
+
process.exitCode = undefined;
|
|
11
|
+
await runStop(runtimeScope);
|
|
12
|
+
if (process.exitCode) {
|
|
13
|
+
process.stderr.write('Error: restart aborted; could not stop the existing runtime. See messages above.\n');
|
|
14
|
+
// Leave the non-zero exit code from the stop phase in place.
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Phase 2: start a fresh detached background runtime. The stop cleaned up the
|
|
18
|
+
// PID file, so the background idempotency probe sees an empty scope.
|
|
19
|
+
process.exitCode = undefined;
|
|
20
|
+
await runBackground(parsedArgv);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=serveRestart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveRestart.js","sourceRoot":"","sources":["../../../src/commands/serve/serveRestart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAuB9C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAAwB,EAAE,OAAuB,EAAE;IACvF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,YAAY,CAAC;IAC7C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,kBAAkB,CAAC;IAC/D,MAAM,EAAE,YAAY,EAAE,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAEzD,sEAAsE;IACtE,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC7B,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oFAAoF,CAAC,CAAC;QAC3G,6DAA6D;QAC7D,OAAO;IACT,CAAC;IAED,8EAA8E;IAC9E,qEAAqE;IACrE,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC7B,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ServerPidInfo } from '../../core/server/pidFileManager.js';
|
|
2
|
+
import { RuntimeStatus } from '../../core/server/runtimeLifecycle.js';
|
|
3
|
+
/**
|
|
4
|
+
* `serve --status`: report the state of the Background Aggregated Runtime in the
|
|
5
|
+
* selected Runtime Scope. Discovery goes through the lifecycle module, so the
|
|
6
|
+
* same two-tier staleness rule applies — a dead PID file is cleaned up and the
|
|
7
|
+
* scope is reported not-running.
|
|
8
|
+
*/
|
|
9
|
+
export interface RuntimeStatusReport {
|
|
10
|
+
status: RuntimeStatus;
|
|
11
|
+
/** The Runtime Scope (resolved configuration directory). */
|
|
12
|
+
configDir: string;
|
|
13
|
+
/** PID record for `running`/`unreachable`; null for `not-running`/`error`. */
|
|
14
|
+
info: ServerPidInfo | null;
|
|
15
|
+
/** Human-readable discovery failure for `error` reports. */
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Process exit codes per runtime state, so scripts can branch on `serve --status`:
|
|
20
|
+
* - running (alive and ready) → 0
|
|
21
|
+
* - not-running (empty scope or stale dead PID) → 3
|
|
22
|
+
* - unreachable (alive but `/health/ready` failing) → 4
|
|
23
|
+
*/
|
|
24
|
+
export declare const STATUS_EXIT_CODES: Record<RuntimeStatus, number>;
|
|
25
|
+
/**
|
|
26
|
+
* Discover the scoped runtime and assemble a status report. The default
|
|
27
|
+
* readiness probe (`/health/ready`) distinguishes alive-but-not-ready from
|
|
28
|
+
* alive-and-ready.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getRuntimeStatusReport(configDirOption?: string): Promise<RuntimeStatusReport>;
|
|
31
|
+
/**
|
|
32
|
+
* Render a status report as human-readable lines.
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatRuntimeStatusReport(report: RuntimeStatusReport): string;
|
|
35
|
+
/**
|
|
36
|
+
* Entry point for `serve --status`: discover, print, and set the exit code.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runServeStatus(configDirOption?: string): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=serveStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveStatus.d.ts","sourceRoot":"","sources":["../../../src/commands/serve/serveStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAyB,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE5F;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IAC3B,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAK3D,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAInG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAuB7E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getConfigDir } from '../../constants.js';
|
|
2
|
+
import { discoverScopedRuntime } from '../../core/server/runtimeLifecycle.js';
|
|
3
|
+
/**
|
|
4
|
+
* Process exit codes per runtime state, so scripts can branch on `serve --status`:
|
|
5
|
+
* - running (alive and ready) → 0
|
|
6
|
+
* - not-running (empty scope or stale dead PID) → 3
|
|
7
|
+
* - unreachable (alive but `/health/ready` failing) → 4
|
|
8
|
+
*/
|
|
9
|
+
export const STATUS_EXIT_CODES = {
|
|
10
|
+
running: 0,
|
|
11
|
+
'not-running': 3,
|
|
12
|
+
unreachable: 4,
|
|
13
|
+
error: 2,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Discover the scoped runtime and assemble a status report. The default
|
|
17
|
+
* readiness probe (`/health/ready`) distinguishes alive-but-not-ready from
|
|
18
|
+
* alive-and-ready.
|
|
19
|
+
*/
|
|
20
|
+
export async function getRuntimeStatusReport(configDirOption) {
|
|
21
|
+
const configDir = getConfigDir(configDirOption);
|
|
22
|
+
const { status, info, error } = await discoverScopedRuntime(configDir);
|
|
23
|
+
return { status, configDir, info, error };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Render a status report as human-readable lines.
|
|
27
|
+
*/
|
|
28
|
+
export function formatRuntimeStatusReport(report) {
|
|
29
|
+
const { status, configDir, info } = report;
|
|
30
|
+
const lines = [`Runtime Scope: ${configDir}`];
|
|
31
|
+
if (status === 'not-running' || !info) {
|
|
32
|
+
if (status === 'error') {
|
|
33
|
+
lines.push('Status: error');
|
|
34
|
+
lines.push(`Error: ${report.error ?? 'PID file could not be read'}`);
|
|
35
|
+
return `${lines.join('\n')}\n`;
|
|
36
|
+
}
|
|
37
|
+
lines.push('Status: not running');
|
|
38
|
+
return `${lines.join('\n')}\n`;
|
|
39
|
+
}
|
|
40
|
+
const ready = status === 'running';
|
|
41
|
+
lines.push(`Status: ${ready ? 'running (ready)' : 'starting (not ready)'}`);
|
|
42
|
+
lines.push(`PID: ${info.pid}`);
|
|
43
|
+
lines.push(`URL: ${info.url}`);
|
|
44
|
+
lines.push(`Started: ${info.startedAt}`);
|
|
45
|
+
lines.push(`Log file: ${info.logFile ?? '(console only)'}`);
|
|
46
|
+
lines.push('Process: alive');
|
|
47
|
+
lines.push(`Readiness (/health/ready): ${ready ? 'ready' : 'not ready'}`);
|
|
48
|
+
return `${lines.join('\n')}\n`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Entry point for `serve --status`: discover, print, and set the exit code.
|
|
52
|
+
*/
|
|
53
|
+
export async function runServeStatus(configDirOption) {
|
|
54
|
+
const report = await getRuntimeStatusReport(configDirOption);
|
|
55
|
+
process.stdout.write(formatRuntimeStatusReport(report));
|
|
56
|
+
process.exitCode = STATUS_EXIT_CODES[report.status];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=serveStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveStatus.js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AC,IAAI,CAAC;IACjC,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,KAAK,SAAS,CAAC;IACnC,KAAK,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,sBAAsB,EAAE,CAAC,CAAC;IAC5E,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACzC,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,OAAO,IAAI,gBAAgB,EAAE,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC7B,KAAK,CAAC,IAAI,CAAC,8BAA8B,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1E,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,eAAwB;IAC3D,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,eAAe,CAAC,CAAC;IAC7D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readPidFile } from '../../core/server/pidFileManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* `serve --stop`: stop only the runtime in the selected Runtime Scope.
|
|
4
|
+
*
|
|
5
|
+
* Discovery uses the pure PID reader plus a liveness check (not the readiness
|
|
6
|
+
* probe — stopping should work even for an alive-but-not-ready runtime). The
|
|
7
|
+
* signal targets exactly the PID recorded for this scope, so runtimes in other
|
|
8
|
+
* config directories are never affected.
|
|
9
|
+
*/
|
|
10
|
+
export interface WaitForExitOptions {
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
intervalMs?: number;
|
|
13
|
+
isAlive?: (pid: number) => boolean;
|
|
14
|
+
now?: () => number;
|
|
15
|
+
sleep?: (ms: number) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** Poll until the process is gone or the timeout elapses. Returns true if it exited. */
|
|
18
|
+
export declare function waitForProcessExit(pid: number, options?: WaitForExitOptions): Promise<boolean>;
|
|
19
|
+
/** Signals this command sends to a runtime process. */
|
|
20
|
+
type StopSignal = 'SIGTERM' | 'SIGKILL';
|
|
21
|
+
export interface RunStopDeps {
|
|
22
|
+
readInfo?: typeof readPidFile;
|
|
23
|
+
isAlive?: (pid: number) => boolean;
|
|
24
|
+
kill?: (pid: number, signal: StopSignal) => void;
|
|
25
|
+
/** Delete the PID file only if it still records the stopped PID. */
|
|
26
|
+
cleanup?: (configDir: string, expectedPid: number) => boolean;
|
|
27
|
+
waitForExit?: typeof waitForProcessExit;
|
|
28
|
+
/** Graceful wait before escalating to SIGKILL. */
|
|
29
|
+
gracefulTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stop the scoped runtime. Sets `process.exitCode` and returns.
|
|
33
|
+
*/
|
|
34
|
+
export declare function runServeStop(configDirOption?: string, deps?: RunStopDeps): Promise<void>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=serveStop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveStop.d.ts","sourceRoot":"","sources":["../../../src/commands/serve/serveStop.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EACZ,MAAM,oCAAoC,CAAC;AAG5C;;;;;;;GAOG;AAEH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,wFAAwF;AACxF,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAexG;AAED,uDAAuD;AACvD,KAAK,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,OAAO,WAAW,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACjD,oEAAoE;IACpE,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9D,WAAW,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACxC,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAMD;;GAEG;AACH,wBAAsB,YAAY,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyElG"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getConfigDir } from '../../constants.js';
|
|
2
|
+
import { cleanupPidFileIfMatches, isProcessAlive, PidFileReadError, readPidFile, } from '../../core/server/pidFileManager.js';
|
|
3
|
+
import logger from '../../logger/logger.js';
|
|
4
|
+
/** Poll until the process is gone or the timeout elapses. Returns true if it exited. */
|
|
5
|
+
export async function waitForProcessExit(pid, options = {}) {
|
|
6
|
+
const timeoutMs = options.timeoutMs ?? 10000;
|
|
7
|
+
const intervalMs = options.intervalMs ?? 200;
|
|
8
|
+
const isAlive = options.isAlive ?? isProcessAlive;
|
|
9
|
+
const now = options.now ?? (() => Date.now());
|
|
10
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
11
|
+
const start = now();
|
|
12
|
+
while (now() - start < timeoutMs) {
|
|
13
|
+
if (!isAlive(pid)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
await sleep(intervalMs);
|
|
17
|
+
}
|
|
18
|
+
return !isAlive(pid);
|
|
19
|
+
}
|
|
20
|
+
function defaultKill(pid, signal) {
|
|
21
|
+
process.kill(pid, signal);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Stop the scoped runtime. Sets `process.exitCode` and returns.
|
|
25
|
+
*/
|
|
26
|
+
export async function runServeStop(configDirOption, deps = {}) {
|
|
27
|
+
const configDir = getConfigDir(configDirOption);
|
|
28
|
+
const readInfo = deps.readInfo ?? readPidFile;
|
|
29
|
+
const isAlive = deps.isAlive ?? isProcessAlive;
|
|
30
|
+
const kill = deps.kill ?? defaultKill;
|
|
31
|
+
const cleanup = deps.cleanup ?? cleanupPidFileIfMatches;
|
|
32
|
+
const waitForExit = deps.waitForExit ?? waitForProcessExit;
|
|
33
|
+
const gracefulTimeoutMs = deps.gracefulTimeoutMs ?? 10000;
|
|
34
|
+
let info;
|
|
35
|
+
try {
|
|
36
|
+
info = readInfo(configDir);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof PidFileReadError) {
|
|
40
|
+
process.stderr.write(`Error: cannot inspect Runtime Scope ${configDir}: ${error.message}\n`);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
if (!info) {
|
|
47
|
+
process.stdout.write(`No runtime is running in this Runtime Scope: ${configDir}\n`);
|
|
48
|
+
process.exitCode = 0;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Stale dead-process PID file: clean it up and report cleanly.
|
|
52
|
+
if (!isAlive(info.pid)) {
|
|
53
|
+
if (cleanup(configDir, info.pid)) {
|
|
54
|
+
process.stdout.write(`No running runtime in this Runtime Scope; removed a stale PID file (was PID ${info.pid}).\n`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
process.stderr.write(`No running runtime in this Runtime Scope, but the stale PID file could not be removed ` +
|
|
58
|
+
`(${getConfigDir(configDirOption)}). Remove it manually.\n`);
|
|
59
|
+
}
|
|
60
|
+
process.exitCode = 0;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Graceful termination, then escalate to SIGKILL if it does not exit in time.
|
|
64
|
+
try {
|
|
65
|
+
kill(info.pid, 'SIGTERM');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger.warn(`Failed to send SIGTERM to PID ${info.pid}: ${error}`);
|
|
69
|
+
}
|
|
70
|
+
let exited = await waitForExit(info.pid, { timeoutMs: gracefulTimeoutMs, isAlive });
|
|
71
|
+
if (!exited) {
|
|
72
|
+
logger.warn(`Runtime (PID ${info.pid}) did not exit after SIGTERM; escalating to SIGKILL`);
|
|
73
|
+
try {
|
|
74
|
+
kill(info.pid, 'SIGKILL');
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
logger.warn(`Failed to send SIGKILL to PID ${info.pid}: ${error}`);
|
|
78
|
+
}
|
|
79
|
+
exited = await waitForExit(info.pid, { timeoutMs: 2000, isAlive });
|
|
80
|
+
}
|
|
81
|
+
if (exited) {
|
|
82
|
+
// The runtime removes its own PID file on graceful shutdown; clean up in
|
|
83
|
+
// case it was force-killed before it could. Match on PID so a runtime that
|
|
84
|
+
// restarted in this scope (rare, but possible) is not clobbered.
|
|
85
|
+
cleanup(configDir, info.pid);
|
|
86
|
+
process.stdout.write(`Stopped runtime in Runtime Scope ${configDir} (PID ${info.pid}).\n`);
|
|
87
|
+
process.exitCode = 0;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
process.stderr.write(`Error: failed to stop runtime (PID ${info.pid}) in Runtime Scope ${configDir}.\n`);
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=serveStop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveStop.js","sourceRoot":"","sources":["../../../src/commands/serve/serveStop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAmB3C,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAW,EAAE,UAA8B,EAAE;IACpF,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAEnG,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;IACpB,OAAO,GAAG,EAAE,GAAG,KA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IAAI,CAAC,iCAAiC,IAAI,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,yEAAyE;QACzE,2EAA2E;QAC3E,iEAAiE;QACjE,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,SAAS,SAAS,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QAC3F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,IAAI,CAAC,GAAG,sBAAsB,SAAS,KAAK,CAAC,CAAC;IACzG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
package/build/constants/mcp.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const MCP_CONFIG_FILE = "mcp.json";
|
|
|
6
6
|
export declare const APP_CONFIG_FILE = "config.toml";
|
|
7
7
|
export declare const MCP_INSTRUCTIONS_TEMPLATE_FILE = "instructions-template.md";
|
|
8
8
|
export declare const MCP_SERVER_NAME = "1mcp";
|
|
9
|
-
export declare const MCP_SERVER_VERSION = "0.
|
|
9
|
+
export declare const MCP_SERVER_VERSION = "0.34.0";
|
|
10
10
|
export declare const MCP_URI_SEPARATOR = "_1mcp_";
|
|
11
11
|
/**
|
|
12
12
|
* Default maximum number of MCP servers to load concurrently
|
package/build/constants/mcp.js
CHANGED
|
@@ -3,7 +3,7 @@ export const MCP_CONFIG_FILE = 'mcp.json';
|
|
|
3
3
|
export const APP_CONFIG_FILE = 'config.toml';
|
|
4
4
|
export const MCP_INSTRUCTIONS_TEMPLATE_FILE = 'instructions-template.md';
|
|
5
5
|
export const MCP_SERVER_NAME = '1mcp';
|
|
6
|
-
export const MCP_SERVER_VERSION = '0.
|
|
6
|
+
export const MCP_SERVER_VERSION = '0.34.0';
|
|
7
7
|
export const MCP_URI_SEPARATOR = '_1mcp_';
|
|
8
8
|
/**
|
|
9
9
|
* Default maximum number of MCP servers to load concurrently
|