backeer-codex 0.7.0 → 0.7.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,6 +1,6 @@
1
1
  {
2
2
  "name": "backeer-codex",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Backeer approvals, lifecycle notifications and chat-scoped OpenCode connections.",
5
5
  "author": {
6
6
  "name": "Backeer"
package/README.md CHANGED
@@ -170,6 +170,13 @@ or deny the pending operation. The launcher forces local hook mode only for its
170
170
  child processes, leaving your saved standalone mode unchanged. See the
171
171
  [official hook contract](https://learn.chatgpt.com/docs/hooks#permissionrequest).
172
172
 
173
+ ## 0.7.1 maintenance release
174
+
175
+ - Include the corrected OpenCode client diagnostics and indexed SSE history from Backeer OpenCode 0.10.1.
176
+ - Close incomplete HTTP connections when the companion shuts down.
177
+ - Validate the personal marketplace before replacing installed plugin files.
178
+ - Update the WebSocket runtime dependency to 8.22.1.
179
+
173
180
  ## Configure
174
181
 
175
182
  Install the published package and register it in the default Codex personal marketplace:
package/dist/opencode.mjs CHANGED
@@ -13004,7 +13004,7 @@ async function checkWindowsTokenAcl(file2, run = execute) {
13004
13004
  var details = Object.freeze({
13005
13005
  local_endpoint_unavailable: ["The local connection is not accepting connections.", "Open the existing SSH tunnel, then retry the same connection.", true],
13006
13006
  connection_timeout: ["The connection did not respond in time.", "Check the existing tunnel and remote bridge. Keep the current session running.", true],
13007
- connection_interrupted: ["The connection was interrupted.", "The stream retries automatically; keep the same binding and cursor.", true],
13007
+ connection_interrupted: ["The connection was interrupted.", "Check the existing tunnel and remote bridge, then retry the read. This operation does not retry automatically.", true],
13008
13008
  credentials_rejected: ["The bridge rejected the existing credential.", "Check that the protected local credential belongs to the intended bridge. Do not paste its value.", false],
13009
13009
  project_mismatch: ["The connection points to a different project.", "Check the tunnel target and saved project. Do not switch sessions automatically.", false],
13010
13010
  session_unavailable: ["The selected session is no longer available.", "List current sessions and ask the user to select one. Never create or substitute a session automatically.", false],
@@ -13017,7 +13017,7 @@ var details = Object.freeze({
13017
13017
  cancelled: ["The local operation was cancelled.", "Retry only if the user still wants this operation.", false],
13018
13018
  connection_unavailable: ["The connection could not be verified.", "Check the existing tunnel and bridge; keep the selected session unchanged.", true]
13019
13019
  });
13020
- function connectionDiagnostic(error62, { session = false, write = false, timeout = false, cancelled = false, tokenFile = false } = {}) {
13020
+ function connectionDiagnostic(error62, { session = false, write = false, timeout = false, cancelled = false, tokenFile = false, stream = false } = {}) {
13021
13021
  const code = error62?.cause?.code ?? error62?.code;
13022
13022
  let kind = "connection_unavailable";
13023
13023
  if (cancelled) kind = "cancelled";
@@ -13033,7 +13033,7 @@ function connectionDiagnostic(error62, { session = false, write = false, timeout
13033
13033
  else if (["ECONNRESET", "EPIPE", "UND_ERR_SOCKET"].includes(code)) kind = "connection_interrupted";
13034
13034
  else if (error62 instanceof SyntaxError) kind = "invalid_bridge_response";
13035
13035
  const [message, nextStep, retryable] = details[kind];
13036
- return { code: kind, message, nextStep, retryable };
13036
+ return { code: kind, message, nextStep: kind === "connection_interrupted" && stream ? "The stream retries automatically; keep the same binding and cursor. Never automatically repeat an instruction." : nextStep, retryable };
13037
13037
  }
13038
13038
  function safeConnectionMessage(error62) {
13039
13039
  if (!Object.hasOwn(details, error62?.connectionCode)) return void 0;
@@ -13138,6 +13138,8 @@ var LiveControlClient = class {
13138
13138
  this.maxBufferBytes = maxBufferBytes;
13139
13139
  this.reconnectMs = reconnectMs;
13140
13140
  this.events = [];
13141
+ this.eventPositions = /* @__PURE__ */ new Map();
13142
+ this.eventOffset = 0;
13141
13143
  this.bufferBytes = 0;
13142
13144
  this.listeners = /* @__PURE__ */ new Set();
13143
13145
  this.controller = new AbortController();
@@ -13371,8 +13373,7 @@ var LiveControlClient = class {
13371
13373
  resync = true;
13372
13374
  this.cursor = this.gap.cursor;
13373
13375
  this.floor = this.cursor;
13374
- this.events = [];
13375
- this.bufferBytes = 0;
13376
+ this.clearEvents();
13376
13377
  this.status = "resync_required";
13377
13378
  this.notify();
13378
13379
  break;
@@ -13381,17 +13382,7 @@ var LiveControlClient = class {
13381
13382
  if (checkedCursor(frame.id) !== event.id || !frame.id || typeof event.type !== "string") {
13382
13383
  throw new Error("Invalid SSE event envelope");
13383
13384
  }
13384
- if (this.events.some((item2) => item2.event.id === event.id)) continue;
13385
- const bytes = Buffer.byteLength(JSON.stringify(event));
13386
- if (bytes > this.maxBufferBytes) throw new Error("SSE event exceeds buffer limit");
13387
- this.events.push({ event, bytes });
13388
- this.bufferBytes += bytes;
13389
- this.cursor = event.id;
13390
- while (this.events.length > this.maxEvents || this.bufferBytes > this.maxBufferBytes) {
13391
- const discarded = this.events.shift();
13392
- this.bufferBytes -= discarded.bytes;
13393
- this.floor = discarded.event.id;
13394
- }
13385
+ if (!this.retainEvent(event)) continue;
13395
13386
  this.notify();
13396
13387
  }
13397
13388
  }
@@ -13426,7 +13417,31 @@ var LiveControlClient = class {
13426
13417
  }
13427
13418
  recordFailure(error62, context) {
13428
13419
  this.lastDisconnectedAt = Date.now();
13429
- this.lastDiagnostic = connectionDiagnostic(error62, context);
13420
+ this.lastDiagnostic = connectionDiagnostic(error62, { ...context, stream: !this.controller.signal.aborted && Boolean(this.task || this.starting) });
13421
+ }
13422
+ retainEvent(event) {
13423
+ if (this.eventPositions.has(event.id)) return false;
13424
+ const encoded = JSON.stringify(event);
13425
+ const bytes = Buffer.byteLength(encoded);
13426
+ if (bytes > this.maxBufferBytes) throw new Error("SSE event exceeds buffer limit");
13427
+ this.eventPositions.set(event.id, this.eventOffset + this.events.length);
13428
+ this.events.push({ event, bytes, chars: encoded.length });
13429
+ this.bufferBytes += bytes;
13430
+ this.cursor = event.id;
13431
+ while (this.events.length > this.maxEvents || this.bufferBytes > this.maxBufferBytes) {
13432
+ const discarded = this.events.shift();
13433
+ this.eventPositions.delete(discarded.event.id);
13434
+ this.eventOffset++;
13435
+ this.bufferBytes -= discarded.bytes;
13436
+ this.floor = discarded.event.id;
13437
+ }
13438
+ return true;
13439
+ }
13440
+ clearEvents() {
13441
+ this.events = [];
13442
+ this.eventPositions.clear();
13443
+ this.eventOffset = 0;
13444
+ this.bufferBytes = 0;
13430
13445
  }
13431
13446
  connectionState() {
13432
13447
  return {
@@ -13450,8 +13465,8 @@ var LiveControlClient = class {
13450
13465
  let gap = this.gap;
13451
13466
  let start = 0;
13452
13467
  if (!gap && afterCursor !== this.floor) {
13453
- const at = this.events.findIndex((item) => item.event.id === afterCursor);
13454
- if (at >= 0) start = at + 1;
13468
+ const at = this.eventPositions.get(afterCursor);
13469
+ if (at !== void 0) start = at - this.eventOffset + 1;
13455
13470
  else if (afterCursor && afterCursor !== this.cursor) gap = { reason: "client_buffer_expired", cursor: this.floor };
13456
13471
  }
13457
13472
  if (gap) return { events: [], cursor: afterCursor, gap, connection: this.status, hasMore: false };
@@ -13465,7 +13480,7 @@ var LiveControlClient = class {
13465
13480
  cursor = event.id;
13466
13481
  continue;
13467
13482
  }
13468
- const size = JSON.stringify(event).length;
13483
+ const size = this.events[index].chars;
13469
13484
  if (result.length >= limit || result.length && chars + size > maxChars) break;
13470
13485
  if (size > maxChars) {
13471
13486
  return { events: result, cursor, connection: this.status, hasMore: true, requiredMaxChars: size };
@@ -13516,8 +13531,7 @@ var LiveControlClient = class {
13516
13531
  this.notify();
13517
13532
  await this.starting;
13518
13533
  await this.task;
13519
- this.events = [];
13520
- this.bufferBytes = 0;
13534
+ this.clearEvents();
13521
13535
  this.listeners.clear();
13522
13536
  }
13523
13537
  };
@@ -13834,7 +13848,7 @@ var LiveSessionManager = class {
13834
13848
  return {
13835
13849
  ...result2,
13836
13850
  verified: false,
13837
- diagnostic: connectionDiagnostic(error62),
13851
+ diagnostic: connectionDiagnostic(error62, { stream: true }),
13838
13852
  nextStep: "Keep this binding and cursor. The stream retries every 3 seconds; verify the same session after reconnection before sending or acknowledging a gap."
13839
13853
  };
13840
13854
  }
@@ -13869,7 +13883,7 @@ var LiveSessionManager = class {
13869
13883
  ...bindingId ? { bindingId } : {},
13870
13884
  healthy: false,
13871
13885
  verified: false,
13872
- diagnostic: connectionDiagnostic(error62),
13886
+ diagnostic: connectionDiagnostic(error62, { stream: Boolean(bound) }),
13873
13887
  ...bound ? { transport: bound.client.connectionState() } : {}
13874
13888
  };
13875
13889
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backeer-codex",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Backeer approvals, notifications and per-chat OpenCode connections for Codex",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -39,7 +39,7 @@
39
39
  "check:package": "node scripts/check-package.mjs"
40
40
  },
41
41
  "dependencies": {
42
- "ws": "^8.22.0"
42
+ "ws": "^8.22.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@modelcontextprotocol/sdk": "^1.32.2",
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "backeer-codex",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "description": "Backeer approvals, lifecycle notifications and chat-scoped OpenCode connections.",
6
6
  "author": {
7
7
  "name": "Backeer"
package/src/companion.mjs CHANGED
@@ -30,6 +30,12 @@ export async function createCompanion({
30
30
  const sockets = new WebSocketServer({ noServer: true, maxPayload: 0, perMessageDeflate: false });
31
31
  const abort = new AbortController();
32
32
  let backend, socket, bridge, lines, remoteTask, closeTask, closing = false, used = false;
33
+ const connections = new Set();
34
+ server.on("connection", (connection) => {
35
+ if (closing) { connection.destroy(); return; }
36
+ connections.add(connection);
37
+ connection.once("close", () => connections.delete(connection));
38
+ });
33
39
 
34
40
  const sendBackend = (message) => {
35
41
  if (!backend || backend.stdin.destroyed || backend.stdin.writableEnded) throw new Error("App-server disconnected");
@@ -113,6 +119,10 @@ export async function createCompanion({
113
119
  bridge?.dispose();
114
120
  lines?.close();
115
121
  socket?.terminate();
122
+ // A peer can connect without finishing HTTP/upgrade headers. Those
123
+ // sockets never reach the WebSocket handler but must close with us too.
124
+ for (const connection of connections) connection.destroy();
125
+ connections.clear();
116
126
  backend?.stdin.end();
117
127
  let backendClosed;
118
128
  if (backend?.pid && backend.exitCode === null && backend.signalCode === null) {
package/src/installer.mjs CHANGED
@@ -43,14 +43,17 @@ function backeerEntry() {
43
43
  };
44
44
  }
45
45
 
46
- async function writeMarketplace(file, marketplace) {
47
- if (!/^[A-Za-z0-9_-]+$/.test(marketplace.name || "")) {
46
+ function validateMarketplace(file, marketplace) {
47
+ if (!marketplace || !/^[A-Za-z0-9_-]+$/.test(marketplace.name || "")) {
48
48
  throw new Error(`Invalid personal marketplace name in ${file}`);
49
49
  }
50
50
  if (!Array.isArray(marketplace.plugins)) {
51
51
  throw new Error(`Invalid plugins list in ${file}`);
52
52
  }
53
+ }
53
54
 
55
+ async function writeMarketplace(file, marketplace) {
56
+ validateMarketplace(file, marketplace);
54
57
  const entry = backeerEntry();
55
58
  const index = marketplace.plugins.findIndex((plugin) => plugin?.name === PLUGIN_NAME);
56
59
  if (index === -1) marketplace.plugins.push(entry);
@@ -99,6 +102,10 @@ function runCodexInstall(marketplaceName) {
99
102
 
100
103
  export async function installPlugin(options = {}) {
101
104
  const paths = personalPaths(options.homeDirectory);
105
+ // Validate before touching an installed plugin: a corrupt registry must not
106
+ // leave new files behind while reporting that the installation failed.
107
+ const marketplace = await readMarketplace(paths.marketplaceFile);
108
+ validateMarketplace(paths.marketplaceFile, marketplace);
102
109
  await copyPlugin(options.packageRoot || PACKAGE_ROOT, paths.pluginDirectory);
103
110
  // Codex loads a copied plugin outside npm's global package directory. Its
104
111
  // companion therefore needs its own runtime dependency, not just source files.
@@ -107,7 +114,7 @@ export async function installPlugin(options = {}) {
107
114
  if (path.resolve(wsRoot) !== path.resolve(wsDestination)) {
108
115
  await fs.cp(wsRoot, wsDestination, { recursive: true, force: true });
109
116
  }
110
- const marketplaceName = await writeMarketplace(paths.marketplaceFile, await readMarketplace(paths.marketplaceFile));
117
+ const marketplaceName = await writeMarketplace(paths.marketplaceFile, marketplace);
111
118
  if (options.installWithCodex !== false) await runCodexInstall(marketplaceName);
112
119
  return { ...paths, marketplaceName };
113
120
  }