@reticlehq/server 2.8.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/SKILL.md +130 -813
  2. package/dist/bridge/bridge.d.ts +23 -0
  3. package/dist/bridge/bridge.js +80 -2
  4. package/dist/bridge/bridge.test-harness.d.ts +5 -0
  5. package/dist/bridge/bridge.test-harness.js +6 -4
  6. package/dist/capsule/capsule-store.d.ts +2 -2
  7. package/dist/capsule/causal-summary.d.ts +16 -1
  8. package/dist/capsule/causal-summary.js +2 -1
  9. package/dist/cli/cli-doctor.js +41 -13
  10. package/dist/cli/cli-flow-commands.js +8 -8
  11. package/dist/cli/cli-launch.d.ts +0 -17
  12. package/dist/cli/cli-launch.js +0 -28
  13. package/dist/cli/cli-parse.d.ts +1 -1
  14. package/dist/cli/cli-parse.js +1 -1
  15. package/dist/cli/cli-port.d.ts +24 -0
  16. package/dist/cli/cli-port.js +66 -35
  17. package/dist/cli/cli-verify.d.ts +21 -0
  18. package/dist/cli/cli-verify.js +45 -1
  19. package/dist/cli/config-discovery.d.ts +35 -0
  20. package/dist/cli/config-discovery.js +163 -0
  21. package/dist/cli/doctor-daemon-line.js +4 -1
  22. package/dist/cli/doctor-project-line.d.ts +37 -0
  23. package/dist/cli/doctor-project-line.js +35 -0
  24. package/dist/cli/doctor-rows.d.ts +51 -0
  25. package/dist/cli/doctor-rows.js +54 -0
  26. package/dist/cli/doctor-sessions-line.js +6 -3
  27. package/dist/cli/drive-attach.d.ts +99 -0
  28. package/dist/cli/drive-attach.js +203 -0
  29. package/dist/cli/drive-command.d.ts +13 -0
  30. package/dist/cli/drive-command.js +103 -0
  31. package/dist/cli/open-note.d.ts +20 -0
  32. package/dist/cli/open-note.js +37 -0
  33. package/dist/cli/status-next-action.d.ts +37 -0
  34. package/dist/cli/status-next-action.js +61 -0
  35. package/dist/cli.js +65 -70
  36. package/dist/crawl/crawl.d.ts +7 -2
  37. package/dist/crawl/crawl.js +52 -9
  38. package/dist/ee/audit-log.js +2 -2
  39. package/dist/events/body-failures.d.ts +2 -2
  40. package/dist/events/contradiction-folds.d.ts +45 -0
  41. package/dist/events/contradiction-folds.js +42 -0
  42. package/dist/events/contradictions.d.ts +51 -1
  43. package/dist/events/contradictions.js +26 -7
  44. package/dist/events/declared.d.ts +45 -0
  45. package/dist/events/declared.js +73 -0
  46. package/dist/events/echo-mismatch.d.ts +9 -3
  47. package/dist/events/echo-mismatch.js +33 -5
  48. package/dist/events/event-filters.d.ts +1 -1
  49. package/dist/events/event-filters.js +7 -4
  50. package/dist/events/predicate-eval.d.ts +17 -91
  51. package/dist/events/predicate-eval.js +85 -326
  52. package/dist/events/predicate-parse.js +31 -3
  53. package/dist/events/predicate-route.d.ts +32 -0
  54. package/dist/events/predicate-route.js +102 -0
  55. package/dist/events/predicate-schema.d.ts +99 -0
  56. package/dist/events/predicate-schema.js +309 -0
  57. package/dist/events/predicate.d.ts +8 -0
  58. package/dist/events/predicate.js +127 -5
  59. package/dist/events/stale-response.d.ts +2 -3
  60. package/dist/events/stale-response.js +49 -2
  61. package/dist/events/unit-mismatch.d.ts +2 -2
  62. package/dist/flows/annotate-tools.js +3 -0
  63. package/dist/flows/annotate.js +18 -4
  64. package/dist/flows/coverage.d.ts +38 -5
  65. package/dist/flows/coverage.js +30 -4
  66. package/dist/flows/decision.d.ts +15 -0
  67. package/dist/flows/decision.js +1 -1
  68. package/dist/flows/flow-replay-run.js +8 -1
  69. package/dist/flows/flow-tools.js +9 -1
  70. package/dist/flows/replay.js +3 -0
  71. package/dist/flows/verify-change-tools.js +1 -1
  72. package/dist/honesty/accepted-write.d.ts +3 -0
  73. package/dist/honesty/accepted-write.js +8 -3
  74. package/dist/honesty/already-true.js +15 -0
  75. package/dist/honesty/blind-spots.js +4 -0
  76. package/dist/honesty/honesty.d.ts +11 -0
  77. package/dist/honesty/honesty.js +1 -0
  78. package/dist/honesty/uncaptured-bodies.d.ts +4 -2
  79. package/dist/honesty/uncaptured-bodies.js +9 -2
  80. package/dist/honesty/unread-outcome.d.ts +8 -0
  81. package/dist/honesty/unread-outcome.js +36 -9
  82. package/dist/honesty/unsettled.d.ts +9 -0
  83. package/dist/honesty/unsettled.js +7 -3
  84. package/dist/honesty/verified.d.ts +29 -3
  85. package/dist/honesty/verified.js +67 -8
  86. package/dist/http-server.d.ts +19 -0
  87. package/dist/http-server.js +202 -4
  88. package/dist/impact/impact-recorder.d.ts +23 -0
  89. package/dist/impact/impact-recorder.js +76 -0
  90. package/dist/impact/impact-store.d.ts +47 -0
  91. package/dist/impact/impact-store.js +171 -0
  92. package/dist/index.d.ts +25 -0
  93. package/dist/index.js +60 -10
  94. package/dist/init/agent-rules.d.ts +20 -0
  95. package/dist/init/agent-rules.js +36 -0
  96. package/dist/init/astro-patch.js +27 -1
  97. package/dist/init/confirm.d.ts +21 -3
  98. package/dist/init/confirm.js +32 -5
  99. package/dist/init/connect-steps.d.ts +2 -0
  100. package/dist/init/connect-steps.js +50 -0
  101. package/dist/init/csp-check.d.ts +38 -0
  102. package/dist/init/csp-check.js +92 -0
  103. package/dist/init/csp-doctor.d.ts +25 -0
  104. package/dist/init/csp-doctor.js +49 -0
  105. package/dist/init/cursor.js +6 -9
  106. package/dist/init/detect.d.ts +8 -0
  107. package/dist/init/detect.js +33 -3
  108. package/dist/init/mcp-clients.d.ts +1 -0
  109. package/dist/init/mcp-clients.js +51 -7
  110. package/dist/init/mcp.d.ts +16 -2
  111. package/dist/init/mcp.js +23 -1
  112. package/dist/init/plan-framework.d.ts +10 -0
  113. package/dist/init/plan-framework.js +25 -1
  114. package/dist/init/plan.d.ts +7 -2
  115. package/dist/init/plan.js +66 -30
  116. package/dist/init/run.js +11 -5
  117. package/dist/init/slash-command.d.ts +1 -1
  118. package/dist/init/slash-command.js +12 -4
  119. package/dist/init/snippets.d.ts +1 -1
  120. package/dist/init/snippets.js +35 -7
  121. package/dist/init/vite-config.js +24 -2
  122. package/dist/input/network-mock-tools.js +8 -1
  123. package/dist/input/scroll-find.d.ts +6 -0
  124. package/dist/input/scroll-find.js +17 -2
  125. package/dist/input/scroll-tools.js +4 -0
  126. package/dist/journal/attach-journal.d.ts +9 -1
  127. package/dist/journal/attach-journal.js +13 -2
  128. package/dist/journal/journal-query.d.ts +13 -0
  129. package/dist/journal/journal-query.js +28 -3
  130. package/dist/journal/workspace-gitignore.d.ts +10 -0
  131. package/dist/journal/workspace-gitignore.js +59 -0
  132. package/dist/license/license.d.ts +69 -4
  133. package/dist/license/license.js +84 -15
  134. package/dist/mcp/mcp-proxy.d.ts +7 -93
  135. package/dist/mcp/mcp-proxy.js +183 -250
  136. package/dist/mcp/mcp.d.ts +27 -2
  137. package/dist/mcp/mcp.js +77 -36
  138. package/dist/mcp/proxy-daemon-probe.d.ts +8 -0
  139. package/dist/mcp/proxy-daemon-probe.js +48 -0
  140. package/dist/mcp/proxy-handshake.d.ts +82 -1
  141. package/dist/mcp/proxy-handshake.js +110 -3
  142. package/dist/mcp/proxy-lifecycle.d.ts +10 -1
  143. package/dist/mcp/proxy-lifecycle.js +11 -2
  144. package/dist/mcp/proxy-log.d.ts +63 -0
  145. package/dist/mcp/proxy-log.js +132 -0
  146. package/dist/mcp/server-instructions.d.ts +17 -0
  147. package/dist/mcp/server-instructions.js +56 -0
  148. package/dist/mcp/shared-params.d.ts +27 -0
  149. package/dist/mcp/shared-params.js +36 -0
  150. package/dist/mcp/sse-frame-parser.d.ts +19 -0
  151. package/dist/mcp/sse-frame-parser.js +41 -0
  152. package/dist/project/reticle-dir.d.ts +2 -0
  153. package/dist/project/reticle-dir.js +1 -0
  154. package/dist/session/connection-memory.d.ts +59 -0
  155. package/dist/session/connection-memory.js +108 -0
  156. package/dist/session/dev-command.d.ts +26 -0
  157. package/dist/session/dev-command.js +89 -0
  158. package/dist/session/dev-server-probe.d.ts +68 -0
  159. package/dist/session/dev-server-probe.js +102 -7
  160. package/dist/session/last-act.d.ts +26 -0
  161. package/dist/session/last-act.js +35 -1
  162. package/dist/session/live-control-tools.js +42 -5
  163. package/dist/session/no-session-diagnosis.d.ts +55 -2
  164. package/dist/session/no-session-diagnosis.js +199 -22
  165. package/dist/session/no-session-next-action.d.ts +46 -0
  166. package/dist/session/no-session-next-action.js +85 -0
  167. package/dist/session/no-session-watch.d.ts +40 -1
  168. package/dist/session/no-session-watch.js +172 -11
  169. package/dist/session/pending-commands.d.ts +12 -0
  170. package/dist/session/pending-commands.js +13 -1
  171. package/dist/session/session-manager.d.ts +4 -0
  172. package/dist/session/session-manager.js +35 -5
  173. package/dist/session/session-readiness.js +1 -1
  174. package/dist/session/session.d.ts +10 -1
  175. package/dist/session/session.js +146 -5
  176. package/dist/telemetry/app-instrumented.d.ts +8 -0
  177. package/dist/telemetry/app-instrumented.js +10 -0
  178. package/dist/telemetry/bug-found.d.ts +18 -0
  179. package/dist/telemetry/bug-found.js +14 -0
  180. package/dist/telemetry/daemon-telemetry.js +29 -0
  181. package/dist/telemetry/install-source.d.ts +20 -0
  182. package/dist/telemetry/install-source.js +34 -0
  183. package/dist/telemetry/instrumentation-stall.d.ts +57 -0
  184. package/dist/telemetry/instrumentation-stall.js +103 -0
  185. package/dist/telemetry/license-activation.d.ts +48 -0
  186. package/dist/telemetry/license-activation.js +57 -0
  187. package/dist/telemetry/session-metrics.d.ts +8 -0
  188. package/dist/telemetry/session-metrics.js +10 -0
  189. package/dist/telemetry/telemetry.d.ts +3 -1
  190. package/dist/telemetry/telemetry.js +23 -3
  191. package/dist/tools/act-tools.js +166 -29
  192. package/dist/tools/assert-verdict.js +32 -7
  193. package/dist/tools/browser-tools.js +10 -0
  194. package/dist/tools/dynamic-tools.js +17 -8
  195. package/dist/tools/error-recovery.js +10 -6
  196. package/dist/tools/feedback-tools.js +31 -6
  197. package/dist/tools/invoke-tool.d.ts +1 -1
  198. package/dist/tools/invoke-tool.js +30 -8
  199. package/dist/tools/lease-hint.d.ts +30 -8
  200. package/dist/tools/lease-hint.js +65 -14
  201. package/dist/tools/lease-tools.d.ts +11 -0
  202. package/dist/tools/lease-tools.js +141 -96
  203. package/dist/tools/observe-tools.js +9 -3
  204. package/dist/tools/react-grace.d.ts +4 -0
  205. package/dist/tools/react-grace.js +6 -3
  206. package/dist/tools/read-tools.js +47 -1
  207. package/dist/tools/resolve-target.d.ts +33 -0
  208. package/dist/tools/resolve-target.js +53 -0
  209. package/dist/tools/settle-in-flight.d.ts +15 -0
  210. package/dist/tools/settle-in-flight.js +42 -2
  211. package/dist/tools/snapshot-delta.d.ts +3 -0
  212. package/dist/tools/snapshot-delta.js +67 -6
  213. package/dist/tools/tool-kit.d.ts +38 -3
  214. package/dist/tools/tool-names.d.ts +2 -0
  215. package/dist/tools/tool-names.js +2 -0
  216. package/dist/tools/tool-surface.d.ts +60 -0
  217. package/dist/tools/tool-surface.js +84 -19
  218. package/dist/tools/tools.js +61 -5
  219. package/dist/tools/unadvertised-help.js +9 -6
  220. package/docs/README.md +1 -2
  221. package/docs/actions.mdx +41 -8
  222. package/docs/agent-cheatsheet.md +6 -4
  223. package/docs/architecture.md +6 -0
  224. package/docs/benchmarks.md +60 -12
  225. package/docs/best-practices.mdx +11 -6
  226. package/docs/capabilities.mdx +204 -57
  227. package/docs/cli/affected.mdx +6 -4
  228. package/docs/cli/capsules.mdx +9 -8
  229. package/docs/cli/cloud.mdx +30 -4
  230. package/docs/cli/doctor.mdx +41 -8
  231. package/docs/cli/drive.mdx +34 -15
  232. package/docs/cli/gate.mdx +6 -6
  233. package/docs/cli/help.mdx +8 -6
  234. package/docs/cli/hunt.mdx +20 -4
  235. package/docs/cli/identify.mdx +16 -2
  236. package/docs/cli/init.mdx +35 -8
  237. package/docs/cli/kill.mdx +5 -5
  238. package/docs/cli/license.mdx +1 -1
  239. package/docs/cli/open.mdx +6 -0
  240. package/docs/cli/restart.mdx +6 -6
  241. package/docs/cli/serve.mdx +10 -3
  242. package/docs/cli/status.mdx +29 -5
  243. package/docs/cli/stop.mdx +8 -0
  244. package/docs/cli/verify.mdx +20 -1
  245. package/docs/cli/version.mdx +1 -1
  246. package/docs/cli/watch.mdx +9 -2
  247. package/docs/cli.mdx +44 -22
  248. package/docs/debugging.md +3 -1
  249. package/docs/deploy-checks.md +31 -2
  250. package/docs/desktop.mdx +276 -80
  251. package/docs/docs.json +13 -12
  252. package/docs/enterprise.md +9 -3
  253. package/docs/faq.mdx +49 -35
  254. package/docs/fixtures.md +2 -0
  255. package/docs/flows.md +7 -5
  256. package/docs/for-agents.md +3 -3
  257. package/docs/frameworks.mdx +46 -7
  258. package/docs/gate-plan.md +4 -2
  259. package/docs/gates.md +8 -6
  260. package/docs/getting-started.md +53 -12
  261. package/docs/human-control.md +2 -0
  262. package/docs/index.mdx +43 -1
  263. package/docs/install-agentic.mdx +13 -4
  264. package/docs/install-manual.mdx +6 -4
  265. package/docs/instrumentation.mdx +7 -1
  266. package/docs/integration-patterns.md +3 -1
  267. package/docs/local-registry.md +4 -2
  268. package/docs/multi-agent-testing.md +3 -1
  269. package/docs/packages/babel-plugin.mdx +15 -6
  270. package/docs/packages/browser.mdx +2 -2
  271. package/docs/packages/core.mdx +26 -16
  272. package/docs/packages/electron.mdx +5 -7
  273. package/docs/packages/eslint-plugin.mdx +5 -3
  274. package/docs/packages/next.mdx +3 -5
  275. package/docs/packages/react.mdx +3 -3
  276. package/docs/packages/server.mdx +2 -2
  277. package/docs/packages/tauri.mdx +6 -6
  278. package/docs/packages/test.mdx +18 -7
  279. package/docs/packages/vite-plugin.mdx +4 -6
  280. package/docs/packages.mdx +14 -13
  281. package/docs/platform-integration.md +2 -0
  282. package/docs/predicates.mdx +76 -7
  283. package/docs/quickstart.mdx +51 -5
  284. package/docs/recipes.mdx +63 -23
  285. package/docs/skill-file.mdx +3 -1
  286. package/docs/state-management.mdx +2 -0
  287. package/docs/system-map.md +3 -1
  288. package/docs/telemetry-contract.md +33 -5
  289. package/docs/telemetry-events.mdx +63 -18
  290. package/docs/telemetry.md +8 -5
  291. package/docs/testing.md +35 -1
  292. package/docs/token-efficiency.md +8 -2
  293. package/docs/tools-act-and-wait.mdx +64 -14
  294. package/docs/tools-act-sequence.mdx +34 -17
  295. package/docs/tools-act.mdx +24 -11
  296. package/docs/tools-assert.mdx +69 -10
  297. package/docs/tools-console.mdx +11 -7
  298. package/docs/tools-inspect.mdx +11 -8
  299. package/docs/tools-navigate.mdx +41 -5
  300. package/docs/tools-network.mdx +42 -9
  301. package/docs/tools-observe.mdx +66 -10
  302. package/docs/tools-overview.mdx +26 -23
  303. package/docs/tools-query.mdx +52 -8
  304. package/docs/tools-session-and-feedback.mdx +35 -9
  305. package/docs/tools-sessions.mdx +39 -10
  306. package/docs/tools-snapshot.mdx +57 -3
  307. package/docs/tools-state.mdx +24 -1
  308. package/docs/tools-tools-and-run.mdx +55 -24
  309. package/docs/tools-wait-for.mdx +34 -15
  310. package/docs/troubleshooting.mdx +80 -10
  311. package/docs/usage.md +46 -24
  312. package/docs/vs-chrome-devtools-mcp.mdx +41 -0
  313. package/docs/vs-playwright-mcp.mdx +42 -2
  314. package/docs/vs-screenshots.mdx +42 -1
  315. package/docs/what-is-reticle.mdx +1 -1
  316. package/docs/why-reticle.mdx +3 -1
  317. package/package.json +5 -5
  318. package/docs/desktop-apps.md +0 -265
@@ -1,31 +1,34 @@
1
1
  import * as http from 'node:http';
2
- import { localInitializeResponse, isHandshakeLine } from './proxy-handshake.js';
2
+ import { localInitializeResponse, isHandshakeLine, drainLines, MAX_STDIN_LINE_BYTES, } from './proxy-handshake.js';
3
3
  import { ToolCatalogCache } from './tool-catalog-cache.js';
4
- import * as net from 'node:net';
5
- import { appendFileSync, mkdirSync, renameSync, statSync, truncateSync } from 'node:fs';
6
- import { homedir } from 'node:os';
7
- import { join } from 'node:path';
8
- import { LOOPBACK_HOST, MCP_SSE_PATH, ReticleDir, ReticleEnv, CONTRACT_FINGERPRINT, } from '@reticlehq/core';
4
+ import { toolsChangedNotification } from './proxy-handshake.js';
5
+ import { LOOPBACK_HOST, MCP_SSE_PATH, MCP_SHUTDOWN_EVENT, ReticleEnv, CONTRACT_FINGERPRINT, } from '@reticlehq/core';
6
+ import { SseFrameParser } from './sse-frame-parser.js';
7
+ export { SseFrameParser } from './sse-frame-parser.js';
8
+ export { probeDaemon, waitForDaemon } from './proxy-daemon-probe.js';
9
+ import { probeDaemon } from './proxy-daemon-probe.js';
9
10
  import { SERVER_VERSION } from '../version/server-version.js';
11
+ import { buildServerInstructions } from './server-instructions.js';
12
+ import { hasProjectConnectedBefore } from '../session/connection-memory.js';
13
+ import { reticleStateHome } from '../daemon/daemon.js';
14
+ import { readProjectId } from '../cli/cli-port.js';
10
15
  import { PEER_VERSION_PARAM, PEER_CONTRACT_PARAM } from '../version/peer-announce.js';
11
16
  import { onStreamDrop, onClientRequest, onReconnectBudgetSpent, onQueueExpired, OnDrop, OnRequest, } from './proxy-lifecycle.js';
12
- import { log } from '../log.js';
13
- import { MAX_DAEMON_LOG_BYTES, rotateDaemonLog } from '../daemon/daemon.js';
14
- import { OutageStage, reportMcpOutage } from './mcp-outage.js';
15
- const DEFAULT_DAEMON_READY_TIMEOUT_MS = 10_000;
17
+ import { describePresence, probePresence } from '../daemon/port-presence.js';
16
18
  /**
17
- * How long to wait for the spawned daemon's port to accept connections before giving up. The default
18
- * suits a normal machine; a slow CI/VM (heavy headless-browser launch) can raise it via the
19
- * RETICLE_DAEMON_READY_TIMEOUT_MS env var. Invalid/absent values fall back to the default.
19
+ * The same `/status` probe `doctor`, `status` and `kill` ask with. Reused rather than re-written:
20
+ * the whole defect this import closes was the proxy answering a DIFFERENT question from every other
21
+ * surface, and a second copy of the probe is how that comes back.
20
22
  */
21
- const envDaemonReadyTimeoutMs = Number(process.env['RETICLE_DAEMON_READY_TIMEOUT_MS']);
22
- const DAEMON_READY_TIMEOUT_MS = Number.isFinite(envDaemonReadyTimeoutMs) && envDaemonReadyTimeoutMs > 0
23
- ? envDaemonReadyTimeoutMs
24
- : DEFAULT_DAEMON_READY_TIMEOUT_MS;
25
- const DAEMON_POLL_INTERVAL_MS = 100;
26
- function delay(ms) {
27
- return new Promise((resolve) => setTimeout(resolve, ms));
28
- }
23
+ import { fetchStatus as fetchDaemonStatus } from '../cli/cli-launch.js';
24
+ /**
25
+ * Re-exported so every existing caller (and every spec) keeps importing the proxy's log from the
26
+ * proxy. Where the code lives is a file-size decision; where it is imported from is an API.
27
+ */
28
+ export { accountProxyLogWrite, proxyLog, proxyLogPath, PROXY_LOG_CHECK_BYTES, recoverOversizedProxyLog, setProxyLogPort, } from './proxy-log.js';
29
+ import { proxyLog } from './proxy-log.js';
30
+ import { log } from '../log.js';
31
+ import { OutageReason, OutageStage, reportMcpOutage } from './mcp-outage.js';
29
32
  /** Reconnect backoff: linear, capped, so a briefly-restarting daemon is picked up fast. */
30
33
  const RECONNECT_BASE_MS = 250;
31
34
  const RECONNECT_CAP_MS = 5_000;
@@ -52,125 +55,6 @@ export function reconnectDelayMs(attempt) {
52
55
  }
53
56
  /** JSON-RPC id the proxy uses for its own replayed `initialize` — never one the client could send. */
54
57
  export const RECONNECT_INITIALIZE_ID = '__reticle_proxy_reinit';
55
- /**
56
- * Which port this proxy serves, for the log file name. Set once at startup.
57
- *
58
- * One file per port, matching `daemon-<port>.log`. A single shared file interleaved every proxy on
59
- * the machine into one stream, so the first question anyone asks of it — "what happened to MY
60
- * session?" — needed a filter before it could be answered.
61
- */
62
- let logPort;
63
- /**
64
- * How much the proxy may append between size checks.
65
- *
66
- * Statting the file on every line would be a syscall per log line on a process that logs from a
67
- * reconnect loop. Counting what we wrote costs nothing and is exact enough, because this process is
68
- * the only writer of its own log. Well under the cap, so the cap is a cap rather than a suggestion.
69
- */
70
- export const PROXY_LOG_CHECK_BYTES = 256 * 1024;
71
- /** Appended since the last real size check. Reset by every check, whatever the check decides. */
72
- let bytesSinceProxyLogCheck = 0;
73
- /**
74
- * Keep the proxy log under the same cap as the daemon log, without a stat per write.
75
- *
76
- * Returns the new "bytes since the last check" counter, so the accounting is testable without a
77
- * filesystem. Rotation itself is `rotateDaemonLog` — the proxy log had no cap at all while the
78
- * daemon log on the SAME machine stayed small, which is the whole of this defect.
79
- */
80
- export function accountProxyLogWrite(bytesSinceCheck, written, path, deps) {
81
- const total = bytesSinceCheck + written;
82
- if (PROXY_LOG_CHECK_BYTES > total)
83
- return total;
84
- rotateDaemonLog(path, deps);
85
- return 0;
86
- }
87
- /**
88
- * Reclaim a proxy log that a previous process already let run away. Returns the bytes reclaimed.
89
- *
90
- * Reported from the field: one machine's `proxy-4400.log` reached a third of a 460GB disk and broke
91
- * builds, Docker and ordinary shell commands with ENOSPC. Nothing in Reticle degraded first, so the
92
- * failure surfaced as the operating system refusing to write files. Files like that exist on real
93
- * machines now, and the cap alone does not help them: the user should not have to find one with `du`.
94
- *
95
- * TRUNCATED IN PLACE, never renamed or unlinked. A rename moves the bytes without reclaiming a byte,
96
- * and a file that a running process still holds open keeps its blocks allocated after an unlink
97
- * until that handle closes — which is why the reporter recovered with `: > ~/.reticle/proxy-4400.log`
98
- * and why that is the operation to copy here.
99
- *
100
- * Best-effort, in the same spirit as `rotateDaemonLog`: refusing to start the MCP server over
101
- * housekeeping is strictly worse than a large file.
102
- */
103
- export function recoverOversizedProxyLog(path, deps, max = MAX_DAEMON_LOG_BYTES) {
104
- try {
105
- const size = deps.fileSize(path);
106
- if (max >= size)
107
- return 0;
108
- deps.truncateFile(path);
109
- return size;
110
- }
111
- catch {
112
- return 0;
113
- }
114
- }
115
- /** The real filesystem behind the two rotation helpers. */
116
- const proxyLogFileOps = {
117
- fileSize: (p) => statSync(p).size,
118
- renameFile: (from, to) => renameSync(from, to),
119
- truncateFile: (p) => truncateSync(p, 0),
120
- };
121
- /** Name the proxy log after the port it serves. Called before anything can log. */
122
- export function setProxyLogPort(port) {
123
- logPort = port;
124
- // The one moment we know a size check is worth its syscall, and the only place a file inherited
125
- // from an older build can be brought back under control.
126
- const reclaimed = recoverOversizedProxyLog(proxyLogPath(port), proxyLogFileOps);
127
- if (0 < reclaimed) {
128
- proxyLog('reticle_mcp_proxy_log_truncated', {
129
- port,
130
- reclaimedBytes: reclaimed,
131
- note: 'the proxy log had grown past its cap and was truncated in place to reclaim the space',
132
- });
133
- }
134
- }
135
- /** The proxy's own log file, so a silent drop leaves a readable trace the agent can go read. */
136
- export function proxyLogPath(port = logPort) {
137
- const name = port === undefined ? 'mcp-proxy.log' : `proxy-${String(port)}.log`;
138
- return join(homedir(), ReticleDir.ROOT, name);
139
- }
140
- /**
141
- * Log to stderr (which the agent host usually swallows) AND to ~/.reticle/proxy-<port>.log, which it
142
- * does not. A dropped MCP connection is invisible from the agent's side — no message, no exit code —
143
- * so the one thing that makes it diagnosable at all is a file somebody can read afterwards.
144
- *
145
- * EXPORTED because the crash handlers need it. `installProxyResilience` was wired to the bare stderr
146
- * logger, so the proxy's own uncaught exceptions and unhandled rejections — the exact events that
147
- * present to a human as "the MCP server disconnected" — were written to a stream the editor throws
148
- * away. The handler ran, the process kept serving, and the reason went nowhere. Reported as "the
149
- * proxy has no log file… when it dies the diagnostic dies with it", which was half right: the file
150
- * existed, and the one path that most needed it was not using it.
151
- */
152
- export function proxyLog(event, fields = {}) {
153
- log(event, fields);
154
- try {
155
- const dir = join(homedir(), ReticleDir.ROOT);
156
- mkdirSync(dir, { recursive: true });
157
- // WITH A TIMESTAMP. This file is the only record of an outage that survives the session, and
158
- // without one it cannot answer the two questions anyone brings to it: when did this happen, and
159
- // how often. A real 3,283-line log on a dev machine held a `gave_up` — the exact event that used
160
- // to precede `process.exit(1)` and cost the human a manual /mcp reconnect — and it was
161
- // impossible to tell whether it happened during that person's work or a test run hours earlier.
162
- // Evidence you cannot place in time is an anecdote.
163
- const path = proxyLogPath();
164
- const line = `${JSON.stringify({ t: new Date().toISOString(), event, ...fields })}\n`;
165
- appendFileSync(path, line, 'utf8');
166
- // A single proxy process is long-lived and logs from a reconnect loop, so rotating only at
167
- // startup would leave the growth this file is capable of entirely unchecked while it runs.
168
- bytesSinceProxyLogCheck = accountProxyLogWrite(bytesSinceProxyLogCheck, Buffer.byteLength(line, 'utf8'), path, proxyLogFileOps);
169
- }
170
- catch {
171
- // Logging must never be the thing that kills the proxy.
172
- }
173
- }
174
58
  function parseJsonRpc(line) {
175
59
  try {
176
60
  const parsed = JSON.parse(line);
@@ -369,79 +253,6 @@ export class HandshakeReplay {
369
253
  return true;
370
254
  }
371
255
  }
372
- /**
373
- * Incremental SSE frame parser for the MCP front door.
374
- *
375
- * A single SSE field can split across TCP reads (`da` in one chunk, `ta: {...}` in the next), and a
376
- * server may send CRLF or bare CR line endings — so the framing is stateful and edge-case-prone, yet it
377
- * carried every MCP message the agent sends and was only ever exercised end-to-end. Pulled out of the
378
- * socket handler as a pure, chunk-fed parser so those boundaries are unit-testable: feed raw chunks,
379
- * get back each complete frame (a blank line terminates a frame; `event:` names it, `data:` lines
380
- * accumulate newline-joined; `id:`/`retry:`/comments are ignored — not needed for the bridge).
381
- */
382
- export class SseFrameParser {
383
- #buffer = '';
384
- #event = '';
385
- #data = '';
386
- push(chunk) {
387
- this.#buffer += chunk;
388
- // Normalise CRLF/CR so the splitter only handles \n, then hold the trailing partial line for the
389
- // next chunk (it may complete later).
390
- const normalised = this.#buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
391
- const lines = normalised.split('\n');
392
- this.#buffer = lines.pop() ?? '';
393
- const frames = [];
394
- for (const line of lines) {
395
- if ('' === line) {
396
- if (this.#data !== '') {
397
- frames.push({ event: this.#event !== '' ? this.#event : 'message', data: this.#data });
398
- }
399
- this.#event = '';
400
- this.#data = '';
401
- }
402
- else if (line.startsWith('event:')) {
403
- this.#event = line.slice(6).trim();
404
- }
405
- else if (line.startsWith('data:')) {
406
- const val = line.slice(5).trim();
407
- this.#data = this.#data !== '' ? `${this.#data}\n${val}` : val;
408
- }
409
- }
410
- return frames;
411
- }
412
- }
413
- /**
414
- * Returns true if something is already listening on the reticle port.
415
- * Uses a plain TCP probe so we don't create a side-effectful SSE session
416
- * inside the daemon just to check reachability.
417
- */
418
- export function probeDaemon(port) {
419
- return new Promise((resolve) => {
420
- const socket = new net.Socket();
421
- socket.setTimeout(500);
422
- socket.on('connect', () => {
423
- socket.destroy();
424
- resolve(true);
425
- });
426
- socket.on('error', () => resolve(false));
427
- socket.on('timeout', () => {
428
- socket.destroy();
429
- resolve(false);
430
- });
431
- socket.connect(port, LOOPBACK_HOST);
432
- });
433
- }
434
- /** Poll until the daemon's HTTP port accepts connections or the deadline is reached. */
435
- export async function waitForDaemon(port) {
436
- const deadline = Date.now() + DAEMON_READY_TIMEOUT_MS;
437
- while (Date.now() < deadline) {
438
- const reachable = await probeDaemon(port);
439
- if (reachable)
440
- return;
441
- await delay(DAEMON_POLL_INTERVAL_MS);
442
- }
443
- throw new Error(`reticle daemon did not become ready on port ${port} within ${DAEMON_READY_TIMEOUT_MS}ms`);
444
- }
445
256
  /**
446
257
  * POST one JSON-RPC line into the daemon's session. Resolves null on success, or a short reason
447
258
  * when the request never reached a server that will answer it.
@@ -510,6 +321,24 @@ export function buildSessionUrl(rawData, port) {
510
321
  * `/mcp` could. The daemon demonstrably stays up across these drops, so the stream ending is a
511
322
  * transport event, not a shutdown: reconnect to it and replay the handshake instead of dying.
512
323
  */
324
+ /**
325
+ * The instructions this proxy should advertise when it answers the handshake itself.
326
+ *
327
+ * Same inputs the daemon uses, read from the same durable memory, so a client that happens to meet
328
+ * the proxy first is not told something different from one that meets the daemon first. Best-effort:
329
+ * an unreadable state home must never be the reason a handshake fails, so it degrades to the
330
+ * fresh-install wording rather than throwing.
331
+ */
332
+ function proxyInstructions(port) {
333
+ try {
334
+ return buildServerInstructions({
335
+ previouslyConnected: hasProjectConnectedBefore(reticleStateHome(), port, readProjectId(process.cwd())),
336
+ });
337
+ }
338
+ catch {
339
+ return buildServerInstructions({ previouslyConnected: false });
340
+ }
341
+ }
513
342
  export function startMcpProxy(port,
514
343
  /**
515
344
  * Bring a daemon back before reconnecting. Without it the proxy retried a DEAD port until the
@@ -531,6 +360,16 @@ ensureDaemon) {
531
360
  * Dormant means the next thing the CLIENT asks for is what brings Reticle back.
532
361
  */
533
362
  let dormant = false;
363
+ /**
364
+ * Deliver the proxy's own answer to a queued `initialize`, now, for a stated reason.
365
+ *
366
+ * Set by `armLocalHandshake` while the client's handshake is unanswered, and cleared once it is.
367
+ * It exists because the 12-second timer down there is a timeout for a question the proxy could
368
+ * not answer — "is a daemon coming?" — and the drop path CAN answer it: a port a stranger holds
369
+ * will never serve SSE, however long anybody waits. Declared up here with the other closure
370
+ * state so the drop path can reach it without a temporal-dead-zone hazard.
371
+ */
372
+ let deliverHandshakeLocally;
534
373
  const stdinQueue = [];
535
374
  /**
536
375
  * Fail anything still queued after QUEUE_WAIT_MS. Re-armed on every push and cleared on flush,
@@ -542,29 +381,42 @@ ensureDaemon) {
542
381
  clearTimeout(queueTimer);
543
382
  queueTimer = undefined;
544
383
  };
384
+ /**
385
+ * Answer everything queued, drop it, and go dormant.
386
+ *
387
+ * `reason` is what goes on the wire. The timer below passes the only thing a timeout can know —
388
+ * that nothing arrived — but a wake that FAILED knows something much better: exactly why it
389
+ * failed. Both used to end here after the same twenty seconds of silence, because only the timer
390
+ * could reach this code.
391
+ */
392
+ const expireQueue = (reason) => {
393
+ clearQueueTimer();
394
+ if (stopped || 0 === stdinQueue.length)
395
+ return;
396
+ // Drop what we could never send, and answer it, so the caller is never left guessing.
397
+ stdinQueue.splice(0);
398
+ for (const reply of streamLossReplies(pending, reason, queueExpiryNextStep(port))) {
399
+ emit(reply);
400
+ }
401
+ // The expiry is the proof that the reconnect we believed was in flight is not coming — a
402
+ // wedged port accepts the socket and never serves SSE, so `connect` neither resolves nor
403
+ // rejects and `dormant` would otherwise stay false forever. Going dormant is what makes the
404
+ // NEXT request re-probe the port instead of queueing behind a reconnect that will never
405
+ // land, and it is the only path by which a daemon started AFTER we gave up is ever found.
406
+ dormant = onQueueExpired() === OnDrop.DORMANT;
407
+ proxyLog('reticle_mcp_proxy_queue_expired', {
408
+ port,
409
+ dormant,
410
+ reason,
411
+ note: 'answered queued requests and went dormant; the next client request re-probes the port',
412
+ });
413
+ };
545
414
  const armQueueTimer = () => {
546
415
  if (queueTimer !== undefined)
547
416
  return; // the oldest entry owns the deadline
548
417
  queueTimer = setTimeout(() => {
549
418
  queueTimer = undefined;
550
- if (stopped || 0 === stdinQueue.length)
551
- return;
552
- // Drop what we could never send, and answer it, so the caller is never left guessing.
553
- stdinQueue.splice(0);
554
- for (const reply of streamLossReplies(pending, 'no daemon could be reached', queueExpiryNextStep(port))) {
555
- emit(reply);
556
- }
557
- // The expiry is the proof that the reconnect we believed was in flight is not coming — a
558
- // wedged port accepts the socket and never serves SSE, so `connect` neither resolves nor
559
- // rejects and `dormant` would otherwise stay false forever. Going dormant is what makes the
560
- // NEXT request re-probe the port instead of queueing behind a reconnect that will never
561
- // land, and it is the only path by which a daemon started AFTER we gave up is ever found.
562
- dormant = onQueueExpired() === OnDrop.DORMANT;
563
- proxyLog('reticle_mcp_proxy_queue_expired', {
564
- port,
565
- dormant,
566
- note: 'answered queued requests and went dormant; the next client request re-probes the port',
567
- });
419
+ expireQueue('no daemon could be reached');
568
420
  }, QUEUE_WAIT_MS);
569
421
  queueTimer.unref();
570
422
  };
@@ -577,6 +429,10 @@ ensureDaemon) {
577
429
  };
578
430
  let stopped = false;
579
431
  let attempts = 0;
432
+ /** The daemon announced a planned shutdown; the next drop is that, not a fault. */
433
+ let daemonRetiring = false;
434
+ /** Why the stream we are currently trying to replace went away — carried onto the recovery. */
435
+ let lastDropReason = OutageReason.OTHER;
580
436
  /**
581
437
  * When the proxy started, and how many times the first connect has been refused since.
582
438
  *
@@ -623,6 +479,10 @@ ensureDaemon) {
623
479
  // headers, is what earns a fresh retry budget. Resetting on headers let a daemon that
624
480
  // accepts SSE and drops it spin the reconnect loop at the 250ms floor forever, never backing
625
481
  // off and never reaching the budget that puts the proxy dormant. Measured: 32 retries in 8s.
482
+ // Report the recovery BEFORE the counter is cleared: `attempts` is what coming back actually
483
+ // cost, and it is the only number that can falsify the drop event. See OutageStage.RECOVERED.
484
+ if (attempts > 0)
485
+ reportMcpOutage(OutageStage.RECOVERED, { reason: lastDropReason, attempts });
626
486
  attempts = 0;
627
487
  // The new session's McpServer has never seen the client's initialize — replay it first, then
628
488
  // flush whatever the client sent while we were reconnecting.
@@ -631,9 +491,26 @@ ensureDaemon) {
631
491
  clearQueueTimer();
632
492
  for (const queued of stdinQueue.splice(0))
633
493
  forward(url, queued);
494
+ // The client may be holding a tool list we invented. See toolsChangedNotification.
495
+ const relist = toolsChangedNotification(toolsAnnouncedLocally);
496
+ if (relist !== null) {
497
+ toolsAnnouncedLocally = false;
498
+ emit(relist);
499
+ proxyLog('reticle_mcp_proxy_tools_relisted', { port });
500
+ }
634
501
  handshakeAnswered = true;
635
502
  return;
636
503
  }
504
+ // The daemon telling us it is retiring. Not forwarded: it is addressed to this proxy, and the
505
+ // client behind it has no use for a frame it cannot parse.
506
+ if (MCP_SHUTDOWN_EVENT === event) {
507
+ daemonRetiring = true;
508
+ proxyLog('reticle_mcp_proxy_daemon_retiring', {
509
+ port,
510
+ note: 'the daemon announced a planned shutdown; the drop that follows is not an outage',
511
+ });
512
+ return;
513
+ }
637
514
  if ('message' === event && !replay.shouldSuppressInbound(data)) {
638
515
  // Remember the tool catalog as it goes past: it is what makes a locally-answered handshake
639
516
  // useful rather than toolless. See tool-catalog-cache.
@@ -641,10 +518,16 @@ ensureDaemon) {
641
518
  emit(data);
642
519
  }
643
520
  }
644
- function scheduleReconnect(reason, detail) {
521
+ function scheduleReconnect(rawReason, detail) {
645
522
  if (stopped)
646
523
  return;
647
524
  postUrl = null;
525
+ // A stream the daemon warned us about is a planned shutdown, not a fault. The socket looks
526
+ // identical either way from here, so this flag is the only thing that can tell them apart —
527
+ // and without it every scheduled retirement was counted as an outage the agent suffered.
528
+ const reason = daemonRetiring ? OutageReason.DAEMON_SHUTDOWN : rawReason;
529
+ daemonRetiring = false;
530
+ lastDropReason = reason;
648
531
  attempts++;
649
532
  // Everything the dead session owed is settled HERE, in the one place every drop funnels
650
533
  // through, and not in the response callback that first noticed the socket die. A reset emits
@@ -695,16 +578,22 @@ ensureDaemon) {
695
578
  // shut itself down as idle would be respawned instantly, sit unused, shut down again, and
696
579
  // loop forever — measured at four processes in 200s before this. If nothing is listening the
697
580
  // proxy goes DORMANT and the next client request brings a daemon back (see the stdin reader).
698
- void probeDaemon(port).then((listening) => {
699
- if (onStreamDrop(listening) === OnDrop.REATTACH) {
581
+ void probePresence(port, { tcpOpen: probeDaemon, status: fetchDaemonStatus }).then((presence) => {
582
+ if (onStreamDrop(presence) === OnDrop.REATTACH) {
700
583
  connect(false);
701
584
  return;
702
585
  }
703
586
  dormant = true;
704
- proxyLog('reticle_mcp_proxy_dormant', {
705
- port,
706
- note: 'no daemon listening; will start one when the client next sends a request',
707
- });
587
+ // The sentence `doctor` has always been able to say, in the log the agent's own process
588
+ // writes. A FOREIGN holder used to be indistinguishable from a free port here, and the
589
+ // proxy spun against it instead of saying which one it was.
590
+ const sentence = describePresence(presence, port);
591
+ proxyLog('reticle_mcp_proxy_dormant', { port, presence, note: sentence });
592
+ // Nothing is coming that could answer the client's handshake through this port, and the
593
+ // proxy now knows that rather than merely suspecting it. Waiting out LOCAL_HANDSHAKE_MS
594
+ // would be waiting for information already in hand — and #125 measured what that costs:
595
+ // a client whose initialize budget is under ~12s loses Reticle for the whole session.
596
+ deliverHandshakeLocally?.(sentence);
708
597
  });
709
598
  }, wait).unref();
710
599
  }
@@ -797,6 +686,14 @@ ensureDaemon) {
797
686
  // ── stdin reader ─────────────────────────────────────────────────────────
798
687
  process.stdin.setEncoding('utf8');
799
688
  let handshakeAnswered = false;
689
+ /**
690
+ * True while the client is holding a tool list WE made up rather than one the daemon sent.
691
+ *
692
+ * Set when we answer `initialize` locally, cleared the moment we tell the client to re-list. It
693
+ * is not the same question as `handshakeAnswered`, which is also true after a real daemon
694
+ * handshake — and a client that already has the daemon's catalog must not be sent chasing it.
695
+ */
696
+ let toolsAnnouncedLocally = false;
800
697
  /**
801
698
  * Answer a queued `initialize` locally if the daemon has not produced an endpoint in time.
802
699
  *
@@ -807,13 +704,33 @@ ensureDaemon) {
807
704
  const armLocalHandshake = (line) => {
808
705
  if (handshakeAnswered)
809
706
  return;
810
- const response = localInitializeResponse(line);
707
+ // Ask the same question the daemon would, from the same durable memory, so the client gets
708
+ // the same answer it would have got had a daemon been up to give it.
709
+ const response = localInitializeResponse(line, proxyInstructions(port));
811
710
  if (null === response)
812
711
  return;
813
- setTimeout(() => {
712
+ // Take the debt NOW, not when the timer fires.
713
+ //
714
+ // Three paths can answer this id — the daemon, the stream-loss drain, and the timer below —
715
+ // and `take` is the coordination between them. This was the one answerer that never claimed,
716
+ // so a drop before the timer fired paid the handshake a -32001 and the timer then paid it a
717
+ // result, under the same id. Both halves are fatal: a client that gets an error for
718
+ // `initialize` marks the whole MCP server failed, and one that survives that sees two
719
+ // responses for one request. Claiming it here says out loud what has always been true — the
720
+ // proxy owns this answer and will deliver it — so the drain stops owing it. If a session is
721
+ // established first, the `endpoint` handler sets `handshakeAnswered` before the queue is
722
+ // flushed, which disarms the timer and leaves the daemon's own reply the only one.
723
+ const claimed = parseJsonRpc(line);
724
+ if (claimed?.id !== undefined)
725
+ pending.take(claimed.id);
726
+ deliverHandshakeLocally = (reason) => {
814
727
  if (handshakeAnswered || postUrl !== null)
815
728
  return;
816
729
  handshakeAnswered = true;
730
+ deliverHandshakeLocally = undefined;
731
+ // The catalog we are about to serve is ours, not the daemon's, so it has to be corrected
732
+ // the moment a real one exists. See the endpoint handler.
733
+ toolsAnnouncedLocally = true;
817
734
  // Drop the handshake from the queue. Otherwise the daemon, whenever it finally arrives,
818
735
  // answers the SAME id a second time and the client sees two responses to one request — a
819
736
  // corrupted stream, which is worse than the hang this replaces. The daemon still gets its own
@@ -823,16 +740,28 @@ ensureDaemon) {
823
740
  if (queued !== undefined && isHandshakeLine(queued))
824
741
  stdinQueue.splice(i, 1);
825
742
  }
826
- proxyLog('reticle_mcp_local_handshake', { port, reason: 'daemon did not answer in time' });
743
+ proxyLog('reticle_mcp_local_handshake', { port, reason });
827
744
  emit(response);
828
- }, LOCAL_HANDSHAKE_MS).unref();
745
+ };
746
+ setTimeout(() => deliverHandshakeLocally?.('daemon did not answer in time'), LOCAL_HANDSHAKE_MS).unref();
829
747
  };
830
748
  let stdinBuffer = '';
749
+ let stdinDiscarding = false;
831
750
  process.stdin.on('data', (chunk) => {
832
- stdinBuffer += chunk;
833
- const lines = stdinBuffer.split('\n');
834
- stdinBuffer = lines.pop() ?? '';
835
- for (const line of lines) {
751
+ // Not `(buffer + chunk).split()` inline — that rescans everything held on every chunk, so one
752
+ // large line cost O(n²) in its own size and pinned the event loop for tens of seconds, during
753
+ // which every other tool call on this link hung with no response and no error. See drainLines.
754
+ const drained = drainLines(stdinBuffer, chunk, MAX_STDIN_LINE_BYTES, stdinDiscarding);
755
+ stdinBuffer = drained.rest;
756
+ // Carried across chunks: an oversized line is dropped, and the REST of it is still arriving.
757
+ // Without this its tail reads as a complete line and gets forwarded as a message nobody sent.
758
+ stdinDiscarding = drained.discarding;
759
+ if (drained.overflowed) {
760
+ // Logged rather than answered: an unparsed line has no id to answer against, and inventing
761
+ // one would put a reply on the wire that no request is waiting for.
762
+ proxyLog('mcp_stdin_line_too_large', { limitBytes: MAX_STDIN_LINE_BYTES });
763
+ }
764
+ for (const line of drained.lines) {
836
765
  const trimmed = line.trim();
837
766
  if ('' === trimmed)
838
767
  continue;
@@ -869,10 +798,14 @@ ensureDaemon) {
869
798
  .then(() => connect(false))
870
799
  .catch((err) => {
871
800
  dormant = true;
872
- proxyLog('reticle_mcp_proxy_wake_failed', {
873
- port,
874
- error: err instanceof Error ? err.message : String(err),
875
- });
801
+ const reason = err instanceof Error ? err.message : String(err);
802
+ proxyLog('reticle_mcp_proxy_wake_failed', { port, error: reason });
803
+ // The wake is the only thing that can start a daemon, so its failure IS the answer to
804
+ // everything it was woken for. It used to be logged and nothing else: the request sat
805
+ // out the full QUEUE_WAIT_MS and was then refused by a timer that could only say "no
806
+ // daemon could be reached" — twenty seconds later, and less true, than the sentence
807
+ // already in hand.
808
+ expireQueue(reason);
876
809
  });
877
810
  }
878
811
  }
package/dist/mcp/mcp.d.ts CHANGED
@@ -35,7 +35,14 @@ export declare function encodeResult(result: unknown, encoding: string): string;
35
35
  * "Call reticle_tools { names: [...] } for its parameters" — leaving it out made our own advice a
36
36
  * dead end on the one surface that advertises everything.
37
37
  */
38
- export declare function advertisedTools(surface: ToolSurface): ToolDef[];
38
+ export declare function advertisedTools(surface: ToolSurface,
39
+ /**
40
+ * The full table to advertise from. Defaults to what this package ships.
41
+ *
42
+ * A consumer embedding the engine passes its own composition — ours plus its own — so its tools
43
+ * reach the wire without editing the shipped array.
44
+ */
45
+ tools?: readonly ToolDef[]): ToolDef[];
39
46
  /**
40
47
  * Exactly what gets advertised for one tool under a profile: trimmed description, lean input shape,
41
48
  * and (non-lean only) the output schema.
@@ -50,4 +57,22 @@ export declare function advertisedConfig(tool: ToolDef, advertised: readonly Too
50
57
  outputSchema?: z.ZodRawShape;
51
58
  };
52
59
  export declare function installFriendlyArgErrors(server: McpServer, examples: Map<string, string>, allowedKeys?: Map<string, ReadonlySet<string>>): void;
53
- export declare function createMcpServer(deps: ToolDeps, profile?: ToolSurface): McpServer;
60
+ export declare function createMcpServer(deps: ToolDeps, profile?: ToolSurface,
61
+ /**
62
+ * Has an app ever connected for this project? Decides what the instructions LEAD with.
63
+ *
64
+ * Passed in rather than read here, so construction stays free of disk I/O and the decision is
65
+ * testable without a state directory. Defaulting to `false` is the deliberate safe side: an agent
66
+ * told to instrument a project that is already wired loses a paragraph, while an agent not told
67
+ * loses the entire install — and the second is what the field overwhelmingly shows.
68
+ */
69
+ previouslyConnected?: boolean,
70
+ /**
71
+ * The full tool table this server serves. Defaults to what this package ships.
72
+ *
73
+ * Threaded rather than read from the module so a consumer can serve its own tools on one surface
74
+ * with ours. It reaches all three places that need the WHOLE table and not just the advertised
75
+ * slice: the profile filter, the `reticle_run` hatch, and the unadvertised-tool help — a consumer
76
+ * tool missing from either of the last two is a tool the agent is actively told does not exist.
77
+ */
78
+ tools?: readonly ToolDef[]): McpServer;