counterparts 0.3.0 → 0.3.2

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 (207) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/docs/module-map.md +2 -0
  3. package/package.json +2 -1
  4. package/src/adapters/claude-code/CONTRACT.md +2 -1
  5. package/src/adapters/claude-code/NOTES.md +90 -2
  6. package/src/adapters/claude-code/bin/hook.ts +17 -2
  7. package/src/adapters/claude-code/bin/runner.ts +4 -1
  8. package/src/adapters/claude-code/config.ts +23 -0
  9. package/src/adapters/claude-code/doctor.ts +148 -26
  10. package/src/adapters/claude-code/hooks.ts +37 -12
  11. package/src/adapters/claude-code/index.ts +2 -0
  12. package/src/adapters/claude-code/standdown.ts +12 -1
  13. package/src/adapters/claude-code/transcript.ts +79 -6
  14. package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
  15. package/src/adapters/cli/commands.ts +209 -61
  16. package/src/adapters/cli/export.ts +27 -3
  17. package/src/adapters/cli/help.ts +22 -8
  18. package/src/adapters/cli/install.ts +3 -5
  19. package/src/adapters/cli/mechanisms.ts +295 -0
  20. package/src/adapters/cli/repair-dates.ts +3 -1
  21. package/src/adapters/cli/snapshot.ts +4 -27
  22. package/src/adapters/dashboard/CONTRACT.md +13 -9
  23. package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
  24. package/src/adapters/dashboard/NOTES.md +3 -2
  25. package/src/adapters/dashboard/activity.ts +2 -1
  26. package/src/adapters/dashboard/bin/dashboard.ts +18 -3
  27. package/src/adapters/dashboard/upgrade.ts +23 -0
  28. package/src/adapters/dashboard/web/README.md +153 -0
  29. package/src/adapters/dashboard/web/actions.ts +631 -0
  30. package/src/adapters/dashboard/web/app.html +40 -1703
  31. package/src/adapters/dashboard/web/app.js +55 -0
  32. package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
  33. package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
  34. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
  35. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
  36. package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
  37. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
  38. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
  39. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
  40. package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
  41. package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
  42. package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
  43. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
  44. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
  45. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
  46. package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
  47. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
  48. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
  49. package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
  50. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
  51. package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
  52. package/src/adapters/dashboard/web/narrate.ts +10 -10
  53. package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
  54. package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
  55. package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
  56. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
  57. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
  58. package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
  59. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
  60. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
  61. package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
  62. package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
  63. package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
  64. package/src/adapters/dashboard/web/pages/health/health.css +93 -0
  65. package/src/adapters/dashboard/web/pages/health/index.js +41 -0
  66. package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
  67. package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
  68. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
  69. package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
  70. package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
  71. package/src/adapters/dashboard/web/pages/home/home.css +134 -0
  72. package/src/adapters/dashboard/web/pages/home/index.js +84 -0
  73. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
  74. package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
  75. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
  76. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
  77. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
  78. package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
  79. package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
  80. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
  81. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
  82. package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
  83. package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
  84. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
  85. package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
  86. package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
  87. package/src/adapters/dashboard/web/pages/self/index.js +43 -0
  88. package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
  89. package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
  90. package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
  91. package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
  92. package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
  93. package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
  94. package/src/adapters/dashboard/web/pages/self/self.css +182 -0
  95. package/src/adapters/dashboard/web/server.ts +305 -28
  96. package/src/adapters/dashboard/web/shared/absence.js +14 -0
  97. package/src/adapters/dashboard/web/shared/actions.js +48 -0
  98. package/src/adapters/dashboard/web/shared/api.js +17 -0
  99. package/src/adapters/dashboard/web/shared/base.css +34 -0
  100. package/src/adapters/dashboard/web/shared/canvas.js +68 -0
  101. package/src/adapters/dashboard/web/shared/colors.js +6 -0
  102. package/src/adapters/dashboard/web/shared/dom.js +4 -0
  103. package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
  104. package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
  105. package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
  106. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
  107. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
  108. package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
  109. package/src/adapters/dashboard/web/shared/format.js +31 -0
  110. package/src/adapters/dashboard/web/shared/layout.css +32 -0
  111. package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
  112. package/src/adapters/dashboard/web/shared/modal.css +24 -0
  113. package/src/adapters/dashboard/web/shared/modal.js +22 -0
  114. package/src/adapters/dashboard/web/shared/state.js +12 -0
  115. package/src/adapters/dashboard/web/shared/tip.css +4 -0
  116. package/src/adapters/dashboard/web/shared/tip.js +12 -0
  117. package/src/adapters/dashboard/web/shared/tokens.css +50 -0
  118. package/src/adapters/dashboard/web/shared/type.css +52 -0
  119. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  120. package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
  121. package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
  122. package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
  123. package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
  124. package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
  125. package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
  126. package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
  127. package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
  128. package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
  129. package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
  130. package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
  131. package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
  132. package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
  133. package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
  134. package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
  135. package/src/adapters/dashboard/web/shell/pages.js +15 -0
  136. package/src/adapters/dashboard/web/shell/pulse.js +86 -0
  137. package/src/adapters/dashboard/web/shell/tabs.js +49 -0
  138. package/src/adapters/dashboard/web/static.ts +76 -0
  139. package/src/adapters/dashboard/web/views/activity.ts +80 -0
  140. package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
  141. package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
  142. package/src/adapters/dashboard/web/views/health.ts +328 -0
  143. package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
  144. package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
  145. package/src/adapters/dashboard/web/views/memories.ts +342 -0
  146. package/src/adapters/dashboard/web/views/memory.ts +210 -0
  147. package/src/adapters/dashboard/web/views/meta.ts +64 -0
  148. package/src/adapters/dashboard/web/views/mind.ts +729 -0
  149. package/src/adapters/dashboard/web/views/overview.ts +282 -0
  150. package/src/adapters/dashboard/web/views/pulse.ts +19 -0
  151. package/src/adapters/dashboard/web/views/rows.ts +207 -0
  152. package/src/adapters/dashboard/web/views/search.ts +62 -0
  153. package/src/adapters/dashboard/web/views/shared.ts +161 -0
  154. package/src/adapters/dashboard/web/views.ts +34 -1724
  155. package/src/adapters/fired.ts +138 -31
  156. package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
  157. package/src/adapters/mcp/NOTES.md +43 -0
  158. package/src/adapters/mcp/bin/serve.ts +9 -1
  159. package/src/adapters/mcp/index.ts +7 -0
  160. package/src/adapters/mcp/server.ts +167 -6
  161. package/src/adapters/mcp/tools.ts +42 -0
  162. package/src/adapters/mcp/write-up.ts +1 -1
  163. package/src/adapters/sessions.ts +18 -1
  164. package/src/adapters/snapshots.ts +71 -39
  165. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  166. package/src/core/counterpart.ts +86 -7
  167. package/src/core/encode/INTERFACE-GAPS.md +12 -0
  168. package/src/core/feelings-wheel.ts +218 -0
  169. package/src/core/handoff/INTERFACE-GAPS.md +2 -0
  170. package/src/core/mint.ts +14 -2
  171. package/src/core/prospective/INTERFACE-GAPS.md +14 -0
  172. package/src/core/prospective/windows.ts +10 -48
  173. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  174. package/src/core/remember/INTERFACE-GAPS.md +10 -0
  175. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  176. package/src/core/schemas/NOTES.md +118 -1
  177. package/src/core/schemas/index.ts +330 -40
  178. package/src/core/schemas/tunables.ts +23 -0
  179. package/src/core/schemas/types.ts +64 -1
  180. package/src/core/self/CONTRACT.md +3 -0
  181. package/src/core/self/INTERFACE-GAPS.md +10 -0
  182. package/src/core/self/NOTES.md +33 -2
  183. package/src/core/self/calendar.ts +7 -78
  184. package/src/core/self/episodes.ts +52 -12
  185. package/src/core/self/index.ts +40 -12
  186. package/src/core/self/writer.ts +22 -22
  187. package/src/core/sleep/NOTES.md +36 -0
  188. package/src/core/sleep/cycle.ts +38 -3
  189. package/src/core/sleep/fade.ts +76 -0
  190. package/src/core/sleep/index.ts +4 -1
  191. package/src/core/sleep/prune.ts +8 -1
  192. package/src/core/sleep/tunables.ts +5 -0
  193. package/src/core/sleep/types.ts +24 -0
  194. package/src/core/store/CONTRACT.md +36 -7
  195. package/src/core/store/NOTES.md +197 -0
  196. package/src/core/store/errors.ts +22 -0
  197. package/src/core/store/feelings.ts +182 -0
  198. package/src/core/store/index.ts +339 -45
  199. package/src/core/store/operational.ts +240 -22
  200. package/src/core/store/owner-op-seam.ts +13 -3
  201. package/src/core/store/paths.ts +15 -1
  202. package/src/core/store/pre-migration.ts +258 -0
  203. package/src/core/store/prose.ts +8 -1
  204. package/src/core/store/render.ts +3 -0
  205. package/src/core/time.ts +374 -0
  206. package/src/core/types.ts +13 -0
  207. package/src/adapters/dashboard/web/brain.html +0 -463
@@ -21,6 +21,7 @@ import { Dashboard, VIEWS, VIEW_BLURB, isViewName } from "../index.js";
21
21
  import type { ViewArgs, ViewName } from "../index.js";
22
22
  import { terminalWantsColour } from "../ansi.js";
23
23
  import { DATA_DIR_ENV, dataDir, describeGuardRefusal, isStoreError } from "../../../core/store/index.js";
24
+ import { UPGRADE_PENDING_SENTENCE, upgradePending } from "../upgrade.js";
24
25
  import type { StoreError } from "../../../core/store/index.js";
25
26
  import type { Band, Kind } from "../../../core/types.js";
26
27
 
@@ -124,6 +125,8 @@ export function helpText(): string {
124
125
  "The web view:",
125
126
  " serve --dir <path> [--port <n>] the local dashboard, on 127.0.0.1 only",
126
127
  ` (default port ${SERVE_DEFAULT_PORT}, or ${SERVE_PORT_ENV})`,
128
+ " serve ... --config <path> the configuration the page's scope and rebrief",
129
+ " actions name (absent: the page offers no scope)",
127
130
  " serve --default-store open the DEFAULT store instead. Without --dir",
128
131
  " or --default-store, 'serve' refuses: on a machine",
129
132
  " with an install the default is the owner's live",
@@ -131,7 +134,8 @@ export function helpText(): string {
131
134
  "",
132
135
  "A flag a subcommand does not take is refused before anything is opened.",
133
136
  "",
134
- "It reads in observer mode and writes nothing, ever.",
137
+ "Looking reads in observer mode and writes nothing. The web view's management",
138
+ "actions (note, remove, backup, …) run through the console's own commands.",
135
139
  ];
136
140
  return lines.join("\n");
137
141
  }
@@ -151,6 +155,9 @@ export interface ServeArgs {
151
155
  * `serve` has no confirmation to skip. The flag that puts a whole store on a
152
156
  * socket says which store. */
153
157
  readonly defaultStore: boolean;
158
+ /** `--config <path>`: the host configuration the page's `scope` and
159
+ * `rebrief` actions name. Absent, the page offers no `scope`. */
160
+ readonly config: string | undefined;
154
161
  }
155
162
 
156
163
  /**
@@ -172,7 +179,7 @@ export interface ServeArgs {
172
179
  const VIEW_FLAGS: readonly string[] = [
173
180
  "dir", "id", "limit", "band", "kind", "name", "archived", "width", "colour", "no-colour", "help", "h",
174
181
  ];
175
- const SERVE_FLAGS: readonly string[] = ["dir", "port", "default-store", "help", "h"];
182
+ const SERVE_FLAGS: readonly string[] = ["dir", "port", "default-store", "config", "help", "h"];
176
183
 
177
184
  export function unknownFlag(argv: readonly string[]): string | null {
178
185
  const serve = (argv[0] ?? "") === "serve";
@@ -200,6 +207,7 @@ export function parseServe(argv: readonly string[]): ServeArgs {
200
207
  dir: parsed.dir,
201
208
  ...(port === undefined ? { port: undefined } : { port }),
202
209
  defaultStore: argv.includes("--default-store") || argv.includes("--default-store=true"),
210
+ config: flagValue(argv, "config"),
203
211
  };
204
212
  }
205
213
 
@@ -285,11 +293,13 @@ export async function serve(argv: readonly string[]): Promise<number> {
285
293
  const running = await startDashboard({
286
294
  ...(dir === undefined ? {} : { dir }),
287
295
  ...(args.port === undefined ? {} : { port: args.port }),
296
+ ...(args.config === undefined ? {} : { config: resolve(args.config) }),
288
297
  });
289
298
  process.stdout.write(
290
299
  [
291
300
  `counterparts dashboard — ${running.url}`,
292
301
  `reading ${running.dir}`,
302
+ ...(running.upgradePending ? [UPGRADE_PENDING_SENTENCE] : []),
293
303
  // Named when it was not asked for. `--dir` is optional and the default
294
304
  // is somebody's real memory, so a `serve` typed without one should not
295
305
  // look the same as a `serve` aimed on purpose (constitution 16: the
@@ -300,7 +310,11 @@ export async function serve(argv: readonly string[]): Promise<number> {
300
310
  ...(dir === undefined
301
311
  ? [`(--default-store, so this is the DEFAULT store — ${DATA_DIR_ENV} or ~/.counterparts/store)`]
302
312
  : []),
303
- "observer mode: it strengthens nothing, deposits nothing, and writes no file of its own.",
313
+ "looking is observer mode: it strengthens nothing and deposits nothing. What you do on purpose",
314
+ "there (a note, a removal, a backup, …) runs through the console's own commands.",
315
+ ...(args.config === undefined
316
+ ? []
317
+ : [`configuration ${resolve(args.config)} (for scope and rebrief)`]),
304
318
  "ctrl-c to stop.",
305
319
  "",
306
320
  ].join("\n"),
@@ -351,6 +365,7 @@ export function describeStoreError(err: StoreError, dir: string, namedDir = fals
351
365
  // line that just named `--dir /somewhere`, creates the store in the DEFAULT
352
366
  // place instead — advice that works, somewhere else.
353
367
  case "STORE_UNINITIALIZED":
368
+ if (upgradePending(err)) return UPGRADE_PENDING_SENTENCE.replace("; then reload.", "; then run this again.");
354
369
  return `No store at ${dir}. Run 'counterparts init${namedDir ? ` --dir ${dir}` : ""}' to create one.`;
355
370
  // The exact error a stranger who put the adapter's config in the wrong place
356
371
  // will hit. The CLI's `init` already teaches the rule; this says the same
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A store waiting for its one-time schema upgrade, as the dashboard meets it.
3
+ * Its own small module so the terminal views can say the sentence without
4
+ * loading the web server.
5
+ */
6
+ import { SCHEMA_VERSION, isStoreError } from "../../core/store/index.js";
7
+
8
+ /**
9
+ * A store on an OLDER schema this build can upgrade (v6 up): an observer meets
10
+ * it as `STORE_UNINITIALIZED` with a `found` version, and it is waiting for the
11
+ * first Claude Code session to copy and upgrade it. The dashboard is an
12
+ * observer and never upgrades anything, so it says so and waits.
13
+ */
14
+ export function upgradePending(err: unknown): boolean {
15
+ if (!isStoreError(err, "STORE_UNINITIALIZED")) return false;
16
+ const found = Number.parseInt(String(err.detail["found"] ?? ""), 10);
17
+ return Number.isFinite(found) && found >= 6 && found < SCHEMA_VERSION;
18
+ }
19
+
20
+ /** The sentence a store waiting for its upgrade gets, on the page and in the terminal. */
21
+ export const UPGRADE_PENDING_SENTENCE =
22
+ "This memory needs a one-time upgrade. Open a Claude Code session and it will upgrade itself; then reload.";
23
+
@@ -0,0 +1,153 @@
1
+ # `web/` — where the dashboard's pieces live
2
+
3
+ A working map, not a rulebook. Split out of one 1,731-line `app.html` on
4
+ 2026-09-25 with no visible change; move things when a better shape shows up.
5
+
6
+ The page is plain browser ES modules and stylesheets — no bundler, no build
7
+ step, no dependencies. `server.ts` serves them as files (see "Serving" below).
8
+
9
+ ## Server side (TypeScript, runs in bun)
10
+
11
+ | file | what it is |
12
+ |---|---|
13
+ | `server.ts` | `node:http` on 127.0.0.1, the Host allowlist, `router()` (GET: `/`, `/brain` (now a redirect to `/#home`), the favicon, `/api/*`, the static files), and the POST hand-off to `actions.ts`. A store waiting for its one-time upgrade (v6 met by v7, `../upgrade.ts`) gets one calm page instead, and is tried again on every request |
14
+ | `actions.ts` | managing: `POST /api/action/<name>` — the same-origin + per-launch-token guard, argument validation, and the console's own `run()` (loaded lazily; never handed the observer source). `ACTIONS` lists them: `ask`, `note`, `remove`, `backup`, `export`, `scope`, `rebrief`, `verify`, and `doctor` (a read: the health tab's checklist, `doctor --json`) |
15
+ | `static.ts` | `resolveStatic()`: which URL paths are static files and where they live (pure; no fs) |
16
+ | `views.ts` | the index of `views/`: re-exports every view, so callers import from here |
17
+ | `views/<name>.ts` | one module per `/api` view: `meta`, `overview` (the home tab's), `memories` (`/api/memories` + `/api/memories/list`), `memory`, `search`, `mind` (the self tab's), `activity`, `flow-view` (`/api/flow` + `/api/node`), `health`, `pulse`, `mechanisms`, `mechanism-panel` (`/api/mechanism?id=`) |
18
+ | `views/archive-words.ts` | why a memory was archived, in plain words: one table (`ARCHIVE_WORDS`, a group phrase and a single-row phrase per reason) and one fallback for a reason nobody mapped; health's bar, the memories list and home's archived count read it |
19
+ | `views/mechanisms.ts` | `/api/mechanisms`: each mechanism's light (grey = not built, green = fired in the last 7 lived days, amber = built and quiet), one evidence line, the newest backing event `seq`s. `MECHANISM_PROOFS` is the one table saying which durable rows count as a mechanism firing |
20
+ | `views/shared.ts` | the census and small counters every view leans on |
21
+ | `views/rows.ts` | row shapes and builders more than one view uses (band bars, contested beliefs, chapters, lived days) |
22
+ | `flow.ts` | the diagram's static shape: nodes, edges, which event lights which node |
23
+ | `narrate.ts` | a durable event → one first-person sentence |
24
+ | `reveal.ts` | id → words at render time, withholding confidential rows |
25
+ | `fired.ts` | `/api/fired`, the what-fired panel |
26
+
27
+ ## Client side (browser modules)
28
+
29
+ ```
30
+ app.html the shell: header, one empty <section> per tab, #tip, #overlay,
31
+ the <link>s (their ORDER is the cascade order) and one <script type=module>
32
+ app.js entry: mounts every page, the nav, the modal; boot; resize; starts the pulse
33
+ shell/
34
+ pages.js the page registry (nav order) and the page-module interface
35
+ tabs.js nav strip + showTab
36
+ pulse.js the 4-second poll: new events → live feeds + page hooks; store moved → page.refresh()
37
+ shared/
38
+ tokens.css @font-face + colour/type variables (:root) — the site's look (counterparts.ai)
39
+ type.css which face goes where: Outfit (--sans) for anything read as words; Courier (--mono) only for big numbers, ids, record names; loaded LAST
40
+ vendor/ three.module.min.js (0.169.0, MIT) for the home brain
41
+ fonts/ Outfit (variable, latin) + Courier Prime 400/700 (latin) .woff2, with their OFL licences
42
+ base.css layout.css utilities.css reset, header/nav, headings, the .cols grids, .foot/.tone-*/#err
43
+ tip.css modal.css the tooltip and the overlay card
44
+ dom.js $ esc
45
+ format.js n2 n3 pct said livedSpan headline
46
+ colors.js COL BANDCOL ACCENT (canvas needs JS values)
47
+ absence.js emptyBox absenceLine — the "(none yet)" / "(never run)" block
48
+ api.js api() (looking: GET only) and fail()
49
+ actions.js act() (managing: the one POST, with the page's token) and resultHtml()
50
+ canvas.js FACE (the canvas's face, Outfit) fit hitTest roundRect clip wrapText
51
+ tip.js modal.js showTip/hideTip; openModal/closeModal/section
52
+ memory-modal.js openMemory, copyId, removeMemory (window globals: rows use inline onclick)
53
+ event-modal.js openEvent (window global)
54
+ state.js tabs {current, loaded}; live {lastSeq, fingerprint}
55
+ widgets/ card rows table chart tiles bar feed light .css;
56
+ feed.js (renderFeed, live-feed registry), chapters.js (chapterRows),
57
+ confirm.js + .css (confirmTyped: type a phrase back to confirm),
58
+ light.js (the status dot: green / amber / grey)
59
+ pages/<tab>/ tabs: home (was overview), memories, self (was mind), flow, health;
60
+ #overview and #mind still land (shell/tabs.js RENAMED)
61
+ index.js default export { name, mount(section), render(), refresh?, show?,
62
+ resize?, redraw?, onEvents?, onDeposit? }; composes its sections' markup
63
+ sections/*.js one panel each: `export const markup` (its <h2> + container) and
64
+ `paint(d)` (or `render()` when it fetches for itself)
65
+ <tab>.css styles only this page uses (home, memories, self, flow, health)
66
+ mechanisms/
67
+ index.js MECHANISMS (the site's eleven, in its order) and FAMILIES (its four, with colours)
68
+ <id>/index.js default export { id, family, name, short, tagline, inDev, explainer };
69
+ the light comes from /api/mechanisms
70
+ <id>/panel.js picture(payload): the Explorer panel's picture, where one is drawn
71
+ picture.js the pictures' shared pieces
72
+ regions.js brain regions → mechanisms, as the site maps them
73
+ ```
74
+
75
+ Moving a section between pages: import its module in the other page's
76
+ `index.js`, put `${section.markup}` where it should sit, call its `paint` from
77
+ that page's `render` with the right payload (the data comes from that page's
78
+ `/api` view — a section may need its view to grow a field). Its CSS may live in
79
+ a page stylesheet; move that too.
80
+
81
+ A hash can carry more than the tab: `#self/settling` (an anchor) or
82
+ `#memories?state=archived` (a query). `shell/tabs.js#parseRoute` splits it, and
83
+ the page's optional `route({ anchor, params })` is called once the page is
84
+ drawn. The home hero's four counts are links of this kind.
85
+
86
+ The home page is the site's hero plus Explorer. `pages/home/brain.js` is the
87
+ three.js brain, imported statically from `shared/vendor/three.module.min.js`
88
+ (0.169.0, MIT, `MIT-three.txt` beside it; never a CDN). It sets
89
+ `#home-brain[data-ready]` once it is drawing or has fallen back to a sentence.
90
+ `mechanisms/regions.js` maps brain regions to mechanisms, as the site does.
91
+ `sections/explorer.js` owns the pills and the inline panel. The panel's picture
92
+ comes from `mechanisms/<id>/panel.js` (export `picture(payload)`, pure markup),
93
+ gathered in `PANELS` in `mechanisms/index.js` beside `guideUrl(id)`. Its data
94
+ comes from `/api/mechanism?id=` (`views/mechanism-panel.ts`: last firings
95
+ narrated, plus a `picture`, both read-only). `mechanisms/picture.js` holds the
96
+ pictures' shared pieces. A mechanism built later gets a `panel.js`, one line in
97
+ `PANELS`, and a case in `mechanism-panel.ts`.
98
+
99
+ `pages/memories/` — the memories tab. `state.js` holds the page's filters
100
+ (live/archived/all, kind, band, page offset) and notifies the list when they
101
+ change; `counterparts:changed` (a window event, fired after a note and after a
102
+ removal on the memory card) makes the page re-read at once. Sections:
103
+ `search.js` (search by words, plus Ask via `act("ask", {json:true})` rendered
104
+ as a list), `tools.js` (write a note, and the back-up/export folder dialog),
105
+ `constellation.js` (the one picture: the scatter, band chips that filter,
106
+ strength-by-band in the right margin), `kinds.js` (six kinds in words; click to
107
+ filter), `list.js` (every memory, newest first, paged on the server by
108
+ `/api/memories/list` in `views/memories.ts`, whose archive reasons are put into
109
+ plain words by `archiveWords` from `views/archive-words.ts`).
110
+
111
+ `pages/self/`: the self tab. `sections/page.js` is the self page (rendered by
112
+ `markdown.js`, which escapes first) and its history as a timeline; clicking a
113
+ dot diffs that version against the one before with `diff.js` (line comparison,
114
+ then words, no deps). `sections/settling.js` covers the core, protected and
115
+ contested memories, plus the closest candidates for the core; the view computes
116
+ them with `physics#promotionEligibility` and counts memories that can't get
117
+ there by use separately. `sections/wake.js` is the wake folded to one line and
118
+ a stacked bar of its parts (`wakeParts` in `views/mind.ts`, cut at the lane
119
+ headings from `self/`), plus the rebrief button. `sections/journal.js` shows
120
+ chapters by day with their model. `sections/stories.js` is only `storyCard`,
121
+ opened in the overlay. The view is still `views/mind.ts` / `/api/mind`.
122
+
123
+ The health tab answers "is it working?": `pages/health/sections/checks.js` runs
124
+ `counterparts doctor --json` through the actions seam (a read; a dashboard
125
+ opened on a bare `--dir` arms the explicit-dir guard for that run, so the
126
+ settings line reads "not checked") and draws its findings as a checklist,
127
+ folding the non-headline greens the way `cli/report.ts` does; `cycle.js` is the
128
+ last sleep cycle as one line with a dot per phase; `archive.js` is one stacked
129
+ bar of `archived_reason` (plain phrases in the shared archive-words module,
130
+ unknown reasons get their own segment); `verify.js` is "Check the index"
131
+ (`verify` through the seam). The developer panels (band symmetry, what fired,
132
+ every durable record, the day × event grid, what I cannot see) live under the
133
+ flow diagram as "Under the hood"
134
+ (`pages/flow/sections/{symmetry,fired,records,heatmap,blind}.js`), still fed by
135
+ `/api/health` and `/api/fired`. On a bare `--dir` dashboard every action runs
136
+ with the explicit-dir guard, COUNTERPARTS_CONFIG removed, and home pointed at a
137
+ nonexistent dir (doctor keeps the real home for its ~/.claude check), so no
138
+ action can reach a default config.
139
+
140
+ Harness hooks `tools/visual-loop` relies on: `window.tileValue`,
141
+ `window.flowState`, `window.particleCount`, `document.documentElement.dataset.loaded`,
142
+ `#home-brain[data-ready]`, and the element ids it clicks (`#mlist .mrow`, `#flowcv`, `#overlay`, …).
143
+
144
+ ## Serving
145
+
146
+ `resolveStatic` serves only `/app.js` and files under `/shared/`, `/shell/`,
147
+ `/pages/`, `/mechanisms/`, with extension `.js`, `.css` or `.woff2`; every path
148
+ segment must be plain (no `..`, dotfiles, `%`-escapes left after one decode,
149
+ backslashes, NUL). A new top-level folder or extension means editing
150
+ `static.ts` (and its test). Everything is `cache-control: no-store`, so an edit
151
+ shows on reload. `test/dashboard-web.test.ts` checks that every file the shell
152
+ reaches exists and is served, and that no `.js`/`.css` under `web/` is orphaned.
153
+ `test/dashboard.test.ts`'s source scan covers the `.js` files too.