@oh-my-pi/pi-coding-agent 15.3.2 → 15.4.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 (191) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/types/cli/file-processor.d.ts +1 -1
  3. package/dist/types/config/settings-schema.d.ts +45 -3
  4. package/dist/types/config/settings.d.ts +1 -1
  5. package/dist/types/debug/raw-sse.d.ts +2 -0
  6. package/dist/types/edit/file-read-cache.d.ts +15 -4
  7. package/dist/types/edit/index.d.ts +3 -8
  8. package/dist/types/edit/renderer.d.ts +1 -2
  9. package/dist/types/eval/__tests__/shared-executors.test.d.ts +1 -0
  10. package/dist/types/eval/js/shared/local-module-loader.d.ts +16 -0
  11. package/dist/types/eval/js/shared/rewrite-imports.d.ts +4 -0
  12. package/dist/types/eval/js/shared/runtime.d.ts +14 -8
  13. package/dist/types/eval/py/executor.d.ts +1 -2
  14. package/dist/types/eval/py/kernel.d.ts +6 -0
  15. package/dist/types/eval/py/tool-bridge.d.ts +1 -5
  16. package/dist/types/eval/session-id.d.ts +3 -0
  17. package/dist/types/extensibility/extensions/types.d.ts +1 -3
  18. package/dist/types/hashline/anchors.d.ts +15 -9
  19. package/dist/types/hashline/constants.d.ts +0 -2
  20. package/dist/types/hashline/diff.d.ts +1 -2
  21. package/dist/types/hashline/executor.d.ts +52 -0
  22. package/dist/types/hashline/hash.d.ts +44 -93
  23. package/dist/types/hashline/index.d.ts +2 -1
  24. package/dist/types/hashline/input.d.ts +2 -9
  25. package/dist/types/hashline/recovery.d.ts +3 -9
  26. package/dist/types/hashline/tokenizer.d.ts +91 -0
  27. package/dist/types/hashline/types.d.ts +5 -7
  28. package/dist/types/modes/components/extensions/types.d.ts +0 -4
  29. package/dist/types/modes/types.d.ts +1 -0
  30. package/dist/types/modes/utils/ui-helpers.d.ts +1 -0
  31. package/dist/types/sdk.d.ts +2 -0
  32. package/dist/types/session/agent-session.d.ts +11 -15
  33. package/dist/types/session/agent-storage.d.ts +11 -10
  34. package/dist/types/slash-commands/acp-builtins.d.ts +3 -3
  35. package/dist/types/slash-commands/types.d.ts +0 -5
  36. package/dist/types/task/executor.d.ts +2 -0
  37. package/dist/types/tool-discovery/tool-index.d.ts +0 -50
  38. package/dist/types/tools/index.d.ts +2 -8
  39. package/dist/types/tools/match-line-format.d.ts +4 -4
  40. package/dist/types/tools/output-schema-validator.d.ts +64 -0
  41. package/dist/types/tools/review.d.ts +13 -0
  42. package/dist/types/tools/search-tool-bm25.d.ts +1 -1
  43. package/dist/types/tools/search.d.ts +4 -3
  44. package/dist/types/utils/edit-mode.d.ts +1 -1
  45. package/dist/types/web/kagi.d.ts +4 -2
  46. package/dist/types/web/parallel.d.ts +4 -3
  47. package/dist/types/web/scrapers/types.d.ts +2 -1
  48. package/dist/types/web/search/index.d.ts +12 -4
  49. package/dist/types/web/search/provider.d.ts +2 -1
  50. package/dist/types/web/search/providers/anthropic.d.ts +9 -4
  51. package/dist/types/web/search/providers/base.d.ts +34 -2
  52. package/dist/types/web/search/providers/brave.d.ts +8 -1
  53. package/dist/types/web/search/providers/codex.d.ts +13 -9
  54. package/dist/types/web/search/providers/exa.d.ts +10 -1
  55. package/dist/types/web/search/providers/gemini.d.ts +20 -23
  56. package/dist/types/web/search/providers/jina.d.ts +2 -1
  57. package/dist/types/web/search/providers/kagi.d.ts +4 -1
  58. package/dist/types/web/search/providers/kimi.d.ts +10 -1
  59. package/dist/types/web/search/providers/parallel.d.ts +3 -2
  60. package/dist/types/web/search/providers/perplexity.d.ts +5 -2
  61. package/dist/types/web/search/providers/searxng.d.ts +2 -1
  62. package/dist/types/web/search/providers/synthetic.d.ts +5 -8
  63. package/dist/types/web/search/providers/tavily.d.ts +11 -4
  64. package/dist/types/web/search/providers/utils.d.ts +8 -6
  65. package/dist/types/web/search/providers/zai.d.ts +12 -3
  66. package/package.json +7 -7
  67. package/src/cli/file-processor.ts +12 -2
  68. package/src/cli.ts +0 -8
  69. package/src/commands/commit.ts +8 -8
  70. package/src/config/prompt-templates.ts +6 -6
  71. package/src/config/settings-schema.ts +47 -3
  72. package/src/config/settings.ts +5 -5
  73. package/src/debug/raw-sse.ts +68 -3
  74. package/src/edit/file-read-cache.ts +68 -25
  75. package/src/edit/index.ts +6 -37
  76. package/src/edit/renderer.ts +9 -47
  77. package/src/edit/streaming.ts +43 -56
  78. package/src/eval/__tests__/shared-executors.test.ts +520 -0
  79. package/src/eval/js/context-manager.ts +64 -53
  80. package/src/eval/js/shared/local-module-loader.ts +265 -0
  81. package/src/eval/js/shared/prelude.txt +4 -0
  82. package/src/eval/js/shared/rewrite-imports.ts +85 -0
  83. package/src/eval/js/shared/runtime.ts +129 -86
  84. package/src/eval/js/worker-core.ts +23 -38
  85. package/src/eval/py/executor.ts +155 -84
  86. package/src/eval/py/kernel.ts +10 -1
  87. package/src/eval/py/prelude.py +22 -24
  88. package/src/eval/py/runner.py +203 -85
  89. package/src/eval/py/tool-bridge.ts +17 -10
  90. package/src/eval/session-id.ts +8 -0
  91. package/src/exec/bash-executor.ts +27 -16
  92. package/src/extensibility/extensions/runner.ts +0 -1
  93. package/src/extensibility/extensions/types.ts +1 -3
  94. package/src/hashline/anchors.ts +56 -65
  95. package/src/hashline/apply.ts +29 -31
  96. package/src/hashline/constants.ts +0 -3
  97. package/src/hashline/diff-preview.ts +4 -5
  98. package/src/hashline/diff.ts +30 -4
  99. package/src/hashline/execute.ts +91 -26
  100. package/src/hashline/executor.ts +239 -0
  101. package/src/hashline/grammar.lark +12 -10
  102. package/src/hashline/hash.ts +69 -114
  103. package/src/hashline/index.ts +2 -1
  104. package/src/hashline/input.ts +48 -41
  105. package/src/hashline/prefixes.ts +21 -11
  106. package/src/hashline/recovery.ts +63 -71
  107. package/src/hashline/stream.ts +2 -2
  108. package/src/hashline/tokenizer.ts +467 -0
  109. package/src/hashline/types.ts +6 -8
  110. package/src/internal-urls/docs-index.generated.ts +7 -7
  111. package/src/modes/components/extensions/types.ts +0 -5
  112. package/src/modes/components/session-observer-overlay.ts +11 -2
  113. package/src/modes/components/tree-selector.ts +10 -2
  114. package/src/modes/controllers/command-controller.ts +1 -3
  115. package/src/modes/controllers/extension-ui-controller.ts +10 -11
  116. package/src/modes/controllers/selector-controller.ts +5 -5
  117. package/src/modes/types.ts +4 -1
  118. package/src/modes/utils/ui-helpers.ts +4 -0
  119. package/src/prompts/agents/explore.md +1 -1
  120. package/src/prompts/tools/ast-edit.md +1 -1
  121. package/src/prompts/tools/ast-grep.md +1 -1
  122. package/src/prompts/tools/eval.md +1 -1
  123. package/src/prompts/tools/hashline.md +73 -94
  124. package/src/prompts/tools/read.md +4 -4
  125. package/src/prompts/tools/search.md +3 -3
  126. package/src/sdk.ts +17 -23
  127. package/src/session/agent-session.ts +59 -66
  128. package/src/session/agent-storage.ts +13 -14
  129. package/src/slash-commands/acp-builtins.ts +3 -3
  130. package/src/slash-commands/types.ts +0 -6
  131. package/src/task/executor.ts +26 -57
  132. package/src/task/index.ts +8 -4
  133. package/src/tool-discovery/tool-index.ts +0 -134
  134. package/src/tools/ast-edit.ts +36 -13
  135. package/src/tools/ast-grep.ts +45 -4
  136. package/src/tools/browser/tab-worker.ts +3 -2
  137. package/src/tools/eval.ts +2 -1
  138. package/src/tools/fetch.ts +23 -14
  139. package/src/tools/index.ts +2 -8
  140. package/src/tools/irc.ts +59 -5
  141. package/src/tools/match-line-format.ts +5 -7
  142. package/src/tools/output-schema-validator.ts +132 -0
  143. package/src/tools/read.ts +142 -31
  144. package/src/tools/review.ts +23 -0
  145. package/src/tools/search-tool-bm25.ts +3 -30
  146. package/src/tools/search.ts +48 -16
  147. package/src/tools/write.ts +3 -3
  148. package/src/tools/yield.ts +32 -41
  149. package/src/utils/edit-mode.ts +1 -2
  150. package/src/utils/file-mentions.ts +2 -2
  151. package/src/web/kagi.ts +15 -6
  152. package/src/web/parallel.ts +9 -6
  153. package/src/web/scrapers/types.ts +7 -1
  154. package/src/web/scrapers/youtube.ts +13 -7
  155. package/src/web/search/index.ts +37 -11
  156. package/src/web/search/provider.ts +5 -3
  157. package/src/web/search/providers/anthropic.ts +30 -21
  158. package/src/web/search/providers/base.ts +35 -2
  159. package/src/web/search/providers/brave.ts +4 -4
  160. package/src/web/search/providers/codex.ts +118 -89
  161. package/src/web/search/providers/exa.ts +3 -2
  162. package/src/web/search/providers/gemini.ts +58 -155
  163. package/src/web/search/providers/jina.ts +4 -4
  164. package/src/web/search/providers/kagi.ts +17 -11
  165. package/src/web/search/providers/kimi.ts +29 -13
  166. package/src/web/search/providers/parallel.ts +171 -23
  167. package/src/web/search/providers/perplexity.ts +38 -37
  168. package/src/web/search/providers/searxng.ts +3 -1
  169. package/src/web/search/providers/synthetic.ts +16 -19
  170. package/src/web/search/providers/tavily.ts +23 -18
  171. package/src/web/search/providers/utils.ts +11 -17
  172. package/src/web/search/providers/zai.ts +16 -8
  173. package/dist/types/hashline/parser.d.ts +0 -7
  174. package/dist/types/mcp/discoverable-tool-metadata.d.ts +0 -7
  175. package/dist/types/tools/vim.d.ts +0 -58
  176. package/dist/types/vim/buffer.d.ts +0 -41
  177. package/dist/types/vim/commands.d.ts +0 -6
  178. package/dist/types/vim/engine.d.ts +0 -47
  179. package/dist/types/vim/parser.d.ts +0 -3
  180. package/dist/types/vim/render.d.ts +0 -25
  181. package/dist/types/vim/types.d.ts +0 -182
  182. package/src/hashline/parser.ts +0 -246
  183. package/src/mcp/discoverable-tool-metadata.ts +0 -24
  184. package/src/prompts/tools/vim.md +0 -98
  185. package/src/tools/vim.ts +0 -949
  186. package/src/vim/buffer.ts +0 -309
  187. package/src/vim/commands.ts +0 -382
  188. package/src/vim/engine.ts +0 -2409
  189. package/src/vim/parser.ts +0 -134
  190. package/src/vim/render.ts +0 -252
  191. package/src/vim/types.ts +0 -197
@@ -1,58 +0,0 @@
1
- import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
2
- import type { Component } from "@oh-my-pi/pi-tui";
3
- import * as z from "zod/v4";
4
- import type { RenderResultOptions } from "../extensibility/custom-tools/types";
5
- import { type Theme } from "../modes/theme/theme";
6
- import type { VimToolDetails } from "../vim/types";
7
- import type { ToolSession } from ".";
8
- declare const vimSchema: z.ZodObject<{
9
- file: z.ZodString;
10
- steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
11
- kbd: z.ZodArray<z.ZodString>;
12
- insert: z.ZodOptional<z.ZodString>;
13
- }, z.core.$strip>>>;
14
- pause: z.ZodOptional<z.ZodBoolean>;
15
- }, z.core.$strip>;
16
- type VimParams = z.infer<typeof vimSchema>;
17
- interface VimRenderStep {
18
- kbd?: string[];
19
- insert?: string;
20
- }
21
- export interface VimRenderArgs {
22
- file?: string;
23
- steps?: VimRenderStep[];
24
- pause?: boolean;
25
- __partialJson?: string;
26
- }
27
- export declare class VimTool implements AgentTool<typeof vimSchema, VimToolDetails> {
28
- #private;
29
- private readonly session;
30
- readonly name = "vim";
31
- readonly label = "Vim";
32
- readonly description: string;
33
- readonly parameters: z.ZodObject<{
34
- file: z.ZodString;
35
- steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
- kbd: z.ZodArray<z.ZodString>;
37
- insert: z.ZodOptional<z.ZodString>;
38
- }, z.core.$strip>>>;
39
- pause: z.ZodOptional<z.ZodBoolean>;
40
- }, z.core.$strip>;
41
- readonly concurrency = "exclusive";
42
- constructor(session: ToolSession);
43
- execute(_toolCallId: string, params: VimParams, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<VimToolDetails>, _context?: AgentToolContext): Promise<AgentToolResult<VimToolDetails>>;
44
- }
45
- export declare function resetVimRendererStateForTest(): void;
46
- export declare const vimToolRenderer: {
47
- renderCall(args: VimRenderArgs, options: RenderResultOptions, uiTheme: Theme): Component;
48
- renderResult(result: {
49
- content: Array<{
50
- type: string;
51
- text?: string;
52
- }>;
53
- details?: VimToolDetails;
54
- isError?: boolean;
55
- }, options: RenderResultOptions, uiTheme: Theme): Component;
56
- mergeCallAndResult: boolean;
57
- };
58
- export { vimSchema };
@@ -1,41 +0,0 @@
1
- import { type Position, type VimBufferSnapshot, type VimFingerprint, type VimLoadedFile } from "./types";
2
- export declare function snapshotEqual(left: VimBufferSnapshot, right: VimBufferSnapshot): boolean;
3
- export declare class VimBuffer {
4
- displayPath: string;
5
- filePath: string;
6
- lines: string[];
7
- cursor: Position;
8
- modified: boolean;
9
- trailingNewline: boolean;
10
- baseFingerprint: VimFingerprint | null;
11
- editabilityChecked: boolean;
12
- constructor(input: VimLoadedFile);
13
- clone(): VimBuffer;
14
- createSnapshot(): VimBufferSnapshot;
15
- restore(snapshot: VimBufferSnapshot): void;
16
- replaceLoadedFile(input: VimLoadedFile): void;
17
- markSaved(input: VimLoadedFile): void;
18
- lineCount(): number;
19
- lastLineIndex(): number;
20
- getLine(line: number): string;
21
- clampLine(line: number): number;
22
- clampCol(line: number, col: number): number;
23
- setCursor(position: Position): void;
24
- clampCursor(): void;
25
- firstNonBlank(line: number): number;
26
- getText(): string;
27
- setText(text: string, trailingNewline?: boolean): void;
28
- currentOffset(): number;
29
- positionToOffset(position: Position): number;
30
- offsetToPosition(offset: number): Position;
31
- setCursorFromOffset(offset: number): void;
32
- replaceOffsets(start: number, end: number, replacement: string, cursorOffset?: number): void;
33
- deleteOffsets(start: number, end: number): string;
34
- deleteLines(startLine: number, endLine: number): string[];
35
- insertLines(index: number, newLines: string[]): void;
36
- replaceLine(line: number, content: string): void;
37
- joinLines(startLine: number, count: number): void;
38
- indentLines(startLine: number, endLine: number, indentUnit: string, direction: 1 | -1): void;
39
- getCharacterAtOffset(offset: number): string;
40
- getCharacter(position: Position): string;
41
- }
@@ -1,6 +0,0 @@
1
- import type { VimExCommand } from "./types";
2
- export interface VimExParseContext {
3
- currentLine: number;
4
- lastLine: number;
5
- }
6
- export declare function parseExCommand(input: string, context?: VimExParseContext): VimExCommand;
@@ -1,47 +0,0 @@
1
- import type { FileDiagnosticsResult } from "../lsp";
2
- import { type VimBuffer } from "./buffer";
3
- import type { Position, VimInputMode, VimKeyToken, VimLoadedFile, VimPendingInput, VimRegister, VimSearchState, VimSelection } from "./types";
4
- export interface VimSaveResult {
5
- loaded: VimLoadedFile;
6
- diagnostics?: FileDiagnosticsResult;
7
- }
8
- export interface VimEngineCallbacks {
9
- beforeMutate: (buffer: VimBuffer) => Promise<void>;
10
- loadBuffer: (path: string) => Promise<VimLoadedFile>;
11
- saveBuffer: (buffer: VimBuffer, options?: {
12
- force?: boolean;
13
- }) => Promise<VimSaveResult>;
14
- }
15
- export declare class VimEngine {
16
- #private;
17
- buffer: VimBuffer;
18
- inputMode: VimInputMode;
19
- selectionAnchor: Position | null;
20
- register: VimRegister;
21
- lastSearch: VimSearchState | null;
22
- lastCharFind: {
23
- char: string;
24
- mode: "f" | "F" | "t" | "T";
25
- } | null;
26
- lastVisual: {
27
- anchor: Position;
28
- cursor: Position;
29
- mode: VimInputMode;
30
- } | null;
31
- lastCommand?: string;
32
- statusMessage?: string;
33
- diagnostics?: FileDiagnosticsResult;
34
- viewportStart: number;
35
- closed: boolean;
36
- constructor(buffer: VimBuffer, callbacks: VimEngineCallbacks);
37
- clone(callbacks?: Partial<VimEngineCallbacks>): VimEngine;
38
- getPublicMode(): import("./types").VimMode;
39
- getSelection(): VimSelection | undefined;
40
- getPendingInput(): VimPendingInput | undefined;
41
- rollbackPendingInsert(): void;
42
- setCursor(line: number, col: number): void;
43
- executeTokens(tokens: readonly VimKeyToken[], lastCommand?: string, onStep?: () => Promise<void>): Promise<void>;
44
- close(force: boolean): Promise<void>;
45
- centerViewportOnCursor(size?: number): void;
46
- applyLiteralInsert(text: string, exitInsertMode: boolean): Promise<void>;
47
- }
@@ -1,3 +0,0 @@
1
- import { type VimKeyToken } from "./types";
2
- export declare function parseKeySequences(sequences: string[]): VimKeyToken[];
3
- export declare function replayTokens(values: readonly string[]): VimKeyToken[];
@@ -1,25 +0,0 @@
1
- import type { VimErrorLocation, VimMode, VimPendingInput, VimSelection, VimToolDetails, VimViewport } from "./types";
2
- export declare const VIM_OPEN_VIEWPORT_LINES = 80;
3
- export declare const VIM_DEFAULT_VIEWPORT_LINES = 10;
4
- interface ViewportRenderInput {
5
- file: string;
6
- mode: VimMode;
7
- cursor: {
8
- line: number;
9
- col: number;
10
- };
11
- totalLines: number;
12
- modified: boolean;
13
- lines: string[];
14
- viewport: VimViewport;
15
- selection?: VimSelection;
16
- statusMessage?: string;
17
- lastCommand?: string;
18
- pendingInput?: VimPendingInput;
19
- errorLocation?: VimErrorLocation;
20
- closed?: boolean;
21
- }
22
- export declare function computeViewport(cursorLine: number, totalLines: number, size: number, preferredStart?: number): VimViewport;
23
- export declare function renderVimDetails(details: VimToolDetails): string;
24
- export declare function buildDetails(input: ViewportRenderInput): VimToolDetails;
25
- export {};
@@ -1,182 +0,0 @@
1
- import type { FileDiagnosticsResult } from "../lsp";
2
- import type { OutputMeta } from "../tools/output-meta";
3
- export type VimMode = "NORMAL" | "INSERT" | "VISUAL" | "VISUAL-LINE" | "COMMAND";
4
- export type VimInputMode = "normal" | "insert" | "visual" | "visual-line" | "command" | "search-forward" | "search-backward";
5
- export interface Position {
6
- line: number;
7
- col: number;
8
- }
9
- export interface VimViewport {
10
- start: number;
11
- end: number;
12
- }
13
- export interface VimSelection {
14
- kind: "char" | "line";
15
- start: Position;
16
- end: Position;
17
- }
18
- export interface VimFocusLine {
19
- line: number;
20
- text: string;
21
- windowStartCol: number;
22
- windowEndCol: number;
23
- caretCol: number;
24
- }
25
- export interface VimViewportLine {
26
- line: number;
27
- text: string;
28
- isCursor: boolean;
29
- isSelected: boolean;
30
- cursorCol?: number;
31
- }
32
- export interface VimPendingInput {
33
- kind: "insert" | "command" | "search-forward" | "search-backward";
34
- text: string;
35
- }
36
- export interface VimErrorLocation {
37
- sequenceIndex: number;
38
- offset: number;
39
- }
40
- export interface VimToolDetails {
41
- file: string;
42
- mode: VimMode;
43
- cursor: {
44
- line: number;
45
- col: number;
46
- };
47
- totalLines: number;
48
- modified: boolean;
49
- viewport: VimViewport;
50
- focus?: VimFocusLine;
51
- viewportLines?: VimViewportLine[];
52
- selection?: VimSelection;
53
- pendingInput?: VimPendingInput;
54
- errorLocation?: VimErrorLocation;
55
- closed?: boolean;
56
- meta?: OutputMeta;
57
- lastCommand?: string;
58
- statusMessage?: string;
59
- diagnostics?: FileDiagnosticsResult;
60
- }
61
- export interface VimFingerprint {
62
- exists: boolean;
63
- size: number;
64
- mtimeMs: number;
65
- hash: string;
66
- }
67
- export interface VimLoadedFile {
68
- absolutePath: string;
69
- displayPath: string;
70
- lines: string[];
71
- trailingNewline: boolean;
72
- fingerprint: VimFingerprint | null;
73
- }
74
- export interface VimKeyToken {
75
- value: string;
76
- display: string;
77
- sequenceIndex: number;
78
- offset: number;
79
- }
80
- export interface VimRegister {
81
- kind: "char" | "line";
82
- text: string;
83
- }
84
- export interface VimSearchState {
85
- pattern: string;
86
- direction: 1 | -1;
87
- }
88
- export interface VimBufferSnapshot {
89
- displayPath: string;
90
- filePath: string;
91
- lines: string[];
92
- cursor: Position;
93
- modified: boolean;
94
- trailingNewline: boolean;
95
- baseFingerprint: VimFingerprint | null;
96
- editabilityChecked: boolean;
97
- }
98
- export interface VimUndoEntry {
99
- before: VimBufferSnapshot;
100
- after: VimBufferSnapshot;
101
- }
102
- export interface VimLineRange {
103
- start: number;
104
- end: number;
105
- }
106
- export type VimExCommand = {
107
- kind: "write";
108
- force: boolean;
109
- } | {
110
- kind: "update";
111
- force: boolean;
112
- } | {
113
- kind: "quit";
114
- force: boolean;
115
- } | {
116
- kind: "write-quit";
117
- force: boolean;
118
- } | {
119
- kind: "edit";
120
- force: boolean;
121
- path?: string;
122
- } | {
123
- kind: "goto-line";
124
- line: number;
125
- } | {
126
- kind: "substitute";
127
- range?: VimLineRange | "all";
128
- pattern: string;
129
- replacement: string;
130
- flags: string;
131
- } | {
132
- kind: "delete";
133
- range?: VimLineRange | "all";
134
- } | {
135
- kind: "yank";
136
- range?: VimLineRange | "all";
137
- } | {
138
- kind: "put";
139
- range?: VimLineRange | "all";
140
- before: boolean;
141
- } | {
142
- kind: "copy";
143
- range?: VimLineRange | "all";
144
- destination: number;
145
- } | {
146
- kind: "move";
147
- range?: VimLineRange | "all";
148
- destination: number;
149
- } | {
150
- kind: "sort";
151
- range?: VimLineRange | "all";
152
- flags: string;
153
- } | {
154
- kind: "join";
155
- range?: VimLineRange | "all";
156
- trimWhitespace: boolean;
157
- } | {
158
- kind: "global";
159
- range?: VimLineRange | "all";
160
- pattern: string;
161
- command: string;
162
- invert: boolean;
163
- } | {
164
- kind: "append";
165
- range?: VimLineRange;
166
- text: string;
167
- } | {
168
- kind: "insert-before";
169
- range?: VimLineRange;
170
- text: string;
171
- };
172
- export declare class VimInputError extends Error {
173
- location?: {
174
- sequenceIndex: number;
175
- offset: number;
176
- };
177
- constructor(message: string, token?: VimKeyToken);
178
- }
179
- export declare function clonePosition(position: Position): Position;
180
- export declare function minPosition(left: Position, right: Position): Position;
181
- export declare function maxPosition(left: Position, right: Position): Position;
182
- export declare function toPublicMode(mode: VimInputMode): VimMode;
@@ -1,246 +0,0 @@
1
- import { ABORT_MARKER, ABORT_WARNING, BEGIN_PATCH_MARKER, END_PATCH_MARKER, RANGE_INTERIOR_HASH } from "./constants";
2
- import {
3
- computeLineHash,
4
- describeAnchorExamples,
5
- HL_BODY_SEP_RE_RAW,
6
- HL_FILE_PREFIX,
7
- HL_HASH_CAPTURE_RE_RAW,
8
- HL_OP_CHARS,
9
- HL_OP_INSERT_AFTER,
10
- HL_OP_INSERT_BEFORE,
11
- HL_OP_REPLACE,
12
- } from "./hash";
13
- import type { Anchor, HashlineCursor, HashlineEdit } from "./types";
14
-
15
- // Leniently accept anchors copied from read/search output:
16
- // - optional leading line-marker decoration (`*`, `>`, `+`, `-`)
17
- // - the required `LINE+HASH`
18
- // - an optional trailing `|TEXT` body (or anything after the hash) so users
19
- // can paste a full `LINE+HASH|TEXT` line verbatim.
20
- const LID_CAPTURE_RE = new RegExp(`^\\s*[>+\\-*]*\\s*${HL_HASH_CAPTURE_RE_RAW}(?:\\|.*)?\\s*$`);
21
- const regexEscape = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
22
-
23
- function parseLid(raw: string, lineNum: number): Anchor {
24
- const match = LID_CAPTURE_RE.exec(raw);
25
- if (!match) {
26
- throw new Error(
27
- `line ${lineNum}: expected a full anchor such as ${describeAnchorExamples("119")}; ` +
28
- `got ${JSON.stringify(raw)}.`,
29
- );
30
- }
31
- return { line: Number.parseInt(match[1], 10), hash: match[2] };
32
- }
33
-
34
- interface ParsedRange {
35
- start: Anchor;
36
- end: Anchor;
37
- }
38
-
39
- function parseRange(raw: string, lineNum: number): ParsedRange {
40
- if (!raw.includes("..")) {
41
- const start = parseLid(raw, lineNum);
42
- return { start, end: { ...start } };
43
- }
44
- const [startRaw, endRaw, extra] = raw.split("..");
45
- if (extra !== undefined || !startRaw || !endRaw) {
46
- throw new Error(
47
- `line ${lineNum}: range must include exactly two full anchors separated by "..". ` +
48
- `For a one-line edit, repeat the same anchor on both sides.`,
49
- );
50
- }
51
- const start = parseLid(startRaw, lineNum);
52
- const end = parseLid(endRaw, lineNum);
53
- if (end.line < start.line) {
54
- throw new Error(`line ${lineNum}: range ${startRaw}..${endRaw} ends before it starts.`);
55
- }
56
- if (end.line === start.line && end.hash !== start.hash) {
57
- throw new Error(`line ${lineNum}: range ${startRaw}..${endRaw} uses two different hashes for the same line.`);
58
- }
59
- return { start, end };
60
- }
61
-
62
- function expandRange(range: ParsedRange): Anchor[] {
63
- const anchors: Anchor[] = [];
64
- for (let line = range.start.line; line <= range.end.line; line++) {
65
- const hash =
66
- line === range.start.line ? range.start.hash : line === range.end.line ? range.end.hash : RANGE_INTERIOR_HASH;
67
- anchors.push({ line, hash });
68
- }
69
- return anchors;
70
- }
71
-
72
- function parseInsertTarget(raw: string, lineNum: number, kind: "before" | "after"): HashlineCursor {
73
- if (raw === "BOF") return { kind: "bof" };
74
- if (raw === "EOF") return { kind: "eof" };
75
- const cursorKind = kind === "before" ? "before_anchor" : "after_anchor";
76
- return { kind: cursorKind, anchor: parseLid(raw, lineNum) };
77
- }
78
-
79
- /**
80
- * Decide how to interpret the optional `|TEXT` body captured on an insert
81
- * op line:
82
- * - For BOF/EOF cursors the body is always treated as an inline payload
83
- * line (there's no anchor hash to compare against).
84
- * - For anchored cursors, compute the hash of TEXT at the anchor's line
85
- * number. If it matches the anchor's hash, the body is just a verbatim
86
- * copy of the anchored line — discard it, payload must come from the
87
- * following lines as usual.
88
- * - Otherwise the body is the first (or only) payload line for this op.
89
- */
90
- function resolveInlineInsertBody(cursor: HashlineCursor, body: string | undefined): string | undefined {
91
- if (body === undefined) return undefined;
92
- if (cursor.kind !== "before_anchor" && cursor.kind !== "after_anchor") return body;
93
- const { line, hash } = cursor.anchor;
94
- if (computeLineHash(line, body) === hash) return undefined;
95
- return body;
96
- }
97
-
98
- // Insert ops leniently accept a trailing `|TEXT` body on the op line itself
99
- // (e.g. `»502zk|\tconst foo = ...`). The anchor token excludes `|` so the body
100
- // is captured separately; resolveInlineInsertBody decides whether to treat the
101
- // captured text as a verbatim anchor decoration (when its hash matches the
102
- // anchor's) or as an inline payload line.
103
- const INSERT_BEFORE_OP_RE = new RegExp(
104
- `^${regexEscape(HL_OP_INSERT_BEFORE)}\\s*([^|\\s]+)(?:${HL_BODY_SEP_RE_RAW}(.*))?\\s*$`,
105
- );
106
- const INSERT_AFTER_OP_RE = new RegExp(
107
- `^${regexEscape(HL_OP_INSERT_AFTER)}\\s*([^|\\s]+)(?:${HL_BODY_SEP_RE_RAW}(.*))?\\s*$`,
108
- );
109
- const REPLACE_OP_RE = new RegExp(`^${regexEscape(HL_OP_REPLACE)}\\s*([^\\s+<\\-=]\\S*)\\s*$`);
110
-
111
- function isEnvelopeOrAbortMarkerLine(line: string): boolean {
112
- const trimmed = line.trimEnd();
113
- return trimmed === BEGIN_PATCH_MARKER || trimmed === END_PATCH_MARKER || trimmed === ABORT_MARKER;
114
- }
115
-
116
- function isPayloadTerminatorLine(line: string): boolean {
117
- const first = line[0];
118
- return (
119
- first === HL_FILE_PREFIX ||
120
- (first !== undefined && HL_OP_CHARS.includes(first)) ||
121
- isEnvelopeOrAbortMarkerLine(line)
122
- );
123
- }
124
-
125
- export function cloneCursor(cursor: HashlineCursor): HashlineCursor {
126
- if (cursor.kind === "before_anchor") return { kind: "before_anchor", anchor: { ...cursor.anchor } };
127
- if (cursor.kind === "after_anchor") return { kind: "after_anchor", anchor: { ...cursor.anchor } };
128
- return cursor;
129
- }
130
-
131
- function collectPayload(
132
- lines: string[],
133
- startIndex: number,
134
- opLineNum: number,
135
- requirePayload: boolean,
136
- ): { payload: string[]; nextIndex: number } {
137
- const payload: string[] = [];
138
- let index = startIndex;
139
- while (index < lines.length) {
140
- const line = lines[index];
141
- if (isPayloadTerminatorLine(line)) break;
142
- payload.push(line);
143
- index++;
144
- }
145
- if (payload.length === 0 && requirePayload) {
146
- throw new Error(
147
- `line ${opLineNum}: ${HL_OP_INSERT_BEFORE} and ${HL_OP_INSERT_AFTER} operations require at least one verbatim payload line.`,
148
- );
149
- }
150
- return { payload, nextIndex: index };
151
- }
152
-
153
- export function parseHashline(diff: string): HashlineEdit[] {
154
- return parseHashlineWithWarnings(diff).edits;
155
- }
156
-
157
- export function parseHashlineWithWarnings(diff: string): { edits: HashlineEdit[]; warnings: string[] } {
158
- const edits: HashlineEdit[] = [];
159
- const warnings: string[] = [];
160
- const lines = diff.split(/\r?\n/);
161
- if (diff.endsWith("\n") && lines.at(-1) === "") lines.pop();
162
- let editIndex = 0;
163
-
164
- const pushInsert = (cursor: HashlineCursor, text: string, lineNum: number) => {
165
- edits.push({ kind: "insert", cursor: cloneCursor(cursor), text, lineNum, index: editIndex++ });
166
- };
167
-
168
- for (let i = 0; i < lines.length; ) {
169
- const lineNum = i + 1;
170
- const line = lines[i];
171
-
172
- if (line.trim().length === 0) {
173
- i++;
174
- continue;
175
- }
176
- if (line === END_PATCH_MARKER) {
177
- break;
178
- }
179
- if (line === ABORT_MARKER) {
180
- warnings.push(ABORT_WARNING);
181
- break;
182
- }
183
- if (line === BEGIN_PATCH_MARKER) {
184
- i++;
185
- continue;
186
- }
187
-
188
- const insertBeforeMatch = INSERT_BEFORE_OP_RE.exec(line);
189
- if (insertBeforeMatch) {
190
- const cursor = parseInsertTarget(insertBeforeMatch[1], lineNum, "before");
191
- const inlineBody = resolveInlineInsertBody(cursor, insertBeforeMatch[2]);
192
- const { payload, nextIndex } = collectPayload(lines, i + 1, lineNum, inlineBody === undefined);
193
- if (inlineBody !== undefined) pushInsert(cursor, inlineBody, lineNum);
194
- for (const text of payload) pushInsert(cursor, text, lineNum);
195
- i = nextIndex;
196
- continue;
197
- }
198
-
199
- const insertAfterMatch = INSERT_AFTER_OP_RE.exec(line);
200
- if (insertAfterMatch) {
201
- const cursor = parseInsertTarget(insertAfterMatch[1], lineNum, "after");
202
- const inlineBody = resolveInlineInsertBody(cursor, insertAfterMatch[2]);
203
- const { payload, nextIndex } = collectPayload(lines, i + 1, lineNum, inlineBody === undefined);
204
- if (inlineBody !== undefined) pushInsert(cursor, inlineBody, lineNum);
205
- for (const text of payload) pushInsert(cursor, text, lineNum);
206
- i = nextIndex;
207
- continue;
208
- }
209
-
210
- const replaceMatch = REPLACE_OP_RE.exec(line);
211
- if (replaceMatch) {
212
- const range = parseRange(replaceMatch[1], lineNum);
213
- const { payload, nextIndex } = collectPayload(lines, i + 1, lineNum, false);
214
- if (payload.length > 0) {
215
- for (const text of payload) {
216
- edits.push({
217
- kind: "insert",
218
- cursor: { kind: "before_anchor", anchor: { ...range.start } },
219
- text,
220
- lineNum,
221
- index: editIndex++,
222
- });
223
- }
224
- }
225
- for (const anchor of expandRange(range)) {
226
- edits.push({ kind: "delete", anchor, lineNum, index: editIndex++ });
227
- }
228
- i = nextIndex;
229
- continue;
230
- }
231
-
232
- if (isPayloadTerminatorLine(line) || /^[-@\u00B6]/u.test(line)) {
233
- throw new Error(
234
- `line ${lineNum}: unrecognized op. Use ${HL_OP_INSERT_BEFORE}ANCHOR (insert before), ${HL_OP_INSERT_AFTER}ANCHOR (insert after), or ${HL_OP_REPLACE}A..B (replace/delete). ` +
235
- `Got ${JSON.stringify(line)}.`,
236
- );
237
- }
238
-
239
- throw new Error(
240
- `line ${lineNum}: payload line has no preceding ${HL_OP_INSERT_BEFORE}, ${HL_OP_INSERT_AFTER}, or ${HL_OP_REPLACE} operation. ` +
241
- `Got ${JSON.stringify(line)}.`,
242
- );
243
- }
244
-
245
- return { edits, warnings };
246
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Back-compat re-export layer.
3
- * All types and functions have moved to src/tool-discovery/tool-index.ts.
4
- * This file exists solely so existing imports continue to compile without changes.
5
- */
6
- export type {
7
- DiscoverableMCPSearchDocument,
8
- DiscoverableMCPSearchIndex,
9
- DiscoverableMCPSearchResult,
10
- DiscoverableMCPTool,
11
- DiscoverableMCPToolServerSummary,
12
- DiscoverableMCPToolSummary,
13
- } from "../tool-discovery/tool-index";
14
-
15
- export {
16
- buildDiscoverableMCPSearchIndex,
17
- collectDiscoverableMCPTools,
18
- formatDiscoverableMCPToolServerSummary,
19
- getDiscoverableMCPTool,
20
- isMCPToolName,
21
- searchDiscoverableMCPTools,
22
- selectDiscoverableMCPToolNamesByServer,
23
- summarizeDiscoverableMCPTools,
24
- } from "../tool-discovery/tool-index";