Commit Graph

13 Commits

Author SHA1 Message Date
alex dbde651a2a feat: rich AST extraction with classes, methods, calls, and raises
- Upgrade tree-sitter to 0.22.4 with compatible grammar versions
- Add Python support via tree-sitter-python@0.23.6
- Add Go support via tree-sitter-go@0.23.4
- Extract class hierarchies with method signatures (params, returns)
- Extract call graphs including external library calls
- Extract exception raises (ValueError, Error, etc)
- Extract top-level functions with full signatures
- Encode rich AST data into compact markdown format:
  class:Name, method:name(params)→return, call:..., raise:...
- Deduplicate nested call chains (db.query vs db.query().where())
- Filter out simple export names when rich func/class entries exist
- All 55 tests passing
2026-06-10 15:58:52 +02:00
alex ed9f843d65 feat: move LLM cache to project-local directory
- Cache now lives in <project>/.pi-project-map/cache/llm-cache.json
- Removed global ~/.cache/pi-project-map/ usage
- Cache travels with the project, no cross-project collisions
- Easy to invalidate: rm -rf .pi-project-map/cache/

Files changed:
- llm-cache.ts: accept cacheDir parameter, default to project-local
- llm-extract.ts: pass cacheDir through to cache functions
- init.ts: pass rootPath as cacheDir
- patch.ts: accept and pass cacheDir
- cli.ts: pass targetPath as cacheDir
- pi-extension.ts: pass ctx.cwd as cacheDir
- Tests updated to use temp dirs for cache isolation
2026-06-10 15:13:10 +02:00
alex 5c6719817f feat: Pi extension uses Pi's internal complete() for LLM analysis
- PiLLMClient now imports @mariozechner/pi-ai's complete() function
- Respects user's /model selection and /login auth
- No external fetch() — Pi handles transport internally
- Added src/types/pi-ai.d.ts for TypeScript declarations
- Extension reverted to real LLM calls (initProject, patchFile, reinitPath)
- Tests mock @mariozechner/pi-ai for verification
2026-06-10 14:47:47 +02:00
alex 57c0f08210 refactor: Pi extension uses heuristics+AST instead of direct LLM calls
Inside Pi, the extension no longer attempts to call the LLM directly
(which Pi's ExtensionAPI doesn't support). Instead:

- project_map_init: generates maps using AST + heuristics (fast, free)
- project_map_patch: rewrites the file's directory with heuristics
- project_map_reinit: full heuristic regeneration
- project_map_validate: unchanged (no LLM needed)

The CLI still supports real LLM calls via --llm-provider=kimi|openai.
This separates concerns:
- Pi extension: deterministic structural analysis
- CLI: rich semantic analysis with configurable LLM
2026-06-10 10:28:15 +02:00
alex 7db9202658 fix: rename skill to match repo directory name (pi-map) 2026-06-09 23:36:07 +02:00
alex e66ed25cee fix: remove conflicting tree-sitter-go and tree-sitter-python dependencies
These grammars require tree-sitter@^0.25.0 but we use 0.21.1.
They already failed at runtime with try/catch graceful fallback.
Removing them fixes npm peer dependency conflict during pi install.

- Remove tree-sitter-go and tree-sitter-python from dependencies
- ast-extract.ts already handles missing grammars gracefully
- Heuristics + LLM layer cover Go/Python analysis anyway
2026-06-09 23:33:57 +02:00
alex 69d3acda5d feat: M7 proper LLM integration with dual providers, caching, and parallel batching
- Add LLM client abstraction (src/llm-client.ts) with factory pattern
- Add OpenAI-compatible external client (src/external-llm-client.ts)
- Add Kimi.com client using Anthropic-based API (src/kimi-llm-client.ts)
- Add Pi native LLM stub (src/pi-llm-client.ts) for future ExtensionAPI wiring
- Add SHA-256 disk cache at ~/.cache/pi-project-map/ (src/llm-cache.ts)
- Add parallel batching with p-limit, retry + exponential backoff (src/llm-batch.ts)
- Rewrite llm-extract.ts to use real LLM calls with structured prompts
  - File-level: PURPOSE, DEPS, CONCEPTS
  - Package-level: ROLE, ARCH
  - Context truncation, 50KB skip, cache before LLM call
- Wire CLI with --llm-provider, --llm-model, --llm-base-url flags
- Update config.ts with llmProvider, llmBaseUrl fields
- Update init.ts and patch.ts to accept optional LLMClient
- Add sample project fixture for manual testing
- Add tests: llm-cache (3), llm-batch (5), llm-integration (8 with real Kimi API),
  pi-extension (14 mocked)
- All 56 tests pass
2026-06-09 22:49:34 +02:00
alex 7b67205d43 Update design doc and implementation plan for proper LLM integration
- design-doc.md: Rewrote Section 3 (Pipeline Architecture) to describe the
  real LLM integration: dual-provider LLM client (Pi native + external),
  SHA-256 disk cache in ~/.cache/pi-project-map/, parallelization with
  4-8 concurrent requests, retries with exponential backoff, hard-error
  policy, context limit protection. Added new Section 4 with concrete
  file-level and package-level prompts.
- implementation-plan.md: Replaced old milestone schedule with current
  status and detailed M7 tasks for LLM integration: LLM client abstraction,
  external API client, Pi LLM client, disk cache, parallel batching with
  retries, rewriting llm-extract.ts, context limits, CLI/extension wiring,
  and tests.
- Minor formatting cleanup in pi-extension.ts and src/cli.ts

All 16 tests pass. TypeScript compiles clean.
2026-06-09 21:45:44 +02:00
alex 93c2ac60c5 Pi skill integration, CLI polish, --fix flag, config file support
- SKILL.md: Proper Agent Skills frontmatter with name/description
- pi-extension.ts: Pi extension registering 4 custom tools
  (project_map_init/patch/validate/reinit) with prompt snippets/guidelines
- pi-extension.ts: Auto-detects .pi-map.md files on session start, warns
  about dirty markers, injects maintenance hints before agent start
- package.json: Added pi.extensions and pi.skills entries
- CLI: Added picocolors, clean help screen, progress indicators,
  summary output with timing, colored check/warning icons
- validate.ts: Added --fix flag that regenerates directories with
  discrepancies
- config.ts: Reads .pi-project-map.json from project root with merge
  over defaults
- init.ts: Added optional verbose parameter for programmatic use

All 16 tests pass. TypeScript compiles clean. Build succeeds.
2026-06-09 20:54:59 +02:00
alex ab45859d65 Add AST extraction tests, broader ignore patterns, build dist
- ast-extract.ts: Support tree-sitter-python and tree-sitter-go grammar
  loading (pkg.language fallback)
- discover.ts: Add cache directories to default ignore (.cache, tmp,
  temp, .turbo, .parcel-cache, .eslintcache, .prettiercache)
- tests: Add TypeScript AST extraction tests (exports + imports)
- Verified on real project: media_library_viewer (196 .pi-map.md files)
  with accurate React component extraction
- Build: npm run build produces clean dist/ output

All 16 tests pass.
2026-06-09 19:25:56 +02:00
alex 3dbb3cb7b2 Fix discover, improve LLM heuristics, add integration tests
- discover.ts: Fix ignore package path handling for root '.' directories,
  add .pi-map.md to default ignore list
- llm-extract.ts: Fix export regex to only match line-start exports and
  handle 'export async function', fix root package role to 'Project root'
- init.ts: Minor cleanup
- .gitignore: Add .pi-map.md
- tests: 6 integration tests covering init, patch (small/large packages),
  validate (missing, orphaned, stale-signature detection)

All 14 tests pass. TypeScript compiles clean.
2026-06-09 19:14:41 +02:00
alex d311c8fb3c Implement all stubs: parsePackageMap, LLM heuristics, tree-sitter AST, patch rewrite, reinit
- format.ts: Full parsePackageMap implementation with round-trip support
- llm-extract.ts: Heuristic-based extraction without LLM API (regex exports,
  imports, purpose inference from filename patterns)
- ast-extract.ts: Tree-sitter integration for TypeScript/TSX with fallback
  for other languages
- init.ts: Refactored to expose generateDirectoryMap helper, reinitPath
  delegates to initProject
- patch.ts: Small packages now use generateDirectoryMap for full rewrite
- discover.ts: Cleaned up require('fs') to use proper ES import
- Tests: 8 tests covering format round-trip and LLM heuristics
- All TypeScript compiles clean, all tests pass
2026-06-09 18:04:57 +02:00
alex fd958671ca Initial commit: pi-project-map skill scaffolding
- Design doc with full spec (dense markdown format, hybrid AST+LLM pipeline,
  consumption model, stale data mitigation)
- Implementation plan with 6 milestones and rollout strategy
- TypeScript package structure with all source stubs
- CLI entry point, formatter, discover, init, patch, validate, extract, merge
- Pi SKILL.md with tool definitions and format documentation
2026-06-09 17:45:19 +02:00