@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.
Files changed (156) hide show
  1. package/dist/index.js +19 -2
  2. package/package.json +1 -1
  3. package/payload/platform/config/brand.json +1 -0
  4. package/payload/platform/lib/account-enumeration/dist/index.d.ts +33 -0
  5. package/payload/platform/lib/account-enumeration/dist/index.d.ts.map +1 -1
  6. package/payload/platform/lib/account-enumeration/dist/index.js +76 -0
  7. package/payload/platform/lib/account-enumeration/dist/index.js.map +1 -1
  8. package/payload/platform/lib/account-enumeration/src/index.ts +78 -0
  9. package/payload/platform/lib/mcp-spawn-tee/dist/index.d.ts +24 -24
  10. package/payload/platform/lib/mcp-spawn-tee/dist/index.js +109 -75
  11. package/payload/platform/lib/mcp-spawn-tee/dist/index.js.map +1 -1
  12. package/payload/platform/lib/mcp-spawn-tee/src/__tests__/spawn-tee.test.ts +56 -19
  13. package/payload/platform/lib/mcp-spawn-tee/src/index.ts +112 -77
  14. package/payload/platform/neo4j/schema.cypher +58 -4
  15. package/payload/platform/plugins/admin/.claude-plugin/plugin.json +1 -1
  16. package/payload/platform/plugins/admin/PLUGIN.md +13 -1
  17. package/payload/platform/plugins/admin/lib/mcp-spawn-tee/index.js +109 -75
  18. package/payload/platform/plugins/admin/mcp/dist/index.js +102 -0
  19. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  20. package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.d.ts +2 -0
  21. package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.d.ts.map +1 -0
  22. package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.js +57 -0
  23. package/payload/platform/plugins/admin/mcp/dist/tools/__tests__/account-lifecycle.test.js.map +1 -0
  24. package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.d.ts +34 -0
  25. package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.d.ts.map +1 -0
  26. package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.js +78 -0
  27. package/payload/platform/plugins/admin/mcp/dist/tools/account-lifecycle.js.map +1 -0
  28. package/payload/platform/plugins/admin/skills/plainly/SKILL.md +7 -0
  29. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +2 -2
  30. package/payload/platform/plugins/aeo/lib/mcp-spawn-tee/index.js +109 -75
  31. package/payload/platform/plugins/browser/lib/mcp-spawn-tee/index.js +109 -75
  32. package/payload/platform/plugins/contacts/lib/mcp-spawn-tee/index.js +109 -75
  33. package/payload/platform/plugins/contacts/mcp/dist/index.js +1 -1
  34. package/payload/platform/plugins/contacts/mcp/dist/index.js.map +1 -1
  35. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.d.ts +2 -0
  36. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.d.ts.map +1 -0
  37. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.js +71 -0
  38. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/contact-lookup.test.js.map +1 -0
  39. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts +2 -0
  40. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts.map +1 -0
  41. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js +112 -0
  42. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js.map +1 -0
  43. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts +2 -0
  44. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts.map +1 -0
  45. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js +102 -0
  46. package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js.map +1 -0
  47. package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.d.ts +1 -0
  48. package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.d.ts.map +1 -1
  49. package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.js +10 -3
  50. package/payload/platform/plugins/contacts/mcp/dist/tools/contact-lookup.js.map +1 -1
  51. package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.d.ts.map +1 -1
  52. package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js +7 -2
  53. package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js.map +1 -1
  54. package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.d.ts.map +1 -1
  55. package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js +5 -4
  56. package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js.map +1 -1
  57. package/payload/platform/plugins/contacts/mcp/package.json +4 -2
  58. package/payload/platform/plugins/docs/references/admin-ui.md +1 -1
  59. package/payload/platform/plugins/email/lib/mcp-spawn-tee/index.js +109 -75
  60. package/payload/platform/plugins/memory/.claude-plugin/plugin.json +1 -1
  61. package/payload/platform/plugins/memory/PLUGIN.md +1 -1
  62. package/payload/platform/plugins/memory/lib/mcp-spawn-tee/index.js +109 -75
  63. package/payload/platform/plugins/memory/mcp/dist/index.js +3 -1
  64. package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
  65. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-lookup-by-name.test.js +39 -0
  66. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-lookup-by-name.test.js.map +1 -1
  67. package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.d.ts.map +1 -1
  68. package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.js +13 -1
  69. package/payload/platform/plugins/memory/mcp/dist/tools/memory-lookup-by-name.js.map +1 -1
  70. package/payload/platform/plugins/memory/references/schema-estate-agent.md +17 -5
  71. package/payload/platform/plugins/outlook/lib/mcp-spawn-tee/index.js +109 -75
  72. package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/index.js +109 -75
  73. package/payload/platform/plugins/replicate/lib/mcp-spawn-tee/index.js +109 -75
  74. package/payload/platform/plugins/scheduling/lib/mcp-spawn-tee/index.js +109 -75
  75. package/payload/platform/plugins/telegram/lib/mcp-spawn-tee/index.js +109 -75
  76. package/payload/platform/plugins/url-get/lib/mcp-spawn-tee/index.js +109 -75
  77. package/payload/platform/plugins/whatsapp/lib/mcp-spawn-tee/index.js +109 -75
  78. package/payload/platform/plugins/work/lib/mcp-spawn-tee/index.js +109 -75
  79. package/payload/platform/plugins/workflows/lib/mcp-spawn-tee/index.js +109 -75
  80. package/payload/platform/scripts/__tests__/provision-role-stamp.test.sh +40 -0
  81. package/payload/platform/scripts/__tests__/sweep-durability.test.sh +103 -0
  82. package/payload/platform/scripts/lib/provision-account-dir.sh +319 -0
  83. package/payload/platform/scripts/lib/resolve-account-dir.sh +79 -132
  84. package/payload/platform/scripts/seed-neo4j.sh +18 -0
  85. package/payload/platform/scripts/setup-account.sh +28 -361
  86. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  87. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +4 -0
  88. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  89. package/payload/platform/services/claude-session-manager/dist/config.d.ts +18 -0
  90. package/payload/platform/services/claude-session-manager/dist/config.d.ts.map +1 -1
  91. package/payload/platform/services/claude-session-manager/dist/config.js +63 -7
  92. package/payload/platform/services/claude-session-manager/dist/config.js.map +1 -1
  93. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  94. package/payload/platform/services/claude-session-manager/dist/http-server.js +30 -2
  95. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  96. package/payload/platform/services/claude-session-manager/dist/index.js +16 -1
  97. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  98. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
  99. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +7 -0
  100. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
  101. package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts +5 -0
  102. package/payload/platform/services/claude-session-manager/dist/session-sidecar.d.ts.map +1 -1
  103. package/payload/platform/services/claude-session-manager/dist/session-sidecar.js +8 -0
  104. package/payload/platform/services/claude-session-manager/dist/session-sidecar.js.map +1 -1
  105. package/payload/platform/services/claude-session-manager/dist/stuck-turn.d.ts +6 -0
  106. package/payload/platform/services/claude-session-manager/dist/stuck-turn.d.ts.map +1 -1
  107. package/payload/platform/services/claude-session-manager/dist/stuck-turn.js +17 -5
  108. package/payload/platform/services/claude-session-manager/dist/stuck-turn.js.map +1 -1
  109. package/payload/platform/services/webchat-channel/dist/instructions.d.ts.map +1 -1
  110. package/payload/platform/services/webchat-channel/dist/instructions.js +25 -1
  111. package/payload/platform/services/webchat-channel/dist/instructions.js.map +1 -1
  112. package/payload/platform/services/webchat-channel/dist/notification.d.ts +17 -0
  113. package/payload/platform/services/webchat-channel/dist/notification.d.ts.map +1 -1
  114. package/payload/platform/services/webchat-channel/dist/notification.js +14 -0
  115. package/payload/platform/services/webchat-channel/dist/notification.js.map +1 -1
  116. package/payload/platform/services/webchat-channel/dist/server.d.ts.map +1 -1
  117. package/payload/platform/services/webchat-channel/dist/server.js +66 -2
  118. package/payload/platform/services/webchat-channel/dist/server.js.map +1 -1
  119. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts +28 -0
  120. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts.map +1 -0
  121. package/payload/platform/services/webchat-channel/dist/turn-follow.js +188 -0
  122. package/payload/platform/services/webchat-channel/dist/turn-follow.js.map +1 -0
  123. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  124. package/payload/platform/services/whatsapp-channel/dist/notification.js +24 -1
  125. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  126. package/payload/platform/templates/account.json +2 -0
  127. package/payload/premium-plugins/writer-craft/lib/mcp-spawn-tee/index.js +109 -75
  128. package/payload/server/public/assets/AdminLoginScreens-DexSvtjD.js +1 -0
  129. package/payload/server/public/assets/AdminShell-Bf9tndNg.js +1 -0
  130. package/payload/server/public/assets/{Checkbox-1flpB9H0.js → Checkbox-D58GsKoQ.js} +1 -1
  131. package/payload/server/public/assets/{OperatorConversations-DrPqB9Ym.css → OperatorConversations-CDdp2nVn.css} +1 -1
  132. package/payload/server/public/assets/OperatorConversations-RmqANYz8.js +9 -0
  133. package/payload/server/public/assets/{admin-BWJTvagN.js → admin-CH5Vkkt4.js} +1 -1
  134. package/payload/server/public/assets/{browser-XM5e-fn1.js → browser-BwDtzSlr.js} +1 -1
  135. package/payload/server/public/assets/chat-3GY0LmYH.js +1 -0
  136. package/payload/server/public/assets/data-CttrzhfL.js +1 -0
  137. package/payload/server/public/assets/{graph-CIIz9Dmh.js → graph-CZSdF2jv.js} +3 -3
  138. package/payload/server/public/assets/{graph-labels-BRKvhE0e.js → graph-labels-Bi0fu8Ns.js} +1 -1
  139. package/payload/server/public/assets/operator-BEivxmRy.js +1 -0
  140. package/payload/server/public/assets/page-DUvT07SB.js +30 -0
  141. package/payload/server/public/assets/{public-BPlZnopr.js → public-B3eIlVbd.js} +1 -1
  142. package/payload/server/public/browser.html +4 -4
  143. package/payload/server/public/chat.html +5 -5
  144. package/payload/server/public/data.html +4 -4
  145. package/payload/server/public/graph.html +6 -6
  146. package/payload/server/public/index.html +6 -6
  147. package/payload/server/public/operator.html +7 -7
  148. package/payload/server/public/public.html +5 -5
  149. package/payload/server/server.js +605 -435
  150. package/payload/server/public/assets/AdminLoginScreens-BnuaXvxN.js +0 -1
  151. package/payload/server/public/assets/AdminShell-Br0DJQNu.js +0 -1
  152. package/payload/server/public/assets/OperatorConversations-C8sITz2_.js +0 -9
  153. package/payload/server/public/assets/chat-COFMxaoC.js +0 -1
  154. package/payload/server/public/assets/data-BHtJozT2.js +0 -1
  155. package/payload/server/public/assets/operator-9hbxrXKm.js +0 -1
  156. package/payload/server/public/assets/page-CXkBfOhG.js +0 -30
@@ -0,0 +1,57 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdtempSync, mkdirSync, writeFileSync, existsSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { listAccountsFromDir, isHouseAccount, archiveAccountDir } from "../account-lifecycle.js";
7
+ const HOUSE = "11111111-1111-1111-1111-111111111111";
8
+ const CLIENT = "22222222-2222-2222-2222-222222222222";
9
+ function seed(root, id, role) {
10
+ mkdirSync(join(root, id), { recursive: true });
11
+ writeFileSync(join(root, id, "account.json"), JSON.stringify({ accountId: id, role }));
12
+ }
13
+ const mk = () => mkdtempSync(join(tmpdir(), "acct-lifecycle-"));
14
+ test("listAccountsFromDir returns registered accounts with roles", () => {
15
+ const root = mk();
16
+ try {
17
+ seed(root, HOUSE, "house");
18
+ seed(root, CLIENT, "client");
19
+ mkdirSync(join(root, "not-a-uuid")); // ignored
20
+ const list = listAccountsFromDir(root).sort((a, b) => a.accountId.localeCompare(b.accountId));
21
+ assert.equal(list.length, 2);
22
+ assert.deepEqual(list.find((a) => a.accountId === HOUSE), { accountId: HOUSE, role: "house", isHouse: true });
23
+ assert.deepEqual(list.find((a) => a.accountId === CLIENT), { accountId: CLIENT, role: "client", isHouse: false });
24
+ }
25
+ finally {
26
+ rmSync(root, { recursive: true });
27
+ }
28
+ });
29
+ test("isHouseAccount distinguishes house from client", () => {
30
+ const root = mk();
31
+ try {
32
+ seed(root, HOUSE, "house");
33
+ seed(root, CLIENT, "client");
34
+ assert.equal(isHouseAccount(root, HOUSE), true);
35
+ assert.equal(isHouseAccount(root, CLIENT), false);
36
+ }
37
+ finally {
38
+ rmSync(root, { recursive: true });
39
+ }
40
+ });
41
+ test("archiveAccountDir moves the dir to .trash and reports it absent", () => {
42
+ const root = mk();
43
+ try {
44
+ seed(root, CLIENT, "client");
45
+ const { trashPath, dirAbsent } = archiveAccountDir(root, CLIENT, "20260618T000000Z");
46
+ assert.equal(dirAbsent, true);
47
+ assert.equal(existsSync(join(root, CLIENT)), false);
48
+ assert.equal(existsSync(trashPath), true);
49
+ assert.equal(existsSync(join(trashPath, "account.json")), true);
50
+ // archived account is no longer in the registry
51
+ assert.equal(listAccountsFromDir(root).length, 0);
52
+ }
53
+ finally {
54
+ rmSync(root, { recursive: true });
55
+ }
56
+ });
57
+ //# sourceMappingURL=account-lifecycle.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-lifecycle.test.js","sourceRoot":"","sources":["../../../src/tools/__tests__/account-lifecycle.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjG,MAAM,KAAK,GAAG,sCAAsC,CAAC;AACrD,MAAM,MAAM,GAAG,sCAAsC,CAAC;AAEtD,SAAS,IAAI,CAAC,IAAY,EAAE,EAAU,EAAE,IAAY;IAClD,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC;A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mB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC;YAAS,CAAC;QAAC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAAC,CAAC;AAClD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ export interface AccountSummary {
2
+ accountId: string;
3
+ role: string;
4
+ isHouse: boolean;
5
+ }
6
+ /** Enumerate the registry: every UUID dir with a parseable account.json, with
7
+ * its role. An unparseable account.json is excluded (corruption discipline,
8
+ * mirrors account-enumeration). */
9
+ export declare function listAccountsFromDir(accountsDir: string): AccountSummary[];
10
+ /** True iff `id` is the house account. Used to refuse delete/purge of the house. */
11
+ export declare function isHouseAccount(accountsDir: string, id: string): boolean;
12
+ /** Move a live account dir into `data/accounts/.trash/<id>-<ts>/`. Graph rows are
13
+ * retained (purge is a separate, typed-confirmation step). Returns the trash
14
+ * path and whether the live dir is now absent (the verified post-condition). */
15
+ export declare function archiveAccountDir(accountsDir: string, id: string, ts: string): {
16
+ trashPath: string;
17
+ dirAbsent: boolean;
18
+ };
19
+ /** Scaffold a new client account dir by invoking the shared
20
+ * `provision_account_dir` shell function (the same path setup-account.sh uses
21
+ * for the house). Synchronous — throws on non-zero exit, which the caller turns
22
+ * into a tool error. */
23
+ export declare function provisionClientAccount(opts: {
24
+ platformRoot: string;
25
+ accountsDir: string;
26
+ accountId: string;
27
+ usersFile: string;
28
+ }): string;
29
+ /** Cypher for the account-scoped node count and the irreversible purge. The
30
+ * purge deletes every node carrying the accountId (account scope is a property,
31
+ * never an edge — see CLAUDE.md), detaching its relationships. */
32
+ export declare const ACCOUNT_NODE_COUNT_CYPHER = "MATCH (n) WHERE n.accountId = $id RETURN count(n) AS c";
33
+ export declare const ACCOUNT_PURGE_CYPHER = "MATCH (n) WHERE n.accountId = $id DETACH DELETE n";
34
+ //# sourceMappingURL=account-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-lifecycle.d.ts","sourceRoot":"","sources":["../../src/tools/account-lifecycle.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;oCAEoC;AACpC,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,EAAE,CAoBzE;AAED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;iFAEiF;AACjF,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,GACT;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAO3C;AAED;;;yBAGyB;AACzB,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAoBT;AAED;;mEAEmE;AACnE,eAAO,MAAM,yBAAyB,2DAA2D,CAAC;AAClG,eAAO,MAAM,oBAAoB,sDAAsD,CAAC"}
@@ -0,0 +1,78 @@
1
+ // Account lifecycle helpers (Task 983) — pure / side-effecting building blocks
2
+ // for the admin-core account_create / account_list / account_delete /
3
+ // account_purge tools. Kept out of index.ts (which connects its stdio transport
4
+ // at import time and so cannot be imported by a unit test) so the enumeration,
5
+ // house-guard, archive, and provision logic are testable in isolation.
6
+ import { execFileSync } from "node:child_process";
7
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync } from "node:fs";
8
+ import { join, resolve } from "node:path";
9
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ /** Enumerate the registry: every UUID dir with a parseable account.json, with
11
+ * its role. An unparseable account.json is excluded (corruption discipline,
12
+ * mirrors account-enumeration). */
13
+ export function listAccountsFromDir(accountsDir) {
14
+ let names;
15
+ try {
16
+ names = readdirSync(accountsDir);
17
+ }
18
+ catch {
19
+ return [];
20
+ }
21
+ const out = [];
22
+ for (const name of names) {
23
+ if (!UUID_RE.test(name))
24
+ continue;
25
+ const configPath = resolve(accountsDir, name, "account.json");
26
+ try {
27
+ const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
28
+ const role = typeof cfg.role === "string" ? cfg.role : "";
29
+ out.push({ accountId: name, role, isHouse: role === "house" });
30
+ }
31
+ catch {
32
+ // missing/unparseable account.json — not a registered account
33
+ }
34
+ }
35
+ return out;
36
+ }
37
+ /** True iff `id` is the house account. Used to refuse delete/purge of the house. */
38
+ export function isHouseAccount(accountsDir, id) {
39
+ return listAccountsFromDir(accountsDir).some((a) => a.accountId === id && a.isHouse);
40
+ }
41
+ /** Move a live account dir into `data/accounts/.trash/<id>-<ts>/`. Graph rows are
42
+ * retained (purge is a separate, typed-confirmation step). Returns the trash
43
+ * path and whether the live dir is now absent (the verified post-condition). */
44
+ export function archiveAccountDir(accountsDir, id, ts) {
45
+ const liveDir = join(accountsDir, id);
46
+ const trashRoot = join(accountsDir, ".trash");
47
+ mkdirSync(trashRoot, { recursive: true });
48
+ const trashPath = join(trashRoot, `${id}-${ts}`);
49
+ renameSync(liveDir, trashPath);
50
+ return { trashPath, dirAbsent: !existsSync(liveDir) };
51
+ }
52
+ /** Scaffold a new client account dir by invoking the shared
53
+ * `provision_account_dir` shell function (the same path setup-account.sh uses
54
+ * for the house). Synchronous — throws on non-zero exit, which the caller turns
55
+ * into a tool error. */
56
+ export function provisionClientAccount(opts) {
57
+ const accountDir = join(opts.accountsDir, opts.accountId);
58
+ execFileSync("bash", ["-c", '. "$SCRIPT_DIR/lib/provision-account-dir.sh"; provision_account_dir "$ACCT_DIR" "$ACCT_ID" client'], {
59
+ env: {
60
+ ...process.env,
61
+ TEMPLATES_DIR: join(opts.platformRoot, "templates"),
62
+ PROJECT_DIR: opts.platformRoot,
63
+ SCRIPT_DIR: join(opts.platformRoot, "scripts"),
64
+ USERS_FILE: opts.usersFile,
65
+ ACCT_DIR: accountDir,
66
+ ACCT_ID: opts.accountId,
67
+ },
68
+ encoding: "utf-8",
69
+ stdio: ["ignore", "pipe", "pipe"],
70
+ });
71
+ return accountDir;
72
+ }
73
+ /** Cypher for the account-scoped node count and the irreversible purge. The
74
+ * purge deletes every node carrying the accountId (account scope is a property,
75
+ * never an edge — see CLAUDE.md), detaching its relationships. */
76
+ export const ACCOUNT_NODE_COUNT_CYPHER = "MATCH (n) WHERE n.accountId = $id RETURN count(n) AS c";
77
+ export const ACCOUNT_PURGE_CYPHER = "MATCH (n) WHERE n.accountId = $id DETACH DELETE n";
78
+ //# sourceMappingURL=account-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-lifecycle.js","sourceRoot":"","sources":["../../src/tools/account-lifecycle.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,sEAAsE;AACtE,gFAAgF;AAChF,+EAA+E;AAC/E,uEAAuE;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,OAAO,GAAG,iEAAiE,CAAC;AAQlF;;oCAEoC;AACpC,MAAM,UAAU,mBAAmB,CAAC,WAAmB;IACrD,IAAI,KAAe,CAAC;IACpB,IAAI,CAAC;QACH,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IAC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AS,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACjD,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC/B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;AACxD,CAAC;AAED;;;yBAGyB;AACzB,MAAM,UAAU,sBAAsB,CAAC,IAKtC;IACC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1D,YAAY,CACV,MAAM,EACN,CAAC,IAAI,EAAE,mGAAmG,CAAC,EAC3G;QACE,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;YACnD,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC;YAC9C,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,IAAI,CAAC,SAAS;SACxB;QACD,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;KAClC,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;mEAEmE;AACnE,MAAM,CAAC,MAAM,yBAAyB,GAAG,wDAAwD,CAAC;AAClG,MAAM,CAAC,MAAM,oBAAoB,GAAG,mDAAmD,CAAC"}
@@ -96,6 +96,13 @@ Length is dictated by the concept's richness AND by what the user has already su
96
96
  - **No follow-up offers.** End on the definition.
97
97
  - **Strip AI tells.** See the AI-tells catalogue below. Plain English is the *spoken* register, which rules out patterns that AI writing reaches for but humans rarely use in conversation.
98
98
 
99
+ ## Second pass
100
+
101
+ Run this after the precision pass, reading the candidate as a reader rather than as the writer. Two questions, and both must pass before the output ships.
102
+
103
+ - **Would a person say this out loud?** Read it aloud. A sentence that only works on the page (a formula spoken letter by letter, a clause you have to re-read to parse) fails; rewrite it in the spoken register.
104
+ - **Would a stranger flag this as AI?** If a reader who never saw the draft would point at a sentence and call it machine-written, that sentence carries a tell the precision pass missed. Strip it.
105
+
99
106
  ## AI tells to strip
100
107
 
101
108
  These are patterns common in AI-generated prose but rare in actual human writing, especially in spoken or conversational registers. Strip every one on the precision pass. The list grows as more patterns are surfaced.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: platform-architecture
3
3
  description: Use when grounding any documented-surface claim about what Maxy ships — plugins, skills, specialists, install/deploy flows, internals. This is the install catalogue, not evidence of what is enabled on the current account. For install state on this account, call `capabilities-here`; for documented surface, cite the `Source:` URL inline.
4
- content-hash: sha256:b3f1611fcb4116496aadfdfa39e64fce9061f0611c6d926545f6c6523688fc73
4
+ content-hash: sha256:7ce8254f9b8096d919d2be7aa4f6c5a30f5e6dbe1f61007ee00f05af81020445
5
5
  brand: maxy-code
6
6
  product-name: Maxy
7
7
  ---
@@ -2601,7 +2601,7 @@ authoritative. This section names the surfaces and what backs each.
2601
2601
  |---|---|---|
2602
2602
  | `+ New session` button | Opens `NewSessionModal`, which POSTs `{channel, permissionMode, model, initialMessage}` to `/api/admin/claude-sessions`. | `claude-sessions.ts` |
2603
2603
  | Mode trigger | Per-`(accountId, userId)` `SpawnPreference` for `permissionMode` and `model`; persists across reload, tab, device. | `session-defaults.ts` |
2604
- | Nav rows (Chat / People / Agents / Projects / Tasks / Artefacts) | People, Agents, Tasks open the artefact-pane Graph filtered to the matching label. Chat selects the active conversation. Artefacts swaps the list to editable documents. | `graph-search.ts`, `graph-subgraph.ts`, `sidebar-artefacts.ts` |
2604
+ | Nav rows (Chat / People / Agents / Projects / Tasks / Artefacts) | People, Agents, Tasks open the artefact-pane Graph filtered to the matching label. Chat selects the active conversation. Artefacts swaps the list to editable documents. **The "Projects" row is brand-aware:** its visible term and the graph label it filters to both come from the injected `window.__BRAND__.primaryContainer` (`brand.json` → `server/index.ts` inject → `brand.ts` `brandPrimaryContainer()`), so Maxy reads "Projects" → `:Project`, SiteOffice "Jobs" → `:Job`, Real Agent "Properties" → `:Property`. A brand JSON missing `primaryContainer` falls back to Project/Projects (server logs `[brand] op=primaryContainer-default reason=absent brand=<hostname>`; the populated case logs `[brand] op=inject primaryContainer=<label>/<term>`). | `graph-search.ts`, `graph-subgraph.ts`, `sidebar-artefacts.ts` |
2605
2605
  | Sessions list (Active / Archived / All) | Live row store driven by SSE; manual reconcile button on the segmented control re-fetches the full id set. Every listed row carries two launch actions: the claude.ai/code resume (`ExternalLink`) and a chat-launch (`MessageSquare`) that opens `/chat?session=<full sessionId>` — the admin webchat pointed at that exact session; sending there resumes a stopped session with the webchat channel bound to that id (see `admin-webchat-native-channel.md`, "Session-targeted mode"). At the ≤720 px drawer breakpoint each row stacks into two lines — dot + title + id/stamp, then the action icons — with a divider between rows and actions at full opacity (the desktop hover-gated 0.5 opacity never resolves on touch). Below a 400 px list width each row's action icons collapse to a single `MoreHorizontal` ellipsis trigger; its popover menu lists the same actions as the inline icons but labels them with concise verbs (`Resume in claude.ai/code`, `Open in webchat`, `Stop`, `Archive` / `Unarchive`, `Rename`, `Delete`, `Re-seat`) rather than the inline icon buttons' verbose per-session aria-labels — the inline buttons keep those verbose labels because an icon-only control needs the full descriptive accessible name. **Re-seat:** Re-seat is a member action of the one `SessionRowActions` cluster, not a separate sibling control — wide it is the sliders icon inline with the other icons (sharing the cluster geometry and alignment); collapsed it is the `Re-seat` menu item, which expands the model/mode/effort form inline inside the overflow menu. The form (`SessionReseatControl`) forks the session via `/api/admin/session-reseat` and navigates to the fork (the same fork mechanism `/chat`'s pickers drive); its model picker defaults to the row's current model (a `model` field on each row, read from the JSONL tail), and mode and effort each carry a "Keep" option that omits the field. The overflow menu and the Re-seat form render through a `document.body` portal, fixed-positioned from the trigger's rect (right-aligned, flipped above the trigger when there is no room below), so neither is clipped by `.side-list`'s `overflow-y:auto`; Escape, a pointerdown outside the trigger/popover, and any scroll or resize dismiss them. | `/claude-sessions/events`, `/claude-sessions`, `/session-reseat` |
2606
2606
  | Channel reader nav rows (WhatsApp / Telegram) | One conditional nav row **per interactive channel that has ≥1 admin session**. Each row carries its brand glyph (WhatsApp `#25D366`, Telegram `#229ED9`); a channel with no admin session shows no row, and no install ever shows an always-empty "No conversations" row. The channel list loads **once on sidebar mount** (the per-channel counts must be known before the nav renders), so a failed load shows one muted, non-clickable line instead of channel rows. Clicking a channel row lists that channel's admin conversations; each conversation row shows a **display name** resolved by precedence `operatorName ?? whatsappName ?? senderId ?? title`: the bound `Person givenName familyName` when a `senderId`→`userId` binding exists, else the persisted WhatsApp display name (`pushName`, read from the latest `:Message:WhatsAppMessage.senderName`), else the raw `senderId`, else the agent title; the agent session title is the hover tooltip only. Under the name each row shows a **last-message-time breadcrumb** (`conv-timestamp`, same markup as the Sessions rows) formatted from the row's `lastMessageAt` (the last parseable turn's `ts`); a session with no parseable turn shows no time, never "Invalid Date". **Re-seat:** each channel conversation row carries a `SessionRowActions` cluster whose sole action is Re-seat (the row is a `conv-with-actions` shell whose open click moved onto an inner button so the cluster can sit beside it), so a WhatsApp/Telegram session's model/mode/effort is re-seatable from the dashboard exactly like a webchat row — wide it is the inline sliders icon, and below the 400 px width it folds into the `…` overflow menu identically to the Sessions rows; the channel reader row carries the same `model` field for the picker default. A click on a conversation **opens its transcript on the home surface**: on `/` it selects in place, and from any other route (`/graph`, `/data`, `/browser`) it navigates to `/?wa=<sessionId>&projectDir=<dir>`, which the root shell hydrates on mount (then strips the query so a later refresh does not re-pin a closed conversation). Server logs `[wa-reader] op=operator-name-fallback senderId=… source=whatsapp-pushname` when the pushName fallback fires and `[wa-reader] op=conversations count=<n> withTimestamp=<m>` per list build; the client logs `[admin-ui] wa-open route=… via=<in-place\|navigate> …` and `[admin-ui] wa-hydrate route=/ …`. | `/whatsapp-reader/conversations` |
2607
2607
  | Channel transcript (`<Transcript>`) | Reads one session's JSONL over SSE (`/whatsapp-reader/stream`) and renders both sides plus tool calls — the turns claude.ai/code hides because channel inbound is stamped `isMeta`. Every turn shows its time-of-day (HH:MM from the turn's `ts`; a null/unparseable `ts` shows no time, never "Invalid Date"). `tool-call`/`tool-result` turns render as **collapsed cards** (chevron + label + time, default collapsed, expandable per card; one card's state never affects another) so the human↔agent text is not buried in JSON; the three conversation kinds always render in full. The thread **follows the tail**: it opens at the newest turn and pins to the bottom on each live append **only while the operator is already within 32 px of the bottom** — a scroll up suppresses the jump so reading history is never yanked. While the operator is scrolled up a **jump-to-bottom control** (`.wa-jump`, bottom-right of the viewport) appears; clicking it scrolls to the newest turn and re-arms follow-tail, and it hides again at the bottom. The thread scrolls inside its grid cell (header/sidebar/footer fixed). The stream sends a 20 s heartbeat so an idle Cloudflare tunnel does not idle-drop, tags each frame with a byte-offset `id:`, and resumes from the client's `Last-Event-ID` on reconnect (no duplicate backlog); the client clears the "Stream disconnected" banner on reopen and latches it only on a terminal CLOSED state. The thread also interleaves a collapsed `⚙ directive injected (N B)` row per turn, sorted by timestamp just before the turn it informed; expanding one fetches the exact stored `prompt-optimiser-directive` bytes for that turn. The entries are listed by `GET /whatsapp-reader/directives?sessionId=` and the bytes served by `GET /whatsapp-reader/directive?sessionId=&name=`, both admin-gated and account-scoped; a missing store degrades to no rows. A centered day-divider row (`.day-divider`) marks each local calendar-day crossover between consecutive turns so a thread spanning midnight is unambiguous. | `/whatsapp-reader/stream`, `/whatsapp-reader/directives`, `/whatsapp-reader/directive` |
@@ -1,47 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  /**
4
- * MCP spawn-tee — parent-side stderr capture + lifecycle observability.
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 wrapper sits between Claude Code and the real
8
- * MCP server: Claude Code runs `node <this> <real-entry>`, and the wrapper
9
- * spawns the real entry with `stdio:['inherit','inherit','pipe']` so stdin
10
- * and stdout (the JSON-RPC channel) pass through byte-identical. Only stderr
11
- * is intercepted, and only for logging.
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
- * Because the wrapper IS the helper's parent, it observes the helper's true
14
- * exit code, signal, and lifetime for every death mode — including a SIGKILL
15
- * or a transport-layer crash that an in-process handler would miss.
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
- * Claude Code CLI → wrapper (this file) child = node <real-entry>
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; wrapper-only, so it never mixes the enumeration copy with the
26
- * live copy. Authoritative sink. Absent when SESSION_ID is unset
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. A dropped POST loses nothing because
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= (always)
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 wrapper never writes to fd 1 (stdout) — that is the JSON-RPC channel.
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). Wrapper-only. Empty SESSION_ID
53
- // (enumeration spawn) → undefined, and the per-date file is the fallback.
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 child stderr for op=exit. Capped so a chatty child cannot
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
- (0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
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
- // so a dropped POST (unreachable port, process exiting) loses nothing.
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 wrapper's event loop alive
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 wrapper's own stderr (journald / Claude Code
99
- // visibility), and a best-effort server.log mirror. `suffix` is the line body
100
- // after the tag and carries no newline (the log-ingest route rejects newlines).
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
- process.stderr.write(line);
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
- const child = (0, node_child_process_1.spawn)(process.execPath, [ENTRY], {
115
- stdio: ["inherit", "inherit", "pipe"],
116
- env: process.env,
117
- });
118
- emitLifecycle(`op=spawn session=${SESSION_ID8} server=${SERVER_NAME} pid=${child.pid ?? -1} entry=${ENTRY}`, "info");
119
- child.on("error", (err) => {
120
- const msg = err instanceof Error ? err.message : String(err);
121
- emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason=${JSON.stringify(`spawn error: ${msg}`)}`, "error");
122
- process.exit(127);
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
- if (child.stderr) {
125
- child.stderr.on("data", (chunk) => {
126
- appendSafe(perDatePath, chunk); // per-date raw (back-compat)
127
- appendSafe(perSessionPath, chunk); // per-session raw (Task 706)
128
- try {
129
- process.stderr.write(chunk);
130
- }
131
- catch { /* stderr closed */ } // passthrough
132
- stderrTail = (stderrTail + chunk.toString("utf8")).slice(-TAIL_CAP);
133
- if (!bootEmitted) {
134
- bootEmitted = true;
135
- const head = chunk.toString("utf8").split("\n")[0].slice(0, 200);
136
- emitLifecycle(`op=boot session=${SESSION_ID8} server=${SERVER_NAME} head=${JSON.stringify(head)}`, "info");
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
- const forward = (signal) => { if (!child.killed)
141
- child.kill(signal); };
142
- process.on("SIGTERM", () => forward("SIGTERM"));
143
- process.on("SIGINT", () => forward("SIGINT"));
144
- // Signal number, so a signal-killed child propagates as 128+signum (the
145
- // shell convention). `code` is null on a signal exit, so `128 + (code ?? 0)`
146
- // would collapse every signal to 128 and lose the signal identity in the
147
- // wrapper's own exit status.
148
- const SIGNUM = { SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGKILL: 9, SIGTERM: 15 };
149
- child.on("exit", (code, signal) => {
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 level = signal || (code ?? 0) !== 0 ? "error" : "info";
153
- emitLifecycle(`op=exit session=${SESSION_ID8} server=${SERVER_NAME} pid=${child.pid ?? -1} ` +
154
- `code=${code ?? "—"} signal=${signal ?? "—"} lifetimeMs=${lifetimeMs} stderr-tail=${JSON.stringify(tail)}`, level);
155
- if (signal)
156
- process.exit(128 + (SIGNUM[signal] ?? 0));
157
- process.exit(code ?? 0);
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