@ilya-lesikov/pi-pi 0.1.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.
- package/3p/pi-ask-user/index.ts +1835 -0
- package/3p/pi-ask-user/package.json +50 -0
- package/3p/pi-ask-user/single-select-layout.ts +203 -0
- package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
- package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
- package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
- package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
- package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
- package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
- package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
- package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
- package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
- package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
- package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
- package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
- package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
- package/3p/pi-lsp/package.json +54 -0
- package/3p/pi-plannotator/AGENTS.md +583 -0
- package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
- package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
- package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
- package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
- package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
- package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
- package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
- package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
- package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
- package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
- package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
- package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
- package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
- package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
- package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
- package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
- package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
- package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
- package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
- package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
- package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
- package/3p/pi-plannotator/package.json +53 -0
- package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
- package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
- package/3p/pi-plannotator/packages/ai/context.ts +250 -0
- package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
- package/3p/pi-plannotator/packages/ai/index.ts +105 -0
- package/3p/pi-plannotator/packages/ai/package.json +21 -0
- package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
- package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
- package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
- package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
- package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
- package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
- package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/ai/types.ts +379 -0
- package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
- package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
- package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
- package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
- package/3p/pi-plannotator/packages/server/browser.ts +245 -0
- package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
- package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
- package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
- package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
- package/3p/pi-plannotator/packages/server/config.ts +8 -0
- package/3p/pi-plannotator/packages/server/draft.ts +1 -0
- package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
- package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
- package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
- package/3p/pi-plannotator/packages/server/git.ts +141 -0
- package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
- package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
- package/3p/pi-plannotator/packages/server/ide.ts +43 -0
- package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
- package/3p/pi-plannotator/packages/server/image.ts +66 -0
- package/3p/pi-plannotator/packages/server/index.ts +648 -0
- package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
- package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
- package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
- package/3p/pi-plannotator/packages/server/jj.ts +86 -0
- package/3p/pi-plannotator/packages/server/p4.ts +417 -0
- package/3p/pi-plannotator/packages/server/package.json +40 -0
- package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
- package/3p/pi-plannotator/packages/server/pr.ts +146 -0
- package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
- package/3p/pi-plannotator/packages/server/project.ts +45 -0
- package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
- package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
- package/3p/pi-plannotator/packages/server/remote.ts +74 -0
- package/3p/pi-plannotator/packages/server/repo.ts +80 -0
- package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
- package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
- package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
- package/3p/pi-plannotator/packages/server/review.ts +1318 -0
- package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
- package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
- package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
- package/3p/pi-plannotator/packages/server/storage.ts +17 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
- package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
- package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
- package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
- package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
- package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
- package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
- package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
- package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
- package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
- package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
- package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
- package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
- package/3p/pi-plannotator/packages/shared/config.ts +262 -0
- package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
- package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
- package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
- package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
- package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
- package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
- package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
- package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
- package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
- package/3p/pi-plannotator/packages/shared/package.json +55 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
- package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
- package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
- package/3p/pi-plannotator/packages/shared/project.ts +71 -0
- package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
- package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
- package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
- package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
- package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
- package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
- package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
- package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
- package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
- package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
- package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
- package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
- package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
- package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/shared/types.ts +29 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
- package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
- package/3p/pi-subagents/package.json +50 -0
- package/3p/pi-subagents/src/agent-manager.ts +413 -0
- package/3p/pi-subagents/src/agent-runner.ts +502 -0
- package/3p/pi-subagents/src/agent-types.ts +248 -0
- package/3p/pi-subagents/src/context.ts +58 -0
- package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
- package/3p/pi-subagents/src/custom-agents.ts +137 -0
- package/3p/pi-subagents/src/default-agents.ts +144 -0
- package/3p/pi-subagents/src/env.ts +33 -0
- package/3p/pi-subagents/src/group-join.ts +141 -0
- package/3p/pi-subagents/src/index.ts +1811 -0
- package/3p/pi-subagents/src/invocation-config.ts +40 -0
- package/3p/pi-subagents/src/memory.ts +165 -0
- package/3p/pi-subagents/src/model-resolver.ts +81 -0
- package/3p/pi-subagents/src/output-file.ts +77 -0
- package/3p/pi-subagents/src/prompts.ts +85 -0
- package/3p/pi-subagents/src/skill-loader.ts +79 -0
- package/3p/pi-subagents/src/types.ts +111 -0
- package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
- package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
- package/3p/pi-subagents/src/worktree.ts +162 -0
- package/3p/pi-tasks/package.json +52 -0
- package/3p/pi-tasks/src/auto-clear.ts +91 -0
- package/3p/pi-tasks/src/index.ts +1150 -0
- package/3p/pi-tasks/src/process-tracker.ts +140 -0
- package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
- package/3p/pi-tasks/src/task-store.ts +324 -0
- package/3p/pi-tasks/src/tasks-config.ts +27 -0
- package/3p/pi-tasks/src/types.ts +40 -0
- package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
- package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
- package/AGENTS.md +28 -0
- package/LICENSE +201 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
- package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
- package/extensions/orchestrator/agents/explore.ts +33 -0
- package/extensions/orchestrator/agents/librarian.ts +43 -0
- package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
- package/extensions/orchestrator/agents/planner.ts +61 -0
- package/extensions/orchestrator/agents/registry.ts +156 -0
- package/extensions/orchestrator/agents/task.ts +50 -0
- package/extensions/orchestrator/agents/tool-routing.ts +84 -0
- package/extensions/orchestrator/ast-search.ts +85 -0
- package/extensions/orchestrator/cbm.ts +330 -0
- package/extensions/orchestrator/command-handlers.test.ts +163 -0
- package/extensions/orchestrator/command-handlers.ts +116 -0
- package/extensions/orchestrator/commands.test.ts +81 -0
- package/extensions/orchestrator/commands.ts +75 -0
- package/extensions/orchestrator/config.test.ts +221 -0
- package/extensions/orchestrator/config.ts +230 -0
- package/extensions/orchestrator/context.test.ts +293 -0
- package/extensions/orchestrator/context.ts +206 -0
- package/extensions/orchestrator/event-handlers.test.ts +190 -0
- package/extensions/orchestrator/event-handlers.ts +1416 -0
- package/extensions/orchestrator/exa.ts +104 -0
- package/extensions/orchestrator/flant-infra.ts +486 -0
- package/extensions/orchestrator/index.ts +80 -0
- package/extensions/orchestrator/integration.test.ts +1214 -0
- package/extensions/orchestrator/orchestrator.test.ts +252 -0
- package/extensions/orchestrator/orchestrator.ts +538 -0
- package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
- package/extensions/orchestrator/phases/brainstorm.ts +273 -0
- package/extensions/orchestrator/phases/implementation.ts +40 -0
- package/extensions/orchestrator/phases/machine.test.ts +293 -0
- package/extensions/orchestrator/phases/machine.ts +209 -0
- package/extensions/orchestrator/phases/planning.ts +255 -0
- package/extensions/orchestrator/phases/review.ts +193 -0
- package/extensions/orchestrator/plannotator.ts +56 -0
- package/extensions/orchestrator/pp-menu.ts +866 -0
- package/extensions/orchestrator/state.test.ts +343 -0
- package/extensions/orchestrator/state.ts +237 -0
- package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
- package/extensions/orchestrator/validate-artifacts.ts +272 -0
- package/extensions/orchestrator/vendor.d.ts +26 -0
- package/package.json +73 -0
- package/scripts/postinstall.sh +18 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search-based code navigation — shared types and pure logic.
|
|
3
|
+
*
|
|
4
|
+
* Runtime-agnostic: both Bun and Node servers provide their own
|
|
5
|
+
* CodeNavRuntime implementation to run subprocess commands.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function validateFilePath(filePath: string): void {
|
|
9
|
+
if (filePath.includes("..") || filePath.startsWith("/")) {
|
|
10
|
+
throw new Error("Invalid file path");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Types
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
export interface CodeNavRequest {
|
|
19
|
+
symbol: string;
|
|
20
|
+
filePath: string;
|
|
21
|
+
line: number;
|
|
22
|
+
charStart: number;
|
|
23
|
+
side: "old" | "new";
|
|
24
|
+
language?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CodeNavLocation {
|
|
28
|
+
kind: "definition" | "reference";
|
|
29
|
+
confidence: "likely" | "possible";
|
|
30
|
+
filePath: string;
|
|
31
|
+
line: number;
|
|
32
|
+
column: number;
|
|
33
|
+
snippet: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CodeNavResponse {
|
|
37
|
+
backend: "search" | "unavailable";
|
|
38
|
+
complete: boolean;
|
|
39
|
+
definitions: CodeNavLocation[];
|
|
40
|
+
references: CodeNavLocation[];
|
|
41
|
+
stats: { elapsedMs: number; capped: boolean };
|
|
42
|
+
searchScope: "head";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface CodeNavRuntime {
|
|
46
|
+
runCommand: (
|
|
47
|
+
command: string,
|
|
48
|
+
args: string[],
|
|
49
|
+
options?: { cwd?: string; timeoutMs?: number },
|
|
50
|
+
) => Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Constants
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
const CODE_NAV_IGNORED_GLOBS = [
|
|
58
|
+
"node_modules",
|
|
59
|
+
".git",
|
|
60
|
+
"dist",
|
|
61
|
+
"build",
|
|
62
|
+
".next",
|
|
63
|
+
"__pycache__",
|
|
64
|
+
".turbo",
|
|
65
|
+
".cache",
|
|
66
|
+
"target",
|
|
67
|
+
"vendor",
|
|
68
|
+
"coverage",
|
|
69
|
+
".venv",
|
|
70
|
+
".pytest_cache",
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const RG_TYPE_MAP: Record<string, string> = {
|
|
74
|
+
typescript: "ts",
|
|
75
|
+
javascript: "js",
|
|
76
|
+
python: "py",
|
|
77
|
+
go: "go",
|
|
78
|
+
rust: "rust",
|
|
79
|
+
java: "java",
|
|
80
|
+
ruby: "ruby",
|
|
81
|
+
cpp: "cpp",
|
|
82
|
+
c: "c",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Definition patterns
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
interface DefinitionPatternSet {
|
|
90
|
+
languages: string[];
|
|
91
|
+
patterns: string[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const DEFINITION_PATTERNS: DefinitionPatternSet[] = [
|
|
95
|
+
{
|
|
96
|
+
languages: ["typescript", "javascript"],
|
|
97
|
+
patterns: [
|
|
98
|
+
String.raw`(?:export\s+)?(?:async\s+)?function\s+SYMBOL\b`,
|
|
99
|
+
String.raw`(?:export\s+)?(?:const|let|var)\s+SYMBOL\s*[=:]`,
|
|
100
|
+
String.raw`(?:export\s+)?class\s+SYMBOL\b`,
|
|
101
|
+
String.raw`(?:export\s+)?(?:interface|type)\s+SYMBOL\b`,
|
|
102
|
+
String.raw`(?:export\s+)?enum\s+SYMBOL\b`,
|
|
103
|
+
String.raw`^\s+(?:(?:async|static|readonly|get|set|private|protected|public)\s+)+SYMBOL\s*[(<:]`,
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
languages: ["python"],
|
|
108
|
+
patterns: [
|
|
109
|
+
String.raw`(?:^|\s)def\s+SYMBOL\s*\(`,
|
|
110
|
+
String.raw`(?:^|\s)class\s+SYMBOL\b`,
|
|
111
|
+
String.raw`^SYMBOL\s*=`,
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
languages: ["go"],
|
|
116
|
+
patterns: [
|
|
117
|
+
String.raw`func\s+(?:\([^)]+\)\s+)?SYMBOL\s*\(`,
|
|
118
|
+
String.raw`type\s+SYMBOL\s`,
|
|
119
|
+
String.raw`var\s+SYMBOL\s`,
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
languages: ["rust"],
|
|
124
|
+
patterns: [
|
|
125
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?fn\s+SYMBOL\b`,
|
|
126
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?struct\s+SYMBOL\b`,
|
|
127
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?enum\s+SYMBOL\b`,
|
|
128
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?trait\s+SYMBOL\b`,
|
|
129
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?type\s+SYMBOL\b`,
|
|
130
|
+
String.raw`(?:pub(?:\([^)]*\))?\s+)?mod\s+SYMBOL\b`,
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
const GENERIC_DEFINITION_PATTERNS: string[] = [
|
|
136
|
+
String.raw`(?:function|def|func|fn|class|struct|enum|trait|interface|type)\s+SYMBOL\b`,
|
|
137
|
+
String.raw`(?:const|let|var|val)\s+SYMBOL\s*[=:]`,
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// Helpers
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
function escapeRegex(str: string): string {
|
|
145
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function sameDirectory(a: string, b: string): boolean {
|
|
149
|
+
const dirA = a.lastIndexOf("/");
|
|
150
|
+
const dirB = b.lastIndexOf("/");
|
|
151
|
+
if (dirA === -1 && dirB === -1) return true;
|
|
152
|
+
return a.slice(0, dirA) === b.slice(0, dirB);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isTestFile(filePath: string): boolean {
|
|
156
|
+
return /(?:test|spec|__tests__|_test\.|\.test\.|\.spec\.)/i.test(filePath);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// rg argument construction
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
export function buildRgArgs(symbol: string, language?: string): string[] {
|
|
164
|
+
const args: string[] = [
|
|
165
|
+
"--json",
|
|
166
|
+
"--line-number",
|
|
167
|
+
"--column",
|
|
168
|
+
"--max-count",
|
|
169
|
+
"50",
|
|
170
|
+
"--max-filesize",
|
|
171
|
+
"1M",
|
|
172
|
+
"--no-messages",
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
for (const dir of CODE_NAV_IGNORED_GLOBS) {
|
|
176
|
+
args.push("--glob", `!${dir}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (language) {
|
|
180
|
+
const rgType = RG_TYPE_MAP[language];
|
|
181
|
+
if (rgType) args.push("--type", rgType);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
args.push("--word-regexp", "--", escapeRegex(symbol), ".");
|
|
185
|
+
|
|
186
|
+
return args;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// rg JSON output parsing
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
|
|
193
|
+
interface RgMatchData {
|
|
194
|
+
path: { text: string };
|
|
195
|
+
lines: { text: string };
|
|
196
|
+
line_number: number;
|
|
197
|
+
submatches: Array<{ start: number; end: number }>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const PARSE_CAP = 500;
|
|
201
|
+
|
|
202
|
+
export function parseRgJsonOutput(
|
|
203
|
+
stdout: string,
|
|
204
|
+
symbol: string,
|
|
205
|
+
language?: string,
|
|
206
|
+
): CodeNavLocation[] {
|
|
207
|
+
const locations: CodeNavLocation[] = [];
|
|
208
|
+
const lines = stdout.split("\n");
|
|
209
|
+
|
|
210
|
+
for (const line of lines) {
|
|
211
|
+
if (locations.length >= PARSE_CAP) break;
|
|
212
|
+
if (!line.trim()) continue;
|
|
213
|
+
|
|
214
|
+
let parsed: { type: string; data: RgMatchData };
|
|
215
|
+
try {
|
|
216
|
+
parsed = JSON.parse(line);
|
|
217
|
+
} catch {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (parsed.type !== "match") continue;
|
|
222
|
+
|
|
223
|
+
const d = parsed.data;
|
|
224
|
+
const snippet = d.lines.text.trimEnd();
|
|
225
|
+
const column = d.submatches?.[0]?.start ?? 0;
|
|
226
|
+
const kind = classifyMatch(snippet, symbol, language);
|
|
227
|
+
const filePath = d.path.text.startsWith("./")
|
|
228
|
+
? d.path.text.slice(2)
|
|
229
|
+
: d.path.text;
|
|
230
|
+
|
|
231
|
+
locations.push({
|
|
232
|
+
kind,
|
|
233
|
+
confidence: kind === "definition" ? "likely" : "possible",
|
|
234
|
+
filePath,
|
|
235
|
+
line: d.line_number,
|
|
236
|
+
column,
|
|
237
|
+
snippet: snippet.length > 200 ? snippet.slice(0, 200) + "…" : snippet,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return locations;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
// Match classification
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
|
|
248
|
+
export function classifyMatch(
|
|
249
|
+
snippet: string,
|
|
250
|
+
symbol: string,
|
|
251
|
+
language?: string,
|
|
252
|
+
): "definition" | "reference" {
|
|
253
|
+
const escaped = escapeRegex(symbol);
|
|
254
|
+
|
|
255
|
+
if (language) {
|
|
256
|
+
const langPatterns = DEFINITION_PATTERNS.find((p) =>
|
|
257
|
+
p.languages.includes(language),
|
|
258
|
+
);
|
|
259
|
+
if (langPatterns) {
|
|
260
|
+
for (const pattern of langPatterns.patterns) {
|
|
261
|
+
const re = new RegExp(pattern.replace("SYMBOL", escaped));
|
|
262
|
+
if (re.test(snippet)) return "definition";
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const pattern of GENERIC_DEFINITION_PATTERNS) {
|
|
268
|
+
const re = new RegExp(pattern.replace("SYMBOL", escaped));
|
|
269
|
+
if (re.test(snippet)) return "definition";
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return "reference";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
276
|
+
// Ranking
|
|
277
|
+
// ---------------------------------------------------------------------------
|
|
278
|
+
|
|
279
|
+
export function rankLocations(
|
|
280
|
+
locations: CodeNavLocation[],
|
|
281
|
+
context: {
|
|
282
|
+
sourceFilePath: string;
|
|
283
|
+
changedFiles: string[];
|
|
284
|
+
isTestFile: boolean;
|
|
285
|
+
},
|
|
286
|
+
cap = 50,
|
|
287
|
+
): { definitions: CodeNavLocation[]; references: CodeNavLocation[]; capped: boolean } {
|
|
288
|
+
const capped = locations.length > cap;
|
|
289
|
+
const changedSet = new Set(context.changedFiles);
|
|
290
|
+
|
|
291
|
+
function score(loc: CodeNavLocation): number {
|
|
292
|
+
let s = 0;
|
|
293
|
+
|
|
294
|
+
if (loc.filePath === context.sourceFilePath) s += 1000;
|
|
295
|
+
else if (changedSet.has(loc.filePath)) s += 500;
|
|
296
|
+
else if (sameDirectory(loc.filePath, context.sourceFilePath)) s += 200;
|
|
297
|
+
|
|
298
|
+
if (isTestFile(loc.filePath) && !context.isTestFile) s -= 300;
|
|
299
|
+
|
|
300
|
+
if (loc.kind === "definition") s += 100;
|
|
301
|
+
if (loc.confidence === "likely") s += 50;
|
|
302
|
+
|
|
303
|
+
return s;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const sorted = [...locations].sort((a, b) => score(b) - score(a));
|
|
307
|
+
const truncated = sorted.slice(0, cap);
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
definitions: truncated.filter((l) => l.kind === "definition"),
|
|
311
|
+
references: truncated.filter((l) => l.kind === "reference"),
|
|
312
|
+
capped,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
// Changed files extraction from unified diff patch
|
|
318
|
+
// ---------------------------------------------------------------------------
|
|
319
|
+
|
|
320
|
+
export function extractChangedFiles(patch: string | null): string[] {
|
|
321
|
+
if (!patch) return [];
|
|
322
|
+
const set = new Set<string>();
|
|
323
|
+
const re = /^diff --git a\/(.+?) b\/(.+)$/gm;
|
|
324
|
+
let m: RegExpExecArray | null;
|
|
325
|
+
while ((m = re.exec(patch)) !== null) {
|
|
326
|
+
set.add(m[1]);
|
|
327
|
+
set.add(m[2]);
|
|
328
|
+
}
|
|
329
|
+
return [...set];
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ---------------------------------------------------------------------------
|
|
333
|
+
// Validation
|
|
334
|
+
// ---------------------------------------------------------------------------
|
|
335
|
+
|
|
336
|
+
export function validateCodeNavRequest(
|
|
337
|
+
body: unknown,
|
|
338
|
+
): string | null {
|
|
339
|
+
if (!body || typeof body !== "object") return "Invalid request body";
|
|
340
|
+
const b = body as Record<string, unknown>;
|
|
341
|
+
|
|
342
|
+
if (typeof b.symbol !== "string" || !b.symbol.trim()) {
|
|
343
|
+
return "Missing or empty symbol";
|
|
344
|
+
}
|
|
345
|
+
if (typeof b.filePath !== "string" || !b.filePath.trim()) {
|
|
346
|
+
return "Missing filePath";
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
validateFilePath(b.filePath as string);
|
|
350
|
+
} catch {
|
|
351
|
+
return "Invalid filePath";
|
|
352
|
+
}
|
|
353
|
+
if (b.side !== "old" && b.side !== "new") {
|
|
354
|
+
return "side must be 'old' or 'new'";
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
// Main entry point
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
|
|
364
|
+
let rgAvailable: boolean | null = null;
|
|
365
|
+
|
|
366
|
+
export async function resolveCodeNav(
|
|
367
|
+
runtime: CodeNavRuntime,
|
|
368
|
+
request: CodeNavRequest,
|
|
369
|
+
cwd: string,
|
|
370
|
+
changedFiles: string[],
|
|
371
|
+
): Promise<CodeNavResponse> {
|
|
372
|
+
const start = Date.now();
|
|
373
|
+
|
|
374
|
+
if (rgAvailable === null) {
|
|
375
|
+
const check = await runtime.runCommand("rg", ["--version"], {
|
|
376
|
+
cwd,
|
|
377
|
+
timeoutMs: 2000,
|
|
378
|
+
});
|
|
379
|
+
rgAvailable = check.exitCode === 0;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (!rgAvailable) {
|
|
383
|
+
return {
|
|
384
|
+
backend: "unavailable",
|
|
385
|
+
complete: true,
|
|
386
|
+
definitions: [],
|
|
387
|
+
references: [],
|
|
388
|
+
searchScope: "head",
|
|
389
|
+
stats: { elapsedMs: Date.now() - start, capped: false },
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const args = buildRgArgs(request.symbol, request.language);
|
|
394
|
+
|
|
395
|
+
const result = await runtime.runCommand("rg", args, {
|
|
396
|
+
cwd,
|
|
397
|
+
timeoutMs: 5000,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// Exit code 1 = no matches (normal), exit code 2 = error
|
|
401
|
+
if (result.exitCode === 2) {
|
|
402
|
+
return {
|
|
403
|
+
backend: "search",
|
|
404
|
+
complete: true,
|
|
405
|
+
definitions: [],
|
|
406
|
+
references: [],
|
|
407
|
+
searchScope: "head",
|
|
408
|
+
stats: { elapsedMs: Date.now() - start, capped: false },
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const locations = parseRgJsonOutput(
|
|
413
|
+
result.stdout,
|
|
414
|
+
request.symbol,
|
|
415
|
+
request.language,
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
const ranked = rankLocations(locations, {
|
|
419
|
+
sourceFilePath: request.filePath,
|
|
420
|
+
changedFiles,
|
|
421
|
+
isTestFile: isTestFile(request.filePath),
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
backend: "search",
|
|
426
|
+
complete: true,
|
|
427
|
+
definitions: ranked.definitions,
|
|
428
|
+
references: ranked.references,
|
|
429
|
+
searchScope: "head",
|
|
430
|
+
stats: { elapsedMs: Date.now() - start, capped: ranked.capped },
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function resetRgCache(): void {
|
|
435
|
+
rgAvailable = null;
|
|
436
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable deflate-raw + base64url compression.
|
|
3
|
+
*
|
|
4
|
+
* Uses only Web APIs (CompressionStream, TextEncoder, btoa) so it works
|
|
5
|
+
* in browsers, Bun, and edge runtimes. Both @plannotator/server and
|
|
6
|
+
* @plannotator/ui import from here — single source of truth.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export async function compress(data: unknown): Promise<string> {
|
|
10
|
+
const json = JSON.stringify(data);
|
|
11
|
+
const byteArray = new TextEncoder().encode(json);
|
|
12
|
+
|
|
13
|
+
const stream = new CompressionStream('deflate-raw');
|
|
14
|
+
const writer = stream.writable.getWriter();
|
|
15
|
+
writer.write(byteArray);
|
|
16
|
+
writer.close();
|
|
17
|
+
|
|
18
|
+
const buffer = await new Response(stream.readable).arrayBuffer();
|
|
19
|
+
const compressed = new Uint8Array(buffer);
|
|
20
|
+
|
|
21
|
+
// Loop instead of spread to avoid RangeError on large payloads
|
|
22
|
+
// (String.fromCharCode(...arr) has a ~65K argument limit)
|
|
23
|
+
let binary = '';
|
|
24
|
+
for (let i = 0; i < compressed.length; i++) {
|
|
25
|
+
binary += String.fromCharCode(compressed[i]);
|
|
26
|
+
}
|
|
27
|
+
const base64 = btoa(binary);
|
|
28
|
+
return base64
|
|
29
|
+
.replace(/\+/g, '-')
|
|
30
|
+
.replace(/\//g, '_')
|
|
31
|
+
.replace(/=/g, '');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function decompress(b64: string): Promise<unknown> {
|
|
35
|
+
const base64 = b64
|
|
36
|
+
.replace(/-/g, '+')
|
|
37
|
+
.replace(/_/g, '/');
|
|
38
|
+
|
|
39
|
+
const binary = atob(base64);
|
|
40
|
+
const byteArray = Uint8Array.from(binary, c => c.charCodeAt(0));
|
|
41
|
+
|
|
42
|
+
const stream = new DecompressionStream('deflate-raw');
|
|
43
|
+
const writer = stream.writable.getWriter();
|
|
44
|
+
writer.write(byteArray);
|
|
45
|
+
writer.close();
|
|
46
|
+
|
|
47
|
+
const buffer = await new Response(stream.readable).arrayBuffer();
|
|
48
|
+
const json = new TextDecoder().decode(buffer);
|
|
49
|
+
|
|
50
|
+
return JSON.parse(json);
|
|
51
|
+
}
|