negotium 0.3.9 → 0.3.11

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/dist/main.js CHANGED
@@ -1869,7 +1869,7 @@ var exports_version = {};
1869
1869
  __export(exports_version, {
1870
1870
  NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
1871
1871
  });
1872
- var NEGOTIUM_VERSION = "0.3.9";
1872
+ var NEGOTIUM_VERSION = "0.3.11";
1873
1873
 
1874
1874
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
1875
1875
  import { spawn } from "child_process";
@@ -46078,12 +46078,18 @@ var init_workspace_control = __esm(async () => {
46078
46078
  // ../../adapters/otium/src/join-cli.ts
46079
46079
  var exports_join_cli = {};
46080
46080
  __export(exports_join_cli, {
46081
+ localNodeNameDefault: () => localNodeNameDefault,
46081
46082
  joinCommand: () => joinCommand
46082
46083
  });
46084
+ import { hostname as hostname2 } from "os";
46083
46085
  function option2(args, name) {
46084
46086
  const index = args.indexOf(`--${name}`);
46085
46087
  return index >= 0 ? args[index + 1]?.trim() : undefined;
46086
46088
  }
46089
+ function localNodeNameDefault() {
46090
+ const normalized = hostname2().trim().toLowerCase().replace(/\.local$/, "").replace(/[^a-z0-9._-]+/g, "-").replace(/^[-._]+|[-._]+$/g, "").slice(0, 32).replace(/[-._]+$/g, "");
46091
+ return normalized || undefined;
46092
+ }
46087
46093
  async function confirmEnrollment(message) {
46088
46094
  if (!process.stdin.isTTY)
46089
46095
  return false;
@@ -46116,7 +46122,7 @@ async function joinCommand(args) {
46116
46122
  try {
46117
46123
  const invite = parseEnrollmentInvite(code);
46118
46124
  const resuming = isEnrollmentPending(invite);
46119
- let nodeName = option2(args, "name");
46125
+ let nodeName = option2(args, "name") || localNodeNameDefault();
46120
46126
  if (resuming) {
46121
46127
  console.log(`Resuming interrupted Otium enrollment with ${invite.central}`);
46122
46128
  } else {
@@ -46184,8 +46190,30 @@ var init_join_cli = __esm(async () => {
46184
46190
  var exports_sidecar = {};
46185
46191
  __export(exports_sidecar, {
46186
46192
  runOtiumSidecar: () => runOtiumSidecar,
46193
+ resolveTunnelTargets: () => resolveTunnelTargets,
46187
46194
  proxyOtiumPeerRequest: () => proxyOtiumPeerRequest
46188
46195
  });
46196
+ function withCellId(base, cellId) {
46197
+ return {
46198
+ info: (obj, msg) => base.info({ ...obj, cellId }, msg),
46199
+ warn: (obj, msg) => base.warn({ ...obj, cellId }, msg),
46200
+ error: (obj, msg) => base.error({ ...obj, cellId }, msg)
46201
+ };
46202
+ }
46203
+ function resolveTunnelTargets(joins, relayOverride) {
46204
+ const targets = [];
46205
+ const skippedNoRelay = [];
46206
+ const envRelay = process.env.OTIUM_RELAY_URL?.trim();
46207
+ for (const join44 of joins) {
46208
+ const relayUrl = relayOverride?.trim() || join44.relay || envRelay;
46209
+ if (!relayUrl) {
46210
+ skippedNoRelay.push(join44.cellId);
46211
+ continue;
46212
+ }
46213
+ targets.push({ cellId: join44.cellId, relayUrl, secret: join44.secret });
46214
+ }
46215
+ return { targets, skippedNoRelay };
46216
+ }
46189
46217
  function isPublicPeerPath(pathname) {
46190
46218
  return pathname === "/ready" || pathname.startsWith("/api/v1/peer/");
46191
46219
  }
@@ -46219,8 +46247,8 @@ async function proxyOtiumPeerRequest(req, dependencies = {}) {
46219
46247
  }
46220
46248
  }
46221
46249
  async function runOtiumSidecar(options) {
46222
- const join44 = loadJoin();
46223
- if (!join44) {
46250
+ const joins = loadJoins();
46251
+ if (joins.length === 0) {
46224
46252
  throw new Error("not joined to an Otium workspace \u2014 run `negotium otium join <code>` first");
46225
46253
  }
46226
46254
  const initialNode = await inspectNodeDaemon();
@@ -46252,24 +46280,34 @@ async function runOtiumSidecar(options) {
46252
46280
  lease.stop();
46253
46281
  throw error2;
46254
46282
  }
46255
- const selectedRelay = options.relayUrl?.trim() || join44.relay || process.env.OTIUM_RELAY_URL?.trim();
46256
- const tunnel = selectedRelay ? new TunnelClient({
46257
- relayUrl: selectedRelay,
46258
- token: join44.secret,
46259
- targetOrigin: `http://127.0.0.1:${server.port}`,
46260
- nodeVersion: `negotium@${NEGOTIUM_VERSION}`,
46261
- logger
46262
- }) : null;
46263
- tunnel?.start();
46283
+ const { targets, skippedNoRelay } = resolveTunnelTargets(joins, options.relayUrl);
46284
+ const tunnels = new Map;
46285
+ for (const target of targets) {
46286
+ tunnels.set(target.cellId, new TunnelClient({
46287
+ relayUrl: target.relayUrl,
46288
+ token: target.secret,
46289
+ targetOrigin: `http://127.0.0.1:${server.port}`,
46290
+ nodeVersion: `negotium@${NEGOTIUM_VERSION}`,
46291
+ logger: withCellId(logger, target.cellId)
46292
+ }));
46293
+ }
46294
+ if (skippedNoRelay.length > 0) {
46295
+ logger.warn({ cellIds: skippedNoRelay }, "otium sidecar: no relay URL for these joined workspaces; they have no tunnel and will not be reachable");
46296
+ }
46297
+ for (const tunnel of tunnels.values())
46298
+ tunnel.start();
46264
46299
  let resolveCompleted;
46265
46300
  const completed = new Promise((resolve27) => {
46266
46301
  resolveCompleted = resolve27;
46267
46302
  });
46268
46303
  onShutdown("otium-sidecar-server", 130, () => server?.stop(true));
46269
- onShutdown("otium-sidecar-tunnel", 120, () => tunnel?.stop());
46304
+ onShutdown("otium-sidecar-tunnel", 120, () => {
46305
+ for (const tunnel of tunnels.values())
46306
+ tunnel.stop();
46307
+ });
46270
46308
  onShutdown("otium-sidecar-lease", 110, () => lease.stop());
46271
46309
  onShutdown("otium-sidecar-completed", -100, resolveCompleted);
46272
- process.stdout.write(`negotium Otium adapter listening on 127.0.0.1:${server.port} (canonical node pid ${initialNode.info?.pid})
46310
+ process.stdout.write(`negotium Otium adapter listening on 127.0.0.1:${server.port} (canonical node pid ${initialNode.info?.pid}, ${tunnels.size}/${joins.length} workspace tunnel${joins.length === 1 ? "" : "s"} started)
46273
46311
  `);
46274
46312
  await completed;
46275
46313
  }
@@ -47189,4 +47227,4 @@ switch (command) {
47189
47227
  }
47190
47228
  }
47191
47229
 
47192
- //# debugId=CD070F248BC98B8864756E2164756E21
47230
+ //# debugId=4271BDC4F3BBFD0764756E2164756E21