counterparts 0.3.21 → 0.3.23
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 +66 -0
- package/docs/module-map.md +1 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/bin/hook.ts +3 -3
- package/src/adapters/claude-code/bin/runner.ts +27 -1
- package/src/adapters/claude-code/doctor-host.ts +28 -9
- package/src/adapters/claude-code/night-run.ts +2 -3
- package/src/adapters/claude-code/transcript.ts +1 -1
- package/src/adapters/cli/bin/counterparts.ts +9 -2
- package/src/adapters/cli/commands-dashboard.ts +31 -2
- package/src/adapters/cli/commands-start-fresh.ts +11 -2
- package/src/adapters/cli/desktop.ts +10 -5
- package/src/adapters/cli/help.ts +4 -3
- package/src/adapters/cli/install.ts +16 -8
- package/src/adapters/cli/removal.ts +7 -0
- package/src/adapters/cli/uninstall.ts +12 -4
- package/src/adapters/cli/wire.ts +41 -12
- package/src/adapters/dashboard/web/README.md +1 -1
- package/src/adapters/dashboard/web/actions.ts +6 -4
- package/src/adapters/dashboard/web/app.html +3 -0
- package/src/adapters/dashboard/web/favicon.svg +1 -0
- package/src/adapters/dashboard/web/pages/home/home.css +3 -0
- package/src/adapters/dashboard/web/pages/home/sections/brain.js +37 -9
- package/src/adapters/dashboard/web/probe.ts +33 -0
- package/src/adapters/dashboard/web/server.ts +49 -27
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +13 -3
- package/src/adapters/host-wiring.ts +44 -6
- package/src/adapters/mcp/bin/serve.ts +33 -0
- package/src/adapters/mcp/index.ts +1 -0
- package/src/adapters/mcp/server-options.ts +7 -0
- package/src/adapters/mcp/server-words.ts +1 -1
- package/src/adapters/mcp/server.ts +7 -0
- package/src/adapters/mcp/tools.ts +58 -0
- package/src/adapters/plugin.ts +3 -2
- package/src/adapters/runtime.ts +80 -3
- package/src/adapters/scopes.ts +2 -1
- package/src/adapters/sidebar-status.ts +505 -0
- package/src/adapters/spawn.ts +2 -2
- package/src/core/dream/index.ts +1 -1
- package/src/core/dream/reflect.ts +6 -5
- package/src/core/onboarding.ts +5 -2
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
*
|
|
26
26
|
* - the configuration file, and our own temp and backup siblings of it;
|
|
27
27
|
* - `scopes.json` and its siblings;
|
|
28
|
+
* - `sidebar.json` (what the Claude Code sidebar shows, `sidebar-status.ts`)
|
|
29
|
+
* and its temp siblings — a file this package left;
|
|
28
30
|
* - `snapshots/`, when it is the one this layout owns rather than a directory
|
|
29
31
|
* the owner pointed at;
|
|
30
32
|
* - the STORE — at `dataDir`, **wherever that is**, which is the other half of
|
|
@@ -91,8 +93,10 @@ import { basename, dirname, isAbsolute, join, parse as parsePath, resolve } from
|
|
|
91
93
|
import { Store, assertSafeDataDir, dateOf, isWithin, storeExists } from "../../core/store/index.js";
|
|
92
94
|
import { isJournal } from "../../core/sleep/index.js";
|
|
93
95
|
import { SCOPES_FILE_NAME, shellWord } from "../scopes.js";
|
|
96
|
+
import { SIDEBAR_FILE_NAME } from "../sidebar-status.js";
|
|
94
97
|
import { PLUGIN_ROOT_ENV, installRoute } from "../plugin.js";
|
|
95
98
|
import { pluginInstall } from "../host-wiring.js";
|
|
99
|
+
import { pluginConsoleWords } from "../runtime.js";
|
|
96
100
|
import type { PluginInstallRead } from "../host-wiring.js";
|
|
97
101
|
import { SNAPSHOTS_DIR_NAME, resolveSnapshotsDir } from "../snapshots.js";
|
|
98
102
|
import type { AdapterConfig } from "../config.js";
|
|
@@ -139,8 +143,9 @@ export const REMOVE_PLUGIN = "in Claude Code, /plugin → Installed → counterp
|
|
|
139
143
|
*/
|
|
140
144
|
export function consoleName(env: Record<string, string | undefined>, home: string): string {
|
|
141
145
|
if (installRoute(env) !== "plugin") return BIN.cli;
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
return pluginConsoleWords((env[PLUGIN_ROOT_ENV] ?? "").trim())
|
|
147
|
+
.map((w) => shellWord(w, home))
|
|
148
|
+
.join(" ");
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
export function removeProgram(env: Record<string, string | undefined>): string {
|
|
@@ -192,8 +197,10 @@ function removeProgramAfterGone(input: UninstallInput): void {
|
|
|
192
197
|
const route = installRoute(input.env);
|
|
193
198
|
if (route === "npm") {
|
|
194
199
|
input.io.out(`To remove the program too: ${REMOVE_PACKAGE}`);
|
|
195
|
-
// INSTALLED TWICE: the plugin stood down while this
|
|
196
|
-
//
|
|
200
|
+
// INSTALLED TWICE: the plugin's launcher flavor stood down while this
|
|
201
|
+
// install's hooks were live, and the directory flavor (which never reads
|
|
202
|
+
// `~/.claude.json`) ran beside them; either way it is still on, and with
|
|
203
|
+
// the configuration gone its next start is a first run.
|
|
197
204
|
const also = pluginInstall({ home: input.home, env: input.env, cwd: null });
|
|
198
205
|
if (also === null || !also.enabled) return;
|
|
199
206
|
input.io.out(`Claude Code also has the plugin: ${pluginUninstallCommand(also, input.home)}`);
|
|
@@ -292,6 +299,7 @@ export function ownedKind(name: string, owned: OwnedNames): OwnedKind | null {
|
|
|
292
299
|
if (name === owned.scopes) return "scopes";
|
|
293
300
|
if (owned.snapshots !== null && name === owned.snapshots) return "snapshots";
|
|
294
301
|
if (owned.store !== null && name === owned.store) return "store";
|
|
302
|
+
if (name === SIDEBAR_FILE_NAME || /^sidebar\.json\.\d+\.tmp$/.test(name)) return "sidecar";
|
|
295
303
|
const bases = [owned.config, owned.scopes, owned.snapshots, owned.store];
|
|
296
304
|
for (const base of bases) {
|
|
297
305
|
if (base === null || !name.startsWith(`${base}.`)) continue;
|
package/src/adapters/cli/wire.ts
CHANGED
|
@@ -85,7 +85,7 @@ import { DATA_DIR_ENV, isWithin } from "../../core/store/index.js";
|
|
|
85
85
|
import { CONFIG_ENV, CONFIG_FLAG } from "../config-path.js";
|
|
86
86
|
import { isOurHookCommand } from "../host-wiring.js";
|
|
87
87
|
import { claudeCodeEnvMarker } from "../hosts.js";
|
|
88
|
-
import { parseScriptInvocation, scriptArgs, shellTokens } from "../runtime.js";
|
|
88
|
+
import { parseScriptInvocation, readsHostUserConfig, scriptArgs, shellTokens } from "../runtime.js";
|
|
89
89
|
import { installedBuild, readServerRecords, sameBuild, serverBelieved } from "../sessions.js";
|
|
90
90
|
import type { BuildStamp, ServerRecordRead } from "../sessions.js";
|
|
91
91
|
import type { Io } from "./commands.js";
|
|
@@ -924,6 +924,10 @@ export interface McpReading {
|
|
|
924
924
|
/** True when the file exists and could not be read — a different fact from
|
|
925
925
|
* "no registration", and the one that must not read as "not installed". */
|
|
926
926
|
readonly unreadable: boolean;
|
|
927
|
+
/** True when this build does not open the file at all (the plugin
|
|
928
|
+
* directory's, `runtime.ts#readsHostUserConfig`): `present` is then "not
|
|
929
|
+
* looked", and only `claude` itself can say what is registered. */
|
|
930
|
+
readonly notRead?: boolean;
|
|
927
931
|
}
|
|
928
932
|
|
|
929
933
|
/**
|
|
@@ -937,8 +941,10 @@ export function readMcp(
|
|
|
937
941
|
custom: string | undefined,
|
|
938
942
|
exe: string,
|
|
939
943
|
serve: string = MCP_SCRIPT,
|
|
944
|
+
readsUserConfig: boolean = readsHostUserConfig(),
|
|
940
945
|
): McpReading {
|
|
941
946
|
const file = hostMcpFile(hostConfigBase(home, env));
|
|
947
|
+
if (!readsUserConfig) return { file, present: false, matches: false, unreadable: false, notRead: true };
|
|
942
948
|
if (!existsSync(file)) return { file, present: false, matches: false, unreadable: false };
|
|
943
949
|
let raw: unknown;
|
|
944
950
|
try {
|
|
@@ -1022,10 +1028,12 @@ export type ProcessLister = () => ProcessSighting;
|
|
|
1022
1028
|
* segment included, plus the two installed shims anchored at a boundary.
|
|
1023
1029
|
*/
|
|
1024
1030
|
const PROCESS_MARKS: readonly { readonly re: RegExp; readonly what: string }[] = [
|
|
1025
|
-
|
|
1031
|
+
// Ended at the extension, and the transpiled tree's `.js` read only under
|
|
1032
|
+
// `adapters/` (review of #475): those names are names other tools' builds have too.
|
|
1033
|
+
{ re: /(adapters[/\\]mcp[/\\]bin[/\\]serve\.js|mcp[/\\]bin[/\\]serve\.(ts|mjs))(?=$|["'\s])/, what: "an MCP server" },
|
|
1026
1034
|
{ re: /(^|[\s"'/\\])counterparts-mcp(\s|$|")/, what: "an MCP server" },
|
|
1027
|
-
{ re: /claude-code[/\\]bin[/\\]runner\.ts/, what: "the worker" },
|
|
1028
|
-
{ re: /dashboard[/\\]bin[/\\]dashboard\.(ts|mjs)/, what: "a dashboard" },
|
|
1035
|
+
{ re: /(adapters[/\\]claude-code[/\\]bin[/\\]runner\.js|claude-code[/\\]bin[/\\]runner\.ts)(?=$|["'\s])/, what: "the worker" },
|
|
1036
|
+
{ re: /(adapters[/\\]dashboard[/\\]bin[/\\]dashboard\.js|dashboard[/\\]bin[/\\]dashboard\.(ts|mjs))(?=$|["'\s])/, what: "a dashboard" },
|
|
1029
1037
|
{ re: /(^|[\s"'/\\])counterparts-dashboard(\s|$|")/, what: "a dashboard" },
|
|
1030
1038
|
// The single binary (`runtime.ts#BINARY_MODES`): `…/counterparts mcp`.
|
|
1031
1039
|
{ re: /(^|[/\\])counterparts(\.exe)?"?\s+mcp(\s|$)/, what: "an MCP server" },
|
|
@@ -1131,6 +1139,9 @@ export interface WireInput {
|
|
|
1131
1139
|
readonly lister: ProcessLister;
|
|
1132
1140
|
/** `install` prints its own step heading; a bare `wire` prints one here. */
|
|
1133
1141
|
readonly heading?: boolean;
|
|
1142
|
+
/** Whether `unwire` may read `~/.claude.json`: `runtime.ts#readsHostUserConfig`
|
|
1143
|
+
* by default; a test's seam. */
|
|
1144
|
+
readonly readsUserConfig?: boolean;
|
|
1134
1145
|
}
|
|
1135
1146
|
|
|
1136
1147
|
export interface WireResult {
|
|
@@ -1640,12 +1651,14 @@ export async function unwire(input: WireInput): Promise<WireResult> {
|
|
|
1640
1651
|
}
|
|
1641
1652
|
|
|
1642
1653
|
const merged = mergeHooks(sight.value, "", "unwire");
|
|
1643
|
-
const mcp = readMcp(home, env, input.store, input.custom, input.exe);
|
|
1654
|
+
const mcp = readMcp(home, env, input.store, input.custom, input.exe, MCP_SCRIPT, input.readsUserConfig);
|
|
1644
1655
|
|
|
1645
1656
|
// `mcp.unreadable` is NOT "nothing there": that file is the host's own and a
|
|
1646
1657
|
// read that failed is no evidence either way, which is the same stance the
|
|
1647
1658
|
// removal below takes.
|
|
1648
|
-
|
|
1659
|
+
// A file this build never opens (`notRead`) is no evidence either: the
|
|
1660
|
+
// removal below asks `claude`.
|
|
1661
|
+
if (!merged.changed && !mcp.present && !mcp.unreadable && mcp.notRead !== true) {
|
|
1649
1662
|
u.ok("nothing to disconnect: no Counterparts hooks and no memory server were found.");
|
|
1650
1663
|
// SAID EVEN HERE: a wrapper is exactly the case where "nothing of ours"
|
|
1651
1664
|
// needs a sentence, because the person can see a hook that mentions us and
|
|
@@ -1758,6 +1771,8 @@ export async function unwire(input: WireInput): Promise<WireResult> {
|
|
|
1758
1771
|
// `uninstall`'s two irreversible arms refuse on it: a server pointed at a
|
|
1759
1772
|
// store that is no longer there fails at every session start with nothing on
|
|
1760
1773
|
// screen, which is the same argument this file already makes for the hooks.
|
|
1774
|
+
// A build that does not read that file (the plugin directory's) with no
|
|
1775
|
+
// `claude` to ask has neither, and is false too.
|
|
1761
1776
|
let mcpConfirmed = false;
|
|
1762
1777
|
const res = input.spawner(mcpRemoveArgs());
|
|
1763
1778
|
const notThere = /not found|no .*server|does not exist|not configured/i.test(`${res.out}\n${res.err}`);
|
|
@@ -1769,10 +1784,23 @@ export async function unwire(input: WireInput): Promise<WireResult> {
|
|
|
1769
1784
|
// let the irreversible arm run. M2's own words are "a read of the
|
|
1770
1785
|
// registration shows it ABSENT", and a read that failed shows nothing at all.
|
|
1771
1786
|
const stillThere = (): boolean => {
|
|
1772
|
-
const fresh = readMcp(home, env, input.store, input.custom, input.exe);
|
|
1773
|
-
|
|
1787
|
+
const fresh = readMcp(home, env, input.store, input.custom, input.exe, MCP_SCRIPT, input.readsUserConfig);
|
|
1788
|
+
// Not looked (`notRead`) is not "gone" either.
|
|
1789
|
+
return fresh.present || fresh.unreadable || fresh.notRead === true;
|
|
1774
1790
|
};
|
|
1775
|
-
if (res.missing) {
|
|
1791
|
+
if (res.missing && mcp.notRead === true) {
|
|
1792
|
+
// NOT LOOKED, AND NOBODY TO ASK (the plugin directory's build): that
|
|
1793
|
+
// build never registers a server there itself, but an npm install's may
|
|
1794
|
+
// be there, pointing at this same store, and nothing was looked at. Not
|
|
1795
|
+
// confirmed, so uninstall stops before deleting or moving the store (M2):
|
|
1796
|
+
// unknown is not absent (review of #481).
|
|
1797
|
+
mcpConfirmed = false;
|
|
1798
|
+
u.warn(
|
|
1799
|
+
"`claude` is not on this PATH and this version does not read Claude Code's own configuration, so whether a memory server is still registered (an npm install's, if there is one) could not be checked.",
|
|
1800
|
+
);
|
|
1801
|
+
u.hint(`Remove one if it is there: claude mcp remove ${MCP_SERVER_NAME} -s user — and run this again where \`claude\` is on PATH to have it checked.`);
|
|
1802
|
+
mcpWord = "printed";
|
|
1803
|
+
} else if (res.missing) {
|
|
1776
1804
|
mcpConfirmed = !stillThere();
|
|
1777
1805
|
if (mcpConfirmed) {
|
|
1778
1806
|
u.hint(`no MCP registration named "${MCP_SERVER_NAME}" was there to remove.`);
|
|
@@ -1786,10 +1814,11 @@ export async function unwire(input: WireInput): Promise<WireResult> {
|
|
|
1786
1814
|
u.ok("memory server removed");
|
|
1787
1815
|
mcpWord = "removed";
|
|
1788
1816
|
mcpConfirmed = true;
|
|
1789
|
-
} else if (notThere || !mcp.present) {
|
|
1817
|
+
} else if (notThere || (!mcp.present && mcp.notRead !== true)) {
|
|
1790
1818
|
// `claude` says there was nothing there. Believe it, and check the file
|
|
1791
|
-
// too — this is the one place where two sources agreeing is cheap.
|
|
1792
|
-
|
|
1819
|
+
// too — this is the one place where two sources agreeing is cheap. A
|
|
1820
|
+
// build that does not read the file has `claude`'s word alone, and takes it.
|
|
1821
|
+
mcpConfirmed = mcp.notRead === true || !stillThere();
|
|
1793
1822
|
u.hint(`no MCP registration named "${MCP_SERVER_NAME}" was there to remove.`);
|
|
1794
1823
|
mcpWord = "absent";
|
|
1795
1824
|
} else {
|
|
@@ -10,7 +10,7 @@ step, no dependencies. `server.ts` serves them as files (see "Serving" below).
|
|
|
10
10
|
|
|
11
11
|
| file | what it is |
|
|
12
12
|
|---|---|
|
|
13
|
-
| `server.ts` | `node:http` on 127.0.0.1, the Host allowlist, `router()` (GET: `/`, `/brain` (now a redirect to `/#home`), the favicon, `/api/*`, the static files), and the POST hand-off to `actions.ts`. A store waiting for its one-time upgrade (v6 met by v7, `../upgrade.ts`) gets one calm page instead, and is tried again on every request |
|
|
13
|
+
| `server.ts` | `node:http` on 127.0.0.1, the Host allowlist, `router()` (GET: `/`, `/brain` (now a redirect to `/#home`), the favicon (`favicon.svg`, a file beside it since 2026-10-14), `/api/*`, the static files), and the POST hand-off to `actions.ts`. A store waiting for its one-time upgrade (v6 met by v7, `../upgrade.ts`) gets one calm page instead, and is tried again on every request |
|
|
14
14
|
| `actions.ts` | managing: `POST /api/action/<name>` — the same-origin + per-launch-token guard, argument validation, and the console's own `run()` (loaded lazily; never handed the observer source). `ACTIONS` lists them: `ask`, `note`, `remove`, `backup`, `export`, `scope`, `rebrief`, `verify`, and `doctor` (a read: the health tab's checklist, `doctor --json`) |
|
|
15
15
|
| `ask-voice.ts` | `toMyVoice(question, ownerName)`: Ask is the owner talking to me, so `ask` turns his question into my voice before it searches ("do you remember what I said" → "do I remember what Mike said"; his I → "you" when the store knows no name). Pure; the rules are in its header and `test/dashboard-ask-voice.test.ts`. The server reads the name (`sleep#ownerNames`) and hands `actions.ts` the string |
|
|
16
16
|
| `static.ts` | `resolveStatic()`: which URL paths are static files and where they live (pure; no fs) |
|
|
@@ -74,10 +74,12 @@ export function isActionName(name: string): name is ActionName {
|
|
|
74
74
|
return (ACTIONS as readonly string[]).includes(name);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** The header every action must echo the page's token
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export const
|
|
77
|
+
/** The NAME of the header every action must echo the page's per-launch token
|
|
78
|
+
* in (a guard against another page posting here, not a credential; renamed
|
|
79
|
+
* from TOKEN_HEADER 2026-10-14, the directory's validator read it as one). */
|
|
80
|
+
export const ACTION_HEADER_NAME = "x-counterparts-token";
|
|
81
|
+
/** The `<meta name>` the served page carries that token in (was TOKEN_META). */
|
|
82
|
+
export const ACTION_META_NAME = "counterparts-action-token";
|
|
81
83
|
|
|
82
84
|
/** A request body larger than this is refused before it is parsed. */
|
|
83
85
|
export const MAX_BODY_BYTES = 64 * 1024;
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
<!-- The server fills this with a per-launch token; every management action
|
|
9
9
|
echoes it (web/actions.ts). Empty means this page cannot act. -->
|
|
10
10
|
<meta name="counterparts-action-token" content="">
|
|
11
|
+
<!-- The server turns this off when the brain picture's three.js is not
|
|
12
|
+
installed (server.ts#BRAIN_LIBRARY); the home tab then draws without it. -->
|
|
13
|
+
<meta name="counterparts-brain" content="on">
|
|
11
14
|
<!--
|
|
12
15
|
The shell. Styles, scripts and the two font faces are served beside this file
|
|
13
16
|
(see README.md): no CDN, no network of any kind beyond this origin.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="13" fill="#0a0e14"/><path d="M14 46 L32 32 L50 18" stroke="#00e5ff" stroke-opacity=".35" stroke-width="2.5" fill="none" stroke-linecap="round"/><circle cx="14" cy="46" r="4.5" fill="#00bfa5"/><circle cx="32" cy="32" r="7" fill="#00e5ff"/><circle cx="50" cy="18" r="4.5" fill="#b388ff"/></svg>
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
.home-row{display:grid;gap:24px;align-items:start}
|
|
19
19
|
.home-row>*{min-width:0}
|
|
20
20
|
.home-row-a{grid-template-columns:minmax(0,1fr) minmax(0,1.15fr);align-items:center;margin:0 0 18px}
|
|
21
|
+
/* No brain picture in this build (sections/brain.js#pictureServed): "Today" takes the row. */
|
|
22
|
+
.home-row-a.is-solo{grid-template-columns:minmax(0,1fr)}
|
|
23
|
+
.home-brain[hidden]{display:none}
|
|
21
24
|
.home-row-b{grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-items:stretch}
|
|
22
25
|
.home-card{display:flex;flex-direction:column;min-width:0}
|
|
23
26
|
.home-card .card{flex:1;margin-bottom:8px}
|
|
@@ -5,12 +5,19 @@
|
|
|
5
5
|
row it had not seen). The first paint flares each working region once.
|
|
6
6
|
|
|
7
7
|
The brain no longer drives a panel here: clicking a region opens the Health
|
|
8
|
-
tab's "How the memory works" with that region's first mechanism picked.
|
|
8
|
+
tab's "How the memory works" with that region's first mechanism picked.
|
|
9
|
+
|
|
10
|
+
THE PICTURE IS OPTIONAL (2026-10-14). It is the one thing on the dashboard
|
|
11
|
+
drawn with three.js, and the plugin directory's bundle carries neither the
|
|
12
|
+
library nor `../brain.js`. The server says which in the page
|
|
13
|
+
(`<meta name="counterparts-brain" content="off">`, `server.ts#BRAIN_LIBRARY`):
|
|
14
|
+
off, the box is not drawn, "Today" takes the row, and nothing asks for the
|
|
15
|
+
lights. On, the picture's module is loaded here rather than imported, so a
|
|
16
|
+
missing file could never take the whole home tab's modules down with it. */
|
|
9
17
|
import { MECHANISMS } from "../../../mechanisms/index.js";
|
|
10
18
|
import { REGIONS, regionOf } from "../../../mechanisms/regions.js";
|
|
11
19
|
import { api } from "../../../shared/api.js";
|
|
12
20
|
import { $ } from "../../../shared/dom.js";
|
|
13
|
-
import { mountBrain } from "../brain.js";
|
|
14
21
|
import { go } from "../go.js";
|
|
15
22
|
|
|
16
23
|
export const markup = `<div class="home-brain" id="home-brain"></div>`;
|
|
@@ -32,24 +39,44 @@ export function routeOf(key) {
|
|
|
32
39
|
|
|
33
40
|
let brain = { levels() {}, pulse() {} };
|
|
34
41
|
let lastSeen = null; // id → newest backing seq, as of the previous paint
|
|
42
|
+
let lastView = null; // the lights last painted, for a picture that loads after them
|
|
43
|
+
|
|
44
|
+
/** Does the server serve the picture's files? Absent tag: an older server, which always did. */
|
|
45
|
+
export function pictureServed(doc = document) {
|
|
46
|
+
const tag = doc.querySelector('meta[name="counterparts-brain"]');
|
|
47
|
+
return tag === null || tag.getAttribute("content") !== "off";
|
|
48
|
+
}
|
|
35
49
|
|
|
36
50
|
/** Build the brain once; a failure to start is a calm sentence in its place. */
|
|
37
51
|
export function mount() {
|
|
38
52
|
const wrap = $("home-brain");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
53
|
+
if (!pictureServed()) {
|
|
54
|
+
wrap.hidden = true;
|
|
55
|
+
wrap.parentElement.classList.add("is-solo");
|
|
56
|
+
wrap.dataset.ready = "1";
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const calm = () => {
|
|
45
60
|
wrap.classList.add("is-nogl");
|
|
46
61
|
wrap.innerHTML = '<div class="brain-off"><p>The brain picture could not start in this browser.</p>' +
|
|
47
62
|
"<p>Everything it shows is on the Health tab, under how the memory works.</p></div>";
|
|
48
63
|
wrap.dataset.ready = "1";
|
|
49
|
-
}
|
|
64
|
+
};
|
|
65
|
+
import("../brain.js").then(({ mountBrain }) => {
|
|
66
|
+
brain = mountBrain(wrap, (key) => {
|
|
67
|
+
const to = routeOf(key);
|
|
68
|
+
if (to !== null) go(to);
|
|
69
|
+
}, (key) => shortOf[mechanismOf(key)] || key);
|
|
70
|
+
// The lights may have come first: paint them again, first-paint flares and all.
|
|
71
|
+
if (lastView !== null) {
|
|
72
|
+
lastSeen = null;
|
|
73
|
+
paint(lastView);
|
|
74
|
+
}
|
|
75
|
+
}).catch(calm);
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
function paint(view) {
|
|
79
|
+
lastView = view;
|
|
53
80
|
const status = Object.fromEntries(view.mechanisms.map((l) => [l.id, l.status]));
|
|
54
81
|
const levels = {};
|
|
55
82
|
for (const r of REGIONS) {
|
|
@@ -78,6 +105,7 @@ function paint(view) {
|
|
|
78
105
|
|
|
79
106
|
/** Read the lights (at boot, and whenever the store moves). */
|
|
80
107
|
export async function refresh() {
|
|
108
|
+
if (!pictureServed()) return;
|
|
81
109
|
let view;
|
|
82
110
|
try { view = await api("/api/mechanisms"); } catch (e) { return; }
|
|
83
111
|
paint(view);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH STORE THE DASHBOARD ON THIS MACHINE'S PORT SERVES — the one outbound
|
|
3
|
+
* request in the package, and it never leaves the machine.
|
|
4
|
+
*
|
|
5
|
+
* `counterparts dashboard` finds its port taken. A dashboard already serving
|
|
6
|
+
* the same store is the common case (the sidebar's button on the desktop runs
|
|
7
|
+
* the command whether or not one is up), and the right answer there is to open
|
|
8
|
+
* the browser on it, not to fail. Asking it is one GET of `/api/whoami` on
|
|
9
|
+
* 127.0.0.1 — the same question the sidebar asks it — answered with a store id
|
|
10
|
+
* or nothing. No other host, no other path, no body sent, a short timeout.
|
|
11
|
+
*
|
|
12
|
+
* Loaded lazily by `cli/commands-dashboard.ts#realDashboard`, so a console that
|
|
13
|
+
* never hits a taken port never has this in its module graph.
|
|
14
|
+
*/
|
|
15
|
+
import { STORE_ID_RE } from "../../store-id.js";
|
|
16
|
+
|
|
17
|
+
/** How long a dashboard that holds the port may take to say which store it serves. */
|
|
18
|
+
const PROBE_TIMEOUT_MS = 1500;
|
|
19
|
+
|
|
20
|
+
/** The store id the dashboard on `port` serves, or null: nothing there, not ours, no id, too slow. */
|
|
21
|
+
export async function dashboardStoreAt(port: number): Promise<string | null> {
|
|
22
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) return null;
|
|
23
|
+
try {
|
|
24
|
+
const r = await globalThis.fetch(`http://127.0.0.1:${String(port)}/api/whoami`, {
|
|
25
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS),
|
|
26
|
+
});
|
|
27
|
+
if (!r.ok) return null;
|
|
28
|
+
const store = ((await r.json()) as { store?: unknown } | null)?.store;
|
|
29
|
+
return typeof store === "string" && STORE_ID_RE.test(store) ? store : null;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* the page carries, JSON). A GET to an action path is refused here, so no
|
|
58
58
|
* link, image or prefetch can act.
|
|
59
59
|
*/
|
|
60
|
-
import { readFileSync } from "node:fs";
|
|
60
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
61
61
|
import { createServer } from "node:http";
|
|
62
62
|
import type { IncomingMessage, Server, ServerResponse } from "node:http";
|
|
63
63
|
import { join } from "node:path";
|
|
@@ -70,9 +70,9 @@ import { Dashboard } from "../index.js";
|
|
|
70
70
|
import { upgradePending, upgradePendingSentence } from "../upgrade.js";
|
|
71
71
|
import type { DashboardSource } from "../source.js";
|
|
72
72
|
import {
|
|
73
|
+
ACTION_HEADER_NAME,
|
|
74
|
+
ACTION_META_NAME,
|
|
73
75
|
MAX_BODY_BYTES,
|
|
74
|
-
TOKEN_HEADER,
|
|
75
|
-
TOKEN_META,
|
|
76
76
|
checkActionRequest,
|
|
77
77
|
newActionToken,
|
|
78
78
|
runAction,
|
|
@@ -111,22 +111,47 @@ export const PORT_ENV = "COUNTERPARTS_DASHBOARD_PORT";
|
|
|
111
111
|
const HERE = packagePath("src/adapters/dashboard/web");
|
|
112
112
|
const APP_PATH = join(HERE, "app.html");
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* The home tab's brain picture is drawn with three.js, the dashboard's one
|
|
116
|
+
* large file, which the plugin directory's bundle leaves out with the
|
|
117
|
+
* picture's module (tools/plugin-bundle/build.ts). Whether it is here is read
|
|
118
|
+
* off the file itself, per page load, and said in the page
|
|
119
|
+
* (`pages/home/sections/brain.js#pictureServed`): off, the home tab draws
|
|
120
|
+
* without the picture rather than ask for a module that is not there.
|
|
121
|
+
*/
|
|
122
|
+
export const BRAIN_LIBRARY = join(HERE, "shared", "vendor", "three.module.min.js");
|
|
123
|
+
const BRAIN_ON = `<meta name="counterparts-brain" content="on">`;
|
|
124
|
+
const BRAIN_OFF = `<meta name="counterparts-brain" content="off">`;
|
|
125
|
+
|
|
126
|
+
/** The page as served: its brain tag turned off when the library is not here. */
|
|
127
|
+
export function withBrainSwitch(page: string, served: boolean = existsSync(BRAIN_LIBRARY)): string {
|
|
128
|
+
return served ? page : page.replace(BRAIN_ON, BRAIN_OFF);
|
|
129
|
+
}
|
|
130
|
+
|
|
114
131
|
const NO_STORE = { "cache-control": "no-store" } as const;
|
|
115
132
|
|
|
116
133
|
/**
|
|
117
|
-
* A small mark: three dots on a rising diagonal, the middle one lit
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
134
|
+
* A small mark: three dots on a rising diagonal, the middle one lit, in
|
|
135
|
+
* `favicon.svg` beside this file — served at all because a missing favicon is
|
|
136
|
+
* a console error, and this dashboard's bar is zero of them. Static branding
|
|
137
|
+
* rather than a data view, so it is the one response that may cache. A file,
|
|
138
|
+
* not a string here, since 2026-10-14: the plugin directory's review read the
|
|
139
|
+
* SVG namespace URL in this file beside its other identifiers as a credential
|
|
140
|
+
* risk. Read per request like the page; a missing one is the ordinary 404.
|
|
122
141
|
*/
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
const FAVICON_PATH = join(HERE, "favicon.svg");
|
|
143
|
+
|
|
144
|
+
function favicon(): Reply | null {
|
|
145
|
+
try {
|
|
146
|
+
return {
|
|
147
|
+
status: 200,
|
|
148
|
+
headers: { "content-type": "image/svg+xml", "cache-control": "public, max-age=86400" },
|
|
149
|
+
body: readFileSync(FAVICON_PATH, "utf8"),
|
|
150
|
+
};
|
|
151
|
+
} catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
130
155
|
|
|
131
156
|
const ALLOWED_HOSTNAMES = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
132
157
|
|
|
@@ -182,10 +207,10 @@ function html(body: string): Reply {
|
|
|
182
207
|
*/
|
|
183
208
|
function page(file: string, token?: string): Reply {
|
|
184
209
|
try {
|
|
185
|
-
const text = readFileSync(file, "utf8");
|
|
210
|
+
const text = withBrainSwitch(readFileSync(file, "utf8"));
|
|
186
211
|
if (token === undefined || !/^[0-9a-f]+$/.test(token)) return html(text);
|
|
187
212
|
return html(
|
|
188
|
-
text.replace(`<meta name="${
|
|
213
|
+
text.replace(`<meta name="${ACTION_META_NAME}" content="">`, `<meta name="${ACTION_META_NAME}" content="${token}">`),
|
|
189
214
|
);
|
|
190
215
|
} catch {
|
|
191
216
|
return json(
|
|
@@ -248,11 +273,7 @@ export function router(
|
|
|
248
273
|
// The brain lives on the home page now; an old bookmark lands there.
|
|
249
274
|
if (path === "/brain") return { status: 302, headers: { location: "/#home", ...NO_STORE }, body: "" };
|
|
250
275
|
if (path === "/favicon.svg" || path === "/favicon.ico") {
|
|
251
|
-
return {
|
|
252
|
-
status: 200,
|
|
253
|
-
headers: { "content-type": "image/svg+xml", "cache-control": "public, max-age=86400" },
|
|
254
|
-
body: FAVICON_SVG,
|
|
255
|
-
};
|
|
276
|
+
return favicon() ?? json({ error: `not found: ${path}` }, 404);
|
|
256
277
|
}
|
|
257
278
|
|
|
258
279
|
if (path === "/api/meta") return json(metaView(src));
|
|
@@ -297,9 +318,9 @@ export function router(
|
|
|
297
318
|
if (path === "/api/dreams") return json(dreamsView(src, intParam(url, "limit", DREAM_LIMIT)));
|
|
298
319
|
if (path === "/api/flow") return json(flowView(src, intParam(url, "limit", 24)));
|
|
299
320
|
if (path === "/api/node") {
|
|
300
|
-
const
|
|
301
|
-
const detail = nodeDetail(src,
|
|
302
|
-
return detail.found ? json(detail) : json({ error: `no such node: ${
|
|
321
|
+
const nodeKey = url.searchParams.get("key") ?? "";
|
|
322
|
+
const detail = nodeDetail(src, nodeKey, intParam(url, "limit", 8));
|
|
323
|
+
return detail.found ? json(detail) : json({ error: `no such node: ${nodeKey}` }, 404);
|
|
303
324
|
}
|
|
304
325
|
if (path === "/api/health") return json(healthView(src));
|
|
305
326
|
if (path === "/api/fired") return json(firedPanel(src, src.store.today()));
|
|
@@ -463,7 +484,8 @@ export function startDashboard(opts: ServeOptions = {}): Promise<RunningDashboar
|
|
|
463
484
|
return;
|
|
464
485
|
}
|
|
465
486
|
try {
|
|
466
|
-
|
|
487
|
+
// A fixed base: only the path and the query are read here; the Host header is checked on its own (`isAllowedHost`).
|
|
488
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
467
489
|
const open = current();
|
|
468
490
|
reply =
|
|
469
491
|
open === null
|
|
@@ -550,7 +572,7 @@ async function handleAction(
|
|
|
550
572
|
host: header(req, "host"),
|
|
551
573
|
origin: header(req, "origin"),
|
|
552
574
|
contentType: header(req, "content-type"),
|
|
553
|
-
token: header(req,
|
|
575
|
+
token: header(req, ACTION_HEADER_NAME),
|
|
554
576
|
fetchSite: header(req, "sec-fetch-site"),
|
|
555
577
|
},
|
|
556
578
|
token,
|
|
@@ -240,6 +240,18 @@ export function mechanismPanel(src: DashboardSource, id: string): MechanismPanel
|
|
|
240
240
|
const proof = MECHANISM_PROOFS.find((m) => m.id === id);
|
|
241
241
|
if (proof === undefined) return { id, found: false, built: false, livedDay, activity: [], picture: null };
|
|
242
242
|
if (proof.build === "not") return { id, found: true, built: false, livedDay, activity: [], picture: null };
|
|
243
|
+
return { id, found: true, built: true, livedDay, activity: mechanismActivity(src, id), picture: pictureOf(src, id, livedDay) };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A mechanism's panel rows alone, without its picture: what the Claude Code
|
|
248
|
+
* sidebar's status file carries (`adapters/sidebar-status.ts`), which has no
|
|
249
|
+
* use for the picture's reads. Empty for an unknown or unbuilt mechanism.
|
|
250
|
+
*/
|
|
251
|
+
export function mechanismActivity(src: DashboardSource, id: string): Merged[] {
|
|
252
|
+
const store = src.store;
|
|
253
|
+
const proof = MECHANISM_PROOFS.find((m) => m.id === id);
|
|
254
|
+
if (proof === undefined || proof.build === "not") return [];
|
|
243
255
|
|
|
244
256
|
const backing: EventRow[] = [];
|
|
245
257
|
for (const p of proof.proofs) {
|
|
@@ -265,9 +277,7 @@ export function mechanismPanel(src: DashboardSource, id: string): MechanismPanel
|
|
|
265
277
|
}
|
|
266
278
|
lines.push(line);
|
|
267
279
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return { id, found: true, built: true, livedDay, activity, picture: pictureOf(src, id, livedDay) };
|
|
280
|
+
return mergeRepeats(lines).slice(0, PANEL_ACTIVITY);
|
|
271
281
|
}
|
|
272
282
|
|
|
273
283
|
function pictureOf(src: DashboardSource, id: string, day: number): Picture | null {
|
|
@@ -35,7 +35,16 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
35
35
|
import { isAbsolute, join, resolve } from "node:path";
|
|
36
36
|
|
|
37
37
|
import { CONFIG_FLAG } from "./config-path.js";
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
BUN_CONFIG_PREFIX,
|
|
40
|
+
BUN_NO_ENV_FILE,
|
|
41
|
+
isBinaryName,
|
|
42
|
+
parseScriptInvocation,
|
|
43
|
+
readsHostUserConfig,
|
|
44
|
+
runtimeOf,
|
|
45
|
+
runtimePresent,
|
|
46
|
+
shellTokens,
|
|
47
|
+
} from "./runtime.js";
|
|
39
48
|
|
|
40
49
|
/** The name `counterparts connect` registers the server under
|
|
41
50
|
* (`cli/install.ts#MCP_SERVER_NAME`), spelled again because this module may
|
|
@@ -88,20 +97,23 @@ export function isOurHookCommand(command: string): boolean {
|
|
|
88
97
|
// `<runtime> --import <node-hooks.mjs> <our hook script>`, or the single
|
|
89
98
|
// binary's `<binary> hook` (`runtime.ts`).
|
|
90
99
|
const run = parseScriptInvocation(tokens);
|
|
91
|
-
|
|
100
|
+
// The transpiled tree's `.js` only anchored at `adapters/` (as `HOOK_ENTRY`,
|
|
101
|
+
// review of #355): a bare `claude-code/bin/hook.js` is a path another tool's
|
|
102
|
+
// build may well have (review of #475). `.ts` reads as it always has.
|
|
103
|
+
if (run !== null && (run.mode === "hook" || (run.mode === undefined && /((^|[/\\])adapters[/\\]claude-code[/\\]bin[/\\]hook\.js|claude-code[/\\]bin[/\\]hook\.ts)$/.test(run.script)))) {
|
|
92
104
|
return tail(tokens.length - run.rest.length);
|
|
93
105
|
}
|
|
94
106
|
return false;
|
|
95
107
|
}
|
|
96
108
|
|
|
97
|
-
/** Our hook's entry by its path, as a runtime's script: the TypeScript entry
|
|
98
|
-
*
|
|
109
|
+
/** Our hook's entry by its path, as a runtime's script: the TypeScript entry,
|
|
110
|
+
* its `.mjs` shim, or the transpiled tree's `.js` (`runtime.ts#entryScript`). (The installed `counterparts-hook` shim runs itself,
|
|
99
111
|
* so it is read only as the command's first token.) Anchored at
|
|
100
112
|
* `adapters/`, where the entry has lived since it was written (review of
|
|
101
113
|
* #355): a bare `claude-code/bin/hook.ts` is a path any tool with a Claude
|
|
102
114
|
* Code adapter may have, and this reading accepts any runtime before it —
|
|
103
115
|
* `tsx`, `deno run`, `node` — so a match here stands the plugin down. */
|
|
104
|
-
const HOOK_ENTRY = /(^|[/\\])adapters[/\\]claude-code[/\\]bin[/\\]hook\.(ts|mjs)$/;
|
|
116
|
+
const HOOK_ENTRY = /(^|[/\\])adapters[/\\]claude-code[/\\]bin[/\\]hook\.(ts|mjs|js)$/;
|
|
105
117
|
|
|
106
118
|
/** Our hook command, read for WHAT IT RUNS (`readOurHook`). */
|
|
107
119
|
export interface OurHookRead {
|
|
@@ -307,6 +319,22 @@ export interface PluginInstallRead {
|
|
|
307
319
|
/** `enabledPlugins[id]` from user, project and local settings, the last one
|
|
308
320
|
* that says anything winning (Claude Code's precedence); unset is enabled. */
|
|
309
321
|
readonly enabled: boolean;
|
|
322
|
+
/** Does this build stand down beside the npm install's wiring? False for the
|
|
323
|
+
* plugin directory's flavor (a transpiled tree, `src/adapters/runtime.js`
|
|
324
|
+
* and no `plugin-run.sh`), which never reads `~/.claude.json` and so runs
|
|
325
|
+
* beside it (`runtime.ts#readsHostUserConfig`); true for the launcher
|
|
326
|
+
* flavor; null when `installPath` is unrecorded or holds neither. */
|
|
327
|
+
readonly standsDown?: boolean | null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Which flavor sits at a plugin's `installPath`, read by its files: the
|
|
331
|
+
* launcher flavor carries `src/adapters/plugin-run.sh`, the directory flavor
|
|
332
|
+
* the transpiled `src/adapters/runtime.js` in its place. */
|
|
333
|
+
export function pluginStandsDown(installPath: string | null): boolean | null {
|
|
334
|
+
if (installPath === null || installPath.length === 0) return null;
|
|
335
|
+
if (existsSync(join(installPath, "src", "adapters", "plugin-run.sh"))) return true;
|
|
336
|
+
if (existsSync(join(installPath, "src", "adapters", "runtime.js"))) return false;
|
|
337
|
+
return null;
|
|
310
338
|
}
|
|
311
339
|
|
|
312
340
|
/**
|
|
@@ -343,13 +371,15 @@ export function pluginInstall(input: {
|
|
|
343
371
|
const on = settings === null ? undefined : settings["enabledPlugins"];
|
|
344
372
|
if (isRecord(on) && typeof on[id] === "boolean") enabled = on[id] as boolean;
|
|
345
373
|
}
|
|
374
|
+
const installPath = first !== undefined && typeof first["installPath"] === "string" ? first["installPath"] : null;
|
|
346
375
|
return {
|
|
347
376
|
id,
|
|
348
|
-
installPath
|
|
377
|
+
installPath,
|
|
349
378
|
version: first !== undefined && typeof first["version"] === "string" ? first["version"] : null,
|
|
350
379
|
scope: first !== undefined && typeof first["scope"] === "string" ? first["scope"] : null,
|
|
351
380
|
projectPath: first !== undefined && typeof first["projectPath"] === "string" ? first["projectPath"] : null,
|
|
352
381
|
enabled,
|
|
382
|
+
standsDown: pluginStandsDown(installPath),
|
|
353
383
|
};
|
|
354
384
|
}
|
|
355
385
|
|
|
@@ -372,7 +402,15 @@ export function npmWiring(input: {
|
|
|
372
402
|
* nothing. The server, once per session, passes `{ hooks: false }`.
|
|
373
403
|
*/
|
|
374
404
|
readonly read?: { readonly hooks?: boolean; readonly mcp?: boolean };
|
|
405
|
+
/** `runtime.ts#readsHostUserConfig` by default; a test's seam. */
|
|
406
|
+
readonly readsUserConfig?: boolean;
|
|
375
407
|
}): NpmWiring {
|
|
408
|
+
// THE PLUGIN DIRECTORY'S BUILD DOES NOT LOOK (2026-10-14): it never opens
|
|
409
|
+
// `~/.claude.json`, so it has no stand-down to decide, and it reads neither
|
|
410
|
+
// half (the settings files included) rather than stand its hooks down while
|
|
411
|
+
// its server serves tools beside a registration it cannot see. No wiring
|
|
412
|
+
// found is what every caller already handles: nothing stands down.
|
|
413
|
+
if (!(input.readsUserConfig ?? readsHostUserConfig())) return { hooks: [], mcp: [] };
|
|
376
414
|
const { settings, globalConfig } = claudeUserFiles(input.home, input.env);
|
|
377
415
|
const cwd = input.cwd === null || input.cwd.length === 0 ? null : resolve(input.cwd);
|
|
378
416
|
const hooks: WiredHook[] = [];
|