Files
openclaude/scripts/externals.ts
T
fb40d49e68 feat: add repo map codebase intelligence (#1867)
* feat: add Codebase Intelligence — repo map with PageRank-ranked structural summaries

Adds a new module that builds a structural map of the repository by parsing
source files with tree-sitter, building a cross-file reference graph weighted
by IDF, ranking files with PageRank, and rendering a token-budgeted summary
of the most important files and their signatures.

Surface:
- RepoMap tool the model can call on-demand, with focus_files / focus_symbols
- /repomap slash command with --tokens, --focus, --stats, --invalidate
- Auto-injection into session system context, gated by REPO_MAP=1 env var
  (compile-time feature('REPO_MAP') flag stays off in scripts/build.ts)

How it works:
  git ls-files → tree-sitter WASM parse → extract defs/refs →
  IDF-weighted directed graph → PageRank → render top files until token budget

Files imported by many others rank highest. Common symbol names (get, set,
map, value) are down-weighted via IDF. Results cached to disk keyed by
(path, mtime, size) — only changed files are re-parsed.

Supported languages: TypeScript, JavaScript, Python.

Tree-sitter tag queries are inlined as string constants in queries.ts so
they ship inside dist/cli.mjs and work after npm install — the .scm source
files are kept for readability/Aider attribution but are not required at
runtime. A drift-guard test (queries.test.ts) asserts byte-equality between
the inlined strings and the .scm source files.

Dependencies added: web-tree-sitter, tree-sitter-wasms, graphology,
graphology-pagerank, graphology-operators, js-tiktoken.

* fix(repomap): invalidate rendered cache on file edits + Windows test fix

- computeMapHash now folds per-file mtime+size into the cache key so a
  source edit (without changing the file list) no longer returns the
  prior rendered map. Adds a regression test that edits a file and
  confirms the second build reflects the new symbol without manual
  invalidateCache().
- queries.test.ts byte-for-byte drift guard normalizes CRLF -> LF when
  reading the .scm source so Windows checkouts pass. .gitattributes
  also pins *.scm to LF on future checkouts.
- Externals: declare web-tree-sitter, tree-sitter-wasms, graphology*,
  and js-tiktoken in scripts/externals.ts so build validation passes.

* fix(repomap): expand directory focus paths

* fix(repomap): satisfy deadcode check

* Fix repo map review findings

* Resolve remaining repo map review findings

* fix(repomap): address review findings

* fix(repomap): address review findings

* fix(repomap): resolve smoke and review follow-ups

* fix(repomap): preserve cached tag order

* fix(repomap): resolve review follow-ups

* fix(repomap): satisfy query promise lint

* Fix repo map context timeout cleanup

* fix: address repo map review findings

* fix: cancel timed-out repo map context builds

* fix(repomap): preserve git file path whitespace

* fix(repomap): handle graph and parsing edge cases

* fix(repomap): preserve shell token positions

* fix(repomap): respect configured cache home

* fix(repomap): address review findings

- Add explicit 10000ms timeout to the feature-flag-off context test to avoid cold-import flakes.

- Add --focus-symbols flag to /repomap and forward it to buildRepoMap, matching the RepoMap tool.

- Add parsing/command tests and docs coverage for --focus-symbols.

---------

Co-authored-by: gnanam1990 <gnanasekaran.sekareee@gmail.com>
2026-07-07 11:09:41 +08:00

140 lines
4.0 KiB
TypeScript

/**
* Shared external dependency lists for CLI and SDK bundles.
*
* Used by build.ts and validate-externals.ts.
* When adding a new dependency to package.json, check if it should be
* added here (large packages, native modules, or packages with many exports).
*/
// Packages that should be kept external in ALL bundles (CLI + SDK)
export const COMMON_EXTERNALS: string[] = [
// Native image processing
'sharp',
// Cloud provider SDKs
'@aws-sdk/client-bedrock',
'@aws-sdk/client-bedrock-runtime',
'@aws-sdk/client-sts',
'@aws-sdk/credential-providers',
'@azure/identity',
'google-auth-library',
// @vscode/ripgrep ships a platform-specific binary alongside its
// index.js and resolves the path via __dirname at runtime. Bundling
// would freeze the build host's absolute path into dist/cli.mjs, so we
// keep it external and rely on the npm package being installed.
'@vscode/ripgrep',
// Orama search engine
'@orama/orama',
'@orama/plugin-data-persistence',
// web-tree-sitter ships a WASM file alongside its JS and resolves the
// path via require.resolve at runtime; bundling would freeze the build
// host's absolute path, so keep it external.
'web-tree-sitter',
// tree-sitter-wasms ships per-language .wasm files resolved via
// require.resolve at runtime — same bundling concern as web-tree-sitter.
'tree-sitter-wasms',
]
// Additional packages external only in the SDK bundle (TUI + heavy deps)
export const SDK_ONLY_EXTERNALS: string[] = [
'react',
'react-reconciler',
'@anthropic-ai/sdk',
'@modelcontextprotocol/sdk',
]
// Packages kept external but NOT listed in package.json dependencies.
// These are dynamically imported at runtime — they're optional and resolved
// from transitive deps or installed by users who need that provider/protocol.
export const OPTIONAL_RUNTIME_EXTERNALS: string[] = [
// Cloud provider SDKs (dynamically imported per-provider)
'@aws-sdk/client-bedrock',
'@aws-sdk/client-bedrock-runtime',
'@aws-sdk/client-sts',
'@aws-sdk/credential-providers',
'@azure/identity',
]
// Computed full lists
export const CLI_EXTERNALS: string[] = COMMON_EXTERNALS
export const SDK_EXTERNALS: string[] = [...COMMON_EXTERNALS, ...SDK_ONLY_EXTERNALS]
// Packages intentionally bundled (not external, not flagged by validation)
// These are small utilities that are fine to inline into the output bundle.
export const INTENTIONALLY_BUNDLED: string[] = [
// Test utilities (bundled, not external)
// Anthropic provider variants (bundled, not the main SDK)
'@anthropic-ai/bedrock-sdk',
'@anthropic-ai/foundry-sdk',
'@anthropic-ai/sandbox-runtime',
// CLI / TUI utilities
'@alcalzone/ansi-tokenize',
'@commander-js/extra-typings',
'bidi-js',
'chalk',
'cli-boxes',
'cli-highlight',
'commander',
'emoji-regex',
'env-paths',
'figures',
'get-east-asian-width',
'indent-string',
'supports-hyperlinks',
'wrap-ansi',
// Data formats
'jsonc-parser',
'yaml',
'marked',
'turndown',
'xss',
// Data utilities
'ajv',
'auto-bind',
'diff',
'fflate',
'fuse.js',
'ignore',
'lodash-es',
'lru-cache',
'p-map',
'picomatch',
'proper-lockfile',
'qrcode',
'semver',
'shell-quote',
'signal-exit',
'type-fest',
// Networking
'axios',
'cross-spawn',
'duck-duck-scrape',
'execa',
'https-proxy-agent',
'tree-kill',
'undici',
'ws',
// React ecosystem (react/react-reconciler are SDK_ONLY_EXTERNALS, bundled in CLI)
'react',
'react-compiler-runtime',
'react-reconciler',
'usehooks-ts',
// Anthropic SDK (external in SDK bundle, bundled in CLI)
'@anthropic-ai/sdk',
// MCP SDK (external in SDK bundle, bundled in CLI)
'@modelcontextprotocol/sdk',
// Schema validation
'zod',
// gRPC (bundled into CLI, not external)
'@grpc/grpc-js',
'@grpc/proto-loader',
// Language server protocol
'vscode-languageserver-protocol',
// File watching
'chokidar',
// Graph algorithms (repo map PageRank)
'graphology',
'graphology-metrics',
// Tokenizer for repo map token budgeting
'js-tiktoken',
]