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.
- package/CHANGELOG.md +114 -0
- package/CONSTITUTION.md +6 -4
- package/README.md +4 -3
- package/docs/QUICKSTART.md +1 -1
- package/docs/manual.md +123 -0
- package/docs/module-map.md +2 -1
- package/package.json +2 -1
- package/src/adapters/claude-code/CONTRACT.md +15 -4
- package/src/adapters/claude-code/NOTES.md +55 -1
- package/src/adapters/claude-code/awake.ts +122 -0
- package/src/adapters/claude-code/bin/runner.ts +9 -1
- package/src/adapters/claude-code/child.ts +14 -4
- package/src/adapters/claude-code/doctor-self-page.ts +47 -2
- package/src/adapters/claude-code/doctor.ts +27 -8
- package/src/adapters/claude-code/hooks.ts +49 -9
- package/src/adapters/claude-code/night-catch-up.ts +68 -1
- package/src/adapters/claude-code/night-run.ts +97 -19
- package/src/adapters/claude-code/transcript.ts +60 -6
- package/src/adapters/cli/commands-install.ts +9 -4
- package/src/adapters/cli/commands-note.ts +6 -5
- package/src/adapters/cli/commands-readings.ts +10 -2
- package/src/adapters/cli/commands.ts +4 -3
- package/src/adapters/cli/dream-core.ts +1 -1
- package/src/adapters/cli/help.ts +3 -2
- package/src/adapters/cli/uninstall.ts +21 -4
- package/src/adapters/config.ts +16 -3
- package/src/adapters/dashboard/registries.ts +1 -1
- package/src/adapters/dashboard/web/narrate.ts +5 -1
- package/src/adapters/dashboard/web/pages/memories/index.js +4 -2
- package/src/adapters/dashboard/web/views/memories.ts +8 -2
- package/src/adapters/dashboard/web/views/overview.ts +14 -3
- package/src/adapters/dashboard/web/views/today.ts +3 -1
- package/src/adapters/hosts.ts +26 -4
- package/src/adapters/lifecycle.ts +9 -2
- package/src/adapters/log/index.ts +4 -1
- package/src/adapters/mcp/CONTRACT.md +5 -2
- package/src/adapters/mcp/INTERFACE-GAPS.md +5 -0
- package/src/adapters/mcp/NOTES.md +45 -1
- package/src/adapters/mcp/facts.ts +23 -6
- package/src/adapters/mcp/manual.ts +145 -0
- package/src/adapters/mcp/meaning.ts +7 -2
- package/src/adapters/mcp/server-self-tools.ts +7 -2
- package/src/adapters/mcp/server-session-end.ts +2 -2
- package/src/adapters/mcp/server-words.ts +13 -4
- package/src/adapters/mcp/server.ts +96 -30
- package/src/adapters/mcp/tools.ts +75 -13
- package/src/adapters/mcp/write-up.ts +46 -4
- package/src/adapters/plugin-run.sh +32 -8
- package/src/adapters/remote/http.ts +6 -1
- package/src/adapters/sessions.ts +43 -0
- package/src/adapters/snapshots.ts +59 -0
- package/src/adapters/update-check.ts +1 -1
- package/src/core/associate/CONTRACT.md +4 -0
- package/src/core/associate/NOTES.md +43 -0
- package/src/core/associate/index.ts +41 -5
- package/src/core/associate/tunables.ts +29 -0
- package/src/core/counterpart-deposit.ts +45 -14
- package/src/core/counterpart-types.ts +5 -2
- package/src/core/counterpart-wake-news.ts +230 -0
- package/src/core/counterpart-wake-shape.ts +95 -17
- package/src/core/counterpart.ts +25 -2
- package/src/core/dream/CONTRACT.md +4 -3
- package/src/core/dream/NOTES.md +9 -0
- package/src/core/dream/index.ts +26 -9
- package/src/core/dream/reflect.ts +4 -2
- package/src/core/onboarding.ts +43 -13
- package/src/core/recall/CONTRACT.md +1 -1
- package/src/core/recall/INTERFACE-GAPS.md +1 -1
- package/src/core/recall/NOTES.md +110 -0
- package/src/core/recall/activate.ts +28 -5
- package/src/core/recall/gate.ts +63 -12
- package/src/core/recall/habituation.ts +15 -2
- package/src/core/recall/index.ts +10 -2
- package/src/core/recall/session.ts +9 -3
- package/src/core/recall/tunables.ts +8 -2
- package/src/core/remember/CONTRACT.md +23 -4
- package/src/core/remember/NOTES.md +157 -0
- package/src/core/remember/index.ts +2 -0
- package/src/core/remember/owes.ts +100 -1
- package/src/core/remember/owner-strike-seam.ts +7 -1
- package/src/core/remember/proposals.ts +75 -27
- package/src/core/remember/retention.ts +35 -3
- package/src/core/remember/spans.ts +31 -2
- package/src/core/schemas/index.ts +2 -2
- package/src/core/self/CONTRACT.md +1 -1
- package/src/core/self/NOTES.md +54 -0
- package/src/core/self/briefing-delivery.ts +16 -4
- package/src/core/self/identity.ts +4 -0
- package/src/core/self/index.ts +4 -1
- package/src/core/self/journal-file.ts +2 -1
- package/src/core/self/tunables.ts +34 -2
- package/src/core/self/writer.ts +9 -2
- package/src/core/sleep/CONTRACT.md +4 -2
- package/src/core/sleep/consolidate.ts +8 -0
- package/src/core/sleep/cycle.ts +20 -0
- package/src/core/sleep/types.ts +7 -0
- package/src/core/store/CONTRACT.md +1 -1
- package/src/core/store/NOTES.md +9 -1
- package/src/core/store/index.ts +27 -4
- package/src/core/store/reads-memories.ts +44 -1
- package/src/core/store/shapes.ts +10 -0
- package/src/core/store/tag-reads.ts +3 -0
- package/src/core/told.ts +249 -0
- package/src/core/types.ts +15 -0
- package/tools/install-loop/run.sh +21 -7
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
import { spawn } from "node:child_process";
|
|
18
18
|
|
|
19
19
|
import { withHostUmask } from "../private-umask.js";
|
|
20
|
+
import { armAwake } from "./awake.js";
|
|
21
|
+
import type { AwakeOptions } from "./awake.js";
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* The host CLI a windowless child runs — always this one, resolved on the
|
|
@@ -95,12 +97,16 @@ export const STDERR_TAIL_BYTES = 8 * 1024;
|
|
|
95
97
|
export const KILL_GRACE_MS = 5_000;
|
|
96
98
|
export const REAP_GRACE_MS = 2_000;
|
|
97
99
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
+
/**
|
|
101
|
+
* The real starter: one child, two alarms, and an end that does not need it.
|
|
102
|
+
* `awake`: TESTS ONLY, the watchdog's tick and gap (`awake.ts`).
|
|
103
|
+
*/
|
|
104
|
+
export async function startChild(plan: ChildPlan, abort?: AbortSignal, awake?: AwakeOptions): Promise<ChildResult> {
|
|
100
105
|
return await new Promise<ChildResult>((resolve) => {
|
|
101
106
|
let settled = false;
|
|
102
107
|
let terminated = false;
|
|
103
108
|
const timers: ReturnType<typeof setTimeout>[] = [];
|
|
109
|
+
let watchdog: (() => void) | null = null;
|
|
104
110
|
let off: (() => void) | null = null;
|
|
105
111
|
// THE CHILD'S OWN OUTPUT (2026-10-12), kept only when asked for and only
|
|
106
112
|
// up to the cap. A child that writes past it is drained, never blocked.
|
|
@@ -118,6 +124,7 @@ export async function startChild(plan: ChildPlan, abort?: AbortSignal): Promise<
|
|
|
118
124
|
if (settled) return;
|
|
119
125
|
settled = true;
|
|
120
126
|
for (const t of timers) clearTimeout(t);
|
|
127
|
+
watchdog?.();
|
|
121
128
|
off?.();
|
|
122
129
|
resolve({ ...r, ...output(), ...stderr() });
|
|
123
130
|
};
|
|
@@ -190,9 +197,12 @@ export async function startChild(plan: ChildPlan, abort?: AbortSignal): Promise<
|
|
|
190
197
|
);
|
|
191
198
|
};
|
|
192
199
|
// THE CHILD'S OWN WATCHDOG, armed here rather than left to `spawn`'s
|
|
193
|
-
// `timeout` option, which only signals and never resolves anything.
|
|
200
|
+
// `timeout` option, which only signals and never resolves anything. In
|
|
201
|
+
// time AWAKE (2026-11-01, NT1): a laptop's sleep is not the child being
|
|
202
|
+
// stuck. The two graces above stay plain: a kill that waits out a sleep
|
|
203
|
+
// has nothing to lose by landing on wake.
|
|
194
204
|
if (Number.isFinite(plan.timeoutMs) && plan.timeoutMs > 0) {
|
|
195
|
-
|
|
205
|
+
watchdog = armAwake(terminate, plan.timeoutMs, awake);
|
|
196
206
|
}
|
|
197
207
|
// THE CALLER'S WATCHDOG, which may be shorter than the child's. Fired, it
|
|
198
208
|
// takes the child with it rather than leaving the caller holding the store
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
// dashboard's health panel so the three cannot disagree about what "silent"
|
|
34
34
|
// means (constitution 16, the same rule this module already keeps for "healthy").
|
|
35
35
|
import { daysBetween } from "../fired.js";
|
|
36
|
+
import { NIGHT_RUNNER_PREFIX, NON_INTERACTIVE_ENTRYPOINTS, listSessions } from "../sessions.js";
|
|
36
37
|
import { pageWriterMode } from "../config.js";
|
|
37
38
|
import type { AdapterConfig } from "../config.js";
|
|
38
39
|
import { catchUpOf, catchUpWords } from "./night-catch-up.js";
|
|
@@ -112,6 +113,50 @@ function toldDuring(store: Store, startedAt: number): boolean {
|
|
|
112
113
|
* working. The fix says what to look at.
|
|
113
114
|
*/
|
|
114
115
|
export function nightRunFindings(input: DoctorInput, store: Store): Finding[] {
|
|
116
|
+
return [...lastNightFindings(input, store), ...headlessOnlyFindings(store)];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** How long without a night, ms, before a store only headless sessions use says so. */
|
|
120
|
+
export const HEADLESS_ONLY_AFTER_MS = 2 * 24 * 60 * 60_000;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* ONLY HEADLESS SESSIONS HERE, AND NO NIGHTS (2026-11-01, NT1): a night waits for
|
|
124
|
+
* a session a person starts (`hooks.ts#passOnNight`), so a store only `claude -p`
|
|
125
|
+
* or the Agent SDK ever uses gets none under `auto`, the same as it always did
|
|
126
|
+
* under `ask`. Its memories wait in the queue. AMBER: a mechanism the owner chose
|
|
127
|
+
* isn't running. Read from the registry's week, by entrypoint (it keeps no
|
|
128
|
+
* `attended`), so a session the registry can't call headless keeps this quiet.
|
|
129
|
+
*/
|
|
130
|
+
function headlessOnlyFindings(store: Store): Finding[] {
|
|
131
|
+
try {
|
|
132
|
+
if (dreamingSetting(store) !== "auto") return [];
|
|
133
|
+
const now = store.now();
|
|
134
|
+
const run = nightRunOf(store);
|
|
135
|
+
let headless = 0;
|
|
136
|
+
let oldest = now;
|
|
137
|
+
for (const r of listSessions(store.dir)) {
|
|
138
|
+
if (r.sessionId.startsWith(NIGHT_RUNNER_PREFIX)) continue;
|
|
139
|
+
if (r.entrypoint === undefined || !NON_INTERACTIVE_ENTRYPOINTS.has(r.entrypoint)) return [];
|
|
140
|
+
headless += 1;
|
|
141
|
+
oldest = Math.min(oldest, r.startedAt);
|
|
142
|
+
}
|
|
143
|
+
if (headless === 0 || now - (run?.startedAt ?? oldest) < HEADLESS_ONLY_AFTER_MS) return [];
|
|
144
|
+
return [
|
|
145
|
+
finding(
|
|
146
|
+
"night-headless",
|
|
147
|
+
"amber",
|
|
148
|
+
"Nightly run",
|
|
149
|
+
`auto; no night ${run === null ? "yet" : `since ${run.date}`}: only headless sessions here this week (claude -p, the Agent SDK), and a night waits for a session a person starts`,
|
|
150
|
+
"Nothing is lost while it waits: the memories stay queued. Start one session by hand and the night runs.",
|
|
151
|
+
{ setting: "auto", headless },
|
|
152
|
+
),
|
|
153
|
+
];
|
|
154
|
+
} catch {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function lastNightFindings(input: DoctorInput, store: Store): Finding[] {
|
|
115
160
|
let setting: DreamingSetting;
|
|
116
161
|
let run: ReturnType<typeof nightRunOf>;
|
|
117
162
|
let now: number;
|
|
@@ -124,7 +169,7 @@ export function nightRunFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
124
169
|
}
|
|
125
170
|
if (run === null) {
|
|
126
171
|
if (setting !== "auto") return [];
|
|
127
|
-
return [finding("night-run", "green", "Nightly run", "auto; no headless run yet — the first session
|
|
172
|
+
return [finding("night-run", "green", "Nightly run", "auto; no headless run yet — the first session a person starts on a day with enough new memory, or with write-ups owed from an earlier day, starts one", "", { setting, state: null })];
|
|
128
173
|
}
|
|
129
174
|
// ITS MORNING CATCH-UP (2026-10-01, build 3), when it had anything owed.
|
|
130
175
|
const cu = catchUpOf(store, run.run);
|
|
@@ -190,7 +235,7 @@ export function nightRunFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
190
235
|
lost && setting === "auto" ? "amber" : "green",
|
|
191
236
|
"Nightly run",
|
|
192
237
|
lost
|
|
193
|
-
? `${setting}; the run of ${run.date} started ${mins(now - run.startedAt)} ago and never reported an end — its process went away (a
|
|
238
|
+
? `${setting}; the run of ${run.date} started ${mins(now - run.startedAt)} ago and never reported an end — its process went away (a restart, a kill)`
|
|
194
239
|
: `${setting}; running now (${what}), started ${mins(now - run.startedAt)} ago`,
|
|
195
240
|
lost ? "The next session asks instead of starting another headless run. If this repeats, run claude -p once by hand in a terminal to see whether it hangs (a login, an update prompt)." : "",
|
|
196
241
|
data,
|
|
@@ -168,6 +168,7 @@ import { owedFolders, readOwed, crashWriteUpFindings, nightHeldFindings, overdue
|
|
|
168
168
|
import type { OwedSource, OwedReading } from "./doctor-write-ups.js";
|
|
169
169
|
import { worstFirst } from "./doctor-report.js";
|
|
170
170
|
import { feedbackLoopFindings } from "./doctor-feedback.js";
|
|
171
|
+
import { starterNotes } from "../../core/told.js";
|
|
171
172
|
|
|
172
173
|
// What moved to the doctor-*.ts parts, re-exported so every import of this file still resolves.
|
|
173
174
|
export { SEVERITIES } from "./doctor-finding.js";
|
|
@@ -502,7 +503,8 @@ function configFindings(input: DoctorInput): Finding[] {
|
|
|
502
503
|
: finding("store", "green", MEMORY_TITLE, memoryDetail(input, held), "", {
|
|
503
504
|
dir: input.dir,
|
|
504
505
|
exists: true,
|
|
505
|
-
memories: held,
|
|
506
|
+
memories: held === null ? null : held.lived,
|
|
507
|
+
starterNotes: held === null ? null : held.told,
|
|
506
508
|
}),
|
|
507
509
|
);
|
|
508
510
|
return out;
|
|
@@ -595,7 +597,8 @@ function configFindings(input: DoctorInput): Finding[] {
|
|
|
595
597
|
finding("store", "green", MEMORY_TITLE, memoryDetail(input, held), "", {
|
|
596
598
|
dir: input.dir,
|
|
597
599
|
exists: true,
|
|
598
|
-
memories: held,
|
|
600
|
+
memories: held === null ? null : held.lived,
|
|
601
|
+
starterNotes: held === null ? null : held.told,
|
|
599
602
|
}),
|
|
600
603
|
);
|
|
601
604
|
}
|
|
@@ -628,9 +631,11 @@ const MEMORY_TITLE = "Memory";
|
|
|
628
631
|
* row: this line is built on the hook's hot path too, and a census that opened
|
|
629
632
|
* every row would put the whole store between a session and its first word.
|
|
630
633
|
*/
|
|
631
|
-
|
|
634
|
+
/** Live memory rows, the starter memories counted apart (S1): `{ lived, told }`. */
|
|
635
|
+
function memoryCount(store: Store): { lived: number; told: number } | null {
|
|
632
636
|
try {
|
|
633
|
-
|
|
637
|
+
const told = store.liveToldCount();
|
|
638
|
+
return { lived: store.countMemories({ type: "memory", archived: false }) - told, told };
|
|
634
639
|
} catch {
|
|
635
640
|
// A store that will not answer still has a path worth printing, and the
|
|
636
641
|
// `Store open` line is where an unreadable store is graded.
|
|
@@ -647,8 +652,12 @@ function memoryCount(store: Store): number | null {
|
|
|
647
652
|
* `--json` still carry it, and a store that will NOT open prints its own line
|
|
648
653
|
* with the code and the repair.
|
|
649
654
|
*/
|
|
650
|
-
function memoryDetail(input: DoctorInput, n: number | null): string {
|
|
651
|
-
|
|
655
|
+
function memoryDetail(input: DoctorInput, n: { lived: number; told: number } | null): string {
|
|
656
|
+
// The lived memories are the number; the starter notes are said apart (ROADMAP, 11-03).
|
|
657
|
+
const held =
|
|
658
|
+
n === null
|
|
659
|
+
? ""
|
|
660
|
+
: ` — ${String(n.lived)} ${n.lived === 1 ? "memory" : "memories"}${n.told === 0 ? "" : ` · ${starterNotes(n.told)}`}`;
|
|
652
661
|
const opens = input.open?.ok === true ? ", opens fine" : "";
|
|
653
662
|
return `${tilde(input.dir)}${held}${opens}`;
|
|
654
663
|
}
|
|
@@ -957,6 +966,7 @@ function retentionFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
957
966
|
keptYoung: run.keptYoung,
|
|
958
967
|
keptLive: run.keptLive,
|
|
959
968
|
failed: run.failed,
|
|
969
|
+
unboundLines: run.unboundLines,
|
|
960
970
|
};
|
|
961
971
|
const unfinished = run.reason === "STARTED" || run.reason === "LATCH_HELD";
|
|
962
972
|
if (unfinished && run.date < input.today) {
|
|
@@ -974,7 +984,11 @@ function retentionFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
974
984
|
if (unfinished) {
|
|
975
985
|
return [finding("retention", "green", TITLE, `${policy} · a pass started today`, "", data)];
|
|
976
986
|
}
|
|
977
|
-
|
|
987
|
+
// The notes filed under a shared id, "mcp" or "console", go line by line, on
|
|
988
|
+
// their own age (`remember/owes.ts#planUnboundLines`), so they are not in `deleted`.
|
|
989
|
+
const unbound =
|
|
990
|
+
run.unboundLines > 0 ? ` · ${String(run.unboundLines)} old note${run.unboundLines === 1 ? "" : "s"} with no session let go` : "";
|
|
991
|
+
const counts = `${String(run.deleted)} pruned ${run.date}${unbound} · ${String(run.keptOwed)} kept until written up · ${String(run.keptLive)} still open`;
|
|
978
992
|
if (run.failed > 0) {
|
|
979
993
|
return [
|
|
980
994
|
finding(
|
|
@@ -2004,7 +2018,12 @@ function vectorFindings(input: DoctorInput, store: Store): Finding[] {
|
|
|
2004
2018
|
// session. A store that has lived one and still has a shortfall keeps the
|
|
2005
2019
|
// amber below.
|
|
2006
2020
|
if (unembedded > 0 && !livedABoundary(store)) {
|
|
2007
|
-
|
|
2021
|
+
// The starter notes said apart (S1): a new store's 11 are not memories anybody made.
|
|
2022
|
+
const toldIds = new Set(store.toldIds());
|
|
2023
|
+
const toldWaiting = toldIds.size === 0 ? 0 : store.missingVectors(unembedded).filter((id) => toldIds.has(id)).length;
|
|
2024
|
+
const lived = unembedded - toldWaiting;
|
|
2025
|
+
const livedSaid = lived === 1 ? "1 memory" : `${lived} memories`;
|
|
2026
|
+
const memories = toldWaiting === 0 ? livedSaid : lived === 0 ? starterNotes(toldWaiting) : `${livedSaid} · ${starterNotes(toldWaiting)}`;
|
|
2008
2027
|
return [finding("vectors", "green", "Vectors", `${memories} not searchable by meaning yet — this builds after your first session`, "", data)];
|
|
2009
2028
|
}
|
|
2010
2029
|
if (unembedded > 0) {
|
|
@@ -285,15 +285,30 @@ export interface DreamTold {
|
|
|
285
285
|
* code does not know. A headless or SDK one (`sessions.ts#NON_INTERACTIVE_
|
|
286
286
|
* ENTRYPOINTS`: `claude -p` is `sdk-cli`) — or, first, one the host itself
|
|
287
287
|
* says nobody attends (`HookInput.attended`) — leaves them for the next session
|
|
288
|
-
* that is
|
|
289
|
-
*
|
|
290
|
-
*
|
|
288
|
+
* that is. Measured 2026-10-01: the day's first prompt came from an SDK session
|
|
289
|
+
* with no terminal, which started the run and claimed the dream line (nobody saw
|
|
290
|
+
* it). Whether it may START the night is a narrower question: `passesOnNight`.
|
|
291
291
|
*/
|
|
292
292
|
export function isInteractive(input: Pick<HookInput, "entrypoint" | "attended">): boolean {
|
|
293
293
|
if (input.attended !== undefined) return input.attended;
|
|
294
294
|
return input.entrypoint === undefined || !NON_INTERACTIVE_ENTRYPOINTS.has(input.entrypoint);
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* DOES THIS SESSION LEAVE THE NIGHT TO SOMEONE ELSE? (2026-11-01, NT1; review of
|
|
299
|
+
* #712.) Only a name on the headless list (`claude -p`, the SDKs, `mcp`, the GitHub
|
|
300
|
+
* action), the same reading as doctor's (`sessions.ts#notPointableWhy`), unless the
|
|
301
|
+
* host says a person is there. NOT `!isInteractive`: a wrong "nobody's watching"
|
|
302
|
+
* only holds a line for the next prompt, and a wrong "headless" here means no
|
|
303
|
+
* nights. `ATTENDED=0` covers more than `claude -p` (read from the 2.1.316 binary):
|
|
304
|
+
* a person's `claude --bg` (kind `bg`, entrypoint `cli`), a teammate, and any process
|
|
305
|
+
* with no terminal whose entrypoint isn't on the host's own list. Those start the
|
|
306
|
+
* night unwatched (`startUnwatched`), as they always did.
|
|
307
|
+
*/
|
|
308
|
+
export function passesOnNight(input: Pick<HookInput, "entrypoint" | "attended">): boolean {
|
|
309
|
+
return input.attended !== true && input.entrypoint !== undefined && NON_INTERACTIVE_ENTRYPOINTS.has(input.entrypoint);
|
|
310
|
+
}
|
|
311
|
+
|
|
297
312
|
/**
|
|
298
313
|
* IS A PERSON THERE FOR THIS SESSION START? (2026-10-12.) `isInteractive`,
|
|
299
314
|
* and two starts no person makes even when the host says somebody attends:
|
|
@@ -1211,8 +1226,16 @@ export class ClaudeCodeAdapter extends Lifecycle {
|
|
|
1211
1226
|
private dreamLines(input: HookInput, byHost = false): { text: string; told: DreamTold | null; note: { notice: string; context: string } | null } {
|
|
1212
1227
|
const none = { text: "", told: null, note: null };
|
|
1213
1228
|
if (this.observer || input.at === undefined || input.nightRun === true || input.sessionId.length === 0) return none;
|
|
1214
|
-
// A
|
|
1215
|
-
//
|
|
1229
|
+
// A HEADLESS SESSION LEAVES THE NIGHT (2026-11-01, NT1): the night of 11-01
|
|
1230
|
+
// started from one in a lid-closed dark wake. Nothing is claimed, so the
|
|
1231
|
+
// next session a person starts takes it, and nothing is lost by waiting.
|
|
1232
|
+
if (passesOnNight(input)) {
|
|
1233
|
+
this.passOnNight(input);
|
|
1234
|
+
return none;
|
|
1235
|
+
}
|
|
1236
|
+
// A TURN NO PERSON STARTED, in a person's session (review of #445,
|
|
1237
|
+
// 2026-10-12; `startedByHost`), or a session the host calls unattended that
|
|
1238
|
+
// isn't on the headless list: the headless run may start and its line is
|
|
1216
1239
|
// held; the day's line, the morning share and the raises wait for a person.
|
|
1217
1240
|
if (!isInteractive(input) || byHost) {
|
|
1218
1241
|
this.startUnwatched(input);
|
|
@@ -1279,10 +1302,27 @@ export class ClaudeCodeAdapter extends Lifecycle {
|
|
|
1279
1302
|
}
|
|
1280
1303
|
|
|
1281
1304
|
/**
|
|
1282
|
-
* A SESSION
|
|
1305
|
+
* A HEADLESS SESSION PASSES ON THE NIGHT (2026-11-01, NT1): the offer is read
|
|
1306
|
+
* and never claimed, so the day stays the next person's. The line in the log
|
|
1307
|
+
* says one passed; nothing is written to the store. Never throws.
|
|
1308
|
+
*/
|
|
1309
|
+
private passOnNight(input: HookInput): void {
|
|
1310
|
+
if (input.at === undefined) return;
|
|
1311
|
+
try {
|
|
1312
|
+
const offer = this.counterpart.dreams.offer({ at: input.at, session: input.sessionId });
|
|
1313
|
+
if (offer?.headless === true) this.emit("adapter.dream.unwatched", { started: false, passed: "headless", entrypoint: input.entrypoint ?? null });
|
|
1314
|
+
} catch {
|
|
1315
|
+
/* the log line is a courtesy */
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* A TURN NO PERSON STARTED, IN A PERSON'S SESSION, OR A SESSION THE HOST CALLS
|
|
1321
|
+
* UNATTENDED OFF THE HEADLESS LIST (2026-10-01, lane 8; `claude -p`'s and the
|
|
1322
|
+
* SDK's until NT1, `passesOnNight`): it may START the day's
|
|
1283
1323
|
* headless run — the start is the point — and the line it would have been
|
|
1284
|
-
* told is held for the next
|
|
1285
|
-
* ASK is left unclaimed for that
|
|
1324
|
+
* told is held for the next turn a person starts (`Dreams#holdTold`). An
|
|
1325
|
+
* ASK is left unclaimed for that turn too: nobody here could answer it.
|
|
1286
1326
|
* Nothing else is offered, raised, carried or claimed. Never throws.
|
|
1287
1327
|
*/
|
|
1288
1328
|
private startUnwatched(input: HookInput): void {
|
|
@@ -1447,7 +1487,7 @@ export class ClaudeCodeAdapter extends Lifecycle {
|
|
|
1447
1487
|
});
|
|
1448
1488
|
if (!out.started) return couldNot("runner", out.code ?? String(out.reason));
|
|
1449
1489
|
dreams.recordNightRun({ ...base, state: "started" });
|
|
1450
|
-
this.emit("adapter.night.started", { run, pid: out.pid, kind: kind.kind, ...(offer.dreamSkipped === undefined ? {} : { dreamSkipped: offer.dreamSkipped }) });
|
|
1490
|
+
this.emit("adapter.night.started", { run, pid: out.pid, kind: kind.kind, entrypoint: input.entrypoint ?? null, ...(offer.dreamSkipped === undefined ? {} : { dreamSkipped: offer.dreamSkipped }) });
|
|
1451
1491
|
return true;
|
|
1452
1492
|
} catch (err) {
|
|
1453
1493
|
return couldNot("runner", codeOf(err));
|
|
@@ -62,11 +62,14 @@ import type { Counterpart, CounterpartEvent, Seat } from "../../core/counterpart
|
|
|
62
62
|
import { calendarDate } from "../../core/self/index.js";
|
|
63
63
|
import { TUNABLES } from "../config.js";
|
|
64
64
|
import type { AdapterConfig } from "../config.js";
|
|
65
|
+
import { awakeMeter } from "./awake.js";
|
|
66
|
+
import type { AwakeMeter } from "./awake.js";
|
|
65
67
|
import { foldersOn, scopesPath } from "../scopes.js";
|
|
66
68
|
import {
|
|
67
69
|
NIGHT_RUNNER_PREFIX,
|
|
68
70
|
WRITE_UP_CLAIM_MS,
|
|
69
71
|
WRITE_UP_PART_BYTES,
|
|
72
|
+
WRITE_UP_PLUMBING_RULE,
|
|
70
73
|
claimedByOther,
|
|
71
74
|
firstUnwrittenPart,
|
|
72
75
|
grantWriteUps,
|
|
@@ -415,6 +418,37 @@ export function releaseCatchUp(c: Counterpart, plan: CatchUpPlan, opts: { scope:
|
|
|
415
418
|
}
|
|
416
419
|
}
|
|
417
420
|
|
|
421
|
+
/**
|
|
422
|
+
* RENEW WHAT A SLEEP WOULD HAVE LET RUN OUT (2026-11-01, NT1): a sleep past
|
|
423
|
+
* `WRITE_UP_CLAIM_MS` would leave the waking child with no claim on what it is
|
|
424
|
+
* writing and a grant the door refuses (`mcp/write-up.ts`), while another session
|
|
425
|
+
* could take the same subject. A process that noticed its sleep is plainly alive,
|
|
426
|
+
* so its claims and its record are as young as now. Only what is still its own: a
|
|
427
|
+
* subject another writer took meanwhile stays theirs. Never throws.
|
|
428
|
+
*/
|
|
429
|
+
export function renewCatchUp(c: Counterpart, plan: CatchUpPlan, opts: { scope: string; now: number }): void {
|
|
430
|
+
const dir = c.store.dir;
|
|
431
|
+
const scope = opts.scope.length > 0 ? opts.scope : dir;
|
|
432
|
+
try {
|
|
433
|
+
updateWriteUpProgress(c.store, (map) => {
|
|
434
|
+
let changed = false;
|
|
435
|
+
for (const [key, p] of Object.entries(map)) {
|
|
436
|
+
if (p.claim?.by !== plan.runner) continue;
|
|
437
|
+
map[key] = { ...p, claim: { ...p.claim, at: opts.now } };
|
|
438
|
+
changed = true;
|
|
439
|
+
}
|
|
440
|
+
return changed;
|
|
441
|
+
});
|
|
442
|
+
} catch {
|
|
443
|
+
/* it runs out as it would have */
|
|
444
|
+
}
|
|
445
|
+
try {
|
|
446
|
+
recordSession(dir, { sessionId: plan.runner, scope, phase: "boundary", at: opts.now });
|
|
447
|
+
} catch {
|
|
448
|
+
/* it runs out as it would have */
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
418
452
|
/**
|
|
419
453
|
* THE CATCH-UP CHILD'S PROMPT: the runner's id, the sessions in order, and the
|
|
420
454
|
* one way to write each up. Ids, dates and counts — no words of anyone's; the
|
|
@@ -427,6 +461,7 @@ export function catchUpPrompt(plan: CatchUpPlan): string {
|
|
|
427
461
|
"1. Call session_end with writeUp: <its id> and no memories. It returns one part of that conversation.",
|
|
428
462
|
"2. Call session_end with writeUp: <its id>, part: <that part>, memories: [...] — what caught your attention in it, one idea each, in your own words. Do not write again what is marked as already written up. If nothing that is not marked so is worth keeping, send memories: [] with nothing: \"<one line: why>\"; an empty answer without that line is refused while the part holds words not yet written up.",
|
|
429
463
|
"3. Fetch again for its next part, until the answer is \"written-up\" or the door says this run's allowance for it is spent. Then the next session.",
|
|
464
|
+
WRITE_UP_PLUMBING_RULE,
|
|
430
465
|
"",
|
|
431
466
|
"Sessions:",
|
|
432
467
|
...plan.subjects.map(
|
|
@@ -472,6 +507,8 @@ export interface CatchUpReport {
|
|
|
472
507
|
readonly busy: number;
|
|
473
508
|
readonly bytes: number;
|
|
474
509
|
readonly ms: number;
|
|
510
|
+
/** ...of which the machine slept (2026-11-01, NT1). Absent when it didn't. */
|
|
511
|
+
readonly sleptMs?: number;
|
|
475
512
|
readonly code: number | null;
|
|
476
513
|
/** Why the last child failed (2026-10-27, R4): one scrubbed line of what it
|
|
477
514
|
* said (`child-error.ts`); null when it did not fail, or said nothing, and
|
|
@@ -573,6 +610,8 @@ export interface CatchUpInput {
|
|
|
573
610
|
readonly onBatch?: (b: { readonly batch: number; readonly plan: CatchUpPlan }) => void;
|
|
574
611
|
/** The process log (`adapters/log/`), when there is one. */
|
|
575
612
|
readonly onEvent?: (e: CounterpartEvent) => void;
|
|
613
|
+
/** TESTS ONLY: what tells this run it slept; absent, `awake.ts#awakeMeter`. */
|
|
614
|
+
readonly awake?: (onSlept: (ms: number) => void) => AwakeMeter;
|
|
576
615
|
}
|
|
577
616
|
|
|
578
617
|
/** One child, started and waited on: what became of it. */
|
|
@@ -606,6 +645,29 @@ async function runChild(input: CatchUpInput, plan: CatchUpPlan, prompt: string):
|
|
|
606
645
|
* owed (no row: a quiet night is not an event). Never throws.
|
|
607
646
|
*/
|
|
608
647
|
export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | null> {
|
|
648
|
+
// TIME ASLEEP ISN'T THE RUN'S (2026-11-01, NT1): its hour counts time awake,
|
|
649
|
+
// and what the current batch holds is kept alive across a sleep.
|
|
650
|
+
let holding: CatchUpPlan | null = null;
|
|
651
|
+
const onSlept = (): void => {
|
|
652
|
+
if (holding === null) return;
|
|
653
|
+
const c = input.open();
|
|
654
|
+
try {
|
|
655
|
+
renewCatchUp(c, holding, { scope: input.scope, now: input.now() });
|
|
656
|
+
} finally {
|
|
657
|
+
c.close();
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
const meter = input.awake?.(onSlept) ?? awakeMeter({ onSlept });
|
|
661
|
+
try {
|
|
662
|
+
return await catchUpBatches(input, meter, (plan) => {
|
|
663
|
+
holding = plan;
|
|
664
|
+
});
|
|
665
|
+
} finally {
|
|
666
|
+
meter.stop();
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async function catchUpBatches(input: CatchUpInput, meter: AwakeMeter, hold: (plan: CatchUpPlan | null) => void): Promise<CatchUpReport | null> {
|
|
609
671
|
const startedAt = input.now();
|
|
610
672
|
// Read afresh for each plan, and for what is left: a long run sees a folder
|
|
611
673
|
// turned off in the middle of it from its next batch on.
|
|
@@ -634,7 +696,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
|
|
|
634
696
|
limit = "parts";
|
|
635
697
|
break;
|
|
636
698
|
}
|
|
637
|
-
if (batches > 0 && input.now() + TUNABLES.NIGHT_WRITE_UP_MS > deadline) {
|
|
699
|
+
if (batches > 0 && input.now() - meter.asleepMs() + TUNABLES.NIGHT_WRITE_UP_MS > deadline) {
|
|
638
700
|
limit = "time";
|
|
639
701
|
break;
|
|
640
702
|
}
|
|
@@ -691,7 +753,9 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
|
|
|
691
753
|
} catch {
|
|
692
754
|
/* never the run's problem */
|
|
693
755
|
}
|
|
756
|
+
hold(plan);
|
|
694
757
|
const child = await runChild(input, plan, prompt);
|
|
758
|
+
hold(null);
|
|
695
759
|
code = child.code;
|
|
696
760
|
detail = child.detail;
|
|
697
761
|
signedOut = child.signedOut === true;
|
|
@@ -729,6 +793,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
|
|
|
729
793
|
}
|
|
730
794
|
}
|
|
731
795
|
const endedAt = input.now();
|
|
796
|
+
const slept = meter.asleepMs();
|
|
732
797
|
const report = (over: Partial<CatchUpReport>): CatchUpReport => ({
|
|
733
798
|
run: input.run,
|
|
734
799
|
runner: catchUpRunner(input.run),
|
|
@@ -744,6 +809,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
|
|
|
744
809
|
busy,
|
|
745
810
|
bytes,
|
|
746
811
|
ms: endedAt - startedAt,
|
|
812
|
+
...(slept > 0 ? { sleptMs: slept } : {}),
|
|
747
813
|
code,
|
|
748
814
|
detail,
|
|
749
815
|
...(signedOut ? { signedOut: true as const } : {}),
|
|
@@ -784,6 +850,7 @@ function record(input: CatchUpInput, report: CatchUpReport, open?: Counterpart):
|
|
|
784
850
|
busy: report.busy,
|
|
785
851
|
bytes: report.bytes,
|
|
786
852
|
ms: report.ms,
|
|
853
|
+
...(report.sleptMs === undefined ? {} : { sleptMs: report.sleptMs }),
|
|
787
854
|
code: report.code,
|
|
788
855
|
...(report.detail === null ? {} : { detail: report.detail }),
|
|
789
856
|
...(report.signedOut === true ? { signedOut: true } : {}),
|