antechamber 2.0.16 → 2.0.18

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,59 @@
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) {
10
+ for (let dir = extensionDir2; dirname(dir) !== dir; dir = dirname(dir)) {
11
+ if (basename(dirname(dir)) !== "extensions") continue;
12
+ const settings = join(dirname(dirname(dir)), "settings.json");
13
+ if (existsSync(settings)) return settings;
14
+ }
15
+ return void 0;
16
+ }
17
+ function launcherPath(extensionDir2) {
18
+ return join(extensionDir2, "bin", "opencode-antechamber");
19
+ }
20
+ function configuredBinary(settings) {
21
+ const value = JSON.parse(readFileSync(settings, "utf8")).opencodeBinary;
22
+ return typeof value === "string" ? value : void 0;
23
+ }
24
+ function mayActivateUnasked(configured) {
25
+ return !configured?.trim() || basename(configured) === "opencode-antechamber";
26
+ }
27
+ function activateLauncher(settings, launcher, now = /* @__PURE__ */ new Date()) {
28
+ const data = JSON.parse(readFileSync(settings, "utf8"));
29
+ if (data.opencodeBinary === launcher) return {};
30
+ const backup = `${settings}.bak-antechamber-${now.toISOString().replace(/\D/g, "").slice(0, 14)}`;
31
+ if (!existsSync(backup)) copyFileSync(settings, backup);
32
+ const mode = statSync(settings).mode & 511;
33
+ const temporary = `${settings}.antechamber-${process.pid}.tmp`;
34
+ writeFileSync(temporary, `${JSON.stringify({ ...data, opencodeBinary: launcher }, null, 2)}
35
+ `, { mode });
36
+ chmodSync(temporary, mode);
37
+ renameSync(temporary, settings);
38
+ return { backup };
39
+ }
40
+
6
41
  // extensions/antechamber/src/runtime/runtime.ts
7
42
  import { spawn } from "node:child_process";
8
43
  import { createHash } from "node:crypto";
9
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
44
+ import {
45
+ existsSync as existsSync2,
46
+ mkdirSync,
47
+ readdirSync,
48
+ readFileSync as readFileSync2,
49
+ realpathSync,
50
+ renameSync as renameSync2,
51
+ rmSync,
52
+ statSync as statSync2,
53
+ writeFileSync as writeFileSync2
54
+ } from "node:fs";
10
55
  import { homedir } from "node:os";
11
- import { delimiter, isAbsolute, join, resolve } from "node:path";
56
+ import { delimiter, dirname as dirname2, isAbsolute, join as join2, resolve } from "node:path";
12
57
  var STALE_LOCK_MS = 15 * 6e4;
13
58
  var INSTALL_TIMEOUT_MS = 10 * 6e4;
14
59
  var READY = ".ready.json";
@@ -18,25 +63,25 @@ function defaultEnv() {
18
63
  }
19
64
  function runtimeRoot({ env: env2, home }) {
20
65
  const configured = env2.ANTECHAMBER_RUNTIME_DIR?.trim();
21
- return configured ? resolve(configured) : join(home, ".antechamber", "runtime");
66
+ return configured ? resolve(configured) : join2(home, ".antechamber", "runtime");
22
67
  }
23
68
  function runtimePaths(version2, runtime) {
24
69
  const root = runtimeRoot(runtime);
25
70
  const override = runtime.env.ANTECHAMBER_RUNTIME_SPEC?.trim();
26
- if (!override) return { root, spec: version2, key: version2, dir: join(root, version2) };
71
+ if (!override) return { root, spec: version2, key: version2, dir: join2(root, version2) };
27
72
  const spec = isAbsolute(override) ? override : resolve(override);
28
- const stamp = existsSync(spec) ? `${statSync(spec).mtimeMs}:${statSync(spec).size}` : "";
73
+ const stamp = existsSync2(spec) ? `${statSync2(spec).mtimeMs}:${statSync2(spec).size}` : "";
29
74
  const key = `local-${createHash("sha256").update(`${spec}
30
75
  ${stamp}`).digest("hex").slice(0, 12)}`;
31
- return { root, spec: `file:${spec}`, key, dir: join(root, key) };
76
+ return { root, spec: `file:${spec}`, key, dir: join2(root, key) };
32
77
  }
33
- function findBun({ env: env2, home }, exists = existsSync) {
78
+ function findBun({ env: env2, home }, exists = existsSync2) {
34
79
  for (const dir of (env2.PATH ?? "").split(delimiter)) {
35
- if (dir && exists(join(dir, "bun"))) return join(dir, "bun");
80
+ if (dir && exists(join2(dir, "bun"))) return join2(dir, "bun");
36
81
  }
37
82
  for (const candidate of [
38
- join(env2.BUN_INSTALL ?? join(home, ".bun"), "bin", "bun"),
39
- join(home, ".bun", "bin", "bun")
83
+ join2(env2.BUN_INSTALL ?? join2(home, ".bun"), "bin", "bun"),
84
+ join2(home, ".bun", "bin", "bun")
40
85
  ]) {
41
86
  if (exists(candidate)) return candidate;
42
87
  }
@@ -44,28 +89,41 @@ function findBun({ env: env2, home }, exists = existsSync) {
44
89
  }
45
90
  function readJson(path) {
46
91
  try {
47
- const value = JSON.parse(readFileSync(path, "utf8"));
92
+ const value = JSON.parse(readFileSync2(path, "utf8"));
48
93
  return typeof value === "object" && value !== null ? value : void 0;
49
94
  } catch {
50
95
  return void 0;
51
96
  }
52
97
  }
53
98
  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;
99
+ if (!existsSync2(join2(dir, READY))) return void 0;
100
+ const cli = join2(dir, "node_modules", "antechamber", "dist", "cli.js");
101
+ const antechamber = readJson(join2(dir, "node_modules", "antechamber", "package.json"))?.version;
102
+ if (!existsSync2(cli) || typeof antechamber !== "string") return void 0;
103
+ const omo = readJson(join2(dir, "node_modules", "omo-ai", "package.json"))?.version;
59
104
  return { dir, cli, antechamber, omo: typeof omo === "string" ? omo : void 0 };
60
105
  }
106
+ function launchStampPath(home, launcher) {
107
+ const key = createHash("sha256").update(existsSync2(launcher) ? realpathSync(launcher) : launcher).digest("hex").slice(0, 16);
108
+ return join2(home, ".antechamber", "launches", key);
109
+ }
110
+ function writeStamp(stamp, now = Date.now()) {
111
+ mkdirSync(dirname2(stamp), { recursive: true });
112
+ writeFileSync2(stamp, String(now));
113
+ }
114
+ function readStamp(stamp) {
115
+ if (!existsSync2(stamp)) return void 0;
116
+ const at = Number(readFileSync2(stamp, "utf8"));
117
+ return Number.isFinite(at) ? at : void 0;
118
+ }
61
119
  function lockHeld(lock, deps) {
62
120
  let mtime;
63
121
  try {
64
- mtime = statSync(lock).mtimeMs;
122
+ mtime = statSync2(lock).mtimeMs;
65
123
  } catch {
66
124
  return false;
67
125
  }
68
- const pid = Number.parseInt(readFileSync(join(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
126
+ const pid = Number.parseInt(readFileSync2(join2(lock, "pid"), { encoding: "utf8", flag: "a+" }), 10);
69
127
  if (deps.now() - mtime > STALE_LOCK_MS) return false;
70
128
  return !Number.isInteger(pid) || deps.pidAlive(pid);
71
129
  }
@@ -73,7 +131,7 @@ function runtimeState(paths, deps = defaultDeps()) {
73
131
  const runtime = installed(paths.dir);
74
132
  if (runtime) return { state: "ready", runtime };
75
133
  if (lockHeld(`${paths.dir}.lock`, deps)) return { state: "installing" };
76
- const error = existsSync(`${paths.dir}.error`) ? readFileSync(`${paths.dir}.error`, "utf8") : void 0;
134
+ const error = existsSync2(`${paths.dir}.error`) ? readFileSync2(`${paths.dir}.error`, "utf8") : void 0;
77
135
  return error ? { state: "failed", error } : { state: "missing" };
78
136
  }
79
137
  function tryLock(lock, deps) {
@@ -85,11 +143,11 @@ function tryLock(lock, deps) {
85
143
  rmSync(lock, { recursive: true, force: true });
86
144
  return tryLock(lock, deps);
87
145
  }
88
- writeFileSync(join(lock, "pid"), String(process.pid));
146
+ writeFileSync2(join2(lock, "pid"), String(process.pid));
89
147
  return true;
90
148
  }
91
149
  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);
150
+ 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
151
  for (const { dir } of others.slice(1)) rmSync(dir, { recursive: true, force: true });
94
152
  }
95
153
  async function installOnce(paths, bun, deps) {
@@ -103,14 +161,14 @@ async function installOnce(paths, bun, deps) {
103
161
  // omo-ai's postinstall prepares its engine; Bun skips dependency scripts unless trusted.
104
162
  trustedDependencies: ["omo-ai"]
105
163
  };
106
- writeFileSync(join(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
164
+ writeFileSync2(join2(staging, "package.json"), `${JSON.stringify(manifest, null, 2)}
107
165
  `);
108
166
  await deps.install(bun, staging);
109
- writeFileSync(join(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
167
+ writeFileSync2(join2(staging, READY), `${JSON.stringify({ spec: paths.spec, installedAt: deps.now() })}
110
168
  `);
111
169
  if (!installed(staging)) throw new Error(`bun install did not produce node_modules/antechamber/dist/cli.js`);
112
170
  rmSync(paths.dir, { recursive: true, force: true });
113
- renameSync(staging, paths.dir);
171
+ renameSync2(staging, paths.dir);
114
172
  } catch (error) {
115
173
  rmSync(staging, { recursive: true, force: true });
116
174
  throw error;
@@ -139,7 +197,7 @@ async function ensureRuntime(paths, bun, deps = defaultDeps()) {
139
197
  return runtime;
140
198
  } catch (error) {
141
199
  const message = error instanceof Error ? error.message : String(error);
142
- writeFileSync(`${paths.dir}.error`, message.slice(-ERROR_TAIL_CHARS));
200
+ writeFileSync2(`${paths.dir}.error`, message.slice(-ERROR_TAIL_CHARS));
143
201
  throw error;
144
202
  } finally {
145
203
  rmSync(lock, { recursive: true, force: true });
@@ -190,7 +248,6 @@ function defaultDeps() {
190
248
  // extensions/antechamber/src/service.ts
191
249
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
192
250
  import { createServer as createHttpServer } from "node:http";
193
- import { join as join5 } from "node:path";
194
251
 
195
252
  // extensions/antechamber/src/graph/routes.ts
196
253
  import http from "node:http";
@@ -446,19 +503,19 @@ function buildGraph(sessionId, tasks, registry) {
446
503
  }
447
504
 
448
505
  // extensions/antechamber/src/graph/store.ts
449
- import { lstatSync, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
506
+ import { lstatSync, readdirSync as readdirSync2, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
450
507
  import { homedir as homedir2 } from "node:os";
451
- import { join as join2 } from "node:path";
508
+ import { join as join3 } from "node:path";
452
509
  import { DatabaseSync } from "node:sqlite";
453
510
  function expandHome(path) {
454
511
  if (path === "~") return homedir2();
455
- return path.startsWith("~/") ? join2(homedir2(), path.slice(2)) : path;
512
+ return path.startsWith("~/") ? join3(homedir2(), path.slice(2)) : path;
456
513
  }
457
514
  function defaultRoots() {
458
515
  const home = homedir2();
459
516
  return {
460
- agentDirs: [join2(home, ".omo", "agent"), join2(home, ".pi", "agent")],
461
- stateDirs: [join2(home, ".config", "antechamber"), join2(home, ".config", "openchamber-pi-connector")]
517
+ agentDirs: [join3(home, ".omo", "agent"), join3(home, ".pi", "agent")],
518
+ stateDirs: [join3(home, ".config", "antechamber"), join3(home, ".config", "openchamber-pi-connector")]
462
519
  };
463
520
  }
464
521
  function isMissing(error) {
@@ -485,7 +542,7 @@ var JsonCache = class {
485
542
  read(path, accept) {
486
543
  let stat;
487
544
  try {
488
- stat = statSync2(path);
545
+ stat = statSync3(path);
489
546
  } catch (error) {
490
547
  if (isMissing(error)) {
491
548
  this.entries.delete(path);
@@ -497,7 +554,7 @@ var JsonCache = class {
497
554
  if (hit && hit.mtimeMs === stat.mtimeMs && hit.size === stat.size) return hit.value;
498
555
  let value;
499
556
  try {
500
- value = accept(JSON.parse(readFileSync2(path, "utf8")));
557
+ value = accept(JSON.parse(readFileSync3(path, "utf8")));
501
558
  } catch (error) {
502
559
  if (error instanceof SyntaxError || isMissing(error)) return hit?.value;
503
560
  throw error;
@@ -511,11 +568,11 @@ var RegistryReader = class {
511
568
  databases = /* @__PURE__ */ new Map();
512
569
  files = new JsonCache();
513
570
  read(dir) {
514
- const path = join2(dir, "sessions.sqlite");
571
+ const path = join3(dir, "sessions.sqlite");
515
572
  if (!isRegularFile(path)) {
516
573
  this.databases.get(path)?.db.close();
517
574
  this.databases.delete(path);
518
- return this.files.read(join2(dir, "sessions.json"), normalizeRegistry);
575
+ return this.files.read(join3(dir, "sessions.json"), normalizeRegistry);
519
576
  }
520
577
  let open = this.databases.get(path);
521
578
  if (!open) {
@@ -544,18 +601,18 @@ var TaskStore = class {
544
601
  storeDirs() {
545
602
  const dirs = /* @__PURE__ */ new Set();
546
603
  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);
604
+ const registry = this.json.read(join3(agent, "rpc", "task-stores.json"), (v) => isRecord(v) ? v : void 0);
548
605
  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"));
606
+ for (const project of list(join3(agent, "projects"))) dirs.add(join3(agent, "projects", project, "senpi-task"));
550
607
  }
551
608
  return [...dirs];
552
609
  }
553
610
  loadTasks() {
554
611
  const out = /* @__PURE__ */ new Map();
555
612
  for (const dir of this.storeDirs()) {
556
- for (const file of list(join2(dir, "tasks"))) {
613
+ for (const file of list(join3(dir, "tasks"))) {
557
614
  if (!file.endsWith(".json")) continue;
558
- const path = join2(dir, "tasks", file);
615
+ const path = join3(dir, "tasks", file);
559
616
  if (!isRegularFile(path)) continue;
560
617
  const task = this.tasks.read(path, normalizeTask);
561
618
  if (task) out.set(JSON.stringify([task.parent_session_id, task.task_id]), task);
@@ -668,35 +725,6 @@ function createServer(token2, makeStore = (r) => new TaskStore(r)) {
668
725
  });
669
726
  }
670
727
 
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
728
  // extensions/antechamber/src/work/routes.ts
701
729
  import { timingSafeEqual } from "node:crypto";
702
730
  import http2 from "node:http";
@@ -844,24 +872,58 @@ function createService(options) {
844
872
  const graph = createServer(options.token);
845
873
  const work = createServer2({ token: options.token });
846
874
  let installing;
875
+ const launcher = launcherPath(options.extensionDir);
876
+ const launchStamp = launchStampPath(options.home, launcher);
877
+ const switchStamp = `${launchStamp}.switched`;
878
+ const findSettings = () => options.settingsPath ?? openchamberSettingsPath(options.extensionDir);
879
+ const readSettings = (settingsPath) => {
880
+ try {
881
+ const configured = configuredBinary(settingsPath);
882
+ return configured === void 0 ? {} : { configured };
883
+ } catch (error) {
884
+ return { error: `${settingsPath} could not be read: ${error.message}` };
885
+ }
886
+ };
887
+ const activate = (settingsPath) => {
888
+ const activated = activateLauncher(settingsPath, launcher, new Date(deps.now()));
889
+ if (activated.backup !== void 0) writeStamp(switchStamp, deps.now());
890
+ return activated;
891
+ };
892
+ const activateUnasked = () => {
893
+ const settingsPath = findSettings();
894
+ if (settingsPath === void 0 || runtimeState(options.paths, deps).state !== "ready") return;
895
+ if (readStamp(switchStamp) !== void 0) return;
896
+ try {
897
+ const configured = configuredBinary(settingsPath);
898
+ if (configured !== launcher && mayActivateUnasked(configured)) activate(settingsPath);
899
+ } catch (error) {
900
+ console.error(`antechamber: could not set the OpenCode CLI in ${settingsPath}: ${error.message}`);
901
+ }
902
+ };
847
903
  const install = () => {
848
- installing ??= ensureRuntime(options.paths, options.bun, deps).catch(() => void 0).finally(() => {
904
+ installing ??= ensureRuntime(options.paths, options.bun, deps).then(() => {
905
+ if (options.autoActivate) activateUnasked();
906
+ }).catch(() => void 0).finally(() => {
849
907
  installing = void 0;
850
908
  });
851
909
  return installing;
852
910
  };
853
- const launcher = join5(options.extensionDir, "bin", "opencode-antechamber");
854
- const findSettings = () => options.settingsPath ?? openchamberSettingsPath(options.extensionDir);
855
911
  const status = () => {
856
912
  const settingsPath = findSettings();
857
913
  const current = runtimeState(options.paths, deps);
914
+ const { configured, error: settingsError } = settingsPath === void 0 ? {} : readSettings(settingsPath);
915
+ const active = configured === launcher;
916
+ const switchedAt = readStamp(switchStamp);
858
917
  const base = {
859
918
  state: installing && current.state !== "ready" ? "installing" : current.state,
860
919
  spec: options.paths.spec,
861
920
  launcher,
862
921
  bun: options.bun ?? null,
863
922
  settings: settingsPath ?? null,
864
- active: settingsPath !== void 0 && configuredBinary(settingsPath) === launcher
923
+ configured: configured?.trim() ? configured : null,
924
+ active,
925
+ ...settingsError ? { settingsError } : {},
926
+ needsReload: active && switchedAt !== void 0 && (readStamp(launchStamp) ?? 0) < switchedAt
865
927
  };
866
928
  if (current.state === "ready")
867
929
  return {
@@ -875,6 +937,7 @@ function createService(options) {
875
937
  return base;
876
938
  };
877
939
  if (options.prewarm && options.bun && runtimeState(options.paths, deps).state === "missing") void install();
940
+ else if (options.autoActivate) activateUnasked();
878
941
  const expected = Buffer.from(`Bearer ${options.token}`);
879
942
  const send = (res, code, body) => {
880
943
  res.writeHead(code, { "Content-Type": "application/json", "Cache-Control": "no-store" });
@@ -900,10 +963,12 @@ function createService(options) {
900
963
  if (settingsPath === void 0)
901
964
  return send(res, 409, {
902
965
  error: "settings-not-found",
903
- detail: "Set Settings -> OpenCode CLI to the launcher by hand."
966
+ detail: "Set Settings -> General -> OpenCode CLI to the launcher by hand."
904
967
  });
905
968
  if (runtimeState(options.paths, deps).state !== "ready") return send(res, 409, { error: "runtime-not-ready" });
906
- const activated = activateLauncher(settingsPath, launcher);
969
+ const unreadable = readSettings(settingsPath).error;
970
+ if (unreadable) return send(res, 409, { error: "settings-unreadable", detail: unreadable });
971
+ const activated = activate(settingsPath);
907
972
  return send(res, 200, { ...status(), ...activated });
908
973
  }
909
974
  return send(res, 404, { error: "not-found" });
@@ -917,14 +982,16 @@ if (!port || !token) {
917
982
  console.error("OPENCHAMBER_SERVICE_PORT and OPENCHAMBER_SERVICE_TOKEN are required");
918
983
  process.exit(1);
919
984
  }
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);
985
+ var extensionDir = resolve4(dirname3(fileURLToPath(import.meta.url)), "..");
986
+ var { version } = JSON.parse(readFileSync5(join5(extensionDir, "package.json"), "utf8"));
987
+ chmodSync2(launcherPath(extensionDir), 493);
923
988
  var env = defaultEnv();
924
989
  createService({
925
990
  token,
926
991
  extensionDir,
927
992
  paths: runtimePaths(version, env),
928
993
  bun: findBun(env),
929
- prewarm: true
994
+ home: env.home,
995
+ prewarm: true,
996
+ autoActivate: true
930
997
  }).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); }