backeer-codex 0.9.1 → 0.10.0

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.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Backeer approvals, lifecycle notifications and chat-scoped OpenCode connections.",
5
5
  "author": {
6
6
  "name": "Backeer"
package/README.md CHANGED
@@ -266,3 +266,19 @@ model is called. New code requires a new plugin process/chat.
266
266
  ### Notification reliability in 0.9.1
267
267
 
268
268
  Includes the Backeer OpenCode 0.12.1 adapter. Update the owning OpenCode plugin to 0.12.1 for native TUI completion, question and permission pushes. Automatic filesystem Always allow decisions also send an informational notification, without another approval action. The footer now says “Klasör eşleşmiyor” when the live-control project pin differs from the owner location.
269
+
270
+ ### Multiple projects in 0.10.0
271
+
272
+ With Backeer OpenCode 0.13.0+, enable `liveBridge.mode: "shared"` in the existing
273
+ global plugin options and remove the old `projectDirectory` pin. The same SSH
274
+ tunnel/port and protected live token serve multiple OpenCode project owners.
275
+ Discovery presents each project separately; choose its connection, then pick a
276
+ session interactively. Each chat keeps its exact project/session and descendant
277
+ stream. Missing projects fail explicitly and never redirect to a remaining one.
278
+ Existing pinned connections still work. Update both the remote owner and this
279
+ local adapter to use multi-project discovery.
280
+
281
+ The adapter distinguishes native API outages, archived sessions and verified
282
+ project-scope rejection from absence in a particular owner. It does not infer
283
+ deletion merely because an index or another native process omits the ID. Shared
284
+ mode also includes fresh Git-verified worktree sessions without hardcoded IDs.
package/dist/opencode.mjs CHANGED
@@ -13007,7 +13007,13 @@ var details = Object.freeze({
13007
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
- 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],
13010
+ project_required: ["This endpoint hosts multiple projects.", "Discover projects and let the user choose a project connection before selecting a session.", false],
13011
+ session_required: ["This project has several native OpenCode owners.", "Choose an exact session before following output. No owner or session was selected automatically.", false],
13012
+ project_unavailable: ["The selected project owner is temporarily unavailable.", "Keep the same project and binding. Wait for its owner to return; never send work to another project.", true],
13013
+ session_unavailable: ["The current verified OpenCode owner cannot find this exact session.", "Check its project, worktree and owning process. This response does not prove deletion; never create or substitute a session automatically.", false],
13014
+ session_project_mismatch: ["The exact session is outside this connection's verified project/worktree scope.", "Discover its actual project connection or verify the already authorized worktree. Keep the exact session ID; do not substitute another session.", false],
13015
+ session_archived: ["The native API reports that the selected session is archived.", "Confirm the intended session state with the user. Do not create or choose a replacement automatically.", false],
13016
+ native_session_api_unavailable: ["The owning native OpenCode API is temporarily unavailable.", "Keep the same binding, project and session. Check the native API connection and retry after recovery; this is not evidence of deletion.", true],
13011
13017
  bridge_unavailable: ["The remote bridge endpoint is unavailable.", "Check the existing bridge and its version without restarting the active session.", true],
13012
13018
  bridge_busy: ["The remote bridge is temporarily busy.", "Keep the current binding and retry the read later. Never automatically repeat an instruction.", true],
13013
13019
  request_conflict: ["The request conflicts with an existing operation.", "Check the operation result before replying or sending again. Do not change the request ID after uncertain delivery.", false],
@@ -13045,6 +13051,14 @@ function safeConnectionMessage(error62) {
13045
13051
 
13046
13052
  // ../opencode-plugin/src/live-errors.js
13047
13053
  var liveErrorMessages = Object.freeze({
13054
+ native_session_api_unavailable: "The owning native OpenCode API could not be reached or verified. This does not mean the session was deleted. Keep the exact project/session and retry after its native API recovers.",
13055
+ session_not_found: "This verified OpenCode owner cannot currently find the exact session. Check its project, worktree and owning process; absence here is not proof that the session was deleted elsewhere.",
13056
+ session_project_mismatch: "The exact session exists but is outside this connection's verified project/worktree scope. Choose its actual project connection; do not recreate or replace the session.",
13057
+ session_archived: "The exact session is archived in the owning native API. No replacement session was selected.",
13058
+ invalid_native_session_response: "The native API returned a different session identity. The response was rejected without switching the target.",
13059
+ project_required: "Choose an exact project connection before listing sessions or following output. Discover projects through this same endpoint.",
13060
+ session_required: "This project has several OpenCode owners. Select an exact session before following live output.",
13061
+ project_unavailable: "The selected project owner is not available. Keep the same connection; do not select another project automatically.",
13048
13062
  question_private_server_unavailable: "The existing private OpenCode server could not be verified. Keep its current session running; check its native API connection without switching sessions or starting another server.",
13049
13063
  question_shared_service_unavailable: "No compatible running OpenCode shared service is available for native questions. Keep current work running; configure its supported shared-service connection before retrying.",
13050
13064
  question_session_not_in_shared_service: "The running OpenCode shared service does not own this exact question session. Check the service connection; do not switch sessions or create a replacement.",
@@ -13214,6 +13228,7 @@ var LiveControlClient = class {
13214
13228
  Authorization: `Bearer ${this.token}`,
13215
13229
  Accept: "application/json",
13216
13230
  ...this.projectHeaders,
13231
+ ...this.sessionId ? { "X-Backeer-Session": this.sessionId } : {},
13217
13232
  ...body ? { "Content-Type": "application/json" } : {}
13218
13233
  },
13219
13234
  ...body ? { body: JSON.stringify(body) } : {}
@@ -13224,7 +13239,16 @@ var LiveControlClient = class {
13224
13239
  if (response.headers.get("content-type")?.includes("application/json")) {
13225
13240
  const value2 = JSON.parse(await responseText(response));
13226
13241
  if (Object.hasOwn(liveErrorMessages, value2?.error)) code = value2.error;
13227
- if (value2?.error === "project_mismatch") connectionCode = "project_mismatch";
13242
+ if (["project_mismatch", "project_required", "project_unavailable", "session_required"].includes(value2?.error)) connectionCode = value2.error;
13243
+ const sessionErrors = {
13244
+ native_session_api_unavailable: "native_session_api_unavailable",
13245
+ session_not_found: "session_unavailable",
13246
+ session_project_mismatch: "session_project_mismatch",
13247
+ session_archived: "session_archived",
13248
+ invalid_native_session_response: "invalid_bridge_response",
13249
+ route_not_found: "bridge_unavailable"
13250
+ };
13251
+ connectionCode ??= sessionErrors[value2?.error];
13228
13252
  }
13229
13253
  } catch {
13230
13254
  } finally {
@@ -13239,6 +13263,11 @@ var LiveControlClient = class {
13239
13263
  }
13240
13264
  const text = await responseText(response);
13241
13265
  const value = JSON.parse(text);
13266
+ const source = response.headers.get("x-backeer-source");
13267
+ if (source && this.sessionId) {
13268
+ if (this.sourceIdentity && this.sourceIdentity !== source) this.activeConnection?.abort();
13269
+ this.sourceIdentity = source;
13270
+ }
13242
13271
  if (path3 === "/v1/sessions") {
13243
13272
  this.bridgeInfo = { bridgeVersion: value?.bridgeVersion, capabilities: value?.capabilities };
13244
13273
  if (this.eventScope === "tree" && value?.capabilities?.sessionTree !== true) throw treeUnsupported();
@@ -13300,6 +13329,7 @@ var LiveControlClient = class {
13300
13329
  if (this.gap && afterCursor === this.gap.cursor) {
13301
13330
  this.gap = null;
13302
13331
  this.readCursor = afterCursor;
13332
+ if (this.status === "resync_required") this.status = "disconnected";
13303
13333
  }
13304
13334
  if (this.task || this.gap) return;
13305
13335
  if (!this.starting) {
@@ -13346,6 +13376,7 @@ var LiveControlClient = class {
13346
13376
  let resync = false;
13347
13377
  let timedOut = false;
13348
13378
  const connection2 = new AbortController();
13379
+ this.activeConnection = connection2;
13349
13380
  const abort = () => connection2.abort();
13350
13381
  this.controller.signal.addEventListener("abort", abort, { once: true });
13351
13382
  const armWatchdog = (ms = this.staleMs) => {
@@ -13376,7 +13407,12 @@ var LiveControlClient = class {
13376
13407
  const response = await this.fetch(`${this.url}/v1/events?after=${encodeURIComponent(this.cursor)}${selected}`, {
13377
13408
  redirect: "error",
13378
13409
  signal: connection2.signal,
13379
- headers: { Authorization: `Bearer ${this.token}`, Accept: "text/event-stream", ...this.projectHeaders }
13410
+ headers: {
13411
+ Authorization: `Bearer ${this.token}`,
13412
+ Accept: "text/event-stream",
13413
+ ...this.projectHeaders,
13414
+ ...this.sessionId ? { "X-Backeer-Session": this.sessionId } : {}
13415
+ }
13380
13416
  });
13381
13417
  if (this.controller.signal.aborted) {
13382
13418
  await response.body?.cancel().catch(() => {
@@ -13454,6 +13490,7 @@ var LiveControlClient = class {
13454
13490
  }
13455
13491
  } finally {
13456
13492
  clearTimeout(watchdog);
13493
+ if (this.activeConnection === connection2) this.activeConnection = void 0;
13457
13494
  this.controller.signal.removeEventListener("abort", abort);
13458
13495
  await reader?.cancel().catch(() => {
13459
13496
  });
@@ -13749,6 +13786,11 @@ async function discoverLiveConnections({ profiles = [], defaults = discoveryDefa
13749
13786
  const candidates = [];
13750
13787
  const diagnostics = /* @__PURE__ */ new Set();
13751
13788
  const diagnosticDetails = /* @__PURE__ */ new Map();
13789
+ const recordFailure = (error62) => {
13790
+ const detail = error62 instanceof ConnectionError ? connectionDiagnostic({ connectionCode: "project_mismatch" }) : connectionDiagnostic(error62);
13791
+ diagnosticDetails.set(detail.code, detail);
13792
+ diagnostics.add(error62 instanceof ConnectionError ? "project_metadata_missing_or_changed" : /HTTP (401|403)/.test(error62.message) ? "credential_not_accepted" : /HTTP 409/.test(error62.message) ? "project_metadata_missing_or_changed" : "tunnel_or_bridge_unavailable");
13793
+ };
13752
13794
  let readableFiles = 0;
13753
13795
  for (const { origin, file: file2 } of pairs.values()) {
13754
13796
  let token;
@@ -13765,15 +13807,36 @@ async function discoverLiveConnections({ profiles = [], defaults = discoveryDefa
13765
13807
  const known = profiles.find((item) => item.url === origin && item.tokenFile === file2);
13766
13808
  const client = new LiveControlClient({ url: origin, token, expectedDirectory: known?.directory });
13767
13809
  try {
13768
- const result = await client.request("/v1/sessions", { timeoutMs: 3e3, signal });
13769
- const profile = connectionProfile({ name: known?.name || "discovered", url: origin, tokenFile: file2, directory: result.directory });
13770
- if (!Array.isArray(result.sessions)) throw new Error("Invalid session list");
13771
- const sessions = result.sessions.filter((item) => item && typeof item.id === "string" && typeof item.title === "string");
13772
- candidates.push({ profile, sessions: sessions.filter((item) => !item.parentID), subagentCount: sessions.filter((item) => item.parentID).length });
13810
+ let directories = [known?.directory];
13811
+ try {
13812
+ const catalog = await client.request("/v1/projects", { timeoutMs: 3e3, signal });
13813
+ if (catalog.capabilities?.multiProject === true) {
13814
+ if (catalog.protocol !== "backeer-project-gateway/v1" || !Array.isArray(catalog.projects) || catalog.projects.some((item) => typeof item?.directory !== "string" || !isAbsolute3(item.directory))) {
13815
+ throw new Error("Invalid project catalog");
13816
+ }
13817
+ directories = [...new Set(catalog.projects.map((item) => item.directory))];
13818
+ }
13819
+ } catch (error62) {
13820
+ if (error62.status !== 404) throw error62;
13821
+ }
13822
+ for (const directory of directories) {
13823
+ const selected = new LiveControlClient({ url: origin, token, expectedDirectory: directory });
13824
+ try {
13825
+ const result = await selected.request("/v1/sessions", { timeoutMs: 3e3, signal });
13826
+ if (directory !== void 0 && result.directory !== directory) throw new ConnectionError("Project verification failed");
13827
+ const saved = profiles.find((item) => item.url === origin && item.tokenFile === file2 && item.directory === result.directory);
13828
+ const profile = connectionProfile({ name: saved?.name || "discovered", url: origin, tokenFile: file2, directory: result.directory });
13829
+ if (!Array.isArray(result.sessions)) throw new Error("Invalid session list");
13830
+ const sessions = result.sessions.filter((item) => item && typeof item.id === "string" && typeof item.title === "string");
13831
+ candidates.push({ profile, sessions: sessions.filter((item) => !item.parentID), subagentCount: sessions.filter((item) => item.parentID).length });
13832
+ } catch (error62) {
13833
+ recordFailure(error62);
13834
+ } finally {
13835
+ await selected.close();
13836
+ }
13837
+ }
13773
13838
  } catch (error62) {
13774
- const detail = error62 instanceof ConnectionError ? connectionDiagnostic({ connectionCode: "project_mismatch" }) : connectionDiagnostic(error62);
13775
- diagnosticDetails.set(detail.code, detail);
13776
- diagnostics.add(error62 instanceof ConnectionError ? "project_metadata_missing_or_changed" : /HTTP (401|403)/.test(error62.message) ? "credential_not_accepted" : /HTTP 409/.test(error62.message) ? "project_metadata_missing_or_changed" : "tunnel_or_bridge_unavailable");
13839
+ recordFailure(error62);
13777
13840
  } finally {
13778
13841
  await client.close();
13779
13842
  }
@@ -13783,7 +13846,7 @@ async function discoverLiveConnections({ profiles = [], defaults = discoveryDefa
13783
13846
  }
13784
13847
 
13785
13848
  // ../opencode-plugin/src/updates.js
13786
- var PLUGIN_VERSION = "0.12.1";
13849
+ var PLUGIN_VERSION = "0.13.0";
13787
13850
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
13788
13851
 
13789
13852
  // ../opencode-plugin/src/live-health.js
@@ -13984,7 +14047,6 @@ var LiveSessionManager = class {
13984
14047
  if (matches.length !== 1) throw new ConnectionError("Session title is missing or ambiguous. Select an exact ID from the current list.");
13985
14048
  sessionId = matches[0].id;
13986
14049
  }
13987
- if (!bridge.sessions.some((item) => item.id === sessionId)) throw new ConnectionError("Selected session is unavailable. No alternate session was selected.");
13988
14050
  this.checkTreeCapability(bridge);
13989
14051
  client.sessionId = sessionId;
13990
14052
  client.eventScope = "tree";
@@ -13992,7 +14054,7 @@ var LiveSessionManager = class {
13992
14054
  this.checkProject(profile, session);
13993
14055
  if (session.id !== sessionId) throw new ConnectionError("Session verification failed.");
13994
14056
  sessionVerified = true;
13995
- await client.start(bridge.cursor);
14057
+ await client.start();
13996
14058
  const connected = await client.waitForConnection(timeoutMs, signal);
13997
14059
  return {
13998
14060
  connection: connection2,
@@ -43656,12 +43718,13 @@ function choices(sessions) {
43656
43718
  const labels = /* @__PURE__ */ new Set();
43657
43719
  return sessions.map((session, index) => {
43658
43720
  const title = displayTitle(session.title);
43659
- let label = title;
43721
+ const worktree = typeof session.locationDirectory === "string" ? displayTitle(session.locationDirectory.split(/[\\/]/).filter(Boolean).at(-1) ?? "") : "";
43722
+ let label = worktree ? `${title} \xB7 ${worktree}` : title;
43660
43723
  if (counts.get(title) > 1) {
43661
43724
  let length = Math.min(8, session.id.length);
43662
43725
  while (length < session.id.length && sessions.some((other) => other.id !== session.id && other.id.slice(-length) === session.id.slice(-length))) length++;
43663
43726
  const status = typeof session.status === "string" ? ` (${displayTitle(session.status)})` : "";
43664
- label = `${title}${status} \xB7 ${session.id.slice(-length)}`;
43727
+ label = `${label}${status} \xB7 ${session.id.slice(-length)}`;
43665
43728
  }
43666
43729
  while (labels.has(label)) label += ` [${index + 1}]`;
43667
43730
  labels.add(label);
@@ -43669,9 +43732,10 @@ function choices(sessions) {
43669
43732
  });
43670
43733
  }
43671
43734
  function sessionSummaries(sessions) {
43672
- return sessions.map(({ id, title, status, parentID }) => ({
43735
+ return sessions.map(({ id, title, status, parentID, locationDirectory }) => ({
43673
43736
  id,
43674
43737
  title,
43738
+ ...typeof locationDirectory === "string" ? { locationDirectory } : {},
43675
43739
  ...typeof status === "string" ? { status } : {},
43676
43740
  ...parentID ? { parentID } : {}
43677
43741
  }));
@@ -43821,7 +43885,7 @@ function createManagedLiveMcp(manager) {
43821
43885
  );
43822
43886
  tool(
43823
43887
  "discover_connections",
43824
- "Find existing Backeer loopback tunnels using configured/default local endpoints and protected token files. No port-range/vault scan, SSH change or credential copying. Returns safe candidate IDs and clear setup diagnostics. Optional URL/tokenFile are local paths, never secret values.",
43888
+ "Discover active projects through existing Backeer loopback tunnels and protected token files. A shared endpoint can return several project candidates; save a separate named connection for each chosen project. Reuse this tool when another project is requested even if one connection is already saved. No port-range/vault scan, SSH change or credential copying. Optional URL/tokenFile are local paths, never secret values.",
43825
43889
  { url: external_exports.string().optional(), tokenFile: external_exports.string().optional() },
43826
43890
  readOnly,
43827
43891
  (args, extra) => manager.discover(args, extra.signal)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backeer-codex",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Backeer approvals, notifications and per-chat OpenCode connections for Codex",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
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.9.1",
4
+ "version": "0.10.0",
5
5
  "description": "Backeer approvals, lifecycle notifications and chat-scoped OpenCode connections.",
6
6
  "author": {
7
7
  "name": "Backeer"
@@ -31,7 +31,7 @@ Use the bundled Backeer OpenCode MCP tools, not screenshots or terminal scraping
31
31
 
32
32
  Use `connection_setup` for a guided flow when the user needs help choosing a connection/session. It returns a stage and next tool: choose a saved connection, or a verified candidate to save, then a current session. Present choices in the user's language. Use `select_session` for the session step, including when the user asks to list OpenCode sessions for selection. Never silently choose a session or ask for raw credentials. `connection_setup` and `select_session` do not save a profile or bind a session; use the existing save/connect tools only after the intended choice is clear.
33
33
 
34
- 1. Call `list_connections`. If none exist, call `discover_connections` **before asking for technical details**. Discovery checks only default/configured local endpoints and known protected files; no port-range scan, Termius vault access, SSH edits or credential copying.
34
+ 1. Call `list_connections`. If none exist, call `discover_connections` **before asking for technical details**. Also call discovery when the user wants another project on an already saved server: a shared gateway can expose several project candidates through the same endpoint. Present project names/directories in the user's language, let the user choose, and save a separate connection name for each intended project; never repoint an existing profile. Discovery checks only default/configured local endpoints and known protected files; no port-range scan, Termius vault access, SSH edits or credential copying.
35
35
  2. Present verified candidates by project/connection name. If the user clearly identified the only matching target, call `save_connection` with its candidateId and a short name. If ambiguous, ask one concise question in the user's language. Never invent a server or choose a different project automatically.
36
36
  3. If discovery fails, explain the specific diagnostic: missing protected file, tunnel/bridge unavailable, invalid permissions, rejected credential or project mismatch. Guide only the missing prerequisite. Ask for a local file path or loopback URL only when necessary; never request token values, passwords or private key contents. A new computer with no SSH setup still needs that one-time setup.
37
37
  4. Call `select_session` to present an interactive choice of current main sessions; pass a concise `message` in the user's language. Hide subagents unless requested. The tool uses the host's native MCP form when supported; titles identify choices and duplicate titles are disambiguated. If it returns `selectionRequired`, use the host's interactive question tool (such as `request_user_input_async`) with the returned choices in the user's language. If that tool limits the number of choices, offer pages or a title filter without dropping sessions. Use a plain numbered question only if the host has no interactive question interface. Wait for an actual answer: a preselected option, timeout, decline or cancellation is never a choice. Map the answer to the exact ID from the fresh list; ambiguous free text requires clarification. After an accepted selection, call `connect_session` with that exact `sessionId`, without a redundant confirmation. If the user explicitly requested only an inventory and no connection, return the choice without connecting. An already explicit exact session title/ID can use `connect_session` directly. Use `list_sessions` for programmatic inventories or refreshing fallback choices, not as a replacement for the interactive picker. `connect_session` automatically follows the selected task and all its verified subagents, including newly created descendants. Do not ask the user to enable subagent tracking or choose a scope. Never choose the newest session or reuse a hardcoded old ID. A stale selection requires a fresh choice, never a replacement session with the same title.
@@ -83,3 +83,28 @@ Retained history is bounded (10000 events / 16 MiB by default per client/bridge)
83
83
  On expiry, disclose the gap, verify exact session status, then explicitly acknowledge
84
84
  gap.cursor. A stream_payload_limit requires a larger configured budget and explicit
85
85
  reconnection to the same selected session, not automatic retries or a new task.
86
+
87
+ ## Shared project gateway
88
+
89
+ Backeer OpenCode 0.13.0+ supports `liveBridge.mode: "shared"`. One configured
90
+ loopback port and protected token file serve all active project owners. Remove
91
+ legacy `projectDirectory` from global options when migrating; explicit shared
92
+ mode overrides an old pin. The local adapter discovers all verified projects via
93
+ `/v1/projects`, then saves their exact directory in separate named profiles.
94
+ Choose project first, then use the interactive session picker. Existing bindings
95
+ retain their original target even when another project appears or disappears.
96
+ Never turn `project_unavailable` into permission to use another project. Keep the
97
+ same binding/cursor and wait for that owner to recover. Gateway re-election uses
98
+ the same port and never creates an OpenCode session/service or another SSH tunnel.
99
+
100
+ From OpenCode 0.13.0 shared mode, fresh sessions in Git-verified worktrees are
101
+ included automatically, including after reload. Do not ask users to hardcode
102
+ session IDs or worktree paths into global configuration for this mode. The picker
103
+ can show a worktree label while connecting by exact ID. An inventory with
104
+ `complete: false` is partial; never infer deletion from omission. Explicit-ID
105
+ verification checks the actual native session even if its index is incomplete.
106
+ `session_unavailable` means this native owner cannot find the ID, not proof of
107
+ deletion elsewhere. `native_session_api_unavailable` is a retryable native API
108
+ outage: keep the binding and buffered output, and do not resend work.
109
+ `session_project_mismatch` requires the correct project/worktree scope rather
110
+ than a replacement session; `session_archived` reports an actual archived row.