counterparts 0.1.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/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remember→encode bridge — SEAMS.md items 1–3 close here.
|
|
3
|
+
*
|
|
4
|
+
* remember/ owns authorship mechanics and deliberately injects its gate;
|
|
5
|
+
* encode/ owns the battery and deliberately holds no store handle. This file is
|
|
6
|
+
* the one place the two are composed, so the composition rules live in exactly
|
|
7
|
+
* one spot:
|
|
8
|
+
*
|
|
9
|
+
* 1. CHUNK-LEVEL GATED-MEANS-GATED: fallback-sweep chunks route through
|
|
10
|
+
* `encodeChunk`, whose all-rejected rule already returns zero durable
|
|
11
|
+
* effects (including prediction checks). The bridge adds no second
|
|
12
|
+
* implementation — it routes.
|
|
13
|
+
* 2. THE EMOTION EXEMPTION IS ENGINE-SET HERE, from the proposal's source: a
|
|
14
|
+
* session-end dump or an in-the-moment jot IS the experiencer writing, so
|
|
15
|
+
* its feelings are self-authored; a fallback sweep's are not. No author
|
|
16
|
+
* field can claim it (encode validates; remember's drafts can't carry it).
|
|
17
|
+
* 3. Claimed salience, dimensions, and title-as-handle reach the battery, and
|
|
18
|
+
* a battery refusal is marked `refusedByDesign` so callers can tell a
|
|
19
|
+
* working gate from a broken one.
|
|
20
|
+
* 4. SEAMS item H: EPISODES route through the same battery. `self/`'s default
|
|
21
|
+
* episode gate REFUSES everything ("an absent gate is not an open one"), and
|
|
22
|
+
* `episodeGate()` below is what makes that default unreachable in
|
|
23
|
+
* production. Episode ingestion was v1's most heavily gated surface — 66% of
|
|
24
|
+
* all gate fires (scar §2.7) — and a first-person reflection is not exempt
|
|
25
|
+
* from never durably encoding a credential.
|
|
26
|
+
*/
|
|
27
|
+
import { computeNovelty, encodeChunk, gateProposal } from "./encode/index.js";
|
|
28
|
+
import type {
|
|
29
|
+
ChunkInput,
|
|
30
|
+
ClaimedDimensions,
|
|
31
|
+
EncodeOptions,
|
|
32
|
+
EncodeResult,
|
|
33
|
+
Proposal as EncodeProposal,
|
|
34
|
+
} from "./encode/index.js";
|
|
35
|
+
import type { GateFn, GateVerdict } from "./remember/index.js";
|
|
36
|
+
import type { SweepChunk } from "./remember/index.js";
|
|
37
|
+
import type { EpisodeGate } from "./self/index.js";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Where the vectors come from — injected, because `encode/` "supplies the inputs
|
|
41
|
+
* and holds no store handle" and this file holds no network client either. The
|
|
42
|
+
* composition root binds all three members; absent, both gates behave exactly as
|
|
43
|
+
* they did before one existed (novelty null, reason `no-chunk-vector`).
|
|
44
|
+
*
|
|
45
|
+
* Only the AUTHORED door takes one. `GateFn` may return a promise and
|
|
46
|
+
* `submitProposal` awaits it, so that door can pay for a live embedding;
|
|
47
|
+
* `EpisodeGate` is synchronous AND its verdict has nowhere to carry a novelty
|
|
48
|
+
* number, so `episodeGate()` takes no source at all rather than computing one to
|
|
49
|
+
* throw away (INTERFACE-GAPS §8c).
|
|
50
|
+
*
|
|
51
|
+
* Every member is asked for the text AS THE STORE WILL INDEX IT — the gate's
|
|
52
|
+
* output, never the author's draft. That is what makes one embedding serve both
|
|
53
|
+
* the novelty measurement and box 3, and it is also the egress rule: nothing
|
|
54
|
+
* reaches this interface that has not already been through the battery.
|
|
55
|
+
*/
|
|
56
|
+
export interface VectorSource {
|
|
57
|
+
/** Live: may reach the network. Only called where the caller can await. */
|
|
58
|
+
vector(title: string | null, content: string): Promise<number[] | null>;
|
|
59
|
+
/** E(m) — what this brain already holds near `vec`. Read-only. */
|
|
60
|
+
context(vec: readonly number[]): readonly (readonly number[])[];
|
|
61
|
+
/**
|
|
62
|
+
* Fetch vectors for memories about to be written, in ONE batched call. The
|
|
63
|
+
* sweep's only use: its mints happen in a loop, and a round trip each would be
|
|
64
|
+
* the shape scar E1 warns about paid for one item at a time.
|
|
65
|
+
*/
|
|
66
|
+
warm(items: readonly { title: string | null; content: string }[]): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Per-proposal gate for the authored paths (session-end dumps and jots).
|
|
71
|
+
*
|
|
72
|
+
* With a `VectorSource` the returned gate is ASYNC (a live embedding is one
|
|
73
|
+
* network call), which `GateFn` permits and `remember/submitProposal` awaits.
|
|
74
|
+
* WITHOUT one it stays synchronous — not for speed, but because a gate that
|
|
75
|
+
* became a promise for every caller would silently break any caller reading
|
|
76
|
+
* `verdict.ok` off the return value.
|
|
77
|
+
*
|
|
78
|
+
* **THE BATTERY RUNS BEFORE THE SOCKET DOES.** The first version of this
|
|
79
|
+
* function embedded `input.content` — the author's RAW draft — and then gated
|
|
80
|
+
* it, which put un-redacted text on the wire: a credential in a session-end dump
|
|
81
|
+
* reached the embedding provider verbatim while the prose written to disk was
|
|
82
|
+
* correctly redacted. The secrets gate is not ablatable and "durable" is not its
|
|
83
|
+
* scope; egress is egress. So the order here is the order the sweep door already
|
|
84
|
+
* used (`counterpart.applySweep` warms `result.accepted`, post-gate):
|
|
85
|
+
*
|
|
86
|
+
* 1. gate the proposal, with novelty NOT YET KNOWN;
|
|
87
|
+
* 2. a refusal returns immediately — nothing refused is ever embedded;
|
|
88
|
+
* 3. embed the GATE'S text, which is also the text the store will index;
|
|
89
|
+
* 4. compute novelty against E(m) and attach it to the verdict.
|
|
90
|
+
*
|
|
91
|
+
* Step 1 costs nothing in correctness because the battery's accept/refuse never
|
|
92
|
+
* consults novelty: `gateProposal` reads `input.novelty` only AFTER its refusal
|
|
93
|
+
* branch has returned, to tag the accepted proposal's salience and to emit
|
|
94
|
+
* `encode.blind`. Both of those are discarded here (this function returns a
|
|
95
|
+
* `GateVerdict`, not an `AcceptedProposal`, and drops `outcome.events`), so the
|
|
96
|
+
* placeholder cannot leak a wrong number into telemetry either — the novelty
|
|
97
|
+
* that survives is the one attached in step 4.
|
|
98
|
+
*/
|
|
99
|
+
export function batteryGate(vectors?: VectorSource): GateFn {
|
|
100
|
+
if (vectors === undefined) return (input) => verdictFor(input, computeNovelty(null, []));
|
|
101
|
+
return async (input): Promise<GateVerdict> => {
|
|
102
|
+
const verdict = verdictFor(input, computeNovelty(null, []));
|
|
103
|
+
// A refused proposal is not a memory, so it is not a vector either — and it
|
|
104
|
+
// is emphatically not something to send to a third party on the way out.
|
|
105
|
+
if (!verdict.ok) return verdict;
|
|
106
|
+
const vec = await vectors.vector(input.title, verdict.content);
|
|
107
|
+
const novelty = computeNovelty(vec, vec === null ? [] : vectors.context(vec));
|
|
108
|
+
return { ...verdict, novelty: novelty.novelty };
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The battery run itself, novelty already decided. One body, two entrances. */
|
|
113
|
+
function verdictFor(
|
|
114
|
+
input: Parameters<GateFn>[0],
|
|
115
|
+
novelty: ReturnType<typeof computeNovelty>,
|
|
116
|
+
): GateVerdict {
|
|
117
|
+
const selfAuthored = input.source === "session-end" || input.source === "jot";
|
|
118
|
+
const proposal: EncodeProposal = {
|
|
119
|
+
ref: input.span?.hash ?? "authored",
|
|
120
|
+
content: input.content,
|
|
121
|
+
kind: input.kind,
|
|
122
|
+
aliases: input.aliases,
|
|
123
|
+
feeling:
|
|
124
|
+
input.feeling === null
|
|
125
|
+
? null
|
|
126
|
+
: {
|
|
127
|
+
// remember says `feeling`, encode says `type` — same field.
|
|
128
|
+
type: input.feeling.feeling,
|
|
129
|
+
quote: input.feeling.quote,
|
|
130
|
+
subject: input.feeling.subject,
|
|
131
|
+
},
|
|
132
|
+
selfAuthoredFeeling: selfAuthored,
|
|
133
|
+
claimedSalience: input.claimed,
|
|
134
|
+
};
|
|
135
|
+
if (input.title !== null) {
|
|
136
|
+
proposal.title = input.title;
|
|
137
|
+
proposal.handles = [input.title];
|
|
138
|
+
}
|
|
139
|
+
const dims = dimensionsFrom(input.salience);
|
|
140
|
+
if (dims !== null) proposal.dimensions = dims;
|
|
141
|
+
|
|
142
|
+
// Novelty arrives DECIDED — computed against a real vector when the root wired
|
|
143
|
+
// a source, null-with-reason when it did not (scar §2.9: never a default, in
|
|
144
|
+
// either direction). Nothing here invents one.
|
|
145
|
+
const outcome = gateProposal({
|
|
146
|
+
proposal,
|
|
147
|
+
span: input.span?.text ?? input.content,
|
|
148
|
+
novelty,
|
|
149
|
+
});
|
|
150
|
+
const g = outcome.gated;
|
|
151
|
+
if (g.accepted) {
|
|
152
|
+
return {
|
|
153
|
+
ok: true,
|
|
154
|
+
content: g.content,
|
|
155
|
+
aliases: g.aliases,
|
|
156
|
+
// THE RECORDS TRAVEL NOW (replay INTERFACE-GAPS §2a). They used to be
|
|
157
|
+
// dropped here on both arms, which left the authored door with two facts
|
|
158
|
+
// — accepted, or refused-with-a-reason — and nothing durable to write.
|
|
159
|
+
// Relayed, never read: this function decides nothing from them.
|
|
160
|
+
records: g.records,
|
|
161
|
+
channels: outcome.channels,
|
|
162
|
+
feeling:
|
|
163
|
+
g.feeling === null
|
|
164
|
+
? null
|
|
165
|
+
: { feeling: g.feeling.type, quote: "", subject: g.feeling.subject },
|
|
166
|
+
// NO `novelty` field here, deliberately: this function runs before any
|
|
167
|
+
// vector exists. `batteryGate` attaches the computed dimension after the
|
|
168
|
+
// gate has spoken, so an OMITTED field means "no source was wired" and an
|
|
169
|
+
// explicit null means "a source tried and could not measure" — the two
|
|
170
|
+
// records `remember/proposals.ts` documents on the field.
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
ok: false,
|
|
175
|
+
gate: g.reason,
|
|
176
|
+
reason: g.blockedBy.join("+"),
|
|
177
|
+
refusedByDesign: true,
|
|
178
|
+
records: g.records,
|
|
179
|
+
channels: outcome.channels,
|
|
180
|
+
// The same list `reason` above joins. Both, deliberately: the string is what
|
|
181
|
+
// a person reads in an event line, the array is what telemetry counts, and
|
|
182
|
+
// splitting the string back apart at the reader is how a `+` in a future
|
|
183
|
+
// reason word becomes a silently wrong count.
|
|
184
|
+
blockedBy: [...g.blockedBy],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* All three author dimensions or nothing — a partial claim is not padded.
|
|
190
|
+
*
|
|
191
|
+
* NAMED GAP (2026-09-04): the obvious source for `emotional` when the author
|
|
192
|
+
* gave none is the stated-emotion gate, and it cannot supply one.
|
|
193
|
+
* `encode/emotion.ts#gateEmotion` yields a `DurableFeeling` of `{type, subject}`
|
|
194
|
+
* — a feeling that SURVIVED, with no magnitude on it anywhere — so there is no
|
|
195
|
+
* number to read across, and manufacturing one from "a feeling was stated" is
|
|
196
|
+
* retro-typing emotion, which encode §3 forbids outright. Left open rather than
|
|
197
|
+
* approximated; the MCP adapter's contract carries the same gap as its §7.4.
|
|
198
|
+
*/
|
|
199
|
+
function dimensionsFrom(
|
|
200
|
+
s: Partial<{ relevance: number; emotional: number; predictive: number }>,
|
|
201
|
+
): ClaimedDimensions | null {
|
|
202
|
+
if (
|
|
203
|
+
typeof s.relevance === "number" &&
|
|
204
|
+
typeof s.emotional === "number" &&
|
|
205
|
+
typeof s.predictive === "number"
|
|
206
|
+
) {
|
|
207
|
+
return { relevance: s.relevance, emotional: s.emotional, predictive: s.predictive };
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The sweep-chunk composition (SEAMS item 1): parsed fallback proposals for ONE
|
|
214
|
+
* chunk go through `encodeChunk` — never `gateProposal` one at a time — so the
|
|
215
|
+
* chunk-level all-rejected rule holds. Fallback proposals are never
|
|
216
|
+
* self-authored: `selfAuthoredFeeling` is stripped here even if the interpreter
|
|
217
|
+
* hallucinated it (the exemption is engine-set, and this engine says no).
|
|
218
|
+
*/
|
|
219
|
+
export function gateSweepChunk(
|
|
220
|
+
chunk: SweepChunk,
|
|
221
|
+
proposals: readonly EncodeProposal[],
|
|
222
|
+
day: number,
|
|
223
|
+
extras: Omit<ChunkInput, "chunkRef" | "span" | "proposals" | "day"> = {},
|
|
224
|
+
opts: EncodeOptions = {},
|
|
225
|
+
): EncodeResult {
|
|
226
|
+
const stripped = proposals.map((p) => ({ ...p, selfAuthoredFeeling: false }));
|
|
227
|
+
const input: ChunkInput = {
|
|
228
|
+
...extras,
|
|
229
|
+
chunkRef: `sweep:${chunk.index}`,
|
|
230
|
+
span: chunk.spans.map((s) => s.text).join("\n"),
|
|
231
|
+
proposals: stripped,
|
|
232
|
+
day,
|
|
233
|
+
};
|
|
234
|
+
return encodeChunk(input, opts);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The episode gate (SEAMS item H). Episodes are self-authored by definition, so
|
|
239
|
+
* the emotion exemption applies exactly as it does to a session-end dump; the
|
|
240
|
+
* handles are the episode's named people and places, and a credential in one
|
|
241
|
+
* refuses the whole ingestion (the ops rule: a credential must never become an
|
|
242
|
+
* entity the store indexes).
|
|
243
|
+
*
|
|
244
|
+
* A body secret is REDACTED, not fatal, and the redacted text comes back on the
|
|
245
|
+
* verdict — the same rule every other ingestion path follows.
|
|
246
|
+
*/
|
|
247
|
+
export function episodeGate(): EpisodeGate {
|
|
248
|
+
return (input) => {
|
|
249
|
+
const proposal: EncodeProposal = {
|
|
250
|
+
ref: `episode:${input.sessionId}`,
|
|
251
|
+
content: input.text,
|
|
252
|
+
kind: "self",
|
|
253
|
+
selfAuthoredFeeling: true,
|
|
254
|
+
};
|
|
255
|
+
if (input.handles.length > 0) proposal.handles = [...input.handles];
|
|
256
|
+
// NO VECTOR SOURCE, and the reason is structural rather than a shortcut:
|
|
257
|
+
// `EpisodeGateVerdict` has nowhere to put a novelty number, so anything
|
|
258
|
+
// computed here would be spent on a gate decision that never reads it and
|
|
259
|
+
// then dropped — exactly the decorative wire §8d exists to describe. An
|
|
260
|
+
// earlier draft took a `VectorSource` and looked one up anyway; it was
|
|
261
|
+
// removed rather than kept as a comment, and the door is filed in
|
|
262
|
+
// INTERFACE-GAPS §8c as blind until the verdict type can carry the value.
|
|
263
|
+
const outcome = gateProposal({
|
|
264
|
+
proposal,
|
|
265
|
+
span: input.text,
|
|
266
|
+
novelty: computeNovelty(null, []),
|
|
267
|
+
});
|
|
268
|
+
const g = outcome.gated;
|
|
269
|
+
if (g.accepted) return { ok: true, text: g.content };
|
|
270
|
+
return { ok: false, gate: g.reason, reason: g.blockedBy.join("+") };
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wake-briefing composition root — SEAMS item G closes here.
|
|
3
|
+
*
|
|
4
|
+
* `sleep/` guarantees ORDER (the re-render is the cycle's LAST content write, so
|
|
5
|
+
* it sees this boundary's own supersedes, promotions, merges and prunes) and
|
|
6
|
+
* nothing else; the atomic publish, the trim order and the sentinel counts stay
|
|
7
|
+
* `self/`'s. Neither module imports the other, and a test on each side asserts
|
|
8
|
+
* the absence. This file is the one line between them.
|
|
9
|
+
*
|
|
10
|
+
* Two numbers arrive from outside both modules, and that is the point:
|
|
11
|
+
*
|
|
12
|
+
* - **`budgetBytes` is the HOST's reported injection ceiling** (scar §2.18 —
|
|
13
|
+
* the ceiling is a host capability, not a constant either module may invent).
|
|
14
|
+
* It rides in `SleepOptions.budgetBytes` so a wrong value is an argument
|
|
15
|
+
* somebody can see, and `self/` requires it: absent, this adapter REFUSES to
|
|
16
|
+
* render rather than guessing, because an invented ceiling is exactly the
|
|
17
|
+
* failure the scar names.
|
|
18
|
+
* - **`horizon` comes from `prospective/`**, never from `sleep/`
|
|
19
|
+
* (`self/INTERFACE-GAPS.md` §3: the lane, its heading and its trim position
|
|
20
|
+
* are already built; only the source was borrowed).
|
|
21
|
+
*/
|
|
22
|
+
import type { RenderFn } from "./sleep/index.js";
|
|
23
|
+
|
|
24
|
+
/** Structurally `Self`, so this file imports no class. */
|
|
25
|
+
export interface BriefingRenderer {
|
|
26
|
+
boundary(req: {
|
|
27
|
+
day: number;
|
|
28
|
+
budgetBytes: number;
|
|
29
|
+
horizon?: readonly { id: string }[];
|
|
30
|
+
}): { briefing: { bytes: number; elements: number } };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Structurally `Prospective.horizon()`. */
|
|
34
|
+
export interface HorizonSource {
|
|
35
|
+
horizon(input: { at: string; day?: number }): { items: readonly { memoryId: string }[] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RendererOptions {
|
|
39
|
+
/** The calendar date the horizon asks about. Without it, no horizon lane. */
|
|
40
|
+
at?: string;
|
|
41
|
+
prospective?: HorizonSource;
|
|
42
|
+
/** Telemetry only. A refusal must be loud, never a silently empty briefing. */
|
|
43
|
+
onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function selfRenderer(self: BriefingRenderer, opts: RendererOptions = {}): RenderFn {
|
|
47
|
+
return (ctx) => {
|
|
48
|
+
if (ctx.budgetBytes === undefined) {
|
|
49
|
+
// Fail toward saying so. An invented ceiling would publish a briefing the
|
|
50
|
+
// host silently truncates, which is the failure mode scar §2.18 records.
|
|
51
|
+
opts.onEvent?.("briefing.no-budget", { day: ctx.day });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const horizon =
|
|
55
|
+
opts.prospective === undefined || opts.at === undefined
|
|
56
|
+
? undefined
|
|
57
|
+
: opts.prospective
|
|
58
|
+
.horizon({ at: opts.at, day: ctx.day })
|
|
59
|
+
.items.map((i) => ({ id: i.memoryId }));
|
|
60
|
+
const result = self.boundary({
|
|
61
|
+
day: ctx.day,
|
|
62
|
+
budgetBytes: ctx.budgetBytes,
|
|
63
|
+
...(horizon === undefined ? {} : { horizon }),
|
|
64
|
+
});
|
|
65
|
+
return { bytes: result.briefing.bytes, elements: result.briefing.elements };
|
|
66
|
+
};
|
|
67
|
+
}
|