counterparts 0.3.49 → 0.3.52
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 +96 -0
- package/README.md +18 -10
- package/docs/QUICKSTART.md +46 -12
- package/docs/manual.md +2 -1
- package/docs/module-map.md +3 -0
- package/package.json +3 -2
- package/src/adapters/claude-code/NOTES.md +43 -0
- package/src/adapters/claude-code/child.ts +23 -2
- package/src/adapters/claude-code/doctor-growth.ts +269 -0
- package/src/adapters/claude-code/doctor-host.ts +19 -1
- package/src/adapters/claude-code/doctor-recall-steps.ts +84 -0
- package/src/adapters/claude-code/doctor.ts +26 -3
- package/src/adapters/claude-code/hooks.ts +7 -1
- package/src/adapters/cli/INTERFACE-GAPS.md +18 -0
- package/src/adapters/cli/NOTES.md +24 -0
- package/src/adapters/cli/commands-dashboard.ts +9 -1
- package/src/adapters/cli/commands-project.ts +2 -1
- package/src/adapters/cli/commands-readings.ts +19 -8
- package/src/adapters/cli/commands-verify.ts +1 -1
- package/src/adapters/cli/commands.ts +4 -2
- package/src/adapters/cli/export.ts +2 -1
- package/src/adapters/cli/install.ts +14 -6
- package/src/adapters/cli/mechanisms.ts +1 -1
- package/src/adapters/cli/wire.ts +22 -6
- package/src/adapters/dashboard/activity.ts +6 -3
- package/src/adapters/dashboard/registries.ts +11 -0
- package/src/adapters/dashboard/web/flow.ts +3 -0
- package/src/adapters/dashboard/web/lanes.ts +4 -0
- package/src/adapters/dashboard/web/narrate.ts +23 -0
- package/src/adapters/dashboard/web/views/activity.ts +4 -2
- package/src/adapters/dashboard/web/views/flow-view.ts +6 -0
- package/src/adapters/dashboard/web/views/memory.ts +13 -0
- package/src/adapters/dashboard/web/views/shared.ts +2 -1
- package/src/adapters/fired.ts +113 -11
- package/src/adapters/host-wiring.ts +3 -1
- package/src/adapters/lifecycle.ts +36 -9
- package/src/adapters/mcp/CONTRACT.md +22 -1
- package/src/adapters/mcp/server-args.ts +51 -0
- package/src/adapters/mcp/server-session-end.ts +8 -2
- package/src/adapters/mcp/server-words.ts +14 -1
- package/src/adapters/mcp/server.ts +117 -7
- package/src/adapters/mcp/tools.ts +4 -3
- package/src/adapters/plugin.ts +1 -0
- package/src/adapters/presence.ts +74 -0
- package/src/adapters/runtime.ts +258 -8
- package/src/adapters/scopes.ts +3 -2
- package/src/adapters/spawn.ts +3 -0
- package/src/adapters/update-check.ts +1 -1
- package/src/adapters/windows-shims.mjs +102 -0
- package/src/core/close-hint.ts +297 -0
- package/src/core/counterpart-boundary.ts +15 -0
- package/src/core/counterpart-deposit.ts +24 -3
- package/src/core/counterpart-events.ts +14 -0
- package/src/core/counterpart-types.ts +6 -0
- package/src/core/counterpart-wake-shape.ts +88 -19
- package/src/core/counterpart.ts +143 -7
- package/src/core/dream/index.ts +1 -1
- package/src/core/dream/reflect.ts +54 -34
- package/src/core/encode/NOTES.md +55 -0
- package/src/core/encode/secrets.ts +477 -3
- package/src/core/event-rollup.ts +175 -0
- package/src/core/handoff/CONTRACT.md +7 -0
- package/src/core/interference.ts +496 -0
- package/src/core/open-close.ts +583 -0
- package/src/core/prospective/CONTRACT.md +24 -0
- package/src/core/prospective/derive.ts +22 -1
- package/src/core/prospective/index.ts +115 -1
- package/src/core/recall/CONTRACT.md +9 -2
- package/src/core/recall/NOTES.md +99 -0
- package/src/core/recall/activate.ts +83 -6
- package/src/core/recall/index.ts +75 -5
- package/src/core/recall/probe.ts +134 -0
- package/src/core/recall/steps.ts +84 -0
- package/src/core/recall/tunables.ts +11 -0
- package/src/core/reconsolidation.ts +14 -4
- package/src/core/remember/CONTRACT.md +2 -1
- package/src/core/remember/NOTES.md +15 -0
- package/src/core/remember/spans.ts +44 -6
- package/src/core/self/NOTES.md +21 -0
- package/src/core/self/work.ts +9 -5
- package/src/core/sleep/CONTRACT.md +36 -2
- package/src/core/sleep/NOTES.md +35 -0
- package/src/core/sleep/close.ts +77 -0
- package/src/core/sleep/cycle.ts +44 -0
- package/src/core/sleep/index.ts +4 -0
- package/src/core/sleep/interfere.ts +73 -0
- package/src/core/sleep/log.ts +27 -2
- package/src/core/sleep/tunables.ts +19 -0
- package/src/core/sleep/types.ts +20 -0
- package/src/core/store/index.ts +157 -10
- package/src/core/store/operational.ts +22 -0
- package/src/core/store/owner-op-seam.ts +16 -0
- package/src/core/store/reads-history.ts +173 -7
- package/src/core/store/reads-memories.ts +253 -4
- package/src/core/store/shapes.ts +8 -0
package/src/adapters/runtime.ts
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* still parse (`parseScriptInvocation`, `projectEnv: "read"`), `doctor` names
|
|
49
49
|
* them, and `counterparts connect` rewrites them.
|
|
50
50
|
*/
|
|
51
|
-
import { existsSync } from "node:fs";
|
|
51
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
52
52
|
import { basename, dirname, join } from "node:path";
|
|
53
53
|
import { fileURLToPath } from "node:url";
|
|
54
54
|
|
|
@@ -163,6 +163,22 @@ export function packagePath(rel: string, binary: Binary | null = BINARY): string
|
|
|
163
163
|
return rel.includes("/") ? [binary.root, ...rel.split("/")].join(sep) : [binary.root, ".", rel].join(sep);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* The package version the single binary was BUILT from, handed in by its
|
|
168
|
+
* entry (`tools/single-binary/main.ts`) before any mode runs; null from source.
|
|
169
|
+
* `cli/commands.ts#packageVersion` reads the embedded `package.json` first and
|
|
170
|
+
* this only when that fails, which it does on Windows: Bun lists the file as
|
|
171
|
+
* `B:/~BUN/root/./package.json` and then answers ENOENT for that very name
|
|
172
|
+
* (W1, 2026-11-09, CI's windows-x64 selfcheck).
|
|
173
|
+
*/
|
|
174
|
+
let builtVersion: string | null = null;
|
|
175
|
+
export function setBuiltVersion(version: string): void {
|
|
176
|
+
builtVersion = version;
|
|
177
|
+
}
|
|
178
|
+
export function builtVersionOf(): string | null {
|
|
179
|
+
return builtVersion;
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
/** The model table's directory inside the binary; undefined from source,
|
|
167
183
|
* where `core/embed/static.ts` resolves the installed package itself. */
|
|
168
184
|
export function bundledModelDir(binary: Binary | null = BINARY): string | undefined {
|
|
@@ -260,15 +276,236 @@ export function runtimeOf(exe: string): RuntimeKind {
|
|
|
260
276
|
* <node-hooks.mjs> <script>` for Node, and the script's mode alone (`hook`,
|
|
261
277
|
* `runner`, …) when `exe` is the compiled binary itself, which reads no
|
|
262
278
|
* `.env` or `bunfig.toml` (it is built with both off). */
|
|
263
|
-
export function scriptArgs(
|
|
279
|
+
export function scriptArgs(
|
|
280
|
+
script: string,
|
|
281
|
+
exe: string = process.execPath,
|
|
282
|
+
binary: Binary | null = BINARY,
|
|
283
|
+
platform: string = process.platform,
|
|
284
|
+
): string[] {
|
|
264
285
|
// The compiled binary runs ITSELF in another mode: `<binary> runner`.
|
|
265
286
|
const mode = binary !== null && exe === binary.self ? binaryModeOf(script) : undefined;
|
|
266
287
|
if (mode !== undefined) return [mode];
|
|
267
288
|
return runtimeOf(exe) === "node"
|
|
268
|
-
? ["--import", NODE_HOOKS, script]
|
|
289
|
+
? ["--import", platform === "win32" ? windowsFileUrl(NODE_HOOKS) : NODE_HOOKS, script]
|
|
269
290
|
: [BUN_NO_ENV_FILE, `${BUN_CONFIG_PREFIX}${EMPTY_BUNFIG}`, "run", script];
|
|
270
291
|
}
|
|
271
292
|
|
|
293
|
+
// ── Windows (W1, 2026-11-09) ─────────────────────────────────────────────────
|
|
294
|
+
//
|
|
295
|
+
// Claude Code on native Windows runs a hook's command string in Git Bash when
|
|
296
|
+
// Git for Windows is installed, else in PowerShell (code.claude.com/docs/en/hooks,
|
|
297
|
+
// "How shell-form commands are run"), and spawns an MCP server's `command` with
|
|
298
|
+
// its `args` directly. So what `connect` writes there has to read the same in
|
|
299
|
+
// both shells, which is what these do (`claude-code/NOTES.md`, "Windows"):
|
|
300
|
+
//
|
|
301
|
+
// - `--import` takes a module SPECIFIER, and Node reads `C:\…\node-hooks.mjs`
|
|
302
|
+
// as a URL with the scheme `c:` (ERR_UNSUPPORTED_ESM_URL_SCHEME). On win32
|
|
303
|
+
// it is given as a `file:///C:/…` URL; POSIX keeps the plain path every
|
|
304
|
+
// existing hook line carries.
|
|
305
|
+
// - Paths are written with `/`: Windows takes them, and neither shell then
|
|
306
|
+
// has a backslash to read as an escape.
|
|
307
|
+
// - The runtime is written by its bare NAME (`node`) when that name on PATH
|
|
308
|
+
// is the very executable running now. PowerShell will not run a quoted
|
|
309
|
+
// first word without `&` (which bash refuses), and the default Node lives
|
|
310
|
+
// in `C:/Program Files/…`, which needs quotes. On Windows a host's PATH is
|
|
311
|
+
// the one the person set for their account, not a login shell's, so scar
|
|
312
|
+
// §2.18 (the host's PATH is not the shell's) is not the hazard it is on
|
|
313
|
+
// macOS. When the name finds another file (links followed; a version
|
|
314
|
+
// manager's shim is another file), the path is written in the form the
|
|
315
|
+
// shell Claude Code uses there runs (`windowsHookWord`), and `connect` and
|
|
316
|
+
// doctor say it runs in that shell only.
|
|
317
|
+
|
|
318
|
+
/** A Windows path as a `file:` URL, by hand, so it is the same on every host
|
|
319
|
+
* (a test runs it on macOS): `C:\a b\x.mjs` → `file:///C:/a%20b/x.mjs`. */
|
|
320
|
+
export function windowsFileUrl(path: string): string {
|
|
321
|
+
const slashed = path.replace(/\\/g, "/");
|
|
322
|
+
const rooted = slashed.startsWith("/") ? slashed : `/${slashed}`;
|
|
323
|
+
return `file://${encodeURI(rooted).replace(/#/g, "%23").replace(/\?/g, "%3F")}`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A path as a host command on `platform` names it: `/`-separated on win32,
|
|
327
|
+
* unchanged elsewhere. */
|
|
328
|
+
export function hostPath(path: string, platform: string = process.platform): string {
|
|
329
|
+
return platform === "win32" ? path.replace(/\\/g, "/") : path;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Where a bare command name resolves on `PATH` — trying each `PATHEXT`
|
|
333
|
+
* extension on win32, where `node` is `node.exe` on disk — or null. */
|
|
334
|
+
export function whichOnPath(
|
|
335
|
+
name: string,
|
|
336
|
+
env: Record<string, string | undefined> = process.env,
|
|
337
|
+
platform: string = process.platform,
|
|
338
|
+
exists: (path: string) => boolean = existsSync,
|
|
339
|
+
): string | null {
|
|
340
|
+
const win = platform === "win32";
|
|
341
|
+
// Windows spells it `Path`, and a copy of `process.env` is no longer
|
|
342
|
+
// case-blind about it.
|
|
343
|
+
const key = (wanted: string): string | undefined =>
|
|
344
|
+
env[wanted] ?? (win ? Object.entries(env).find(([k]) => k.toUpperCase() === wanted)?.[1] : undefined);
|
|
345
|
+
const dirs = (key("PATH") ?? "").split(win ? ";" : ":").filter((d) => d.length > 0);
|
|
346
|
+
// On win32 only the PATHEXT spellings, unless the name carries its own: npm
|
|
347
|
+
// puts an extensionless sh script beside every `x.cmd` (for Git Bash), and
|
|
348
|
+
// Windows can't start that file (CI 11-09: `claude` was found as it and
|
|
349
|
+
// read as missing).
|
|
350
|
+
const exts = win
|
|
351
|
+
? /\.[A-Za-z0-9]+$/.test(name)
|
|
352
|
+
? [""]
|
|
353
|
+
: (key("PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((e) => e.length > 0).map((e) => e.toLowerCase())
|
|
354
|
+
: [""];
|
|
355
|
+
for (const d of dirs) {
|
|
356
|
+
for (const ext of exts) {
|
|
357
|
+
const candidate = `${d.replace(/[\\/]+$/, "")}${win ? "\\" : "/"}${name}${ext}`;
|
|
358
|
+
if (exists(candidate)) return candidate;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* HOW TO START A COMMAND BY NAME ON WINDOWS, with its arguments kept one each:
|
|
366
|
+
* the file to spawn and the arguments to give it, or null when the name is not
|
|
367
|
+
* on PATH or is something this cannot start without a shell.
|
|
368
|
+
*
|
|
369
|
+
* A native `.exe` is spawned as it is. An npm-installed command is a `.cmd`
|
|
370
|
+
* batch file (`claude.cmd` for an npm install of Claude Code), which Node will
|
|
371
|
+
* not spawn without a shell (EINVAL since 20.12), and a shell would re-read
|
|
372
|
+
* every argument — a night child's `--mcp-config` JSON, its system prompt.
|
|
373
|
+
* npm writes those files one way (`cmd-shim`): the target is the quoted
|
|
374
|
+
* `"%dp0%\…"` path, run by the program the target's shebang named. So the
|
|
375
|
+
* target is read out of the file: an `.exe` is spawned directly, a script is
|
|
376
|
+
* given to `node` (the one on PATH, as the shim does). W1, 2026-11-09.
|
|
377
|
+
*/
|
|
378
|
+
export function windowsLaunch(
|
|
379
|
+
name: string,
|
|
380
|
+
args: readonly string[],
|
|
381
|
+
env: Record<string, string | undefined> = process.env,
|
|
382
|
+
exists: (path: string) => boolean = existsSync,
|
|
383
|
+
read: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
384
|
+
): { file: string; args: string[] } | null {
|
|
385
|
+
const found = whichOnPath(name, env, "win32", exists);
|
|
386
|
+
if (found === null) return null;
|
|
387
|
+
if (!/\.(cmd|bat)$/i.test(found)) return { file: found, args: [...args] };
|
|
388
|
+
let text: string;
|
|
389
|
+
try {
|
|
390
|
+
text = read(found);
|
|
391
|
+
} catch {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
// The LAST quoted `%dp0%` path: a Node bin's shim names `"%dp0%\node.exe"`
|
|
395
|
+
// first (`IF EXIST …`), its target last (measured on Claude Code's, CI 11-09).
|
|
396
|
+
// Older npm and pnpm spell the directory `%~dp0` (read-cmd-shim reads both).
|
|
397
|
+
const target = [...text.matchAll(/"%(?:dp0%|~dp0)\\([^"]+)"/g)].pop()?.[1];
|
|
398
|
+
if (target === undefined) return null;
|
|
399
|
+
const dir = found.replace(/[\\/][^\\/]*$/, "");
|
|
400
|
+
const file = `${dir}\\${target}`;
|
|
401
|
+
if (!exists(file)) return null;
|
|
402
|
+
if (/\.exe$/i.test(file)) return { file, args: [...args] };
|
|
403
|
+
if (!/\.(c|m)?js$/i.test(file)) return null;
|
|
404
|
+
const node = whichOnPath("node", env, "win32", exists);
|
|
405
|
+
return node === null ? null : { file: node, args: [file, ...args] };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** A path with links resolved (`realpathSync.native`), or as given when it
|
|
409
|
+
* can't be. */
|
|
410
|
+
function realOrSelf(path: string): string {
|
|
411
|
+
try {
|
|
412
|
+
return realpathSync.native(path);
|
|
413
|
+
} catch {
|
|
414
|
+
return path;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** The runtime as a host command on `platform` names it: on win32 its bare
|
|
419
|
+
* name when that name on PATH resolves (links followed) to this very file,
|
|
420
|
+
* else its `/` path; the path unchanged elsewhere. Under a version manager
|
|
421
|
+
* (Volta, nvm-windows) `node` on PATH is the manager's shim, another file:
|
|
422
|
+
* then the path, which `windowsHookWord` writes so a shell can run it. */
|
|
423
|
+
export function hostExe(
|
|
424
|
+
exe: string,
|
|
425
|
+
platform: string = process.platform,
|
|
426
|
+
env: Record<string, string | undefined> = process.env,
|
|
427
|
+
exists: (path: string) => boolean = existsSync,
|
|
428
|
+
real: (path: string) => string = realOrSelf,
|
|
429
|
+
): string {
|
|
430
|
+
if (platform !== "win32") return exe;
|
|
431
|
+
const name = (exe.split(/[\\/]/).pop() ?? "").replace(/\.exe$/i, "");
|
|
432
|
+
const same = (a: string, b: string): boolean =>
|
|
433
|
+
hostPath(real(a), "win32").toLowerCase() === hostPath(real(b), "win32").toLowerCase();
|
|
434
|
+
if (/^[A-Za-z0-9_-]+$/.test(name)) {
|
|
435
|
+
const found = whichOnPath(name, env, platform, exists);
|
|
436
|
+
if (found !== null && same(found, exe)) return name;
|
|
437
|
+
}
|
|
438
|
+
return hostPath(exe, platform);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Does Claude Code on this Windows machine have Git Bash to run hooks in? The
|
|
443
|
+
* lookup its docs give (code.claude.com/docs/en/troubleshoot-install):
|
|
444
|
+
* `CLAUDE_CODE_GIT_BASH_PATH`, then `C:\Program Files\Git` and its `(x86)`
|
|
445
|
+
* twin, then the Git for Windows that `git` on PATH belongs to.
|
|
446
|
+
*/
|
|
447
|
+
export function gitBashOnWindows(
|
|
448
|
+
env: Record<string, string | undefined> = process.env,
|
|
449
|
+
exists: (path: string) => boolean = existsSync,
|
|
450
|
+
): boolean {
|
|
451
|
+
const named = (env["CLAUDE_CODE_GIT_BASH_PATH"] ?? "").trim();
|
|
452
|
+
if (named.length > 0 && exists(named)) return true;
|
|
453
|
+
if (exists("C:\\Program Files\\Git\\bin\\bash.exe") || exists("C:\\Program Files (x86)\\Git\\bin\\bash.exe")) return true;
|
|
454
|
+
const git = whichOnPath("git", env, "win32", exists);
|
|
455
|
+
// `…\Git\cmd\git.exe` (or `…\Git\bin\git.exe`): Git Bash is `…\Git\bin\bash.exe`.
|
|
456
|
+
return git !== null && exists(`${git.replace(/[\\/][^\\/]+[\\/][^\\/]+$/, "")}\\bin\\bash.exe`);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* THE FIRST WORD OF A WINDOWS HOOK LINE, and whether it runs in both shells
|
|
461
|
+
* Claude Code may use there (Git Bash, else PowerShell):
|
|
462
|
+
*
|
|
463
|
+
* - `name`: `node` by name. Both run it.
|
|
464
|
+
* - `plain`: a `/` path with no space or shell character, unquoted. Both.
|
|
465
|
+
* - `bash`: a path that needs quotes, quoted, with Git Bash present: bash
|
|
466
|
+
* runs it; PowerShell would read a quoted first word as a string.
|
|
467
|
+
* - `powershell`: the same with no Git Bash: `& "path"`, PowerShell's call
|
|
468
|
+
* operator, which bash refuses. (`shellTokens` reads the `&` away.)
|
|
469
|
+
*
|
|
470
|
+
* The last two are written for the shell present at `connect`; installing or
|
|
471
|
+
* removing Git for Windows afterwards breaks them, which `connect` and doctor
|
|
472
|
+
* say (`windowsHookFit`).
|
|
473
|
+
*/
|
|
474
|
+
export type WindowsHookForm = "name" | "plain" | "bash" | "powershell";
|
|
475
|
+
export function windowsHookWord(
|
|
476
|
+
command: string,
|
|
477
|
+
env: Record<string, string | undefined> = process.env,
|
|
478
|
+
exists: (path: string) => boolean = existsSync,
|
|
479
|
+
): { word: string; form: WindowsHookForm } {
|
|
480
|
+
if (/^[A-Za-z0-9_-]+$/.test(command)) return { word: command, form: "name" };
|
|
481
|
+
if (/^[A-Za-z0-9_.:/+-]+$/.test(command)) return { word: command, form: "plain" };
|
|
482
|
+
const quoted = `"${command}"`;
|
|
483
|
+
return gitBashOnWindows(env, exists) ? { word: quoted, form: "bash" } : { word: `& ${quoted}`, form: "powershell" };
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** What a person is told when a Windows hook line names its runtime by a path
|
|
487
|
+
* only one shell runs (`windowsHookWord`); null when both run it. */
|
|
488
|
+
export function windowsHookFit(form: WindowsHookForm, exe: string): string | null {
|
|
489
|
+
if (form === "name" || form === "plain") return null;
|
|
490
|
+
const shell = form === "bash" ? "Git Bash" : "PowerShell";
|
|
491
|
+
return `the hooks name Node by its path (${exe}), because \`node\` on PATH is another file (a version manager's shim, or another Node); that line runs in ${shell} only, the shell Claude Code uses on this machine now. If Git for Windows is installed or removed later, run counterparts connect again. To make it run in both, put this Node first on PATH and connect again.`;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** What a host is told to run for `script`: the command and its arguments,
|
|
495
|
+
* for the platform (`hostExe`, `hostPath`, `scriptArgs`). Every writer of a
|
|
496
|
+
* hook line or an MCP registration goes through this, and every reader that
|
|
497
|
+
* checks one against what it should be. */
|
|
498
|
+
export function hostInvocation(
|
|
499
|
+
script: string,
|
|
500
|
+
exe: string = process.execPath,
|
|
501
|
+
platform: string = process.platform,
|
|
502
|
+
env: Record<string, string | undefined> = process.env,
|
|
503
|
+
exists: (path: string) => boolean = existsSync,
|
|
504
|
+
): { command: string; args: string[] } {
|
|
505
|
+
const args = scriptArgs(script, exe, BINARY, platform).map((a) => hostPath(a, platform));
|
|
506
|
+
return { command: hostExe(exe, platform, env, exists), args };
|
|
507
|
+
}
|
|
508
|
+
|
|
272
509
|
/** A command split into its parts, when it is `<exe> <scriptArgs(script)> <rest…>`. */
|
|
273
510
|
export interface ScriptInvocation {
|
|
274
511
|
readonly exe: string;
|
|
@@ -343,16 +580,25 @@ export function parseScriptInvocation(tokens: readonly string[]): ScriptInvocati
|
|
|
343
580
|
|
|
344
581
|
/** Is the runtime a command names actually there? An absolute path is checked
|
|
345
582
|
* on disk; a bare name (`bun`, `node`) is looked up on `PATH`. */
|
|
346
|
-
export function runtimePresent(
|
|
583
|
+
export function runtimePresent(
|
|
584
|
+
exe: string,
|
|
585
|
+
env: Record<string, string | undefined> = process.env,
|
|
586
|
+
platform: string = process.platform,
|
|
587
|
+
): boolean {
|
|
347
588
|
if (exe.includes("/") || exe.includes("\\")) return existsSync(exe);
|
|
348
|
-
|
|
349
|
-
return
|
|
589
|
+
// On win32 a bare `node` is `node.exe` on disk (`PATHEXT`).
|
|
590
|
+
return whichOnPath(exe, env, platform) !== null;
|
|
350
591
|
}
|
|
351
592
|
|
|
352
593
|
/** Split on whitespace, honouring double quotes — the only quoting
|
|
353
594
|
* `install.ts#shellQuote` produces, and therefore the only quoting a command
|
|
354
595
|
* we wrote can carry. A single quote is left in the token, which makes the
|
|
355
|
-
* match fail, which is the safe direction.
|
|
596
|
+
* match fail, which is the safe direction.
|
|
597
|
+
*
|
|
598
|
+
* Inside the quotes a backslash escapes only what it escapes there in bash —
|
|
599
|
+
* `"`, `\`, `$` and a backtick — and is otherwise itself (2026-11-09, W1): a
|
|
600
|
+
* hand-typed Windows line, `"C:\Users\me\counterparts.exe" hook`, keeps its
|
|
601
|
+
* backslashes, and everything `shellQuote` writes reads back as before. */
|
|
356
602
|
export function shellTokens(command: string): string[] {
|
|
357
603
|
const out: string[] = [];
|
|
358
604
|
let current = "";
|
|
@@ -360,7 +606,7 @@ export function shellTokens(command: string): string[] {
|
|
|
360
606
|
let started = false;
|
|
361
607
|
for (let i = 0; i < command.length; i += 1) {
|
|
362
608
|
const ch = command[i] ?? "";
|
|
363
|
-
if (ch === "\\" && quoted && i + 1 < command.length) {
|
|
609
|
+
if (ch === "\\" && quoted && i + 1 < command.length && '"\\$`'.includes(command[i + 1] ?? "")) {
|
|
364
610
|
current += command[i + 1] ?? "";
|
|
365
611
|
i += 1;
|
|
366
612
|
continue;
|
|
@@ -380,5 +626,9 @@ export function shellTokens(command: string): string[] {
|
|
|
380
626
|
started = true;
|
|
381
627
|
}
|
|
382
628
|
if (started || current.length > 0) out.push(current);
|
|
629
|
+
// A leading lone `&` is PowerShell's call operator, which a Windows hook line
|
|
630
|
+
// carries before a quoted runtime when there is no Git Bash
|
|
631
|
+
// (`windowsHookWord`): the command is what follows it. No bash line begins so.
|
|
632
|
+
if (out[0] === "&" && out.length > 1) out.shift();
|
|
383
633
|
return out;
|
|
384
634
|
}
|
package/src/adapters/scopes.ts
CHANGED
|
@@ -285,8 +285,9 @@ export function parseRegistry(raw: unknown): {
|
|
|
285
285
|
};
|
|
286
286
|
for (const [path, value] of Object.entries(scopesRaw as Record<string, unknown>)) {
|
|
287
287
|
// An absolute path, or a pseudo-scope (Claude Desktop's `claude-desktop:`,
|
|
288
|
-
// which its `scope` tool writes under that name).
|
|
289
|
-
|
|
288
|
+
// which its `scope` tool writes under that name). On Windows a folder is
|
|
289
|
+
// `C:\…` (W1, 2026-11-09: every Windows scope read back as unset).
|
|
290
|
+
if (!path.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(path) && !isPseudoScope(path)) {
|
|
290
291
|
refuse(path, "the key is not an absolute path");
|
|
291
292
|
continue;
|
|
292
293
|
}
|
package/src/adapters/spawn.ts
CHANGED
|
@@ -252,6 +252,9 @@ export function spawnDetached(
|
|
|
252
252
|
withHostUmask(() =>
|
|
253
253
|
spawn(p.command, [...p.args], {
|
|
254
254
|
detached: true,
|
|
255
|
+
// On Windows a detached child gets a console window of its own, one
|
|
256
|
+
// flashing up on every prompt, unless it is hidden (W1, 2026-11-09).
|
|
257
|
+
windowsHide: true,
|
|
255
258
|
stdio: "ignore",
|
|
256
259
|
env: { ...p.env },
|
|
257
260
|
timeout: p.timeoutMs,
|
|
@@ -63,7 +63,7 @@ import { PLUGIN_UPDATE_COMMUNITY, PLUGIN_UPDATE_STEP, PLUGIN_UPDATE_SYNCED, npmU
|
|
|
63
63
|
* 30 days old from this alone, with nothing fetched. `test/update-check.test.ts`
|
|
64
64
|
* holds it to CHANGELOG's heading for `SERVER_VERSION` once there is one.
|
|
65
65
|
*/
|
|
66
|
-
export const RELEASE_DATE = "2026-11-
|
|
66
|
+
export const RELEASE_DATE = "2026-11-09";
|
|
67
67
|
|
|
68
68
|
export const UPDATE_CHECK_ENV = "COUNTERPARTS_UPDATE_CHECK";
|
|
69
69
|
export const NONESSENTIAL_TRAFFIC_ENV = "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE FOUR COMMANDS, MADE RUNNABLE FROM POWERSHELL AND CMD (W1, 2026-11-09).
|
|
3
|
+
*
|
|
4
|
+
* `package.json#scripts.postinstall` runs this after npm has linked the bins.
|
|
5
|
+
* It acts only for a GLOBAL npm install on Windows (`npm_config_global`), and
|
|
6
|
+
* anywhere else returns at once and touches nothing.
|
|
7
|
+
*
|
|
8
|
+
* Why it exists: each bin (`cli/bin/counterparts.mjs` and its three siblings)
|
|
9
|
+
* is a shell script and an ES module at once, its first line `#!/bin/sh`, so
|
|
10
|
+
* that on macOS and Linux the shell half picks Bun when it is on PATH, else
|
|
11
|
+
* Node (`launch.mjs`). On Windows npm makes a `counterparts.cmd` and a
|
|
12
|
+
* `counterparts.ps1` beside an extensionless shell script, and writes into
|
|
13
|
+
* both whatever the first line named: `/bin/sh`, which neither cmd.exe nor
|
|
14
|
+
* PowerShell can find. Typed in PowerShell, `counterparts` was "not
|
|
15
|
+
* recognized". The first line cannot name Node instead: the kernel reads the
|
|
16
|
+
* same line on macOS and Linux, and a machine with Bun and no Node (`bun add
|
|
17
|
+
* -g counterparts`) would lose the console.
|
|
18
|
+
*
|
|
19
|
+
* So this rewrites the `.cmd` and `.ps1` that npm wrote for THIS package's four
|
|
20
|
+
* bins, in the global prefix, to run `node` (the one beside them, else on PATH,
|
|
21
|
+
* as npm's own shims for a Node bin do) — and nothing else. A file is changed
|
|
22
|
+
* only when it has npm's exact shim shape (the target line `read-cmd-shim`
|
|
23
|
+
* reads) AND that target is this package's own bin for that name. A local
|
|
24
|
+
* install (`npm i counterparts` in a project) is left alone: its launchers are
|
|
25
|
+
* in `node_modules/.bin`, not on a person's PATH, and its project root may hold
|
|
26
|
+
* files of the same name that are somebody else's (W1 review). The
|
|
27
|
+
* extensionless shell script is left as npm wrote it; Git Bash runs it through
|
|
28
|
+
* `/bin/sh` and the polyglot line as on Linux.
|
|
29
|
+
*
|
|
30
|
+
* It never fails the install: whatever goes wrong, it says one line and exits
|
|
31
|
+
* 0. With `--ignore-scripts` it does not run; the commands then work from Git
|
|
32
|
+
* Bash, and `docs/QUICKSTART.md` says how to run them from PowerShell.
|
|
33
|
+
*/
|
|
34
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
35
|
+
import { basename, dirname, join } from "node:path";
|
|
36
|
+
import { fileURLToPath } from "node:url";
|
|
37
|
+
|
|
38
|
+
/** Each bin by the name npm links (`package.json#bin`) → its file under the package. */
|
|
39
|
+
export const BINS = {
|
|
40
|
+
counterparts: "src/adapters/cli/bin/counterparts.mjs",
|
|
41
|
+
"counterparts-hook": "src/adapters/claude-code/bin/hook.mjs",
|
|
42
|
+
"counterparts-mcp": "src/adapters/mcp/bin/serve.mjs",
|
|
43
|
+
"counterparts-dashboard": "src/adapters/dashboard/bin/dashboard.mjs",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The target line of npm's shims, as `read-cmd-shim` reads them: the `.cmd`
|
|
47
|
+
* (`%dp0%`, or `%~dp0` from older npm) and the `.ps1` (`$basedir`). */
|
|
48
|
+
const CMD_TARGET = /"%(?:dp0%|~dp0)\\([^"]+?)"\s+%\*/;
|
|
49
|
+
const PS1_TARGET = /"\$basedir\/([^"]+?)"\s+\$args/;
|
|
50
|
+
|
|
51
|
+
/** A shim's text with `/bin/sh` made `node`, or null when it is not npm's shim
|
|
52
|
+
* for exactly `target` (the bin's path from the prefix, `/`-separated) or
|
|
53
|
+
* names no `/bin/sh`. The longer spellings are replaced first. */
|
|
54
|
+
export function rewriteShim(text, ext, target) {
|
|
55
|
+
const m = (ext === ".cmd" ? CMD_TARGET : PS1_TARGET).exec(text);
|
|
56
|
+
if (m === null) return null;
|
|
57
|
+
const named = (m[1] ?? "").replace(/\\/g, "/");
|
|
58
|
+
if (named !== target) return null;
|
|
59
|
+
if (!text.includes("/bin/sh")) return null;
|
|
60
|
+
return text.split("\\/bin/sh").join("\\node").split("//bin/sh").join("/node").split("/bin/sh").join("node");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The global prefix npm linked this package's bins into, or null when this is
|
|
64
|
+
* not a global install there: `<prefix>\node_modules\<pkg>` → `<prefix>`, the
|
|
65
|
+
* layout of a Windows global install. */
|
|
66
|
+
export function globalBinDir(packageDir, env = process.env) {
|
|
67
|
+
if (String(env.npm_config_global ?? "").toLowerCase() !== "true") return null;
|
|
68
|
+
const parent = dirname(packageDir);
|
|
69
|
+
if (basename(parent) !== "node_modules") return null;
|
|
70
|
+
return dirname(parent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Rewrite what needs it; the names of the files changed. */
|
|
74
|
+
export function fixShims(packageDir, platform = process.platform, env = process.env) {
|
|
75
|
+
if (platform !== "win32") return [];
|
|
76
|
+
const dir = globalBinDir(packageDir, env);
|
|
77
|
+
if (dir === null) return [];
|
|
78
|
+
const changed = [];
|
|
79
|
+
const pkgName = basename(packageDir);
|
|
80
|
+
for (const [name, file] of Object.entries(BINS)) {
|
|
81
|
+
const target = `node_modules/${pkgName}/${file}`;
|
|
82
|
+
for (const ext of [".cmd", ".ps1"]) {
|
|
83
|
+
const shim = join(dir, `${name}${ext}`);
|
|
84
|
+
if (!existsSync(shim)) continue;
|
|
85
|
+
const text = readFileSync(shim, "utf8");
|
|
86
|
+
const next = rewriteShim(text, ext, target);
|
|
87
|
+
if (next === null || next === text) continue;
|
|
88
|
+
writeFileSync(shim, next, "utf8");
|
|
89
|
+
changed.push(shim);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return changed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const self = fileURLToPath(import.meta.url);
|
|
96
|
+
if (process.argv[1] !== undefined && basename(process.argv[1]) === basename(self)) {
|
|
97
|
+
try {
|
|
98
|
+
fixShims(join(dirname(self), "..", ".."));
|
|
99
|
+
} catch (err) {
|
|
100
|
+
process.stderr.write(`counterparts: could not adjust the Windows launchers (${err instanceof Error ? err.message : String(err)}); run it from Git Bash, or see docs/QUICKSTART.md.\n`);
|
|
101
|
+
}
|
|
102
|
+
}
|