@parall/daemon 1.29.2 → 1.30.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.
@@ -428,9 +428,13 @@ function createLogger(prefix) {
428
428
  return {
429
429
  info: (msg) => console.log(`${(/* @__PURE__ */ new Date()).toISOString()} [${prefix}] ${msg}`),
430
430
  warn: (msg) => console.warn(`${(/* @__PURE__ */ new Date()).toISOString()} [${prefix}] ${msg}`),
431
- error: (msg) => console.error(`${(/* @__PURE__ */ new Date()).toISOString()} [${prefix}] ${msg}`)
431
+ error: (msg) => console.error(`${(/* @__PURE__ */ new Date()).toISOString()} [${prefix}] ${msg}`),
432
+ child: (sub) => createLogger(`${prefix}:${sub}`)
432
433
  };
433
434
  }
435
+ function childLogger(logger, sub) {
436
+ return logger.child ? logger.child(sub) : logger;
437
+ }
434
438
 
435
439
  // ts/agent-core/dist/gateway-base.js
436
440
  import * as os from "node:os";
@@ -513,6 +517,7 @@ var ENDPOINTS = {
513
517
  AGENT_ACTIVITY: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/activity`,
514
518
  AGENT_MONITOR: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/monitor`,
515
519
  AGENT_ME: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me`,
520
+ AGENT_NEW_SESSION: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/new-session`,
516
521
  AGENT_SESSIONS: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/sessions`,
517
522
  AGENT_SESSION: (orgId, agentId, sessionId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/sessions/${sessionId}`,
518
523
  AGENT_SESSION_STEPS: (orgId, agentId, sessionId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/sessions/${sessionId}/steps`,
@@ -551,6 +556,7 @@ var ENDPOINTS = {
551
556
  MACHINE_KEY: (orgId, machineId, keyId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/keys/${keyId}`,
552
557
  MACHINE_RUNTIME_AUTH_SESSIONS: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/runtime-auth-sessions`,
553
558
  MACHINE_RUNTIME_AUTH_SESSION_COMPLETE: (orgId, machineId, sessionId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/runtime-auth-sessions/${sessionId}/complete`,
559
+ MACHINE_BROWSE: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/browse`,
554
560
  // Machine self-control-plane (mck_-scoped). The bearer token implicitly
555
561
  // identifies the Machine, so there is no `:mid` URL parameter — these are
556
562
  // "self" routes called by the daemon for its own host.
@@ -560,6 +566,7 @@ var ENDPOINTS = {
560
566
  MACHINES_ME_AGENT_LAUNCH_CREDENTIAL: (agentId) => `${API_BASE}/machines/me/agents/${agentId}/launch-credential`,
561
567
  MACHINES_ME_AGENT_WORKSPACE_STATE: (agentId) => `${API_BASE}/machines/me/agents/${agentId}/workspace-state`,
562
568
  MACHINES_ME_WS_TICKET: `${API_BASE}/machines/me/ws/ticket`,
569
+ MACHINES_ME_BROWSE_RESPONSE: (requestId) => `${API_BASE}/machines/me/browse-response/${requestId}`,
563
570
  // Tasks (org-scoped)
564
571
  TASKS: (orgId) => `${API_BASE}/orgs/${orgId}/tasks`,
565
572
  TASK: (orgId, taskId) => `${API_BASE}/orgs/${orgId}/tasks/${taskId}`,
@@ -739,7 +746,9 @@ var WS_EVENTS = {
739
746
  MACHINE_AGENT_ATTACHED: "machine.agent.attached",
740
747
  MACHINE_AGENT_DETACHED: "machine.agent.detached",
741
748
  MACHINE_STOP: "machine.stop",
742
- MACHINE_WORKSPACE_SETUP_REQUESTED: "machine.workspace.setup.requested"
749
+ MACHINE_WORKSPACE_SETUP_REQUESTED: "machine.workspace.setup.requested",
750
+ MACHINE_FILESYSTEM_BROWSE: "machine.filesystem.browse",
751
+ AGENT_NEW_SESSION: "agent.new_session"
743
752
  };
744
753
 
745
754
  // ts/sdk/dist/client.js
@@ -1285,6 +1294,9 @@ var ParallClient = class _ParallClient {
1285
1294
  return this.request("GET", ENDPOINTS.AGENT_ME(orgId));
1286
1295
  }
1287
1296
  // ---- Agent Sessions (org-scoped) ----
1297
+ async requestNewAgentSession(orgId, agentId) {
1298
+ return this.request("POST", ENDPOINTS.AGENT_NEW_SESSION(orgId, agentId));
1299
+ }
1288
1300
  async createAgentSession(orgId, agentId, req) {
1289
1301
  return this.request("POST", ENDPOINTS.AGENT_SESSIONS(orgId, agentId), req);
1290
1302
  }
@@ -1484,9 +1496,15 @@ var ParallClient = class _ParallClient {
1484
1496
  async getMachineWsTicket() {
1485
1497
  return this.request("POST", ENDPOINTS.MACHINES_ME_WS_TICKET);
1486
1498
  }
1499
+ async postBrowseResponse(requestId, response) {
1500
+ return this.request("POST", ENDPOINTS.MACHINES_ME_BROWSE_RESPONSE(requestId), response);
1501
+ }
1487
1502
  async resizeMachine(orgId, machineId, spec) {
1488
1503
  return this.request("PATCH", ENDPOINTS.MACHINE_SPEC(orgId, machineId), spec);
1489
1504
  }
1505
+ async browseMachineFilesystem(orgId, machineId, path8) {
1506
+ return this.request("POST", ENDPOINTS.MACHINE_BROWSE(orgId, machineId), { path: path8 }, void 0, false, { timeoutMs: 15e3 });
1507
+ }
1490
1508
  /** Create a new machine key. Returns the raw key string (shown once) + metadata. */
1491
1509
  async createMachineKey(orgId, machineId, name) {
1492
1510
  return this.request("POST", ENDPOINTS.MACHINE_KEYS(orgId, machineId), name ? { name } : void 0);
@@ -2399,6 +2417,7 @@ var ParallAgentGateway = class {
2399
2417
  shuttingDown = false;
2400
2418
  inFlightDispatches = 0;
2401
2419
  drainResolvers = [];
2420
+ pendingRestartNotification = null;
2402
2421
  DISPATCHED_MESSAGES_CAP = 5e3;
2403
2422
  COLD_START_WINDOW_MS;
2404
2423
  // SHUTDOWN_DEADLINE_MS is read by waitForDrain via the configured value
@@ -2413,7 +2432,7 @@ var ParallAgentGateway = class {
2413
2432
  async run(abortSignal) {
2414
2433
  const { ws, log: log2 } = this.opts;
2415
2434
  ws.onStateChange((state) => {
2416
- log2?.info(`parall[${this.opts.accountId}]: connection state \u2192 ${state}`);
2435
+ log2?.info(`connection state \u2192 ${state}`);
2417
2436
  });
2418
2437
  ws.on("hello", async (data) => {
2419
2438
  await this.handleHello(data);
@@ -2442,16 +2461,29 @@ var ParallAgentGateway = class {
2442
2461
  await this.handleMessage(data);
2443
2462
  });
2444
2463
  ws.on("agent_config.update", async (data) => {
2445
- this.opts.log?.info(`parall[${this.opts.accountId}]: config update notification (version=${data.version})`);
2464
+ this.opts.log?.info(`config update notification (version=${data.version})`);
2446
2465
  try {
2447
2466
  await this.opts.onConfigUpdate?.(data);
2448
2467
  } catch (err) {
2449
- this.opts.log?.warn(`parall[${this.opts.accountId}]: config update failed: ${String(err)}`);
2468
+ this.opts.log?.warn(`config update failed: ${String(err)}`);
2469
+ }
2470
+ });
2471
+ ws.on("agent.new_session", async (data) => {
2472
+ const prevId = data.previous_session_id ?? "";
2473
+ this.opts.log?.info(`new session signal received (previous=${prevId})`);
2474
+ this.sessionBindings.clear();
2475
+ if (prevId) {
2476
+ this.pendingRestartNotification = `[Harness Notification] This is a fresh session. Your previous session (${prevId}) was ended by the user and you have been restarted.`;
2477
+ }
2478
+ try {
2479
+ await this.opts.onNewSession?.(prevId);
2480
+ } catch (err) {
2481
+ this.opts.log?.warn(`onNewSession callback failed: ${String(err)}`);
2450
2482
  }
2451
2483
  });
2452
2484
  ws.on("recovery.overflow", () => {
2453
- this.opts.log?.warn(`parall[${this.opts.accountId}]: recovery.overflow \u2014 triggering full catch-up`);
2454
- this.catchUpFromDispatch().catch((err) => this.opts.log?.warn(`parall[${this.opts.accountId}]: overflow catch-up failed: ${String(err)}`));
2485
+ this.opts.log?.warn(`recovery.overflow \u2014 triggering full catch-up`);
2486
+ this.catchUpFromDispatch().catch((err) => this.opts.log?.warn(`overflow catch-up failed: ${String(err)}`));
2455
2487
  });
2456
2488
  ws.on("task.assigned", async (data) => {
2457
2489
  if (data.assignee_id !== this.opts.agentUserId)
@@ -2465,7 +2497,7 @@ var ParallAgentGateway = class {
2465
2497
  });
2466
2498
  }
2467
2499
  } catch (err) {
2468
- this.opts.log?.error(`parall[${this.opts.accountId}]: task dispatch failed for ${data.id}: ${String(err)}`);
2500
+ this.opts.log?.error(`task dispatch failed for ${data.id}: ${String(err)}`);
2469
2501
  }
2470
2502
  });
2471
2503
  ws.on("dispatch.new", async (data) => {
@@ -2479,7 +2511,7 @@ var ParallAgentGateway = class {
2479
2511
  });
2480
2512
  }
2481
2513
  } catch (err) {
2482
- this.opts.log?.error(`parall[${this.opts.accountId}]: task comment dispatch failed for ${data.source_id}: ${String(err)}`);
2514
+ this.opts.log?.error(`task comment dispatch failed for ${data.source_id}: ${String(err)}`);
2483
2515
  }
2484
2516
  } else if (data.event_type === "task_update") {
2485
2517
  if (!data.task_id)
@@ -2491,7 +2523,7 @@ var ParallAgentGateway = class {
2491
2523
  });
2492
2524
  }
2493
2525
  } catch (err) {
2494
- this.opts.log?.error(`parall[${this.opts.accountId}]: task update dispatch failed for ${data.task_id}: ${String(err)}`);
2526
+ this.opts.log?.error(`task update dispatch failed for ${data.task_id}: ${String(err)}`);
2495
2527
  }
2496
2528
  } else if (data.event_type === "schedule.fire") {
2497
2529
  if (!data.source_id)
@@ -2503,7 +2535,7 @@ var ParallAgentGateway = class {
2503
2535
  });
2504
2536
  }
2505
2537
  } catch (err) {
2506
- this.opts.log?.error(`parall[${this.opts.accountId}]: schedule fire dispatch failed for ${data.source_id}: ${String(err)}`);
2538
+ this.opts.log?.error(`schedule fire dispatch failed for ${data.source_id}: ${String(err)}`);
2507
2539
  }
2508
2540
  } else if (data.event_type === "approval_decided") {
2509
2541
  if (!data.source_id)
@@ -2515,13 +2547,13 @@ var ParallAgentGateway = class {
2515
2547
  });
2516
2548
  }
2517
2549
  } catch (err) {
2518
- this.opts.log?.error(`parall[${this.opts.accountId}]: approval decided dispatch failed for ${data.source_id}: ${String(err)}`);
2550
+ this.opts.log?.error(`approval decided dispatch failed for ${data.source_id}: ${String(err)}`);
2519
2551
  }
2520
2552
  } else if (data.event_type !== "message" && data.event_type !== "task_assign") {
2521
- this.opts.log?.info(`parall[${this.opts.accountId}]: dispatch.new with unhandled event_type=${String(data.event_type)} (id=${data.id}) \u2014 no-op`);
2553
+ this.opts.log?.info(`dispatch.new with unhandled event_type=${String(data.event_type)} (id=${data.id}) \u2014 no-op`);
2522
2554
  }
2523
2555
  });
2524
- this.opts.log?.info(`parall[${this.opts.accountId}]: connecting to ${this.opts.connectionLabel ?? "Parall WS"}...`);
2556
+ this.opts.log?.info(`connecting to ${this.opts.connectionLabel ?? "Parall WS"}...`);
2525
2557
  await ws.connect();
2526
2558
  return new Promise((resolve4) => {
2527
2559
  abortSignal.addEventListener("abort", async () => {
@@ -2635,7 +2667,7 @@ var ParallAgentGateway = class {
2635
2667
  }
2636
2668
  });
2637
2669
  } catch (err) {
2638
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to create input step: ${String(err)}`);
2670
+ this.opts.log?.warn(`failed to create input step: ${String(err)}`);
2639
2671
  }
2640
2672
  }
2641
2673
  async createRuntimeStep(sessionId, event, runtimeEvent, stepIdFilePath, contextFilePath) {
@@ -2713,12 +2745,12 @@ var ParallAgentGateway = class {
2713
2745
  target_type: target.target_type,
2714
2746
  target_id: target.target_id,
2715
2747
  content: { text: runtimeEvent.message, suppressed: false },
2716
- projection: true
2748
+ projection: false
2717
2749
  });
2718
2750
  break;
2719
2751
  }
2720
2752
  } catch (err) {
2721
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to create ${runtimeEvent.type} step: ${String(err)}`);
2753
+ this.opts.log?.warn(`failed to create ${runtimeEvent.type} step: ${String(err)}`);
2722
2754
  }
2723
2755
  }
2724
2756
  writeContextFile(filePath, ctx) {
@@ -2726,7 +2758,7 @@ var ParallAgentGateway = class {
2726
2758
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
2727
2759
  fs.writeFileSync(filePath, JSON.stringify(ctx), "utf8");
2728
2760
  } catch (err) {
2729
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to write context file ${filePath}: ${String(err)}`);
2761
+ this.opts.log?.warn(`failed to write context file ${filePath}: ${String(err)}`);
2730
2762
  }
2731
2763
  }
2732
2764
  updateContextFileStepId(filePath, stepId) {
@@ -2736,7 +2768,7 @@ var ParallAgentGateway = class {
2736
2768
  ctx.step_id = stepId;
2737
2769
  fs.writeFileSync(filePath, JSON.stringify(ctx), "utf8");
2738
2770
  } catch (err) {
2739
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to update context file step_id ${filePath}: ${String(err)}`);
2771
+ this.opts.log?.warn(`failed to update context file step_id ${filePath}: ${String(err)}`);
2740
2772
  }
2741
2773
  }
2742
2774
  updateContextFileSessionId(filePath, sessionId) {
@@ -2746,7 +2778,7 @@ var ParallAgentGateway = class {
2746
2778
  ctx.session_id = sessionId;
2747
2779
  fs.writeFileSync(filePath, JSON.stringify(ctx), "utf8");
2748
2780
  } catch (err) {
2749
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to update context file session_id ${filePath}: ${String(err)}`);
2781
+ this.opts.log?.warn(`failed to update context file session_id ${filePath}: ${String(err)}`);
2750
2782
  }
2751
2783
  }
2752
2784
  /** @deprecated Use writeContextFile / updateContextFileStepId. */
@@ -2755,7 +2787,7 @@ var ParallAgentGateway = class {
2755
2787
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
2756
2788
  fs.writeFileSync(filePath, stepId, "utf8");
2757
2789
  } catch (err) {
2758
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to write step id file ${filePath}: ${String(err)}`);
2790
+ this.opts.log?.warn(`failed to write step id file ${filePath}: ${String(err)}`);
2759
2791
  }
2760
2792
  }
2761
2793
  /** @deprecated Use writeContextFile / updateContextFileStepId. */
@@ -2812,9 +2844,13 @@ var ParallAgentGateway = class {
2812
2844
  // catch-up on the replacement pod — otherwise we silently drop work.
2813
2845
  async runDispatch(event, sessionKey, bodyForAgent, earlierEvents = [], captureText) {
2814
2846
  if (this.shuttingDown) {
2815
- this.opts.log?.info(`parall[${this.opts.accountId}]: skipping dispatch for ${event.messageId} (shutting down) \u2014 leaving unacked for catch-up on replacement pod`);
2847
+ this.opts.log?.info(`skipping dispatch for ${event.messageId} (shutting down) \u2014 leaving unacked for catch-up on replacement pod`);
2816
2848
  return false;
2817
2849
  }
2850
+ if (this.pendingRestartNotification) {
2851
+ bodyForAgent = this.pendingRestartNotification + "\n\n---\n\n" + bodyForAgent;
2852
+ this.pendingRestartNotification = null;
2853
+ }
2818
2854
  setSessionChatId(sessionKey, event.targetId);
2819
2855
  setSessionMessageId(sessionKey, event.messageId);
2820
2856
  setDispatchMessageId(sessionKey, event.messageId);
@@ -2944,7 +2980,7 @@ var ParallAgentGateway = class {
2944
2980
  item.resolve(true);
2945
2981
  }
2946
2982
  } catch (err) {
2947
- this.opts.log?.error(`parall[${this.opts.accountId}]: fork dispatch failed for ${last.messageId}: ${String(err)}`);
2983
+ this.opts.log?.error(`fork dispatch failed for ${last.messageId}: ${String(err)}`);
2948
2984
  for (const item of items) {
2949
2985
  item.resolve(false);
2950
2986
  }
@@ -2962,7 +2998,7 @@ var ParallAgentGateway = class {
2962
2998
  try {
2963
2999
  historyPath = this.opts.dispatchAdapter.getSessionHistoryPath?.(fork.fork.sessionKey);
2964
3000
  } catch (err) {
2965
- this.opts.log?.warn?.(`parall[${this.opts.accountId}]: failed to resolve fork history path: ${String(err)}`);
3001
+ this.opts.log?.warn?.(`failed to resolve fork history path: ${String(err)}`);
2966
3002
  }
2967
3003
  this.dispatchState.pendingForkResults.push({
2968
3004
  forkSessionKey: fork.fork.sessionKey,
@@ -3013,7 +3049,7 @@ var ParallAgentGateway = class {
3013
3049
  try {
3014
3050
  while (this.dispatchState.mainBuffer.length > 0) {
3015
3051
  if (this.shuttingDown) {
3016
- this.opts.log?.info(`parall[${this.opts.accountId}]: drainMainBuffer halted (shutting down) \u2014 ${this.dispatchState.mainBuffer.length} buffered, ${this.dispatchState.pendingForkResults.length} pending fork results left for catch-up`);
3052
+ this.opts.log?.info(`drainMainBuffer halted (shutting down) \u2014 ${this.dispatchState.mainBuffer.length} buffered, ${this.dispatchState.pendingForkResults.length} pending fork results left for catch-up`);
3017
3053
  break;
3018
3054
  }
3019
3055
  const targetId = this.dispatchState.mainBuffer[0].targetId;
@@ -3079,7 +3115,7 @@ var ParallAgentGateway = class {
3079
3115
  this.dispatchState.mainBuffer.push(event);
3080
3116
  if (this.dispatchState.mainCurrentTargetId === event.targetId && await this.opts.dispatchAdapter.enqueueDuringDispatch?.(this.opts.runtimeKey, buildEventBody(event))) {
3081
3117
  this.startInjectedTyping(event);
3082
- this.opts.log?.info(`parall[${this.opts.accountId}]: steer injected for ${event.messageId} (will drain for bookkeeping)`);
3118
+ this.opts.log?.info(`steer injected for ${event.messageId} (will drain for bookkeeping)`);
3083
3119
  }
3084
3120
  if (!this.dispatchState.mainDispatching && !this.draining && this.dispatchState.mainBuffer.length > 0) {
3085
3121
  this.dispatchState.mainDispatching = true;
@@ -3108,7 +3144,7 @@ var ParallAgentGateway = class {
3108
3144
  preDispatchBranchPoint: this.dispatchState.mainPreDispatchBranchPoint
3109
3145
  });
3110
3146
  if (!fork) {
3111
- this.opts.log?.warn(`parall[${this.opts.accountId}]: fork failed, buffering event for main session`);
3147
+ this.opts.log?.warn(`fork failed, buffering event for main session`);
3112
3148
  this.dispatchState.mainBuffer.push(event);
3113
3149
  return false;
3114
3150
  }
@@ -3124,7 +3160,7 @@ var ParallAgentGateway = class {
3124
3160
  activeFork.queue.push({ event, resolve: resolve4 });
3125
3161
  });
3126
3162
  this.runForkDrainLoop(activeFork).catch((err) => {
3127
- this.opts.log?.error(`parall[${this.opts.accountId}]: fork drain loop error: ${String(err)}`);
3163
+ this.opts.log?.error(`fork drain loop error: ${String(err)}`);
3128
3164
  });
3129
3165
  return firstEventPromise;
3130
3166
  }
@@ -3144,7 +3180,7 @@ var ParallAgentGateway = class {
3144
3180
  this.chatInfoMap.set(chatId, chatInfo);
3145
3181
  return chatInfo;
3146
3182
  } catch (err) {
3147
- this.opts.log?.warn(`parall[${this.opts.accountId}]: failed to resolve chat ${chatId}: ${String(err)}`);
3183
+ this.opts.log?.warn(`failed to resolve chat ${chatId}: ${String(err)}`);
3148
3184
  return null;
3149
3185
  }
3150
3186
  }
@@ -3217,7 +3253,7 @@ var ParallAgentGateway = class {
3217
3253
  this.dispatchedMessages.delete(data.id);
3218
3254
  }
3219
3255
  } catch (err) {
3220
- this.opts.log?.error(`parall[${this.opts.accountId}]: event dispatch failed for ${data.id}: ${String(err)}`);
3256
+ this.opts.log?.error(`event dispatch failed for ${data.id}: ${String(err)}`);
3221
3257
  this.dispatchedMessages.delete(data.id);
3222
3258
  }
3223
3259
  }
@@ -3226,11 +3262,11 @@ var ParallAgentGateway = class {
3226
3262
  return false;
3227
3263
  const dedupeKey = `${task.id}:${task.updated_at}`;
3228
3264
  if (this.dispatchedTasks.has(dedupeKey)) {
3229
- this.opts.log?.info(`parall[${this.opts.accountId}]: skipping already-dispatched task ${task.identifier ?? task.id}`);
3265
+ this.opts.log?.info(`skipping already-dispatched task ${task.identifier ?? task.id}`);
3230
3266
  return false;
3231
3267
  }
3232
3268
  this.dispatchedTasks.add(dedupeKey);
3233
- this.opts.log?.info(`parall[${this.opts.accountId}]: task assigned: ${task.identifier ?? task.id} "${task.title}"`);
3269
+ this.opts.log?.info(`task assigned: ${task.identifier ?? task.id} "${task.title}"`);
3234
3270
  const parts = [`Title: ${task.title}`];
3235
3271
  parts.push(`Status: ${task.status}`, `Priority: ${task.priority}`);
3236
3272
  if (task.project_id)
@@ -3271,7 +3307,7 @@ var ParallAgentGateway = class {
3271
3307
  const isAssignee = task.assignee_id === this.opts.agentUserId;
3272
3308
  const isCreatorUpdate = opts.allowCreator === true && task.creator_id === this.opts.agentUserId;
3273
3309
  if (!isAssignee && !isCreatorUpdate) {
3274
- this.opts.log?.info(`parall[${this.opts.accountId}]: skipping stale task dispatch ${ackSourceId ?? taskId} \u2014 assigned to ${task.assignee_id}, creator ${task.creator_id}`);
3310
+ this.opts.log?.info(`skipping stale task dispatch ${ackSourceId ?? taskId} \u2014 assigned to ${task.assignee_id}, creator ${task.creator_id}`);
3275
3311
  return true;
3276
3312
  }
3277
3313
  return this.handleTaskAssignment(task, ackSourceId);
@@ -3289,7 +3325,7 @@ var ParallAgentGateway = class {
3289
3325
  } catch (err) {
3290
3326
  const status = err?.status;
3291
3327
  if (status === 404) {
3292
- this.opts.log?.info(`parall[${this.opts.accountId}]: skipping deleted comment ${commentId}, acking stale dispatch`);
3328
+ this.opts.log?.info(`skipping deleted comment ${commentId}, acking stale dispatch`);
3293
3329
  this.dispatchedTasks.delete(dedupeKey);
3294
3330
  return true;
3295
3331
  }
@@ -3301,7 +3337,7 @@ var ParallAgentGateway = class {
3301
3337
  return true;
3302
3338
  }
3303
3339
  if (comment.hints?.no_reply) {
3304
- this.opts.log?.info(`parall[${this.opts.accountId}]: skipping no_reply task comment ${commentId}, acking stale dispatch`);
3340
+ this.opts.log?.info(`skipping no_reply task comment ${commentId}, acking stale dispatch`);
3305
3341
  this.dispatchedTasks.delete(dedupeKey);
3306
3342
  return true;
3307
3343
  }
@@ -3311,7 +3347,7 @@ var ParallAgentGateway = class {
3311
3347
  } catch {
3312
3348
  }
3313
3349
  const taskLabel = task ? `${task.identifier ?? task.id} "${task.title}"` : taskId;
3314
- this.opts.log?.info(`parall[${this.opts.accountId}]: task comment on ${taskLabel} by ${actorId ?? "unknown"}`);
3350
+ this.opts.log?.info(`task comment on ${taskLabel} by ${actorId ?? "unknown"}`);
3315
3351
  const parts = [];
3316
3352
  if (task) {
3317
3353
  parts.push(`Task: ${task.title} (prll://${task.id})`);
@@ -3361,10 +3397,10 @@ var ParallAgentGateway = class {
3361
3397
  } catch (err) {
3362
3398
  const status = err?.status;
3363
3399
  if (status === 404) {
3364
- this.opts.log?.warn(`parall[${this.opts.accountId}]: schedule run ${runId} not accessible (404), acking stale dispatch`);
3400
+ this.opts.log?.warn(`schedule run ${runId} not accessible (404), acking stale dispatch`);
3365
3401
  return true;
3366
3402
  }
3367
- this.opts.log?.warn(`parall[${this.opts.accountId}]: schedule run fetch failed for ${runId}, leaving pending: ${String(err)}`);
3403
+ this.opts.log?.warn(`schedule run fetch failed for ${runId}, leaving pending: ${String(err)}`);
3368
3404
  return false;
3369
3405
  }
3370
3406
  if (!run)
@@ -3378,7 +3414,7 @@ var ParallAgentGateway = class {
3378
3414
  if (this.dispatchedTasks.has(dedupeKey))
3379
3415
  return false;
3380
3416
  this.dispatchedTasks.add(dedupeKey);
3381
- this.opts.log?.info(`parall[${this.opts.accountId}]: schedule fired: ${run.id} (schedule ${run.schedule_id})`);
3417
+ this.opts.log?.info(`schedule fired: ${run.id} (schedule ${run.schedule_id})`);
3382
3418
  const event = {
3383
3419
  type: "schedule",
3384
3420
  // Route by schedule_id (not attached chat_id) so concurrent fires of
@@ -3415,10 +3451,10 @@ var ParallAgentGateway = class {
3415
3451
  } catch (err) {
3416
3452
  const status = err?.status;
3417
3453
  if (status === 404 || status === 403) {
3418
- this.opts.log?.warn(`parall[${this.opts.accountId}]: approval ${approvalId} not accessible (${status}), acking stale dispatch`);
3454
+ this.opts.log?.warn(`approval ${approvalId} not accessible (${status}), acking stale dispatch`);
3419
3455
  return true;
3420
3456
  }
3421
- this.opts.log?.warn(`parall[${this.opts.accountId}]: approval fetch failed for ${approvalId}, leaving pending: ${String(err)}`);
3457
+ this.opts.log?.warn(`approval fetch failed for ${approvalId}, leaving pending: ${String(err)}`);
3422
3458
  return false;
3423
3459
  }
3424
3460
  if (!approval)
@@ -3429,7 +3465,7 @@ var ParallAgentGateway = class {
3429
3465
  if (this.dispatchedTasks.has(dedupeKey))
3430
3466
  return false;
3431
3467
  this.dispatchedTasks.add(dedupeKey);
3432
- this.opts.log?.info(`parall[${this.opts.accountId}]: approval decided: ${approval.id} (${approval.status})`);
3468
+ this.opts.log?.info(`approval decided: ${approval.id} (${approval.status})`);
3433
3469
  const statusLabel = approval.status === "approved" ? "Approved" : "Rejected";
3434
3470
  const execInfo = approval.execution_status ? ` | execution: ${approval.execution_status}` : "";
3435
3471
  const body = `${statusLabel}: ${approval.title}${execInfo}`;
@@ -3479,14 +3515,14 @@ var ParallAgentGateway = class {
3479
3515
  try {
3480
3516
  dispatched = await this.handleTaskDispatch(item.task_id, item.source_id ?? item.task_id);
3481
3517
  } catch (err) {
3482
- this.opts.log?.warn(`parall[${this.opts.accountId}]: catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
3518
+ this.opts.log?.warn(`catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
3483
3519
  continue;
3484
3520
  }
3485
3521
  } else if (item.event_type === "task_update" && item.task_id) {
3486
3522
  try {
3487
3523
  dispatched = await this.handleTaskDispatch(item.task_id, item.source_id ?? item.task_id, { allowCreator: true });
3488
3524
  } catch (err) {
3489
- this.opts.log?.warn(`parall[${this.opts.accountId}]: catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
3525
+ this.opts.log?.warn(`catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
3490
3526
  continue;
3491
3527
  }
3492
3528
  } else if (item.event_type === "task_comment" && item.source_id && item.task_id) {
@@ -3508,7 +3544,7 @@ var ParallAgentGateway = class {
3508
3544
  msg = null;
3509
3545
  } else {
3510
3546
  msgFetchFailed = true;
3511
- this.opts.log?.warn(`parall[${this.opts.accountId}]: catch-up message fetch failed for ${item.source_id}, leaving pending: ${String(err)}`);
3547
+ this.opts.log?.warn(`catch-up message fetch failed for ${item.source_id}, leaving pending: ${String(err)}`);
3512
3548
  }
3513
3549
  }
3514
3550
  if (msgFetchFailed) {
@@ -3539,13 +3575,13 @@ var ParallAgentGateway = class {
3539
3575
  });
3540
3576
  }
3541
3577
  } catch (err) {
3542
- this.opts.log?.warn(`parall[${this.opts.accountId}]: catch-up dispatch ${item.id} (${item.event_type}) failed: ${String(err)}`);
3578
+ this.opts.log?.warn(`catch-up dispatch ${item.id} (${item.event_type}) failed: ${String(err)}`);
3543
3579
  }
3544
3580
  }
3545
3581
  cursor = !this.shuttingDown && page.has_more ? page.next_cursor : void 0;
3546
3582
  } while (cursor);
3547
3583
  if (processed > 0 || skippedOld > 0) {
3548
- this.opts.log?.info(`parall[${this.opts.accountId}]: dispatch catch-up: processed ${processed}, skipped ${skippedOld} old item(s)`);
3584
+ this.opts.log?.info(`dispatch catch-up: processed ${processed}, skipped ${skippedOld} old item(s)`);
3549
3585
  }
3550
3586
  }
3551
3587
  async handleHello(data) {
@@ -3554,7 +3590,7 @@ var ParallAgentGateway = class {
3554
3590
  const intervalSec = data.heartbeat_interval > 0 ? data.heartbeat_interval : 30;
3555
3591
  try {
3556
3592
  const count = await fetchAllChats(client, config.org_id, this.chatInfoMap);
3557
- log2?.info(`parall[${this.opts.accountId}]: WebSocket connected, ${count} chats cached`);
3593
+ log2?.info(`WebSocket connected, ${count} chats cached`);
3558
3594
  await this.opts.onSessionReady?.({
3559
3595
  activeSessionId: this.activeSessionId,
3560
3596
  ws: this.opts.ws,
@@ -3568,7 +3604,7 @@ var ParallAgentGateway = class {
3568
3604
  const expectedMs = intervalSec * 1e3;
3569
3605
  const drift = now - this.lastHeartbeatAt - expectedMs;
3570
3606
  if (drift > 15e3) {
3571
- log2?.warn(`parall[${this.opts.accountId}]: heartbeat drift ${drift}ms \u2014 event loop may be blocked`);
3607
+ log2?.warn(`heartbeat drift ${drift}ms \u2014 event loop may be blocked`);
3572
3608
  }
3573
3609
  this.lastHeartbeatAt = now;
3574
3610
  if (this.opts.ws.state !== "connected")
@@ -3584,10 +3620,10 @@ var ParallAgentGateway = class {
3584
3620
  const isFirstHello = !this.hadSuccessfulHello;
3585
3621
  this.hadSuccessfulHello = true;
3586
3622
  this.catchUpFromDispatch(isFirstHello).catch((err) => {
3587
- log2?.warn(`parall[${this.opts.accountId}]: dispatch catch-up failed: ${String(err)}`);
3623
+ log2?.warn(`dispatch catch-up failed: ${String(err)}`);
3588
3624
  });
3589
3625
  } catch (err) {
3590
- log2?.error(`parall[${this.opts.accountId}]: failed to fetch chats: ${String(err)}`);
3626
+ log2?.error(`failed to fetch chats: ${String(err)}`);
3591
3627
  }
3592
3628
  }
3593
3629
  // Resolves when in-flight dispatches hit 0 or the deadline elapses.
@@ -3613,12 +3649,12 @@ var ParallAgentGateway = class {
3613
3649
  async shutdown() {
3614
3650
  this.shuttingDown = true;
3615
3651
  if (this.inFlightDispatches > 0) {
3616
- this.opts.log?.info(`parall[${this.opts.accountId}]: draining ${this.inFlightDispatches} in-flight dispatch(es), deadline ${this.SHUTDOWN_DEADLINE_MS}ms`);
3652
+ this.opts.log?.info(`draining ${this.inFlightDispatches} in-flight dispatch(es), deadline ${this.SHUTDOWN_DEADLINE_MS}ms`);
3617
3653
  await this.waitForDrain(this.SHUTDOWN_DEADLINE_MS);
3618
3654
  if (this.inFlightDispatches > 0) {
3619
- this.opts.log?.warn(`parall[${this.opts.accountId}]: drain deadline hit; ${this.inFlightDispatches} dispatch(es) still running \u2014 they will be killed by process exit`);
3655
+ this.opts.log?.warn(`drain deadline hit; ${this.inFlightDispatches} dispatch(es) still running \u2014 they will be killed by process exit`);
3620
3656
  } else {
3621
- this.opts.log?.info(`parall[${this.opts.accountId}]: drain complete`);
3657
+ this.opts.log?.info(`drain complete`);
3622
3658
  }
3623
3659
  }
3624
3660
  if (this.heartbeatTimer)
@@ -3629,7 +3665,7 @@ var ParallAgentGateway = class {
3629
3665
  this.activeDispatches.clear();
3630
3666
  await this.opts.onBeforeDisconnect?.();
3631
3667
  this.opts.ws.disconnect();
3632
- this.opts.log?.info(`parall[${this.opts.accountId}]: disconnected`);
3668
+ this.opts.log?.info(`disconnected`);
3633
3669
  }
3634
3670
  };
3635
3671
 
@@ -5262,7 +5298,7 @@ var CodexAppServerAdapter = class {
5262
5298
  setActiveTurn(threadId, sink, log2) {
5263
5299
  const existing = this.activeTurns.get(threadId);
5264
5300
  if (existing) {
5265
- (log2 ?? this.opts.log)?.warn?.(`codex-agent: thread ${threadId} already had an active turn; failing the previous dispatch`);
5301
+ (log2 ?? this.opts.log)?.warn?.(`thread ${threadId} already had an active turn; failing the previous dispatch`);
5266
5302
  existing.push({ kind: "error", message: `thread ${threadId} replaced by concurrent turn` });
5267
5303
  existing.close();
5268
5304
  }
@@ -5296,7 +5332,7 @@ var CodexAppServerAdapter = class {
5296
5332
  this.pendingInjections.set(sessionKey, (this.pendingInjections.get(sessionKey) ?? 0) + 1);
5297
5333
  return true;
5298
5334
  } catch (err) {
5299
- this.opts.log?.warn?.(`codex-agent: turn/steer failed: ${errToString(err)}`);
5335
+ this.opts.log?.warn?.(`turn/steer failed: ${errToString(err)}`);
5300
5336
  return false;
5301
5337
  }
5302
5338
  }
@@ -5309,7 +5345,7 @@ var CodexAppServerAdapter = class {
5309
5345
  this.pendingInjections.delete(sessionKey);
5310
5346
  const threadId2 = this.opts.sessionManager.getThreadId(sessionKey);
5311
5347
  if (threadId2 && this.client && !this.client.isDisposed()) {
5312
- (this.opts.log ?? context.log)?.info?.(`codex-agent[${context.accountId}]: ${pending} steer injection(s) already sent; skipping turn/start`);
5348
+ (this.opts.log ?? context.log)?.info?.(`${pending} steer injection(s) already sent; skipping turn/start`);
5313
5349
  yield {
5314
5350
  type: "runtime_session",
5315
5351
  runtimeSessionId: threadId2,
@@ -5317,7 +5353,7 @@ var CodexAppServerAdapter = class {
5317
5353
  };
5318
5354
  return;
5319
5355
  }
5320
- (this.opts.log ?? context.log)?.warn?.(`codex-agent[${context.accountId}]: pending steer invalidated (subprocess died); falling through to normal dispatch`);
5356
+ (this.opts.log ?? context.log)?.warn?.(`pending steer invalidated (subprocess died); falling through to normal dispatch`);
5321
5357
  }
5322
5358
  await this.ensureStarted(context.log);
5323
5359
  const client = this.client;
@@ -5343,7 +5379,7 @@ var CodexAppServerAdapter = class {
5343
5379
  this.opts.sessionManager.recordThreadId(sessionKey, threadId);
5344
5380
  this.resumedThreadIds.add(threadId);
5345
5381
  } catch (err) {
5346
- log2?.warn?.(`codex-agent: thread/resume failed (${errToString(err)}); attempting one-shot fresh-thread start`);
5382
+ log2?.warn?.(`thread/resume failed (${errToString(err)}); attempting one-shot fresh-thread start`);
5347
5383
  let freshThreadId;
5348
5384
  try {
5349
5385
  freshThreadId = await this.openThread(client, { resumeId: void 0 });
@@ -5378,7 +5414,7 @@ var CodexAppServerAdapter = class {
5378
5414
  preparedImages = prepared.attachments.images;
5379
5415
  releasePreparedAttachments = pinLocalAttachmentPaths(preparedImages);
5380
5416
  } catch (err) {
5381
- log2?.warn?.(`codex-agent[${context.accountId}]: failed to prepare local attachments: ${errToString(err)}`);
5417
+ log2?.warn?.(`failed to prepare local attachments: ${errToString(err)}`);
5382
5418
  }
5383
5419
  const turnInput = buildTurnInput(preparedBody, preparedImages);
5384
5420
  const startTurn = (targetThreadId) => client.sendRequest("turn/start", {
@@ -5399,7 +5435,7 @@ var CodexAppServerAdapter = class {
5399
5435
  yield { type: "error", message: `Codex turn/start failed: ${message}` };
5400
5436
  return;
5401
5437
  }
5402
- log2?.warn?.(`codex-agent: turn/start on thread ${threadId} failed (${message}); attempting one-shot fresh-thread retry`);
5438
+ log2?.warn?.(`turn/start on thread ${threadId} failed (${message}); attempting one-shot fresh-thread retry`);
5403
5439
  this.activeTurns.delete(threadId);
5404
5440
  let freshThreadId;
5405
5441
  try {
@@ -5500,7 +5536,7 @@ var CodexAppServerAdapter = class {
5500
5536
  const result = await client.sendRequest("thread/fork", forkParams);
5501
5537
  const forkedThreadId = extractThreadId(result);
5502
5538
  if (!forkedThreadId) {
5503
- this.opts.log?.warn?.("codex-agent: thread/fork returned no thread id");
5539
+ this.opts.log?.warn?.("thread/fork returned no thread id");
5504
5540
  return null;
5505
5541
  }
5506
5542
  this.opts.sessionManager.recordThreadId(handle.sessionKey, forkedThreadId);
@@ -5513,7 +5549,7 @@ var CodexAppServerAdapter = class {
5513
5549
  this.opts.sessionManager.cleanupFork(fork.sessionKey);
5514
5550
  }
5515
5551
  logForkFailure(err) {
5516
- this.opts.log?.warn?.(`codex-agent: thread/fork failed: ${errToString(err)}`);
5552
+ this.opts.log?.warn?.(`thread/fork failed: ${errToString(err)}`);
5517
5553
  return null;
5518
5554
  }
5519
5555
  async stop() {
@@ -5571,7 +5607,7 @@ var CodexAppServerAdapter = class {
5571
5607
  env.PRLL_CONTEXT_FILE = this.opts.contextFilePath;
5572
5608
  }
5573
5609
  const args = ["app-server", "--listen", "stdio://"];
5574
- (log2 ?? this.opts.log)?.info?.(`codex-agent: spawning ${this.opts.codexBin} ${args.join(" ")}`);
5610
+ (log2 ?? this.opts.log)?.info?.(`spawning ${this.opts.codexBin} ${args.join(" ")}`);
5575
5611
  const proc = spawn(IS_WIN32 ? quoteWin32Arg(this.opts.codexBin) : this.opts.codexBin, IS_WIN32 ? args.map(quoteWin32Arg) : args, {
5576
5612
  cwd: this.opts.workspaceDir,
5577
5613
  env,
@@ -5580,7 +5616,7 @@ var CodexAppServerAdapter = class {
5580
5616
  });
5581
5617
  proc.stderr.setEncoding("utf8");
5582
5618
  proc.stderr.on("data", (chunk) => {
5583
- (log2 ?? this.opts.log)?.warn?.(`codex-agent[stderr]: ${chunk.trim()}`);
5619
+ (log2 ?? this.opts.log)?.warn?.(`[stderr] ${chunk.trim()}`);
5584
5620
  });
5585
5621
  const client = new JsonRpcStdioClient(proc, void 0, (p) => {
5586
5622
  if (!IS_WIN32 || !p.pid || !killWin32Tree(p.pid)) {
@@ -5615,9 +5651,9 @@ var CodexAppServerAdapter = class {
5615
5651
  const reason = err ? `spawn error: ${err.message}` : `exited (code=${code ?? "null"}${signal ? `, signal=${signal}` : ""})`;
5616
5652
  const logger = log2 ?? this.opts.log;
5617
5653
  if (this.stopping) {
5618
- logger?.info?.(`codex-agent: app-server subprocess ${reason} during graceful stop`);
5654
+ logger?.info?.(`app-server subprocess ${reason} during graceful stop`);
5619
5655
  } else {
5620
- logger?.warn?.(`codex-agent: app-server subprocess ${reason}; resetting adapter`);
5656
+ logger?.warn?.(`app-server subprocess ${reason}; resetting adapter`);
5621
5657
  }
5622
5658
  this.client?.dispose(err ?? new Error(`app-server ${reason}`));
5623
5659
  for (const activeSink of this.activeTurns.values()) {
@@ -6641,9 +6677,12 @@ function ensureParallProvider(codexHome, apiUrl, log2) {
6641
6677
  ].join("\n");
6642
6678
  const headerIdx = content.indexOf(sectionHeader);
6643
6679
  if (headerIdx !== -1) {
6644
- const sectionEnd = findSectionEnd(content, headerIdx + sectionHeader.length + 1);
6645
- const authIdx = content.indexOf(authHeader, headerIdx);
6646
- const blockEnd = authIdx !== -1 && authIdx < sectionEnd ? findSectionEnd(content, authIdx + authHeader.length + 1) : sectionEnd;
6680
+ let blockEnd = findSectionEnd(content, headerIdx + sectionHeader.length + 1);
6681
+ let authIdx = content.indexOf(authHeader, blockEnd);
6682
+ while (authIdx !== -1 && content.substring(blockEnd, authIdx).trim() === "") {
6683
+ blockEnd = findSectionEnd(content, authIdx + authHeader.length + 1);
6684
+ authIdx = content.indexOf(authHeader, blockEnd);
6685
+ }
6647
6686
  content = content.substring(0, headerIdx) + providerBlock + content.substring(blockEnd);
6648
6687
  } else {
6649
6688
  content = content.trimEnd() + "\n\n" + providerBlock + "\n";
@@ -6682,6 +6721,7 @@ ${systemPrompt.replace(/\\/g, "\\\\").replace(/"""/g, '\\"""')}
6682
6721
 
6683
6722
  // ts/codex-agent/dist/index.js
6684
6723
  var log = createLogger("codex-agent");
6724
+ var activeLog = log;
6685
6725
  async function getAgentMeWithLegacyFallback(client, orgId) {
6686
6726
  try {
6687
6727
  return await client.getAgentMe(orgId);
@@ -6702,13 +6742,15 @@ async function main() {
6702
6742
  });
6703
6743
  const me = await getAgentMeWithLegacyFallback(client, config.orgId);
6704
6744
  const agentUserId = me.id;
6705
- ensureWorkspaceTrusted(config.codexHome, config.workspaceDir, log);
6745
+ const agentLog = childLogger(log, agentUserId);
6746
+ activeLog = agentLog;
6747
+ ensureWorkspaceTrusted(config.codexHome, config.workspaceDir, agentLog);
6706
6748
  const useParallProvider = isParallProxyMode();
6707
6749
  if (useParallProvider) {
6708
- ensureParallProvider(config.codexHome, config.apiUrl, log);
6709
- log.info("parall custom provider configured (Responses API HTTP/SSE mode)");
6750
+ ensureParallProvider(config.codexHome, config.apiUrl, agentLog);
6751
+ agentLog.info("parall custom provider configured (Responses API HTTP/SSE mode)");
6710
6752
  }
6711
- ensureCodexWorkspace(config.workspaceDir, log, {
6753
+ ensureCodexWorkspace(config.workspaceDir, agentLog, {
6712
6754
  userId: agentUserId,
6713
6755
  displayName: me.display_name,
6714
6756
  description: me.agent_profile?.description ?? void 0
@@ -6716,21 +6758,21 @@ async function main() {
6716
6758
  const runtimeKey = config.runtimeKey || buildCodexRuntimeKey(agentUserId);
6717
6759
  const mainContextFilePath = contextFilePathForSession(config.stateDir, runtimeKey);
6718
6760
  const sessionStateFilePath = sessionStateFilePathForRuntime(config.stateDir, runtimeKey);
6719
- const sessionManager = new CodexSessionManager(runtimeKey, sessionStateFilePath, log);
6761
+ const sessionManager = new CodexSessionManager(runtimeKey, sessionStateFilePath, agentLog);
6720
6762
  const resolvedWsUrl = resolveWsUrl(config.apiUrl, config.wsUrl, config.swimlaneName);
6721
6763
  const ws = new ParallWs({
6722
6764
  getTicket: () => client.getWsTicket(),
6723
6765
  wsUrl: resolvedWsUrl
6724
6766
  });
6725
- const configMgr = createPlatformConfigManager({ client, stateDir: config.stateDir, runtimeType: "codex", log });
6767
+ const configMgr = createPlatformConfigManager({ client, stateDir: config.stateDir, runtimeType: "codex", log: agentLog });
6726
6768
  const platformDefaults = await configMgr.fetch();
6727
6769
  let platformManaged = isPlatformManagedProfile(me.agent_profile);
6728
6770
  const resolvedModel = platformManaged ? platformDefaults.model ?? config.model : config.model;
6729
6771
  const resolvedEffort = platformManaged ? platformDefaults.thinkingEffort ?? config.reasoningEffort : config.reasoningEffort;
6730
6772
  if (platformDefaults.model)
6731
- log.info(`platform config: model=${platformDefaults.model} (${platformManaged ? "applied" : "ignored, model_management=self"})`);
6773
+ agentLog.info(`platform config: model=${platformDefaults.model} (${platformManaged ? "applied" : "ignored, model_management=self"})`);
6732
6774
  if (platformDefaults.thinkingEffort)
6733
- log.info(`platform config: reasoning_effort=${platformDefaults.thinkingEffort} (${platformManaged ? "applied" : "ignored, model_management=self"})`);
6775
+ agentLog.info(`platform config: reasoning_effort=${platformDefaults.thinkingEffort} (${platformManaged ? "applied" : "ignored, model_management=self"})`);
6734
6776
  const adapter = new CodexAppServerAdapter({
6735
6777
  codexBin: config.codexBin,
6736
6778
  codexHome: config.codexHome,
@@ -6740,7 +6782,7 @@ async function main() {
6740
6782
  sandbox: config.sandbox,
6741
6783
  approvalPolicy: config.approvalPolicy,
6742
6784
  sessionManager,
6743
- log,
6785
+ log: agentLog,
6744
6786
  contextFilePath: mainContextFilePath,
6745
6787
  useParallProvider
6746
6788
  });
@@ -6765,7 +6807,7 @@ async function main() {
6765
6807
  driver: "app-server"
6766
6808
  },
6767
6809
  dispatchAdapter: adapter,
6768
- log,
6810
+ log: agentLog,
6769
6811
  shutdownDeadlineMs: parseShutdownDeadlineMs(process.env.PRLL_SHUTDOWN_DEADLINE_MS),
6770
6812
  contextFilePathForSession: (sessionKey) => contextFilePathForSession(config.stateDir, sessionKey),
6771
6813
  stepIdFilePathForSession: (sessionKey) => stepIdFilePathForSession(config.stateDir, sessionKey),
@@ -6786,6 +6828,9 @@ async function main() {
6786
6828
  model: platformManaged ? updated.model ?? config.model : config.model ?? null,
6787
6829
  reasoningEffort: platformManaged ? updated.thinkingEffort ?? config.reasoningEffort : config.reasoningEffort ?? null
6788
6830
  });
6831
+ },
6832
+ onNewSession: () => {
6833
+ sessionManager.clearMainThread();
6789
6834
  }
6790
6835
  });
6791
6836
  const abortController = new AbortController();
@@ -6793,7 +6838,7 @@ async function main() {
6793
6838
  process.on("SIGINT", abort);
6794
6839
  process.on("SIGTERM", abort);
6795
6840
  try {
6796
- log.info(`starting self-hosted Codex runtime (app-server driver) for ${me.display_name} (${agentUserId})`);
6841
+ agentLog.info(`starting self-hosted Codex runtime (app-server driver) for ${me.display_name} (${agentUserId})`);
6797
6842
  await gateway.run(abortController.signal);
6798
6843
  } finally {
6799
6844
  await adapter.stop();
@@ -6802,7 +6847,7 @@ async function main() {
6802
6847
  }
6803
6848
  }
6804
6849
  main().catch((err) => {
6805
- log.error(`fatal: ${String(err)}`);
6850
+ activeLog.error(`fatal: ${String(err)}`);
6806
6851
  process.exitCode = 1;
6807
6852
  });
6808
6853
  /*! Bundled license information: