@dotobokuri/fleet-cli 1.14.0 → 1.15.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.
package/dist/index.js CHANGED
@@ -24805,7 +24805,7 @@ async function validateAuthKeyForCli(cli, apiKey) {
24805
24805
  };
24806
24806
  }
24807
24807
 
24808
- // ../../packages/fleet-infra/dist/chunk-EXVG4MVC.js
24808
+ // ../../packages/fleet-infra/dist/chunk-2AS5XT5Z.js
24809
24809
  init_chunk_UH3Q34DS();
24810
24810
 
24811
24811
  // ../../packages/fleet-infra/dist/chunk-24PI6O5Z.js
@@ -24895,13 +24895,15 @@ function ensureSafeDirectoryIfSensitive(dir, sensitivity) {
24895
24895
  }
24896
24896
  }
24897
24897
 
24898
- // ../../packages/fleet-infra/dist/chunk-EXVG4MVC.js
24898
+ // ../../packages/fleet-infra/dist/chunk-2AS5XT5Z.js
24899
24899
  import * as path7 from "path";
24900
24900
  var GLOBAL_OPTIONS_VERSION = 1;
24901
24901
  var GLOBAL_OPTIONS_FILE_NAME = "settings.json";
24902
24902
  var LOCK_DIR_NAME = "settings.json.lock";
24903
24903
  var LOCK_OWNER_FILE_NAME = "owner";
24904
24904
  var TEMP_FILE_PREFIX = `.tmp-${GLOBAL_OPTIONS_FILE_NAME}-`;
24905
+ var MIN_CONSOLE_STATIC_PORT = 1024;
24906
+ var MAX_CONSOLE_STATIC_PORT = 65535;
24905
24907
  function createGlobalOptionsStore(deps = {}) {
24906
24908
  const dataDir = deps.dataDir ?? getFleetDataDir();
24907
24909
  const optionsPath = path7.join(dataDir, GLOBAL_OPTIONS_FILE_NAME);
@@ -24939,15 +24941,20 @@ function sanitizeGlobalOptionsData(value) {
24939
24941
  const data = {
24940
24942
  version: GLOBAL_OPTIONS_VERSION,
24941
24943
  ...typeof value.replaceSystemPrompt === "boolean" ? { replaceSystemPrompt: value.replaceSystemPrompt } : {},
24942
- ...typeof value.enableMetaphor === "boolean" ? { enableMetaphor: value.enableMetaphor } : {}
24944
+ ...typeof value.enableMetaphor === "boolean" ? { enableMetaphor: value.enableMetaphor } : {},
24945
+ ...value.consolePortMode === "dynamic" || value.consolePortMode === "static" ? { consolePortMode: value.consolePortMode } : {},
24946
+ ...isValidConsoleStaticPort(value.consoleStaticPort) ? { consoleStaticPort: value.consoleStaticPort } : {}
24943
24947
  };
24944
- const allowedKeys = /* @__PURE__ */ new Set(["version", "replaceSystemPrompt", "enableMetaphor"]);
24945
- const changed = Object.keys(value).some((key) => !allowedKeys.has(key)) || "replaceSystemPrompt" in value && typeof value.replaceSystemPrompt !== "boolean" || "enableMetaphor" in value && typeof value.enableMetaphor !== "boolean";
24948
+ const allowedKeys = /* @__PURE__ */ new Set(["version", "replaceSystemPrompt", "enableMetaphor", "consolePortMode", "consoleStaticPort"]);
24949
+ const changed = Object.keys(value).some((key) => !allowedKeys.has(key)) || "replaceSystemPrompt" in value && typeof value.replaceSystemPrompt !== "boolean" || "enableMetaphor" in value && typeof value.enableMetaphor !== "boolean" || "consolePortMode" in value && value.consolePortMode !== "dynamic" && value.consolePortMode !== "static" || "consoleStaticPort" in value && !isValidConsoleStaticPort(value.consoleStaticPort);
24946
24950
  return { data, changed };
24947
24951
  }
24948
24952
  function isRecord(value) {
24949
24953
  return typeof value === "object" && value !== null && !Array.isArray(value);
24950
24954
  }
24955
+ function isValidConsoleStaticPort(value) {
24956
+ return typeof value === "number" && Number.isInteger(value) && value >= MIN_CONSOLE_STATIC_PORT && value <= MAX_CONSOLE_STATIC_PORT;
24957
+ }
24951
24958
  function createGlobalOptionsService(deps = {}) {
24952
24959
  const store3 = deps.store ?? createGlobalOptionsStore({ dataDir: deps.dataDir });
24953
24960
  return {
@@ -61320,6 +61327,8 @@ var GLOBAL_OPTIONS_FILE_NAME2 = "settings.json";
61320
61327
  var LOCK_DIR_NAME2 = "settings.json.lock";
61321
61328
  var LOCK_OWNER_FILE_NAME2 = "owner";
61322
61329
  var TEMP_FILE_PREFIX2 = `.tmp-${GLOBAL_OPTIONS_FILE_NAME2}-`;
61330
+ var MIN_CONSOLE_STATIC_PORT2 = 1024;
61331
+ var MAX_CONSOLE_STATIC_PORT2 = 65535;
61323
61332
  function createGlobalOptionsStore2(deps = {}) {
61324
61333
  const dataDir = deps.dataDir ?? getFleetDataDir2();
61325
61334
  const optionsPath = path92.join(dataDir, GLOBAL_OPTIONS_FILE_NAME2);
@@ -61357,15 +61366,20 @@ function sanitizeGlobalOptionsData2(value) {
61357
61366
  const data = {
61358
61367
  version: GLOBAL_OPTIONS_VERSION2,
61359
61368
  ...typeof value.replaceSystemPrompt === "boolean" ? { replaceSystemPrompt: value.replaceSystemPrompt } : {},
61360
- ...typeof value.enableMetaphor === "boolean" ? { enableMetaphor: value.enableMetaphor } : {}
61369
+ ...typeof value.enableMetaphor === "boolean" ? { enableMetaphor: value.enableMetaphor } : {},
61370
+ ...value.consolePortMode === "dynamic" || value.consolePortMode === "static" ? { consolePortMode: value.consolePortMode } : {},
61371
+ ...isValidConsoleStaticPort2(value.consoleStaticPort) ? { consoleStaticPort: value.consoleStaticPort } : {}
61361
61372
  };
61362
- const allowedKeys = /* @__PURE__ */ new Set(["version", "replaceSystemPrompt", "enableMetaphor"]);
61363
- const changed = Object.keys(value).some((key) => !allowedKeys.has(key)) || "replaceSystemPrompt" in value && typeof value.replaceSystemPrompt !== "boolean" || "enableMetaphor" in value && typeof value.enableMetaphor !== "boolean";
61373
+ const allowedKeys = /* @__PURE__ */ new Set(["version", "replaceSystemPrompt", "enableMetaphor", "consolePortMode", "consoleStaticPort"]);
61374
+ const changed = Object.keys(value).some((key) => !allowedKeys.has(key)) || "replaceSystemPrompt" in value && typeof value.replaceSystemPrompt !== "boolean" || "enableMetaphor" in value && typeof value.enableMetaphor !== "boolean" || "consolePortMode" in value && value.consolePortMode !== "dynamic" && value.consolePortMode !== "static" || "consoleStaticPort" in value && !isValidConsoleStaticPort2(value.consoleStaticPort);
61364
61375
  return { data, changed };
61365
61376
  }
61366
61377
  function isRecord3(value) {
61367
61378
  return typeof value === "object" && value !== null && !Array.isArray(value);
61368
61379
  }
61380
+ function isValidConsoleStaticPort2(value) {
61381
+ return typeof value === "number" && Number.isInteger(value) && value >= MIN_CONSOLE_STATIC_PORT2 && value <= MAX_CONSOLE_STATIC_PORT2;
61382
+ }
61369
61383
  function createGlobalOptionsService2(deps = {}) {
61370
61384
  const store22 = deps.store ?? createGlobalOptionsStore2({ dataDir: deps.dataDir });
61371
61385
  return {
@@ -79864,6 +79878,8 @@ function requireCarrierConfig(registry32, carrierId) {
79864
79878
  if (!config22) throw new Error(`Carrier not found: ${carrierId}`);
79865
79879
  return config22;
79866
79880
  }
79881
+ var MIN_CONSOLE_STATIC_PORT22 = 1024;
79882
+ var MAX_CONSOLE_STATIC_PORT22 = 65535;
79867
79883
  var GLOBAL_SETTINGS_API_CATALOG = [
79868
79884
  {
79869
79885
  method: "GET",
@@ -79927,10 +79943,20 @@ async function mutateGlobalSettings(req, res, deps) {
79927
79943
  deps.writeJson(res, 400, { error: "invalid_enable_metaphor" });
79928
79944
  return;
79929
79945
  }
79946
+ if (body.consolePortMode !== void 0 && body.consolePortMode !== "dynamic" && body.consolePortMode !== "static") {
79947
+ deps.writeJson(res, 400, { error: "invalid_console_port_mode" });
79948
+ return;
79949
+ }
79950
+ if (body.consoleStaticPort !== void 0 && body.consoleStaticPort !== null && !isValidConsoleStaticPort22(body.consoleStaticPort)) {
79951
+ deps.writeJson(res, 400, { error: "invalid_console_static_port" });
79952
+ return;
79953
+ }
79930
79954
  const updated = deps.globalOptionsService.update((current) => ({
79931
79955
  ...current,
79932
79956
  ...typeof body.replaceSystemPrompt === "boolean" ? { replaceSystemPrompt: body.replaceSystemPrompt } : {},
79933
- ...typeof body.enableMetaphor === "boolean" ? { enableMetaphor: body.enableMetaphor } : {}
79957
+ ...typeof body.enableMetaphor === "boolean" ? { enableMetaphor: body.enableMetaphor } : {},
79958
+ ...body.consolePortMode === "dynamic" || body.consolePortMode === "static" ? { consolePortMode: body.consolePortMode } : {},
79959
+ ...isValidConsoleStaticPort22(body.consoleStaticPort) ? { consoleStaticPort: body.consoleStaticPort } : {}
79934
79960
  }));
79935
79961
  const response = { state: toGlobalSettingsState(updated) };
79936
79962
  deps.writeJson(res, 200, response);
@@ -79938,13 +79964,18 @@ async function mutateGlobalSettings(req, res, deps) {
79938
79964
  function toGlobalSettingsState(data) {
79939
79965
  return {
79940
79966
  replaceSystemPrompt: data.replaceSystemPrompt ?? false,
79941
- enableMetaphor: data.enableMetaphor ?? false
79967
+ enableMetaphor: data.enableMetaphor ?? false,
79968
+ consolePortMode: data.consolePortMode ?? "dynamic",
79969
+ consoleStaticPort: data.consoleStaticPort ?? null
79942
79970
  };
79943
79971
  }
79944
79972
  function isJsonRequest2(req) {
79945
79973
  const contentType = req.headers["content-type"];
79946
79974
  return typeof contentType === "string" && contentType.toLowerCase().split(";")[0]?.trim() === "application/json";
79947
79975
  }
79976
+ function isValidConsoleStaticPort22(value) {
79977
+ return typeof value === "number" && Number.isInteger(value) && value >= MIN_CONSOLE_STATIC_PORT22 && value <= MAX_CONSOLE_STATIC_PORT22;
79978
+ }
79948
79979
  var MODEL_AUTH_PROVIDERS = [
79949
79980
  { cli: "claude-kimi", displayName: "Moonshot Kimi" },
79950
79981
  { cli: "claude-glm", displayName: "ZhipuAI GLM" }
@@ -83702,6 +83733,8 @@ function createConsoleUpdateCheckService(deps = {}) {
83702
83733
  }
83703
83734
  var DEFAULT_HOST22 = "127.0.0.1";
83704
83735
  var DEFAULT_PORT22 = 0;
83736
+ var MIN_CONSOLE_STATIC_PORT3 = 1024;
83737
+ var MAX_CONSOLE_STATIC_PORT3 = 65535;
83705
83738
  var SHELL_TERMINAL_SESSION_ID = "shell";
83706
83739
  var THEATER_SHELL_SESSION_PREFIX2 = "shell:";
83707
83740
  var SERVER_TIMEOUT_MS = 30 * 60 * 1e3;
@@ -83872,7 +83905,7 @@ var SERVER_API_CATALOG = [
83872
83905
  ];
83873
83906
  function createConsoleServer(deps = {}) {
83874
83907
  const host = deps.host ?? DEFAULT_HOST22;
83875
- const port = deps.port ?? DEFAULT_PORT22;
83908
+ const injectedPort = deps.port ?? DEFAULT_PORT22;
83876
83909
  const release2 = deps.release ?? readFleetConsoleRelease();
83877
83910
  const version22 = deps.version ?? release2.version;
83878
83911
  const channel = release2.channel;
@@ -83912,7 +83945,7 @@ function createConsoleServer(deps = {}) {
83912
83945
  cwd: deps.codexCwd ?? process.cwd(),
83913
83946
  host,
83914
83947
  version: version22,
83915
- getPort: () => lockHandle?.payload.port ?? port,
83948
+ getPort: () => lockHandle?.payload.port ?? portState.effectivePort,
83916
83949
  getAdminToken: () => lockHandle?.payload.token ?? null
83917
83950
  });
83918
83951
  const pendingRuntimeSessions = /* @__PURE__ */ new Map();
@@ -83960,7 +83993,7 @@ function createConsoleServer(deps = {}) {
83960
83993
  });
83961
83994
  const terminalUpgrade = createTerminalUpgradeHandler({
83962
83995
  expectedHost: host,
83963
- getExpectedPort: () => lockHandle?.payload.port ?? port,
83996
+ getExpectedPort: () => lockHandle?.payload.port ?? portState.effectivePort,
83964
83997
  tickets: terminalTickets,
83965
83998
  sessions: terminalSessions,
83966
83999
  validateHost
@@ -83970,6 +84003,12 @@ function createConsoleServer(deps = {}) {
83970
84003
  let lockHandle = null;
83971
84004
  let activeLockFile = null;
83972
84005
  let activeEndpoint = null;
84006
+ let portState = {
84007
+ requestedPort: null,
84008
+ effectivePort: injectedPort,
84009
+ portMode: "dynamic",
84010
+ portHonored: true
84011
+ };
83973
84012
  let agentRuntimeStopped = false;
83974
84013
  let consoleResourcesDisposed = false;
83975
84014
  let updateApplyInFlight = false;
@@ -84003,7 +84042,7 @@ function createConsoleServer(deps = {}) {
84003
84042
  runAsyncBooleanHandler(codex.handle(req, res), res, () => tryServeStaticConsole(req, res, pathname));
84004
84043
  return;
84005
84044
  }
84006
- if (!validateHost(req, lockHandle?.payload.port ?? port)) {
84045
+ if (!validateHost(req, lockHandle?.payload.port ?? portState.effectivePort)) {
84007
84046
  writeJson(res, 403, { error: "host_mismatch" });
84008
84047
  return;
84009
84048
  }
@@ -84130,7 +84169,11 @@ function createConsoleServer(deps = {}) {
84130
84169
  endpoint: payload.endpoint,
84131
84170
  startedAt: payload.startedAt,
84132
84171
  version: payload.version,
84133
- workspaceCount: observability.workspaceCount()
84172
+ workspaceCount: observability.workspaceCount(),
84173
+ portMode: portState.portMode,
84174
+ requestedPort: portState.requestedPort,
84175
+ effectivePort: portState.effectivePort,
84176
+ portHonored: portState.portHonored
84134
84177
  };
84135
84178
  writeJson(res, 200, body);
84136
84179
  }
@@ -84533,7 +84576,11 @@ function createConsoleServer(deps = {}) {
84533
84576
  version: version22,
84534
84577
  channel,
84535
84578
  ...updateCheck.getStatus(),
84536
- port: lockHandle?.payload.port ?? port,
84579
+ port: lockHandle?.payload.port ?? portState.effectivePort,
84580
+ portMode: portState.portMode,
84581
+ requestedPort: portState.requestedPort,
84582
+ effectivePort: portState.effectivePort,
84583
+ portHonored: portState.portHonored,
84537
84584
  wikiServerStatus: resolveWikiServerStatus(theaterId)
84538
84585
  };
84539
84586
  writeJson(res, 200, payload);
@@ -84656,11 +84703,11 @@ function createConsoleServer(deps = {}) {
84656
84703
  }
84657
84704
  function isTerminalAuthorized(req) {
84658
84705
  if (!lockHandle) return false;
84659
- return isAllowedTerminalOrigin(req, lockHandle.payload.port ?? port);
84706
+ return isAllowedTerminalOrigin(req, lockHandle.payload.port ?? portState.effectivePort);
84660
84707
  }
84661
84708
  function isExactConsoleOrigin(req) {
84662
84709
  if (!lockHandle) return false;
84663
- return req.headers.origin === `http://127.0.0.1:${lockHandle.payload.port ?? port}`;
84710
+ return req.headers.origin === `http://127.0.0.1:${lockHandle.payload.port ?? portState.effectivePort}`;
84664
84711
  }
84665
84712
  function listVisibleWorkspaces(requestedTenantId) {
84666
84713
  if (requestedTenantId) {
@@ -84834,36 +84881,19 @@ function createConsoleServer(deps = {}) {
84834
84881
  }
84835
84882
  const returnedServer = {
84836
84883
  host,
84837
- port,
84884
+ port: injectedPort,
84838
84885
  async start(lockPaths) {
84839
84886
  if (server && lockHandle) return lockHandle.payload.endpoint;
84840
84887
  try {
84841
84888
  await rehydrateDurableState();
84842
- await new Promise((resolve2, reject) => {
84843
- const srv = createHttpServer(handleRequest, terminalUpgrade);
84844
- srv.once("error", reject);
84845
- srv.listen(port, host, async () => {
84846
- srv.off("error", reject);
84847
- const address = srv.address();
84848
- const actualPort = typeof address === "object" && address ? address.port : port;
84849
- const endpoint = `http://${host}:${actualPort}/`;
84850
- try {
84851
- const localLoopbackServer = await maybeStartLoopbackServer(host, actualPort, handleRequest, terminalUpgrade);
84852
- server = srv;
84853
- loopbackServer = localLoopbackServer;
84854
- lockHandle = lock.writeLock({ dir: lockPaths.dir, lockFile: lockPaths.lockFile, pid: process.pid, port: actualPort, endpoint, version: version22 });
84855
- activeLockFile = lockPaths.lockFile;
84856
- activeEndpoint = endpoint;
84857
- resolve2();
84858
- } catch (err) {
84859
- await closeHttpServer(srv);
84860
- await closeHttpServer(loopbackServer);
84861
- server = null;
84862
- loopbackServer = null;
84863
- reject(err);
84864
- }
84865
- });
84866
- });
84889
+ const listenPlan = resolveConsolePortListenPlan();
84890
+ const result = await listenConsolePort(listenPlan);
84891
+ server = result.srv;
84892
+ loopbackServer = result.localLoopbackServer;
84893
+ portState = result.portState;
84894
+ lockHandle = lock.writeLock({ dir: lockPaths.dir, lockFile: lockPaths.lockFile, pid: process.pid, port: result.actualPort, endpoint: result.endpoint, version: version22 });
84895
+ activeLockFile = lockPaths.lockFile;
84896
+ activeEndpoint = result.endpoint;
84867
84897
  } catch (error512) {
84868
84898
  await cleanupAfterFailedStart();
84869
84899
  throw error512;
@@ -84876,6 +84906,78 @@ function createConsoleServer(deps = {}) {
84876
84906
  await stopServer();
84877
84907
  }
84878
84908
  };
84909
+ function resolveConsolePortListenPlan() {
84910
+ if (deps.port !== void 0) {
84911
+ return {
84912
+ port: injectedPort,
84913
+ requestedPort: null,
84914
+ portMode: "dynamic",
84915
+ allowFallback: false
84916
+ };
84917
+ }
84918
+ const options2 = infraServices.globalOptionsService.load();
84919
+ if (options2.consolePortMode === "static" && isValidConsoleStaticPort3(options2.consoleStaticPort)) {
84920
+ return {
84921
+ port: options2.consoleStaticPort,
84922
+ requestedPort: options2.consoleStaticPort,
84923
+ portMode: "static",
84924
+ allowFallback: true
84925
+ };
84926
+ }
84927
+ return {
84928
+ port: DEFAULT_PORT22,
84929
+ requestedPort: null,
84930
+ portMode: "dynamic",
84931
+ allowFallback: false
84932
+ };
84933
+ }
84934
+ async function listenConsolePort(plan) {
84935
+ try {
84936
+ return await listenOnce(plan.port, {
84937
+ requestedPort: plan.requestedPort,
84938
+ portMode: plan.portMode,
84939
+ portHonored: true
84940
+ });
84941
+ } catch (error512) {
84942
+ if (!plan.allowFallback || plan.requestedPort === null) throw error512;
84943
+ return listenOnce(DEFAULT_PORT22, {
84944
+ requestedPort: plan.requestedPort,
84945
+ portMode: "static",
84946
+ portHonored: false
84947
+ });
84948
+ }
84949
+ }
84950
+ function listenOnce(portToBind, statePatch) {
84951
+ return new Promise((resolve2, reject) => {
84952
+ const srv = createHttpServer(handleRequest, terminalUpgrade);
84953
+ const onError = (error512) => {
84954
+ reject(error512);
84955
+ };
84956
+ srv.once("error", onError);
84957
+ srv.listen(portToBind, host, async () => {
84958
+ srv.off("error", onError);
84959
+ const address = srv.address();
84960
+ const actualPort = typeof address === "object" && address ? address.port : portToBind;
84961
+ const endpoint = `http://${host}:${actualPort}/`;
84962
+ try {
84963
+ const localLoopbackServer = await maybeStartLoopbackServer(host, actualPort, handleRequest, terminalUpgrade);
84964
+ resolve2({
84965
+ srv,
84966
+ localLoopbackServer,
84967
+ actualPort,
84968
+ endpoint,
84969
+ portState: {
84970
+ ...statePatch,
84971
+ effectivePort: actualPort
84972
+ }
84973
+ });
84974
+ } catch (err) {
84975
+ await closeHttpServer(srv);
84976
+ reject(err);
84977
+ }
84978
+ });
84979
+ });
84980
+ }
84879
84981
  return returnedServer;
84880
84982
  }
84881
84983
  function resolveCarrierEventOrigin(event, jobOriginById) {
@@ -85028,6 +85130,9 @@ function validateHost(req, expectedPort) {
85028
85130
  if (!hostHeader) return false;
85029
85131
  return hostHeader === `127.0.0.1:${expectedPort}`;
85030
85132
  }
85133
+ function isValidConsoleStaticPort3(value) {
85134
+ return typeof value === "number" && Number.isInteger(value) && value >= MIN_CONSOLE_STATIC_PORT3 && value <= MAX_CONSOLE_STATIC_PORT3;
85135
+ }
85031
85136
  function isAllowedTerminalOrigin(req, expectedPort) {
85032
85137
  const origin = req.headers.origin;
85033
85138
  if (origin === void 0) return true;