@shardworks/nexus 0.1.270 → 0.1.272
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/README.md +15 -1
- package/dist/commands/clock.d.ts +225 -0
- package/dist/commands/clock.d.ts.map +1 -0
- package/dist/commands/clock.js +652 -0
- package/dist/commands/clock.js.map +1 -0
- package/dist/commands/index.d.ts +14 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +18 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/signal.d.ts +41 -0
- package/dist/commands/signal.d.ts.map +1 -0
- package/dist/commands/signal.js +85 -0
- package/dist/commands/signal.js.map +1 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +59 -40
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/stop.d.ts.map +1 -1
- package/dist/commands/stop.js +1 -41
- package/dist/commands/stop.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +17 -2
- package/dist/program.js.map +1 -1
- package/dist/started-guild.d.ts +41 -0
- package/dist/started-guild.d.ts.map +1 -0
- package/dist/started-guild.js +47 -0
- package/dist/started-guild.js.map +1 -0
- package/package.json +5 -4
package/dist/commands/index.d.ts
CHANGED
|
@@ -8,7 +8,21 @@
|
|
|
8
8
|
* Plugin-contributed tools are discovered at runtime via The Instrumentarium
|
|
9
9
|
* when a guild is present and the tools apparatus is installed.
|
|
10
10
|
*/
|
|
11
|
+
import type { Command } from 'commander';
|
|
11
12
|
import type { ToolDefinition } from '@shardworks/tools-apparatus';
|
|
12
13
|
/** All framework commands, typed as the base ToolDefinition for uniform handling. */
|
|
13
14
|
export declare const frameworkCommands: ToolDefinition[];
|
|
15
|
+
/**
|
|
16
|
+
* Hand-written Commander commands that bypass the tool auto-builder.
|
|
17
|
+
*
|
|
18
|
+
* These exist for commands whose CLI shape (positional arguments,
|
|
19
|
+
* locally-parsed flag values, custom emitter defaults, …) does not fit
|
|
20
|
+
* the Zod-driven option generator in `program.ts`. Each entry is a
|
|
21
|
+
* factory that returns a fully-configured Command — the CLI registers
|
|
22
|
+
* them alongside the auto-built framework and plugin commands.
|
|
23
|
+
*
|
|
24
|
+
* Currently: `nsg signal`, `nsg clock` (see those files for the
|
|
25
|
+
* rationale on each).
|
|
26
|
+
*/
|
|
27
|
+
export declare const customFrameworkCommands: Array<() => Command>;
|
|
14
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAWlE,qFAAqF;AACrF,eAAO,MAAM,iBAAiB,EAWzB,cAAc,EAAE,CAAC;AAEtB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,MAAM,OAAO,CAGxD,CAAC"}
|
package/dist/commands/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import upgrade from "./upgrade.js";
|
|
|
15
15
|
import start from "./start.js";
|
|
16
16
|
import stop from "./stop.js";
|
|
17
17
|
import { pluginList, pluginInstall, pluginRemove, pluginUpgrade } from "./plugin.js";
|
|
18
|
+
import { buildSignalCommand } from "./signal.js";
|
|
19
|
+
import { buildClockCommand } from "./clock.js";
|
|
18
20
|
/** All framework commands, typed as the base ToolDefinition for uniform handling. */
|
|
19
21
|
export const frameworkCommands = [
|
|
20
22
|
init,
|
|
@@ -28,4 +30,20 @@ export const frameworkCommands = [
|
|
|
28
30
|
pluginRemove,
|
|
29
31
|
pluginUpgrade,
|
|
30
32
|
];
|
|
33
|
+
/**
|
|
34
|
+
* Hand-written Commander commands that bypass the tool auto-builder.
|
|
35
|
+
*
|
|
36
|
+
* These exist for commands whose CLI shape (positional arguments,
|
|
37
|
+
* locally-parsed flag values, custom emitter defaults, …) does not fit
|
|
38
|
+
* the Zod-driven option generator in `program.ts`. Each entry is a
|
|
39
|
+
* factory that returns a fully-configured Command — the CLI registers
|
|
40
|
+
* them alongside the auto-built framework and plugin commands.
|
|
41
|
+
*
|
|
42
|
+
* Currently: `nsg signal`, `nsg clock` (see those files for the
|
|
43
|
+
* rationale on each).
|
|
44
|
+
*/
|
|
45
|
+
export const customFrameworkCommands = [
|
|
46
|
+
buildSignalCommand,
|
|
47
|
+
buildClockCommand,
|
|
48
|
+
];
|
|
31
49
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,qFAAqF;AACrF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,OAAO;IACP,MAAM;IACN,OAAO;IACP,KAAK;IACL,IAAI;IACJ,UAAU;IACV,aAAa;IACb,YAAY;IACZ,aAAa;CACM,CAAC;AAEtB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAyB;IAC3D,kBAAkB;IAClB,iBAAiB;CAClB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nsg signal — operator-facing event emission.
|
|
3
|
+
*
|
|
4
|
+
* The patron-facing counterpart to the anima-only `signal` tool exposed
|
|
5
|
+
* by the Clockworks. Both surfaces resolve the running guild's
|
|
6
|
+
* Clockworks apparatus and call `ClockworksApi.validateSignal(name)`
|
|
7
|
+
* before emitting — there is one canonical validator path, owned by
|
|
8
|
+
* the apparatus closure.
|
|
9
|
+
*
|
|
10
|
+
* Why hand-written instead of going through the auto-builder?
|
|
11
|
+
*
|
|
12
|
+
* - The Commander auto-builder cannot JSON-parse a `--payload <json>`
|
|
13
|
+
* flag — that parsing happens here, locally, before the call into
|
|
14
|
+
* `ClockworksApi.emit`.
|
|
15
|
+
* - The auto-builder's positional convention only promotes `id`/`*Id`
|
|
16
|
+
* params; this command needs `<name>` as a positional argument.
|
|
17
|
+
* - The emitter is hardcoded to `'operator'` — not the `'anima'`
|
|
18
|
+
* default the tool uses.
|
|
19
|
+
*
|
|
20
|
+
* The CLI deliberately does not depend on the clockworks plugin
|
|
21
|
+
* package; the minimum interface is declared inline and resolved at
|
|
22
|
+
* runtime via `guild().apparatus<T>(name)`. This matches the same
|
|
23
|
+
* lazy-resolution pattern other CLI commands use (see `start.ts`).
|
|
24
|
+
*/
|
|
25
|
+
import { Command } from 'commander';
|
|
26
|
+
export interface SignalHandlerInput {
|
|
27
|
+
name: string;
|
|
28
|
+
/** Raw JSON string from `--payload`, or undefined if the flag was omitted. */
|
|
29
|
+
payloadJson?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function runSignal(input: SignalHandlerInput): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Build the `nsg signal` Commander Command.
|
|
34
|
+
*
|
|
35
|
+
* Hand-written rather than auto-generated so the event name can live in
|
|
36
|
+
* the positional slot and `--payload` can be JSON-parsed locally. The
|
|
37
|
+
* action handler mirrors the auto-builder's contract: thrown errors
|
|
38
|
+
* print as `Error: <message>` and exit with a non-zero code.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildSignalCommand(): Command;
|
|
41
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/commands/signal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgC1E;AAID;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAoB5C"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nsg signal — operator-facing event emission.
|
|
3
|
+
*
|
|
4
|
+
* The patron-facing counterpart to the anima-only `signal` tool exposed
|
|
5
|
+
* by the Clockworks. Both surfaces resolve the running guild's
|
|
6
|
+
* Clockworks apparatus and call `ClockworksApi.validateSignal(name)`
|
|
7
|
+
* before emitting — there is one canonical validator path, owned by
|
|
8
|
+
* the apparatus closure.
|
|
9
|
+
*
|
|
10
|
+
* Why hand-written instead of going through the auto-builder?
|
|
11
|
+
*
|
|
12
|
+
* - The Commander auto-builder cannot JSON-parse a `--payload <json>`
|
|
13
|
+
* flag — that parsing happens here, locally, before the call into
|
|
14
|
+
* `ClockworksApi.emit`.
|
|
15
|
+
* - The auto-builder's positional convention only promotes `id`/`*Id`
|
|
16
|
+
* params; this command needs `<name>` as a positional argument.
|
|
17
|
+
* - The emitter is hardcoded to `'operator'` — not the `'anima'`
|
|
18
|
+
* default the tool uses.
|
|
19
|
+
*
|
|
20
|
+
* The CLI deliberately does not depend on the clockworks plugin
|
|
21
|
+
* package; the minimum interface is declared inline and resolved at
|
|
22
|
+
* runtime via `guild().apparatus<T>(name)`. This matches the same
|
|
23
|
+
* lazy-resolution pattern other CLI commands use (see `start.ts`).
|
|
24
|
+
*/
|
|
25
|
+
import { Command } from 'commander';
|
|
26
|
+
import { guild } from '@shardworks/nexus-core';
|
|
27
|
+
export async function runSignal(input) {
|
|
28
|
+
let g;
|
|
29
|
+
try {
|
|
30
|
+
g = guild();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new Error('Not inside a guild. Run `nsg init` to create one first.');
|
|
34
|
+
}
|
|
35
|
+
// Parse the payload locally — Commander hands us a string, but the
|
|
36
|
+
// emit API expects the parsed value. Surfacing JSON parse failures
|
|
37
|
+
// here keeps them attached to the --payload flag rather than the
|
|
38
|
+
// (otherwise opaque) Clockworks emit error.
|
|
39
|
+
let parsedPayload = undefined;
|
|
40
|
+
if (input.payloadJson !== undefined) {
|
|
41
|
+
try {
|
|
42
|
+
parsedPayload = JSON.parse(input.payloadJson);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
46
|
+
throw new Error(`signal: --payload is not valid JSON: ${reason}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Resolve the apparatus once per call. Both the validator-rejection
|
|
50
|
+
// path and the apparatus-not-installed path surface as `Error:
|
|
51
|
+
// <message>` through the Commander action handler — the validator
|
|
52
|
+
// throws with the `signal:` prefix, the not-installed throw uses
|
|
53
|
+
// the framework's apparatus-resolution message verbatim.
|
|
54
|
+
const clockworks = g.apparatus('clockworks');
|
|
55
|
+
clockworks.validateSignal(input.name);
|
|
56
|
+
return clockworks.emit(input.name, parsedPayload, 'operator');
|
|
57
|
+
}
|
|
58
|
+
// ── Commander Command ────────────────────────────────────────────────
|
|
59
|
+
/**
|
|
60
|
+
* Build the `nsg signal` Commander Command.
|
|
61
|
+
*
|
|
62
|
+
* Hand-written rather than auto-generated so the event name can live in
|
|
63
|
+
* the positional slot and `--payload` can be JSON-parsed locally. The
|
|
64
|
+
* action handler mirrors the auto-builder's contract: thrown errors
|
|
65
|
+
* print as `Error: <message>` and exit with a non-zero code.
|
|
66
|
+
*/
|
|
67
|
+
export function buildSignalCommand() {
|
|
68
|
+
const cmd = new Command('signal')
|
|
69
|
+
.description('Emit a custom event into the Clockworks events book')
|
|
70
|
+
.argument('<name>', 'Event name (must be declared under clockworks.events)')
|
|
71
|
+
.option('--payload <json>', 'JSON-serializable payload (parsed locally before emission). Omit for null.')
|
|
72
|
+
.action(async (name, opts) => {
|
|
73
|
+
try {
|
|
74
|
+
const id = await runSignal({ name, payloadJson: opts.payload });
|
|
75
|
+
console.log(id);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
79
|
+
console.error(`Error: ${message}`);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return cmd;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/commands/signal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAwB/C,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAyB;IACvD,IAAI,CAAC,CAAC;IACN,IAAI,CAAC;QACH,CAAC,GAAG,KAAK,EAAE,CAAC;I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,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YAChE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,CAAC,KAAK,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;;;;AAwWxB,wBA4BG"}
|
package/dist/commands/start.js
CHANGED
|
@@ -24,7 +24,8 @@ import path from 'node:path';
|
|
|
24
24
|
import { spawn } from 'node:child_process';
|
|
25
25
|
import { z } from 'zod';
|
|
26
26
|
import { tool } from '@shardworks/tools-apparatus';
|
|
27
|
-
import { guild } from '@shardworks/nexus-core';
|
|
27
|
+
import { guild, isProcessAlive, readPidFile, tryUnlink, } from '@shardworks/nexus-core';
|
|
28
|
+
import { getStartedGuild } from "../started-guild.js";
|
|
28
29
|
// ── Filesystem layout helpers ────────────────────────────────────────
|
|
29
30
|
function paths(home) {
|
|
30
31
|
const nexusDir = path.join(home, '.nexus');
|
|
@@ -36,37 +37,6 @@ function paths(home) {
|
|
|
36
37
|
errLog: path.join(nexusDir, 'logs', 'daemon.err'),
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
|
-
function isProcessAlive(pid) {
|
|
40
|
-
try {
|
|
41
|
-
process.kill(pid, 0);
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
const code = err.code;
|
|
46
|
-
if (code === 'ESRCH')
|
|
47
|
-
return false;
|
|
48
|
-
// EPERM → exists but we can't signal it. Treat as alive.
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function readPidFile(pidFile) {
|
|
53
|
-
try {
|
|
54
|
-
const raw = fs.readFileSync(pidFile, 'utf-8').trim();
|
|
55
|
-
const pid = Number(raw);
|
|
56
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function tryUnlink(file) {
|
|
63
|
-
try {
|
|
64
|
-
fs.unlinkSync(file);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// ignore
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
40
|
function tailFile(file, lines) {
|
|
71
41
|
try {
|
|
72
42
|
const content = fs.readFileSync(file, 'utf-8');
|
|
@@ -211,12 +181,25 @@ async function startForeground(home) {
|
|
|
211
181
|
// Write the pidfile now that the servers are up.
|
|
212
182
|
fs.writeFileSync(p.pidFile, String(process.pid), 'utf-8');
|
|
213
183
|
// ── Shutdown wiring ────────────────────────────────────────────────
|
|
214
|
-
|
|
184
|
+
//
|
|
185
|
+
// Teardown order on SIGTERM/SIGINT:
|
|
186
|
+
// 1. Flip `spiderStop` so the crawl loop exits at its next yield.
|
|
187
|
+
// 2. Close the tool HTTP server (D7: the daemon owns this handle —
|
|
188
|
+
// it is returned by tools.startToolServer() rather than wired
|
|
189
|
+
// into the apparatus's stop()).
|
|
190
|
+
// 3. Call guildInstance.shutdown(), which fires guild:shutdown,
|
|
191
|
+
// walks the started apparatus list in reverse topological
|
|
192
|
+
// order calling each `stop()` — including Oculus's, so the
|
|
193
|
+
// explicit oculus.stopServer() call that used to live here is
|
|
194
|
+
// now redundant and removed.
|
|
195
|
+
// 4. Unlink the pidfile and process.exit(0).
|
|
196
|
+
//
|
|
197
|
+
// shutdown() is itself idempotent (D4), so the local "first signal
|
|
198
|
+
// wins" guard is no longer load-bearing for double-fire safety; we
|
|
199
|
+
// keep `spiderStop` local because the crawl loop reads it directly.
|
|
200
|
+
const startedGuild = getStartedGuild();
|
|
215
201
|
let spiderStop = false;
|
|
216
202
|
const shutdown = async (signal) => {
|
|
217
|
-
if (shuttingDown)
|
|
218
|
-
return;
|
|
219
|
-
shuttingDown = true;
|
|
220
203
|
console.log(`[daemon] ${signal} received — shutting down...`);
|
|
221
204
|
spiderStop = true;
|
|
222
205
|
try {
|
|
@@ -225,13 +208,29 @@ async function startForeground(home) {
|
|
|
225
208
|
catch (err) {
|
|
226
209
|
console.warn(`[daemon] tool server close failed: ${err instanceof Error ? err.message : err}`);
|
|
227
210
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
211
|
+
if (startedGuild) {
|
|
212
|
+
try {
|
|
213
|
+
await startedGuild.shutdown();
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
// shutdown() throws an aggregate when one or more apparatus
|
|
217
|
+
// stop()s fail. Surface it but still proceed with pidfile
|
|
218
|
+
// cleanup and process exit — partial teardown is better than
|
|
219
|
+
// a stuck process.
|
|
220
|
+
console.warn(`[daemon] guild shutdown reported failures: ${err instanceof Error ? err.message : err}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// No StartedGuild reference — program.ts never deposited one,
|
|
225
|
+
// which means createGuild() failed during startup. Nothing to
|
|
226
|
+
// tear down.
|
|
227
|
+
console.warn('[daemon] no StartedGuild reference — skipping apparatus stop() pass');
|
|
231
228
|
}
|
|
232
|
-
catch { /* not installed or already stopped */ }
|
|
233
229
|
tryUnlink(p.pidFile);
|
|
234
230
|
console.log('[daemon] stopped');
|
|
231
|
+
// D13: explicit exit. The crawl loop and other in-flight timers
|
|
232
|
+
// may keep the event loop alive even after apparatus stops; force
|
|
233
|
+
// exit to avoid hangs.
|
|
235
234
|
process.exit(0);
|
|
236
235
|
};
|
|
237
236
|
process.on('SIGTERM', () => { void shutdown('SIGTERM'); });
|
|
@@ -246,6 +245,20 @@ async function startForeground(home) {
|
|
|
246
245
|
//
|
|
247
246
|
// This is what keeps the daemon alive. If the Spider isn't installed,
|
|
248
247
|
// we still run a sleep loop so the tool/oculus servers stay up.
|
|
248
|
+
//
|
|
249
|
+
// Two loop-body cases:
|
|
250
|
+
//
|
|
251
|
+
// 1. Idle return (null). Spider had nothing dispatchable this tick —
|
|
252
|
+
// either the queue is empty, or every candidate was gated on
|
|
253
|
+
// non-terminal blockers. Sleep intervalMs before asking again.
|
|
254
|
+
//
|
|
255
|
+
// 2. Progress return (any non-null CrawlResult). Work happened this
|
|
256
|
+
// tick. Yield one macrotask via setImmediate so HTTP/timer
|
|
257
|
+
// handlers run between progress ticks (microtask-only awaits on
|
|
258
|
+
// steady work would otherwise starve them).
|
|
259
|
+
//
|
|
260
|
+
// Mirror of the fix in packages/plugins/spider/src/tools/crawl-continual.ts
|
|
261
|
+
// (both loops exist independently and must be kept in sync).
|
|
249
262
|
let spider = null;
|
|
250
263
|
let intervalMs = 5000;
|
|
251
264
|
try {
|
|
@@ -261,8 +274,14 @@ async function startForeground(home) {
|
|
|
261
274
|
try {
|
|
262
275
|
const result = await spider.crawl();
|
|
263
276
|
if (result === null) {
|
|
277
|
+
// Idle: nothing dispatchable this tick. Sleep the full interval.
|
|
264
278
|
await new Promise((r) => setTimeout(r, intervalMs));
|
|
265
279
|
}
|
|
280
|
+
else {
|
|
281
|
+
// Genuine progress: yield one macrotask so HTTP handlers and
|
|
282
|
+
// timers aren't starved by microtask-only awaits on steady work.
|
|
283
|
+
await new Promise((r) => setImmediate(r));
|
|
284
|
+
}
|
|
266
285
|
}
|
|
267
286
|
catch (err) {
|
|
268
287
|
console.error(`[daemon] crawl() error: ${err instanceof Error ? err.message : err}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EACL,KAAK,EACL,cAAc,EACd,WAAW,EACX,SAAS,GACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA2CtD,wEAAwE;AAExE,SAAS,KAAK,CAAC,IAAY;IAOzB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC3C,OAAO;QACL,QAAQ;QACR,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../src/commands/stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../src/commands/stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;;;;AAUxB,wBA0DG"}
|
package/dist/commands/stop.js
CHANGED
|
@@ -9,50 +9,10 @@
|
|
|
9
9
|
* they were spawned with `detached: true` and have their own lifecycle. Only
|
|
10
10
|
* the daemon process itself (tool server, oculus, spider crawl loop) stops.
|
|
11
11
|
*/
|
|
12
|
-
import fs from 'node:fs';
|
|
13
12
|
import path from 'node:path';
|
|
14
13
|
import { z } from 'zod';
|
|
15
14
|
import { tool } from '@shardworks/tools-apparatus';
|
|
16
|
-
import { guild } from '@shardworks/nexus-core';
|
|
17
|
-
function isProcessAlive(pid) {
|
|
18
|
-
try {
|
|
19
|
-
process.kill(pid, 0);
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
const code = err.code;
|
|
24
|
-
if (code === 'ESRCH')
|
|
25
|
-
return false;
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function readPidFile(pidFile) {
|
|
30
|
-
try {
|
|
31
|
-
const raw = fs.readFileSync(pidFile, 'utf-8').trim();
|
|
32
|
-
const pid = Number(raw);
|
|
33
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function tryUnlink(file) {
|
|
40
|
-
try {
|
|
41
|
-
fs.unlinkSync(file);
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// ignore
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async function waitForExit(pid, timeoutMs) {
|
|
48
|
-
const deadline = Date.now() + timeoutMs;
|
|
49
|
-
while (Date.now() < deadline) {
|
|
50
|
-
if (!isProcessAlive(pid))
|
|
51
|
-
return true;
|
|
52
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
15
|
+
import { guild, isProcessAlive, readPidFile, tryUnlink, waitForExit, } from '@shardworks/nexus-core';
|
|
56
16
|
export default tool({
|
|
57
17
|
name: 'stop',
|
|
58
18
|
description: 'Stop the guild daemon (graceful SIGTERM with SIGKILL escalation)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop.js","sourceRoot":"","sources":["../../src/commands/stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"stop.js","sourceRoot":"","sources":["../../src/commands/stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EACL,KAAK,EACL,cAAc,EACd,WAAW,EACX,SAAS,EACT,WAAW,GACZ,MAAM,wBAAwB,CAAC;AAEhC,eAAe,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,kEAAkE;IAC/E,UAAU,EAAE,CAAC,QAAQ,CAAC;IACtB,MAAM,EAAE;QACN,SAAS,EAAE,CAAC;aACT,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,wEAAwE,CAAC;KACtF;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,IAAI,IAAY,CAAC;QACjB,IAAI,CAAC;YACH,IAAI,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;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C,CAAC,CAAC;YAC1E,CAAC;YACD,OAAO,8BAA8B,GAAG,gCAAgC,SAAS,MAAM,CAAC;QAC1F,CAAC;QAED,SAAS,CAAC,OAAO,CAAC,CAAC;QACnB,OAAO,8BAA8B,GAAG,IAAI,CAAC;IAC/C,CAAC;CACF,CAAC,CAAC"}
|
package/dist/program.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,6BAA6B,CAAC;AAmDtF,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,GACtB,OAAO,CAwET;AA6CD,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA8E1C"}
|
package/dist/program.js
CHANGED
|
@@ -21,8 +21,9 @@ import { Command } from 'commander';
|
|
|
21
21
|
import { z } from 'zod';
|
|
22
22
|
import { findGuildRoot, guild } from '@shardworks/nexus-core';
|
|
23
23
|
import { createGuild } from '@shardworks/nexus-arbor';
|
|
24
|
-
import { frameworkCommands } from "./commands/index.js";
|
|
24
|
+
import { frameworkCommands, customFrameworkCommands } from "./commands/index.js";
|
|
25
25
|
import { toFlag, isBooleanSchema, isRepeatableSchema, findGroupPrefixes, coerceCliOpts, resolveGuildRoot } from "./helpers.js";
|
|
26
|
+
import { setStartedGuild } from "./started-guild.js";
|
|
26
27
|
/**
|
|
27
28
|
* Build a Commander command from a ToolDefinition.
|
|
28
29
|
*
|
|
@@ -189,13 +190,27 @@ export async function main() {
|
|
|
189
190
|
// Always register framework commands (init, status, version, upgrade,
|
|
190
191
|
// plugin management). These work with or without a guild.
|
|
191
192
|
registerTools(program, frameworkCommands);
|
|
193
|
+
// Register hand-written framework commands that bypass the
|
|
194
|
+
// tool→Commander auto-builder (e.g. `nsg signal`). Each factory
|
|
195
|
+
// returns a fully-configured Command. These are always available so
|
|
196
|
+
// their --help text is reachable even outside a guild; the handler
|
|
197
|
+
// itself errors out if a guild is required.
|
|
198
|
+
for (const buildCommand of customFrameworkCommands) {
|
|
199
|
+
program.addCommand(buildCommand());
|
|
200
|
+
}
|
|
192
201
|
// Load plugin-contributed tools when inside a guild.
|
|
193
202
|
// Tools are discovered via The Instrumentarium (tools apparatus).
|
|
194
203
|
// If the guild doesn't have the tools apparatus installed, no plugin
|
|
195
204
|
// tools are available — only framework commands.
|
|
196
205
|
if (home) {
|
|
197
206
|
try {
|
|
198
|
-
|
|
207
|
+
// Retain the StartedGuild so daemon handlers (nsg start
|
|
208
|
+
// --foreground, nsg clock start --foreground) can call
|
|
209
|
+
// `shutdown()` on SIGTERM/SIGINT. Plugin code only ever sees
|
|
210
|
+
// the narrower Guild via `guild()`; this is the bootstrap
|
|
211
|
+
// caller's reference. (D8: thread-from-program.)
|
|
212
|
+
const started = await createGuild(home);
|
|
213
|
+
setStartedGuild(started);
|
|
199
214
|
}
|
|
200
215
|
catch (err) {
|
|
201
216
|
const message = err instanceof Error ? err.message : String(err);
|
package/dist/program.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK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E,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;iBACrF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YAC5B,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,yDAAyD;YACzD,qCAAqC;QACvC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-internal carrier for the `StartedGuild` returned by
|
|
3
|
+
* `createGuild()`.
|
|
4
|
+
*
|
|
5
|
+
* The `Guild` accessor in `@shardworks/nexus-core` deliberately
|
|
6
|
+
* narrows away `shutdown()` because plugin code has no legitimate
|
|
7
|
+
* reason to tear down the guild it is running inside (commission
|
|
8
|
+
* decision D1). The bootstrap caller — `program.ts` — does have a
|
|
9
|
+
* reason: when a long-lived foreground command (the `nsg start`
|
|
10
|
+
* daemon, the Clockworks foreground daemon entry) finishes, the
|
|
11
|
+
* SIGTERM/SIGINT handler must invoke `shutdown()` on the way out so
|
|
12
|
+
* every apparatus's optional `stop()` runs and handles get released.
|
|
13
|
+
*
|
|
14
|
+
* The threading channel used to be implicit (handlers called
|
|
15
|
+
* `guild()` and trusted the singleton). With the lifecycle contract
|
|
16
|
+
* in place, the daemon handlers need the richer `StartedGuild` value;
|
|
17
|
+
* this module is where `program.ts` deposits it for those handlers to
|
|
18
|
+
* read without changing the `tool({ … })` factory's signature.
|
|
19
|
+
*
|
|
20
|
+
* Per D8 the threading is explicit: `program.ts` sets, the start
|
|
21
|
+
* tool's handler gets. There is no transparent fallback to the
|
|
22
|
+
* `guild()` singleton — if no one called `setStartedGuild()` the
|
|
23
|
+
* accessor returns `undefined` and the daemon decides what to do.
|
|
24
|
+
*/
|
|
25
|
+
import type { StartedGuild } from '@shardworks/nexus-core';
|
|
26
|
+
/** Record the `StartedGuild` returned by Arbor's `createGuild()`. */
|
|
27
|
+
export declare function setStartedGuild(g: StartedGuild): void;
|
|
28
|
+
/**
|
|
29
|
+
* Read the `StartedGuild` deposited by `program.ts`. Returns
|
|
30
|
+
* `undefined` when no guild has been started in this process —
|
|
31
|
+
* callers in daemon paths should treat that as a fail-loud
|
|
32
|
+
* misconfiguration.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getStartedGuild(): StartedGuild | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Clear the stored reference. Provided for test isolation; production
|
|
37
|
+
* code never calls this directly — `StartedGuild.shutdown()` is what
|
|
38
|
+
* tears the guild down, and the process exits shortly after.
|
|
39
|
+
*/
|
|
40
|
+
export declare function clearStartedGuild(): void;
|
|
41
|
+
//# sourceMappingURL=started-guild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"started-guild.d.ts","sourceRoot":"","sources":["../src/started-guild.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI3D,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,YAAY,GAAG,IAAI,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,SAAS,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|