chatroom-cli 1.55.6 → 1.55.7

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
@@ -27327,6 +27327,96 @@ var init_opencode = __esm(() => {
27327
27327
  init_opencode_agent_service();
27328
27328
  });
27329
27329
 
27330
+ // src/infrastructure/services/remote-agents/agent-log-format.ts
27331
+ function buildAgentLogPrefix(agent, context5) {
27332
+ const roleTag = context5.role ?? "unknown";
27333
+ const chatroomSuffix = context5.chatroomId ? `@${context5.chatroomId.slice(-6)}` : "";
27334
+ return `[${agent}:${roleTag}${chatroomSuffix}`;
27335
+ }
27336
+ function formatAgentLogLine(prefix, kind, payload) {
27337
+ return payload !== undefined && payload !== "" ? `${prefix} ${kind}] ${payload}` : `${prefix} ${kind}]`;
27338
+ }
27339
+ function formatTimestampedLogLine(role, kind, payload, now) {
27340
+ const ts = now ? now() : new Date().toISOString();
27341
+ return `[${ts}] role:${role} ${kind}]${payload ? ` ${payload}` : ""}`;
27342
+ }
27343
+ function formatBashRunningPayload(command) {
27344
+ return `${BASH_RUNNING_PREFIX} ${command}`;
27345
+ }
27346
+ function isBashLikeToolName(name) {
27347
+ return /bash|shell|terminal|command/i.test(name);
27348
+ }
27349
+ function extractBashCommandFromToolInput(name, input) {
27350
+ if (!isBashLikeToolName(name))
27351
+ return null;
27352
+ if (input && typeof input === "object" && "command" in input) {
27353
+ return String(input.command);
27354
+ }
27355
+ if (typeof input === "string")
27356
+ return input;
27357
+ return null;
27358
+ }
27359
+ function resolveBashCommandForLog(name, input) {
27360
+ if (!isBashLikeToolName(name))
27361
+ return null;
27362
+ const extracted = extractBashCommandFromToolInput(name, input);
27363
+ if (extracted !== null)
27364
+ return extracted;
27365
+ if (input != null)
27366
+ return JSON.stringify(input);
27367
+ return "";
27368
+ }
27369
+ function extractBashCommandFromCursorToolCall(toolCall) {
27370
+ if (!toolCall || typeof toolCall !== "object")
27371
+ return null;
27372
+ for (const [key, value] of Object.entries(toolCall)) {
27373
+ if (!isBashLikeToolName(key) || !value || typeof value !== "object")
27374
+ continue;
27375
+ const args2 = value.args;
27376
+ if (args2 && typeof args2 === "object" && "command" in args2) {
27377
+ return String(args2.command);
27378
+ }
27379
+ }
27380
+ return null;
27381
+ }
27382
+ function appendToolInputToPayload(base, input, toolName) {
27383
+ if (!input || typeof input === "object" && Object.keys(input).length === 0) {
27384
+ return base;
27385
+ }
27386
+ const inp = input;
27387
+ if (toolName === "bash" && typeof inp.command === "string") {
27388
+ return `${base}: ${inp.command}`;
27389
+ }
27390
+ const inputStr = typeof inp === "string" ? inp : JSON.stringify(inp);
27391
+ return `${base}: ${inputStr}`;
27392
+ }
27393
+ function createAgentLogWriter(prefix, options) {
27394
+ const target = options?.target ?? process.stdout;
27395
+ const emitLogLine = options?.emitLogLine;
27396
+ const writeLine = (formatted) => {
27397
+ target.write(`${formatted}
27398
+ `);
27399
+ emitLogLine?.(formatted);
27400
+ };
27401
+ return {
27402
+ write(kind, payload) {
27403
+ writeLine(formatAgentLogLine(prefix, kind, payload));
27404
+ },
27405
+ writeLine,
27406
+ flushBufferedLines(buffer, kind) {
27407
+ if (!buffer)
27408
+ return buffer;
27409
+ for (const line of buffer.split(`
27410
+ `)) {
27411
+ if (line)
27412
+ writeLine(formatAgentLogLine(prefix, kind, line));
27413
+ }
27414
+ return "";
27415
+ }
27416
+ };
27417
+ }
27418
+ var BASH_TOOL_KIND = "tool: bash", BASH_RUNNING_PREFIX = "running:";
27419
+
27330
27420
  // src/infrastructure/services/remote-agents/pi/pi-rpc-reader.ts
27331
27421
  import { createInterface } from "node:readline";
27332
27422
 
@@ -27616,9 +27706,7 @@ var init_pi_agent_service = __esm(() => {
27616
27706
  this.childProcesses.set(pid, childProcess);
27617
27707
  this.trackedSessions.set(pid, { harnessSessionId, workingDir, model });
27618
27708
  const entry = this.registerProcess(pid, context5);
27619
- const roleTag = context5.role ?? "unknown";
27620
- const chatroomSuffix = context5.chatroomId ? `@${context5.chatroomId.slice(-6)}` : "";
27621
- const logPrefix = `[pi:${roleTag}${chatroomSuffix}`;
27709
+ const logPrefix = buildAgentLogPrefix("pi", context5);
27622
27710
  const outputCallbacks = [];
27623
27711
  const logLineCallbacks = [];
27624
27712
  const agentEndCallbacks = [];
@@ -27654,11 +27742,7 @@ var init_pi_agent_service = __esm(() => {
27654
27742
  onOutput,
27655
27743
  onLogLine
27656
27744
  };
27657
- const writeFormattedLogLine = (formatted) => {
27658
- process.stdout.write(`${formatted}
27659
- `);
27660
- emitLogLine(formatted);
27661
- };
27745
+ const log4 = createAgentLogWriter(logPrefix, { emitLogLine });
27662
27746
  const onStderrData = (chunk2) => {
27663
27747
  entry.lastOutputAt = Date.now();
27664
27748
  for (const cb of outputCallbacks)
@@ -27679,15 +27763,9 @@ var init_pi_agent_service = __esm(() => {
27679
27763
  let textBuffer = "";
27680
27764
  let thinkingBuffer = "";
27681
27765
  const flushBufferedLines = (buffer, kind, clear) => {
27682
- if (!buffer)
27683
- return;
27684
- for (const line of buffer.split(`
27685
- `)) {
27686
- if (line) {
27687
- writeFormattedLogLine(`${logPrefix} ${kind}] ${line}`);
27688
- }
27689
- }
27766
+ const remaining = log4.flushBufferedLines(buffer, kind);
27690
27767
  clear();
27768
+ return remaining;
27691
27769
  };
27692
27770
  const flushText = () => flushBufferedLines(textBuffer, "text", () => {
27693
27771
  textBuffer = "";
@@ -27722,20 +27800,24 @@ var init_pi_agent_service = __esm(() => {
27722
27800
  reader.onAgentEnd(() => {
27723
27801
  flushText();
27724
27802
  flushThinking();
27725
- process.stdout.write(`${logPrefix} agent_end]
27726
- `);
27803
+ log4.write("agent_end");
27727
27804
  for (const cb of agentEndCallbacks)
27728
27805
  cb();
27729
27806
  });
27730
27807
  reader.onToolCall((name, toolArgs) => {
27731
27808
  flushText();
27732
27809
  flushThinking();
27810
+ const bashCmd = resolveBashCommandForLog(name, toolArgs);
27811
+ if (bashCmd !== null) {
27812
+ log4.write(BASH_TOOL_KIND, formatBashRunningPayload(bashCmd));
27813
+ return;
27814
+ }
27733
27815
  const argsStr = toolArgs != null ? ` args: ${JSON.stringify(toolArgs)}` : "";
27734
- writeFormattedLogLine(`${logPrefix} tool: ${name}${argsStr}]`);
27816
+ log4.write("tool", `${name}${argsStr}`);
27735
27817
  });
27736
27818
  reader.onToolResult((name, result) => {
27737
27819
  const resultStr = typeof result === "string" ? result : JSON.stringify(result);
27738
- writeFormattedLogLine(`${logPrefix} tool_result: ${name} result: ${resultStr}]`);
27820
+ log4.write("tool_result", `${name} result: ${resultStr}`);
27739
27821
  });
27740
27822
  attachStderr(childProcess.stderr);
27741
27823
  return {
@@ -27941,9 +28023,7 @@ ${options.prompt}`;
27941
28023
  const pid = childProcess.pid;
27942
28024
  const context5 = options.context;
27943
28025
  const entry = this.registerProcess(pid, context5);
27944
- const roleTag = context5.role ?? "unknown";
27945
- const chatroomSuffix = context5.chatroomId ? `@${context5.chatroomId.slice(-6)}` : "";
27946
- const logPrefix = `[cursor:${roleTag}${chatroomSuffix}`;
28026
+ const logPrefix = buildAgentLogPrefix("cursor", context5);
27947
28027
  const outputCallbacks = [];
27948
28028
  if (childProcess.stdout) {
27949
28029
  const reader = new CursorStreamReader(childProcess.stdout);
@@ -27954,7 +28034,7 @@ ${options.prompt}`;
27954
28034
  for (const line of textBuffer.split(`
27955
28035
  `)) {
27956
28036
  if (line)
27957
- process.stdout.write(`${logPrefix} text] ${line}
28037
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "text", line)}
27958
28038
  `);
27959
28039
  }
27960
28040
  textBuffer = "";
@@ -27975,17 +28055,23 @@ ${options.prompt}`;
27975
28055
  });
27976
28056
  reader.onAgentEnd(() => {
27977
28057
  flushText();
27978
- process.stdout.write(`${logPrefix} agent_end]
28058
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "agent_end")}
27979
28059
  `);
27980
28060
  });
27981
28061
  reader.onToolCall((callId, toolCall) => {
27982
28062
  flushText();
27983
- process.stdout.write(`${logPrefix} tool: ${callId} ${JSON.stringify(toolCall)}]
28063
+ const bashCmd = extractBashCommandFromCursorToolCall(toolCall);
28064
+ if (bashCmd !== null) {
28065
+ process.stdout.write(`${formatAgentLogLine(logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd))}
28066
+ `);
28067
+ return;
28068
+ }
28069
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "tool", `${callId} ${JSON.stringify(toolCall)}`)}
27984
28070
  `);
27985
28071
  });
27986
28072
  reader.onToolResult((callId) => {
27987
28073
  flushText();
27988
- process.stdout.write(`${logPrefix} tool_result: ${callId}]
28074
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "tool_result", callId)}
27989
28075
  `);
27990
28076
  });
27991
28077
  if (childProcess.stderr) {
@@ -28376,9 +28462,7 @@ var init_claude_code_agent_service = __esm(() => {
28376
28462
  const pid = childProcess.pid;
28377
28463
  const context5 = options.context;
28378
28464
  const entry = this.registerProcess(pid, context5);
28379
- const roleTag = context5.role ?? "unknown";
28380
- const chatroomSuffix = context5.chatroomId ? `@${context5.chatroomId.slice(-6)}` : "";
28381
- const logPrefix = `[claude:${roleTag}${chatroomSuffix}]`;
28465
+ const logPrefix = buildAgentLogPrefix("claude", context5);
28382
28466
  const outputCallbacks = [];
28383
28467
  if (childProcess.stdout) {
28384
28468
  const reader = new ClaudeStreamReader(childProcess.stdout);
@@ -28390,7 +28474,7 @@ var init_claude_code_agent_service = __esm(() => {
28390
28474
  for (const line of textBuffer.split(`
28391
28475
  `)) {
28392
28476
  if (line)
28393
- process.stdout.write(`${logPrefix} text] ${line}
28477
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "text", line)}
28394
28478
  `);
28395
28479
  }
28396
28480
  textBuffer = "";
@@ -28401,7 +28485,7 @@ var init_claude_code_agent_service = __esm(() => {
28401
28485
  for (const line of thinkingBuffer.split(`
28402
28486
  `)) {
28403
28487
  if (line)
28404
- process.stdout.write(`${logPrefix} thinking] ${line}
28488
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "thinking", line)}
28405
28489
  `);
28406
28490
  }
28407
28491
  thinkingBuffer = "";
@@ -28432,8 +28516,16 @@ var init_claude_code_agent_service = __esm(() => {
28432
28516
  });
28433
28517
  reader.onToolUse((name, input) => {
28434
28518
  entry.lastOutputAt = Date.now();
28519
+ const bashCmd = extractBashCommandFromToolInput(name, input);
28520
+ if (bashCmd !== null) {
28521
+ process.stdout.write(`${formatAgentLogLine(logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd))}
28522
+ `);
28523
+ for (const cb of outputCallbacks)
28524
+ cb();
28525
+ return;
28526
+ }
28435
28527
  const inputStr = JSON.stringify(input);
28436
- process.stdout.write(`${logPrefix} tool] ${name}(${inputStr.slice(0, 100)}${inputStr.length > 100 ? "..." : ""})
28528
+ process.stdout.write(`${formatAgentLogLine(logPrefix, "tool", `${name}(${inputStr.slice(0, 100)}${inputStr.length > 100 ? "..." : ""})`)}
28437
28529
  `);
28438
28530
  for (const cb of outputCallbacks)
28439
28531
  cb();
@@ -28826,19 +28918,25 @@ class CursorSdkStreamAdapter {
28826
28918
  case "assistant":
28827
28919
  this.handleAssistant(message);
28828
28920
  break;
28829
- case "tool_call":
28921
+ case "tool_call": {
28830
28922
  this.flushText();
28831
- this.writeLine(`${this.logPrefix} tool: ${message.call_id} ${message.name} ${JSON.stringify({ status: message.status, args: message.args })}]`);
28923
+ const bashCmd = extractBashCommandFromToolInput(message.name, message.args);
28924
+ if (bashCmd !== null) {
28925
+ this.writeLine(formatAgentLogLine(this.logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd)));
28926
+ break;
28927
+ }
28928
+ this.writeLine(formatAgentLogLine(this.logPrefix, `tool: ${message.call_id} ${message.name} ${JSON.stringify({ status: message.status, args: message.args })}`));
28832
28929
  break;
28930
+ }
28833
28931
  case "status":
28834
- this.writeLine(`${this.logPrefix} status: ${message.status}]`);
28932
+ this.writeLine(formatAgentLogLine(this.logPrefix, `status: ${message.status}`));
28835
28933
  break;
28836
28934
  case "thinking":
28837
- this.writeLine(`${this.logPrefix} thinking] ${message.text}`);
28935
+ this.writeLine(formatAgentLogLine(this.logPrefix, "thinking", message.text));
28838
28936
  break;
28839
28937
  case "system":
28840
28938
  if (message.subtype === "init") {
28841
- this.writeLine(`${this.logPrefix} system: init]`);
28939
+ this.writeLine(formatAgentLogLine(this.logPrefix, "system: init"));
28842
28940
  }
28843
28941
  break;
28844
28942
  default:
@@ -28869,7 +28967,7 @@ class CursorSdkStreamAdapter {
28869
28967
  for (const line of this.textBuffer.split(`
28870
28968
  `)) {
28871
28969
  if (line)
28872
- this.writeLine(`${this.logPrefix} text] ${line}`);
28970
+ this.writeLine(formatAgentLogLine(this.logPrefix, "text", line));
28873
28971
  }
28874
28972
  this.textBuffer = "";
28875
28973
  }
@@ -28878,7 +28976,7 @@ class CursorSdkStreamAdapter {
28878
28976
  return;
28879
28977
  this.agentEndEmitted = true;
28880
28978
  this.flushText();
28881
- this.writeLine(`${this.logPrefix} agent_end]`);
28979
+ this.writeLine(formatAgentLogLine(this.logPrefix, "agent_end"));
28882
28980
  for (const cb of this.agentEndCallbacks)
28883
28981
  cb();
28884
28982
  }
@@ -28892,6 +28990,7 @@ class CursorSdkStreamAdapter {
28892
28990
  cb();
28893
28991
  }
28894
28992
  }
28993
+ var init_cursor_sdk_stream_adapter = () => {};
28895
28994
 
28896
28995
  // src/infrastructure/services/remote-agents/cursor-sdk/cursor-sdk-agent-service.ts
28897
28996
  import { randomUUID } from "node:crypto";
@@ -28951,16 +29050,11 @@ function waitForResumeOrAbort(session2) {
28951
29050
  })
28952
29051
  ]);
28953
29052
  }
28954
- function buildLogPrefix(context5) {
28955
- const roleTag = context5.role ?? "unknown";
28956
- const chatroomSuffix = context5.chatroomId ? `@${context5.chatroomId.slice(-6)}` : "";
28957
- return `[cursor-sdk:${roleTag}${chatroomSuffix}`;
28958
- }
28959
29053
  function resolveModelId(model) {
28960
29054
  return model ? resolveCursorSdkModel(model) : DEFAULT_MODEL;
28961
29055
  }
28962
29056
  function writeSpawnError(logPrefix, err, emitLogLine) {
28963
- const line = `${logPrefix} spawn-error] ${formatCursorSdkLoadError(err)}`;
29057
+ const line = formatAgentLogLine(logPrefix, "spawn-error", formatCursorSdkLoadError(err));
28964
29058
  process.stderr.write(`${line}
28965
29059
  `);
28966
29060
  emitLogLine?.(line);
@@ -28972,6 +29066,7 @@ var init_cursor_sdk_agent_service = __esm(() => {
28972
29066
  init_base_cli_agent_service();
28973
29067
  init_detection_result();
28974
29068
  init_cursor_sdk_package();
29069
+ init_cursor_sdk_stream_adapter();
28975
29070
  CursorSdkAgentService = class CursorSdkAgentService extends BaseCLIAgentService {
28976
29071
  id = "cursor-sdk";
28977
29072
  displayName = "Cursor (SDK)";
@@ -29139,7 +29234,7 @@ ${options.prompt}`;
29139
29234
  forceFirstTurn
29140
29235
  } = args2;
29141
29236
  const entry = this.registerProcess(pid, context5);
29142
- const logPrefix = buildLogPrefix(context5);
29237
+ const logPrefix = buildAgentLogPrefix("cursor-sdk", context5);
29143
29238
  const session2 = {
29144
29239
  agent,
29145
29240
  keeper,
@@ -29266,7 +29361,7 @@ ${options.prompt}`;
29266
29361
  adapter.flushPendingOutput();
29267
29362
  if (result.status === "error") {
29268
29363
  exitCode = 2;
29269
- const runErrorLine = `${logPrefix} run-error] run ${result.id} failed`;
29364
+ const runErrorLine = formatAgentLogLine(logPrefix, "run-error", `run ${result.id} failed`);
29270
29365
  process.stderr.write(`${runErrorLine}
29271
29366
  `);
29272
29367
  emitLogLine(runErrorLine);
@@ -29362,6 +29457,7 @@ ${options.prompt}`;
29362
29457
  // src/infrastructure/services/remote-agents/cursor-sdk/index.ts
29363
29458
  var init_cursor_sdk = __esm(() => {
29364
29459
  init_cursor_sdk_agent_service();
29460
+ init_cursor_sdk_stream_adapter();
29365
29461
  });
29366
29462
 
29367
29463
  // ../../node_modules/.pnpm/@opencode-ai+sdk@1.15.11/node_modules/@opencode-ai/sdk/dist/gen/types.gen.js
@@ -31371,8 +31467,7 @@ function selectAgent(agents) {
31371
31467
 
31372
31468
  // src/infrastructure/services/remote-agents/opencode-sdk/session-event-forwarder.ts
31373
31469
  function formatLogLine(options, kind, payload) {
31374
- const ts = options.now ? options.now() : new Date().toISOString();
31375
- return `[${ts}] role:${options.role} ${kind}]${payload ? ` ${payload}` : ""}`;
31470
+ return formatTimestampedLogLine(options.role, kind, payload, options.now);
31376
31471
  }
31377
31472
  function writeLogLine(target, options, kind, payload) {
31378
31473
  const line = formatLogLine(options, kind, payload);
@@ -31462,25 +31557,14 @@ function startSessionEventForwarder(client4, options) {
31462
31557
  writeLogLine(target, options, "thinking", chunk2);
31463
31558
  }
31464
31559
  } else if (part?.type === "tool" && part.tool) {
31465
- let appendInput = function(base, input, tool) {
31466
- if (!input || typeof input === "object" && Object.keys(input).length === 0) {
31467
- return base;
31468
- }
31469
- const inp = input;
31470
- if (tool === "bash" && typeof inp.command === "string") {
31471
- return `${base}: ${inp.command}`;
31472
- }
31473
- const inputStr = typeof inp === "string" ? inp : JSON.stringify(inp);
31474
- return `${base}: ${inputStr}`;
31475
- };
31476
31560
  const state = typeof props?.state === "string" ? props.state : typeof part.state?.status === "string" ? part.state.status : "started";
31477
31561
  let payload = state;
31478
31562
  if (part.state?.input) {
31479
- payload = appendInput(payload, part.state.input, part.tool);
31563
+ payload = appendToolInputToPayload(payload, part.state.input, part.tool);
31480
31564
  }
31481
31565
  if (state === "completed" && part.state?.time?.start !== undefined && part.state?.time?.end !== undefined) {
31482
31566
  const duration3 = ((part.state.time.end - part.state.time.start) / 1000).toFixed(1);
31483
- payload = appendInput(`${state} (${duration3}s)`, part.state.input, part.tool);
31567
+ payload = appendToolInputToPayload(`${state} (${duration3}s)`, part.state.input, part.tool);
31484
31568
  }
31485
31569
  const callID = part.callID ?? "unknown";
31486
31570
  const seenKey = `${callID}:${state}`;
@@ -31565,6 +31649,7 @@ function startSessionEventForwarder(client4, options) {
31565
31649
  }
31566
31650
  };
31567
31651
  }
31652
+ var init_session_event_forwarder = () => {};
31568
31653
 
31569
31654
  // src/infrastructure/services/remote-agents/opencode-sdk/session-metadata-store.ts
31570
31655
  import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
@@ -31633,6 +31718,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
31633
31718
  init_dist();
31634
31719
  init_base_cli_agent_service();
31635
31720
  init_parse_listening_url();
31721
+ init_session_event_forwarder();
31636
31722
  init_session_metadata_store();
31637
31723
  OpenCodeSdkAgentService = class OpenCodeSdkAgentService extends BaseCLIAgentService {
31638
31724
  agentEndCallbacksByPid = new Map;
@@ -92338,4 +92424,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
92338
92424
  });
92339
92425
  program2.parse();
92340
92426
 
92341
- //# debugId=D908929E6EC55FCC64756E2164756E21
92427
+ //# debugId=77F10DD437D49D8264756E2164756E21