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
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
NOTICE_DROPPED_EVENT,
|
|
49
49
|
GATE_CHUNK_EVENT,
|
|
50
50
|
GATE_DEPOSIT_EVENT,
|
|
51
|
+
HOOK_CLAIM_LOST_EVENT,
|
|
51
52
|
MCP_OVERSIZE_EVENT,
|
|
52
53
|
MCP_PART_EVENT,
|
|
53
54
|
MCP_SPILLED_EVENT,
|
|
@@ -74,7 +75,8 @@ import {
|
|
|
74
75
|
preMigrationDir,
|
|
75
76
|
} from "../../core/store/index.js";
|
|
76
77
|
import { BUSY_TIMEOUT_MS, journalModeOf } from "../../core/store/db.js";
|
|
77
|
-
import {
|
|
78
|
+
import { heldCorrections } from "../../core/contradictions.js";
|
|
79
|
+
import { CLI_SCRIPT, NODE_HOOKS, bundledModelDir } from "../runtime.js";
|
|
78
80
|
import { acceptsReflectedFeeling, laterFeelingWasAwake, laterFeelingWasReflections, selfRelevantFeeling } from "../../core/sleep/index.js";
|
|
79
81
|
import { TUNABLES as ASSOCIATE_TUNABLES, isDead, pairKey } from "../../core/associate/index.js";
|
|
80
82
|
import type { EventRow } from "../../core/store/index.js";
|
|
@@ -1227,7 +1229,8 @@ function staticFinding(input: DoctorInput, data: Record<string, string | number
|
|
|
1227
1229
|
{ ...data, kind: "static", weights: str(row, "weights") },
|
|
1228
1230
|
);
|
|
1229
1231
|
}
|
|
1230
|
-
const
|
|
1232
|
+
const bundled = bundledModelDir();
|
|
1233
|
+
const found = resolveStaticWeights(bundled === undefined ? {} : { packageDir: bundled });
|
|
1231
1234
|
// THE TABLE FILE, not just a folder: a `COUNTERPARTS_STATIC_WEIGHTS_DIR`
|
|
1232
1235
|
// naming an empty or wrong folder is found by name and holds nothing, and a
|
|
1233
1236
|
// green here would last until the first worker row said NO_WEIGHTS.
|
|
@@ -2781,6 +2784,25 @@ export function recognitionLaneFindings(store: Store): Finding[] {
|
|
|
2781
2784
|
/** The lived days the Contradictions line covers. */
|
|
2782
2785
|
export const CONTRADICTION_WINDOW_DAYS = 7;
|
|
2783
2786
|
|
|
2787
|
+
/**
|
|
2788
|
+
* The Contradictions line's held part, plainly: "; 2 corrections held because
|
|
2789
|
+
* they didn't look related to the memory they named; if any were meant,
|
|
2790
|
+
* settle them with counterparts settle, which lists them". Empty when nothing
|
|
2791
|
+
* was held. Those settled by hand since are counted, and the pointer is only
|
|
2792
|
+
* for the ones still held — most are a wrong pointer caught, which needs nothing.
|
|
2793
|
+
*/
|
|
2794
|
+
export function heldLine(held: number, settledAfter: number): string {
|
|
2795
|
+
if (held <= 0) return "";
|
|
2796
|
+
const one = held === 1;
|
|
2797
|
+
const left = held - settledAfter;
|
|
2798
|
+
const head = `; ${String(held)} ${one ? "correction" : "corrections"} held because ${one ? "it" : "they"} didn't look related to the memory ${one ? "it" : "they"} named`;
|
|
2799
|
+
if (left <= 0) return `${head}, ${one ? "settled" : "all settled"} by hand since`;
|
|
2800
|
+
const since = settledAfter > 0 ? `, ${String(settledAfter)} settled by hand since` : "";
|
|
2801
|
+
const them = left === 1 ? "it" : "them";
|
|
2802
|
+
const was = left > 1 ? "any were" : one ? "it was" : held === 2 ? "the other was" : "the one left was";
|
|
2803
|
+
return `${head}${since}; if ${was} meant, settle ${them} with counterparts settle, which lists ${them}`;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2784
2806
|
/**
|
|
2785
2807
|
* CONTRADICTIONS, informational (2026-09-29): over the last
|
|
2786
2808
|
* `CONTRADICTION_WINDOW_DAYS` lived days, how many pairs were flagged, how
|
|
@@ -2826,14 +2848,28 @@ export function contradictionFindings(store: Store): Finding[] {
|
|
|
2826
2848
|
.sort((a, b) => b[1] - a[1])
|
|
2827
2849
|
.map(([k, n]) => `${k === "owner" ? "you" : k} ${String(n)}`)
|
|
2828
2850
|
.join(", ");
|
|
2851
|
+
// HELD CORRECTIONS (mcp INTERFACE-GAPS §12, closed 2026-10-09): a write that
|
|
2852
|
+
// said it changed or corrected a memory that looked unrelated was held, so
|
|
2853
|
+
// nothing was settled. Informational, like the rest of this line: a hold is
|
|
2854
|
+
// the guard working. Unreadable, the line goes on without it.
|
|
2855
|
+
let heldWords = "";
|
|
2856
|
+
let heldData: Record<string, number> = { held: 0, heldSettledAfter: 0, heldByMeaning: 0, heldByWords: 0 };
|
|
2857
|
+
try {
|
|
2858
|
+
const h = heldCorrections(store, { sinceDay: since });
|
|
2859
|
+
heldData = { held: h.held, heldSettledAfter: h.settledAfter, heldByMeaning: h.byMeaning, heldByWords: h.byWords };
|
|
2860
|
+
heldWords = heldLine(h.held, h.settledAfter);
|
|
2861
|
+
} catch {
|
|
2862
|
+
// An event log this cannot read: the held count is left out, not guessed.
|
|
2863
|
+
}
|
|
2829
2864
|
return [
|
|
2830
2865
|
finding(
|
|
2831
2866
|
"contradictions",
|
|
2832
2867
|
"green",
|
|
2833
2868
|
"Contradictions",
|
|
2834
|
-
`last ${String(CONTRADICTION_WINDOW_DAYS)} lived days: ${String(flagged)} flagged, ${String(kept.length)} settled (${kinds})${kept.length > 0 ? ` by ${whoWords}` : ""}${undone > 0 ? `, ${String(undone)} undone` : ""}; standing: ${String(open)} open, ${String(unsettled)} unsettled${unsettled > 0 ? " (counterparts settle lists them)" : ""}`,
|
|
2869
|
+
`last ${String(CONTRADICTION_WINDOW_DAYS)} lived days: ${String(flagged)} flagged, ${String(kept.length)} settled (${kinds})${kept.length > 0 ? ` by ${whoWords}` : ""}${undone > 0 ? `, ${String(undone)} undone` : ""}; standing: ${String(open)} open, ${String(unsettled)} unsettled${unsettled > 0 ? " (counterparts settle lists them)" : ""}${heldWords}`,
|
|
2835
2870
|
"",
|
|
2836
2871
|
{
|
|
2872
|
+
...heldData,
|
|
2837
2873
|
flagged,
|
|
2838
2874
|
settled: kept.length,
|
|
2839
2875
|
changed: how["changed"] ?? 0,
|
|
@@ -3118,6 +3154,65 @@ const WAKE_WINDOW_DAYS = 7;
|
|
|
3118
3154
|
* notice dropped to keep the envelope under the cap, parts that waited for room (`adapter.envelope.gave-way`), a handoff
|
|
3119
3155
|
* or "Last here" line with no room, and "Work here" lines that did not fit.
|
|
3120
3156
|
*/
|
|
3157
|
+
/** How far back the `Installed twice` line looks, in lived days, and how many rows it reads. */
|
|
3158
|
+
const CLAIM_WINDOW_DAYS = 7;
|
|
3159
|
+
const CLAIM_ROWS = 500;
|
|
3160
|
+
|
|
3161
|
+
/**
|
|
3162
|
+
* INSTALLED TWICE, AND THE CLAIM HELD (2026-10-09, `claim.ts`). Silent unless a
|
|
3163
|
+
* hook stood down by claim inside the window: two wirings of Counterparts are
|
|
3164
|
+
* live in Claude Code, both ran an event, and the second to claim it delivered
|
|
3165
|
+
* nothing. The plugin stands down by itself when it can read the npm wiring
|
|
3166
|
+
* (`plugin.ts#hookGate`), so a row here means that reading failed — an older
|
|
3167
|
+
* plugin beside a newer `connect`, or two settings files naming two builds.
|
|
3168
|
+
* AMBER: nothing reached the session twice, but every event still starts two
|
|
3169
|
+
* hook processes, and the two builds' workers take turns at the store. One
|
|
3170
|
+
* bounded read of an indexed name.
|
|
3171
|
+
*/
|
|
3172
|
+
export function claimFindings(store: Store, plugin: PluginInstallRead | null = null): Finding[] {
|
|
3173
|
+
let rows: EventRow[];
|
|
3174
|
+
try {
|
|
3175
|
+
rows = store.eventLog({
|
|
3176
|
+
name: HOOK_CLAIM_LOST_EVENT,
|
|
3177
|
+
sinceDay: Math.max(0, store.livedDay() - (CLAIM_WINDOW_DAYS - 1)),
|
|
3178
|
+
order: "desc",
|
|
3179
|
+
limit: CLAIM_ROWS,
|
|
3180
|
+
});
|
|
3181
|
+
} catch {
|
|
3182
|
+
return [];
|
|
3183
|
+
}
|
|
3184
|
+
const newest = rows[0];
|
|
3185
|
+
if (newest === undefined) return [];
|
|
3186
|
+
const sides = new Set<string>();
|
|
3187
|
+
const hooks = new Set<string>();
|
|
3188
|
+
for (const row of rows) {
|
|
3189
|
+
const p = payloadOf(row);
|
|
3190
|
+
for (const side of [str(p, "lost"), str(p, "won")]) if (side !== null) sides.add(side);
|
|
3191
|
+
const hook = str(p, "hook");
|
|
3192
|
+
if (hook !== null) hooks.add(hook);
|
|
3193
|
+
}
|
|
3194
|
+
const who =
|
|
3195
|
+
sides.has("plugin") && sides.has("settings")
|
|
3196
|
+
? "the Claude Code plugin's hooks and the hooks in your settings"
|
|
3197
|
+
: sides.has("plugin")
|
|
3198
|
+
? "the Claude Code plugin's hooks, twice"
|
|
3199
|
+
: "two sets of hooks in your settings";
|
|
3200
|
+
const count = rows.length >= CLAIM_ROWS ? `${String(CLAIM_ROWS)}+` : String(rows.length);
|
|
3201
|
+
const fix = sides.has("plugin")
|
|
3202
|
+
? `Keep one: to keep only the plugin, run \`counterparts disconnect\` and restart Claude Code; to keep only the npm install, run \`claude plugin uninstall ${plugin?.id ?? "counterparts@<marketplace>"}\`. Same memory either way.`
|
|
3203
|
+
: "Keep one: remove the extra Counterparts hook lines from the project's .claude/settings.json or .claude/settings.local.json (or run `counterparts disconnect` and then `counterparts connect`), then restart Claude Code.";
|
|
3204
|
+
return [
|
|
3205
|
+
finding(
|
|
3206
|
+
"claim",
|
|
3207
|
+
"amber",
|
|
3208
|
+
"Installed twice",
|
|
3209
|
+
`two Counterparts wirings are live (${who}): ${count} hook ${rows.length === 1 ? "run" : "runs"} in the last ${String(CLAIM_WINDOW_DAYS)} days found the event already taken and stood down by claim, so nothing was delivered twice; newest ${localStamp(newest.at, store.zone())} (${[...hooks].sort().join(", ")})`,
|
|
3210
|
+
fix,
|
|
3211
|
+
{ stoodDown: rows.length, sides: [...sides].sort().join(","), hooks: [...hooks].sort().join(","), newestAt: newest.at },
|
|
3212
|
+
),
|
|
3213
|
+
];
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3121
3216
|
export function wakeArrivalFindings(store: Store): Finding[] {
|
|
3122
3217
|
const since = Math.max(0, store.livedDay() - WAKE_WINDOW_DAYS);
|
|
3123
3218
|
let wakes: EventRow[];
|
|
@@ -3754,13 +3849,17 @@ export function selfPageFindings(store: Store): Finding[] {
|
|
|
3754
3849
|
];
|
|
3755
3850
|
}
|
|
3756
3851
|
const stale = pageStaleOn(page.revisedOn, store.today(), SELF_TUNABLES.PAGE_STALE_DAYS);
|
|
3757
|
-
// WHAT THE WAKE SHOWS OF IT (2026-10-02, the "nobody saw it" review
|
|
3758
|
-
//
|
|
3759
|
-
//
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3852
|
+
// WHAT THE WAKE SHOWS OF IT (2026-10-02, the "nobody saw it" review; since
|
|
3853
|
+
// 2026-10-09 the wake never cuts the page). Every write since is held to
|
|
3854
|
+
// `PAGE_MAX_BYTES`, the page the wake prints whole at 9,000 bytes, so a page
|
|
3855
|
+
// past it was written before the limit. The wake still prints it whole when
|
|
3856
|
+
// it fits with the room held for "Work here" borrowed (review of #358), and
|
|
3857
|
+
// one line instead of it when even that is not enough. Amber either way,
|
|
3858
|
+
// and said with what to do: the next revision tightens it.
|
|
3859
|
+
const overLimit = page.bytes > SELF_TUNABLES.PAGE_MAX_BYTES;
|
|
3860
|
+
const wakeShows = overLimit
|
|
3861
|
+
? `; past the ${String(SELF_TUNABLES.PAGE_MAX_BYTES)}-byte limit, so the wake prints it whole only by borrowing the room held for "Work here", and says so in one line when even that is not enough (the self_page tool reads it whole)`
|
|
3862
|
+
: "";
|
|
3764
3863
|
const detail =
|
|
3765
3864
|
`${page.bytes} bytes, version ${page.version}, last revised ${page.revisedOn === "" ? "(unrecorded)" : page.revisedOn}` +
|
|
3766
3865
|
`${page.by === null ? "" : ` by ${page.by}`}${wakeShows}`;
|
|
@@ -3772,10 +3871,13 @@ export function selfPageFindings(store: Store): Finding[] {
|
|
|
3772
3871
|
version: page.version,
|
|
3773
3872
|
revisedOn: page.revisedOn,
|
|
3774
3873
|
stale,
|
|
3775
|
-
|
|
3874
|
+
// True when the wake prints it whole at 9,000 bytes whatever it reserves.
|
|
3875
|
+
wakeShowsAll: !overLimit,
|
|
3876
|
+
limit: SELF_TUNABLES.PAGE_MAX_BYTES,
|
|
3776
3877
|
daysSince: calendarDaysSince(page.revisedOn, store.today()),
|
|
3777
3878
|
staleAfter: SELF_TUNABLES.PAGE_STALE_DAYS,
|
|
3778
3879
|
};
|
|
3880
|
+
const shorten = `Its next revision has to come in under ${String(SELF_TUNABLES.PAGE_MAX_BYTES)} bytes: counterparts self-page --write, or the self_page tool.`;
|
|
3779
3881
|
return [
|
|
3780
3882
|
stale
|
|
3781
3883
|
? finding(
|
|
@@ -3783,10 +3885,12 @@ export function selfPageFindings(store: Store): Finding[] {
|
|
|
3783
3885
|
"amber",
|
|
3784
3886
|
"Self page",
|
|
3785
3887
|
`${detail} — stale (over ${SELF_TUNABLES.PAGE_STALE_DAYS} days)`,
|
|
3786
|
-
|
|
3888
|
+
`Nothing has revised it lately: check the page writer, or amend it yourself with counterparts self-page --write.${overLimit ? ` ${shorten}` : ""}`,
|
|
3787
3889
|
data,
|
|
3788
3890
|
)
|
|
3789
|
-
:
|
|
3891
|
+
: overLimit
|
|
3892
|
+
? finding("self-page", "amber", "Self page", detail, shorten, data)
|
|
3893
|
+
: finding("self-page", "green", "Self page", detail, "", data),
|
|
3790
3894
|
];
|
|
3791
3895
|
}
|
|
3792
3896
|
|
|
@@ -4250,9 +4354,14 @@ export interface HostReading {
|
|
|
4250
4354
|
* (`cli/install.ts#readHost`); absent when not read. */
|
|
4251
4355
|
readonly runtimes?: readonly {
|
|
4252
4356
|
readonly exe: string;
|
|
4253
|
-
|
|
4357
|
+
/** `binary`: the single compiled binary (`runtime.ts#Binary`). */
|
|
4358
|
+
readonly kind: "bun" | "node" | "binary";
|
|
4254
4359
|
readonly present: boolean;
|
|
4255
4360
|
readonly used: readonly string[];
|
|
4361
|
+
/** Of `used`, the commands that let Bun read the project's `.env` or
|
|
4362
|
+
* `bunfig.toml` (wired before `--no-env-file` and an empty `--config=`);
|
|
4363
|
+
* absent on a reading that predates the field. */
|
|
4364
|
+
readonly projectEnv?: readonly string[];
|
|
4256
4365
|
}[];
|
|
4257
4366
|
/** The runtime this console is running under (`runtime.ts#runtimeLabel`). */
|
|
4258
4367
|
readonly consoleRuntime?: string;
|
|
@@ -4261,6 +4370,19 @@ export interface HostReading {
|
|
|
4261
4370
|
readonly plugin?: PluginInstallRead | null;
|
|
4262
4371
|
}
|
|
4263
4372
|
|
|
4373
|
+
/** How a Runtime row names where a command was wired: `desktop` is Claude
|
|
4374
|
+
* Desktop's `counterparts` entry (`cli/install.ts#readHost`, 2026-10-10).
|
|
4375
|
+
* It is read after "the" ("the Claude Desktop server was wired…"), so no
|
|
4376
|
+
* possessive (review of #354). */
|
|
4377
|
+
function useLabel(use: string): string {
|
|
4378
|
+
return use === "desktop" ? "Claude Desktop server" : use;
|
|
4379
|
+
}
|
|
4380
|
+
|
|
4381
|
+
/** Claude Code's hooks and registration first, Claude Desktop's entry last. */
|
|
4382
|
+
function byUse(a: string, b: string): number {
|
|
4383
|
+
return Number(a === "desktop") - Number(b === "desktop") || a.localeCompare(b);
|
|
4384
|
+
}
|
|
4385
|
+
|
|
4264
4386
|
/**
|
|
4265
4387
|
* WHICH RUNTIME the host starts us with (2026-10-01, Node support): Bun or
|
|
4266
4388
|
* Node, read off the commands `install` wrote, and whether that executable is
|
|
@@ -4273,13 +4395,43 @@ export interface HostReading {
|
|
|
4273
4395
|
function runtimeFindings(reading: HostReading): Finding[] {
|
|
4274
4396
|
const rows = reading.runtimes ?? [];
|
|
4275
4397
|
if (rows.length === 0) return [];
|
|
4276
|
-
const said = rows
|
|
4398
|
+
const said = rows
|
|
4399
|
+
.map((r) => `${r.used.map(useLabel).join(" and ")} ${r.kind === "binary" ? "run as the single binary" : `run under ${r.kind}`} (${r.exe})`)
|
|
4400
|
+
.join("; ");
|
|
4401
|
+
// CLAUDE DESKTOP rewrites its own config file while it is open, so `connect`
|
|
4402
|
+
// leaves Desktop's entry alone until it is quit (`cli/desktop.ts#repairDesktop`):
|
|
4403
|
+
// any fix that has to reach that entry says so first.
|
|
4404
|
+
const quitDesktop = (uses: readonly string[]): string =>
|
|
4405
|
+
uses.includes("desktop") ? "Quit Claude Desktop first (it rewrites its config file while it runs). " : "";
|
|
4406
|
+
const reopenDesktop = (uses: readonly string[]): string => (uses.includes("desktop") ? " and reopen Claude Desktop" : "");
|
|
4277
4407
|
const console_ = reading.consoleRuntime === undefined ? "" : `; this console is ${reading.consoleRuntime}`;
|
|
4278
4408
|
const data: Record<string, string | number | boolean | null> = {
|
|
4279
4409
|
runtimes: rows.map((r) => `${r.kind}:${r.exe}:${r.present ? "present" : "missing"}`).join(","),
|
|
4280
4410
|
console: reading.consoleRuntime ?? null,
|
|
4281
4411
|
};
|
|
4282
4412
|
const missing = rows.filter((r) => !r.present);
|
|
4413
|
+
// WIRED BEFORE `--no-env-file` AND `--config=<empty-bunfig.toml>`
|
|
4414
|
+
// (2026-10-09): Bun loads the project's `.env` into every hook and server it
|
|
4415
|
+
// starts there, so a project could name another store, and runs its
|
|
4416
|
+
// `bunfig.toml` preload inside them. A command missing EITHER flag counts,
|
|
4417
|
+
// so one `connect` closes both. Amber, because it is a hole and not a fault:
|
|
4418
|
+
// everything still runs, and `connect` rewrites the commands (it repairs an
|
|
4419
|
+
// entry that is ours in an older shape).
|
|
4420
|
+
const readsEnv = rows.flatMap((r) => r.projectEnv ?? []);
|
|
4421
|
+
data["projectEnv"] = readsEnv.length === 0 ? "ignored" : [...new Set(readsEnv)].sort().join(",");
|
|
4422
|
+
if (missing.length === 0 && readsEnv.length > 0) {
|
|
4423
|
+
const what = [...new Set(readsEnv)].sort(byUse).map(useLabel).join(" and ");
|
|
4424
|
+
return [
|
|
4425
|
+
finding(
|
|
4426
|
+
"runtime",
|
|
4427
|
+
"amber",
|
|
4428
|
+
"Runtime",
|
|
4429
|
+
`${said}${console_}; the ${what} ${what.includes(" and ") ? "were" : "was"} wired before Counterparts told Bun to skip a project's .env and bunfig.toml, so a project whose .env sets COUNTERPARTS_DATA_DIR or COUNTERPARTS_CONFIG could point them at another memory, and its bunfig.toml could run its own code inside them`,
|
|
4430
|
+
`${quitDesktop(readsEnv)}Run: counterparts connect — it rewrites the commands with --no-env-file and an empty --config${readsEnv.includes("desktop") ? ", Claude Desktop's entry included" : ""}. Then restart Claude Code${reopenDesktop(readsEnv)}.`,
|
|
4431
|
+
data,
|
|
4432
|
+
),
|
|
4433
|
+
];
|
|
4434
|
+
}
|
|
4283
4435
|
if (missing.length === 0) return [finding("runtime", "green", "Runtime", `${said}${console_}`, "", data)];
|
|
4284
4436
|
return [
|
|
4285
4437
|
finding(
|
|
@@ -4290,7 +4442,7 @@ function runtimeFindings(reading: HostReading): Finding[] {
|
|
|
4290
4442
|
// `counterparts` itself runs under bun whenever bun is on PATH (the
|
|
4291
4443
|
// launcher prefers it), so "run it under the runtime you want" would be
|
|
4292
4444
|
// advice nobody can follow for Node. The explicit Node line is printed.
|
|
4293
|
-
|
|
4445
|
+
`${quitDesktop(missing.flatMap((r) => r.used))}Run: counterparts connect — it rewrites them with the runtime it runs under (bun when bun is on PATH, else Node). To wire Node with bun also installed: node --import "${NODE_HOOKS}" "${CLI_SCRIPT}" connect. Then restart Claude Code${reopenDesktop(missing.flatMap((r) => r.used))}.`,
|
|
4294
4446
|
data,
|
|
4295
4447
|
),
|
|
4296
4448
|
];
|
|
@@ -4697,6 +4849,8 @@ export function doctorFindings(input: DoctorInput): Finding[] {
|
|
|
4697
4849
|
["results", () => resultFindings(store)],
|
|
4698
4850
|
// 2026-10-02: whether the wake reached the session whole (`adapter.wake.delivered`).
|
|
4699
4851
|
["wake", () => wakeArrivalFindings(store)],
|
|
4852
|
+
// 2026-10-09: two wirings live, the second held off by the per-event claim.
|
|
4853
|
+
["claim", () => claimFindings(store, input.host?.plugin ?? null)],
|
|
4700
4854
|
// Association build 1 (2026-09-28): what spreading did, and the edges.
|
|
4701
4855
|
["association", () => associationFindings(store)],
|
|
4702
4856
|
// LAST, and deliberately: it is the widest read here — the whole event log,
|
|
@@ -22,6 +22,7 @@ import type { Embedder, EmbedderIdentity } from "../../core/store/index.js";
|
|
|
22
22
|
import { hashText } from "../../core/store/index.js";
|
|
23
23
|
|
|
24
24
|
import type { AdapterConfig, EmbedderKind } from "../config.js";
|
|
25
|
+
import { bundledModelDir } from "../runtime.js";
|
|
25
26
|
|
|
26
27
|
/** One fill's failure, named — what the worker's backfill row persists as `codes`. */
|
|
27
28
|
export interface ChunkFailure {
|
|
@@ -197,9 +198,11 @@ export function unavailableStaticEmbedder(code: string): LiveEmbedder {
|
|
|
197
198
|
*/
|
|
198
199
|
export function openStaticEmbedder(opts: StaticEmbedderOptions = {}): LiveEmbedder {
|
|
199
200
|
const emit = opts.onEvent ?? ((): void => {});
|
|
201
|
+
const bundled = bundledModelDir();
|
|
200
202
|
const found = resolveStaticWeights({
|
|
201
203
|
...(opts.weightsDir === undefined ? {} : { dir: opts.weightsDir }),
|
|
202
204
|
...(opts.env === undefined ? {} : { env: opts.env }),
|
|
205
|
+
...(bundled === undefined ? {} : { packageDir: bundled }),
|
|
203
206
|
});
|
|
204
207
|
if (found === null) {
|
|
205
208
|
emit("embed.refused", { code: "NO_WEIGHTS", kind: "static" });
|
|
@@ -636,6 +636,11 @@ or no entry in it; green with the last wake and the last Desktop session when th
|
|
|
636
636
|
amber only when the entry names another store, directly or through the Code tab's name clash
|
|
637
637
|
with `~/.claude.json`'s `counterparts`. `counterparts coverage` names a day's Desktop sessions
|
|
638
638
|
as unmeasured — never lost.
|
|
639
|
+
**[M]** `connect`, and `install` at a terminal, bring an entry of ours in an older shape up
|
|
640
|
+
to today's command (2026-10-10, `commands.ts#repairDesktopEntry`): only `command` and
|
|
641
|
+
`args` change, the store its `env` names is kept, the file is backed up first and written
|
|
642
|
+
whole, and nothing is written while Desktop is open or could not be ruled out — the person
|
|
643
|
+
is told to quit it and run `connect` again. The scripted install reads no host file.
|
|
639
644
|
|
|
640
645
|
## 7. Open questions
|
|
641
646
|
|
|
@@ -1997,3 +1997,28 @@ into my voice is mine.
|
|
|
1997
1997
|
only; in review it learned `hostSettingsDir` too, so with
|
|
1998
1998
|
`CLAUDE_CONFIG_DIR=~/.claude-work` an `--config` inside that directory is refused the
|
|
1999
1999
|
same way (`configDirRefusal`'s optional `env`, passed through `planUninstall`).
|
|
2000
|
+
|
|
2001
|
+
## 2026-10-10 — `install` at a terminal repairs Claude Desktop's entry too
|
|
2002
|
+
|
|
2003
|
+
#354 taught `connect` to rewrite Desktop's entry in today's shape and left `install` at a
|
|
2004
|
+
terminal, the other caller of `wire()`, without it. A person who re-runs `install` after an
|
|
2005
|
+
upgrade now gets the same repair. The block moved out of `hostWiringCommand` into
|
|
2006
|
+
`repairDesktopEntry`, which both call: the process look, `desktop.ts#repairDesktop`, one
|
|
2007
|
+
line about it.
|
|
2008
|
+
|
|
2009
|
+
- *Choices:*
|
|
2010
|
+
- It runs whether or not Claude Code is on this machine: Desktop's file is there or not
|
|
2011
|
+
either way.
|
|
2012
|
+
- A Desktop that is open (or not ruled out) leaves the entry as it was, as with `connect`,
|
|
2013
|
+
and the message still says to quit Desktop and run `connect` again. That is the
|
|
2014
|
+
command that does it alone, without the install conversation.
|
|
2015
|
+
- Exit stays 0 on a failed write, like every other host step of `install` at a terminal
|
|
2016
|
+
(a `wire()` that fails is a hint, not an exit). `connect` still exits 1.
|
|
2017
|
+
- The closing line no longer says "it should be all green" while Desktop's entry is left
|
|
2018
|
+
in the old shape: doctor's Runtime line is amber then (review M1's rule).
|
|
2019
|
+
- In review: a Desktop file that does not parse (`refused`) fell through to "all green".
|
|
2020
|
+
Doctor cannot read an entry in it, so its Runtime line really is green, which is why
|
|
2021
|
+
the ending can't say amber either: it says the file was left as it was and that
|
|
2022
|
+
`connect` brings the entry up to date once it's fixed. Tested with a trailing comma,
|
|
2023
|
+
and a write that fails (a read-only folder: install exits 0, connect 1).
|
|
2024
|
+
- The scripted install (`--no-connect`, a pipe, CI) reads no host file, as before.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
|
-
':' //; if command -v bun >/dev/null 2>&1; then exec bun "$0" "$@"; elif command -v node >/dev/null 2>&1; then exec node "$0" "$@"; else echo "counterparts: needs Bun 1.3+ or Node 22.15+ on PATH" >&2; exit 127; fi
|
|
2
|
+
':' //; s="$0"; n=0; while [ -h "$s" ] && [ $n -lt 32 ]; do n=$((n+1)); l="$(readlink "$s")"; case "$l" in /*) s="$l" ;; *) s="${s%/*}/$l" ;; esac; done; c="${s%/*}/../../empty-bunfig.toml"; [ -f "$c" ] || c=/dev/null; if command -v bun >/dev/null 2>&1; then exec bun --no-env-file "--config=$c" "$0" "$@"; elif command -v node >/dev/null 2>&1; then exec node "$0" "$@"; else echo "counterparts: needs Bun 1.3+ or Node 22.15+ on PATH" >&2; exit 127; fi
|
|
3
3
|
// A shell script and an ES module at once: the line above is a no-op string to
|
|
4
|
-
// JavaScript and, to sh, the runtime choice (Bun if it is on PATH, else Node
|
|
4
|
+
// JavaScript and, to sh, the runtime choice (Bun if it is on PATH, else Node;
|
|
5
|
+
// Bun with --no-env-file and --config=<empty-bunfig.toml>, found through any
|
|
6
|
+
// bin symlink, so a project's .env and bunfig.toml stay out: adapters/runtime.ts).
|
|
5
7
|
// See `adapters/launch.mjs`.
|
|
6
8
|
import { launch } from "../../launch.mjs";
|
|
7
9
|
|
|
@@ -28,9 +28,16 @@
|
|
|
28
28
|
* a stdin that closes under the question both reject with `PromptAborted`
|
|
29
29
|
* rather than resolving as an answer nobody gave.
|
|
30
30
|
*/
|
|
31
|
+
import { spawnSync } from "node:child_process";
|
|
32
|
+
import { homedir } from "node:os";
|
|
31
33
|
import { resolve } from "node:path";
|
|
32
34
|
import { fileURLToPath } from "node:url";
|
|
33
35
|
|
|
36
|
+
import { BINARY } from "../../runtime.js";
|
|
37
|
+
import type { Binary } from "../../runtime.js";
|
|
38
|
+
import { npmWiring } from "../../host-wiring.js";
|
|
39
|
+
import { npmDoctorCommand, pluginDoctorLine, pluginOrigin, runningAsPlugin } from "../../plugin.js";
|
|
40
|
+
|
|
34
41
|
import { run } from "../commands.js";
|
|
35
42
|
import { echoPrompt, hiddenPrompt } from "../ui.js";
|
|
36
43
|
|
|
@@ -56,7 +63,40 @@ async function readStdin(): Promise<string> {
|
|
|
56
63
|
*/
|
|
57
64
|
const ask = echoPrompt(process.stdin, process.stdout);
|
|
58
65
|
|
|
66
|
+
/**
|
|
67
|
+
* `doctor` launched from the plugin (`plugin-run.sh cli doctor`, the plugin's
|
|
68
|
+
* /counterparts:doctor) while the npm install's wiring is live: say so, then
|
|
69
|
+
* run THAT install's own doctor, with the runtime and the install its live
|
|
70
|
+
* hook names (`plugin.ts#npmDoctorCommand`); PATH's `counterparts` only when
|
|
71
|
+
* the wiring can't be read that way. Null when this is not that case and the
|
|
72
|
+
* ordinary console runs.
|
|
73
|
+
*/
|
|
74
|
+
function doctorFromStoodDownPlugin(): number | null {
|
|
75
|
+
if (process.argv[2] !== "doctor" || !runningAsPlugin(process.env)) return null;
|
|
76
|
+
const home = homedir();
|
|
77
|
+
const cwd = process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
|
|
78
|
+
const wiring = npmWiring({ home, env: process.env, cwd });
|
|
79
|
+
const line = pluginDoctorLine(wiring, home, pluginOrigin({ home, env: process.env, cwd }));
|
|
80
|
+
if (line === null) return null;
|
|
81
|
+
process.stdout.write(`${line}\n\n`);
|
|
82
|
+
// Not the plugin any more: the npm install's doctor must not take itself for it.
|
|
83
|
+
const env = { ...process.env };
|
|
84
|
+
delete env["CLAUDE_PLUGIN_ROOT"];
|
|
85
|
+
const wired = npmDoctorCommand(wiring);
|
|
86
|
+
const r =
|
|
87
|
+
wired !== null
|
|
88
|
+
? spawnSync(wired.exe, [...wired.args], { stdio: "inherit", env })
|
|
89
|
+
: spawnSync("counterparts", process.argv.slice(2), { stdio: "inherit", env });
|
|
90
|
+
if (r.error !== undefined) {
|
|
91
|
+
process.stdout.write("The npm install's `counterparts` is not on this PATH. Run `counterparts doctor` in a terminal.\n");
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
return r.status ?? 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
59
97
|
async function main(): Promise<number> {
|
|
98
|
+
const redirected = doctorFromStoodDownPlugin();
|
|
99
|
+
if (redirected !== null) return redirected;
|
|
60
100
|
return run(process.argv.slice(2), {
|
|
61
101
|
io: {
|
|
62
102
|
out: (line) => {
|
|
@@ -101,12 +141,16 @@ async function main(): Promise<number> {
|
|
|
101
141
|
}
|
|
102
142
|
|
|
103
143
|
/** True only when this file is the process entry point. */
|
|
104
|
-
export function isEntryPoint(argv1: string | undefined, url: string): boolean {
|
|
105
|
-
|
|
144
|
+
export function isEntryPoint(argv1: string | undefined, url: string, binary: Binary | null = BINARY): boolean {
|
|
145
|
+
// Never in the single binary, where every module shares one URL: its
|
|
146
|
+
// dispatcher (tools/single-binary/main.ts) calls `start()` itself.
|
|
147
|
+
if (argv1 === undefined || binary !== null) return false;
|
|
106
148
|
return resolve(argv1) === fileURLToPath(new URL(url));
|
|
107
149
|
}
|
|
108
150
|
|
|
109
|
-
|
|
151
|
+
/** Run one console command and exit — what this file does as a script, and
|
|
152
|
+
* what the single binary's `cli` mode calls. */
|
|
153
|
+
export function start(): void {
|
|
110
154
|
void main().then(
|
|
111
155
|
(code) => process.exit(code),
|
|
112
156
|
(err: unknown) => {
|
|
@@ -115,3 +159,5 @@ if (isEntryPoint(process.argv[1], import.meta.url)) {
|
|
|
115
159
|
},
|
|
116
160
|
);
|
|
117
161
|
}
|
|
162
|
+
|
|
163
|
+
if (isEntryPoint(process.argv[1], import.meta.url)) start();
|