counterparts 0.3.44 → 0.3.46

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 (105) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/CONSTITUTION.md +6 -4
  3. package/README.md +4 -3
  4. package/docs/QUICKSTART.md +1 -1
  5. package/docs/manual.md +123 -0
  6. package/docs/module-map.md +2 -1
  7. package/package.json +2 -1
  8. package/src/adapters/claude-code/CONTRACT.md +15 -4
  9. package/src/adapters/claude-code/NOTES.md +55 -1
  10. package/src/adapters/claude-code/awake.ts +122 -0
  11. package/src/adapters/claude-code/bin/runner.ts +9 -1
  12. package/src/adapters/claude-code/child.ts +14 -4
  13. package/src/adapters/claude-code/doctor-self-page.ts +47 -2
  14. package/src/adapters/claude-code/doctor.ts +27 -8
  15. package/src/adapters/claude-code/hooks.ts +49 -9
  16. package/src/adapters/claude-code/night-catch-up.ts +68 -1
  17. package/src/adapters/claude-code/night-run.ts +97 -19
  18. package/src/adapters/claude-code/transcript.ts +60 -6
  19. package/src/adapters/cli/commands-install.ts +9 -4
  20. package/src/adapters/cli/commands-note.ts +6 -5
  21. package/src/adapters/cli/commands-readings.ts +10 -2
  22. package/src/adapters/cli/commands.ts +4 -3
  23. package/src/adapters/cli/dream-core.ts +1 -1
  24. package/src/adapters/cli/help.ts +3 -2
  25. package/src/adapters/cli/uninstall.ts +21 -4
  26. package/src/adapters/config.ts +16 -3
  27. package/src/adapters/dashboard/registries.ts +1 -1
  28. package/src/adapters/dashboard/web/narrate.ts +5 -1
  29. package/src/adapters/dashboard/web/pages/memories/index.js +4 -2
  30. package/src/adapters/dashboard/web/views/memories.ts +8 -2
  31. package/src/adapters/dashboard/web/views/overview.ts +14 -3
  32. package/src/adapters/dashboard/web/views/today.ts +3 -1
  33. package/src/adapters/hosts.ts +26 -4
  34. package/src/adapters/lifecycle.ts +9 -2
  35. package/src/adapters/log/index.ts +4 -1
  36. package/src/adapters/mcp/CONTRACT.md +5 -2
  37. package/src/adapters/mcp/INTERFACE-GAPS.md +5 -0
  38. package/src/adapters/mcp/NOTES.md +45 -1
  39. package/src/adapters/mcp/facts.ts +23 -6
  40. package/src/adapters/mcp/manual.ts +145 -0
  41. package/src/adapters/mcp/meaning.ts +7 -2
  42. package/src/adapters/mcp/server-self-tools.ts +7 -2
  43. package/src/adapters/mcp/server-session-end.ts +2 -2
  44. package/src/adapters/mcp/server-words.ts +13 -4
  45. package/src/adapters/mcp/server.ts +96 -30
  46. package/src/adapters/mcp/tools.ts +75 -13
  47. package/src/adapters/mcp/write-up.ts +46 -4
  48. package/src/adapters/plugin-run.sh +32 -8
  49. package/src/adapters/remote/http.ts +6 -1
  50. package/src/adapters/sessions.ts +43 -0
  51. package/src/adapters/snapshots.ts +59 -0
  52. package/src/adapters/update-check.ts +1 -1
  53. package/src/core/associate/CONTRACT.md +4 -0
  54. package/src/core/associate/NOTES.md +43 -0
  55. package/src/core/associate/index.ts +41 -5
  56. package/src/core/associate/tunables.ts +29 -0
  57. package/src/core/counterpart-deposit.ts +45 -14
  58. package/src/core/counterpart-types.ts +5 -2
  59. package/src/core/counterpart-wake-news.ts +230 -0
  60. package/src/core/counterpart-wake-shape.ts +95 -17
  61. package/src/core/counterpart.ts +25 -2
  62. package/src/core/dream/CONTRACT.md +4 -3
  63. package/src/core/dream/NOTES.md +9 -0
  64. package/src/core/dream/index.ts +26 -9
  65. package/src/core/dream/reflect.ts +4 -2
  66. package/src/core/onboarding.ts +43 -13
  67. package/src/core/recall/CONTRACT.md +1 -1
  68. package/src/core/recall/INTERFACE-GAPS.md +1 -1
  69. package/src/core/recall/NOTES.md +110 -0
  70. package/src/core/recall/activate.ts +28 -5
  71. package/src/core/recall/gate.ts +63 -12
  72. package/src/core/recall/habituation.ts +15 -2
  73. package/src/core/recall/index.ts +10 -2
  74. package/src/core/recall/session.ts +9 -3
  75. package/src/core/recall/tunables.ts +8 -2
  76. package/src/core/remember/CONTRACT.md +23 -4
  77. package/src/core/remember/NOTES.md +157 -0
  78. package/src/core/remember/index.ts +2 -0
  79. package/src/core/remember/owes.ts +100 -1
  80. package/src/core/remember/owner-strike-seam.ts +7 -1
  81. package/src/core/remember/proposals.ts +75 -27
  82. package/src/core/remember/retention.ts +35 -3
  83. package/src/core/remember/spans.ts +31 -2
  84. package/src/core/schemas/index.ts +2 -2
  85. package/src/core/self/CONTRACT.md +1 -1
  86. package/src/core/self/NOTES.md +54 -0
  87. package/src/core/self/briefing-delivery.ts +16 -4
  88. package/src/core/self/identity.ts +4 -0
  89. package/src/core/self/index.ts +4 -1
  90. package/src/core/self/journal-file.ts +2 -1
  91. package/src/core/self/tunables.ts +34 -2
  92. package/src/core/self/writer.ts +9 -2
  93. package/src/core/sleep/CONTRACT.md +4 -2
  94. package/src/core/sleep/consolidate.ts +8 -0
  95. package/src/core/sleep/cycle.ts +20 -0
  96. package/src/core/sleep/types.ts +7 -0
  97. package/src/core/store/CONTRACT.md +1 -1
  98. package/src/core/store/NOTES.md +9 -1
  99. package/src/core/store/index.ts +27 -4
  100. package/src/core/store/reads-memories.ts +44 -1
  101. package/src/core/store/shapes.ts +10 -0
  102. package/src/core/store/tag-reads.ts +3 -0
  103. package/src/core/told.ts +249 -0
  104. package/src/core/types.ts +15 -0
  105. package/tools/install-loop/run.sh +21 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,119 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.46 — 2026-11-03
4
+
5
+ **New stores get starter memories and the new wake layout; existing stores barely change.** A store `counterparts install` (or `start-fresh`, or hosted signup) creates begins with eleven starter notes, "told, not lived", counted apart from your own memories, and its sessions start in the wake's shape, which now opens with what happened since the last night, steps an old handoff down to one line, drops empty sections and settles dated things that already happened. A store that already exists gets no starter notes and keeps its wake-shape setting; where the shape is on (`counterparts wake-shape on`), its wake gains those same changes, and on any store a reminder that a newer done memory says already happened is no longer told as due. Also: write-ups leave out permission prompts and refused tool calls, the first meeting asks easier questions, a manual ships with every install (`recall` the handle `manual`), a memory called noise twice stays quieter for 14 lived days rather than 7, and the plugin downloads its program once. No store-format change (store v15, cache v7), no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.45 needs no store restore: `counterparts disconnect`, 0.3.45's install, then `counterparts connect`.
6
+
7
+ - **A memory two sessions called noise now stays quieter for two weeks, not one.** Rated 0 in two sessions within 14 lived
8
+ days (it was 7), it faces the same raised bar until those ratings age out or a later 2 or 3 clears it. A turn that
9
+ reaches it strongly still shows it. Right after installing, the longer window starts counting at the next rating.
10
+ `recall.HABITUATION_WINDOW_DAYS` back to 7 undoes it.
11
+ - **The plugin downloads its program once on Ubuntu 26.04.** On a computer with no Bun or Node,
12
+ the hook and the memory server starting together could both download the program (about
13
+ 56 MB), because that Ubuntu's `mkdir` can tell two processes they each made the same
14
+ directory. The launcher now takes its lock with the shell itself. The same double download
15
+ could follow a download that died, on any system, and now doesn't. Nothing unchecked ever
16
+ ran: each download was checked and moved into place in one step. And on a Mac whose `sh`
17
+ is zsh, a first start now downloads the program at all: it used to say "getting ready"
18
+ and never start.
19
+ - **Hosted: Litestream's own log lines reach the server's log.** A backup that fails to sync (a refused upload, an
20
+ R2 permission error, a rejected encryption key) now says so in the log, and a redeploy's log shows Litestream's
21
+ final sync finishing. Before, those lines were dropped and only the process being up was visible.
22
+ - **Hosted: the restore drill is in the repository, and the KEK check is by fingerprint.** `hosted/drill/drill.sh`
23
+ restores production's deployed image from a drill bucket on R2 with a throwaway key, and writes its results outside
24
+ the repository. The offline copies of the key are now checked by a short fingerprint against Railway's, so the real
25
+ key no longer goes into a drill. The runbook says what to do when a restore refuses a mistyped key.
26
+ - **Recall's per-conversation bookkeeping no longer piles up.** The record of what each
27
+ conversation was already shown (so nothing repeats) is now cleared once a conversation
28
+ has gone unused for the retention window, 90 days of use by default, in the nightly run
29
+ beside the old-version cleanup. A conversation used inside the window keeps all of it.
30
+ - **A new store starts with eleven starter memories, "told, not lived".** `counterparts install` (and
31
+ `start-fresh`) and hosted signup plant a short set about how this memory works and how to use it well, in each
32
+ surface's own words, marked with the source `told` and the set's version in the store's meta. They start weak,
33
+ fade unless used, and can be corrected or removed like any memory. Recall fills its footnotes with every lived
34
+ memory first and never shows a starter one loud; the deliberate `recall` ranks one below a lived match of
35
+ comparable score. The night, the wake, the core, beliefs and cards never read them. An upgraded store never gets
36
+ them. No store-format change.
37
+ `status`, doctor and the dashboard count them apart ("0 memories · 11 starter notes"), and `uninstall` says how
38
+ many of the memories it counts are starter notes. `init` still makes a bare store; the harness `week` starts with
39
+ the set unless given `--no-told`.
40
+ - **Nightly write-ups leave out permission prompts and refused tool calls.** When you decline a
41
+ permission prompt, the host's "interrupted for tool use" line no longer reaches the write-up
42
+ of that conversation, and whoever writes a session up (the nightly catch-up, or the next
43
+ session pointed at it) is told that permission prompts, refused tool calls and the
44
+ memory system's own notices aren't things that happened between you, unless you talked
45
+ about them. A night had saved "declined permission to mark a note delivered" as a memory.
46
+ - **The first meeting asks four questions now, and easier ones.** After your week, it asks "What are you working
47
+ on right now?", then what you've been into lately that has nothing to do with work, then a good Saturday. "What do
48
+ you love most about what you do?" is gone, and so is "What got you started building things?". A meeting already
49
+ under way when you update finishes as it started: the answers it gives under the old questions are still kept.
50
+ - **Starter memories no longer push out a lived memory.** On a new store, a seed that shared a word with the question
51
+ set the deliberate `recall`'s "weak match" bar, and a lived memory found by meaning alone fell under it ("which
52
+ coffee maker do we own?" lost the note about the espresso machine). Facts mode now lists every lived match before
53
+ any starter one, and judges a lived match only against lived ones. The turn's footnotes read their floors from the
54
+ lived memories too, so eleven starter notes no longer double the bar a young store's memories must clear (a
55
+ starter memory still faces the stricter whole-store bar, so a loosely matched seed is not footnoted on a turn nothing lived answers). The
56
+ single-binary check now runs on every pull request that touches `src/`.
57
+ - **The counterpart has a manual.** `docs/manual.md` says how Counterparts works and how to
58
+ use it: the everyday phrases, folders, nights and dreams, seeing and changing what's kept,
59
+ export, backup and uninstall, checking health, and how hosted differs. It ships with every
60
+ install, so it matches the version you run and works offline. Your counterpart opens it
61
+ with `recall`'s handle `manual` (a list of sections), and `manual <section>` opens one.
62
+ - **The wake knows yesterday's news.** In the wake's shape (on for new installs, below), a session start opens, after
63
+ the page, with "Since the last night:": up to three of the strongest things about you, or about the two of you, saved since the last
64
+ night ran, from any folder that's on. Something said in another folder this morning (a launch, good news from the vet)
65
+ no longer waits a night to reach the next session. Nothing new, no section.
66
+ - **An old handoff stops leading the wake** (the wake's shape, as the next one). Half a day after a folder's last handoff, once another session has worked
67
+ there and left something, the handoff shows as one line with its age and how many sessions came since, after what they
68
+ did, instead of whole and first for days. A quick check-in that saved nothing, or a session still open beside yours,
69
+ leaves it whole.
70
+ - **No empty sections in the wake.** "Nothing open.", "Nothing dated." and "Open here now: no other session." are gone,
71
+ with their headings: a section with nothing in it isn't printed.
72
+ - **Something that already happened stops being "due today".** When a newer memory marked done says a dated thing
73
+ happened (the shop launched a day early), its reminder isn't told and it leaves Coming up. Only on or after its day,
74
+ and only by a memory from the day before it or later, so last week's vet visit never settles this week's.
75
+ - **A new install starts with the wake's shape on.** The top-down wake (where this folder stands, elsewhere, coming up,
76
+ still open, yesterday, last night, each said once) is now how a new store's sessions start. A store that already existed
77
+ keeps its setting (`counterparts wake-shape on|off|default`).
78
+ - **Help no longer says export is encrypted by default.** It never was: export refuses until you pass
79
+ `--passphrase` (encrypted) or `--plaintext` (said on purpose). `counterparts --help`, `counterparts export --help`,
80
+ the README and the quickstart now say so.
81
+ - **On claude.ai, the `scope` tool speaks of one memory, not folders.** Its description, its read and the refusal
82
+ while memory is off or paused say one account is one memory, to pause, turn off and turn back on; they no longer
83
+ show the server's file path or a `counterparts scope` command nobody on claude.ai can run. Claude Code's and
84
+ Claude Desktop's words are unchanged.
85
+ - **A new store's starter note on using memory well points to the manual** (`recall` the handle "manual"). Stores
86
+ that already exist keep their notes as they are.
87
+
88
+ ## 0.3.45 — 2026-11-01
89
+
90
+ Nearly nothing you'd notice changes. **One thing happens at once: the first pass after upgrading deletes the raw copies of notes saved with no session or with `counterparts note` that are already past their age (3 days once the memory has landed, 14 whatever). Memories aren't touched, and raw text deleted this way doesn't come back, even if you go back to 0.3.44.** Learned cue words skip path fragments and acknowledgements. A memory that couldn't be saved can be sent again. A laptop's sleep no longer stops the night's work, and a headless session leaves the night to the next one a person starts. No store-format change (store v15, cache v7), no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.44 needs no store restore: `counterparts disconnect`, 0.3.44's install, then `counterparts connect`.
91
+
92
+ - **Learned cue words skip path fragments and acknowledgements.** Words from file and socket paths (`tmp`, `uds`, ...),
93
+ hex ids, and replies like "sounds good, go ahead" no longer wire themselves to a memory, and what they learned before
94
+ is ignored. Nothing in your store is changed.
95
+ - **Notes saved with no session, or with `counterparts note`, now lose their raw copies on time.** Those copies shared
96
+ a label, so each new note restarted the clock for the old ones, and with a note every couple of days the oldest was
97
+ never deleted. Each now goes on its own age: 3 days once its memory has landed, never more than 14. The memories
98
+ themselves aren't touched. The first run after updating deletes every such copy already past those ages, at once;
99
+ doctor's Raw transcripts line says how many.
100
+ - **A laptop's sleep no longer stops the night's work.** A night's watchdogs count time awake now, so a machine that
101
+ slept mid-run picks up where it left off instead of killing the child on waking. What a run slept through is on its
102
+ row, and a run that's asleep isn't read as lost, so no second one starts beside it. A child that's really stuck is
103
+ still stopped on schedule.
104
+ - **A headless session no longer starts the night.** `claude -p` and the Agent SDK leave it for the next session a
105
+ person starts, which runs it as usual, so nothing is lost by waiting. `counterparts catch-up` is run by hand as before.
106
+ A store that only headless sessions use gets no nights, and doctor says so after two days.
107
+ - **A memory that couldn't be saved can be saved again.** When the store was locked or full
108
+ at the moment of writing, the note was recorded as handled anyway: nothing was stored, sending
109
+ it again was refused as a duplicate, and its raw copy started its 3-day clock, along with
110
+ everything else that session had said if it was a `session_end`. Now nothing is marked
111
+ until the memory is on disk, so sending it again saves it once, and an unsaved note's words
112
+ stay owed for a later write-up. `remember` says what happened and to send it again, and the
113
+ failure shows in doctor. A write-up part with a memory that didn't land stays open to be
114
+ sent again, unless it's the last part and another memory from it landed; then the reply
115
+ says to save the rest with `remember`.
116
+
3
117
  ## 0.3.44 — 2026-11-01
4
118
 
5
119
  Nothing you'd notice changes by default. `counterparts page-form own` is new: one store's nightly writers amend its self page in the page's own form, and it's off until you set it (`counterparts page-form default` puts it back). The core door's shadow has stopped recording; what becomes core is decided exactly as before and nothing in it moves. No store-format change (store v15, cache v7); the switch is one setting kept in the store, with no migration. Nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.43 needs no store restore: `counterparts disconnect`, 0.3.43's install, then `counterparts connect`; 0.3.43 ignores the switch.
package/CONSTITUTION.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The Counterparts Constitution
2
2
 
3
- _Ratified by the owner 2026-08-25; last amended 2026-10-20 (this file's git history is
3
+ _Ratified by the owner 2026-08-25; last amended 2026-11-02 (this file's git history is
4
4
  the amendment log). This is the ONE page with standing authority — everything else,
5
5
  including owner answers given during the build, is a working default, open to discussion
6
6
  at any time and revisable without ceremony. Changing THIS page is deliberate and rare._
@@ -30,9 +30,11 @@ at any time and revisable without ceremony. Changing THIS page is deliberate and
30
30
 
31
31
  **Properties — what must stay true**
32
32
 
33
- 6. **The owner owns the data.** Local-first, portable formats, memories kept as prose
34
- the owner can view. Data leaves the machine only by the owner's explicit choice,
35
- never silently.
33
+ 6. **The owner owns the data.** Local is always available, and the owner can always take
34
+ their memory home. Memories are written as prose and kept in open, portable formats (a
35
+ database file or readable files), and the owner can read their own memories wherever
36
+ they live. Data leaves the machine only by the owner's explicit choice, never
37
+ silently. _(Amended 2026-11-02.)_
36
38
  7. **Memory changes like human memory.** Revision, fading, and forgetting are the
37
39
  system working. Revisions keep their history; nothing bulk-wipes silently; backups
38
40
  catch catastrophe. No ceremony beyond that.
package/README.md CHANGED
@@ -51,8 +51,9 @@ to be deleted. The full walkthrough is in [`docs/QUICKSTART.md`](docs/QUICKSTART
51
51
  thing reminds you of another.
52
52
  - **It's yours.** Everything lives on your machine in one SQLite file you can read,
53
53
  export or delete. No API keys, no accounts, nothing sent anywhere. The text of your
54
- conversations is kept only until it's written up: deleted 3 days after that, never
55
- kept more than 14 days, and never in a backup. You can delete the conversation text,
54
+ conversations is kept only until it's written up: deleted 3 days after that, or at most
55
+ about two weeks after the conversation goes quiet, whichever comes first, once Counterparts
56
+ next runs, and never in a backup. You can delete the conversation text,
56
57
  the backups or the activity log on their own at any time (`counterparts delete`).
57
58
 
58
59
  ## Who it's for
@@ -79,7 +80,7 @@ Once installed it runs on its own. A few commands are worth knowing:
79
80
  counterparts dashboard # look at the memory in your browser
80
81
  counterparts ask "..." # ask the memory a question
81
82
  counterparts scope . --off # don't remember this directory
82
- counterparts export # a copy of everything, encrypted by default
83
+ counterparts export # a copy of everything; --passphrase encrypts it
83
84
  counterparts --help # the rest
84
85
  ```
85
86
 
@@ -92,7 +92,7 @@ counterparts ask "..." # ask the memory a question
92
92
  counterparts status # how much it holds
93
93
  counterparts self-page # who it thinks it is, and who you are
94
94
  counterparts remove # delete one memory for good
95
- counterparts export # a copy of everything, encrypted by default
95
+ counterparts export # a copy of everything; --passphrase encrypts it
96
96
  counterparts --help # everything else
97
97
  ```
98
98
 
package/docs/manual.md ADDED
@@ -0,0 +1,123 @@
1
+ # The Counterparts manual
2
+
3
+ How this memory works and how to use it: the phrases, the switches, the commands, and what to do when something seems off. It is written for the counterpart first (that's you, if you opened it through `recall`), and a person can read it too.
4
+
5
+ Some things differ by where the memory lives. **[local]** means a memory on the person's own computer, used from Claude Code or Claude Desktop. **[hosted]** means Counterparts Online, used from claude.ai, or from Claude Code when there's no local install. Where neither mark appears, it holds for both. "Since 0.3.x" says when something arrived, where that matters. This file ships with the code, so it describes the version that's installed.
6
+
7
+ ## What Counterparts is
8
+
9
+ Counterparts is a memory for an AI: the counterpart keeps what something meant and how it went, in its own words, not a transcript.
10
+
11
+ - It writes its own memories: in the moment with the `remember` tool, and at the end of a stretch of work with `session_end` and `chapter`.
12
+ - What isn't used fades, on purpose, so what matters stays easy to find. A faded memory can still turn up when it's searched for, until it is let go.
13
+ - Each session opens with a wake: who I am (the self page), where the work stands, what's coming up and still open, how yesterday went.
14
+ - In Claude Code, related memories come up as footnotes as the conversation goes. `recall` is the deliberate look, everywhere.
15
+ - It's theirs to see, export and delete. [local] It is one SQLite file on their computer, and Counterparts sends nothing about them anywhere (the details are on counterparts.ai/privacy). [hosted] It lives on Counterparts' server, one store per account; backups that leave the server are encrypted with a key for their account.
16
+ - A new memory may start with a few starter notes, titled "Told: …". They were given, not lived: they start weak, come after lived memories that match as well, are never part of the self, and can be corrected or let go like any memory.
17
+
18
+ ## Everyday phrases
19
+
20
+ These are things a person can say. Offer one when it fits; don't list them all.
21
+
22
+ - "Where did we leave off?" brings back the last session here. A short facts question like that reads that session first.
23
+ - "Remember this" saves it now, with the `remember` tool.
24
+ - "How did X go?" or "what do you remember about Y?" asks the memory, not just this chat: `recall` with `mode: "facts"` for what happened, `mode: "meaning"` for how it went and what it adds up to.
25
+ - "Remind me Thursday to …" is saved with the date in `eventDate` and `remind: "plain"`, so it is said plainly on that day, or, if that day is missed, the next time you talk within the week after. Without `remind: "plain"`, a dated memory is quiet: in Claude Code it may come up as a footnote around the date.
26
+ - "That's wrong" corrects a memory: write the right version with `updates` naming the old one and `how: "corrected"`. The wrong one leaves recall and stays readable by its id.
27
+ - "What's still open?" lists the threads the wake carries: the handle `still open`.
28
+ - "What's coming up?" lists what's due: the handle `coming up`.
29
+ - "Not here", "just read" or "pause this" sets the scope (see Folders).
30
+ - "No dreams", or "dream", sets or starts the night (see Nights and dreams).
31
+ - "Let's meet" starts the first meeting, if it hasn't happened: the `meet` tool.
32
+
33
+ ## Folders
34
+
35
+ [local] Memory is set per folder: on, observer (reads only), off, or paused, and the person can ask which this folder is.
36
+
37
+ - The `scope` tool reads the setting for this folder with no `mode`, and sets it with `mode` `on`, `observer`, `off`, `pause` or `resume`. Set it when the person says so, not on a guess.
38
+ - Off: the hooks write nothing and read nothing here, and every tool but `scope` refuses. Paused is off until they say to resume; it has no timer. `resume` goes back to what it was before, or on.
39
+ - A setting covers the folder and everything under it; the nearest setting wins. Nothing set means on.
40
+ - From a terminal: `counterparts scope .` shows this folder's setting, and `counterparts scope . --off` (or `--pause`, `--resume`, `--on`) sets it. `counterparts scope --list` prints every setting.
41
+ - The `scope` tool's `updates` turns the update reminder off when they say stop reminding them about updates.
42
+
43
+ [hosted] One account is one memory, with no folders. The `scope` tool pauses it or turns it off, for every claude.ai chat, and back on. Paused lasts until they say to resume (`mode: "resume"`).
44
+
45
+ ## Remembering well
46
+
47
+ These make the memory work better.
48
+
49
+ - Save while it's fresh: when something matters, `remember` it then, one idea per call, in your own words. Keep the exact words when the words matter.
50
+ - A date to come back to goes in `eventDate`, not just the text, or it never comes back. Four shapes: a day "2026-10-15", a month "2026-10", a range "2026-10-20..2026-10-31", or a year. Add `recurring` for a date that repeats.
51
+ - Something open: `unresolved: true`, with `settlesWhen` naming what would settle it. It stays on the still-open list, and the night can close it once a memory shows it happened.
52
+ - When a memory turns out wrong: `updates` with its id and `how: "corrected"`. When it was true then and has changed: `how: "changed"` (the default), and the old one is shown as earlier. A real disagreement: `how: "open"`, and both stay.
53
+ - Before saying "I don't remember", ask `recall` once, and try other words before saying it's gone.
54
+ - [local] At the end of a session in Claude Code, the Stop ask asks for the write-up: memories through `session_end`, and the session's own account through `chapter`. Write it honestly, including what didn't go well.
55
+ - [hosted] Nothing tells this memory when a chat ends, so `remember` as things come up, and write a `chapter` when the chat is wrapping up.
56
+
57
+ ## Nights and dreams
58
+
59
+ After a day of use, a night pass sorts that day: day's end, then a dream, then a reflection.
60
+
61
+ - Day's end writes the day's summary and brings the self page's day-to-day sections up to date. The dream replays what was lived beside what it resembles: it can merge near-copies, link what belongs together, note a pattern, flag a contradiction. The reflection is awake: it can rewrite the page's Core from the memories it cites and leave a short morning share.
62
+ - A dream is kept in its own journal, marked as a dream, never as something that happened. Tell it as a dream.
63
+ - The setting is `auto`, `ask` or `off`: the `dream` tool's `setting` phase, when they say "no dreams" (off) or choose one.
64
+ - [local] On `auto` (a new install's default), the next day's first Claude Code session starts the night in the background, as a separate claude -p run, and says so in one line. On `ask`, that session asks first. `counterparts dream --setting off` (or `ask`, `auto`) sets it from a terminal.
65
+ - [local] `counterparts night` lists recent nights, and `counterparts night last` shows last night's dream and reflection (since 0.3.28). `counterparts dream --undo <id>` reverses one dream as a whole.
66
+ - [local] `counterparts catch-up` writes up, now, sessions that ended without a write-up. The night does it too.
67
+ - [hosted] Nothing runs the night by itself. It runs when the person's nightly routine (a scheduled run they set up in Claude) calls the `dream` tool, or when they say "dream" in a chat.
68
+ - Either surface: the handle `last dream` (or `last night`) reads the newest dream whole, and the reflection after it.
69
+
70
+ ## Seeing and changing what's kept
71
+
72
+ The person can see all of it, correct any of it, and remove it.
73
+
74
+ - Ask the memory: `recall` with a question and a mode, or a memory's id or exact title as `handle` to read it whole. [local] From a terminal: `counterparts ask "…"`.
75
+ - The self page, the "Who I am" the wake opens with: the `self_page` tool reads it, and writes it whole when something about you will still be true next month. [local] `counterparts self-page` shows it, and `counterparts self-page --versions` lists earlier versions.
76
+ - [local] `counterparts dashboard` opens the dashboard in a browser: the memories, the self page and the memory's health.
77
+ - Correct a memory with `remember`, `updates` and `how: "corrected"` (see Remembering well).
78
+ - [local] `counterparts remove <id>` shows what would go; with `--confirm` it asks them to type the id back, then deletes that memory for good. It needs a terminal, and it is the person's to run.
79
+ - [local] `counterparts delete conversation-text`, `counterparts delete backups` or `counterparts delete activity-log` deletes one kind of data and nothing else (since 0.3.21).
80
+ - [local] `counterparts settle` lists memories that disagree and how each pair was settled; `counterparts core` lists what became part of who I am, and `counterparts core --demote <id>` sends one back.
81
+ - [hosted] One memory can't be removed; a correction takes it out of what comes up.
82
+
83
+ ## Export, backup, uninstall
84
+
85
+ The memory is the person's to keep or take with them.
86
+
87
+ - [local] `counterparts export --out <dir> --passphrase <secret>` makes an encrypted copy they can take anywhere. Export refuses without `--passphrase`, or `--plaintext` said on purpose. `--markdown` writes a readable tree instead.
88
+ - [local] `counterparts backup --out <dir>` saves a snapshot to a folder. A daily snapshot is also kept automatically.
89
+ - [local] `counterparts uninstall` disconnects Claude Code and keeps the memory unless they say otherwise; `--keep-memories` keeps it without asking.
90
+ - [local] `counterparts start-fresh` sets this memory aside and starts a blank one; `counterparts start-fresh --undo` brings it back. Nothing is deleted.
91
+ - [local] `counterparts rollback` puts the memory back as it was before an upgrade (since 0.3.17).
92
+ - [hosted] The account page's "Download my memory" gives the whole memory as one SQLite file, readable by any SQLite tool. "Delete my account" locks it at once and erases the memory, its backups and its key after 24 hours, unless they sign in and keep it; "Delete everything now" erases at once.
93
+
94
+ ## Checking that it works
95
+
96
+ If something seems off (no wake, no footnotes, a night that didn't run), check before guessing.
97
+
98
+ - The `status` tool gives the census: how much is held, of what kinds, how much has left. Ask it when the person asks "what's your status?".
99
+ - [local] `counterparts doctor` checks everything and says what to fix. Show its lines as they are. `counterparts status` counts memories and recent activity; `counterparts log` shows today's events in order; `counterparts mechanisms` shows which parts of memory have been working.
100
+ - [local] After an update, start a new Claude Code session so the new version's tools load. To update: `npm install -g counterparts@latest` (or `bun add -g counterparts@latest`), or for the plugin, /plugin → Marketplaces → counterparts → Update marketplace.
101
+ - [local] A plugin install has no counterparts command in the terminal: the person uses /counterparts:doctor, /counterparts:dashboard and /counterparts:uninstall instead.
102
+ - [local] `counterparts install --host claude-desktop` connects Claude Desktop's chat to the same memory. Desktop's chat has no hooks: the `wake` tool starts each chat, there are no footnotes, and the write-up is asked on a tool result once a chat has gone on a while.
103
+ - [hosted] The account page lists the connected AIs, with when each was last used, and disconnects one.
104
+ - A tool that refuses says why and what to do. Pass that on in plain words, don't retry blindly.
105
+
106
+ ## Hosted
107
+
108
+ [hosted] Counterparts Online is the same memory, run on Counterparts' server, used from claude.ai.
109
+
110
+ - It's connected in claude.ai as a custom connector, from the setup page the person was given. In a new chat, the `wake` tool starts the conversation.
111
+ - Sign-in is by an emailed link. The account page has the connected AIs, the time zone (the memory's day turns over at their midnight), "Download my memory", and delete.
112
+ - There are no hooks: the `wake` tool starts each chat, and nothing asks for a write-up at the end. There are no terminal commands and no dashboard.
113
+ - One account is one memory, with no folders: the `scope` tool pauses it or turns it off.
114
+ - Nights run from the person's own routine or when they say "dream".
115
+ - One memory can't be removed.
116
+ - Limits in the beta: about 120 calls a minute and 1,500 an hour; a store of up to 1 GiB. Over a limit, the tool says so; nothing is lost.
117
+ - A hosted memory and a local one are separate. [local] `counterparts connect` keeps the hosted connector out of Claude Code, so one session never sees two memories.
118
+
119
+ ## What's new
120
+
121
+ What changed in each version is in CHANGELOG.md, which ships with the package and is on GitHub.
122
+
123
+ - [hosted] Updates arrive when Counterparts Online is deployed; there is nothing to install.
@@ -31,6 +31,7 @@ code and the `NOTES.md` / `INTERFACE-GAPS.md` next to it.*
31
31
  | *(`feelings-wheel.ts`)* | — (a vocabulary) | The feelings wheel as a typed list: seven cores (happy, warm, calm, curious, sad, uneasy, angry), the groups and their words, default valence and intensity on every entry, blends, aliases, and the rule that re-filed the first wheel's feelings (v11). Read by `store/` to validate the `feelings` table. **Added 2026-09-25; v2 2026-09-30.** |
32
32
  | *(`leaving.ts`)* | — (a table) | What counts as having left: every `archived_reason` the code writes, filed `replaced` (a live row carries it — a revision, a merge, a rebuilt journal copy), `let-go` or `removed`. The `status` census and the dashboard's archive words both read it, so they agree. **Added 2026-09-30.** |
33
33
  | *(`onboarding.ts`)* | — (getting to know someone) | The first meeting, for every install path: its state in `meta` (`not_started` only on a store `install` made; absent reads `done`), the script the `meet` tool returns, the fixed style bundles (preferences about the owner, each keeping honest pushback), the wake's offer line and marker, and the second session's one memory. A new install's dreaming `auto` is written here too. **Added 2026-10-11.** |
34
+ | *(`told.ts`)* | — (what a newborn is told) | The starter memories (S1): eleven ordinary memories a NEW store begins with (`install`, `start-fresh`, hosted signup; never an upgrade), source `told`, in each surface's words, the set's version in `meta`. Weak at birth, lived-first in recall (`recall/gate.ts`, `mcp/facts.ts`), and kept out of the night, the wake, the core, beliefs and cards. **Added 2026-11-03.** |
34
35
  | *(observer)* | — (instrument stance) | **RESOLVED (owner, 2026-08-25): a MODE, not a module** — one predicate threaded through the core API, checked at the store seam. Spec moved to `docs/observer-mode.md`. |
35
36
 
36
37
  **Third open question (check-in): the `remember`/`encode` boundary.** With the
@@ -42,7 +43,7 @@ input — does `encode` shrink to gates-and-tagging inside `remember`'s pipeline
42
43
  | adapter | job |
43
44
  |---|---|
44
45
  | `claude-code/` | Hooks: Claude Code's five events driving the host lifecycle (`lifecycle.ts`, below) — its payload translation, JSON envelope and the room it measures, transcript reader and wake-arrival check, the Stop ask's words, the first-launch question, the update and doctor notices, the dream line, and the headless nightly run (`night-run.ts`, `claude -p`, **2026-09-29**), which reads its child's transcript for the host's cut (**2026-10-09**). The launch adapter. |
45
- | `mcp/` | Deliberate tools, ten: remember, recall, status — plus the Stop ask's two return channels, `session_end` (memories, and the next-session write-up's door) and `chapter` (the episode's own journal, **added 2026-09-04**, because the ask named a door no adapter had built) — `scope` (this directory's setting, **2026-09-15**), `self_page` (the page the wake opens with, **2026-09-18**), `dream`, the dreamer's phases (**added 2026-09-26**), and `reflect`, the waking self's (**added 2026-09-27**), and `meet`, the first meeting (**2026-10-11**, `core/onboarding.ts`). A result's words about the host come from `hosts.ts`. For a Claude Desktop client (by its name at `initialize`, **2026-09-30**) an eleventh, `wake` — Desktop's session start, since it has no hooks — plus per-call binding to the most recent live Desktop session, the write-up ask on a tool result, and a "Start with Counterparts" prompt; a Claude Code client sees none of it. `recall` (**2026-10-03**) answers a question in the mode it names — facts (`facts.ts`, with `recall/time-ask.ts`) or meaning (`meaning.ts`) — and an address (`ids`, `handle`, `epi_…#N`) in `deliberate.ts`. |
46
+ | `mcp/` | Deliberate tools, ten: remember, recall, status — plus the Stop ask's two return channels, `session_end` (memories, and the next-session write-up's door) and `chapter` (the episode's own journal, **added 2026-09-04**, because the ask named a door no adapter had built) — `scope` (this directory's setting, **2026-09-15**), `self_page` (the page the wake opens with, **2026-09-18**), `dream`, the dreamer's phases (**added 2026-09-26**), and `reflect`, the waking self's (**added 2026-09-27**), and `meet`, the first meeting (**2026-10-11**, `core/onboarding.ts`). A result's words about the host come from `hosts.ts`. For a Claude Desktop client (by its name at `initialize`, **2026-09-30**) an eleventh, `wake` — Desktop's session start, since it has no hooks — plus per-call binding to the most recent live Desktop session, the write-up ask on a tool result, and a "Start with Counterparts" prompt; a Claude Code client sees none of it. `recall` (**2026-10-03**) answers a question in the mode it names — facts (`facts.ts`, with `recall/time-ask.ts`) or meaning (`meaning.ts`) — and an address (`ids`, `handle`, `epi_…#N`) in `deliberate.ts`. The handle `manual` (**2026-11-03**, H1, `manual.ts`) opens `docs/manual.md`, the installed version's manual: its section index, or one section. |
46
47
  | `cli/` | `counterparts` command — the full list is `COMMANDS` in `cli/commands.ts`: status, install, connect / disconnect (the host's two files), `install --host claude-desktop` (Desktop's config entry, **2026-09-30**), uninstall, start-fresh, init, owner operations (note, ask, export, backup, remove, verify, repairs, rebrief), the readings (doctor, mechanisms, log, coverage, version, help), scope, self-page, dream, core, settle, and dashboard. |
47
48
  | `dashboard/` | The owner's window (constitution line 16): brain-view, revision stories, band/protected lists. Observer-mode by construction; minimal version ships DURING the parallel run. **Added 2026-08-25 (owner elevation).** |
48
49
  | `remote/` | The memory server as a web connector (**2026-10-26**, the claude.ai trial): `http.ts` serves the same `McpServer` as MCP over HTTP (plain JSON, no SSE), bound to 127.0.0.1 and answering only under a per-run 192-bit secret path, one message at a time; `call-log.ts` keeps one id-only line per call; `bin/serve-http.ts` refuses a store or configuration nobody named and the owner's live stores. Its host is claude.ai's (`claude-ai:`), set at launch. No sign-in yet (its CONTRACT). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.3.44",
3
+ "version": "0.3.46",
4
4
  "license": "MIT",
5
5
  "description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
6
6
  "repository": {
@@ -55,6 +55,7 @@
55
55
  "files": [
56
56
  "src/",
57
57
  "docs/QUICKSTART.md",
58
+ "docs/manual.md",
58
59
  "docs/ELI5.md",
59
60
  "docs/module-map.md",
60
61
  "tools/install-loop/",
@@ -765,9 +765,15 @@ working default).** `hooks.ts#isInteractive`: the host's own `CLAUDE_CODE_SESSIO
765
765
  `sessions.ts#NON_INTERACTIVE_ENTRYPOINTS` (`sdk-cli` is `claude -p`; the SDKs; `mcp`; the
766
766
  GitHub action) claims none of them — the dream line, a night run's hand-back, a carried
767
767
  share, a raised contradiction, plain reminders (at SessionStart and at a prompt), the update
768
- notice. An unknown or absent value is a person's. It may still START the day's headless run
769
- (`startUnwatched`); the line it would have been told is held (`Dreams#holdTold`) and the next
770
- interactive prompt says it while the run is still going, claimed at delivery (`claimHeld`,
768
+ notice. An unknown or absent value is a person's. Since 2026-11-01 (NT1) a name on that list,
769
+ unless the host says `ATTENDED=1`, leaves the day's headless run too (`passesOnNight`,
770
+ `passOnNight`): it reads the offer, claims nothing, and the next session a person starts takes the
771
+ night, with one `adapter.dream.unwatched` log line (`passed: "headless"`) when a night was due.
772
+ That is narrower than `isInteractive` on purpose, so a wrong reading costs a held line rather than
773
+ the night: `ATTENDED=0` off the list (a person's `claude --bg`, a teammate, a host name the host's
774
+ own list lacks) and a turn no person started in a person's session (`startedByHost`) may still
775
+ START it (`startUnwatched`); the line it would have been told is held (`Dreams#holdTold`) and the
776
+ next prompt a person starts says it while the run is still going, claimed at delivery (`claimHeld`,
771
777
  an event latch per run) — once the run has ended its hand-back tells what it did instead. An
772
778
  `ask` is left unclaimed for the next interactive session. Every day's line now tells the
773
779
  model to say it ONCE, in its first reply, as one plain sentence (`dream/#sayOnce`); the
@@ -947,7 +953,12 @@ they still owe, over the ceiling, busy elsewhere, batches, what stopped it, stat
947
953
  process-log line record it, and doctor's Nightly run and Catch-up lines read it through one
948
954
  renderer (`catchUpWords`). Nothing owed: no child, no row. The hook's `started` row carries
949
955
  the catch-up's whole watchdog from the start (`nightRowTimeoutMs`), so a long catch-up is
950
- not read as lost. A clean exit that stopped short of
956
+ not read as lost. **Every one of these watchdogs counts time awake (2026-11-01, NT1;
957
+ `awake.ts`):** a child's (`child.ts`), the run's hour (`NIGHT_WRITE_UP_TOTAL_MS`), and the row's,
958
+ where the waiting process adds each sleep it notices to `NightRun.sleptMs` so a run asleep isn't
959
+ read as lost and a dead one stops adding. A sleep also renews the batch's claims and its runner's
960
+ record (`renewCatchUp`, `WRITE_UP_CLAIM_MS`), so the waking child still holds what it was writing.
961
+ A child truly stuck awake is killed on schedule, a tick late at worst. A clean exit that stopped short of
951
962
  its allowance — some granted session neither written up nor brought to its `upTo` part —
952
963
  is recorded `partial`, not `done` (a usage limit exits 0 too; its output is not read), and
953
964
  starts no further batch. A runner record a killed process left open is ended at the
@@ -1126,7 +1126,8 @@ no content was copied. `parseTranscript` reads only entries with a `message.role
1126
1126
  | the compaction summary | `isCompactSummary: true`, `isVisibleInTranscriptOnly` | `This session is being continued…` | `injected` (was `conversation`) |
1127
1127
  | slash-command echo, `!`-command | no metadata | `<command-name>`, `<local-command-stdout>`, `<bash-input>`, `<bash-stdout>` | unchanged text rule; `<bash-stdout>`/`<bash-stderr>` now `injected` |
1128
1128
  | an interrupt | `interruptedMessageId`, no origin | `[Request interrupted by user]` | `injected` |
1129
- | hook output (`UserPromptSubmit hook success`, `hook_additional_context`, `hook_system_message`) | `type: "attachment"`, **no role** | — | never a turn (unchanged) |
1129
+ | a declined permission prompt (measured 2026-11-03: after the rejected `tool_result`, its own entry) | no metadata | exactly `[Request interrupted by user for tool use]` | `plumbing` since 2026-11-03 (WP1; was `injected`, and reached the night's write-up) |
1130
+ | hook output (`UserPromptSubmit hook success`, `hook_additional_context`, `hook_system_message`) | `type: "attachment"`, **no role** | — | never a turn (unchanged); should a build write it as user text, bare or in a system reminder, `plumbing` since 2026-11-03 (was `injected`) |
1130
1131
  | **a prompt typed while the model works** (review M3: 76 seen) | `type: "attachment"`, `attachment.type: "queued_command"`, `commandMode: "prompt"`, `origin.kind: "human"` | — | `conversation` since 2026-09-24 — see "Prompts typed mid-turn" below (was never a turn) |
1131
1132
  | an API error written as the assistant | `isApiErrorMessage: true`, `model: "<synthetic>"` | `API Error: …` | `injected` (was `conversation`) |
1132
1133
 
@@ -2942,3 +2943,56 @@ still merge an off folder's memories into a new row filed where the night ran. O
2942
2943
  `verifyRebuild` left `skippedArchived` out of what it counted; the plain arm has counted it since I13. On
2943
2944
  a copy of the live store the difference was exactly the archived rows (621; superseded rows are all archived
2944
2945
  too). A miscount in the check, and no row was unaccounted for.
2946
+
2947
+ ## 2026-11-01 — the night's two holes (NT1)
2948
+
2949
+ **What the clocks do, and how we know.** Nothing in JavaScript exposes a clock that stops for sleep everywhere, and
2950
+ the two platforms go opposite ways. So `awake.ts` depends on neither: it looks for a late tick on the wall clock.
2951
+
2952
+ - macOS, RUN on this laptop, 2026-11-01: `CLOCK_MONOTONIC` was 197,008 s and `CLOCK_UPTIME_RAW` 151,537 s, so the
2953
+ first runs through sleep and the second doesn't. Node 20.19, 22.23 and 24.22's `process.hrtime` read about 197,014 to
2954
+ 197,057 s, on the sleep-counting side (they follow `CLOCK_MONOTONIC_RAW`). READ: libuv's `darwin.c` takes `uv__hrtime`
2955
+ from `mach_continuous_time`, and the event loop's time, which `setTimeout` runs on, comes from `uv__hrtime`.
2956
+ - bun on macOS: its `process.hrtime` starts at 0 for each process, so running it says nothing about sleep. The evidence is
2957
+ the live log of 11-01 (the MCP server runs under bun here): started 16:02:33Z, `adapter.night.writeup` `state: timed-out`
2958
+ at 16:17:02Z, `ms: 868484`, on a 600,000 ms timer. So its timer counted the sleep and fired on wake. Bun's source wasn't read.
2959
+ - Linux, READ ONLY (no Linux machine, no Docker): libuv's `linux.c` uses `CLOCK_MONOTONIC` (or `_COARSE`), which
2960
+ `clock_gettime(2)` says doesn't count suspended time, and `CLOCK_BOOTTIME` only for `uv_uptime`. So under Node on Linux a
2961
+ plain `setTimeout` already waits out a suspend. Bun on Linux was neither run across a suspend nor read. The fix doesn't
2962
+ care: a tick a suspend delays shows the same gap on the wall clock whichever way the timer behaves.
2963
+ - RUN, SIGSTOP, bun 1.3.10 and Node 22.23, macOS: an 800 ms plain timer in a process stopped from 150 to 2,150 ms fires at
2964
+ 2,154 ms under both. The clocks ran on through the stop, as they do through a Mac's sleep. CI runs the awake-time version
2965
+ of that under bun and Node on Linux and macOS (`night-holes.test.ts`, `node-smoke.ts`). A stop isn't a sleep: the child
2966
+ keeps running through it, and on Linux the clocks wouldn't run on through a suspend. It proves the gap is told from the
2967
+ watchdog in a real process. Real sleep gets read live (`docs/CHECK-AFTER.md`).
2968
+
2969
+ **The tick looks at the wall clock, not the runtime's monotonic clock,** because a monotonic clock that stops for a suspend
2970
+ would show no gap at all. A stepped wall clock costs one misread: forward reads as sleep (the watchdog is that much longer),
2971
+ back reads as no time (a tick shorter).
2972
+
2973
+ **Separate meters.** The child's watchdog, the catch-up's hour and the run's row each keep their own, each a timer a second
2974
+ in a process that's otherwise waiting. Sharing one would thread it through the seat, and a seat that isn't Claude Code's
2975
+ would lose the row and the hour.
2976
+
2977
+ **A small window on wake.** The renewals and the row wait for the first tick after waking: right away on a Mac, up to a
2978
+ second on Linux. A person's prompt or the child's own tool call inside that second can still read a claim or a row as
2979
+ expired, as it would have before.
2980
+
2981
+ **A run asleep past midnight (review of #712).** `Dreams#status` held a second run off only for a row of the same date. That
2982
+ looked older than NT1, but on a Mac the plain timer used to kill such a run on wake, ahead of the morning's first prompt. Now it
2983
+ wakes and goes on, and after hours of quiet its dream reads as abandoned, so the prompt would start a second run that resumes
2984
+ the same dream. The gate now holds for any date up to today (`night.date <= at`), until the run ends or is lost. Nothing ends up
2985
+ waiting long: only a living process adds to `sleptMs`, and its watchdogs count time awake.
2986
+
2987
+ **What the host's `ATTENDED` means (review of #712, READ from the 2.1.316 binary, not run).** `XU()`: false for a session of kind
2988
+ `bg`, `daemon` or `daemon-worker` and for a teammate, even with a terminal; true with a terminal; otherwise true only for a
2989
+ non-child process whose entrypoint is on the host's own list (`claude-vscode`, `claude-desktop`, `claude-desktop-3p`,
2990
+ `local-agent`, `remote`, `remote_desktop`, `remote_mobile`, `remote_projects`, `remote_cowork`, `ssh-remote`, Slack, Teams,
2991
+ `claude-coworker`, and so on). Hooks always get it, so the entrypoint fallback in `isInteractive` doesn't run on a current host.
2992
+ A person's `claude --bg` is `cli` with `ATTENDED=0`, and a new host with no terminal is `ATTENDED=0` under a name nobody knows.
2993
+ So the night reads the list (`passesOnNight`), and only the told lines read `ATTENDED`. Not measured in a real `--bg` session.
2994
+
2995
+ **A headless-only store.** A night waits for a session a person starts, so a store only `claude -p` or the Agent SDK uses gets
2996
+ none under `auto`, as it already got none under `ask`. An app a person really talks to through the Agent SDK reads as
2997
+ headless too, unless the host says `ATTENDED=1`. Doctor's `night-headless` line says so after two days without a night; nothing
2998
+ more was built.
@@ -0,0 +1,122 @@
1
+ /**
2
+ * TIME AWAKE, TOLD FROM TIME ASLEEP (2026-11-01, NT1).
3
+ *
4
+ * On 2026-11-01 a night started in a lid-closed dark wake. Its catch-up child got about 15 s
5
+ * awake, the laptop slept 853 s, and its 10-minute `setTimeout` fired on wake. A watchdog is
6
+ * there to stop a child that is stuck, not one whose machine was asleep.
7
+ *
8
+ * No clock JavaScript can read stops for sleep everywhere, and timers disagree (run and read
9
+ * in the PR): on macOS `process.hrtime` runs through sleep (libuv uses `mach_continuous_time`,
10
+ * and bun's timer fired on wake on 11-01); on Linux libuv uses `CLOCK_MONOTONIC`, which stops
11
+ * for a suspend. So this leans on none of them. It looks at the wall clock every tick while it
12
+ * waits: a tick that comes `NIGHT_ASLEEP_GAP_MS` late means the process was not running, and
13
+ * that gap is not charged. Whether the runtime's timer fired right on wake (macOS) or a tick
14
+ * after it (Linux), the wall clock shows the same gap.
15
+ *
16
+ * Loose on purpose. A sleep shorter than the gap is charged, so nothing below it is ever
17
+ * mistaken for sleep and a stuck child still dies on schedule, a tick late at worst. A wall
18
+ * clock stepped forward reads as sleep and one stepped back as no time at all, each once.
19
+ * A process stopped by SIGSTOP reads as asleep too: it was not running either.
20
+ */
21
+ import { TUNABLES } from "../config.js";
22
+
23
+ export interface AwakeOptions {
24
+ /** The wall clock. */
25
+ readonly now?: () => number;
26
+ readonly tickMs?: number;
27
+ readonly gapMs?: number;
28
+ /** Starts one wait and returns how to cancel it; absent, an unref'd `setTimeout`. */
29
+ readonly schedule?: (fn: () => void, ms: number) => () => void;
30
+ /** Told each sleep as it is noticed, with how long it lasted. Its throw is swallowed. */
31
+ readonly onSlept?: (ms: number) => void;
32
+ }
33
+
34
+ /** What a wait has seen so far. Reading it looks at the clock, so a wait that ends on wake sees the sleep before the next tick. */
35
+ export interface AwakeMeter {
36
+ asleepMs(): number;
37
+ stop(): void;
38
+ }
39
+
40
+ function realSchedule(fn: () => void, ms: number): () => void {
41
+ const t = setTimeout(fn, ms);
42
+ t.unref?.();
43
+ return () => {
44
+ clearTimeout(t);
45
+ };
46
+ }
47
+
48
+ /** The accounts, with no timer of their own. */
49
+ function accounts(opts: AwakeOptions): { readonly tick: number; look(): void; awake(): number; asleep(): number } {
50
+ const now = opts.now ?? ((): number => Date.now());
51
+ const tick = opts.tickMs ?? TUNABLES.NIGHT_AWAKE_TICK_MS;
52
+ const gap = opts.gapMs ?? TUNABLES.NIGHT_ASLEEP_GAP_MS;
53
+ let last = now();
54
+ let awake = 0;
55
+ let asleep = 0;
56
+ return {
57
+ tick,
58
+ look(): void {
59
+ const t = now();
60
+ const elapsed = t - last;
61
+ last = t;
62
+ if (elapsed > gap) {
63
+ const slept = elapsed - tick;
64
+ awake += tick;
65
+ asleep += slept;
66
+ try {
67
+ opts.onSlept?.(slept);
68
+ } catch {
69
+ /* a sleep nobody could write down is still a sleep */
70
+ }
71
+ } else if (elapsed > 0) {
72
+ awake += elapsed;
73
+ }
74
+ },
75
+ awake: () => awake,
76
+ asleep: () => asleep,
77
+ };
78
+ }
79
+
80
+ /** A running count of what a long wait slept through. */
81
+ export function awakeMeter(opts: AwakeOptions = {}): AwakeMeter {
82
+ const a = accounts(opts);
83
+ const schedule = opts.schedule ?? realSchedule;
84
+ let cancel: (() => void) | null = null;
85
+ const step = (): void => {
86
+ a.look();
87
+ if (cancel !== null) cancel = schedule(step, a.tick);
88
+ };
89
+ cancel = schedule(step, a.tick);
90
+ return {
91
+ asleepMs(): number {
92
+ a.look();
93
+ return a.asleep();
94
+ },
95
+ stop(): void {
96
+ cancel?.();
97
+ cancel = null;
98
+ },
99
+ };
100
+ }
101
+
102
+ /** Run `fn` once after `ms` of time awake. Returns how to cancel it. */
103
+ export function armAwake(fn: () => void, ms: number, opts: AwakeOptions = {}): () => void {
104
+ const a = accounts(opts);
105
+ const schedule = opts.schedule ?? realSchedule;
106
+ let cancel: (() => void) | null = null;
107
+ const step = (): void => {
108
+ a.look();
109
+ const left = ms - a.awake();
110
+ if (left <= 0) {
111
+ cancel = null;
112
+ fn();
113
+ return;
114
+ }
115
+ cancel = schedule(step, Math.min(a.tick, left));
116
+ };
117
+ cancel = schedule(step, Math.min(a.tick, ms));
118
+ return () => {
119
+ cancel?.();
120
+ cancel = null;
121
+ };
122
+ }
@@ -85,7 +85,7 @@ import type { HostSessionEvidence, RetentionReport } from "../../../core/remembe
85
85
  import { pruneRetention } from "../../../core/remember/retention.js";
86
86
  import { dataDir, describeGuardRefusal } from "../../../core/store/index.js";
87
87
  import type { Store } from "../../../core/store/index.js";
88
- import { hostSessionEvidence, installedVersion, writeUpSources } from "../../sessions.js";
88
+ import { hostSessionEvidence, installedVersion, rewindWriteUps, writeUpSources } from "../../sessions.js";
89
89
  import { openLog } from "../../log/index.js";
90
90
  import { BINARY, TRANSPILED } from "../../runtime.js";
91
91
  import { installRoute } from "../../plugin.js";
@@ -197,6 +197,8 @@ const EMPTY_RETENTION: RetentionReport = {
197
197
  failed: 0,
198
198
  lines: 0,
199
199
  bytes: 0,
200
+ unboundLines: 0,
201
+ unboundSessions: [],
200
202
  };
201
203
 
202
204
  /**
@@ -285,6 +287,11 @@ export function retentionJob(input: {
285
287
  if (report.reason === "IO_FAILED" && report.failed === 0 && report.scopes === 0) {
286
288
  return { ...none, reason: "failed", code: "LATCH_FAILED" };
287
289
  }
290
+ // Lines gone from the head of a bucket move every part after them, so a
291
+ // write-up of it part way through starts again rather than skip what moved.
292
+ // Only that bucket: a write-up of the other lost nothing, and starting it
293
+ // again on every pass could keep it from ever finishing.
294
+ for (const session of report.unboundSessions) rewindWriteUps(store, session);
288
295
  let recorded = false;
289
296
  try {
290
297
  store.appendEvent({
@@ -305,6 +312,7 @@ export function retentionJob(input: {
305
312
  keptLive: report.keptLive,
306
313
  failed: report.failed,
307
314
  lines: report.lines,
315
+ unboundLines: report.unboundLines,
308
316
  recorded,
309
317
  });
310
318
  return { reason: "ran", date, report, recorded, code: null };