@evandu/super-pi-server 0.0.0-stage → 0.1.259
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/README.md +248 -3
- package/agents/code-auditor.md +64 -0
- package/agents/code-designer.md +64 -0
- package/agents/coder.md +24 -0
- package/agents/critic.md +24 -0
- package/agents/document-organizer.md +48 -0
- package/agents/patcher.md +27 -0
- package/agents/planner.md +30 -0
- package/agents/project-leader.md +28 -0
- package/agents/reviewer.md +27 -0
- package/agents/scout.md +27 -0
- package/agents/solution-designer.md +62 -0
- package/agents/super-pi-documents/index.ts +92 -0
- package/agents/super-pi-feishu/index.ts +88 -0
- package/agents/super-pi-knowledge/index.ts +70 -0
- package/agents/super-pi-managed-model/index.ts +9 -0
- package/agents/super-pi-memory/index.ts +75 -0
- package/agents/super-pi-native-tools/index.ts +1 -0
- package/agents/super-pi-task/core.ts +2262 -0
- package/agents/super-pi-task/index.ts +814 -0
- package/agents/super-pi-task/workflow-schema.ts +34 -0
- package/agents/super-pi-web/index.ts +32 -0
- package/agents/verifier.md +25 -0
- package/assets/fonts/LICENSE +92 -0
- package/assets/fonts/NotoSansSC-Bold.otf +0 -0
- package/assets/fonts/NotoSansSC-Regular.otf +0 -0
- package/assets/knowledge-model/README.md +37 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
- package/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +349 -0
- package/dist/client/.super-pi-client-sources.json +82 -0
- package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
- package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
- package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
- package/dist/client/assets/diff-ChtP43wD.js +1 -0
- package/dist/client/assets/dist-AW5lyI3I.js +1 -0
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/dist-BRVQKlcp.js +1 -0
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-BXAOrsjq.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/dist-Cus6_oaF.js +2 -0
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-D978o95T.js +5 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/dist-QzbOCAU6.js +1 -0
- package/dist/client/assets/dist-moiMRpw_.js +1 -0
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
- package/dist/client/assets/index-Cn7hdrDw.js +350 -0
- package/dist/client/assets/index-UfzqdECL.css +1 -0
- package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
- package/dist/client/assets/properties-C357ku5U.js +1 -0
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
- package/dist/client/assets/shell-DwuoZtxw.js +1 -0
- package/dist/client/assets/swift-DKB6_1j6.js +1 -0
- package/dist/client/assets/toml-BPTmHmyx.js +1 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +10 -0
- package/dist/client/index.html +18 -0
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +126 -0
- package/dist/server/active-memory.d.ts +247 -0
- package/dist/server/active-memory.js +669 -0
- package/dist/server/agents.d.ts +245 -0
- package/dist/server/agents.js +701 -0
- package/dist/server/application/catalog-service.d.ts +98 -0
- package/dist/server/application/catalog-service.js +245 -0
- package/dist/server/application/conversation-service.d.ts +245 -0
- package/dist/server/application/conversation-service.js +654 -0
- package/dist/server/application/document-service.d.ts +68 -0
- package/dist/server/application/document-service.js +120 -0
- package/dist/server/application/extension-ui-service.d.ts +44 -0
- package/dist/server/application/extension-ui-service.js +135 -0
- package/dist/server/application/feishu-service.d.ts +179 -0
- package/dist/server/application/feishu-service.js +358 -0
- package/dist/server/application/group-chat-service.d.ts +75 -0
- package/dist/server/application/group-chat-service.js +953 -0
- package/dist/server/application/group-execution.d.ts +15 -0
- package/dist/server/application/group-execution.js +77 -0
- package/dist/server/application/project-service.d.ts +464 -0
- package/dist/server/application/project-service.js +2523 -0
- package/dist/server/application/provider-service.d.ts +174 -0
- package/dist/server/application/provider-service.js +510 -0
- package/dist/server/application/run-service.d.ts +547 -0
- package/dist/server/application/run-service.js +2683 -0
- package/dist/server/application/scheduled-task-service.d.ts +184 -0
- package/dist/server/application/scheduled-task-service.js +391 -0
- package/dist/server/application/session-orchestrator-service.d.ts +388 -0
- package/dist/server/application/session-orchestrator-service.js +1146 -0
- package/dist/server/application/session-reminder-service.d.ts +59 -0
- package/dist/server/application/session-reminder-service.js +141 -0
- package/dist/server/application/session-watchdog.d.ts +171 -0
- package/dist/server/application/session-watchdog.js +284 -0
- package/dist/server/application/workspace-service.d.ts +52 -0
- package/dist/server/application/workspace-service.js +186 -0
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/browser-access.d.ts +34 -0
- package/dist/server/browser-access.js +89 -0
- package/dist/server/capability.d.ts +105 -0
- package/dist/server/capability.js +170 -0
- package/dist/server/command-handler.d.ts +93 -0
- package/dist/server/command-handler.js +540 -0
- package/dist/server/content-search.d.ts +16 -0
- package/dist/server/content-search.js +235 -0
- package/dist/server/conversation-usage.d.ts +22 -0
- package/dist/server/conversation-usage.js +43 -0
- package/dist/server/documents.d.ts +152 -0
- package/dist/server/documents.js +998 -0
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/exec-service.d.ts +45 -0
- package/dist/server/exec-service.js +167 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/failure-text.d.ts +18 -0
- package/dist/server/failure-text.js +44 -0
- package/dist/server/feishu-cli.d.ts +223 -0
- package/dist/server/feishu-cli.js +464 -0
- package/dist/server/file-changes.d.ts +119 -0
- package/dist/server/file-changes.js +280 -0
- package/dist/server/file-diff.d.ts +41 -0
- package/dist/server/file-diff.js +97 -0
- package/dist/server/file-index.d.ts +100 -0
- package/dist/server/file-index.js +296 -0
- package/dist/server/file-name-index.d.ts +160 -0
- package/dist/server/file-name-index.js +411 -0
- package/dist/server/files.d.ts +269 -0
- package/dist/server/files.js +748 -0
- package/dist/server/git.d.ts +245 -0
- package/dist/server/git.js +903 -0
- package/dist/server/http-server.d.ts +45 -0
- package/dist/server/http-server.js +3830 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +485 -0
- package/dist/server/inline-thinking.d.ts +90 -0
- package/dist/server/inline-thinking.js +181 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/knowledge-embedding-worker.d.ts +1 -0
- package/dist/server/knowledge-embedding-worker.js +27 -0
- package/dist/server/knowledge-vectors.d.ts +150 -0
- package/dist/server/knowledge-vectors.js +385 -0
- package/dist/server/knowledge.d.ts +273 -0
- package/dist/server/knowledge.js +848 -0
- package/dist/server/length-continuation.d.ts +83 -0
- package/dist/server/length-continuation.js +118 -0
- package/dist/server/logging.d.ts +32 -0
- package/dist/server/logging.js +185 -0
- package/dist/server/managed-http-tunnel.d.ts +6 -0
- package/dist/server/managed-http-tunnel.js +85 -0
- package/dist/server/managed-http.d.ts +4 -0
- package/dist/server/managed-http.js +85 -0
- package/dist/server/managed-model-adapter.d.ts +17 -0
- package/dist/server/managed-model-adapter.js +75 -0
- package/dist/server/managed-model-gateway.d.ts +49 -0
- package/dist/server/managed-model-gateway.js +73 -0
- package/dist/server/managed-servers.d.ts +55 -0
- package/dist/server/managed-servers.js +392 -0
- package/dist/server/managed-ssh.d.ts +26 -0
- package/dist/server/managed-ssh.js +73 -0
- package/dist/server/manager-vault.d.ts +11 -0
- package/dist/server/manager-vault.js +67 -0
- package/dist/server/memory-recall.d.ts +25 -0
- package/dist/server/memory-recall.js +45 -0
- package/dist/server/memory.d.ts +67 -0
- package/dist/server/memory.js +216 -0
- package/dist/server/message-media.d.ts +7 -0
- package/dist/server/message-media.js +54 -0
- package/dist/server/model-context-window.d.ts +186 -0
- package/dist/server/model-context-window.js +444 -0
- package/dist/server/model-filter.d.ts +23 -0
- package/dist/server/model-filter.js +48 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/native-tool-settings.d.ts +25 -0
- package/dist/server/native-tool-settings.js +41 -0
- package/dist/server/native-tools-extension.d.ts +2 -0
- package/dist/server/native-tools-extension.js +39 -0
- package/dist/server/native-tools-service.d.ts +39 -0
- package/dist/server/native-tools-service.js +240 -0
- package/dist/server/persistence/app-state-repository.d.ts +65 -0
- package/dist/server/persistence/app-state-repository.js +1 -0
- package/dist/server/persistence/json-state-repository.d.ts +14 -0
- package/dist/server/persistence/json-state-repository.js +43 -0
- package/dist/server/persistence/open-state-store.d.ts +3 -0
- package/dist/server/persistence/open-state-store.js +35 -0
- package/dist/server/persistence/rename.d.ts +22 -0
- package/dist/server/persistence/rename.js +44 -0
- package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
- package/dist/server/persistence/sqlite-state-repository.js +264 -0
- package/dist/server/pi-command.d.ts +94 -0
- package/dist/server/pi-command.js +265 -0
- package/dist/server/pi-native.d.ts +12 -0
- package/dist/server/pi-native.js +16 -0
- package/dist/server/pi-session-events.d.ts +158 -0
- package/dist/server/pi-session-events.js +373 -0
- package/dist/server/pi-session-pool.d.ts +233 -0
- package/dist/server/pi-session-pool.js +382 -0
- package/dist/server/pi-session.d.ts +642 -0
- package/dist/server/pi-session.js +655 -0
- package/dist/server/presentations/schema.d.ts +120 -0
- package/dist/server/presentations/schema.js +128 -0
- package/dist/server/provider-network.d.ts +16 -0
- package/dist/server/provider-network.js +106 -0
- package/dist/server/provider-proxy.d.ts +18 -0
- package/dist/server/provider-proxy.js +200 -0
- package/dist/server/providers.d.ts +333 -0
- package/dist/server/providers.js +989 -0
- package/dist/server/remote-bootstrap.d.ts +17 -0
- package/dist/server/remote-bootstrap.js +119 -0
- package/dist/server/rpc-channel.d.ts +131 -0
- package/dist/server/rpc-channel.js +135 -0
- package/dist/server/runtime.d.ts +1393 -0
- package/dist/server/runtime.js +3286 -0
- package/dist/server/scheduled-tasks.d.ts +101 -0
- package/dist/server/scheduled-tasks.js +138 -0
- package/dist/server/server-context.d.ts +119 -0
- package/dist/server/server-context.js +1 -0
- package/dist/server/session-cwd.d.ts +19 -0
- package/dist/server/session-cwd.js +58 -0
- package/dist/server/session-ledger.d.ts +67 -0
- package/dist/server/session-ledger.js +76 -0
- package/dist/server/session-memory-scope.d.ts +4 -0
- package/dist/server/session-memory-scope.js +30 -0
- package/dist/server/session-repository.d.ts +100 -0
- package/dist/server/session-repository.js +246 -0
- package/dist/server/session-tree-scope.d.ts +125 -0
- package/dist/server/session-tree-scope.js +337 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +190 -0
- package/dist/server/store.d.ts +1062 -0
- package/dist/server/store.js +3305 -0
- package/dist/server/subagent-runs.d.ts +185 -0
- package/dist/server/subagent-runs.js +383 -0
- package/dist/server/subagents.d.ts +200 -0
- package/dist/server/subagents.js +619 -0
- package/dist/server/task-tool.d.ts +282 -0
- package/dist/server/task-tool.js +507 -0
- package/dist/server/tavily.d.ts +32 -0
- package/dist/server/tavily.js +136 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +180 -0
- package/dist/server/terminal.d.ts +163 -0
- package/dist/server/terminal.js +557 -0
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +183 -0
- package/dist/server/time-zone.d.ts +20 -0
- package/dist/server/time-zone.js +32 -0
- package/dist/server/tool-calls.d.ts +130 -0
- package/dist/server/tool-calls.js +341 -0
- package/dist/server/tool-llm.d.ts +72 -0
- package/dist/server/tool-llm.js +146 -0
- package/dist/server/tool-registry.d.ts +129 -0
- package/dist/server/tool-registry.js +249 -0
- package/dist/server/tool-runner.d.ts +112 -0
- package/dist/server/tool-runner.js +306 -0
- package/dist/server/turn-failure.d.ts +48 -0
- package/dist/server/turn-failure.js +148 -0
- package/dist/server/types.d.ts +2315 -0
- package/dist/server/types.js +11 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +46 -0
- package/dist/server/update.js +104 -0
- package/dist/server/upload.d.ts +35 -0
- package/dist/server/upload.js +177 -0
- package/dist/server/version.d.ts +33 -0
- package/dist/server/version.js +111 -0
- package/dist/server/web.d.ts +27 -0
- package/dist/server/web.js +183 -0
- package/dist/server/workflow-engine.d.ts +47 -0
- package/dist/server/workflow-engine.js +255 -0
- package/dist/server/workflow.d.ts +329 -0
- package/dist/server/workflow.js +469 -0
- package/dist/server/workspace-file-indexes.d.ts +2 -0
- package/dist/server/workspace-file-indexes.js +61 -0
- package/dist/server/workspace-file-operations.d.ts +36 -0
- package/dist/server/workspace-file-operations.js +281 -0
- package/dist/server/workspace-file-response.d.ts +7 -0
- package/dist/server/workspace-file-response.js +79 -0
- package/dist/server/ws-server.d.ts +149 -0
- package/dist/server/ws-server.js +640 -0
- package/dist/shared/agent-order.d.ts +44 -0
- package/dist/shared/agent-order.js +50 -0
- package/dist/shared/archive-decisions.d.ts +44 -0
- package/dist/shared/archive-decisions.js +98 -0
- package/dist/shared/background-task.d.ts +25 -0
- package/dist/shared/background-task.js +183 -0
- package/dist/shared/child-session-lock.d.ts +37 -0
- package/dist/shared/child-session-lock.js +59 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/dist/shared/file-mentions.d.ts +17 -0
- package/dist/shared/file-mentions.js +91 -0
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +42 -0
- package/dist/shared/git-graph.js +30 -0
- package/dist/shared/group-chat.d.ts +132 -0
- package/dist/shared/group-chat.js +6 -0
- package/dist/shared/managed-servers.d.ts +36 -0
- package/dist/shared/managed-servers.js +1 -0
- package/dist/shared/message-media.d.ts +12 -0
- package/dist/shared/message-media.js +27 -0
- package/dist/shared/model-window-label.d.ts +39 -0
- package/dist/shared/model-window-label.js +55 -0
- package/dist/shared/native-tools.d.ts +43 -0
- package/dist/shared/native-tools.js +1 -0
- package/dist/shared/pi-cache-warming.d.ts +9 -0
- package/dist/shared/pi-cache-warming.js +4 -0
- package/dist/shared/project-overview.d.ts +107 -0
- package/dist/shared/project-overview.js +92 -0
- package/dist/shared/project-presentation.d.ts +55 -0
- package/dist/shared/project-presentation.js +111 -0
- package/dist/shared/provider-network.d.ts +30 -0
- package/dist/shared/provider-network.js +1 -0
- package/dist/shared/session-reporting.d.ts +40 -0
- package/dist/shared/session-reporting.js +97 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/dist/shared/team-context-view.d.ts +33 -0
- package/dist/shared/team-context-view.js +49 -0
- package/dist/shared/team-context.d.ts +59 -0
- package/dist/shared/team-context.js +3 -0
- package/dist/shared/terminal-protocol.d.ts +71 -0
- package/dist/shared/terminal-protocol.js +1 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/dist/shared/transcript-order.d.ts +7 -0
- package/dist/shared/transcript-order.js +12 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/dist/shared/workspace-file-preview.d.ts +4 -0
- package/dist/shared/workspace-file-preview.js +28 -0
- package/package.json +448 -4
- package/scripts/diagnose.mjs +603 -0
- package/scripts/patch-brace-expansion.mjs +260 -0
- package/scripts/restart-server.mjs +104 -0
- package/skills/presentation/SKILL.md +30 -0
- package/skills/presentation/references/data.md +10 -0
- package/skills/presentation/references/quality.md +12 -0
- package/skills/presentation/references/story.md +12 -0
- package/skills/presentation/references/templates-and-editing.md +11 -0
- package/skills/presentation/references/visual-system.md +10 -0
- package/skills/super-pi-agent-development/SKILL.md +25 -0
- package/skills/super-pi-development/SKILL.md +31 -0
- package/skills/super-pi-tool-development/SKILL.md +39 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE NAME INDEX. Every file in the workspace, indexed once, queried in memory.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS FILE EXISTS AT ALL, because there is already a `file-index.ts` and the obvious move is
|
|
5
|
+
* to extend it. That move is wrong, and the reason is that the two indexes have OPPOSITE scopes:
|
|
6
|
+
*
|
|
7
|
+
* - `FileIndex` (the content-search one) deliberately SKIPS dependency directories. A grep through
|
|
8
|
+
* `node_modules` is slow and returns nothing a person asked for. Measured on this repository:
|
|
9
|
+
* 15388 files of which 13949 are `node_modules`, while the project's own `src/` has 75.
|
|
10
|
+
* - THIS index deliberately SKIPS NOTHING. A person typing `config` into a filename box wants
|
|
11
|
+
* `node_modules/some-pkg/config.js` to be findable, and the old behaviour made it unfindable
|
|
12
|
+
* while announcing the omission in the UI as a dashed "已跳过 N 个目录" note.
|
|
13
|
+
*
|
|
14
|
+
* Those are not two settings of one thing. They are two different questions ("where is this
|
|
15
|
+
* symbol used" vs "what is this file called"), and one index cannot answer both.
|
|
16
|
+
*
|
|
17
|
+
* WHY AN INDEX AND NOT A FRESH WALK PER KEYSTROKE. The old path re-walked the whole tree on every
|
|
18
|
+
* keystroke (`files.ts` `searchByName`), which cost the user a full scan per character typed. The
|
|
19
|
+
* cost of building this index ONCE is 960ms of `readdir` on this repository (measured: 3257
|
|
20
|
+
* directories, 28289 files, no `stat`), and the cost of a query afterwards is a substring filter
|
|
21
|
+
* over an in-memory map - about 3ms for 30000 entries. So the pressure moves from the user's
|
|
22
|
+
* keystrokes to the server's background, which is where it belongs.
|
|
23
|
+
*
|
|
24
|
+
* WHY THE SCAN HAS NO `stat`. The measurements are unambiguous: `readdir` over the whole tree is
|
|
25
|
+
* 960ms and `stat` over every directory is 166ms, but a per-FILE `stat` is what costs seconds
|
|
26
|
+
* (the documented 2-3s figure). This index does not need file sizes or etags - it needs NAMES -
|
|
27
|
+
* so it stats only symbolic links to tell whether their names can open a single file.
|
|
28
|
+
*
|
|
29
|
+
* THE LIMITS ARE HONEST AND LOOSE. 20000 directories and 200000 files are three to four orders of
|
|
30
|
+
* magnitude above a real repository, and hitting one is reported (`complete: false`) rather than
|
|
31
|
+
* silently applied - a search that quietly stopped at a limit is the exact defect this file
|
|
32
|
+
* replaces.
|
|
33
|
+
*/
|
|
34
|
+
import { readdir, stat } from "node:fs/promises";
|
|
35
|
+
import { resolve } from "node:path";
|
|
36
|
+
import Fuse from "fuse.js";
|
|
37
|
+
import { matchPathMentions, rankPathMatches } from "../shared/file-mentions.js";
|
|
38
|
+
import { createRootGuard, toRelative } from "./files.js";
|
|
39
|
+
import { belowPath, blockedBy, inScope, matchesDirectoryReads } from "./file-index.js";
|
|
40
|
+
import { explorerInternalPath } from "./workspace-file-operations.js";
|
|
41
|
+
import { sessionScopeKey } from "./session-cwd.js";
|
|
42
|
+
/**
|
|
43
|
+
* THE INDEX FOR ONE WORKSPACE, created on demand and then kept.
|
|
44
|
+
*
|
|
45
|
+
* Both layers that need it - the HTTP route that answers a search and the run service that records
|
|
46
|
+
* the agent's writes - go through this one function, so there is exactly one index per workspace and
|
|
47
|
+
* the two never drift into answering from different maps.
|
|
48
|
+
*/
|
|
49
|
+
export function ensureNameIndex(indexes, workspaceId, root, cwd = "") {
|
|
50
|
+
const key = sessionScopeKey(workspaceId, cwd);
|
|
51
|
+
let index = indexes.get(key);
|
|
52
|
+
if (!index) {
|
|
53
|
+
index = new FileNameIndex(workspaceId, cwd);
|
|
54
|
+
indexes.set(key, index);
|
|
55
|
+
}
|
|
56
|
+
index.start(root);
|
|
57
|
+
return index;
|
|
58
|
+
}
|
|
59
|
+
/** Keeps every root/subdirectory index for a workspace in step with one observed write. */
|
|
60
|
+
export function recordWorkspacePath(indexes, workspaceId, workspaceRoot, path) {
|
|
61
|
+
if (explorerInternalPath(path))
|
|
62
|
+
return;
|
|
63
|
+
for (const index of indexes.values()) {
|
|
64
|
+
if (index.workspaceId !== workspaceId)
|
|
65
|
+
continue;
|
|
66
|
+
const scoped = inScope(workspaceRoot, index.cwd, path);
|
|
67
|
+
if (scoped)
|
|
68
|
+
index.upsert(scoped);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export const QUICK_OPEN_PAGE_SIZE = 60;
|
|
72
|
+
const MAX_DIRECTORIES = 20000;
|
|
73
|
+
const MAX_ENTRIES = 200000;
|
|
74
|
+
const DIRECTORY_BATCH = 12;
|
|
75
|
+
/**
|
|
76
|
+
* The result ordering, and why it is not the path dictionary order.
|
|
77
|
+
*
|
|
78
|
+
* A dictionary order puts `zzz-notes.md` before `notes.md`, because "zzz" sorts after "notes" as
|
|
79
|
+
* a whole string. In a list of two hundred that is actively hostile: the file whose name STARTS
|
|
80
|
+
* with what you typed is the one you meant, and it is somewhere in the middle. So the order is:
|
|
81
|
+
*
|
|
82
|
+
* 1. exact filenames;
|
|
83
|
+
* 2. the hit position inside the file name, so prefixes rank ahead of other substrings;
|
|
84
|
+
* 3. shallower directories first;
|
|
85
|
+
* 4. path order as the final tie-break.
|
|
86
|
+
*/
|
|
87
|
+
export function compareNameHits(a, b, needle) {
|
|
88
|
+
const exact = Number(b.name.toLowerCase() === needle) - Number(a.name.toLowerCase() === needle);
|
|
89
|
+
if (exact !== 0)
|
|
90
|
+
return exact;
|
|
91
|
+
const position = hitPosition(a, needle) - hitPosition(b, needle);
|
|
92
|
+
if (position !== 0)
|
|
93
|
+
return position;
|
|
94
|
+
const depth = a.directory.split("/").filter(Boolean).length - b.directory.split("/").filter(Boolean).length;
|
|
95
|
+
if (depth !== 0)
|
|
96
|
+
return depth;
|
|
97
|
+
return a.path.localeCompare(b.path, undefined, { numeric: true, sensitivity: "base" });
|
|
98
|
+
}
|
|
99
|
+
/** Where in the NAME the needle first appears. A name that does not contain it at all sorts last. */
|
|
100
|
+
function hitPosition(entry, needle) {
|
|
101
|
+
const at = entry.name.toLowerCase().indexOf(needle);
|
|
102
|
+
return at < 0 ? Number.MAX_SAFE_INTEGER : at;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A per-workspace index of every path in the tree, built in the background.
|
|
106
|
+
*
|
|
107
|
+
* THE LIFECYCLE. `start()` kicks off one background scan and returns immediately - the first
|
|
108
|
+
* screen must never wait for an index. `search()` works at any point in that scan and answers with
|
|
109
|
+
* what is known so far, together with `indexed: false` so the caller can say "正在建立索引"
|
|
110
|
+
* rather than pretending the answer is complete.
|
|
111
|
+
*
|
|
112
|
+
* THE INCREMENTAL PATH. `upsert()` and `remove()` are how the index stays true once it exists.
|
|
113
|
+
* The agent writes files through the run service and the user saves through the files API, and
|
|
114
|
+
* BOTH of those places already know the path - so keeping the index true costs no extra I/O at
|
|
115
|
+
* all, it is one map write.
|
|
116
|
+
*/
|
|
117
|
+
export class FileNameIndex {
|
|
118
|
+
workspaceId;
|
|
119
|
+
cwd;
|
|
120
|
+
entries = new Map();
|
|
121
|
+
root = "";
|
|
122
|
+
building = false;
|
|
123
|
+
started = false;
|
|
124
|
+
scanned = 0;
|
|
125
|
+
stopped = false;
|
|
126
|
+
incomplete = false;
|
|
127
|
+
needsScan = false;
|
|
128
|
+
generation = 0;
|
|
129
|
+
unread = new Set();
|
|
130
|
+
hasScanned = false;
|
|
131
|
+
removedDuringScan = new Set();
|
|
132
|
+
directoriesReadDuringScan = new Map();
|
|
133
|
+
constructor(workspaceId, cwd = "") {
|
|
134
|
+
this.workspaceId = workspaceId;
|
|
135
|
+
this.cwd = cwd;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether the first pass has FINISHED.
|
|
139
|
+
*
|
|
140
|
+
* "Finished" is not "found something": an EMPTY directory finishes the scan with zero entries, and
|
|
141
|
+
* that directory is exactly the case where the answer "no matches" is TRUE rather than premature.
|
|
142
|
+
* A readiness test that asked "are there any entries yet" would leave an empty workspace stuck on
|
|
143
|
+
* "building" forever.
|
|
144
|
+
*
|
|
145
|
+
* A scan that FAILED has not finished either - it never will be, and `failure` says why.
|
|
146
|
+
*/
|
|
147
|
+
get indexed() {
|
|
148
|
+
return !this.building && this.failure === undefined;
|
|
149
|
+
}
|
|
150
|
+
get hasSnapshot() { return this.hasScanned; }
|
|
151
|
+
get progress() {
|
|
152
|
+
// The percentage is deliberately not a promise about the whole tree: the total is unknown
|
|
153
|
+
// until the scan ends, so it is derived from the directory budget instead, and the UI shows
|
|
154
|
+
// the file COUNT next to it rather than a bare percentage that would be a guess.
|
|
155
|
+
const percent = Math.min(99, Math.round((this.scanned / MAX_DIRECTORIES) * 100));
|
|
156
|
+
return { scanned: this.entries.size, percent: this.building ? percent : 100 };
|
|
157
|
+
}
|
|
158
|
+
/** Begin the background scan. Safe to call more than once; the second call is a no-op. */
|
|
159
|
+
start(root) {
|
|
160
|
+
// The guard is "has a scan been started", NOT "are there any entries". An EMPTY workspace
|
|
161
|
+
// finishes its scan with zero entries, and an emptiness test would restart the scan on every
|
|
162
|
+
// request - so the answer to every query would be "still building" forever.
|
|
163
|
+
if (!this.started || this.needsScan)
|
|
164
|
+
this.revalidate(root);
|
|
165
|
+
}
|
|
166
|
+
/** Keep the preceding results usable while checking files written outside Super Pi. */
|
|
167
|
+
revalidate(root) {
|
|
168
|
+
if (this.building)
|
|
169
|
+
return;
|
|
170
|
+
if (this.root && this.root !== root) {
|
|
171
|
+
this.entries.clear();
|
|
172
|
+
this.hasScanned = false;
|
|
173
|
+
}
|
|
174
|
+
this.unread = new Set(this.entries.keys());
|
|
175
|
+
this.removedDuringScan.clear();
|
|
176
|
+
this.directoriesReadDuringScan.clear();
|
|
177
|
+
this.root = root;
|
|
178
|
+
this.needsScan = false;
|
|
179
|
+
this.started = true;
|
|
180
|
+
this.building = true;
|
|
181
|
+
this.failure = undefined;
|
|
182
|
+
this.incomplete = false;
|
|
183
|
+
this.stopped = false;
|
|
184
|
+
this.scanned = 0;
|
|
185
|
+
void this.scan(++this.generation);
|
|
186
|
+
}
|
|
187
|
+
markStale() { if (this.started)
|
|
188
|
+
this.needsScan = true; }
|
|
189
|
+
/**
|
|
190
|
+
* WHY THE SCAN'S FAILURE IS RECORDED RATHER THAN THROWN.
|
|
191
|
+
*
|
|
192
|
+
* The first version rethrew a missing root so the failure could not be swallowed - and that crashed
|
|
193
|
+
* the server, because a background scan has no caller to receive its rejection and Node's default
|
|
194
|
+
* for an unhandled rejection is to terminate the process. The whole test server went down, and the
|
|
195
|
+
* symptom ("fetch failed") pointed at the network rather than at a promise.
|
|
196
|
+
*
|
|
197
|
+
* So the failure is RECORDED (`this.failure`) and the route asks about it (`throwIfBroken`). The
|
|
198
|
+
* answer is still the 404 the route owes, but it is now delivered by the request rather than by an
|
|
199
|
+
* exception nobody is listening for.
|
|
200
|
+
*/
|
|
201
|
+
failure;
|
|
202
|
+
/** The error that stopped the scan, if the root itself could not be read. */
|
|
203
|
+
get broken() {
|
|
204
|
+
return this.failure;
|
|
205
|
+
}
|
|
206
|
+
/** Rethrow the scan's failure, so the route can turn it into the status it deserves. */
|
|
207
|
+
throwIfBroken() {
|
|
208
|
+
if (this.failure === undefined)
|
|
209
|
+
return;
|
|
210
|
+
throw this.failure;
|
|
211
|
+
}
|
|
212
|
+
/** Record a path that appeared or changed. Used for agent writes and user saves. */
|
|
213
|
+
upsert(relativePath, kind = "file", openLink) {
|
|
214
|
+
const path = relativePath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
215
|
+
if (!path)
|
|
216
|
+
return;
|
|
217
|
+
const cut = path.lastIndexOf("/");
|
|
218
|
+
const name = cut < 0 ? path : path.slice(cut + 1);
|
|
219
|
+
const directory = cut < 0 ? "" : path.slice(0, cut);
|
|
220
|
+
this.unread.delete(path);
|
|
221
|
+
this.entries.set(path, { path, name, directory, kind, ...(openLink ? { openLink } : {}) });
|
|
222
|
+
}
|
|
223
|
+
/** Forget a path that is gone. */
|
|
224
|
+
remove(relativePath) {
|
|
225
|
+
const path = relativePath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
226
|
+
this.entries.delete(path);
|
|
227
|
+
// The directories that held it are still there; only the file itself is gone.
|
|
228
|
+
}
|
|
229
|
+
removeTree(path) {
|
|
230
|
+
if (this.building)
|
|
231
|
+
this.removedDuringScan.add(path);
|
|
232
|
+
for (const key of this.entries.keys())
|
|
233
|
+
if (belowPath(key, path))
|
|
234
|
+
this.entries.delete(key);
|
|
235
|
+
}
|
|
236
|
+
reconcileDirectory(directory, entries) {
|
|
237
|
+
const indexed = entries.filter(entry => entry.openLink || !entry.symlink && entry.kind !== "symlink");
|
|
238
|
+
const present = new Map(indexed.map(entry => [entry.path, entry]));
|
|
239
|
+
if (this.building)
|
|
240
|
+
this.directoriesReadDuringScan.set(directory, new Set(present.keys()));
|
|
241
|
+
for (const [path, existing] of this.entries) {
|
|
242
|
+
if (existing.directory !== directory)
|
|
243
|
+
continue;
|
|
244
|
+
const entry = present.get(path);
|
|
245
|
+
if (!entry || (entry.openLink ? "file" : entry.kind) !== existing.kind)
|
|
246
|
+
this.removeTree(path);
|
|
247
|
+
}
|
|
248
|
+
for (const entry of indexed)
|
|
249
|
+
this.upsert(entry.path, entry.kind === "directory" ? "directory" : "file", entry.openLink);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The query. A substring filter over an in-memory map - no filesystem access at all.
|
|
253
|
+
*
|
|
254
|
+
* The needle is matched against the FILE NAME only. Matching the path as well would be a
|
|
255
|
+
* different feature ("find everything under src/server"), and mixing the two makes a search for
|
|
256
|
+
* `app` return every file in `application/` as well - a result set nobody can read.
|
|
257
|
+
*/
|
|
258
|
+
search(needle, linksOnly = false) {
|
|
259
|
+
const normalized = needle.trim().replaceAll("\\", "/").replace(/^\.\//u, "");
|
|
260
|
+
const query = normalized.toLowerCase();
|
|
261
|
+
if (!query) {
|
|
262
|
+
return { hits: [], total: 0, indexed: this.indexed, progress: this.progress, incomplete: this.incomplete };
|
|
263
|
+
}
|
|
264
|
+
const hits = [];
|
|
265
|
+
const withDirectory = query.includes("/");
|
|
266
|
+
for (const entry of this.entries.values()) {
|
|
267
|
+
if (entry.kind !== "file" || linksOnly && !entry.openLink)
|
|
268
|
+
continue;
|
|
269
|
+
if (linksOnly || (withDirectory ? entry.path : entry.name).toLowerCase().includes(query))
|
|
270
|
+
hits.push(entry);
|
|
271
|
+
}
|
|
272
|
+
if (withDirectory && !linksOnly) {
|
|
273
|
+
hits.sort((a, b) => Number(b.path === normalized) - Number(a.path === normalized)
|
|
274
|
+
|| Number(b.path.toLowerCase() === query) - Number(a.path.toLowerCase() === query) || compareNameHits(a, b, query));
|
|
275
|
+
}
|
|
276
|
+
else if (!linksOnly)
|
|
277
|
+
hits.sort((a, b) => compareNameHits(a, b, query));
|
|
278
|
+
const results = linksOnly ? matchPathMentions(hits, query, 100) : hits;
|
|
279
|
+
return {
|
|
280
|
+
hits: results,
|
|
281
|
+
total: results.length,
|
|
282
|
+
indexed: this.indexed,
|
|
283
|
+
progress: this.progress,
|
|
284
|
+
incomplete: this.incomplete,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
searchQuickOpen(query, offset) {
|
|
288
|
+
const files = [...this.entries.values()].filter(entry => entry.kind === "file");
|
|
289
|
+
const ranked = query ? rankPathMatches(files, query) : files;
|
|
290
|
+
if (query && !ranked.length && this.indexed) {
|
|
291
|
+
const approximate = new Fuse(files, { keys: [{ name: "name", weight: 2 }, { name: "path", weight: 1 }], threshold: 0.38, ignoreLocation: true });
|
|
292
|
+
ranked.push(...approximate.search(query, { limit: QUICK_OPEN_PAGE_SIZE }).map(match => match.item));
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
hits: ranked.slice(offset, offset + (query ? QUICK_OPEN_PAGE_SIZE : 20)),
|
|
296
|
+
total: ranked.length,
|
|
297
|
+
indexed: this.indexed,
|
|
298
|
+
progress: this.progress,
|
|
299
|
+
incomplete: this.incomplete,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Wait until the first scan has finished, or until the deadline passes.
|
|
304
|
+
*
|
|
305
|
+
* WHY THIS EXISTS, and it is the difference between a search that works and one that does not.
|
|
306
|
+
*
|
|
307
|
+
* The panel fetches the index the moment a workspace opens, so the background scan is normally
|
|
308
|
+
* already running (or finished) by the time anybody types. But "normally" is not "always": a person
|
|
309
|
+
* who opens the panel and types immediately would otherwise get an answer computed from a
|
|
310
|
+
* half-built map - and an answer of "no matches" from a half-built map is a LIE. It is exactly the
|
|
311
|
+
* complaint this work exists to fix: "搜不出他想搜的东西".
|
|
312
|
+
*
|
|
313
|
+
* So the search WAITS for the scan, up to a deadline. The deadline is what keeps this from being a
|
|
314
|
+
* hang: past it, the search answers with what it knows and says so (`indexed: false`), which is a
|
|
315
|
+
* statement about the state rather than a claim about the tree.
|
|
316
|
+
*/
|
|
317
|
+
async waitUntilIndexed(timeoutMs) {
|
|
318
|
+
if (this.indexed)
|
|
319
|
+
return true;
|
|
320
|
+
const deadline = Date.now() + timeoutMs;
|
|
321
|
+
while (!this.indexed && Date.now() < deadline) {
|
|
322
|
+
// A scan that failed will never become ready, so waiting for it would burn the whole deadline
|
|
323
|
+
// on every request against a workspace whose directory is gone.
|
|
324
|
+
if (this.failure !== undefined)
|
|
325
|
+
return false;
|
|
326
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
327
|
+
}
|
|
328
|
+
return this.indexed;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The background scan.
|
|
332
|
+
*
|
|
333
|
+
* `readdir` provides ordinary entry types. Symlink targets are checked only for file type.
|
|
334
|
+
* Link names can be found, and linked directories never enter this traversal's queue.
|
|
335
|
+
*/
|
|
336
|
+
async scan(generation) {
|
|
337
|
+
const guard = createRootGuard(this.root);
|
|
338
|
+
const queue = [""];
|
|
339
|
+
let count = 0;
|
|
340
|
+
scan: for (let next = 0; next < queue.length;) {
|
|
341
|
+
if (this.stopped || generation !== this.generation)
|
|
342
|
+
return;
|
|
343
|
+
const batch = queue.slice(next, Math.min(next + DIRECTORY_BATCH, MAX_DIRECTORIES));
|
|
344
|
+
if (!batch.length) {
|
|
345
|
+
this.incomplete = true;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
next += batch.length;
|
|
349
|
+
const listings = await Promise.allSettled(batch.map(async (directory) => readdir(await guard(directory), { withFileTypes: true })));
|
|
350
|
+
if (this.stopped || generation !== this.generation)
|
|
351
|
+
return;
|
|
352
|
+
for (const [index, listing] of listings.entries()) {
|
|
353
|
+
const directory = batch[index];
|
|
354
|
+
this.scanned += 1;
|
|
355
|
+
if (listing.status === "rejected") {
|
|
356
|
+
if (!directory) {
|
|
357
|
+
this.failure = listing.reason;
|
|
358
|
+
this.building = false;
|
|
359
|
+
this.unread.clear();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
this.incomplete = true;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
for (const entry of listing.value) {
|
|
366
|
+
const relative = directory ? `${directory}/${entry.name}` : entry.name;
|
|
367
|
+
if (explorerInternalPath(this.cwd ? `${this.cwd}/${relative}` : relative) || blockedBy(relative, this.removedDuringScan)
|
|
368
|
+
|| !matchesDirectoryReads(relative, this.directoriesReadDuringScan))
|
|
369
|
+
continue;
|
|
370
|
+
const isDirectory = entry.isDirectory();
|
|
371
|
+
const openLink = entry.isSymbolicLink() && await stat(resolve(this.root, relative)).then(info => info.isFile(), () => false);
|
|
372
|
+
if (generation !== this.generation || this.stopped)
|
|
373
|
+
return;
|
|
374
|
+
if (openLink && (blockedBy(relative, this.removedDuringScan) || !matchesDirectoryReads(relative, this.directoriesReadDuringScan)))
|
|
375
|
+
continue;
|
|
376
|
+
if (!isDirectory && !entry.isFile() && !openLink)
|
|
377
|
+
continue;
|
|
378
|
+
if (count >= MAX_ENTRIES) {
|
|
379
|
+
this.incomplete = true;
|
|
380
|
+
break scan;
|
|
381
|
+
}
|
|
382
|
+
count++;
|
|
383
|
+
this.unread.delete(relative);
|
|
384
|
+
this.entries.set(relative, { path: relative, name: entry.name, directory, kind: isDirectory ? "directory" : "file",
|
|
385
|
+
...(openLink ? { openLink: true } : {}) });
|
|
386
|
+
if (isDirectory)
|
|
387
|
+
queue.push(relative);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (!this.incomplete) {
|
|
392
|
+
for (const path of this.unread)
|
|
393
|
+
this.entries.delete(path);
|
|
394
|
+
}
|
|
395
|
+
this.unread.clear();
|
|
396
|
+
this.hasScanned = true;
|
|
397
|
+
this.building = false;
|
|
398
|
+
this.removedDuringScan.clear();
|
|
399
|
+
this.directoriesReadDuringScan.clear();
|
|
400
|
+
}
|
|
401
|
+
/** Stop a running scan. Used when a workspace goes away. */
|
|
402
|
+
stop() {
|
|
403
|
+
this.generation += 1;
|
|
404
|
+
this.stopped = true;
|
|
405
|
+
this.building = false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** The workspace-relative path of an absolute one, for callers holding an absolute path. */
|
|
409
|
+
export function relativeTo(root, absolute) {
|
|
410
|
+
return toRelative(root, absolute);
|
|
411
|
+
}
|