pi-agent-ide 1.0.0 → 1.0.1

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 (121) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{chunk-LG22ELG4.js → chunk-26SMC6OS.js} +1 -1
  3. package/dist/{chunk-QC6VFZSB.js → chunk-3BRGWFEI.js} +1 -1
  4. package/dist/chunk-3JBQYLJ4.js +5 -0
  5. package/dist/{chunk-LRAMFOUP.js → chunk-3KM5DSWL.js} +1 -1
  6. package/dist/{chunk-FVWMI4GP.js → chunk-7OAAM5FL.js} +1 -1
  7. package/dist/{chunk-X4CU7CMR.js → chunk-C327T6YP.js} +1 -1
  8. package/dist/{chunk-WZ7MNISG.js → chunk-KM4NOIOB.js} +1 -1
  9. package/dist/{chunk-NGWQRV25.js → chunk-L2YDUMZC.js} +1 -1
  10. package/dist/chunk-MCHU3BLO.js +53 -0
  11. package/dist/{chunk-AKUBFJAR.js → chunk-NSBRKTZ7.js} +1 -1
  12. package/dist/{chunk-SKHD2QIT.js → chunk-QUK5ZEYX.js} +1 -1
  13. package/dist/{chunk-E6G3UVS7.js → chunk-RYJEEBET.js} +1 -1
  14. package/dist/chunk-UN3XLVPR.js +18 -0
  15. package/dist/{chunk-KJ6HZC6L.js → chunk-VQ2RA43A.js} +1 -1
  16. package/dist/{chunk-HUICUICD.js → chunk-VWYI4WF7.js} +1 -1
  17. package/dist/{chunk-UHGHVYAW.js → chunk-W25HNEMR.js} +1 -1
  18. package/dist/entry-0.js +1 -1
  19. package/dist/entry-20.js +1 -1
  20. package/dist/entry-38.js +1 -1
  21. package/dist/entry-44.js +1 -1
  22. package/dist/entry-57.js +1 -1
  23. package/dist/entry-58.js +1 -1
  24. package/dist/entry-59.js +1 -1
  25. package/dist/entry-60.js +1 -1
  26. package/dist/entry-61.js +1 -1
  27. package/dist/entry-62.js +1 -1
  28. package/dist/entry-94.js +1 -1
  29. package/dist/pi-agent-ide.js +1 -1
  30. package/docs/nightly.md +7 -1
  31. package/docs/releases.md +1 -1
  32. package/node_modules/pi-agent-doctor/package.json +1 -1
  33. package/node_modules/pi-agent-documentation/package.json +1 -1
  34. package/node_modules/pi-agent-filesystem/package.json +7 -7
  35. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  36. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  37. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  38. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  39. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  40. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  41. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  42. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  43. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  44. package/node_modules/pi-agent-ide-lsp/package.json +12 -12
  45. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +28 -0
  46. package/node_modules/pi-agent-ide-lsp/src/lsp/corrected-names.ts +16 -5
  47. package/node_modules/pi-agent-ide-lsp/src/lsp/declaration-scan.ts +116 -0
  48. package/node_modules/pi-agent-ide-lsp/src/lsp/initialization-options.ts +37 -0
  49. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +138 -128
  50. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +1 -24
  51. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +40 -12
  52. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +98 -40
  53. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +48 -0
  54. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +61 -0
  55. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +1 -1
  56. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +51 -2
  57. package/node_modules/pi-agent-image/package.json +2 -2
  58. package/node_modules/pi-agent-invariant/package.json +1 -1
  59. package/node_modules/pi-agent-pdf/package.json +2 -2
  60. package/node_modules/pi-agent-read/package.json +7 -7
  61. package/node_modules/pi-agent-resource/package.json +1 -1
  62. package/node_modules/pi-agent-search/package.json +4 -4
  63. package/node_modules/pi-agent-search/src/api/structured-result.ts +28 -4
  64. package/node_modules/pi-agent-search-text/package.json +10 -10
  65. package/node_modules/pi-agent-text/package.json +2 -2
  66. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  67. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  68. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  69. package/node_modules/pi-agent-text-editor/package.json +8 -8
  70. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  71. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  72. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  73. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  74. package/node_modules/pi-agent-web/package.json +7 -7
  75. package/node_modules/pi-agent-web-html/package.json +2 -2
  76. package/node_modules/pi-agent-web-image/package.json +3 -3
  77. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  78. package/node_modules/pi-agent-web-text/package.json +3 -3
  79. package/package.json +35 -35
  80. package/src/composite/script-values/lsp-search.ts +56 -12
  81. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  82. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  83. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  84. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  85. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  86. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  87. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  88. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  89. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  90. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  91. package/src/extensions/pi-agent-read/package.json +7 -7
  92. package/src/extensions/pi-agent-search/package.json +4 -4
  93. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -10
  94. package/src/extensions/pi-agent-search/src/api/structured-result.ts +28 -4
  95. package/src/extensions/pi-agent-text-editor/package.json +8 -8
  96. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  97. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  98. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  99. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  100. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  101. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  102. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  103. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  104. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  105. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  106. package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
  107. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +28 -0
  108. package/src/plugins/pi-agent-ide-lsp/src/lsp/corrected-names.ts +16 -5
  109. package/src/plugins/pi-agent-ide-lsp/src/lsp/declaration-scan.ts +116 -0
  110. package/src/plugins/pi-agent-ide-lsp/src/lsp/initialization-options.ts +37 -0
  111. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +138 -128
  112. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +1 -24
  113. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +40 -12
  114. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +98 -40
  115. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +48 -0
  116. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +61 -0
  117. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +1 -1
  118. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +51 -2
  119. package/dist/chunk-4AEYLVSR.js +0 -5
  120. package/dist/chunk-DSB6A5P5.js +0 -53
  121. package/dist/chunk-YSGPCH52.js +0 -18
@@ -1,19 +1,47 @@
1
1
  import type { LspClient } from "./client.ts";
2
2
 
3
- /** Load unopened TypeScript project files before a workspace query; other servers keep their own readiness rules. */
4
- export async function prepareProjectQuery(client: LspClient, source: string): Promise<void> {
5
- if (!client.supportsCommand("typescript.tsserverRequest")) return;
6
- const project = await client.sendRequest<{ success?: boolean } | null>(
3
+ const TSSERVER_REQUEST = "typescript.tsserverRequest";
4
+
5
+ export function hasTypeScriptProjectQueries(client: LspClient): boolean {
6
+ return client.supportsCommand(TSSERVER_REQUEST);
7
+ }
8
+
9
+ type TsserverQuery =
10
+ | ["projectInfo", { file: string; needFileNameList: true }]
11
+ | ["navto", { searchValue: string }];
12
+
13
+ export async function requestTsserver<Body>(
14
+ client: LspClient,
15
+ query: TsserverQuery,
16
+ signal?: AbortSignal,
17
+ ): Promise<Body | undefined> {
18
+ signal?.throwIfAborted();
19
+ const response = await client.sendRequest<{ success: boolean; body?: Body } | null>(
7
20
  "workspace/executeCommand",
8
21
  {
9
- command: "typescript.tsserverRequest",
10
- arguments: [
11
- "projectInfo",
12
- { file: source, needFileNameList: true },
13
- { isAsync: false, expectsResult: true },
14
- ],
22
+ command: TSSERVER_REQUEST,
23
+ arguments: [...query, { isAsync: false, expectsResult: true }],
15
24
  },
25
+ signal,
26
+ );
27
+ signal?.throwIfAborted();
28
+ if (response?.success !== true)
29
+ throw new Error(`TypeScript project request failed (${query[0]}).`);
30
+ return response.body;
31
+ }
32
+
33
+ /** Load the seed's project and report the files it already covers, in server path spelling. */
34
+ export async function loadQueryProject(
35
+ client: LspClient,
36
+ uri: string,
37
+ signal?: AbortSignal,
38
+ ): Promise<readonly string[]> {
39
+ signal?.throwIfAborted();
40
+ if (!hasTypeScriptProjectQueries(client)) return [];
41
+ const project = await requestTsserver<{ fileNames?: string[] }>(
42
+ client,
43
+ ["projectInfo", { file: client.serverDocumentPath(uri), needFileNameList: true }],
44
+ signal,
16
45
  );
17
- if (project?.success !== true)
18
- throw new Error("TypeScript could not load the project for a workspace query.");
46
+ return project?.fileNames ?? [];
19
47
  }
@@ -18,6 +18,7 @@ import { requireReferenceReply, requestReferences, type LspLocation } from "./na
18
18
  import { lspRangeMatch } from "./range-match.ts";
19
19
  import { diagnosticErrors, withoutCorrectedNames } from "./corrected-names.ts";
20
20
  import { isMissingSource } from "./missing-sources.ts";
21
+ import { hasTypeScriptProjectQueries } from "./project.ts";
21
22
  import type { LspPosition } from "./types.ts";
22
23
  import {
23
24
  clangCoverage,
@@ -27,9 +28,9 @@ import {
27
28
  type ClangCoverage,
28
29
  } from "./clang-coverage.ts";
29
30
  import { requestWorkspaceSymbols, requestDocumentSymbols } from "./symbols.ts";
31
+ import { exactIdentifier, scanDeclarations } from "./declaration-scan.ts";
30
32
  import {
31
- declarationAt,
32
- declarationsNamed,
33
+ declarationsForWorkspaceSymbol,
33
34
  normalizeDocumentSymbols,
34
35
  preferredDeclaration,
35
36
  type LspCodeSymbol,
@@ -112,6 +113,18 @@ interface Snapshot {
112
113
  readonly version: string;
113
114
  }
114
115
 
116
+ /** A workspace symbol with no usable declaration anchor in the current file. */
117
+ export interface SkippedSymbol {
118
+ readonly name: string;
119
+ readonly source: string;
120
+ }
121
+
122
+ /** A server returned at least its known workspace/symbol candidate limit. */
123
+ export interface WorkspaceSymbolCandidateLimit {
124
+ readonly server: string;
125
+ readonly limit: number;
126
+ }
127
+
115
128
  /** Symbols found by {@link searchSymbols}. */
116
129
  export interface SymbolSearchResult {
117
130
  readonly hits: SymbolHit[];
@@ -128,6 +141,8 @@ export interface SymbolSearchResult {
128
141
  * listed; their places are left out. Present only when there are such files.
129
142
  */
130
143
  readonly missing?: readonly string[];
144
+ readonly skipped?: readonly SkippedSymbol[];
145
+ readonly candidateLimits?: readonly WorkspaceSymbolCandidateLimit[];
131
146
  }
132
147
 
133
148
  /** Search workspace declarations/references, keeping real provider ranges and honest completeness. */
@@ -187,6 +202,17 @@ async function searchSymbolsOnce(
187
202
  return read;
188
203
  };
189
204
  const readText = async (file: string) => (await snapshotOf(sourceOf(file, cwd))).document.content;
205
+ const outlines = new Map<LspClient, Map<string, Promise<LspCodeSymbol[]>>>();
206
+ const outlineOf = (client: LspClient, uri: string) => {
207
+ const byUri = outlines.get(client) ?? new Map<string, Promise<LspCodeSymbol[]>>();
208
+ outlines.set(client, byUri);
209
+ let outline = byUri.get(uri);
210
+ if (outline === undefined) {
211
+ outline = requestDocumentSymbols(client, uri, signal).then(normalizeDocumentSymbols);
212
+ byUri.set(uri, outline);
213
+ }
214
+ return outline;
215
+ };
190
216
  const roots = resultScope?.targets.map((target) => target.source) ??
191
217
  scope.paths ?? [scope.path ?? cwd];
192
218
  const clients = new Set(
@@ -208,6 +234,22 @@ async function searchSymbolsOnce(
208
234
  throw new Error(
209
235
  "LSP symbol search is unavailable: no provider supports workspace/symbol in this scope.",
210
236
  );
237
+ // An exact name is looked up in the files that write it, whatever the servers' indexes hold.
238
+ const word = exactIdentifier(query);
239
+ const scan =
240
+ word === undefined
241
+ ? undefined
242
+ : await scanDeclarations({
243
+ manager,
244
+ cwd,
245
+ roots,
246
+ word,
247
+ accepts: (source) => withinScope(source, cwd, scope),
248
+ readText,
249
+ outlineOf,
250
+ ...(signal && { signal }),
251
+ });
252
+ for (const client of scan?.declarations.keys() ?? []) clients.add(client);
211
253
  // The result scope as the text each hit was read from. Another session may have written the file
212
254
  // since the scope was resolved, before or while the server answered; the scope follows its
213
255
  // region through unchanged lines, and the call fails when the region is gone.
@@ -322,6 +364,7 @@ async function searchSymbolsOnce(
322
364
  // The server's index can keep places in files deleted since, such as another session's scratch
323
365
  // copy of a source. The search leaves them out and names the files it could have listed.
324
366
  const missing = new Set<string>();
367
+ const skipped = new Map<string, SkippedSymbol>();
325
368
  const exists = async (source: string): Promise<boolean> => {
326
369
  try {
327
370
  await snapshotOf(source);
@@ -332,55 +375,57 @@ async function searchSymbolsOnce(
332
375
  return false;
333
376
  }
334
377
  };
335
- const coverages: (ClangCoverage | undefined)[] = [];
378
+ const coverages: (ClangCoverage | undefined)[] = [scan?.coverage];
379
+ const candidateLimits: WorkspaceSymbolCandidateLimit[] = [];
336
380
  // Declarations already listed, by file and the name position of their first entry.
337
- const listed = new Set<string>();
338
- const outlines = new Map<string, Promise<LspCodeSymbol[]>>();
339
- const outlineOf = (client: LspClient, uri: string) => {
340
- let outline = outlines.get(uri);
341
- if (outline === undefined) {
342
- outline = requestDocumentSymbols(client, uri, signal).then(normalizeDocumentSymbols);
343
- outlines.set(uri, outline);
344
- }
345
- return outline;
346
- };
381
+ const listed = new Map<LspClient, Set<string>>();
347
382
  for (const client of clients) {
383
+ const typescript = hasTypeScriptProjectQueries(client);
348
384
  signal?.throwIfAborted();
349
- const definitions = await requestWorkspaceSymbols(
350
- client,
351
- query,
352
- Number.MAX_SAFE_INTEGER,
353
- signal,
354
- );
385
+ const indexed = await requestWorkspaceSymbols(client, query, Number.MAX_SAFE_INTEGER, signal);
386
+ // Count the raw reply. Candidates omitted here could have had declarations or references
387
+ // inside the scope. The exact-name scan cannot recover all of the server's fuzzy matches.
388
+ const candidateLimit = client.workspaceSymbolCandidateLimit;
389
+ if (candidateLimit !== undefined && indexed.length >= candidateLimit)
390
+ candidateLimits.push({ server: client.commandName, limit: candidateLimit });
391
+ const definitions = [...indexed, ...(scan?.declarations.get(client) ?? [])];
355
392
  for (const definition of definitions) {
356
393
  signal?.throwIfAborted();
357
- if (!withinScope(sourceOf(definition.location.uri, cwd), cwd, {})) continue;
358
- if (!(await exists(sourceOf(definition.location.uri, cwd)))) continue;
394
+ const source = sourceOf(definition.location.uri, cwd);
395
+ if (!withinScope(source, cwd, {})) continue;
396
+ if (!(await exists(source))) continue;
359
397
  const workspaceMatch = await toMatch(definition.location, client).catch((error: unknown) => {
360
398
  if ((error as { code?: unknown } | null)?.code === "SOURCE_CHANGED") return undefined;
361
399
  throw error;
362
400
  });
363
- const opened = await manager.openFile(
364
- sourceOf(definition.location.uri, cwd),
365
- cwd,
366
- "symbols",
367
- signal,
368
- readText,
369
- );
401
+ // The Vue-backed TypeScript project can see references that the plain TS server cannot.
402
+ const extension = path.extname(decodeURIComponent(new URL(definition.location.uri).pathname));
403
+ const opened = typescript
404
+ ? await manager.openClientFile(
405
+ client,
406
+ source,
407
+ manager.languageId(extension),
408
+ signal,
409
+ readText,
410
+ )
411
+ : await manager.openFile(source, cwd, "symbols", signal, readText);
370
412
  if (opened === null)
371
413
  throw new Error("LSP references are unavailable for a discovered declaration.");
372
414
  // The server's symbol index can lag behind edits, so its range may belong to an older text.
373
415
  // The file's current symbols then name every declaration with that name, each overload
374
416
  // apart; a prototype and its definition are one declaration.
375
417
  const outline = await outlineOf(opened.client, opened.uri);
376
- const fresh = workspaceMatch?.matchedText === definition.name;
377
- const declarations: (readonly LspCodeSymbol[] | undefined)[] = fresh
378
- ? [declarationAt(outline, definition.location.range)]
379
- : declarationsNamed(outline, definition.name);
380
- if (declarations.length === 0)
381
- throw sourceChanged(
382
- `LSP declaration "${definition.name}" is not among the current symbols of its file.`,
383
- );
418
+ const declarations = declarationsForWorkspaceSymbol(
419
+ outline,
420
+ definition.name,
421
+ definition.location.range,
422
+ workspaceMatch?.matchedText,
423
+ );
424
+ if (declarations.length === 0) {
425
+ // Without an anchor we cannot ask for its references or rule out a hit inside the scope.
426
+ skipped.set(JSON.stringify([source, definition.name]), { name: definition.name, source });
427
+ continue;
428
+ }
384
429
  for (const entries of declarations) {
385
430
  signal?.throwIfAborted();
386
431
  // A declaration's references and renames are the same from each of its entries; its
@@ -401,11 +446,17 @@ async function searchSymbolsOnce(
401
446
  opened.uri,
402
447
  (entries?.[0]?.selectionRange ?? definition.location.range).start,
403
448
  ]);
404
- if (listed.has(identity)) continue;
405
- listed.add(identity);
449
+ const seenDeclarations = listed.get(opened.client) ?? new Set<string>();
450
+ listed.set(opened.client, seenDeclarations);
451
+ if (seenDeclarations.has(identity)) continue;
452
+ seenDeclarations.add(identity);
406
453
  const declared = await toMatch(location, opened.client);
407
454
  const symbol: SearchSymbol = {
408
- id: JSON.stringify([client.serverId, declared.source, location.range]),
455
+ id: JSON.stringify([
456
+ typescript ? "typescript" : client.serverId,
457
+ declared.source,
458
+ location.range,
459
+ ]),
409
460
  name: entry?.name ?? definition.name,
410
461
  kind: String(entry?.kind ?? definition.kind),
411
462
  ...(entry !== undefined && { selector: entry.selector }),
@@ -535,7 +586,14 @@ async function searchSymbolsOnce(
535
586
  contents: new Map(
536
587
  returned.map((hit) => [hit.source, requiredValue(mappedOnto.get(hit.source))]),
537
588
  ),
538
- complete: (resultScope?.complete ?? true) && kept.length <= limit && coverageComplete(coverage),
589
+ complete:
590
+ (resultScope?.complete ?? true) &&
591
+ kept.length <= limit &&
592
+ coverageComplete(coverage) &&
593
+ skipped.size === 0 &&
594
+ candidateLimits.length === 0,
595
+ ...(candidateLimits.length > 0 && { candidateLimits }),
596
+ ...(skipped.size > 0 && { skipped: [...skipped.values()] }),
539
597
  ...(coverage !== undefined && !coverageComplete(coverage) && { coverage }),
540
598
  ...(missing.size > 0 && { missing: [...missing].sort() }),
541
599
  };
@@ -130,6 +130,54 @@ export function declarationsNamed(
130
130
  return groupDeclarations(named(symbols));
131
131
  }
132
132
 
133
+ /**
134
+ * The declarations of one workspace symbol in the current outline of its file.
135
+ *
136
+ * A server can spell the symbol's name differently in its index and in its outline, such as gopls
137
+ * with `Engine.Start` and `(*Engine).Start`, while both ranges select the identifier `Start`. When
138
+ * the text at the indexed `range` is the name or its last identifier, the declaration whose name
139
+ * range is `range` is the symbol, provided its qualified name agrees. Otherwise the index may
140
+ * describe an older text, and the declarations with the same qualified name are the candidates.
141
+ * An empty result means the outline has no such declaration. An undefined entry is a fresh range
142
+ * that no outline entry names; the workspace location then stands for the declaration.
143
+ */
144
+ export function declarationsForWorkspaceSymbol(
145
+ outline: readonly LspCodeSymbol[],
146
+ name: string,
147
+ range: LspRange,
148
+ textAtRange: string | undefined,
149
+ ): (readonly LspCodeSymbol[] | undefined)[] {
150
+ const qualified = qualifiedName(name);
151
+ const tail = qualified.split(/[.:]+/u).at(-1);
152
+ if (textAtRange === name) return [declarationAt(outline, range)];
153
+ if (textAtRange !== undefined && textAtRange === tail) {
154
+ const found = declarationAt(outline, range);
155
+ if (found === undefined) return [undefined];
156
+ if (found[0] !== undefined && isQualifiedAs(found[0], qualified)) return [found];
157
+ }
158
+ const all = (items: readonly LspCodeSymbol[]): LspCodeSymbol[] =>
159
+ items.flatMap((symbol) => [symbol, ...all(symbol.children)]);
160
+ return groupDeclarations(all(outline).filter((symbol) => isQualifiedAs(symbol, qualified)));
161
+ }
162
+
163
+ /** A name without receiver parentheses, pointer stars, type arguments and spaces. */
164
+ function qualifiedName(name: string): string {
165
+ return name.replace(/\[[^\]]*\]/gu, "").replace(/[()*\s]/gu, "");
166
+ }
167
+
168
+ /**
169
+ * Whether `qualified` names the symbol the way a server's index does: by its own name, as gopls
170
+ * spells a method `(*Engine).Start`, or by the names on its path, as gopls lists a struct field
171
+ * `Holder.Value` in the index and `Value` under `Holder` in the outline. A server that matches a
172
+ * fuzzy query against the full name may put the package first, as in `pkg.Holder.Value`; a name
173
+ * with a container tolerates such a prefix, a bare name cannot tell it from a container.
174
+ */
175
+ function isQualifiedAs(symbol: LspCodeSymbol, qualified: string): boolean {
176
+ return [qualifiedName(symbol.name), symbol.selector.map(qualifiedName).join(".")].some(
177
+ (name) => qualified === name || (name.includes(".") && qualified.endsWith(`.${name}`)),
178
+ );
179
+ }
180
+
133
181
  /** The declaration entries that contain `range` as their name range. */
134
182
  export function declarationAt(
135
183
  symbols: readonly LspCodeSymbol[],
@@ -8,6 +8,7 @@ import type { LspClient } from "./client.ts";
8
8
  import type { LspManager } from "./manager.ts";
9
9
  import type { LspRange } from "./types.ts";
10
10
  import { sourceChanged } from "./source-changes.ts";
11
+ import { hasTypeScriptProjectQueries, requestTsserver } from "./project.ts";
11
12
 
12
13
  // ── Types ────────────────────────────────────────────────────────────
13
14
 
@@ -97,6 +98,64 @@ export interface LspWorkspaceSymbol {
97
98
  containerName?: string;
98
99
  }
99
100
 
101
+ interface TsNavigateToItem {
102
+ readonly name: string;
103
+ readonly kind: string;
104
+ readonly file: string;
105
+ readonly start: { readonly line: number; readonly offset: number };
106
+ readonly end: { readonly line: number; readonly offset: number };
107
+ }
108
+
109
+ // Match typescript-language-server's SymbolKind conversion when no outline entry is available.
110
+ const TS_SYMBOL_KIND = new Map([
111
+ ["file", 1],
112
+ ["module", 2],
113
+ ["class", 5],
114
+ ["local class", 5],
115
+ ["method", 6],
116
+ ["getter", 6],
117
+ ["setter", 6],
118
+ ["property", 7],
119
+ ["JSX attribute", 7],
120
+ ["field", 8],
121
+ ["constructor", 9],
122
+ ["enum", 10],
123
+ ["interface", 11],
124
+ ["function", 12],
125
+ ["local function", 12],
126
+ ["const", 14],
127
+ ["enum member", 14],
128
+ ]);
129
+
130
+ async function requestTypeScriptSymbols(
131
+ client: LspClient,
132
+ query: string,
133
+ signal?: AbortSignal,
134
+ ): Promise<LspWorkspaceSymbol[]> {
135
+ // TLS passes its first open file to navto, which can select an unrelated project or a
136
+ // document retained by another session. Omitting file searches all of its loaded projects.
137
+ const items = await requestTsserver<TsNavigateToItem[]>(
138
+ client,
139
+ ["navto", { searchValue: query }],
140
+ signal,
141
+ );
142
+ const position = ({ line, offset }: TsNavigateToItem["start"]) => ({
143
+ line: line - 1,
144
+ character: offset - 1,
145
+ });
146
+ // LSP erases tsserver's distinction between import aliases and real declarations.
147
+ return (items ?? [])
148
+ .filter(({ kind }) => kind !== "alias")
149
+ .map((item) => ({
150
+ name: item.name,
151
+ kind: TS_SYMBOL_KIND.get(item.kind) ?? 13,
152
+ location: {
153
+ uri: client.serverPathToDocumentUri(item.file),
154
+ range: { start: position(item.start), end: position(item.end) },
155
+ },
156
+ }));
157
+ }
158
+
100
159
  /**
101
160
  Request workspace symbols from one native LSP server.
102
161
  */
@@ -106,6 +165,8 @@ export async function requestWorkspaceSymbols(
106
165
  limit = 100,
107
166
  signal?: AbortSignal,
108
167
  ): Promise<LspWorkspaceSymbol[]> {
168
+ if (hasTypeScriptProjectQueries(client))
169
+ return (await requestTypeScriptSymbols(client, query, signal)).slice(0, limit);
109
170
  const result = await client.sendRequest<LspWorkspaceSymbol[] | null>(
110
171
  "workspace/symbol",
111
172
  {
@@ -17,7 +17,7 @@ import type { LspClient } from "./lsp/client.ts";
17
17
  import type { LspPosition, LspTextEdit } from "./lsp/types.ts";
18
18
  import { documentUri } from "./lsp/document-uri.ts";
19
19
  import { assertLspLines } from "./lsp/line-breaks.ts";
20
- import { loadQueryProject } from "./lsp/navigation.ts";
20
+ import { loadQueryProject } from "./lsp/project.ts";
21
21
  import { diagnosticErrors, textInRange, withoutCorrectedNames } from "./lsp/corrected-names.ts";
22
22
  import {
23
23
  CLANG_LANGUAGES,
@@ -26,7 +26,12 @@ import {
26
26
  import { coverageNotes, mergeCoverage, type ClangCoverage } from "./lsp/clang-coverage.ts";
27
27
  import { missingSourcesNotes } from "./lsp/missing-sources.ts";
28
28
  import type { LspManager } from "./lsp/manager.ts";
29
- import { searchSymbols, type SymbolHit } from "./lsp/symbol-search.ts";
29
+ import {
30
+ searchSymbols,
31
+ type SkippedSymbol,
32
+ type SymbolHit,
33
+ type WorkspaceSymbolCandidateLimit,
34
+ } from "./lsp/symbol-search.ts";
30
35
  import { withLspDocuments } from "./lsp/document-leases.ts";
31
36
  import { retryWhileSourceChanges, sourceChanged } from "./lsp/source-changes.ts";
32
37
  import { lspRangeMatch } from "./lsp/range-match.ts";
@@ -58,6 +63,8 @@ type Payload =
58
63
  readonly coverage?: ClangCoverage;
59
64
  /** Files the server reported places in that no longer exist. */
60
65
  readonly missing?: readonly string[];
66
+ readonly skipped?: readonly SkippedSymbol[];
67
+ readonly candidateLimits?: readonly WorkspaceSymbolCandidateLimit[];
61
68
  readonly references: boolean;
62
69
  readonly data: unknown;
63
70
  }
@@ -340,6 +347,8 @@ export function createLspSearchResolver(
340
347
  let complete = scope?.complete ?? true;
341
348
  const coverages: (ClangCoverage | undefined)[] = [];
342
349
  const missing = new Set<string>();
350
+ const skipped = new Map<string, SkippedSymbol>();
351
+ const candidateLimits = new Map<string, WorkspaceSymbolCandidateLimit>();
343
352
  for (const [manager, { targets, paths }] of groups) {
344
353
  const found = await backend.searchSymbols(
345
354
  query,
@@ -366,7 +375,11 @@ export function createLspSearchResolver(
366
375
  }
367
376
  complete = complete && found.complete;
368
377
  coverages.push(found.coverage);
378
+ for (const cap of found.candidateLimits ?? [])
379
+ candidateLimits.set(JSON.stringify([cap.server, cap.limit]), cap);
369
380
  for (const source of found.missing ?? []) missing.add(source);
381
+ for (const candidate of found.skipped ?? [])
382
+ skipped.set(JSON.stringify([candidate.source, candidate.name]), candidate);
370
383
  }
371
384
  for (const source of conflicting) contents.delete(source);
372
385
  // The search session keeps these hits and its refresh closure for as long as its anchors
@@ -378,7 +391,13 @@ export function createLspSearchResolver(
378
391
  hits: hits.slice(0, limit),
379
392
  complete: complete && hits.length <= limit,
380
393
  ...(coverage && { coverage }),
394
+ ...(candidateLimits.size > 0 && { candidateLimits: [...candidateLimits.values()] }),
381
395
  ...(missing.size > 0 && { missing: [...missing].sort() }),
396
+ ...(skipped.size > 0 && {
397
+ skipped: [...skipped.values()].sort(
398
+ (a, b) => a.source.localeCompare(b.source) || a.name.localeCompare(b.name),
399
+ ),
400
+ }),
382
401
  }),
383
402
  contents,
384
403
  };
@@ -412,9 +431,13 @@ export function createLspSearchResolver(
412
431
  complete: found.complete,
413
432
  ...(found.coverage && { coverage: found.coverage }),
414
433
  ...(found.missing && { missing: found.missing }),
434
+ ...(found.candidateLimits && { candidateLimits: found.candidateLimits }),
435
+ ...(found.skipped && { skipped: found.skipped }),
415
436
  references,
416
437
  data: {
417
438
  ...data,
439
+ ...(found.candidateLimits && { candidateLimits: found.candidateLimits }),
440
+ ...(found.skipped && { skipped: found.skipped }),
418
441
  matches: data.matches.map((match, index) => ({
419
442
  ...match,
420
443
  role: found.hits[index]?.role,
@@ -458,7 +481,9 @@ export function createLspSearchResolver(
458
481
  [
459
482
  ...(data.references ? ["LSP reference navigation · may leave input scope"] : []),
460
483
  ...coverageNotes(data.coverage, (source) => displaySource(source, data.cwd)),
484
+ ...candidateLimitNotes(data.candidateLimits),
461
485
  ...missingSourcesNotes(data.missing ?? [], (source) => displaySource(source, data.cwd)),
486
+ ...skippedSymbolNotes(data.skipped, (source) => displaySource(source, data.cwd)),
462
487
  ],
463
488
  data.hits.map((hit) => `${hit.role} ${hit.symbol.name}`),
464
489
  );
@@ -500,7 +525,7 @@ export function createLspSearchResolver(
500
525
  : "LSP symbols inside scope";
501
526
  const lines =
502
527
  result.hits.length === 0
503
- ? ["No symbols found."]
528
+ ? [result.skipped ? "No resolvable symbols found." : "No symbols found."]
504
529
  : result.hits.slice(0, 100).map(
505
530
  (hit, index) =>
506
531
  `SEARCH#${result.sessionId}:${index + 1}:match ${display(hit.source)}:${hit.lineNumber}:${hit.startColumn + 1} ${hit.role} ${hit.symbol.name} · ${
@@ -514,7 +539,9 @@ export function createLspSearchResolver(
514
539
  lines.unshift(`SEARCH#${result.sessionId}:all:match selects all exact symbol matches.`);
515
540
  if (result.hits.length > 100) lines.push("Preview shortened; full source targets retained.");
516
541
  lines.push(...coverageNotes(result.coverage, display));
542
+ lines.push(...candidateLimitNotes(result.candidateLimits));
517
543
  lines.push(...missingSourcesNotes(result.missing ?? [], display));
544
+ lines.push(...skippedSymbolNotes(result.skipped, display));
518
545
  return {
519
546
  content: [{ type: "text", text: [heading, ...lines].join("\n") }],
520
547
  details: { ...result, cwd: context.cwd },
@@ -523,6 +550,28 @@ export function createLspSearchResolver(
523
550
  };
524
551
  }
525
552
 
553
+ function candidateLimitNotes(limits: readonly WorkspaceSymbolCandidateLimit[] = []): string[] {
554
+ return limits.map(
555
+ ({ server, limit }) =>
556
+ `${server} reached its workspace symbol limit (${limit}) before scope filtering. Try a narrower query.`,
557
+ );
558
+ }
559
+
560
+ /** Show why coverage is incomplete without letting a large index reply dominate the preview. */
561
+ function skippedSymbolNotes(
562
+ skipped: readonly SkippedSymbol[] | undefined,
563
+ display: (source: string) => string,
564
+ ): string[] {
565
+ if (!skipped?.length) return [];
566
+ const limit = 8;
567
+ const shown = skipped
568
+ .slice(0, limit)
569
+ .map(({ name, source }) => `${name} in ${display(source)}`)
570
+ .join(", ");
571
+ const more = skipped.length > limit ? ` (and ${skipped.length - limit} more)` : "";
572
+ return [`Skipped symbols with no declaration anchor: ${shown}${more}.`];
573
+ }
574
+
526
575
  /** A source as the result names it: relative to the workspace, or its ssh:// URI. */
527
576
  function displaySource(source: string, cwd: string): string {
528
577
  return source.startsWith("ssh://") ? source : path.relative(cwd, source);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-image",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "exports": {
@@ -10,7 +10,7 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "pi-agent-resource": "1.0.0"
13
+ "pi-agent-resource": "1.0.1"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "@earendil-works/pi-coding-agent": "*"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-invariant",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-pdf",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "exports": {
@@ -10,6 +10,6 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "pi-agent-resource": "1.0.0"
13
+ "pi-agent-resource": "1.0.1"
14
14
  }
15
15
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-read",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "pi-agent-documentation": "1.0.0",
28
- "pi-agent-invariant": "1.0.0",
29
- "pi-agent-resource": "1.0.0",
30
- "pi-agent-text": "1.0.0",
31
- "pi-agent-tool-call-interception": "1.0.0",
32
- "pi-agent-tool-ui": "1.0.0"
27
+ "pi-agent-documentation": "1.0.1",
28
+ "pi-agent-invariant": "1.0.1",
29
+ "pi-agent-resource": "1.0.1",
30
+ "pi-agent-text": "1.0.1",
31
+ "pi-agent-tool-call-interception": "1.0.1",
32
+ "pi-agent-tool-ui": "1.0.1"
33
33
  },
34
34
  "pi": {
35
35
  "extensions": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-resource",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "types": "./src/index.ts",
6
6
  "imports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-search",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
@@ -20,9 +20,9 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "pi-agent-resource": "1.0.0",
24
- "pi-agent-tool-call-interception": "1.0.0",
25
- "pi-agent-tool-ui": "1.0.0"
23
+ "pi-agent-resource": "1.0.1",
24
+ "pi-agent-tool-call-interception": "1.0.1",
25
+ "pi-agent-tool-ui": "1.0.1"
26
26
  },
27
27
  "pi": {
28
28
  "extensions": [