counterparts 0.3.11 → 0.3.13

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 (150) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/docs/QUICKSTART.md +5 -0
  3. package/docs/README.md +2 -2
  4. package/docs/module-map.md +3 -3
  5. package/package.json +1 -1
  6. package/src/adapters/claude-code/CONTRACT.md +36 -10
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  8. package/src/adapters/claude-code/NOTES.md +182 -0
  9. package/src/adapters/claude-code/bin/hook.ts +46 -12
  10. package/src/adapters/claude-code/bin/runner.ts +7 -1
  11. package/src/adapters/claude-code/doctor.ts +632 -18
  12. package/src/adapters/claude-code/hooks.ts +61 -16
  13. package/src/adapters/claude-code/index.ts +11 -0
  14. package/src/adapters/claude-code/night-run.ts +150 -14
  15. package/src/adapters/claude-code/transcript.ts +268 -1
  16. package/src/adapters/cli/CONTRACT.md +5 -0
  17. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  18. package/src/adapters/cli/NOTES.md +111 -0
  19. package/src/adapters/cli/commands.ts +134 -92
  20. package/src/adapters/cli/dream-core.ts +57 -42
  21. package/src/adapters/cli/export.ts +320 -21
  22. package/src/adapters/cli/help.ts +2 -1
  23. package/src/adapters/cli/index.ts +1 -0
  24. package/src/adapters/cli/install.ts +39 -7
  25. package/src/adapters/cli/mechanisms.ts +7 -1
  26. package/src/adapters/cli/uninstall.ts +13 -5
  27. package/src/adapters/cli/wire.ts +189 -63
  28. package/src/adapters/config.ts +2 -0
  29. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  30. package/src/adapters/dashboard/NOTES.md +79 -0
  31. package/src/adapters/dashboard/registries.ts +34 -2
  32. package/src/adapters/dashboard/web/README.md +19 -14
  33. package/src/adapters/dashboard/web/actions.ts +23 -1
  34. package/src/adapters/dashboard/web/flow.ts +14 -0
  35. package/src/adapters/dashboard/web/lanes.ts +10 -0
  36. package/src/adapters/dashboard/web/narrate.ts +88 -2
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  38. package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
  39. package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
  40. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  41. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  43. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  44. package/src/adapters/dashboard/web/server.ts +0 -5
  45. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  46. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  47. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  48. package/src/adapters/dashboard/web/views/health.ts +21 -3
  49. package/src/adapters/dashboard/web/views/search.ts +4 -45
  50. package/src/adapters/dashboard/web/views.ts +2 -2
  51. package/src/adapters/fired.ts +430 -28
  52. package/src/adapters/host-wiring.ts +300 -0
  53. package/src/adapters/hosts.ts +11 -0
  54. package/src/adapters/lifecycle.ts +42 -2
  55. package/src/adapters/log/index.ts +9 -0
  56. package/src/adapters/mcp/CONTRACT.md +151 -11
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  58. package/src/adapters/mcp/NOTES.md +313 -1
  59. package/src/adapters/mcp/bin/serve.ts +74 -1
  60. package/src/adapters/mcp/deliberate.ts +169 -651
  61. package/src/adapters/mcp/facts.ts +1094 -0
  62. package/src/adapters/mcp/index.ts +25 -7
  63. package/src/adapters/mcp/meaning.ts +1610 -0
  64. package/src/adapters/mcp/server.ts +835 -150
  65. package/src/adapters/mcp/stdio.ts +3 -1
  66. package/src/adapters/mcp/stood-down.ts +51 -0
  67. package/src/adapters/mcp/tools.ts +167 -41
  68. package/src/adapters/plugin-run.sh +133 -0
  69. package/src/adapters/plugin.ts +329 -0
  70. package/src/adapters/sessions.ts +18 -4
  71. package/src/core/associate/CONTRACT.md +2 -1
  72. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  73. package/src/core/associate/NOTES.md +45 -0
  74. package/src/core/briefing.ts +12 -3
  75. package/src/core/contradictions.ts +184 -0
  76. package/src/core/counterpart.ts +797 -51
  77. package/src/core/dream/CONTRACT.md +36 -4
  78. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  79. package/src/core/dream/NOTES.md +107 -0
  80. package/src/core/dream/feeling-weeks.ts +198 -0
  81. package/src/core/dream/index.ts +109 -18
  82. package/src/core/dream/reflect.ts +346 -87
  83. package/src/core/dream/tunables.ts +24 -4
  84. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  85. package/src/core/encode/NOTES.md +7 -0
  86. package/src/core/encode/words.ts +45 -0
  87. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  88. package/src/core/fit/NOTES.md +39 -1
  89. package/src/core/fit/index.ts +40 -0
  90. package/src/core/handoff/CONTRACT.md +37 -2
  91. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  92. package/src/core/handoff/NOTES.md +72 -0
  93. package/src/core/handoff/index.ts +214 -12
  94. package/src/core/handoff/last-here.ts +6 -4
  95. package/src/core/mint.ts +12 -2
  96. package/src/core/physics/CONTRACT.md +14 -2
  97. package/src/core/physics/NOTES.md +33 -1
  98. package/src/core/physics/index.ts +28 -5
  99. package/src/core/prospective/CONTRACT.md +45 -6
  100. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  101. package/src/core/prospective/NOTES.md +138 -0
  102. package/src/core/prospective/derive.ts +33 -5
  103. package/src/core/prospective/index.ts +90 -5
  104. package/src/core/prospective/windows.ts +72 -1
  105. package/src/core/recall/CONTRACT.md +31 -12
  106. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  107. package/src/core/recall/NOTES.md +70 -1
  108. package/src/core/recall/feeling-ask.ts +10 -1
  109. package/src/core/recall/index.ts +3 -1
  110. package/src/core/recall/probe.ts +58 -0
  111. package/src/core/recall/session.ts +46 -2
  112. package/src/core/recall/time-ask.ts +487 -0
  113. package/src/core/remember/CONTRACT.md +4 -1
  114. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  115. package/src/core/remember/NOTES.md +8 -0
  116. package/src/core/remember/proposals.ts +47 -5
  117. package/src/core/revision.ts +18 -1
  118. package/src/core/schemas/CONTRACT.md +21 -1
  119. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  120. package/src/core/schemas/NOTES.md +144 -0
  121. package/src/core/schemas/aliases.ts +55 -5
  122. package/src/core/schemas/index.ts +93 -1
  123. package/src/core/schemas/types.ts +2 -0
  124. package/src/core/self/CONTRACT.md +32 -5
  125. package/src/core/self/INTERFACE-GAPS.md +7 -2
  126. package/src/core/self/NOTES.md +102 -1
  127. package/src/core/self/behind.ts +43 -3
  128. package/src/core/self/briefing.ts +12 -2
  129. package/src/core/self/chapter-address.ts +254 -0
  130. package/src/core/self/episodes.ts +27 -0
  131. package/src/core/self/index.ts +83 -8
  132. package/src/core/self/page.ts +88 -0
  133. package/src/core/self/tunables.ts +5 -0
  134. package/src/core/self/work.ts +35 -2
  135. package/src/core/self/writer.ts +30 -0
  136. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  137. package/src/core/sleep/NOTES.md +20 -1
  138. package/src/core/sleep/consolidate.ts +59 -7
  139. package/src/core/sleep/index.ts +3 -0
  140. package/src/core/sleep/prune.ts +6 -2
  141. package/src/core/sleep/types.ts +7 -0
  142. package/src/core/store/CONTRACT.md +16 -0
  143. package/src/core/store/NOTES.md +66 -0
  144. package/src/core/store/feelings.ts +14 -1
  145. package/src/core/store/index.ts +483 -16
  146. package/src/core/store/operational.ts +95 -2
  147. package/src/core/store/owner-op-seam.ts +23 -0
  148. package/src/core/time.ts +152 -0
  149. package/tools/install-loop/run.sh +48 -12
  150. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -22,7 +22,9 @@ export interface StdioOptions {
22
22
  }
23
23
 
24
24
  export async function serveStdio(
25
- server: McpServer,
25
+ // Only `handle` is used, so a stand-in that answers the protocol and nothing
26
+ // else (`stood-down.ts`) is served by the same pump.
27
+ server: Pick<McpServer, "handle">,
26
28
  input: AsyncIterable<string | Uint8Array>,
27
29
  opts: StdioOptions,
28
30
  ): Promise<void> {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * A SERVER THAT IS THERE AND OFFERS NOTHING — the plugin's MCP server when the
3
+ * npm install's own `counterparts` server is already registered in this host
4
+ * (`adapters/plugin.ts#mcpGate`).
5
+ *
6
+ * Why not just exit: Claude Code reports a server that exited at start-up as
7
+ * "failed", which is a broken tool rather than a deliberate stand-down (scar
8
+ * §2.4: a stood-down tool must be distinguishable from a broken one). So it
9
+ * answers `initialize` with no tool capability worth having, lists no tools,
10
+ * and puts the reason in `instructions` — the one field of a server with no
11
+ * tools that a model, and `/mcp`, will show.
12
+ *
13
+ * It opens no store, reads no configuration and writes nothing: a stood-down
14
+ * server that touched the memory would be the double-write this exists to
15
+ * prevent.
16
+ */
17
+ import { ERROR_CODES, failure, negotiateVersion, success } from "./protocol.js";
18
+ import type { Request, Response } from "./protocol.js";
19
+ import { SERVER_NAME, SERVER_VERSION } from "./server.js";
20
+
21
+ export interface StoodDownServer {
22
+ handle(request: Request): Promise<Response | null>;
23
+ }
24
+
25
+ export function stoodDownServer(instructions: string): StoodDownServer {
26
+ return {
27
+ handle(request: Request): Promise<Response | null> {
28
+ const id = request.id;
29
+ // A notification is answered with nothing, ever (`protocol.ts`).
30
+ if (id === undefined) return Promise.resolve(null);
31
+ const params = request.params ?? {};
32
+ switch (request.method) {
33
+ case "initialize":
34
+ return Promise.resolve(
35
+ success(id, {
36
+ protocolVersion: negotiateVersion(params["protocolVersion"]),
37
+ capabilities: { tools: { listChanged: false } },
38
+ serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
39
+ instructions,
40
+ }),
41
+ );
42
+ case "tools/list":
43
+ return Promise.resolve(success(id, { tools: [] }));
44
+ case "ping":
45
+ return Promise.resolve(success(id, {}));
46
+ default:
47
+ return Promise.resolve(failure(id, ERROR_CODES.METHOD_NOT_FOUND, `${request.method}: this server is standing down. ${instructions}`));
48
+ }
49
+ },
50
+ };
51
+ }
@@ -57,6 +57,8 @@
57
57
  */
58
58
  import { CORE_EMOTIONS } from "../../core/feelings-wheel.js";
59
59
  import { RECALL_MAX_IDS } from "./deliberate.js";
60
+ import { FACTS_MEANING_CAP, FACTS_PAGE_SIZE } from "./facts.js";
61
+ import { RECURRENCES } from "../../core/time.js";
60
62
 
61
63
  /**
62
64
  * A MEMORY'S TITLE, ASKED FOR AS ONE LINE (2026-09-28, build B). Indexes — the
@@ -187,9 +189,9 @@ const UNRESOLVED_PROPERTY = {
187
189
  /**
188
190
  * WHAT GOES IN `emotion` AND WHAT IN `carried_by` — said the same way at every
189
191
  * door a model writes a feeling through (note, session_end, a dream's
190
- * feeling-now, a reflection's feelings), 2026-09-28: a dream put a phrase in
191
- * `emotion` because nothing it read said the word goes there and the nuance
192
- * in `carried_by`. A phrase that still arrives there is split, not refused.
192
+ * feeling-now, a reflection's feelings; note's feelingsNow since 2026-10-02),
193
+ * 2026-09-28: a dream put a phrase in `emotion` because nothing it read said
194
+ * the word goes there and the nuance in `carried_by`. A phrase that still arrives there is split, not refused.
193
195
  */
194
196
  export const EMOTION_TEXT =
195
197
  "ONE word: the feeling, from the wheel (happy: hopeful, eager, amused, proud; warm: grateful, fond, trusted, moved, tender; calm: steadied, relieved, settled, content; curious: interested, recognized, clarified, amazed, confused; sad: wistful, rueful, disappointed, lonely; uneasy: sheepish, caught out, guilty, unsettled, wary, worried, afraid; angry: frustrated, hurt, critical, disgusted) or your own word, kept as yours. Never a phrase — the nuance goes in carried_by. The core you name is kept even when the word sits under another: hurt can be sad or angry.";
@@ -239,6 +241,34 @@ const FEELINGS_PROPERTY = {
239
241
  },
240
242
  } as const;
241
243
 
244
+ /**
245
+ * `feelingsNow` on a `note` (2026-10-02, lane B, owner pick 2): RE-FEELING
246
+ * WHILE AWAKE. When an old memory comes up in a session and feels different
247
+ * now, a later feeling beside the first — the nightly reflection's
248
+ * feeling-now, from an ordinary session. On `note` and not `session_end`: the
249
+ * moment it comes up is mid-session, and `note` already acts on existing
250
+ * memories without writing one (`settle`).
251
+ */
252
+ const FEELINGS_NOW_PROPERTY = {
253
+ type: "array",
254
+ description:
255
+ "Optional: when a memory you were shown in this session (by recall, or a write's neighbours) feels DIFFERENT now than when it was written, record how it feels now, beside the first — which stays. One object each, at most 5; `text` may be left out. Not for a new moment (that is `feelings`), not to restate the old feeling, and not on a memory you have not read here (recall it by id first). At most once a calendar day per memory; recorded as felt today, looking back, awake.",
256
+ items: {
257
+ type: "object",
258
+ properties: {
259
+ id: { type: "string", description: "The memory's id, as recall or a write showed it." },
260
+ whose: { type: "string", enum: ["self", "owner"], description: "Yours (the default), or the owner's when they said how it sits now." },
261
+ core: { type: "string", enum: CORES, description: `${CORE_TEXT} Leave it out to use the word's own core.` },
262
+ emotion: { type: "string", description: EMOTION_TEXT },
263
+ strength: { type: "number", minimum: 0, maximum: 1, description: "How strong now, 0-1. Leave it out for the word's default." },
264
+ valence: { type: "number", minimum: -1, maximum: 1, description: "Optional: how pleasant now, -1 to 1." },
265
+ carried_by: { type: "string", description: `${CARRIED_BY_TEXT} Say what changed.` },
266
+ },
267
+ required: ["id", "emotion"],
268
+ additionalProperties: false,
269
+ },
270
+ } as const;
271
+
242
272
  /**
243
273
  * `traits` on a `note` or a `session_end` entry (folded into schema v9,
244
274
  * 2026-09-27): trait nudges — where this memory shows how I acted, on one of
@@ -287,9 +317,55 @@ const TRAITS_PROPERTY = {
287
317
  const EVENT_DATE_PROPERTY = {
288
318
  type: ["string", "null"],
289
319
  description:
290
- 'Optional: the calendar date this memory is ABOUT, when that is a future date — so it comes back around then. Write it yourself, in one of four shapes: a day "2026-10-15", a month "2026-10", a range of two days "2026-10-20..2026-10-31" (that is how to say "late October"), or a year "2026" (a year alone never comes back on its own). Say "before the 15th" as the day or a range ending on it. Leave it out when nothing is dated; a date written only in the text is never read. An unreadable date is refused, and nothing is stored. Revising a dated memory by its id with `updates`: its date and remind carry over unless you send new ones; send null to drop the date (done, cancelled).',
320
+ 'Optional: the calendar date this memory is ABOUT, when that is a future date — so it comes back around then (when it already happened, that is occurredOn). Write it yourself, in one of four shapes: a day "2026-10-15", a month "2026-10", a range of two days "2026-10-20..2026-10-31" (that is how to say "late October"), or a year "2026" (a year alone never comes back on its own). Say "before the 15th" as the day or a range ending on it. Leave it out when nothing is dated; a date written only in the text is never read. An unreadable date is refused, and nothing is stored. Revising a dated memory by its id with `updates`: its date, remind and recurring carry over unless you send new ones; send null to drop the date (done, cancelled).',
321
+ } as const;
322
+
323
+ /**
324
+ * `recurring` beside `eventDate` (2026-10-09, the owner's design, held
325
+ * lightly): how often a DAY comes round, anchored on it, in `meta.recurring`.
326
+ * One sentence on the field, which the host serves whole.
327
+ */
328
+ const RECURRING_PROPERTY = {
329
+ type: ["string", "null"],
330
+ enum: [...RECURRENCES, null],
331
+ description:
332
+ 'Optional, with a day eventDate: "daily", "weekly", "monthly" or "yearly" — it then comes back every time, counted from that day (a birthday: its date, "yearly"); null on a revision stops it repeating.',
333
+ } as const;
334
+
335
+ /**
336
+ * v12 (2026-10-03): the writer's three fields on a `note` or a `session_end`
337
+ * entry — what deliberate recall's facts answer will show for each memory
338
+ * (when it happened, who said it, what kind of thing it is). Filled at write
339
+ * time because the context is here now; recall does not guess them.
340
+ */
341
+ const OCCURRED_ON_PROPERTY = {
342
+ type: ["string", "null"],
343
+ description:
344
+ 'Optional: when the thing this memory is about happened — a day "2026-09-24", a month "2026-09", a range "2026-09-21..2026-09-27" or a year "2026". Resolve "yesterday" or "last week" to a real date NOW, while you know today\'s date; leave it out when you do not know. Not eventDate, which is a future date to be reminded on.',
345
+ } as const;
346
+
347
+ const SAID_BY_PROPERTY = {
348
+ type: "string",
349
+ enum: ["owner", "self", "inferred"],
350
+ description:
351
+ 'Optional: who said it — "owner" (they told you), "self" (you said or decided it), "inferred" (your own reading; nobody said it).',
352
+ } as const;
353
+
354
+ const STATUS_PROPERTY = {
355
+ type: "string",
356
+ enum: ["done", "planned", "proposed", "asked"],
357
+ description:
358
+ 'Optional: what kind of thing it is — "done" (it happened), "planned" (decided, not done yet), "proposed" (put forward, not decided), "asked" (a question or request still open).',
291
359
  } as const;
292
360
 
361
+ /** The privilege `note` and `session_end` share for the three fields (v12). */
362
+ const WRITE_FACTS_PRIVILEGE: Privilege = {
363
+ claim:
364
+ "`occurredOn`, `saidBy` and `status` are FIELDS you fill, never read out of your text. One that cannot be read is dropped and said beside the memory, which is stored all the same; revising a memory by its id with `updates` carries all three over unless you send your own (occurredOn null: no date carried).",
365
+ mechanizedBy:
366
+ "src/adapters/mcp/server.ts#readWriteFacts -> src/core/counterpart.ts#carryFacts -> src/core/mint.ts#mintProposal -> src/core/store/index.ts#insertOne (occurred_on, said_by, status)",
367
+ };
368
+
293
369
  const REMIND_PROPERTY = {
294
370
  type: "string",
295
371
  enum: ["plain", "quiet"],
@@ -307,9 +383,9 @@ const DATE_PRIVILEGES: readonly Privilege[] = [
307
383
  },
308
384
  {
309
385
  claim:
310
- 'A "plain" reminder is said at most once per beat — on its day, or on the first and the last day of a month or range — and never under observer stance; a "quiet" one is only ever a cue, capped at the footnote tier and spent at most twice per window.',
386
+ 'A "plain" reminder is said at most once per beat — on its day, or on the first and the last day of a month or range — and never under observer stance; a "quiet" one is only ever a cue, capped at the footnote tier and spent at most twice per window. A recurring date counts each time it comes round as its own, and each time it is said or surfaced counts once as a use of the memory; while it repeats, the nightly prune keeps it, and it comes round on its date even when it has faded.',
311
387
  mechanizedBy:
312
- "src/core/prospective/index.ts#Prospective.plainDue + claimPlain (dedupKey latch) + fire (FIRES_PER_WINDOW) -> src/core/counterpart.ts#recallForTurn",
388
+ "src/core/prospective/index.ts#Prospective.plainDue + claimPlain (dedupKey latch) + fire (FIRES_PER_WINDOW) -> src/core/counterpart.ts#recallForTurn; src/core/prospective/windows.ts#recurringWindowAt (one window key per occurrence); Prospective.occurrenceUndelivered -> src/core/counterpart.ts#creditOccurrence (store.reinforce, surfaced) + src/core/physics/index.ts#pruneVerdict (recurring); src/core/prospective/derive.ts#derive (a live repeat is not refused faded)",
313
389
  },
314
390
  {
315
391
  claim:
@@ -332,7 +408,7 @@ const HOW_PROPERTY = {
332
408
  type: "string",
333
409
  enum: ["changed", "corrected", "open"],
334
410
  description:
335
- "With `updates`: how this settles the memory it revises. `changed` (the default): both were true at their time — the old one fades once and is shown as earlier. `corrected`: the old one was wrong — it leaves recall, still readable by its id. `open`: a real disagreement — both stay, each shown with the other. For changed or corrected, say the journey in your own words (\"I used to think X, now Y\").",
411
+ "With `updates`: how this settles the memory it revises. `changed` (the default): both were true at their time — the old one fades once and is shown as earlier. `corrected`: the old one was wrong — it leaves recall, still readable by its id. `open`: a real disagreement — both stay, each shown with the other. For changed or corrected, say the journey in your own words (\"I used to think X, now Y\"). If the memory you name looks unrelated to what you wrote, nothing is settled and you are shown it: settle it yourself if you meant it.",
336
412
  } as const;
337
413
 
338
414
  /** Settling two memories that already exist, on `note` (2026-09-29). */
@@ -358,6 +434,11 @@ const SETTLE_PRIVILEGES: readonly Privilege[] = [
358
434
  "`how` beside `updates` settles the memory it revises — changed (it fades once and is shown as earlier), corrected (archived: out of recall, readable by its id, never deleted), or open (both kept, shown together) — and every settle is recorded (who, how, why, when) and can be undone. A belief, a core memory, a current-state fact and a protected memory keep their own revision path, and the result says so.",
359
435
  mechanizedBy: "src/core/revision.ts#applyRevision -> src/core/contradictions.ts#settleOnWrite",
360
436
  },
437
+ {
438
+ claim:
439
+ "A changed or corrected at a memory that looks unrelated to the new one — not close in meaning, or with no embedder, no content word in common — is held: the new memory is stored unlinked, the old one is left as it was, its title and text come back with the ask to settle it yourself if you meant it, and the hold is recorded. Closing an open thread, moving or dropping a date, and changing a status go straight through.",
440
+ mechanizedBy: "src/core/counterpart.ts#guardUpdate -> src/core/contradictions.ts#updateRelatedness",
441
+ },
361
442
  {
362
443
  claim:
363
444
  "A stored memory comes back with its nearest few existing memories, when any are close, so you can settle one there and then.",
@@ -375,6 +456,7 @@ const NOTE: ToolSpec = {
375
456
  "Do NOT call it to record what you are about to do, or just did, in this session — that is a plan, not a memory.",
376
457
  "Do NOT call it to re-state something you were told earlier in this same conversation; it is already in your context and the ambient path already has it.",
377
458
  "Do NOT call it to store a credential, key or token 'for later' — the gate redacts it and the note is refused as empty.",
459
+ "Do NOT use `feelingsNow` for a feeling in this moment about something new — that is `feelings` on the note that remembers it — nor to restate how an old memory felt: only when it feels DIFFERENT now.",
378
460
  ],
379
461
  privileges: [
380
462
  {
@@ -422,6 +504,7 @@ const NOTE: ToolSpec = {
422
504
  "src/core/remember/updates.ts#resolveUpdates -> src/core/mint.ts#mintProposal (UPDATES_META_KEY)",
423
505
  },
424
506
  ...DATE_PRIVILEGES,
507
+ WRITE_FACTS_PRIVILEGE,
425
508
  {
426
509
  claim: "Under observer stance nothing is written and the refusal says so.",
427
510
  mechanizedBy: "src/core/store/index.ts#mutate (observer stand-down)",
@@ -432,6 +515,12 @@ const NOTE: ToolSpec = {
432
515
  "`settle` settles two memories that already exist, by the same rules, and rewrites neither: the pair and a short why are the record.",
433
516
  mechanizedBy: "src/core/counterpart.ts#settleContradiction -> src/core/contradictions.ts#settle",
434
517
  },
518
+ {
519
+ claim:
520
+ "`feelingsNow` records a later feeling beside the first, the way the nightly reflection does: only on a memory this session was shown, at most once a calendar day per memory, marked as recorded later and awake. The first feeling is never rewritten, and the core reads a later feeling only as it reads a reflection's.",
521
+ mechanizedBy:
522
+ "src/adapters/mcp/server.ts#feelingsNowOutcome -> src/core/dream/reflect.ts#Reflections.feelAgain (source awake, recorded_later) + src/core/store/index.ts#row (feeling_peak_lived)",
523
+ },
435
524
  ],
436
525
  inputSchema: {
437
526
  type: "object",
@@ -477,14 +566,19 @@ const NOTE: ToolSpec = {
477
566
  title: { type: "string", description: TITLE_TEXT },
478
567
  eventDate: EVENT_DATE_PROPERTY,
479
568
  remind: REMIND_PROPERTY,
569
+ recurring: RECURRING_PROPERTY,
570
+ occurredOn: OCCURRED_ON_PROPERTY,
571
+ saidBy: SAID_BY_PROPERTY,
572
+ status: STATUS_PROPERTY,
480
573
  feelings: FEELINGS_PROPERTY,
481
574
  about: ABOUT_PROPERTY,
482
575
  unresolved: UNRESOLVED_PROPERTY,
483
576
  traits: TRAITS_PROPERTY,
577
+ feelingsNow: FEELINGS_NOW_PROPERTY,
484
578
  },
485
579
  // `text` is not required in the published schema (2026-09-29): a `settle`
486
- // alone writes no memory. The server refuses `text-required` when neither
487
- // is sent.
580
+ // or (2026-10-02) `feelingsNow` alone writes no memory. The server refuses
581
+ // `text-required` when none is sent.
488
582
  required: [],
489
583
  additionalProperties: false,
490
584
  },
@@ -493,20 +587,21 @@ const NOTE: ToolSpec = {
493
587
  const RECALL: ToolSpec = {
494
588
  name: "recall",
495
589
  summary:
496
- "Deliberate retrieval: a deeper, more effortful look than the ambient reminding you already get. One argument, three paths — a handle expands that memory exactly, a question runs a search and answers with excerpts, and ids returns a few of those in full.",
590
+ "Deliberate retrieval: a look you take on purpose, beyond the ambient reminding you already get. Three kinds of ask, one per call — a question with a mode (facts or meaning), ids to read memories whole, or a handle (an id or an exact title) to read one.",
497
591
  admission:
498
- "Call it when the ambient context did not bring something you have reason to believe is there, or when you need the full body of a memory you were only shown a footnote or an excerpt of.",
592
+ "Call it when the ambient context did not bring something you have reason to believe is there, or when you need the whole of a memory you were shown only a line or an excerpt of. A question takes mode \"facts\" when you need what happened, who said it, when, and whether it still holds; mode \"meaning\" when you want how something went, how it felt, or what it adds up to — a person, a project, us.",
499
593
  negativeExamples: [
500
594
  "Do NOT call it to check whether a memory exists before writing one — a duplicate is refused at the write, so the check costs a round trip and buys nothing.",
501
595
  "Do NOT call it with a handle you are guessing at: an unresolvable handle is answered as not-found, never as a fuzzy search over the store.",
502
596
  "Do NOT pass a question and ids together, or ids you have not seen in a result: ids is the follow-up to a list, not a second way to search.",
597
+ "Do NOT send a question without a mode: there is no default, and the call is refused with the two modes named.",
503
598
  ],
504
599
  privileges: [
505
600
  {
506
601
  claim:
507
- "A search strengthens nothing — exposure is not recording, and a memory you were only shown in a list is no stronger for having been listed. EXPANDING one in full, by id or by title handle, is USING it: that is credited at the session boundary, once per lived day. The tool itself never writes a memory; what it writes is host bookkeeping — one line saying which memory a title reached.",
602
+ "A search strengthens nothing — a memory you were only shown in a list is no stronger for having been listed. OPENING one, by id or by title handle, is using it, and so is QUOTING the words a question's answer showed you in your reply: either is credited at the session boundary, once per lived day. The tool never writes a memory; what it writes is bookkeeping — which memory a title reached, which memories an answer showed this session, and one count row per call.",
508
603
  mechanizedBy:
509
- "src/core/recall/index.ts#build (the search half: pure; no resolveUse, no coactivate) + src/adapters/expansions.ts#recordHandleResolution -> src/adapters/lifecycle.ts#creditAtBoundary -> src/core/recall/reference.ts (the expansion door) -> src/core/recall/index.ts#resolveUse (once per lived day)",
604
+ "src/adapters/mcp/facts.ts#factsRecall (reads only) + src/adapters/expansions.ts#recordHandleResolution -> src/adapters/lifecycle.ts#creditAtBoundary -> src/core/recall/reference.ts (expansion and quote) + src/adapters/mcp/server.ts#noteAsked -> src/core/counterpart.ts#noteAsked / creditReferences (asked records) -> src/core/recall/index.ts#resolveUse (once per lived day)",
510
605
  },
511
606
  {
512
607
  claim:
@@ -515,53 +610,64 @@ const RECALL: ToolSpec = {
515
610
  },
516
611
  {
517
612
  claim:
518
- "Effort lowers the bar but never removes the hard gates: a memory the conversation did not reach stays dark however hard you look.",
519
- mechanizedBy: "src/adapters/mcp/deliberate.ts#DELIBERATE_TIERS (dark-uncued/below-floor excluded)",
613
+ "A question needs mode: \"facts\" or \"meaning\". Each is its own path, with its own ranking and its own answer, returned as labeled lines in `answer`; tuning one does not change the other.",
614
+ mechanizedBy:
615
+ "src/adapters/mcp/server.ts#recallTool (mode-required, mode-unknown) + src/adapters/mcp/facts.ts#factsRecall + src/adapters/mcp/meaning.ts#meaningRecall",
616
+ },
617
+ {
618
+ claim: `Facts mode considers every memory the question's words reach, every memory linked to a person or project it names, and the ${String(FACTS_MEANING_CAP)} closest by meaning — and, for a question that is only a time, everything in that window. A memory matched more ways ranks higher; it ranks by how strongly it matched, and newer comes first only on a tie.`,
619
+ mechanizedBy:
620
+ "src/adapters/mcp/facts.ts#factsRecall (store.search per word with a limit of its document count; schemas#subjectsIn -> store.memoriesNaming; FACTS_MEANING_CAP)",
520
621
  },
521
622
  {
522
623
  claim:
523
- "The lower-confidence tier is LABELED as such, and quiet items come back with their bodies rather than as a count.",
524
- mechanizedBy: "src/adapters/mcp/deliberate.ts#tierOf",
624
+ "A time in the question filters: \"last week\", \"in September\", \"early October\", \"3 days ago\", \"last Saturday\", a date, \"since 09-20\", \"before 09-20\", \"this morning\" — only memories inside the window come back, by when the thing happened or, with no event date, when it was learned, and the header counts the matches outside it. A week or a month stretches two days each side; a date stays exact; \"before\" a date is every day before it, \"after\" every day after, \"until\" or \"by\" every day through it. \"Around the cut-over\" resolves the event to the date of the memory that best names it, shown in the header as \"cut-over → 09-21\"; \"the last session\" or \"where did we leave off\" means the session the session-start \"Last here\" line named, and its own rows come first.",
625
+ mechanizedBy: "src/core/recall/time-ask.ts#readTimeAsk + src/adapters/mcp/facts.ts#factsRecall (inWindow, lastSession)",
626
+ },
627
+ {
628
+ claim: `A facts answer opens with a count of distinct facts — \"12 match · showing ${String(FACTS_PAGE_SIZE)} · 2 more → page 2\" — and pages with page: 2, 3, … in a stable order. It says \"may not be everything\" only when a cap cut something or weak matches were left out, and says which.`,
629
+ mechanizedBy: "src/adapters/mcp/facts.ts#renderFacts (FACTS_PAGE_SIZE, FACTS_WEAK_FRACTION, meaningCapped)",
525
630
  },
526
631
  {
527
632
  claim:
528
- "The number of candidates considered is reported separately from the number returned, so a count here is never an undercount of the store — and the cap that produced it is reported next to it.",
529
- mechanizedBy: "src/adapters/mcp/deliberate.ts#deliberateRecall (considered/storeSize) + src/adapters/mcp/server.ts#recallPayload (consideredCap)",
633
+ "Each fact says who said it (\"you said\" is the owner, \"I said\" is you, or \"inferred\"), what kind of thing it is (done, planned, proposed, asked), when it happened (or \"no event date\"), when and where it was learned, and whether it is CURRENT. A field the writer did not record says so (\"speaker unknown\"). Earlier versions are folded under the current one with their dates; a corrected one is hidden and counted.",
634
+ mechanizedBy: "src/adapters/mcp/facts.ts#factItem (occurred_on, said_by, status; versions rows + contradictions pairs) + src/adapters/mcp/deliberate.ts#provenanceParts",
530
635
  },
531
636
  {
532
637
  claim:
533
- "A search answers with excerpts and a bounded total, never with every body at full length: an answer the host truncates is not a smaller answer, it is no answer. When something was cut or dropped, the result says so.",
534
- mechanizedBy: "src/adapters/mcp/deliberate.ts#boundMemories (RECALL_EXCERPT_CHARS/RECALL_RESULT_CHARS)",
638
+ "Meaning mode answers with the arc of what the question names — a person, a project, \"us\", or a feeling: the chapters that hold it, in time order, each with a line of what happened, its moments by id and the feelings in it with whose they are, side by side; then earlier readings (dreams, reflections) and what is still open. It arranges; you say what it adds up to. When it names several, the arc follows the one the question asks about (\"what has X been to Y\" is X's; named alike, the first, and it says so), and the rest are listed to ask for by name. In a question about feeling, \"I\" and \"me\" mean YOU, the counterpart, and \"you\" means the owner: to ask about the owner's feelings, say \"the owner\" or the owner's name — do not pass the owner's own words through unchanged.",
639
+ mechanizedBy:
640
+ "src/adapters/mcp/meaning.ts#meaningRecall + src/adapters/mcp/meaning.ts#subjectOf + src/adapters/mcp/meaning.ts#renderMeaning + src/core/recall/feeling-ask.ts#whoseAsked (asker: self, src/adapters/mcp/server.ts#askQuestion)",
535
641
  },
536
642
  {
537
643
  claim:
538
- `Pass ids to read those memories whole. It takes up to ${RECALL_MAX_IDS}, each resolved as an exact address with the same confidentiality boundary; a long body comes in parts, and ids past the result's room wait, named.`,
539
- mechanizedBy: "src/adapters/mcp/deliberate.ts#expandIds (RECALL_MAX_IDS, expandHandle per id) + src/adapters/mcp/deliberate.ts#boundById (RECALL_BODY_CHARS parts, RECALL_ID_RESULT_CHARS)",
644
+ "A matched memory that has faded from long disuse is not dropped: it is listed after the main results as one line — title, date, id, labeled faded — and never takes a main slot. Opening it by id brings it back.",
645
+ mechanizedBy: "src/adapters/mcp/facts.ts#factsRecall (FACTS_FADED_LINES) + src/adapters/mcp/deliberate.ts#hasFaded (FADED_RETAINED)",
540
646
  },
541
647
  {
542
648
  claim:
543
- "Confidential material is returned only in the owner's own session: a direct lookup says it is withholding, a list simply does not contain it.",
544
- mechanizedBy: "src/core/recall/activate.ts#isConfidential + gate verdict confidential-withheld",
649
+ "An answer is bounded and never ships every body at full length: a short fact comes whole, a long one as an excerpt, and the whole answer stays under the result's room. An answer the host truncates is not a smaller answer, it is no answer.",
650
+ mechanizedBy: "src/adapters/mcp/facts.ts#renderFacts (RECALL_EXCERPT_CHARS, RECALL_RESULT_CHARS)",
545
651
  },
546
652
  {
547
653
  claim:
548
- "A chapter of the journal can come back here — it is a first-person account and may rightly come to mind — and every one that does is marked `journal: true`. That row is the account a memory was made from, not a memory: it is outside decay, dedup and the prune, and it is not a claim about the world the way a memory is.",
549
- mechanizedBy: "src/adapters/mcp/deliberate.ts#JOURNAL_GLOSS (ProseDoc.type === episode)",
654
+ `Pass ids to read those memories whole. It takes up to ${RECALL_MAX_IDS}, each resolved as an exact address with the same confidentiality boundary; a long body comes in parts, and ids past the result's room wait, named. Ids and a handle take no mode.`,
655
+ mechanizedBy: "src/adapters/mcp/deliberate.ts#expandIds (RECALL_MAX_IDS, expandHandle per id) + src/adapters/mcp/deliberate.ts#boundById (RECALL_BODY_CHARS parts, RECALL_ID_RESULT_CHARS)",
550
656
  },
551
657
  {
552
658
  claim:
553
- "A question about feeling is answered from the feelings recorded on memories, strongest first. In it, \"I\" and \"me\" mean YOU, the counterpart, and \"you\" means the owner: to ask about the owner's feelings, say \"the owner\" or the owner's name — do not pass the owner's own words through unchanged.",
554
- mechanizedBy: "src/core/recall/feeling-ask.ts#whoseAsked (asker: self) + src/adapters/mcp/deliberate.ts#answerQuestion",
659
+ "Confidential material is returned only in the owner's own session: a direct lookup says it is withholding, a list simply does not contain it.",
660
+ mechanizedBy: "src/adapters/mcp/facts.ts#factsRecall (confidential column) + src/adapters/mcp/deliberate.ts#expandHandle (isConfidential)",
555
661
  },
556
662
  {
557
663
  claim:
558
- "A question about time is answered with the session it means first, marked `recent: true`: \"our most recent session\" or \"where did we leave off\" means the session the session-start \"Last here\" line named (else the newest one here that ended); \"this morning\", \"yesterday\", \"16:01–17:48\" mean the sessions here at work then. Its latest chapter comes first, then the memories it wrote here, newest first. Asked plainly, those lead; a question that is also about something else (\"what did we decide about the deploy today\") only moves up the ones the search found too. Not with a question about feeling, which keeps its own order. Nothing else needs to be passed.",
559
- mechanizedBy: "src/core/recall/recency-ask.ts#readRecencyAsk + src/adapters/mcp/deliberate.ts#answerQuestion (recentRows, leadWith)",
664
+ "A chapter of the journal can come back — it is a first-person account and may rightly come to mind — and every one that does is marked journal. It is the account a memory was made from, not a memory: it is outside decay, dedup and the prune, and it is not a claim about the world the way a memory is. A chapter and the memory made from it come back as one result.",
665
+ mechanizedBy: "src/adapters/mcp/facts.ts#factsRecall (the chapter-copy fold, FACTS_JOURNAL_GLOSS) + src/adapters/mcp/deliberate.ts#JOURNAL_GLOSS (ProseDoc.type === episode)",
560
666
  },
561
667
  {
562
668
  claim:
563
- "Every memory returned says where it came from in `from`: the session that wrote it (\"this session\" for yours), the directory, and when it was written, as far as the row recorded them. A row the nightly run made says so (\"a dream launched from session …\", \"a reflection\"). An older row says less, and \"an earlier session\" when it names none.",
564
- mechanizedBy: "src/adapters/mcp/deliberate.ts#provenanceOf",
669
+ "Every memory says where it came from: the session that wrote it (\"this session\" for yours), the directory, and when, as far as the row recorded them. A row the nightly run made says so (\"a dream launched from session …\", \"a reflection\"). An older row says less, and \"an earlier session\" when it names none.",
670
+ mechanizedBy: "src/adapters/mcp/deliberate.ts#provenanceParts",
565
671
  },
566
672
  {
567
673
  claim: "Under observer stance it stands down over the wire and says so.",
@@ -571,14 +677,25 @@ const RECALL: ToolSpec = {
571
677
  inputSchema: {
572
678
  type: "object",
573
679
  properties: {
574
- handle: {
680
+ question: {
575
681
  type: "string",
576
- description: "A memory id or exact handle to expand. Exact: never treated as a search term.",
682
+ description:
683
+ "What you are trying to remember, in words. Needs mode. A time in it (\"last week\", \"in September\", \"around the cut-over\", \"where did we leave off\") filters a facts answer to that window.",
577
684
  },
578
- question: {
685
+ mode: {
579
686
  type: "string",
687
+ enum: ["facts", "meaning"],
580
688
  description:
581
- "What you are trying to remember, in words. Runs the deeper retrieval and answers with excerpts. A question about time (\"what did we do in our most recent session\", \"this evening\") puts the session it means in this directory first.",
689
+ "Required with a question, and only with one. facts: what happened, who said it, when, whether it still holds — every match, ranked, with dates and speaker. meaning: how something went, felt, and what it adds up to — a person, a project, us.",
690
+ },
691
+ page: {
692
+ type: "integer",
693
+ minimum: 1,
694
+ description: "With a question: which page of the answer (1 is the first). The header says how many more there are.",
695
+ },
696
+ handle: {
697
+ type: "string",
698
+ description: "A memory id or exact title to read whole. Exact: never treated as a search term. Takes no mode.",
582
699
  },
583
700
  ids: {
584
701
  type: "array",
@@ -586,7 +703,7 @@ const RECALL: ToolSpec = {
586
703
  // The cap is one number, imported. A literal here and a constant in
587
704
  // `deliberate.ts` is the drift the registry audit exists to prevent.
588
705
  maxItems: RECALL_MAX_IDS,
589
- description: `Memory ids from an earlier result or an index (a dream's, a reflection's), to read whole — up to ${RECALL_MAX_IDS} at once. A long body comes in parts: see part. Not combinable with handle or question.`,
706
+ description: `Memory ids from an earlier answer or an index (a dream's, a reflection's), to read whole — up to ${RECALL_MAX_IDS} at once. A long body comes in parts: see part. Not combinable with handle or question; takes no mode.`,
590
707
  },
591
708
  part: {
592
709
  type: "integer",
@@ -688,6 +805,7 @@ const SESSION_END: ToolSpec = {
688
805
  mechanizedBy: "src/core/encode/secrets.ts + src/adapters/mcp/server.ts#sessionEndTool (per-entry isolation)",
689
806
  },
690
807
  ...DATE_PRIVILEGES,
808
+ WRITE_FACTS_PRIVILEGE,
691
809
  {
692
810
  claim: "Under observer stance nothing is written and the refusal says so.",
693
811
  mechanizedBy: "src/core/store/index.ts#mutate (observer stand-down)",
@@ -806,6 +924,10 @@ const SESSION_END: ToolSpec = {
806
924
  how: HOW_PROPERTY,
807
925
  eventDate: EVENT_DATE_PROPERTY,
808
926
  remind: REMIND_PROPERTY,
927
+ recurring: RECURRING_PROPERTY,
928
+ occurredOn: OCCURRED_ON_PROPERTY,
929
+ saidBy: SAID_BY_PROPERTY,
930
+ status: STATUS_PROPERTY,
809
931
  feelings: FEELINGS_PROPERTY,
810
932
  about: ABOUT_PROPERTY,
811
933
  unresolved: UNRESOLVED_PROPERTY,
@@ -1187,7 +1309,7 @@ const DREAM: ToolSpec = {
1187
1309
  changes: {
1188
1310
  type: "array",
1189
1311
  description:
1190
- "`propose`: the changes, each an object with `action` — `merge` (ids: two or more near-copies, text: the one memory in better words, title?), `link` (a, b), `replayed` (id), `gist` (text, sources: ids, title?, kind?), `contradiction` (a, b), `settle` (holds, over, how: changed|corrected|open, why — only when the reason is plain; flag otherwise), `feeling-now` (id, core, emotion: ONE word, strength, carried_by: the nuance in your own words), `nominate-core` (id, why). Usually far fewer changes than the limits; none is fine.",
1312
+ "`propose`: the changes, each an object with `action` — `merge` (ids: two or more near-copies, text: the one memory in better words, title?), `link` (a, b), `replayed` (id), `gist` (text, sources: ids, title?, kind?, occurredOn?: when what it draws on happened, saidBy?: owner|self|inferred, status?: done|planned|proposed|asked), `contradiction` (a, b), `settle` (holds, over, how: changed|corrected|open, why — only when the reason is plain; flag otherwise), `feeling-now` (id, core, emotion: ONE word, strength, carried_by: the nuance in your own words), `nominate-core` (id, why). Usually far fewer changes than the limits; none is fine.",
1191
1313
  items: {
1192
1314
  type: "object",
1193
1315
  properties: {
@@ -1203,6 +1325,9 @@ const DREAM: ToolSpec = {
1203
1325
  title: { type: "string" },
1204
1326
  kind: { type: "string", enum: ["self", "person", "entity", "skill", "place", "fact"] },
1205
1327
  sources: { type: "array", items: { type: "string" } },
1328
+ occurredOn: { type: "string", description: "`gist`: when what it draws on happened — a day, a month, a year or a range." },
1329
+ saidBy: { type: "string", enum: ["owner", "self", "inferred"], description: "`gist`: who said it; inferred when it is your own reading." },
1330
+ status: { type: "string", enum: ["done", "planned", "proposed", "asked"], description: "`gist`: what kind of thing it is." },
1206
1331
  core: { type: "string", enum: CORES, description: `\`feeling-now\`: ${CORE_TEXT}` },
1207
1332
  emotion: { type: "string", description: `\`feeling-now\`: ${EMOTION_TEXT}` },
1208
1333
  strength: { type: "number", minimum: 0, maximum: 1 },
@@ -1400,9 +1525,10 @@ export const WAKE: ToolSpec = {
1400
1525
  summary:
1401
1526
  "Start here in Claude Desktop: wakes this chat's memory. Returns the same briefing a Claude Code session gets when it starts — who I am, what is nearby and arriving, any reminder due today — and a session id for this chat.",
1402
1527
  admission:
1403
- "Call it once, at the start of a chat, before answering the first message. Then pass the session id it returns as `session` on session_end, chapter, dream and reflect in this chat; a call that leaves it out is filed under the most recent Desktop session, and says so.",
1528
+ "Call it first in every new chat, once, before answering anything — above all anything about the person, the past, or work in progress. Then pass the session id it returns as `session` on session_end, chapter, dream and reflect in this chat; a call that leaves it out is filed under the most recent Desktop session, and says so.",
1404
1529
  negativeExamples: [
1405
- "Do NOT call it again later in the same chat to refresh what you know — it starts a new session. Ask `recall` a question instead.",
1530
+ "Do NOT answer what you remember — yesterday, a person, a project — from `recall` alone before this chat has woken, and never call what `recall` returned the full record: it is a slice. Wake first; the wake carries the whole store's Yesterday line.",
1531
+ "Do NOT call it again later in the same chat to refresh what you know — it starts a new session. Ask `recall` a question (with a mode) instead.",
1406
1532
  "Do NOT call it in a Claude Code session — Desktop's Code tab included, where these tools are Claude Desktop's: the hook already woke you, and a wake here would start a second session beside yours. Pass your session id — the one your wake or Stop ask names — as `session` instead.",
1407
1533
  ],
1408
1534
  privileges: [
@@ -0,0 +1,133 @@
1
+ #!/bin/sh
2
+ # The Claude Code plugin's launcher (prototype, 2026-10-09).
3
+ #
4
+ # sh plugin-run.sh hook - the five hooks (hooks/hooks.json)
5
+ # sh plugin-run.sh mcp - the memory server (.claude-plugin/plugin.json)
6
+ # sh plugin-run.sh cli … - the console, for a plugin user with no
7
+ # `counterparts` on PATH (commands/doctor.md)
8
+ #
9
+ # Claude Code runs this with `sh` and the absolute path, so it needs no exec
10
+ # bit and no runtime of its own. Its one job is the one the npm install does
11
+ # at `install` time and a plugin cannot: FIND A RUNTIME. The install writes the
12
+ # absolute path of the runtime it ran under into the host's configuration
13
+ # (cli/install.ts, scar 2.18: a host's PATH is not the login shell's); a
14
+ # plugin's command is fixed in a file we ship, so the search happens here, at
15
+ # every launch, in this order:
16
+ #
17
+ # 1. COUNTERPARTS_RUNTIME, when set: that executable and nothing else.
18
+ # 2. Bun 1.3+: on PATH, then $BUN_INSTALL/bin, ~/.bun/bin, Homebrew.
19
+ # 3. Node 22.15+: on PATH, then Homebrew, /usr/local, Volta, nvm, fnm, asdf,
20
+ # mise. A Node older than 22.15 is skipped, not run (it cannot load the
21
+ # TypeScript sources: adapters/runtime.ts#NODE_FLOOR).
22
+ #
23
+ # Bun first, because that is what the npm bins do (cli/bin/counterparts.mjs).
24
+ # The entry it runs is the same one those bins run (hook.mjs, serve.mjs,
25
+ # counterparts.mjs), so the runtime choice is the only difference.
26
+ #
27
+ # With no runtime: a hook says so ONCE, at SessionStart, as a systemMessage the
28
+ # person sees (and a line of context, so the model can say it too), and exits 0;
29
+ # every other event exits 0 in silence. The server exits 127 with the reason on
30
+ # stderr, which /mcp shows. Claude Code's own native binary does not double as
31
+ # a JavaScript runtime (BUN_BE_BUN=1 is ignored; measured on 2.1.295).
32
+ #
33
+ # Only shell built-ins and parameter expansion below, plus the runtimes'
34
+ # own --version: a PATH with nothing on it still reaches the message.
35
+
36
+ mode="${1:-}"
37
+ [ $# -gt 0 ] && shift
38
+
39
+ here="${0%/*}"
40
+ [ "$here" = "$0" ] && here="."
41
+
42
+ case "$mode" in
43
+ hook) entry="$here/claude-code/bin/hook.mjs" ;;
44
+ mcp) entry="$here/mcp/bin/serve.mjs" ;;
45
+ cli) entry="$here/cli/bin/counterparts.mjs" ;;
46
+ *)
47
+ echo "counterparts plugin-run: usage: sh plugin-run.sh hook|mcp|cli [args]" >&2
48
+ exit 2
49
+ ;;
50
+ esac
51
+
52
+ runtime=""
53
+
54
+ # version_at_least <version> <major> <minor> (a leading "v" is ignored)
55
+ version_at_least() {
56
+ v="${1#v}"
57
+ major="${v%%.*}"
58
+ rest="${v#*.}"
59
+ minor="${rest%%.*}"
60
+ minor="${minor%%-*}"
61
+ case "$major" in "" | *[!0-9]*) return 1 ;; esac
62
+ case "$minor" in "" | *[!0-9]*) return 1 ;; esac
63
+ [ "$major" -gt "$2" ] && return 0
64
+ [ "$major" -eq "$2" ] && [ "$minor" -ge "$3" ] && return 0
65
+ return 1
66
+ }
67
+
68
+ try_bun() {
69
+ [ -n "$1" ] && [ -x "$1" ] || return 1
70
+ v="$("$1" --version 2>/dev/null)" || return 1
71
+ version_at_least "$v" 1 3 || return 1
72
+ runtime="$1"
73
+ }
74
+
75
+ try_node() {
76
+ [ -n "$1" ] && [ -x "$1" ] || return 1
77
+ v="$("$1" --version 2>/dev/null)" || return 1
78
+ version_at_least "$v" 22 15 || return 1
79
+ runtime="$1"
80
+ }
81
+
82
+ try_node_glob() { # a glob of node binaries: the first that is new enough
83
+ for candidate in "$@"; do
84
+ try_node "$candidate" && return 0
85
+ done
86
+ return 1
87
+ }
88
+
89
+ if [ -n "${COUNTERPARTS_RUNTIME:-}" ]; then
90
+ case "${COUNTERPARTS_RUNTIME##*/}" in
91
+ node*) try_node "$COUNTERPARTS_RUNTIME" ;;
92
+ *) try_bun "$COUNTERPARTS_RUNTIME" ;;
93
+ esac
94
+ else
95
+ try_bun "$(command -v bun 2>/dev/null)" ||
96
+ try_bun "${BUN_INSTALL:-$HOME/.bun}/bin/bun" ||
97
+ try_bun "$HOME/.bun/bin/bun" ||
98
+ try_bun /opt/homebrew/bin/bun ||
99
+ try_bun /usr/local/bin/bun ||
100
+ try_node "$(command -v node 2>/dev/null)" ||
101
+ try_node /opt/homebrew/bin/node ||
102
+ try_node /usr/local/bin/node ||
103
+ try_node /usr/bin/node ||
104
+ try_node "$HOME/.volta/bin/node" ||
105
+ try_node_glob "$HOME"/.nvm/versions/node/v*/bin/node ||
106
+ try_node_glob "$HOME"/.local/share/fnm/node-versions/*/installation/bin/node ||
107
+ try_node_glob "$HOME/Library/Application Support/fnm/node-versions"/*/installation/bin/node ||
108
+ try_node_glob "$HOME"/.asdf/installs/nodejs/*/bin/node ||
109
+ try_node_glob "$HOME"/.local/share/mise/installs/node/*/bin/node
110
+ fi
111
+
112
+ if [ -n "$runtime" ]; then
113
+ exec "$runtime" "$entry" "$@"
114
+ fi
115
+
116
+ said="Counterparts (memory) is not running: it needs Bun 1.3+ or Node.js 22.15+ and found neither on PATH or in the usual places. Install one (https://bun.sh or https://nodejs.org), then restart Claude Code."
117
+
118
+ if [ "$mode" = "hook" ]; then
119
+ payload=""
120
+ while IFS= read -r line || [ -n "$line" ]; do
121
+ payload="$payload$line"
122
+ done
123
+ case "$payload" in
124
+ *'"hook_event_name":"SessionStart"'* | *'"hook_event_name": "SessionStart"'*)
125
+ printf '{"systemMessage":"%s","hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"%s"}}\n' \
126
+ "$said" "Counterparts memory is not running in this session (no Bun 1.3+ or Node.js 22.15+ found). If the person asks about memory, tell them that."
127
+ ;;
128
+ esac
129
+ exit 0
130
+ fi
131
+
132
+ echo "$said" >&2
133
+ exit 127