@reticlehq/server 2.8.0 → 2.9.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 (292) 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/causal-summary.d.ts +16 -1
  7. package/dist/capsule/causal-summary.js +2 -1
  8. package/dist/cli/cli-doctor.js +41 -13
  9. package/dist/cli/cli-flow-commands.js +8 -8
  10. package/dist/cli/cli-launch.d.ts +0 -17
  11. package/dist/cli/cli-launch.js +0 -28
  12. package/dist/cli/cli-port.d.ts +24 -0
  13. package/dist/cli/cli-port.js +66 -35
  14. package/dist/cli/cli-verify.d.ts +21 -0
  15. package/dist/cli/cli-verify.js +45 -1
  16. package/dist/cli/config-discovery.d.ts +35 -0
  17. package/dist/cli/config-discovery.js +163 -0
  18. package/dist/cli/doctor-daemon-line.js +4 -1
  19. package/dist/cli/doctor-project-line.d.ts +37 -0
  20. package/dist/cli/doctor-project-line.js +35 -0
  21. package/dist/cli/doctor-rows.d.ts +51 -0
  22. package/dist/cli/doctor-rows.js +54 -0
  23. package/dist/cli/doctor-sessions-line.js +6 -3
  24. package/dist/cli/drive-attach.d.ts +99 -0
  25. package/dist/cli/drive-attach.js +203 -0
  26. package/dist/cli/drive-command.d.ts +13 -0
  27. package/dist/cli/drive-command.js +103 -0
  28. package/dist/cli/open-note.d.ts +20 -0
  29. package/dist/cli/open-note.js +37 -0
  30. package/dist/cli/status-next-action.d.ts +37 -0
  31. package/dist/cli/status-next-action.js +61 -0
  32. package/dist/cli.js +65 -70
  33. package/dist/events/contradictions.d.ts +32 -0
  34. package/dist/events/contradictions.js +9 -5
  35. package/dist/events/declared.d.ts +45 -0
  36. package/dist/events/declared.js +73 -0
  37. package/dist/events/echo-mismatch.d.ts +8 -2
  38. package/dist/events/echo-mismatch.js +33 -5
  39. package/dist/events/event-filters.d.ts +1 -1
  40. package/dist/events/event-filters.js +7 -4
  41. package/dist/events/predicate-eval.d.ts +17 -91
  42. package/dist/events/predicate-eval.js +85 -326
  43. package/dist/events/predicate-parse.js +31 -3
  44. package/dist/events/predicate-route.d.ts +32 -0
  45. package/dist/events/predicate-route.js +102 -0
  46. package/dist/events/predicate-schema.d.ts +99 -0
  47. package/dist/events/predicate-schema.js +309 -0
  48. package/dist/events/predicate.d.ts +8 -0
  49. package/dist/events/predicate.js +127 -5
  50. package/dist/flows/annotate-tools.js +3 -0
  51. package/dist/flows/annotate.js +18 -4
  52. package/dist/flows/coverage.d.ts +38 -5
  53. package/dist/flows/coverage.js +30 -4
  54. package/dist/flows/decision.d.ts +15 -0
  55. package/dist/flows/decision.js +1 -1
  56. package/dist/flows/flow-replay-run.js +8 -1
  57. package/dist/flows/flow-tools.js +9 -1
  58. package/dist/flows/replay.js +3 -0
  59. package/dist/honesty/accepted-write.d.ts +3 -0
  60. package/dist/honesty/accepted-write.js +8 -3
  61. package/dist/honesty/already-true.js +15 -0
  62. package/dist/honesty/blind-spots.js +4 -0
  63. package/dist/honesty/honesty.d.ts +11 -0
  64. package/dist/honesty/honesty.js +1 -0
  65. package/dist/honesty/uncaptured-bodies.d.ts +4 -2
  66. package/dist/honesty/uncaptured-bodies.js +9 -2
  67. package/dist/honesty/unread-outcome.d.ts +8 -0
  68. package/dist/honesty/unread-outcome.js +36 -9
  69. package/dist/honesty/unsettled.d.ts +9 -0
  70. package/dist/honesty/unsettled.js +7 -3
  71. package/dist/honesty/verified.d.ts +29 -3
  72. package/dist/honesty/verified.js +51 -8
  73. package/dist/http-server.d.ts +19 -0
  74. package/dist/http-server.js +202 -4
  75. package/dist/impact/impact-recorder.d.ts +23 -0
  76. package/dist/impact/impact-recorder.js +76 -0
  77. package/dist/impact/impact-store.d.ts +47 -0
  78. package/dist/impact/impact-store.js +171 -0
  79. package/dist/index.d.ts +7 -0
  80. package/dist/index.js +44 -10
  81. package/dist/init/agent-rules.d.ts +20 -0
  82. package/dist/init/agent-rules.js +36 -0
  83. package/dist/init/astro-patch.js +27 -1
  84. package/dist/init/confirm.d.ts +21 -3
  85. package/dist/init/confirm.js +32 -5
  86. package/dist/init/connect-steps.d.ts +2 -0
  87. package/dist/init/connect-steps.js +50 -0
  88. package/dist/init/csp-check.d.ts +38 -0
  89. package/dist/init/csp-check.js +92 -0
  90. package/dist/init/csp-doctor.d.ts +25 -0
  91. package/dist/init/csp-doctor.js +49 -0
  92. package/dist/init/cursor.js +6 -9
  93. package/dist/init/detect.d.ts +8 -0
  94. package/dist/init/detect.js +33 -3
  95. package/dist/init/mcp-clients.d.ts +1 -0
  96. package/dist/init/mcp-clients.js +51 -7
  97. package/dist/init/mcp.d.ts +15 -0
  98. package/dist/init/mcp.js +19 -0
  99. package/dist/init/plan-framework.d.ts +10 -0
  100. package/dist/init/plan-framework.js +25 -1
  101. package/dist/init/plan.d.ts +7 -2
  102. package/dist/init/plan.js +66 -30
  103. package/dist/init/run.js +11 -5
  104. package/dist/init/slash-command.d.ts +1 -1
  105. package/dist/init/slash-command.js +12 -4
  106. package/dist/init/snippets.d.ts +1 -1
  107. package/dist/init/snippets.js +35 -7
  108. package/dist/init/vite-config.js +24 -2
  109. package/dist/input/network-mock-tools.js +8 -1
  110. package/dist/input/scroll-find.d.ts +6 -0
  111. package/dist/input/scroll-find.js +17 -2
  112. package/dist/input/scroll-tools.js +4 -0
  113. package/dist/journal/attach-journal.d.ts +9 -1
  114. package/dist/journal/attach-journal.js +13 -2
  115. package/dist/journal/journal-query.d.ts +13 -0
  116. package/dist/journal/journal-query.js +28 -3
  117. package/dist/journal/workspace-gitignore.d.ts +10 -0
  118. package/dist/journal/workspace-gitignore.js +59 -0
  119. package/dist/mcp/mcp-proxy.d.ts +5 -66
  120. package/dist/mcp/mcp-proxy.js +180 -163
  121. package/dist/mcp/mcp.d.ts +10 -1
  122. package/dist/mcp/mcp.js +47 -27
  123. package/dist/mcp/proxy-handshake.d.ts +82 -1
  124. package/dist/mcp/proxy-handshake.js +109 -2
  125. package/dist/mcp/proxy-lifecycle.d.ts +10 -1
  126. package/dist/mcp/proxy-lifecycle.js +11 -2
  127. package/dist/mcp/proxy-log.d.ts +63 -0
  128. package/dist/mcp/proxy-log.js +132 -0
  129. package/dist/mcp/server-instructions.d.ts +17 -0
  130. package/dist/mcp/server-instructions.js +56 -0
  131. package/dist/mcp/shared-params.d.ts +27 -0
  132. package/dist/mcp/shared-params.js +36 -0
  133. package/dist/project/reticle-dir.d.ts +2 -0
  134. package/dist/project/reticle-dir.js +1 -0
  135. package/dist/session/connection-memory.d.ts +59 -0
  136. package/dist/session/connection-memory.js +108 -0
  137. package/dist/session/dev-command.d.ts +26 -0
  138. package/dist/session/dev-command.js +89 -0
  139. package/dist/session/dev-server-probe.d.ts +68 -0
  140. package/dist/session/dev-server-probe.js +102 -7
  141. package/dist/session/last-act.d.ts +26 -0
  142. package/dist/session/last-act.js +35 -1
  143. package/dist/session/live-control-tools.js +42 -5
  144. package/dist/session/no-session-diagnosis.d.ts +48 -2
  145. package/dist/session/no-session-diagnosis.js +176 -20
  146. package/dist/session/no-session-next-action.d.ts +46 -0
  147. package/dist/session/no-session-next-action.js +85 -0
  148. package/dist/session/no-session-watch.d.ts +40 -1
  149. package/dist/session/no-session-watch.js +165 -11
  150. package/dist/session/pending-commands.d.ts +12 -0
  151. package/dist/session/pending-commands.js +13 -1
  152. package/dist/session/session-manager.d.ts +4 -0
  153. package/dist/session/session-manager.js +35 -5
  154. package/dist/session/session.d.ts +10 -1
  155. package/dist/session/session.js +146 -5
  156. package/dist/telemetry/app-instrumented.d.ts +8 -0
  157. package/dist/telemetry/app-instrumented.js +10 -0
  158. package/dist/telemetry/bug-found.d.ts +18 -0
  159. package/dist/telemetry/bug-found.js +14 -0
  160. package/dist/telemetry/daemon-telemetry.js +24 -0
  161. package/dist/telemetry/install-source.d.ts +20 -0
  162. package/dist/telemetry/install-source.js +34 -0
  163. package/dist/telemetry/instrumentation-stall.d.ts +50 -0
  164. package/dist/telemetry/instrumentation-stall.js +90 -0
  165. package/dist/telemetry/session-metrics.d.ts +8 -0
  166. package/dist/telemetry/session-metrics.js +10 -0
  167. package/dist/telemetry/telemetry.d.ts +3 -1
  168. package/dist/telemetry/telemetry.js +13 -2
  169. package/dist/tools/act-tools.js +166 -29
  170. package/dist/tools/assert-verdict.js +32 -7
  171. package/dist/tools/browser-tools.js +10 -0
  172. package/dist/tools/dynamic-tools.js +16 -7
  173. package/dist/tools/error-recovery.js +9 -5
  174. package/dist/tools/invoke-tool.js +20 -3
  175. package/dist/tools/lease-hint.d.ts +30 -8
  176. package/dist/tools/lease-hint.js +65 -14
  177. package/dist/tools/lease-tools.d.ts +11 -0
  178. package/dist/tools/lease-tools.js +141 -96
  179. package/dist/tools/observe-tools.js +9 -3
  180. package/dist/tools/react-grace.d.ts +4 -0
  181. package/dist/tools/react-grace.js +6 -3
  182. package/dist/tools/read-tools.js +47 -1
  183. package/dist/tools/resolve-target.d.ts +33 -0
  184. package/dist/tools/resolve-target.js +53 -0
  185. package/dist/tools/settle-in-flight.d.ts +15 -0
  186. package/dist/tools/settle-in-flight.js +42 -2
  187. package/dist/tools/snapshot-delta.d.ts +3 -0
  188. package/dist/tools/snapshot-delta.js +67 -6
  189. package/dist/tools/tool-kit.d.ts +8 -0
  190. package/dist/tools/tool-surface.d.ts +60 -0
  191. package/dist/tools/tool-surface.js +85 -19
  192. package/dist/tools/tools.js +45 -4
  193. package/dist/tools/unadvertised-help.js +9 -6
  194. package/docs/README.md +1 -2
  195. package/docs/actions.mdx +41 -8
  196. package/docs/agent-cheatsheet.md +4 -2
  197. package/docs/architecture.md +6 -0
  198. package/docs/benchmarks.md +60 -12
  199. package/docs/best-practices.mdx +11 -6
  200. package/docs/capabilities.mdx +201 -54
  201. package/docs/cli/affected.mdx +6 -4
  202. package/docs/cli/capsules.mdx +9 -8
  203. package/docs/cli/cloud.mdx +30 -4
  204. package/docs/cli/doctor.mdx +41 -8
  205. package/docs/cli/drive.mdx +34 -15
  206. package/docs/cli/gate.mdx +6 -6
  207. package/docs/cli/help.mdx +8 -6
  208. package/docs/cli/hunt.mdx +18 -2
  209. package/docs/cli/identify.mdx +16 -2
  210. package/docs/cli/init.mdx +35 -8
  211. package/docs/cli/kill.mdx +5 -5
  212. package/docs/cli/license.mdx +1 -1
  213. package/docs/cli/open.mdx +6 -0
  214. package/docs/cli/restart.mdx +6 -6
  215. package/docs/cli/serve.mdx +10 -3
  216. package/docs/cli/status.mdx +29 -5
  217. package/docs/cli/stop.mdx +8 -0
  218. package/docs/cli/verify.mdx +20 -1
  219. package/docs/cli/version.mdx +1 -1
  220. package/docs/cli/watch.mdx +9 -2
  221. package/docs/cli.mdx +44 -22
  222. package/docs/debugging.md +3 -1
  223. package/docs/deploy-checks.md +30 -1
  224. package/docs/desktop.mdx +276 -80
  225. package/docs/docs.json +13 -12
  226. package/docs/enterprise.md +2 -0
  227. package/docs/faq.mdx +49 -35
  228. package/docs/fixtures.md +2 -0
  229. package/docs/flows.md +3 -1
  230. package/docs/for-agents.md +3 -3
  231. package/docs/frameworks.mdx +46 -7
  232. package/docs/gate-plan.md +4 -2
  233. package/docs/gates.md +7 -5
  234. package/docs/getting-started.md +53 -12
  235. package/docs/human-control.md +2 -0
  236. package/docs/index.mdx +43 -1
  237. package/docs/install-agentic.mdx +13 -4
  238. package/docs/install-manual.mdx +6 -4
  239. package/docs/instrumentation.mdx +7 -1
  240. package/docs/integration-patterns.md +3 -1
  241. package/docs/local-registry.md +4 -2
  242. package/docs/multi-agent-testing.md +3 -1
  243. package/docs/packages/babel-plugin.mdx +15 -6
  244. package/docs/packages/browser.mdx +2 -2
  245. package/docs/packages/core.mdx +26 -16
  246. package/docs/packages/electron.mdx +5 -7
  247. package/docs/packages/eslint-plugin.mdx +5 -3
  248. package/docs/packages/next.mdx +3 -5
  249. package/docs/packages/react.mdx +3 -3
  250. package/docs/packages/server.mdx +2 -2
  251. package/docs/packages/tauri.mdx +6 -6
  252. package/docs/packages/test.mdx +18 -7
  253. package/docs/packages/vite-plugin.mdx +4 -6
  254. package/docs/packages.mdx +14 -13
  255. package/docs/platform-integration.md +2 -0
  256. package/docs/predicates.mdx +76 -7
  257. package/docs/quickstart.mdx +51 -5
  258. package/docs/recipes.mdx +62 -22
  259. package/docs/skill-file.mdx +3 -1
  260. package/docs/state-management.mdx +2 -0
  261. package/docs/system-map.md +3 -1
  262. package/docs/telemetry-contract.md +16 -5
  263. package/docs/telemetry-events.mdx +63 -18
  264. package/docs/telemetry.md +8 -5
  265. package/docs/testing.md +35 -1
  266. package/docs/token-efficiency.md +8 -2
  267. package/docs/tools-act-and-wait.mdx +64 -14
  268. package/docs/tools-act-sequence.mdx +34 -17
  269. package/docs/tools-act.mdx +24 -11
  270. package/docs/tools-assert.mdx +69 -10
  271. package/docs/tools-console.mdx +11 -7
  272. package/docs/tools-inspect.mdx +11 -8
  273. package/docs/tools-navigate.mdx +41 -5
  274. package/docs/tools-network.mdx +42 -9
  275. package/docs/tools-observe.mdx +66 -10
  276. package/docs/tools-overview.mdx +26 -23
  277. package/docs/tools-query.mdx +52 -8
  278. package/docs/tools-session-and-feedback.mdx +30 -9
  279. package/docs/tools-sessions.mdx +39 -10
  280. package/docs/tools-snapshot.mdx +57 -3
  281. package/docs/tools-state.mdx +24 -1
  282. package/docs/tools-tools-and-run.mdx +40 -9
  283. package/docs/tools-wait-for.mdx +34 -15
  284. package/docs/troubleshooting.mdx +80 -10
  285. package/docs/usage.md +43 -21
  286. package/docs/vs-chrome-devtools-mcp.mdx +41 -0
  287. package/docs/vs-playwright-mcp.mdx +42 -2
  288. package/docs/vs-screenshots.mdx +42 -1
  289. package/docs/what-is-reticle.mdx +1 -1
  290. package/docs/why-reticle.mdx +3 -1
  291. package/package.json +5 -5
  292. package/docs/desktop-apps.md +0 -265
@@ -33,5 +33,13 @@ export interface InstrumentationFacts {
33
33
  * never be the reason a session fails to register.
34
34
  */
35
35
  export declare function reportAppInstrumented(facts: InstrumentationFacts, now?: () => number): void;
36
+ /**
37
+ * Has an app connected to this daemon run at all?
38
+ *
39
+ * The same flag `reportAppInstrumented` uses for idempotency, read from outside. The stall check
40
+ * needs exactly this question and must not answer it from a window counter, which resets on every
41
+ * flush and would then report a long-instrumented daemon as freshly stalled.
42
+ */
43
+ export declare function appEverConnected(): boolean;
36
44
  /** Tests only. */
37
45
  export declare function resetAppInstrumented(): void;
@@ -47,6 +47,16 @@ export function reportAppInstrumented(facts, now = () => Date.now()) {
47
47
  /* never let a metric interfere with a page connecting */
48
48
  }
49
49
  }
50
+ /**
51
+ * Has an app connected to this daemon run at all?
52
+ *
53
+ * The same flag `reportAppInstrumented` uses for idempotency, read from outside. The stall check
54
+ * needs exactly this question and must not answer it from a window counter, which resets on every
55
+ * flush and would then report a long-instrumented daemon as freshly stalled.
56
+ */
57
+ export function appEverConnected() {
58
+ return reported;
59
+ }
50
60
  /** Tests only. */
51
61
  export function resetAppInstrumented() {
52
62
  reported = false;
@@ -7,3 +7,21 @@ import { type BugFound } from '@reticlehq/core';
7
7
  */
8
8
  export type BugCandidate = Omit<BugFound, 'repeat'>;
9
9
  export declare function bugsInResult(toolName: string, result: Record<string, unknown>): BugCandidate[];
10
+ /**
11
+ * Crawl anomaly kinds that are CONTRADICTIONS rather than single-channel faults.
12
+ *
13
+ * `reticle_crawl` returns both classes in one `anomalies` array — a console error is one channel
14
+ * complaining, while a UI that advanced over a failed write is two channels disagreeing. Only the
15
+ * second presents as success, and collapsing them would inflate the one claim that has to be exact.
16
+ *
17
+ * DERIVED from core's `ContradictionKind`, never hand-listed. The first version copied the twelve
18
+ * strings into a literal here, which matched on the day it was written and would have silently
19
+ * misclassified the thirteenth: a new contradiction kind would have been counted as an ordinary
20
+ * fault, quietly deflating the exact number we intend to publish. A copied enum is a drift hazard
21
+ * wherever it appears; it is a correctness hazard when the thing that drifts is a public claim.
22
+ */
23
+ /**
24
+ * The route the app was on when this result was produced — extracted from the tool result so the
25
+ * fingerprint can identify the same defect across sessions without sending the route itself.
26
+ */
27
+ export declare function routeOf(result: Record<string, unknown>): string | undefined;
@@ -221,4 +221,18 @@ export function bugsInResult(toolName, result) {
221
221
  * fault, quietly deflating the exact number we intend to publish. A copied enum is a drift hazard
222
222
  * wherever it appears; it is a correctness hazard when the thing that drifts is a public claim.
223
223
  */
224
+ /**
225
+ * The route the app was on when this result was produced — extracted from the tool result so the
226
+ * fingerprint can identify the same defect across sessions without sending the route itself.
227
+ */
228
+ export function routeOf(result) {
229
+ const status = result['status'];
230
+ if ('object' === typeof status && status !== null) {
231
+ const r = status['route'];
232
+ if ('string' === typeof r && r.length > 0)
233
+ return r;
234
+ }
235
+ const r = result['route'];
236
+ return 'string' === typeof r && r.length > 0 ? r : undefined;
237
+ }
224
238
  const CONTRADICTION_KINDS = new Set(Object.values(ContradictionKind));
@@ -13,6 +13,8 @@ import { profileProject } from './project-profile.js';
13
13
  import { startUpdateCheck } from '../update/update-nudge.js';
14
14
  import { markDaemonStart } from './mcp-connection.js';
15
15
  import { markInstrumentationClock } from './app-instrumented.js';
16
+ import { markStallClock, reportInstrumentationStall } from './instrumentation-stall.js';
17
+ import { readProjectId } from '../cli/cli-port.js';
16
18
  /** Let the daemon finish coming up before walking the source tree for a profile. */
17
19
  const PROJECT_PROFILE_DELAY_MS = 5_000;
18
20
  /**
@@ -57,6 +59,8 @@ export function installDaemonTelemetry(cwd, now = () => Date.now()) {
57
59
  // Same clock, different half of the install: one measures how long before an AGENT attached, this
58
60
  // one how long before an APP did. The gap between them is the funnel.
59
61
  markInstrumentationClock(now());
62
+ // The other half of the same question: how long before an app arrives, and a report if none does.
63
+ markStallClock(now());
60
64
  // One profile per daemon start: what kind of project this is and how deeply Reticle is used in it.
61
65
  // Deferred off the boot path — it walks the source tree, and nothing about a daemon coming up
62
66
  // should wait on a filesystem scan.
@@ -71,6 +75,17 @@ export function installDaemonTelemetry(cwd, now = () => Date.now()) {
71
75
  }
72
76
  }, PROJECT_PROFILE_DELAY_MS).unref();
73
77
  const flushWindow = () => {
78
+ // BEFORE the idle return, and that ordering is the whole point: a stalled install produces an
79
+ // empty window by definition — no app, so no tool calls, so nothing to roll up. Checking it
80
+ // after the early return would make the one case this event exists for the one case it never
81
+ // sees. It is self-limiting (once per run, never after an app connects), so running it on every
82
+ // tick costs a comparison.
83
+ reportInstrumentationStall({
84
+ // Same test `app_instrumented` uses for the same field, so the success and failure events
85
+ // stay directly comparable: a stamped projectId means `init` has run here.
86
+ initialized: readProjectId(cwd) !== undefined,
87
+ agentAttached: metrics.agentEverAttached,
88
+ }, now);
74
89
  if (metrics.empty)
75
90
  return; // an idle window is not worth an event
76
91
  // NOT daemon_stopped: the daemon is still running. See SESSION_PROGRESS.
@@ -93,6 +108,15 @@ export function installDaemonTelemetry(cwd, now = () => Date.now()) {
93
108
  stopped ??= (async () => {
94
109
  clearInterval(flush);
95
110
  clearTimeout(firstFlush);
111
+ // Last chance to say that no app ever arrived. The periodic path cannot report an
112
+ // UNATTENDED stall at all — that daemon idle-exits at five minutes and the periodic
113
+ // threshold is ten — so without this the event only ever describes daemons with an agent
114
+ // attached, which is not the population it was built to measure. Self-limiting: if the
115
+ // interval already reported, this returns false and emits nothing.
116
+ reportInstrumentationStall({
117
+ initialized: readProjectId(cwd) !== undefined,
118
+ agentAttached: metrics.agentEverAttached,
119
+ }, now, { atShutdown: true });
96
120
  // The rich one: the whole session in a single event — duration, the tool histogram, error
97
121
  // shapes, verifications, browser launches. This is what replaced the per-tool-call event.
98
122
  await getTelemetry().emit(TelemetryEventKind.DAEMON_STOPPED, {
@@ -34,3 +34,23 @@ export declare const INSTALL_SOURCE_ENV = "RETICLE_INSTALL_SOURCE";
34
34
  * shell snippets and copy-paste, and `Skill_File` is the same channel as `skill_file`.
35
35
  */
36
36
  export declare function resolveInstallSource(env?: NodeJS.ProcessEnv): InstallSource;
37
+ /**
38
+ * The install source declared by the environment, or undefined when nothing declared one.
39
+ *
40
+ * Distinct from `resolveInstallSource`, which answers `unknown` so an event always carries a value.
41
+ * A config file wants the opposite: writing `unknown` into `.reticle.json` is indistinguishable
42
+ * from a config written before this field existed, and those two are different facts.
43
+ */
44
+ export declare function declaredInstallSource(env?: NodeJS.ProcessEnv): InstallSource | undefined;
45
+ /**
46
+ * The install source for a project: what its config recorded, else what the environment declares.
47
+ *
48
+ * The config wins because it is the durable answer. The marker is an environment variable set by
49
+ * whichever channel ran the install, so it exists for exactly one command and is gone by the next
50
+ * one — which is why this field reached a handful of events and nothing else, and why the question
51
+ * it exists to answer could not be asked.
52
+ *
53
+ * Narrowed against the closed list on the way out, the same as the env path: a config file is user
54
+ * data, and a hand-edited one must not be able to put an arbitrary string on the wire.
55
+ */
56
+ export declare function projectInstallSource(cwd: string, env?: NodeJS.ProcessEnv): InstallSource;
@@ -23,6 +23,7 @@
23
23
  * are indistinguishable once they are in the same column.
24
24
  */
25
25
  import { InstallSource } from '@reticlehq/core';
26
+ import { findProjectConfig } from '../cli/cli-port.js';
26
27
  /** The one marker. Set by a channel on the process that runs the install. */
27
28
  export const INSTALL_SOURCE_ENV = 'RETICLE_INSTALL_SOURCE';
28
29
  const KNOWN = new Set(Object.values(InstallSource));
@@ -38,3 +39,36 @@ export function resolveInstallSource(env = process.env) {
38
39
  const declared = (env[INSTALL_SOURCE_ENV] ?? '').trim().toLowerCase();
39
40
  return KNOWN.has(declared) ? declared : InstallSource.UNKNOWN;
40
41
  }
42
+ /**
43
+ * The install source declared by the environment, or undefined when nothing declared one.
44
+ *
45
+ * Distinct from `resolveInstallSource`, which answers `unknown` so an event always carries a value.
46
+ * A config file wants the opposite: writing `unknown` into `.reticle.json` is indistinguishable
47
+ * from a config written before this field existed, and those two are different facts.
48
+ */
49
+ export function declaredInstallSource(env = process.env) {
50
+ const declared = (env[INSTALL_SOURCE_ENV] ?? '').trim().toLowerCase();
51
+ return KNOWN.has(declared) && InstallSource.UNKNOWN !== declared
52
+ ? declared
53
+ : undefined;
54
+ }
55
+ /**
56
+ * The install source for a project: what its config recorded, else what the environment declares.
57
+ *
58
+ * The config wins because it is the durable answer. The marker is an environment variable set by
59
+ * whichever channel ran the install, so it exists for exactly one command and is gone by the next
60
+ * one — which is why this field reached a handful of events and nothing else, and why the question
61
+ * it exists to answer could not be asked.
62
+ *
63
+ * Narrowed against the closed list on the way out, the same as the env path: a config file is user
64
+ * data, and a hand-edited one must not be able to put an arbitrary string on the wire.
65
+ */
66
+ export function projectInstallSource(cwd, env = process.env) {
67
+ const recorded = findProjectConfig(cwd)?.['installSource'];
68
+ if ('string' === typeof recorded) {
69
+ const narrowed = recorded.trim().toLowerCase();
70
+ if (KNOWN.has(narrowed))
71
+ return narrowed;
72
+ }
73
+ return resolveInstallSource(env);
74
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * When a daemon has waited long enough that no app is coming.
3
+ *
4
+ * `app_instrumented` fires on success and only on success, so the population that matters most —
5
+ * daemons that never get an app wired at all — exists in the data only as an absence. An absence is
6
+ * the one thing telemetry cannot interpret: it cannot separate "nothing was ever wired" from "the
7
+ * process was killed before it could say so" from "we never sent the event". The funnel breaks at
8
+ * exactly this step and nowhere else, which makes it the one silence worth converting into a signal.
9
+ *
10
+ * Once per daemon run, and never after an app has connected. A daemon that takes a while and then
11
+ * works reports nothing at all: the question is "did this run ever get an app", and a run that did
12
+ * is not stalled no matter how long it took.
13
+ *
14
+ * The threshold is a judgement, not a measurement, and it is deliberately generous. Someone running
15
+ * `init` and then going to make coffee has not hit a defect, and calling that a stall would drown
16
+ * the real signal in ordinary human latency.
17
+ *
18
+ * Read the result against `agentAttached`, which is what makes it actionable: a stalled daemon with
19
+ * no agent is somebody who installed and walked away, and is not a defect. A stalled daemon WITH an
20
+ * agent attached is the failure the product actually has — the tools are loaded, something is asking
21
+ * for them, and there is nothing on the other end to drive.
22
+ */
23
+ /**
24
+ * How long a daemon may sit with no app before it counts as stalled.
25
+ *
26
+ * Ten minutes sits well past setup latency — reading a doc, restarting a dev server, opening a tab —
27
+ * and well short of the half-hour idle windows that dominate the field, so a stall is reported while
28
+ * the session is still alive rather than inferred from its corpse.
29
+ */
30
+ export declare const STALL_AFTER_MS: number;
31
+ /** Start the clock. Called from the same place the instrumentation clock is marked. */
32
+ export declare function markStallClock(now: number): void;
33
+ export interface StallFacts {
34
+ /** Whether this project has a projectId stamped — i.e. `init` has run here. */
35
+ initialized: boolean;
36
+ /** Whether an MCP client is attached right now. */
37
+ agentAttached: boolean;
38
+ }
39
+ /**
40
+ * Report a stalled install, at most once per daemon run.
41
+ *
42
+ * Returns whether it emitted, so the caller's test can assert the once-only rule without reaching
43
+ * into the telemetry client. Best-effort like every other metric here: it must never be the reason
44
+ * a daemon misbehaves.
45
+ */
46
+ export declare function reportInstrumentationStall(facts: StallFacts, now?: () => number, opts?: {
47
+ atShutdown?: boolean;
48
+ }): boolean;
49
+ /** Tests only. */
50
+ export declare function resetInstrumentationStall(): void;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * When a daemon has waited long enough that no app is coming.
3
+ *
4
+ * `app_instrumented` fires on success and only on success, so the population that matters most —
5
+ * daemons that never get an app wired at all — exists in the data only as an absence. An absence is
6
+ * the one thing telemetry cannot interpret: it cannot separate "nothing was ever wired" from "the
7
+ * process was killed before it could say so" from "we never sent the event". The funnel breaks at
8
+ * exactly this step and nowhere else, which makes it the one silence worth converting into a signal.
9
+ *
10
+ * Once per daemon run, and never after an app has connected. A daemon that takes a while and then
11
+ * works reports nothing at all: the question is "did this run ever get an app", and a run that did
12
+ * is not stalled no matter how long it took.
13
+ *
14
+ * The threshold is a judgement, not a measurement, and it is deliberately generous. Someone running
15
+ * `init` and then going to make coffee has not hit a defect, and calling that a stall would drown
16
+ * the real signal in ordinary human latency.
17
+ *
18
+ * Read the result against `agentAttached`, which is what makes it actionable: a stalled daemon with
19
+ * no agent is somebody who installed and walked away, and is not a defect. A stalled daemon WITH an
20
+ * agent attached is the failure the product actually has — the tools are loaded, something is asking
21
+ * for them, and there is nothing on the other end to drive.
22
+ */
23
+ import { TelemetryEventKind } from '@reticlehq/core';
24
+ import { getTelemetry } from './telemetry.js';
25
+ import { appEverConnected } from './app-instrumented.js';
26
+ /**
27
+ * How long a daemon may sit with no app before it counts as stalled.
28
+ *
29
+ * Ten minutes sits well past setup latency — reading a doc, restarting a dev server, opening a tab —
30
+ * and well short of the half-hour idle windows that dominate the field, so a stall is reported while
31
+ * the session is still alive rather than inferred from its corpse.
32
+ */
33
+ export const STALL_AFTER_MS = 10 * 60 * 1000;
34
+ let reported = false;
35
+ let daemonStartedAt;
36
+ /** Start the clock. Called from the same place the instrumentation clock is marked. */
37
+ export function markStallClock(now) {
38
+ daemonStartedAt = now;
39
+ reported = false;
40
+ }
41
+ /**
42
+ * Report a stalled install, at most once per daemon run.
43
+ *
44
+ * Returns whether it emitted, so the caller's test can assert the once-only rule without reaching
45
+ * into the telemetry client. Best-effort like every other metric here: it must never be the reason
46
+ * a daemon misbehaves.
47
+ */
48
+ export function reportInstrumentationStall(facts, now = () => Date.now(), opts = {}) {
49
+ if (reported)
50
+ return false;
51
+ // An app arrived. Whatever this run was, it was not stalled.
52
+ if (appEverConnected())
53
+ return false;
54
+ if (daemonStartedAt === undefined)
55
+ return false;
56
+ const waited = now() - daemonStartedAt;
57
+ // The threshold is a guard against crying stall seconds after boot. At SHUTDOWN there is nothing
58
+ // left to wait for: this daemon ran, no app ever connected, and it is now gone. That is a fact
59
+ // rather than an inference, and it does not become truer at ten minutes than at five.
60
+ //
61
+ // Skipping it here is what makes the event able to see anything at all. An UNATTENDED daemon
62
+ // idle-exits at DAEMON_IDLE_SHUTDOWN_MS (5 min), well short of STALL_AFTER_MS (10) — only an
63
+ // attached one gets the six-times grace that reaches the threshold. So on the periodic path alone
64
+ // `agentAttached` was forced to true on every row, and the bucket this event exists for —
65
+ // installed it, walked away, never wired the app — could not appear in the data at all.
66
+ //
67
+ // `msWaited` still carries the duration, so a consumer that wants to exclude short runs can do it
68
+ // on the data instead of being unable to see them.
69
+ if (true !== opts.atShutdown && waited < STALL_AFTER_MS)
70
+ return false;
71
+ reported = true;
72
+ try {
73
+ void getTelemetry().emit(TelemetryEventKind.INSTRUMENTATION_STALLED, {
74
+ stall: {
75
+ initialized: facts.initialized,
76
+ agentAttached: facts.agentAttached,
77
+ msWaited: Math.max(0, waited),
78
+ },
79
+ });
80
+ }
81
+ catch {
82
+ /* never let a metric interfere with a running daemon */
83
+ }
84
+ return true;
85
+ }
86
+ /** Tests only. */
87
+ export function resetInstrumentationStall() {
88
+ reported = false;
89
+ daemonStartedAt = undefined;
90
+ }
@@ -130,6 +130,14 @@ export declare class SessionMetrics {
130
130
  * false so a session killed before it can exit is not lost entirely (see the flush note in cli.ts).
131
131
  */
132
132
  summarize(final: boolean, exit?: SessionSummary['exit']): SessionSummary;
133
+ /**
134
+ * Has an agent ever attached to this daemon?
135
+ *
136
+ * Read by the instrumentation-stall check, which needs to tell two very different silences apart:
137
+ * a daemon nobody is using, and a daemon with an agent sitting on it that has no app to drive.
138
+ * The second is the funnel's failure case and the first is not a problem at all.
139
+ */
140
+ get agentEverAttached(): boolean;
133
141
  /** True when nothing at all happened — a flush of an idle daemon is not worth an event. */
134
142
  get empty(): boolean;
135
143
  /** Zero the counters after a non-final flush so the next flush reports the NEXT window, not a total. */
@@ -572,6 +572,16 @@ export class SessionMetrics {
572
572
  return 'verified';
573
573
  return 'explored';
574
574
  }
575
+ /**
576
+ * Has an agent ever attached to this daemon?
577
+ *
578
+ * Read by the instrumentation-stall check, which needs to tell two very different silences apart:
579
+ * a daemon nobody is using, and a daemon with an agent sitting on it that has no app to drive.
580
+ * The second is the funnel's failure case and the first is not a problem at all.
581
+ */
582
+ get agentEverAttached() {
583
+ return this.#clients.size > 0;
584
+ }
575
585
  /** True when nothing at all happened — a flush of an idle daemon is not worth an event. */
576
586
  get empty() {
577
587
  return (0 === this.#toolCalls &&
@@ -1,4 +1,4 @@
1
- import { TelemetryEventKind, ProjectIdSource, type Crash, type Feedback, type Identity, type BugFound, type InitOutcome, type InstallSource, type McpConnection, type McpOutage, type ToolRefusal, type AppInstrumentation, type ProjectProfile, type SessionSummary, type TelemetryActor, type Verification, type VersionChange } from '@reticlehq/core';
1
+ import { TelemetryEventKind, ProjectIdSource, type Crash, type Feedback, type Identity, type BugFound, type InitOutcome, type InstallSource, type McpConnection, type McpOutage, type ToolRefusal, type AppInstrumentation, type InstrumentationStall, type ProjectProfile, type SessionSummary, type TelemetryActor, type Verification, type VersionChange } from '@reticlehq/core';
2
2
  /**
3
3
  * Feedback gets its own, much larger budget — and a retry.
4
4
  *
@@ -78,6 +78,8 @@ export interface TelemetryExtra {
78
78
  outage?: McpOutage;
79
79
  /** `app_instrumented`: an app carrying the SDK reached this daemon for the first time. */
80
80
  instrumentation?: AppInstrumentation;
81
+ /** `instrumentation_stalled`: the daemon waited and no app ever arrived. */
82
+ stall?: InstrumentationStall;
81
83
  /** `reticle_installed` / `init_completed`: which published route brought this install in. */
82
84
  installSource?: InstallSource;
83
85
  }
@@ -70,6 +70,7 @@ const DETACHED_SEND_SCRIPT = "fetch(process.argv[1],{method:'POST',headers:{'con
70
70
  '.catch(()=>{}).finally(()=>process.exit(0))';
71
71
  /** Env var names — mirror cloud-sync's `RETICLE_*` convention. */
72
72
  import { isReticleSourceCheckout } from './dev-repo.js';
73
+ import { projectInstallSource } from './install-source.js';
73
74
  import { gitFacts } from './git-facts.js';
74
75
  import { currentAutomationHint } from './automation-hint.js';
75
76
  const Env = {
@@ -274,6 +275,12 @@ export const createTelemetry = (opts) => {
274
275
  */
275
276
  const sessionId = randomUUID();
276
277
  const { projectId, source: projectIdSource } = projectFingerprint(opts.cwd ?? process.cwd());
278
+ // Resolved ONCE, beside projectId, and for the same reason: it is a property of this install, not
279
+ // of any one event. It used to be passed per-call and therefore rode only `reticle_installed` and
280
+ // `init_completed` — two of the rarest events there are — so the channel that brought a user in
281
+ // was unknown for every event that could show whether they got anywhere. Reading it here puts it
282
+ // on all of them, which is the only shape in which the question can be asked.
283
+ const installSource = projectInstallSource(opts.cwd ?? process.cwd());
277
284
  showNoticeOnce();
278
285
  const spawnDetached = opts.spawnImpl ??
279
286
  ((command, args) => {
@@ -326,17 +333,20 @@ export const createTelemetry = (opts) => {
326
333
  ...(extra?.refusal !== undefined ? { refusal: extra.refusal } : {}),
327
334
  ...(extra?.outage !== undefined ? { outage: extra.outage } : {}),
328
335
  ...(extra?.instrumentation !== undefined ? { instrumentation: extra.instrumentation } : {}),
336
+ ...(extra?.stall !== undefined ? { stall: extra.stall } : {}),
329
337
  // A SCALAR, so it needs the event build and the wire schema but no entry in `blocks` below —
330
338
  // there is nothing to flatten. It still needs both of those, which is the trap `outage` fell
331
339
  // into: a field declared on TelemetryExtra and missing from either one is dropped in silence.
332
- ...(extra?.installSource !== undefined ? { installSource: extra.installSource } : {}),
340
+ // Always present now, rather than only when a caller remembered to pass it. A per-call
341
+ // override still wins so a command that genuinely knows better can say so.
342
+ installSource: extra?.installSource ?? installSource,
333
343
  };
334
344
  // Map the core contract onto PostHog's capture shape: id/name/time move up, the rest are properties.
335
345
  // The feedback body is FLATTENED into `feedback_*` properties rather than sent as a nested object:
336
346
  // PostHog filters and breakdowns operate on top-level properties, so a nested `feedback.stack`
337
347
  // would be invisible to the exact "which stacks report the most bugs" question this exists to
338
348
  // answer. One prefix keeps them grouped in the UI without a nested path.
339
- const { anonymousId: distinctId, event: name, ts, sessionId: eventSessionId, feedback, session, project, verification, versionChange, crash, identity, connection, init, bug, refusal, outage, instrumentation, ...rest } = event;
349
+ const { anonymousId: distinctId, event: name, ts, sessionId: eventSessionId, feedback, session, project, verification, versionChange, crash, identity, connection, init, bug, refusal, outage, instrumentation, stall, ...rest } = event;
340
350
  // `$session_id` is PostHog's OWN session property, so sending ours under that name lights up
341
351
  // its built-in session views and funnels for free rather than requiring custom HogQL everywhere.
342
352
  // `sessionId` rides only on events that happened inside a daemon run. A one-shot CLI command
@@ -367,6 +377,7 @@ export const createTelemetry = (opts) => {
367
377
  refusal,
368
378
  outage,
369
379
  instrumentation,
380
+ stall,
370
381
  };
371
382
  for (const [prefix, block] of Object.entries(blocks)) {
372
383
  for (const [key, value] of Object.entries(block ?? {})) {