18 Commits

Author SHA1 Message Date
Developer cb581f44b9 feat: smart subtree-aware reinit and validate --fix
- project_map_reinit now regenerates only the target subtree + ancestors
  by default, falling back to full reinit when subtree file count exceeds
  reinitFullThresholdPercent (default 10%).
- Add reinitFullThresholdPercent config option.
- Expose fix=true on project_map_validate Pi tool for localized repair.
- Update docs and runtime guidance to prefer patch / validate --fix
  before full reinit.
- Add integration tests for smart reinit and update typebox mock.
2026-06-16 11:46:48 +00:00
Developer 5f1c107667 feat: avoid duplicate project-map hint injection by checking context
The before_agent_start handler now scans the active session context via
ctx.sessionManager.buildSessionContext() for an existing pi-project-map-hint
custom message and skips injection when one is already present in the
current branch. This prevents duplicate visible hints in advisory/pre-init
modes and duplicate hidden hints in strong/strict modes. The hint is
automatically re-injected after compaction or /tree navigation removes it
from the active path.

Also removes the unused hooks/on-prompt.ts prompt-text injector.
2026-06-14 08:57:23 +00:00
Developer 6bc7be4c21 feat: avoid duplicate project-map hint injection by checking context
The before_agent_start handler now inspects the current session context
and skips injection if a pi-project-map-hint custom message is already
present in the active branch. This prevents duplicate hints on every
prompt while still re-injecting after compaction or tree navigation.

Also removes the unused hooks/on-prompt.ts prompt-text injector.
2026-06-14 08:53:26 +00:00
alex 58e8bd31d3 feat(prompt): implement prompt injection slice 4 2026-06-11 22:54:51 +02:00
alex 19666c900e feat(prompt): implement prompt injection slice 3 2026-06-11 21:32:38 +02:00
alex 621434b6e8 feat(prompt): implement prompt injection slice 2 2026-06-11 17:27:31 +02:00
alex 56560d9d56 feat(prompt): implement prompt injection slice 1 2026-06-11 17:01:10 +02:00
alex c6064f8d94 Implement layered maps and context retrieval 2026-06-11 12:56:18 +02:00
alex 010e4b83eb feat: render ASCII progress bar in Pi extension updates
- Add renderProgressBar() helper in pi-extension.ts
- Pi init/reinit now show [████░░░░░░] 3/20 → filename.ts
- Replaces plain text percentage with visual bar
- All 52 tests passing
2026-06-10 18:53:49 +02:00
alex 9bdb862cca feat: add progress bar to init/reinit with per-file tracking
- processFiles() now accepts onProgress callback (completed, total, currentFile)
- InitOptions.onProgress receives structured ProgressInfo object
- initProject aggregates progress across all directories
- CLI renders ASCII progress bar: [████░░░░░░] 3/20 | filename.ts
- Pi extension sends structured updates with percentage + file details
- All 52 tests passing
2026-06-10 18:43:42 +02:00
alex 2f198ea0d2 feat: remove heuristics, go LLM-only with mocks + restructure
BREAKING: Heuristic fallback removed — LLM client now required

Changes:
- Remove extractFileHeuristic, extractPackageHeuristic, all helpers
- extractFileLLM / extractPackageLLM now throw LLMError when client missing
- Add hybrid binary detection: extension blacklist + content sniffing
- Increase file size limit: 50KB → 500KB (text files only)
- Restructure src/ into subdirectories:
  - src/llm/ — all LLM clients, extract, batch, cache, error
  - src/ast/ — AST extraction
  - src/cli/ — CLI entry point
- Update all imports across codebase and tests
- Add tests/mock-llm.ts helper for deterministic mock clients
- Update all tests to use mock LLM clients (no heuristics dependency)
- All 52 tests passing (including 8 real LLM integration tests)
2026-06-10 17:34:37 +02:00
alex d948d88d0a feat: add live progress streaming to init/reinit tools
- InitOptions.onProgress callback for directory-level progress
- generateDirectoryMap reports per-file progress (→ filename)
- initProject reports [N/M] Analyzing <path> (X files)...
- pi-extension wires _onUpdate to onProgress for live Pi UI updates
- User sees real-time feedback instead of silent long waits
2026-06-10 16:32:08 +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 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 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