pan-wizard 3.35.0 → 3.37.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/CHANGELOG.md +3645 -0
- package/README.md +46 -52
- package/agents/pan-conductor.md +2 -3
- package/agents/pan-counterfactual.md +1 -2
- package/agents/pan-debugger.md +14 -3
- package/agents/pan-design-checker.md +1 -2
- package/agents/pan-designer.md +2 -3
- package/agents/pan-document_code.md +1 -2
- package/agents/pan-executor.md +25 -0
- package/agents/pan-hardener.md +4 -3
- package/agents/pan-integration-checker.md +1 -2
- package/agents/pan-knowledge.md +1 -2
- package/agents/pan-meta-reviewer.md +3 -3
- package/agents/pan-optimizer.md +4 -4
- package/agents/pan-phase-researcher.md +80 -475
- package/agents/pan-plan-checker.md +40 -3
- package/agents/pan-planner.md +21 -7
- package/agents/pan-previewer.md +3 -2
- package/agents/pan-project-researcher.md +72 -493
- package/agents/pan-release.md +1 -1
- package/agents/pan-reviewer.md +14 -3
- package/agents/pan-roadmapper.md +12 -7
- package/agents/pan-verifier.md +9 -4
- package/bin/install-lib.cjs +134 -14
- package/bin/install.js +59 -12
- package/commands/pan/army.md +1 -1
- package/commands/pan/autodev.md +76 -0
- package/commands/pan/cost.md +21 -1
- package/commands/pan/exec-phase.md +3 -4
- package/commands/pan/focus-auto.md +14 -7
- package/commands/pan/focus-design.md +4 -5
- package/commands/pan/focus-docs.md +24 -0
- package/commands/pan/learn.md +13 -6
- package/commands/pan/milestone-audit.md +8 -1
- package/commands/pan/milestone-done.md +10 -5
- package/commands/pan/milestone-new.md +2 -2
- package/commands/pan/new-project.md +15 -12
- package/commands/pan/plan-phase.md +15 -9
- package/commands/pan/preview.md +1 -1
- package/commands/pan/quick.md +1 -1
- package/commands/pan/review-deep.md +11 -5
- package/commands/pan/settings.md +6 -0
- package/commands/pan/verify-phase.md +6 -2
- package/docs/AGENTS.md +917 -0
- package/docs/ARCHITECTURE.md +1054 -0
- package/docs/CLI-REFERENCE.md +4582 -0
- package/docs/COMPARISON.md +116 -0
- package/docs/DEVELOPMENT.md +490 -0
- package/docs/ECOSYSTEM-REVIEW-2026-06.md +107 -0
- package/docs/ECOSYSTEM-REVIEW-2026-08.md +349 -0
- package/docs/EXAMPLES.md +584 -0
- package/docs/FAQ.md +254 -0
- package/docs/FIELD-HARVEST-2026-07.md +88 -0
- package/docs/FIELD-REPORT-army-2026-06.md +121 -0
- package/docs/HOOKS.md +638 -0
- package/docs/IMPROVEMENT-TODO.md +246 -0
- package/docs/INTERNALS.md +485 -0
- package/docs/MIGRATION-v2-to-v3.md +258 -0
- package/docs/SECURITY-HARDENING.md +230 -0
- package/docs/SKILLS-ENHANCEMENT-PLAN-V2.md +122 -0
- package/docs/SKILLS-FULL-TEXT.md +9685 -0
- package/docs/SKILLS-REFERENCE.md +1037 -0
- package/docs/TROUBLESHOOTING.md +1084 -0
- package/docs/USER-GUIDE.md +1437 -0
- package/docs/archive/SKILLS-ENHANCEMENT-PLAN.md +230 -0
- package/docs/audits/AUDIT-2026-08-e2e-ROADMAP.md +117 -0
- package/docs/audits/AUDIT-2026-08-e2e-VERIFICATION.md +693 -0
- package/docs/audits/AUDIT-2026-08-e2e.md +1546 -0
- package/docs/audits/OUTSTANDING-2026-08.md +275 -0
- package/docs/audits/STABILITY-TEST-2026-08.md +640 -0
- package/docs/branding/README-brand-draft.md +119 -0
- package/docs/branding/handoff/IMPLEMENTATION.md +205 -0
- package/docs/branding/handoff/README-brand-draft.md +119 -0
- package/docs/branding/handoff/image-prompts.md +46 -0
- package/docs/branding/image-prompts.md +46 -0
- package/docs/branding/nano-banana-prompts.txt +60 -0
- package/docs/context-monitor.md +13 -0
- package/docs/decisions/ADR-0001-strategic-feature-prioritization.md +83 -0
- package/docs/decisions/ADR-0002-copilot-cli-runtime.md +71 -0
- package/docs/decisions/ADR-0003-smart-execution.md +84 -0
- package/docs/decisions/ADR-0004-copilot-cli-interaction.md +89 -0
- package/docs/decisions/ADR-0005-command-naming.md +80 -0
- package/docs/decisions/ADR-0006-focus-commands.md +101 -0
- package/docs/decisions/ADR-0007-ship-v1.md +73 -0
- package/docs/decisions/ADR-0008-map-codebase-mermaid-togaf.md +80 -0
- package/docs/decisions/ADR-0009-production-deployment-checklist.md +68 -0
- package/docs/decisions/ADR-0010-standards-integration.md +79 -0
- package/docs/decisions/ADR-0011-help-commands-rewrite.md +64 -0
- package/docs/decisions/ADR-0012-contributors-attribution-index.md +42 -0
- package/docs/decisions/ADR-0013-strategic-feature-additions.md +53 -0
- package/docs/decisions/ADR-0014-internal-cleanup-code-quality.md +53 -0
- package/docs/decisions/ADR-0015-focus-auto-runner.md +296 -0
- package/docs/decisions/ADR-0016-enhanced-doc-sync.md +54 -0
- package/docs/decisions/ADR-0017-enhanced-focus-design.md +69 -0
- package/docs/decisions/ADR-0018-user-reality-testing.md +84 -0
- package/docs/decisions/ADR-0019-end-to-end-user-acceptance-testing.md +113 -0
- package/docs/decisions/ADR-0020-ai-drift-prevention.md +55 -0
- package/docs/decisions/ADR-0021-codebase-mapper-v2.md +76 -0
- package/docs/decisions/ADR-0022-lifecycle-completeness.md +63 -0
- package/docs/decisions/ADR-0023-opus-4-7-adoption.md +89 -0
- package/docs/decisions/ADR-0024-spec-b-v2-completion.md +137 -0
- package/docs/decisions/ADR-0025-behavioral-guardrails-layer.md +129 -0
- package/docs/decisions/ADR-0026-self-improvement-loop.md +171 -0
- package/docs/decisions/ADR-0027-doc-code-link-graph.md +164 -0
- package/docs/decisions/ADR-0028-unified-agents-skills-target.md +46 -0
- package/docs/decisions/ADR-0029-experiment-evaluator.md +76 -0
- package/docs/decisions/ADR-0030-planning-concurrency.md +37 -0
- package/docs/decisions/ADR-0031-focus-auto-backlog-source.md +47 -0
- package/docs/decisions/ADR-0032-squad-model.md +64 -0
- package/docs/decisions/ADR-0033-army-campaign.md +40 -0
- package/docs/decisions/ADR-0034-scheduled-campaigns.md +57 -0
- package/docs/decisions/ADR-0035-army-hud-dashboard.md +40 -0
- package/docs/decisions/ADR-0036-agentic-memory-architecture.md +106 -0
- package/docs/decisions/ADR-0037-pin-security-agents-to-opus.md +51 -0
- package/docs/decisions/ADR-0038-skill-aligned-decomposition.md +41 -0
- package/docs/decisions/ADR-0039-worktree-as-project-variant.md +37 -0
- package/docs/decisions/ADR-0040-memory-injection-defense.md +55 -0
- package/docs/decisions/ADR-0041-mcp-dual-era-bridge.md +47 -0
- package/docs/decisions/ADR-0042-design-parity-both-flows.md +45 -0
- package/docs/decisions/ADR-0043-addressable-planning-roots.md +56 -0
- package/docs/decisions/ADR-0044-bound-the-cached-context.md +104 -0
- package/docs/decisions/ADR-0045-agent-plugins-bundle.md +76 -0
- package/docs/decisions/ADR-0046-subagent-frontmatter-decisions.md +39 -0
- package/docs/decisions/ADR-0047-pan-harness.md +76 -0
- package/docs/decisions/ADR-0048-one-core-per-project.md +43 -0
- package/docs/decisions/ADR-0049-machine-verdicts-and-findings-ledger.md +116 -0
- package/docs/specs/ai_drift_prevention_featureai.md +286 -0
- package/docs/specs/codebase_mapper_v2_featureai.md +930 -0
- package/docs/specs/command_naming_optimization_featureai.md +930 -0
- package/docs/specs/comp_analysis_markdown_v1.md +149 -0
- package/docs/specs/continuous_autonomous_execution_featureai.md +304 -0
- package/docs/specs/contributors_attribution_index_featureai.md +476 -0
- package/docs/specs/copilot_cli_interaction_featureai.md +868 -0
- package/docs/specs/copilot_cli_runtime_featureai.md +647 -0
- package/docs/specs/custom-skills-assessment.md +461 -0
- package/docs/specs/deployment_audit_findings_featureai.md +243 -0
- package/docs/specs/doc_code_link_graph_featureai.md +253 -0
- package/docs/specs/documentation_alignment_cleanup_featureai.md +69 -0
- package/docs/specs/e2e_visual_testing_featureai.md +615 -0
- package/docs/specs/end_to_end_user_acceptance_testing_featureai.md +810 -0
- package/docs/specs/evidence-loop-plan.md +76 -0
- package/docs/specs/evidence_loop_featureai.md +497 -0
- package/docs/specs/focus-auto-optimize-category.md +449 -0
- package/docs/specs/focus-auto-optimize-superplan.md +188 -0
- package/docs/specs/focus_auto_runner_featureai.md +1102 -0
- package/docs/specs/focus_design_v2_featureai.md +197 -0
- package/docs/specs/focus_sync_v2_featureai.md +202 -0
- package/docs/specs/git_integration_overhaul_featureai.md +326 -0
- package/docs/specs/glm_zai_provider_featureai.md +200 -0
- package/docs/specs/googlecli_adoption_featureai.md +661 -0
- package/docs/specs/help_commands_rewrite_featureai.md +860 -0
- package/docs/specs/industry_analysis_strategic_additions_featureai.md +231 -0
- package/docs/specs/industry_comparison_and_feature_gaps_featureai.md +674 -0
- package/docs/specs/internal_cleanup_code_quality_featureai.md +486 -0
- package/docs/specs/investigations/README.md +31 -0
- package/docs/specs/investigations/digests/2026-09-28.md +47 -0
- package/docs/specs/investigations/digests/2026-10-08.md +62 -0
- package/docs/specs/investigations/digests/2026-10-10.md +61 -0
- package/docs/specs/investigations/features/debugger-red-loop-first.md +55 -0
- package/docs/specs/investigations/features/harness-cross-host-behaviour.md +93 -0
- package/docs/specs/investigations/features/optimize-apply-regression-gate.md +66 -0
- package/docs/specs/investigations/features/reviewer-smell-baseline.md +57 -0
- package/docs/specs/investigations/features/trace-failure-capture.md +69 -0
- package/docs/specs/lifecycle_completeness_featureai.md +754 -0
- package/docs/specs/local-first-ci.md +42 -0
- package/docs/specs/map_codebase_mermaid_togaf_featureai.md +805 -0
- package/docs/specs/market-delta-2026-09-superplan.md +310 -0
- package/docs/specs/market-ideas-2026-09.md +131 -0
- package/docs/specs/market-ideas-2026-10.md +428 -0
- package/docs/specs/market-ideas-ledger.md +177 -0
- package/docs/specs/memory-optimization-2026-10.md +285 -0
- package/docs/specs/multi-track-planning-roots.md +143 -0
- package/docs/specs/multi_model_routing_featureai.md +687 -0
- package/docs/specs/multi_model_routing_superplan.md +197 -0
- package/docs/specs/opus_47_existing_enhancements_featureai.md +247 -0
- package/docs/specs/opus_47_extended_features_featureai.md +363 -0
- package/docs/specs/opus_47_extended_features_v2_featureai.md +397 -0
- package/docs/specs/pan_focus_commands_featureai.md +2336 -0
- package/docs/specs/pan_zcode_mcp_bridge_featureai.md +120 -0
- package/docs/specs/product-excellence-superplan.md +315 -0
- package/docs/specs/product_excellence_program_2026_q4_featureai.md +365 -0
- package/docs/specs/production_deployment_readiness_featureai.md +433 -0
- package/docs/specs/production_readiness_ship_v1_featureai.md +698 -0
- package/docs/specs/real_test_enforcement_featureai.md +213 -0
- package/docs/specs/reality-check-2026-09-superplan.md +362 -0
- package/docs/specs/right-sized-ceremony.md +74 -0
- package/docs/specs/roadmap_and_competition_2026_q4_featureai.md +390 -0
- package/docs/specs/self_improvement_loop_featureai.md +875 -0
- package/docs/specs/skill-aligned-decomposition.md +155 -0
- package/docs/specs/standards_integration_featureai.md +833 -0
- package/docs/specs/testing-system-redesign-2026-09.md +267 -0
- package/docs/specs/user_reality_testing_system_featureai.md +788 -0
- package/docs/specs/watch-triggers.json +22 -0
- package/docs/specs/workflow-integration-redesign.md +742 -0
- package/docs/specs/workflow_state_consistency_featureai.md +183 -0
- package/hooks/dist/pan-context-monitor.js +9 -2
- package/hooks/dist/pan-cost-logger.js +5 -0
- package/hooks/dist/pan-guard.js +28 -5
- package/hooks/dist/pan-stop-guard.js +9 -9
- package/hooks/dist/pan-trace-logger.js +5 -0
- package/package.json +10 -2
- package/pan-wizard-core/bin/lib/agents-md.cjs +57 -8
- package/pan-wizard-core/bin/lib/autodev-report.cjs +180 -0
- package/pan-wizard-core/bin/lib/autodev.cjs +642 -0
- package/pan-wizard-core/bin/lib/ci.cjs +143 -0
- package/pan-wizard-core/bin/lib/commands.cjs +1 -1
- package/pan-wizard-core/bin/lib/config.cjs +41 -5
- package/pan-wizard-core/bin/lib/constants.cjs +27 -1
- package/pan-wizard-core/bin/lib/core.cjs +31 -14
- package/pan-wizard-core/bin/lib/cost.cjs +160 -4
- package/pan-wizard-core/bin/lib/cross-family.cjs +164 -0
- package/pan-wizard-core/bin/lib/debug-cases.cjs +104 -0
- package/pan-wizard-core/bin/lib/doc-lint.cjs +5 -3
- package/pan-wizard-core/bin/lib/failure-class.cjs +81 -0
- package/pan-wizard-core/bin/lib/findings.cjs +148 -9
- package/pan-wizard-core/bin/lib/focus.cjs +1 -1
- package/pan-wizard-core/bin/lib/git.cjs +1 -1
- package/pan-wizard-core/bin/lib/hosts.cjs +88 -0
- package/pan-wizard-core/bin/lib/init.cjs +7 -2
- package/pan-wizard-core/bin/lib/knowledge.cjs +2 -0
- package/pan-wizard-core/bin/lib/merge.cjs +50 -0
- package/pan-wizard-core/bin/lib/mutate.cjs +268 -0
- package/pan-wizard-core/bin/lib/next-action.cjs +112 -0
- package/pan-wizard-core/bin/lib/optimize.cjs +2 -2
- package/pan-wizard-core/bin/lib/phase-gate.cjs +15 -9
- package/pan-wizard-core/bin/lib/phase-remove.cjs +91 -11
- package/pan-wizard-core/bin/lib/phase.cjs +85 -13
- package/pan-wizard-core/bin/lib/plan-lint.cjs +310 -0
- package/pan-wizard-core/bin/lib/preview.cjs +26 -4
- package/pan-wizard-core/bin/lib/requirements-lint.cjs +130 -0
- package/pan-wizard-core/bin/lib/research-lint.cjs +268 -0
- package/pan-wizard-core/bin/lib/review-deep.cjs +14 -22
- package/pan-wizard-core/bin/lib/review-vote.cjs +105 -0
- package/pan-wizard-core/bin/lib/roadmap.cjs +1 -0
- package/pan-wizard-core/bin/lib/runner.cjs +2 -16
- package/pan-wizard-core/bin/lib/sizing.cjs +356 -0
- package/pan-wizard-core/bin/lib/squads.cjs +1 -1
- package/pan-wizard-core/bin/lib/state-write.cjs +247 -0
- package/pan-wizard-core/bin/lib/test-gate.cjs +433 -0
- package/pan-wizard-core/bin/lib/uat.cjs +149 -0
- package/pan-wizard-core/bin/lib/usage.cjs +104 -0
- package/pan-wizard-core/bin/lib/verdict.cjs +26 -3
- package/pan-wizard-core/bin/lib/verify-plan-set.cjs +30 -1
- package/pan-wizard-core/bin/lib/verify-preflight.cjs +2 -2
- package/pan-wizard-core/bin/lib/verify-red.cjs +174 -0
- package/pan-wizard-core/bin/lib/verify-retro.cjs +3 -2
- package/pan-wizard-core/bin/lib/verify-scope.cjs +143 -2
- package/pan-wizard-core/bin/lib/verify.cjs +86 -31
- package/pan-wizard-core/bin/lib/worktree.cjs +70 -0
- package/pan-wizard-core/bin/pan-tools.cjs +257 -28
- package/pan-wizard-core/learnings/universal/autonomous-loop.md +2 -2
- package/pan-wizard-core/mcp/orchestrator.cjs +4 -1
- package/pan-wizard-core/references/continuation-format.md +3 -3
- package/pan-wizard-core/references/design-methodology.md +1 -1
- package/pan-wizard-core/references/guardrails.md +1 -1
- package/pan-wizard-core/references/handoff-decisions.md +1 -1
- package/pan-wizard-core/references/model-profiles.md +2 -3
- package/pan-wizard-core/references/questioning.md +24 -0
- package/pan-wizard-core/references/ui-brand.md +4 -6
- package/pan-wizard-core/references/verdict-contract.md +2 -1
- package/pan-wizard-core/templates/config.json +10 -2
- package/pan-wizard-core/templates/debug.md +1 -0
- package/pan-wizard-core/templates/design.md +5 -4
- package/pan-wizard-core/templates/discovery.md +2 -2
- package/pan-wizard-core/templates/phase-prompt.md +7 -0
- package/pan-wizard-core/templates/requirements.md +9 -0
- package/pan-wizard-core/templates/research.md +10 -0
- package/pan-wizard-core/templates/summary-complex.md +5 -1
- package/pan-wizard-core/templates/summary-minimal.md +4 -0
- package/pan-wizard-core/templates/summary-standard.md +5 -1
- package/pan-wizard-core/templates/summary.md +8 -1
- package/pan-wizard-core/workflows/add-phase.md +4 -6
- package/pan-wizard-core/workflows/assumptions.md +19 -1
- package/pan-wizard-core/workflows/diagnose-issues.md +2 -0
- package/pan-wizard-core/workflows/discuss-phase.md +4 -2
- package/pan-wizard-core/workflows/exec-lean.md +69 -0
- package/pan-wizard-core/workflows/exec-phase.md +79 -15
- package/pan-wizard-core/workflows/execute-plan.md +3 -1
- package/{commands/pan → pan-wizard-core/workflows}/focus-doc-audit.md +13 -29
- package/{commands/pan → pan-wizard-core/workflows}/focus-drift-walking.md +3 -18
- package/{commands/pan → pan-wizard-core/workflows}/focus-exec.md +8 -23
- package/{commands/pan → pan-wizard-core/workflows}/focus-plan.md +6 -20
- package/{commands/pan → pan-wizard-core/workflows}/focus-scan.md +3 -16
- package/{commands/pan → pan-wizard-core/workflows}/focus-sync.md +7 -21
- package/pan-wizard-core/workflows/health.md +6 -0
- package/pan-wizard-core/workflows/help.md +114 -77
- package/pan-wizard-core/workflows/insert-phase.md +4 -6
- package/pan-wizard-core/workflows/learn.md +3 -3
- package/pan-wizard-core/workflows/milestone-audit.md +2 -2
- package/pan-wizard-core/workflows/milestone-new.md +38 -95
- package/pan-wizard-core/workflows/new-project.md +96 -258
- package/pan-wizard-core/workflows/optimize.md +107 -5
- package/pan-wizard-core/workflows/phase-tests.md +10 -0
- package/pan-wizard-core/workflows/plan-phase.md +106 -45
- package/pan-wizard-core/workflows/profile.md +50 -0
- package/pan-wizard-core/workflows/progress.md +10 -0
- package/pan-wizard-core/workflows/quick.md +34 -43
- package/pan-wizard-core/workflows/remove-phase.md +11 -1
- package/pan-wizard-core/workflows/research-phase.md +118 -40
- package/pan-wizard-core/workflows/resume-project.md +18 -2
- package/pan-wizard-core/workflows/settings.md +33 -19
- package/pan-wizard-core/workflows/todo-check.md +6 -2
- package/pan-wizard-core/workflows/transition.md +22 -4
- package/pan-wizard-core/workflows/uat-walkthrough.md +90 -0
- package/pan-wizard-core/workflows/update.md +1 -1
- package/pan-wizard-core/workflows/verify-phase.md +39 -46
- package/scripts/build-agent-plugin.js +35 -15
- package/scripts/build-help.cjs +106 -0
- package/scripts/build-plugin.js +10 -1
- package/scripts/deprecate-old-versions.js +70 -3
- package/scripts/generate-skills-docs.py +1 -1
- package/scripts/git-hooks/pre-push +27 -0
- package/scripts/install-git-hooks.js +7 -5
- package/scripts/install-pre-push.cjs +38 -0
- package/scripts/land.cjs +151 -0
- package/scripts/local-ci.cjs +501 -0
- package/scripts/local-schedule.cjs +277 -0
- package/scripts/mutation-probe.cjs +7 -80
- package/scripts/prompt-lint.cjs +32 -0
- package/scripts/prompt-rules.cjs +156 -0
- package/scripts/run-tests.cjs +7 -1
- package/scripts/test-quality-lint.cjs +3 -3
- package/scripts/test-surface.cjs +175 -6
- package/agents/pan-research-synthesizer.md +0 -246
- package/commands/pan/audit-deployment.md +0 -386
- package/commands/pan/dashboard.md +0 -22
- package/commands/pan/discord.md +0 -19
- package/commands/pan/mcp-bridge.md +0 -143
- package/commands/pan/milestone-cleanup.md +0 -19
- package/commands/pan/milestone-gaps.md +0 -35
- package/commands/pan/optimize.md +0 -115
- package/commands/pan/profile.md +0 -76
- package/commands/pan/research-phase.md +0 -189
- package/pan-wizard-core/bin/lib/bridge.cjs +0 -269
- package/pan-wizard-core/templates/research-project/architecture.md +0 -204
- package/pan-wizard-core/templates/research-project/features.md +0 -147
- package/pan-wizard-core/templates/research-project/pitfalls.md +0 -200
- package/pan-wizard-core/templates/research-project/stack.md +0 -120
- package/pan-wizard-core/templates/research-project/summary.md +0 -170
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
# Codebase Mapper v2 — Advanced Codebase Import & Analysis — featureAI Specification
|
|
2
|
+
|
|
3
|
+
**Generated:** 2026-03-08
|
|
4
|
+
**Mode:** Full (all 10 phases)
|
|
5
|
+
**Scope:** Redesign `/pan:map-codebase` for deep codebase import with relationship maps, technical architecture analysis, best practices detection, and lowercase output filenames
|
|
6
|
+
**ADR:** ADR-0021
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Phase 0: Problem Framing & Demand Validation
|
|
11
|
+
|
|
12
|
+
### 0.1 Problem Statement
|
|
13
|
+
|
|
14
|
+
`/pan:map-codebase` currently produces 7 template-driven documents via 4 parallel agents, but the analysis is shallow for importing complex brownfield codebases. The agents rely on bash commands (`find`, `grep`, `ls`) with hardcoded patterns (e.g., `grep -r "import.*stripe"`) that miss most real-world codebases. There is no module dependency graph, no import/export analysis, no relationship mapping between components, no best-practice detection, and no cross-referencing between documents. For a tool whose core value proposition is "understand your codebase before planning," this is the weakest link in the PAN workflow chain.
|
|
15
|
+
|
|
16
|
+
### 0.2 Demand Evidence
|
|
17
|
+
|
|
18
|
+
| Evidence Type | Source | Finding |
|
|
19
|
+
|--------------|--------|---------|
|
|
20
|
+
| Personal pain (user-stated) | This conversation | "this one is little half baked for importing codebases... expand quite heavy, technical arch, relationship maps, best practices, go far and go wide" |
|
|
21
|
+
| Competitor feature parity | Aider repo-map | Aider builds tree-sitter AST-based repo maps showing every class/function/method with call relationships |
|
|
22
|
+
| Competitor feature parity | Continue.dev @codebase | RAG-based codebase indexing with embeddings for semantic search (has accuracy issues but sets user expectations) |
|
|
23
|
+
| Competitor feature parity | DeepWiki | Auto-generates comprehensive wiki from repos with architecture diagrams and relationship maps |
|
|
24
|
+
| Competitor feature parity | Swark | LLM-powered architecture diagram generation from code analysis |
|
|
25
|
+
|
|
26
|
+
### 0.3 Scope Definition
|
|
27
|
+
|
|
28
|
+
| In Scope | Out of Scope (and why) |
|
|
29
|
+
|----------|------------------------|
|
|
30
|
+
| Regex-based import/export analysis per language | AST parsing with tree-sitter (adds runtime dep) |
|
|
31
|
+
| Module dependency graph (Mermaid) | Interactive visualization (D2, vis.js — adds deps) |
|
|
32
|
+
| Circular dependency detection | Auto-fix of circular deps (too dangerous) |
|
|
33
|
+
| Best practices detection (patterns matched against known conventions) | Linting/formatting enforcement (existing tools do this) |
|
|
34
|
+
| Cross-document references (ARCHITECTURE.md links to STRUCTURE.md) | Hyperlink validation (too fragile) |
|
|
35
|
+
| Lowercase output filenames (stack.md not STACK.md) | Renaming existing UPPERCASE files (migration handled separately) |
|
|
36
|
+
| 6 focus areas (was 4) with expanded document set | More than 9 output documents (diminishing returns) |
|
|
37
|
+
| Language-aware file scanning (JS/TS, Python, Go, Rust, Java, C#) | Every language on earth (cover top 6, fallback for others) |
|
|
38
|
+
| Relationship maps (who-calls-whom, who-imports-whom) | Runtime call graph tracing (requires instrumentation) |
|
|
39
|
+
| Entry point detection heuristics | Build system integration (too many build tools) |
|
|
40
|
+
| Dead code detection (unreferenced exports) | Auto-deletion of dead code (dangerous) |
|
|
41
|
+
|
|
42
|
+
### 0.4 Success Criteria
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
SC-1: Codebase mapper produces 9 documents (was 7) covering stack, integrations, architecture, structure, conventions, testing, concerns, relationships, and best-practices
|
|
46
|
+
SC-2: All output filenames are lowercase (stack.md, not STACK.md)
|
|
47
|
+
SC-3: relationships.md contains a Mermaid module dependency graph derived from actual import analysis
|
|
48
|
+
SC-4: best-practices.md identifies at least 5 pattern categories with prescriptive guidance
|
|
49
|
+
SC-5: Analysis works for JS/TS, Python, Go, Rust, Java, and C# codebases (language-aware scanning)
|
|
50
|
+
SC-6: No runtime dependencies added (regex-based analysis only)
|
|
51
|
+
SC-7: Cross-platform: works on Windows, Mac, Linux
|
|
52
|
+
SC-8: Backward compatible: existing UPPERCASE.md files still consumed by plan-phase/exec-phase
|
|
53
|
+
SC-9: Full analysis completes in < 60 seconds for a 10,000-file codebase
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 0.5 User Stories
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
As a developer importing a brownfield codebase into PAN,
|
|
60
|
+
I want the mapper to discover module relationships and draw dependency graphs,
|
|
61
|
+
so that I understand the coupling between components before planning changes,
|
|
62
|
+
instead of manually tracing imports across hundreds of files.
|
|
63
|
+
|
|
64
|
+
As a developer starting a new PAN project on an existing repo,
|
|
65
|
+
I want the mapper to detect which best practices are followed vs missing,
|
|
66
|
+
so that I can prioritize technical debt cleanup in my roadmap,
|
|
67
|
+
instead of discovering convention violations during execution.
|
|
68
|
+
|
|
69
|
+
As a team lead onboarding developers to a codebase,
|
|
70
|
+
I want the mapper to produce a comprehensive architecture document with entry points, layers, and data flows,
|
|
71
|
+
so that new developers can orient quickly,
|
|
72
|
+
instead of spending days reading code to understand the system.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 0.6 Cannibalization Check
|
|
76
|
+
|
|
77
|
+
| Existing Command/Agent | Overlap? | Impact |
|
|
78
|
+
|-----------------------|----------|--------|
|
|
79
|
+
| `/pan:map-codebase` (current) | Full | This IS the redesign — replaces current implementation |
|
|
80
|
+
| `pan-document_code` agent | Full | Agent rewritten with expanded focus areas |
|
|
81
|
+
| `init map-codebase` command | Partial | Enhanced with new config fields, backward compatible |
|
|
82
|
+
| `/pan:focus-scan` | None | Focus-scan reads codebase docs as input, doesn't produce them |
|
|
83
|
+
| `drift-check` | None | Drift-check validates conventions, mapper discovers them |
|
|
84
|
+
|
|
85
|
+
### 0.7 Cognitive Load Assessment
|
|
86
|
+
|
|
87
|
+
| Metric | Before | After | Delta |
|
|
88
|
+
|--------|--------|-------|-------|
|
|
89
|
+
| Commands a new user must learn | 42 | 42 | +0 |
|
|
90
|
+
| New concepts introduced | 0 | 2 (relationships, best-practices) | +2 |
|
|
91
|
+
| Score | — | — | neutral (0) — same command, richer output |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Phase 1: Internal Reconnaissance
|
|
96
|
+
|
|
97
|
+
### 1.1 Existing Capabilities Inventory
|
|
98
|
+
|
|
99
|
+
| Capability | Status | Location | Relevance |
|
|
100
|
+
|------------|--------|----------|-----------|
|
|
101
|
+
| 4 parallel mapper agents | Working | `agents/pan-document_code.md` | Core pattern to keep and extend |
|
|
102
|
+
| 7 document templates | Working | `pan-wizard-core/templates/codebase/*.md` | All need lowercase rename + 2 new templates |
|
|
103
|
+
| init map-codebase bootstrap | Working | `pan-wizard-core/bin/lib/init.cjs:699-733` | Needs new config fields |
|
|
104
|
+
| Orchestrator workflow | Working | `pan-wizard-core/workflows/map-codebase.md` | Needs 6 agents (was 4) |
|
|
105
|
+
| Command definition | Working | `commands/pan/map-codebase.md` | Minor updates |
|
|
106
|
+
| Secret scanning post-step | Working | workflow step 7 | Keep as-is |
|
|
107
|
+
| Mermaid diagram generation | Working (v1) | Templates + agent prompts | Extend with dependency graphs |
|
|
108
|
+
| TOGAF-aligned sections | Working (v1) | Templates (ADR-0008) | Keep |
|
|
109
|
+
|
|
110
|
+
### 1.2 Convention Enforcement Checklist
|
|
111
|
+
|
|
112
|
+
- [x] Functions named `cmd<Module><Action>(cwd, raw, ...args)` — `cmdInitMapCodebase()`
|
|
113
|
+
- [x] File reads use `safeReadFile()` pattern
|
|
114
|
+
- [x] JSON output via `output(data, raw, humanLabel)`
|
|
115
|
+
- [x] Errors via `error(message)`
|
|
116
|
+
- [x] Paths in JSON output pass through `toPosix()`
|
|
117
|
+
- [x] CommonJS only (`.cjs` with `require()`)
|
|
118
|
+
- [x] Zero runtime dependencies
|
|
119
|
+
|
|
120
|
+
### 1.3 Integration Points
|
|
121
|
+
|
|
122
|
+
8 workflows + 4 commands reference codebase documents:
|
|
123
|
+
- `/pan:plan-phase` → loads CONVENTIONS.md, STRUCTURE.md, ARCHITECTURE.md, STACK.md, TESTING.md, INTEGRATIONS.md, CONCERNS.md based on phase type
|
|
124
|
+
- `/pan:exec-phase` → references conventions, structure, testing patterns
|
|
125
|
+
- `/pan:focus-design` → reads codebase docs for Phase 0.8 investigation
|
|
126
|
+
- `/pan:research-phase` → loads relevant codebase docs
|
|
127
|
+
|
|
128
|
+
**Backward compatibility requirement:** All consumers currently expect UPPERCASE.md filenames. The migration must support both until all references are updated.
|
|
129
|
+
|
|
130
|
+
### 1.4 Dependency Map
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
map-codebase.md (command)
|
|
134
|
+
└─→ map-codebase.md (workflow)
|
|
135
|
+
├─→ init.cjs:cmdInitMapCodebase() (bootstrap)
|
|
136
|
+
├─→ pan-document_code agent × 6 (was 4)
|
|
137
|
+
│ └─→ templates/codebase/*.md (9 templates, was 7)
|
|
138
|
+
└─→ commands.cjs:cmdCommit() (auto-commit)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Phase 2: Competitive Intelligence
|
|
144
|
+
|
|
145
|
+
### 2.1 Deep-Dive Research
|
|
146
|
+
|
|
147
|
+
| Tool | Approach | Strengths | Weaknesses |
|
|
148
|
+
|------|----------|-----------|------------|
|
|
149
|
+
| **Aider** | tree-sitter AST repo-map: every class/function/method with signatures + call graph | Precise, language-aware, shows relationships | Requires tree-sitter WASM binaries (runtime dep), no architectural narrative |
|
|
150
|
+
| **Cursor** | @codebase with embeddings + RAG vector search | Fast semantic search, good for "find related code" | No structured output, no relationship maps, opaque index |
|
|
151
|
+
| **Continue.dev** | @codebase with RAG/embeddings, reranking | IDE-integrated, semantic understanding | Known accuracy issues, hallucinated references, slow indexing |
|
|
152
|
+
| **Cline** | No indexing — deliberate filesystem traversal + grep per task | No stale index, always fresh, zero setup | Slow for large codebases, no persistent understanding |
|
|
153
|
+
| **Swark** | LLM-powered Mermaid architecture diagrams | Visual output, understands high-level patterns | Single-purpose (diagrams only), requires API calls |
|
|
154
|
+
| **DeepWiki** | Full auto-wiki generation from repos | Comprehensive, multi-page wiki with diagrams | Requires cloud API, not local, expensive |
|
|
155
|
+
|
|
156
|
+
### 2.2 Competitive Matrix
|
|
157
|
+
|
|
158
|
+
| Aspect | PAN (Current) | PAN v2 (Proposed) | Aider | Cursor | Cline | DeepWiki |
|
|
159
|
+
|--------|--------------|-------------------|-------|--------|-------|----------|
|
|
160
|
+
| Structured output | 7 docs, template-based | 9 docs, cross-referenced | Flat repo-map | None (embeddings) | None | Wiki pages |
|
|
161
|
+
| Dependency graphs | None | Mermaid from import analysis | tree-sitter AST | None | None | LLM-generated |
|
|
162
|
+
| Best practices | None | Pattern detection | None | None | None | None |
|
|
163
|
+
| Language support | Bash grep (fragile) | 6-language regex | tree-sitter (30+ langs) | All (embeddings) | All (grep) | All (LLM) |
|
|
164
|
+
| Runtime deps | Zero | Zero | tree-sitter WASM | Embeddings model | None | Cloud API |
|
|
165
|
+
| Cross-platform | Yes | Yes | Yes | IDE-only | IDE-only | Web-only |
|
|
166
|
+
| Offline capable | Yes | Yes | Yes | No | Yes | No |
|
|
167
|
+
| Prescriptive output | Yes (conventions) | Yes (expanded) | No | No | No | Descriptive only |
|
|
168
|
+
|
|
169
|
+
**PAN v2's unique position:** The only tool that produces structured, prescriptive, cross-referenced analysis documents with dependency graphs AND zero runtime dependencies. Aider is more precise (AST) but less useful (no narrative). DeepWiki is more comprehensive but requires cloud. PAN v2 occupies the sweet spot: thorough enough to be useful, lightweight enough to run anywhere.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Phase 3: Strategic Analysis
|
|
174
|
+
|
|
175
|
+
### 3.1 Blue Ocean Four Actions Framework
|
|
176
|
+
|
|
177
|
+
| Action | Decision |
|
|
178
|
+
|--------|----------|
|
|
179
|
+
| **ELIMINATE** | Hardcoded bash grep patterns in agent (replace with language-aware regex engine) |
|
|
180
|
+
| **REDUCE** | Template rigidity — allow agents to expand sections organically while maintaining structure |
|
|
181
|
+
| **RAISE** | Relationship awareness — from zero to module dependency graphs with circular dep detection |
|
|
182
|
+
| **CREATE** | Best practices detection, cross-document references, dead export identification, entry point heuristics |
|
|
183
|
+
|
|
184
|
+
### 3.2 Wardley Evolution Assessment
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
Genesis ──── Custom-Built ──── Product ──── Commodity
|
|
188
|
+
↑ ↑
|
|
189
|
+
Codebase mapping Aider repo-map
|
|
190
|
+
with relationships (AST-based)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Codebase analysis is moving from Custom-Built toward Product. Aider's tree-sitter approach is the most productized. PAN v2 targets the Custom-Built→Product boundary: more structured than Aider's flat map, less dependent than Cursor's embeddings.
|
|
194
|
+
|
|
195
|
+
### 3.3 Strategic Moat Analysis
|
|
196
|
+
|
|
197
|
+
| Moat Type | Contribution | Score (0-5) |
|
|
198
|
+
|-----------|-------------|-------------|
|
|
199
|
+
| **Context Engineering** | Structured docs feed directly into plan-phase/exec-phase — no other tool does this | 5 |
|
|
200
|
+
| **Cross-Platform** | Works on all 5 AI runtimes + all 3 OS | 5 |
|
|
201
|
+
| **Developer Experience** | One command → 9 rich documents | 4 |
|
|
202
|
+
| **Zero Dependencies** | Regex-based analysis, no tree-sitter/embeddings needed | 5 |
|
|
203
|
+
| **State Persistence** | Codebase docs persist across sessions, consumed by all PAN commands | 4 |
|
|
204
|
+
| **Verification Quality** | Drift-check can validate conventions discovered by mapper | 3 |
|
|
205
|
+
| **Total** | | **26/30** |
|
|
206
|
+
|
|
207
|
+
### 3.4 Strategic Recommendation
|
|
208
|
+
|
|
209
|
+
**Build.** The codebase mapper is PAN's first impression for brownfield projects — the gateway command that determines whether users trust PAN with their existing codebase. The current shallow analysis (bash grep with hardcoded patterns) undermines this trust. The v2 redesign with language-aware import analysis, dependency graphs, and best-practices detection addresses the user's exact pain ("half baked for importing codebases") while maintaining PAN's zero-dependency constraint through regex-only analysis. Our unique angle: no other tool produces structured, prescriptive, cross-referenced analysis that feeds directly into an AI-driven planning and execution pipeline. We explicitly do NOT copy Aider's tree-sitter approach (adds runtime dep) or Cursor's embeddings (opaque, accuracy issues).
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Phase 3.5: Architecture & Implementation Assessment
|
|
214
|
+
|
|
215
|
+
### 3.5.1 Feature Type Classification
|
|
216
|
+
|
|
217
|
+
| Type | Description |
|
|
218
|
+
|------|-------------|
|
|
219
|
+
| **Agent rewrite** | `pan-document_code.md` rewritten with 6 focus areas (was 4), language-aware scanning |
|
|
220
|
+
| **Template expansion** | 9 templates (was 7), all lowercase filenames |
|
|
221
|
+
| **Workflow update** | `map-codebase.md` spawns 6 agents (was 4) |
|
|
222
|
+
| **Core enhancement** | `init.cjs:cmdInitMapCodebase()` enhanced with new config |
|
|
223
|
+
| **New core module** | `codebase.cjs` — language-aware import parser, dependency graph builder |
|
|
224
|
+
|
|
225
|
+
### 3.5.2 Layer Violation Check
|
|
226
|
+
|
|
227
|
+
- [x] Command .md files invoke pan-tools CLI, not core modules directly
|
|
228
|
+
- [x] Core modules return data, not import agent .md files
|
|
229
|
+
- [x] New `codebase.cjs` module only used by mapper agent via pan-tools CLI
|
|
230
|
+
- [x] No upward dependencies
|
|
231
|
+
|
|
232
|
+
### 3.5.3 Output Contract Design
|
|
233
|
+
|
|
234
|
+
**`init map-codebase` enhanced output:**
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"mapper_model": "string — model for mapper agents",
|
|
238
|
+
"commit_docs": "boolean — auto-commit after mapping",
|
|
239
|
+
"search_gitignored": "boolean",
|
|
240
|
+
"parallelization": "string — agent parallelization mode",
|
|
241
|
+
"codebase_dir": "string — relative path to .planning/codebase/",
|
|
242
|
+
"existing_maps": ["string[] — existing .md filenames"],
|
|
243
|
+
"has_maps": "boolean",
|
|
244
|
+
"planning_exists": "boolean",
|
|
245
|
+
"codebase_dir_exists": "boolean",
|
|
246
|
+
"supported_languages": ["string[] — detected languages in codebase"],
|
|
247
|
+
"file_count": "number — total source files detected",
|
|
248
|
+
"focus_areas": ["string[] — 6 focus area names"]
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**New `codebase analyze-imports` command output:**
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"language": "string — detected primary language",
|
|
256
|
+
"modules": "number — total modules analyzed",
|
|
257
|
+
"imports": "number — total import statements found",
|
|
258
|
+
"exports": "number — total export statements found",
|
|
259
|
+
"circular_deps": ["string[] — circular dependency chains"],
|
|
260
|
+
"entry_points": ["string[] — detected entry point files"],
|
|
261
|
+
"orphan_modules": ["string[] — files with exports but no importers"],
|
|
262
|
+
"dependency_graph": "string — Mermaid graph source"
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 3.5.4 Breaking Change Assessment
|
|
267
|
+
|
|
268
|
+
| Question | Answer |
|
|
269
|
+
|----------|--------|
|
|
270
|
+
| Changes any existing command's JSON output schema? | Yes — `init map-codebase` adds 3 new fields (backward compatible, additive) |
|
|
271
|
+
| Changes file formats? | Yes — lowercase filenames. Migration: symlink or dual-check in consumers |
|
|
272
|
+
| Changes directory structure? | No — still `.planning/codebase/` |
|
|
273
|
+
| Changes installer output? | No |
|
|
274
|
+
|
|
275
|
+
**Migration strategy for lowercase filenames:**
|
|
276
|
+
1. New mapper writes lowercase files (stack.md, architecture.md, etc.)
|
|
277
|
+
2. All consumers (plan-phase, exec-phase, focus-design, research-phase) updated to check lowercase first, fallback to UPPERCASE
|
|
278
|
+
3. `init map-codebase` reports which naming convention is in use
|
|
279
|
+
4. No auto-rename of existing files — user runs `/pan:map-codebase` to regenerate
|
|
280
|
+
|
|
281
|
+
### 3.5.5 Performance Budget
|
|
282
|
+
|
|
283
|
+
| Operation | Cost | Notes |
|
|
284
|
+
|-----------|------|-------|
|
|
285
|
+
| File discovery (glob) | ~50ms | Walk source directories |
|
|
286
|
+
| Import parsing (6 languages) | ~200ms/1000 files | Regex-based, single-pass per file |
|
|
287
|
+
| Dependency graph construction | ~50ms | In-memory adjacency list |
|
|
288
|
+
| Circular dependency detection | ~20ms | DFS cycle detection |
|
|
289
|
+
| Mermaid generation | ~10ms | String concatenation |
|
|
290
|
+
| **Total (core analysis)** | **< 500ms for 5000 files** | |
|
|
291
|
+
| Agent execution (6 parallel) | ~30-60s | LLM-bound, not CPU-bound |
|
|
292
|
+
|
|
293
|
+
### 3.5.6 Cross-Platform Considerations
|
|
294
|
+
|
|
295
|
+
| Platform | Consideration |
|
|
296
|
+
|----------|---------------|
|
|
297
|
+
| Windows | `toPosix()` all paths, `path.join()` everywhere, no hardcoded `/` |
|
|
298
|
+
| All | Import regex handles both `require('x')` and `import x from 'x'` |
|
|
299
|
+
| All | File extension detection case-insensitive on Windows |
|
|
300
|
+
| All | Line endings: handle both `\n` and `\r\n` in parsing |
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Phase 4: Design Synthesis
|
|
305
|
+
|
|
306
|
+
### 4.1 Guide-Level Explanation
|
|
307
|
+
|
|
308
|
+
**Codebase Mapper v2** is the redesigned `/pan:map-codebase` command that produces a comprehensive analysis of your existing codebase. Instead of the previous 7 surface-level documents, v2 produces 9 deeply analyzed documents including module relationship maps and best-practices assessment.
|
|
309
|
+
|
|
310
|
+
**Example 1: Import a Node.js monorepo**
|
|
311
|
+
```
|
|
312
|
+
/pan:map-codebase
|
|
313
|
+
```
|
|
314
|
+
Produces `.planning/codebase/` with:
|
|
315
|
+
- `relationships.md` — Mermaid dependency graph showing which modules import which, circular dependency warnings, orphan module detection
|
|
316
|
+
- `best-practices.md` — Analysis of which patterns the codebase follows (error handling, testing, naming, security, performance) with prescriptive improvement guidance
|
|
317
|
+
- Plus 7 improved existing documents (stack, integrations, architecture, structure, conventions, testing, concerns)
|
|
318
|
+
|
|
319
|
+
**Example 2: Focus on a subsystem**
|
|
320
|
+
```
|
|
321
|
+
/pan:map-codebase api
|
|
322
|
+
```
|
|
323
|
+
Agents focus their analysis on the `api/` or API-related portions of the codebase.
|
|
324
|
+
|
|
325
|
+
**Example 3: Refresh after changes**
|
|
326
|
+
```
|
|
327
|
+
/pan:map-codebase
|
|
328
|
+
> .planning/codebase/ already exists with 9 documents
|
|
329
|
+
> 1. Refresh — remap entire codebase
|
|
330
|
+
> 2. Update — remap specific documents
|
|
331
|
+
> 3. Skip — use existing
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**What it does NOT do:**
|
|
335
|
+
- Does not use AST parsing or tree-sitter (zero runtime deps)
|
|
336
|
+
- Does not index or cache (always fresh analysis)
|
|
337
|
+
- Does not modify source code
|
|
338
|
+
- Does not require any specific language toolchain
|
|
339
|
+
|
|
340
|
+
### 4.2 Reference-Level Explanation
|
|
341
|
+
|
|
342
|
+
#### 4.2.1 New Module: `codebase.cjs`
|
|
343
|
+
|
|
344
|
+
Core analysis engine with these exported functions:
|
|
345
|
+
|
|
346
|
+
```
|
|
347
|
+
detectLanguages(cwd) → { primary, secondary, files_by_language }
|
|
348
|
+
parseImports(filePath, lang) → [{ source, specifiers, line, type }]
|
|
349
|
+
parseExports(filePath, lang) → [{ name, type, line, default }]
|
|
350
|
+
buildDependencyGraph(cwd) → { nodes, edges, adjacency }
|
|
351
|
+
findCircularDeps(graph) → [string[]] — each array is a cycle
|
|
352
|
+
findEntryPoints(cwd, graph) → string[] — files with no importers
|
|
353
|
+
findOrphanExports(cwd, graph) → string[] — exports never imported
|
|
354
|
+
generateMermaidGraph(graph) → string — Mermaid flowchart source
|
|
355
|
+
detectBestPractices(cwd) → { categories: [...], score, recommendations }
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Language-aware import regex patterns:**
|
|
359
|
+
|
|
360
|
+
| Language | Import Pattern | Export Pattern |
|
|
361
|
+
|----------|---------------|----------------|
|
|
362
|
+
| JS/TS | `require('...')`, `import ... from '...'`, `import('...')` | `module.exports`, `export default`, `export { }`, `export function` |
|
|
363
|
+
| Python | `import ...`, `from ... import ...` | Module-level functions/classes (heuristic) |
|
|
364
|
+
| Go | `import "..."`, `import (...)` | Capitalized identifiers (heuristic) |
|
|
365
|
+
| Rust | `use ...::...`, `mod ...` | `pub fn`, `pub struct`, `pub mod` |
|
|
366
|
+
| Java | `import ...;` | `public class`, `public interface` |
|
|
367
|
+
| C# | `using ...;` | `public class`, `public interface`, `namespace` |
|
|
368
|
+
|
|
369
|
+
#### 4.2.2 Six Focus Areas (was 4)
|
|
370
|
+
|
|
371
|
+
| Focus | Agent | Documents Produced |
|
|
372
|
+
|-------|-------|--------------------|
|
|
373
|
+
| **tech** | pan-document_code | `stack.md`, `integrations.md` |
|
|
374
|
+
| **arch** | pan-document_code | `architecture.md`, `structure.md` |
|
|
375
|
+
| **quality** | pan-document_code | `conventions.md`, `testing.md` |
|
|
376
|
+
| **concerns** | pan-document_code | `concerns.md` |
|
|
377
|
+
| **relationships** | pan-document_code | `relationships.md` |
|
|
378
|
+
| **practices** | pan-document_code | `best-practices.md` |
|
|
379
|
+
|
|
380
|
+
The `relationships` agent is bootstrapped with pre-computed dependency graph data from `codebase analyze-imports`, avoiding expensive re-scanning by the LLM.
|
|
381
|
+
|
|
382
|
+
The `practices` agent receives detected language info and scans for known patterns.
|
|
383
|
+
|
|
384
|
+
#### 4.2.3 New Document: `relationships.md`
|
|
385
|
+
|
|
386
|
+
```markdown
|
|
387
|
+
# Module Relationships
|
|
388
|
+
|
|
389
|
+
**Analysis Date:** YYYY-MM-DD
|
|
390
|
+
|
|
391
|
+
## Dependency Overview
|
|
392
|
+
|
|
393
|
+
**Total modules:** N
|
|
394
|
+
**Total import relationships:** N
|
|
395
|
+
**Circular dependencies:** N (list below)
|
|
396
|
+
**Orphan modules:** N (exported but never imported)
|
|
397
|
+
**Entry points:** N (imported by nothing, not exported)
|
|
398
|
+
|
|
399
|
+
## Module Dependency Graph
|
|
400
|
+
|
|
401
|
+
```mermaid
|
|
402
|
+
graph LR
|
|
403
|
+
A[module-a] --> B[module-b]
|
|
404
|
+
B --> C[module-c]
|
|
405
|
+
C --> A
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Circular Dependencies
|
|
409
|
+
|
|
410
|
+
**Cycle 1:** `a.js` → `b.js` → `c.js` → `a.js`
|
|
411
|
+
- Severity: High
|
|
412
|
+
- Fix approach: Extract shared code into `shared.js`
|
|
413
|
+
|
|
414
|
+
## High-Coupling Modules
|
|
415
|
+
|
|
416
|
+
| Module | Incoming | Outgoing | Total | Risk |
|
|
417
|
+
|--------|----------|----------|-------|------|
|
|
418
|
+
| `src/core.js` | 15 | 3 | 18 | Hub — changes here break many consumers |
|
|
419
|
+
|
|
420
|
+
## Orphan Modules
|
|
421
|
+
|
|
422
|
+
Files that export but are never imported (potential dead code):
|
|
423
|
+
- `src/utils/legacy.js` — exports `oldHelper()`, `deprecatedFormat()`
|
|
424
|
+
|
|
425
|
+
## Entry Points
|
|
426
|
+
|
|
427
|
+
Files that are imported by nothing (application roots):
|
|
428
|
+
- `src/index.js` — main entry
|
|
429
|
+
- `src/cli.js` — CLI entry
|
|
430
|
+
|
|
431
|
+
## Layer Violations
|
|
432
|
+
|
|
433
|
+
Imports that cross architectural boundaries:
|
|
434
|
+
- `src/ui/Button.tsx` imports `src/db/query.ts` — UI layer should not access DB layer directly
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
#### 4.2.4 New Document: `best-practices.md`
|
|
438
|
+
|
|
439
|
+
```markdown
|
|
440
|
+
# Best Practices Assessment
|
|
441
|
+
|
|
442
|
+
**Analysis Date:** YYYY-MM-DD
|
|
443
|
+
**Overall Score:** 7/10
|
|
444
|
+
|
|
445
|
+
## Categories
|
|
446
|
+
|
|
447
|
+
### Error Handling (8/10)
|
|
448
|
+
**Detected patterns:**
|
|
449
|
+
- Try-catch in async functions: 85% coverage
|
|
450
|
+
- Error types: Custom error classes used in `src/errors/`
|
|
451
|
+
- Unhandled promise rejections: 2 found
|
|
452
|
+
|
|
453
|
+
**Recommendations:**
|
|
454
|
+
- Add error boundary in `src/components/App.tsx`
|
|
455
|
+
- Wrap `src/api/client.ts` fetch calls in try-catch
|
|
456
|
+
|
|
457
|
+
### Testing (6/10)
|
|
458
|
+
**Detected patterns:**
|
|
459
|
+
- Test co-location: Tests in `__tests__/` directories
|
|
460
|
+
- Coverage: No coverage config found
|
|
461
|
+
- Test types: Unit only, no integration tests
|
|
462
|
+
|
|
463
|
+
**Recommendations:**
|
|
464
|
+
- Add vitest coverage config
|
|
465
|
+
- Create integration test suite for API routes
|
|
466
|
+
|
|
467
|
+
### Naming Conventions (9/10)
|
|
468
|
+
**Detected patterns:**
|
|
469
|
+
- Files: kebab-case.ts consistently
|
|
470
|
+
- Functions: camelCase consistently
|
|
471
|
+
- Components: PascalCase consistently
|
|
472
|
+
- Constants: UPPER_SNAKE_CASE
|
|
473
|
+
|
|
474
|
+
**Violations:**
|
|
475
|
+
- `src/utils/Helper.ts` — should be `helper.ts` (PascalCase file, not a component)
|
|
476
|
+
|
|
477
|
+
### Security (5/10)
|
|
478
|
+
**Detected patterns:**
|
|
479
|
+
- Input validation: Present in API routes
|
|
480
|
+
- SQL injection: Parameterized queries used
|
|
481
|
+
- XSS: No sanitization in `src/components/RichText.tsx`
|
|
482
|
+
- Secrets: `.env.example` exists, `.env` in `.gitignore`
|
|
483
|
+
|
|
484
|
+
**Recommendations:**
|
|
485
|
+
- Add DOMPurify for rich text rendering
|
|
486
|
+
- Audit `src/middleware/auth.ts` for timing attacks
|
|
487
|
+
|
|
488
|
+
### Performance (7/10)
|
|
489
|
+
**Detected patterns:**
|
|
490
|
+
- Memoization: `useMemo`/`useCallback` in 60% of components
|
|
491
|
+
- Lazy loading: `React.lazy()` for route components
|
|
492
|
+
- Bundle splitting: Vite config with manual chunks
|
|
493
|
+
|
|
494
|
+
**Recommendations:**
|
|
495
|
+
- Add `useMemo` to `src/components/DataGrid.tsx` (renders 1000+ rows)
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### 4.3 Design Decisions
|
|
499
|
+
|
|
500
|
+
| Decision | Rationale | What We Did NOT Copy |
|
|
501
|
+
|----------|-----------|---------------------|
|
|
502
|
+
| Regex-based import parsing (not AST) | Zero runtime deps, cross-platform, good enough for 90% of cases | Aider's tree-sitter WASM (adds ~5MB dep) |
|
|
503
|
+
| 6 focus areas with 6 parallel agents | Fresh context per domain, no token contamination | Cursor's monolithic embedding approach |
|
|
504
|
+
| Pre-compute dependency graph, pass to relationship agent | Avoids agent re-scanning thousands of files | DeepWiki's full-LLM analysis (expensive) |
|
|
505
|
+
| Lowercase filenames | User request + convention alignment (.planning/ files are lowercase) | N/A |
|
|
506
|
+
| Best practices as scored categories | Prescriptive, actionable, prioritized | Swark's diagram-only approach |
|
|
507
|
+
| Language detection heuristic (file extensions + package files) | Simple, fast, no external tools | Linguist/enry (adds dep) |
|
|
508
|
+
|
|
509
|
+
### 4.4 Drawbacks & Alternatives
|
|
510
|
+
|
|
511
|
+
| Decision | Chosen | Alternative | Why Not | Drawback |
|
|
512
|
+
|----------|--------|------------|---------|----------|
|
|
513
|
+
| Regex imports | Regex patterns per language | tree-sitter AST | Adds 5MB WASM runtime dep | Misses complex patterns (re-exports, dynamic imports) |
|
|
514
|
+
| 6 agents | 6 parallel agents | Single agent, 9 docs | Token contamination, slower | Higher token cost (6 agent spawns) |
|
|
515
|
+
| New codebase.cjs module | Dedicated module | Add to core.cjs | core.cjs already 400+ LOC | New file to maintain |
|
|
516
|
+
| Lowercase files | lowercase.md | Keep UPPERCASE.md | User explicitly requested lowercase | Migration period with dual naming |
|
|
517
|
+
|
|
518
|
+
### 4.5 Feature Ladder
|
|
519
|
+
|
|
520
|
+
| Version | Scope | Value Delivered | Effort |
|
|
521
|
+
|---------|-------|----------------|--------|
|
|
522
|
+
| **v0 (MVP)** | `codebase.cjs` with JS/TS import parsing + dependency graph + `relationships.md` template + `best-practices.md` template + lowercase filenames + 6 focus areas | Dependency graphs and best-practice assessment for JS/TS codebases | M (13 pts) |
|
|
523
|
+
| **v1 (Complete)** | Add Python, Go, Rust, Java, C# language support + circular dep detection + orphan detection + entry point heuristics + enhanced agent prompts | Full 6-language support with advanced analysis | M (10 pts) |
|
|
524
|
+
| **v2 (Enhanced)** | Layer violation detection, coupling metrics, change-impact analysis ("if I change X, what breaks?"), incremental refresh (only re-analyze changed files) | Architectural intelligence | L (15 pts) |
|
|
525
|
+
|
|
526
|
+
### 4.6 Adoption Analysis
|
|
527
|
+
|
|
528
|
+
| Question | Answer |
|
|
529
|
+
|----------|--------|
|
|
530
|
+
| How does the user discover this feature? | Same command: `/pan:map-codebase` — existing users get richer output automatically |
|
|
531
|
+
| What's the learning curve? | Zero — same invocation, richer output |
|
|
532
|
+
| Does it require changing existing workflows? | No — drop-in replacement |
|
|
533
|
+
| What's the "aha moment"? | Opening `relationships.md` and seeing a Mermaid dependency graph of your entire codebase with circular deps highlighted |
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## Phase 5: Architecture Decision Record
|
|
538
|
+
|
|
539
|
+
See `docs/decisions/ADR-0021-codebase-mapper-v2.md` (written as Phase 10 artifact).
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## Phase 6: Error Handling & Diagnostics Design
|
|
544
|
+
|
|
545
|
+
### 6.1 Failure Mode Analysis
|
|
546
|
+
|
|
547
|
+
| Failure Mode | Category | Detection | Recovery | User Sees |
|
|
548
|
+
|-------------|----------|-----------|----------|-----------|
|
|
549
|
+
| No source files found | User error | `detectLanguages()` returns empty | JSON error + hint | `{"error": "No source files found", "hint": "Ensure codebase has .js/.ts/.py/.go/.rs/.java/.cs files"}` |
|
|
550
|
+
| Import regex misparse | Analysis limit | Graceful skip (log warning in verbose) | Continue analysis, note in `relationships.md` | Slightly incomplete graph |
|
|
551
|
+
| Circular dep in stdlib imports | False positive | Filter known stdlib/node_modules paths | Exclude from results | Clean output |
|
|
552
|
+
| `.planning/codebase/` not writable | Environment | try-catch on mkdirSync | JSON error | `{"error": "Cannot create .planning/codebase/"}` |
|
|
553
|
+
| Agent timeout/failure | LLM issue | Agent returns no confirmation | Note failed focus area, continue | Partial mapping with clear report |
|
|
554
|
+
| Massive codebase (100k+ files) | Performance | File count check in init | Warn + suggest focus area filter | Warning in init output |
|
|
555
|
+
| Binary files in source dirs | Data | File size + null byte check | Skip binary files | Clean analysis |
|
|
556
|
+
|
|
557
|
+
### 6.2 Diagnostic Support
|
|
558
|
+
|
|
559
|
+
| Diagnostic | How | When |
|
|
560
|
+
|------------|-----|------|
|
|
561
|
+
| `codebase analyze-imports --verbose` | Shows per-file import details | Debugging import analysis |
|
|
562
|
+
| `init map-codebase` | Shows detected languages, file counts | Before running mapper |
|
|
563
|
+
| Agent confirmation output | Reports line counts per document | After mapping |
|
|
564
|
+
| `--files` flag on analyze-imports | Analyze specific files only | Debugging specific modules |
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
## Phase 7: Security & Threat Model
|
|
569
|
+
|
|
570
|
+
### 7.1 Asset & Attack Surface
|
|
571
|
+
|
|
572
|
+
| Asset | Accessed How | Trust Level |
|
|
573
|
+
|-------|-------------|-------------|
|
|
574
|
+
| Source code files | Read-only scan | User-controlled |
|
|
575
|
+
| `.planning/codebase/*.md` | Write (analysis output) | System-generated |
|
|
576
|
+
| Import/export data | Regex extraction from source | Derived from user code |
|
|
577
|
+
|
|
578
|
+
| Input Vector | Validation Required |
|
|
579
|
+
|-------------|-------------------|
|
|
580
|
+
| File paths (source files) | Must be within cwd, no `..` traversal |
|
|
581
|
+
| File content (parsed for imports) | No eval(), regex only, size limit (DRIFT_MAX_FILE_SIZE) |
|
|
582
|
+
| Language detection | Based on file extensions, not content execution |
|
|
583
|
+
|
|
584
|
+
### 7.2 Path Safety
|
|
585
|
+
|
|
586
|
+
- All file paths resolved relative to `cwd` via `path.resolve(cwd, filePath)`
|
|
587
|
+
- Verify resolved path starts with `path.resolve(cwd)`
|
|
588
|
+
- Skip files in `node_modules/`, `.git/`, `dist/`, `build/`
|
|
589
|
+
- Respect `.gitignore` unless `search_gitignored` config is true
|
|
590
|
+
- Output paths pass through `toPosix()`
|
|
591
|
+
|
|
592
|
+
### 7.3 Output Sanitization
|
|
593
|
+
|
|
594
|
+
- [x] No absolute filesystem paths in output
|
|
595
|
+
- [x] No environment variable values
|
|
596
|
+
- [x] No file content beyond import/export statements
|
|
597
|
+
- [x] Forbidden files list (`.env`, credentials, keys) respected by agents AND core module
|
|
598
|
+
- [x] Dependency graph shows module names only, not file content
|
|
599
|
+
|
|
600
|
+
### 7.4 Content Validation
|
|
601
|
+
|
|
602
|
+
- Import parsing uses regex only — never `eval()` or `Function()`
|
|
603
|
+
- File content read as UTF-8 text — binary files skipped (null byte detection)
|
|
604
|
+
- Maximum file size: 1MB (reuse `DRIFT_MAX_FILE_SIZE` constant)
|
|
605
|
+
- Maximum files per analysis: 50,000 (configurable, prevents OOM)
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Phase 8: Implementation Roadmap
|
|
610
|
+
|
|
611
|
+
### 8.1 v0 (MVP) Task Breakdown
|
|
612
|
+
|
|
613
|
+
#### Task 1: Create `codebase.cjs` core module
|
|
614
|
+
**Files:** `pan-wizard-core/bin/lib/codebase.cjs` (new)
|
|
615
|
+
**Scope:**
|
|
616
|
+
- `detectLanguages(cwd)` — scan file extensions, detect primary/secondary languages
|
|
617
|
+
- `parseImports(filePath, lang)` — regex-based import extraction for JS/TS (v0), extensible for other languages (v1)
|
|
618
|
+
- `parseExports(filePath, lang)` — regex-based export extraction for JS/TS (v0)
|
|
619
|
+
- `buildDependencyGraph(cwd)` — walk source files, parse imports, build adjacency list
|
|
620
|
+
- `findCircularDeps(graph)` — DFS cycle detection on adjacency list
|
|
621
|
+
- `findEntryPoints(cwd, graph)` — files with zero incoming edges
|
|
622
|
+
- `findOrphanExports(cwd, graph)` — exported symbols never imported anywhere
|
|
623
|
+
- `generateMermaidGraph(graph, maxNodes)` — render top-N modules as Mermaid LR flowchart
|
|
624
|
+
- `detectBestPractices(cwd)` — scan for 5 pattern categories: error handling, testing, naming, security, performance
|
|
625
|
+
**Estimate:** M (5 pts)
|
|
626
|
+
**Priority:** P1
|
|
627
|
+
|
|
628
|
+
#### Task 2: Add `codebase` CLI dispatcher routes
|
|
629
|
+
**Files:** `pan-wizard-core/bin/pan-tools.cjs`
|
|
630
|
+
**Scope:**
|
|
631
|
+
- `codebase analyze-imports` → `codebase.cmdAnalyzeImports(cwd, raw, args)`
|
|
632
|
+
- `codebase detect-languages` → `codebase.cmdDetectLanguages(cwd, raw)`
|
|
633
|
+
- `codebase best-practices` → `codebase.cmdBestPractices(cwd, raw)`
|
|
634
|
+
**Estimate:** XS (1 pt)
|
|
635
|
+
**Priority:** P1
|
|
636
|
+
|
|
637
|
+
#### Task 3: Create lowercase templates
|
|
638
|
+
**Files:** `pan-wizard-core/templates/codebase/relationships.md` (new), `pan-wizard-core/templates/codebase/best-practices.md` (new)
|
|
639
|
+
**Scope:**
|
|
640
|
+
- `relationships.md` template with dependency overview, Mermaid graph, circular deps, high-coupling, orphans, entry points, layer violations sections
|
|
641
|
+
- `best-practices.md` template with scored categories (error handling, testing, naming, security, performance), detected patterns, recommendations
|
|
642
|
+
**Estimate:** S (2 pts)
|
|
643
|
+
**Priority:** P1
|
|
644
|
+
|
|
645
|
+
#### Task 4: Enhance `init map-codebase`
|
|
646
|
+
**Files:** `pan-wizard-core/bin/lib/init.cjs`
|
|
647
|
+
**Scope:**
|
|
648
|
+
- Add `supported_languages`, `file_count`, `focus_areas` to output
|
|
649
|
+
- Call `detectLanguages(cwd)` for language detection
|
|
650
|
+
- Report 6 focus areas (was 4)
|
|
651
|
+
**Estimate:** XS (1 pt)
|
|
652
|
+
**Priority:** P1
|
|
653
|
+
|
|
654
|
+
#### Task 5: Rewrite mapper agent for 6 focus areas
|
|
655
|
+
**Files:** `agents/pan-document_code.md`
|
|
656
|
+
**Scope:**
|
|
657
|
+
- Add `relationships` focus: consume pre-computed graph data, write `relationships.md`
|
|
658
|
+
- Add `practices` focus: consume language detection, scan for patterns, write `best-practices.md`
|
|
659
|
+
- Update all existing focus areas to use lowercase filenames
|
|
660
|
+
- Replace hardcoded bash grep patterns with language-aware guidance
|
|
661
|
+
- Add `<files_to_read>` injection for pre-computed data (relationships agent receives graph JSON)
|
|
662
|
+
**Estimate:** S (3 pts)
|
|
663
|
+
**Priority:** P1
|
|
664
|
+
|
|
665
|
+
#### Task 6: Update orchestrator workflow
|
|
666
|
+
**Files:** `pan-wizard-core/workflows/map-codebase.md`
|
|
667
|
+
**Scope:**
|
|
668
|
+
- Spawn 6 agents (was 4): add `relationships` and `practices`
|
|
669
|
+
- Before spawning `relationships` agent: call `codebase analyze-imports`, pass result in agent prompt
|
|
670
|
+
- Before spawning `practices` agent: call `codebase detect-languages`, pass result in agent prompt
|
|
671
|
+
- Verify 9 documents (was 7)
|
|
672
|
+
- Update expected filenames to lowercase
|
|
673
|
+
**Estimate:** S (2 pts)
|
|
674
|
+
**Priority:** P1
|
|
675
|
+
|
|
676
|
+
#### Task 7: Update consumers for lowercase filenames
|
|
677
|
+
**Files:** Multiple workflow .md files, plan-phase, exec-phase, focus-design, research-phase
|
|
678
|
+
**Scope:**
|
|
679
|
+
- All codebase doc references: check lowercase first, fallback to UPPERCASE
|
|
680
|
+
- Helper function in workflow: `resolve_codebase_doc(name)` tries both
|
|
681
|
+
**Estimate:** S (2 pts)
|
|
682
|
+
**Priority:** P2
|
|
683
|
+
|
|
684
|
+
#### Task 8: Tests for codebase.cjs
|
|
685
|
+
**Files:** `tests/codebase.test.cjs` (new)
|
|
686
|
+
**Scope:**
|
|
687
|
+
- Unit tests for all exported functions
|
|
688
|
+
- Integration tests via `runPanTools('codebase analyze-imports', tmpDir)`
|
|
689
|
+
- Contract tests for output schemas
|
|
690
|
+
**Estimate:** M (5 pts)
|
|
691
|
+
**Priority:** P1
|
|
692
|
+
|
|
693
|
+
#### Task 9: Documentation updates
|
|
694
|
+
**Files:** `docs/CLI-REFERENCE.md`, `CHANGELOG.md`, `README.md`
|
|
695
|
+
**Scope:**
|
|
696
|
+
- Add `codebase` command family to CLI reference
|
|
697
|
+
- Update map-codebase description
|
|
698
|
+
- Changelog entry
|
|
699
|
+
**Estimate:** XS (1 pt)
|
|
700
|
+
**Priority:** P3
|
|
701
|
+
|
|
702
|
+
### 8.2 Dependency Graph
|
|
703
|
+
|
|
704
|
+
```
|
|
705
|
+
Task 1 (codebase.cjs core module)
|
|
706
|
+
├─→ Task 2 (CLI dispatcher)
|
|
707
|
+
├─→ Task 4 (init enhancement)
|
|
708
|
+
├─→ Task 8 (tests)
|
|
709
|
+
└─→ Task 5 (agent rewrite) + Task 6 (workflow update)
|
|
710
|
+
└─→ Task 7 (consumer updates)
|
|
711
|
+
|
|
712
|
+
Task 3 (templates) — independent, parallel with Task 1
|
|
713
|
+
|
|
714
|
+
Task 9 (docs) — after all others
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
### 8.3 Recommended Execution Waves
|
|
718
|
+
|
|
719
|
+
#### Wave 1: Foundation (parallel) — 8 pts
|
|
720
|
+
| # | Task | Effort |
|
|
721
|
+
|---|------|--------|
|
|
722
|
+
| 1 | `codebase.cjs` core module | M (5) |
|
|
723
|
+
| 3 | New templates (relationships.md, best-practices.md) | S (2) |
|
|
724
|
+
| 4 | Enhanced `init map-codebase` | XS (1) |
|
|
725
|
+
|
|
726
|
+
#### Wave 2: Integration — 6 pts
|
|
727
|
+
| # | Task | Effort |
|
|
728
|
+
|---|------|--------|
|
|
729
|
+
| 2 | CLI dispatcher routes | XS (1) |
|
|
730
|
+
| 5 | Mapper agent rewrite | S (3) |
|
|
731
|
+
| 6 | Workflow update | S (2) |
|
|
732
|
+
|
|
733
|
+
#### Wave 3: Consumers + Tests — 7 pts
|
|
734
|
+
| # | Task | Effort |
|
|
735
|
+
|---|------|--------|
|
|
736
|
+
| 7 | Consumer lowercase fallback | S (2) |
|
|
737
|
+
| 8 | Test suite | M (5) |
|
|
738
|
+
|
|
739
|
+
#### Wave 4: Docs — 1 pt
|
|
740
|
+
| # | Task | Effort |
|
|
741
|
+
|---|------|--------|
|
|
742
|
+
| 9 | Documentation | XS (1) |
|
|
743
|
+
|
|
744
|
+
### 8.4 Risk Register
|
|
745
|
+
|
|
746
|
+
| Risk | Probability | Impact | Mitigation |
|
|
747
|
+
|------|------------|--------|------------|
|
|
748
|
+
| Regex misses complex import patterns (re-exports, barrel files) | Medium | Low | Document known limitations, iterate in v1 |
|
|
749
|
+
| Agent generates poor-quality relationships.md from pre-computed data | Medium | Medium | Rich prompt with examples, pre-computed graph gives agent a head start |
|
|
750
|
+
| Lowercase filename migration breaks existing projects | Low | High | Dual-check (lowercase then UPPERCASE) in all consumers |
|
|
751
|
+
| Performance on very large codebases (100k+ files) | Low | Medium | File count warning in init, configurable max |
|
|
752
|
+
| 6 agents hit rate limits | Low | Medium | Agent spawning already handles retries |
|
|
753
|
+
|
|
754
|
+
### 8.5 Cognitive Complexity Budget
|
|
755
|
+
|
|
756
|
+
All new functions in `codebase.cjs`:
|
|
757
|
+
- Max 50 lines per function
|
|
758
|
+
- Max 3 nesting levels
|
|
759
|
+
- Max 4 parameters (use options object for `buildDependencyGraph`)
|
|
760
|
+
- `parseImports()` uses a pattern registry (object of lang → regex[]) not nested if/else
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
764
|
+
## Phase 9: Test Plan
|
|
765
|
+
|
|
766
|
+
### 9.1 Test Pyramid
|
|
767
|
+
|
|
768
|
+
| Level | Count | What It Catches |
|
|
769
|
+
|-------|-------|-----------------|
|
|
770
|
+
| **Unit** | 25+ | Import parsing accuracy, graph algorithms, language detection, best-practices patterns |
|
|
771
|
+
| **Integration** | 10+ | CLI dispatch, JSON output shape, end-to-end codebase analysis |
|
|
772
|
+
| **E2E** | 3+ | Full map-codebase workflow with 6 agents, document verification |
|
|
773
|
+
|
|
774
|
+
### 9.2 Unit Test Plan for `codebase.cjs`
|
|
775
|
+
|
|
776
|
+
**detectLanguages (4 tests):**
|
|
777
|
+
- JS/TS project (has package.json, .ts files) → primary: "typescript"
|
|
778
|
+
- Python project (has requirements.txt, .py files) → primary: "python"
|
|
779
|
+
- Mixed project → primary + secondary
|
|
780
|
+
- Empty directory → `{ primary: null, secondary: [], files_by_language: {} }`
|
|
781
|
+
|
|
782
|
+
**parseImports — JS/TS (8 tests):**
|
|
783
|
+
- `require('fs')` → `{ source: 'fs', type: 'require' }`
|
|
784
|
+
- `import x from './module'` → `{ source: './module', type: 'esm' }`
|
|
785
|
+
- `import { a, b } from 'pkg'` → `{ source: 'pkg', type: 'esm' }`
|
|
786
|
+
- `import('./lazy')` → `{ source: './lazy', type: 'dynamic' }`
|
|
787
|
+
- `const x = require('./local')` → `{ source: './local', type: 'require' }`
|
|
788
|
+
- Multi-line imports → parsed correctly
|
|
789
|
+
- Comments containing import → ignored
|
|
790
|
+
- String containing import → ignored
|
|
791
|
+
|
|
792
|
+
**parseExports — JS/TS (5 tests):**
|
|
793
|
+
- `module.exports = { fn }` → `[{ name: 'fn', type: 'cjs' }]`
|
|
794
|
+
- `export default class Foo` → `[{ name: 'Foo', type: 'esm', default: true }]`
|
|
795
|
+
- `export function bar()` → `[{ name: 'bar', type: 'esm' }]`
|
|
796
|
+
- `export { a, b }` → 2 exports
|
|
797
|
+
- No exports → `[]`
|
|
798
|
+
|
|
799
|
+
**buildDependencyGraph (4 tests):**
|
|
800
|
+
- Simple A→B→C chain → correct adjacency
|
|
801
|
+
- Self-import → ignored
|
|
802
|
+
- Node_modules import → excluded from graph
|
|
803
|
+
- Relative imports resolved to actual files
|
|
804
|
+
|
|
805
|
+
**findCircularDeps (3 tests):**
|
|
806
|
+
- No cycles → `[]`
|
|
807
|
+
- A→B→A cycle → `[['A', 'B', 'A']]`
|
|
808
|
+
- Complex graph with multiple cycles → all detected
|
|
809
|
+
|
|
810
|
+
**findEntryPoints (2 tests):**
|
|
811
|
+
- File with no importers → included
|
|
812
|
+
- File imported by others → excluded
|
|
813
|
+
|
|
814
|
+
**findOrphanExports (2 tests):**
|
|
815
|
+
- Export never imported → included
|
|
816
|
+
- Export imported elsewhere → excluded
|
|
817
|
+
|
|
818
|
+
**generateMermaidGraph (3 tests):**
|
|
819
|
+
- Small graph → valid Mermaid syntax
|
|
820
|
+
- Empty graph → `"graph LR\n (no modules found)"`
|
|
821
|
+
- Large graph (>15 nodes) → truncated with note
|
|
822
|
+
|
|
823
|
+
**detectBestPractices (4 tests):**
|
|
824
|
+
- Codebase with try-catch → error handling score > 0
|
|
825
|
+
- Codebase with test files → testing score > 0
|
|
826
|
+
- Codebase with consistent naming → naming score > 0
|
|
827
|
+
- Empty codebase → all scores 0
|
|
828
|
+
|
|
829
|
+
### 9.3 Integration Test Plan
|
|
830
|
+
|
|
831
|
+
**CLI dispatch (3 tests):**
|
|
832
|
+
- `codebase analyze-imports` → valid JSON with expected fields
|
|
833
|
+
- `codebase detect-languages` → valid JSON with `primary` field
|
|
834
|
+
- `codebase best-practices` → valid JSON with `categories` array
|
|
835
|
+
|
|
836
|
+
**Contract tests (3 tests):**
|
|
837
|
+
- `codebase analyze-imports` schema validation
|
|
838
|
+
- `codebase detect-languages` schema validation
|
|
839
|
+
- `codebase best-practices` schema validation
|
|
840
|
+
|
|
841
|
+
**init map-codebase enhanced (2 tests):**
|
|
842
|
+
- Returns new fields: `supported_languages`, `file_count`, `focus_areas`
|
|
843
|
+
- `focus_areas` has 6 entries
|
|
844
|
+
|
|
845
|
+
**Lowercase filename (2 tests):**
|
|
846
|
+
- New mapping writes lowercase files
|
|
847
|
+
- Consumer finds lowercase file when UPPERCASE doesn't exist
|
|
848
|
+
|
|
849
|
+
### 9.4 Boundary Value Analysis
|
|
850
|
+
|
|
851
|
+
- [x] Empty codebase (zero source files)
|
|
852
|
+
- [x] Single file codebase
|
|
853
|
+
- [x] Codebase with only node_modules (no user code)
|
|
854
|
+
- [x] File with 1000+ imports (stress test)
|
|
855
|
+
- [x] Circular dependency chain of length 10+
|
|
856
|
+
- [x] Binary file mixed with source files
|
|
857
|
+
- [x] File paths with spaces and special characters
|
|
858
|
+
- [x] Windows-style paths (backslashes)
|
|
859
|
+
- [x] Symlinked directories
|
|
860
|
+
- [x] File larger than DRIFT_MAX_FILE_SIZE (skipped)
|
|
861
|
+
|
|
862
|
+
### 9.5 Regression Verification
|
|
863
|
+
|
|
864
|
+
After implementing, verify:
|
|
865
|
+
- [x] `npm test` — ALL existing tests pass unchanged
|
|
866
|
+
- [x] `tests/init.test.cjs` — init map-codebase tests still pass
|
|
867
|
+
- [x] Existing codebase mapper workflow still works (backward compatible)
|
|
868
|
+
- [x] All consumers that read codebase docs still function with UPPERCASE files
|
|
869
|
+
|
|
870
|
+
---
|
|
871
|
+
|
|
872
|
+
## Phase 10: Output Artifacts
|
|
873
|
+
|
|
874
|
+
### 10.1 Specification Document
|
|
875
|
+
Written to: `docs/specs/codebase_mapper_v2_featureai.md` (this file)
|
|
876
|
+
|
|
877
|
+
### 10.2 ADR
|
|
878
|
+
Written to: `docs/decisions/ADR-0021-codebase-mapper-v2.md`
|
|
879
|
+
|
|
880
|
+
### 10.3 Report Summary
|
|
881
|
+
|
|
882
|
+
## /featureAI Complete — Codebase Mapper v2
|
|
883
|
+
|
|
884
|
+
### Problem & Evidence
|
|
885
|
+
Shallow codebase analysis ("half baked for importing codebases") — lacks relationship maps, dependency graphs, best-practices detection. Evidence: user pain, Aider/DeepWiki feature parity, Swark competition.
|
|
886
|
+
|
|
887
|
+
### Strategic Assessment
|
|
888
|
+
- Blue Ocean: Eliminate hardcoded grep, Reduce template rigidity, Raise relationship awareness, Create best-practices detection + dependency graphs
|
|
889
|
+
- Wardley: Custom-Built → Product boundary
|
|
890
|
+
- Moat Score: 26/30 — strongest in Context Engineering (5) + Zero Dependencies (5) + Cross-Platform (5)
|
|
891
|
+
- Cognitive Load: neutral (0) — same command, richer output
|
|
892
|
+
- Recommendation: BUILD — gateway command for brownfield projects, must be best-in-class
|
|
893
|
+
|
|
894
|
+
### Design Summary
|
|
895
|
+
- Feature Type: Agent rewrite + New core module + Template expansion + Workflow update
|
|
896
|
+
- Modules Affected: `codebase.cjs` (new), `init.cjs`, `pan-tools.cjs`, `pan-document_code.md`, `map-codebase.md` (workflow)
|
|
897
|
+
- Output Schema: 3 new commands (`codebase analyze-imports`, `detect-languages`, `best-practices`)
|
|
898
|
+
- Error Handling: Graceful degradation (skip unparseable files, continue analysis)
|
|
899
|
+
- Breaking Changes: Lowercase filenames (migration: dual-check in consumers)
|
|
900
|
+
- Layer Violations: None
|
|
901
|
+
|
|
902
|
+
### Feature Ladder
|
|
903
|
+
- v0 (MVP): JS/TS import analysis + dependency graph + best-practices + lowercase filenames + 6 agents — M (22 pts)
|
|
904
|
+
- v1 (Complete): 6-language support + circular dep detection + orphan detection — M (10 pts)
|
|
905
|
+
- v2 (Enhanced): Layer violation detection, coupling metrics, change-impact analysis — L (15 pts)
|
|
906
|
+
|
|
907
|
+
### Implementation
|
|
908
|
+
- Tasks: 9 tasks across 4 waves
|
|
909
|
+
- Complexity: M (22 total points for v0)
|
|
910
|
+
- Files to create: 3 (`codebase.cjs`, `relationships.md` template, `best-practices.md` template)
|
|
911
|
+
- Files to modify: 6 (`init.cjs`, `pan-tools.cjs`, `pan-document_code.md`, `map-codebase.md` workflow, consumer workflows, `map-codebase.md` command)
|
|
912
|
+
- Tests planned: 38+ (unit: 25+, integration: 10+, e2e: 3+)
|
|
913
|
+
|
|
914
|
+
### Security
|
|
915
|
+
- Attack surface: Read-only source file scanning, regex-only parsing, no eval()
|
|
916
|
+
- Path safety: All paths resolved within cwd, toPosix() on output
|
|
917
|
+
- Output sanitization: No absolute paths, no file content beyond import statements
|
|
918
|
+
|
|
919
|
+
### Adoption
|
|
920
|
+
- Discovery: Same `/pan:map-codebase` command — automatic upgrade
|
|
921
|
+
- Learning curve: Zero (drop-in replacement)
|
|
922
|
+
- Aha moment: Opening `relationships.md` and seeing a Mermaid dependency graph with circular deps
|
|
923
|
+
|
|
924
|
+
### Documents Created
|
|
925
|
+
- Spec: `docs/specs/codebase_mapper_v2_featureai.md`
|
|
926
|
+
- ADR: `docs/decisions/ADR-0021-codebase-mapper-v2.md`
|
|
927
|
+
|
|
928
|
+
### Next Step
|
|
929
|
+
Add to superplan: `/pan:focus-scan`
|
|
930
|
+
Execute: `/pan:focus-exec`
|