antechamber 2.0.17 → 2.0.19

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,14 +1,30 @@
1
1
  // extensions/antechamber/src/runtime/launcher.ts
2
2
  import { readFileSync as readFileSync2 } from "node:fs";
3
- import { dirname, join as join2, resolve as resolve2 } from "node:path";
3
+ import { dirname as dirname3, join as join3, resolve as resolve2 } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
+ // extensions/antechamber/src/runtime/activate.ts
7
+ import { basename, dirname, join } from "node:path";
8
+ function launcherPath(extensionDir2) {
9
+ return join(extensionDir2, "bin", "opencode-antechamber");
10
+ }
11
+
6
12
  // extensions/antechamber/src/runtime/runtime.ts
7
13
  import { spawn } from "node:child_process";
8
14
  import { createHash } from "node:crypto";
9
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
15
+ import {
16
+ existsSync,
17
+ mkdirSync,
18
+ readdirSync,
19
+ readFileSync,
20
+ realpathSync,
21
+ renameSync,
22
+ rmSync,
23
+ statSync,
24
+ writeFileSync
25
+ } from "node:fs";
10
26
  import { homedir } from "node:os";
11
- import { delimiter, isAbsolute, join, resolve } from "node:path";
27
+ import { delimiter, dirname as dirname2, isAbsolute, join as join2, resolve } from "node:path";
12
28
  var STALE_LOCK_MS = 15 * 6e4;
13
29
  var INSTALL_TIMEOUT_MS = 10 * 6e4;
14
30
  var READY = ".ready.json";
@@ -18,25 +34,25 @@ function defaultEnv() {
18
34
  }
19
35
  function runtimeRoot({ env, home }) {
20
36
  const configured = env.ANTECHAMBER_RUNTIME_DIR?.trim();
21
- return configured ? resolve(configured) : join(home, ".antechamber", "runtime");
37
+ return configured ? resolve(configured) : join2(home, ".antechamber", "runtime");
22
38
  }
23
39
  function runtimePaths(version, runtime) {
24
40
  const root = runtimeRoot(runtime);
25
41
  const override = runtime.env.ANTECHAMBER_RUNTIME_SPEC?.trim();
26
- if (!override) return { root, spec: version, key: version, dir: join(root, version) };
42
+ if (!override) return { root, spec: version, key: version, dir: join2(root, version) };
27
43
  const spec = isAbsolute(override) ? override : resolve(override);
28
44
  const stamp = existsSync(spec) ? `${statSync(spec).mtimeMs}:${statSync(spec).size}` : "";
29
45
  const key = `local-${createHash("sha256").update(`${spec}
30
46
  ${stamp}`).digest("hex").slice(0, 12)}`;
31
- return { root, spec: `file:${spec}`, key, dir: join(root, key) };
47
+ return { root, spec: `file:${spec}`, key, dir: join2(root, key) };
32
48
  }
33
49
  function findBun({ env, home }, exists = existsSync) {
34
50
  for (const dir of (env.PATH ?? "").split(delimiter)) {
35
- if (dir && exists(join(dir, "bun"))) return join(dir, "bun");
51
+ if (dir && exists(join2(dir, "bun"))) return join2(dir, "bun");
36
52
  }
37
53
  for (const candidate of [
38
- join(env.BUN_INSTALL ?? join(home, ".bun"), "bin", "bun"),
39
- join(home, ".bun", "bin", "bun")
54
+ join2(env.BUN_INSTALL ?? join2(home, ".bun"), "bin", "bun"),
55
+ join2(home, ".bun", "bin", "bun")
40
56
  ]) {
41
57
  if (exists(candidate)) return candidate;
42
58
  }
@@ -51,13 +67,21 @@ function readJson(path) {
51
67
  }
52
68
  }
53
69
  function installed(dir) {
54
- if (!existsSync(join(dir, READY))) return void 0;
55
- const cli = join(dir, "node_modules", "antechamber", "dist", "cli.js");
56
- const antechamber = readJson(join(dir, "node_modules", "antechamber", "package.json"))?.version;
70
+ if (!existsSync(join2(dir, READY))) return void 0;
71
+ const cli = join2(dir, "node_modules", "antechamber", "dist", "cli.js");
72
+ const antechamber = readJson(join2(dir, "node_modules", "antechamber", "package.json"))?.version;
57
73
  if (!existsSync(cli) || typeof antechamber !== "string") return void 0;
58
- const omo = readJson(join(dir, "node_modules", "omo-ai", "package.json"))?.version;
74
+ const omo = readJson(join2(dir, "node_modules", "omo-ai", "package.json"))?.version;
59
75
  return { dir, cli, antechamber, omo: typeof omo === "string" ? omo : void 0 };
60
76
  }
77
+ function launchStampPath(home, launcher) {
78
+ const key = createHash("sha256").update(existsSync(launcher) ? realpathSync(launcher) : launcher).digest("hex").slice(0, 16);
79
+ return join2(home, ".antechamber", "launches", key);
80
+ }
81
+ function writeStamp(stamp, now = Date.now()) {
82
+ mkdirSync(dirname2(stamp), { recursive: true });
83
+ writeFileSync(stamp, String(now));
84
+ }
61
85
  function lockHeld(lock, deps) {
62
86
  let mtime;
63
87
  try {
@@ -65,7 +89,7 @@ function lockHeld(lock, deps) {
65
89
  } catch {
66
90
  return false;
67
91
  }
68
- const pid = Number.parseInt(readFileSync(join(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
92
+ const pid = Number.parseInt(readFileSync(join2(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
69
93
  if (deps.now() - mtime > STALE_LOCK_MS) return false;
70
94
  return !Number.isInteger(pid) || deps.pidAlive(pid);
71
95
  }
@@ -78,11 +102,11 @@ function tryLock(lock, deps) {
78
102
  rmSync(lock, { recursive: true, force: true });
79
103
  return tryLock(lock, deps);
80
104
  }
81
- writeFileSync(join(lock, "pid"), String(process.pid));
105
+ writeFileSync(join2(lock, "pid"), String(process.pid));
82
106
  return true;
83
107
  }
84
108
  function prune(paths) {
85
- const others = readdirSync(paths.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== paths.key && !/\.(lock|tmp-.*)$/.test(entry.name)).map((entry) => join(paths.root, entry.name)).filter((dir) => existsSync(join(dir, READY)) && !existsSync(`${dir}.lock`)).map((dir) => ({ dir, at: Number(readJson(join(dir, READY))?.installedAt ?? 0) })).sort((a, b) => b.at - a.at);
109
+ const others = readdirSync(paths.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== paths.key && !/\.(lock|tmp-.*)$/.test(entry.name)).map((entry) => join2(paths.root, entry.name)).filter((dir) => existsSync(join2(dir, READY)) && !existsSync(`${dir}.lock`)).map((dir) => ({ dir, at: Number(readJson(join2(dir, READY))?.installedAt ?? 0) })).sort((a, b) => b.at - a.at);
86
110
  for (const { dir } of others.slice(1)) rmSync(dir, { recursive: true, force: true });
87
111
  }
88
112
  async function installOnce(paths, bun, deps) {
@@ -96,10 +120,10 @@ async function installOnce(paths, bun, deps) {
96
120
  // omo-ai's postinstall prepares its engine; Bun skips dependency scripts unless trusted.
97
121
  trustedDependencies: ["omo-ai"]
98
122
  };
99
- writeFileSync(join(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
123
+ writeFileSync(join2(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
100
124
  `);
101
125
  await deps.install(bun, staging);
102
- writeFileSync(join(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
126
+ writeFileSync(join2(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
103
127
  `);
104
128
  if (!installed(staging)) throw new Error(`bun install did not produce node_modules/antechamber/dist/cli.js`);
105
129
  rmSync(paths.dir, { recursive: true, force: true });
@@ -181,15 +205,23 @@ function defaultDeps() {
181
205
  }
182
206
 
183
207
  // extensions/antechamber/src/runtime/launcher.ts
184
- var extensionDir = resolve2(dirname(fileURLToPath(import.meta.url)), "..");
208
+ var extensionDir = resolve2(dirname3(fileURLToPath(import.meta.url)), "..");
185
209
  var command = process.argv[2];
186
210
  if (command === "version") {
187
211
  console.log(`opencode v${"2.999.0"}`);
188
212
  } else if (command === "resolve") {
189
- const { version } = JSON.parse(readFileSync2(join2(extensionDir, "package.json"), "utf8"));
213
+ const { version } = JSON.parse(readFileSync2(join3(extensionDir, "package.json"), "utf8"));
190
214
  const env = defaultEnv();
191
215
  try {
192
- const runtime = await ensureRuntime(runtimePaths(version, env), findBun(env) ?? process.execPath);
216
+ const paths = runtimePaths(version, env);
217
+ const runtime = await ensureRuntime(paths, findBun(env) ?? process.execPath);
218
+ try {
219
+ writeStamp(launchStampPath(env.home, launcherPath(extensionDir)));
220
+ } catch (error) {
221
+ console.error(
222
+ `opencode-antechamber: could not record the launch: ${error instanceof Error ? error.message : error}`
223
+ );
224
+ }
193
225
  console.log(runtime.cli);
194
226
  } catch (error) {
195
227
  console.error(`opencode-antechamber: ${error instanceof Error ? error.message : String(error)}`);
@@ -1,14 +1,61 @@
1
1
  // extensions/antechamber/src/service-main.ts
2
2
  import { chmodSync as chmodSync2, readFileSync as readFileSync5 } from "node:fs";
3
- import { dirname as dirname2, join as join6, resolve as resolve4 } from "node:path";
3
+ import { dirname as dirname3, join as join5, resolve as resolve4 } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
+ // extensions/antechamber/src/runtime/activate.ts
7
+ import { chmodSync, copyFileSync, existsSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
8
+ import { basename, dirname, join } from "node:path";
9
+ function openchamberSettingsPath(extensionDir2, home) {
10
+ for (let dir = extensionDir2; dirname(dir) !== dir; dir = dirname(dir)) {
11
+ if (basename(dirname(dir)) !== "extensions") continue;
12
+ const settings2 = join(dirname(dirname(dir)), "settings.json");
13
+ if (existsSync(settings2)) return settings2;
14
+ }
15
+ if (home === void 0) return void 0;
16
+ const settings = join(home, ".config", "openchamber", "settings.json");
17
+ return existsSync(settings) ? settings : void 0;
18
+ }
19
+ function launcherPath(extensionDir2) {
20
+ return join(extensionDir2, "bin", "opencode-antechamber");
21
+ }
22
+ function configuredBinary(settings) {
23
+ const value = JSON.parse(readFileSync(settings, "utf8")).opencodeBinary;
24
+ return typeof value === "string" ? value : void 0;
25
+ }
26
+ function mayActivateUnasked(configured) {
27
+ return !configured?.trim() || basename(configured) === "opencode-antechamber";
28
+ }
29
+ function activateLauncher(settings, launcher, now = /* @__PURE__ */ new Date()) {
30
+ const data = JSON.parse(readFileSync(settings, "utf8"));
31
+ if (data.opencodeBinary === launcher) return {};
32
+ const backup = `${settings}.bak-antechamber-${now.toISOString().replace(/\D/g, "").slice(0, 14)}`;
33
+ if (!existsSync(backup)) copyFileSync(settings, backup);
34
+ const mode = statSync(settings).mode & 511;
35
+ const temporary = `${settings}.antechamber-${process.pid}.tmp`;
36
+ writeFileSync(temporary, `${JSON.stringify({ ...data, opencodeBinary: launcher }, null, 2)}
37
+ `, { mode });
38
+ chmodSync(temporary, mode);
39
+ renameSync(temporary, settings);
40
+ return { backup };
41
+ }
42
+
6
43
  // extensions/antechamber/src/runtime/runtime.ts
7
44
  import { spawn } from "node:child_process";
8
45
  import { createHash } from "node:crypto";
9
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
46
+ import {
47
+ existsSync as existsSync2,
48
+ mkdirSync,
49
+ readdirSync,
50
+ readFileSync as readFileSync2,
51
+ realpathSync,
52
+ renameSync as renameSync2,
53
+ rmSync,
54
+ statSync as statSync2,
55
+ writeFileSync as writeFileSync2
56
+ } from "node:fs";
10
57
  import { homedir } from "node:os";
11
- import { delimiter, isAbsolute, join, resolve } from "node:path";
58
+ import { delimiter, dirname as dirname2, isAbsolute, join as join2, resolve } from "node:path";
12
59
  var STALE_LOCK_MS = 15 * 6e4;
13
60
  var INSTALL_TIMEOUT_MS = 10 * 6e4;
14
61
  var READY = ".ready.json";
@@ -18,25 +65,25 @@ function defaultEnv() {
18
65
  }
19
66
  function runtimeRoot({ env: env2, home }) {
20
67
  const configured = env2.ANTECHAMBER_RUNTIME_DIR?.trim();
21
- return configured ? resolve(configured) : join(home, ".antechamber", "runtime");
68
+ return configured ? resolve(configured) : join2(home, ".antechamber", "runtime");
22
69
  }
23
70
  function runtimePaths(version2, runtime) {
24
71
  const root = runtimeRoot(runtime);
25
72
  const override = runtime.env.ANTECHAMBER_RUNTIME_SPEC?.trim();
26
- if (!override) return { root, spec: version2, key: version2, dir: join(root, version2) };
73
+ if (!override) return { root, spec: version2, key: version2, dir: join2(root, version2) };
27
74
  const spec = isAbsolute(override) ? override : resolve(override);
28
- const stamp = existsSync(spec) ? `${statSync(spec).mtimeMs}:${statSync(spec).size}` : "";
75
+ const stamp = existsSync2(spec) ? `${statSync2(spec).mtimeMs}:${statSync2(spec).size}` : "";
29
76
  const key = `local-${createHash("sha256").update(`${spec}
30
77
  ${stamp}`).digest("hex").slice(0, 12)}`;
31
- return { root, spec: `file:${spec}`, key, dir: join(root, key) };
78
+ return { root, spec: `file:${spec}`, key, dir: join2(root, key) };
32
79
  }
33
- function findBun({ env: env2, home }, exists = existsSync) {
80
+ function findBun({ env: env2, home }, exists = existsSync2) {
34
81
  for (const dir of (env2.PATH ?? "").split(delimiter)) {
35
- if (dir && exists(join(dir, "bun"))) return join(dir, "bun");
82
+ if (dir && exists(join2(dir, "bun"))) return join2(dir, "bun");
36
83
  }
37
84
  for (const candidate of [
38
- join(env2.BUN_INSTALL ?? join(home, ".bun"), "bin", "bun"),
39
- join(home, ".bun", "bin", "bun")
85
+ join2(env2.BUN_INSTALL ?? join2(home, ".bun"), "bin", "bun"),
86
+ join2(home, ".bun", "bin", "bun")
40
87
  ]) {
41
88
  if (exists(candidate)) return candidate;
42
89
  }
@@ -44,28 +91,41 @@ function findBun({ env: env2, home }, exists = existsSync) {
44
91
  }
45
92
  function readJson(path) {
46
93
  try {
47
- const value = JSON.parse(readFileSync(path, "utf8"));
94
+ const value = JSON.parse(readFileSync2(path, "utf8"));
48
95
  return typeof value === "object" && value !== null ? value : void 0;
49
96
  } catch {
50
97
  return void 0;
51
98
  }
52
99
  }
53
100
  function installed(dir) {
54
- if (!existsSync(join(dir, READY))) return void 0;
55
- const cli = join(dir, "node_modules", "antechamber", "dist", "cli.js");
56
- const antechamber = readJson(join(dir, "node_modules", "antechamber", "package.json"))?.version;
57
- if (!existsSync(cli) || typeof antechamber !== "string") return void 0;
58
- const omo = readJson(join(dir, "node_modules", "omo-ai", "package.json"))?.version;
101
+ if (!existsSync2(join2(dir, READY))) return void 0;
102
+ const cli = join2(dir, "node_modules", "antechamber", "dist", "cli.js");
103
+ const antechamber = readJson(join2(dir, "node_modules", "antechamber", "package.json"))?.version;
104
+ if (!existsSync2(cli) || typeof antechamber !== "string") return void 0;
105
+ const omo = readJson(join2(dir, "node_modules", "omo-ai", "package.json"))?.version;
59
106
  return { dir, cli, antechamber, omo: typeof omo === "string" ? omo : void 0 };
60
107
  }
108
+ function launchStampPath(home, launcher) {
109
+ const key = createHash("sha256").update(existsSync2(launcher) ? realpathSync(launcher) : launcher).digest("hex").slice(0, 16);
110
+ return join2(home, ".antechamber", "launches", key);
111
+ }
112
+ function writeStamp(stamp, now = Date.now()) {
113
+ mkdirSync(dirname2(stamp), { recursive: true });
114
+ writeFileSync2(stamp, String(now));
115
+ }
116
+ function readStamp(stamp) {
117
+ if (!existsSync2(stamp)) return void 0;
118
+ const at = Number(readFileSync2(stamp, "utf8"));
119
+ return Number.isFinite(at) ? at : void 0;
120
+ }
61
121
  function lockHeld(lock, deps) {
62
122
  let mtime;
63
123
  try {
64
- mtime = statSync(lock).mtimeMs;
124
+ mtime = statSync2(lock).mtimeMs;
65
125
  } catch {
66
126
  return false;
67
127
  }
68
- const pid = Number.parseInt(readFileSync(join(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
128
+ const pid = Number.parseInt(readFileSync2(join2(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
69
129
  if (deps.now() - mtime > STALE_LOCK_MS) return false;
70
130
  return !Number.isInteger(pid) || deps.pidAlive(pid);
71
131
  }
@@ -73,7 +133,7 @@ function runtimeState(paths, deps = defaultDeps()) {
73
133
  const runtime = installed(paths.dir);
74
134
  if (runtime) return { state: "ready", runtime };
75
135
  if (lockHeld(`${paths.dir}.lock`, deps)) return { state: "installing" };
76
- const error = existsSync(`${paths.dir}.error`) ? readFileSync(`${paths.dir}.error`, "utf8") : void 0;
136
+ const error = existsSync2(`${paths.dir}.error`) ? readFileSync2(`${paths.dir}.error`, "utf8") : void 0;
77
137
  return error ? { state: "failed", error } : { state: "missing" };
78
138
  }
79
139
  function tryLock(lock, deps) {
@@ -85,11 +145,11 @@ function tryLock(lock, deps) {
85
145
  rmSync(lock, { recursive: true, force: true });
86
146
  return tryLock(lock, deps);
87
147
  }
88
- writeFileSync(join(lock, "pid"), String(process.pid));
148
+ writeFileSync2(join2(lock, "pid"), String(process.pid));
89
149
  return true;
90
150
  }
91
151
  function prune(paths) {
92
- const others = readdirSync(paths.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== paths.key && !/\.(lock|tmp-.*)$/.test(entry.name)).map((entry) => join(paths.root, entry.name)).filter((dir) => existsSync(join(dir, READY)) && !existsSync(`${dir}.lock`)).map((dir) => ({ dir, at: Number(readJson(join(dir, READY))?.installedAt ?? 0) })).sort((a, b) => b.at - a.at);
152
+ const others = readdirSync(paths.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== paths.key && !/\.(lock|tmp-.*)$/.test(entry.name)).map((entry) => join2(paths.root, entry.name)).filter((dir) => existsSync2(join2(dir, READY)) && !existsSync2(`${dir}.lock`)).map((dir) => ({ dir, at: Number(readJson(join2(dir, READY))?.installedAt ?? 0) })).sort((a, b) => b.at - a.at);
93
153
  for (const { dir } of others.slice(1)) rmSync(dir, { recursive: true, force: true });
94
154
  }
95
155
  async function installOnce(paths, bun, deps) {
@@ -103,14 +163,14 @@ async function installOnce(paths, bun, deps) {
103
163
  // omo-ai's postinstall prepares its engine; Bun skips dependency scripts unless trusted.
104
164
  trustedDependencies: ["omo-ai"]
105
165
  };
106
- writeFileSync(join(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
166
+ writeFileSync2(join2(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
107
167
  `);
108
168
  await deps.install(bun, staging);
109
- writeFileSync(join(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
169
+ writeFileSync2(join2(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
110
170
  `);
111
171
  if (!installed(staging)) throw new Error(`bun install did not produce node_modules/antechamber/dist/cli.js`);
112
172
  rmSync(paths.dir, { recursive: true, force: true });
113
- renameSync(staging, paths.dir);
173
+ renameSync2(staging, paths.dir);
114
174
  } catch (error) {
115
175
  rmSync(staging, { recursive: true, force: true });
116
176
  throw error;
@@ -139,7 +199,7 @@ async function ensureRuntime(paths, bun, deps = defaultDeps()) {
139
199
  return runtime;
140
200
  } catch (error) {
141
201
  const message = error instanceof Error ? error.message : String(error);
142
- writeFileSync(`${paths.dir}.error`, message.slice(-ERROR_TAIL_CHARS));
202
+ writeFileSync2(`${paths.dir}.error`, message.slice(-ERROR_TAIL_CHARS));
143
203
  throw error;
144
204
  } finally {
145
205
  rmSync(lock, { recursive: true, force: true });
@@ -190,7 +250,6 @@ function defaultDeps() {
190
250
  // extensions/antechamber/src/service.ts
191
251
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
192
252
  import { createServer as createHttpServer } from "node:http";
193
- import { join as join5 } from "node:path";
194
253
 
195
254
  // extensions/antechamber/src/graph/routes.ts
196
255
  import http from "node:http";
@@ -446,19 +505,19 @@ function buildGraph(sessionId, tasks, registry) {
446
505
  }
447
506
 
448
507
  // extensions/antechamber/src/graph/store.ts
449
- import { lstatSync, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
508
+ import { lstatSync, readdirSync as readdirSync2, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
450
509
  import { homedir as homedir2 } from "node:os";
451
- import { join as join2 } from "node:path";
510
+ import { join as join3 } from "node:path";
452
511
  import { DatabaseSync } from "node:sqlite";
453
512
  function expandHome(path) {
454
513
  if (path === "~") return homedir2();
455
- return path.startsWith("~/") ? join2(homedir2(), path.slice(2)) : path;
514
+ return path.startsWith("~/") ? join3(homedir2(), path.slice(2)) : path;
456
515
  }
457
516
  function defaultRoots() {
458
517
  const home = homedir2();
459
518
  return {
460
- agentDirs: [join2(home, ".omo", "agent"), join2(home, ".pi", "agent")],
461
- stateDirs: [join2(home, ".config", "antechamber"), join2(home, ".config", "openchamber-pi-connector")]
519
+ agentDirs: [join3(home, ".omo", "agent"), join3(home, ".pi", "agent")],
520
+ stateDirs: [join3(home, ".config", "antechamber"), join3(home, ".config", "openchamber-pi-connector")]
462
521
  };
463
522
  }
464
523
  function isMissing(error) {
@@ -485,7 +544,7 @@ var JsonCache = class {
485
544
  read(path, accept) {
486
545
  let stat;
487
546
  try {
488
- stat = statSync2(path);
547
+ stat = statSync3(path);
489
548
  } catch (error) {
490
549
  if (isMissing(error)) {
491
550
  this.entries.delete(path);
@@ -497,7 +556,7 @@ var JsonCache = class {
497
556
  if (hit && hit.mtimeMs === stat.mtimeMs && hit.size === stat.size) return hit.value;
498
557
  let value;
499
558
  try {
500
- value = accept(JSON.parse(readFileSync2(path, "utf8")));
559
+ value = accept(JSON.parse(readFileSync3(path, "utf8")));
501
560
  } catch (error) {
502
561
  if (error instanceof SyntaxError || isMissing(error)) return hit?.value;
503
562
  throw error;
@@ -511,11 +570,11 @@ var RegistryReader = class {
511
570
  databases = /* @__PURE__ */ new Map();
512
571
  files = new JsonCache();
513
572
  read(dir) {
514
- const path = join2(dir, "sessions.sqlite");
573
+ const path = join3(dir, "sessions.sqlite");
515
574
  if (!isRegularFile(path)) {
516
575
  this.databases.get(path)?.db.close();
517
576
  this.databases.delete(path);
518
- return this.files.read(join2(dir, "sessions.json"), normalizeRegistry);
577
+ return this.files.read(join3(dir, "sessions.json"), normalizeRegistry);
519
578
  }
520
579
  let open = this.databases.get(path);
521
580
  if (!open) {
@@ -544,18 +603,18 @@ var TaskStore = class {
544
603
  storeDirs() {
545
604
  const dirs = /* @__PURE__ */ new Set();
546
605
  for (const agent of this.roots.agentDirs) {
547
- const registry = this.json.read(join2(agent, "rpc", "task-stores.json"), (v) => isRecord(v) ? v : void 0);
606
+ const registry = this.json.read(join3(agent, "rpc", "task-stores.json"), (v) => isRecord(v) ? v : void 0);
548
607
  if (isRecord(registry?.stores)) for (const dir of Object.keys(registry.stores)) dirs.add(dir);
549
- for (const project of list(join2(agent, "projects"))) dirs.add(join2(agent, "projects", project, "senpi-task"));
608
+ for (const project of list(join3(agent, "projects"))) dirs.add(join3(agent, "projects", project, "senpi-task"));
550
609
  }
551
610
  return [...dirs];
552
611
  }
553
612
  loadTasks() {
554
613
  const out = /* @__PURE__ */ new Map();
555
614
  for (const dir of this.storeDirs()) {
556
- for (const file of list(join2(dir, "tasks"))) {
615
+ for (const file of list(join3(dir, "tasks"))) {
557
616
  if (!file.endsWith(".json")) continue;
558
- const path = join2(dir, "tasks", file);
617
+ const path = join3(dir, "tasks", file);
559
618
  if (!isRegularFile(path)) continue;
560
619
  const task = this.tasks.read(path, normalizeTask);
561
620
  if (task) out.set(JSON.stringify([task.parent_session_id, task.task_id]), task);
@@ -668,35 +727,6 @@ function createServer(token2, makeStore = (r) => new TaskStore(r)) {
668
727
  });
669
728
  }
670
729
 
671
- // extensions/antechamber/src/runtime/activate.ts
672
- import { chmodSync, copyFileSync, existsSync as existsSync2, readFileSync as readFileSync3, renameSync as renameSync2, statSync as statSync3, writeFileSync as writeFileSync2 } from "node:fs";
673
- import { basename, dirname, join as join3 } from "node:path";
674
- function openchamberSettingsPath(extensionDir2) {
675
- for (let dir = extensionDir2; dirname(dir) !== dir; dir = dirname(dir)) {
676
- if (basename(dirname(dir)) !== "extensions") continue;
677
- const settings = join3(dirname(dirname(dir)), "settings.json");
678
- if (existsSync2(settings)) return settings;
679
- }
680
- return void 0;
681
- }
682
- function configuredBinary(settings) {
683
- const value = JSON.parse(readFileSync3(settings, "utf8")).opencodeBinary;
684
- return typeof value === "string" ? value : void 0;
685
- }
686
- function activateLauncher(settings, launcher, now = /* @__PURE__ */ new Date()) {
687
- const data = JSON.parse(readFileSync3(settings, "utf8"));
688
- if (data.opencodeBinary === launcher) return {};
689
- const backup = `${settings}.bak-antechamber-${now.toISOString().replace(/\D/g, "").slice(0, 14)}`;
690
- if (!existsSync2(backup)) copyFileSync(settings, backup);
691
- const mode = statSync3(settings).mode & 511;
692
- const temporary = `${settings}.antechamber-${process.pid}.tmp`;
693
- writeFileSync2(temporary, `${JSON.stringify({ ...data, opencodeBinary: launcher }, null, 2)}
694
- `, { mode });
695
- chmodSync(temporary, mode);
696
- renameSync2(temporary, settings);
697
- return { backup };
698
- }
699
-
700
730
  // extensions/antechamber/src/work/routes.ts
701
731
  import { timingSafeEqual } from "node:crypto";
702
732
  import http2 from "node:http";
@@ -844,24 +874,60 @@ function createService(options) {
844
874
  const graph = createServer(options.token);
845
875
  const work = createServer2({ token: options.token });
846
876
  let installing;
877
+ const launcher = launcherPath(options.extensionDir);
878
+ const launchStamp = launchStampPath(options.home, launcher);
879
+ const switchStamp = `${launchStamp}.switched`;
880
+ const findWritableSettings = () => options.settingsPath ?? openchamberSettingsPath(options.extensionDir);
881
+ const readSettings = (settingsPath) => {
882
+ try {
883
+ const configured = configuredBinary(settingsPath);
884
+ return configured === void 0 ? {} : { configured };
885
+ } catch (error) {
886
+ return { error: `${settingsPath} could not be read: ${error.message}` };
887
+ }
888
+ };
889
+ const activate = (settingsPath) => {
890
+ const activated = activateLauncher(settingsPath, launcher, new Date(deps.now()));
891
+ if (activated.backup !== void 0) writeStamp(switchStamp, deps.now());
892
+ return activated;
893
+ };
894
+ const activateUnasked = () => {
895
+ const settingsPath = findWritableSettings();
896
+ if (settingsPath === void 0 || runtimeState(options.paths, deps).state !== "ready") return;
897
+ if (readStamp(switchStamp) !== void 0) return;
898
+ try {
899
+ const configured = configuredBinary(settingsPath);
900
+ if (configured !== launcher && mayActivateUnasked(configured)) activate(settingsPath);
901
+ } catch (error) {
902
+ console.error(`antechamber: could not set the OpenCode CLI in ${settingsPath}: ${error.message}`);
903
+ }
904
+ };
847
905
  const install = () => {
848
- installing ??= ensureRuntime(options.paths, options.bun, deps).catch(() => void 0).finally(() => {
906
+ installing ??= ensureRuntime(options.paths, options.bun, deps).then(() => {
907
+ if (options.autoActivate) activateUnasked();
908
+ }).catch(() => void 0).finally(() => {
849
909
  installing = void 0;
850
910
  });
851
911
  return installing;
852
912
  };
853
- const launcher = join5(options.extensionDir, "bin", "opencode-antechamber");
854
- const findSettings = () => options.settingsPath ?? openchamberSettingsPath(options.extensionDir);
855
913
  const status = () => {
856
- const settingsPath = findSettings();
914
+ const writableSettings = findWritableSettings();
915
+ const settingsPath = writableSettings ?? openchamberSettingsPath(options.extensionDir, options.home);
857
916
  const current = runtimeState(options.paths, deps);
917
+ const { configured, error } = settingsPath === void 0 ? {} : readSettings(settingsPath);
918
+ const settingsError = writableSettings === void 0 ? void 0 : error;
919
+ const active = configured === launcher;
920
+ const switchedAt = readStamp(switchStamp);
858
921
  const base = {
859
922
  state: installing && current.state !== "ready" ? "installing" : current.state,
860
923
  spec: options.paths.spec,
861
924
  launcher,
862
925
  bun: options.bun ?? null,
863
- settings: settingsPath ?? null,
864
- active: settingsPath !== void 0 && configuredBinary(settingsPath) === launcher
926
+ settings: writableSettings ?? null,
927
+ configured: configured?.trim() ? configured : null,
928
+ active,
929
+ ...settingsError ? { settingsError } : {},
930
+ needsReload: active && switchedAt !== void 0 && (readStamp(launchStamp) ?? 0) < switchedAt
865
931
  };
866
932
  if (current.state === "ready")
867
933
  return {
@@ -875,6 +941,7 @@ function createService(options) {
875
941
  return base;
876
942
  };
877
943
  if (options.prewarm && options.bun && runtimeState(options.paths, deps).state === "missing") void install();
944
+ else if (options.autoActivate) activateUnasked();
878
945
  const expected = Buffer.from(`Bearer ${options.token}`);
879
946
  const send = (res, code, body) => {
880
947
  res.writeHead(code, { "Content-Type": "application/json", "Cache-Control": "no-store" });
@@ -896,14 +963,16 @@ function createService(options) {
896
963
  }
897
964
  if (pathname === "/runtime/activate" && req.method === "POST") {
898
965
  req.resume();
899
- const settingsPath = findSettings();
966
+ const settingsPath = findWritableSettings();
900
967
  if (settingsPath === void 0)
901
968
  return send(res, 409, {
902
969
  error: "settings-not-found",
903
- detail: "Set Settings -> OpenCode CLI to the launcher by hand."
970
+ detail: "Set Settings -> General -> OpenCode CLI to the launcher by hand."
904
971
  });
905
972
  if (runtimeState(options.paths, deps).state !== "ready") return send(res, 409, { error: "runtime-not-ready" });
906
- const activated = activateLauncher(settingsPath, launcher);
973
+ const unreadable = readSettings(settingsPath).error;
974
+ if (unreadable) return send(res, 409, { error: "settings-unreadable", detail: unreadable });
975
+ const activated = activate(settingsPath);
907
976
  return send(res, 200, { ...status(), ...activated });
908
977
  }
909
978
  return send(res, 404, { error: "not-found" });
@@ -917,14 +986,16 @@ if (!port || !token) {
917
986
  console.error("OPENCHAMBER_SERVICE_PORT and OPENCHAMBER_SERVICE_TOKEN are required");
918
987
  process.exit(1);
919
988
  }
920
- var extensionDir = resolve4(dirname2(fileURLToPath(import.meta.url)), "..");
921
- var { version } = JSON.parse(readFileSync5(join6(extensionDir, "package.json"), "utf8"));
922
- chmodSync2(join6(extensionDir, "bin", "opencode-antechamber"), 493);
989
+ var extensionDir = resolve4(dirname3(fileURLToPath(import.meta.url)), "..");
990
+ var { version } = JSON.parse(readFileSync5(join5(extensionDir, "package.json"), "utf8"));
991
+ chmodSync2(launcherPath(extensionDir), 493);
923
992
  var env = defaultEnv();
924
993
  createService({
925
994
  token,
926
995
  extensionDir,
927
996
  paths: runtimePaths(version, env),
928
997
  bun: findBun(env),
929
- prewarm: true
998
+ home: env.home,
999
+ prewarm: true,
1000
+ autoActivate: true
930
1001
  }).listen(port, "127.0.0.1");
@@ -63,6 +63,13 @@
63
63
  .action.danger { color: var(--bad-text); }
64
64
  .action[disabled] { opacity: .5; cursor: default; }
65
65
  .note { padding: 2px 4px; color: var(--muted); }
66
+ .notice { display: grid; gap: 6px; justify-items: start; padding: 7px 9px; border-radius: 6px; border-left: 3px solid var(--notice);
67
+ background: color-mix(in srgb, var(--notice) 12%, transparent); --notice: var(--run); }
68
+ .notice.n-warn { --notice: var(--warn); }
69
+ .notice.n-bad { --notice: var(--bad); }
70
+ .notice > span { justify-self: stretch; min-width: 0; overflow-wrap: anywhere; }
71
+ .notice code { font: 11px var(--mono); overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
72
+ .notice .primary { min-height: 24px; max-width: 100%; padding: 4px 10px; border-radius: 5px; background: var(--oc-primary, var(--run)); color: var(--oc-primary-fg, #001); font-weight: 600; }
66
73
  .note.is-error { color: var(--bad-text); }
67
74
  .settings { display: grid; gap: 6px; padding: 6px 8px; border-radius: 5px; background: var(--surface); }
68
75
  .settings label { display: grid; gap: 3px; font-size: 11px; color: var(--muted); }