@cotal-ai/connector-opencode 0.2.0 → 0.3.1

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.
@@ -3,13 +3,13 @@ import { type Connector } from "@cotal-ai/core";
3
3
  * The OpenCode connector: launches a watchable `opencode` TUI bound to the agent's session, using
4
4
  * OpenCode's client/server split (see serve.ts). The Cotal mesh bridge runs as an in-process plugin
5
5
  * inside a headless `opencode serve`: it holds the {@link MeshAgent}, registers the cotal_* tools
6
- * natively (from the shared specs, at parity with Claude/Codex), reports presence off the event bus,
6
+ * natively (from the shared specs, at parity with Claude Code), reports presence off the event bus,
7
7
  * and owns ONE session it drives — injecting each incoming peer batch as a turn via the prompt API
8
8
  * (`session.promptAsync`, server-side, so it can't race the TUI input box). The shim then attaches a
9
9
  * foreground TUI to that session, so a human watching sees the agent work and can type into it.
10
10
  *
11
11
  * Config rides in `OPENCODE_CONFIG_CONTENT` (inline JSON, the highest merge layer), so the
12
- * operator's `~/.config/opencode` is never written — the Codex `-c` trick in JSON.
12
+ * operator's `~/.config/opencode` is never written.
13
13
  * `permission:"allow"` keeps a supervised agent from stalling on a tool approval the human may not
14
14
  * be at the keyboard to grant. Self-registers on import; the manager resolves it by type "opencode".
15
15
  */
package/dist/extension.js CHANGED
@@ -13,13 +13,13 @@ const SERVE_SHIM = fileURLToPath(new URL("./serve.js", import.meta.url));
13
13
  * The OpenCode connector: launches a watchable `opencode` TUI bound to the agent's session, using
14
14
  * OpenCode's client/server split (see serve.ts). The Cotal mesh bridge runs as an in-process plugin
15
15
  * inside a headless `opencode serve`: it holds the {@link MeshAgent}, registers the cotal_* tools
16
- * natively (from the shared specs, at parity with Claude/Codex), reports presence off the event bus,
16
+ * natively (from the shared specs, at parity with Claude Code), reports presence off the event bus,
17
17
  * and owns ONE session it drives — injecting each incoming peer batch as a turn via the prompt API
18
18
  * (`session.promptAsync`, server-side, so it can't race the TUI input box). The shim then attaches a
19
19
  * foreground TUI to that session, so a human watching sees the agent work and can type into it.
20
20
  *
21
21
  * Config rides in `OPENCODE_CONFIG_CONTENT` (inline JSON, the highest merge layer), so the
22
- * operator's `~/.config/opencode` is never written — the Codex `-c` trick in JSON.
22
+ * operator's `~/.config/opencode` is never written.
23
23
  * `permission:"allow"` keeps a supervised agent from stalling on a tool approval the human may not
24
24
  * be at the keyboard to grant. Self-registers on import; the manager resolves it by type "opencode".
25
25
  */
@@ -28,7 +28,7 @@ export const opencodeConnector = {
28
28
  name: "opencode",
29
29
  buildLaunch(opts) {
30
30
  // Identity rides the process env: the plugin runs in the opencode process and inherits it
31
- // (unlike the Codex/Claude MCP servers, which get none of the parent env).
31
+ // (unlike the Claude Code MCP server, which gets none of the parent env).
32
32
  const env = { COTAL_SPACE: opts.space, COTAL_NAME: opts.name };
33
33
  if (opts.role)
34
34
  env.COTAL_ROLE = opts.role;
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAoD,MAAM,gBAAgB,CAAC;AAE3G;;;oCAGoC;AACpC,MAAM,YAAY,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnF;uFACuF;AACvF,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAc;IAC1C,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,UAAU;IAChB,WAAW,CAAC,IAAgB;QAC1B,0FAA0F;QAC1F,2EAA2E;QAC3E,MAAM,GAAG,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AAM,GAA4B;YACtC,OAAO,EAAE,iCAAiC;YAC1C,UAAU,EAAE,OAAO;YACnB,MAAM,EAAE,CAAC,YAAY,CAAC;SACvB,CAAC;QAEF,8FAA8F;QAC9F,8FAA8F;QAC9F,+EAA+E;QAC/E,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACtC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,+BAA+B;YAC5D,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,GAAG,CAAC,KAAK;gBAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;YACxC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;YAC5B,IAAI,IAAI;gBAAE,GAAG,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC,yCAAyC;QACpF,CAAC;QAED,GAAG,CAAC,uBAAuB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAErD,oFAAoF;QACpF,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,IAAI,EAAE,CAAC,UAAU,CAAC;YAClB,GAAG;SACJ,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC"}
@@ -16898,7 +16898,8 @@ var CotalEndpoint = class extends EventEmitter {
16898
16898
  async requestControl(service, req, timeoutMs = 5e3) {
16899
16899
  if (!this.nc)
16900
16900
  throw new Error("endpoint not started");
16901
- const m = await this.nc.request(controlServiceSubject(this.space, service, this.card.id), JSON.stringify({ ...req, from: req.from ?? this.ref() }), { timeout: timeoutMs });
16901
+ const body = { ...req, from: req.from ?? this.ref() };
16902
+ const m = await this.nc.request(controlServiceSubject(this.space, service, this.card.id), JSON.stringify(body), { timeout: timeoutMs });
16902
16903
  return m.json();
16903
16904
  }
16904
16905
  // ---- presence ------------------------------------------------------------
@@ -17921,6 +17922,15 @@ var MeshAgent = class extends EventEmitter2 {
17921
17922
  args: { name, graceful: opts?.graceful ?? true }
17922
17923
  });
17923
17924
  }
17925
+ /** Ask the manager to purge the space's retained chat backlog (its `purge` op). Cleanup only —
17926
+ * it doesn't touch live agents or the anycast work queue. `includeDms` also clears DM history. */
17927
+ async purgeHistory(opts) {
17928
+ this.assertConnected();
17929
+ return this.ep.requestControl("manager", {
17930
+ op: "purge",
17931
+ args: { includeDms: opts?.includeDms ?? false }
17932
+ });
17933
+ }
17924
17934
  /** Define a persona and persist it as config (the manager's `definePersona` op writes
17925
17935
  * .cotal/agents/<name>.md). On success, announce it on the channel — the "send it out"
17926
17936
  * half — so peers see the new persona; `spawn(name)` then launches an agent wearing it. */
@@ -32872,6 +32882,27 @@ ${info}${caught}`);
32872
32882
  }
32873
32883
  }
32874
32884
  },
32885
+ {
32886
+ name: "cotal_purge",
32887
+ title: "Cotal: clear chat history",
32888
+ description: "Ask the manager to purge this space's retained chat backlog (channel history). Set includeDms to also clear direct-message history. Cleanup only \u2014 it does not affect live agents or the anycast work queue. Irreversible.",
32889
+ schema: {
32890
+ includeDms: external_exports.boolean().optional().describe("Default false: channel history only. true = also purge DM history.")
32891
+ },
32892
+ async run(agent, _config, { includeDms }) {
32893
+ try {
32894
+ const reply = await agent.purgeHistory({ includeDms });
32895
+ if (!reply.ok)
32896
+ return err(`Couldn't purge history: ${reply.error ?? "manager refused"}`);
32897
+ const d = reply.data;
32898
+ const chat = d?.chat ?? 0;
32899
+ const dm = d?.dm;
32900
+ return ok(`Cleared ${chat} channel message${chat === 1 ? "" : "s"}${dm === void 0 ? "" : ` and ${dm} DM${dm === 1 ? "" : "s"}`} from "${_config.space}".`);
32901
+ } catch (e) {
32902
+ return err(`Couldn't purge history: no manager reachable (${e.message}). Is the manager running?`);
32903
+ }
32904
+ }
32905
+ },
32875
32906
  {
32876
32907
  name: "cotal_persona",
32877
32908
  title: "Cotal: define a persona",
package/dist/plugin.js CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * • holds the {@link MeshAgent} (NATS endpoint, inbox, presence) for the server's lifetime;
8
8
  * • registers the cotal_* tools natively, rendered from the SHARED {@link cotalToolSpecs}
9
- * (`./tools.ts`) — same surface as Claude/Codex, incl. channels / join / leave / channel_info;
9
+ * (`./tools.ts`) — same surface as Claude Code, incl. channels / join / leave / channel_info;
10
10
  * • maps OpenCode bus events to presence (idle | working | waiting | offline);
11
11
  * • owns ONE session (created at boot) and drives it: it injects each inbox batch as a turn via the
12
12
  * prompt API (`session.promptAsync` — server-side, so it can't race the TUI input box; the
package/dist/tools.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The Cotal tool surface for OpenCode, rendered from the **shared** {@link cotalToolSpecs}
3
- * (the same source the Claude Code / Codex MCP connectors render) as OpenCode-native plugin
3
+ * (the same source the Claude Code MCP connector renders) as OpenCode-native plugin
4
4
  * tools (the `tool()` helper). One source of truth → the cotal_* surface can't drift across
5
5
  * adapters: an OpenCode peer gets the same tools (incl. channels / join / leave / channel_info).
6
6
  *
package/dist/tools.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The Cotal tool surface for OpenCode, rendered from the **shared** {@link cotalToolSpecs}
3
- * (the same source the Claude Code / Codex MCP connectors render) as OpenCode-native plugin
3
+ * (the same source the Claude Code MCP connector renders) as OpenCode-native plugin
4
4
  * tools (the `tool()` helper). One source of truth → the cotal_* surface can't drift across
5
5
  * adapters: an OpenCode peer gets the same tools (incl. channels / join / leave / channel_info).
6
6
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cotal-ai/connector-opencode",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,19 +17,19 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@cotal-ai/connector-core": "0.2.0"
20
+ "@cotal-ai/connector-core": "0.3.1"
21
21
  },
22
22
  "peerDependencies": {
23
+ "@cotal-ai/core": ">=0.1.0",
23
24
  "@opencode-ai/plugin": "^1.16.2",
24
- "@opencode-ai/sdk": "^1.16.2",
25
- "@cotal-ai/core": "0.1.3"
25
+ "@opencode-ai/sdk": "^1.16.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.16.2",
29
29
  "@opencode-ai/sdk": "^1.16.2",
30
30
  "esbuild": "^0.28.0",
31
31
  "tsx": "^4.22.4",
32
- "@cotal-ai/core": "0.1.3"
32
+ "@cotal-ai/core": "0.3.1"
33
33
  },
34
34
  "files": [
35
35
  "dist"