counterparts 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +326 -0
- package/docs/QUICKSTART.md +5 -0
- package/docs/README.md +2 -2
- package/docs/module-map.md +3 -3
- package/package.json +1 -1
- package/src/adapters/claude-code/CONTRACT.md +36 -10
- package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
- package/src/adapters/claude-code/NOTES.md +182 -0
- package/src/adapters/claude-code/bin/hook.ts +46 -12
- package/src/adapters/claude-code/bin/runner.ts +7 -1
- package/src/adapters/claude-code/doctor.ts +632 -18
- package/src/adapters/claude-code/hooks.ts +61 -16
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/night-run.ts +150 -14
- package/src/adapters/claude-code/transcript.ts +268 -1
- package/src/adapters/cli/CONTRACT.md +5 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
- package/src/adapters/cli/NOTES.md +111 -0
- package/src/adapters/cli/commands.ts +134 -92
- package/src/adapters/cli/dream-core.ts +57 -42
- package/src/adapters/cli/export.ts +320 -21
- package/src/adapters/cli/help.ts +2 -1
- package/src/adapters/cli/index.ts +1 -0
- package/src/adapters/cli/install.ts +39 -7
- package/src/adapters/cli/mechanisms.ts +7 -1
- package/src/adapters/cli/uninstall.ts +13 -5
- package/src/adapters/cli/wire.ts +189 -63
- package/src/adapters/config.ts +2 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
- package/src/adapters/dashboard/NOTES.md +79 -0
- package/src/adapters/dashboard/registries.ts +34 -2
- package/src/adapters/dashboard/web/README.md +19 -14
- package/src/adapters/dashboard/web/actions.ts +23 -1
- package/src/adapters/dashboard/web/flow.ts +14 -0
- package/src/adapters/dashboard/web/lanes.ts +10 -0
- package/src/adapters/dashboard/web/narrate.ts +88 -2
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
- package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
- package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
- package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
- package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
- package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
- package/src/adapters/dashboard/web/server.ts +0 -5
- package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
- package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
- package/src/adapters/dashboard/web/views/health.ts +21 -3
- package/src/adapters/dashboard/web/views/search.ts +4 -45
- package/src/adapters/dashboard/web/views.ts +2 -2
- package/src/adapters/fired.ts +430 -28
- package/src/adapters/host-wiring.ts +300 -0
- package/src/adapters/hosts.ts +11 -0
- package/src/adapters/lifecycle.ts +42 -2
- package/src/adapters/log/index.ts +9 -0
- package/src/adapters/mcp/CONTRACT.md +151 -11
- package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
- package/src/adapters/mcp/NOTES.md +313 -1
- package/src/adapters/mcp/bin/serve.ts +74 -1
- package/src/adapters/mcp/deliberate.ts +169 -651
- package/src/adapters/mcp/facts.ts +1094 -0
- package/src/adapters/mcp/index.ts +25 -7
- package/src/adapters/mcp/meaning.ts +1610 -0
- package/src/adapters/mcp/server.ts +835 -150
- package/src/adapters/mcp/stdio.ts +3 -1
- package/src/adapters/mcp/stood-down.ts +51 -0
- package/src/adapters/mcp/tools.ts +167 -41
- package/src/adapters/plugin-run.sh +133 -0
- package/src/adapters/plugin.ts +329 -0
- package/src/adapters/sessions.ts +18 -4
- package/src/core/associate/CONTRACT.md +2 -1
- package/src/core/associate/INTERFACE-GAPS.md +6 -1
- package/src/core/associate/NOTES.md +45 -0
- package/src/core/briefing.ts +12 -3
- package/src/core/contradictions.ts +184 -0
- package/src/core/counterpart.ts +797 -51
- package/src/core/dream/CONTRACT.md +36 -4
- package/src/core/dream/INTERFACE-GAPS.md +29 -6
- package/src/core/dream/NOTES.md +107 -0
- package/src/core/dream/feeling-weeks.ts +198 -0
- package/src/core/dream/index.ts +109 -18
- package/src/core/dream/reflect.ts +346 -87
- package/src/core/dream/tunables.ts +24 -4
- package/src/core/encode/INTERFACE-GAPS.md +3 -1
- package/src/core/encode/NOTES.md +7 -0
- package/src/core/encode/words.ts +45 -0
- package/src/core/fit/INTERFACE-GAPS.md +8 -2
- package/src/core/fit/NOTES.md +39 -1
- package/src/core/fit/index.ts +40 -0
- package/src/core/handoff/CONTRACT.md +37 -2
- package/src/core/handoff/INTERFACE-GAPS.md +10 -0
- package/src/core/handoff/NOTES.md +72 -0
- package/src/core/handoff/index.ts +214 -12
- package/src/core/handoff/last-here.ts +6 -4
- package/src/core/mint.ts +12 -2
- package/src/core/physics/CONTRACT.md +14 -2
- package/src/core/physics/NOTES.md +33 -1
- package/src/core/physics/index.ts +28 -5
- package/src/core/prospective/CONTRACT.md +45 -6
- package/src/core/prospective/INTERFACE-GAPS.md +4 -0
- package/src/core/prospective/NOTES.md +138 -0
- package/src/core/prospective/derive.ts +33 -5
- package/src/core/prospective/index.ts +90 -5
- package/src/core/prospective/windows.ts +72 -1
- package/src/core/recall/CONTRACT.md +31 -12
- package/src/core/recall/INTERFACE-GAPS.md +28 -4
- package/src/core/recall/NOTES.md +70 -1
- package/src/core/recall/feeling-ask.ts +10 -1
- package/src/core/recall/index.ts +3 -1
- package/src/core/recall/probe.ts +58 -0
- package/src/core/recall/session.ts +46 -2
- package/src/core/recall/time-ask.ts +487 -0
- package/src/core/remember/CONTRACT.md +4 -1
- package/src/core/remember/INTERFACE-GAPS.md +9 -1
- package/src/core/remember/NOTES.md +8 -0
- package/src/core/remember/proposals.ts +47 -5
- package/src/core/revision.ts +18 -1
- package/src/core/schemas/CONTRACT.md +21 -1
- package/src/core/schemas/INTERFACE-GAPS.md +20 -2
- package/src/core/schemas/NOTES.md +144 -0
- package/src/core/schemas/aliases.ts +55 -5
- package/src/core/schemas/index.ts +93 -1
- package/src/core/schemas/types.ts +2 -0
- package/src/core/self/CONTRACT.md +32 -5
- package/src/core/self/INTERFACE-GAPS.md +7 -2
- package/src/core/self/NOTES.md +102 -1
- package/src/core/self/behind.ts +43 -3
- package/src/core/self/briefing.ts +12 -2
- package/src/core/self/chapter-address.ts +254 -0
- package/src/core/self/episodes.ts +27 -0
- package/src/core/self/index.ts +83 -8
- package/src/core/self/page.ts +88 -0
- package/src/core/self/tunables.ts +5 -0
- package/src/core/self/work.ts +35 -2
- package/src/core/self/writer.ts +30 -0
- package/src/core/sleep/INTERFACE-GAPS.md +22 -3
- package/src/core/sleep/NOTES.md +20 -1
- package/src/core/sleep/consolidate.ts +59 -7
- package/src/core/sleep/index.ts +3 -0
- package/src/core/sleep/prune.ts +6 -2
- package/src/core/sleep/types.ts +7 -0
- package/src/core/store/CONTRACT.md +16 -0
- package/src/core/store/NOTES.md +66 -0
- package/src/core/store/feelings.ts +14 -1
- package/src/core/store/index.ts +483 -16
- package/src/core/store/operational.ts +95 -2
- package/src/core/store/owner-op-seam.ts +23 -0
- package/src/core/time.ts +152 -0
- package/tools/install-loop/run.sh +48 -12
- package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
package/src/core/dream/index.ts
CHANGED
|
@@ -44,8 +44,8 @@ import type { Fidelity, FitCandidate, Placed } from "../fit/index.js";
|
|
|
44
44
|
import { emotionalIntensity, sal, strength } from "../physics/index.js";
|
|
45
45
|
import { isHandoff, isSelfPage } from "../recall/index.js";
|
|
46
46
|
import { namesOwner, ownerNames } from "../sleep/index.js";
|
|
47
|
-
import { CARRIED_BY_MAX_CHARS, checkFeelings, checkTraits, defaultStrength, isStoreError, repairEmotion, splitNote } from "../store/index.js";
|
|
48
|
-
import type { DreamChangeRow, DreamRow, FeelingInput, MemoryRow, ProseDoc, Store } from "../store/index.js";
|
|
47
|
+
import { CARRIED_BY_MAX_CHARS, SAID_BY, STATUSES, checkFeelings, checkTraits, defaultStrength, isStoreError, occurredOnOf, repairEmotion, saidByOf, splitNote, statusOf } from "../store/index.js";
|
|
48
|
+
import type { DreamChangeRow, DreamRow, FeelingInput, MemoryRow, MemoryStatus, ProseDoc, SaidBy, Store } from "../store/index.js";
|
|
49
49
|
import { TUNABLES as PHYSICS } from "../physics/index.js";
|
|
50
50
|
import { addDays, isDay } from "../time.js";
|
|
51
51
|
import { livedOn } from "../types.js";
|
|
@@ -55,7 +55,7 @@ import { mindRanked, noteMindShown } from "./mind.js";
|
|
|
55
55
|
import type { MindItem } from "./mind.js";
|
|
56
56
|
import { chapterEntries, entryKey, fitEpisodes, shownEntry } from "./slices.js";
|
|
57
57
|
import type { ChapterEntry, EpisodeInView, EpisodesFit, ShownChapter, ShownEntry } from "./slices.js";
|
|
58
|
-
import { DREAM_ACTIONS, DREAM_TUNABLES } from "./tunables.js";
|
|
58
|
+
import { BUNDLE_OWNER, DREAM_ACTIONS, DREAM_TUNABLES } from "./tunables.js";
|
|
59
59
|
import type { DreamAction } from "./tunables.js";
|
|
60
60
|
import { flag as flagContradiction, pairStanding, settle as settleContradiction, undo as undoContradiction } from "../contradictions.js";
|
|
61
61
|
|
|
@@ -64,6 +64,8 @@ export type { DreamAction } from "./tunables.js";
|
|
|
64
64
|
export { MIND_TUNABLES, mindRanked, onMyMind } from "./mind.js";
|
|
65
65
|
export type { MindItem } from "./mind.js";
|
|
66
66
|
export { CORE_MENTIONED_PREFIX, REFLECT_QUESTIONS, REFLECT_TUNABLES, Reflections, reflectionOpener } from "./reflect.js";
|
|
67
|
+
export { FEELING_WEEKS_TUNABLES, awakeFeelingCounts, feelingWeeks } from "./feeling-weeks.js";
|
|
68
|
+
export type { FeelingWeeks } from "./feeling-weeks.js";
|
|
67
69
|
export type { ReflectBundle, ReflectContext, ReflectFinish, ReflectItem, ReflectOutcome, ReflectRefusal } from "./reflect.js";
|
|
68
70
|
|
|
69
71
|
/**
|
|
@@ -232,6 +234,9 @@ export interface DreamContext {
|
|
|
232
234
|
readonly observer: boolean;
|
|
233
235
|
/** The owner's own session: confidential memories may be shown (recall's gate 1). */
|
|
234
236
|
readonly owner: boolean;
|
|
237
|
+
/** Read the BUNDLES as the owner too (`BUNDLE_OWNER`, review of #318). No host sets it; the
|
|
238
|
+
* store-level tests of what an owner-read bundle must keep do. Absent: a guest. */
|
|
239
|
+
readonly bundleOwner?: boolean;
|
|
235
240
|
/** The credential battery (`bridge.episodeGate`), for every word a dream writes. */
|
|
236
241
|
readonly gate: (text: string, sessionId: string) => { ok: true; text: string } | { ok: false; reason: string };
|
|
237
242
|
readonly page: () => string | null;
|
|
@@ -275,6 +280,10 @@ export interface DreamChange {
|
|
|
275
280
|
readonly why?: string;
|
|
276
281
|
readonly relevance?: number;
|
|
277
282
|
readonly predictive?: number;
|
|
283
|
+
/** `gist` (v12, 2026-10-03): when what it draws on happened, who said it, what kind of thing it is. */
|
|
284
|
+
readonly occurredOn?: string;
|
|
285
|
+
readonly saidBy?: string;
|
|
286
|
+
readonly status?: string;
|
|
278
287
|
/** `settle`: the memory that holds, the one it is over, and how (2026-09-29). */
|
|
279
288
|
readonly holds?: string;
|
|
280
289
|
readonly over?: string;
|
|
@@ -406,6 +415,15 @@ export interface NightRun {
|
|
|
406
415
|
readonly parts?: readonly NightPart[];
|
|
407
416
|
/** The child's watchdog, ms, as the host started it — what makes a `started` row LOST past it. */
|
|
408
417
|
readonly timeoutMs?: number;
|
|
418
|
+
/**
|
|
419
|
+
* WHAT THE HOST CUT (2026-10-09, U14 item 3): how the child's own transcript
|
|
420
|
+
* read once it exited — `read`, `absent` (not where the host keeps it) or
|
|
421
|
+
* `unreadable` — and, when read, how many of the run's tool results the host
|
|
422
|
+
* showed the model only as a preview (one `mcp.result.spilled` row each).
|
|
423
|
+
* Absent on a run whose child never started, and on rows from before.
|
|
424
|
+
*/
|
|
425
|
+
readonly transcript?: "read" | "absent" | "unreadable";
|
|
426
|
+
readonly spills?: number;
|
|
409
427
|
/**
|
|
410
428
|
* When its hand-back was carried to a prompt (or found already carried) —
|
|
411
429
|
* so the per-prompt path READS this and writes nothing once it is set.
|
|
@@ -472,6 +490,8 @@ export function nightRunOf(store: Pick<Store, "getMeta">): NightRun | null {
|
|
|
472
490
|
...(typeof v.handedAt === "number" ? { handedAt: v.handedAt } : {}),
|
|
473
491
|
...(typeof v.timeoutMs === "number" ? { timeoutMs: v.timeoutMs } : {}),
|
|
474
492
|
...(Array.isArray(v.parts) ? { parts: v.parts.filter((p): p is NightPart => p === "writer" || p === "dream" || p === "reflection") } : {}),
|
|
493
|
+
...(v.transcript === "read" || v.transcript === "absent" || v.transcript === "unreadable" ? { transcript: v.transcript } : {}),
|
|
494
|
+
...(typeof v.spills === "number" ? { spills: v.spills } : {}),
|
|
475
495
|
};
|
|
476
496
|
} catch {
|
|
477
497
|
return null;
|
|
@@ -640,6 +660,11 @@ export class Dreams {
|
|
|
640
660
|
this.ctx = ctx;
|
|
641
661
|
}
|
|
642
662
|
|
|
663
|
+
/** Whose a bundle is read as: a guest (`BUNDLE_OWNER`), unless a test asked otherwise. */
|
|
664
|
+
private get bundleOwner(): boolean {
|
|
665
|
+
return this.ctx.bundleOwner ?? BUNDLE_OWNER;
|
|
666
|
+
}
|
|
667
|
+
|
|
643
668
|
private get store(): Store {
|
|
644
669
|
return this.ctx.store;
|
|
645
670
|
}
|
|
@@ -810,6 +835,8 @@ export class Dreams {
|
|
|
810
835
|
reflection: run.reflection,
|
|
811
836
|
parts: run.parts === undefined ? null : run.parts.join(","),
|
|
812
837
|
ms: run.endedAt === null ? null : run.endedAt - run.startedAt,
|
|
838
|
+
...(run.transcript === undefined ? {} : { transcript: run.transcript }),
|
|
839
|
+
...(run.spills === undefined ? {} : { spills: run.spills }),
|
|
813
840
|
},
|
|
814
841
|
dedupKey: `${NIGHT_RUN_EVENT}:${run.run}:${run.state}`,
|
|
815
842
|
});
|
|
@@ -1239,6 +1266,25 @@ export class Dreams {
|
|
|
1239
1266
|
return `Counterparts: the nightly run finished in the background, on its own${unfinished}. At a natural moment — not mid-task — tell ${who} in your own words what it did: ${dreamLine}`;
|
|
1240
1267
|
}
|
|
1241
1268
|
|
|
1269
|
+
/**
|
|
1270
|
+
* THE HOST'S CUT, SAID PLAINLY (2026-10-09, U14 item 3): when the run's own
|
|
1271
|
+
* transcript showed results of ours the host cut to a preview (`spills`),
|
|
1272
|
+
* the morning hand-back says so beside the dream's line and the share — so
|
|
1273
|
+
* the owner hears it without opening doctor. A dream or a reflection that
|
|
1274
|
+
* read through a keyhole may still sound whole, and its own entry is not
|
|
1275
|
+
* where he would look. Null when nothing was cut, or nobody checked.
|
|
1276
|
+
*/
|
|
1277
|
+
nightSpillLine(run: Pick<NightRun, "spills">): string | null {
|
|
1278
|
+
const n = run.spills ?? 0;
|
|
1279
|
+
if (n <= 0) return null;
|
|
1280
|
+
const who = this.ownerName() ?? "the owner";
|
|
1281
|
+
const what = n === 1 ? "one of the nightly run's tool results" : `${String(n)} of the nightly run's tool results`;
|
|
1282
|
+
return (
|
|
1283
|
+
`Counterparts: Claude Code cut ${what} to a short preview before the run could read ${n === 1 ? "it" : "them"}, so last night's run worked from part of what it was handed. ` +
|
|
1284
|
+
`At a natural moment — not mid-task — tell ${who} plainly, in a sentence, that this happened: Claude Code cut results that Counterparts had already sized to fit. \`counterparts doctor\` has the details on its Tool results line.`
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1242
1288
|
/**
|
|
1243
1289
|
* CLAIM THE DAY for an offer the host is certainly delivering: the
|
|
1244
1290
|
* `dream_asks` latch (a fresh row, or a reclaim of the row the offer read —
|
|
@@ -1319,7 +1365,8 @@ export class Dreams {
|
|
|
1319
1365
|
`${String(n())}. Call the counterparts dream tool: phase "begin", session: ${input.session}. It returns the bundle and a dream id. (If it says the dream was resumed, an earlier session began it and closed: carry on from there.) If it says it comes in parts, fetch every part (phase "part") before you change anything.`,
|
|
1320
1366
|
` Tonight's most important memories come whole; the rest come as a line or an excerpt ("fidelity"), with their whole length ("chars"). Before you merge, gist or feel one you have only in part, read it whole: the recall tool with ids: [...] (several at once). New memories tonight's room could not take wait for the next night — the bundle's "queue" says how many.`,
|
|
1321
1367
|
`${String(n())}. Read it slowly. Then call phase "propose" with dream: <id> and your changes. Usually far fewer than the ceilings — ${String(L.merge)} merges, ${String(L.link)} links, ${String(L.gist)} gists, ${String(L["feeling-now"])} feelings, ${String(L["nominate-core"])} nominations — and none is fine: change only what the night really calls for. Use only ids the bundle showed you.`,
|
|
1322
|
-
' The fields of each change: merge {ids: two or more near-copies, text, title?}; link {a, b}; replayed {id}; gist {text, sources: ids, title?, kind?}; contradiction {a, b}; settle {holds, over, how: changed|corrected|open, why}; feeling-now {id, core: happy|warm|calm|curious|sad|uneasy|angry, emotion, strength, carried_by}; nominate-core {id, why}.',
|
|
1368
|
+
' The fields of each change: merge {ids: two or more near-copies, text, title?}; link {a, b}; replayed {id}; gist {text, sources: ids, title?, kind?, occurredOn?, saidBy?, status?}; contradiction {a, b}; settle {holds, over, how: changed|corrected|open, why}; feeling-now {id, core: happy|warm|calm|curious|sad|uneasy|angry, emotion, strength, carried_by}; nominate-core {id, why}.',
|
|
1369
|
+
' On a gist, occurredOn is when what it draws on happened (a day "2026-09-24", a month, a range "2026-09-21..2026-09-27"), saidBy who said it (owner, self, or inferred — your own reading), status what kind of thing it is (done, planned, proposed, asked); leave out what you do not know.',
|
|
1323
1370
|
" A feeling: `emotion` is ONE word — from the wheel (hopeful, proud, wistful, peaceful…) or your own (steadied); `carried_by` is the nuance, in your own words (what the feeling is about now, why it shifted). Never put a phrase in `emotion`.",
|
|
1324
1371
|
`${String(n())}. Call phase "journal" with dream: <id>, a short title and your dream journal entry: first person, what you dreamed and what you noticed. It is kept as a dream, never as something that happened.`,
|
|
1325
1372
|
" In the dream you cannot delete anything, edit the self page, promote a memory, or rewrite one in place — the tool refuses. Nothing you write in the dream is a lived event.",
|
|
@@ -1330,7 +1377,7 @@ export class Dreams {
|
|
|
1330
1377
|
],
|
|
1331
1378
|
reflection: (n) => [
|
|
1332
1379
|
"The reflection — waking up and thinking about yourself: awake, lived, your own.",
|
|
1333
|
-
`${String(n())}. Call the counterparts reflect tool: phase "begin", session: ${input.session}, dream: <id>. It hands you what the dream saw, the last few days, your whole self page, the memories that matter most, and a few questions. If it says it comes in parts, fetch every part (phase "part") before you answer.`,
|
|
1380
|
+
`${String(n())}. Call the counterparts reflect tool: phase "begin", session: ${input.session}, dream: <id>. It hands you what the dream saw, the last few days, your whole self page, the memories that matter most, and a few questions. If it says it comes in parts, fetch every part (phase "part") before you answer or write anything.`,
|
|
1334
1381
|
`${String(n())}. Answer them honestly, then call phase "finish" as it tells you. "Nothing much" is a normal answer: a short entry and no share.`,
|
|
1335
1382
|
],
|
|
1336
1383
|
};
|
|
@@ -1380,7 +1427,7 @@ export class Dreams {
|
|
|
1380
1427
|
// The dream before this one (an undone dream does not count), and the
|
|
1381
1428
|
// queue as every dream that stands leaves it.
|
|
1382
1429
|
const prior = this.lastDream();
|
|
1383
|
-
const q = this.queue({ owner: this.
|
|
1430
|
+
const q = this.queue({ owner: this.bundleOwner });
|
|
1384
1431
|
if (q.ids.length === 0) return { ok: false, reason: "nothing-new" };
|
|
1385
1432
|
const id = `drm_${randomBytes(6).toString("hex")}`;
|
|
1386
1433
|
const composed = this.compose(id, q, prior, day, at);
|
|
@@ -1454,7 +1501,7 @@ export class Dreams {
|
|
|
1454
1501
|
const prior = this.store.dreams({ limit: 20 }).find((d) => d.state !== "undone" && d.id !== dream.id) ?? null;
|
|
1455
1502
|
// Its queue: what no OTHER standing dream was shown — so what this dream
|
|
1456
1503
|
// was shown before it closed is shown to it again.
|
|
1457
|
-
const q = this.queue({ owner: this.
|
|
1504
|
+
const q = this.queue({ owner: this.bundleOwner, skip: (d) => d.id === dream.id });
|
|
1458
1505
|
const made = this.counts(dream.id);
|
|
1459
1506
|
const composed = this.compose(dream.id, q, prior, day, at);
|
|
1460
1507
|
const said = Object.entries(made)
|
|
@@ -1613,7 +1660,9 @@ export class Dreams {
|
|
|
1613
1660
|
})),
|
|
1614
1661
|
// Each feeling keeps who recorded it and when (v9): a reflection's
|
|
1615
1662
|
// later feeling stays one on the merged memory.
|
|
1616
|
-
|
|
1663
|
+
// And WHEN (2026-10-02): a feeling is a moment's, so the merge
|
|
1664
|
+
// does not date it to tonight (the reflection reads feelings by week).
|
|
1665
|
+
{ provenance: feelings.map((f) => ({ source: f.source, recordedLater: f.recorded_later, createdAt: f.created_at })) },
|
|
1617
1666
|
);
|
|
1618
1667
|
}
|
|
1619
1668
|
// TRAIT NUDGES TRAVEL THE SAME WAY (v9): each keeps who recorded it,
|
|
@@ -1696,6 +1745,8 @@ export class Dreams {
|
|
|
1696
1745
|
const words = this.words(change.text, dream);
|
|
1697
1746
|
if (!words.ok) return { action, ok: false, reason: words.reason, detail: `text: ${words.detail}` };
|
|
1698
1747
|
const kind: Kind = (KINDS as readonly string[]).includes(String(change.kind)) ? (change.kind as Kind) : "fact";
|
|
1748
|
+
// v12: the three fields, loose-first — what cannot be read is dropped and said.
|
|
1749
|
+
const facts = gistFacts(change);
|
|
1699
1750
|
const cap = PHYSICS.DREAMED_CLAIM_CEILING;
|
|
1700
1751
|
const title = (change.title ?? "").trim().slice(0, DREAM_TUNABLES.MAX_TITLE_CHARS);
|
|
1701
1752
|
const id = this.store.put({
|
|
@@ -1716,6 +1767,7 @@ export class Dreams {
|
|
|
1716
1767
|
meta: { dream: dream.id, dreamed: true, sources, ...confidentialityOf(sourceRows as MemoryRow[]) },
|
|
1717
1768
|
origin: { ...(dream.session === null ? {} : { session: dream.session }), ...(dream.scope === null ? {} : { scope: dream.scope }), ref: `dream:${dream.id}` },
|
|
1718
1769
|
...(dream.model === null ? {} : { model: dream.model }),
|
|
1770
|
+
...facts.put,
|
|
1719
1771
|
});
|
|
1720
1772
|
// The gist's ties to its sources, through the edge module, in the
|
|
1721
1773
|
// dream's own source order: each lands only where both ends have room
|
|
@@ -1741,6 +1793,7 @@ export class Dreams {
|
|
|
1741
1793
|
shown.add(id);
|
|
1742
1794
|
const gistNotes = [
|
|
1743
1795
|
...(words.cut ? [`text was kept to its first ${String(DREAM_TUNABLES.MAX_TEXT_CHARS)} characters.`] : []),
|
|
1796
|
+
...facts.notes,
|
|
1744
1797
|
...((change.title ?? "").trim().length > DREAM_TUNABLES.MAX_TITLE_CHARS ? [titleNote()] : []),
|
|
1745
1798
|
...(ties.reason === "failed" || ties.reason === "observer"
|
|
1746
1799
|
? [`its ties to its sources were not written (${ties.reason}).`]
|
|
@@ -1877,7 +1930,7 @@ export class Dreams {
|
|
|
1877
1930
|
try {
|
|
1878
1931
|
// What waited from before the dream began — not what was made during the night.
|
|
1879
1932
|
const began = this.store.dream(id)?.started_at;
|
|
1880
|
-
waiting = this.queue({ owner: this.
|
|
1933
|
+
waiting = this.queue({ owner: this.bundleOwner, ...(began === undefined ? {} : { madeBy: began }) }).ids.length;
|
|
1881
1934
|
} catch {
|
|
1882
1935
|
waiting = 0;
|
|
1883
1936
|
}
|
|
@@ -2061,7 +2114,7 @@ export class Dreams {
|
|
|
2061
2114
|
* confidential unless this is the owner's own session.
|
|
2062
2115
|
*/
|
|
2063
2116
|
showable(row: MemoryRow): boolean {
|
|
2064
|
-
return this.showableAs(row, this.
|
|
2117
|
+
return this.showableAs(row, this.bundleOwner);
|
|
2065
2118
|
}
|
|
2066
2119
|
|
|
2067
2120
|
/** `showable`, for a session whose owner stance is `owner` (the preview's). */
|
|
@@ -2216,7 +2269,7 @@ export class Dreams {
|
|
|
2216
2269
|
today: at,
|
|
2217
2270
|
day,
|
|
2218
2271
|
showable: (row) => !denied.has(row.id) && this.showable(row),
|
|
2219
|
-
owner: this.
|
|
2272
|
+
owner: this.bundleOwner,
|
|
2220
2273
|
});
|
|
2221
2274
|
const mindAll = mindRead.items;
|
|
2222
2275
|
const mindIds = new Set(mindAll.flatMap((m) => m.ids));
|
|
@@ -2315,7 +2368,7 @@ export class Dreams {
|
|
|
2315
2368
|
const selfPage = page === null ? null : clipWire(page, T.PAGE_CHARS);
|
|
2316
2369
|
const wakeText = wake === null ? null : clipWire(wake, T.WAKE_CHARS);
|
|
2317
2370
|
const room = Math.max(0, T.NIGHT_CHARS - chaptersFit.used - wireChars(selfPage ?? "") - wireChars(wakeText ?? "") - FURNITURE);
|
|
2318
|
-
const aged = this.agedOut(last, q.from, this.
|
|
2371
|
+
const aged = this.agedOut(last, q.from, this.bundleOwner);
|
|
2319
2372
|
const base: Record<DreamRole, number> = { new: 4, "on-mind": 3, lookback: 2, neighbour: 1, mixing: 0.5 };
|
|
2320
2373
|
const cands: FitCandidate[] = [];
|
|
2321
2374
|
for (const [mid, r] of role) {
|
|
@@ -2418,7 +2471,7 @@ export class Dreams {
|
|
|
2418
2471
|
for (const eid of this.store.list({ type: "episode", archived: false })) {
|
|
2419
2472
|
const row = this.store.row(eid);
|
|
2420
2473
|
if (row === undefined) continue;
|
|
2421
|
-
if (row.confidential === 1 && !this.
|
|
2474
|
+
if (row.confidential === 1 && !this.bundleOwner) continue;
|
|
2422
2475
|
const at = row.updated_at ?? row.created_at ?? 0;
|
|
2423
2476
|
// `>=`: an episode written in the same millisecond the last dream began is read again (its index says how far).
|
|
2424
2477
|
const since = last === null ? row.birth_day >= day - T.FIRST_DREAM_DAYS : at >= last.started_at;
|
|
@@ -2507,7 +2560,9 @@ export class Dreams {
|
|
|
2507
2560
|
private pack(id: string, session: string, c: Composed, lead: string): { bundle: DreamBundle; later: string[][] } {
|
|
2508
2561
|
const T = DREAM_TUNABLES;
|
|
2509
2562
|
const whole = c.bundle;
|
|
2510
|
-
|
|
2563
|
+
// WHOLE WITH ITS MARGIN TOO (2026-10-02): `how` and the other fields ride
|
|
2564
|
+
// beside the bundle whether it comes in parts or not.
|
|
2565
|
+
if (dreamResultChars(renderDream(id, whole, lead), session, id) + PACK_MARGIN <= T.RESULT_CHARS) return { bundle: whole, later: [] };
|
|
2511
2566
|
const cost = (v: unknown): number => wireChars(JSON.stringify(JSON.stringify(v)));
|
|
2512
2567
|
const pieces: { key: string; size: number }[] = [
|
|
2513
2568
|
...Object.entries(whole.memories).map(([k, v]) => ({ key: `m:${k}`, size: cost({ [k]: v }) })),
|
|
@@ -2521,10 +2576,18 @@ export class Dreams {
|
|
|
2521
2576
|
// first (it is the page plus lanes), then the page (the self_page tool
|
|
2522
2577
|
// reads it whole), then what's on my mind (counted in onMindMore) — each
|
|
2523
2578
|
// left out with its length said, never cut silently.
|
|
2579
|
+
//
|
|
2580
|
+
// THE LINE MOVED WITH THE CEILING (2026-10-02, review of #315). It was
|
|
2581
|
+
// `RESULT_CHARS - PART_CHARS / 4`: 40,500 of furniture at 54,000, and 30,000
|
|
2582
|
+
// at 40,000 — which would drop the wake and the page on a busy night that
|
|
2583
|
+
// used to keep them. The wake and the page cannot be fetched in a later
|
|
2584
|
+
// part, and memories can, so the furniture now keeps all but
|
|
2585
|
+
// `FIRST_PART_MIN_ROOM` of part 1 (36,000), and the memories move on.
|
|
2524
2586
|
let base: DreamBundle = whole;
|
|
2525
|
-
|
|
2526
|
-
if (measure(base) >
|
|
2527
|
-
if (measure(base) >
|
|
2587
|
+
const furnitureLine = T.RESULT_CHARS - FIRST_PART_MIN_ROOM;
|
|
2588
|
+
if (measure(base) > furnitureLine) base = { ...base, wake: null };
|
|
2589
|
+
if (measure(base) > furnitureLine) base = { ...base, selfPage: null };
|
|
2590
|
+
if (measure(base) > furnitureLine) base = { ...base, onMind: [], onMindMore: (base.onMindMore ?? 0) + base.onMind.length };
|
|
2528
2591
|
const fixed = measure(base);
|
|
2529
2592
|
const groups = packParts(pieces, Math.max(0, T.RESULT_CHARS - fixed), Math.max(0, T.PART_CHARS - PART_FURNITURE));
|
|
2530
2593
|
if (groups.length === 1) return { bundle: base, later: [] };
|
|
@@ -2609,7 +2672,7 @@ export class Dreams {
|
|
|
2609
2672
|
const row = this.store.row(eid);
|
|
2610
2673
|
const ch = chapters.get(eid) ?? { id: eid, title: row?.title ?? null, entries: [] };
|
|
2611
2674
|
chapters.set(eid, ch);
|
|
2612
|
-
const entry = row === undefined || (row.confidential === 1 && !this.
|
|
2675
|
+
const entry = row === undefined || (row.confidential === 1 && !this.bundleOwner) ? undefined : chapterEntries(row.body)[Number(at)];
|
|
2613
2676
|
if (entry === undefined) {
|
|
2614
2677
|
ch.entries.push({ chapter: null, day: null, fidelity: "line", text: gone, chars: 0 });
|
|
2615
2678
|
continue;
|
|
@@ -2868,6 +2931,8 @@ const FIT_OVERHEAD = FIT_TUNABLES.OVERHEAD;
|
|
|
2868
2931
|
const FURNITURE = 4_000;
|
|
2869
2932
|
/** Slack for the result's other fields (phase, session, the server's `how`) beside the bundle. */
|
|
2870
2933
|
const PACK_MARGIN = 1_500;
|
|
2934
|
+
/** The least of part 1 kept for memories before its furniture (wake, page, on my mind) gives way. CAL. */
|
|
2935
|
+
const FIRST_PART_MIN_ROOM = 4_000;
|
|
2871
2936
|
/** A later part's own furniture: its opener, ids and `next`. */
|
|
2872
2937
|
const PART_FURNITURE = 1_500;
|
|
2873
2938
|
|
|
@@ -2897,6 +2962,32 @@ export function dreamResultChars(text: string, session: string, dream: string):
|
|
|
2897
2962
|
}
|
|
2898
2963
|
|
|
2899
2964
|
/** What a title kept to its cap says — never cut without a word (2026-09-28). */
|
|
2965
|
+
/**
|
|
2966
|
+
* A gist's three fields (v12, 2026-10-03), read loose-first: what reads goes
|
|
2967
|
+
* to the row, what does not is dropped with a note — the gist is written
|
|
2968
|
+
* either way, as a malformed `kind` falls back to `fact`.
|
|
2969
|
+
*/
|
|
2970
|
+
function gistFacts(change: DreamChange): { put: { occurredOn?: string; saidBy?: SaidBy; status?: MemoryStatus }; notes: string[] } {
|
|
2971
|
+
const put: { occurredOn?: string; saidBy?: SaidBy; status?: MemoryStatus } = {};
|
|
2972
|
+
const notes: string[] = [];
|
|
2973
|
+
if (change.occurredOn !== undefined && change.occurredOn !== null) {
|
|
2974
|
+
const d = occurredOnOf(change.occurredOn);
|
|
2975
|
+
if (d === null) notes.push(`occurredOn "${String(change.occurredOn).slice(0, 64)}" is not a date this can read (a day, a month, a year or a range), so it was left off.`);
|
|
2976
|
+
else put.occurredOn = d;
|
|
2977
|
+
}
|
|
2978
|
+
if (change.saidBy !== undefined && change.saidBy !== null) {
|
|
2979
|
+
const v = saidByOf(change.saidBy);
|
|
2980
|
+
if (v === null) notes.push(`saidBy "${String(change.saidBy).slice(0, 64)}" is not one of ${SAID_BY.join(", ")}, so it was left off.`);
|
|
2981
|
+
else put.saidBy = v;
|
|
2982
|
+
}
|
|
2983
|
+
if (change.status !== undefined && change.status !== null) {
|
|
2984
|
+
const v = statusOf(change.status);
|
|
2985
|
+
if (v === null) notes.push(`status "${String(change.status).slice(0, 64)}" is not one of ${STATUSES.join(", ")}, so it was left off.`);
|
|
2986
|
+
else put.status = v;
|
|
2987
|
+
}
|
|
2988
|
+
return { put, notes };
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2900
2991
|
function titleNote(): string {
|
|
2901
2992
|
return `title was kept to its first ${String(DREAM_TUNABLES.MAX_TITLE_CHARS)} characters.`;
|
|
2902
2993
|
}
|