counterparts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/CONSTITUTION.md +68 -0
  2. package/LICENSE +21 -0
  3. package/README.md +348 -0
  4. package/docs/ELI5.md +84 -0
  5. package/docs/QUICKSTART.md +1258 -0
  6. package/docs/module-map.md +81 -0
  7. package/package.json +63 -0
  8. package/src/adapters/claude-code/CONTRACT.md +606 -0
  9. package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
  10. package/src/adapters/claude-code/NOTES.md +1055 -0
  11. package/src/adapters/claude-code/bin/hook.ts +820 -0
  12. package/src/adapters/claude-code/bin/runner.ts +522 -0
  13. package/src/adapters/claude-code/config.ts +778 -0
  14. package/src/adapters/claude-code/credentials.ts +199 -0
  15. package/src/adapters/claude-code/doctor.ts +2557 -0
  16. package/src/adapters/claude-code/embed-client.ts +617 -0
  17. package/src/adapters/claude-code/hooks.ts +2240 -0
  18. package/src/adapters/claude-code/index.ts +224 -0
  19. package/src/adapters/claude-code/interpret-client.ts +395 -0
  20. package/src/adapters/claude-code/page-writer.ts +462 -0
  21. package/src/adapters/claude-code/primacy.ts +162 -0
  22. package/src/adapters/claude-code/spawn.ts +241 -0
  23. package/src/adapters/claude-code/standdown.ts +536 -0
  24. package/src/adapters/claude-code/transcript.ts +661 -0
  25. package/src/adapters/claude-code/vectors.ts +415 -0
  26. package/src/adapters/cli/CONTRACT.md +255 -0
  27. package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
  28. package/src/adapters/cli/NOTES.md +936 -0
  29. package/src/adapters/cli/bin/counterparts.ts +74 -0
  30. package/src/adapters/cli/commands.ts +6095 -0
  31. package/src/adapters/cli/export.ts +766 -0
  32. package/src/adapters/cli/index.ts +103 -0
  33. package/src/adapters/cli/install.ts +670 -0
  34. package/src/adapters/cli/removal.ts +1186 -0
  35. package/src/adapters/cli/repair-dates.ts +659 -0
  36. package/src/adapters/cli/self-page.ts +229 -0
  37. package/src/adapters/cli/snapshot.ts +279 -0
  38. package/src/adapters/cli/start-fresh.ts +1228 -0
  39. package/src/adapters/config-path.ts +342 -0
  40. package/src/adapters/dashboard/CONTRACT.md +67 -0
  41. package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
  42. package/src/adapters/dashboard/NOTES.md +474 -0
  43. package/src/adapters/dashboard/activity.ts +121 -0
  44. package/src/adapters/dashboard/ansi.ts +82 -0
  45. package/src/adapters/dashboard/bin/dashboard.ts +479 -0
  46. package/src/adapters/dashboard/browse.ts +298 -0
  47. package/src/adapters/dashboard/identity.ts +182 -0
  48. package/src/adapters/dashboard/index.ts +183 -0
  49. package/src/adapters/dashboard/layout.ts +149 -0
  50. package/src/adapters/dashboard/registries.ts +291 -0
  51. package/src/adapters/dashboard/resolve.ts +206 -0
  52. package/src/adapters/dashboard/source.ts +48 -0
  53. package/src/adapters/dashboard/status.ts +327 -0
  54. package/src/adapters/dashboard/stories.ts +194 -0
  55. package/src/adapters/dashboard/web/app.html +1731 -0
  56. package/src/adapters/dashboard/web/brain.html +463 -0
  57. package/src/adapters/dashboard/web/fired.ts +31 -0
  58. package/src/adapters/dashboard/web/flow.ts +457 -0
  59. package/src/adapters/dashboard/web/narrate.ts +1042 -0
  60. package/src/adapters/dashboard/web/reveal.ts +135 -0
  61. package/src/adapters/dashboard/web/server.ts +287 -0
  62. package/src/adapters/dashboard/web/views.ts +1744 -0
  63. package/src/adapters/expansions.ts +569 -0
  64. package/src/adapters/fired.ts +1580 -0
  65. package/src/adapters/mcp/CONTRACT.md +240 -0
  66. package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
  67. package/src/adapters/mcp/NOTES.md +205 -0
  68. package/src/adapters/mcp/bin/serve.ts +349 -0
  69. package/src/adapters/mcp/deliberate.ts +619 -0
  70. package/src/adapters/mcp/index.ts +101 -0
  71. package/src/adapters/mcp/protocol.ts +170 -0
  72. package/src/adapters/mcp/server.ts +1740 -0
  73. package/src/adapters/mcp/stdio.ts +56 -0
  74. package/src/adapters/mcp/tools.ts +779 -0
  75. package/src/adapters/scopes.ts +657 -0
  76. package/src/adapters/sessions.ts +402 -0
  77. package/src/adapters/snapshots.ts +1069 -0
  78. package/src/adapters/stance-env.ts +137 -0
  79. package/src/core/associate/CONTRACT.md +118 -0
  80. package/src/core/associate/INTERFACE-GAPS.md +173 -0
  81. package/src/core/associate/NOTES.md +194 -0
  82. package/src/core/associate/buffer.ts +66 -0
  83. package/src/core/associate/edges.ts +188 -0
  84. package/src/core/associate/index.ts +570 -0
  85. package/src/core/associate/pending.ts +383 -0
  86. package/src/core/associate/spread.ts +149 -0
  87. package/src/core/associate/tunables.ts +123 -0
  88. package/src/core/bridge.ts +272 -0
  89. package/src/core/briefing.ts +67 -0
  90. package/src/core/counterpart.ts +3855 -0
  91. package/src/core/encode/CONTRACT.md +151 -0
  92. package/src/core/encode/INTERFACE-GAPS.md +135 -0
  93. package/src/core/encode/NOTES.md +146 -0
  94. package/src/core/encode/aliases.ts +71 -0
  95. package/src/core/encode/battery.ts +284 -0
  96. package/src/core/encode/chunk.ts +265 -0
  97. package/src/core/encode/emotion.ts +119 -0
  98. package/src/core/encode/floor.ts +76 -0
  99. package/src/core/encode/index.ts +100 -0
  100. package/src/core/encode/precision.ts +162 -0
  101. package/src/core/encode/preselect.ts +269 -0
  102. package/src/core/encode/salience.ts +108 -0
  103. package/src/core/encode/secrets.ts +265 -0
  104. package/src/core/encode/tunables.ts +99 -0
  105. package/src/core/encode/types.ts +286 -0
  106. package/src/core/encode/words.ts +75 -0
  107. package/src/core/handoff/CONTRACT.md +199 -0
  108. package/src/core/handoff/INTERFACE-GAPS.md +166 -0
  109. package/src/core/handoff/NOTES.md +206 -0
  110. package/src/core/handoff/index.ts +957 -0
  111. package/src/core/mint.ts +279 -0
  112. package/src/core/observer.ts +28 -0
  113. package/src/core/physics/CONTRACT.md +341 -0
  114. package/src/core/physics/NOTES.md +155 -0
  115. package/src/core/physics/clock.ts +51 -0
  116. package/src/core/physics/index.ts +1054 -0
  117. package/src/core/prospective/CONTRACT.md +137 -0
  118. package/src/core/prospective/INTERFACE-GAPS.md +112 -0
  119. package/src/core/prospective/NOTES.md +160 -0
  120. package/src/core/prospective/derive.ts +188 -0
  121. package/src/core/prospective/index.ts +1030 -0
  122. package/src/core/prospective/tunables.ts +72 -0
  123. package/src/core/prospective/windows.ts +187 -0
  124. package/src/core/recall/CONTRACT.md +326 -0
  125. package/src/core/recall/INTERFACE-GAPS.md +163 -0
  126. package/src/core/recall/NOTES.md +472 -0
  127. package/src/core/recall/activate.ts +521 -0
  128. package/src/core/recall/cues.ts +275 -0
  129. package/src/core/recall/gate.ts +441 -0
  130. package/src/core/recall/index.ts +692 -0
  131. package/src/core/recall/probe.ts +239 -0
  132. package/src/core/recall/reference.ts +201 -0
  133. package/src/core/recall/render.ts +285 -0
  134. package/src/core/recall/session.ts +403 -0
  135. package/src/core/recall/tunables.ts +329 -0
  136. package/src/core/remember/CONTRACT.md +293 -0
  137. package/src/core/remember/INTERFACE-GAPS.md +189 -0
  138. package/src/core/remember/NOTES.md +373 -0
  139. package/src/core/remember/fallback.ts +452 -0
  140. package/src/core/remember/index.ts +103 -0
  141. package/src/core/remember/owner-strike-seam.ts +479 -0
  142. package/src/core/remember/proposals.ts +609 -0
  143. package/src/core/remember/spans.ts +1310 -0
  144. package/src/core/remember/tunables.ts +111 -0
  145. package/src/core/remember/updates.ts +198 -0
  146. package/src/core/retrieval.ts +96 -0
  147. package/src/core/revision.ts +441 -0
  148. package/src/core/schemas/CONTRACT.md +190 -0
  149. package/src/core/schemas/INTERFACE-GAPS.md +172 -0
  150. package/src/core/schemas/NOTES.md +260 -0
  151. package/src/core/schemas/aliases.ts +160 -0
  152. package/src/core/schemas/index.ts +1459 -0
  153. package/src/core/schemas/tunables.ts +44 -0
  154. package/src/core/schemas/types.ts +387 -0
  155. package/src/core/self/CONTRACT.md +459 -0
  156. package/src/core/self/INTERFACE-GAPS.md +284 -0
  157. package/src/core/self/NOTES.md +1057 -0
  158. package/src/core/self/briefing.ts +980 -0
  159. package/src/core/self/episodes.ts +483 -0
  160. package/src/core/self/freeze.ts +103 -0
  161. package/src/core/self/identity.ts +604 -0
  162. package/src/core/self/index.ts +2130 -0
  163. package/src/core/self/journal-file.ts +760 -0
  164. package/src/core/self/page.ts +404 -0
  165. package/src/core/self/tunables.ts +244 -0
  166. package/src/core/self/writer.ts +714 -0
  167. package/src/core/sleep/CONTRACT.md +298 -0
  168. package/src/core/sleep/INTERFACE-GAPS.md +262 -0
  169. package/src/core/sleep/NOTES.md +770 -0
  170. package/src/core/sleep/briefing.ts +86 -0
  171. package/src/core/sleep/consolidate.ts +241 -0
  172. package/src/core/sleep/cycle.ts +598 -0
  173. package/src/core/sleep/decay.ts +237 -0
  174. package/src/core/sleep/dedup.ts +373 -0
  175. package/src/core/sleep/index.ts +112 -0
  176. package/src/core/sleep/log.ts +116 -0
  177. package/src/core/sleep/markers.ts +164 -0
  178. package/src/core/sleep/prune.ts +170 -0
  179. package/src/core/sleep/strength-cache.ts +176 -0
  180. package/src/core/sleep/tunables.ts +135 -0
  181. package/src/core/sleep/types.ts +542 -0
  182. package/src/core/store/CONTRACT.md +446 -0
  183. package/src/core/store/NOTES.md +1068 -0
  184. package/src/core/store/cache.ts +709 -0
  185. package/src/core/store/db.ts +275 -0
  186. package/src/core/store/errors.ts +134 -0
  187. package/src/core/store/index.ts +2450 -0
  188. package/src/core/store/operational.ts +610 -0
  189. package/src/core/store/owner-op-seam.ts +428 -0
  190. package/src/core/store/paths.ts +494 -0
  191. package/src/core/store/prose.ts +165 -0
  192. package/src/core/store/render.ts +87 -0
  193. package/src/core/store/walk-seam.ts +78 -0
  194. package/src/core/types.ts +68 -0
  195. package/tools/install-loop/run.sh +1063 -0
@@ -0,0 +1,81 @@
1
+ # Module map
2
+
3
+ *The skeleton's spine. One brain function per self-contained module (constitution line
4
+ 10); each module's `CONTRACT.md` states purpose, brain analog, what it keeps (with
5
+ lineage: v0 / engram / v1 / the store's design memory), what it drops or simplifies,
6
+ its guarantees, and the scars it honors. Contracts are spec, and they were written
7
+ first; the skeleton they describe has since been built, so read each contract beside the
8
+ code and the `NOTES.md` / `INTERFACE-GAPS.md` next to it.*
9
+
10
+ ## Core (`src/core/`) — knows no host
11
+
12
+ | module | brain function | one line |
13
+ |---|---|---|
14
+ | `physics/` | synaptic plasticity | ALL the arithmetic on one page: strength, decay, reinforcement, strength-weighted revision. No opinions, no model calls. |
15
+ | `encode/` | attention + amygdala tagging | What gets in: gates (secrets, precision), salience tagged at write time, novelty as prediction error. |
16
+ | `remember/` | hippocampal encoding | The authorship contract: the experiencer's end-of-session dump (content, salience tags, `updates:` marks), in-the-moment jots, crash-fallback ingestion. |
17
+ | `store/` | the substrate | Two boxes since the floor (schema v6, 2026-09-20): one small canonical transactional SQLite (`counterparts.sqlite` — the memories' words, their archived versions, and every structured field), one rebuildable cache (embeddings/FTS, never backed up). The third box — one markdown file per memory — is gone. Markdown is an export (`render.ts`), plus a derived, write-only file copy of the journal under `journal/` — classified in the layout, deliberately NOT in the backup set, regenerated from its rows if deleted. |
18
+ | `recall/` | retrieval + priming | Cues → activation → surfacing gate → bounded injection; footnote tier; reinforcement on real use. |
19
+ | `associate/` | Hebbian linking | Co-activation strengthens links; spreading activation at recall. **RESOLVED (owner, 2026-08-25): stays a module** — edge-level arithmetic keeps `physics/` one page; Hebbian plasticity/contiguity is its own mechanism in the field guide. |
20
+ | `schemas/` | semantic memory | Entities and beliefs; birth by mention, death by decay; strength-weighted revision with row history. |
21
+ | `self/` | autobiographical self | Identity documents, episodes, the wake briefing (v0's briefing, grown up). Governed: frozen self-reinforcement rules. |
22
+ | `prospective/` | prospective memory | Future intentions, cued by time or context; fire / suppress / reference telemetry. |
23
+ | `handoff/` | working context for a place | The per-directory handoff: where the work here stands, written as a field on the end-of-session ask, shown as a two-line pointer at the next wake in that directory, expiring in lived days. **Never a memory** — out of recall, out of credit, out of consolidation, out of identity. **Added 2026-09-20 (E1, spec §6.4 / §15 item 6).** |
24
+ | `sleep/` | systems consolidation | Pure math on a cycle: decay tick (active-day clock), floor-pruning (real forgetting), re-render of the wake briefing. Zero standing model calls. |
25
+ | *(observer)* | — (instrument stance) | **RESOLVED (owner, 2026-08-25): a MODE, not a module** — one predicate threaded through the core API, checked at the store seam. Spec moved to `docs/observer-mode.md`. |
26
+
27
+ **Third open question (check-in): the `remember`/`encode` boundary.** With the
28
+ experiencer's dump as the primary path, span-capture survives mainly as crash-fallback
29
+ input — does `encode` shrink to gates-and-tagging inside `remember`'s pipeline?
30
+
31
+ ## Adapters (`src/adapters/`) — one host each
32
+
33
+ | adapter | job |
34
+ |---|---|
35
+ | `claude-code/` | Hooks: wake injection at session start, end-of-session remember, crash detection. The launch adapter. |
36
+ | `mcp/` | Deliberate tools: note, recall, status — plus the Stop ask's two return channels, `session_end` (memories) and `chapter` (the episode's own journal, **added 2026-09-04**, because the ask named a door no adapter had built). |
37
+ | `cli/` | `counterparts` command: status, install, owner operations (delete, export, backup). |
38
+ | `dashboard/` | The owner's window (constitution line 16): brain-view, revision stories, band/protected lists. Observer-mode by construction; minimal version ships DURING the parallel run. **Added 2026-08-25 (owner elevation).** |
39
+ | `sessions.ts` | Not an adapter — a leaf both may import: the live-session registry a host's hooks write (`<dataDir>/sessions/`) and its tools read, so a tool launched without a session can bind to one that is real, live and in its project. Adapters stay leaves; this is the sibling they share instead of importing each other. **Added 2026-09-04**, because this host's MCP servers are launched from a static config and cannot be told which session they serve. |
40
+ | `expansions.ts` | The same shape, for the other direction: the handle-resolution log the MCP `recall` tool writes (`<dataDir>/sessions/expansions.jsonl` — a per-store SALTED hash of the handle (G58), the id it reached or `null` for a refusal, a timestamp, the project) and the boundary's credit pass reads, so an expansion by TITLE credits the memory it actually reached, and a refusal shadows it. **Added 2026-09-15** (LAUNCH-STATUS G50): `recall/reference.ts` credits literal `mem_…` addresses and resolves nothing, so until this the most deliberate act a session had — naming a memory and reading it — earned no credit at all. |
41
+ | `scopes.ts` | The third shared leaf: the per-directory scope registry (`scopes.json` BESIDE the config, never inside the store, because the hook decides `off` before anything opens) — `on` / `observer` / `off` / `paused`, longest prefix wins, absent-or-unreadable meaning `unset` meaning on. Written by the `counterparts scope` console and the MCP `scope` tool, read by every hook. **Added 2026-09-15** (PR #92, G19): the hooks are registered globally, so until this the only way to say *not here* was a second config file and two environment variables. |
42
+
43
+ ## Tools (`tools/`)
44
+
45
+ | tool | job |
46
+ |---|---|
47
+ | `replay/` | Validation harness: feed v1's recorded month of real inputs through Counterparts, compare against the distributional baselines (`docs/harvest/replay-baselines.md`, behavioral-spec §17). |
48
+
49
+ ## Rulings — 2026-08-25 (check-in + adversarial review, all owner-ratified)
50
+
51
+ Contracts are read subject to these; where a contract still says PROPOSED on a listed
52
+ item, this section is the newer law.
53
+
54
+ 1. `associate/` stays a module; observer is a mode (`docs/observer-mode.md`); `encode/`
55
+ stays separate; `dashboard/` added as an adapter (constitution line 16, ratified).
56
+ 2. Physics: pressure-accumulator revision (§5.6 rewritten — field on target, one credited
57
+ challenge/day, force = strength × sal, novelty at encoding only); nothing born into
58
+ identity, N = 3 promotion at consolidation (§5.3 rewritten); bands 4→3 and one strength
59
+ number both settled; decay is a three-way (flat/exponential/power-law) decided by
60
+ replay; H = 90 is a TUNABLE default, not an owner ruling.
61
+ 3. Settled drops: identity-promotion surface, `protected.add` queue, model-seat pins,
62
+ zero-deps vow. Per-session gate state is persisted (`recall/`). Replay gates use
63
+ ranges, not point targets. Wake briefing renders WITHOUT a model at launch (the sleep/
64
+ OQ3 correction: v0's briefing was in fact model-compressed — the precedent cuts the
65
+ other way, and Amendment 15 decides instead).
66
+ 4. The adversarial review's five findings are all conceded and resolved in the contracts
67
+ as of this date; the §4-vs-§5.3 band contradiction is closed.
68
+
69
+ ## Authority note
70
+
71
+ Owner-decided (2026-08-25, bansai `docs/DECISIONS.md`): experiencer authorship with
72
+ crash fallback; librarian-as-physics with zero standing model calls; strength-weighted
73
+ revision (no ledger subsystem); only physics forgets; the three storage boxes;
74
+ birth-by-mention entities; Amendment 15. Anything a CONTRACT drops beyond that list is
75
+ marked **PROPOSED** and waits for the owner's check-in.
76
+
77
+ *The three storage boxes became two on 2026-09-20 (the floor, schema v6): the canonical
78
+ prose box is gone and the memory IS the row. That is the same owner, revising his own
79
+ default — "going forward by 'readable' we mean if someone can view them" (2026-09-16),
80
+ and `docs/storage-spec-2026-09-16.md` §15 item 9, "everything lives in the database for
81
+ now; markdown is an export". The other seven entries above are untouched.*
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "counterparts",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/mlapeter/counterparts.git"
9
+ },
10
+ "homepage": "https://github.com/mlapeter/counterparts#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/mlapeter/counterparts/issues"
13
+ },
14
+ "keywords": [
15
+ "memory",
16
+ "ai",
17
+ "claude",
18
+ "mcp",
19
+ "local-first"
20
+ ],
21
+ "type": "module",
22
+ "engines": {
23
+ "bun": ">=1.3.0"
24
+ },
25
+ "bin": {
26
+ "counterparts": "./src/adapters/cli/bin/counterparts.ts",
27
+ "counterparts-hook": "./src/adapters/claude-code/bin/hook.ts",
28
+ "counterparts-mcp": "./src/adapters/mcp/bin/serve.ts",
29
+ "counterparts-dashboard": "./src/adapters/dashboard/bin/dashboard.ts"
30
+ },
31
+ "main": "./src/core/counterpart.ts",
32
+ "types": "./src/core/counterpart.ts",
33
+ "exports": {
34
+ ".": "./src/core/counterpart.ts",
35
+ "./store": "./src/core/store/index.ts",
36
+ "./claude-code": "./src/adapters/claude-code/index.ts",
37
+ "./mcp": "./src/adapters/mcp/index.ts",
38
+ "./cli": "./src/adapters/cli/commands.ts",
39
+ "./dashboard": "./src/adapters/dashboard/index.ts",
40
+ "./sessions": "./src/adapters/sessions.ts",
41
+ "./scopes": "./src/adapters/scopes.ts",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "src/",
46
+ "docs/QUICKSTART.md",
47
+ "docs/ELI5.md",
48
+ "docs/module-map.md",
49
+ "tools/install-loop/",
50
+ "CONSTITUTION.md",
51
+ "README.md",
52
+ "LICENSE"
53
+ ],
54
+ "devDependencies": {
55
+ "@types/bun": "^1.1.0",
56
+ "playwright": "1.62.1",
57
+ "typescript": "^5.6.0"
58
+ },
59
+ "scripts": {
60
+ "test": "bun test",
61
+ "typecheck": "tsc --noEmit"
62
+ }
63
+ }