@adhdev/daemon-core 0.7.40 → 0.7.41

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.
@@ -46,6 +46,7 @@ export interface HostedCliRuntimeDescriptor {
46
46
  cliType: string;
47
47
  workspace: string;
48
48
  cliArgs?: string[];
49
+ launchMode?: string;
49
50
  }
50
51
  export declare class DaemonCliManager {
51
52
  readonly adapters: Map<string, CliAdapter>;
@@ -58,7 +59,7 @@ export declare class DaemonCliManager {
58
59
  private createAdapter;
59
60
  private startCliExitMonitor;
60
61
  private registerCliInstance;
61
- startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string): Promise<void>;
62
+ startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string, launchMode?: string, launchOptionValues?: Record<string, string | boolean | number>): Promise<void>;
62
63
  stopSession(key: string): Promise<void>;
63
64
  stopSessionWithMode(key: string, mode: 'hard' | 'save'): Promise<void>;
64
65
  shutdownAll(): void;
package/dist/index.js CHANGED
@@ -5068,6 +5068,8 @@ function buildCliSession(state) {
5068
5068
  runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
5069
5069
  runtimeWriteOwner: state.runtime?.writeOwner || null,
5070
5070
  runtimeAttachedClients: state.runtime?.attachedClients || [],
5071
+ launchMode: state.launchMode,
5072
+ mode: state.mode,
5071
5073
  resume: state.resume,
5072
5074
  activeChat,
5073
5075
  capabilities: PTY_SESSION_CAPABILITIES,
@@ -9145,12 +9147,14 @@ var crypto3 = __toESM(require("crypto"));
9145
9147
  init_provider_cli_adapter();
9146
9148
  init_logger();
9147
9149
  var CliProviderInstance = class {
9148
- constructor(provider, workingDir, cliArgs = [], instanceId, transportFactory) {
9150
+ constructor(provider, workingDir, cliArgs = [], instanceId, transportFactory, launchModeId) {
9149
9151
  this.provider = provider;
9150
9152
  this.workingDir = workingDir;
9151
9153
  this.cliArgs = cliArgs;
9152
9154
  this.type = provider.type;
9153
9155
  this.instanceId = instanceId || crypto3.randomUUID();
9156
+ this.launchMode = launchModeId && provider.launchModes?.find((m) => m.id === launchModeId) || null;
9157
+ this.resolvedOutputFormat = this.resolveOutputFormat();
9154
9158
  this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
9155
9159
  this.monitor = new StatusMonitor();
9156
9160
  this.historyWriter = new ChatHistoryWriter();
@@ -9169,6 +9173,26 @@ var CliProviderInstance = class {
9169
9173
  lastApprovalEventAt = 0;
9170
9174
  historyWriter;
9171
9175
  instanceId;
9176
+ launchMode;
9177
+ resolvedOutputFormat;
9178
+ /**
9179
+ * Determine output rendering format from:
9180
+ * 1. launchMode.outputFormat (explicit override)
9181
+ * 2. launchOptions[].outputFormatMap — check actual args for matching values
9182
+ * 3. Default: 'terminal'
9183
+ */
9184
+ resolveOutputFormat() {
9185
+ if (this.launchMode?.outputFormat) return this.launchMode.outputFormat;
9186
+ if (this.provider.launchOptions?.length) {
9187
+ for (const opt of this.provider.launchOptions) {
9188
+ if (!opt.outputFormatMap) continue;
9189
+ for (const [val, fmt] of Object.entries(opt.outputFormatMap)) {
9190
+ if (this.cliArgs.includes(val)) return fmt;
9191
+ }
9192
+ }
9193
+ }
9194
+ return "terminal";
9195
+ }
9172
9196
  // ─── Lifecycle ─────────────────────────────────
9173
9197
  async init(context) {
9174
9198
  this.context = context;
@@ -9208,7 +9232,8 @@ var CliProviderInstance = class {
9208
9232
  name: this.provider.name,
9209
9233
  category: "cli",
9210
9234
  status: adapterStatus.status,
9211
- mode: "terminal",
9235
+ mode: this.resolvedOutputFormat === "stream-json" ? "chat" : "terminal",
9236
+ launchMode: this.launchMode?.id,
9212
9237
  activeChat: {
9213
9238
  id: `${this.type}_${this.workingDir}`,
9214
9239
  title: `${this.provider.name} \xB7 ${dirName}`,
@@ -10350,12 +10375,12 @@ var DaemonCliManager = class {
10350
10375
  }
10351
10376
  }, 3e3);
10352
10377
  }
10353
- async registerCliInstance(key, normalizedType, cliType, resolvedDir, cliArgs, provider, settings, attachExisting = false) {
10378
+ async registerCliInstance(key, normalizedType, cliType, resolvedDir, cliArgs, provider, settings, attachExisting = false, launchModeId) {
10354
10379
  const instanceManager = this.deps.getInstanceManager();
10355
10380
  const sessionRegistry = this.deps.getSessionRegistry?.() || null;
10356
10381
  if (!instanceManager) throw new Error("InstanceManager not available");
10357
10382
  const transportFactory = this.getTransportFactory(key, normalizedType, resolvedDir, cliArgs, attachExisting);
10358
- const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key, transportFactory);
10383
+ const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key, transportFactory, launchModeId);
10359
10384
  try {
10360
10385
  await instanceManager.addInstance(key, cliInstance, {
10361
10386
  serverConn: this.deps.getServerConn(),
@@ -10381,7 +10406,7 @@ var DaemonCliManager = class {
10381
10406
  this.startCliExitMonitor(key, cliType);
10382
10407
  }
10383
10408
  // ─── Session start/management ──────────────────────────────
10384
- async startSession(cliType, workingDir, cliArgs, initialModel) {
10409
+ async startSession(cliType, workingDir, cliArgs, initialModel, launchMode, launchOptionValues) {
10385
10410
  const trimmed = (workingDir || "").trim();
10386
10411
  if (!trimmed) throw new Error("working directory required");
10387
10412
  const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path10.resolve(trimmed);
@@ -10473,6 +10498,29 @@ ${installInfo}`
10473
10498
  if (provider) {
10474
10499
  console.log(colorize("cyan", ` \u{1F4E6} Using provider: ${provider.name} (${provider.type})`));
10475
10500
  }
10501
+ let resolvedCliArgs = cliArgs;
10502
+ let resolvedLaunchMode = launchMode;
10503
+ const activeMode = provider?.launchModes?.length ? launchMode ? provider.launchModes.find((m) => m.id === launchMode) : provider.launchModes.find((m) => m.default) : void 0;
10504
+ if (activeMode) {
10505
+ resolvedLaunchMode = activeMode.id;
10506
+ }
10507
+ if (provider?.launchArgBuilder) {
10508
+ const defaults = {};
10509
+ for (const opt of provider.launchOptions || []) {
10510
+ if (opt.default !== void 0) defaults[opt.id] = opt.default;
10511
+ }
10512
+ const modeOptions = activeMode?.options || {};
10513
+ const userOptions = launchOptionValues || {};
10514
+ const merged = { ...defaults, ...modeOptions, ...userOptions };
10515
+ const extraArgs = provider.launchArgBuilder(merged);
10516
+ if (extraArgs.length) {
10517
+ resolvedCliArgs = [...cliArgs || [], ...extraArgs];
10518
+ console.log(colorize("cyan", ` \u{1F680} Launch options applied: ${extraArgs.join(" ")}`));
10519
+ }
10520
+ } else if (activeMode?.extraArgs?.length) {
10521
+ resolvedCliArgs = [...cliArgs || [], ...activeMode.extraArgs];
10522
+ console.log(colorize("cyan", ` \u{1F680} Launch mode '${activeMode.name}': appending args ${activeMode.extraArgs.join(" ")}`));
10523
+ }
10476
10524
  const instanceManager = this.deps.getInstanceManager();
10477
10525
  if (provider && instanceManager) {
10478
10526
  const resolvedProvider = this.providerLoader.resolve(cliType, { version: cliInfo.version }) || provider;
@@ -10481,14 +10529,15 @@ ${installInfo}`
10481
10529
  normalizedType,
10482
10530
  cliType,
10483
10531
  resolvedDir,
10484
- cliArgs,
10532
+ resolvedCliArgs,
10485
10533
  resolvedProvider,
10486
10534
  {},
10487
- false
10535
+ false,
10536
+ resolvedLaunchMode
10488
10537
  );
10489
10538
  console.log(colorize("green", ` \u2713 CLI started: ${cliInfo.displayName} v${cliInfo.version || "unknown"} in ${resolvedDir}`));
10490
10539
  } else {
10491
- const adapter = this.createAdapter(cliType, resolvedDir, cliArgs, key, false);
10540
+ const adapter = this.createAdapter(cliType, resolvedDir, resolvedCliArgs, key, false);
10492
10541
  try {
10493
10542
  await adapter.spawn();
10494
10543
  } catch (spawnErr) {
@@ -10596,7 +10645,8 @@ ${installInfo}`
10596
10645
  record.cliArgs,
10597
10646
  resolvedProvider,
10598
10647
  {},
10599
- true
10648
+ true,
10649
+ record.launchMode
10600
10650
  );
10601
10651
  restored += 1;
10602
10652
  LOG.info("CLI", `\u267B Restored hosted runtime: ${record.runtimeKey || record.runtimeId} (${record.displayName || record.workspace})`);
@@ -10666,7 +10716,7 @@ ${installInfo}`
10666
10716
  const dir = resolved.path;
10667
10717
  const launchSource = resolved.source;
10668
10718
  if (!cliType) throw new Error("cliType required");
10669
- await this.startSession(cliType, dir, args?.cliArgs, args?.initialModel);
10719
+ await this.startSession(cliType, dir, args?.cliArgs, args?.initialModel, args?.launchMode, args?.launchOptionValues);
10670
10720
  let newKey = null;
10671
10721
  for (const [k, adapter] of this.adapters) {
10672
10722
  if (adapter.cliType === cliType && adapter.workingDir === dir) {