@rubytech/create-maxy-code 0.1.330 → 0.1.332
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/dist/index.js +19 -2
- package/package.json +1 -1
- package/payload/platform/config/brand.json +1 -0
- package/payload/platform/lib/account-enumeration/dist/index.d.ts +33 -0
- package/payload/platform/lib/account-enumeration/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/account-enumeration/dist/index.js +76 -0
- package/payload/platform/lib/account-enumeration/dist/index.js.map +1 -1
- package/payload/platform/lib/account-enumeration/src/index.ts +78 -0
- package/payload/platform/lib/mcp-spawn-tee/dist/index.d.ts +24 -24
- package/payload/platform/lib/mcp-spawn-tee/dist/index.js +109 -75
- package/payload/platform/lib/mcp-spawn-tee/dist/index.js.map +1 -1
- package/payload/platform/lib/mcp-spawn-tee/src/__tests__/spawn-tee.test.ts +56 -19
- package/payload/platform/lib/mcp-spawn-tee/src/index.ts +112 -77
- package/payload/platform/neo4j/schema.cypher +58 -4
- package/payload/platform/plugins/admin/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/admin/PLUGIN.md +13 -1
- package/payload/platform/plugins/admin/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/admin/mcp/dist/index.js +102 -0
- package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.d.ts +2 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.d.ts.map +1 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.js +57 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.js.map +1 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.d.ts +34 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.d.ts.map +1 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.js +78 -0
- package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.js.map +1 -0
- package/payload/platform/plugins/admin/skills/plainly/SKILL.md +7 -0
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +2 -2
- package/payload/platform/plugins/aeo/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/browser/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/contacts/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/contacts/mcp/dist/index.js +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.d.ts +2 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.d.ts.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.js +71 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.js.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts +2 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js +112 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts +2 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js +102 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.d.ts +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.js +10 -3
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js +7 -2
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js +5 -4
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/package.json +4 -2
- package/payload/platform/plugins/docs/references/admin-ui.md +1 -1
- package/payload/platform/plugins/email/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/memory/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/memory/PLUGIN.md +1 -1
- package/payload/platform/plugins/memory/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/memory/mcp/dist/index.js +3 -1
- package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-lookup-by-name.test.js +39 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-lookup-by-name.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.js +13 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.js.map +1 -1
- package/payload/platform/plugins/memory/references/schema-estate-agent.md +17 -5
- package/payload/platform/plugins/outlook/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/replicate/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/scheduling/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/telegram/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/url-get/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/whatsapp/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/work/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/workflows/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/scripts/__tests__/provision-role-stamp.test.sh +40 -0
- package/payload/platform/scripts/__tests__/sweep-durability.test.sh +103 -0
- package/payload/platform/scripts/lib/provision-account-dir.sh +319 -0
- package/payload/platform/scripts/lib/resolve-account-dir.sh +79 -132
- package/payload/platform/scripts/seed-neo4j.sh +18 -0
- package/payload/platform/scripts/setup-account.sh +28 -361
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +4 -0
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/config.d.ts +18 -0
- package/payload/platform/services/claude-session-manager/dist/config.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/config.js +63 -7
- package/payload/platform/services/claude-session-manager/dist/config.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +30 -2
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +16 -1
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +7 -0
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts +5 -0
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.js +8 -0
- package/payload/platform/services/claude-session-manager/dist/session-sidecar.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/stuck-turn.d.ts +6 -0
- package/payload/platform/services/claude-session-manager/dist/stuck-turn.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/stuck-turn.js +17 -5
- package/payload/platform/services/claude-session-manager/dist/stuck-turn.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.d.ts.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.js +25 -1
- package/payload/platform/services/webchat-channel/dist/instructions.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/notification.d.ts +17 -0
- package/payload/platform/services/webchat-channel/dist/notification.d.ts.map +1 -1
- package/payload/platform/services/webchat-channel/dist/notification.js +14 -0
- package/payload/platform/services/webchat-channel/dist/notification.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/server.d.ts.map +1 -1
- package/payload/platform/services/webchat-channel/dist/server.js +66 -2
- package/payload/platform/services/webchat-channel/dist/server.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts +28 -0
- package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts.map +1 -0
- package/payload/platform/services/webchat-channel/dist/turn-follow.js +188 -0
- package/payload/platform/services/webchat-channel/dist/turn-follow.js.map +1 -0
- package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/notification.js +24 -1
- package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
- package/payload/platform/templates/account.json +2 -0
- package/payload/premium-plugins/writer-craft/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/server/public/assets/AdminLoginScreens-DexSvtjD.js +1 -0
- package/payload/server/public/assets/AdminShell-Bf9tndNg.js +1 -0
- package/payload/server/public/assets/{Checkbox-1flpB9H0.js → Checkbox-D58GsKoQ.js} +1 -1
- package/payload/server/public/assets/{OperatorConversations-DrPqB9Ym.css → OperatorConversations-CDdp2nVn.css} +1 -1
- package/payload/server/public/assets/OperatorConversations-RmqANYz8.js +9 -0
- package/payload/server/public/assets/{admin-BWJTvagN.js → admin-CH5Vkkt4.js} +1 -1
- package/payload/server/public/assets/{browser-XM5e-fn1.js → browser-BwDtzSlr.js} +1 -1
- package/payload/server/public/assets/chat-3GY0LmYH.js +1 -0
- package/payload/server/public/assets/data-CttrzhfL.js +1 -0
- package/payload/server/public/assets/{graph-CIIz9Dmh.js → graph-CZSdF2jv.js} +3 -3
- package/payload/server/public/assets/{graph-labels-BRKvhE0e.js → graph-labels-Bi0fu8Ns.js} +1 -1
- package/payload/server/public/assets/operator-BEivxmRy.js +1 -0
- package/payload/server/public/assets/page-DUvT07SB.js +30 -0
- package/payload/server/public/assets/{public-BPlZnopr.js → public-B3eIlVbd.js} +1 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/chat.html +5 -5
- package/payload/server/public/data.html +4 -4
- package/payload/server/public/graph.html +6 -6
- package/payload/server/public/index.html +6 -6
- package/payload/server/public/operator.html +7 -7
- package/payload/server/public/public.html +5 -5
- package/payload/server/server.js +605 -435
- package/payload/server/public/assets/AdminLoginScreens-BnuaXvxN.js +0 -1
- package/payload/server/public/assets/AdminShell-Br0DJQNu.js +0 -1
- package/payload/server/public/assets/OperatorConversations-C8sITz2_.js +0 -9
- package/payload/server/public/assets/chat-COFMxaoC.js +0 -1
- package/payload/server/public/assets/data-BHtJozT2.js +0 -1
- package/payload/server/public/assets/operator-9hbxrXKm.js +0 -1
- package/payload/server/public/assets/page-CXkBfOhG.js +0 -30
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/**
|
|
4
|
-
* MCP spawn-tee —
|
|
4
|
+
* MCP spawn-tee — in-process stderr capture + lifecycle observability.
|
|
5
5
|
*
|
|
6
6
|
* Claude Code spawns each MCP server itself; the platform never holds a
|
|
7
|
-
* ChildProcess handle. This
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* is
|
|
7
|
+
* ChildProcess handle. This shim sits between Claude Code and the real MCP
|
|
8
|
+
* server: Claude Code runs `node <this> <real-entry>`, and the shim runs the
|
|
9
|
+
* real entry IN ITS OWN PROCESS via dynamic import() — one node runtime, not
|
|
10
|
+
* two. Before importing, it replaces process.stderr.write with a tee so every
|
|
11
|
+
* stderr byte the server writes is mirrored to the log sinks; stdin and stdout
|
|
12
|
+
* (the JSON-RPC channel) are never touched.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Claude Code CLI → shim (this file) = node running <real-entry> in-process
|
|
15
|
+
* stdin/stdout : untouched (JSON-RPC channel)
|
|
16
|
+
* stderr : process.stderr.write teed → per-date + per-session + passthrough
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* child stdin/stdout : inherited (Claude Code pipe, untouched)
|
|
19
|
-
* child stderr : piped → per-date log + per-session log + passthrough
|
|
20
|
-
*
|
|
21
|
-
* Destinations (Task 706):
|
|
18
|
+
* Destinations (Task 706) — unchanged:
|
|
22
19
|
* - `${LOG_DIR}/mcp-<name>-stderr-<date>.log` — per-date raw (back-compat;
|
|
23
20
|
* the in-process mcp-stderr-tee and the [mcp-init-error] probe read it).
|
|
24
21
|
* - `${LOG_DIR}/mcp-<name>-<SESSION_ID>.log` — per-session raw + lifecycle
|
|
25
|
-
* lines
|
|
26
|
-
*
|
|
27
|
-
* (enumeration spawn) — then the per-date file is the fallback.
|
|
22
|
+
* lines. Authoritative sink. Absent when SESSION_ID is unset (enumeration
|
|
23
|
+
* spawn) — then the per-date file is the fallback.
|
|
28
24
|
* - `server.log` via the loopback log-ingest route — best-effort mirror of
|
|
29
|
-
* the [mcp-helper] lifecycle lines.
|
|
30
|
-
* the per-session file already holds the line (written synchronously).
|
|
25
|
+
* the [mcp-helper] lifecycle lines.
|
|
31
26
|
*
|
|
32
|
-
* Lifecycle lines, correlation key `session=<id8> server=<name
|
|
27
|
+
* Lifecycle lines, correlation key `session=<id8> server=<name>` — unchanged:
|
|
33
28
|
* [mcp-helper] op=spawn ... pid= entry=
|
|
34
29
|
* [mcp-helper] op=boot ... head=<first stderr bytes>
|
|
35
|
-
* [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
|
|
30
|
+
* [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
|
|
31
|
+
*
|
|
32
|
+
* Process model (Task 989): the shim IS the server's process. op=exit fires
|
|
33
|
+
* from process.on("exit"), so it covers a normal exit, a non-zero exit, an
|
|
34
|
+
* uncaught throw (code 1), and a catchable-signal exit (SIGTERM/SIGINT/SIGHUP,
|
|
35
|
+
* whose handlers record the signal name). An external SIGKILL is uncatchable
|
|
36
|
+
* and leaves no op=exit line — the per-session stderr tail already on disk and
|
|
37
|
+
* Claude Code's own transport-drop are the evidence for that death mode.
|
|
36
38
|
*
|
|
37
|
-
* The
|
|
38
|
-
* SIGTERM/SIGINT are forwarded to the child so a Claude Code shutdown does
|
|
39
|
-
* not orphan it; the child exit code/signal is propagated verbatim.
|
|
39
|
+
* The shim never writes to fd 1 (stdout) — that is the JSON-RPC channel.
|
|
40
40
|
*/
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
const node_child_process_1 = require("node:child_process");
|
|
43
42
|
const node_fs_1 = require("node:fs");
|
|
44
43
|
const node_path_1 = require("node:path");
|
|
44
|
+
const node_url_1 = require("node:url");
|
|
45
45
|
const SERVER_NAME = process.env.MCP_SPAWN_TEE_NAME ?? "unknown";
|
|
46
46
|
const LOG_DIR = process.env.LOG_DIR;
|
|
47
47
|
const SESSION_ID = process.env.SESSION_ID;
|
|
@@ -49,24 +49,37 @@ const PLATFORM_PORT = process.env.PLATFORM_PORT;
|
|
|
49
49
|
const ENTRY = process.argv[2];
|
|
50
50
|
const SESSION_ID8 = SESSION_ID ? SESSION_ID.slice(0, 8) : "—";
|
|
51
51
|
const spawnStamp = Date.now();
|
|
52
|
-
// Per-session raw + lifecycle log (Task 706).
|
|
53
|
-
//
|
|
52
|
+
// Per-session raw + lifecycle log (Task 706). Empty SESSION_ID (enumeration
|
|
53
|
+
// spawn) → undefined, and the per-date file is the fallback.
|
|
54
54
|
const perSessionPath = LOG_DIR && SESSION_ID
|
|
55
55
|
? (0, node_path_1.resolve)(LOG_DIR, `mcp-${SERVER_NAME}-${SESSION_ID}.log`)
|
|
56
56
|
: undefined;
|
|
57
57
|
const perDatePath = LOG_DIR
|
|
58
58
|
? (0, node_path_1.resolve)(LOG_DIR, `mcp-${SERVER_NAME}-stderr-${new Date(spawnStamp).toISOString().slice(0, 10)}.log`)
|
|
59
59
|
: undefined;
|
|
60
|
-
// Rolling tail of
|
|
60
|
+
// Rolling tail of entry stderr for op=exit. Capped so a chatty server cannot
|
|
61
61
|
// grow the buffer without bound.
|
|
62
62
|
const TAIL_CAP = 2048;
|
|
63
63
|
let stderrTail = "";
|
|
64
64
|
let bootEmitted = false;
|
|
65
|
+
let exitEmitted = false;
|
|
66
|
+
let exitSignal;
|
|
67
|
+
// The real stderr writer, captured before the tee replaces it. Lifecycle lines
|
|
68
|
+
// and stderr passthrough both go through this so they are never re-teed into
|
|
69
|
+
// the per-date sink nor recursed back into the patched writer.
|
|
70
|
+
const rawStderrWrite = process.stderr.write.bind(process.stderr);
|
|
71
|
+
// LOG_DIR is created once, lazily, on the first successful append — not per
|
|
72
|
+
// chunk. teeWrite runs on the server's own stderr hot path now, so a per-call
|
|
73
|
+
// mkdirSync would be two syscalls per log line for nothing.
|
|
74
|
+
let logDirReady = false;
|
|
65
75
|
function appendSafe(path, data) {
|
|
66
76
|
if (!path || !LOG_DIR)
|
|
67
77
|
return;
|
|
68
78
|
try {
|
|
69
|
-
(
|
|
79
|
+
if (!logDirReady) {
|
|
80
|
+
(0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
|
|
81
|
+
logDirReady = true;
|
|
82
|
+
}
|
|
70
83
|
(0, node_fs_1.appendFileSync)(path, data);
|
|
71
84
|
}
|
|
72
85
|
catch {
|
|
@@ -74,15 +87,16 @@ function appendSafe(path, data) {
|
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
// Best-effort mirror of a lifecycle line to server.log via the loopback
|
|
77
|
-
// log-ingest route. Fire-and-forget: the per-session file is authoritative,
|
|
78
|
-
//
|
|
90
|
+
// log-ingest route. Fire-and-forget: the per-session file is authoritative, so
|
|
91
|
+
// a dropped POST loses nothing. On the "exit" event the loop is stopping, so
|
|
92
|
+
// the op=exit mirror may not flush — the per-session line, written sync, holds.
|
|
79
93
|
function postToServerLog(suffix, level) {
|
|
80
94
|
if (!PLATFORM_PORT)
|
|
81
95
|
return;
|
|
82
96
|
try {
|
|
83
97
|
const ctrl = new AbortController();
|
|
84
98
|
const t = setTimeout(() => ctrl.abort(), 500);
|
|
85
|
-
t.unref?.(); // never let the abort timer keep the
|
|
99
|
+
t.unref?.(); // never let the abort timer keep the shim's event loop alive
|
|
86
100
|
void fetch(`http://127.0.0.1:${PLATFORM_PORT}/api/admin/log-ingest`, {
|
|
87
101
|
method: "POST",
|
|
88
102
|
headers: { "content-type": "application/json" },
|
|
@@ -95,14 +109,15 @@ function postToServerLog(suffix, level) {
|
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
// Emit one [mcp-helper] lifecycle line: authoritative per-session file (sync,
|
|
98
|
-
// survives process.exit), the
|
|
99
|
-
// visibility), and a best-effort server.log mirror.
|
|
100
|
-
// after the tag and carries no newline (the
|
|
112
|
+
// survives process.exit), the shim's own stderr via the RAW writer (journald /
|
|
113
|
+
// Claude Code visibility, never re-teed), and a best-effort server.log mirror.
|
|
114
|
+
// `suffix` is the line body after the tag and carries no newline (the
|
|
115
|
+
// log-ingest route rejects newlines).
|
|
101
116
|
function emitLifecycle(suffix, level) {
|
|
102
117
|
const line = `[mcp-helper] ${suffix}\n`;
|
|
103
118
|
appendSafe(perSessionPath, line);
|
|
104
119
|
try {
|
|
105
|
-
|
|
120
|
+
rawStderrWrite(line);
|
|
106
121
|
}
|
|
107
122
|
catch { /* stderr closed */ }
|
|
108
123
|
postToServerLog(suffix, level);
|
|
@@ -111,49 +126,68 @@ if (!ENTRY) {
|
|
|
111
126
|
emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason="no entry given (argv[2] missing)"`, "error");
|
|
112
127
|
process.exit(2);
|
|
113
128
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
// Replace process.stderr.write with a tee: mirror every server stderr byte to
|
|
130
|
+
// the per-date and per-session sinks, keep a rolling tail for op=exit, emit
|
|
131
|
+
// op=boot on the first bytes, then pass the write through to the real stderr.
|
|
132
|
+
const teeWrite = ((...args) => {
|
|
133
|
+
const chunk = args[0];
|
|
134
|
+
appendSafe(perDatePath, chunk); // per-date raw (back-compat)
|
|
135
|
+
appendSafe(perSessionPath, chunk); // per-session raw (Task 706)
|
|
136
|
+
const text = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
137
|
+
stderrTail = (stderrTail + text).slice(-TAIL_CAP);
|
|
138
|
+
if (!bootEmitted) {
|
|
139
|
+
bootEmitted = true;
|
|
140
|
+
const head = text.split("\n")[0].slice(0, 200);
|
|
141
|
+
emitLifecycle(`op=boot session=${SESSION_ID8} server=${SERVER_NAME} head=${JSON.stringify(head)}`, "info");
|
|
142
|
+
}
|
|
143
|
+
return rawStderrWrite(...args); // passthrough
|
|
123
144
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
process.stderr.write = teeWrite;
|
|
146
|
+
// Catchable-signal handling. The shim drives the exit ONLY when it is the sole
|
|
147
|
+
// listener for the signal — i.e. the imported entry installed no handler of its
|
|
148
|
+
// own. In that case it records the signal (so op=exit carries signal=<sig>) and
|
|
149
|
+
// exits with 128+signum, mirroring the prior wrapper's exit-status convention.
|
|
150
|
+
//
|
|
151
|
+
// When the entry DID install a handler, the shim defers entirely and records
|
|
152
|
+
// nothing: the entry's handler decides the exit code, and op=exit reflects that
|
|
153
|
+
// exit verbatim. This matches the prior two-process model, where a child that
|
|
154
|
+
// caught the signal and exited cleanly was observed as code=0 signal=— (a clean
|
|
155
|
+
// self-exit), not as a signal death. Setting exitSignal here unconditionally
|
|
156
|
+
// would mislabel every graceful signal-driven shutdown as a signal kill.
|
|
157
|
+
function onSignal(sig, code) {
|
|
158
|
+
return () => {
|
|
159
|
+
if (process.listenerCount(sig) === 1) {
|
|
160
|
+
exitSignal = sig;
|
|
161
|
+
process.exit(code);
|
|
137
162
|
}
|
|
138
|
-
}
|
|
163
|
+
};
|
|
139
164
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
process.on("
|
|
143
|
-
process
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
165
|
+
process.on("SIGTERM", onSignal("SIGTERM", 143));
|
|
166
|
+
process.on("SIGINT", onSignal("SIGINT", 130));
|
|
167
|
+
process.on("SIGHUP", onSignal("SIGHUP", 129));
|
|
168
|
+
// op=exit, emitted once from the process "exit" event. Sync-only — the loop is
|
|
169
|
+
// stopping. When a catchable signal caused the exit, report code=— signal=<sig>
|
|
170
|
+
// to match the prior wrapper's format; otherwise code=<exit code> signal=—.
|
|
171
|
+
process.on("exit", (code) => {
|
|
172
|
+
if (exitEmitted)
|
|
173
|
+
return;
|
|
174
|
+
exitEmitted = true;
|
|
150
175
|
const lifetimeMs = Date.now() - spawnStamp;
|
|
151
176
|
const tail = stderrTail.slice(-200);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
177
|
+
const codeField = exitSignal ? "—" : String(code);
|
|
178
|
+
const level = exitSignal || code !== 0 ? "error" : "info";
|
|
179
|
+
emitLifecycle(`op=exit session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} ` +
|
|
180
|
+
`code=${codeField} signal=${exitSignal ?? "—"} lifetimeMs=${lifetimeMs} stderr-tail=${JSON.stringify(tail)}`, level);
|
|
181
|
+
});
|
|
182
|
+
emitLifecycle(`op=spawn session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} entry=${ENTRY}`, "info");
|
|
183
|
+
// Run the real MCP server in THIS process. Dynamic import() (not top-level
|
|
184
|
+
// await — this file compiles to CommonJS) loads the ESM entry; a load-time
|
|
185
|
+
// failure mirrors the old child spawn-error path (op=error, exit 127). The
|
|
186
|
+
// op=exit handler is suppressed on this path so op=error stays the sole record.
|
|
187
|
+
import((0, node_url_1.pathToFileURL)(ENTRY).href).catch((err) => {
|
|
188
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
189
|
+
exitEmitted = true;
|
|
190
|
+
emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason=${JSON.stringify(`import error: ${msg}`)}`, "error");
|
|
191
|
+
process.exit(127);
|
|
158
192
|
});
|
|
159
193
|
//# sourceMappingURL=index.js.map
|
|
@@ -26,6 +26,7 @@ import { publishSite } from "./tools/publish-site.js";
|
|
|
26
26
|
import { resolveCapabilitiesHere } from "./tools/capabilities-here.js";
|
|
27
27
|
import { runCatalogueCensus } from "./lib/catalogue-census.js";
|
|
28
28
|
import { lifelineTool } from "../../../../lib/mcp-lifeline/dist/index.js";
|
|
29
|
+
import { listAccountsFromDir, isHouseAccount, archiveAccountDir, provisionClientAccount, ACCOUNT_NODE_COUNT_CYPHER, ACCOUNT_PURGE_CYPHER, } from "./tools/account-lifecycle.js";
|
|
29
30
|
function refusalGuidance(kind) {
|
|
30
31
|
switch (kind) {
|
|
31
32
|
case "unsafe-slug":
|
|
@@ -3180,6 +3181,107 @@ eagerTool(server, "action-edit", "Edit a pending action's input and then execute
|
|
|
3180
3181
|
};
|
|
3181
3182
|
}
|
|
3182
3183
|
});
|
|
3184
|
+
// ---------------------------------------------------------------------------
|
|
3185
|
+
// Multi-account lifecycle (Task 983) — admin-core only, never public/specialist.
|
|
3186
|
+
// One Rubytech operator hosts N client accounts on one brand install: one
|
|
3187
|
+
// role:"house" account receives customer-channel inbound; clients are
|
|
3188
|
+
// operator-provisioned tenants. Account scope is a property (n.accountId), never
|
|
3189
|
+
// an edge. The accounts root is install-wide, so these tools resolve it from
|
|
3190
|
+
// PLATFORM_ROOT rather than the per-session ACCOUNT_ID.
|
|
3191
|
+
// ---------------------------------------------------------------------------
|
|
3192
|
+
const ACCOUNTS_ROOT = resolve(PLATFORM_ROOT, "..", "data/accounts");
|
|
3193
|
+
eagerTool(server, "account_list", "List every account on this install (one house + N clients) with its role. Managed-service operator tool — the active account drives which account a switched session reads and writes.", {}, async () => {
|
|
3194
|
+
const accounts = listAccountsFromDir(ACCOUNTS_ROOT);
|
|
3195
|
+
const lines = accounts.map((a) => `${a.accountId} role=${a.role}${a.isHouse ? " (house)" : ""}`);
|
|
3196
|
+
return {
|
|
3197
|
+
content: [{ type: "text", text: accounts.length ? lines.join("\n") : "No accounts found." }],
|
|
3198
|
+
};
|
|
3199
|
+
});
|
|
3200
|
+
eagerTool(server, "account_create", "Provision a new CLIENT account on this install (managed service). Mints a UUID, scaffolds the account directory (agents, specialists, settings, account.json with role:\"client\"), seeds default plugins, and adds you (the install owner) to the account's admins so you can switch to it. Returns the new accountId. Operator-only; never creates the house account (that is the install itself).", {}, async () => {
|
|
3201
|
+
if (!ACCOUNT_ID)
|
|
3202
|
+
return refuseNoAccount("account_create");
|
|
3203
|
+
const newId = randomUUID();
|
|
3204
|
+
try {
|
|
3205
|
+
const accountDir = provisionClientAccount({
|
|
3206
|
+
platformRoot: PLATFORM_ROOT,
|
|
3207
|
+
accountsDir: ACCOUNTS_ROOT,
|
|
3208
|
+
accountId: newId,
|
|
3209
|
+
usersFile: USERS_FILE,
|
|
3210
|
+
});
|
|
3211
|
+
const accountJson = join(accountDir, "account.json");
|
|
3212
|
+
const dirExists = existsSync(accountJson);
|
|
3213
|
+
let role = "client";
|
|
3214
|
+
try {
|
|
3215
|
+
role = String(JSON.parse(readFileSync(accountJson, "utf-8")).role ?? "client");
|
|
3216
|
+
}
|
|
3217
|
+
catch { /* keep default */ }
|
|
3218
|
+
process.stderr.write(`[account-lifecycle] op=create accountId=${newId} dir-exists=${dirExists} role=${role}\n`);
|
|
3219
|
+
if (!dirExists) {
|
|
3220
|
+
return { content: [{ type: "text", text: `account_create FAILED: scaffold did not produce ${accountJson}` }], isError: true };
|
|
3221
|
+
}
|
|
3222
|
+
return { content: [{ type: "text", text: `Created client account ${newId}. Switch to it from the account picker to work in its data.` }] };
|
|
3223
|
+
}
|
|
3224
|
+
catch (err) {
|
|
3225
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3226
|
+
process.stderr.write(`[account-lifecycle] op=create accountId=${newId} dir-exists=false role=client error=${msg}\n`);
|
|
3227
|
+
return { content: [{ type: "text", text: `account_create FAILED: ${msg}` }], isError: true };
|
|
3228
|
+
}
|
|
3229
|
+
});
|
|
3230
|
+
eagerTool(server, "account_delete", "Archive a CLIENT account: move its directory to data/accounts/.trash/ so it no longer appears in the account list. Graph data is RETAINED — run account_purge with the typed confirmation to irreversibly delete it. Refuses to archive the house account. Pass the accountId to archive.", {
|
|
3231
|
+
accountId: z.string().describe("The client accountId (UUID) to archive."),
|
|
3232
|
+
}, async ({ accountId }) => {
|
|
3233
|
+
if (!ACCOUNT_ID)
|
|
3234
|
+
return refuseNoAccount("account_delete");
|
|
3235
|
+
if (!existsSync(join(ACCOUNTS_ROOT, accountId, "account.json"))) {
|
|
3236
|
+
return { content: [{ type: "text", text: `account_delete: ${accountId} is not a registered account on this install.` }], isError: true };
|
|
3237
|
+
}
|
|
3238
|
+
if (isHouseAccount(ACCOUNTS_ROOT, accountId)) {
|
|
3239
|
+
return { content: [{ type: "text", text: `account_delete refused: ${accountId} is the house account and cannot be archived.` }], isError: true };
|
|
3240
|
+
}
|
|
3241
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "").replace(/-/g, "");
|
|
3242
|
+
try {
|
|
3243
|
+
const { trashPath, dirAbsent } = archiveAccountDir(ACCOUNTS_ROOT, accountId, ts);
|
|
3244
|
+
process.stderr.write(`[account-lifecycle] op=archive accountId=${accountId} trash-path=${trashPath} dir-absent=${dirAbsent}\n`);
|
|
3245
|
+
return { content: [{ type: "text", text: `Archived ${accountId} to ${trashPath}. Graph data retained — run account_purge to delete it permanently.` }] };
|
|
3246
|
+
}
|
|
3247
|
+
catch (err) {
|
|
3248
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3249
|
+
return { content: [{ type: "text", text: `account_delete FAILED: ${msg}` }], isError: true };
|
|
3250
|
+
}
|
|
3251
|
+
});
|
|
3252
|
+
eagerTool(server, "account_purge", "IRREVERSIBLY delete every graph node carrying an account's accountId (DETACH DELETE). Two-step safety: account_delete archives first; this purges. Requires a typed confirmation equal to the accountId itself — any mismatch refuses. Refuses the house account. Returns the node count before and after (after must be zero).", {
|
|
3253
|
+
accountId: z.string().describe("The accountId (UUID) whose graph data to purge."),
|
|
3254
|
+
confirm: z.string().describe("Type the accountId exactly to confirm the irreversible purge."),
|
|
3255
|
+
}, async ({ accountId, confirm }) => {
|
|
3256
|
+
if (!ACCOUNT_ID)
|
|
3257
|
+
return refuseNoAccount("account_purge");
|
|
3258
|
+
if (isHouseAccount(ACCOUNTS_ROOT, accountId)) {
|
|
3259
|
+
return { content: [{ type: "text", text: `account_purge refused: ${accountId} is the house account.` }], isError: true };
|
|
3260
|
+
}
|
|
3261
|
+
if (confirm !== accountId) {
|
|
3262
|
+
return { content: [{ type: "text", text: `account_purge refused: confirmation does not match the accountId. Type the accountId exactly to confirm.` }], isError: true };
|
|
3263
|
+
}
|
|
3264
|
+
const session = getSession();
|
|
3265
|
+
try {
|
|
3266
|
+
const before = await session.run(ACCOUNT_NODE_COUNT_CYPHER, { id: accountId });
|
|
3267
|
+
const beforeCount = Number(before.records[0]?.get("c") ?? 0);
|
|
3268
|
+
await session.run(ACCOUNT_PURGE_CYPHER, { id: accountId });
|
|
3269
|
+
const after = await session.run(ACCOUNT_NODE_COUNT_CYPHER, { id: accountId });
|
|
3270
|
+
const afterCount = Number(after.records[0]?.get("c") ?? 0);
|
|
3271
|
+
process.stderr.write(`[account-lifecycle] op=purge accountId=${accountId} nodes-before=${beforeCount} nodes-after=${afterCount}\n`);
|
|
3272
|
+
if (afterCount !== 0) {
|
|
3273
|
+
return { content: [{ type: "text", text: `account_purge INCOMPLETE: ${afterCount} node(s) still carry accountId ${accountId} (was ${beforeCount}).` }], isError: true };
|
|
3274
|
+
}
|
|
3275
|
+
return { content: [{ type: "text", text: `Purged ${beforeCount} node(s) for account ${accountId}. This is irreversible.` }] };
|
|
3276
|
+
}
|
|
3277
|
+
catch (err) {
|
|
3278
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3279
|
+
return { content: [{ type: "text", text: `account_purge FAILED: ${msg}` }], isError: true };
|
|
3280
|
+
}
|
|
3281
|
+
finally {
|
|
3282
|
+
await session.close();
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3183
3285
|
// Cleanup on exit (SIGTERM for systemd service stops on Pi)
|
|
3184
3286
|
const cleanup = async () => {
|
|
3185
3287
|
await closeDriver();
|