@mrclrchtr/supi-code-intelligence 11.3.0 → 12.0.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 (132) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +15 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  7. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  8. package/node_modules/@mrclrchtr/supi-lsp/README.md +22 -17
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  19. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
  20. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
  25. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
  27. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +67 -3
  30. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
  32. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
  34. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  35. package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +106 -16
  37. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
  58. package/package.json +5 -5
  59. package/src/analysis/health/server-status.ts +41 -12
  60. package/src/analysis/helpers.ts +0 -7
  61. package/src/analysis/relations/implementations.ts +5 -0
  62. package/src/analysis/relations/references.ts +5 -0
  63. package/src/analysis/target/anchored-structural.ts +4 -1
  64. package/src/analysis/target/file-merge.ts +162 -0
  65. package/src/analysis/target/file-outline-omissions.ts +146 -0
  66. package/src/analysis/target/file-refinement.ts +7 -7
  67. package/src/analysis/target/file.ts +44 -156
  68. package/src/analysis/target/symbol.ts +5 -1
  69. package/src/analysis/target/types.ts +32 -6
  70. package/src/api.ts +1 -1
  71. package/src/app/app.ts +9 -3
  72. package/src/session/find-types.ts +8 -4
  73. package/src/session/find-workflow.ts +11 -16
  74. package/src/session/graph/collect.ts +2 -0
  75. package/src/session/graph-types.ts +3 -1
  76. package/src/session/graph-workflow.ts +5 -4
  77. package/src/session/input/health-refactor.ts +48 -34
  78. package/src/session/input/workflows.ts +45 -46
  79. package/src/session/inspect/file-point.ts +2 -2
  80. package/src/session/inspect-types.ts +1 -1
  81. package/src/session/inspect-workflow.ts +3 -3
  82. package/src/session/orientation/workspace-context.ts +3 -0
  83. package/src/session/orientation-workflow.ts +6 -3
  84. package/src/session/refactor-file-actions.ts +122 -0
  85. package/src/session/refactor-plan-pipeline.ts +152 -0
  86. package/src/session/refactor-plans.ts +18 -15
  87. package/src/session/refactor-types.ts +24 -12
  88. package/src/session/refactor-workflow.ts +70 -244
  89. package/src/session/session.ts +87 -12
  90. package/src/session/target-workflow.ts +23 -21
  91. package/src/tool/code_find/execute.ts +6 -7
  92. package/src/tool/code_find/spec.ts +9 -16
  93. package/src/tool/code_find/tui.ts +12 -6
  94. package/src/tool/code_graph/section.ts +4 -0
  95. package/src/tool/code_graph/spec.ts +6 -0
  96. package/src/tool/code_health/spec.ts +6 -0
  97. package/src/tool/code_health/structured-schema.ts +4 -4
  98. package/src/tool/code_health/structured.ts +15 -17
  99. package/src/tool/code_inspect/execute.ts +1 -1
  100. package/src/tool/code_inspect/markdown.ts +33 -6
  101. package/src/tool/code_inspect/result.ts +1 -1
  102. package/src/tool/code_inspect/spec.ts +14 -6
  103. package/src/tool/code_inspect/structured.ts +2 -2
  104. package/src/tool/code_inspect/tui.ts +2 -2
  105. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  106. package/src/tool/code_orientation/spec.ts +8 -0
  107. package/src/tool/code_orientation/workspace-output.ts +40 -13
  108. package/src/tool/code_orientation/workspace-sections.ts +45 -2
  109. package/src/tool/code_refactor_apply/result.ts +2 -1
  110. package/src/tool/code_refactor_apply/spec.ts +7 -0
  111. package/src/tool/code_refactor_plan/execute.ts +0 -2
  112. package/src/tool/code_refactor_plan/result.ts +23 -13
  113. package/src/tool/code_refactor_plan/spec.ts +8 -2
  114. package/src/tool/code_refactor_plan/structured.ts +59 -12
  115. package/src/tool/code_refactor_plan/tui.ts +14 -17
  116. package/src/tool/code_resolve/guidance.ts +1 -1
  117. package/src/tool/code_resolve/markdown.ts +121 -34
  118. package/src/tool/code_resolve/result.ts +18 -15
  119. package/src/tool/code_resolve/spec.ts +6 -0
  120. package/src/tool/code_resolve/structured.ts +43 -10
  121. package/src/tool/namespace.ts +14 -0
  122. package/src/tool/refactor-markdown.ts +55 -15
  123. package/src/tool/register.ts +3 -0
  124. package/src/tool/result/model-budget.ts +2 -2
  125. package/src/tool/result/refactor-preview.ts +118 -0
  126. package/src/tool/result/refactor-unavailable.ts +16 -0
  127. package/src/tool/result/refactor.ts +8 -2
  128. package/src/tool/result/types.ts +13 -10
  129. package/src/tool/schemas.ts +63 -20
  130. package/src/tool/specs.ts +3 -0
  131. package/src/ui/status-overlay.ts +1 -1
  132. package/src/ui/tui/common.ts +10 -10
@@ -6,7 +6,7 @@ import type { AutomaticLspPathPolicy } from "@mrclrchtr/supi-lsp/api";
6
6
  import { SEMANTIC_READINESS_TIMEOUT_REASON } from "../analysis/readiness.ts";
7
7
  import { resolveScopeSet } from "../analysis/search/paths.ts";
8
8
  import { getStructuredPatternMatches } from "../analysis/search/pattern.ts";
9
- import { isCodeFindAstKind } from "../tool/code_find/ast-kinds.ts";
9
+ import type { CodeFindAstKind } from "../tool/code_find/ast-kinds.ts";
10
10
  import type { CapabilityAdapter } from "./capability-adapter.ts";
11
11
  import type { FindWorkflowInput, FindWorkflowOutcome } from "./find-types.ts";
12
12
  import { parseFindWorkflowInput } from "./input/workflows.ts";
@@ -29,10 +29,9 @@ export async function runFindWorkflow(
29
29
  const parsed = parseFindWorkflowInput(input);
30
30
  if (parsed.kind === "invalid-input") return parsed;
31
31
  const request = parsed.value;
32
- const query = request.query;
33
- const mode = request.mode;
32
+ const mode = "ast" in request.search ? "ast" : "semantic";
34
33
 
35
- const scope = resolveScopeSet(request.scope ? [...request.scope] : undefined, deps.cwd);
34
+ const scope = resolveScopeSet(request.scopes ? [...request.scopes] : undefined, deps.cwd);
36
35
  if (scope.kind === "error") return { kind: "invalid-input", message: scope.reason };
37
36
 
38
37
  if (mode === "ast") control?.signal?.throwIfAborted();
@@ -45,9 +44,9 @@ export async function runFindWorkflow(
45
44
 
46
45
  const maxResults = request.maxResults ?? 8;
47
46
  const scopeLabel = scope.display ?? ".";
48
- if (mode === "semantic") {
47
+ if ("semantic" in request.search) {
49
48
  return runSemanticSearch({
50
- query,
49
+ query: request.search.semantic.query,
51
50
  scopePaths: scope.paths,
52
51
  scopeLabel,
53
52
  maxResults,
@@ -56,8 +55,7 @@ export async function runFindWorkflow(
56
55
  });
57
56
  }
58
57
  return runAstSearch({
59
- query,
60
- input: request,
58
+ search: request.search.ast,
61
59
  scopePaths: scope.paths,
62
60
  scopeLabel,
63
61
  maxResults,
@@ -108,25 +106,22 @@ async function runSemanticSearch(options: {
108
106
  }
109
107
 
110
108
  async function runAstSearch(options: {
111
- query: string;
112
- input: FindWorkflowInput;
109
+ search: { readonly kind: CodeFindAstKind; readonly query: string };
113
110
  scopePaths: readonly string[];
114
111
  scopeLabel: string;
115
112
  maxResults: number;
116
113
  deps: FindWorkflowDeps;
117
114
  control?: WorkflowControl;
118
115
  }): Promise<FindWorkflowOutcome> {
119
- const { query, input, scopePaths, scopeLabel, maxResults, deps, control } = options;
120
- if (!isCodeFindAstKind(input.kind)) {
121
- return { kind: "invalid-input", message: "Unsupported AST kind." };
122
- }
116
+ const { search, scopePaths, scopeLabel, maxResults, deps, control } = options;
117
+ const { kind, query } = search;
123
118
  const provider = deps.capability.getStructuralProvider(deps.cwd);
124
119
  if (!provider) {
125
120
  return { kind: "unavailable", reason: "No structural provider is active." };
126
121
  }
127
122
  control?.signal?.throwIfAborted();
128
123
  const outcome = await getStructuredPatternMatches({
129
- params: { pattern: query, kind: input.kind },
124
+ params: { pattern: query, kind },
130
125
  roots: scopePaths,
131
126
  cwd: deps.cwd,
132
127
  structural: provider,
@@ -145,6 +140,6 @@ async function runAstSearch(options: {
145
140
  mode: "ast",
146
141
  scopeLabel,
147
142
  maxResults,
148
- data: { kind: "ast", astKind: input.kind, result: outcome.result },
143
+ data: { kind: "ast", astKind: kind, result: outcome.result },
149
144
  };
150
145
  }
@@ -88,6 +88,7 @@ async function collectReferences(options: CollectRelationOptions): Promise<Graph
88
88
  externalCount: result.externalCount,
89
89
  invalidLocationCount: result.invalidLocationCount,
90
90
  partialReason: result.partialReason,
91
+ partialMessage: result.partialMessage,
91
92
  confidence: "semantic",
92
93
  },
93
94
  readNext: [
@@ -189,6 +190,7 @@ async function collectImplementationsRelation(
189
190
  externalCount: result.externalCount,
190
191
  invalidLocationCount: result.invalidLocationCount,
191
192
  partialReason: result.partialReason,
193
+ partialMessage: result.partialMessage,
192
194
  },
193
195
  readNext: result.implementations
194
196
  .slice(0, Math.min(options.maxResults, 2))
@@ -32,6 +32,7 @@ export type GraphSection =
32
32
  readonly externalCount: number;
33
33
  readonly invalidLocationCount: number;
34
34
  readonly partialReason: RelationLocationPartialReason | null;
35
+ readonly partialMessage: string | null;
35
36
  readonly confidence: "semantic";
36
37
  };
37
38
  readonly readNext: readonly ReadNextItem[];
@@ -59,6 +60,7 @@ export type GraphSection =
59
60
  readonly externalCount: number;
60
61
  readonly invalidLocationCount: number;
61
62
  readonly partialReason: RelationLocationPartialReason | null;
63
+ readonly partialMessage: string | null;
62
64
  };
63
65
  readonly readNext: readonly ReadNextItem[];
64
66
  }
@@ -82,4 +84,4 @@ export interface CompletedGraphWorkflow {
82
84
  /** Graph workflow outcome, preserving target disambiguation and failure states. */
83
85
  export type GraphWorkflowOutcome =
84
86
  | CompletedGraphWorkflow
85
- | Exclude<TargetWorkflowOutcome, { kind: "resolved" } | { kind: "target-group" }>;
87
+ | Exclude<TargetWorkflowOutcome, { kind: "resolved" } | { kind: "file-outline" }>;
@@ -57,10 +57,11 @@ export async function runGraphWorkflow(
57
57
  control,
58
58
  );
59
59
  throwIfAborted(control);
60
- if (targetOutcome.kind === "target-group") {
60
+ if (targetOutcome.kind === "file-outline") {
61
61
  return {
62
62
  kind: "invalid-input",
63
- message: "Graph analysis requires one member handle from a Target group.",
63
+ message:
64
+ "Graph analysis requires one declaration, not a whole file. Pass one handle from the file outline as target.handle.",
64
65
  };
65
66
  }
66
67
  if (targetOutcome.kind !== "resolved") return targetOutcome;
@@ -155,6 +156,6 @@ async function getSemanticReadinessError(options: {
155
156
  /** Narrow helper retained for session method typing. */
156
157
  export function isTargetFailure(
157
158
  outcome: TargetWorkflowOutcome,
158
- ): outcome is Exclude<TargetWorkflowOutcome, { kind: "resolved" } | { kind: "target-group" }> {
159
- return outcome.kind !== "resolved" && outcome.kind !== "target-group";
159
+ ): outcome is Exclude<TargetWorkflowOutcome, { kind: "resolved" } | { kind: "file-outline" }> {
160
+ return outcome.kind !== "resolved" && outcome.kind !== "file-outline";
160
161
  }
@@ -79,17 +79,11 @@ export function parseRefactorPlanWorkflowInput(
79
79
  ): InputValidation<RefactorPlanWorkflowInput> {
80
80
  const record = requireRecord(value, "code_refactor_plan input");
81
81
  if (record.kind === "invalid-input") return record;
82
- const keysError = requireOnlyKeys(
83
- record.value,
84
- ["target", "operation"],
85
- "code_refactor_plan input",
86
- );
82
+ const keysError = requireOnlyKeys(record.value, ["operation"], "code_refactor_plan input");
87
83
  if (keysError) return invalid(keysError);
88
- const target = parseTargetInput(record.value.target, ["handle", "anchor"]);
89
- if (target.kind === "invalid-input") return target;
90
84
  const operation = parseRefactorOperation(record.value.operation);
91
85
  if (operation.kind === "invalid-input") return operation;
92
- return valid({ target: target.value as RefactorTargetInput, operation: operation.value });
86
+ return valid({ operation: operation.value });
93
87
  }
94
88
 
95
89
  function parseRefactorOperation(value: unknown): InputValidation<RefactorOperationInput> {
@@ -104,56 +98,76 @@ function parseRefactorOperation(value: unknown): InputValidation<RefactorOperati
104
98
  const payload = requireRecord(record.value[name], `operation.${name}`);
105
99
  if (payload.kind === "invalid-input") return payload;
106
100
  if (name === "rename_symbol") return parseRenameOperation(payload.value);
107
- if (name === "extract_function" || name === "extract_variable") {
108
- return parseExtractOperation(name, payload.value);
109
- }
110
- const payloadError = requireOnlyKeys(payload.value, [], `operation.${name}`);
111
- if (payloadError) return invalid(payloadError);
112
- return name === "update_imports"
113
- ? valid({ update_imports: {} })
114
- : valid({ delete_dead_code: {} });
101
+ return parseActionOperation(name, payload.value);
115
102
  }
116
103
 
117
104
  function parseRenameOperation(
118
105
  payload: Record<string, unknown>,
119
106
  ): InputValidation<RefactorOperationInput> {
120
- const payloadError = requireOnlyKeys(payload, ["newName"], "operation.rename_symbol");
107
+ const payloadError = requireOnlyKeys(payload, ["target", "newName"], "operation.rename_symbol");
121
108
  if (payloadError) return invalid(payloadError);
109
+ const target = parseTargetInput(payload.target, ["handle", "anchor"]);
110
+ if (target.kind === "invalid-input") return target;
122
111
  const newName = requireString(payload.newName, "operation.rename_symbol.newName", {
123
112
  nonEmpty: true,
124
113
  });
125
- return newName.kind === "valid" ? valid({ rename_symbol: { newName: newName.value } }) : newName;
114
+ if (newName.kind === "invalid-input") return newName;
115
+ return valid({
116
+ rename_symbol: { target: target.value as RefactorTargetInput, newName: newName.value },
117
+ });
126
118
  }
127
119
 
128
- function parseExtractOperation(
129
- name: "extract_function" | "extract_variable",
120
+ /** Kind family each action operation accepts; `quickfix` and `notebook` kinds are never valid. */
121
+ const ACTION_KIND_FAMILY = { code_action: "refactor", source_action: "source" } as const;
122
+
123
+ function parseActionOperation(
124
+ name: "code_action" | "source_action",
130
125
  payload: Record<string, unknown>,
131
126
  ): InputValidation<RefactorOperationInput> {
132
- const payloadError = requireOnlyKeys(payload, ["newName", "range"], `operation.${name}`);
127
+ const label = `operation.${name}`;
128
+ const allowed =
129
+ name === "code_action" ? ["file", "range", "kind", "title"] : ["file", "kind", "title"];
130
+ const payloadError = requireOnlyKeys(payload, allowed, label);
133
131
  if (payloadError) return invalid(payloadError);
134
- const newName = requireString(payload.newName, `operation.${name}.newName`, { nonEmpty: true });
135
- if (newName.kind === "invalid-input") return newName;
136
- const range = parsePublicRange(payload.range);
132
+ const file = requireString(payload.file, `${label}.file`, { nonEmpty: true });
133
+ if (file.kind === "invalid-input") return file;
134
+ const kind = requireString(payload.kind, `${label}.kind`, { nonEmpty: true });
135
+ if (kind.kind === "invalid-input") return kind;
136
+ const family = ACTION_KIND_FAMILY[name];
137
+ if (kind.value !== family && !kind.value.startsWith(`${family}.`)) {
138
+ return invalid(`${label}.kind must be "${family}" or start with "${family}.".`);
139
+ }
140
+ const title =
141
+ payload.title === undefined
142
+ ? valid(undefined)
143
+ : requireString(payload.title, `${label}.title`, { nonEmpty: true });
144
+ if (title.kind === "invalid-input") return title;
145
+ const selection = {
146
+ file: file.value,
147
+ kind: kind.value,
148
+ ...(title.value === undefined ? {} : { title: title.value }),
149
+ };
150
+ if (name === "source_action") return valid({ source_action: selection });
151
+ const range = parsePublicRange(payload.range, `${label}.range`);
137
152
  if (range.kind === "invalid-input") return range;
138
- return name === "extract_function"
139
- ? valid({ extract_function: { newName: newName.value, range: range.value } })
140
- : valid({ extract_variable: { newName: newName.value, range: range.value } });
153
+ return valid({ code_action: { ...selection, range: range.value } });
141
154
  }
142
155
 
143
- function parsePublicRange(value: unknown): InputValidation<PublicSourceRange> {
144
- const record = requireRecord(value, "range");
156
+ /** Parse a one-based range; an empty range (`start` equal to `end`) marks a cursor position. */
157
+ function parsePublicRange(value: unknown, label: string): InputValidation<PublicSourceRange> {
158
+ const record = requireRecord(value, label);
145
159
  if (record.kind === "invalid-input") return record;
146
- const keysError = requireOnlyKeys(record.value, ["start", "end"], "range");
160
+ const keysError = requireOnlyKeys(record.value, ["start", "end"], label);
147
161
  if (keysError) return invalid(keysError);
148
- const start = parsePosition(record.value.start, "range.start");
162
+ const start = parsePosition(record.value.start, `${label}.start`);
149
163
  if (start.kind === "invalid-input") return start;
150
- const end = parsePosition(record.value.end, "range.end");
164
+ const end = parsePosition(record.value.end, `${label}.end`);
151
165
  if (end.kind === "invalid-input") return end;
152
166
  if (
153
167
  end.value.line < start.value.line ||
154
- (end.value.line === start.value.line && end.value.character <= start.value.character)
168
+ (end.value.line === start.value.line && end.value.character < start.value.character)
155
169
  ) {
156
- return invalid("range.end must be after range.start.");
170
+ return invalid(`${label}.end must not be before ${label}.start.`);
157
171
  }
158
172
  return valid({ start: start.value, end: end.value });
159
173
  }
@@ -1,8 +1,8 @@
1
1
  /** Runtime parsers for inspection, Orientation, graph, and find workflows. */
2
2
 
3
- import { type CodeFindAstKind, isCodeFindAstKind } from "../../tool/code_find/ast-kinds.ts";
3
+ import { isCodeFindAstKind } from "../../tool/code_find/ast-kinds.ts";
4
4
  import { CODE_FIND_MODES } from "../../tool/code_find/modes.ts";
5
- import type { FindMode, FindWorkflowInput } from "../find-types.ts";
5
+ import type { FindMode, FindSearchInput, FindWorkflowInput } from "../find-types.ts";
6
6
  import type { GraphWorkflowInput, RequestedGraphRelation } from "../graph-types.ts";
7
7
  import type { InspectWorkflowInput } from "../inspect-types.ts";
8
8
  import type { OrientationFocusInput, OrientationWorkflowInput } from "../orientation-types.ts";
@@ -19,7 +19,6 @@ import {
19
19
  valid,
20
20
  } from "./common.ts";
21
21
 
22
- const FIND_MODES = new Set<FindMode>(CODE_FIND_MODES);
23
22
  const GRAPH_RELATIONS = new Set<RequestedGraphRelation>([
24
23
  "all",
25
24
  "references",
@@ -30,14 +29,14 @@ const GRAPH_RELATIONS = new Set<RequestedGraphRelation>([
30
29
  export function parseInspectWorkflowInput(value: unknown): InputValidation<InspectWorkflowInput> {
31
30
  const record = requireRecord(value, "code_inspect input");
32
31
  if (record.kind === "invalid-input") return record;
33
- const keysError = requireOnlyKeys(record.value, ["point", "maxResults"], "code_inspect input");
32
+ const keysError = requireOnlyKeys(record.value, ["anchor", "maxResults"], "code_inspect input");
34
33
  if (keysError) return invalid(keysError);
35
- const point = parseSourcePoint(record.value.point);
36
- if (point.kind === "invalid-input") return point;
34
+ const anchor = parseSourcePoint(record.value.anchor, "anchor");
35
+ if (anchor.kind === "invalid-input") return anchor;
37
36
  const maxResults = optionalPositiveInteger(record.value.maxResults, "maxResults");
38
37
  if (maxResults.kind === "invalid-input") return maxResults;
39
38
  return valid({
40
- point: point.value,
39
+ anchor: anchor.value,
41
40
  ...(maxResults.value === undefined ? {} : { maxResults: maxResults.value }),
42
41
  });
43
42
  }
@@ -149,63 +148,63 @@ export function parseFindWorkflowInput(value: unknown): InputValidation<FindWork
149
148
  if (record.kind === "invalid-input") return record;
150
149
  const keysError = requireOnlyKeys(
151
150
  record.value,
152
- ["query", "scope", "mode", "kind", "maxResults"],
151
+ ["search", "scopes", "maxResults"],
153
152
  "code_find input",
154
153
  );
155
154
  if (keysError) return invalid(keysError);
156
- const query = requireString(record.value.query, "query", { nonEmpty: true });
157
- if (query.kind === "invalid-input") return query;
158
- const scope = parseFindScope(record.value.scope);
159
- if (scope.kind === "invalid-input") return scope;
160
- const mode = parseFindMode(record.value.mode);
161
- if (mode.kind === "invalid-input") return mode;
162
- const patternKind = parsePatternKind(record.value.kind);
163
- if (patternKind.kind === "invalid-input") return patternKind;
164
- const modeError = validateFindModeFields(mode.value, patternKind.value);
165
- if (modeError) return invalid(modeError);
155
+ const search = parseFindSearch(record.value.search);
156
+ if (search.kind === "invalid-input") return search;
157
+ const scopes = parseFindScopes(record.value.scopes);
158
+ if (scopes.kind === "invalid-input") return scopes;
166
159
  const maxResults = optionalPositiveInteger(record.value.maxResults, "maxResults");
167
160
  if (maxResults.kind === "invalid-input") return maxResults;
168
161
  return valid({
169
- query: query.value,
170
- ...(scope.value === undefined ? {} : { scope: scope.value }),
171
- mode: mode.value,
172
- ...(patternKind.value === undefined ? {} : { kind: patternKind.value }),
162
+ search: search.value,
163
+ ...(scopes.value === undefined ? {} : { scopes: scopes.value }),
173
164
  ...(maxResults.value === undefined ? {} : { maxResults: maxResults.value }),
174
165
  });
175
166
  }
176
167
 
177
- function parseFindScope(value: unknown): InputValidation<readonly string[] | undefined> {
168
+ function parseFindSearch(value: unknown): InputValidation<FindSearchInput> {
169
+ const record = requireRecord(value, "search");
170
+ if (record.kind === "invalid-input") return record;
171
+ const keysError = requireOnlyKeys(record.value, CODE_FIND_MODES, "search");
172
+ if (keysError) return invalid(keysError);
173
+ const selected = CODE_FIND_MODES.filter((mode) => record.value[mode] !== undefined);
174
+ if (selected.length !== 1) {
175
+ return invalid("search must contain exactly one of `ast` or `semantic`.");
176
+ }
177
+ const mode = selected[0] as FindMode;
178
+ const label = `search.${mode}`;
179
+ const branch = requireRecord(record.value[mode], label);
180
+ if (branch.kind === "invalid-input") return branch;
181
+ const branchKeysError = requireOnlyKeys(
182
+ branch.value,
183
+ mode === "ast" ? ["kind", "query"] : ["query"],
184
+ label,
185
+ );
186
+ if (branchKeysError) return invalid(branchKeysError);
187
+ const query = requireString(branch.value.query, `${label}.query`, { nonEmpty: true });
188
+ if (query.kind === "invalid-input") return query;
189
+ if (mode === "semantic") return valid({ semantic: { query: query.value } });
190
+ return isCodeFindAstKind(branch.value.kind)
191
+ ? valid({ ast: { kind: branch.value.kind, query: query.value } })
192
+ : invalid(
193
+ branch.value.kind === undefined ? "search.ast.kind is required." : "Unsupported AST kind.",
194
+ );
195
+ }
196
+
197
+ function parseFindScopes(value: unknown): InputValidation<readonly string[] | undefined> {
178
198
  if (value === undefined) return valid(undefined);
179
199
  if (
180
200
  !Array.isArray(value) ||
181
201
  value.length === 0 ||
182
202
  !value.every((item) => typeof item === "string")
183
203
  ) {
184
- return invalid("scope must be a non-empty array of workspace-relative paths.");
204
+ return invalid("scopes must be a non-empty array of workspace-relative paths.");
185
205
  }
186
206
  if (value.some((item) => item.trim().length === 0)) {
187
- return invalid("scope must not contain empty paths.");
207
+ return invalid("scopes must not contain empty paths.");
188
208
  }
189
209
  return valid(value);
190
210
  }
191
-
192
- function parseFindMode(value: unknown): InputValidation<FindMode> {
193
- return typeof value === "string" && FIND_MODES.has(value as FindMode)
194
- ? valid(value as FindMode)
195
- : invalid("mode is required and must be one of ast or semantic.");
196
- }
197
-
198
- function parsePatternKind(value: unknown): InputValidation<CodeFindAstKind | undefined> {
199
- if (value === undefined) return valid(undefined);
200
- return isCodeFindAstKind(value) ? valid(value) : invalid("Unsupported AST kind.");
201
- }
202
-
203
- function validateFindModeFields(
204
- mode: FindMode,
205
- patternKind: CodeFindAstKind | undefined,
206
- ): string | null {
207
- if (mode === "ast" && patternKind === undefined) return 'mode "ast" requires kind.';
208
- return mode !== "ast" && patternKind !== undefined
209
- ? `kind is not valid with mode "${mode}".`
210
- : null;
211
- }
@@ -42,7 +42,7 @@ export function validateInspectPoint(
42
42
  if (point.line > lines.length) {
43
43
  return {
44
44
  kind: "invalid-input",
45
- message: `Point line ${point.line} is beyond the end of \`${point.file}\` (${lines.length} lines).`,
45
+ message: `Anchor line ${point.line} is beyond the end of \`${point.file}\` (${lines.length} lines).`,
46
46
  };
47
47
  }
48
48
 
@@ -51,7 +51,7 @@ export function validateInspectPoint(
51
51
  if (point.character > maximumCharacter) {
52
52
  return {
53
53
  kind: "invalid-input",
54
- message: `Point character ${point.character} is beyond line ${point.line} of \`${point.file}\` (maximum ${maximumCharacter}, 1-based UTF-16).`,
54
+ message: `Anchor character ${point.character} is beyond line ${point.line} of \`${point.file}\` (maximum ${maximumCharacter}, 1-based UTF-16).`,
55
55
  };
56
56
  }
57
57
 
@@ -7,7 +7,7 @@ import type { SourcePointInput } from "./target-input.ts";
7
7
 
8
8
  /** Canonical code_inspect workflow input. */
9
9
  export interface InspectWorkflowInput {
10
- readonly point: SourcePointInput;
10
+ readonly anchor: SourcePointInput;
11
11
  readonly maxResults?: number;
12
12
  }
13
13
 
@@ -30,7 +30,7 @@ export async function runInspectWorkflow(
30
30
  const parsed = parseInspectWorkflowInput(input);
31
31
  if (parsed.kind === "invalid-input") return parsed;
32
32
  const request = parsed.value;
33
- const point = validateInspectPoint(request.point, deps.cwd);
33
+ const point = validateInspectPoint(request.anchor, deps.cwd);
34
34
  if (point.kind === "invalid-input") return point;
35
35
  throwIfAborted(control);
36
36
 
@@ -63,7 +63,7 @@ export async function runInspectWorkflow(
63
63
  structural: deps.capability.getStructuralProvider(deps.cwd),
64
64
  semantic,
65
65
  semanticUnavailableReason: semantic
66
- ? "Semantic point query unavailable."
66
+ ? "Semantic anchor query unavailable."
67
67
  : semanticReadinessReason(readiness),
68
68
  lspState,
69
69
  });
@@ -72,7 +72,7 @@ export async function runInspectWorkflow(
72
72
  if (everySectionUnavailable(sections)) {
73
73
  return {
74
74
  kind: "unavailable",
75
- reason: "No semantic, structural, or diagnostic provider could inspect this point.",
75
+ reason: "No semantic, structural, or diagnostic provider could inspect this anchor.",
76
76
  };
77
77
  }
78
78
 
@@ -20,6 +20,8 @@ export interface WorkspaceOrientationFacts {
20
20
  /** Absolute explicit focus, or null for the session working directory. */
21
21
  readonly focus: string | null;
22
22
  readonly maxResults: number;
23
+ /** True when the caller set `maxResults`; directory file lists then honor it exactly. */
24
+ readonly maxResultsExplicit?: boolean;
23
25
  readonly overview?: boolean;
24
26
  }
25
27
 
@@ -64,6 +66,7 @@ export async function orientWorkspaceContext(
64
66
  cwd: options.cwd,
65
67
  focus,
66
68
  maxResults: request.maxResults ?? 10,
69
+ maxResultsExplicit: request.maxResults !== undefined,
67
70
  }),
68
71
  focusKind: workspaceFocusKind(request),
69
72
  },
@@ -30,6 +30,8 @@ import { reportProgress, throwIfAborted, type WorkflowControl } from "./workflow
30
30
  export interface OrientationWorkflowDeps extends TargetWorkflowDeps {
31
31
  readonly capability: CapabilityAdapter;
32
32
  readonly nativeInstructionPaths: Set<string>;
33
+ /** Absolute files read in full since the latest compaction; not embedded again. */
34
+ readonly fullyReadPaths: Set<string>;
33
35
  readonly surfacedInstructionDirs: Set<string>;
34
36
  /** Whether the project is trusted — controls instruction-file discovery. */
35
37
  readonly projectTrusted: boolean;
@@ -122,10 +124,11 @@ async function orientTarget(options: {
122
124
  control,
123
125
  );
124
126
  throwIfAborted(control);
125
- if (target.kind === "target-group") {
127
+ if (target.kind === "file-outline") {
126
128
  return {
127
129
  kind: "invalid-input",
128
- message: "Precise Orientation requires one member handle from a Target group.",
130
+ message:
131
+ "Orientation on a target requires one declaration, not a whole file. Pass one handle from the file outline as target.handle, or use focus.path for the file.",
129
132
  };
130
133
  }
131
134
  if (target.kind === "disambiguation" || target.kind === "kind-mismatch") {
@@ -244,7 +247,7 @@ function addInstructionFiles(
244
247
  directory: focusPath,
245
248
  cwd: deps.cwd,
246
249
  fileNames: config.instructionFileNames,
247
- nativeContextPaths: deps.nativeInstructionPaths,
250
+ nativeContextPaths: new Set([...deps.nativeInstructionPaths, ...deps.fullyReadPaths]),
248
251
  surfacedDirectories: deps.surfacedInstructionDirs,
249
252
  projectTrusted: deps.projectTrusted,
250
253
  });
@@ -0,0 +1,122 @@
1
+ /** Code- and source-action refactor planning for one named file. */
2
+
3
+ import { existsSync, readFileSync, statSync } from "node:fs";
4
+ import type { RefactorRequest, SourceRange } from "@mrclrchtr/supi-code-runtime/api";
5
+ import { toLspPosition } from "@mrclrchtr/supi-lsp/api";
6
+ import { normalizePath } from "../analysis/search/paths.ts";
7
+ import {
8
+ ensureFileReadiness,
9
+ finishProviderPlan,
10
+ planWithProvider,
11
+ type RefactorWorkflowDeps,
12
+ } from "./refactor-plan-pipeline.ts";
13
+ import type {
14
+ PublicSourceRange,
15
+ RefactorOperationInput,
16
+ RefactorPlanWorkflowOutcome,
17
+ } from "./refactor-types.ts";
18
+ import { reportProgress, throwIfAborted, type WorkflowControl } from "./workflow-control.ts";
19
+
20
+ /**
21
+ * Plan one code or source action. These operations name a file directly and
22
+ * never resolve a symbol target; source actions cover the whole document.
23
+ */
24
+ export async function planFileAction(
25
+ operation: Exclude<RefactorOperationInput, { rename_symbol: unknown }>,
26
+ deps: RefactorWorkflowDeps,
27
+ control?: WorkflowControl,
28
+ ): Promise<RefactorPlanWorkflowOutcome> {
29
+ const { name, selection, range } =
30
+ "code_action" in operation
31
+ ? {
32
+ name: "code_action" as const,
33
+ selection: operation.code_action,
34
+ range: operation.code_action.range,
35
+ }
36
+ : { name: "source_action" as const, selection: operation.source_action, range: undefined };
37
+ const file = normalizePath(selection.file, deps.cwd);
38
+ const fileError = validateActionFile(file, selection.file, `operation.${name}.file`);
39
+ if (fileError) return { kind: "invalid-input", message: fileError };
40
+ const rangeError = range
41
+ ? validateRangeWithinFile(file, selection.file, range, `operation.${name}.range`)
42
+ : null;
43
+ if (rangeError) return { kind: "invalid-input", message: rangeError };
44
+
45
+ const readiness = await ensureFileReadiness(file, deps, control);
46
+ if (readiness) return readiness;
47
+ reportProgress(control, {
48
+ intent: "refactor-plan",
49
+ phase: "provider",
50
+ message: `Requesting ${selection.kind} code actions`,
51
+ });
52
+ const action = {
53
+ file,
54
+ kind: selection.kind,
55
+ ...(selection.title === undefined ? {} : { title: selection.title }),
56
+ };
57
+ const request: RefactorRequest = range
58
+ ? { operation: "code_action", ...action, range: toLspRange(range) }
59
+ : { operation: "source_action", ...action };
60
+ const result = await planWithProvider(
61
+ deps.capability.getSemanticProvider(deps.cwd),
62
+ request,
63
+ control,
64
+ );
65
+ throwIfAborted(control);
66
+ return finishProviderPlan(result, deps, {
67
+ operation: name,
68
+ file,
69
+ discriminator: `${selection.kind}:${selection.title ?? ""}:${JSON.stringify(range ?? null)}`,
70
+ fields: range ? { range } : {},
71
+ evidenceSource: "semantic",
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Check that an action file exists and is a file. The routed language server
77
+ * enforces its own project root before any request.
78
+ */
79
+ function validateActionFile(file: string, input: string, label: string): string | null {
80
+ if (!existsSync(file)) return `File not found: \`${input}\``;
81
+ if (statSync(file).isDirectory()) {
82
+ return `${label} must be a file, not a directory: \`${input}\`.`;
83
+ }
84
+ return null;
85
+ }
86
+
87
+ /**
88
+ * Check that both range ends lie inside the file's current disk text, so an
89
+ * out-of-range position fails as input instead of as a server error. Positions
90
+ * are one-based UTF-16; a line's maximum character is one past its last character.
91
+ */
92
+ function validateRangeWithinFile(
93
+ file: string,
94
+ input: string,
95
+ range: PublicSourceRange,
96
+ label: string,
97
+ ): string | null {
98
+ let lines: string[];
99
+ try {
100
+ lines = readFileSync(file, "utf-8").split(/\r\n|\r|\n/);
101
+ } catch {
102
+ return `Cannot read file: \`${input}\``;
103
+ }
104
+ for (const end of ["start", "end"] as const) {
105
+ const { line, character } = range[end];
106
+ if (line > lines.length) {
107
+ return `${label}.${end} line ${line} is beyond the end of \`${input}\` (${lines.length} lines).`;
108
+ }
109
+ const maximum = (lines[line - 1] ?? "").length + 1;
110
+ if (character > maximum) {
111
+ return `${label}.${end} character ${character} is beyond line ${line} of \`${input}\` (maximum ${maximum}, 1-based UTF-16).`;
112
+ }
113
+ }
114
+ return null;
115
+ }
116
+
117
+ function toLspRange(range: PublicSourceRange): SourceRange {
118
+ return {
119
+ start: toLspPosition(range.start.line, range.start.character),
120
+ end: toLspPosition(range.end.line, range.end.character),
121
+ };
122
+ }