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,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The credential file — the ONE file the package's own configuration names.
|
|
3
|
+
*
|
|
4
|
+
* MEASURED, day 0 of the parallel run: this host's hook processes carry neither
|
|
5
|
+
* `ANTHROPIC_API_KEY` nor `VOYAGE_API_KEY`, even with both exported in the
|
|
6
|
+
* owner's `~/.zshrc`. The host's process environment is not the login shell's.
|
|
7
|
+
* A v2 that reads `process.env` and nothing else therefore never opens the
|
|
8
|
+
* embedder, and its worker skips the crash-fallback sweep at every boundary:
|
|
9
|
+
* the run is blind, and blind on day 0 is a run that measured nothing.
|
|
10
|
+
*
|
|
11
|
+
* Until 2026-09-11 the consequence was worse than blind — `planSpawn` refused
|
|
12
|
+
* the whole spawn on the missing key, so an EMPTY file stopped the clock, the
|
|
13
|
+
* sleep cycle and the day's ask cap as well (I32). The worker degrades one step
|
|
14
|
+
* at a time now; this file is still the thing that keeps it from having to.
|
|
15
|
+
*
|
|
16
|
+
* §2.18 is also the FIX, not just the diagnosis. The scar says a guarantee
|
|
17
|
+
* carried by something you don't own is not a guarantee, and the CONTRACT's
|
|
18
|
+
* rule is "credentials come from one configured source the package owns". A
|
|
19
|
+
* file whose PATH IS NAMED IN THIS PACKAGE'S OWN CONFIG is that source. v1's
|
|
20
|
+
* `.env`-found-by-convention is not, and stays forbidden: convention means the
|
|
21
|
+
* process's working directory decides which credential a run uses, which is the
|
|
22
|
+
* same class of mistake as inheriting one from whatever shell launched it.
|
|
23
|
+
*
|
|
24
|
+
* The rules this file mechanizes:
|
|
25
|
+
*
|
|
26
|
+
* - **The environment stays the FIRST source; the file fills the gap.** A
|
|
27
|
+
* name already answered in `env` is never overwritten — so an owner who
|
|
28
|
+
* does have the variable exported keeps exactly the behaviour they had, and
|
|
29
|
+
* the file cannot silently redirect a live session to another account.
|
|
30
|
+
* - **Only the two documented names are honored** (`API_KEY_ENV`,
|
|
31
|
+
* `EMBED_KEY_ENV`). Anything else in the file is ignored and COUNTED, so a
|
|
32
|
+
* file the owner filled with a third name reads as "1 ignored" rather than
|
|
33
|
+
* as a general-purpose env loader nobody bounded.
|
|
34
|
+
* - **Values are never logged, never emitted, never hashed.** Everything that
|
|
35
|
+
* leaves this module is a NAME or a COUNT. The only place a value goes is
|
|
36
|
+
* `env[name]`.
|
|
37
|
+
* - **It never throws.** An absent file is ordinary; an unreadable one is a
|
|
38
|
+
* named reason. Neither may fail a hook (CONTRACT §5 G2).
|
|
39
|
+
*/
|
|
40
|
+
import { readFileSync, statSync } from "node:fs";
|
|
41
|
+
|
|
42
|
+
import { API_KEY_ENV, EMBED_KEY_ENV } from "./config.js";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The ONLY names this file honors. Two, because the package documents two — a
|
|
46
|
+
* loader that honored whatever it found would be an inherited environment with
|
|
47
|
+
* extra steps.
|
|
48
|
+
*/
|
|
49
|
+
export const CREDENTIAL_NAMES: readonly string[] = [API_KEY_ENV, EMBED_KEY_ENV];
|
|
50
|
+
|
|
51
|
+
/** The event the entry points emit when the file actually answered. */
|
|
52
|
+
export const CREDENTIAL_FILE_EVENT = "adapter.credentials.file";
|
|
53
|
+
|
|
54
|
+
export interface CredentialLoad {
|
|
55
|
+
/** Names this load filled FROM THE FILE. Names only — never values. */
|
|
56
|
+
readonly loaded: string[];
|
|
57
|
+
/** Names the file offered and `env` had already answered. The env wins. */
|
|
58
|
+
readonly skippedPresent: string[];
|
|
59
|
+
/** Lines that produced no credential: foreign names, malformed lines, empty
|
|
60
|
+
* values, and repeats of a name already taken. Blank and `#` lines are not
|
|
61
|
+
* counted — they are not attempts at anything. */
|
|
62
|
+
readonly ignoredLines: number;
|
|
63
|
+
readonly reason: "absent" | "unreadable" | "loaded" | "not-configured";
|
|
64
|
+
/** The file's permission bits, octal (e.g. `"600"`). Null when unread. */
|
|
65
|
+
readonly mode: string | null;
|
|
66
|
+
/** True when group or other may READ this file. Reported, never refused: it
|
|
67
|
+
* is the owner's machine and their call (§4 warn, do not refuse). */
|
|
68
|
+
readonly permissive: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const nothing = (reason: CredentialLoad["reason"]): CredentialLoad => ({
|
|
72
|
+
loaded: [],
|
|
73
|
+
skippedPresent: [],
|
|
74
|
+
ignoredLines: 0,
|
|
75
|
+
reason,
|
|
76
|
+
mode: null,
|
|
77
|
+
permissive: false,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/** Present means NON-EMPTY, the same test every reader of these two names makes
|
|
81
|
+
* (`interpret-client`, `embed-client`, `planSpawn` all `.trim()`). An exported
|
|
82
|
+
* but empty variable is a gap the file may fill, not an answer. */
|
|
83
|
+
function answered(value: string | undefined): boolean {
|
|
84
|
+
return value !== undefined && value.trim().length > 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Strip one layer of matching quotes, tolerating the shapes a human actually
|
|
89
|
+
* writes: `KEY=v`, `KEY="v"`, `KEY='v'`, `export KEY=v`, and any of them with a
|
|
90
|
+
* CR still attached from a CRLF file.
|
|
91
|
+
*/
|
|
92
|
+
function unquote(raw: string): string {
|
|
93
|
+
const value = raw.trim();
|
|
94
|
+
if (value.length < 2) return value;
|
|
95
|
+
const first = value[0];
|
|
96
|
+
const last = value[value.length - 1];
|
|
97
|
+
if ((first === '"' || first === "'") && last === first) return value.slice(1, -1);
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Read the configured credential file and fill the gaps in `env`.
|
|
103
|
+
*
|
|
104
|
+
* Pure over the injected environment: it mutates `env` for the two documented
|
|
105
|
+
* names and touches nothing else, so a test hands it `{}` and reads the result
|
|
106
|
+
* rather than the process.
|
|
107
|
+
*/
|
|
108
|
+
export function loadCredentials(
|
|
109
|
+
path: string | undefined,
|
|
110
|
+
env: NodeJS.ProcessEnv,
|
|
111
|
+
): CredentialLoad {
|
|
112
|
+
if (path === undefined || path.trim().length === 0) return nothing("not-configured");
|
|
113
|
+
|
|
114
|
+
let text: string;
|
|
115
|
+
let mode: string | null = null;
|
|
116
|
+
let permissive = false;
|
|
117
|
+
try {
|
|
118
|
+
const stat = statSync(path);
|
|
119
|
+
mode = (stat.mode & 0o777).toString(8).padStart(3, "0");
|
|
120
|
+
permissive = (stat.mode & 0o077) !== 0;
|
|
121
|
+
text = readFileSync(path, "utf8");
|
|
122
|
+
} catch (err) {
|
|
123
|
+
// ENOENT is ORDINARY — an owner who exports the variables configures no
|
|
124
|
+
// file and never sees this. Anything else (a directory, a permission
|
|
125
|
+
// error, a device) is a different record: "we looked and could not read".
|
|
126
|
+
const code =
|
|
127
|
+
err !== null && typeof err === "object" && typeof (err as { code?: unknown }).code === "string"
|
|
128
|
+
? (err as { code: string }).code
|
|
129
|
+
: "";
|
|
130
|
+
return { ...nothing(code === "ENOENT" ? "absent" : "unreadable"), mode, permissive };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const loaded: string[] = [];
|
|
134
|
+
const skippedPresent: string[] = [];
|
|
135
|
+
let ignoredLines = 0;
|
|
136
|
+
|
|
137
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
138
|
+
const line = rawLine.trim();
|
|
139
|
+
if (line.length === 0 || line.startsWith("#")) continue;
|
|
140
|
+
const body = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
|
|
141
|
+
const eq = body.indexOf("=");
|
|
142
|
+
if (eq <= 0) {
|
|
143
|
+
ignoredLines += 1;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const name = body.slice(0, eq).trim();
|
|
147
|
+
const value = unquote(body.slice(eq + 1));
|
|
148
|
+
if (!CREDENTIAL_NAMES.includes(name)) {
|
|
149
|
+
// The bound, made countable: a third name in the file is not honored, and
|
|
150
|
+
// the count is how the owner sees that it was not.
|
|
151
|
+
ignoredLines += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (value.length === 0 || loaded.includes(name) || skippedPresent.includes(name)) {
|
|
155
|
+
// An empty value is not a credential (writing `""` would make the
|
|
156
|
+
// capability row say "reported" of nothing), and the FIRST occurrence of
|
|
157
|
+
// a name wins — a second line for the same name is ignored and counted.
|
|
158
|
+
ignoredLines += 1;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (answered(env[name])) {
|
|
162
|
+
// THE ENVIRONMENT WINS. The file fills gaps; it never redirects a session
|
|
163
|
+
// whose credential was already answered.
|
|
164
|
+
skippedPresent.push(name);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
env[name] = value;
|
|
168
|
+
loaded.push(name);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return { loaded, skippedPresent, ignoredLines, reason: "loaded", mode, permissive };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The one line a process says about a credential file, for the ring and for
|
|
176
|
+
* stderr. NAMES AND COUNTS ONLY — this string is emitted, so nothing that could
|
|
177
|
+
* carry a value may enter it.
|
|
178
|
+
*/
|
|
179
|
+
export function credentialRow(load: CredentialLoad): Record<string, string | number | boolean> {
|
|
180
|
+
return {
|
|
181
|
+
reason: load.reason,
|
|
182
|
+
loaded: load.loaded.join(","),
|
|
183
|
+
skipped: load.skippedPresent.join(","),
|
|
184
|
+
ignoredLines: load.ignoredLines,
|
|
185
|
+
mode: load.mode ?? "",
|
|
186
|
+
permissive: load.permissive,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The permission warning, or null. A file the group or the world can read is
|
|
192
|
+
* WARNED about by name and mode and never refused: it is the owner's machine,
|
|
193
|
+
* and a refusal here would be this package deciding a security policy for them
|
|
194
|
+
* (CONTRACT §5 G2 — and a throw would fail the host besides).
|
|
195
|
+
*/
|
|
196
|
+
export function permissionWarning(path: string | undefined, load: CredentialLoad): string | null {
|
|
197
|
+
if (!load.permissive || load.mode === null || path === undefined) return null;
|
|
198
|
+
return `[counterparts] credentials file is group/other-readable (mode ${load.mode}): ${path}`;
|
|
199
|
+
}
|