cognitive-ledger 0.4.0__tar.gz
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.
- cognitive_ledger-0.4.0/.gitignore +31 -0
- cognitive_ledger-0.4.0/AGENTS.md +502 -0
- cognitive_ledger-0.4.0/CHANGELOG.md +221 -0
- cognitive_ledger-0.4.0/CLAUDE.md +1 -0
- cognitive_ledger-0.4.0/FIRSTRUN.md +35 -0
- cognitive_ledger-0.4.0/LICENSE +13 -0
- cognitive_ledger-0.4.0/PKG-INFO +22 -0
- cognitive_ledger-0.4.0/README.md +316 -0
- cognitive_ledger-0.4.0/cognitive_lightcone.png +0 -0
- cognitive_ledger-0.4.0/config.sample.yaml +32 -0
- cognitive_ledger-0.4.0/docs/ab/charts/hitk_over_time.png +0 -0
- cognitive_ledger-0.4.0/docs/ab/charts/mrr_over_time.png +0 -0
- cognitive_ledger-0.4.0/docs/ab/charts/p95_query_over_time.png +0 -0
- cognitive_ledger-0.4.0/docs/ab/performance_series.json +380 -0
- cognitive_ledger-0.4.0/ledger/__init__.py +31 -0
- cognitive_ledger-0.4.0/ledger/__main__.py +5 -0
- cognitive_ledger-0.4.0/ledger/ab.py +1383 -0
- cognitive_ledger-0.4.0/ledger/ab_charts.py +81 -0
- cognitive_ledger-0.4.0/ledger/ab_probe.py +258 -0
- cognitive_ledger-0.4.0/ledger/briefing.py +266 -0
- cognitive_ledger-0.4.0/ledger/browse.py +252 -0
- cognitive_ledger-0.4.0/ledger/cli.py +1306 -0
- cognitive_ledger-0.4.0/ledger/config.py +707 -0
- cognitive_ledger-0.4.0/ledger/context.py +346 -0
- cognitive_ledger-0.4.0/ledger/conventions.py +224 -0
- cognitive_ledger-0.4.0/ledger/doctor.py +105 -0
- cognitive_ledger-0.4.0/ledger/embeddings.py +941 -0
- cognitive_ledger-0.4.0/ledger/errors.py +244 -0
- cognitive_ledger-0.4.0/ledger/eval.py +538 -0
- cognitive_ledger-0.4.0/ledger/inbox.py +227 -0
- cognitive_ledger-0.4.0/ledger/ingest.py +216 -0
- cognitive_ledger-0.4.0/ledger/init.py +298 -0
- cognitive_ledger-0.4.0/ledger/io/__init__.py +23 -0
- cognitive_ledger-0.4.0/ledger/io/safe_write.py +348 -0
- cognitive_ledger-0.4.0/ledger/layout.py +155 -0
- cognitive_ledger-0.4.0/ledger/maintenance.py +1385 -0
- cognitive_ledger-0.4.0/ledger/notes/__init__.py +535 -0
- cognitive_ledger-0.4.0/ledger/obsidian/__init__.py +28 -0
- cognitive_ledger-0.4.0/ledger/obsidian/bases.py +66 -0
- cognitive_ledger-0.4.0/ledger/obsidian/cli.py +332 -0
- cognitive_ledger-0.4.0/ledger/obsidian/config.py +121 -0
- cognitive_ledger-0.4.0/ledger/obsidian/daemon.py +131 -0
- cognitive_ledger-0.4.0/ledger/obsidian/doctor.py +76 -0
- cognitive_ledger-0.4.0/ledger/obsidian/extraction.py +225 -0
- cognitive_ledger-0.4.0/ledger/obsidian/importer.py +507 -0
- cognitive_ledger-0.4.0/ledger/obsidian/layout.py +36 -0
- cognitive_ledger-0.4.0/ledger/obsidian/models.py +112 -0
- cognitive_ledger-0.4.0/ledger/obsidian/queue.py +125 -0
- cognitive_ledger-0.4.0/ledger/obsidian/state.py +47 -0
- cognitive_ledger-0.4.0/ledger/obsidian/utils.py +171 -0
- cognitive_ledger-0.4.0/ledger/obsidian/watch.py +74 -0
- cognitive_ledger-0.4.0/ledger/parsing/__init__.py +73 -0
- cognitive_ledger-0.4.0/ledger/parsing/frontmatter.py +362 -0
- cognitive_ledger-0.4.0/ledger/parsing/links.py +91 -0
- cognitive_ledger-0.4.0/ledger/parsing/privacy.py +55 -0
- cognitive_ledger-0.4.0/ledger/parsing/sections.py +149 -0
- cognitive_ledger-0.4.0/ledger/parsing/tokenizer.py +39 -0
- cognitive_ledger-0.4.0/ledger/query.py +682 -0
- cognitive_ledger-0.4.0/ledger/rerank.py +84 -0
- cognitive_ledger-0.4.0/ledger/retrieval.py +1377 -0
- cognitive_ledger-0.4.0/ledger/retrieval_types.py +79 -0
- cognitive_ledger-0.4.0/ledger/schema_values.py +16 -0
- cognitive_ledger-0.4.0/ledger/semantic.py +255 -0
- cognitive_ledger-0.4.0/ledger/signals.py +313 -0
- cognitive_ledger-0.4.0/ledger/timeline.py +187 -0
- cognitive_ledger-0.4.0/ledger/validation.py +285 -0
- cognitive_ledger-0.4.0/ledger/venv.py +46 -0
- cognitive_ledger-0.4.0/ledger/voice.py +161 -0
- cognitive_ledger-0.4.0/ledger/web/__init__.py +16 -0
- cognitive_ledger-0.4.0/ledger/web/routes/__init__.py +1 -0
- cognitive_ledger-0.4.0/ledger/web/routes/admin.py +93 -0
- cognitive_ledger-0.4.0/ledger/web/routes/browse.py +73 -0
- cognitive_ledger-0.4.0/ledger/web/routes/note.py +45 -0
- cognitive_ledger-0.4.0/ledger/web/routes/search.py +70 -0
- cognitive_ledger-0.4.0/ledger/web/server.py +148 -0
- cognitive_ledger-0.4.0/ledger/web/services/__init__.py +8 -0
- cognitive_ledger-0.4.0/ledger/web/services/corpus.py +275 -0
- cognitive_ledger-0.4.0/ledger/web/services/render.py +113 -0
- cognitive_ledger-0.4.0/ledger/web/services/search.py +188 -0
- cognitive_ledger-0.4.0/ledger/web/static/README.md +16 -0
- cognitive_ledger-0.4.0/ledger/web/static/htmx.min.js +1 -0
- cognitive_ledger-0.4.0/ledger/web/static/style.css +374 -0
- cognitive_ledger-0.4.0/ledger/web/templates/_search_results.html +33 -0
- cognitive_ledger-0.4.0/ledger/web/templates/base.html +70 -0
- cognitive_ledger-0.4.0/ledger/web/templates/browse.html +45 -0
- cognitive_ledger-0.4.0/ledger/web/templates/note.html +71 -0
- cognitive_ledger-0.4.0/ledger/web/templates/search.html +58 -0
- cognitive_ledger-0.4.0/package-lock.json +82 -0
- cognitive_ledger-0.4.0/package.json +14 -0
- cognitive_ledger-0.4.0/pyproject.toml +42 -0
- cognitive_ledger-0.4.0/schema.yaml +173 -0
- cognitive_ledger-0.4.0/scripts/add-to-path.sh +16 -0
- cognitive_ledger-0.4.0/scripts/build_ab_charts.py +13 -0
- cognitive_ledger-0.4.0/scripts/build_context.py +13 -0
- cognitive_ledger-0.4.0/scripts/build_context_profiles.py +13 -0
- cognitive_ledger-0.4.0/scripts/hooks/post_write.sh +78 -0
- cognitive_ledger-0.4.0/scripts/hooks/session_end.sh +71 -0
- cognitive_ledger-0.4.0/scripts/hooks/session_end_capture.py +240 -0
- cognitive_ledger-0.4.0/scripts/hooks/session_end_capture.sh +20 -0
- cognitive_ledger-0.4.0/scripts/hooks/session_start.sh +105 -0
- cognitive_ledger-0.4.0/scripts/setup-venv.sh +114 -0
- cognitive_ledger-0.4.0/scripts/sheep-auto.sh +78 -0
- cognitive_ledger-0.4.0/templates/generic_note_template.md +47 -0
- cognitive_ledger-0.4.0/templates/inbox_template.md +22 -0
- cognitive_ledger-0.4.0/templates/ingest_prompt_template.md +31 -0
- cognitive_ledger-0.4.0/templates/open_loop_template.md +39 -0
- cognitive_ledger-0.4.0/templates/voice_dna_template.md +35 -0
- cognitive_ledger-0.4.0/tests/conftest.py +194 -0
- cognitive_ledger-0.4.0/tests/fixtures/retrieval_eval_cases.yaml +14 -0
- cognitive_ledger-0.4.0/tests/test_activity_type.py +64 -0
- cognitive_ledger-0.4.0/tests/test_browse.py +56 -0
- cognitive_ledger-0.4.0/tests/test_cli.py +745 -0
- cognitive_ledger-0.4.0/tests/test_cli_doctor.py +47 -0
- cognitive_ledger-0.4.0/tests/test_cli_doctor_siblings.py +66 -0
- cognitive_ledger-0.4.0/tests/test_cli_init_envelope.py +76 -0
- cognitive_ledger-0.4.0/tests/test_cli_reserved_key.py +38 -0
- cognitive_ledger-0.4.0/tests/test_cli_sheep_json.py +63 -0
- cognitive_ledger-0.4.0/tests/test_config.py +343 -0
- cognitive_ledger-0.4.0/tests/test_context.py +117 -0
- cognitive_ledger-0.4.0/tests/test_context_profiles.py +112 -0
- cognitive_ledger-0.4.0/tests/test_conventions.py +177 -0
- cognitive_ledger-0.4.0/tests/test_cost_hints.py +46 -0
- cognitive_ledger-0.4.0/tests/test_errors.py +260 -0
- cognitive_ledger-0.4.0/tests/test_eval_helpers.py +71 -0
- cognitive_ledger-0.4.0/tests/test_inbox_voice_briefing.py +311 -0
- cognitive_ledger-0.4.0/tests/test_init.py +92 -0
- cognitive_ledger-0.4.0/tests/test_io.py +193 -0
- cognitive_ledger-0.4.0/tests/test_ledger.py +958 -0
- cognitive_ledger-0.4.0/tests/test_ledger_ab.py +619 -0
- cognitive_ledger-0.4.0/tests/test_ledger_embeddings.py +350 -0
- cognitive_ledger-0.4.0/tests/test_maintenance.py +270 -0
- cognitive_ledger-0.4.0/tests/test_notes.py +321 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_cli.py +171 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_daemon.py +60 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_doctor.py +204 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_dropin.py +184 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_exports.py +13 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_extraction.py +39 -0
- cognitive_ledger-0.4.0/tests/test_obsidian_queue.py +325 -0
- cognitive_ledger-0.4.0/tests/test_parsing.py +412 -0
- cognitive_ledger-0.4.0/tests/test_path_naming_refactor.py +162 -0
- cognitive_ledger-0.4.0/tests/test_privacy.py +68 -0
- cognitive_ledger-0.4.0/tests/test_qa_hardening.py +295 -0
- cognitive_ledger-0.4.0/tests/test_query.py +107 -0
- cognitive_ledger-0.4.0/tests/test_related_and_ingest.py +333 -0
- cognitive_ledger-0.4.0/tests/test_rerank_charts.py +170 -0
- cognitive_ledger-0.4.0/tests/test_retrieval_index.py +144 -0
- cognitive_ledger-0.4.0/tests/test_retrieval_types.py +252 -0
- cognitive_ledger-0.4.0/tests/test_scoring_extensions.py +281 -0
- cognitive_ledger-0.4.0/tests/test_semantic.py +127 -0
- cognitive_ledger-0.4.0/tests/test_session_end_capture.py +68 -0
- cognitive_ledger-0.4.0/tests/test_signals.py +247 -0
- cognitive_ledger-0.4.0/tests/test_timeline.py +57 -0
- cognitive_ledger-0.4.0/tests/test_validation.py +317 -0
- cognitive_ledger-0.4.0/tests/test_venv_helper.py +55 -0
- cognitive_ledger-0.4.0/tests/test_view_layers.py +183 -0
- cognitive_ledger-0.4.0/tests/web/__init__.py +0 -0
- cognitive_ledger-0.4.0/tests/web/conftest.py +142 -0
- cognitive_ledger-0.4.0/tests/web/test_admin.py +84 -0
- cognitive_ledger-0.4.0/tests/web/test_backlinks.py +130 -0
- cognitive_ledger-0.4.0/tests/web/test_routes.py +223 -0
- cognitive_ledger-0.4.0/tests/web/test_search.py +101 -0
- cognitive_ledger-0.4.0/uxl.config.mjs +173 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
node_modules/
|
|
3
|
+
dist/
|
|
4
|
+
.env
|
|
5
|
+
.vscode/
|
|
6
|
+
.obsidian/
|
|
7
|
+
.misc/
|
|
8
|
+
.tmp/
|
|
9
|
+
.plans/
|
|
10
|
+
# Claude worktrees
|
|
11
|
+
.claude/
|
|
12
|
+
.claude-mem/
|
|
13
|
+
# Ignore Smart Environment folder
|
|
14
|
+
.smart-env
|
|
15
|
+
# Build artifacts
|
|
16
|
+
build/
|
|
17
|
+
dist/
|
|
18
|
+
*.spec
|
|
19
|
+
.venv/
|
|
20
|
+
**__pycache__/
|
|
21
|
+
*.pyc
|
|
22
|
+
# Lock artifacts from safe_write
|
|
23
|
+
*.lock
|
|
24
|
+
# Repo-local notes-folder, should not be committed.
|
|
25
|
+
notes/*
|
|
26
|
+
config.yaml
|
|
27
|
+
# Local dev convenience symlink to the installed CLI (machine-specific, do not track)
|
|
28
|
+
/scripts/ledger
|
|
29
|
+
.coverage
|
|
30
|
+
# uxl artifacts (screenshots, reports, logs)
|
|
31
|
+
.uxl/
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
# Agent Instructions (Cognitive Ledger)
|
|
2
|
+
|
|
3
|
+
## Quick Reference
|
|
4
|
+
|
|
5
|
+
Machine-readable spec: `schema.yaml`. Note templates: `templates/`.
|
|
6
|
+
|
|
7
|
+
Resolve the active physical corpus path with `ledger paths --field ledger_notes_dir`.
|
|
8
|
+
Logical note references remain `notes/...` even when the corpus lives outside this repo.
|
|
9
|
+
|
|
10
|
+
The canonical `/notes` agent skill is maintained in a separate repository:
|
|
11
|
+
https://github.com/damsleth/SKILLS. Install it from there rather than
|
|
12
|
+
duplicating its contents here.
|
|
13
|
+
|
|
14
|
+
### Boot
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
LEDGER_NOTES_DIR="$(ledger paths --field ledger_notes_dir)"
|
|
18
|
+
ledger context --format boot # full boot payload (identity + loops + status)
|
|
19
|
+
tail -20 "$LEDGER_NOTES_DIR/08_indices/timeline.md" # recent changes
|
|
20
|
+
rg "<keyword>" "$LEDGER_NOTES_DIR" -n # search content (show matches)
|
|
21
|
+
fd "id__" "$LEDGER_NOTES_DIR/01_identity" # identity notes
|
|
22
|
+
fd "pref__" "$LEDGER_NOTES_DIR/03_preferences" && fd "concept__" "$LEDGER_NOTES_DIR/06_concepts" # search by type
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Two-tier lookup strategy:**
|
|
26
|
+
- `context.md` for boot (compact summary, always loaded at session start)
|
|
27
|
+
- `notes/08_indices/index.md` / `index.json` as a lookup table for deeper searches
|
|
28
|
+
(do NOT load into context at boot - on a mature ledger it would become the bottleneck)
|
|
29
|
+
|
|
30
|
+
**Voice DNA:** If `notes/01_identity/id__voice_dna.md` exists, read it at boot.
|
|
31
|
+
Apply the voice profile to tone, sentence structure, and vocabulary when writing notes.
|
|
32
|
+
|
|
33
|
+
**Non-negotiables:**
|
|
34
|
+
|
|
35
|
+
- No chat transcripts — ever
|
|
36
|
+
- No invented facts — use `source: inferred` + `confidence < 0.7`
|
|
37
|
+
- Always bump `updated` timestamp when editing
|
|
38
|
+
- Always append to `notes/08_indices/timeline.md` after any note operation
|
|
39
|
+
|
|
40
|
+
### Should I write?
|
|
41
|
+
|
|
42
|
+
Persist only if it's **durable** and **re-usable** (Decision / Preference / Correction / Goal / Concept / Open loop).
|
|
43
|
+
If none apply: don't write. Noise kills retrieval.
|
|
44
|
+
|
|
45
|
+
### Create or update a note
|
|
46
|
+
|
|
47
|
+
1. **Search first**: `rg "<topic>" notes -l`
|
|
48
|
+
2. **Create/update the right type** (atomic, one idea per file; use the right folder + prefix)
|
|
49
|
+
3. **Frontmatter required**: `created`, `updated`, `tags`, `confidence`, `source`, `scope`, `lang` (+ `status` for loops)
|
|
50
|
+
4. **No transcripts**: never store raw chat logs; summarize into atomic notes
|
|
51
|
+
5. **Append timeline**: `echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) | <verb> | <path> | <why>" >> notes/08_indices/timeline.md`
|
|
52
|
+
|
|
53
|
+
### Python env
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
./scripts/setup-venv.sh # default: base + dev + embeddings
|
|
57
|
+
./scripts/setup-venv.sh --python python3.12 --recreate # if torch wheels are missing
|
|
58
|
+
./scripts/setup-venv.sh --minimal # base-only fallback
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Obsidian Drop-In
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pipx install cognitive-ledger
|
|
65
|
+
ledger-obsidian init --vault /path/to/obsidian-vault
|
|
66
|
+
ledger-obsidian import --vault /path/to/obsidian-vault
|
|
67
|
+
ledger-obsidian bootstrap --root ~/Code/notes
|
|
68
|
+
ledger-obsidian watch --vault /path/to/obsidian-vault
|
|
69
|
+
ledger-obsidian queue sync --vault /path/to/obsidian-vault
|
|
70
|
+
ledger-obsidian doctor --vault /path/to/obsidian-vault
|
|
71
|
+
ledger-obsidian daemon start|status|stop --vault /path/to/vault # macOS
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Retrieve & Eval
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
ledger query "<topic>" --scope all --limit 8
|
|
78
|
+
ledger query "<topic>" --scope all --limit 8 --retrieval-mode <mode>
|
|
79
|
+
ledger query "<topic>" --scope dev --bundle
|
|
80
|
+
ledger discover-source "<topic>" --source-notes-dir <root> --limit 20
|
|
81
|
+
ledger embed build --target ledger --backend local --model TaylorAI/bge-micro-v2
|
|
82
|
+
ledger embed status --target both
|
|
83
|
+
ledger eval --cases "$(ledger paths --field ledger_notes_dir)/08_indices/retrieval_eval_cases.yaml" --k 3 --strict-cases
|
|
84
|
+
ledger loops # compact list (default)
|
|
85
|
+
ledger notes --type <all|identity|facts|preferences|goals|loops|concepts>
|
|
86
|
+
ledger context --format boot # session boot payload
|
|
87
|
+
ledger context --format identity # identity notes only
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Signals (Feedback Loop)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
ledger signal add --type retrieval_hit --query "deploy" --note notes/02_facts/fact__k8s.md
|
|
94
|
+
ledger signal add --type correction --note notes/03_preferences/pref__x.md --detail "outdated"
|
|
95
|
+
ledger signal add --type rating --rating 8
|
|
96
|
+
ledger signal summarize # rebuild signal_summary.json
|
|
97
|
+
ledger signal stats # show signal counts, top notes, gaps
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Signal types: `retrieval_hit`, `retrieval_miss`, `correction`, `affirmation`,
|
|
101
|
+
`stale_flag`, `preference_applied`, `rating`.
|
|
102
|
+
|
|
103
|
+
`<mode>`: `legacy`, `two_stage`, `scope_type_prefilter`, `precomputed_index`, `progressive_disclosure`, `semantic_hybrid`.
|
|
104
|
+
|
|
105
|
+
### A/B Testing
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
ledger ab run --baseline-ref main --candidate-ref HEAD # uses ledger_notes_dir from config.yaml
|
|
109
|
+
ledger ab run --corpus ~/Code/ledger-notes --baseline-ref main --candidate-ref HEAD
|
|
110
|
+
ledger ab run --baseline-ref main --candidate-ref HEAD --eval-runs 7 --query-runs 5
|
|
111
|
+
ledger ab run --baseline-ref main --candidate-ref HEAD --query-runs 5 --cold-query
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Exit codes: `0` beneficial, `2` regression, `3` neutral, `4` invalid setup.
|
|
115
|
+
|
|
116
|
+
### Electric Sheep (sleep / consolidation)
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
ledger sleep status
|
|
120
|
+
ledger sleep sync --check && ledger sleep sync --apply
|
|
121
|
+
ledger sleep sleep
|
|
122
|
+
ledger sleep lint
|
|
123
|
+
ledger sleep index
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Folder map
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
notes/01_identity/ core identity: mission, beliefs, models, strategies, narratives
|
|
130
|
+
notes/02_facts/ stable truths / decisions
|
|
131
|
+
notes/03_preferences/ user preferences / policies
|
|
132
|
+
notes/04_goals/ long-lived objectives
|
|
133
|
+
notes/05_open_loops/ durable unresolved items (status lifecycle)
|
|
134
|
+
notes/06_concepts/ definitions / frameworks / mental models
|
|
135
|
+
notes/08_indices/ timeline, logs, import state, generated indexes, signals
|
|
136
|
+
notes/09_archive/ superseded notes (do not delete)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### Recommended Setup
|
|
142
|
+
|
|
143
|
+
**Claude Code hooks** (`.claude/settings.json`):
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"hooks": {
|
|
147
|
+
"SessionStart": [
|
|
148
|
+
{"type": "command", "command": "bash scripts/hooks/session_start.sh"}
|
|
149
|
+
],
|
|
150
|
+
"Notification": [
|
|
151
|
+
{"type": "command", "command": "bash scripts/hooks/session_end_capture.sh"}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Codex** (`AGENTS.md` in repo root already covers this).
|
|
158
|
+
|
|
159
|
+
**Automated maintenance** (cron or Claude Code `/schedule`):
|
|
160
|
+
```
|
|
161
|
+
0 6 * * * /path/to/cognitive-ledger/scripts/sheep-auto.sh
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Troubleshooting:**
|
|
165
|
+
- If hooks don't fire: check that scripts are executable (`chmod +x scripts/hooks/*.sh`)
|
|
166
|
+
- If venv is missing: run `./scripts/setup-venv.sh`
|
|
167
|
+
- If session_start is slow: ensure `.venv` exists (avoids pip install on each run)
|
|
168
|
+
- If capture creates too many inbox items: review and triage with `ledger inbox triage`
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Purpose
|
|
173
|
+
|
|
174
|
+
This repository implements a **Cognitive Ledger**: a persistent, file-based
|
|
175
|
+
memory system to extend the temporal reach of language models and their users.
|
|
176
|
+
Agents interacting with this repo are responsible for maintaining the
|
|
177
|
+
integrity, readability and usefulness of the notes. The goal is to build a
|
|
178
|
+
rich, inspectable history of reasoning, preferences, decisions and concepts
|
|
179
|
+
that can be reused across sessions without blowing up context windows.
|
|
180
|
+
|
|
181
|
+
### North Star (how this is used in practice)
|
|
182
|
+
|
|
183
|
+
When the cog-led skill is active, the agent should:
|
|
184
|
+
|
|
185
|
+
1. **Interpret the conversation as it happens** and decide whether to persist durable artifacts (facts/prefs/goals/concepts/loops).
|
|
186
|
+
2. **Use the ledger as externalized memory** (metadata + `rg`/`fd` + indices) to avoid bloating the context window.
|
|
187
|
+
3. Provide **ledger-enriched answers**: continuity, suggestions, and knowledge informed by relevant artifacts.
|
|
188
|
+
|
|
189
|
+
The ledger should maintain cohesion as it grows via periodic consolidation (“Electric Sheep”).
|
|
190
|
+
|
|
191
|
+
## Golden rules
|
|
192
|
+
|
|
193
|
+
1. **Never store raw chat logs.** Summarize conversations into atomic
|
|
194
|
+
notes (facts/preferences/goals/concepts/open loops). Full transcripts
|
|
195
|
+
are prohibited.
|
|
196
|
+
2. **Never invent facts.** If you are unsure about a claim, write it as a
|
|
197
|
+
hypothesis with a confidence < 0.7. Only facts from the user or tools
|
|
198
|
+
should have high confidence.
|
|
199
|
+
3. **One idea per file.** Keep notes atomic so they are easy to find,
|
|
200
|
+
update and reason about. Use relative links to connect ideas.
|
|
201
|
+
4. **Search before you write.** Use command-line tools (e.g. `rg` or
|
|
202
|
+
`fd`) to look for existing notes with similar titles or tags. If a
|
|
203
|
+
related note exists, update or link to it instead of creating a
|
|
204
|
+
duplicate.
|
|
205
|
+
5. **Respect scopes and the user's personalization preferences.**
|
|
206
|
+
This ledger may store user-specific details and personal analytics when it is useful.
|
|
207
|
+
Avoid needless hoarding; prefer durable, structured facts/preferences.
|
|
208
|
+
If a detail feels unusually sensitive or ambiguous, ask.
|
|
209
|
+
6. **Append before overwrite.** When updating a note, bump the `updated`
|
|
210
|
+
timestamp and adjust sections; avoid deleting history. If a note is
|
|
211
|
+
superseded, move it to `/notes/09_archive/` instead of deleting it.
|
|
212
|
+
|
|
213
|
+
## Folder layout
|
|
214
|
+
|
|
215
|
+
The repository is organised under `notes/`. Subfolders group notes by
|
|
216
|
+
purpose:
|
|
217
|
+
|
|
218
|
+
| Folder | Purpose |
|
|
219
|
+
| ----------------- | -------------------------------------------------------- |
|
|
220
|
+
| `00_inbox/` | Temporary capture zone. Notes here should be reviewed |
|
|
221
|
+
| | and either promoted or discarded during consolidation. |
|
|
222
|
+
| `01_identity/` | Core identity documents (mission, beliefs, mental |
|
|
223
|
+
| | models, strategies, narratives). Max 5 files. |
|
|
224
|
+
| `02_facts/` | Stable truths sourced from the user or external tools. |
|
|
225
|
+
| `03_preferences/` | Recorded user preferences, styles or habits. |
|
|
226
|
+
| `04_goals/` | Long-term objectives and commitments. |
|
|
227
|
+
| `05_open_loops/` | Unresolved questions or tasks with next actions. |
|
|
228
|
+
| `06_concepts/` | Definitions of frameworks or models (e.g. cognitive |
|
|
229
|
+
| | lightcone). |
|
|
230
|
+
| `07_projects/` | Subfolders for project-specific notes. Create as needed. |
|
|
231
|
+
| `08_indices/` | Generated indices like timelines or tag maps. |
|
|
232
|
+
| `09_archive/` | Superseded or obsolete notes. |
|
|
233
|
+
|
|
234
|
+
## Note conventions
|
|
235
|
+
|
|
236
|
+
### Frontmatter
|
|
237
|
+
|
|
238
|
+
All atomic notes require YAML frontmatter. See `schema.yaml` for machine-readable
|
|
239
|
+
specification. Required fields:
|
|
240
|
+
|
|
241
|
+
| Field | Format | Notes |
|
|
242
|
+
| ---------- | ------------ | ---------------------------------------------- |
|
|
243
|
+
| created | ISO 8601 UTC | `2026-01-20T12:00:00Z` |
|
|
244
|
+
| updated | ISO 8601 UTC | bump on every edit |
|
|
245
|
+
| tags | list | lowercase, no spaces |
|
|
246
|
+
| confidence | 0.0–1.0 | <0.7 = hypothesis |
|
|
247
|
+
| source | enum | user, tool, assistant, inferred |
|
|
248
|
+
| scope | enum | home, work, dev, personal, life (alias), meta |
|
|
249
|
+
| lang | enum | en, no, mixed |
|
|
250
|
+
| status | enum | **loops only**: open, closed, blocked, snoozed |
|
|
251
|
+
|
|
252
|
+
### File naming
|
|
253
|
+
|
|
254
|
+
Pattern: `{type}__{slug}.md` where slug is lowercase with underscores.
|
|
255
|
+
|
|
256
|
+
| Type | Prefix | Folder |
|
|
257
|
+
| ---------- | ----------- | ----------------------------------- |
|
|
258
|
+
| identity | `id__` | `notes/01_identity/` |
|
|
259
|
+
| fact | `fact__` | `notes/02_facts/` |
|
|
260
|
+
| preference | `pref__` | `notes/03_preferences/` |
|
|
261
|
+
| goal | `goal__` | `notes/04_goals/` |
|
|
262
|
+
| open loop | `loop__` | `notes/05_open_loops/` |
|
|
263
|
+
| concept | `concept__` | `notes/06_concepts/` |
|
|
264
|
+
|
|
265
|
+
### Creating a note (convention)
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
1. SEARCH rg "<topic>" notes -l && fd "<topic>" notes
|
|
269
|
+
2. DECIDE If exists: update. If not: create.
|
|
270
|
+
3. PATH notes/{folder}/{type}__{slug}.md
|
|
271
|
+
4. WRITE Frontmatter + content (use template as reference)
|
|
272
|
+
5. TIMELINE echo "{ts} | created | {path} | {desc}" >> notes/08_indices/timeline.md
|
|
273
|
+
6. VERIFY git diff
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Timeline format: `{ISO timestamp} | {action} | {path} | {description}`
|
|
277
|
+
Actions: created, updated, archived, deleted, closed, sleep
|
|
278
|
+
|
|
279
|
+
### Templates
|
|
280
|
+
|
|
281
|
+
Reusable Markdown templates are provided under `templates/` for convenience:
|
|
282
|
+
|
|
283
|
+
- `generic_note_template.md` – for atomic notes (facts, preferences,
|
|
284
|
+
goals, concepts). Contains sections for Statement, Context, Implications
|
|
285
|
+
and Links.
|
|
286
|
+
- `open_loop_template.md` – for unresolved questions or tasks, including
|
|
287
|
+
status and next actions.
|
|
288
|
+
|
|
289
|
+
Agents may copy from these templates when creating new notes, but should
|
|
290
|
+
always customise the content and metadata.
|
|
291
|
+
|
|
292
|
+
## Triggers for writing
|
|
293
|
+
|
|
294
|
+
Write or update a note when any of the following events occur:
|
|
295
|
+
|
|
296
|
+
1. **Decision** – A concrete choice is made (e.g. selecting a name or
|
|
297
|
+
adopting a strategy).
|
|
298
|
+
2. **Preference** – The user expresses a stable preference or style.
|
|
299
|
+
3. **Correction** – A prior belief is corrected or clarified.
|
|
300
|
+
4. **Long-lived goal or constraint** – A new objective or invariant is set.
|
|
301
|
+
5. **New concept or framework** – You define or discover a useful concept.
|
|
302
|
+
6. **Open loop** – An unresolved question or task arises that spans
|
|
303
|
+
sessions.
|
|
304
|
+
7. **Identity change** – The user expresses a core belief, mission shift,
|
|
305
|
+
strategic heuristic, or narrative reframing → persist to identity layer.
|
|
306
|
+
|
|
307
|
+
If none of these triggers fire, do not persist anything. Noise kills
|
|
308
|
+
future context.
|
|
309
|
+
|
|
310
|
+
### Signal capture (feedback loop)
|
|
311
|
+
|
|
312
|
+
In addition to note writes, capture feedback signals when:
|
|
313
|
+
|
|
314
|
+
- A retrieved note was **used** in a response → `retrieval_hit`
|
|
315
|
+
- A search found **nothing useful** → `retrieval_miss`
|
|
316
|
+
- The user **corrects** the agent's use of a note → `correction`
|
|
317
|
+
- The user **confirms** the agent got it right → `affirmation`
|
|
318
|
+
- A note is referenced but its content is **outdated** → `stale_flag`
|
|
319
|
+
|
|
320
|
+
Capture via: `ledger signal add --type <type> [--query <q>] [--note <path>]`
|
|
321
|
+
|
|
322
|
+
Do NOT capture signals speculatively or for trivial queries. Only log when
|
|
323
|
+
there is clear user feedback or deliberate note usage.
|
|
324
|
+
|
|
325
|
+
## Cross-agent handoff (cross-agentism)
|
|
326
|
+
|
|
327
|
+
This ledger is designed to be **cross-agentic** (Codex / VSCode / Claude Code / future agents).
|
|
328
|
+
Notes must be understandable and useful without prior chat context.
|
|
329
|
+
|
|
330
|
+
When the user says “remember this”, “hold that thought”, “store this”, or similar:
|
|
331
|
+
|
|
332
|
+
- Persist the **smallest durable artifact(s)** that preserve the thread.
|
|
333
|
+
- Prefer atomic notes + links over long summaries.
|
|
334
|
+
- If the thread should be resumed later, create or update an open loop with:
|
|
335
|
+
- a clear next action,
|
|
336
|
+
- and an exit condition.
|
|
337
|
+
|
|
338
|
+
Goal: another agent can resume by searching (`rg`/`fd`), reading 1–3 atomic notes,
|
|
339
|
+
and continuing without loading a large context window.
|
|
340
|
+
|
|
341
|
+
## Operating loop for each interaction
|
|
342
|
+
|
|
343
|
+
Agents should follow this loop on every user interaction:
|
|
344
|
+
|
|
345
|
+
1. **Search** – Identify relevant context:
|
|
346
|
+
- Use `fd` to locate candidate files by name or tag; use `rg` to search
|
|
347
|
+
within files for keywords. Combine tag filters and keywords to
|
|
348
|
+
narrow down the search space.
|
|
349
|
+
- Load only what is necessary; avoid concatenating entire archives into
|
|
350
|
+
the prompt. Keep the working set small to preserve context window.
|
|
351
|
+
- Identity notes (`notes/01_identity/`) are always relevant context;
|
|
352
|
+
load them early in the session if not already loaded.
|
|
353
|
+
2. **Respond** – Generate the user-facing answer or action.
|
|
354
|
+
3. **Persist** – If a trigger fires:
|
|
355
|
+
- Draft a new note using the appropriate template, or update an
|
|
356
|
+
existing note. Populate the frontmatter and relevant sections.
|
|
357
|
+
- Update the `updated` timestamp whenever modifying a note.
|
|
358
|
+
- For open loops, add a `next action` checklist item to guide the
|
|
359
|
+
resolution.
|
|
360
|
+
- Keep cross-agent readability in mind: write so a different agent can pick up the thread
|
|
361
|
+
using only the ledger + search tools.
|
|
362
|
+
4. **Signal** – If user feedback occurred (correction, affirmation, or
|
|
363
|
+
explicit rating), or a retrieved note was used in the response, log a
|
|
364
|
+
signal via `ledger signal add`. See "Signal capture" above.
|
|
365
|
+
5. **Report** – Summarise what you changed. In the chat, list any
|
|
366
|
+
created or updated files with a one-line description. Do not dump
|
|
367
|
+
the full note contents unless the user asks.
|
|
368
|
+
|
|
369
|
+
## Session Lifecycle Hooks
|
|
370
|
+
|
|
371
|
+
Hook scripts under `scripts/hooks/` automate common session patterns:
|
|
372
|
+
|
|
373
|
+
| Hook | Script | Purpose |
|
|
374
|
+
| ------------------ | ------------------------------- | -------------------------------------------- |
|
|
375
|
+
| **session-start** | `scripts/hooks/session_start.sh` | Load boot context: identity + loops + status |
|
|
376
|
+
| **post-write** | `scripts/hooks/post_write.sh` | Append timeline entry after note operations |
|
|
377
|
+
| **session-end** | `scripts/hooks/session_end.sh` | Flush signals, report session activity |
|
|
378
|
+
|
|
379
|
+
Manual invocation: `bash scripts/hooks/session_start.sh`
|
|
380
|
+
|
|
381
|
+
For Claude Code integration, configure in `.claude/settings.json`:
|
|
382
|
+
```jsonc
|
|
383
|
+
{
|
|
384
|
+
"hooks": {
|
|
385
|
+
"SessionStart": [{"type": "command", "command": "bash scripts/hooks/session_start.sh"}]
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Identity Layer
|
|
391
|
+
|
|
392
|
+
Identity notes in `notes/01_identity/` capture *who the user is* — their
|
|
393
|
+
mission, beliefs, mental models, decision strategies, and personal narratives.
|
|
394
|
+
These are high-signal, small files that provide rich context for interpreting
|
|
395
|
+
requests.
|
|
396
|
+
|
|
397
|
+
- Max 5 files (one per `identity_type`: mission, beliefs, models, strategies, narratives)
|
|
398
|
+
- Always loaded at boot (via context profile or session-start hook)
|
|
399
|
+
- Receive a retrieval score boost (identity notes surface above similarly-relevant notes)
|
|
400
|
+
- Distinct from `06_concepts/` (general frameworks) — identity is *personal* axioms
|
|
401
|
+
|
|
402
|
+
When to update: mission shifts, new beliefs, changed decision heuristics, or
|
|
403
|
+
narrative reframing. Flag identity notes >90 days old during consolidation.
|
|
404
|
+
|
|
405
|
+
## Tooling hints
|
|
406
|
+
|
|
407
|
+
To operate efficiently without exhausting context windows, lean on
|
|
408
|
+
standard command-line tools:
|
|
409
|
+
|
|
410
|
+
- **`fd`** – Fast, user-friendly file finder. Example: `fd open_loop pref__`.
|
|
411
|
+
- **`rg` (ripgrep)** – Recursively search for keywords or tags inside files.
|
|
412
|
+
Example: `rg "tags: \[.*ai.*\]"` to find notes tagged with `ai`.
|
|
413
|
+
- **`git diff`** – Inspect uncommitted changes before reporting them.
|
|
414
|
+
- **`git log`** – Review history and reconstruct timelines. Combined with
|
|
415
|
+
commit messages, this forms an append-only ledger.
|
|
416
|
+
- **`wc`** – Estimate token counts quickly (`wc -w`) to avoid exceeding
|
|
417
|
+
context limits.
|
|
418
|
+
|
|
419
|
+
Prefer these tools to complex frameworks. Simplicity makes it easier for
|
|
420
|
+
future agents to understand and extend the system.
|
|
421
|
+
|
|
422
|
+
## Electric Sheep (sleep / consolidation)
|
|
423
|
+
|
|
424
|
+
The ledger must maintain cohesion as it grows. Consolidation ("sleep") is the primary tool for preventing drift and fragmentation. Commands are listed in the Quick Reference above.
|
|
425
|
+
|
|
426
|
+
Run sleep when:
|
|
427
|
+
|
|
428
|
+
- many new artifacts were created recently,
|
|
429
|
+
- duplicates start appearing,
|
|
430
|
+
- concepts are fragmented across many notes,
|
|
431
|
+
- open loops proliferate without clear next actions,
|
|
432
|
+
- or on a periodic schedule (see `schema.yaml` limits: sleep interval and change threshold).
|
|
433
|
+
|
|
434
|
+
Expected behaviors:
|
|
435
|
+
|
|
436
|
+
- merge duplicates (preserve provenance; prefer oldest canonical note),
|
|
437
|
+
- promote repeated patterns into stable concepts/preferences,
|
|
438
|
+
- update indices (timeline, tags, loop summaries),
|
|
439
|
+
- clarify open loops (tighten statements; add next actions; adjust status),
|
|
440
|
+
- surface conflicts as explicit open loops ("needs decision").
|
|
441
|
+
|
|
442
|
+
## Safety & control
|
|
443
|
+
|
|
444
|
+
At any point, the user may request to delete or forget a note. When this
|
|
445
|
+
happens:
|
|
446
|
+
|
|
447
|
+
1. Remove the file from its current location.
|
|
448
|
+
2. Remove or update any links pointing to it.
|
|
449
|
+
3. Append a `deleted` entry to `notes/08_indices/timeline.md`.
|
|
450
|
+
4. Do not move the note to `09_archive/` for delete/forget requests; treat these as hard-deletes.
|
|
451
|
+
|
|
452
|
+
If you are unsure whether to persist something, either ask the user or
|
|
453
|
+
store it as a low-confidence hypothesis. Respect the user's privacy and
|
|
454
|
+
preferences throughout.
|
|
455
|
+
|
|
456
|
+
## Write modes (interaction policy)
|
|
457
|
+
|
|
458
|
+
Different environments may prefer different degrees of visibility.
|
|
459
|
+
|
|
460
|
+
- **Auto-write:** persist high-confidence durable artifacts without asking.
|
|
461
|
+
- **Silent write:** do not show diffs by default; rely on git for reversibility.
|
|
462
|
+
- **Ask-to-write:** ask before persisting when uncertain or sensitive.
|
|
463
|
+
|
|
464
|
+
Default preference (unless the user requests otherwise): **Auto-write + Silent write**,
|
|
465
|
+
asking only for genuinely ambiguous items.
|
|
466
|
+
|
|
467
|
+
## Output expectations
|
|
468
|
+
|
|
469
|
+
When you modify the ledger within a session:
|
|
470
|
+
|
|
471
|
+
- Provide a succinct summary of changes. Include the relative path of
|
|
472
|
+
each created or updated note and a one-line description. For example:
|
|
473
|
+
|
|
474
|
+
> Created `02_facts/fact__cognitive_ledger.md` – defined the Cognitive Ledger concept
|
|
475
|
+
|
|
476
|
+
> Updated `03_preferences/pref__concise_answers.md` – lowered confidence to 0.6
|
|
477
|
+
|
|
478
|
+
- Do **not** paste entire file contents unless explicitly requested.
|
|
479
|
+
|
|
480
|
+
If the user has requested silent operation, keep the report minimal (e.g. “logged to cog-led”),
|
|
481
|
+
but still remain correct and reversible via git history.
|
|
482
|
+
|
|
483
|
+
These conventions maintain transparency without flooding the user or
|
|
484
|
+
future agents with unnecessary text.
|
|
485
|
+
|
|
486
|
+
## Keeping docs in sync
|
|
487
|
+
|
|
488
|
+
When you make changes to the ledger's **infrastructure** (new note types,
|
|
489
|
+
config parameters, retrieval modes, CLI subcommands, schema changes, hooks,
|
|
490
|
+
or other user-facing features):
|
|
491
|
+
|
|
492
|
+
1. **`CHANGELOG.md`** – Append an entry under the current date. Use
|
|
493
|
+
`### Added`, `### Changed`, `### Fixed`, or `### Removed` headings
|
|
494
|
+
(keep-a-changelog style). One bullet per distinct change.
|
|
495
|
+
2. **`README.md`** – Update if the change affects getting-started steps,
|
|
496
|
+
folder layout, CLI examples, or introduces a new top-level feature
|
|
497
|
+
section. Keep the README concise; link to `AGENTS.md` or `schema.yaml`
|
|
498
|
+
for details.
|
|
499
|
+
|
|
500
|
+
Do **not** update these files for routine note operations (creating,
|
|
501
|
+
updating, or archiving individual notes). Only infrastructure and tooling
|
|
502
|
+
changes warrant doc updates.
|