@cotal-ai/connector-claude-code 0.85.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3643,49 +3643,49 @@ var require_fast_uri = __commonJS({
3643
3643
  schemelessOptions.skipEscape = true;
3644
3644
  return serialize(resolved, schemelessOptions);
3645
3645
  }
3646
- function resolveComponent(base, relative, options, skipNormalization) {
3646
+ function resolveComponent(base, relative2, options, skipNormalization) {
3647
3647
  const target = {};
3648
3648
  if (!skipNormalization) {
3649
3649
  base = parse3(serialize(base, options), options);
3650
- relative = parse3(serialize(relative, options), options);
3650
+ relative2 = parse3(serialize(relative2, options), options);
3651
3651
  }
3652
3652
  options = options || {};
3653
- if (!options.tolerant && relative.scheme) {
3654
- target.scheme = relative.scheme;
3655
- target.userinfo = relative.userinfo;
3656
- target.host = relative.host;
3657
- target.port = relative.port;
3658
- target.path = removeDotSegments(relative.path || "");
3659
- target.query = relative.query;
3653
+ if (!options.tolerant && relative2.scheme) {
3654
+ target.scheme = relative2.scheme;
3655
+ target.userinfo = relative2.userinfo;
3656
+ target.host = relative2.host;
3657
+ target.port = relative2.port;
3658
+ target.path = removeDotSegments(relative2.path || "");
3659
+ target.query = relative2.query;
3660
3660
  } else {
3661
- if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
3662
- target.userinfo = relative.userinfo;
3663
- target.host = relative.host;
3664
- target.port = relative.port;
3665
- target.path = removeDotSegments(relative.path || "");
3666
- target.query = relative.query;
3661
+ if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
3662
+ target.userinfo = relative2.userinfo;
3663
+ target.host = relative2.host;
3664
+ target.port = relative2.port;
3665
+ target.path = removeDotSegments(relative2.path || "");
3666
+ target.query = relative2.query;
3667
3667
  } else {
3668
- if (!relative.path) {
3668
+ if (!relative2.path) {
3669
3669
  target.path = base.path;
3670
- if (relative.query !== void 0) {
3671
- target.query = relative.query;
3670
+ if (relative2.query !== void 0) {
3671
+ target.query = relative2.query;
3672
3672
  } else {
3673
3673
  target.query = base.query;
3674
3674
  }
3675
3675
  } else {
3676
- if (relative.path[0] === "/") {
3677
- target.path = removeDotSegments(relative.path);
3676
+ if (relative2.path[0] === "/") {
3677
+ target.path = removeDotSegments(relative2.path);
3678
3678
  } else {
3679
3679
  if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
3680
- target.path = "/" + relative.path;
3680
+ target.path = "/" + relative2.path;
3681
3681
  } else if (!base.path) {
3682
- target.path = relative.path;
3682
+ target.path = relative2.path;
3683
3683
  } else {
3684
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
3684
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
3685
3685
  }
3686
3686
  target.path = removeDotSegments(target.path);
3687
3687
  }
3688
- target.query = relative.query;
3688
+ target.query = relative2.query;
3689
3689
  }
3690
3690
  target.userinfo = base.userinfo;
3691
3691
  target.host = base.host;
@@ -3693,7 +3693,7 @@ var require_fast_uri = __commonJS({
3693
3693
  }
3694
3694
  target.scheme = base.scheme;
3695
3695
  }
3696
- target.fragment = relative.fragment;
3696
+ target.fragment = relative2.fragment;
3697
3697
  return target;
3698
3698
  }
3699
3699
  function equal(uriA, uriB, options) {
@@ -6886,10 +6886,10 @@ var require_dist = __commonJS({
6886
6886
 
6887
6887
  // src/setup.ts
6888
6888
  import { spawn, spawnSync } from "node:child_process";
6889
- import { randomUUID } from "node:crypto";
6890
- import { cpSync, existsSync as existsSync2, mkdirSync, readdirSync, readFileSync as readFileSync2, renameSync, rmSync, writeFileSync } from "node:fs";
6891
- import { homedir as homedir2 } from "node:os";
6892
- import { dirname, join as join3 } from "node:path";
6889
+ import { createHash as createHash2, randomUUID } from "node:crypto";
6890
+ import { cpSync, existsSync as existsSync3, mkdirSync, readdirSync, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
6891
+ import { homedir as homedir3 } from "node:os";
6892
+ import { dirname as dirname2, join as join4, relative } from "node:path";
6893
6893
  import { fileURLToPath } from "node:url";
6894
6894
  import {
6895
6895
  globalConfigPath,
@@ -6907,7 +6907,7 @@ import { LAUNCH_MATERIAL_ENV, readLaunchMaterial } from "@cotal-ai/core/launch-m
6907
6907
  import { normalizeMentions, RUN_LAUNCH_DEADLINE_MS, subjectMatches, isConcreteChannel as isConcreteChannel2, assertValidChannel as assertValidChannel2, channelInAllow as channelInAllow2, resolvePeer as resolvePeerInRoster, peerLabel as peerLabel2, CotalEndpoint, acquireLocalConsumer, BASELINE_LIFECYCLE_ENDPOINT as BASELINE_LIFECYCLE_ENDPOINT2, BIND_SPLIT_REISSUES, assertLifecycleToken as assertLifecycleToken2, EpEnvelopeError as EpEnvelopeError2, isPublishPermissionDenied, unansweredRequest, controlReplyFrom, controlReplyFromThrown, runAgentBearer, partsToText, assertValidRole } from "@cotal-ai/core";
6908
6908
 
6909
6909
  // ../connector-core/dist/framing.js
6910
- import { peerLabel } from "@cotal-ai/core";
6910
+ import { peerLabel } from "@cotal-ai/core/peer-label";
6911
6911
 
6912
6912
  // ../connector-core/dist/manager-call.js
6913
6913
  import { BASELINE_LIFECYCLE_ENDPOINT, EpEnvelopeError, dialerFor, goalFollowRefusal, invokeCommand, isPermissionDenied, issuedUserCaller, managerCallerBinding, replyRefusedBeforeEffect, resolveService, standaloneConnectOpts } from "@cotal-ai/core";
@@ -6934,6 +6934,7 @@ function controlEndpoint(space, name, token = randomBytes(32).toString("base64ur
6934
6934
 
6935
6935
  // ../connector-core/dist/launch.js
6936
6936
  import { eventChannel as eventChannel2, LAUNCH_MATERIAL_ENV as LAUNCH_MATERIAL_ENV3, parsePrincipalKey, principalKey, writeLaunchMaterial } from "@cotal-ai/core";
6937
+ import { dirname } from "node:path";
6937
6938
  import { EVENT_CHANNEL_PREFIX, eventChannel as eventChannel3, eventChannelPrincipal, isEventChannel } from "@cotal-ai/core";
6938
6939
  var OS_ENV_ALLOW = [
6939
6940
  "PATH",
@@ -7049,7 +7050,7 @@ function connectorLaunchOptions(connector, launchOptions) {
7049
7050
  throw new Error(`${connector} connector: launch option key ${JSON.stringify(k)} is not a valid flag name`);
7050
7051
  return Object.entries(launchOptions);
7051
7052
  }
7052
- function materialEnv(opts) {
7053
+ function materialEnv(opts, artifacts) {
7053
7054
  if (opts.userAuth && opts.creds)
7054
7055
  throw new Error("launch: creds (static auth) and userAuth (user-mode auth) are mutually exclusive \u2014 one launch carries one identity plane");
7055
7056
  const material = {};
@@ -7067,7 +7068,9 @@ function materialEnv(opts) {
7067
7068
  material.userAuth = opts.userAuth;
7068
7069
  if (Object.keys(material).length === 0)
7069
7070
  return {};
7070
- return { [LAUNCH_MATERIAL_ENV3]: writeLaunchMaterial(material) };
7071
+ const path = writeLaunchMaterial(material);
7072
+ artifacts.push(dirname(path));
7073
+ return { [LAUNCH_MATERIAL_ENV3]: path };
7071
7074
  }
7072
7075
  function launchArmsEvents(opts) {
7073
7076
  return opts.events !== false || opts.eventsRequired === true;
@@ -21774,7 +21777,7 @@ function date4(params) {
21774
21777
  config(en_default());
21775
21778
 
21776
21779
  // ../connector-core/dist/tool-specs.js
21777
- import { isConcreteChannel as isConcreteChannel3, channelInAllow as channelInAllow3, AmbiguousPeerError, peerLabel as peerLabel4, assertLifecycleToken as assertLifecycleToken3, isPermissionDenied as isPermissionDenied2, renderLifecycleBlocked, EpEnvelopeError as EpEnvelopeError3, LANG_PROBLEM_DETAIL_KIND, formatAge, presenceAges } from "@cotal-ai/core";
21780
+ import { isConcreteChannel as isConcreteChannel3, channelInAllow as channelInAllow3, AmbiguousPeerError, peerLabel as peerLabel4, assertLifecycleToken as assertLifecycleToken3, isPermissionDenied as isPermissionDenied2, renderLifecycleBlocked, EpEnvelopeError as EpEnvelopeError3, LANG_PROBLEM_DETAIL_KIND, formatAge, presenceAges, presenceText } from "@cotal-ai/core";
21778
21781
 
21779
21782
  // ../connector-core/dist/orientation.js
21780
21783
  import { peerLabel as peerLabel3 } from "@cotal-ai/core";
@@ -21784,6 +21787,14 @@ var STOP = new Set("a an and are as at be by do for from has how in is it of on
21784
21787
 
21785
21788
  // ../connector-core/dist/tool-specs.js
21786
21789
  var NO_TOOL_ARGS = external_exports.strictObject({});
21790
+ var managerInstanceArg = external_exports.string().refine((value) => {
21791
+ try {
21792
+ assertLifecycleToken3(value, "instance");
21793
+ return true;
21794
+ } catch {
21795
+ return false;
21796
+ }
21797
+ }, "instance must be a lifecycle token ([a-z0-9]{26,32})").optional().describe("Optional manager instance id for a multi-manager space. When omitted, a seat a manager launched uses that manager and any other caller lets the mesh select one; on a user-auth mesh with several of your managers live, that selection refuses and lists their ids. A pin that cannot be resolved is refused without falling back to another manager.");
21787
21798
 
21788
21799
  // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
21789
21800
  var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
@@ -23513,21 +23524,66 @@ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
23513
23524
  // ../connector-core/dist/gateway.js
23514
23525
  import { assertValidName } from "@cotal-ai/core";
23515
23526
  var CONNECTION_ID = external_exports.string().min(1).describe("The connection_id cotal_connect returned in THIS conversation. Never reuse another conversation's.");
23527
+ var GATEWAY_LISTENING = "Messages reach you only when you call a tool: to listen, call cotal_wait, which returns as soon as a message arrives. When the person asks you to stay on Cotal or keep listening, call cotal_wait again each time it returns and handle each message as it arrives, until they ask you to stop.";
23528
+ var GATEWAY_CONNECTING = "Cotal connects this conversation to the person's Cotal space. Call cotal_connect once with a short name for this conversation, then pass the returned connection_id on every other cotal tool call. Each conversation needs its own connection. Never reuse another conversation's connection_id.";
23529
+ var GATEWAY_INSTRUCTIONS = `${GATEWAY_CONNECTING} ${GATEWAY_LISTENING}`;
23516
23530
 
23517
23531
  // ../connector-core/dist/control.js
23518
23532
  var MAX_FRAME_BYTES = 1 << 20;
23519
23533
 
23520
- // src/user-mcp.ts
23521
- import { existsSync, readFileSync } from "node:fs";
23534
+ // src/cli-record.ts
23535
+ var CLI_RECORD = "cli.json";
23536
+
23537
+ // src/desktop-config.ts
23538
+ import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
23522
23539
  import { homedir } from "node:os";
23523
23540
  import { join as join2 } from "node:path";
23541
+ var DESKTOP_SERVER = "cotal";
23542
+ function desktopConfigPath(platform = process.platform, env = process.env, home = homedir()) {
23543
+ if (platform === "darwin") return join2(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
23544
+ if (platform === "win32" && env.APPDATA) return join2(env.APPDATA, "Claude", "claude_desktop_config.json");
23545
+ return void 0;
23546
+ }
23547
+ function readConfig(path) {
23548
+ if (!existsSync(path)) return {};
23549
+ const text = readFileSync(path, "utf8");
23550
+ let parsed;
23551
+ try {
23552
+ parsed = text.trim() ? JSON.parse(text) : {};
23553
+ } catch {
23554
+ throw new Error(`${path} is not valid JSON, so Cotal left it alone. Fix it, then run \`cotal setup\` again.`);
23555
+ }
23556
+ const servers = parsed?.mcpServers;
23557
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || servers !== void 0 && (!servers || typeof servers !== "object" || Array.isArray(servers)))
23558
+ throw new Error(`${path} is not a Claude Desktop config (an object whose mcpServers is an object), so Cotal left it alone.`);
23559
+ return parsed;
23560
+ }
23561
+ function readDesktopEntry(path) {
23562
+ return readConfig(path).mcpServers?.[DESKTOP_SERVER];
23563
+ }
23564
+ function writeDesktopEntry(path, entry) {
23565
+ const config2 = readConfig(path);
23566
+ const before = config2.mcpServers?.[DESKTOP_SERVER];
23567
+ if (JSON.stringify(before) === JSON.stringify(entry)) return "current";
23568
+ config2.mcpServers = { ...config2.mcpServers, [DESKTOP_SERVER]: entry };
23569
+ const tmp = `${path}.cotal-${process.pid}`;
23570
+ writeFileSync(tmp, `${JSON.stringify(config2, null, 2)}
23571
+ `, { mode: existsSync(path) ? statSync(path).mode & 511 : 384 });
23572
+ renameSync(tmp, path);
23573
+ return before === void 0 ? "added" : "updated";
23574
+ }
23575
+
23576
+ // src/user-mcp.ts
23577
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
23578
+ import { homedir as homedir2 } from "node:os";
23579
+ import { join as join3 } from "node:path";
23524
23580
  import { mcpServerProblem } from "@cotal-ai/core";
23525
23581
  function claudeUserMcpServers() {
23526
- const path = join2(process.env.CLAUDE_CONFIG_DIR?.trim() || homedir(), ".claude.json");
23527
- if (!existsSync(path)) return {};
23582
+ const path = join3(process.env.CLAUDE_CONFIG_DIR?.trim() || homedir2(), ".claude.json");
23583
+ if (!existsSync2(path)) return {};
23528
23584
  let config2;
23529
23585
  try {
23530
- config2 = JSON.parse(readFileSync(path, "utf8"));
23586
+ config2 = JSON.parse(readFileSync2(path, "utf8"));
23531
23587
  } catch (e) {
23532
23588
  throw new Error(`${path}: invalid JSON - ${e.message}`);
23533
23589
  }
@@ -23540,91 +23596,130 @@ function claudeUserMcpEnvKeys() {
23540
23596
 
23541
23597
  // src/setup.ts
23542
23598
  var PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
23599
+ var COTAL_ASSETS = [".claude-plugin", ".mcp.json", "hooks", "monitors", "dist/mcp.cjs", "dist/hook.cjs", "dist/monitor.cjs"];
23600
+ function pluginVersion(root, assets, files) {
23601
+ const hash2 = createHash2("sha256");
23602
+ const add = (path, bytes) => hash2.update(`${path}\0${bytes.length}\0`).update(bytes);
23603
+ const walk = (path) => {
23604
+ if (statSync2(path).isDirectory()) for (const entry of readdirSync(path).sort()) walk(join4(path, entry));
23605
+ else add(relative(root, path), readFileSync3(path));
23606
+ };
23607
+ for (const asset of [...assets].sort()) walk(join4(root, asset));
23608
+ for (const [path, text] of Object.entries(files).sort(([a], [b]) => a.localeCompare(b))) add(path, text);
23609
+ const release = JSON.parse(readFileSync3(join4(PACKAGE_ROOT, "package.json"), "utf8")).version;
23610
+ return `${release}+${hash2.digest("hex").slice(0, 12)}`;
23611
+ }
23612
+ function materializeCotal(cotal) {
23613
+ for (const asset of COTAL_ASSETS) if (!existsSync3(join4(PACKAGE_ROOT, asset))) throw new Error(`plugin asset missing: ${join4(PACKAGE_ROOT, asset)}`);
23614
+ const files = { [`dist/${CLI_RECORD}`]: `${JSON.stringify({ argv: cotal })}
23615
+ ` };
23616
+ const version2 = pluginVersion(PACKAGE_ROOT, COTAL_ASSETS, files);
23617
+ materialize("cotal", PACKAGE_ROOT, COTAL_ASSETS, version2, files);
23618
+ return version2;
23619
+ }
23620
+ function desktopEntry(cotal) {
23621
+ return {
23622
+ command: cotal[0],
23623
+ args: [join4(marketplaceDir(), "cotal", "dist", "mcp.cjs"), "--desktop"],
23624
+ ...process.env.COTAL_HOME ? { env: { COTAL_HOME: process.env.COTAL_HOME } } : {}
23625
+ };
23626
+ }
23627
+ function desktop(cotal, add) {
23628
+ const path = desktopConfigPath();
23629
+ if (!path || !existsSync3(dirname2(path))) return void 0;
23630
+ if (!add && readDesktopEntry(path) === void 0) return void 0;
23631
+ const state = writeDesktopEntry(path, desktopEntry(cotal));
23632
+ return `Claude Desktop ${state}${state === "current" ? "" : "; quit and reopen Claude Desktop to load it"}`;
23633
+ }
23543
23634
  var DOCS_URL = "https://github.com/Cotal-AI/Cotal/blob/main/docs/connect-claude.md";
23544
23635
  var MARKETPLACE = "cotal-mesh";
23545
23636
  function cotalHome() {
23546
23637
  if (process.env.COTAL_HOME) return process.env.COTAL_HOME;
23547
- if (process.platform === "win32" && process.env.LOCALAPPDATA) return join3(process.env.LOCALAPPDATA, "Cotal");
23548
- return join3(homedir2(), ".cotal");
23638
+ if (process.platform === "win32" && process.env.LOCALAPPDATA) return join4(process.env.LOCALAPPDATA, "Cotal");
23639
+ return join4(homedir3(), ".cotal");
23549
23640
  }
23550
23641
  function marketplaceDir() {
23551
- return join3(cotalHome(), "claude-plugin");
23642
+ return join4(cotalHome(), "claude-plugin");
23552
23643
  }
23553
- function materialize(name, root, assets, version2) {
23644
+ function materialize(name, root, assets, version2, files = {}) {
23554
23645
  const market = marketplaceDir();
23555
23646
  mkdirSync(market, { recursive: true });
23556
- const dest = join3(market, name);
23647
+ const dest = join4(market, name);
23557
23648
  const staging = `${dest}.staging.${process.pid}`;
23558
23649
  const old = `${dest}.old.${process.pid}`;
23559
23650
  const orphans = readdirSync(market, { withFileTypes: true }).filter((entry) => entry.isDirectory() && (entry.name.startsWith(`${name}.old.`) || entry.name.startsWith(`${name}.staging.`))).map((entry) => entry.name);
23560
- if (!existsSync2(dest)) {
23651
+ if (!existsSync3(dest)) {
23561
23652
  const recoverable = orphans.find((entry) => entry.startsWith(`${name}.old.`));
23562
- if (recoverable) renameSync(join3(market, recoverable), dest);
23653
+ if (recoverable) renameSync2(join4(market, recoverable), dest);
23563
23654
  }
23564
- for (const entry of orphans) rmSync(join3(market, entry), { recursive: true, force: true });
23655
+ for (const entry of orphans) rmSync(join4(market, entry), { recursive: true, force: true });
23565
23656
  let movedAside = false;
23566
23657
  let swapped = false;
23567
23658
  try {
23568
23659
  mkdirSync(staging, { recursive: true });
23569
23660
  for (const asset of assets) {
23570
- const destination = join3(staging, asset);
23571
- mkdirSync(join3(destination, ".."), { recursive: true });
23572
- cpSync(join3(root, asset), destination, { recursive: true, dereference: true });
23661
+ const destination = join4(staging, asset);
23662
+ mkdirSync(join4(destination, ".."), { recursive: true });
23663
+ cpSync(join4(root, asset), destination, { recursive: true, dereference: true });
23573
23664
  }
23665
+ for (const [path, text] of Object.entries(files)) writeFileSync2(join4(staging, path), text);
23574
23666
  if (version2) {
23575
- const manifestPath = join3(staging, ".claude-plugin", "plugin.json");
23576
- const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
23667
+ const manifestPath = join4(staging, ".claude-plugin", "plugin.json");
23668
+ const manifest = JSON.parse(readFileSync3(manifestPath, "utf8"));
23577
23669
  manifest.version = version2;
23578
- writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
23670
+ writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
23579
23671
  }
23580
- if (existsSync2(dest)) {
23581
- renameSync(dest, old);
23672
+ if (existsSync3(dest)) {
23673
+ renameSync2(dest, old);
23582
23674
  movedAside = true;
23583
23675
  }
23584
- renameSync(staging, dest);
23676
+ renameSync2(staging, dest);
23585
23677
  swapped = true;
23586
23678
  if (movedAside) rmSync(old, { recursive: true, force: true });
23587
23679
  } catch (error51) {
23588
- if (movedAside && !swapped && !existsSync2(dest) && existsSync2(old)) renameSync(old, dest);
23680
+ if (movedAside && !swapped && !existsSync3(dest) && existsSync3(old)) renameSync2(old, dest);
23589
23681
  throw error51;
23590
23682
  } finally {
23591
23683
  rmSync(staging, { recursive: true, force: true });
23592
23684
  if (swapped) rmSync(old, { recursive: true, force: true });
23593
23685
  }
23594
23686
  }
23687
+ var CLAUDE_OUTPUT_LIMIT = 64 * 1024 * 1024;
23595
23688
  function command(...args) {
23596
- const result = spawnSync("claude", args, { encoding: "utf8" });
23689
+ return commandIn(process.cwd(), ...args);
23690
+ }
23691
+ function commandIn(cwd, ...args) {
23692
+ const result = spawnSync("claude", args, { cwd, encoding: "utf8", maxBuffer: CLAUDE_OUTPUT_LIMIT });
23693
+ if (result.error) return { status: null, output: result.error.message };
23597
23694
  return { status: result.status, output: `${result.stdout ?? ""}${result.stderr ?? ""}`.trim() };
23598
23695
  }
23599
23696
  function marketplaceEntry(market, name) {
23600
- const manifest = JSON.parse(readFileSync2(join3(market, name, ".claude-plugin", "plugin.json"), "utf8"));
23697
+ const manifest = JSON.parse(readFileSync3(join4(market, name, ".claude-plugin", "plugin.json"), "utf8"));
23601
23698
  const description = typeof manifest.description === "string" ? manifest.description : void 0;
23602
23699
  return { name, source: `./${name}`, ...description ? { description } : {} };
23603
23700
  }
23604
23701
  function marketplaceManifest(market) {
23605
- const plugins = ["cotal", "cotal-skills"].filter((name) => existsSync2(join3(market, name, ".claude-plugin", "plugin.json"))).map((name) => marketplaceEntry(market, name));
23702
+ const plugins = ["cotal", "cotal-skills"].filter((name) => existsSync3(join4(market, name, ".claude-plugin", "plugin.json"))).map((name) => marketplaceEntry(market, name));
23606
23703
  return { name: MARKETPLACE, description: "Cotal for Claude Code", owner: { name: "Cotal" }, plugins };
23607
23704
  }
23608
23705
  function writeMarketplaceManifest(market) {
23609
- const path = join3(market, ".claude-plugin", "marketplace.json");
23610
- mkdirSync(dirname(path), { recursive: true });
23611
- writeFileSync(path, JSON.stringify(marketplaceManifest(market), null, 2) + "\n");
23706
+ const path = join4(market, ".claude-plugin", "marketplace.json");
23707
+ mkdirSync(dirname2(path), { recursive: true });
23708
+ writeFileSync2(path, JSON.stringify(marketplaceManifest(market), null, 2) + "\n");
23612
23709
  return path;
23613
23710
  }
23614
23711
  function writeMarketplace() {
23615
23712
  const market = marketplaceDir();
23616
23713
  writeMarketplaceManifest(market);
23617
23714
  const add = command("plugin", "marketplace", "add", market);
23618
- if (add.status !== 0 && !/already (?:exists|added)/i.test(add.output)) throw new Error(`plugin marketplace add failed:
23715
+ if (add.status !== 0 && !/already (?:exists|added|on disk)/i.test(add.output)) throw new Error(`plugin marketplace add failed:
23619
23716
  ${add.output}`);
23620
- if (/already (?:exists|added)/i.test(add.output)) {
23621
- const update = command("plugin", "marketplace", "update", MARKETPLACE);
23622
- if (update.status !== 0) throw new Error(`plugin marketplace update failed:
23717
+ const update = command("plugin", "marketplace", "update", MARKETPLACE);
23718
+ if (update.status !== 0) throw new Error(`plugin marketplace update failed:
23623
23719
  ${update.output}`);
23624
- }
23625
23720
  }
23626
- function verify(name, scope, expectedVersion) {
23627
- const result = command("plugin", "list", "--json");
23721
+ function listPlugins(cwd = process.cwd()) {
23722
+ const result = commandIn(cwd, "plugin", "list", "--json");
23628
23723
  if (result.status !== 0) throw new Error(`plugin list failed:
23629
23724
  ${result.output}`);
23630
23725
  let entries;
@@ -23634,9 +23729,16 @@ ${result.output}`);
23634
23729
  throw new Error(`could not parse plugin list:
23635
23730
  ${result.output}`);
23636
23731
  }
23637
- const match = Array.isArray(entries) ? entries.find((entry) => entry && typeof entry === "object" && entry.id === `${name}@${MARKETPLACE}` && entry.scope === scope) : void 0;
23638
- if (!match || match.enabled !== true || match.errors?.length)
23639
- throw new Error(`plugin ${name}@${MARKETPLACE} (${scope} scope) did not load`);
23732
+ if (!Array.isArray(entries)) throw new Error(`could not parse plugin list:
23733
+ ${result.output}`);
23734
+ return entries;
23735
+ }
23736
+ function verify(name, scope, expectedVersion) {
23737
+ const match = listPlugins(cotalHome()).find((entry) => entry.id === `${name}@${MARKETPLACE}` && entry.scope === scope);
23738
+ const where = `${scope} scope`;
23739
+ if (!match) throw new Error(`plugin ${name}@${MARKETPLACE} (${where}) is not installed`);
23740
+ if (match.enabled !== true || match.errors?.length)
23741
+ throw new Error(`plugin ${name}@${MARKETPLACE} (${where}) did not load: ${JSON.stringify({ enabled: match.enabled, errors: match.errors })}`);
23640
23742
  if (expectedVersion && match.version !== expectedVersion)
23641
23743
  throw new Error(`plugin ${name}@${MARKETPLACE} loaded version ${String(match.version)}; expected ${expectedVersion}`);
23642
23744
  }
@@ -23652,9 +23754,26 @@ ${update.output}`);
23652
23754
  }
23653
23755
  verify(name, scope, expectedVersion);
23654
23756
  }
23757
+ function retireProjectInstalls() {
23758
+ let removed = 0;
23759
+ const failed = [];
23760
+ for (const entry of listPlugins()) {
23761
+ if (entry.id !== `cotal@${MARKETPLACE}` || entry.scope !== "local" || typeof entry.projectPath !== "string") continue;
23762
+ if (!statSync2(entry.projectPath, { throwIfNoEntry: false })?.isDirectory()) continue;
23763
+ const result = commandIn(entry.projectPath, "plugin", "uninstall", `cotal@${MARKETPLACE}`, "--scope", "local");
23764
+ if (result.status === 0) removed += 1;
23765
+ else failed.push(`${entry.projectPath}: ${result.output}`);
23766
+ }
23767
+ if (failed.length)
23768
+ throw new Error(
23769
+ `cotal@${MARKETPLACE} is installed at user scope, but ${failed.length} earlier per-project install${failed.length === 1 ? "" : "s"} could not be removed. In each directory, run \`claude plugin uninstall cotal@${MARKETPLACE} --scope local\`:
23770
+ ${failed.join("\n")}`
23771
+ );
23772
+ return removed;
23773
+ }
23655
23774
  function pluginList() {
23656
- const result = spawnSync("claude", ["plugin", "list", "--json"], { encoding: "utf8" });
23657
- if (result.status !== 0) return void 0;
23775
+ const result = spawnSync("claude", ["plugin", "list", "--json"], { encoding: "utf8", maxBuffer: CLAUDE_OUTPUT_LIMIT });
23776
+ if (result.error || result.status !== 0) return void 0;
23658
23777
  try {
23659
23778
  const parsed = JSON.parse(result.stdout || "[]");
23660
23779
  return Array.isArray(parsed) ? parsed : void 0;
@@ -23672,6 +23791,39 @@ function skillsRow(entries, { version: version2, skillsRemedy }) {
23672
23791
  if (match.version === version2) return row("ok", "current");
23673
23792
  return row("warn", `${typeof match.version === "string" ? `v${match.version} \u2260 v${version2} \xB7 ` : ""}stale \xB7 ${skillsRemedy}`);
23674
23793
  }
23794
+ function pluginRow(entries, { version: version2 }) {
23795
+ const row = (state, text) => ({ label: "Claude plugin", state, text });
23796
+ if (entries === void 0) return row("off", "unknown");
23797
+ const installs = entries.filter((entry) => entry.id === `cotal@${MARKETPLACE}`);
23798
+ if (!installs.length) return row("off", "not installed");
23799
+ if (installs.some((entry) => Array.isArray(entry.errors) ? entry.errors.length > 0 : Boolean(entry.errors ?? entry.error)))
23800
+ return row("error", "load error \xB7 run `cotal setup`");
23801
+ let materialized;
23802
+ try {
23803
+ materialized = JSON.parse(readFileSync3(join4(marketplaceDir(), "cotal", ".claude-plugin", "plugin.json"), "utf8")).version;
23804
+ } catch {
23805
+ materialized = void 0;
23806
+ }
23807
+ if (typeof materialized !== "string" || !materialized.startsWith(`${version2}+`)) return row("warn", "stale \xB7 run `cotal setup`");
23808
+ if (installs.some((entry) => entry.scope === "user")) return row("ok", "current (user scope)");
23809
+ return row("ok", `current (${installs.length} install${installs.length === 1 ? "" : "s"})`);
23810
+ }
23811
+ function desktopRow() {
23812
+ const path = desktopConfigPath();
23813
+ if (!path || !existsSync3(dirname2(path))) return void 0;
23814
+ const row = (state, text) => ({ label: "Claude Desktop", state, text });
23815
+ let entry;
23816
+ try {
23817
+ entry = readDesktopEntry(path);
23818
+ } catch (e) {
23819
+ return row("error", e.message);
23820
+ }
23821
+ if (entry === void 0) return row("off", "not added \xB7 run `cotal setup`");
23822
+ const server = entry.args;
23823
+ const expected = join4(marketplaceDir(), "cotal", "dist", "mcp.cjs");
23824
+ if (!Array.isArray(server) || server[0] !== expected || !existsSync3(expected)) return row("warn", "stale \xB7 run `cotal setup`");
23825
+ return row("ok", "added");
23826
+ }
23675
23827
  function copyable(name, spec) {
23676
23828
  if (mcpServerProblem2(name, spec) !== void 0) return false;
23677
23829
  const { env, headers } = spec;
@@ -23685,14 +23837,36 @@ var claudeSetupProvider = {
23685
23837
  connector: {
23686
23838
  name: "claude-plugin",
23687
23839
  title: "Install the Claude Code plugin",
23688
- explain: "Lets a Claude Code session join the web and wake on peer messages.",
23840
+ explain: "Lets every Claude Code session on this machine join the web and wake on peer messages.",
23689
23841
  context: [DOCS_URL],
23690
- run() {
23691
- for (const asset of ["dist/mcp.cjs", "dist/hook.cjs", ".claude-plugin/plugin.json", ".mcp.json", "hooks/hooks.json"])
23692
- if (!existsSync2(join3(PACKAGE_ROOT, asset))) throw new Error(`plugin asset missing: ${join3(PACKAGE_ROOT, asset)}`);
23693
- materialize("cotal", PACKAGE_ROOT, [".claude-plugin", ".mcp.json", "hooks", "dist/mcp.cjs", "dist/hook.cjs"]);
23694
- install("cotal", "local");
23695
- return `cotal@${MARKETPLACE} (local scope)`;
23842
+ run({ cotal }) {
23843
+ materializeCotal(cotal);
23844
+ install("cotal", "user");
23845
+ const app = desktop(cotal, true);
23846
+ const removed = retireProjectInstalls();
23847
+ const replaced = removed ? `, replacing ${removed} project install${removed === 1 ? "" : "s"}` : "";
23848
+ return `cotal@${MARKETPLACE} (user scope${replaced})${app ? `; ${app}` : ""}`;
23849
+ }
23850
+ },
23851
+ refresh: {
23852
+ name: "claude-plugin-refresh",
23853
+ title: "Refresh the Claude Code plugin",
23854
+ explain: "Rewrites the copy of the Cotal plugin that Claude Code sessions load, and Cotal's entry in Claude Desktop, for this release.",
23855
+ context: [DOCS_URL],
23856
+ run({ cotal }) {
23857
+ const code = listPlugins().some((entry) => entry.id === `cotal@${MARKETPLACE}`);
23858
+ const path = desktopConfigPath();
23859
+ const app = path !== void 0 && readDesktopEntry(path) !== void 0;
23860
+ if (!code && !app) return "not installed";
23861
+ const version2 = materializeCotal(cotal);
23862
+ const parts = [];
23863
+ if (code) {
23864
+ writeMarketplace();
23865
+ parts.push(`cotal@${MARKETPLACE} ${version2}; each Claude Code session loads it when it starts`);
23866
+ }
23867
+ const desktopText = app ? desktop(cotal, false) : void 0;
23868
+ if (desktopText) parts.push(desktopText);
23869
+ return parts.join("; ");
23696
23870
  }
23697
23871
  },
23698
23872
  skills: {
@@ -23701,14 +23875,14 @@ var claudeSetupProvider = {
23701
23875
  explain: "Installs Cotal's authored skills as a Claude Code plugin.",
23702
23876
  context: [DOCS_URL],
23703
23877
  run({ skillsDir, version: version2, stateDir }) {
23704
- const manifestRoot = join3(PACKAGE_ROOT, "skills-plugin");
23705
- if (!existsSync2(join3(manifestRoot, ".claude-plugin", "plugin.json"))) throw new Error("Claude skills plugin manifest is missing");
23706
- const payload = join3(stateDir, `.claude-skills-payload.${process.pid}`);
23878
+ const manifestRoot = join4(PACKAGE_ROOT, "skills-plugin");
23879
+ if (!existsSync3(join4(manifestRoot, ".claude-plugin", "plugin.json"))) throw new Error("Claude skills plugin manifest is missing");
23880
+ const payload = join4(stateDir, `.claude-skills-payload.${process.pid}`);
23707
23881
  rmSync(payload, { recursive: true, force: true });
23708
23882
  try {
23709
23883
  mkdirSync(payload, { recursive: true });
23710
- cpSync(join3(manifestRoot, ".claude-plugin"), join3(payload, ".claude-plugin"), { recursive: true, dereference: true });
23711
- cpSync(skillsDir, join3(payload, "skills"), { recursive: true, dereference: true });
23884
+ cpSync(join4(manifestRoot, ".claude-plugin"), join4(payload, ".claude-plugin"), { recursive: true, dereference: true });
23885
+ cpSync(skillsDir, join4(payload, "skills"), { recursive: true, dereference: true });
23712
23886
  materialize("cotal-skills", payload, [".claude-plugin", "skills"], version2);
23713
23887
  install("cotal-skills", "user", version2);
23714
23888
  return `cotal-skills@${MARKETPLACE} (user scope)`;
@@ -23747,11 +23921,8 @@ var claudeSetupProvider = {
23747
23921
  },
23748
23922
  status(input) {
23749
23923
  const plugins = pluginList();
23750
- const plugin = plugins?.some((entry) => entry.id === `cotal@${MARKETPLACE}`) ?? false;
23751
- return [
23752
- { label: "Claude plugin", state: plugin ? "ok" : "off", text: plugin ? "installed" : "not installed" },
23753
- skillsRow(plugins, input)
23754
- ];
23924
+ const app = desktopRow();
23925
+ return [pluginRow(plugins, input), ...app ? [app] : [], skillsRow(plugins, input)];
23755
23926
  }
23756
23927
  };
23757
23928
  registry3.register(claudeSetupProvider);
@@ -23762,32 +23933,32 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
23762
23933
  import { loadAgentFile as loadAgentFile2, registry as registry4, writeLaunchArtifact } from "@cotal-ai/core";
23763
23934
 
23764
23935
  // src/carried.ts
23765
- import { createHash as createHash2 } from "node:crypto";
23936
+ import { createHash as createHash3 } from "node:crypto";
23766
23937
  import { execFileSync } from "node:child_process";
23767
- import { copyFileSync, lstatSync, mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
23768
- import { homedir as homedir3, hostname as hostname3 } from "node:os";
23769
- import { join as join4 } from "node:path";
23938
+ import { copyFileSync, lstatSync, mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
23939
+ import { homedir as homedir4, hostname as hostname3 } from "node:os";
23940
+ import { join as join5 } from "node:path";
23770
23941
  var SEAT_PROJECT = "seat";
23771
23942
  var FORK_RECORD = "cotal-fork.json";
23772
23943
  var MIN_VERSION = [2, 1, 234];
23773
23944
  var MAX_TITLE = 1024;
23774
23945
  function configDir(env) {
23775
- return env.CLAUDE_CONFIG_DIR || join4(env.HOME || homedir3(), ".claude");
23946
+ return env.CLAUDE_CONFIG_DIR || join5(env.HOME || homedir4(), ".claude");
23776
23947
  }
23777
23948
  function transcripts(env) {
23778
- const projects = join4(configDir(env), "projects");
23949
+ const projects = join5(configDir(env), "projects");
23779
23950
  let dirs;
23780
23951
  try {
23781
- dirs = readdirSync2(projects, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join4(projects, d.name));
23952
+ dirs = readdirSync2(projects, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join5(projects, d.name));
23782
23953
  } catch (e) {
23783
23954
  if (e.code === "ENOENT") return [];
23784
23955
  throw e;
23785
23956
  }
23786
- return dirs.flatMap((dir) => readdirSync2(dir, { withFileTypes: true }).filter((f) => f.isFile() && f.name.endsWith(".jsonl")).map((f) => join4(dir, f.name)));
23957
+ return dirs.flatMap((dir) => readdirSync2(dir, { withFileTypes: true }).filter((f) => f.isFile() && f.name.endsWith(".jsonl")).map((f) => join5(dir, f.name)));
23787
23958
  }
23788
23959
  function titleOf(path) {
23789
23960
  let title;
23790
- for (const line of readFileSync3(path, "utf8").split("\n")) {
23961
+ for (const line of readFileSync4(path, "utf8").split("\n")) {
23791
23962
  try {
23792
23963
  const entry = JSON.parse(line);
23793
23964
  if (entry.type === "custom-title" && typeof entry.customTitle === "string") title = entry.customTitle;
@@ -23797,7 +23968,7 @@ function titleOf(path) {
23797
23968
  return title;
23798
23969
  }
23799
23970
  function sha256(path) {
23800
- return createHash2("sha256").update(readFileSync3(path)).digest("hex");
23971
+ return createHash3("sha256").update(readFileSync4(path)).digest("hex");
23801
23972
  }
23802
23973
  var claudeResumeTranscript = {
23803
23974
  find(id, env) {
@@ -23840,14 +24011,14 @@ function refuseCarriedLaunch(binary, seatEnv) {
23840
24011
  );
23841
24012
  }
23842
24013
  function carriedForkRecord(home) {
23843
- return join4(home, FORK_RECORD);
24014
+ return join5(home, FORK_RECORD);
23844
24015
  }
23845
24016
  function placeCarried(home, transcript, resume, cwd) {
23846
- writeFileSync2(join4(home, ".claude.json"), JSON.stringify({ hasCompletedOnboarding: true, projects: { [cwd]: { hasTrustDialogAccepted: true } } }), { mode: 384 });
24017
+ writeFileSync3(join5(home, ".claude.json"), JSON.stringify({ hasCompletedOnboarding: true, projects: { [cwd]: { hasTrustDialogAccepted: true } } }), { mode: 384 });
23847
24018
  if (resume !== void 0) {
23848
- const dir = join4(home, "projects", SEAT_PROJECT);
24019
+ const dir = join5(home, "projects", SEAT_PROJECT);
23849
24020
  mkdirSync2(dir, { recursive: true, mode: 448 });
23850
- copyFileSync(transcript, join4(dir, `${resume}.jsonl`));
24021
+ copyFileSync(transcript, join5(dir, `${resume}.jsonl`));
23851
24022
  }
23852
24023
  return { CLAUDE_CONFIG_DIR: home, CLAUDE_CODE_PROJECT_DIR_NAME: SEAT_PROJECT, ...resume !== void 0 ? { COTAL_CLAUDE_CARRIED: resume } : {} };
23853
24024
  }
@@ -23979,9 +24150,6 @@ var claudeConnector = {
23979
24150
  const env = {
23980
24151
  ...launchEnv({ providerKeys: CLAUDE_PROVIDER_KEYS, mcpKeys: [...mcpServerEnvKeys(shared), ...nativeEnvKeys, ...CLAUDE_MCP_KEYS], envAllow: opts.envAllow }),
23981
24152
  ...aclEnv(opts),
23982
- // Creds, broker URL and the control token ride a 0600 file; only its path is exported, so the
23983
- // shells, builds and third-party CLIs this session runs no longer inherit live authority.
23984
- ...materialEnv({ creds: opts.creds, servers: opts.servers, controlToken: control.token, eventsRequired: opts.eventsRequired, userAuth: opts.userAuth }),
23985
24153
  COTAL_SPACE: opts.space,
23986
24154
  COTAL_NAME: opts.name,
23987
24155
  // Force the connector to emit channel wake-nudges: Claude doesn't advertise the
@@ -24015,6 +24183,7 @@ var claudeConnector = {
24015
24183
  if (opts.model) assertServableModel(opts.model);
24016
24184
  const passthrough = connectorLaunchOptions("claude", opts.launchOptions).map(([k, v]) => [k, String(v)]);
24017
24185
  const artifacts = [];
24186
+ Object.assign(env, materialEnv({ creds: opts.creds, servers: opts.servers, controlToken: control.token, eventsRequired: opts.eventsRequired, userAuth: opts.userAuth }, artifacts));
24018
24187
  let mcpConfig;
24019
24188
  if (Object.keys(shared).length === 0) {
24020
24189
  mcpConfig = JSON.stringify({ mcpServers });