@rubytech/create-realagent-code 0.1.566 → 0.1.568

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 (176) hide show
  1. package/dist/__tests__/brand-agent-root.test.js +91 -0
  2. package/dist/brand-agent-root.js +58 -0
  3. package/dist/index.js +25 -28
  4. package/package.json +1 -1
  5. package/payload/platform/neo4j/schema.cypher +9 -0
  6. package/payload/platform/package-lock.json +66 -1
  7. package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
  8. package/payload/platform/plugins/admin/hooks/lib/maxy-mcp-plugins.txt +1 -0
  9. package/payload/platform/plugins/admin/mcp/dist/index.js +7 -1
  10. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  11. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.d.ts +10 -1
  12. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.d.ts.map +1 -1
  13. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.js +6 -1
  14. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.js.map +1 -1
  15. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.d.ts +9 -0
  16. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.d.ts.map +1 -1
  17. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.js +1 -1
  18. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.js.map +1 -1
  19. package/payload/platform/plugins/admin/skills/capabilities-here/SKILL.md +1 -1
  20. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +91 -1
  21. package/payload/platform/plugins/admin/skills/public-agent-manager/SKILL.md +5 -1
  22. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +13 -0
  23. package/payload/platform/plugins/docs/references/channel-wake-and-prompt.md +90 -0
  24. package/payload/platform/plugins/inventory/.claude-plugin/plugin.json +21 -0
  25. package/payload/platform/plugins/inventory/PLUGIN.md +75 -0
  26. package/payload/platform/plugins/inventory/lib/mcp-spawn-tee/index.js +204 -0
  27. package/payload/platform/plugins/inventory/lib/mcp-spawn-tee/package.json +3 -0
  28. package/payload/platform/plugins/inventory/mcp/dist/index.d.ts +2 -0
  29. package/payload/platform/plugins/inventory/mcp/dist/index.d.ts.map +1 -0
  30. package/payload/platform/plugins/inventory/mcp/dist/index.js +241 -0
  31. package/payload/platform/plugins/inventory/mcp/dist/index.js.map +1 -0
  32. package/payload/platform/plugins/inventory/mcp/dist/lib/forecast.d.ts +20 -0
  33. package/payload/platform/plugins/inventory/mcp/dist/lib/forecast.d.ts.map +1 -0
  34. package/payload/platform/plugins/inventory/mcp/dist/lib/forecast.js +29 -0
  35. package/payload/platform/plugins/inventory/mcp/dist/lib/forecast.js.map +1 -0
  36. package/payload/platform/plugins/inventory/mcp/dist/lib/neo4j.d.ts +5 -0
  37. package/payload/platform/plugins/inventory/mcp/dist/lib/neo4j.d.ts.map +1 -0
  38. package/payload/platform/plugins/inventory/mcp/dist/lib/neo4j.js +40 -0
  39. package/payload/platform/plugins/inventory/mcp/dist/lib/neo4j.js.map +1 -0
  40. package/payload/platform/plugins/inventory/mcp/dist/lib/read.d.ts +28 -0
  41. package/payload/platform/plugins/inventory/mcp/dist/lib/read.d.ts.map +1 -0
  42. package/payload/platform/plugins/inventory/mcp/dist/lib/read.js +91 -0
  43. package/payload/platform/plugins/inventory/mcp/dist/lib/read.js.map +1 -0
  44. package/payload/platform/plugins/inventory/mcp/dist/lib/replenish.d.ts +56 -0
  45. package/payload/platform/plugins/inventory/mcp/dist/lib/replenish.d.ts.map +1 -0
  46. package/payload/platform/plugins/inventory/mcp/dist/lib/replenish.js +107 -0
  47. package/payload/platform/plugins/inventory/mcp/dist/lib/replenish.js.map +1 -0
  48. package/payload/platform/plugins/inventory/mcp/dist/lib/types.d.ts +98 -0
  49. package/payload/platform/plugins/inventory/mcp/dist/lib/types.d.ts.map +1 -0
  50. package/payload/platform/plugins/inventory/mcp/dist/lib/types.js +7 -0
  51. package/payload/platform/plugins/inventory/mcp/dist/lib/types.js.map +1 -0
  52. package/payload/platform/plugins/inventory/mcp/dist/lib/write-rejects.d.ts +12 -0
  53. package/payload/platform/plugins/inventory/mcp/dist/lib/write-rejects.d.ts.map +1 -0
  54. package/payload/platform/plugins/inventory/mcp/dist/lib/write-rejects.js +49 -0
  55. package/payload/platform/plugins/inventory/mcp/dist/lib/write-rejects.js.map +1 -0
  56. package/payload/platform/plugins/inventory/mcp/dist/tools/demand-record.d.ts +20 -0
  57. package/payload/platform/plugins/inventory/mcp/dist/tools/demand-record.d.ts.map +1 -0
  58. package/payload/platform/plugins/inventory/mcp/dist/tools/demand-record.js +53 -0
  59. package/payload/platform/plugins/inventory/mcp/dist/tools/demand-record.js.map +1 -0
  60. package/payload/platform/plugins/inventory/mcp/dist/tools/forecast.d.ts +23 -0
  61. package/payload/platform/plugins/inventory/mcp/dist/tools/forecast.d.ts.map +1 -0
  62. package/payload/platform/plugins/inventory/mcp/dist/tools/forecast.js +18 -0
  63. package/payload/platform/plugins/inventory/mcp/dist/tools/forecast.js.map +1 -0
  64. package/payload/platform/plugins/inventory/mcp/dist/tools/policy-set.d.ts +25 -0
  65. package/payload/platform/plugins/inventory/mcp/dist/tools/policy-set.d.ts.map +1 -0
  66. package/payload/platform/plugins/inventory/mcp/dist/tools/policy-set.js +37 -0
  67. package/payload/platform/plugins/inventory/mcp/dist/tools/policy-set.js.map +1 -0
  68. package/payload/platform/plugins/inventory/mcp/dist/tools/purchase-order-record.d.ts +25 -0
  69. package/payload/platform/plugins/inventory/mcp/dist/tools/purchase-order-record.d.ts.map +1 -0
  70. package/payload/platform/plugins/inventory/mcp/dist/tools/purchase-order-record.js +43 -0
  71. package/payload/platform/plugins/inventory/mcp/dist/tools/purchase-order-record.js.map +1 -0
  72. package/payload/platform/plugins/inventory/mcp/dist/tools/replenish-plan.d.ts +29 -0
  73. package/payload/platform/plugins/inventory/mcp/dist/tools/replenish-plan.d.ts.map +1 -0
  74. package/payload/platform/plugins/inventory/mcp/dist/tools/replenish-plan.js +95 -0
  75. package/payload/platform/plugins/inventory/mcp/dist/tools/replenish-plan.js.map +1 -0
  76. package/payload/platform/plugins/inventory/mcp/dist/tools/stock-record.d.ts +21 -0
  77. package/payload/platform/plugins/inventory/mcp/dist/tools/stock-record.d.ts.map +1 -0
  78. package/payload/platform/plugins/inventory/mcp/dist/tools/stock-record.js +46 -0
  79. package/payload/platform/plugins/inventory/mcp/dist/tools/stock-record.js.map +1 -0
  80. package/payload/platform/plugins/inventory/mcp/dist/tools/supplier-terms-set.d.ts +24 -0
  81. package/payload/platform/plugins/inventory/mcp/dist/tools/supplier-terms-set.d.ts.map +1 -0
  82. package/payload/platform/plugins/inventory/mcp/dist/tools/supplier-terms-set.js +29 -0
  83. package/payload/platform/plugins/inventory/mcp/dist/tools/supplier-terms-set.js.map +1 -0
  84. package/payload/platform/plugins/inventory/mcp/package.json +21 -0
  85. package/payload/platform/plugins/memory/references/schema-retail.md +20 -0
  86. package/payload/platform/scripts/lib/provision-account-dir.sh +0 -2
  87. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.d.ts +19 -0
  88. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.d.ts.map +1 -0
  89. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.js +146 -0
  90. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.js.map +1 -0
  91. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  92. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +8 -0
  93. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  94. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts +5 -0
  95. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts.map +1 -1
  96. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js +5 -5
  97. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js.map +1 -1
  98. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +11 -1
  99. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  100. package/payload/platform/services/claude-session-manager/dist/http-server.js +124 -17
  101. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  102. package/payload/platform/services/claude-session-manager/dist/index.js +25 -13
  103. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  104. package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts +6 -1
  105. package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts.map +1 -1
  106. package/payload/platform/services/claude-session-manager/dist/pty-census.js +6 -3
  107. package/payload/platform/services/claude-session-manager/dist/pty-census.js.map +1 -1
  108. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts +21 -8
  109. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
  110. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +38 -15
  111. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
  112. package/payload/platform/services/claude-session-manager/dist/public-spawn-model.d.ts +28 -0
  113. package/payload/platform/services/claude-session-manager/dist/public-spawn-model.d.ts.map +1 -0
  114. package/payload/platform/services/claude-session-manager/dist/public-spawn-model.js +58 -0
  115. package/payload/platform/services/claude-session-manager/dist/public-spawn-model.js.map +1 -0
  116. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +2 -0
  117. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
  118. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +4 -1
  119. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
  120. package/payload/platform/services/claude-session-manager/dist/reaper.d.ts +3 -0
  121. package/payload/platform/services/claude-session-manager/dist/reaper.d.ts.map +1 -1
  122. package/payload/platform/services/claude-session-manager/dist/reaper.js +2 -1
  123. package/payload/platform/services/claude-session-manager/dist/reaper.js.map +1 -1
  124. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.d.ts +2 -0
  125. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.d.ts.map +1 -1
  126. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.js +5 -2
  127. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.js.map +1 -1
  128. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts +2 -0
  129. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts.map +1 -1
  130. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js +5 -3
  131. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js.map +1 -1
  132. package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts +26 -16
  133. package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts.map +1 -1
  134. package/payload/platform/services/claude-session-manager/dist/systemd-scope.js +84 -31
  135. package/payload/platform/services/claude-session-manager/dist/systemd-scope.js.map +1 -1
  136. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts +7 -0
  137. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts.map +1 -1
  138. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js +6 -0
  139. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js.map +1 -1
  140. package/payload/platform/services/telegram-channel/dist/notification.d.ts +10 -2
  141. package/payload/platform/services/telegram-channel/dist/notification.d.ts.map +1 -1
  142. package/payload/platform/services/telegram-channel/dist/notification.js +15 -3
  143. package/payload/platform/services/telegram-channel/dist/notification.js.map +1 -1
  144. package/payload/platform/services/telegram-channel/dist/server.d.ts +5 -0
  145. package/payload/platform/services/telegram-channel/dist/server.d.ts.map +1 -1
  146. package/payload/platform/services/telegram-channel/dist/server.js +57 -5
  147. package/payload/platform/services/telegram-channel/dist/server.js.map +1 -1
  148. package/payload/platform/services/telegram-channel/dist/turn-follow.d.ts +44 -2
  149. package/payload/platform/services/telegram-channel/dist/turn-follow.d.ts.map +1 -1
  150. package/payload/platform/services/telegram-channel/dist/turn-follow.js +188 -15
  151. package/payload/platform/services/telegram-channel/dist/turn-follow.js.map +1 -1
  152. package/payload/platform/services/webchat-channel/dist/server.d.ts +5 -0
  153. package/payload/platform/services/webchat-channel/dist/server.d.ts.map +1 -1
  154. package/payload/platform/services/webchat-channel/dist/server.js +53 -4
  155. package/payload/platform/services/webchat-channel/dist/server.js.map +1 -1
  156. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts +44 -2
  157. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts.map +1 -1
  158. package/payload/platform/services/webchat-channel/dist/turn-follow.js +188 -15
  159. package/payload/platform/services/webchat-channel/dist/turn-follow.js.map +1 -1
  160. package/payload/platform/services/whatsapp-channel/dist/instructions.d.ts +9 -0
  161. package/payload/platform/services/whatsapp-channel/dist/instructions.d.ts.map +1 -0
  162. package/payload/platform/services/whatsapp-channel/dist/instructions.js +22 -0
  163. package/payload/platform/services/whatsapp-channel/dist/instructions.js.map +1 -0
  164. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +3 -1
  165. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  166. package/payload/platform/services/whatsapp-channel/dist/notification.js +10 -2
  167. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  168. package/payload/platform/services/whatsapp-channel/dist/server.d.ts +10 -2
  169. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  170. package/payload/platform/services/whatsapp-channel/dist/server.js +71 -8
  171. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  172. package/payload/platform/services/whatsapp-channel/dist/turn-follow.d.ts +34 -2
  173. package/payload/platform/services/whatsapp-channel/dist/turn-follow.d.ts.map +1 -1
  174. package/payload/platform/services/whatsapp-channel/dist/turn-follow.js +153 -15
  175. package/payload/platform/services/whatsapp-channel/dist/turn-follow.js.map +1 -1
  176. package/payload/server/server.js +254 -96
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * MCP spawn-tee — in-process stderr capture + lifecycle observability.
5
+ *
6
+ * Claude Code spawns each MCP server itself; the platform never holds a
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.
13
+ *
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 → raw sink + passthrough
17
+ *
18
+ * Destinations:
19
+ * - `${LOG_DIR}/mcp-<name>-<SESSION_ID>.log` — raw stderr + lifecycle lines.
20
+ * The sole raw sink. Task 1721 retired the per-date twin: its date was
21
+ * pinned at spawn, no reader ever parsed it, and a since-removed stderr
22
+ * tee wrote the same file, so every line landed twice.
23
+ * - `${LOG_DIR}/mcp-<name>-nosession.log` — the same, for a spawn with
24
+ * no SESSION_ID (enumeration). One fixed file per server.
25
+ * - `server.log` via the loopback log-ingest route — best-effort mirror of
26
+ * the [mcp-helper] lifecycle lines.
27
+ *
28
+ * Lifecycle lines, correlation key `session=<id8> server=<name>` — unchanged:
29
+ * [mcp-helper] op=spawn ... pid= entry=
30
+ * [mcp-helper] op=boot ... head=<first stderr bytes>
31
+ * [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
32
+ *
33
+ * Process model (Task 989): the shim IS the server's process. op=exit fires
34
+ * from process.on("exit"), so it covers a normal exit, a non-zero exit, an
35
+ * uncaught throw (code 1), and a catchable-signal exit (SIGTERM/SIGINT/SIGHUP,
36
+ * whose handlers record the signal name). An external SIGKILL is uncatchable
37
+ * and leaves no op=exit line — the per-session stderr tail already on disk and
38
+ * Claude Code's own transport-drop are the evidence for that death mode.
39
+ *
40
+ * The shim never writes to fd 1 (stdout) — that is the JSON-RPC channel.
41
+ */
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ const node_fs_1 = require("node:fs");
44
+ const node_path_1 = require("node:path");
45
+ const node_url_1 = require("node:url");
46
+ const SERVER_NAME = process.env.MCP_SPAWN_TEE_NAME ?? "unknown";
47
+ const LOG_DIR = process.env.LOG_DIR;
48
+ const SESSION_ID = process.env.SESSION_ID;
49
+ const PLATFORM_PORT = process.env.PLATFORM_PORT;
50
+ const ENTRY = process.argv[2];
51
+ const SESSION_ID8 = SESSION_ID ? SESSION_ID.slice(0, 8) : "—";
52
+ const spawnStamp = Date.now();
53
+ // The one raw sink (Task 1721). A sessionless spawn (rc-daemon stamps
54
+ // SESSION_ID='' — rc-daemon.ts:513 — while still stamping LOG_DIR) shares one
55
+ // fixed file per server rather than a date-named one: the date was never read
56
+ // by any reader and named a process lifetime, not a day. Interleaved spawns in
57
+ // the nosession file are separated by the [mcp-helper] op=spawn pid= lines.
58
+ const rawSinkPath = LOG_DIR
59
+ ? (0, node_path_1.resolve)(LOG_DIR, SESSION_ID ? `mcp-${SERVER_NAME}-${SESSION_ID}.log` : `mcp-${SERVER_NAME}-nosession.log`)
60
+ : undefined;
61
+ // Rolling tail of entry stderr for op=exit. Capped so a chatty server cannot
62
+ // grow the buffer without bound.
63
+ const TAIL_CAP = 2048;
64
+ let stderrTail = "";
65
+ let bootEmitted = false;
66
+ let exitEmitted = false;
67
+ let exitSignal;
68
+ // The real stderr writer, captured before the tee replaces it. Lifecycle lines
69
+ // and stderr passthrough both go through this so they are never re-teed into
70
+ // the raw sink nor recursed back into the patched writer.
71
+ const rawStderrWrite = process.stderr.write.bind(process.stderr);
72
+ // LOG_DIR is created once, lazily, on the first successful append — not per
73
+ // chunk. teeWrite runs on the server's own stderr hot path now, so a per-call
74
+ // mkdirSync would be two syscalls per log line for nothing.
75
+ let logDirReady = false;
76
+ function appendSafe(path, data) {
77
+ if (!path || !LOG_DIR)
78
+ return;
79
+ try {
80
+ if (!logDirReady) {
81
+ (0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
82
+ logDirReady = true;
83
+ }
84
+ (0, node_fs_1.appendFileSync)(path, data);
85
+ }
86
+ catch {
87
+ /* unwritable destination — never mask primary output */
88
+ }
89
+ }
90
+ // Best-effort mirror of a lifecycle line to server.log via the loopback
91
+ // log-ingest route. Fire-and-forget: the per-session file is authoritative, so
92
+ // a dropped POST loses nothing. On the "exit" event the loop is stopping, so
93
+ // the op=exit mirror may not flush — the per-session line, written sync, holds.
94
+ function postToServerLog(suffix, level) {
95
+ if (!PLATFORM_PORT)
96
+ return;
97
+ try {
98
+ const ctrl = new AbortController();
99
+ const t = setTimeout(() => ctrl.abort(), 500);
100
+ t.unref?.(); // never let the abort timer keep the shim's event loop alive
101
+ void fetch(`http://127.0.0.1:${PLATFORM_PORT}/api/admin/log-ingest`, {
102
+ method: "POST",
103
+ headers: { "content-type": "application/json" },
104
+ body: JSON.stringify({ tag: "mcp-helper", level, line: suffix }),
105
+ signal: ctrl.signal,
106
+ }).then(() => clearTimeout(t)).catch(() => clearTimeout(t));
107
+ }
108
+ catch {
109
+ /* fetch threw synchronously — best-effort only */
110
+ }
111
+ }
112
+ // Emit one [mcp-helper] lifecycle line: authoritative per-session file (sync,
113
+ // survives process.exit), the shim's own stderr via the RAW writer (journald /
114
+ // Claude Code visibility, never re-teed), and a best-effort server.log mirror.
115
+ // `suffix` is the line body after the tag and carries no newline (the
116
+ // log-ingest route rejects newlines).
117
+ function emitLifecycle(suffix, level) {
118
+ const line = `[mcp-helper] ${suffix}\n`;
119
+ appendSafe(rawSinkPath, line);
120
+ try {
121
+ rawStderrWrite(line);
122
+ }
123
+ catch { /* stderr closed */ }
124
+ postToServerLog(suffix, level);
125
+ }
126
+ if (!ENTRY) {
127
+ emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason="no entry given (argv[2] missing)"`, "error");
128
+ process.exit(2);
129
+ }
130
+ // Replace process.stderr.write with a tee: mirror every server stderr byte to
131
+ // the raw sink, keep a rolling tail for op=exit, emit
132
+ // op=boot on the first bytes, then pass the write through to the real stderr.
133
+ const teeWrite = ((...args) => {
134
+ const chunk = args[0];
135
+ appendSafe(rawSinkPath, chunk); // raw sink (Task 1721)
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
144
+ });
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);
162
+ }
163
+ };
164
+ }
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;
175
+ const lifetimeMs = Date.now() - spawnStamp;
176
+ const tail = stderrTail.slice(-200);
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
+ // Task 2356 — present argv as a direct `node <entry>` invocation before the
184
+ // entry loads. The shim is meant to be transparent: an entry that asks the
185
+ // standard "am I the entry module?" question
186
+ // (`import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href`)
187
+ // must get the same answer it gets when Claude Code runs it without the shim.
188
+ // With the shim's own path left in argv[1] the answer is no, so such an entry
189
+ // loads, starts nothing, and exits 0 — measured on the three channel servers,
190
+ // which all gate main() that way. Plugin MCPs connect at module top level and
191
+ // never read argv, so this is inert for them. ENTRY was captured above, before
192
+ // the rewrite. Extra CLI args keep their positions after the entry slot.
193
+ process.argv = [process.argv[0], ENTRY, ...process.argv.slice(3)];
194
+ // Run the real MCP server in THIS process. Dynamic import() (not top-level
195
+ // await — this file compiles to CommonJS) loads the ESM entry; a load-time
196
+ // failure mirrors the old child spawn-error path (op=error, exit 127). The
197
+ // op=exit handler is suppressed on this path so op=error stays the sole record.
198
+ import((0, node_url_1.pathToFileURL)(ENTRY).href).catch((err) => {
199
+ const msg = err instanceof Error ? err.message : String(err);
200
+ exitEmitted = true;
201
+ emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason=${JSON.stringify(`import error: ${msg}`)}`, "error");
202
+ process.exit(127);
203
+ });
204
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,241 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { eagerTool } from "../../../../lib/mcp-eager/dist/index.js";
4
+ import { writeNodeWithEdges } from "../../../../lib/graph-write/dist/index.js";
5
+ import { z } from "zod";
6
+ import { closeDriver, getSession } from "./lib/neo4j.js";
7
+ import { readDemandHistory, readPlanCandidates, resolveLocation, resolveProductBySku, setSupplierTerms, } from "./lib/read.js";
8
+ import { replenishPlan, } from "./tools/replenish-plan.js";
9
+ import { purchaseOrderRecord, } from "./tools/purchase-order-record.js";
10
+ import { forecast } from "./tools/forecast.js";
11
+ import { policySet } from "./tools/policy-set.js";
12
+ import { supplierTermsSet, } from "./tools/supplier-terms-set.js";
13
+ import { stockRecord } from "./tools/stock-record.js";
14
+ import { demandRecord } from "./tools/demand-record.js";
15
+ import { countWriteRejects24h } from "./lib/write-rejects.js";
16
+ const server = new McpServer({ name: "maxy-inventory", version: "0.1.0" });
17
+ // Plugin-system boot tolerance. Module init must never throw: plugin-system
18
+ // spawn enumerates tools/list with empty env, and a boot throw empties the
19
+ // registry for every plugin. Refusal is per call, which preserves account
20
+ // isolation without breaking enumeration.
21
+ const accountId = process.env.ACCOUNT_ID ?? null;
22
+ const logDir = process.env.LOG_DIR;
23
+ const agentSlug = process.env.AGENT_SLUG;
24
+ const sessionId = process.env.SESSION_ID;
25
+ process.stderr.write(`[inventory] boot accountId=${accountId ?? "-"} sessionId=${sessionId || "-"} agentSlug=${agentSlug || "-"}\n`);
26
+ function refuseNoAccount(toolName) {
27
+ process.stderr.write(`[inventory] tool=${toolName} refuse reason=no-account-context\n`);
28
+ return {
29
+ content: [
30
+ {
31
+ type: "text",
32
+ text: `${toolName} cannot execute: this MCP instance was launched without ACCOUNT_ID (plugin-system metadata-only mode). Per-account writes require ACCOUNT_ID at spawn.`,
33
+ },
34
+ ],
35
+ isError: true,
36
+ };
37
+ }
38
+ // `agent` stays undefined when AGENT_SLUG is unset rather than defaulting to
39
+ // "". graph-write resolves `agent ?? source ?? "unknown"` and an empty string
40
+ // is not nullish, so a default prints a blank agent= on every reject.
41
+ const createdBy = (tool) => ({
42
+ agent: agentSlug,
43
+ session: sessionId,
44
+ tool,
45
+ source: "inventory",
46
+ });
47
+ // No cast. Casting writeNodeWithEdges is what let a dead write path ship in
48
+ // the ledger plugin.
49
+ const write = writeNodeWithEdges;
50
+ async function withSession(fn) {
51
+ const session = getSession();
52
+ try {
53
+ return await fn(session);
54
+ }
55
+ finally {
56
+ await session.close();
57
+ }
58
+ }
59
+ const stockRowShape = z.object({
60
+ sku: z.string().min(1).describe("Product SKU as it appears on the :Product node"),
61
+ location: z
62
+ .string()
63
+ .min(1)
64
+ .describe("Element id of the existing :StoreLocation. Look it up first; this tool never creates locations"),
65
+ quantityOnHand: z.number().describe("Units physically in stock at this location"),
66
+ quantityOnOrder: z
67
+ .number()
68
+ .describe("Units already on an open purchase order for this location"),
69
+ asOf: z.string().describe("ISO timestamp the count was taken, e.g. 2026-08-05T09:00:00Z"),
70
+ });
71
+ eagerTool(server, "inventory-stock-record", "Record measured stock for one or more products at a location. Parse the operator's stock export into rows first. Rows whose SKU or location cannot be resolved are rejected and named back to you; they are never written with a guessed target.", {
72
+ rows: z.array(stockRowShape).min(1).describe("One entry per product per location"),
73
+ }, async (args) => {
74
+ if (accountId === null)
75
+ return refuseNoAccount("inventory-stock-record");
76
+ return withSession((session) => stockRecord({
77
+ session,
78
+ write,
79
+ resolveProduct: resolveProductBySku,
80
+ resolveLocation,
81
+ accountId,
82
+ createdBy: createdBy("inventory-stock-record"),
83
+ ...args,
84
+ }));
85
+ });
86
+ const demandRowShape = z.object({
87
+ sku: z.string().min(1).describe("Product SKU as it appears on the :Product node"),
88
+ location: z.string().min(1).describe("Element id of the existing :StoreLocation"),
89
+ periodStart: z.string().describe("ISO date the period opens, e.g. 2026-07-01"),
90
+ periodEnd: z.string().describe("ISO date the period closes, must be after periodStart"),
91
+ quantitySold: z
92
+ .number()
93
+ .min(0)
94
+ .describe("Units sold in the period. Zero is meaningful and is stored; omit the row only when there is genuinely no data"),
95
+ });
96
+ eagerTool(server, "inventory-demand-record", "Record observed sales per product per location per period. Parse the operator's sales export into equal-length periods first, one row per product per location per period. A period with zero sales should be recorded as zero, not omitted, because the forecast reads a missing period differently from a quiet one.", {
97
+ rows: z
98
+ .array(demandRowShape)
99
+ .min(1)
100
+ .describe("One entry per product per location per period"),
101
+ }, async (args) => {
102
+ if (accountId === null)
103
+ return refuseNoAccount("inventory-demand-record");
104
+ return withSession((session) => demandRecord({
105
+ session,
106
+ write,
107
+ resolveProduct: resolveProductBySku,
108
+ resolveLocation,
109
+ accountId,
110
+ createdBy: createdBy("inventory-demand-record"),
111
+ ...args,
112
+ }));
113
+ });
114
+ eagerTool(server, "inventory-policy-set", "Set how hard to try to stay in stock for one product at one location, and how often the operator reviews reordering. Ask the operator for both rather than assuming: a 95% service level and a weekly review are common but neither is a safe default.", {
115
+ sku: z.string().min(1).describe("Product SKU"),
116
+ location: z.string().min(1).describe("Element id of the :StoreLocation"),
117
+ serviceLevel: z
118
+ .number()
119
+ .gt(0)
120
+ .lt(1)
121
+ .describe("Target in-stock probability, e.g. 0.95. Strictly between 0 and 1"),
122
+ reviewPeriodDays: z
123
+ .number()
124
+ .positive()
125
+ .describe("Days between reorder reviews, e.g. 7 for a weekly order"),
126
+ }, async (args) => {
127
+ if (accountId === null)
128
+ return refuseNoAccount("inventory-policy-set");
129
+ return withSession((session) => policySet({
130
+ session,
131
+ write,
132
+ resolveProduct: resolveProductBySku,
133
+ resolveLocation,
134
+ accountId,
135
+ createdBy: createdBy("inventory-policy-set"),
136
+ ...args,
137
+ }));
138
+ });
139
+ eagerTool(server, "inventory-supplier-terms-set", "Set lead time, minimum order, pack multiple and unit cost for a product from a given supplier. The product must already be linked to the supplier; this tool never creates that link.", {
140
+ sku: z.string().min(1).describe("Product SKU"),
141
+ supplierNodeId: z
142
+ .string()
143
+ .min(1)
144
+ .describe("Element id of the existing :Organization the product is SUPPLIED_BY"),
145
+ leadTimeDays: z
146
+ .number()
147
+ .min(0)
148
+ .describe("Whole days from placing the order to it arriving"),
149
+ minimumOrderQuantity: z
150
+ .number()
151
+ .min(0)
152
+ .describe("Smallest order the supplier accepts. Use 0 when there is no minimum"),
153
+ orderMultiple: z
154
+ .number()
155
+ .positive()
156
+ .describe("Pack size orders must be a multiple of. Use 1 when they ship singles"),
157
+ unitCost: z.number().min(0).describe("Cost per unit in the account's currency"),
158
+ }, async (args) => {
159
+ if (accountId === null)
160
+ return refuseNoAccount("inventory-supplier-terms-set");
161
+ return withSession((session) => supplierTermsSet({
162
+ session,
163
+ resolveProduct: resolveProductBySku,
164
+ setTerms: setSupplierTerms,
165
+ accountId,
166
+ ...args,
167
+ }));
168
+ });
169
+ eagerTool(server, "inventory-forecast", "Expected demand per period for one product at one location, worked out from recorded sales history. Nothing is stored; the figure is derived on every call. An empty history is reported as an error rather than as zero demand, because those mean opposite things.", {
170
+ sku: z.string().min(1).describe("Product SKU"),
171
+ location: z.string().min(1).describe("Element id of the :StoreLocation"),
172
+ window: z
173
+ .number()
174
+ .int()
175
+ .positive()
176
+ .describe("How many trailing periods to average, e.g. 8 for eight weeks of weekly data"),
177
+ }, async (args) => {
178
+ if (accountId === null)
179
+ return refuseNoAccount("inventory-forecast");
180
+ return withSession((session) => forecast({
181
+ session,
182
+ resolveProduct: resolveProductBySku,
183
+ readHistory: readDemandHistory,
184
+ accountId,
185
+ ...args,
186
+ }));
187
+ });
188
+ eagerTool(server, "inventory-replenish-plan", "What to reorder at one location, how much, and from whom. Returns the oldest and newest stock timestamps it read, so state the age of the data when you report the result. Lines that could not be worked out come back named with the missing input; do not fill those in yourself, ask the operator for the value and record it with the matching set tool.", {
189
+ location: z.string().min(1).describe("Element id of the :StoreLocation to plan for"),
190
+ window: z
191
+ .number()
192
+ .int()
193
+ .positive()
194
+ .describe("How many trailing demand periods to average, e.g. 8"),
195
+ periodDays: z
196
+ .number()
197
+ .positive()
198
+ .describe("Length of one demand period in days, e.g. 7 when the sales export is weekly"),
199
+ today: z.string().describe("ISO date to treat as the order date, e.g. 2026-08-05"),
200
+ }, async (args) => {
201
+ if (accountId === null)
202
+ return refuseNoAccount("inventory-replenish-plan");
203
+ return withSession((session) => replenishPlan({
204
+ session,
205
+ readCandidates: readPlanCandidates,
206
+ accountId,
207
+ recentWriteRejects: logDir ? countWriteRejects24h(logDir, Date.now()) : 0,
208
+ ...args,
209
+ }));
210
+ });
211
+ eagerTool(server, "inventory-purchase-order-record", "Record a purchase order the operator has confirmed. Confirm the lines and the supplier with the operator before calling this. It records the order in the graph and does not send anything to the supplier, so tell the operator they still need to place it.", {
212
+ supplierNodeId: z.string().min(1).describe("Element id of the supplier :Organization"),
213
+ orderDate: z.string().describe("ISO date the order is placed, e.g. 2026-08-05"),
214
+ expectedDelivery: z
215
+ .string()
216
+ .describe("ISO date the order should arrive, from the plan's expectedArrival"),
217
+ lines: z
218
+ .array(z.object({
219
+ sku: z.string().min(1).describe("Product SKU"),
220
+ quantity: z.number().positive().describe("Units ordered"),
221
+ }))
222
+ .min(1)
223
+ .describe("The confirmed order lines"),
224
+ }, async (args) => {
225
+ if (accountId === null)
226
+ return refuseNoAccount("inventory-purchase-order-record");
227
+ return withSession((session) => purchaseOrderRecord({
228
+ session,
229
+ write,
230
+ accountId,
231
+ createdBy: createdBy("inventory-purchase-order-record"),
232
+ ...args,
233
+ }));
234
+ });
235
+ const transport = new StdioServerTransport();
236
+ await server.connect(transport);
237
+ process.on("SIGTERM", async () => {
238
+ await closeDriver();
239
+ process.exit(0);
240
+ });
241
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[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AAE,SAAS,CAAC,iCAAiC,CAAC;QACvD,GAAI,IAAmD;KACxD,CAAC,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAEhC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IAC/B,MAAM,WAAW,EAAE,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Task 2448 — demand forecast.
3
+ *
4
+ * A trailing moving average, deliberately: it is the smallest method that is
5
+ * defensible and testable with plain numbers. It lags a trend and flattens a
6
+ * seasonal peak; replacing it is Task 2449, and because no forecast is ever
7
+ * stored, that replacement needs no migration.
8
+ */
9
+ /**
10
+ * Mean of the trailing `window` periods.
11
+ *
12
+ * A history shorter than the window averages what exists rather than padding
13
+ * with zeros: padding would read a new product's short history as a collapse
14
+ * in demand.
15
+ *
16
+ * @param quantities units sold per period, oldest first
17
+ * @param window how many trailing periods to average, at least 1
18
+ */
19
+ export declare function movingAverage(quantities: number[], window: number): number;
20
+ //# sourceMappingURL=forecast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forecast.d.ts","sourceRoot":"","sources":["../../src/lib/forecast.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAU1E"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Task 2448 — demand forecast.
3
+ *
4
+ * A trailing moving average, deliberately: it is the smallest method that is
5
+ * defensible and testable with plain numbers. It lags a trend and flattens a
6
+ * seasonal peak; replacing it is Task 2449, and because no forecast is ever
7
+ * stored, that replacement needs no migration.
8
+ */
9
+ /**
10
+ * Mean of the trailing `window` periods.
11
+ *
12
+ * A history shorter than the window averages what exists rather than padding
13
+ * with zeros: padding would read a new product's short history as a collapse
14
+ * in demand.
15
+ *
16
+ * @param quantities units sold per period, oldest first
17
+ * @param window how many trailing periods to average, at least 1
18
+ */
19
+ export function movingAverage(quantities, window) {
20
+ if (!Number.isFinite(window) || window < 1) {
21
+ throw new Error(`[inventory] movingAverage: window must be at least 1, got ${window}`);
22
+ }
23
+ if (quantities.length === 0)
24
+ return 0;
25
+ const slice = quantities.slice(-Math.floor(window));
26
+ const total = slice.reduce((sum, n) => sum + n, 0);
27
+ return total / slice.length;
28
+ }
29
+ //# sourceMappingURL=forecast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forecast.js","sourceRoot":"","sources":["../../src/lib/forecast.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,UAAoB,EAAE,MAAc;IAChE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,6DAA6D,MAAM,EAAE,CACtE,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Driver, Session } from "neo4j-driver";
2
+ export declare function getDriver(): Driver;
3
+ export declare function getSession(): Session;
4
+ export declare function closeDriver(): Promise<void>;
5
+ //# sourceMappingURL=neo4j.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neo4j.d.ts","sourceRoot":"","sources":["../../src/lib/neo4j.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAuBtD,wBAAgB,SAAS,IAAI,MAAM,CAgBlC;AAED,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAKjD"}
@@ -0,0 +1,40 @@
1
+ import neo4j from "neo4j-driver";
2
+ import { readFileSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ let driver = null;
5
+ function readPassword() {
6
+ if (process.env.NEO4J_PASSWORD)
7
+ return process.env.NEO4J_PASSWORD;
8
+ const passwordFile = resolve(process.env.PLATFORM_ROOT ?? resolve(import.meta.dirname, "../../../.."), "config/.neo4j-password");
9
+ try {
10
+ return readFileSync(passwordFile, "utf-8").trim();
11
+ }
12
+ catch {
13
+ throw new Error(`Neo4j password not found. Expected at ${passwordFile} or in NEO4J_PASSWORD env var.`);
14
+ }
15
+ }
16
+ export function getDriver() {
17
+ if (!driver) {
18
+ // NEO4J_URI must be explicit. A silent default to :7687 was the vector for
19
+ // orphan data in one brand's database written by another brand's install.
20
+ const uri = process.env.NEO4J_URI;
21
+ if (!uri) {
22
+ throw new Error("[inventory] NEO4J_URI unset — refusing to default to bolt://localhost:7687");
23
+ }
24
+ const user = process.env.NEO4J_USER ?? "neo4j";
25
+ const password = readPassword();
26
+ console.error(`[inventory] resolved neo4j_uri=${uri}`);
27
+ driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
28
+ }
29
+ return driver;
30
+ }
31
+ export function getSession() {
32
+ return getDriver().session();
33
+ }
34
+ export async function closeDriver() {
35
+ if (driver) {
36
+ await driver.close();
37
+ driver = null;
38
+ }
39
+ }
40
+ //# sourceMappingURL=neo4j.js.map
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I,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Session } from "neo4j-driver";
2
+ import type { PlanCandidate } from "./types.js";
3
+ /** Everything the plan needs for one location, in one query. OPTIONAL MATCH
4
+ * throughout rather than MATCH: a product missing its policy or supplier
5
+ * terms must still come back, as a skipped line naming what is missing. A
6
+ * plain MATCH would drop it and the plan would look complete while silently
7
+ * omitting exactly the products that need operator attention. */
8
+ export declare function readPlanCandidates(session: Session, accountId: string, location: string): Promise<PlanCandidate[]>;
9
+ /** Resolves a SKU to a :Product element id on this account. Null when absent
10
+ * or when the SKU is ambiguous — two products sharing a SKU is a data fault
11
+ * the operator must fix, not something to guess past. */
12
+ export declare function resolveProductBySku(session: Session, accountId: string, sku: string): Promise<string | null>;
13
+ /** Units sold per period for one product at one location, oldest first. */
14
+ export declare function readDemandHistory(session: Session, accountId: string, productNodeId: string, location: string): Promise<number[]>;
15
+ export interface SupplierTerms {
16
+ leadTimeDays: number;
17
+ minimumOrderQuantity: number;
18
+ orderMultiple: number;
19
+ unitCost: number;
20
+ }
21
+ /** Sets the commercial terms on an existing SUPPLIED_BY edge. Returns false
22
+ * when no such edge exists: the edge is the operator's assertion that this
23
+ * supplier supplies this product, and creating it here would let a typo
24
+ * invent a supply relationship. */
25
+ export declare function setSupplierTerms(session: Session, accountId: string, productNodeId: string, supplierNodeId: string, terms: SupplierTerms): Promise<boolean>;
26
+ /** Confirms a :StoreLocation element id exists on this account. */
27
+ export declare function resolveLocation(session: Session, accountId: string, nodeId: string): Promise<boolean>;
28
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/lib/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAUhD;;;;kEAIkE;AAClE,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,EAAE,CAAC,CAwC1B;AAED;;0DAE0D;AAC1D,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASxB;AAED,2EAA2E;AAC3E,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,EAAE,CAAC,CAWnB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;oCAGoC;AACpC,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,OAAO,CAAC,CAalB;AAED,mEAAmE;AACnE,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CASlB"}