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.
Files changed (88) hide show
  1. agent_knowledge/__init__.py +3 -0
  2. agent_knowledge/__main__.py +3 -0
  3. agent_knowledge/assets/__init__.py +0 -0
  4. agent_knowledge/assets/claude/global.md +44 -0
  5. agent_knowledge/assets/claude/project-template.md +46 -0
  6. agent_knowledge/assets/claude/scripts/install.sh +85 -0
  7. agent_knowledge/assets/commands/doctor.md +21 -0
  8. agent_knowledge/assets/commands/global-knowledge-sync.md +27 -0
  9. agent_knowledge/assets/commands/graphify-sync.md +26 -0
  10. agent_knowledge/assets/commands/knowledge-sync.md +26 -0
  11. agent_knowledge/assets/commands/ship.md +29 -0
  12. agent_knowledge/assets/rules/generate-architecture-doc.mdc +87 -0
  13. agent_knowledge/assets/rules/history-backfill.mdc +67 -0
  14. agent_knowledge/assets/rules/memory-bootstrap.mdc +53 -0
  15. agent_knowledge/assets/rules/memory-writeback.mdc +90 -0
  16. agent_knowledge/assets/rules/shared-memory.mdc +102 -0
  17. agent_knowledge/assets/rules/workflow-orchestration.mdc +93 -0
  18. agent_knowledge/assets/rules-global/action-first.mdc +26 -0
  19. agent_knowledge/assets/rules-global/no-icons-emojis.mdc +16 -0
  20. agent_knowledge/assets/rules-global/no-unsolicited-docs.mdc +20 -0
  21. agent_knowledge/assets/scripts/bootstrap-memory-tree.sh +389 -0
  22. agent_knowledge/assets/scripts/compact-memory.sh +191 -0
  23. agent_knowledge/assets/scripts/doctor.sh +137 -0
  24. agent_knowledge/assets/scripts/global-knowledge-sync.sh +372 -0
  25. agent_knowledge/assets/scripts/graphify-sync.sh +397 -0
  26. agent_knowledge/assets/scripts/import-agent-history.sh +706 -0
  27. agent_knowledge/assets/scripts/install-project-links.sh +258 -0
  28. agent_knowledge/assets/scripts/lib/knowledge-common.sh +875 -0
  29. agent_knowledge/assets/scripts/measure-token-savings.py +540 -0
  30. agent_knowledge/assets/scripts/ship.sh +256 -0
  31. agent_knowledge/assets/scripts/update-knowledge.sh +341 -0
  32. agent_knowledge/assets/scripts/validate-knowledge.sh +265 -0
  33. agent_knowledge/assets/skills/decision-recording/SKILL.md +124 -0
  34. agent_knowledge/assets/skills/history-backfill/SKILL.md +115 -0
  35. agent_knowledge/assets/skills/memory-compaction/SKILL.md +115 -0
  36. agent_knowledge/assets/skills/memory-management/SKILL.md +134 -0
  37. agent_knowledge/assets/skills/project-ontology-bootstrap/SKILL.md +173 -0
  38. agent_knowledge/assets/skills/session-management/SKILL.md +116 -0
  39. agent_knowledge/assets/skills-cursor/create-rule/SKILL.md +164 -0
  40. agent_knowledge/assets/skills-cursor/create-skill/SKILL.md +498 -0
  41. agent_knowledge/assets/skills-cursor/create-subagent/SKILL.md +225 -0
  42. agent_knowledge/assets/skills-cursor/migrate-to-skills/SKILL.md +134 -0
  43. agent_knowledge/assets/skills-cursor/shell/SKILL.md +24 -0
  44. agent_knowledge/assets/skills-cursor/update-cursor-settings/SKILL.md +122 -0
  45. agent_knowledge/assets/templates/dashboards/project-overview.template.md +24 -0
  46. agent_knowledge/assets/templates/dashboards/session-rollup.template.md +23 -0
  47. agent_knowledge/assets/templates/hooks/hooks.json.template +11 -0
  48. agent_knowledge/assets/templates/integrations/claude/CLAUDE.md +7 -0
  49. agent_knowledge/assets/templates/integrations/codex/AGENTS.md +7 -0
  50. agent_knowledge/assets/templates/integrations/cursor/agent-knowledge.mdc +11 -0
  51. agent_knowledge/assets/templates/integrations/cursor/hooks.json +11 -0
  52. agent_knowledge/assets/templates/memory/MEMORY.root.template.md +36 -0
  53. agent_knowledge/assets/templates/memory/branch.template.md +33 -0
  54. agent_knowledge/assets/templates/memory/decision.template.md +33 -0
  55. agent_knowledge/assets/templates/memory/profile.hybrid.yaml +16 -0
  56. agent_knowledge/assets/templates/memory/profile.ml-platform.yaml +18 -0
  57. agent_knowledge/assets/templates/memory/profile.robotics.yaml +19 -0
  58. agent_knowledge/assets/templates/memory/profile.web-app.yaml +16 -0
  59. agent_knowledge/assets/templates/portfolio/.obsidian/README.md +21 -0
  60. agent_knowledge/assets/templates/portfolio/.obsidian/app.json +5 -0
  61. agent_knowledge/assets/templates/portfolio/.obsidian/core-plugins.json +7 -0
  62. agent_knowledge/assets/templates/project/.agent-project.yaml +36 -0
  63. agent_knowledge/assets/templates/project/.agentknowledgeignore +10 -0
  64. agent_knowledge/assets/templates/project/AGENTS.md +87 -0
  65. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/README.md +23 -0
  66. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/app.json +5 -0
  67. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/core-plugins.json +7 -0
  68. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/README.md +34 -0
  69. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/imports/README.md +29 -0
  70. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/raw/README.md +25 -0
  71. agent_knowledge/assets/templates/project/agent-knowledge/Memory/MEMORY.md +37 -0
  72. agent_knowledge/assets/templates/project/agent-knowledge/Memory/decisions/decisions.md +31 -0
  73. agent_knowledge/assets/templates/project/agent-knowledge/Outputs/README.md +24 -0
  74. agent_knowledge/assets/templates/project/agent-knowledge/STATUS.md +43 -0
  75. agent_knowledge/assets/templates/project/agent-knowledge/Sessions/README.md +21 -0
  76. agent_knowledge/assets/templates/project/agent-knowledge/Templates/README.md +19 -0
  77. agent_knowledge/assets/templates/project/gitignore.agent-knowledge +13 -0
  78. agent_knowledge/cli.py +457 -0
  79. agent_knowledge/runtime/__init__.py +0 -0
  80. agent_knowledge/runtime/integrations.py +154 -0
  81. agent_knowledge/runtime/paths.py +46 -0
  82. agent_knowledge/runtime/shell.py +22 -0
  83. agent_knowledge/runtime/sync.py +255 -0
  84. agent_knowledge_cli-0.1.2.dist-info/METADATA +155 -0
  85. agent_knowledge_cli-0.1.2.dist-info/RECORD +88 -0
  86. agent_knowledge_cli-0.1.2.dist-info/WHEEL +4 -0
  87. agent_knowledge_cli-0.1.2.dist-info/entry_points.txt +2 -0
  88. agent_knowledge_cli-0.1.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,265 @@
1
+ #!/bin/bash
2
+ #
3
+ # Validate the project knowledge layout and key operational links.
4
+ #
5
+
6
+ set -euo pipefail
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9
+ AGENTS_RULES_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
10
+ # shellcheck source=/dev/null
11
+ . "$SCRIPT_DIR/lib/knowledge-common.sh"
12
+
13
+ usage() {
14
+ cat <<'EOF'
15
+ Usage:
16
+ scripts/validate-knowledge.sh [project-dir]
17
+ scripts/validate-knowledge.sh --project <dir> [--dry-run] [--json] [--summary-file <file>]
18
+ EOF
19
+ }
20
+
21
+ TARGET_PROJECT_ARG="."
22
+ POSITIONAL=()
23
+ ERRORS=()
24
+ WARNINGS=()
25
+ CHECKS=()
26
+
27
+ while [ "$#" -gt 0 ]; do
28
+ if kc_parse_common_flag "$@" ; then
29
+ shift
30
+ continue
31
+ fi
32
+ flag_status=$?
33
+ if [ "$flag_status" -eq 2 ]; then
34
+ shift 2
35
+ continue
36
+ fi
37
+
38
+ case "$1" in
39
+ --project)
40
+ TARGET_PROJECT_ARG="${2:-.}"
41
+ shift 2
42
+ ;;
43
+ *)
44
+ POSITIONAL+=("$1")
45
+ shift
46
+ ;;
47
+ esac
48
+ done
49
+
50
+ if [ "$SHOW_HELP" -eq 1 ]; then
51
+ usage
52
+ exit 0
53
+ fi
54
+
55
+ if [ ${#POSITIONAL[@]} -ge 1 ]; then
56
+ TARGET_PROJECT_ARG="${POSITIONAL[0]}"
57
+ fi
58
+
59
+ kc_load_project_context "$TARGET_PROJECT_ARG"
60
+
61
+ check_required_path() {
62
+ local path="$1"
63
+ local label="$2"
64
+ if [ -e "$path" ]; then
65
+ CHECKS+=("$label:ok")
66
+ else
67
+ ERRORS+=("Missing $label at $path")
68
+ fi
69
+ }
70
+
71
+ check_required_dir() {
72
+ local path="$1"
73
+ local label="$2"
74
+ if [ -d "$path" ]; then
75
+ CHECKS+=("$label:ok")
76
+ else
77
+ ERRORS+=("Missing directory $label at $path")
78
+ fi
79
+ }
80
+
81
+ check_required_path "$AGENT_PROJECT_FILE" ".agent-project.yaml"
82
+ check_required_dir "$KNOWLEDGE_POINTER_PATH" "agent-knowledge local handle"
83
+ check_required_dir "$KNOWLEDGE_REAL_DIR" "real knowledge dir"
84
+ check_required_path "$STATUS_FILE" "STATUS.md"
85
+ check_required_path "$MEMORY_ROOT" "Memory/MEMORY.md"
86
+ check_required_dir "$DECISIONS_DIR" "Memory/decisions"
87
+ check_required_dir "$EVIDENCE_RAW_DIR" "Evidence/raw"
88
+ check_required_dir "$EVIDENCE_IMPORTS_DIR" "Evidence/imports"
89
+ check_required_dir "$SESSIONS_DIR" "Sessions"
90
+ check_required_dir "$OUTPUTS_DIR" "Outputs"
91
+
92
+ if [ -f "$AGENT_PROJECT_FILE" ]; then
93
+ for key in name slug pointer_path real_path memory_root evidence_raw evidence_imports; do
94
+ if [ -z "$(kc_yaml_leaf_value "$AGENT_PROJECT_FILE" "$key" || true)" ]; then
95
+ ERRORS+=("Missing required .agent-project.yaml key: $key")
96
+ fi
97
+ done
98
+ fi
99
+
100
+ pointer_resolved="$(kc_pointer_resolved_path || true)"
101
+ if [ -z "$pointer_resolved" ]; then
102
+ ERRORS+=("Unable to resolve ./agent-knowledge as a local handle.")
103
+ elif [ "$pointer_resolved" != "$KNOWLEDGE_REAL_DIR" ]; then
104
+ ERRORS+=("agent-knowledge resolves to $pointer_resolved but .agent-project.yaml expects $KNOWLEDGE_REAL_DIR")
105
+ elif [ ! -L "$KNOWLEDGE_POINTER_PATH" ]; then
106
+ if kc_is_windows_like; then
107
+ WARNINGS+=("agent-knowledge is not reported as a symlink; if this is a junction, verify it still points to the external knowledge folder.")
108
+ else
109
+ ERRORS+=("agent-knowledge must be a symlink to the external knowledge folder in canonical mode.")
110
+ fi
111
+ fi
112
+
113
+ validate_durable_note() {
114
+ local file="$1"
115
+ local rel
116
+ rel="$(kc_rel_knowledge_path "$file")"
117
+ local note_type
118
+
119
+ note_type="$(kc_yaml_leaf_value "$file" "note_type" || true)"
120
+ if ! kc_has_frontmatter "$file"; then
121
+ ERRORS+=("$rel is missing YAML frontmatter")
122
+ return
123
+ fi
124
+
125
+ case "$note_type" in
126
+ durable-memory-root|durable-memory-branch|memory-branch|tooling-memory|tooling-index|decision-log)
127
+ for heading in "## Purpose" "## Current State" "## Recent Changes" "## Decisions" "## Open Questions"; do
128
+ if ! grep -q "^$heading\$" "$file"; then
129
+ ERRORS+=("$rel is missing required section: $heading")
130
+ fi
131
+ done
132
+ ;;
133
+ structural-evidence|generated-output)
134
+ for heading in "## Purpose"; do
135
+ if ! grep -q "^$heading\$" "$file"; then
136
+ ERRORS+=("$rel is missing required section: $heading")
137
+ fi
138
+ done
139
+ ;;
140
+ decision)
141
+ for heading in "## What" "## Why" "## Alternatives Considered" "## Consequences"; do
142
+ if ! grep -q "^$heading\$" "$file"; then
143
+ ERRORS+=("$rel is missing required section: $heading")
144
+ fi
145
+ done
146
+ ;;
147
+ esac
148
+ }
149
+
150
+ check_links() {
151
+ local file="$1"
152
+ local rel
153
+ rel="$(kc_rel_knowledge_path "$file")"
154
+ local link=""
155
+ local target=""
156
+ local base_dir
157
+ base_dir="$(dirname "$file")"
158
+
159
+ while IFS= read -r link; do
160
+ target="$(printf '%s' "$link" | sed 's/^[^)]*(//; s/)$//')"
161
+ case "$target" in
162
+ http:*|https:*|mailto:*|'#'*|'')
163
+ continue
164
+ ;;
165
+ esac
166
+ if [ ! -e "$base_dir/$target" ]; then
167
+ WARNINGS+=("Broken-looking link in $rel -> $target")
168
+ fi
169
+ done <<EOF
170
+ $(grep -o '\[[^]]*\]([^)]*)' "$file" 2>/dev/null || true)
171
+ EOF
172
+ }
173
+
174
+ memory_files="$(find "$MEMORY_DIR" -name "*.md" | sort)"
175
+ while IFS= read -r file; do
176
+ [ -n "$file" ] || continue
177
+ validate_durable_note "$file"
178
+ done <<EOF
179
+ $memory_files
180
+ EOF
181
+
182
+ # Check same-name branch convention: folders under Memory/ should have a same-name entry note
183
+ branch_dirs="$(find "$MEMORY_DIR" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort)"
184
+ while IFS= read -r branch_dir; do
185
+ [ -n "$branch_dir" ] || continue
186
+ branch_name="$(basename "$branch_dir")"
187
+ entry_note="$branch_dir/$branch_name.md"
188
+ if [ ! -f "$entry_note" ]; then
189
+ WARNINGS+=("Branch folder Memory/$branch_name/ is missing its entry note: $branch_name.md")
190
+ fi
191
+ done <<EOF
192
+ $branch_dirs
193
+ EOF
194
+
195
+ knowledge_markdown="$(find "$KNOWLEDGE_DIR" -name "*.md" | sort)"
196
+ while IFS= read -r file; do
197
+ [ -n "$file" ] || continue
198
+ check_links "$file"
199
+ done <<EOF
200
+ $knowledge_markdown
201
+ EOF
202
+
203
+ for path in \
204
+ "$AGENTS_RULES_DIR/scripts/update-knowledge.sh" \
205
+ "$AGENTS_RULES_DIR/scripts/ship.sh" \
206
+ "$AGENTS_RULES_DIR/scripts/global-knowledge-sync.sh" \
207
+ "$AGENTS_RULES_DIR/scripts/graphify-sync.sh" \
208
+ "$AGENTS_RULES_DIR/scripts/bootstrap-memory-tree.sh" \
209
+ "$AGENTS_RULES_DIR/scripts/import-agent-history.sh" \
210
+ "$AGENTS_RULES_DIR/scripts/compact-memory.sh" \
211
+ "$AGENTS_RULES_DIR/scripts/validate-knowledge.sh" \
212
+ "$AGENTS_RULES_DIR/scripts/doctor.sh" \
213
+ "$AGENTS_RULES_DIR/commands/knowledge-sync.md" \
214
+ "$AGENTS_RULES_DIR/commands/ship.md" \
215
+ "$AGENTS_RULES_DIR/commands/global-knowledge-sync.md" \
216
+ "$AGENTS_RULES_DIR/commands/graphify-sync.md" \
217
+ "$AGENTS_RULES_DIR/commands/doctor.md" \
218
+ "$AGENTS_RULES_DIR/rules/memory-bootstrap.mdc" \
219
+ "$AGENTS_RULES_DIR/rules/memory-writeback.mdc" \
220
+ "$AGENTS_RULES_DIR/rules/history-backfill.mdc" \
221
+ "$AGENTS_RULES_DIR/rules/workflow-orchestration.mdc"; do
222
+ [ -e "$path" ] || ERRORS+=("Missing required framework target: $path")
223
+ done
224
+
225
+ result="ok"
226
+ exit_code=0
227
+ if [ ${#ERRORS[@]} -gt 0 ]; then
228
+ result="error"
229
+ exit_code=1
230
+ elif [ ${#WARNINGS[@]} -gt 0 ]; then
231
+ result="warn"
232
+ fi
233
+
234
+ kc_status_load
235
+ if [ "${DRY_RUN:-0}" -eq 0 ]; then
236
+ STATUS_LAST_VALIDATION="$(kc_now_utc)"
237
+ STATUS_LAST_VALIDATION_RESULT="$result"
238
+ fi
239
+ STATUS_WARNING_LINES="$(printf '%s\n' "${WARNINGS[@]+"${WARNINGS[@]}"}")"
240
+ kc_status_write "$STATUS_WARNING_LINES"
241
+
242
+ json_summary="{"
243
+ json_summary="$json_summary\"script\":\"validate-knowledge\","
244
+ json_summary="$json_summary\"project_root\":\"$(kc_json_escape "$TARGET_PROJECT")\","
245
+ json_summary="$json_summary\"result\":\"$(kc_json_escape "$result")\","
246
+ json_summary="$json_summary\"dry_run\":$(kc_json_bool "$DRY_RUN"),"
247
+ json_summary="$json_summary\"errors\":$(kc_json_array "${ERRORS[@]+"${ERRORS[@]}"}"),"
248
+ json_summary="$json_summary\"warnings\":$(kc_json_array "${WARNINGS[@]+"${WARNINGS[@]}"}"),"
249
+ json_summary="$json_summary\"checks\":$(kc_json_array "${CHECKS[@]+"${CHECKS[@]}"}")"
250
+ json_summary="$json_summary}"
251
+ kc_write_json_output "$json_summary"
252
+
253
+ if [ "$JSON_MODE" -ne 1 ]; then
254
+ kc_log "Knowledge validation: $result"
255
+ if [ ${#ERRORS[@]} -gt 0 ]; then
256
+ kc_log "Errors:"
257
+ printf ' %s\n' "${ERRORS[@]+"${ERRORS[@]}"}"
258
+ fi
259
+ if [ ${#WARNINGS[@]} -gt 0 ]; then
260
+ kc_log "Warnings:"
261
+ printf ' %s\n' "${WARNINGS[@]+"${WARNINGS[@]}"}"
262
+ fi
263
+ fi
264
+
265
+ exit "$exit_code"
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: decision-recording
3
+ description: Record architectural and design decisions as lightweight ADRs in agent-knowledge/Memory/decisions/. Use when an important decision is made, reversed, or when the user asks to preserve rationale.
4
+ ---
5
+
6
+ # Decision Recording
7
+
8
+ Persists the rationale for architectural and design choices so future agents
9
+ do not re-litigate settled questions.
10
+
11
+ ---
12
+
13
+ ## When to record a decision
14
+
15
+ Record when any of these occur:
16
+ - A technology, framework, or pattern is chosen over alternatives
17
+ - A structural constraint is adopted (e.g., "no ORM", "raw SQL only")
18
+ - A previous decision is reversed or superseded
19
+ - The user says "remember why we chose X" or "note that we decided not to do Y"
20
+
21
+ Do NOT record:
22
+ - Tactical choices (variable names, minor refactors, formatting)
23
+ - Facts that are obvious from reading the code
24
+ - Speculative decisions not yet confirmed
25
+
26
+ ---
27
+
28
+ ## Step 1 -- Create the decision file
29
+
30
+ ```bash
31
+ SLUG="<short-hyphenated-title>"
32
+ DATE=$(date +%Y-%m-%d)
33
+ FILE="agent-knowledge/Memory/decisions/${DATE}-${SLUG}.md"
34
+ ```
35
+
36
+ Copy from `templates/memory/decision.template.md`.
37
+ Preserve YAML frontmatter.
38
+
39
+ ---
40
+
41
+ ## Step 2 -- Fill in the template
42
+
43
+ Required fields -- keep each one short:
44
+
45
+ | Field | Content |
46
+ |-------|---------|
47
+ | **What** | One sentence: what was decided |
48
+ | **Why** | Primary driver: constraint, measurement, user preference |
49
+ | **Alternatives considered** | 1-3 bullets: what was rejected and why |
50
+ | **Consequences** | 1-3 bullets: what this locks in or rules out |
51
+
52
+ Optional:
53
+ - **Superseded by**: link to the reversal decision if this one is no longer active
54
+
55
+ ---
56
+
57
+ ## Step 3 -- Link from the relevant branch note
58
+
59
+ In the relevant branch note under `Memory/`, add or update the **Decisions** section:
60
+
61
+ ```markdown
62
+ ## Decisions
63
+ - [2025-01-15-use-raw-sql.md](decisions/2025-01-15-use-raw-sql.md) -- chose raw SQL over ORM
64
+ ```
65
+
66
+ One line per decision. Keep descriptions under 10 words.
67
+
68
+ ---
69
+
70
+ ## Step 4 -- Update decisions/decisions.md
71
+
72
+ Prepend a line in `agent-knowledge/Memory/decisions/decisions.md`:
73
+
74
+ ```markdown
75
+ - [2025-01-15-use-raw-sql.md](2025-01-15-use-raw-sql.md) -- chose raw SQL over ORM
76
+ ```
77
+
78
+ Newest first. If the decision reverses an earlier one, add `[reverses YYYY-MM-DD-slug]`.
79
+
80
+ ---
81
+
82
+ ## Step 5 -- Update Memory/MEMORY.md if the root summary changed
83
+
84
+ Keep the root note short. Only update it if the project-level decision summary changed.
85
+
86
+ ---
87
+
88
+ ## Reversing a decision
89
+
90
+ 1. Add `Status: reversed` to the original decision file
91
+ 2. Add `Superseded by: [new-decision.md](new-decision.md)` to the original
92
+ 3. Create a new decision file for the replacement
93
+ 4. Update `decisions/decisions.md`: mark the old entry as `~~reversed~~`
94
+ 5. Update the branch note's Decisions section to link the new one
95
+
96
+ ---
97
+
98
+ ## Format reference
99
+
100
+ ```markdown
101
+ ---
102
+ note_type: decision
103
+ status: active
104
+ date: 2025-01-15
105
+ ---
106
+
107
+ # Decision: use-raw-sql
108
+
109
+ ## What
110
+ Use raw parameterized SQL instead of an ORM for all database access.
111
+
112
+ ## Why
113
+ Need full control over query shape; ORM abstraction adds complexity without benefit
114
+ given the team's SQL proficiency.
115
+
116
+ ## Alternatives considered
117
+ - **Prisma**: rejected -- too much magic, migration model doesn't fit
118
+ - **Drizzle**: rejected -- adds a dependency and type layer we don't need yet
119
+
120
+ ## Consequences
121
+ - All DB access goes through raw SQL + pgtyped-generated types
122
+ - No model layer; query files live in packages/server/src/queries/
123
+ - New contributors must know SQL
124
+ ```
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: history-backfill
3
+ description: Backfill project memory from existing repo evidence (codebase, docs, configs, git history, tasks, sessions, agent traces). Use when the memory tree is new or sparse and the project has existing history.
4
+ ---
5
+
6
+ # History Backfill
7
+
8
+ Reads raw evidence from the repo and existing artifacts, then distills stable facts
9
+ into the curated memory tree.
10
+
11
+ Use this after `project-ontology-bootstrap` when the project has existing history.
12
+
13
+ ---
14
+
15
+ ## Separation rule -- enforced, never relaxed
16
+
17
+ | Location | What goes here | Who edits it |
18
+ |----------|----------------|--------------|
19
+ | `agent-knowledge/Evidence/raw/` | Direct snapshots from the current repo state | Only the import script |
20
+ | `agent-knowledge/Evidence/imports/` | Imported docs, tasks, sessions, traces, graph exports | Only the import script |
21
+ | `agent-knowledge/Outputs/` | Generated discovery summaries and structural maps | Only scripts or agents treating them as non-canonical outputs |
22
+ | `agent-knowledge/Memory/` | Curated, stable, distilled facts | Only the agent, via writeback rule |
23
+
24
+ Never write raw evidence into memory. Never treat evidence as authoritative -- it is input for judgment, not truth.
25
+
26
+ ---
27
+
28
+ ## Step 1 -- Collect evidence
29
+
30
+ Run the import script:
31
+
32
+ ```bash
33
+ scripts/import-agent-history.sh /path/to/project
34
+ ```
35
+
36
+ This creates evidence files under `Evidence/raw/` and `Evidence/imports/`, and
37
+ generated summaries under `Outputs/`.
38
+
39
+ ---
40
+
41
+ ## Step 2 -- Read evidence in priority order
42
+
43
+ Read these files in order. Each source has different signal quality:
44
+
45
+ 1. **`imports/existing-docs.txt`** -- highest signal. README, CLAUDE.md, AGENTS.md, and project metadata contain curated intent.
46
+ 2. **`raw/manifests.txt`** -- authoritative for stack and dependency boundaries.
47
+ 3. **`raw/config-files.txt`** -- strongest signal for conventions and tooling.
48
+ 4. **`raw/tests.txt`** and **`raw/ci-workflows.txt`** -- how the project proves and ships behavior.
49
+ 5. **`raw/structure.txt`** -- actual architecture shape.
50
+ 6. **`imports/tasks.txt`** and **`imports/session-files.txt`** -- recurring work areas and unresolved questions.
51
+ 7. **`raw/git-log-detail.txt`** and **`raw/git-log.txt`** -- what changed and why.
52
+ 8. **`imports/trace-index.txt`** -- supplemental traces only; never canonical truth.
53
+
54
+ Read confidence labels before trusting a source:
55
+
56
+ - `EXTRACTED` means direct structural evidence
57
+ - `INFERRED` means a derived summary that still needs review
58
+ - `AMBIGUOUS` means the source may be stale, partial, or wrong
59
+
60
+ For agent traces and graph summaries: treat them as evidence with lower confidence than direct repo scans. Extract patterns, not individual claims.
61
+
62
+ ---
63
+
64
+ ## Step 3 -- Distill into memory
65
+
66
+ For each stable fact extracted from evidence:
67
+
68
+ 1. Identify which memory branch it belongs to
69
+ 2. Read the current branch note
70
+ 3. Place the fact in the correct section:
71
+ - **Current State**: for verified facts about the project as it is now
72
+ - **Recent Changes**: for things that changed recently (prune after ~4 weeks)
73
+ - **Open Questions**: for things the evidence hints at but doesn't resolve
74
+ - **Decisions**: link to a decision file if it's an architectural choice
75
+ 4. Lead with the fact. Do not pad with context the reader can find in git.
76
+
77
+ If a fact doesn't fit any existing branch, create a new branch note using the
78
+ same-name convention. Use the project's own terminology for the branch name.
79
+
80
+ ---
81
+
82
+ ## Step 4 -- Quality filters
83
+
84
+ Only write a fact to memory if it passes all of:
85
+ - **Stable**: unlikely to change in the next few weeks
86
+ - **Non-obvious**: not immediately derivable from reading the code
87
+ - **Useful**: would save a future agent meaningful time or prevent a mistake
88
+ - **Verified**: supported by at least one evidence source (not inferred)
89
+
90
+ Do not write:
91
+ - Commit-level implementation details
92
+ - Speculative interpretations of code intent
93
+ - Facts already in project docs that agents can read directly
94
+ - Anything marked as in-progress or planned (goes in session file until confirmed)
95
+ - Machine-generated summaries unless verified against the repo
96
+
97
+ ---
98
+
99
+ ## Step 5 -- Update Memory/MEMORY.md
100
+
101
+ After updating branch notes, check that `Memory/MEMORY.md` reflects the new content:
102
+ - Keep the root note short
103
+ - Update branch summaries if their durable state changed
104
+ - Add branch links for any new branches created during backfill
105
+
106
+ ---
107
+
108
+ ## Output checklist
109
+
110
+ - [ ] Each branch note has populated **Current State** (not just TODO markers)
111
+ - [ ] Any patterns from git log are captured in relevant branch notes
112
+ - [ ] Active decisions found in docs are recorded in `decisions/`
113
+ - [ ] Open questions are listed for anything evidence hints at but doesn't resolve
114
+ - [ ] `Memory/MEMORY.md` reflects the real branch state
115
+ - [ ] No evidence content was written directly into memory files
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: memory-compaction
3
+ description: Compact and prune the memory tree when it grows large or stale. Use when Memory/MEMORY.md grows noisy, branch notes exceed 150 lines, or when explicitly asked to clean up memory.
4
+ ---
5
+
6
+ # Memory Compaction
7
+
8
+ Reorganizes the memory tree to keep it scannable without losing durable facts.
9
+
10
+ Run this when `compact-memory.sh` reports warnings, or proactively after dense work periods.
11
+
12
+ ---
13
+
14
+ ## Invariants -- never violate
15
+
16
+ - Every durable fact must survive compaction (move or merge, never delete)
17
+ - `Memory/MEMORY.md` must stay short and scannable
18
+ - Every branch folder must contain a same-name entry note (`<topic>/<topic>.md`)
19
+ - Evidence files are never touched during compaction
20
+
21
+ ---
22
+
23
+ ## Step 1 -- Audit
24
+
25
+ Run the report script first:
26
+
27
+ ```bash
28
+ scripts/compact-memory.sh /path/to/project
29
+ ```
30
+
31
+ Note which files are flagged as:
32
+ - `CRITICAL` (>200 lines) -- act immediately
33
+ - `WARNING` (>150 lines) -- split at next opportunity
34
+ - `stub or empty` -- populate or remove
35
+
36
+ ---
37
+
38
+ ## Step 2 -- Prune stale entries
39
+
40
+ In each branch note, remove or update entries that are:
41
+
42
+ - **Superseded**: a newer entry contradicts the old one -> remove the old, update the new
43
+ - **Dead reference**: refers to a path, API, or dependency that no longer exists -> remove
44
+ - **Speculation never confirmed**: still marked with "might", "probably", "TODO: verify" -> remove or move to Open Questions
45
+ - **Recent Changes too old**: entries older than ~4 weeks -> move stable facts to Current State, drop transient ones
46
+
47
+ Do not prune:
48
+ - Gotchas and lessons (even old ones are valuable if the risk still exists)
49
+ - Decision rationale (even for reversed decisions -- mark as `Status: reversed`)
50
+
51
+ ---
52
+
53
+ ## Step 3 -- Split large branch notes
54
+
55
+ If a branch note exceeds ~150 lines:
56
+
57
+ 1. Identify the dominant sub-topic that makes it large
58
+ 2. Promote the branch to a folder if it is still a flat note:
59
+ - Create `Memory/<topic>/` directory
60
+ - Move `Memory/<topic>.md` to `Memory/<topic>/<topic>.md`
61
+ 3. Create `Memory/<topic>/<subtopic>.md` for the extracted content
62
+ 4. Replace the moved section in the entry note with a link:
63
+ ```markdown
64
+ See [subtopic.md](subtopic.md) for details.
65
+ ```
66
+ 5. Update `Memory/MEMORY.md` branch link if the path changed
67
+
68
+ ---
69
+
70
+ ## Step 4 -- Merge overlapping thin notes
71
+
72
+ If two branch notes cover the same ground and together are under ~100 lines:
73
+
74
+ 1. Choose the name that better describes the combined scope
75
+ 2. Merge content, resolving any contradictions (newer wins)
76
+ 3. Delete the merged file
77
+ 4. Update `Memory/MEMORY.md` to remove the deleted entry and update the surviving one
78
+
79
+ ---
80
+
81
+ ## Step 5 -- Compact Memory/MEMORY.md
82
+
83
+ The root note must be scannable at a glance. Keep:
84
+
85
+ ```markdown
86
+ - one short summary per branch
87
+ - markdown links to the branch notes
88
+ - only the most useful open questions
89
+ ```
90
+
91
+ Remove:
92
+ - Branches with empty files that will not be populated
93
+ - Duplicate entries
94
+
95
+ Add:
96
+ - Any branch notes that exist but are not yet linked
97
+
98
+ ---
99
+
100
+ ## Step 6 -- Update decisions/decisions.md
101
+
102
+ Verify every file in `decisions/` is listed in `decisions/decisions.md`.
103
+ Remove entries for deleted decision files.
104
+ Mark superseded decisions with `~~strikethrough~~` or `[reversed]` in the log.
105
+
106
+ ---
107
+
108
+ ## Output checklist
109
+
110
+ - [ ] `compact-memory.sh` shows no CRITICAL or WARNING flags
111
+ - [ ] `Memory/MEMORY.md` is short and readable
112
+ - [ ] No branch note exceeds 150 lines
113
+ - [ ] All branch notes are linked from `Memory/MEMORY.md`
114
+ - [ ] Every branch folder has a same-name entry note
115
+ - [ ] `decisions/decisions.md` is current