@reticlehq/init 2.14.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 (114) hide show
  1. package/LICENSE +105 -0
  2. package/NOTICE +5 -0
  3. package/README.md +29 -0
  4. package/dist/agent-rules.d.ts +116 -0
  5. package/dist/agent-rules.js +279 -0
  6. package/dist/app-choice.d.ts +29 -0
  7. package/dist/app-choice.js +39 -0
  8. package/dist/astro-host.d.ts +21 -0
  9. package/dist/astro-host.js +27 -0
  10. package/dist/astro-patch.d.ts +33 -0
  11. package/dist/astro-patch.js +103 -0
  12. package/dist/brace-scan.d.ts +24 -0
  13. package/dist/brace-scan.js +46 -0
  14. package/dist/capabilities.d.ts +40 -0
  15. package/dist/capabilities.js +167 -0
  16. package/dist/closing-hint.d.ts +35 -0
  17. package/dist/closing-hint.js +122 -0
  18. package/dist/codex-toml.d.ts +10 -0
  19. package/dist/codex-toml.js +144 -0
  20. package/dist/connect-steps.d.ts +55 -0
  21. package/dist/connect-steps.js +92 -0
  22. package/dist/cra.d.ts +82 -0
  23. package/dist/cra.js +183 -0
  24. package/dist/csp-check.d.ts +49 -0
  25. package/dist/csp-check.js +168 -0
  26. package/dist/csp-doctor.d.ts +32 -0
  27. package/dist/csp-doctor.js +62 -0
  28. package/dist/desktop-doctor.d.ts +46 -0
  29. package/dist/desktop-doctor.js +201 -0
  30. package/dist/detect.d.ts +225 -0
  31. package/dist/detect.js +334 -0
  32. package/dist/dev-script.d.ts +51 -0
  33. package/dist/dev-script.js +66 -0
  34. package/dist/dev-server-ports.d.ts +20 -0
  35. package/dist/dev-server-ports.js +45 -0
  36. package/dist/electron-patch.d.ts +11 -0
  37. package/dist/electron-patch.js +70 -0
  38. package/dist/electron-vite-patch.d.ts +12 -0
  39. package/dist/electron-vite-patch.js +100 -0
  40. package/dist/existing-config.d.ts +31 -0
  41. package/dist/existing-config.js +63 -0
  42. package/dist/format-generated.d.ts +18 -0
  43. package/dist/format-generated.js +48 -0
  44. package/dist/framework-adapter.d.ts +60 -0
  45. package/dist/framework-adapter.js +138 -0
  46. package/dist/host.d.ts +41 -0
  47. package/dist/host.js +21 -0
  48. package/dist/index.d.ts +25 -0
  49. package/dist/index.js +25 -0
  50. package/dist/init-failure.d.ts +19 -0
  51. package/dist/init-failure.js +18 -0
  52. package/dist/init-opt-out.d.ts +17 -0
  53. package/dist/init-opt-out.js +30 -0
  54. package/dist/install-hint.d.ts +9 -0
  55. package/dist/install-hint.js +41 -0
  56. package/dist/install-retries.d.ts +22 -0
  57. package/dist/install-retries.js +65 -0
  58. package/dist/install-source-config.d.ts +18 -0
  59. package/dist/install-source-config.js +34 -0
  60. package/dist/lockfiles.d.ts +14 -0
  61. package/dist/lockfiles.js +49 -0
  62. package/dist/mcp-clients.d.ts +94 -0
  63. package/dist/mcp-clients.js +327 -0
  64. package/dist/mcp-registered.d.ts +12 -0
  65. package/dist/mcp-registered.js +14 -0
  66. package/dist/mcp.d.ts +89 -0
  67. package/dist/mcp.js +129 -0
  68. package/dist/next-patch.d.ts +49 -0
  69. package/dist/next-patch.js +237 -0
  70. package/dist/node-io.d.ts +22 -0
  71. package/dist/node-io.js +150 -0
  72. package/dist/non-js-project.d.ts +44 -0
  73. package/dist/non-js-project.js +137 -0
  74. package/dist/nuxt-patch.d.ts +18 -0
  75. package/dist/nuxt-patch.js +33 -0
  76. package/dist/patch-kind.d.ts +20 -0
  77. package/dist/patch-kind.js +10 -0
  78. package/dist/plan-electron-vite.d.ts +16 -0
  79. package/dist/plan-electron-vite.js +72 -0
  80. package/dist/plan-framework.d.ts +122 -0
  81. package/dist/plan-framework.js +773 -0
  82. package/dist/plan.d.ts +312 -0
  83. package/dist/plan.js +650 -0
  84. package/dist/platform.d.ts +16 -0
  85. package/dist/platform.js +16 -0
  86. package/dist/preflight.d.ts +30 -0
  87. package/dist/preflight.js +52 -0
  88. package/dist/project-id.d.ts +12 -0
  89. package/dist/project-id.js +25 -0
  90. package/dist/refresh-rules.d.ts +40 -0
  91. package/dist/refresh-rules.js +51 -0
  92. package/dist/remember-project.d.ts +24 -0
  93. package/dist/remember-project.js +40 -0
  94. package/dist/run.d.ts +122 -0
  95. package/dist/run.js +762 -0
  96. package/dist/slash-command.d.ts +27 -0
  97. package/dist/slash-command.js +132 -0
  98. package/dist/snippets.d.ts +267 -0
  99. package/dist/snippets.js +898 -0
  100. package/dist/tanstack-start.d.ts +18 -0
  101. package/dist/tanstack-start.js +57 -0
  102. package/dist/version.d.ts +18 -0
  103. package/dist/version.js +23 -0
  104. package/dist/vite-config.d.ts +18 -0
  105. package/dist/vite-config.js +111 -0
  106. package/dist/vite-owning-config.d.ts +25 -0
  107. package/dist/vite-owning-config.js +219 -0
  108. package/dist/windows-quote.d.ts +38 -0
  109. package/dist/windows-quote.js +70 -0
  110. package/dist/workspace-apps.d.ts +40 -0
  111. package/dist/workspace-apps.js +188 -0
  112. package/dist/workspace-redirect.d.ts +22 -0
  113. package/dist/workspace-redirect.js +97 -0
  114. package/package.json +53 -0
package/dist/plan.js ADDED
@@ -0,0 +1,650 @@
1
+ /**
2
+ * Pure assembly of the `reticle init` action plan. Given the detection result and the relevant file
3
+ * contents, produce an ordered list of steps — each marked apply / manual / already / skip. The
4
+ * runner performs the `write` side-effects; this module decides *what* should happen.
5
+ */
6
+ import { Framework, UiLibrary, installCommand, installCommandParts, } from './detect.js';
7
+ import { installFailureHint } from './install-hint.js';
8
+ import { installRetries } from './install-retries.js';
9
+ import { claudeAddCommand, mcpManual, mcpWindowsNote } from './mcp.js';
10
+ import { NodePlatform } from './platform.js';
11
+ import { mergeClientConfig, ClientMergeStatus, clientSnippet, clientSpec, McpClient, } from './mcp-clients.js';
12
+ import { CLAUDE_COMMAND_PATH, CURSOR_COMMAND_PATH, SLASH_COMMAND_BODY, SLASH_COMMAND_SIGNATURE, } from './slash-command.js';
13
+ import { mergeMarkedInstruction, reticleMdFile, cursorRuleFile, AgentRuleStatus, CLAUDE_MD_PATH, markedBlock, AGENTS_MD_PATH, RETICLE_MD_PATH, CURSOR_RULE_PATH, } from './agent-rules.js';
14
+ import { cspStep, frameworkSteps } from './plan-framework.js';
15
+ import { FRAMEWORK_ADAPTERS, RETICLE_BROWSER_SDK, RETICLE_REACT_KIT } from './framework-adapter.js';
16
+ import { join } from 'node:path';
17
+ import { reticleConfigContent, unverifiedUiLibraryNote, WEBGL_CANVAS_LIMIT_NOTE, } from './snippets.js';
18
+ import { configWithInstallSource } from './install-source-config.js';
19
+ import { existingConfigProblem, projectIdOf, RETICLE_CONFIG_FILE } from './existing-config.js';
20
+ // Re-exported: it moved to the module that reads it, and every existing importer says `plan.js`.
21
+ export { RETICLE_CONFIG_FILE };
22
+ /**
23
+ * Pin the SDK to the CLI's own version.
24
+ *
25
+ * `pnpm add -D @reticlehq/react` installed **2.2.1** in one project while npm and yarn took 2.3.0 in
26
+ * the next — a stale registry metadata cache, invisible to the user and to us. A version-skewed SDK
27
+ * talking to a newer daemon is the `-32000` failure path: the app connects, the protocol disagrees,
28
+ * and nothing on either side names a version. Asking for the CLI's exact version makes the cache
29
+ * irrelevant, and a skewed pair impossible to install by accident.
30
+ */
31
+ function pinnedPackages(packages, version) {
32
+ if (version === undefined || 0 === version.length)
33
+ return packages;
34
+ return packages.map((p) => `${p}@${version}`);
35
+ }
36
+ /**
37
+ * Does this codebase want the React kit, or the framework-neutral sensor?
38
+ *
39
+ * The kit is what adds component identity — component names and stacks — and it is worth having
40
+ * wherever React or Preact is rendering (the adapter reaches Preact through `preact/compat`).
41
+ * Everywhere else it is a package named `@reticlehq/react`, carrying `react` in its peer
42
+ * dependencies, being installed into a codebase that has no React in it.
43
+ *
44
+ * UNKNOWN keeps the kit deliberately. Absence of evidence is not evidence of Vue, and guessing
45
+ * "sensor" on no information silently drops component identity from apps that should have it.
46
+ */
47
+ function wantsReactKit(ui) {
48
+ return ui !== UiLibrary.VUE && ui !== UiLibrary.SVELTE;
49
+ }
50
+ /**
51
+ * The dev-dependencies `reticle init` installs — kit (or sensor) first, build plugin next.
52
+ *
53
+ * `uiLibrary` matters because the framework does not always name the renderer. The rule below was
54
+ * already written for Nuxt, correctly, and applied only there: a Vue app on plain Vite is
55
+ * `Framework.VITE` and a SvelteKit app renders Svelte, and both were being handed the React kit
56
+ * right after `init` had detected the real UI library and said so on screen.
57
+ */
58
+ export function frameworkPackages(framework, uiLibrary = UiLibrary.UNKNOWN) {
59
+ const kit = wantsReactKit(uiLibrary) ? RETICLE_REACT_KIT : RETICLE_BROWSER_SDK;
60
+ return FRAMEWORK_ADAPTERS[framework].packages(kit);
61
+ }
62
+ /** Exported so the init telemetry can tell an MCP-registration failure from a dependency install. */
63
+ export const MCP_TARGET = 'global (claude user scope)';
64
+ /** The step that runs the package manager — the other thing that commonly fails on a user's machine. */
65
+ export const DEPS_TARGET = 'package.json';
66
+ export const StepStatus = {
67
+ APPLY: 'apply',
68
+ MANUAL: 'manual',
69
+ ALREADY: 'already',
70
+ SKIP: 'skip',
71
+ /**
72
+ * Something the user should KNOW, not something they must DO. The UNVERIFIED lines are the case:
73
+ * a Preact or SvelteKit app is wired and working, it just isn't covered by a gate. Reporting those
74
+ * as `manual` made "steps left to do" a number that could never reach zero, and made a release gate
75
+ * read two regressions that were not regressions.
76
+ */
77
+ NOTICE: 'notice',
78
+ };
79
+ /**
80
+ * Where the agent-facing files go, which is not always where the app is.
81
+ *
82
+ * Reported from the field (#318): a repo with its app at `src/admin` got `.claude/commands/reticle.md`
83
+ * written into the app directory, while the human's agent session runs at the repo root — so
84
+ * `/reticle` did not exist for them at all until they copied it up by hand. The rule and command
85
+ * files are read by the AGENT, so they belong where the agent stands; the app files stay with the
86
+ * app. The two are the same directory in a single-package repo, which is why this went unnoticed.
87
+ */
88
+ function agentFile(input, relPath) {
89
+ const root = input.agentFileRoot;
90
+ return root === undefined || 0 === root.length ? relPath : join(root, relPath);
91
+ }
92
+ const CLAUDE_MCP_TITLE = 'MCP server (Claude, global)';
93
+ function claudeMcpStep(input) {
94
+ if (!input.claudeCli)
95
+ return null;
96
+ if (input.mcpExists) {
97
+ return {
98
+ title: CLAUDE_MCP_TITLE,
99
+ target: MCP_TARGET,
100
+ status: StepStatus.ALREADY,
101
+ detail: 'reticle already registered (install once, used by every project)',
102
+ };
103
+ }
104
+ const cmd = claudeAddCommand();
105
+ return {
106
+ title: CLAUDE_MCP_TITLE,
107
+ target: MCP_TARGET,
108
+ status: StepStatus.APPLY,
109
+ detail: 'register reticle globally for all projects',
110
+ exec: { command: cmd.command, args: cmd.args, fallback: cmd.display },
111
+ };
112
+ }
113
+ /**
114
+ * One step per OTHER detected client.
115
+ *
116
+ * The shapes differ enough that a shared "write mcp.json" would be wrong for three of them — see
117
+ * mcp-clients.ts. What is shared is the DECISION: already-correct is left alone, a file we cannot
118
+ * parse is reported with a paste-able block rather than overwritten, and everything else is written.
119
+ */
120
+ function otherClientSteps(input) {
121
+ const steps = [];
122
+ for (const detected of input.detectedClients ?? []) {
123
+ const spec = clientSpec(detected.id);
124
+ const merged = mergeClientConfig(spec, detected.existing);
125
+ const title = `MCP server (${spec.label})`;
126
+ if (merged.status === ClientMergeStatus.ALREADY) {
127
+ steps.push({
128
+ title,
129
+ target: detected.configPath,
130
+ status: StepStatus.ALREADY,
131
+ detail: `reticle already registered with ${spec.label}`,
132
+ });
133
+ continue;
134
+ }
135
+ if (merged.status === ClientMergeStatus.MANUAL) {
136
+ // Either the file did not parse, or the format is one we refuse to edit blind (TOML). Both
137
+ // end the same way: say so, and hand over the exact block.
138
+ steps.push({
139
+ title,
140
+ target: detected.configPath,
141
+ status: StepStatus.MANUAL,
142
+ detail: `add this to ${detected.configPath} by hand:\n${clientSnippet(spec)}`,
143
+ });
144
+ continue;
145
+ }
146
+ steps.push({
147
+ title,
148
+ target: detected.configPath,
149
+ status: StepStatus.APPLY,
150
+ detail: `register reticle with ${spec.label}`,
151
+ write: { path: detected.configPath, content: merged.content },
152
+ });
153
+ }
154
+ return steps;
155
+ }
156
+ /** One global registration per detected agent (Claude + Cursor). Falls back to a manual note. */
157
+ function mcpSteps(input) {
158
+ if (!input.options.mcp) {
159
+ return [
160
+ {
161
+ title: 'MCP server (global)',
162
+ target: MCP_TARGET,
163
+ status: StepStatus.SKIP,
164
+ // Names everything it turns off. `--no-mcp` reads like "skip one step" and skips three: the
165
+ // registration, the agent rule files, and the /reticle command. A gate running with this flag
166
+ // therefore covers far less than its name suggests, which is worth saying out loud.
167
+ detail: '--no-mcp — also skips the agent rule files (CLAUDE.md / AGENTS.md / .cursor) and the /reticle command',
168
+ },
169
+ ];
170
+ }
171
+ // Claude and Cursor first (they have their own registration paths), then every other detected
172
+ // client. A machine with Cursor AND Windsurf gets both — registering only the first one found is
173
+ // how a user ends up with Reticle in the editor they were not using.
174
+ const steps = [...stepsForAgents(input, (a) => a.mcpStep), ...otherClientSteps(input)];
175
+ if (0 === steps.length) {
176
+ // No agent detected. mcpManual already carries the Windows cmd fallback — do not append it again.
177
+ return [
178
+ {
179
+ title: 'MCP server (global)',
180
+ target: MCP_TARGET,
181
+ status: StepStatus.MANUAL,
182
+ detail: mcpManual(),
183
+ },
184
+ ];
185
+ }
186
+ const windowsNote = windowsMcpNoteStep(input);
187
+ if (windowsNote !== null)
188
+ steps.push(windowsNote);
189
+ return steps;
190
+ }
191
+ const WINDOWS_MCP_TITLE = 'Windows MCP spawn';
192
+ /** Windows only. The reported install never reached mcpManual because `claude mcp add` succeeded. */
193
+ function windowsMcpNoteStep(input) {
194
+ if (input.platform !== NodePlatform.WINDOWS)
195
+ return null;
196
+ return {
197
+ title: WINDOWS_MCP_TITLE,
198
+ target: MCP_TARGET,
199
+ status: StepStatus.NOTICE,
200
+ detail: mcpWindowsNote(),
201
+ };
202
+ }
203
+ const SLASH_COMMAND_TITLE = 'The /reticle command';
204
+ /**
205
+ * Nothing to do for this command file: it already holds the CURRENT body, or it is not ours at all.
206
+ *
207
+ * Gating on mere existence froze the command at whatever release wrote it. Rewriting anything found
208
+ * there would be worse — a human may have claimed `/reticle` for their own prompt — so a file without
209
+ * our signature is left exactly as it is.
210
+ */
211
+ function commandIsSettled(content) {
212
+ if (null === content || content === undefined)
213
+ return false;
214
+ return content === SLASH_COMMAND_BODY || !content.includes(SLASH_COMMAND_SIGNATURE);
215
+ }
216
+ /**
217
+ * `/reticle` — the entry point SKILL.md promises in three places and nothing ever created, so it
218
+ * silently did nothing in every tool.
219
+ *
220
+ * CURRENT, not merely present — same reason as the Cursor rule: a command file frozen at whatever
221
+ * release created it is a command that can never be improved for anyone who already ran init. The
222
+ * whole file is Reticle's, so a stale one is rewritten.
223
+ */
224
+ function commandStepFor(path, present, content) {
225
+ if (!present)
226
+ return null;
227
+ return commandIsSettled(content)
228
+ ? {
229
+ title: SLASH_COMMAND_TITLE,
230
+ target: path,
231
+ status: StepStatus.ALREADY,
232
+ detail: 'command already exists',
233
+ }
234
+ : {
235
+ title: SLASH_COMMAND_TITLE,
236
+ target: path,
237
+ status: StepStatus.APPLY,
238
+ detail: 'type /reticle to verify one flow in the browser',
239
+ write: { path, content: SLASH_COMMAND_BODY },
240
+ };
241
+ }
242
+ function claudeCommandStep(input) {
243
+ return commandStepFor(agentFile(input, CLAUDE_COMMAND_PATH), input.claudeCli, input.claudeCommandContent);
244
+ }
245
+ function cursorCommandStep(input) {
246
+ const cursorGlobal = (input.detectedClients ?? []).some((c) => c.id === McpClient.CURSOR);
247
+ const present = true === input.cursorProjectPresent || (cursorGlobal && !input.claudeCli);
248
+ return commandStepFor(agentFile(input, CURSOR_COMMAND_PATH), present, input.cursorCommandContent);
249
+ }
250
+ const AGENT_RULE_TITLE = 'Agent verification rule';
251
+ const AGENT_RULE_DETAIL = 'teach the agent to verify features with Reticle after building them';
252
+ /**
253
+ * What this step is about to do to a file somebody else already writes in.
254
+ *
255
+ * Creating an instruction file and APPENDING to an existing one are different acts, and the plan
256
+ * said the same sentence for both. Reported from the field on a monorepo audit: `init` appended 68
257
+ * lines to `CLAUDE.md` — the repo's binding agent contract, the file every agent there reads first —
258
+ * described only as "teach the agent to verify features with Reticle after building them". The
259
+ * reporter reverted the whole install.
260
+ *
261
+ * `--dry-run` already exists, so the consent mechanism was never missing; what was missing was the
262
+ * plan telling the truth loudly enough to act on. A reader deciding whether to allow this needs the
263
+ * SIZE and the fact that the file is already theirs — both of which are known here and were being
264
+ * withheld. The markers are named too, because a reversible edit and an irreversible one are also
265
+ * different acts, and this one is reversible.
266
+ */
267
+ function ruleWriteDetail(existing, file) {
268
+ const hasContent = existing !== null && existing !== undefined && existing.trim().length > 0;
269
+ if (!hasContent)
270
+ return `${AGENT_RULE_DETAIL} — creates ${file}`;
271
+ const added = markedBlock().split('\n').length - 1;
272
+ return (`${AGENT_RULE_DETAIL} — APPENDS ${String(added)} lines to your existing ${file}, ` +
273
+ 'inside `reticle:begin`/`reticle:end` markers; delete the marked block to undo');
274
+ }
275
+ const RETICLE_MD_TITLE = 'Full agent rules';
276
+ const RETICLE_MD_DETAIL = 'the reference the always-loaded rule points at (when NOT to verify, recovery, feedback)';
277
+ function claudeRuleStep(input) {
278
+ if (!input.claudeCli)
279
+ return null;
280
+ const path = agentFile(input, CLAUDE_MD_PATH);
281
+ const r = mergeMarkedInstruction(input.claudeMdContent);
282
+ if (r.status === AgentRuleStatus.ALREADY) {
283
+ return {
284
+ title: AGENT_RULE_TITLE,
285
+ target: path,
286
+ status: StepStatus.ALREADY,
287
+ detail: 'Reticle rule already in CLAUDE.md',
288
+ };
289
+ }
290
+ return {
291
+ title: AGENT_RULE_TITLE,
292
+ target: path,
293
+ status: StepStatus.APPLY,
294
+ detail: ruleWriteDetail(input.claudeMdContent, CLAUDE_MD_PATH),
295
+ write: { path, content: r.content },
296
+ };
297
+ }
298
+ /**
299
+ * The Cursor rule is a PROJECT file, so it is written only when Cursor plausibly works on THIS
300
+ * project — the repo has a `.cursor/` dir, or Cursor is the only agent found. `~/.cursor` merely
301
+ * existing on the machine meant every Claude Code user got an unexplained `.cursor/rules/reticle.mdc`
302
+ * committed into their repo. (Global MCP registration is different: it is global, and stays.)
303
+ */
304
+ function cursorRuleStep(input) {
305
+ const cursorGlobal = (input.detectedClients ?? []).some((c) => c.id === McpClient.CURSOR);
306
+ if (!cursorGlobal && true !== input.cursorProjectPresent)
307
+ return null;
308
+ if (input.cursorProjectPresent !== true && input.claudeCli)
309
+ return null;
310
+ // The whole file is Reticle's — init created it — so a stale one is REWRITTEN rather than merged.
311
+ // Comparing content is what makes the rule updatable; comparing existence made it permanent.
312
+ const path = agentFile(input, CURSOR_RULE_PATH);
313
+ if (input.cursorRuleContent === cursorRuleFile()) {
314
+ return {
315
+ title: AGENT_RULE_TITLE,
316
+ target: path,
317
+ status: StepStatus.ALREADY,
318
+ detail: 'Reticle rule already in .cursor/rules',
319
+ };
320
+ }
321
+ return {
322
+ title: AGENT_RULE_TITLE,
323
+ target: path,
324
+ status: StepStatus.APPLY,
325
+ detail: AGENT_RULE_DETAIL,
326
+ write: { path, content: cursorRuleFile() },
327
+ };
328
+ }
329
+ /**
330
+ * Every coding agent `reticle init` knows how to wire itself into, and the three surfaces it wires:
331
+ * the global MCP registration, the project rule file that makes the agent USE Reticle, and the
332
+ * `/reticle` command.
333
+ *
334
+ * One list, because those three surfaces used to enumerate Claude and Cursor separately in three
335
+ * places — so supporting a fourth agent meant finding all three and getting each right. Adding one
336
+ * is now an entry here plus its builders; each builder answers null when that agent is not present
337
+ * for this user or this project, which is also how "no agent detected" falls through to the
338
+ * cross-agent AGENTS.md.
339
+ *
340
+ * Deliberately functions rather than data: registering with Claude runs its CLI while Cursor merges
341
+ * a JSON file, and pretending those are the same shape would cost more than it saves.
342
+ */
343
+ const AgentId = {
344
+ CLAUDE: 'claude',
345
+ CURSOR: 'cursor',
346
+ };
347
+ const AGENT_INTEGRATIONS = [
348
+ {
349
+ id: AgentId.CLAUDE,
350
+ mcpStep: claudeMcpStep,
351
+ ruleStep: claudeRuleStep,
352
+ commandStep: claudeCommandStep,
353
+ },
354
+ {
355
+ id: AgentId.CURSOR,
356
+ ruleStep: cursorRuleStep,
357
+ commandStep: cursorCommandStep,
358
+ },
359
+ ];
360
+ /** The steps one surface contributes across every known agent, in registry order. */
361
+ function stepsForAgents(input, surface) {
362
+ return AGENT_INTEGRATIONS.map((a) => surface(a)?.(input) ?? null).filter((s) => s !== null);
363
+ }
364
+ /** The `/reticle` command file for every agent that has a command surface and is present here. */
365
+ function slashCommandSteps(input) {
366
+ return stepsForAgents(input, (a) => a.commandStep);
367
+ }
368
+ /**
369
+ * `AGENTS.md`, always. It is the file every agent that is not Claude or Cursor reads.
370
+ *
371
+ * This used to be a FALLBACK, written only when no agent was detected. So a repo set up on a machine
372
+ * with Claude Code got `CLAUDE.md` and nothing else, and the next person to open it with Codex,
373
+ * Copilot, Amp, Gemini or any other agent found a fully instrumented app whose rules were addressed
374
+ * to somebody else's tool. The detection tells you which agent is running the install; it says
375
+ * nothing about which agents will open the repository afterwards.
376
+ */
377
+ function agentsMdStep(input) {
378
+ const r = mergeMarkedInstruction(input.agentsMdContent);
379
+ const path = agentFile(input, AGENTS_MD_PATH);
380
+ if (r.status === AgentRuleStatus.ALREADY) {
381
+ return {
382
+ title: AGENT_RULE_TITLE,
383
+ target: path,
384
+ status: StepStatus.ALREADY,
385
+ detail: 'Reticle rule already in AGENTS.md',
386
+ };
387
+ }
388
+ return {
389
+ title: AGENT_RULE_TITLE,
390
+ target: path,
391
+ status: StepStatus.APPLY,
392
+ detail: ruleWriteDetail(input.agentsMdContent, AGENTS_MD_PATH),
393
+ write: { path, content: r.content },
394
+ };
395
+ }
396
+ /**
397
+ * `RETICLE.md`, the reference the always-loaded blocks point at.
398
+ *
399
+ * Written whole rather than merged, because `init` owns the entire file: there is no user content to
400
+ * preserve, and the marker dance exists only for files somebody else already writes in.
401
+ */
402
+ function reticleMdStep(input) {
403
+ const path = agentFile(input, RETICLE_MD_PATH);
404
+ const content = reticleMdFile();
405
+ if (input.reticleMdContent === content) {
406
+ return {
407
+ title: RETICLE_MD_TITLE,
408
+ target: path,
409
+ status: StepStatus.ALREADY,
410
+ detail: 'full rules already current',
411
+ };
412
+ }
413
+ return {
414
+ title: RETICLE_MD_TITLE,
415
+ target: path,
416
+ status: StepStatus.APPLY,
417
+ detail: RETICLE_MD_DETAIL,
418
+ write: { path, content },
419
+ };
420
+ }
421
+ /**
422
+ * The behavioral rules that make the agent actually USE Reticle, and know when not to.
423
+ *
424
+ * Every detected agent's own file, plus `AGENTS.md` for the ones that will open this repo later, plus
425
+ * `RETICLE.md` holding the reference half. Rides with the MCP wiring: `--no-mcp` opts out of
426
+ * registering the tools AND of every rule file, because rules for tools the agent cannot reach are
427
+ * noise.
428
+ */
429
+ function agentRuleSteps(input) {
430
+ if (!input.options.mcp)
431
+ return [];
432
+ return [...stepsForAgents(input, (a) => a.ruleStep), agentsMdStep(input), reticleMdStep(input)];
433
+ }
434
+ /**
435
+ * What to say when the install command fails.
436
+ *
437
+ * pnpm's `minimumReleaseAge` refuses any release younger than the configured window — a deliberate
438
+ * supply-chain policy, not a bug — with `ERR_PNPM_NO_MATURE_MATCHING_VERSION`. Unpinned it silently
439
+ * resolves to an OLDER version instead, which is how an app ends up running a 2.2.1 SDK against a
440
+ * 2.3.0 daemon: the connection succeeds, the protocol disagrees, and the failure surfaces as -32000
441
+ * with nothing naming a version. Pinning turns that into this loud failure, which is the better
442
+ * trade — but only if the message says what to do about it.
443
+ */
444
+ function installStep(input) {
445
+ const pm = input.detection.packageManager;
446
+ const packages = pinnedPackages(frameworkPackages(input.detection.framework, input.detection.uiLibrary), input.options.sdkVersion);
447
+ const command = installCommand(pm, packages);
448
+ if (!input.options.install) {
449
+ return {
450
+ title: 'Install dependencies',
451
+ target: 'package.json',
452
+ status: StepStatus.MANUAL,
453
+ detail: command,
454
+ };
455
+ }
456
+ const parts = installCommandParts(pm, packages);
457
+ return {
458
+ title: 'Install dependencies',
459
+ target: 'package.json',
460
+ status: StepStatus.APPLY,
461
+ detail: command,
462
+ exec: {
463
+ command: parts.command,
464
+ args: parts.args,
465
+ fallback: `${command}\n\n${installFailureHint(pm)}`,
466
+ },
467
+ retries: installRetries(pm, packages, frameworkPackages(input.detection.framework, input.detection.uiLibrary), input.options.sdkVersion),
468
+ };
469
+ }
470
+ const RETICLE_CONFIG_TITLE = 'Reticle config';
471
+ const AGENT_ROOT_CONFIG_TITLE = 'Reticle config (agent root)';
472
+ /**
473
+ * The SECOND `.reticle.json`, in the directory the agent runs from.
474
+ *
475
+ * `.reticle.json` is not app wiring — nothing in the app reads it. The CLI and `reticle mcp` read it
476
+ * from their own CWD (see cli-port), and that CWD is the repo root, not the app directory a redirect
477
+ * wired. Reported from the field: an app in `frontend/` on a non-default bridge port left the root
478
+ * with no config at all, so `reticle mcp` fell back to 4400 — which on that machine was ANOTHER
479
+ * project's daemon, and `reticle_sessions` would have listed a different app's tabs while the wired
480
+ * app sat unseen. Nothing in the report said so; every step was green.
481
+ *
482
+ * Written in BOTH places rather than moved: a human standing in the app runs `reticle status` there,
483
+ * and the two files are byte-identical, so neither can disagree with the other about the port or the
484
+ * project identity.
485
+ */
486
+ function agentRootConfigStep(input, content) {
487
+ const root = input.agentFileRoot;
488
+ if (root === undefined || 0 === root.length)
489
+ return [];
490
+ const path = agentFile(input, RETICLE_CONFIG_FILE);
491
+ const existingProject = projectIdOf(input.agentRootConfigSource);
492
+ const wantedProject = projectIdOf(content);
493
+ /**
494
+ * A monorepo has more than one app and the root can only point at one of them.
495
+ *
496
+ * ABSENT and CONFLICTING used to share this branch, so the second got the first's treatment and
497
+ * its reassuring wording. Reported from the field: two instrumented apps, a root config naming
498
+ * the first, and `init --app <the second>` repointed the root with no warning -- after which an
499
+ * agent started at the root reads one project's config and drives another. That is the
500
+ * silent-wrong-target failure this product exists to prevent, shipped by its own installer.
501
+ *
502
+ * Neither answer is ours to pick. Overwriting discards the other app's identity; skipping quietly
503
+ * leaves the agent aimed away from the app just wired. So the conflict is NAMED and nothing is
504
+ * written -- the app's own config is still correct either way, so the app is fully instrumented
505
+ * and only the root pointer is left for a human to decide.
506
+ */
507
+ if (existingProject !== undefined &&
508
+ wantedProject !== undefined &&
509
+ existingProject !== wantedProject) {
510
+ return [
511
+ {
512
+ title: AGENT_ROOT_CONFIG_TITLE,
513
+ target: path,
514
+ status: StepStatus.NOTICE,
515
+ detail: `left alone: it names project "${existingProject}", not "${wantedProject}". An agent ` +
516
+ 'started here would read that project and drive this one. Point it at whichever app ' +
517
+ 'this agent should verify, or run the agent from the app directory.',
518
+ },
519
+ ];
520
+ }
521
+ if (input.agentRootConfigSource === content) {
522
+ return [
523
+ {
524
+ title: AGENT_ROOT_CONFIG_TITLE,
525
+ target: path,
526
+ status: StepStatus.ALREADY,
527
+ detail: 'the agent already reads the same project config',
528
+ },
529
+ ];
530
+ }
531
+ return [
532
+ {
533
+ title: AGENT_ROOT_CONFIG_TITLE,
534
+ target: path,
535
+ status: StepStatus.APPLY,
536
+ detail: 'the same config where the agent runs — `reticle mcp` reads it from ITS cwd, and without ' +
537
+ 'it the agent talks to whatever daemon is on the default port',
538
+ write: { path, content },
539
+ },
540
+ ];
541
+ }
542
+ function reticleConfigStep(input, content) {
543
+ if (true === input.reticleConfigExists) {
544
+ const problem = existingConfigProblem(input.reticleConfigSource);
545
+ if (problem !== undefined) {
546
+ // `ℹ`, not `·`: the step is done and something about the result still stops things working,
547
+ // which is the one mark that says "there is something here to read".
548
+ return {
549
+ title: RETICLE_CONFIG_TITLE,
550
+ target: RETICLE_CONFIG_FILE,
551
+ status: StepStatus.NOTICE,
552
+ detail: problem,
553
+ };
554
+ }
555
+ // The one thing a re-run can still learn: which channel the user actually arrived through.
556
+ // See configWithInstallSource — it only ever ADDS a field that is absent.
557
+ const backfilled = configWithInstallSource(input.reticleConfigSource, input.installSource);
558
+ if (backfilled !== undefined) {
559
+ return {
560
+ title: RETICLE_CONFIG_TITLE,
561
+ target: RETICLE_CONFIG_FILE,
562
+ status: StepStatus.APPLY,
563
+ detail: 'record which install route this project came through',
564
+ write: { path: RETICLE_CONFIG_FILE, content: backfilled },
565
+ };
566
+ }
567
+ return {
568
+ title: RETICLE_CONFIG_TITLE,
569
+ target: RETICLE_CONFIG_FILE,
570
+ status: StepStatus.ALREADY,
571
+ detail: '.reticle.json already exists',
572
+ };
573
+ }
574
+ return {
575
+ title: RETICLE_CONFIG_TITLE,
576
+ target: RETICLE_CONFIG_FILE,
577
+ status: StepStatus.APPLY,
578
+ detail: 'write project config (framework + port)',
579
+ write: { path: RETICLE_CONFIG_FILE, content },
580
+ };
581
+ }
582
+ /**
583
+ * The project config, in every directory that has to read it: the app's, and — after a redirect —
584
+ * the one the agent runs from. One content string for both, so they cannot disagree; an existing
585
+ * app-side config wins over a freshly derived one, or a re-run would copy a DIFFERENT identity up.
586
+ */
587
+ function reticleConfigSteps(input) {
588
+ const existing = input.reticleConfigSource;
589
+ const content = true === input.reticleConfigExists && null !== existing && existing !== undefined
590
+ ? existing
591
+ : reticleConfigContent(input.detection.framework, input.options.port, input.options.projectId,
592
+ // Only when it is actually known. Writing `unknown` would be indistinguishable from a
593
+ // config written before this field existed, and the two mean different things.
594
+ input.installSource);
595
+ return [reticleConfigStep(input, content), ...agentRootConfigStep(input, content)];
596
+ }
597
+ /**
598
+ * A step that says out loud when the app isn't React. SvelteKit already carries its own unverified
599
+ * note, so it isn't doubled up here.
600
+ */
601
+ function uiLibraryStep(input) {
602
+ const lib = input.detection.uiLibrary;
603
+ // A framework whose own recipe already says it is unverified must not be argued with by a second,
604
+ // more generic notice. Asked of the registry rather than of a remembered `SVELTEKIT || NUXT` pair:
605
+ // the pair was the answer, not the question, and a third framework joining it was a silent edit.
606
+ if (lib === UiLibrary.REACT)
607
+ return [];
608
+ if (FRAMEWORK_ADAPTERS[input.detection.framework].carriesOwnUnverifiedNote)
609
+ return [];
610
+ if (lib === UiLibrary.UNKNOWN)
611
+ return [];
612
+ return [
613
+ {
614
+ title: `${lib} is UNVERIFIED`,
615
+ target: 'package.json',
616
+ status: StepStatus.NOTICE,
617
+ detail: unverifiedUiLibraryNote(lib),
618
+ },
619
+ ];
620
+ }
621
+ /**
622
+ * Say the WebGL gap out loud at install time. Without it, init looks fully green on an R3F app
623
+ * while the canvas — often the product — stays a blank rectangle to every look and act tool (#880).
624
+ */
625
+ function webGlCanvasStep(input) {
626
+ if (true !== input.detection.webGlSubtree)
627
+ return [];
628
+ return [
629
+ {
630
+ title: 'WebGL canvas is not observable',
631
+ target: 'package.json',
632
+ status: StepStatus.NOTICE,
633
+ detail: WEBGL_CANVAS_LIMIT_NOTE,
634
+ },
635
+ ];
636
+ }
637
+ export function buildPlan(input) {
638
+ const steps = [
639
+ ...cspStep(input),
640
+ ...mcpSteps(input),
641
+ ...agentRuleSteps(input),
642
+ ...slashCommandSteps(input),
643
+ ...uiLibraryStep(input),
644
+ ...webGlCanvasStep(input),
645
+ installStep(input),
646
+ ...reticleConfigSteps(input),
647
+ ];
648
+ steps.push(...frameworkSteps(input));
649
+ return { framework: input.detection.framework, uiLibrary: input.detection.uiLibrary, steps };
650
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The `process.platform` values this daemon actually branches on, named once.
3
+ *
4
+ * They were spelled inline in five files — `cli-launch`, `cloud-cli`, `init/node-io`, `update/updater`
5
+ * — and every one of them gates real behaviour rather than cosmetics: whether a spawn needs a shell,
6
+ * whether the npm binary is `npm.cmd`, which command opens a browser. A typo in any of those reads as
7
+ * "Windows is broken" and is invisible on the machine of whoever wrote it, because the wrong branch
8
+ * simply never runs there.
9
+ *
10
+ * Node-side only, so deliberately NOT in `@reticlehq/core` — core is the wire contract, and a
11
+ * platform name never crosses the wire.
12
+ */
13
+ export declare const NodePlatform: {
14
+ readonly WINDOWS: "win32";
15
+ readonly MACOS: "darwin";
16
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The `process.platform` values this daemon actually branches on, named once.
3
+ *
4
+ * They were spelled inline in five files — `cli-launch`, `cloud-cli`, `init/node-io`, `update/updater`
5
+ * — and every one of them gates real behaviour rather than cosmetics: whether a spawn needs a shell,
6
+ * whether the npm binary is `npm.cmd`, which command opens a browser. A typo in any of those reads as
7
+ * "Windows is broken" and is invisible on the machine of whoever wrote it, because the wrong branch
8
+ * simply never runs there.
9
+ *
10
+ * Node-side only, so deliberately NOT in `@reticlehq/core` — core is the wire contract, and a
11
+ * platform name never crosses the wire.
12
+ */
13
+ export const NodePlatform = {
14
+ WINDOWS: 'win32',
15
+ MACOS: 'darwin',
16
+ };