counterparts 0.3.5 → 0.3.7

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 (142) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/docs/module-map.md +1 -0
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +110 -30
  5. package/src/adapters/claude-code/NOTES.md +96 -0
  6. package/src/adapters/claude-code/bin/hook.ts +62 -2
  7. package/src/adapters/claude-code/bin/nightly.ts +76 -0
  8. package/src/adapters/claude-code/config.ts +80 -0
  9. package/src/adapters/claude-code/doctor.ts +386 -25
  10. package/src/adapters/claude-code/hooks.ts +273 -311
  11. package/src/adapters/claude-code/index.ts +20 -2
  12. package/src/adapters/claude-code/night-run.ts +504 -0
  13. package/src/adapters/claude-code/page-writer.ts +50 -16
  14. package/src/adapters/cli/commands.ts +53 -16
  15. package/src/adapters/cli/dream-core.ts +54 -8
  16. package/src/adapters/cli/help.ts +7 -6
  17. package/src/adapters/cli/self-page.ts +5 -2
  18. package/src/adapters/dashboard/activity.ts +18 -5
  19. package/src/adapters/dashboard/registries.ts +1 -1
  20. package/src/adapters/dashboard/stories.ts +3 -1
  21. package/src/adapters/dashboard/web/README.md +108 -93
  22. package/src/adapters/dashboard/web/app.html +0 -6
  23. package/src/adapters/dashboard/web/app.js +3 -7
  24. package/src/adapters/dashboard/web/mechanisms/prospective/panel.js +11 -2
  25. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +16 -4
  26. package/src/adapters/dashboard/web/narrate.ts +25 -6
  27. package/src/adapters/dashboard/web/pages/health/health.css +139 -0
  28. package/src/adapters/dashboard/web/pages/health/index.js +23 -12
  29. package/src/adapters/dashboard/web/pages/health/sections/archive.js +5 -2
  30. package/src/adapters/dashboard/web/pages/health/sections/checks.js +31 -24
  31. package/src/adapters/dashboard/web/pages/{home/sections/explorer.js → health/sections/mechanisms.js} +38 -75
  32. package/src/adapters/dashboard/web/pages/home/brain.js +17 -36
  33. package/src/adapters/dashboard/web/pages/home/go.js +7 -0
  34. package/src/adapters/dashboard/web/pages/home/home.css +56 -204
  35. package/src/adapters/dashboard/web/pages/home/index.js +48 -58
  36. package/src/adapters/dashboard/web/pages/home/sections/brain.js +84 -0
  37. package/src/adapters/dashboard/web/pages/home/sections/feel.js +27 -0
  38. package/src/adapters/dashboard/web/pages/home/sections/hero.js +43 -20
  39. package/src/adapters/dashboard/web/pages/home/sections/map.js +26 -0
  40. package/src/adapters/dashboard/web/pages/home/sections/today.js +41 -0
  41. package/src/adapters/dashboard/web/pages/memories/index.js +36 -19
  42. package/src/adapters/dashboard/web/pages/memories/memories.css +32 -42
  43. package/src/adapters/dashboard/web/pages/memories/row.js +37 -24
  44. package/src/adapters/dashboard/web/pages/memories/sections/feel.js +13 -154
  45. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +34 -31
  46. package/src/adapters/dashboard/web/pages/memories/sections/list.js +70 -36
  47. package/src/adapters/dashboard/web/pages/memories/sections/search.js +90 -85
  48. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +5 -4
  49. package/src/adapters/dashboard/web/pages/memories/state.js +11 -5
  50. package/src/adapters/dashboard/web/pages/self/index.js +2 -0
  51. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +4 -1
  52. package/src/adapters/dashboard/web/pages/self/sections/map.js +453 -96
  53. package/src/adapters/dashboard/web/pages/self/sections/page.js +2 -2
  54. package/src/adapters/dashboard/web/pages/self/sections/traits.js +10 -9
  55. package/src/adapters/dashboard/web/pages/self/self.css +28 -20
  56. package/src/adapters/dashboard/web/shared/base.css +0 -1
  57. package/src/adapters/dashboard/web/shared/doctor.js +68 -0
  58. package/src/adapters/dashboard/web/shared/layout.css +0 -1
  59. package/src/adapters/dashboard/web/shared/memory-marks.css +1 -4
  60. package/src/adapters/dashboard/web/shared/memory-marks.js +2 -16
  61. package/src/adapters/dashboard/web/shared/memory-modal.js +45 -24
  62. package/src/adapters/dashboard/web/shared/modal.css +5 -0
  63. package/src/adapters/dashboard/web/shared/voice.js +18 -0
  64. package/src/adapters/dashboard/web/shared/widgets/feed.js +13 -43
  65. package/src/adapters/dashboard/web/shared/widgets/feel-radar.js +137 -0
  66. package/src/adapters/dashboard/web/shell/pulse.js +1 -16
  67. package/src/adapters/dashboard/web/views/activity.ts +10 -4
  68. package/src/adapters/dashboard/web/views/archive-words.ts +7 -1
  69. package/src/adapters/dashboard/web/views/dreams.ts +8 -5
  70. package/src/adapters/dashboard/web/views/flow-view.ts +9 -5
  71. package/src/adapters/dashboard/web/views/health.ts +13 -4
  72. package/src/adapters/dashboard/web/views/mechanism-panel.ts +24 -11
  73. package/src/adapters/dashboard/web/views/memories.ts +131 -29
  74. package/src/adapters/dashboard/web/views/memory-words.ts +29 -1
  75. package/src/adapters/dashboard/web/views/memory.ts +6 -3
  76. package/src/adapters/dashboard/web/views/mind.ts +19 -12
  77. package/src/adapters/dashboard/web/views/overview.ts +56 -91
  78. package/src/adapters/dashboard/web/views/search.ts +13 -5
  79. package/src/adapters/dashboard/web/views/today.ts +181 -0
  80. package/src/adapters/dashboard/web/views/traits.ts +117 -18
  81. package/src/adapters/dashboard/web/views.ts +2 -2
  82. package/src/adapters/fired.ts +9 -10
  83. package/src/adapters/mcp/NOTES.md +29 -0
  84. package/src/adapters/mcp/deliberate.ts +80 -5
  85. package/src/adapters/mcp/index.ts +2 -0
  86. package/src/adapters/mcp/server.ts +339 -42
  87. package/src/adapters/mcp/tools.ts +84 -34
  88. package/src/adapters/sessions.ts +5 -0
  89. package/src/core/associate/CONTRACT.md +33 -4
  90. package/src/core/associate/INTERFACE-GAPS.md +70 -0
  91. package/src/core/associate/NOTES.md +220 -1
  92. package/src/core/associate/buffer.ts +12 -9
  93. package/src/core/associate/contiguity.ts +81 -0
  94. package/src/core/associate/edges.ts +117 -6
  95. package/src/core/associate/index.ts +224 -7
  96. package/src/core/associate/pending.ts +7 -3
  97. package/src/core/associate/spread.ts +154 -69
  98. package/src/core/associate/tunables.ts +75 -5
  99. package/src/core/counterpart.ts +539 -25
  100. package/src/core/dream/CONTRACT.md +175 -40
  101. package/src/core/dream/NOTES.md +225 -1
  102. package/src/core/dream/index.ts +1869 -288
  103. package/src/core/dream/mind.ts +120 -39
  104. package/src/core/dream/reflect.ts +1074 -298
  105. package/src/core/dream/slices.ts +217 -0
  106. package/src/core/dream/tunables.ts +105 -16
  107. package/src/core/fit/CONTRACT.md +80 -0
  108. package/src/core/fit/INTERFACE-GAPS.md +16 -0
  109. package/src/core/fit/NOTES.md +37 -0
  110. package/src/core/fit/index.ts +499 -0
  111. package/src/core/recall/CONTRACT.md +13 -2
  112. package/src/core/recall/INTERFACE-GAPS.md +10 -0
  113. package/src/core/recall/NOTES.md +76 -0
  114. package/src/core/recall/activate.ts +320 -62
  115. package/src/core/recall/gate.ts +73 -4
  116. package/src/core/recall/index.ts +46 -10
  117. package/src/core/recall/render.ts +12 -1
  118. package/src/core/recall/session.ts +8 -0
  119. package/src/core/recall/tunables.ts +30 -0
  120. package/src/core/remember/owes.ts +4 -1
  121. package/src/core/retrieval.ts +15 -6
  122. package/src/core/schemas/index.ts +8 -1
  123. package/src/core/self/CONTRACT.md +33 -18
  124. package/src/core/self/NOTES.md +26 -0
  125. package/src/core/self/index.ts +22 -3
  126. package/src/core/self/journal-file.ts +5 -2
  127. package/src/core/self/page.ts +60 -30
  128. package/src/core/self/writer.ts +114 -19
  129. package/src/core/sleep/NOTES.md +11 -0
  130. package/src/core/sleep/decay.ts +16 -1
  131. package/src/core/sleep/prune.ts +16 -1
  132. package/src/core/store/NOTES.md +3 -1
  133. package/src/core/store/errors.ts +4 -3
  134. package/src/core/store/feelings.ts +143 -22
  135. package/src/core/store/index.ts +200 -16
  136. package/src/core/store/traits.ts +24 -6
  137. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +0 -34
  138. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +0 -62
  139. package/src/adapters/dashboard/web/pages/home/sections/tonight.js +0 -74
  140. package/src/adapters/dashboard/web/pages/home/sections/written.js +0 -76
  141. package/src/adapters/dashboard/web/views/tonight.ts +0 -158
  142. package/src/adapters/dashboard/web/views/written-returned.ts +0 -93
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * THE HEADLESS NIGHTLY RUN'S OWN PROCESS (2026-09-29) — started DETACHED by the
4
+ * hook when the dreaming setting is `auto` (`night-run.ts#planNightRunner`),
5
+ * with a pinned environment: the data dir and configuration the hook read, the
6
+ * session the run is attributed to and its directory, the run's id and what it
7
+ * is (`NIGHT_RUN_ENV`, `NIGHT_KIND_ENV`).
8
+ *
9
+ * It composes the launch prompt from the store, starts `claude -p` with it on
10
+ * stdin, waits under the run's watchdog, and records what became of the run —
11
+ * then exits 0 on every path. Nothing about a failed run may reach the host;
12
+ * the ROW is how the next session hears of it.
13
+ */
14
+ import { implicitConfigRefusal, namedConfigRefusal, namedUnreadableRefusal } from "../../config-path.js";
15
+
16
+ import { NIGHT_KIND_ENV, NIGHT_RUN_ENV, openNightCounterpart, readKind, runNight } from "../night-run.js";
17
+ import { isEntryPoint, pinnedScope, pinnedSession, runnerConfig, runnerConfigChoice } from "./runner.js";
18
+
19
+ async function main(): Promise<void> {
20
+ const choice = runnerConfigChoice();
21
+ const refusal = namedConfigRefusal(choice) ?? implicitConfigRefusal(choice);
22
+ if (refusal !== null) {
23
+ process.stderr.write(`[counterparts] nightly run stood down: ${refusal}\n`);
24
+ return;
25
+ }
26
+ const { config, reason } = runnerConfig(choice.path);
27
+ const unreadable = namedUnreadableRefusal(choice, reason);
28
+ if (unreadable !== null) {
29
+ process.stderr.write(`[counterparts] nightly run stood down: ${unreadable}\n`);
30
+ return;
31
+ }
32
+ const run = (process.env[NIGHT_RUN_ENV] ?? "").trim();
33
+ const session = pinnedSession();
34
+ if (run.length === 0 || session === null || config.observer === true) {
35
+ process.stderr.write("[counterparts] nightly run stood down: no run, no session, or an observer\n");
36
+ // SAID WHERE IT CAN BE (review of #282, finding 4): a run the hook started
37
+ // and this process will not carry is recorded `could-not-start`, so the
38
+ // next prompt asks instead of waiting on a row that stays `started`.
39
+ if (run.length > 0 && config.observer !== true) standDown(config, run, session ?? "", readKind(process.env[NIGHT_KIND_ENV]).kind);
40
+ return;
41
+ }
42
+ await runNight({
43
+ open: () => openNightCounterpart(config),
44
+ config,
45
+ run,
46
+ session,
47
+ scope: pinnedScope() ?? "",
48
+ kind: readKind(process.env[NIGHT_KIND_ENV]),
49
+ configPath: choice.path,
50
+ });
51
+ }
52
+
53
+ /** One `could-not-start` row for a run this process stood down from. Never throws. */
54
+ function standDown(config: Parameters<typeof openNightCounterpart>[0], run: string, session: string, kind: "night" | "reflection"): void {
55
+ try {
56
+ const c = openNightCounterpart(config);
57
+ try {
58
+ const now = c.store.now();
59
+ c.dreams.recordNightRun({ run, date: c.store.today(), state: "could-not-start", kind, session, startedAt: now, endedAt: now, reason: "refused", detail: session.length === 0 ? "NO_SESSION" : "STOOD_DOWN", code: null, dream: null, reflection: null });
60
+ } finally {
61
+ c.close();
62
+ }
63
+ } catch {
64
+ /* a store that will not open: the row stays `started` and reads as lost later */
65
+ }
66
+ }
67
+
68
+ if (isEntryPoint(process.argv[1], import.meta.url)) {
69
+ void main().then(
70
+ () => process.exit(0),
71
+ (err: unknown) => {
72
+ process.stderr.write(`[counterparts] nightly run stood down: ${err instanceof Error ? err.message : String(err)}\n`);
73
+ process.exit(0);
74
+ },
75
+ );
76
+ }
@@ -64,6 +64,25 @@ export const TUNABLES = {
64
64
  * worker's it is not validated against `remember/`'s claim staleness, because
65
65
  * it claims no spans. */
66
66
  PAGE_WRITER_MS: 10 * 60_000,
67
+ /**
68
+ * THE HEADLESS NIGHTLY RUN'S WATCHDOG (2026-09-29), ms: `claude -p` running
69
+ * the page writer, the dream and the reflection in one windowless session.
70
+ * A run measured ~4.5 minutes on 2026-09-29; this is generous on purpose.
71
+ * `dreaming.timeoutMs` in the configuration overrides it.
72
+ */
73
+ NIGHT_RUN_MS: 20 * 60_000,
74
+ /**
75
+ * A headless run that exits non-zero sooner than this "could not start"
76
+ * (not logged in, a bad flag) rather than failed partway: the next prompt
77
+ * falls back to asking, with the reason.
78
+ */
79
+ NIGHT_QUICK_EXIT_MS: 60_000,
80
+ /**
81
+ * The headless run's turn ceiling (`claude -p --max-turns`), beside its
82
+ * watchdog (owner decision B, 2026-09-29). A night is some tens of tool calls;
83
+ * this is generous. `dreaming.maxTurns` overrides it.
84
+ */
85
+ NIGHT_MAX_TURNS: 60,
67
86
  /** Reference resolution at a session-ending boundary (recall §9.2), ms. The
68
87
  * resolver stops between candidates past it and the row says so
69
88
  * (`recall.credit` reason `budget-exceeded`); nothing is truncated silently. */
@@ -224,6 +243,21 @@ export interface AdapterConfig {
224
243
  * front of somebody. */
225
244
  readonly ignored?: readonly string[];
226
245
  };
246
+ /**
247
+ * THE HEADLESS NIGHTLY RUN (2026-09-29), read leniently like `pageWriter`:
248
+ * `model` pins the model the run uses (`claude -p --model …`; absent, the
249
+ * user's default), `timeoutMs` its watchdog (absent, `TUNABLES.NIGHT_RUN_MS`).
250
+ * Whether the run is headless at all is the dreaming SETTING (`auto`), which
251
+ * lives in the store, not here.
252
+ */
253
+ readonly dreaming?: {
254
+ readonly model?: string;
255
+ readonly timeoutMs?: number;
256
+ /** The run's turn ceiling; absent, `TUNABLES.NIGHT_MAX_TURNS`. */
257
+ readonly maxTurns?: number;
258
+ /** What this file could not read inside the block, phrased for a person. */
259
+ readonly ignored?: readonly string[];
260
+ };
227
261
  /**
228
262
  * SETTINGS THIS BUILD NO LONGER READS, phrased for a person — e.g.
229
263
  * `"credentialsFile" is no longer used …`. Present only when the file named
@@ -290,6 +324,7 @@ export function loadConfig(raw: unknown): LoadedConfig {
290
324
  parallel?: { enabled: boolean };
291
325
  snapshots?: { dir?: string; keep?: number; mirror?: string; ignored?: string[] };
292
326
  pageWriter?: { mode: PageWriterMode; timeoutMs?: number; ignored?: string[] };
327
+ dreaming?: { model?: string; timeoutMs?: number; maxTurns?: number; ignored?: string[] };
293
328
  retired?: string[];
294
329
  owner?: boolean;
295
330
  timeZone?: string;
@@ -448,6 +483,13 @@ export function loadConfig(raw: unknown): LoadedConfig {
448
483
  retired.push(`"pageWriter.command" is no longer used — the page writer always starts claude`);
449
484
  }
450
485
  }
486
+ // THE THIRD LENIENT BLOCK (2026-09-29): the headless nightly run's model pin
487
+ // and watchdog. A bad field costs that field and is named; nothing here
488
+ // ever sets `unreadable`.
489
+ const dreaming = rec["dreaming"];
490
+ if (dreaming !== undefined) {
491
+ out.dreaming = readDreaming(dreaming);
492
+ }
451
493
  // THE FIRST LENIENT BLOCK. See the `snapshots` knob above for why: a backup
452
494
  // preference that could not be read must cost the backup preference and
453
495
  // nothing else. Nothing in here ever sets `unreadable`.
@@ -542,6 +584,44 @@ function readPageWriter(raw: unknown): {
542
584
  return done();
543
585
  }
544
586
 
587
+ /**
588
+ * The `dreaming` block, read leniently. A model name is one token that does
589
+ * not start with a dash — it goes on a command line (`--model <name>`), and a
590
+ * value that looked like a flag would be read as one.
591
+ */
592
+ function readDreaming(raw: unknown): { model?: string; timeoutMs?: number; maxTurns?: number; ignored?: string[] } {
593
+ const raws: string[] = [];
594
+ const out: { model?: string; timeoutMs?: number; maxTurns?: number } = {};
595
+ const done = (): typeof out & { ignored?: string[] } => (raws.length === 0 ? out : { ...out, ignored: tidy(raws) });
596
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
597
+ raws.push(`"dreaming" was not an object; it was ignored`);
598
+ return done();
599
+ }
600
+ const d = raw as Record<string, unknown>;
601
+ const model = d["model"];
602
+ if (typeof model === "string" && /^[A-Za-z0-9][A-Za-z0-9._:[\]/-]*$/.test(model.trim())) {
603
+ out.model = model.trim();
604
+ } else if (model !== undefined) {
605
+ raws.push(`"dreaming.model" was ${JSON.stringify(model)}, which is not a model name; the default model is used`);
606
+ }
607
+ const timeoutMs = d["timeoutMs"];
608
+ if (typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0) {
609
+ out.timeoutMs = timeoutMs;
610
+ } else if (timeoutMs !== undefined) {
611
+ raws.push(`"dreaming.timeoutMs" was ${JSON.stringify(timeoutMs)}; using the default watchdog`);
612
+ }
613
+ const maxTurns = d["maxTurns"];
614
+ if (typeof maxTurns === "number" && Number.isInteger(maxTurns) && maxTurns > 0) {
615
+ out.maxTurns = maxTurns;
616
+ } else if (maxTurns !== undefined) {
617
+ raws.push(`"dreaming.maxTurns" was ${JSON.stringify(maxTurns)}; using the default`);
618
+ }
619
+ for (const key of Object.keys(d)) {
620
+ if (key !== "model" && key !== "timeoutMs" && key !== "maxTurns") raws.push(`"dreaming.${key}" is not a setting this reads; it was ignored`);
621
+ }
622
+ return done();
623
+ }
624
+
545
625
  /**
546
626
  * The `snapshots` block, read leniently — the FIRST place in this file that
547
627
  * never stands the configuration down.