@pugi/cli 0.1.0-beta.3 → 0.1.0-beta.30

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 (218) hide show
  1. package/THIRD_PARTY_NOTICES.md +40 -0
  2. package/assets/pugi-mascot.ansi +15 -40
  3. package/bin/run.js +33 -1
  4. package/dist/commands/jobs-watch.js +201 -0
  5. package/dist/commands/jobs.js +15 -0
  6. package/dist/core/agent-progress/cleanup.js +134 -0
  7. package/dist/core/agent-progress/schema.js +144 -0
  8. package/dist/core/agent-progress/writer.js +101 -0
  9. package/dist/core/artifact-chain/dispatcher.js +148 -0
  10. package/dist/core/artifact-chain/exporter.js +164 -0
  11. package/dist/core/artifact-chain/state.js +243 -0
  12. package/dist/core/artifact-chain/steps.js +169 -0
  13. package/dist/core/auth/env-provider.js +238 -0
  14. package/dist/core/auto-update/channels.js +122 -0
  15. package/dist/core/auto-update/checker.js +241 -0
  16. package/dist/core/auto-update/state.js +235 -0
  17. package/dist/core/bare-mode/index.js +107 -0
  18. package/dist/core/checkpoint/resumer.js +149 -0
  19. package/dist/core/checkpoint/rewinder.js +291 -0
  20. package/dist/core/compact/auto-trigger.js +96 -0
  21. package/dist/core/compact/buffer-rewriter.js +115 -0
  22. package/dist/core/compact/summarizer.js +208 -0
  23. package/dist/core/compact/token-counter.js +108 -0
  24. package/dist/core/consensus/diff-capture.js +73 -0
  25. package/dist/core/context/index.js +7 -0
  26. package/dist/core/context/markdown-traverse.js +255 -0
  27. package/dist/core/cost/rate-card.js +129 -0
  28. package/dist/core/cost/tracker.js +221 -0
  29. package/dist/core/denial-tracking/index.js +8 -0
  30. package/dist/core/denial-tracking/state.js +264 -0
  31. package/dist/core/diagnostics/probe-runner.js +93 -0
  32. package/dist/core/diagnostics/probes/api.js +46 -0
  33. package/dist/core/diagnostics/probes/auth.js +86 -0
  34. package/dist/core/diagnostics/probes/bare-mode.js +42 -0
  35. package/dist/core/diagnostics/probes/cli-version.js +127 -0
  36. package/dist/core/diagnostics/probes/config.js +72 -0
  37. package/dist/core/diagnostics/probes/denial-tracking.js +57 -0
  38. package/dist/core/diagnostics/probes/disk.js +81 -0
  39. package/dist/core/diagnostics/probes/git.js +65 -0
  40. package/dist/core/diagnostics/probes/mcp.js +75 -0
  41. package/dist/core/diagnostics/probes/node.js +59 -0
  42. package/dist/core/diagnostics/probes/pnpm.js +36 -0
  43. package/dist/core/diagnostics/probes/pugi-md.js +89 -0
  44. package/dist/core/diagnostics/probes/session.js +74 -0
  45. package/dist/core/diagnostics/probes/status-snapshot.js +442 -0
  46. package/dist/core/diagnostics/probes/workspace.js +63 -0
  47. package/dist/core/diagnostics/types.js +70 -0
  48. package/dist/core/dispatch/cache-cleanup.js +197 -0
  49. package/dist/core/dispatch/cache-handoff.js +295 -0
  50. package/dist/core/edits/dispatch.js +218 -2
  51. package/dist/core/edits/journal.js +199 -0
  52. package/dist/core/edits/layer-d-ast.js +557 -14
  53. package/dist/core/edits/verify-hook.js +273 -0
  54. package/dist/core/edits/worktree.js +111 -18
  55. package/dist/core/engine/anvil-client.js +115 -5
  56. package/dist/core/engine/budgets.js +89 -0
  57. package/dist/core/engine/context-prefix.js +155 -0
  58. package/dist/core/engine/intent.js +260 -0
  59. package/dist/core/engine/native-pugi.js +852 -210
  60. package/dist/core/engine/prompts.js +89 -6
  61. package/dist/core/engine/strip-internal-fields.js +124 -0
  62. package/dist/core/engine/tool-bridge.js +972 -33
  63. package/dist/core/feedback/queue.js +177 -0
  64. package/dist/core/feedback/submitter.js +145 -0
  65. package/dist/core/file-cache.js +113 -1
  66. package/dist/core/hooks/events.js +44 -0
  67. package/dist/core/hooks/index.js +15 -0
  68. package/dist/core/hooks/registry.js +213 -0
  69. package/dist/core/hooks/runner.js +236 -0
  70. package/dist/core/init/scaffold.js +195 -0
  71. package/dist/core/lsp/cache.js +105 -0
  72. package/dist/core/lsp/client.js +174 -29
  73. package/dist/core/lsp/language-detect.js +66 -0
  74. package/dist/core/lsp/post-edit-diagnostics.js +171 -0
  75. package/dist/core/mcp/client.js +75 -6
  76. package/dist/core/mcp/http-server.js +553 -0
  77. package/dist/core/mcp/permission.js +190 -0
  78. package/dist/core/mcp/registry.js +24 -2
  79. package/dist/core/mcp/server-tools.js +219 -0
  80. package/dist/core/mcp/server.js +397 -0
  81. package/dist/core/memory/dual-write.js +416 -0
  82. package/dist/core/memory/dual-write.spec.js +297 -0
  83. package/dist/core/memory/phase1-kinds.js +20 -0
  84. package/dist/core/memory-sync/queue.js +158 -0
  85. package/dist/core/memory-sync/queue.spec.js +105 -0
  86. package/dist/core/onboarding/marker.js +111 -0
  87. package/dist/core/onboarding/telemetry-state.js +108 -0
  88. package/dist/core/output-style/presets.js +176 -0
  89. package/dist/core/output-style/state.js +185 -0
  90. package/dist/core/permissions/gate.js +187 -0
  91. package/dist/core/permissions/index.js +18 -0
  92. package/dist/core/permissions/mode.js +102 -0
  93. package/dist/core/permissions/state.js +215 -0
  94. package/dist/core/permissions/tool-class.js +93 -0
  95. package/dist/core/prd-check/parser.js +215 -0
  96. package/dist/core/prd-check/reporter.js +127 -0
  97. package/dist/core/prd-check/verifiers.js +223 -0
  98. package/dist/core/pugi-md/context-injector.js +76 -0
  99. package/dist/core/pugi-md/walk-up.js +207 -0
  100. package/dist/core/release-notes/parser.js +241 -0
  101. package/dist/core/release-notes/state.js +116 -0
  102. package/dist/core/repl/codebase-survey.js +308 -0
  103. package/dist/core/repl/history.js +11 -1
  104. package/dist/core/repl/init-interview.js +457 -0
  105. package/dist/core/repl/model-pricing.js +135 -0
  106. package/dist/core/repl/onboarding-state.js +297 -0
  107. package/dist/core/repl/session.js +1486 -30
  108. package/dist/core/repl/slash-commands.js +345 -9
  109. package/dist/core/repl/store/session-store.js +31 -2
  110. package/dist/core/repl/workspace-context.js +22 -0
  111. package/dist/core/repo-map/build.js +125 -0
  112. package/dist/core/repo-map/cache.js +185 -0
  113. package/dist/core/repo-map/extractor.js +254 -0
  114. package/dist/core/repo-map/formatter.js +145 -0
  115. package/dist/core/repo-map/scanner.js +211 -0
  116. package/dist/core/retry-budget/budget.js +284 -0
  117. package/dist/core/retry-budget/index.js +5 -0
  118. package/dist/core/session.js +44 -0
  119. package/dist/core/settings.js +80 -0
  120. package/dist/core/share/formatter.js +271 -0
  121. package/dist/core/share/redactor.js +221 -0
  122. package/dist/core/share/uploader.js +267 -0
  123. package/dist/core/skills/defaults.js +457 -0
  124. package/dist/core/subagents/dispatcher-real.js +600 -0
  125. package/dist/core/subagents/dispatcher.js +113 -24
  126. package/dist/core/subagents/index.js +18 -5
  127. package/dist/core/subagents/isolation-matrix.js +213 -0
  128. package/dist/core/subagents/spawn.js +19 -4
  129. package/dist/core/telemetry/emitter.js +229 -0
  130. package/dist/core/telemetry/queue.js +251 -0
  131. package/dist/core/theme/context.js +91 -0
  132. package/dist/core/theme/presets.js +228 -0
  133. package/dist/core/theme/state.js +181 -0
  134. package/dist/core/todos/invariant.js +10 -0
  135. package/dist/core/todos/state.js +177 -0
  136. package/dist/core/transport/version-interceptor.js +166 -0
  137. package/dist/core/vim/keymap.js +288 -0
  138. package/dist/core/vim/state.js +92 -0
  139. package/dist/index.js +28 -0
  140. package/dist/runtime/bootstrap.js +190 -0
  141. package/dist/runtime/cli.js +2595 -278
  142. package/dist/runtime/commands/chain.js +489 -0
  143. package/dist/runtime/commands/compact.js +297 -0
  144. package/dist/runtime/commands/cost.js +199 -0
  145. package/dist/runtime/commands/delegate.js +312 -0
  146. package/dist/runtime/commands/dispatch.js +126 -0
  147. package/dist/runtime/commands/doctor.js +390 -0
  148. package/dist/runtime/commands/feedback.js +184 -0
  149. package/dist/runtime/commands/hooks.js +184 -0
  150. package/dist/runtime/commands/lsp.js +212 -28
  151. package/dist/runtime/commands/mcp.js +824 -0
  152. package/dist/runtime/commands/memory.js +508 -0
  153. package/dist/runtime/commands/memory.spec.js +174 -0
  154. package/dist/runtime/commands/model.js +237 -0
  155. package/dist/runtime/commands/onboarding.js +275 -0
  156. package/dist/runtime/commands/patch.js +17 -0
  157. package/dist/runtime/commands/permissions.js +87 -0
  158. package/dist/runtime/commands/plan.js +143 -0
  159. package/dist/runtime/commands/prd-check.js +235 -0
  160. package/dist/runtime/commands/release-notes.js +229 -0
  161. package/dist/runtime/commands/repo-map.js +95 -0
  162. package/dist/runtime/commands/report.js +299 -0
  163. package/dist/runtime/commands/resume.js +118 -0
  164. package/dist/runtime/commands/review-consensus.js +17 -2
  165. package/dist/runtime/commands/rewind.js +333 -0
  166. package/dist/runtime/commands/roster.js +117 -0
  167. package/dist/runtime/commands/sessions.js +163 -0
  168. package/dist/runtime/commands/share.js +316 -0
  169. package/dist/runtime/commands/status.js +178 -0
  170. package/dist/runtime/commands/stickers.js +82 -0
  171. package/dist/runtime/commands/style.js +194 -0
  172. package/dist/runtime/commands/theme.js +196 -0
  173. package/dist/runtime/commands/update.js +289 -0
  174. package/dist/runtime/commands/vim.js +140 -0
  175. package/dist/runtime/commands/worktree.js +50 -6
  176. package/dist/runtime/headless.js +543 -0
  177. package/dist/runtime/load-hooks-or-exit.js +71 -0
  178. package/dist/runtime/plan-decompose.js +531 -0
  179. package/dist/runtime/version.js +65 -0
  180. package/dist/tools/agent-tool.js +229 -0
  181. package/dist/tools/apply-patch.js +281 -39
  182. package/dist/tools/ask-user-question.js +213 -0
  183. package/dist/tools/ask-user.js +115 -0
  184. package/dist/tools/file-tools.js +85 -14
  185. package/dist/tools/mcp-tool.js +260 -0
  186. package/dist/tools/multi-edit.js +361 -0
  187. package/dist/tools/registry.js +30 -2
  188. package/dist/tools/skill-tool.js +96 -0
  189. package/dist/tools/tasks.js +208 -0
  190. package/dist/tools/todo-write.js +184 -0
  191. package/dist/tools/web-fetch.js +147 -2
  192. package/dist/tools/web-search.js +458 -0
  193. package/dist/tui/agent-progress-card.js +111 -0
  194. package/dist/tui/agent-tree.js +10 -0
  195. package/dist/tui/ask-modal.js +2 -2
  196. package/dist/tui/ask-user-question-prompt.js +192 -0
  197. package/dist/tui/compact-banner.js +81 -0
  198. package/dist/tui/conversation-pane.js +82 -8
  199. package/dist/tui/cost-table.js +111 -0
  200. package/dist/tui/doctor-table.js +46 -0
  201. package/dist/tui/feedback-prompt.js +156 -0
  202. package/dist/tui/input-box.js +46 -2
  203. package/dist/tui/markdown-render.js +4 -4
  204. package/dist/tui/onboarding-wizard.js +240 -0
  205. package/dist/tui/repl-render.js +293 -35
  206. package/dist/tui/repl-splash.js +2 -2
  207. package/dist/tui/repl.js +45 -13
  208. package/dist/tui/splash.js +1 -1
  209. package/dist/tui/status-bar.js +94 -16
  210. package/dist/tui/status-table.js +7 -0
  211. package/dist/tui/stickers-art.js +136 -0
  212. package/dist/tui/style-table.js +28 -0
  213. package/dist/tui/theme-table.js +29 -0
  214. package/dist/tui/tool-stream-pane.js +7 -0
  215. package/dist/tui/update-banner.js +20 -2
  216. package/dist/tui/vim-input.js +267 -0
  217. package/docs/examples/codegraph.mcp.json +10 -0
  218. package/package.json +9 -6
@@ -0,0 +1,184 @@
1
+ /**
2
+ * `pugi hooks` — operator surface for user-config hooks (Leak L12 MVP).
3
+ *
4
+ * Two subcommands ship in the MVP:
5
+ *
6
+ * pugi hooks list List configured hooks per event.
7
+ * pugi hooks doctor Validate the config and surface any
8
+ * parse / schema errors.
9
+ *
10
+ * Both accept `--json` for scripted callers. Argument grammar is
11
+ * intentionally narrow — no `add` / `remove` / `test` subcommands in
12
+ * the MVP. Operators hand-edit `~/.pugi/hooks-mvp.json` for now.
13
+ *
14
+ * Exit codes:
15
+ * 0 -> happy path (no hooks OR config valid).
16
+ * 1 -> config present but invalid (only `doctor` returns this).
17
+ * 2 -> unknown subcommand / argument error.
18
+ *
19
+ * Brand voice: ASCII only.
20
+ */
21
+ import { ALL_HOOK_EVENTS_V2, defaultHooksMvpPath, loadHooksConfig, } from '../../core/hooks/index.js';
22
+ function parseFlags(args) {
23
+ const rest = [];
24
+ const flags = { json: false };
25
+ for (const arg of args) {
26
+ if (arg === '--json') {
27
+ flags.json = true;
28
+ continue;
29
+ }
30
+ rest.push(arg);
31
+ }
32
+ return { rest, flags };
33
+ }
34
+ /**
35
+ * Top-level dispatcher for `pugi hooks <subcommand>`. Returns the
36
+ * intended process exit code. `cli.ts` is expected to set
37
+ * `process.exitCode = <return value>` so error states propagate to
38
+ * scripted callers without throwing.
39
+ */
40
+ export async function runHooksCommand(args, ctx) {
41
+ const { rest, flags } = parseFlags(args);
42
+ const sub = rest[0];
43
+ if (!sub || sub === 'help' || sub === '--help') {
44
+ emitUsage(ctx, flags);
45
+ return sub ? 0 : 2;
46
+ }
47
+ if (sub === 'list') {
48
+ return runList(ctx, flags);
49
+ }
50
+ if (sub === 'doctor') {
51
+ return runDoctor(ctx, flags);
52
+ }
53
+ ctx.writeOutput({ ok: false, error: `unknown subcommand: ${sub}` }, `pugi hooks: unknown subcommand '${sub}'. Try 'pugi hooks --help'.`);
54
+ return 2;
55
+ }
56
+ function emitUsage(ctx, flags) {
57
+ const text = [
58
+ 'pugi hooks — user-config lifecycle hooks (MVP).',
59
+ '',
60
+ 'Subcommands:',
61
+ ' pugi hooks list Show hooks configured per event.',
62
+ ' pugi hooks doctor Validate ~/.pugi/hooks-mvp.json.',
63
+ '',
64
+ 'Flags:',
65
+ ' --json Emit a JSON envelope instead of human text.',
66
+ '',
67
+ 'Config file:',
68
+ ' ~/.pugi/hooks-mvp.json',
69
+ '',
70
+ 'Status:',
71
+ ' MVP — 2 events out of 8. Remaining events (PostToolUse,',
72
+ " UserPromptSubmit, Stop, SubagentStop, PreCompact, Notification)",
73
+ ' deferred to fast-follow PR.',
74
+ ].join('\n');
75
+ ctx.writeOutput({
76
+ ok: true,
77
+ command: 'hooks',
78
+ usage: text,
79
+ }, text);
80
+ if (flags.json) {
81
+ // The structured payload is already emitted by writeOutput when
82
+ // --json is on; nothing extra to do.
83
+ }
84
+ }
85
+ function runList(ctx, flags) {
86
+ let config;
87
+ try {
88
+ config = loadHooksConfig(ctx.configPath);
89
+ }
90
+ catch (error) {
91
+ const msg = error.message;
92
+ ctx.writeOutput({ ok: false, error: msg }, `pugi hooks list: ${msg}\nFix the config or remove the file. Run 'pugi hooks doctor' for details.`);
93
+ return 1;
94
+ }
95
+ const perEvent = {
96
+ SessionStart: [],
97
+ PreToolUse: [],
98
+ PostToolUse: [],
99
+ UserPromptSubmit: [],
100
+ Stop: [],
101
+ SubagentStop: [],
102
+ PreCompact: [],
103
+ Notification: [],
104
+ };
105
+ for (const event of ALL_HOOK_EVENTS_V2) {
106
+ perEvent[event] = config.list(event).map((entry) => ({
107
+ matcher: entry.matcher,
108
+ command: entry.command,
109
+ timeoutMs: entry.timeoutMs,
110
+ blocking: entry.blocking,
111
+ }));
112
+ }
113
+ const total = Object.values(perEvent).reduce((acc, list) => acc + list.length, 0);
114
+ const payload = {
115
+ ok: true,
116
+ configPath: config.configPath(),
117
+ total,
118
+ perEvent,
119
+ };
120
+ if (flags.json) {
121
+ ctx.writeOutput(payload, JSON.stringify(payload, null, 2));
122
+ return 0;
123
+ }
124
+ const lines = [];
125
+ lines.push(`pugi hooks (${total} configured)`);
126
+ lines.push(` config: ${config.configPath()}`);
127
+ if (total === 0) {
128
+ lines.push(' no hooks configured — create the file above to add one.');
129
+ }
130
+ else {
131
+ for (const event of ALL_HOOK_EVENTS_V2) {
132
+ const list = perEvent[event];
133
+ if (list.length === 0)
134
+ continue;
135
+ lines.push(` ${event}:`);
136
+ for (const entry of list) {
137
+ const tags = [];
138
+ if (entry.matcher)
139
+ tags.push(`matcher=${entry.matcher}`);
140
+ if (entry.timeoutMs)
141
+ tags.push(`timeoutMs=${entry.timeoutMs}`);
142
+ if (entry.blocking)
143
+ tags.push('blocking');
144
+ const suffix = tags.length ? ` [${tags.join(', ')}]` : '';
145
+ lines.push(` - ${entry.command}${suffix}`);
146
+ }
147
+ }
148
+ }
149
+ const text = lines.join('\n');
150
+ ctx.writeOutput(payload, text);
151
+ return 0;
152
+ }
153
+ function runDoctor(ctx, flags) {
154
+ const path = ctx.configPath ?? defaultHooksMvpPath();
155
+ try {
156
+ const config = loadHooksConfig(ctx.configPath);
157
+ const total = config.flatten().length;
158
+ const payload = {
159
+ ok: true,
160
+ configPath: config.configPath(),
161
+ total,
162
+ issues: [],
163
+ };
164
+ const text = total
165
+ ? `pugi hooks doctor: ${path} OK (${total} hooks).`
166
+ : `pugi hooks doctor: ${path} not present (no hooks configured).`;
167
+ ctx.writeOutput(payload, text);
168
+ return 0;
169
+ }
170
+ catch (error) {
171
+ const msg = error.message;
172
+ const payload = {
173
+ ok: false,
174
+ configPath: path,
175
+ error: msg,
176
+ };
177
+ const text = `pugi hooks doctor: ${msg}`;
178
+ ctx.writeOutput(payload, text);
179
+ return 1;
180
+ }
181
+ // flags.json is consumed by writeOutput in the host shell.
182
+ void flags;
183
+ }
184
+ //# sourceMappingURL=hooks.js.map
@@ -24,17 +24,64 @@
24
24
  *
25
25
  * Brand voice: ASCII only, no emoji, no banned words.
26
26
  */
27
- import { extname } from 'node:path';
28
- import { startLspClient } from '../../core/lsp/client.js';
27
+ import { inspectLspServers, startLspClient } from '../../core/lsp/client.js';
28
+ import { languageForFile as inferLanguage } from '../../core/lsp/language-detect.js';
29
+ import { loadSettings } from '../../core/settings.js';
29
30
  export async function runLspCommand(args, opts) {
30
31
  const [op, file, ...rest] = args;
31
- if (!op || !file) {
32
+ if (!op) {
32
33
  return usage();
33
34
  }
35
+ // β7 L9: introspection subcommand. `pugi lsp servers` reports the
36
+ // language matrix — binary-on-PATH + enabled-via-settings — so the
37
+ // operator can debug `lsp_unavailable` vs `lsp_disabled` without
38
+ // re-running an actual hover.
39
+ if (op === 'servers' || op === 'status') {
40
+ const settings = loadSettings(opts.cwd);
41
+ const lspSettings = settings.lsp;
42
+ const rows = inspectLspServers(lspSettings);
43
+ if (opts.json) {
44
+ return { ok: true, text: JSON.stringify(rows, null, 2), exitCode: 0 };
45
+ }
46
+ const lines = ['language\tcommand\tavailable\tenabled'];
47
+ for (const r of rows) {
48
+ lines.push(`${r.language}\t${r.command}\t${r.available ? 'yes' : 'no'}\t${r.enabled ? 'yes' : 'no'}`);
49
+ }
50
+ return { ok: true, text: lines.join('\n'), exitCode: 0 };
51
+ }
52
+ if (!file) {
53
+ return usage();
54
+ }
55
+ // β7 L6: `find_definition` convenience subcommand. Identical wire to
56
+ // `definition` but takes `<symbol>` instead of <line> <col>. We grep
57
+ // the workspace for the first hit on `<symbol>` (whole-word match) to
58
+ // recover a position, then route through LSP. Falls back cleanly when
59
+ // the symbol is not present in the file.
60
+ if (op === 'find_definition' || op === 'find-definition') {
61
+ const { lang: explicitLangFD, positional: positionalFD } = pullLangFlag(rest);
62
+ const symbol = positionalFD[0];
63
+ if (!symbol) {
64
+ return {
65
+ ok: false,
66
+ text: 'Usage: pugi lsp find_definition <file> <symbol> [--lang ts|js|py|go|rust]',
67
+ exitCode: 2,
68
+ };
69
+ }
70
+ const lang = explicitLangFD ?? inferLanguage(file);
71
+ if (!lang) {
72
+ return {
73
+ ok: false,
74
+ text: `cannot infer language from ${file}; pass --lang ts|js|py|go|rust. ` +
75
+ `Supported extensions: .ts/.tsx, .js/.jsx/.mjs, .py, .go, .rs`,
76
+ exitCode: 2,
77
+ };
78
+ }
79
+ return await findDefinition(file, symbol, lang, opts);
80
+ }
34
81
  if (!['hover', 'definition', 'references', 'diagnostics'].includes(op)) {
35
82
  return {
36
83
  ok: false,
37
- text: `unknown lsp operation: ${op}. Supported: hover, definition, references, diagnostics`,
84
+ text: `unknown lsp operation: ${op}. Supported: hover, definition, references, diagnostics, find_definition, servers`,
38
85
  exitCode: 2,
39
86
  };
40
87
  }
@@ -48,7 +95,30 @@ export async function runLspCommand(args, opts) {
48
95
  exitCode: 2,
49
96
  };
50
97
  }
51
- const clientResult = await startLspClient(lang, { cwd: opts.cwd });
98
+ const settings = loadSettings(opts.cwd);
99
+ // Leak L15 (2026-05-27): `pugi lsp check <file>` — manual probe of
100
+ // the post-edit diagnostics pipeline. Identical output to what the
101
+ // model sees appended to its tool envelope after a successful
102
+ // edit/write. Lets operators dry-run the auto-diagnostic surface
103
+ // without dispatching an actual edit.
104
+ if (op === 'check') {
105
+ const { runPostEditDiagnostics } = await import('../../core/lsp/post-edit-diagnostics.js');
106
+ const result = await runPostEditDiagnostics(file, {
107
+ cwd: opts.cwd,
108
+ ...(settings.lsp ? { lspSettings: settings.lsp } : {}),
109
+ });
110
+ if (opts.json) {
111
+ return { ok: true, text: JSON.stringify(result, null, 2), exitCode: 0 };
112
+ }
113
+ if (result.skip) {
114
+ return { ok: true, text: `${file}: skipped (${result.reason})`, exitCode: 0 };
115
+ }
116
+ return { ok: true, text: result.tail, exitCode: 0 };
117
+ }
118
+ const clientResult = await startLspClient(lang, {
119
+ cwd: opts.cwd,
120
+ ...(settings.lsp ? { lspSettings: settings.lsp } : {}),
121
+ });
52
122
  if (!clientResult.ok) {
53
123
  return {
54
124
  ok: false,
@@ -57,6 +127,20 @@ export async function runLspCommand(args, opts) {
57
127
  };
58
128
  }
59
129
  const client = clientResult.value;
130
+ // R1 fix (2026-05-26, PR #413 r1, P2 #12): propagate SIGINT/SIGTERM
131
+ // to the LSP child process. Without this, ^C in the middle of a
132
+ // hung definition request would kill the CLI but leave the spawned
133
+ // language server orphaned (especially expensive for rust-analyzer
134
+ // / pyright which hold workspace indices in memory). We register
135
+ // listeners narrowly scoped to this single command invocation and
136
+ // tear them down in the `finally` block.
137
+ let interrupted = false;
138
+ const signalHandler = () => {
139
+ interrupted = true;
140
+ void client.stop();
141
+ };
142
+ process.once('SIGINT', signalHandler);
143
+ process.once('SIGTERM', signalHandler);
60
144
  try {
61
145
  if (op === 'diagnostics') {
62
146
  const result = await client.diagnostics(file);
@@ -120,7 +204,15 @@ export async function runLspCommand(args, opts) {
120
204
  return { ok: true, text: lines.join('\n') || 'no references', exitCode: 0 };
121
205
  }
122
206
  finally {
207
+ process.removeListener('SIGINT', signalHandler);
208
+ process.removeListener('SIGTERM', signalHandler);
123
209
  await client.stop();
210
+ if (interrupted) {
211
+ // Propagate the interruption so the shell sees a sensible exit
212
+ // code on ^C rather than the last successful result code.
213
+ // 130 is the canonical "terminated by SIGINT" exit value.
214
+ return { ok: false, text: 'lsp aborted by signal', exitCode: 130 };
215
+ }
124
216
  }
125
217
  }
126
218
  function usage() {
@@ -130,10 +222,120 @@ function usage() {
130
222
  ' pugi lsp hover <file> <line> <col>\n' +
131
223
  ' pugi lsp definition <file> <line> <col>\n' +
132
224
  ' pugi lsp references <file> <line> <col>\n' +
133
- ' pugi lsp diagnostics <file>',
225
+ ' pugi lsp diagnostics <file>\n' +
226
+ ' pugi lsp check <file> (Leak L15: probe post-edit tail)\n' +
227
+ ' pugi lsp find_definition <file> <symbol>\n' +
228
+ ' pugi lsp servers',
134
229
  exitCode: 2,
135
230
  };
136
231
  }
232
+ /**
233
+ * β7 L6: find_definition convenience.
234
+ *
235
+ * Reads the file, walks line-by-line looking for the first whole-word
236
+ * match of `<symbol>`, then runs `lsp definition` at that position.
237
+ * The result is a normal location array — empty when the LSP server
238
+ * can't resolve the symbol (typically because the workspace TS server
239
+ * hasn't indexed the import yet).
240
+ *
241
+ * "Whole-word match" uses the same identifier-boundary rules as Layer
242
+ * D's tokenizer: matches inside string literals / comments / partial
243
+ * identifiers are skipped. This keeps the result aligned with what the
244
+ * operator means by "where is foo defined" — not "any character sequence
245
+ * spelling foo".
246
+ */
247
+ async function findDefinition(file, symbol, lang, opts) {
248
+ const { readFileSync, existsSync } = await import('node:fs');
249
+ const { resolve } = await import('node:path');
250
+ const abs = resolve(opts.cwd, file);
251
+ if (!existsSync(abs)) {
252
+ return { ok: false, text: `file not found: ${file}`, exitCode: 1 };
253
+ }
254
+ let body;
255
+ try {
256
+ body = readFileSync(abs, 'utf8');
257
+ }
258
+ catch (error) {
259
+ const detail = error instanceof Error ? error.message : String(error);
260
+ return { ok: false, text: `cannot read ${file}: ${detail}`, exitCode: 1 };
261
+ }
262
+ const position = locateIdentifier(body, symbol);
263
+ if (!position) {
264
+ return {
265
+ ok: false,
266
+ text: `symbol '${symbol}' not found in ${file}`,
267
+ exitCode: 1,
268
+ };
269
+ }
270
+ const settings = loadSettings(opts.cwd);
271
+ const clientResult = await startLspClient(lang, {
272
+ cwd: opts.cwd,
273
+ ...(settings.lsp ? { lspSettings: settings.lsp } : {}),
274
+ });
275
+ if (!clientResult.ok) {
276
+ return { ok: false, text: `${clientResult.reason}: ${clientResult.detail}`, exitCode: 1 };
277
+ }
278
+ const client = clientResult.value;
279
+ try {
280
+ const result = await client.definition(file, position);
281
+ if (!result.ok) {
282
+ return { ok: false, text: `${result.reason}: ${result.detail}`, exitCode: 1 };
283
+ }
284
+ if (opts.json) {
285
+ return {
286
+ ok: true,
287
+ text: JSON.stringify({
288
+ symbol,
289
+ file,
290
+ sourcePosition: { line: position.line + 1, character: position.character + 1 },
291
+ definitions: result.value,
292
+ }, null, 2),
293
+ exitCode: 0,
294
+ };
295
+ }
296
+ if (result.value.length === 0) {
297
+ return { ok: true, text: `no definition for ${symbol}`, exitCode: 0 };
298
+ }
299
+ const lines = result.value.map((loc) => `${loc.path || loc.uri}:${loc.range.start.line + 1}:${loc.range.start.character + 1}`);
300
+ return { ok: true, text: lines.join('\n'), exitCode: 0 };
301
+ }
302
+ finally {
303
+ await client.stop();
304
+ }
305
+ }
306
+ /**
307
+ * Find the first whole-word occurrence of `symbol` in `body`. Returns
308
+ * the 0-based LSP position (line + character) or null when absent.
309
+ * Uses the same identifier boundary rule as Layer D's tokenizer to
310
+ * avoid matching inside larger identifiers.
311
+ */
312
+ export function locateIdentifier(body, symbol) {
313
+ const lines = body.split('\n');
314
+ // Build the boundary regex once. We can't use `\b` directly because
315
+ // it treats `$` as a word boundary and TS/JS allow `$` in identifiers;
316
+ // implement the boundary check with a manual lookaround.
317
+ const isIdent = (ch) => {
318
+ if (!ch)
319
+ return false;
320
+ return /[A-Za-z0-9_$]/.test(ch);
321
+ };
322
+ for (let line = 0; line < lines.length; line += 1) {
323
+ const text = lines[line];
324
+ let from = 0;
325
+ while (from < text.length) {
326
+ const idx = text.indexOf(symbol, from);
327
+ if (idx === -1)
328
+ break;
329
+ const before = idx > 0 ? text[idx - 1] : undefined;
330
+ const after = idx + symbol.length < text.length ? text[idx + symbol.length] : undefined;
331
+ if (!isIdent(before) && !isIdent(after)) {
332
+ return { line, character: idx };
333
+ }
334
+ from = idx + symbol.length;
335
+ }
336
+ }
337
+ return null;
338
+ }
137
339
  function pullLangFlag(args) {
138
340
  let lang;
139
341
  const positional = [];
@@ -159,26 +361,8 @@ function pullLangFlag(args) {
159
361
  function isLspLanguage(value) {
160
362
  return value === 'ts' || value === 'js' || value === 'py' || value === 'go' || value === 'rust';
161
363
  }
162
- export function inferLanguage(file) {
163
- const ext = extname(file).toLowerCase();
164
- switch (ext) {
165
- case '.ts':
166
- case '.tsx':
167
- return 'ts';
168
- case '.js':
169
- case '.jsx':
170
- case '.mjs':
171
- case '.cjs':
172
- return 'js';
173
- case '.py':
174
- case '.pyi':
175
- return 'py';
176
- case '.go':
177
- return 'go';
178
- case '.rs':
179
- return 'rust';
180
- default:
181
- return undefined;
182
- }
183
- }
364
+ // Leak L15 (2026-05-27): single source of truth for ext → language
365
+ // lives in `core/lsp/language-detect.ts`. The CLI surface re-exports
366
+ // the lookup so existing call sites keep their import path.
367
+ export { inferLanguage };
184
368
  //# sourceMappingURL=lsp.js.map