@cotal-ai/connector-opencode 0.69.0 → 0.70.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.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAuCA,OAAO,EAGL,SAAS,EAoBV,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAK,EAAE,MAAM,EAAyB,MAAM,qBAAqB,CAAC;AAgBzE;;;0EAG0E;AAC1E,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAC1D,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAC5D;iEACiE;AACjE,eAAO,MAAM,UAAU,wBAAwB,CAAC;AAChD;;gCAEgC;AAChC,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAC5C;;0EAE0E;AAC1E,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF;AACD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAYnH;AA8BD;;;;GAIG;AACH,iBAAe,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB1G;AACD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,GAAG,SAAS,CAQZ;AAED,eAAO,MAAM,KAAK,EAAE,MA8vCnB,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAuCA,OAAO,EAGL,SAAS,EAqBV,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAK,EAAE,MAAM,EAAyB,MAAM,qBAAqB,CAAC;AAgBzE;;;0EAG0E;AAC1E,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAC1D,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAC5D;iEACiE;AACjE,eAAO,MAAM,UAAU,wBAAwB,CAAC;AAChD;;gCAEgC;AAChC,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAC5C;;0EAE0E;AAC1E,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElF;AACD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAYnH;AA8BD;;;;GAIG;AACH,iBAAe,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB1G;AACD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,GAAG,SAAS,CAQZ;AAED,eAAO,MAAM,KAAK,EAAE,MA4vCnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin2.d.ts","sourceRoot":"","sources":["../src/plugin2.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAiB7D;;;;;;8EAM8E;AAC9E,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAoC3C,4CAA4C;AAC5C,wBAAsB,UAAU,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAkT7F"}
1
+ {"version":3,"file":"plugin2.d.ts","sourceRoot":"","sources":["../src/plugin2.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAiB7D;;;;;;8EAM8E;AAC9E,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAoC3C,4CAA4C;AAC5C,wBAAsB,UAAU,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAmT7F"}
package/dist/serve.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/serve.ts
1
+ // src/launch.ts
2
2
  import { execFileSync, spawn } from "node:child_process";
3
3
  import { createServer } from "node:net";
4
4
  import { once } from "node:events";
@@ -16,7 +16,7 @@ function opencodeLine(raw, bin) {
16
16
  );
17
17
  }
18
18
 
19
- // src/serve.ts
19
+ // src/launch.ts
20
20
  function resolveOpencodeBin() {
21
21
  const override = process.env.COTAL_OPENCODE_BIN?.trim() || process.env.COTAL_OPENCODE_RESOLVED_BIN?.trim();
22
22
  if (override) return override;
@@ -81,7 +81,7 @@ function isLiveOpencodeServe(pid) {
81
81
  if (!cmd) return true;
82
82
  return /\bserve\b/.test(cmd) && (/(?:^|[\\/\s])opencode(?:\.exe)?(?:\s|$)/i.test(cmd) || /--hostname\s+127\.0\.0\.1\b/.test(cmd) && /--port\s+\d+\b/.test(cmd));
83
83
  }
84
- async function main() {
84
+ async function launch(tuiArgv, serveEnv) {
85
85
  const port = process.env.COTAL_OPENCODE_PORT?.trim() || String(await freePort());
86
86
  const url = `http://127.0.0.1:${port}`;
87
87
  const name = process.env.COTAL_NAME?.trim() || "agent";
@@ -90,11 +90,17 @@ async function main() {
90
90
  const agentHome = join(dataRoot, ".cotal", "opencode", name);
91
91
  const dbPath = join(agentHome, "opencode.db");
92
92
  const pidFile = join(agentHome, "serve.pid");
93
- if (existsSync(pidFile)) {
94
- const pid = Number(readFileSync(pidFile, "utf8"));
93
+ let recorded;
94
+ try {
95
+ recorded = readFileSync(pidFile, "utf8");
96
+ } catch (e) {
97
+ if (e.code !== "ENOENT") throw e;
98
+ }
99
+ if (recorded !== void 0) {
100
+ const pid = Number(recorded);
95
101
  if (isLiveOpencodeServe(pid))
96
102
  throw new Error(`agent "${name}" is already running (opencode serve pid ${pid}) \u2014 kill it first`);
97
- rmSync(pidFile);
103
+ rmSync(pidFile, { force: true });
98
104
  }
99
105
  const versionRaw = execFileSync(BIN, ["--version"], { encoding: "utf8" }).trim();
100
106
  const line = opencodeLine(versionRaw, BIN);
@@ -102,6 +108,7 @@ async function main() {
102
108
  const serve = spawn(BIN, ["serve", "--hostname", "127.0.0.1", "--port", port], {
103
109
  env: {
104
110
  ...process.env,
111
+ ...serveEnv?.(agentHome),
105
112
  COTAL_OPENCODE_SERVER_URL: url,
106
113
  COTAL_OPENCODE_LINE: String(line),
107
114
  OPENCODE_SERVER_USERNAME: USERNAME,
@@ -170,7 +177,8 @@ async function main() {
170
177
  delete tuiEnv.OPENCODE_CONFIG_CONTENT;
171
178
  for (const k of Object.keys(tuiEnv)) if (k.startsWith("COTAL_")) delete tuiEnv[k];
172
179
  attached = true;
173
- const tui = line === 2 ? spawn(BIN, ["--server", url, "--session", id], { env: tuiEnv, stdio: "inherit" }) : spawn(BIN, ["attach", url, "--session", id], { env: tuiEnv, stdio: "inherit" });
180
+ const [command, ...args] = tuiArgv({ url, session: id, line });
181
+ const tui = spawn(command, args, { env: tuiEnv, stdio: "inherit" });
174
182
  for (const sig of ["SIGINT", "SIGTERM"])
175
183
  process.on(sig, () => {
176
184
  tui.kill(sig);
@@ -181,4 +189,6 @@ async function main() {
181
189
  void terminate(serve).then(() => process.exit(code ?? (signal ? 1 : 0)));
182
190
  });
183
191
  }
184
- void main();
192
+
193
+ // src/serve.ts
194
+ void launch(({ url, session, line }) => line === 2 ? [BIN, "--server", url, "--session", session] : [BIN, "attach", url, "--session", session]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cotal-ai/connector-opencode",
3
3
  "description": "Cotal connector for OpenCode: a native in-process plugin that joins a session to the mesh.",
4
- "version": "0.69.0",
4
+ "version": "0.70.1",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,8 +21,8 @@
21
21
  "@cotal-ai/core": ">=0.1.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@cotal-ai/connector-core": "0.69.0",
25
- "@cotal-ai/core": "0.69.0",
24
+ "@cotal-ai/connector-core": "0.70.1",
25
+ "@cotal-ai/core": "0.70.1",
26
26
  "@cotal-ai/smoke-kit": "0.0.0",
27
27
  "@nats-io/transport-node": "^3.4.0",
28
28
  "@opencode-ai/plugin": "^1.16.2",
@@ -39,6 +39,6 @@
39
39
  "test": "tsx smoke/tool-input-closed.smoke.ts",
40
40
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.smoke.json",
41
41
  "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json --emitDeclarationOnly && pnpm run bundle",
42
- "bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/index.js --external:@cotal-ai/core && esbuild src/plugin.entry.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/plugin/index.js && esbuild src/serve.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/serve.js"
42
+ "bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/index.js --external:@cotal-ai/core && esbuild src/plugin.entry.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/plugin/index.js && esbuild src/serve.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/serve.js && esbuild src/launch.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/launch.js"
43
43
  }
44
44
  }