agent-knowledge-cli 0.1.2__py3-none-any.whl
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.
- agent_knowledge/__init__.py +3 -0
- agent_knowledge/__main__.py +3 -0
- agent_knowledge/assets/__init__.py +0 -0
- agent_knowledge/assets/claude/global.md +44 -0
- agent_knowledge/assets/claude/project-template.md +46 -0
- agent_knowledge/assets/claude/scripts/install.sh +85 -0
- agent_knowledge/assets/commands/doctor.md +21 -0
- agent_knowledge/assets/commands/global-knowledge-sync.md +27 -0
- agent_knowledge/assets/commands/graphify-sync.md +26 -0
- agent_knowledge/assets/commands/knowledge-sync.md +26 -0
- agent_knowledge/assets/commands/ship.md +29 -0
- agent_knowledge/assets/rules/generate-architecture-doc.mdc +87 -0
- agent_knowledge/assets/rules/history-backfill.mdc +67 -0
- agent_knowledge/assets/rules/memory-bootstrap.mdc +53 -0
- agent_knowledge/assets/rules/memory-writeback.mdc +90 -0
- agent_knowledge/assets/rules/shared-memory.mdc +102 -0
- agent_knowledge/assets/rules/workflow-orchestration.mdc +93 -0
- agent_knowledge/assets/rules-global/action-first.mdc +26 -0
- agent_knowledge/assets/rules-global/no-icons-emojis.mdc +16 -0
- agent_knowledge/assets/rules-global/no-unsolicited-docs.mdc +20 -0
- agent_knowledge/assets/scripts/bootstrap-memory-tree.sh +389 -0
- agent_knowledge/assets/scripts/compact-memory.sh +191 -0
- agent_knowledge/assets/scripts/doctor.sh +137 -0
- agent_knowledge/assets/scripts/global-knowledge-sync.sh +372 -0
- agent_knowledge/assets/scripts/graphify-sync.sh +397 -0
- agent_knowledge/assets/scripts/import-agent-history.sh +706 -0
- agent_knowledge/assets/scripts/install-project-links.sh +258 -0
- agent_knowledge/assets/scripts/lib/knowledge-common.sh +875 -0
- agent_knowledge/assets/scripts/measure-token-savings.py +540 -0
- agent_knowledge/assets/scripts/ship.sh +256 -0
- agent_knowledge/assets/scripts/update-knowledge.sh +341 -0
- agent_knowledge/assets/scripts/validate-knowledge.sh +265 -0
- agent_knowledge/assets/skills/decision-recording/SKILL.md +124 -0
- agent_knowledge/assets/skills/history-backfill/SKILL.md +115 -0
- agent_knowledge/assets/skills/memory-compaction/SKILL.md +115 -0
- agent_knowledge/assets/skills/memory-management/SKILL.md +134 -0
- agent_knowledge/assets/skills/project-ontology-bootstrap/SKILL.md +173 -0
- agent_knowledge/assets/skills/session-management/SKILL.md +116 -0
- agent_knowledge/assets/skills-cursor/create-rule/SKILL.md +164 -0
- agent_knowledge/assets/skills-cursor/create-skill/SKILL.md +498 -0
- agent_knowledge/assets/skills-cursor/create-subagent/SKILL.md +225 -0
- agent_knowledge/assets/skills-cursor/migrate-to-skills/SKILL.md +134 -0
- agent_knowledge/assets/skills-cursor/shell/SKILL.md +24 -0
- agent_knowledge/assets/skills-cursor/update-cursor-settings/SKILL.md +122 -0
- agent_knowledge/assets/templates/dashboards/project-overview.template.md +24 -0
- agent_knowledge/assets/templates/dashboards/session-rollup.template.md +23 -0
- agent_knowledge/assets/templates/hooks/hooks.json.template +11 -0
- agent_knowledge/assets/templates/integrations/claude/CLAUDE.md +7 -0
- agent_knowledge/assets/templates/integrations/codex/AGENTS.md +7 -0
- agent_knowledge/assets/templates/integrations/cursor/agent-knowledge.mdc +11 -0
- agent_knowledge/assets/templates/integrations/cursor/hooks.json +11 -0
- agent_knowledge/assets/templates/memory/MEMORY.root.template.md +36 -0
- agent_knowledge/assets/templates/memory/branch.template.md +33 -0
- agent_knowledge/assets/templates/memory/decision.template.md +33 -0
- agent_knowledge/assets/templates/memory/profile.hybrid.yaml +16 -0
- agent_knowledge/assets/templates/memory/profile.ml-platform.yaml +18 -0
- agent_knowledge/assets/templates/memory/profile.robotics.yaml +19 -0
- agent_knowledge/assets/templates/memory/profile.web-app.yaml +16 -0
- agent_knowledge/assets/templates/portfolio/.obsidian/README.md +21 -0
- agent_knowledge/assets/templates/portfolio/.obsidian/app.json +5 -0
- agent_knowledge/assets/templates/portfolio/.obsidian/core-plugins.json +7 -0
- agent_knowledge/assets/templates/project/.agent-project.yaml +36 -0
- agent_knowledge/assets/templates/project/.agentknowledgeignore +10 -0
- agent_knowledge/assets/templates/project/AGENTS.md +87 -0
- agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/README.md +23 -0
- agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/app.json +5 -0
- agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/core-plugins.json +7 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Evidence/README.md +34 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Evidence/imports/README.md +29 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Evidence/raw/README.md +25 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Memory/MEMORY.md +37 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Memory/decisions/decisions.md +31 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Outputs/README.md +24 -0
- agent_knowledge/assets/templates/project/agent-knowledge/STATUS.md +43 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Sessions/README.md +21 -0
- agent_knowledge/assets/templates/project/agent-knowledge/Templates/README.md +19 -0
- agent_knowledge/assets/templates/project/gitignore.agent-knowledge +13 -0
- agent_knowledge/cli.py +457 -0
- agent_knowledge/runtime/__init__.py +0 -0
- agent_knowledge/runtime/integrations.py +154 -0
- agent_knowledge/runtime/paths.py +46 -0
- agent_knowledge/runtime/shell.py +22 -0
- agent_knowledge/runtime/sync.py +255 -0
- agent_knowledge_cli-0.1.2.dist-info/METADATA +155 -0
- agent_knowledge_cli-0.1.2.dist-info/RECORD +88 -0
- agent_knowledge_cli-0.1.2.dist-info/WHEEL +4 -0
- agent_knowledge_cli-0.1.2.dist-info/entry_points.txt +2 -0
- agent_knowledge_cli-0.1.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Keep the shared project memory file up to date across all AI agents.
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Shared Memory
|
|
7
|
+
|
|
8
|
+
This project stores persistent memory at `agent-knowledge/Memory/MEMORY.md`.
|
|
9
|
+
The repo-local `./agent-knowledge` path is the working entrypoint and should point to the real dedicated knowledge folder.
|
|
10
|
+
If Cursor project memory is used, `~/.cursor/projects/<project-id>/memory/` should point to `./agent-knowledge/Memory/` so all agents read and write the same curated files.
|
|
11
|
+
|
|
12
|
+
When the symlink is missing or broken, create it:
|
|
13
|
+
```bash
|
|
14
|
+
ln -s <workspace>/agent-knowledge/Memory ~/.cursor/projects/<project-id>/memory
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Tree structure
|
|
18
|
+
|
|
19
|
+
Memory is organized as a **tree** using the same-name branch convention.
|
|
20
|
+
Agents load only the branches relevant to their current task.
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
agent-knowledge/
|
|
24
|
+
Memory/
|
|
25
|
+
MEMORY.md <- root curated-memory index -- always loaded, max ~200 lines
|
|
26
|
+
<topic>.md <- flat branch note (no subtopics)
|
|
27
|
+
<topic>/
|
|
28
|
+
<topic>.md <- branch entry note (same name as folder)
|
|
29
|
+
<subtopic>.md <- leaf note beside the entry
|
|
30
|
+
decisions/
|
|
31
|
+
decisions.md <- decision log
|
|
32
|
+
Evidence/
|
|
33
|
+
raw/
|
|
34
|
+
imports/
|
|
35
|
+
Sessions/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Reading the tree
|
|
39
|
+
|
|
40
|
+
1. `Memory/MEMORY.md` is always loaded automatically. It is a concise index only -- no deep detail.
|
|
41
|
+
2. At session start, identify which branch(es) your task touches from the Branches section.
|
|
42
|
+
3. Read the relevant branch entry notes before starting work.
|
|
43
|
+
4. If the branch has subtopic files needed for your task, read those too.
|
|
44
|
+
5. Do not read branches unrelated to your task -- keep context lean.
|
|
45
|
+
|
|
46
|
+
### Writing to the tree
|
|
47
|
+
|
|
48
|
+
- **Memory/MEMORY.md**: short branch summaries with relative links. Keep it under 200 lines.
|
|
49
|
+
- **Branch entry note** (`<topic>.md` or `<topic>/<topic>.md`): stable facts for one focused domain.
|
|
50
|
+
- **Subtopic note** (`<topic>/<subtopic>.md`): created only when a branch note grows beyond ~150 lines.
|
|
51
|
+
- When adding a subtopic, replace the inline detail in the entry note with a link.
|
|
52
|
+
- **Each note must stay under ~150 lines.** Split if bigger.
|
|
53
|
+
- **Link related notes** with relative markdown links (e.g., `See [perception](perception/perception.md)`).
|
|
54
|
+
- **One branch = one functional domain.** Do NOT lump unrelated subsystems into one file.
|
|
55
|
+
|
|
56
|
+
### Example branch link in Memory/MEMORY.md
|
|
57
|
+
|
|
58
|
+
```markdown
|
|
59
|
+
## Branches
|
|
60
|
+
|
|
61
|
+
- [Perception](perception/perception.md) -- camera pipeline, YOLO detection, depth fusion
|
|
62
|
+
- [Stack](stack.md) -- Python 3.10, ROS2, colcon
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Example branch entry note
|
|
66
|
+
|
|
67
|
+
```markdown
|
|
68
|
+
# Perception
|
|
69
|
+
|
|
70
|
+
## Purpose
|
|
71
|
+
Camera data acquisition, object detection, and depth fusion pipeline.
|
|
72
|
+
|
|
73
|
+
## Current State
|
|
74
|
+
- YOLO v8 for detection, custom depth fusion node
|
|
75
|
+
- 30 Hz pipeline on Jetson Orin
|
|
76
|
+
|
|
77
|
+
## Decisions
|
|
78
|
+
- [2025-01-20-yolo-v8.md](decisions/2025-01-20-yolo-v8.md) -- chose YOLO v8 for latency
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## When to update
|
|
82
|
+
|
|
83
|
+
Update the tree when you learn:
|
|
84
|
+
- A new architectural decision or pattern
|
|
85
|
+
- A critical "gotcha" (DB state, build requirement, PATH issue, etc.)
|
|
86
|
+
- A customer-facing fact that changed
|
|
87
|
+
- A lesson from a mistake that should not be repeated
|
|
88
|
+
|
|
89
|
+
Do NOT save: in-progress task state, speculative plans, or anything already in git history.
|
|
90
|
+
|
|
91
|
+
## Format
|
|
92
|
+
|
|
93
|
+
Lead with the fact. For feedback/lessons: add a **Why:** line and a **How to apply:** line so future agents understand the context, not just the rule.
|
|
94
|
+
|
|
95
|
+
## Extensions
|
|
96
|
+
|
|
97
|
+
- **Bootstrap**: if `agent-knowledge/Memory/MEMORY.md` is missing, apply the `memory-bootstrap` rule before any other work.
|
|
98
|
+
- **Writeback**: after meaningful state changes, apply the `memory-writeback` rule.
|
|
99
|
+
- **Backfill**: when memory is sparse and the repo has history, apply the `history-backfill` rule.
|
|
100
|
+
- **Decisions**: record architecture decisions with the `decision-recording` skill.
|
|
101
|
+
- **Compaction**: when files grow large, apply the `memory-compaction` skill.
|
|
102
|
+
- **Evidence**: evidence lives in `agent-knowledge/Evidence/` -- never mix with curated memory.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Workflow orchestration, task management, and core engineering principles for AI-assisted development.
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow Orchestration
|
|
7
|
+
|
|
8
|
+
## 1. Plan First (Default)
|
|
9
|
+
|
|
10
|
+
- Enter plan mode for ANY non-trivial task (3+ steps or architectural decisions)
|
|
11
|
+
- If something goes sideways, STOP and re-plan immediately - do not keep pushing
|
|
12
|
+
- Use plan mode for verification steps, not just building
|
|
13
|
+
- Write detailed specs upfront to reduce ambiguity
|
|
14
|
+
|
|
15
|
+
## 2. Subagent Strategy
|
|
16
|
+
|
|
17
|
+
- Use subagents liberally to keep the main context window clean
|
|
18
|
+
- Offload research, exploration, and parallel analysis to subagents
|
|
19
|
+
- For complex problems, throw more compute at it via subagents
|
|
20
|
+
- One task per subagent for focused execution
|
|
21
|
+
|
|
22
|
+
## 3. Self-Improvement Loop
|
|
23
|
+
|
|
24
|
+
- After ANY correction from the user: update `tasks/lessons.md` with the pattern
|
|
25
|
+
- Write rules for yourself that prevent the same mistake
|
|
26
|
+
- Ruthlessly iterate on these lessons until mistake rate drops
|
|
27
|
+
- Review lessons at session start for relevant project
|
|
28
|
+
|
|
29
|
+
## 4. Verification Before Done
|
|
30
|
+
|
|
31
|
+
- Never mark a task complete without proving it works
|
|
32
|
+
- Diff behavior between main and your changes when relevant
|
|
33
|
+
- Ask yourself: "Would a staff engineer approve this?"
|
|
34
|
+
- Run tests, check logs, demonstrate correctness
|
|
35
|
+
|
|
36
|
+
## 5. Demand Elegance (Balanced)
|
|
37
|
+
|
|
38
|
+
- For non-trivial changes: pause and ask "is there a more elegant way?"
|
|
39
|
+
- If a fix feels hacky: "Knowing everything I know now, implement the elegant solution"
|
|
40
|
+
- Skip this for simple, obvious fixes - do not over-engineer
|
|
41
|
+
- Challenge your own work before presenting it
|
|
42
|
+
|
|
43
|
+
## 6. Autonomous Bug Fixing
|
|
44
|
+
|
|
45
|
+
- When given a bug report: just fix it. Do not ask for hand-holding
|
|
46
|
+
- Point at logs, errors, failing tests - then resolve them
|
|
47
|
+
- Zero context switching required from the user
|
|
48
|
+
- Go fix failing CI tests without being told how
|
|
49
|
+
|
|
50
|
+
## Task Management
|
|
51
|
+
|
|
52
|
+
1. **Plan First**: Write plan to `tasks/todo.md` with checkable items
|
|
53
|
+
2. **Verify Plan**: Check in before starting implementation
|
|
54
|
+
3. **Track Progress**: Mark items complete as you go
|
|
55
|
+
4. **Explain Changes**: High-level summary at each step
|
|
56
|
+
5. **Document Results**: Add review section to `tasks/todo.md`
|
|
57
|
+
6. **Capture Lessons**: Update `tasks/lessons.md` after corrections
|
|
58
|
+
|
|
59
|
+
## Core Principles
|
|
60
|
+
|
|
61
|
+
- **Simplicity First**: Make every change as simple as possible. Impact minimal code.
|
|
62
|
+
- **No Laziness**: Find root causes. No temporary fixes. Senior developer standards.
|
|
63
|
+
- **Minimal Impact**: Changes should only touch what is necessary. Avoid introducing bugs.
|
|
64
|
+
|
|
65
|
+
## Memory Flow
|
|
66
|
+
|
|
67
|
+
Session lifecycle includes memory at start and end:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
session start
|
|
71
|
+
├─ check memory-bootstrap rule (bootstrap if Memory/MEMORY.md missing or generic)
|
|
72
|
+
├─ read agent-knowledge/Memory/MEMORY.md and relevant branch notes
|
|
73
|
+
└─ read session-management skill
|
|
74
|
+
|
|
75
|
+
plan → execute → verify
|
|
76
|
+
└─ update session file at milestones
|
|
77
|
+
|
|
78
|
+
session end
|
|
79
|
+
├─ evaluate writeback: did this session produce durable knowledge?
|
|
80
|
+
├─ if yes: apply memory-writeback rule (branch notes + decisions/ as needed)
|
|
81
|
+
└─ if no: state "Memory writeback: none needed."
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For new or inherited projects, insert **history backfill** after bootstrap:
|
|
85
|
+
```
|
|
86
|
+
bootstrap → import-agent-history.sh → history-backfill skill → steady-state
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The required loop is:
|
|
90
|
+
1. Plan the work.
|
|
91
|
+
2. Execute the change.
|
|
92
|
+
3. Verify behavior.
|
|
93
|
+
4. Write back durable project understanding when needed.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Think deeply, act decisively, speak briefly - maximum intelligence with minimum verbal output
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Action-First Principle
|
|
7
|
+
|
|
8
|
+
THINK DEEPLY. ACT DECISIVELY. SPEAK BRIEFLY.
|
|
9
|
+
|
|
10
|
+
## Maximize
|
|
11
|
+
|
|
12
|
+
- Thinking depth, reasoning, and cognitive effort
|
|
13
|
+
- Code quality, correctness, and solution completeness
|
|
14
|
+
- Strategic planning and risk assessment
|
|
15
|
+
|
|
16
|
+
## Minimize
|
|
17
|
+
|
|
18
|
+
- Verbal responses and filler text
|
|
19
|
+
- Explanations, lists, and summaries (unless explicitly requested)
|
|
20
|
+
- Redundant descriptions and unnecessary elaboration
|
|
21
|
+
|
|
22
|
+
## Behavior
|
|
23
|
+
|
|
24
|
+
- Execute over explain -- let code and results speak
|
|
25
|
+
- Ask before irreversible or destructive actions
|
|
26
|
+
- Only provide detailed explanations when explicitly requested
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Prohibit use of icons and emojis in code, logs, and LLM output
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# No Icons or Emojis
|
|
7
|
+
|
|
8
|
+
Icons and emojis are NOT allowed in:
|
|
9
|
+
|
|
10
|
+
- Code
|
|
11
|
+
- Logs
|
|
12
|
+
- Skills
|
|
13
|
+
- Commands
|
|
14
|
+
- LLM output
|
|
15
|
+
|
|
16
|
+
Use plain text for all communication and code and files output.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Never create documentation files unless explicitly requested
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# No Unsolicited Documentation
|
|
7
|
+
|
|
8
|
+
NEVER create .md, README, or documentation files unless the user explicitly requests it.
|
|
9
|
+
|
|
10
|
+
This includes:
|
|
11
|
+
|
|
12
|
+
- README.md
|
|
13
|
+
- CHANGELOG.md
|
|
14
|
+
- CONTRIBUTING.md
|
|
15
|
+
- docs/ files
|
|
16
|
+
- Any explanatory markdown files
|
|
17
|
+
|
|
18
|
+
**Exception:** Internal workspace files (memory, session, topic files managed by skills) are not documentation -- create and update them freely.
|
|
19
|
+
|
|
20
|
+
If documentation is genuinely needed for a task, ask first.
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Bootstrap a minimal project knowledge tree under ./agent-knowledge/.
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# ./bootstrap-memory-tree.sh [project-dir] [profile]
|
|
7
|
+
# ./bootstrap-memory-tree.sh . # auto-detect profile hint
|
|
8
|
+
# ./bootstrap-memory-tree.sh /path/to/project robotics
|
|
9
|
+
#
|
|
10
|
+
# Profile hints: web-app | robotics | ml-platform | hybrid
|
|
11
|
+
#
|
|
12
|
+
# What it does:
|
|
13
|
+
# 1. Detects a profile hint from manifests, docs, configs, tests, and workflows
|
|
14
|
+
# 2. Creates the minimal knowledge tree: Memory/, Evidence/, Sessions/, Outputs/, Dashboards/
|
|
15
|
+
# 3. Creates Memory/MEMORY.md and Memory/decisions/decisions.md
|
|
16
|
+
# 4. Stores profile hint in STATUS.md (the agent infers the actual ontology)
|
|
17
|
+
#
|
|
18
|
+
# What it does NOT do:
|
|
19
|
+
# - Create per-area branch notes (the agent does this after inspecting the repo)
|
|
20
|
+
# - Define the ontology tree (the agent infers it from the project)
|
|
21
|
+
#
|
|
22
|
+
|
|
23
|
+
set -euo pipefail
|
|
24
|
+
|
|
25
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
26
|
+
AGENTS_RULES_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
27
|
+
# shellcheck source=/dev/null
|
|
28
|
+
. "$SCRIPT_DIR/lib/knowledge-common.sh"
|
|
29
|
+
TEMPLATES_DIR="$AGENTS_RULES_DIR/templates/memory"
|
|
30
|
+
PROJECT_TEMPLATE_DIR="$AGENTS_RULES_DIR/templates/project/agent-knowledge"
|
|
31
|
+
DASHBOARD_TEMPLATES_DIR="$AGENTS_RULES_DIR/templates/dashboards"
|
|
32
|
+
STATUS_TEMPLATE="$AGENTS_RULES_DIR/templates/project/agent-knowledge/STATUS.md"
|
|
33
|
+
|
|
34
|
+
TARGET_PROJECT_ARG="."
|
|
35
|
+
PROFILE=""
|
|
36
|
+
POSITIONAL=()
|
|
37
|
+
CHANGES=()
|
|
38
|
+
|
|
39
|
+
while [ "$#" -gt 0 ]; do
|
|
40
|
+
if kc_parse_common_flag "$@" ; then
|
|
41
|
+
shift
|
|
42
|
+
continue
|
|
43
|
+
fi
|
|
44
|
+
flag_status=$?
|
|
45
|
+
if [ "$flag_status" -eq 2 ]; then
|
|
46
|
+
shift 2
|
|
47
|
+
continue
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
case "$1" in
|
|
51
|
+
--project)
|
|
52
|
+
TARGET_PROJECT_ARG="${2:-.}"
|
|
53
|
+
shift 2
|
|
54
|
+
;;
|
|
55
|
+
--profile)
|
|
56
|
+
PROFILE="${2:-}"
|
|
57
|
+
shift 2
|
|
58
|
+
;;
|
|
59
|
+
*)
|
|
60
|
+
POSITIONAL+=("$1")
|
|
61
|
+
shift
|
|
62
|
+
;;
|
|
63
|
+
esac
|
|
64
|
+
done
|
|
65
|
+
|
|
66
|
+
if [ "$SHOW_HELP" -eq 1 ]; then
|
|
67
|
+
cat <<'EOF'
|
|
68
|
+
Usage:
|
|
69
|
+
scripts/bootstrap-memory-tree.sh [project-dir] [profile]
|
|
70
|
+
scripts/bootstrap-memory-tree.sh --project <dir> [--profile <profile>] [--dry-run] [--json] [--summary-file <file>] [--force]
|
|
71
|
+
EOF
|
|
72
|
+
exit 0
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
if [ ${#POSITIONAL[@]} -ge 1 ]; then
|
|
76
|
+
TARGET_PROJECT_ARG="${POSITIONAL[0]}"
|
|
77
|
+
fi
|
|
78
|
+
if [ ${#POSITIONAL[@]} -ge 2 ] && [ -z "$PROFILE" ]; then
|
|
79
|
+
PROFILE="${POSITIONAL[1]}"
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
kc_load_project_context "$TARGET_PROJECT_ARG"
|
|
83
|
+
DATE="$(kc_today)"
|
|
84
|
+
|
|
85
|
+
[ -L "$KNOWLEDGE_POINTER_PATH" ] || kc_fail "Bootstrap requires ./agent-knowledge to already be a pointer to the external knowledge folder. Run: agent-knowledge init"
|
|
86
|
+
|
|
87
|
+
# ---------------------------------------------------------------------------
|
|
88
|
+
# Profile detection (hint only -- does not drive file creation)
|
|
89
|
+
# ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
detect_profile() {
|
|
92
|
+
local dir="$1"
|
|
93
|
+
local docs_text=""
|
|
94
|
+
local has_workspace="no"
|
|
95
|
+
local manifest_total=0
|
|
96
|
+
|
|
97
|
+
local manifest_paths=""
|
|
98
|
+
manifest_paths="$(list_existing_paths "$dir" \
|
|
99
|
+
package.json pnpm-workspace.yaml nx.json turbo.json yarn.lock pnpm-lock.yaml package-lock.json \
|
|
100
|
+
pyproject.toml requirements.txt setup.py setup.cfg Pipfile poetry.lock \
|
|
101
|
+
Cargo.toml Cargo.lock go.mod go.sum CMakeLists.txt Makefile package.xml)"
|
|
102
|
+
|
|
103
|
+
manifest_total="$(printf "%s\n" "$manifest_paths" | awk 'NF{count++} END{print count+0}')"
|
|
104
|
+
|
|
105
|
+
if [ -f "$dir/pnpm-workspace.yaml" ] || [ -f "$dir/nx.json" ] || [ -f "$dir/turbo.json" ] || \
|
|
106
|
+
[ -d "$dir/packages" ] || [ -d "$dir/services" ] || [ -d "$dir/apps" ] || \
|
|
107
|
+
( [ -f "$dir/package.json" ] && grep -q '"workspaces"' "$dir/package.json" 2>/dev/null ); then
|
|
108
|
+
has_workspace="yes"
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
docs_text="$(cat "$dir/README.md" "$dir/docs/README.md" "$dir/AGENTS.md" "$dir/CLAUDE.md" 2>/dev/null || true)"
|
|
112
|
+
|
|
113
|
+
if [ -f "$dir/package.xml" ] || [ -f "$dir/CMakeLists.txt" ] || [ -d "$dir/urdf" ] || [ -d "$dir/launch" ] || \
|
|
114
|
+
printf "%s" "$docs_text" | grep -Eiq 'ros2|ros |gazebo|rviz|urdf|moveit'; then
|
|
115
|
+
echo "robotics"
|
|
116
|
+
return
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
if { [ -f "$dir/pyproject.toml" ] || [ -f "$dir/requirements.txt" ]; } && \
|
|
120
|
+
{ [ -d "$dir/notebooks" ] || [ -d "$dir/models" ] || [ -d "$dir/data" ] || \
|
|
121
|
+
grep -Eiq 'torch|tensorflow|jax|sklearn|transformers|mlflow|wandb|ray' "$dir/requirements.txt" "$dir/pyproject.toml" 2>/dev/null || \
|
|
122
|
+
printf "%s" "$docs_text" | grep -Eiq 'training|inference|model registry|feature store'; }; then
|
|
123
|
+
echo "ml-platform"
|
|
124
|
+
return
|
|
125
|
+
fi
|
|
126
|
+
|
|
127
|
+
if [ "$has_workspace" = "yes" ] || [ "$manifest_total" -ge 3 ]; then
|
|
128
|
+
echo "hybrid"
|
|
129
|
+
return
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
if [ -f "$dir/package.json" ] && \
|
|
133
|
+
grep -qE '"react"|"next"|"vue"|"svelte"|"angular"|"nuxt"|"vite"' "$dir/package.json" 2>/dev/null; then
|
|
134
|
+
echo "web-app"
|
|
135
|
+
return
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
echo "hybrid"
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
relative_path() {
|
|
142
|
+
sed "s|$TARGET_PROJECT/||" | sed "s|^$TARGET_PROJECT$|.|"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
list_existing_paths() {
|
|
146
|
+
local base="$1"
|
|
147
|
+
shift
|
|
148
|
+
local path=""
|
|
149
|
+
|
|
150
|
+
for path in "$@"; do
|
|
151
|
+
if [ -e "$base/$path" ]; then
|
|
152
|
+
printf "%s\n" "$path"
|
|
153
|
+
fi
|
|
154
|
+
done
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
render_text_template() {
|
|
158
|
+
local src="$1"
|
|
159
|
+
local dst="$2"
|
|
160
|
+
local current_state_lines="${3:-}"
|
|
161
|
+
local recent_change_lines="${4:-}"
|
|
162
|
+
local decision_lines="${5:-}"
|
|
163
|
+
local open_question_lines="${6:-}"
|
|
164
|
+
local branch_lines="${7:-}"
|
|
165
|
+
local tmp_file
|
|
166
|
+
|
|
167
|
+
tmp_file="$(mktemp)"
|
|
168
|
+
|
|
169
|
+
TEMPLATE_PROJECT_NAME="$PROJECT_NAME" \
|
|
170
|
+
TEMPLATE_DATE="$DATE" \
|
|
171
|
+
TEMPLATE_CURRENT_STATE_LINES="$current_state_lines" \
|
|
172
|
+
TEMPLATE_RECENT_CHANGE_LINES="$recent_change_lines" \
|
|
173
|
+
TEMPLATE_DECISION_LINES="$decision_lines" \
|
|
174
|
+
TEMPLATE_OPEN_QUESTION_LINES="$open_question_lines" \
|
|
175
|
+
TEMPLATE_BRANCH_LINES="$branch_lines" \
|
|
176
|
+
awk '
|
|
177
|
+
BEGIN {
|
|
178
|
+
project = ENVIRON["TEMPLATE_PROJECT_NAME"]
|
|
179
|
+
date = ENVIRON["TEMPLATE_DATE"]
|
|
180
|
+
current_state_lines = ENVIRON["TEMPLATE_CURRENT_STATE_LINES"]
|
|
181
|
+
recent_change_lines = ENVIRON["TEMPLATE_RECENT_CHANGE_LINES"]
|
|
182
|
+
decision_lines = ENVIRON["TEMPLATE_DECISION_LINES"]
|
|
183
|
+
open_question_lines = ENVIRON["TEMPLATE_OPEN_QUESTION_LINES"]
|
|
184
|
+
branch_lines = ENVIRON["TEMPLATE_BRANCH_LINES"]
|
|
185
|
+
}
|
|
186
|
+
{
|
|
187
|
+
gsub(/<project-name>/, project)
|
|
188
|
+
gsub(/<date>/, date)
|
|
189
|
+
|
|
190
|
+
if ($0 == "<current-state-lines>") { print current_state_lines; next }
|
|
191
|
+
if ($0 == "<recent-change-lines>") { print recent_change_lines; next }
|
|
192
|
+
if ($0 == "<decision-lines>") { print decision_lines; next }
|
|
193
|
+
if ($0 == "<open-question-lines>") { print open_question_lines; next }
|
|
194
|
+
if ($0 == "<branch-lines>") { print branch_lines; next }
|
|
195
|
+
|
|
196
|
+
print
|
|
197
|
+
}' "$src" > "$tmp_file"
|
|
198
|
+
|
|
199
|
+
kc_apply_temp_file "$tmp_file" "$dst" "$dst"
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
copy_static_template() {
|
|
203
|
+
local src="$1"
|
|
204
|
+
local dst="$2"
|
|
205
|
+
local label="$3"
|
|
206
|
+
|
|
207
|
+
render_text_template "$src" "$dst"
|
|
208
|
+
case "$KC_LAST_ACTION" in
|
|
209
|
+
created|updated|would-create|would-update)
|
|
210
|
+
CHANGES+=("$label")
|
|
211
|
+
;;
|
|
212
|
+
esac
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
render_dashboard_note() {
|
|
216
|
+
local src="$1"
|
|
217
|
+
local dst="$2"
|
|
218
|
+
local label="$3"
|
|
219
|
+
|
|
220
|
+
render_text_template "$src" "$dst"
|
|
221
|
+
case "$KC_LAST_ACTION" in
|
|
222
|
+
created|updated|would-create|would-update)
|
|
223
|
+
CHANGES+=("$label")
|
|
224
|
+
;;
|
|
225
|
+
esac
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
# ---------------------------------------------------------------------------
|
|
229
|
+
# Detect or accept profile hint
|
|
230
|
+
# ---------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
if [ -z "$PROFILE" ]; then
|
|
233
|
+
PROFILE="$(detect_profile "$TARGET_PROJECT")"
|
|
234
|
+
kc_log "Auto-detected profile hint: $PROFILE"
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
PROFILE_FILE="$TEMPLATES_DIR/profile.$PROFILE.yaml"
|
|
238
|
+
if [ ! -f "$PROFILE_FILE" ]; then
|
|
239
|
+
kc_log "Warning: Unknown profile hint '$PROFILE'; defaulting to hybrid"
|
|
240
|
+
PROFILE="hybrid"
|
|
241
|
+
PROFILE_FILE="$TEMPLATES_DIR/profile.$PROFILE.yaml"
|
|
242
|
+
fi
|
|
243
|
+
|
|
244
|
+
if [ -f "$AGENT_PROJECT_FILE" ]; then
|
|
245
|
+
tmp_file="$(mktemp)"
|
|
246
|
+
sed "s/^\([[:space:]]*profile_hint:[[:space:]]*\).*/\1$PROFILE/" "$AGENT_PROJECT_FILE" > "$tmp_file"
|
|
247
|
+
# Also handle legacy 'profile:' key for compat
|
|
248
|
+
sed -i "s/^\([[:space:]]*profile:[[:space:]]*\).*/\1$PROFILE/" "$tmp_file" 2>/dev/null || true
|
|
249
|
+
kc_apply_temp_file "$tmp_file" "$AGENT_PROJECT_FILE" ".agent-project.yaml"
|
|
250
|
+
case "$KC_LAST_ACTION" in
|
|
251
|
+
created|updated|would-create|would-update)
|
|
252
|
+
CHANGES+=(".agent-project.yaml")
|
|
253
|
+
;;
|
|
254
|
+
esac
|
|
255
|
+
fi
|
|
256
|
+
|
|
257
|
+
kc_log "Bootstrapping memory tree: $PROJECT_NAME (profile hint: $PROFILE)"
|
|
258
|
+
kc_log ""
|
|
259
|
+
|
|
260
|
+
# ---------------------------------------------------------------------------
|
|
261
|
+
# Create minimal directory scaffold
|
|
262
|
+
# ---------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
for dir in \
|
|
265
|
+
"$KNOWLEDGE_DIR" \
|
|
266
|
+
"$MEMORY_DIR" \
|
|
267
|
+
"$DECISIONS_DIR" \
|
|
268
|
+
"$EVIDENCE_DIR" \
|
|
269
|
+
"$EVIDENCE_RAW_DIR" \
|
|
270
|
+
"$EVIDENCE_IMPORTS_DIR" \
|
|
271
|
+
"$SESSIONS_DIR" \
|
|
272
|
+
"$OUTPUTS_DIR" \
|
|
273
|
+
"$DASHBOARDS_DIR" \
|
|
274
|
+
"$LOCAL_TEMPLATES_DIR" \
|
|
275
|
+
"$OBSIDIAN_DIR"; do
|
|
276
|
+
kc_ensure_dir "$dir" "$dir"
|
|
277
|
+
done
|
|
278
|
+
|
|
279
|
+
# ---------------------------------------------------------------------------
|
|
280
|
+
# Copy static templates (no INDEX.md -- uses STATUS.md + MEMORY.md as entries)
|
|
281
|
+
# ---------------------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Evidence/README.md" "$EVIDENCE_DIR/README.md" "agent-knowledge/Evidence/README.md"
|
|
284
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Evidence/raw/README.md" "$EVIDENCE_RAW_DIR/README.md" "agent-knowledge/Evidence/raw/README.md"
|
|
285
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Evidence/imports/README.md" "$EVIDENCE_IMPORTS_DIR/README.md" "agent-knowledge/Evidence/imports/README.md"
|
|
286
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Sessions/README.md" "$SESSIONS_DIR/README.md" "agent-knowledge/Sessions/README.md"
|
|
287
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Outputs/README.md" "$OUTPUTS_DIR/README.md" "agent-knowledge/Outputs/README.md"
|
|
288
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Templates/README.md" "$LOCAL_TEMPLATES_DIR/README.md" "agent-knowledge/Templates/README.md"
|
|
289
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/.obsidian/README.md" "$OBSIDIAN_DIR/README.md" "agent-knowledge/.obsidian/README.md"
|
|
290
|
+
copy_static_template "$PROJECT_TEMPLATE_DIR/Memory/decisions/decisions.md" "$DECISIONS_DIR/decisions.md" "agent-knowledge/Memory/decisions/decisions.md"
|
|
291
|
+
|
|
292
|
+
kc_copy_file "$PROJECT_TEMPLATE_DIR/.obsidian/core-plugins.json" "$OBSIDIAN_DIR/core-plugins.json" "agent-knowledge/.obsidian/core-plugins.json"
|
|
293
|
+
case "$KC_LAST_ACTION" in
|
|
294
|
+
created|updated|would-create|would-update)
|
|
295
|
+
CHANGES+=("agent-knowledge/.obsidian/core-plugins.json")
|
|
296
|
+
;;
|
|
297
|
+
esac
|
|
298
|
+
kc_copy_file "$PROJECT_TEMPLATE_DIR/.obsidian/app.json" "$OBSIDIAN_DIR/app.json" "agent-knowledge/.obsidian/app.json"
|
|
299
|
+
case "$KC_LAST_ACTION" in
|
|
300
|
+
created|updated|would-create|would-update)
|
|
301
|
+
CHANGES+=("agent-knowledge/.obsidian/app.json")
|
|
302
|
+
;;
|
|
303
|
+
esac
|
|
304
|
+
|
|
305
|
+
# ---------------------------------------------------------------------------
|
|
306
|
+
# STATUS.md
|
|
307
|
+
# ---------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
kc_replace_in_template \
|
|
310
|
+
"$STATUS_TEMPLATE" \
|
|
311
|
+
"$STATUS_FILE" \
|
|
312
|
+
"agent-knowledge/STATUS.md" \
|
|
313
|
+
"<project-name>" "$PROJECT_NAME" \
|
|
314
|
+
"<profile-type>" "$PROFILE" \
|
|
315
|
+
"<absolute-path-to-dedicated-knowledge-folder>" "$KNOWLEDGE_REAL_DIR"
|
|
316
|
+
case "$KC_LAST_ACTION" in
|
|
317
|
+
created|updated|would-create|would-update)
|
|
318
|
+
CHANGES+=("agent-knowledge/STATUS.md")
|
|
319
|
+
;;
|
|
320
|
+
esac
|
|
321
|
+
|
|
322
|
+
# ---------------------------------------------------------------------------
|
|
323
|
+
# Dashboard stubs
|
|
324
|
+
# ---------------------------------------------------------------------------
|
|
325
|
+
|
|
326
|
+
render_dashboard_note \
|
|
327
|
+
"$DASHBOARD_TEMPLATES_DIR/project-overview.template.md" \
|
|
328
|
+
"$DASHBOARDS_DIR/project-overview.md" \
|
|
329
|
+
"agent-knowledge/Dashboards/project-overview.md"
|
|
330
|
+
render_dashboard_note \
|
|
331
|
+
"$DASHBOARD_TEMPLATES_DIR/session-rollup.template.md" \
|
|
332
|
+
"$DASHBOARDS_DIR/session-rollup.md" \
|
|
333
|
+
"agent-knowledge/Dashboards/session-rollup.md"
|
|
334
|
+
|
|
335
|
+
# ---------------------------------------------------------------------------
|
|
336
|
+
# Memory/MEMORY.md (minimal -- agent infers branches later)
|
|
337
|
+
# ---------------------------------------------------------------------------
|
|
338
|
+
|
|
339
|
+
render_text_template \
|
|
340
|
+
"$TEMPLATES_DIR/MEMORY.root.template.md" \
|
|
341
|
+
"$MEMORY_ROOT" \
|
|
342
|
+
"$(printf -- '- Profile hint: `%s`. The agent should inspect the repo to infer the real ontology.\n- Memory has been initialized but branches have not been created yet.' "$PROFILE")" \
|
|
343
|
+
"$(printf -- '- %s - Bootstrapped minimal memory root.' "$DATE")" \
|
|
344
|
+
"$(printf -- '- [decisions/decisions.md](decisions/decisions.md) - Decision log.')" \
|
|
345
|
+
"$(printf -- '- Which areas of the project should become the first memory branches?\n- Which decisions should be recorded explicitly from existing docs and code?')" \
|
|
346
|
+
"$(printf -- '- Add branch links here as the agent infers project structure.')"
|
|
347
|
+
case "$KC_LAST_ACTION" in
|
|
348
|
+
created|updated|would-create|would-update)
|
|
349
|
+
CHANGES+=("agent-knowledge/Memory/MEMORY.md")
|
|
350
|
+
;;
|
|
351
|
+
esac
|
|
352
|
+
|
|
353
|
+
# ---------------------------------------------------------------------------
|
|
354
|
+
# STATUS bookkeeping
|
|
355
|
+
# ---------------------------------------------------------------------------
|
|
356
|
+
|
|
357
|
+
kc_status_load
|
|
358
|
+
STATUS_PROFILE="$PROFILE"
|
|
359
|
+
STATUS_REAL_PATH="$KNOWLEDGE_REAL_DIR"
|
|
360
|
+
STATUS_POINTER_PATH="$POINTER_DISPLAY"
|
|
361
|
+
if [ "${DRY_RUN:-0}" -eq 0 ] && [ ${#CHANGES[@]} -gt 0 ]; then
|
|
362
|
+
STATUS_LAST_BOOTSTRAP="$(kc_now_utc)"
|
|
363
|
+
fi
|
|
364
|
+
kc_status_write
|
|
365
|
+
|
|
366
|
+
# ---------------------------------------------------------------------------
|
|
367
|
+
# JSON summary
|
|
368
|
+
# ---------------------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
json_summary="{"
|
|
371
|
+
json_summary="$json_summary\"script\":\"bootstrap-memory-tree\","
|
|
372
|
+
json_summary="$json_summary\"project_root\":\"$(kc_json_escape "$TARGET_PROJECT")\","
|
|
373
|
+
json_summary="$json_summary\"profile_hint\":\"$(kc_json_escape "$PROFILE")\","
|
|
374
|
+
json_summary="$json_summary\"real_knowledge_path\":\"$(kc_json_escape "$KNOWLEDGE_REAL_DIR")\","
|
|
375
|
+
json_summary="$json_summary\"dry_run\":$(kc_json_bool "$DRY_RUN"),"
|
|
376
|
+
json_summary="$json_summary\"changes\":$(kc_json_array "${CHANGES[@]+"${CHANGES[@]}"}")"
|
|
377
|
+
json_summary="$json_summary}"
|
|
378
|
+
kc_write_json_output "$json_summary"
|
|
379
|
+
|
|
380
|
+
if [ "$JSON_MODE" -ne 1 ]; then
|
|
381
|
+
kc_log ""
|
|
382
|
+
kc_log "Memory tree ready for: $PROJECT_NAME"
|
|
383
|
+
kc_log "Profile hint: $PROFILE"
|
|
384
|
+
kc_log ""
|
|
385
|
+
kc_log "Next steps:"
|
|
386
|
+
kc_log " 1. agent-knowledge import --project $TARGET_PROJECT"
|
|
387
|
+
kc_log " 2. Agent inspects repo and creates initial branch notes in Memory/"
|
|
388
|
+
kc_log " 3. agent-knowledge doctor --project $TARGET_PROJECT"
|
|
389
|
+
fi
|