counterparts 0.3.53 → 0.4.0
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 +202 -0
- package/LICENSE +114 -21
- package/README.md +15 -4
- package/docs/QUICKSTART.md +23 -0
- package/docs/manual.md +33 -5
- package/docs/module-map.md +2 -0
- package/package.json +2 -2
- package/src/adapters/claude-code/CONTRACT.md +11 -0
- package/src/adapters/claude-code/NOTES.md +69 -0
- package/src/adapters/claude-code/bin/hook.ts +3 -0
- package/src/adapters/claude-code/bin/runner.ts +21 -1
- package/src/adapters/claude-code/envelope.ts +5 -1
- package/src/adapters/claude-code/hooks.ts +77 -3
- package/src/adapters/claude-code/night-run.ts +2 -1
- package/src/adapters/claude-code/noticing.ts +339 -0
- package/src/adapters/claude-code/transcript.ts +66 -6
- package/src/adapters/cli/NOTES.md +9 -0
- package/src/adapters/cli/codex.ts +223 -0
- package/src/adapters/cli/commands-install.ts +55 -8
- package/src/adapters/cli/commands-readings.ts +32 -7
- package/src/adapters/cli/commands.ts +11 -8
- package/src/adapters/cli/index.ts +1 -0
- package/src/adapters/cli/mechanisms.ts +3 -1
- package/src/adapters/codex/CONTRACT.md +69 -0
- package/src/adapters/codex/INTERFACE-GAPS.md +78 -0
- package/src/adapters/codex/NOTES.md +37 -0
- package/src/adapters/codex/adapter.ts +248 -0
- package/src/adapters/codex/bin/hook.ts +210 -0
- package/src/adapters/codex/doctor.ts +171 -0
- package/src/adapters/codex/envelope.ts +41 -0
- package/src/adapters/codex/index.ts +58 -0
- package/src/adapters/codex/transcript.ts +216 -0
- package/src/adapters/codex/wire.ts +468 -0
- package/src/adapters/codex/words.ts +104 -0
- package/src/adapters/config.ts +120 -0
- package/src/adapters/dashboard/CONTRACT.md +8 -0
- package/src/adapters/dashboard/registries.ts +3 -0
- package/src/adapters/dashboard/web/README.md +7 -2
- package/src/adapters/dashboard/web/app.html +4 -0
- package/src/adapters/dashboard/web/app.js +31 -2
- package/src/adapters/dashboard/web/flow.ts +2 -0
- package/src/adapters/dashboard/web/lanes.ts +1 -0
- package/src/adapters/dashboard/web/mechanisms/picture.js +2 -2
- package/src/adapters/dashboard/web/narrate.ts +17 -0
- package/src/adapters/dashboard/web/pages/flow/sections/detail.js +3 -1
- package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +1 -1
- package/src/adapters/dashboard/web/pages/health/sections/archive.js +2 -1
- package/src/adapters/dashboard/web/pages/home/sections/hero.js +3 -0
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +10 -4
- package/src/adapters/dashboard/web/pages/memories/sections/tools.js +7 -3
- package/src/adapters/dashboard/web/pages/self/sections/dreams.js +2 -2
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +2 -1
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +4 -3
- package/src/adapters/dashboard/web/pages/self/sections/stories.js +3 -2
- package/src/adapters/dashboard/web/pages/self/sections/traits.js +2 -1
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +2 -1
- package/src/adapters/dashboard/web/respond.ts +349 -0
- package/src/adapters/dashboard/web/server.ts +41 -209
- package/src/adapters/dashboard/web/shared/actions.js +4 -1
- package/src/adapters/dashboard/web/shared/api.js +17 -1
- package/src/adapters/dashboard/web/shared/dom.js +50 -1
- package/src/adapters/dashboard/web/shared/event-modal.js +3 -0
- package/src/adapters/dashboard/web/shared/host.js +48 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +17 -9
- package/src/adapters/dashboard/web/shared/modal.js +8 -3
- package/src/adapters/dashboard/web/shared/utilities.css +5 -0
- package/src/adapters/dashboard/web/shared/widgets/feed.js +1 -1
- package/src/adapters/dashboard/web/shell/pages.js +13 -1
- package/src/adapters/fired.ts +11 -0
- package/src/adapters/hosts.ts +46 -0
- package/src/adapters/lifecycle.ts +35 -7
- package/src/adapters/mcp/CONTRACT.md +158 -9
- package/src/adapters/mcp/NOTES.md +346 -0
- package/src/adapters/mcp/bin/serve.ts +13 -2
- package/src/adapters/mcp/facts.ts +433 -52
- package/src/adapters/mcp/index.ts +7 -0
- package/src/adapters/mcp/meaning.ts +10 -3
- package/src/adapters/mcp/server-args.ts +1281 -7
- package/src/adapters/mcp/server-options.ts +13 -0
- package/src/adapters/mcp/server-session-end.ts +129 -52
- package/src/adapters/mcp/server-words.ts +4 -2
- package/src/adapters/mcp/server.ts +446 -71
- package/src/adapters/mcp/tools.ts +558 -1091
- package/src/adapters/mcp/write-up.ts +21 -4
- package/src/adapters/remote/bin/serve-http.ts +2 -0
- package/src/adapters/remote/http.ts +9 -1
- package/src/adapters/runtime.ts +4 -1
- package/src/adapters/spawn.ts +12 -0
- package/src/adapters/update-check.ts +1 -1
- package/src/core/briefing.ts +20 -7
- package/src/core/counterpart-boundary.ts +13 -0
- package/src/core/counterpart-deposit.ts +141 -14
- package/src/core/counterpart-events.ts +23 -0
- package/src/core/counterpart-types.ts +80 -1
- package/src/core/counterpart-wake-news.ts +23 -8
- package/src/core/counterpart-wake-shape.ts +134 -36
- package/src/core/counterpart.ts +99 -27
- package/src/core/dream/CONTRACT.md +15 -1
- package/src/core/dream/NOTES.md +64 -0
- package/src/core/dream/index.ts +33 -11
- package/src/core/dream/reflect.ts +149 -14
- package/src/core/dream/slices.ts +17 -2
- package/src/core/feelings-wheel.ts +154 -0
- package/src/core/mint.ts +27 -0
- package/src/core/owner-waits.ts +135 -12
- package/src/core/prospective/NOTES.md +113 -1
- package/src/core/prospective/index.ts +70 -15
- package/src/core/reader-note.ts +235 -0
- package/src/core/recall/CONTRACT.md +18 -3
- package/src/core/recall/NOTES.md +125 -0
- package/src/core/recall/gate.ts +14 -0
- package/src/core/recall/index.ts +197 -2
- package/src/core/recall/render.ts +7 -1
- package/src/core/recall/standing.ts +87 -10
- package/src/core/recall/time-ask.ts +276 -4
- package/src/core/recall/tunables.ts +16 -0
- package/src/core/reconsolidation.ts +56 -11
- package/src/core/remember/proposals.ts +8 -1
- package/src/core/schemas/NOTES.md +6 -0
- package/src/core/schemas/index.ts +25 -2
- package/src/core/schemas/tags.ts +7 -1
- package/src/core/schemas/types.ts +2 -0
- package/src/core/self/CONTRACT.md +46 -5
- package/src/core/self/NOTES.md +158 -0
- package/src/core/self/briefing-delivery.ts +11 -4
- package/src/core/self/briefing-room.ts +4 -2
- package/src/core/self/briefing.ts +14 -5
- package/src/core/self/episodes.ts +24 -1
- package/src/core/self/identity.ts +4 -0
- package/src/core/self/index.ts +75 -16
- package/src/core/self/set-down.ts +33 -0
- package/src/core/self/tunables.ts +18 -3
- package/src/core/self/writer.ts +107 -16
- package/src/core/sleep/CONTRACT.md +2 -1
- package/src/core/sleep/NOTES.md +13 -0
- package/src/core/sleep/consolidate.ts +8 -1
- package/src/core/sleep/cycle.ts +12 -2
- package/src/core/sleep/dedup.ts +8 -0
- package/src/core/sleep/types.ts +26 -0
- package/src/core/store/NOTES.md +7 -0
- package/src/core/store/errors.ts +5 -0
- package/src/core/store/index.ts +18 -3
- package/src/core/store/reads-memories.ts +29 -1
- package/src/core/store/shapes.ts +6 -0
- package/src/core/store/wave2.ts +34 -15
- package/src/core/time.ts +721 -0
- package/src/core/types.ts +9 -0
|
@@ -3039,3 +3039,72 @@ for its target (an `.exe`, or a `.js` given to `node`) rather than running it th
|
|
|
3039
3039
|
prompt as arguments. Proven in CI by `.github/workflows/windows.yml` (`tools/door/npm-door.mjs`), which installs Claude
|
|
3040
3040
|
Code from npm so `claude` is the `.cmd`; a full night needs a Claude login a runner doesn't have, so the door checks the
|
|
3041
3041
|
night starts and reaches `claude -p`.
|
|
3042
|
+
|
|
3043
|
+
## 2026-11-16 — the worker on a host's store clock
|
|
3044
|
+
|
|
3045
|
+
`runner.ts#storeClockOf` reads `COUNTERPARTS_STORE_CLOCK_OFFSET_MS` (`spawn.ts#STORE_CLOCK_OFFSET_ENV`) and opens the
|
|
3046
|
+
run's counterpart on the system clock plus that offset. Only hosted sets it, under `storeClock` (a simulated month):
|
|
3047
|
+
without it, a page revised the day before read "more than 14 days" old in every bundle the worker published.
|
|
3048
|
+
`planSpawn` drops an inherited one, so the hooks' workers never see a value a shell exported.
|
|
3049
|
+
|
|
3050
|
+
## 2026-11-09 — a second hooked host borrows this entry's readers (CX2)
|
|
3051
|
+
|
|
3052
|
+
- `codex/bin/hook.ts` imports `hookConfigChoice`, `hostConfig`, `eventDirectory`, `sessionScope` and
|
|
3053
|
+
`hookScopeVerdict` from `bin/hook.ts`, and `openEmbedder`: an entry point borrowing, as `mcp/bin/serve.ts` does.
|
|
3054
|
+
`sessionScope`'s `opensASession` keys on `SessionStart`, which is Codex's spelling too. Nothing here changed; the
|
|
3055
|
+
Codex hook's command (`adapters/codex/bin/hook.ts`) does not match `HOOK_COMMAND_MARK`, so neither host's
|
|
3056
|
+
`connect` reads the other's line as its own.
|
|
3057
|
+
|
|
3058
|
+
## 2026-11-26 — noticing v1: a counts-only nudge toward `remember` after reading or sending
|
|
3059
|
+
|
|
3060
|
+
What the build learned (`noticing.ts`; design: the noticing note's v2, part A, plus the coordinator's addition the
|
|
3061
|
+
same day: count what a session SENT as well as what it read).
|
|
3062
|
+
|
|
3063
|
+
- **The side list.** `parseTranscript` now keeps every tool call the assistant made (`toolCalls`: id, name, one input
|
|
3064
|
+
field: Bash's command, Read's path, Agent's subagent type), beside `expansions`, because tool blocks never enter the
|
|
3065
|
+
turn list. A sidechain's calls and a host-synthesised line's are left out. It rides `HookInput.toolCalls`, not
|
|
3066
|
+
`SessionInput`: codex and core never see it.
|
|
3067
|
+
- **The watermark is a tool_use id**, kept in one meta row per session (`adapter.noticing.<session>`) with the last
|
|
3068
|
+
nudge's time, a `pending` flag and the four counters. The turn cursor could not serve (`claim()` moves it before the
|
|
3069
|
+
ask). A stored id the file no longer holds moves to the end quietly. The row is written only when a Stop scanned
|
|
3070
|
+
calls; a session's first row deletes rows untouched for `NOTICING_ROW_DAYS` (30).
|
|
3071
|
+
- **Counting.** `would` counts every scanned Stop with unwritten perception, the re-fire included (it scans and never
|
|
3072
|
+
speaks); `nudged` counts lines sent. No cap was built: the design's "before any cap" had no cap to name, and the
|
|
3073
|
+
calibration below gave no reason for one. `taken` is a `remember` among the calls the next Stop scans after a nudge,
|
|
3074
|
+
which is the re-fire when the host sends one. `quiet` is perception a `remember` already followed. `session_end`
|
|
3075
|
+
does not count as the answer (it answers the full ask); `remember`'s old name `note` does, on a counterparts server.
|
|
3076
|
+
- **Beyond the design's list, deliberately:** `Read` of a `.pdf`/`.epub` is a document (the same act as `pdftotext`),
|
|
3077
|
+
and the host's `web-fetch` subagent is a page (it stands in for `WebFetch` where that tool is absent). Sends: MCP
|
|
3078
|
+
`…send_message` (case-sensitive, so the host's own `SendMessage` agent tool is not a letter) and the owner's
|
|
3079
|
+
`noticing.bashOutgoing` patterns (counted as posts). `noticing.bashPatterns` reads count as pages.
|
|
3080
|
+
- **Two openers now.** `NOTICE_OPENER` ("Counterparts, since you last wrote:") joins `STOP_ASK_OPENER` in `OWN_ASK`, so
|
|
3081
|
+
the line is `ritual` wherever the host writes it back. Alone, its person's line is `NOTICE_HUMAN_LINE`; beside the
|
|
3082
|
+
full ask it is appended to the ask's block and the ask's person's line stands.
|
|
3083
|
+
- **Mechanisms** prints one line under the settled-things line, summing rows changed in the console's seven days
|
|
3084
|
+
(`noticingTotals`); `--json` carries the totals as `noticing`.
|
|
3085
|
+
|
|
3086
|
+
**Calibration** (`tools/noticing-replay.ts`, 2026-11-26; counts only, read-only over the host's project files; a
|
|
3087
|
+
Stop is each `stop_hook_summary` line the host wrote; active hours cap each gap at 10 minutes; every session counted,
|
|
3088
|
+
attended or not, so this is an upper bound):
|
|
3089
|
+
|
|
3090
|
+
| Session | Stops | would | quiet | unwritten at the nudges |
|
|
3091
|
+
|---|---|---|---|---|
|
|
3092
|
+
| c830b02c (a book read through `pdftotext`) | 7 | 2 | 0 | 5 documents |
|
|
3093
|
+
| 11fe0128 (letters read through a phone's MCP tools) | 6 | 1 | 2 | 2 letters |
|
|
3094
|
+
| c4d85e36 (a social feed), no patterns | 20 | 1 | 2 | 1 letter |
|
|
3095
|
+
| c4d85e36, with the post script's read and post/reply subcommands as `bashPatterns`/`bashOutgoing` | 20 | 2 | 2 | 4 posts, 1 page, 1 letter |
|
|
3096
|
+
|
|
3097
|
+
Coding sessions over the last 7 days, three folders (this repo, the site, one other app): 13 sessions, 48.1 active
|
|
3098
|
+
hours, 5 `would`, **0.10 per active hour** (0.06, 0.40 and 0.11 by folder), all pages and documents. Under the ~1/hour
|
|
3099
|
+
bar, so it ships on (`TUNABLES.NOTICING_ON`). For scale: those folders' agent worktrees, 44 sessions, 83.3 hours,
|
|
3100
|
+
0.23/hour; two personal folders, 0.20 and 1.31/hour, which is where it is meant to fire.
|
|
3101
|
+
|
|
3102
|
+
Two effects the replay does not measure. A session with no row yet (one running across the upgrade, a resume or a
|
|
3103
|
+
fork under a new id) scans its whole file at its first Stop and may nudge once for an old reading. And a nudge beside
|
|
3104
|
+
the full ask is answered with `session_end`, which `taken` does not count, so `taken` reads low on those Stops. A
|
|
3105
|
+
nudge answered in words alone (the continuation calls nothing) clears `pending` at the re-fire, so a later turn's
|
|
3106
|
+
`remember` is not read as taking it.
|
|
3107
|
+
|
|
3108
|
+
Named gaps, for later and only when earned by a real miss: a killed session (no Stop), auto-compact mid-read, a
|
|
3109
|
+
subagent's reads (sidechains), pages read as images, long autonomous runs. The social feed's reads were plain
|
|
3110
|
+
`python3` in the miss itself; only a configured pattern catches those.
|
|
@@ -458,6 +458,9 @@ export function toHookInput(
|
|
|
458
458
|
scope,
|
|
459
459
|
turns: transcript.turns,
|
|
460
460
|
expansions: transcript.expansions,
|
|
461
|
+
// Every tool call, for noticing at a Stop (`noticing.ts`): names, ids and
|
|
462
|
+
// one input field, never a result.
|
|
463
|
+
toolCalls: transcript.toolCalls,
|
|
461
464
|
// A named transcript that would not read is not an empty conversation.
|
|
462
465
|
...(transcriptPath !== undefined && !transcript.ok ? { turnsUnread: true } : {}),
|
|
463
466
|
// THE PATH ITSELF, beside the parse of it. The delivery check reads the head
|
|
@@ -109,7 +109,7 @@ import { loadConfig, retentionClocks, withBudgetDefault, withEmbedderDefault } f
|
|
|
109
109
|
import type { AdapterConfig } from "../../config.js";
|
|
110
110
|
import { openEmbedder } from "../index.js";
|
|
111
111
|
import type { LiveEmbedder } from "../embed-client.js";
|
|
112
|
-
import { DATA_DIR_ENV, SCOPE_ENV, SESSION_ENV, WATCHDOG_ENV } from "../../spawn.js";
|
|
112
|
+
import { DATA_DIR_ENV, SCOPE_ENV, SESSION_ENV, STORE_CLOCK_OFFSET_ENV, WATCHDOG_ENV } from "../../spawn.js";
|
|
113
113
|
import { backfillVectors, laggedSemantic } from "../vectors.js";
|
|
114
114
|
import type { BackfillReport, LagReport } from "../vectors.js";
|
|
115
115
|
import { removeSidebarStatus, sidebarInstalled, writeSidebarStatus } from "../../sidebar-status.js";
|
|
@@ -407,6 +407,9 @@ export async function runOnce(input: {
|
|
|
407
407
|
/** The wall clock the hold sweep reads (HD1). Absent: the store's. Injected
|
|
408
408
|
* so a test can step past the 24-hour window without waiting a day. */
|
|
409
409
|
now?: () => number;
|
|
410
|
+
/** The store's clock (`storeClockOf`, hosted's `storeClock` across the spawn).
|
|
411
|
+
* Absent: the system clock, as before. */
|
|
412
|
+
storeNow?: () => number;
|
|
410
413
|
onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
|
|
411
414
|
}): Promise<RunReport> {
|
|
412
415
|
const { config } = input;
|
|
@@ -437,6 +440,7 @@ export async function runOnce(input: {
|
|
|
437
440
|
? {}
|
|
438
441
|
: { budgetBytes: config.injectionBudgetBytes }),
|
|
439
442
|
...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
|
|
443
|
+
...(input.storeNow === undefined ? {} : { now: input.storeNow }),
|
|
440
444
|
// The build stamps the wake it publishes, and a wake another build
|
|
441
445
|
// published is re-rendered at step 3a (`version`, 2026-10-02).
|
|
442
446
|
build: input.build === undefined ? installedVersion() : input.build,
|
|
@@ -793,6 +797,19 @@ export function pinnedSession(env: Record<string, string | undefined> = process.
|
|
|
793
797
|
return raw !== undefined && raw.trim().length > 0 ? raw : null;
|
|
794
798
|
}
|
|
795
799
|
|
|
800
|
+
/**
|
|
801
|
+
* The store's clock, when the spawner that owns one set it
|
|
802
|
+
* (`spawn.ts#STORE_CLOCK_OFFSET_ENV`, hosted's `storeClock`): the system clock
|
|
803
|
+
* plus that offset. Null otherwise, or when the number is not a whole one.
|
|
804
|
+
*/
|
|
805
|
+
export function storeClockOf(env: Record<string, string | undefined> = process.env): (() => number) | null {
|
|
806
|
+
const raw = env[STORE_CLOCK_OFFSET_ENV];
|
|
807
|
+
if (raw === undefined || raw.trim().length === 0) return null;
|
|
808
|
+
const offset = Number(raw);
|
|
809
|
+
if (!Number.isSafeInteger(offset)) return null;
|
|
810
|
+
return () => Date.now() + offset;
|
|
811
|
+
}
|
|
812
|
+
|
|
796
813
|
export function pinnedScope(env: Record<string, string | undefined> = process.env): string | null {
|
|
797
814
|
const raw = env[SCOPE_ENV];
|
|
798
815
|
return raw !== undefined && raw.trim().length > 0 ? raw : null;
|
|
@@ -889,6 +906,7 @@ async function main(): Promise<void> {
|
|
|
889
906
|
log.start();
|
|
890
907
|
const sidebarWanted = sidebarInstalled(process.env, homedir(), choice.path);
|
|
891
908
|
if (!sidebarWanted && removeSidebarStatus(choice.path)) log.event({ name: "runner.sidebar", data: { removed: true } });
|
|
909
|
+
const storeClock = storeClockOf();
|
|
892
910
|
try {
|
|
893
911
|
const report = await runOnce({
|
|
894
912
|
config,
|
|
@@ -896,6 +914,8 @@ async function main(): Promise<void> {
|
|
|
896
914
|
signal: controller.signal,
|
|
897
915
|
...(pinnedSession() === null ? {} : { session: pinnedSession() as string }),
|
|
898
916
|
...(pinnedScope() === null ? {} : { scope: pinnedScope() as string }),
|
|
917
|
+
// The store's clock, from the spawner that owns one (hosted's `storeClock`).
|
|
918
|
+
...(storeClock === null ? {} : { storeNow: storeClock }),
|
|
899
919
|
// Only where the sidebar is installed (the plugin); otherwise an old file goes.
|
|
900
920
|
...(sidebarWanted ? { sidebarConfigPath: choice.path } : {}),
|
|
901
921
|
// The update check: never in the directory flavor, which reads nothing
|
|
@@ -20,6 +20,8 @@ import type { DreamOffer } from "../../core/dream/index.js";
|
|
|
20
20
|
import { TUNABLES } from "../config.js";
|
|
21
21
|
import { STOP_HUMAN_LINE, plainLine, withoutDream, withoutDreamNote, withoutPlain } from "./hooks.js";
|
|
22
22
|
import type { DreamTold, HookInput, HookName } from "./hooks.js";
|
|
23
|
+
import { NOTICE_HUMAN_LINE } from "./noticing.js";
|
|
24
|
+
import { NOTICE_OPENER } from "./transcript.js";
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* The host's own spelling of the event that carries a notice at a session's
|
|
@@ -424,7 +426,9 @@ export function hostDelivery(
|
|
|
424
426
|
// ask is ~430 characters, far inside the host's 10,000-character cap.
|
|
425
427
|
return {
|
|
426
428
|
stdout: JSON.stringify({
|
|
427
|
-
|
|
429
|
+
// The noticing line alone (`noticing.ts`) has its own person's line: the
|
|
430
|
+
// ask's says a write-up is being asked for, which this is not.
|
|
431
|
+
systemMessage: ask.startsWith(NOTICE_OPENER) ? NOTICE_HUMAN_LINE : STOP_HUMAN_LINE,
|
|
428
432
|
hookSpecificOutput: { hookEventName: HOST_STOP, additionalContext: ask },
|
|
429
433
|
}),
|
|
430
434
|
stderr: "",
|
|
@@ -91,7 +91,9 @@ import type { NightKind } from "./night-run.js";
|
|
|
91
91
|
import { spawnDetached } from "../spawn.js";
|
|
92
92
|
import { ONE_TAG_LINE, tagLead } from "../store-id.js";
|
|
93
93
|
import type { SpawnOutcome } from "../spawn.js";
|
|
94
|
-
import { NO_ARRIVAL, STOP_ASK_OPENER, readWakeArrival, startedByHost } from "./transcript.js";
|
|
94
|
+
import { NOTICE_OPENER, NO_ARRIVAL, STOP_ASK_OPENER, readWakeArrival, startedByHost } from "./transcript.js";
|
|
95
|
+
import type { ToolCall } from "./transcript.js";
|
|
96
|
+
import { NOTICING_META_PREFIX, noticeLine, noticingKey, noticingSettings, readNoticingState, scanAtStop } from "./noticing.js";
|
|
95
97
|
import type { WakeArrival } from "./transcript.js";
|
|
96
98
|
|
|
97
99
|
/**
|
|
@@ -160,6 +162,13 @@ export interface HookInput extends SessionInput {
|
|
|
160
162
|
* file read for the one thing that parse deliberately skips.
|
|
161
163
|
*/
|
|
162
164
|
readonly transcriptPath?: string;
|
|
165
|
+
/**
|
|
166
|
+
* EVERY TOOL CALL IN THE TRANSCRIPT, in file order (`transcript.ts#ToolCall`):
|
|
167
|
+
* what noticing reads at a Stop (`noticing.ts`). Names, ids and one input
|
|
168
|
+
* field; never a result. Absent: not read (a test, an embedder), and
|
|
169
|
+
* noticing says nothing.
|
|
170
|
+
*/
|
|
171
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
163
172
|
/**
|
|
164
173
|
* THE HOST'S RE-FIRE. A blocked Stop comes back with `stop_hook_active`, and
|
|
165
174
|
* that pass must ask nothing — v1's anti-loop, kept for the same reason. It is
|
|
@@ -546,6 +555,10 @@ export const RATE_CLAUSE = "`rated` 0–3 each footnote shown since you last wro
|
|
|
546
555
|
/**
|
|
547
556
|
* WHAT OPEN MEANS, IN THE ASK (2026-10-22, the open-threads brief): the same
|
|
548
557
|
* narrowing as the `unresolved` field's own text (`mcp/tools.ts#UNRESOLVED_PROPERTY`).
|
|
558
|
+
* Narrowed again 2026-11-13 (trim PR 2, the wording half of #819's raise
|
|
559
|
+
* schedule): open means something is BLOCKED — a decision the counterpart
|
|
560
|
+
* needs from them, a promise, a dated check — not curiosity about how
|
|
561
|
+
* something went. "never curiosity" is said on the field, which has the room.
|
|
549
562
|
*
|
|
550
563
|
* AND WHAT WOULD CLOSE IT (2026-10-27, F1 after S1): the Stop ask is the door
|
|
551
564
|
* most open items come through, so it invites `settlesWhen` beside them — "if
|
|
@@ -553,7 +566,7 @@ export const RATE_CLAUSE = "`rated` 0–3 each footnote shown since you last wro
|
|
|
553
566
|
* Without it the nightly reflection is shown few items it could close.
|
|
554
567
|
*/
|
|
555
568
|
export const OPEN_MEANS =
|
|
556
|
-
"`unresolved` only when
|
|
569
|
+
"`unresolved` only when something is blocked (a decision you need from them, a promise, a dated check), plus `settlesWhen` if you can name what closes it";
|
|
557
570
|
|
|
558
571
|
/** How long one open item's title may run in the ask's last line (2026-10-22). */
|
|
559
572
|
const OPEN_TITLE_CHARS = 60;
|
|
@@ -1689,7 +1702,12 @@ export class ClaudeCodeAdapter extends Lifecycle {
|
|
|
1689
1702
|
// the code did not keep: one evening's Stops billed 13 chunks and minted
|
|
1690
1703
|
// 61 memories beside 34 the model had authored itself.
|
|
1691
1704
|
// The headless nightly run is asked nothing (`HookInput.nightRun`).
|
|
1692
|
-
const
|
|
1705
|
+
const asked = input.nightRun !== true ? this.askAtStop(input) : null;
|
|
1706
|
+
// NOTICING (2026-11-26, `noticing.ts`): its own line, its own state,
|
|
1707
|
+
// never the pacer. Due beside the ask, it rides in the ask's block: one
|
|
1708
|
+
// output, never two.
|
|
1709
|
+
const noticed = this.noticeAtStop(input);
|
|
1710
|
+
const ask = noticed === null ? asked : asked === null ? noticed : `${asked}\n${noticed}`;
|
|
1693
1711
|
const spawn = this.spawnWorker(input);
|
|
1694
1712
|
return { ...claimed, ask, spawn };
|
|
1695
1713
|
});
|
|
@@ -1788,6 +1806,62 @@ export class ClaudeCodeAdapter extends Lifecycle {
|
|
|
1788
1806
|
return chapter === null ? null : stopAsk(input.sessionId, chapter, this.openHere(input.sessionId));
|
|
1789
1807
|
}
|
|
1790
1808
|
|
|
1809
|
+
/**
|
|
1810
|
+
* NOTICING AT A STOP (2026-11-26, `noticing.ts`): scan the tool calls since
|
|
1811
|
+
* this session's watermark, move the watermark and the counters in the
|
|
1812
|
+
* session's one meta row, and return the counts-only line, or null.
|
|
1813
|
+
*
|
|
1814
|
+
* Silent for a session nobody attends (`isInteractive`), the night's child,
|
|
1815
|
+
* an observer (the guard already stood it down), the switch off, and a
|
|
1816
|
+
* transcript that did not read. The re-fire scans and records `taken`, and
|
|
1817
|
+
* never speaks (`scanAtStop`). It never consults or moves the ask's pacer,
|
|
1818
|
+
* and it never fails the Stop: any error is a silent Stop.
|
|
1819
|
+
*/
|
|
1820
|
+
private noticeAtStop(input: HookInput): string | null {
|
|
1821
|
+
try {
|
|
1822
|
+
if (input.nightRun === true || this.observer || input.sessionId.length === 0) return null;
|
|
1823
|
+
if (!isInteractive(input) || input.turnsUnread === true || input.toolCalls === undefined) return null;
|
|
1824
|
+
const settings = noticingSettings(this.config);
|
|
1825
|
+
if (!settings.on) return null;
|
|
1826
|
+
const calls = input.toolCalls;
|
|
1827
|
+
const store = this.counterpart.store;
|
|
1828
|
+
const now = this.nowFn();
|
|
1829
|
+
let done: ReturnType<typeof scanAtStop> | null = null;
|
|
1830
|
+
let fresh = false;
|
|
1831
|
+
store.updateMeta(noticingKey(input.sessionId), (raw) => {
|
|
1832
|
+
fresh = raw === undefined;
|
|
1833
|
+
const scan = scanAtStop(calls, readNoticingState(raw), settings, { reFired: input.reFired === true, now });
|
|
1834
|
+
done = scan;
|
|
1835
|
+
return scan.next === null ? undefined : JSON.stringify(scan.next);
|
|
1836
|
+
});
|
|
1837
|
+
const scan = done as ReturnType<typeof scanAtStop> | null;
|
|
1838
|
+
if (scan === null) return null;
|
|
1839
|
+
if (scan.outcome !== "none") {
|
|
1840
|
+
const said = scan.say === null ? 0 : Object.values(scan.say).reduce((n, v) => n + (v ?? 0), 0);
|
|
1841
|
+
this.emit("adapter.noticing", { outcome: scan.outcome, reFired: input.reFired === true, said });
|
|
1842
|
+
}
|
|
1843
|
+
// A session's first row lets go of rows nobody has touched in a month.
|
|
1844
|
+
if (fresh && scan.next !== null) this.pruneNoticing(now);
|
|
1845
|
+
return scan.say === null ? null : noticeLine(NOTICE_OPENER, scan.say);
|
|
1846
|
+
} catch (err) {
|
|
1847
|
+
this.emit("adapter.noticing.failed", { code: codeOf(err) });
|
|
1848
|
+
return null;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/** Rows untouched for `TUNABLES.NOTICING_ROW_DAYS`, deleted. Never throws. */
|
|
1853
|
+
private pruneNoticing(now: number): void {
|
|
1854
|
+
try {
|
|
1855
|
+
const store = this.counterpart.store;
|
|
1856
|
+
const before = now - TUNABLES.NOTICING_ROW_DAYS * 86_400_000;
|
|
1857
|
+
for (const [key, raw] of store.metaWithPrefix(NOTICING_META_PREFIX)) {
|
|
1858
|
+
if (readNoticingState(raw).at < before) store.updateMeta(key, () => null);
|
|
1859
|
+
}
|
|
1860
|
+
} catch {
|
|
1861
|
+
/* a row left over is a few bytes */
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1791
1865
|
/**
|
|
1792
1866
|
* This session's own open items, for the ask's last line (2026-10-22,
|
|
1793
1867
|
* `openHereLine`): what the store says it wrote or touched, the flag
|
|
@@ -105,7 +105,7 @@ import { TOOL_RESULT_CEILING } from "../../core/fit/index.js";
|
|
|
105
105
|
import { installedVersion } from "../sessions.js";
|
|
106
106
|
import { OBSERVER_ENV } from "../stance-env.js";
|
|
107
107
|
|
|
108
|
-
import { NIGHT_DEBUG_DIR, NIGHT_TRANSCRIPT_NAME, TUNABLES, nightDebugDir } from "../config.js";
|
|
108
|
+
import { NIGHT_DEBUG_DIR, NIGHT_TRANSCRIPT_NAME, TUNABLES, nightDebugDir, shareOptions } from "../config.js";
|
|
109
109
|
import type { AdapterConfig } from "../config.js";
|
|
110
110
|
import { awakeMeter } from "./awake.js";
|
|
111
111
|
import type { AwakeMeter } from "./awake.js";
|
|
@@ -1659,6 +1659,7 @@ export function openNightCounterpart(config: AdapterConfig, onEvent?: (e: Counte
|
|
|
1659
1659
|
...(config.injectionBudgetBytes === undefined ? {} : { budgetBytes: config.injectionBudgetBytes }),
|
|
1660
1660
|
...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
|
|
1661
1661
|
...(config.pageWriter?.mode === undefined ? {} : { pageWriterMode: config.pageWriter.mode }),
|
|
1662
|
+
...shareOptions(config),
|
|
1662
1663
|
...(config.identity === undefined ? {} : { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
|
|
1663
1664
|
build: installedVersion(),
|
|
1664
1665
|
// The headless night runs on the person's computer (EX1).
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTICING v1 (2026-11-26; design: the noticing-and-wake note, "v2 — after the
|
|
3
|
+
* Fable review", part A). An experiment, lightly held.
|
|
4
|
+
*
|
|
5
|
+
* **What it is for.** Three readings were lost in one week: a book read page by
|
|
6
|
+
* page through `pdftotext`, a run of letters read through a phone's MCP tools,
|
|
7
|
+
* and a social feed read and answered through a script. Each time the session
|
|
8
|
+
* read (or sent) something that mattered and never called `remember`, and the
|
|
9
|
+
* Stop ask, paced on what the PERSON typed, did not come round in time. What a
|
|
10
|
+
* session did toward someone, a letter sent or a post answered, is lost the
|
|
11
|
+
* same way.
|
|
12
|
+
*
|
|
13
|
+
* **What it does.** At an attended Stop in this adapter, if perception calls
|
|
14
|
+
* (reads, and sends) happened since this session's watermark and no `remember`
|
|
15
|
+
* call came after them, ONE line is added, counts only, pointing at
|
|
16
|
+
* `remember`. Per turn, not per session: reading a book together nudges each
|
|
17
|
+
* sitting. Core, the night and codex are untouched (constitution 5): this
|
|
18
|
+
* module and its call in `hooks.ts#stop` are the whole mechanism.
|
|
19
|
+
*
|
|
20
|
+
* **What counts** (`classifyCall`), by kind:
|
|
21
|
+
* - letters read: MCP tools named `…read_inbox`, `…read_thread`,
|
|
22
|
+
* `…read_message`, `…open_message` (by name SUFFIX, as `RECALL_TOOL_NAME`,
|
|
23
|
+
* because the server prefix is the host's);
|
|
24
|
+
* - pages: `WebFetch`, any tool named `…web_fetch`/`…webfetch`, and the
|
|
25
|
+
* host's `web-fetch` subagent;
|
|
26
|
+
* - documents: `Bash` whose command matches `pdftotext`, `.pdf` or `.epub`,
|
|
27
|
+
* and `Read` of a `.pdf` or `.epub`; nothing under `tool-results/` (the
|
|
28
|
+
* host's own spill files);
|
|
29
|
+
* - letters sent: MCP tools named `…send_message` (case-sensitive: the
|
|
30
|
+
* host's own agent tool `SendMessage` is not a letter);
|
|
31
|
+
* - the owner's own Bash patterns (`noticing.bashPatterns`, reads, counted as
|
|
32
|
+
* pages; `noticing.bashOutgoing`, sends, counted as posts). No defaults for
|
|
33
|
+
* any one service beyond the generic letter suffixes.
|
|
34
|
+
* - `remember` (and its old name `note` on a counterparts server) is the
|
|
35
|
+
* write that answers them. `session_end` is not: it answers the full ask.
|
|
36
|
+
*
|
|
37
|
+
* **What it says** (`noticeLine`): numbers and kind words only, built from a
|
|
38
|
+
* record of counts. Nothing from a tool's input or output can reach the line,
|
|
39
|
+
* by construction: an injection in a file name has no path into context.
|
|
40
|
+
*
|
|
41
|
+
* **State** (`NoticingState`): one store meta row per session,
|
|
42
|
+
* `adapter.noticing.<session>`: the watermark (the last tool_use id scanned),
|
|
43
|
+
* the last nudge's time, whether a nudge awaits its answer, and the counters.
|
|
44
|
+
* The turn cursor cannot serve: `claim()` advances it before the ask.
|
|
45
|
+
*
|
|
46
|
+
* **Counters** (constitution 11/16), summed by `counterparts mechanisms`:
|
|
47
|
+
* - `would`: a scanned Stop found unwritten perception (re-fire included);
|
|
48
|
+
* - `nudged`: the line went out;
|
|
49
|
+
* - `taken`: a `remember` came in the continuation after a nudge;
|
|
50
|
+
* - `quiet`: perception, and a `remember` already followed it.
|
|
51
|
+
*/
|
|
52
|
+
import type { AdapterConfig } from "../config.js";
|
|
53
|
+
import { TUNABLES } from "../config.js";
|
|
54
|
+
import type { ToolCall } from "./transcript.js";
|
|
55
|
+
|
|
56
|
+
/** What a call was, for the line. */
|
|
57
|
+
export type NoticeKind = "letter" | "page" | "document" | "sentLetter" | "post";
|
|
58
|
+
export type CallKind = NoticeKind | "remember";
|
|
59
|
+
|
|
60
|
+
const READS: readonly NoticeKind[] = ["letter", "page", "document"];
|
|
61
|
+
const SENDS: readonly NoticeKind[] = ["sentLetter", "post"];
|
|
62
|
+
|
|
63
|
+
/** The compiled settings: the switch, and the owner's extra Bash patterns. */
|
|
64
|
+
export interface NoticingSettings {
|
|
65
|
+
readonly on: boolean;
|
|
66
|
+
readonly bashPatterns: readonly RegExp[];
|
|
67
|
+
readonly bashOutgoing: readonly RegExp[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const LETTER_READ = /(^|__)(read_inbox|read_thread|read_message|open_message)$/;
|
|
71
|
+
const LETTER_SENT = /(^|__)send_message$/;
|
|
72
|
+
const WEB_FETCH = /^WebFetch$|(^|__)web_?fetch$/i;
|
|
73
|
+
const REMEMBER = /(^|__)remember$/;
|
|
74
|
+
/** The old name still answers on our own server (`mcp/tools.ts#TOOL_ALIASES`). */
|
|
75
|
+
const REMEMBER_OLD = /counterparts[^_]*__note$/;
|
|
76
|
+
const DOCUMENT = /\bpdftotext\b|\.pdf\b|\.epub\b/i;
|
|
77
|
+
const DOCUMENT_PATH = /\.(pdf|epub)$/i;
|
|
78
|
+
/** The host's own spill files: a large result saved for the model, not a document. */
|
|
79
|
+
const TOOL_RESULTS = /tool-results\//;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* ONE CALL'S KIND, or null for a call that is neither perception nor a
|
|
83
|
+
* `remember`. Pure: the tool's name and one input field (`ToolCall.arg`).
|
|
84
|
+
*/
|
|
85
|
+
export function classifyCall(call: Pick<ToolCall, "name" | "arg">, settings: Pick<NoticingSettings, "bashPatterns" | "bashOutgoing">): CallKind | null {
|
|
86
|
+
const { name, arg } = call;
|
|
87
|
+
if (REMEMBER.test(name) || REMEMBER_OLD.test(name)) return "remember";
|
|
88
|
+
if (LETTER_READ.test(name)) return "letter";
|
|
89
|
+
if (LETTER_SENT.test(name)) return "sentLetter";
|
|
90
|
+
if (WEB_FETCH.test(name)) return "page";
|
|
91
|
+
if ((name === "Agent" || name === "Task") && arg === "web-fetch") return "page";
|
|
92
|
+
if (name === "Read" && arg !== undefined && DOCUMENT_PATH.test(arg) && !TOOL_RESULTS.test(arg)) return "document";
|
|
93
|
+
if (name === "Bash" && arg !== undefined && !TOOL_RESULTS.test(arg)) {
|
|
94
|
+
if (settings.bashOutgoing.some((p) => p.test(arg))) return "post";
|
|
95
|
+
if (settings.bashPatterns.some((p) => p.test(arg))) return "page";
|
|
96
|
+
if (DOCUMENT.test(arg)) return "document";
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Counts by kind; zero kinds are absent. */
|
|
102
|
+
export type NoticeCounts = Partial<Record<NoticeKind, number>>;
|
|
103
|
+
|
|
104
|
+
/** One session's row. Numbers and one tool_use id; never text. */
|
|
105
|
+
export interface NoticingState {
|
|
106
|
+
/** The last tool_use id scanned; absent before the first scan. */
|
|
107
|
+
readonly mark?: string;
|
|
108
|
+
/** When the last line went out (epoch ms). */
|
|
109
|
+
readonly nudgedAt?: number;
|
|
110
|
+
/** A line went out and its continuation has not been scanned yet. */
|
|
111
|
+
readonly pending?: boolean;
|
|
112
|
+
readonly would: number;
|
|
113
|
+
readonly nudged: number;
|
|
114
|
+
readonly taken: number;
|
|
115
|
+
readonly quiet: number;
|
|
116
|
+
/** When this row last changed (epoch ms): the window `mechanisms` reads. */
|
|
117
|
+
readonly at: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const EMPTY_STATE: NoticingState = { would: 0, nudged: 0, taken: 0, quiet: 0, at: 0 };
|
|
121
|
+
|
|
122
|
+
export interface StopScan {
|
|
123
|
+
/** The row to write, or null when nothing changed (no write). */
|
|
124
|
+
readonly next: NoticingState | null;
|
|
125
|
+
/** The counts to say, or null: no line at this Stop. */
|
|
126
|
+
readonly say: NoticeCounts | null;
|
|
127
|
+
/** What the scan found, for the ring: never text. */
|
|
128
|
+
readonly outcome: "none" | "lost-mark" | "quiet" | "would" | "nudged";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* THE STOP'S DECISION. `calls` is the whole transcript's call list (file
|
|
133
|
+
* order), `state` the session's row. The re-fire (`reFired`) scans, advances
|
|
134
|
+
* the watermark and records `taken`, and never says anything.
|
|
135
|
+
*
|
|
136
|
+
* A stored watermark the file no longer holds (a rewritten or foreign file) is
|
|
137
|
+
* not a reason to speak: the scan moves the mark to the end and says nothing.
|
|
138
|
+
*/
|
|
139
|
+
export function scanAtStop(
|
|
140
|
+
calls: readonly Pick<ToolCall, "id" | "name" | "arg">[],
|
|
141
|
+
state: NoticingState,
|
|
142
|
+
settings: Pick<NoticingSettings, "bashPatterns" | "bashOutgoing">,
|
|
143
|
+
opts: { readonly reFired: boolean; readonly now: number },
|
|
144
|
+
): StopScan {
|
|
145
|
+
const last = calls.length === 0 ? undefined : calls[calls.length - 1]?.id;
|
|
146
|
+
let start = 0;
|
|
147
|
+
if (state.mark !== undefined) {
|
|
148
|
+
const at = calls.findIndex((c) => c.id === state.mark);
|
|
149
|
+
if (at === -1) {
|
|
150
|
+
if (last === undefined || last === state.mark) return { next: null, say: null, outcome: "none" };
|
|
151
|
+
return { next: { ...state, mark: last, pending: false, at: opts.now }, say: null, outcome: "lost-mark" };
|
|
152
|
+
}
|
|
153
|
+
start = at + 1;
|
|
154
|
+
}
|
|
155
|
+
const fresh = calls.slice(start).map((c) => classifyCall(c, settings));
|
|
156
|
+
if (fresh.length === 0) {
|
|
157
|
+
// A nudge answered in words alone (no call at all): not taken, and the
|
|
158
|
+
// flag goes, or a later turn's `remember` would read as this nudge's.
|
|
159
|
+
if (state.pending === true) {
|
|
160
|
+
const { pending: _answered, ...rest } = state;
|
|
161
|
+
return { next: { ...rest, at: opts.now }, say: null, outcome: "none" };
|
|
162
|
+
}
|
|
163
|
+
return { next: null, say: null, outcome: "none" };
|
|
164
|
+
}
|
|
165
|
+
let { would, nudged, taken, quiet } = state;
|
|
166
|
+
let pending = state.pending === true;
|
|
167
|
+
let nudgedAt = state.nudgedAt;
|
|
168
|
+
const wrote = fresh.lastIndexOf("remember");
|
|
169
|
+
// The nudge's continuation: a `remember` anywhere in it is the line taken.
|
|
170
|
+
if (pending) {
|
|
171
|
+
if (wrote !== -1) taken += 1;
|
|
172
|
+
pending = false;
|
|
173
|
+
}
|
|
174
|
+
const seen = fresh.some((k) => k !== null && k !== "remember");
|
|
175
|
+
const unwritten = fresh.slice(wrote + 1).filter((k): k is NoticeKind => k !== null && k !== "remember");
|
|
176
|
+
let say: NoticeCounts | null = null;
|
|
177
|
+
let outcome: StopScan["outcome"] = "none";
|
|
178
|
+
if (unwritten.length > 0) {
|
|
179
|
+
would += 1;
|
|
180
|
+
outcome = "would";
|
|
181
|
+
if (!opts.reFired) {
|
|
182
|
+
const counts: NoticeCounts = {};
|
|
183
|
+
for (const k of unwritten) counts[k] = (counts[k] ?? 0) + 1;
|
|
184
|
+
say = counts;
|
|
185
|
+
nudged += 1;
|
|
186
|
+
pending = true;
|
|
187
|
+
nudgedAt = opts.now;
|
|
188
|
+
outcome = "nudged";
|
|
189
|
+
}
|
|
190
|
+
} else if (seen) {
|
|
191
|
+
quiet += 1;
|
|
192
|
+
outcome = "quiet";
|
|
193
|
+
}
|
|
194
|
+
const next: NoticingState = {
|
|
195
|
+
...(last === undefined ? {} : { mark: last }),
|
|
196
|
+
...(nudgedAt === undefined ? {} : { nudgedAt }),
|
|
197
|
+
...(pending ? { pending: true } : {}),
|
|
198
|
+
would,
|
|
199
|
+
nudged,
|
|
200
|
+
taken,
|
|
201
|
+
quiet,
|
|
202
|
+
at: opts.now,
|
|
203
|
+
};
|
|
204
|
+
return { next, say, outcome };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function plural(n: number, one: string, many: string): string {
|
|
208
|
+
return `${String(n)} ${n === 1 ? one : many}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const WORDS: Record<NoticeKind, readonly [string, string]> = {
|
|
212
|
+
letter: ["letter", "letters"],
|
|
213
|
+
page: ["page", "pages"],
|
|
214
|
+
document: ["document", "documents"],
|
|
215
|
+
sentLetter: ["letter", "letters"],
|
|
216
|
+
post: ["post", "posts"],
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
function listed(counts: NoticeCounts, kinds: readonly NoticeKind[]): string[] {
|
|
220
|
+
return kinds.flatMap((k) => {
|
|
221
|
+
const n = counts[k] ?? 0;
|
|
222
|
+
return n > 0 ? [plural(n, WORDS[k][0], WORDS[k][1])] : [];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* THE LINE, from numbers alone. It opens with `NOTICE_OPENER`
|
|
228
|
+
* (`transcript.ts`), the second own-ask opener the reader refuses as `ritual`.
|
|
229
|
+
*/
|
|
230
|
+
export function noticeLine(opener: string, counts: NoticeCounts): string {
|
|
231
|
+
const reads = listed(counts, READS);
|
|
232
|
+
const sends = listed(counts, SENDS);
|
|
233
|
+
const readTotal = READS.reduce((n, k) => n + (counts[k] ?? 0), 0);
|
|
234
|
+
const readPart =
|
|
235
|
+
reads.length === 0 ? "" : reads.length === 1 ? `read ${reads[0] ?? ""}` : `read ${plural(readTotal, "thing", "things")} (${reads.join(", ")})`;
|
|
236
|
+
const sendPart = sends.length === 0 ? "" : `sent ${sends.join(", ")}`;
|
|
237
|
+
const did = [readPart, sendPart].filter((s) => s.length > 0).join(" and ");
|
|
238
|
+
const keep =
|
|
239
|
+
sends.length === 0
|
|
240
|
+
? "Keep what struck you with remember: the lines word for word, who wrote them, and your reaction, one memory each."
|
|
241
|
+
: reads.length === 0
|
|
242
|
+
? "Keep what you did toward whom with remember, one memory each."
|
|
243
|
+
: "Keep what struck you, and what you did toward whom, with remember: the lines word for word, who wrote them, and your reaction, one memory each.";
|
|
244
|
+
return `${opener} you ${did}. ${keep}`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The person's line on a Stop that carries the noticing line alone (`envelope.ts#hostDelivery`). */
|
|
248
|
+
export const NOTICE_HUMAN_LINE = "Counterparts: reminding the assistant to keep what it just read or sent.";
|
|
249
|
+
|
|
250
|
+
// ── the row ─────────────────────────────────────────────────────────────────
|
|
251
|
+
|
|
252
|
+
export const NOTICING_META_PREFIX = "adapter.noticing.";
|
|
253
|
+
|
|
254
|
+
export function noticingKey(sessionId: string): string {
|
|
255
|
+
return `${NOTICING_META_PREFIX}${sessionId}`;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const count = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.floor(v) : 0);
|
|
259
|
+
|
|
260
|
+
/** A row as stored, read leniently: an unreadable one is a fresh start. */
|
|
261
|
+
export function readNoticingState(raw: string | undefined): NoticingState {
|
|
262
|
+
if (raw === undefined) return EMPTY_STATE;
|
|
263
|
+
let v: unknown;
|
|
264
|
+
try {
|
|
265
|
+
v = JSON.parse(raw);
|
|
266
|
+
} catch {
|
|
267
|
+
return EMPTY_STATE;
|
|
268
|
+
}
|
|
269
|
+
if (v === null || typeof v !== "object" || Array.isArray(v)) return EMPTY_STATE;
|
|
270
|
+
const r = v as Record<string, unknown>;
|
|
271
|
+
return {
|
|
272
|
+
...(typeof r["mark"] === "string" ? { mark: r["mark"] } : {}),
|
|
273
|
+
...(typeof r["nudgedAt"] === "number" ? { nudgedAt: r["nudgedAt"] } : {}),
|
|
274
|
+
...(r["pending"] === true ? { pending: true } : {}),
|
|
275
|
+
would: count(r["would"]),
|
|
276
|
+
nudged: count(r["nudged"]),
|
|
277
|
+
taken: count(r["taken"]),
|
|
278
|
+
quiet: count(r["quiet"]),
|
|
279
|
+
at: count(r["at"]),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The four counters, summed over the rows that changed since `sinceMs`. */
|
|
284
|
+
export interface NoticingTotals {
|
|
285
|
+
readonly sessions: number;
|
|
286
|
+
readonly would: number;
|
|
287
|
+
readonly nudged: number;
|
|
288
|
+
readonly taken: number;
|
|
289
|
+
readonly quiet: number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function noticingTotals(store: { metaWithPrefix(prefix: string): Map<string, string> }, sinceMs: number): NoticingTotals {
|
|
293
|
+
let sessions = 0;
|
|
294
|
+
let would = 0;
|
|
295
|
+
let nudged = 0;
|
|
296
|
+
let taken = 0;
|
|
297
|
+
let quiet = 0;
|
|
298
|
+
for (const raw of store.metaWithPrefix(NOTICING_META_PREFIX).values()) {
|
|
299
|
+
const s = readNoticingState(raw);
|
|
300
|
+
if (s.at < sinceMs || s.would + s.nudged + s.taken + s.quiet === 0) continue;
|
|
301
|
+
sessions += 1;
|
|
302
|
+
would += s.would;
|
|
303
|
+
nudged += s.nudged;
|
|
304
|
+
taken += s.taken;
|
|
305
|
+
quiet += s.quiet;
|
|
306
|
+
}
|
|
307
|
+
return { sessions, would, nudged, taken, quiet };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** The console's line (`counterparts mechanisms`). Pure. */
|
|
311
|
+
export function noticingConsoleLine(t: NoticingTotals): string {
|
|
312
|
+
if (t.sessions === 0) return "Noticing at Stops (Claude Code): nothing read or sent this week.";
|
|
313
|
+
return `Noticing at Stops (Claude Code), this week over ${plural(t.sessions, "session", "sessions")}: would ${String(t.would)}, nudged ${String(t.nudged)}, taken ${String(t.taken)}, quiet ${String(t.quiet)}`;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── the settings ────────────────────────────────────────────────────────────
|
|
317
|
+
|
|
318
|
+
/** Compile the owner's patterns; one that will not compile is left out (the config reader names it). */
|
|
319
|
+
export function compilePatterns(sources: readonly string[] | undefined): RegExp[] {
|
|
320
|
+
const out: RegExp[] = [];
|
|
321
|
+
for (const s of sources ?? []) {
|
|
322
|
+
try {
|
|
323
|
+
out.push(new RegExp(s));
|
|
324
|
+
} catch {
|
|
325
|
+
/* named by `config.ts#readNoticing` */
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** The configuration's switch and patterns, compiled (`AdapterConfig.noticing`; absent: `TUNABLES.NOTICING_ON`, no patterns). */
|
|
332
|
+
export function noticingSettings(config: Pick<AdapterConfig, "noticing">): NoticingSettings {
|
|
333
|
+
const n = config.noticing;
|
|
334
|
+
return {
|
|
335
|
+
on: n?.enabled ?? TUNABLES.NOTICING_ON,
|
|
336
|
+
bashPatterns: compilePatterns(n?.bashPatterns),
|
|
337
|
+
bashOutgoing: compilePatterns(n?.bashOutgoing),
|
|
338
|
+
};
|
|
339
|
+
}
|