counterparts 0.3.13 → 0.3.15
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 +264 -0
- package/docs/QUICKSTART.md +22 -0
- package/docs/README.md +1 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/CONTRACT.md +48 -0
- package/src/adapters/claude-code/NOTES.md +148 -0
- package/src/adapters/claude-code/bin/hook.mjs +4 -2
- package/src/adapters/claude-code/bin/hook.ts +61 -7
- package/src/adapters/claude-code/bin/nightly.ts +5 -1
- package/src/adapters/claude-code/bin/runner.ts +11 -3
- package/src/adapters/claude-code/claim.ts +319 -0
- package/src/adapters/claude-code/doctor.ts +170 -16
- package/src/adapters/claude-code/embed-client.ts +3 -0
- package/src/adapters/cli/CONTRACT.md +5 -0
- package/src/adapters/cli/NOTES.md +25 -0
- package/src/adapters/cli/bin/counterparts.mjs +4 -2
- package/src/adapters/cli/bin/counterparts.ts +49 -3
- package/src/adapters/cli/commands.ts +169 -32
- package/src/adapters/cli/desktop.ts +112 -7
- package/src/adapters/cli/help.ts +10 -0
- package/src/adapters/cli/index.ts +1 -0
- package/src/adapters/cli/install.ts +94 -14
- package/src/adapters/cli/self-page.ts +5 -8
- package/src/adapters/cli/settle.ts +39 -2
- package/src/adapters/cli/wire.ts +18 -1
- package/src/adapters/config.ts +29 -1
- package/src/adapters/dashboard/NOTES.md +33 -0
- package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
- package/src/adapters/dashboard/bin/dashboard.ts +11 -3
- package/src/adapters/dashboard/index.ts +14 -0
- package/src/adapters/dashboard/registries.ts +3 -0
- package/src/adapters/dashboard/source.ts +0 -8
- package/src/adapters/dashboard/web/fired.ts +8 -0
- package/src/adapters/dashboard/web/flow.ts +1 -0
- package/src/adapters/dashboard/web/lanes.ts +1 -0
- package/src/adapters/dashboard/web/narrate.ts +11 -0
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
- package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
- package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
- package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
- package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
- package/src/adapters/dashboard/web/server.ts +16 -4
- package/src/adapters/dashboard/web/shared/dates.js +6 -16
- package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
- package/src/adapters/dashboard/web/views/health.ts +19 -5
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
- package/src/adapters/dashboard/web/views/memories.ts +26 -7
- package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
- package/src/adapters/dashboard/web/views/memory.ts +51 -2
- package/src/adapters/dashboard/web/views/mind.ts +38 -6
- package/src/adapters/empty-bunfig.toml +5 -0
- package/src/adapters/fired.ts +16 -2
- package/src/adapters/host-wiring.ts +112 -17
- package/src/adapters/log/index.ts +2 -2
- package/src/adapters/mcp/CONTRACT.md +17 -2
- package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
- package/src/adapters/mcp/NOTES.md +269 -0
- package/src/adapters/mcp/bin/serve.mjs +4 -2
- package/src/adapters/mcp/bin/serve.ts +17 -6
- package/src/adapters/mcp/facts.ts +72 -4
- package/src/adapters/mcp/meaning.ts +218 -15
- package/src/adapters/mcp/server.ts +21 -6
- package/src/adapters/mcp/tools.ts +86 -61
- package/src/adapters/plugin-run.sh +413 -34
- package/src/adapters/plugin.ts +141 -17
- package/src/adapters/runtime.ts +192 -17
- package/src/adapters/sessions.ts +2 -2
- package/src/core/associate/NOTES.md +10 -0
- package/src/core/bridge.ts +1 -1
- package/src/core/briefing.ts +20 -3
- package/src/core/contradictions.ts +56 -20
- package/src/core/counterpart.ts +72 -23
- package/src/core/dream/CONTRACT.md +6 -14
- package/src/core/dream/INTERFACE-GAPS.md +3 -2
- package/src/core/dream/NOTES.md +10 -0
- package/src/core/dream/index.ts +11 -53
- package/src/core/dream/reflect.ts +11 -2
- package/src/core/embed/static.ts +5 -1
- package/src/core/encode/INTERFACE-GAPS.md +2 -1
- package/src/core/encode/NOTES.md +12 -0
- package/src/core/encode/chunk.ts +6 -30
- package/src/core/encode/index.ts +0 -1
- package/src/core/encode/types.ts +1 -13
- package/src/core/handoff/INTERFACE-GAPS.md +1 -1
- package/src/core/handoff/index.ts +2 -1
- package/src/core/handoff/last-here.ts +18 -2
- package/src/core/physics/CONTRACT.md +6 -0
- package/src/core/physics/NOTES.md +33 -2
- package/src/core/physics/index.ts +22 -7
- package/src/core/prospective/CONTRACT.md +3 -1
- package/src/core/prospective/NOTES.md +15 -0
- package/src/core/recall/activate.ts +1 -1
- package/src/core/recall/time-ask.ts +173 -19
- package/src/core/self/CONTRACT.md +56 -19
- package/src/core/self/NOTES.md +172 -0
- package/src/core/self/behind.ts +6 -3
- package/src/core/self/briefing.ts +384 -28
- package/src/core/self/index.ts +105 -44
- package/src/core/self/page.ts +12 -85
- package/src/core/self/tunables.ts +16 -19
- package/src/core/self/writer.ts +31 -4
- package/src/core/sleep/NOTES.md +32 -0
- package/src/core/store/NOTES.md +21 -2
- package/src/core/store/index.ts +2 -1
- package/src/core/time.ts +15 -0
|
@@ -10,11 +10,13 @@ import { isConfidential } from "../../../../core/recall/index.js";
|
|
|
10
10
|
import {
|
|
11
11
|
FRAMING,
|
|
12
12
|
LANE_ORDER,
|
|
13
|
+
collapsedLane,
|
|
13
14
|
SELF_PAGE_REVISED_EVENT,
|
|
14
15
|
chapterModels,
|
|
15
16
|
dayBefore,
|
|
16
17
|
pageSections,
|
|
17
18
|
readChapterLead,
|
|
19
|
+
readPageTooLargeDetail,
|
|
18
20
|
} from "../../../../core/self/index.js";
|
|
19
21
|
import type { PageVersion, PageWriterRun, PageWriterStatus } from "../../../../core/self/index.js";
|
|
20
22
|
import { TUNABLES as SLEEP, coreContextFor, isJournal } from "../../../../core/sleep/index.js";
|
|
@@ -511,6 +513,11 @@ export function writerReason(detail: string): string {
|
|
|
511
513
|
if (known !== undefined) return known.why;
|
|
512
514
|
const exit = /^exit (\S+)$/.exec(d);
|
|
513
515
|
if (exit !== null) return `it stopped with an error (exit ${exit[1] as string})`;
|
|
516
|
+
// A page refused for length carries its numbers (review of #358).
|
|
517
|
+
const large = readPageTooLargeDetail(d);
|
|
518
|
+
if (large !== null) {
|
|
519
|
+
return `the page it sent was ${String(large.bytes)} bytes, ${String(large.over)} over the ${String(large.limit)}-byte limit${large.then === "" ? "" : `, and was ${large.then}`}`;
|
|
520
|
+
}
|
|
514
521
|
return d.replace(/[-_]+/g, " ");
|
|
515
522
|
}
|
|
516
523
|
|
|
@@ -520,6 +527,7 @@ function writerNext(detail: string, lastNight: boolean): string | null {
|
|
|
520
527
|
const known = WRITER_REASON[d];
|
|
521
528
|
if (known !== undefined) return known.next === undefined ? null : known.next(lastNight);
|
|
522
529
|
if (/^exit \S+$/.test(d)) return TONIGHT;
|
|
530
|
+
if (readPageTooLargeDetail(d) !== null) return TONIGHT;
|
|
523
531
|
return null;
|
|
524
532
|
}
|
|
525
533
|
|
|
@@ -716,13 +724,17 @@ function pageHistory(src: DashboardSource, page: ReturnType<DashboardSource["sel
|
|
|
716
724
|
const pageId = page?.id ?? null;
|
|
717
725
|
const zone = src.store.zone();
|
|
718
726
|
try {
|
|
727
|
+
// NEWEST first (2026-10-09, audit #1's last caller): past `LOG_LIMIT` an
|
|
728
|
+
// ascending read kept the oldest rows, and the newest versions — the ones
|
|
729
|
+
// the timeline ends on — lost their dates. The first row seen for a version
|
|
730
|
+
// is its newest, as the last one seen was when this read ascended.
|
|
719
731
|
const rows = pageId === null
|
|
720
|
-
? src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, limit: LOG_LIMIT })
|
|
721
|
-
: src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, ref: pageId, limit: LOG_LIMIT });
|
|
732
|
+
? src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, order: "desc", limit: LOG_LIMIT })
|
|
733
|
+
: src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, ref: pageId, order: "desc", limit: LOG_LIMIT });
|
|
722
734
|
for (const row of rows) {
|
|
723
735
|
const payload = JSON.parse(row.payload ?? "{}") as Record<string, unknown>;
|
|
724
736
|
const v = payload["version"];
|
|
725
|
-
if (typeof v === "number") {
|
|
737
|
+
if (typeof v === "number" && !at.has(v)) {
|
|
726
738
|
at.set(v, row.at);
|
|
727
739
|
onDay.set(v, row.day);
|
|
728
740
|
}
|
|
@@ -762,7 +774,8 @@ function pageHistory(src: DashboardSource, page: ReturnType<DashboardSource["sel
|
|
|
762
774
|
return steps;
|
|
763
775
|
}
|
|
764
776
|
|
|
765
|
-
|
|
777
|
+
/** Rows the page's history and its day strip read per event name, newest first. */
|
|
778
|
+
export const LOG_LIMIT = 2_000;
|
|
766
779
|
|
|
767
780
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
768
781
|
// the page's history as one strip of lived days (round 3b, item 1)
|
|
@@ -839,9 +852,12 @@ function pageDays(src: DashboardSource, history: readonly PageStep[]): { pageDay
|
|
|
839
852
|
// records the calendar date it closed.
|
|
840
853
|
const cycleDate = new Map<number, string>();
|
|
841
854
|
try {
|
|
842
|
-
|
|
855
|
+
// NEWEST first, so past `LOG_LIMIT` it is the oldest days that go undated,
|
|
856
|
+
// not today's (one row per session end; 2026-10-09). Each day keeps its
|
|
857
|
+
// OLDEST row's date, as before: the last one seen wins.
|
|
858
|
+
for (const row of src.store.eventLog({ name: "sleep.cycle", sinceDay: first, order: "desc", limit: LOG_LIMIT })) {
|
|
843
859
|
const date = (JSON.parse(row.payload ?? "{}") as Record<string, unknown>)["date"];
|
|
844
|
-
if (typeof date === "string" && isIsoDay(date)
|
|
860
|
+
if (typeof date === "string" && isIsoDay(date)) cycleDate.set(row.day, date);
|
|
845
861
|
}
|
|
846
862
|
} catch {
|
|
847
863
|
/* undated days stay undated */
|
|
@@ -1125,6 +1141,14 @@ export function wakeParts(text: string, hasPage: boolean): WakePart[] {
|
|
|
1125
1141
|
add("furniture", n);
|
|
1126
1142
|
return;
|
|
1127
1143
|
}
|
|
1144
|
+
// A lane that listed nothing is ONE line, its heading inside it
|
|
1145
|
+
// (`self/briefing.ts#collapsedLine`, 2026-10-09): it is that lane's.
|
|
1146
|
+
const collapsed = collapsedLane(line);
|
|
1147
|
+
if (collapsed !== null) {
|
|
1148
|
+
current = collapsed;
|
|
1149
|
+
add(collapsed, n);
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1128
1152
|
if (line.startsWith("<!--") || line === FRAMING.context) {
|
|
1129
1153
|
add("furniture", n);
|
|
1130
1154
|
return;
|
|
@@ -1435,6 +1459,14 @@ export function wakeLanes(text: string): WakeLane[] {
|
|
|
1435
1459
|
if (line.startsWith("<!--")) continue;
|
|
1436
1460
|
if (line.length === 0) continue;
|
|
1437
1461
|
const lane = headings.get(line);
|
|
1462
|
+
// A lane that listed nothing is one line with its heading inside it
|
|
1463
|
+
// (`self/briefing.ts#collapsedLine`, 2026-10-09): that lane, that one item.
|
|
1464
|
+
const collapsed = collapsedLane(line);
|
|
1465
|
+
if (collapsed !== null) {
|
|
1466
|
+
if (current.items.length > 0) lanes.push(current);
|
|
1467
|
+
current = { heading: FRAMING[collapsed], lane: collapsed, items: [line.slice(FRAMING[collapsed].length).trim()] };
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1438
1470
|
// A markdown heading counts too, so a future briefing that uses one still
|
|
1439
1471
|
// splits rather than collapsing into a single block.
|
|
1440
1472
|
const mdHeading = /^#{1,6}\s+(.*)$/.exec(line);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Deliberately empty. Every Bun launch Counterparts makes passes
|
|
2
|
+
# --config=<this file>, so Bun reads this instead of the bunfig.toml in the
|
|
3
|
+
# folder it starts in (the person's project), whose `preload` would otherwise
|
|
4
|
+
# run inside the hooks and the memory server. adapters/runtime.ts says why.
|
|
5
|
+
# Installed commands name this path: it must stay, and stay empty.
|
package/src/adapters/fired.ts
CHANGED
|
@@ -723,8 +723,12 @@ export const MECHANISMS: readonly Mechanism[] = [
|
|
|
723
723
|
// reminder date that still comes round, kept for its next occurrence —
|
|
724
724
|
// and physics names it only where the floor would otherwise have let the
|
|
725
725
|
// memory go (review of #341), or every pill reminder would read as a
|
|
726
|
-
// refusal every night.
|
|
727
|
-
//
|
|
726
|
+
// refusal every night. `protected` is named on the same terms (2026-10-09):
|
|
727
|
+
// the self page is born protected, and counting it every night read
|
|
728
|
+
// "BLOCKED: protected ×8" on a store too young for anything to be at the
|
|
729
|
+
// floor. `in-live-revision-chain` too (review of #343): a row under challenge
|
|
730
|
+
// pressure was counted every night it stayed so. All three are a rule
|
|
731
|
+
// refusing a memory that qualified, and only that. `above-floor`,
|
|
728
732
|
// `dwell-too-short` and `band-not-episodic`
|
|
729
733
|
// are the ordinary condition of almost every memory on almost every night —
|
|
730
734
|
// the reviewer measured `dwell-too-short ×240` on a healthy forty-memory
|
|
@@ -1060,6 +1064,16 @@ export const MECHANISMS: readonly Mechanism[] = [
|
|
|
1060
1064
|
names: ["adapter.spawn.refused", "adapter.spawn.failed", "adapter.runner.failed"],
|
|
1061
1065
|
},
|
|
1062
1066
|
},
|
|
1067
|
+
{
|
|
1068
|
+
// 2026-10-09: two wirings of Counterparts both ran one event, and the per-event
|
|
1069
|
+
// claim kept the second from delivering. Silent whenever there is one wiring.
|
|
1070
|
+
id: "hook-claim",
|
|
1071
|
+
label: "a second Counterparts hook found its event already taken, and said nothing",
|
|
1072
|
+
module: "claude-code/claim.ts",
|
|
1073
|
+
cadence: { kind: "occasion", when: "two Counterparts installs run the same hook at once" },
|
|
1074
|
+
evidence: { kind: "event", names: ["adapter.hook.claim.lost"] },
|
|
1075
|
+
since: "2026-10-09",
|
|
1076
|
+
},
|
|
1063
1077
|
{
|
|
1064
1078
|
id: "checkout",
|
|
1065
1079
|
label: "which copy of the code the hooks were actually running",
|
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
* hook and the MCP server both need the answer, and adapters are leaves that
|
|
19
19
|
* never import each other (`mcp/INTERFACE-GAPS.md` §7). `isOurHookCommand`
|
|
20
20
|
* moved here from `wire.ts` on 2026-10-09 for that reason and `wire.ts`
|
|
21
|
-
* re-exports it unchanged
|
|
22
|
-
*
|
|
21
|
+
* re-exports it unchanged. It is the WRITER's question and stays strict; the
|
|
22
|
+
* stand-down reads with `readOurHook`, which recognises the hook by its
|
|
23
|
+
* script whatever flags surround it, because the plugin reading the settings
|
|
24
|
+
* may be older or newer than the `connect` that wrote them.
|
|
23
25
|
*
|
|
24
26
|
* WHERE CLAUDE CODE KEEPS THEM, measured against 2.1.295 on 2026-10-09 (a
|
|
25
27
|
* throwaway HOME, `--debug-file` naming every settings path it read):
|
|
@@ -33,13 +35,16 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
33
35
|
import { isAbsolute, join, resolve } from "node:path";
|
|
34
36
|
|
|
35
37
|
import { CONFIG_FLAG } from "./config-path.js";
|
|
36
|
-
import { parseScriptInvocation, runtimePresent, shellTokens } from "./runtime.js";
|
|
38
|
+
import { BUN_CONFIG_PREFIX, BUN_NO_ENV_FILE, isBinaryName, parseScriptInvocation, runtimeOf, runtimePresent, shellTokens } from "./runtime.js";
|
|
37
39
|
|
|
38
40
|
/** The name `counterparts connect` registers the server under
|
|
39
41
|
* (`cli/install.ts#MCP_SERVER_NAME`), spelled again because this module may
|
|
40
42
|
* not import the console. `test/plugin.test.ts` holds the two equal. */
|
|
41
43
|
export const NPM_MCP_NAME = "counterparts";
|
|
42
44
|
|
|
45
|
+
/** Anything that makes a command line more than one program run. */
|
|
46
|
+
const SHELL_OPERATOR = /&&|\|\||;|\||>|<|`|\$\(/;
|
|
47
|
+
|
|
43
48
|
/**
|
|
44
49
|
* IS THIS COMMAND OURS TO REWRITE — which is a stricter question than "does it
|
|
45
50
|
* mention us" (review m1).
|
|
@@ -68,7 +73,7 @@ export const NPM_MCP_NAME = "counterparts";
|
|
|
68
73
|
*/
|
|
69
74
|
export function isOurHookCommand(command: string): boolean {
|
|
70
75
|
// A shell operator means the line does something besides run our hook.
|
|
71
|
-
if (
|
|
76
|
+
if (SHELL_OPERATOR.test(command)) return false;
|
|
72
77
|
const tokens = shellTokens(command);
|
|
73
78
|
if (tokens.length === 0) return false;
|
|
74
79
|
const tail = (from: number): boolean => {
|
|
@@ -79,15 +84,102 @@ export function isOurHookCommand(command: string): boolean {
|
|
|
79
84
|
const first = tokens[0] ?? "";
|
|
80
85
|
// The installed shim, by itself.
|
|
81
86
|
if (/(^|[/\\])counterparts-hook$/.test(first)) return tail(1);
|
|
82
|
-
// `<runtime> run <our hook script>`,
|
|
83
|
-
// `<runtime> --import <node-hooks.mjs> <our hook script
|
|
87
|
+
// `<runtime> run <our hook script>`, Node's
|
|
88
|
+
// `<runtime> --import <node-hooks.mjs> <our hook script>`, or the single
|
|
89
|
+
// binary's `<binary> hook` (`runtime.ts`).
|
|
84
90
|
const run = parseScriptInvocation(tokens);
|
|
85
|
-
if (run !== null && /claude-code[/\\]bin[/\\]hook\.ts$/.test(run.script)) {
|
|
91
|
+
if (run !== null && (run.mode === "hook" || (run.mode === undefined && /claude-code[/\\]bin[/\\]hook\.ts$/.test(run.script)))) {
|
|
86
92
|
return tail(tokens.length - run.rest.length);
|
|
87
93
|
}
|
|
88
94
|
return false;
|
|
89
95
|
}
|
|
90
96
|
|
|
97
|
+
/** Our hook's entry by its path, as a runtime's script: the TypeScript entry
|
|
98
|
+
* or its `.mjs` shim. (The installed `counterparts-hook` shim runs itself,
|
|
99
|
+
* so it is read only as the command's first token.) Anchored at
|
|
100
|
+
* `adapters/`, where the entry has lived since it was written (review of
|
|
101
|
+
* #355): a bare `claude-code/bin/hook.ts` is a path any tool with a Claude
|
|
102
|
+
* Code adapter may have, and this reading accepts any runtime before it —
|
|
103
|
+
* `tsx`, `deno run`, `node` — so a match here stands the plugin down. */
|
|
104
|
+
const HOOK_ENTRY = /(^|[/\\])adapters[/\\]claude-code[/\\]bin[/\\]hook\.(ts|mjs)$/;
|
|
105
|
+
|
|
106
|
+
/** Our hook command, read for WHAT IT RUNS (`readOurHook`). */
|
|
107
|
+
export interface OurHookRead {
|
|
108
|
+
/** `shim`: `counterparts-hook` by itself. `binary`: `<binary> hook`.
|
|
109
|
+
* `script`: a runtime given our hook entry. */
|
|
110
|
+
readonly shape: "shim" | "binary" | "script";
|
|
111
|
+
readonly exe: string;
|
|
112
|
+
/** The file that must be on disk for it to run: the shim, the binary, or
|
|
113
|
+
* the hook entry the runtime is given. */
|
|
114
|
+
readonly script: string;
|
|
115
|
+
/** Whether the runtime reads the project's `.env` or `bunfig.toml`
|
|
116
|
+
* (`runtime.ts#ScriptInvocation.projectEnv`, by the same rule). */
|
|
117
|
+
readonly projectEnv: "read" | "ignored";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* IS THIS COMMAND OUR HOOK — read by its SCRIPT, so a reader from one version
|
|
122
|
+
* recognises what another version wrote (2026-10-09).
|
|
123
|
+
*
|
|
124
|
+
* The question the plugin's stand-down and `doctor` ask is not
|
|
125
|
+
* `isOurHookCommand`'s ("may `connect` rewrite this line?") but "does this
|
|
126
|
+
* line run our hook?". They were answered by the same strict parser, and it
|
|
127
|
+
* returns null for any Bun flag it does not know: 0.3.14's `connect` wrote
|
|
128
|
+
* `"<bun>" --no-env-file "--config=<…>" run "<…/hook.ts>"`, a plugin built
|
|
129
|
+
* before those two flags existed did not read that as the npm wiring, did not
|
|
130
|
+
* stand down, and every session got two wakes and two recall blocks per
|
|
131
|
+
* prompt. The next flag would have done it again to every plugin out there.
|
|
132
|
+
*
|
|
133
|
+
* So this reads the shape, not the vocabulary: `<exe>`, any number of flags
|
|
134
|
+
* (a token starting with `-`; Node's `--import` takes the next token as its
|
|
135
|
+
* value), at most one `run`, more flags, and then the FIRST other token is the
|
|
136
|
+
* script — ours when its path ends in our hook entry (`claude-code/bin/hook.ts`
|
|
137
|
+
* or its `.mjs` shim). Whatever follows the script is the script's own
|
|
138
|
+
* arguments. Also `counterparts-hook` itself, and the single binary's
|
|
139
|
+
* `<binary> [flags] hook`. Any shell operator
|
|
140
|
+
* refuses the line, exactly as for a rewrite: a wrapper runs something else
|
|
141
|
+
* too, and is somebody's own line (review m1).
|
|
142
|
+
*
|
|
143
|
+
* WRITERS, THEREFORE: a future flag must be ONE token (`--name` or
|
|
144
|
+
* `--name=value`). A flag whose value is a separate token would be read as
|
|
145
|
+
* the script by every older reader.
|
|
146
|
+
*/
|
|
147
|
+
export function readOurHook(command: string): OurHookRead | null {
|
|
148
|
+
if (SHELL_OPERATOR.test(command)) return null;
|
|
149
|
+
const tokens = shellTokens(command);
|
|
150
|
+
const exe = tokens[0] ?? "";
|
|
151
|
+
if (exe.length === 0) return null;
|
|
152
|
+
if (/(^|[/\\])counterparts-hook$/.test(exe)) return { shape: "shim", exe, script: exe, projectEnv: "ignored" };
|
|
153
|
+
let at = 1;
|
|
154
|
+
const isFlag = (t: string | undefined): boolean => t !== undefined && t.length > 1 && t.startsWith("-");
|
|
155
|
+
if (isBinaryName(exe)) {
|
|
156
|
+
while (isFlag(tokens[at])) at += 1;
|
|
157
|
+
return tokens[at] === "hook" ? { shape: "binary", exe, script: exe, projectEnv: "ignored" } : null;
|
|
158
|
+
}
|
|
159
|
+
let ran = false;
|
|
160
|
+
let noEnvFile = false;
|
|
161
|
+
let ownConfig = false;
|
|
162
|
+
for (; at < tokens.length; at += 1) {
|
|
163
|
+
const t = tokens[at] ?? "";
|
|
164
|
+
if (isFlag(t)) {
|
|
165
|
+
if (t === BUN_NO_ENV_FILE) noEnvFile = true;
|
|
166
|
+
if (t.startsWith(BUN_CONFIG_PREFIX) && t.length > BUN_CONFIG_PREFIX.length) ownConfig = true;
|
|
167
|
+
// Node's loader, `--import <node-hooks.mjs>`: the one flag we write
|
|
168
|
+
// whose value is its own token.
|
|
169
|
+
if (t === "--import") at += 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (t === "run" && !ran) {
|
|
173
|
+
ran = true;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (!HOOK_ENTRY.test(t)) return null;
|
|
177
|
+
const projectEnv = runtimeOf(exe) === "node" || (noEnvFile && ownConfig) ? "ignored" : "read";
|
|
178
|
+
return { shape: "script", exe, script: t, projectEnv };
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
91
183
|
/** Claude Code's two user-level files, wherever `CLAUDE_CONFIG_DIR` puts them. */
|
|
92
184
|
export function claudeUserFiles(
|
|
93
185
|
home: string,
|
|
@@ -141,17 +233,18 @@ function readObject(path: string): Record<string, unknown> | null {
|
|
|
141
233
|
|
|
142
234
|
/**
|
|
143
235
|
* Would this hook command actually run? The shim must be on PATH (or at the
|
|
144
|
-
* absolute path named)
|
|
145
|
-
* the
|
|
146
|
-
*
|
|
236
|
+
* absolute path named), and so must the single binary; a runtime given our
|
|
237
|
+
* hook entry needs both the runtime and the entry on disk. `env` is the hook
|
|
238
|
+
* process's own, which is the host's — the PATH that counts is the one the
|
|
239
|
+
* host will run the command with. Read by `readOurHook`, so a flag this build
|
|
240
|
+
* has never heard of does not make a live entry read as dead (a dead one is
|
|
241
|
+
* one nobody stands down for).
|
|
147
242
|
*/
|
|
148
243
|
export function hookCommandLive(command: string, env: Record<string, string | undefined>): boolean {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
if (run === null) return false;
|
|
154
|
-
return runtimePresent(run.exe, env) && existsSync(run.script);
|
|
244
|
+
const ours = readOurHook(command);
|
|
245
|
+
if (ours === null) return false;
|
|
246
|
+
if (ours.shape !== "script") return runtimePresent(ours.exe, env);
|
|
247
|
+
return runtimePresent(ours.exe, env) && existsSync(ours.script);
|
|
155
248
|
}
|
|
156
249
|
|
|
157
250
|
/** Every hook entry of ours in one settings object, by event. */
|
|
@@ -167,7 +260,9 @@ function hooksIn(file: string, settings: Record<string, unknown> | null, env: Re
|
|
|
167
260
|
for (const entry of group["hooks"] as unknown[]) {
|
|
168
261
|
if (!isRecord(entry)) continue;
|
|
169
262
|
const command = entry["command"];
|
|
170
|
-
|
|
263
|
+
// RUNS OUR HOOK, read tolerantly (`readOurHook`): whatever flags the
|
|
264
|
+
// version that wrote it put around the script.
|
|
265
|
+
if (typeof command !== "string" || readOurHook(command) === null) continue;
|
|
171
266
|
out.push({ file, event, command, live: hookCommandLive(command, env) });
|
|
172
267
|
}
|
|
173
268
|
}
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync } from "node:fs";
|
|
42
42
|
import { join, relative, resolve } from "node:path";
|
|
43
|
-
import { fileURLToPath } from "node:url";
|
|
44
43
|
|
|
45
44
|
import { assertSafeDataDir } from "../../core/store/index.js";
|
|
46
45
|
import { daysBetween, isDay, isoInstant, localDate, resolveZone } from "../../core/time.js";
|
|
47
46
|
import { SESSIONS_DIR } from "../sessions.js";
|
|
47
|
+
import { packagePath } from "../runtime.js";
|
|
48
48
|
|
|
49
49
|
/** The directory, inside `sessions/`. */
|
|
50
50
|
export const LOG_DIR = "log";
|
|
@@ -179,7 +179,7 @@ export function clean(data: Record<string, unknown> | undefined): Record<string,
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
/** This package's `src/`, for an error's top frame. */
|
|
182
|
-
const SRC_ROOT = resolve(
|
|
182
|
+
const SRC_ROOT = resolve(packagePath("src"));
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* An error as the log may write it: its class, its code, and the top source
|
|
@@ -542,7 +542,18 @@ Working defaults, held lightly; the revisit (a few days of daily use) checks the
|
|
|
542
542
|
bound does not stretch ("since" keeps a month's two days). A date is `2026-07-22`, `2026-07`, `7/22`
|
|
543
543
|
or `07-22` (month first), `7/22/2026`, "July 22", "22 July", "July 22, 2026"; a year
|
|
544
544
|
written with it is the year meant; without one, this year's when its month has begun,
|
|
545
|
-
else last year's ("before 1/5" asked on 01-03 is through this year's 01-04)
|
|
545
|
+
else last year's ("before 1/5" asked on 01-03 is through this year's 01-04) — except
|
|
546
|
+
that under "since" or "after" a day that has not come yet is last year's ("since 10/25"
|
|
547
|
+
asked on 10-03 runs from last year's 10-25; 2026-10-09), and under "before", "until"
|
|
548
|
+
or "by" it is the year, last, this or next, whose date is nearest today ("by 12/20"
|
|
549
|
+
asked on 10-09 is through this year's 12-20, review of #345; "by 1/5" asked on 12-28 is
|
|
550
|
+
through next year's 01-05, 2026-10-10; "until Dec 30" asked on 01-03 is still last
|
|
551
|
+
year's). An amount is not a date: a
|
|
552
|
+
`7-8` or `1/2` with a unit after it ("7-8 hours", "3/4 cup", "1/2 of it"), a price
|
|
553
|
+
("$5-10"), or a fraction after a word of quantity ("cut it by 1/2"; "finish by 1/2" is
|
|
554
|
+
still January 2); one written with a leading zero ("09-28 minutes") is a date. A range
|
|
555
|
+
of days or weeks ago ("3-4 days ago", "two or three weeks ago") covers both ends
|
|
556
|
+
(review of #345). "Around the X"
|
|
546
557
|
resolves X to the date of its best word match, shown in the header; "the last session"
|
|
547
558
|
is the session "Last here" names (else the newest here), whose rows lead.
|
|
548
559
|
- **[M]** Rebuilt here, not inherited from ambient: a chapter and its copy are one result
|
|
@@ -552,7 +563,11 @@ Working defaults, held lightly; the revisit (a few days of daily use) checks the
|
|
|
552
563
|
- **[M]** Each result: title and id; `you said / I said / inferred · status · happened <date>
|
|
553
564
|
| no event date`; `learned <date> in <dir> · <who> · CURRENT`; earlier versions folded
|
|
554
565
|
(in-place `versions`, and `changed` pairs — an earlier one that matched brings its
|
|
555
|
-
current one in); corrected ones
|
|
566
|
+
current one in); corrected ones never results, but named under the one that corrected
|
|
567
|
+
them — `corrected (was wrong): "…" (learned <date>), corrected <date> · mem_…`, the
|
|
568
|
+
ones the question's words reach first, then the latest, three at most and the rest
|
|
569
|
+
counted (2026-10-09: archived, a corrected memory is out of the word index, and a wrong
|
|
570
|
+
correction made a true one unreachable); `open` and unsettled pairs named —
|
|
556
571
|
never naming a confidential or removed memory to a non-owner.
|
|
557
572
|
Unknown fields say so. Short bodies whole, long ones a 300-character excerpt.
|
|
558
573
|
- **[M]** The header counts distinct facts; "may not be everything" only when the meaning
|
|
@@ -347,7 +347,21 @@ writes through `self_page`, which takes no settle; if it settles through `note`,
|
|
|
347
347
|
trail says the launching session. A `settle` on `self_page`, or a page-writer claim on
|
|
348
348
|
`note`, would close it — neither is built until the writer is seen wanting one.
|
|
349
349
|
|
|
350
|
-
## 12. Nobody reads how often the update guard fires —
|
|
350
|
+
## 12. Nobody reads how often the update guard fires — CLOSED 2026-10-09
|
|
351
|
+
|
|
352
|
+
**Closed the same day.** Doctor's Contradictions line reads `heldCorrections` over its
|
|
353
|
+
seven lived days and says it plainly: "2 corrections held because they didn't look
|
|
354
|
+
related to the memory they named, 1 settled by hand since; if the other was meant, settle
|
|
355
|
+
it with counterparts settle, which lists it". The finding's data carries `held`,
|
|
356
|
+
`heldSettledAfter`, `heldByMeaning` and `heldByWords`, so `settledAfter / held` can be
|
|
357
|
+
watched from `doctor --json`. It stays green: a hold is the guard working.
|
|
358
|
+
`counterparts settle` lists the week's holds nobody settled since (`heldPairs`, the same
|
|
359
|
+
read, newest first), each with its two ids and the `--holds <new> --against <old>` command,
|
|
360
|
+
because a hold writes no pair for `--pair` to name. Proof: `test/contradictions.test.ts`
|
|
361
|
+
"doctor's Contradictions line counts the week's held corrections" and
|
|
362
|
+
`test/update-guard.test.ts`, through a real held `note`.
|
|
363
|
+
|
|
364
|
+
The gap as it was filed:
|
|
351
365
|
|
|
352
366
|
A held `updates` (`schemas/CONTRACT.md` §5 1b) leaves one durable `contradiction.held`
|
|
353
367
|
row: the two ids, the `how`, which reading decided (`meaning` or `words`), the cosine and
|