Loading...
Loading...
Orchestrates parallel KB generation using spatial analysis and a map-reduce architecture with incremental update support.
npx skill4agent add rp1-run/rp1 knowledge-build| Parameter | Required | Default | Description |
|---|---|---|---|
| No | - | Feature ID to incorporate learnings from an archived feature into KB |
RP1_ROOTrp1 agent-tools rp1-root-dirdata.rootPhase 1 (Sequential): Spatial Analyzer -> Categorized file lists
Phase 2 (Parallel): 4 Analysis Agents -> JSON outputs (concept, arch, module, pattern)
Phase 3 (Sequential): Command -> Merge JSON -> Generate index.md -> Write KB filesFEATURE_IDFEATURE_PATH = {{$RP1_ROOT}}/work/archives/features/{FEATURE_ID}/FEATURE_PATH = {{$RP1_ROOT}}/work/features/{FEATURE_ID}/Feature not found: {FEATURE_ID}
Checked: {{$RP1_ROOT}}/work/archives/features/{FEATURE_ID}/
{{$RP1_ROOT}}/work/features/{FEATURE_ID}/{FEATURE_PATH}/requirements.md{FEATURE_PATH}/design.md{FEATURE_PATH}/field-notes.md{FEATURE_PATH}/tasks.mdFILES_MODIFIEDLook for patterns:
- **Files**: `src/file1.ts`, `src/file2.ts`
- **Files Modified**: ...
Extract all file paths into FILES_MODIFIED array.FEATURE_CONTEXTfiles_modifiedFILES_MODIFIEDFEATURE_LEARNING mode. Categorize these files modified during feature implementation:
FILES: {{stringify(FILES_MODIFIED)}}
Rank each file 0-5, categorize by KB section (index_files, concept_files, arch_files, module_files).
Return JSON with categorized files.FEATURE_CONTEXT: {{stringify(feature_context)}}
MODE: FEATURE_LEARNING
Incorporate learnings from this completed feature:
- Update patterns.md with implementation patterns discovered
- Update architecture.md if new architectural patterns emerged
- Update modules.md with new components/dependencies
- Update concept_map.md with new domain concepts
Focus on files that were modified: {{stringify(FILES_MODIFIED)}}{{$RP1_ROOT}}/context/state.jsongit_commitgit rev-parse HEADgit_commit# Read shareable state
repo_type=$(jq -r '.repo_type // "single-project"' {{$RP1_ROOT}}/context/state.json)
# Read local values from meta.json (with fallback to state.json for backward compatibility)
if [ -f "{{$RP1_ROOT}}/context/meta.json" ]; then
repo_root=$(jq -r '.repo_root // "."' {{$RP1_ROOT}}/context/meta.json)
current_project_path=$(jq -r '.current_project_path // "."' {{$RP1_ROOT}}/context/meta.json)
else
# Backward compatibility: read from state.json if meta.json doesn't exist
repo_root=$(jq -r '.repo_root // "."' {{$RP1_ROOT}}/context/state.json)
current_project_path=$(jq -r '.current_project_path // "."' {{$RP1_ROOT}}/context/state.json)
fi# If monorepo, run git diff from repo root and filter to current project
if [ "$repo_type" = "monorepo" ]; then
cd "$repo_root"
# Get all changed files
all_changes=$(git diff --name-only {{old_commit}} {{new_commit}})
# Filter to current project (skip filtering if root project)
if [ "$current_project_path" = "." ] || [ "$current_project_path" = "" ]; then
# Root project - include all files
echo "$all_changes"
else
# Subdirectory project - filter to project path
echo "$all_changes" | grep "^${current_project_path}"
fi
else
# Single-project - get all changes
git diff --name-only {{old_commit}} {{new_commit}}
fichanged_file_count=$(echo "$changed_files" | wc -l)
if [ $changed_file_count -gt 50 ]; then
echo "Large change set ($changed_file_count files changed). Using FULL mode for reliability."
# Fall back to FULL mode (skip getting diffs)
MODE="FULL"
else
MODE="INCREMENTAL"
fi# Only if incremental mode (< 50 files)
git diff {{old_commit}} {{new_commit}} -- <filepath>Use Task tool with:
subagent_type: rp1-base:kb-spatial-analyzer
prompt: "FULL SCAN mode. Scan all files in repository at {{CODEBASE_ROOT}}, rank files 0-5, categorize by KB section. Return JSON with index_files, concept_files, arch_files, module_files arrays."Use Task tool with:
subagent_type: rp1-base:kb-spatial-analyzer
prompt: "INCREMENTAL mode. Only categorize these changed files: {{changed_files_list}}. Rank each file 0-5, categorize by KB section (index_files, concept_files, arch_files, module_files). Return JSON with categorized changed files."repo_typemonorepo_projectstotal_files_scannedindex_filesconcept_filesarch_filesmodule_fileslocal_metarepo_typemonorepo_projectslocal_metarepo_rootcurrent_project_pathUse Task tool with:
subagent_type: rp1-base:kb-concept-extractor
prompt: "MODE={{mode}}. Extract domain concepts for concept_map.md. Repository type: {{repo_type}}. Files to analyze (JSON): {{stringify(concept_files)}}. {{if mode==INCREMENTAL}}File diffs (JSON): {{stringify(file_diffs_for_concept_files)}}{{endif}}. Return JSON with concepts, terminology, relationships."Use Task tool with:
subagent_type: rp1-base:kb-architecture-mapper
prompt: "MODE={{mode}}. Map system architecture for architecture.md. Repository type: {{repo_type}}. Files to analyze (JSON): {{stringify(arch_files)}}. {{if mode==INCREMENTAL}}File diffs (JSON): {{stringify(file_diffs_for_arch_files)}}{{endif}}. Return JSON with patterns, layers, diagram."Use Task tool with:
subagent_type: rp1-base:kb-module-analyzer
prompt: "MODE={{mode}}. Analyze modules for modules.md. Repository type: {{repo_type}}. Files to analyze (JSON): {{stringify(module_files)}}. {{if mode==INCREMENTAL}}File diffs (JSON): {{stringify(file_diffs_for_module_files)}}{{endif}}. Return JSON with modules, components, dependencies."Use Task tool with:
subagent_type: rp1-base:kb-pattern-extractor
prompt: "MODE={{mode}}. Extract implementation patterns for patterns.md. Repository type: {{repo_type}}. Files to analyze (JSON): {{stringify(concept_files + module_files)}}. {{if mode==INCREMENTAL}}File diffs (JSON): {{stringify(file_diffs_for_pattern_files)}}{{endif}}. Return JSON with patterns (<=150 lines when rendered)."Use Skill tool with:
skill: rp1-base:knowledge-base-templatesUse Skill tool with:
skill: rp1-base:mermaidUse Write tool to write:
- {{$RP1_ROOT}}/context/index.md
- {{$RP1_ROOT}}/context/concept_map.md
- {{$RP1_ROOT}}/context/architecture.md
- {{$RP1_ROOT}}/context/modules.md
- {{$RP1_ROOT}}/context/patterns.md{
"strategy": "parallel-map-reduce",
"repo_type": "{{repo_type}}",
"monorepo_projects": ["{{project1}}", "{{project2}}"],
"generated_at": "{{ISO timestamp}}",
"git_commit": "{{git rev-parse HEAD}}",
"files_analyzed": {{total_files}},
"languages": ["{{lang1}}", "{{lang2}}"],
"metrics": {
"modules": {{module_count}},
"components": {{component_count}},
"concepts": {{concept_count}}
}
}{
"repo_root": "{{repo_root}}",
"current_project_path": "{{current_project_path}}"
}meta.json.gitignoreUse Write tool to write:
- {{$RP1_ROOT}}/context/state.json
- {{$RP1_ROOT}}/context/meta.jsonKnowledge Base Generated Successfully
Strategy: Parallel map-reduce
Repository: {{repo_type}}
Files Analyzed: {{total_files}}
KB Files Written:
- {{$RP1_ROOT}}/context/index.md
- {{$RP1_ROOT}}/context/concept_map.md
- {{$RP1_ROOT}}/context/architecture.md
- {{$RP1_ROOT}}/context/modules.md
- {{$RP1_ROOT}}/context/patterns.md
- {{$RP1_ROOT}}/context/state.json (shareable metadata)
- {{$RP1_ROOT}}/context/meta.json (local paths - add to .gitignore)
Next steps:
- KB is automatically loaded by agents when needed (no manual /knowledge-load required)
- Subsequent runs will use same parallel approach (10-15 min)
- Incremental updates (changed files only) are faster (2-5 min)
- Add meta.json to .gitignore to prevent sharing local pathsFeature Learnings Captured
Feature: {{FEATURE_ID}}
Source: {{FEATURE_PATH}}
Learnings Incorporated:
- patterns.md: {{N}} new patterns from implementation
- architecture.md: {{N}} architectural decisions
- modules.md: {{N}} new components/dependencies
- concept_map.md: {{N}} domain concepts
KB Files Updated:
- {{$RP1_ROOT}}/context/index.md
- {{$RP1_ROOT}}/context/concept_map.md
- {{$RP1_ROOT}}/context/architecture.md
- {{$RP1_ROOT}}/context/modules.md
- {{$RP1_ROOT}}/context/patterns.md
The knowledge from feature "{{FEATURE_ID}}" has been captured into the KB.
Future agents will benefit from these learnings.| Parameter | Default | Purpose |
|---|---|---|
| RP1_ROOT | | Root directory for KB artifacts |
| CODEBASE_ROOT | | Repository root to analyze |
| EXCLUDE_PATTERNS | | Patterns to exclude from scanning |
First-time KB generation with parallel analysis (10-15 min)
Analyzing... (Phase 2/5)
Knowledge Base Generated Successfully
[Final Report as shown above]Checking for state.json...
state.json not found, proceeding with first-time build
Running git rev-parse HEAD to get commit...
Commit is 475b03e...
Spawning kb-spatial-analyzer agent...
Parsing spatial analyzer output...
Found 90 files in index_files category...
Now spawning 4 parallel agents...
Spawning kb-concept-extractor...
Spawning kb-architecture-mapper...
Spawning kb-module-analyzer...
etc. (too verbose!)