@auroraflow/code 0.0.9 → 0.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auroraflow/code",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "description": "Aurora launcher and sidecar for official Codex and Claude Code clients.",
6
6
  "repository": {
@@ -1,15 +1,17 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
2
  import { randomBytes } from "node:crypto";
3
- import { existsSync, readFileSync } from "node:fs";
3
+ import { closeSync, existsSync, openSync, readFileSync } from "node:fs";
4
4
  import { mkdir, writeFile } from "node:fs/promises";
5
5
  import { delimiter, dirname, join, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { AURORA_SIDECAR_PORT } from "../../protocol/src/index.js";
8
- import { CLAUDE_HOME, CODEX_HOME, readSidecarInfo, readState, writeSidecarInfo } from "../../state/src/index.js";
8
+ import { AURORA_HOME, CLAUDE_HOME, CODEX_HOME, readSidecarInfo, readState, writeSidecarInfo } from "../../state/src/index.js";
9
9
 
10
10
  const here = dirname(fileURLToPath(import.meta.url));
11
11
  const packageRoot = resolve(here, "..", "..", "..");
12
12
  const rootSidecarBin = join(packageRoot, "bin", "aurora-sidecar.js");
13
+ const sidecarLogPath = join(AURORA_HOME, "log", "sidecar.log");
14
+ let sidecarSupervisor = null;
13
15
 
14
16
  const OFFICIAL_CLIENTS = {
15
17
  claude: {
@@ -150,18 +152,45 @@ async function ensureSidecar() {
150
152
  // Start below.
151
153
  }
152
154
  const token = `aurora-local-${randomBytes(24).toString("hex")}`;
153
- const child = spawn(process.execPath, [process.env.AURORA_SIDECAR_BIN || rootSidecarBin, "--token", token], {
154
- detached: true,
155
- stdio: "ignore",
156
- env: process.env
157
- });
158
- child.unref();
159
155
  const info = { port: AURORA_SIDECAR_PORT, token, baseURL: `http://127.0.0.1:${AURORA_SIDECAR_PORT}` };
156
+ await startManagedSidecar(info);
160
157
  await waitForSidecar(info);
161
158
  await writeSidecarInfo(info);
162
159
  return info;
163
160
  }
164
161
 
162
+ async function startManagedSidecar(info) {
163
+ if (sidecarSupervisor) return;
164
+ await mkdir(dirname(sidecarLogPath), { recursive: true });
165
+ const launch = () => {
166
+ const logFd = openSync(sidecarLogPath, "a");
167
+ const child = spawn(process.execPath, [
168
+ process.env.AURORA_SIDECAR_BIN || rootSidecarBin,
169
+ "--token",
170
+ info.token,
171
+ "--port",
172
+ String(info.port)
173
+ ], {
174
+ detached: true,
175
+ stdio: ["ignore", logFd, logFd],
176
+ env: process.env
177
+ });
178
+ closeSync(logFd);
179
+ sidecarSupervisor.child = child;
180
+ child.on("error", error => {
181
+ console.error(`Aurora sidecar failed to start: ${error.message}`);
182
+ });
183
+ child.on("exit", () => {
184
+ sidecarSupervisor.child = null;
185
+ setTimeout(launch, 1000);
186
+ });
187
+ };
188
+ sidecarSupervisor = {
189
+ child: null
190
+ };
191
+ launch();
192
+ }
193
+
165
194
  async function writeCodexRuntimeFiles({ sidecar, model }) {
166
195
  await mkdir(CODEX_HOME, { recursive: true });
167
196
  const modelCatalogPath = join(CODEX_HOME, "model_catalog.json");
@@ -15,12 +15,26 @@ export async function startSidecar(options = {}) {
15
15
  response.end(JSON.stringify({ error: { type: "sidecar_error", message: error.message } }));
16
16
  });
17
17
  });
18
+ server.on("error", error => {
19
+ console.error(`Aurora sidecar listen error on ${AURORA_LOCALHOST}:${port}: ${error.message}`);
20
+ process.exit(1);
21
+ });
18
22
  server.listen(port, AURORA_LOCALHOST, async () => {
19
23
  await writeSidecarInfo({ port, token, baseURL: `http://${AURORA_LOCALHOST}:${port}` });
20
24
  console.error(`Aurora sidecar listening on http://${AURORA_LOCALHOST}:${port}`);
21
25
  });
22
26
  }
23
27
 
28
+ process.on("uncaughtException", error => {
29
+ console.error(`Aurora sidecar uncaught exception: ${error?.stack || error?.message || error}`);
30
+ process.exit(1);
31
+ });
32
+
33
+ process.on("unhandledRejection", reason => {
34
+ console.error(`Aurora sidecar unhandled rejection: ${reason?.stack || reason?.message || reason}`);
35
+ process.exit(1);
36
+ });
37
+
24
38
  async function handle(request, response, token) {
25
39
  if (!isAuthorized(request, token)) {
26
40
  writeJSON(response, 401, { error: { type: "unauthorized", message: "sidecar token required" } });