chatroom-cli 1.58.5 → 1.58.6

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
@@ -28962,6 +28962,23 @@ var init_commandcode = __esm(() => {
28962
28962
  init_command_code_agent_service();
28963
28963
  });
28964
28964
 
28965
+ // src/infrastructure/services/remote-agents/wire-native-stream-adapter.ts
28966
+ function wireNativeStreamAdapter(args2) {
28967
+ args2.adapter.setAssistantTextCapture((text) => {
28968
+ for (const cb of args2.assistantTextCallbacks)
28969
+ cb(text);
28970
+ });
28971
+ args2.adapter.onOutput(() => {
28972
+ args2.entry.lastOutputAt = Date.now();
28973
+ for (const cb of args2.outputCallbacks)
28974
+ cb();
28975
+ });
28976
+ args2.adapter.onAgentEnd(() => {
28977
+ for (const cb of args2.agentEndCallbacks)
28978
+ cb();
28979
+ });
28980
+ }
28981
+
28965
28982
  // src/infrastructure/services/remote-agents/cursor-sdk/cursor-models.ts
28966
28983
  function resolveCursorSdkModel(model) {
28967
28984
  const prefix = `${CURSOR_PROVIDER2}/`;
@@ -29086,103 +29103,132 @@ function closeCursorAgentOnFailure(agent, session2, exitCode, force = false) {
29086
29103
  } catch {}
29087
29104
  }
29088
29105
 
29089
- // src/infrastructure/services/remote-agents/cursor-sdk/cursor-sdk-stream-adapter.ts
29090
- class CursorSdkStreamAdapter {
29106
+ // src/infrastructure/services/remote-agents/assistant-text-capture.ts
29107
+ function createAssistantTextCapture() {
29108
+ let onAssistantText;
29109
+ return {
29110
+ setAssistantTextCapture(cb) {
29111
+ onAssistantText = cb;
29112
+ },
29113
+ captureAssistantText(text) {
29114
+ onAssistantText?.(text);
29115
+ }
29116
+ };
29117
+ }
29118
+
29119
+ // src/infrastructure/services/remote-agents/native-stream-adapter-base.ts
29120
+ class NativeStreamAdapterBase {
29091
29121
  logPrefix;
29092
29122
  emitLogLine;
29093
29123
  agentEndCallbacks = [];
29094
29124
  outputCallbacks = [];
29095
29125
  agentEndEmitted = false;
29096
- textBuffer = "";
29126
+ assistantTextCapture = createAssistantTextCapture();
29097
29127
  constructor(logPrefix, emitLogLine) {
29098
29128
  this.logPrefix = logPrefix;
29099
29129
  this.emitLogLine = emitLogLine;
29100
29130
  }
29131
+ setAssistantTextCapture(cb) {
29132
+ this.assistantTextCapture.setAssistantTextCapture(cb);
29133
+ }
29101
29134
  onAgentEnd(cb) {
29102
29135
  this.agentEndCallbacks.push(cb);
29103
29136
  }
29104
29137
  onOutput(cb) {
29105
29138
  this.outputCallbacks.push(cb);
29106
29139
  }
29107
- handleMessage(message) {
29108
- this.notifyOutput();
29109
- switch (message.type) {
29110
- case "assistant":
29111
- this.handleAssistant(message);
29112
- break;
29113
- case "tool_call": {
29114
- this.flushText();
29115
- const bashCmd = extractBashCommandFromToolInput(message.name, message.args);
29116
- if (bashCmd !== null) {
29117
- this.writeLine(formatAgentLogLine(this.logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd)));
29140
+ notifyOutput() {
29141
+ for (const cb of this.outputCallbacks)
29142
+ cb();
29143
+ }
29144
+ writeLine(line) {
29145
+ this.emitLogLine?.(line);
29146
+ }
29147
+ }
29148
+ var init_native_stream_adapter_base = () => {};
29149
+
29150
+ // src/infrastructure/services/remote-agents/cursor-sdk/cursor-sdk-stream-adapter.ts
29151
+ var CursorSdkStreamAdapter;
29152
+ var init_cursor_sdk_stream_adapter = __esm(() => {
29153
+ init_native_stream_adapter_base();
29154
+ CursorSdkStreamAdapter = class CursorSdkStreamAdapter extends NativeStreamAdapterBase {
29155
+ textBuffer = "";
29156
+ handleMessage(message) {
29157
+ this.notifyOutput();
29158
+ switch (message.type) {
29159
+ case "assistant":
29160
+ this.handleAssistant(message);
29161
+ break;
29162
+ case "tool_call": {
29163
+ this.flushText();
29164
+ const bashCmd = extractBashCommandFromToolInput(message.name, message.args);
29165
+ if (bashCmd !== null) {
29166
+ this.writeLine(formatAgentLogLine(this.logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd)));
29167
+ break;
29168
+ }
29169
+ this.writeLine(formatAgentLogLine(this.logPrefix, `tool: ${message.call_id} ${message.name} ${JSON.stringify({ status: message.status, args: message.args })}`));
29118
29170
  break;
29119
29171
  }
29120
- this.writeLine(formatAgentLogLine(this.logPrefix, `tool: ${message.call_id} ${message.name} ${JSON.stringify({ status: message.status, args: message.args })}`));
29121
- break;
29172
+ case "status":
29173
+ this.writeLine(formatAgentLogLine(this.logPrefix, `status: ${message.status}`));
29174
+ break;
29175
+ case "thinking":
29176
+ this.writeLine(formatAgentLogLine(this.logPrefix, "thinking", message.text));
29177
+ break;
29178
+ case "system":
29179
+ if (message.subtype === "init") {
29180
+ this.writeLine(formatAgentLogLine(this.logPrefix, "system: init"));
29181
+ }
29182
+ break;
29183
+ default:
29184
+ break;
29122
29185
  }
29123
- case "status":
29124
- this.writeLine(formatAgentLogLine(this.logPrefix, `status: ${message.status}`));
29125
- break;
29126
- case "thinking":
29127
- this.writeLine(formatAgentLogLine(this.logPrefix, "thinking", message.text));
29128
- break;
29129
- case "system":
29130
- if (message.subtype === "init") {
29131
- this.writeLine(formatAgentLogLine(this.logPrefix, "system: init"));
29132
- }
29133
- break;
29134
- default:
29135
- break;
29136
29186
  }
29137
- }
29138
- flushPendingOutput() {
29139
- this.flushText();
29140
- }
29141
- finish() {
29142
- this.flushText();
29143
- this.emitAgentEnd();
29144
- }
29145
- handleAssistant(message) {
29146
- for (const block of message.message.content) {
29147
- if (block.type === "text") {
29148
- this.textBuffer += block.text;
29149
- if (this.textBuffer.includes(`
29187
+ flushPendingOutput() {
29188
+ this.flushText();
29189
+ }
29190
+ finish() {
29191
+ this.flushText();
29192
+ this.emitAgentEnd();
29193
+ }
29194
+ handleAssistant(message) {
29195
+ for (const block of message.message.content) {
29196
+ if (block.type === "text") {
29197
+ this.textBuffer += block.text;
29198
+ this.assistantTextCapture.captureAssistantText(block.text);
29199
+ if (this.textBuffer.includes(`
29150
29200
  `)) {
29151
- this.flushText();
29201
+ this.flushText();
29202
+ }
29152
29203
  }
29153
29204
  }
29154
29205
  }
29155
- }
29156
- flushText() {
29157
- if (!this.textBuffer)
29158
- return;
29159
- for (const line of this.textBuffer.split(`
29206
+ flushText() {
29207
+ if (!this.textBuffer)
29208
+ return;
29209
+ for (const line of this.textBuffer.split(`
29160
29210
  `)) {
29161
- if (line)
29162
- this.writeLine(formatAgentLogLine(this.logPrefix, "text", line));
29211
+ if (line)
29212
+ this.writeLine(formatAgentLogLine(this.logPrefix, "text", line));
29213
+ }
29214
+ this.textBuffer = "";
29163
29215
  }
29164
- this.textBuffer = "";
29165
- }
29166
- emitAgentEnd() {
29167
- if (this.agentEndEmitted)
29168
- return;
29169
- this.agentEndEmitted = true;
29170
- this.flushText();
29171
- this.writeLine(formatAgentLogLine(this.logPrefix, "agent_end"));
29172
- for (const cb of this.agentEndCallbacks)
29173
- cb();
29174
- }
29175
- writeLine(formatted) {
29176
- process.stdout.write(`${formatted}
29216
+ emitAgentEnd() {
29217
+ if (this.agentEndEmitted)
29218
+ return;
29219
+ this.agentEndEmitted = true;
29220
+ this.flushText();
29221
+ this.writeLine(formatAgentLogLine(this.logPrefix, "agent_end"));
29222
+ for (const cb of this.agentEndCallbacks)
29223
+ cb();
29224
+ }
29225
+ writeLine(formatted) {
29226
+ process.stdout.write(`${formatted}
29177
29227
  `);
29178
- this.emitLogLine?.(formatted);
29179
- }
29180
- notifyOutput() {
29181
- for (const cb of this.outputCallbacks)
29182
- cb();
29183
- }
29184
- }
29185
- var init_cursor_sdk_stream_adapter = () => {};
29228
+ this.emitLogLine?.(formatted);
29229
+ }
29230
+ };
29231
+ });
29186
29232
 
29187
29233
  // src/infrastructure/services/remote-agents/with-timeout.ts
29188
29234
  async function withTimeout(p, ms, label) {
@@ -29453,6 +29499,7 @@ ${options.prompt}`;
29453
29499
  const outputCallbacks = [];
29454
29500
  const agentEndCallbacks = [];
29455
29501
  const logLineCallbacks = [];
29502
+ const assistantTextCallbacks = [];
29456
29503
  const emitLogLine = (line) => {
29457
29504
  for (const cb of logLineCallbacks)
29458
29505
  cb(line);
@@ -29477,6 +29524,7 @@ ${options.prompt}`;
29477
29524
  finishExit,
29478
29525
  outputCallbacks,
29479
29526
  agentEndCallbacks,
29527
+ assistantTextCallbacks,
29480
29528
  emitLogLine
29481
29529
  });
29482
29530
  return {
@@ -29497,6 +29545,9 @@ ${options.prompt}`;
29497
29545
  },
29498
29546
  onLogLine: (cb) => {
29499
29547
  logLineCallbacks.push(cb);
29548
+ },
29549
+ onAssistantText: (cb) => {
29550
+ assistantTextCallbacks.push(cb);
29500
29551
  }
29501
29552
  };
29502
29553
  }
@@ -29512,6 +29563,7 @@ ${options.prompt}`;
29512
29563
  entry,
29513
29564
  outputCallbacks,
29514
29565
  agentEndCallbacks,
29566
+ assistantTextCallbacks,
29515
29567
  emitLogLine
29516
29568
  } = args2;
29517
29569
  let exited = false;
@@ -29549,14 +29601,12 @@ ${deferredResume}` : deferredResume;
29549
29601
  session2.run = run3;
29550
29602
  isFirstTurn = false;
29551
29603
  const adapter = new CursorSdkStreamAdapter(logPrefix, emitLogLine);
29552
- adapter.onOutput(() => {
29553
- entry.lastOutputAt = Date.now();
29554
- for (const cb of outputCallbacks)
29555
- cb();
29556
- });
29557
- adapter.onAgentEnd(() => {
29558
- for (const cb of agentEndCallbacks)
29559
- cb();
29604
+ wireNativeStreamAdapter({
29605
+ adapter,
29606
+ assistantTextCallbacks,
29607
+ outputCallbacks,
29608
+ agentEndCallbacks,
29609
+ entry
29560
29610
  });
29561
29611
  try {
29562
29612
  for await (const message of run3.stream()) {
@@ -31920,8 +31970,10 @@ function startSessionEventForwarder(client4, options) {
31920
31970
  }
31921
31971
  async function handleTextPartUpdate(props, part) {
31922
31972
  const chunk2 = resolvePartContent(props?.delta, part.text);
31923
- if (chunk2)
31973
+ if (chunk2) {
31974
+ options.onAssistantText?.(chunk2);
31924
31975
  logLine(target, "text", chunk2);
31976
+ }
31925
31977
  }
31926
31978
  async function handleReasoningPartUpdate(props, part) {
31927
31979
  const chunk2 = resolvePartContent(props?.delta, part.text);
@@ -32187,6 +32239,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32187
32239
  init_terminal_provider_error();
32188
32240
  OpenCodeSdkAgentService = class OpenCodeSdkAgentService extends OpenCodeBinaryAgentService {
32189
32241
  agentEndCallbacksByPid = new Map;
32242
+ assistantTextCallbacksByPid = new Map;
32190
32243
  id = "opencode-sdk";
32191
32244
  displayName = "OpenCode (SDK)";
32192
32245
  listModelsHarnessId = "opencode-sdk";
@@ -32312,6 +32365,9 @@ var init_opencode_sdk_agent_service = __esm(() => {
32312
32365
  const entry = this.registerProcess(pid, context5);
32313
32366
  if (forwarder)
32314
32367
  this.forwarders.set(pid, forwarder);
32368
+ if (args2.assistantTextCallbacks) {
32369
+ this.assistantTextCallbacksByPid.set(pid, args2.assistantTextCallbacks);
32370
+ }
32315
32371
  const outputCallbacks = args2.outputCallbacks ?? [];
32316
32372
  this.wireChildOutput(childProcess, pid, entry, emitLogLine, outputCallbacks);
32317
32373
  return {
@@ -32330,6 +32386,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32330
32386
  }
32331
32387
  this.sessionStore.remove(sessionId);
32332
32388
  this.agentEndCallbacksByPid.delete(pid);
32389
+ this.assistantTextCallbacksByPid.delete(pid);
32333
32390
  this.deleteProcess(pid);
32334
32391
  cb({ code: code2, signal, context: context5 });
32335
32392
  });
@@ -32345,6 +32402,11 @@ var init_opencode_sdk_agent_service = __esm(() => {
32345
32402
  },
32346
32403
  onLogLine: (cb) => {
32347
32404
  logLineCallbacks.push(cb);
32405
+ },
32406
+ onAssistantText: (cb) => {
32407
+ const callbacks = this.assistantTextCallbacksByPid.get(pid) ?? args2.assistantTextCallbacks ?? [];
32408
+ callbacks.push(cb);
32409
+ this.assistantTextCallbacksByPid.set(pid, callbacks);
32348
32410
  }
32349
32411
  };
32350
32412
  }
@@ -32358,6 +32420,16 @@ var init_opencode_sdk_agent_service = __esm(() => {
32358
32420
  }
32359
32421
  };
32360
32422
  }
32423
+ createAssistantTextEmitter() {
32424
+ const assistantTextCallbacks = [];
32425
+ return {
32426
+ assistantTextCallbacks,
32427
+ emitAssistantText: (text) => {
32428
+ for (const cb of assistantTextCallbacks)
32429
+ cb(text);
32430
+ }
32431
+ };
32432
+ }
32361
32433
  async startServeAndClient(workingDir, resolvedConvexUrl) {
32362
32434
  const childProcess = this.spawnServeProcess(workingDir, resolvedConvexUrl);
32363
32435
  const pid = childProcess.pid;
@@ -32406,7 +32478,12 @@ var init_opencode_sdk_agent_service = __esm(() => {
32406
32478
  const newSessionId2 = sessionCreateResult.data.id;
32407
32479
  const forwarder = startSessionEventForwarder(client4, {
32408
32480
  sessionId: newSessionId2,
32409
- role: args2.context.role
32481
+ role: args2.context.role,
32482
+ onAssistantText: (text) => {
32483
+ const callbacks2 = this.assistantTextCallbacksByPid.get(args2.pid) ?? [];
32484
+ for (const cb of callbacks2)
32485
+ cb(text);
32486
+ }
32410
32487
  });
32411
32488
  const callbacks = this.agentEndCallbacksByPid.get(args2.pid) ?? [];
32412
32489
  for (const cb of callbacks) {
@@ -32442,6 +32519,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32442
32519
  const { childProcess, pid, baseUrl, client: client4 } = await this.startServeAndClient(workingDir, options.resolvedConvexUrl);
32443
32520
  let forwarder;
32444
32521
  const { logLineCallbacks, emitLogLine } = this.createLogLineEmitter();
32522
+ const { assistantTextCallbacks, emitAssistantText } = this.createAssistantTextEmitter();
32445
32523
  const outputCallbacks = [];
32446
32524
  try {
32447
32525
  const sessionInfo = await withTimeout(client4.session.get({ path: { id: sessionId } }), SESSION_GET_TIMEOUT_MS, "session.get");
@@ -32452,6 +32530,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32452
32530
  sessionId,
32453
32531
  role: context5.role,
32454
32532
  onLogLine: emitLogLine,
32533
+ onAssistantText: emitAssistantText,
32455
32534
  onActivity: () => {
32456
32535
  for (const cb of outputCallbacks)
32457
32536
  cb();
@@ -32483,6 +32562,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32483
32562
  model: modelForSession,
32484
32563
  workingDir,
32485
32564
  logLineCallbacks,
32565
+ assistantTextCallbacks,
32486
32566
  outputCallbacks
32487
32567
  });
32488
32568
  }
@@ -32495,6 +32575,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32495
32575
  let agentName;
32496
32576
  let deferredSystemPrompt;
32497
32577
  const { logLineCallbacks, emitLogLine } = this.createLogLineEmitter();
32578
+ const { assistantTextCallbacks, emitAssistantText } = this.createAssistantTextEmitter();
32498
32579
  const outputCallbacks = [];
32499
32580
  try {
32500
32581
  const sessionCreateResult = await withTimeout(client4.session.create({ body: {} }), SESSION_CREATE_TIMEOUT_MS, "session.create");
@@ -32506,6 +32587,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32506
32587
  sessionId,
32507
32588
  role: context5.role,
32508
32589
  onLogLine: emitLogLine,
32590
+ onAssistantText: emitAssistantText,
32509
32591
  onActivity: () => {
32510
32592
  for (const cb of outputCallbacks)
32511
32593
  cb();
@@ -32545,6 +32627,7 @@ var init_opencode_sdk_agent_service = __esm(() => {
32545
32627
  model,
32546
32628
  workingDir: options.workingDir,
32547
32629
  logLineCallbacks,
32630
+ assistantTextCallbacks,
32548
32631
  deferredSystemPrompt,
32549
32632
  outputCallbacks
32550
32633
  });
@@ -32704,126 +32787,111 @@ var init_pi_sdk_package = __esm(() => {
32704
32787
  });
32705
32788
 
32706
32789
  // src/infrastructure/services/remote-agents/pi-sdk/pi-sdk-stream-adapter.ts
32707
- class PiSdkStreamAdapter {
32708
- logPrefix;
32709
- emitLogLine;
32710
- agentEndCallbacks = [];
32711
- outputCallbacks = [];
32712
- agentEndEmitted = false;
32713
- textBuffer = "";
32714
- thinkingBuffer = "";
32715
- constructor(logPrefix, emitLogLine) {
32716
- this.logPrefix = logPrefix;
32717
- this.emitLogLine = emitLogLine;
32718
- }
32719
- onAgentEnd(cb) {
32720
- this.agentEndCallbacks.push(cb);
32721
- }
32722
- onOutput(cb) {
32723
- this.outputCallbacks.push(cb);
32724
- }
32725
- handleEvent(event) {
32726
- this.notifyOutput();
32727
- switch (event.type) {
32728
- case "message_update": {
32729
- const assistantEvent = event.assistantMessageEvent;
32730
- if (assistantEvent.type === "text_delta") {
32731
- this.appendText(assistantEvent.delta);
32732
- } else if (assistantEvent.type === "thinking_delta") {
32733
- this.appendThinking(assistantEvent.delta);
32790
+ var PiSdkStreamAdapter;
32791
+ var init_pi_sdk_stream_adapter = __esm(() => {
32792
+ init_native_stream_adapter_base();
32793
+ PiSdkStreamAdapter = class PiSdkStreamAdapter extends NativeStreamAdapterBase {
32794
+ textBuffer = "";
32795
+ thinkingBuffer = "";
32796
+ handleEvent(event) {
32797
+ this.notifyOutput();
32798
+ switch (event.type) {
32799
+ case "message_update": {
32800
+ const assistantEvent = event.assistantMessageEvent;
32801
+ if (assistantEvent.type === "text_delta") {
32802
+ this.appendText(assistantEvent.delta);
32803
+ } else if (assistantEvent.type === "thinking_delta") {
32804
+ this.appendThinking(assistantEvent.delta);
32805
+ }
32806
+ break;
32734
32807
  }
32735
- break;
32736
- }
32737
- case "tool_execution_start": {
32738
- this.flushText();
32739
- this.flushThinking();
32740
- const bashCmd = resolveBashCommandForLog(event.toolName, event.args);
32741
- if (bashCmd !== null) {
32742
- this.writeLine(formatAgentLogLine(this.logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd)));
32808
+ case "tool_execution_start": {
32809
+ this.flushText();
32810
+ this.flushThinking();
32811
+ const bashCmd = resolveBashCommandForLog(event.toolName, event.args);
32812
+ if (bashCmd !== null) {
32813
+ this.writeLine(formatAgentLogLine(this.logPrefix, BASH_TOOL_KIND, formatBashRunningPayload(bashCmd)));
32814
+ break;
32815
+ }
32816
+ const argsStr = event.args != null ? ` args: ${JSON.stringify(event.args)}` : "";
32817
+ this.writeLine(formatAgentLogLine(this.logPrefix, "tool", `${event.toolName}${argsStr}`));
32743
32818
  break;
32744
32819
  }
32745
- const argsStr = event.args != null ? ` args: ${JSON.stringify(event.args)}` : "";
32746
- this.writeLine(formatAgentLogLine(this.logPrefix, "tool", `${event.toolName}${argsStr}`));
32747
- break;
32748
- }
32749
- case "tool_execution_end": {
32750
- const resultStr = typeof event.result === "string" ? event.result : JSON.stringify(event.result);
32751
- this.writeLine(formatAgentLogLine(this.logPrefix, "tool_result", `${event.toolName} result: ${resultStr}`));
32752
- break;
32820
+ case "tool_execution_end": {
32821
+ const resultStr = typeof event.result === "string" ? event.result : JSON.stringify(event.result);
32822
+ this.writeLine(formatAgentLogLine(this.logPrefix, "tool_result", `${event.toolName} result: ${resultStr}`));
32823
+ break;
32824
+ }
32825
+ case "agent_end":
32826
+ this.emitAgentEnd();
32827
+ break;
32828
+ default:
32829
+ break;
32753
32830
  }
32754
- case "agent_end":
32755
- this.emitAgentEnd();
32756
- break;
32757
- default:
32758
- break;
32759
32831
  }
32760
- }
32761
- finish() {
32762
- this.flushText();
32763
- this.flushThinking();
32764
- this.emitAgentEnd();
32765
- }
32766
- emitAgentEnd() {
32767
- if (this.agentEndEmitted)
32768
- return;
32769
- this.agentEndEmitted = true;
32770
- this.writeLine(formatAgentLogLine(this.logPrefix, "agent_end"));
32771
- for (const cb of this.agentEndCallbacks)
32772
- cb();
32773
- }
32774
- appendText(delta) {
32775
- this.flushThinking();
32776
- this.textBuffer += delta;
32777
- if (this.textBuffer.includes(`
32832
+ finish() {
32833
+ this.flushText();
32834
+ this.flushThinking();
32835
+ this.emitAgentEnd();
32836
+ }
32837
+ emitAgentEnd() {
32838
+ if (this.agentEndEmitted)
32839
+ return;
32840
+ this.agentEndEmitted = true;
32841
+ this.writeLine(formatAgentLogLine(this.logPrefix, "agent_end"));
32842
+ for (const cb of this.agentEndCallbacks)
32843
+ cb();
32844
+ }
32845
+ appendText(delta) {
32846
+ this.flushThinking();
32847
+ this.textBuffer += delta;
32848
+ this.assistantTextCapture.captureAssistantText(delta);
32849
+ if (this.textBuffer.includes(`
32778
32850
  `))
32851
+ this.flushText();
32852
+ }
32853
+ appendThinking(delta) {
32779
32854
  this.flushText();
32780
- }
32781
- appendThinking(delta) {
32782
- this.flushText();
32783
- this.thinkingBuffer += delta;
32784
- if (this.thinkingBuffer.includes(`
32855
+ this.thinkingBuffer += delta;
32856
+ if (this.thinkingBuffer.includes(`
32785
32857
  `))
32786
- this.flushThinking();
32787
- }
32788
- flushText() {
32789
- if (!this.textBuffer)
32790
- return;
32791
- const lines = this.textBuffer.split(`
32858
+ this.flushThinking();
32859
+ }
32860
+ flushText() {
32861
+ if (!this.textBuffer)
32862
+ return;
32863
+ const lines = this.textBuffer.split(`
32792
32864
  `);
32793
- const remaining = this.textBuffer.endsWith(`
32865
+ const remaining = this.textBuffer.endsWith(`
32794
32866
  `) ? "" : lines.pop() ?? "";
32795
- for (const line of lines) {
32796
- if (line.length > 0) {
32797
- this.writeLine(formatAgentLogLine(this.logPrefix, "text", line));
32867
+ for (const line of lines) {
32868
+ if (line.length > 0) {
32869
+ this.writeLine(formatAgentLogLine(this.logPrefix, "text", line));
32870
+ }
32798
32871
  }
32872
+ this.textBuffer = remaining;
32799
32873
  }
32800
- this.textBuffer = remaining;
32801
- }
32802
- flushThinking() {
32803
- if (!this.thinkingBuffer)
32804
- return;
32805
- const lines = this.thinkingBuffer.split(`
32874
+ flushThinking() {
32875
+ if (!this.thinkingBuffer)
32876
+ return;
32877
+ const lines = this.thinkingBuffer.split(`
32806
32878
  `);
32807
- const remaining = this.thinkingBuffer.endsWith(`
32879
+ const remaining = this.thinkingBuffer.endsWith(`
32808
32880
  `) ? "" : lines.pop() ?? "";
32809
- for (const line of lines) {
32810
- if (line.length > 0) {
32811
- this.writeLine(formatAgentLogLine(this.logPrefix, "thinking", line));
32881
+ for (const line of lines) {
32882
+ if (line.length > 0) {
32883
+ this.writeLine(formatAgentLogLine(this.logPrefix, "thinking", line));
32884
+ }
32812
32885
  }
32886
+ this.thinkingBuffer = remaining;
32813
32887
  }
32814
- this.thinkingBuffer = remaining;
32815
- }
32816
- notifyOutput() {
32817
- for (const cb of this.outputCallbacks)
32818
- cb();
32819
- }
32820
- writeLine(line) {
32821
- process.stderr.write(`${line}
32888
+ writeLine(line) {
32889
+ process.stderr.write(`${line}
32822
32890
  `);
32823
- this.emitLogLine?.(line);
32824
- }
32825
- }
32826
- var init_pi_sdk_stream_adapter = () => {};
32891
+ this.emitLogLine?.(line);
32892
+ }
32893
+ };
32894
+ });
32827
32895
 
32828
32896
  // src/infrastructure/services/remote-agents/pi-sdk/pi-sdk-agent-service.ts
32829
32897
  async function loadSdk2() {
@@ -33045,6 +33113,7 @@ var init_pi_sdk_agent_service = __esm(() => {
33045
33113
  const outputCallbacks = [];
33046
33114
  const agentEndCallbacks = [];
33047
33115
  const logLineCallbacks = [];
33116
+ const assistantTextCallbacks = [];
33048
33117
  const emitLogLine = (line) => {
33049
33118
  for (const cb of logLineCallbacks)
33050
33119
  cb(line);
@@ -33066,6 +33135,7 @@ var init_pi_sdk_agent_service = __esm(() => {
33066
33135
  finishExit,
33067
33136
  outputCallbacks,
33068
33137
  agentEndCallbacks,
33138
+ assistantTextCallbacks,
33069
33139
  emitLogLine
33070
33140
  });
33071
33141
  return {
@@ -33082,6 +33152,9 @@ var init_pi_sdk_agent_service = __esm(() => {
33082
33152
  },
33083
33153
  onLogLine: (cb) => {
33084
33154
  logLineCallbacks.push(cb);
33155
+ },
33156
+ onAssistantText: (cb) => {
33157
+ assistantTextCallbacks.push(cb);
33085
33158
  }
33086
33159
  };
33087
33160
  }
@@ -33095,6 +33168,7 @@ var init_pi_sdk_agent_service = __esm(() => {
33095
33168
  entry,
33096
33169
  outputCallbacks,
33097
33170
  agentEndCallbacks,
33171
+ assistantTextCallbacks,
33098
33172
  emitLogLine
33099
33173
  } = args2;
33100
33174
  let exited = false;
@@ -33122,14 +33196,12 @@ ${deferredResume}` : deferredResume;
33122
33196
  prependSystemOnNextResume = false;
33123
33197
  }
33124
33198
  const adapter = new PiSdkStreamAdapter(logPrefix, emitLogLine);
33125
- adapter.onOutput(() => {
33126
- entry.lastOutputAt = Date.now();
33127
- for (const cb of outputCallbacks)
33128
- cb();
33129
- });
33130
- adapter.onAgentEnd(() => {
33131
- for (const cb of agentEndCallbacks)
33132
- cb();
33199
+ wireNativeStreamAdapter({
33200
+ adapter,
33201
+ assistantTextCallbacks,
33202
+ outputCallbacks,
33203
+ agentEndCallbacks,
33204
+ entry
33133
33205
  });
33134
33206
  const onSessionEvent = (event) => {
33135
33207
  if (sdkSession.aborted)
@@ -75581,10 +75653,7 @@ Put your **complete** deliverable in the handoff message — not in session text
75581
75653
  }
75582
75654
 
75583
75655
  // ../../services/backend/prompts/utils/code-change-verification.ts
75584
- var CODE_CHANGE_VERIFICATION_COMMAND = "pnpm typecheck && pnpm test", CODE_CHANGE_VERIFICATION_CONFIRMATION;
75585
- var init_code_change_verification = __esm(() => {
75586
- CODE_CHANGE_VERIFICATION_CONFIRMATION = `- [ ] I confirm that I have run \`${CODE_CHANGE_VERIFICATION_COMMAND}\` (only required if code changes were made)`;
75587
- });
75656
+ var CODE_CHANGE_VERIFICATION_CONFIRMATION = "- [ ] I confirm that I have run typecheck and tests for the project (only required if code changes were made)";
75588
75657
 
75589
75658
  // ../../services/backend/prompts/cli/context/read.ts
75590
75659
  function contextReadCommand(params = {}) {
@@ -75663,7 +75732,6 @@ ${CODE_CHANGE_VERIFICATION_CONFIRMATION}
75663
75732
  \`\`\``;
75664
75733
  }
75665
75734
  var init_builder_to_planner = __esm(() => {
75666
- init_code_change_verification();
75667
75735
  init_context_disclosure();
75668
75736
  init_role_guidance_disclosure();
75669
75737
  });
@@ -75820,7 +75888,6 @@ ${CODE_CHANGE_VERIFICATION_CONFIRMATION}
75820
75888
  \`\`\``;
75821
75889
  }
75822
75890
  var init_planner_to_user = __esm(() => {
75823
- init_code_change_verification();
75824
75891
  init_context_disclosure();
75825
75892
  init_role_guidance_disclosure();
75826
75893
  });
@@ -75919,7 +75986,6 @@ ${CODE_CHANGE_VERIFICATION_CONFIRMATION}
75919
75986
  \`\`\``;
75920
75987
  }
75921
75988
  var init_solo_to_user = __esm(() => {
75922
- init_code_change_verification();
75923
75989
  init_context_disclosure();
75924
75990
  init_role_guidance_disclosure();
75925
75991
  });
@@ -76155,8 +76221,6 @@ var init_commands_reference = __esm(() => {
76155
76221
  init_command2();
76156
76222
  init_utils3();
76157
76223
  });
76158
- // ../../services/backend/src/domain/usecase/skills/modules/attachments/index.ts
76159
- var init_attachments = () => {};
76160
76224
 
76161
76225
  // ../../services/backend/prompts/cli/backlog/command.ts
76162
76226
  var init_command3 = __esm(() => {
@@ -76173,7 +76237,6 @@ var init_code_review = () => {};
76173
76237
 
76174
76238
  // ../../services/backend/src/domain/usecase/skills/registry.ts
76175
76239
  var init_registry3 = __esm(() => {
76176
- init_attachments();
76177
76240
  init_backlog();
76178
76241
  init_code_review();
76179
76242
  });
@@ -76203,8 +76266,7 @@ var init_glossary = __esm(() => {
76203
76266
  },
76204
76267
  {
76205
76268
  term: "attachments",
76206
- definition: "Message attachment types (task, backlog, message, snippet) and their compose, delivery, and task-read paths. " + "Use when adding or changing attachment UI, delivery XML, or agent-facing attachment formats.",
76207
- linkedSkillId: "attachments"
76269
+ definition: "Message attachment types (task, backlog, message, snippet) delivered in agent prompts as XML when users attach context to messages."
76208
76270
  },
76209
76271
  {
76210
76272
  term: "code-review",
@@ -76599,15 +76661,6 @@ function handleHandoffError(err) {
76599
76661
  } else if (err._tag === "InvalidChatroomId") {
76600
76662
  formatChatroomIdError(err.id);
76601
76663
  process.exit(1);
76602
- } else if (err._tag === "ArtifactsInvalid") {
76603
- formatError("One or more artifacts not found", [
76604
- "Please create artifacts first:",
76605
- `chatroom artifact create <chatroom-id> --from-file=... --filename=...`
76606
- ]);
76607
- process.exit(1);
76608
- } else if (err._tag === "ArtifactValidationFailed") {
76609
- formatError("Failed to validate artifacts", [String(err.cause)]);
76610
- process.exit(1);
76611
76664
  } else if (err._tag === "HandoffFailed") {
76612
76665
  console.error(`
76613
76666
  ❌ ERROR: Handoff failed`);
@@ -76670,7 +76723,7 @@ async function handoff(chatroomId, options, deps) {
76670
76723
  var handoffEffect = (chatroomId, options) => exports_Effect.gen(function* () {
76671
76724
  const session2 = yield* SessionService;
76672
76725
  const backend2 = yield* BackendService;
76673
- const { role, message, nextRole, attachedArtifactIds = [] } = options;
76726
+ const { role, message, nextRole } = options;
76674
76727
  const sessionId = yield* requireSessionIdEffect((a) => ({
76675
76728
  _tag: "NotAuthenticated",
76676
76729
  convexUrl: a.convexUrl,
@@ -76680,24 +76733,12 @@ var handoffEffect = (chatroomId, options) => exports_Effect.gen(function* () {
76680
76733
  _tag: "InvalidChatroomId",
76681
76734
  id: id3
76682
76735
  }));
76683
- if (attachedArtifactIds.length > 0) {
76684
- const areValid = yield* backend2.query(api.artifacts.validateArtifactIds, {
76685
- sessionId,
76686
- artifactIds: attachedArtifactIds
76687
- }).pipe(exports_Effect.mapError((cause3) => ({ _tag: "ArtifactValidationFailed", cause: cause3 })));
76688
- if (!areValid) {
76689
- return yield* exports_Effect.fail({ _tag: "ArtifactsInvalid" });
76690
- }
76691
- }
76692
76736
  const result = yield* backend2.mutation(api.messages.handoff, {
76693
76737
  sessionId,
76694
76738
  chatroomId,
76695
76739
  senderRole: role,
76696
76740
  content: message,
76697
- targetRole: nextRole,
76698
- ...attachedArtifactIds.length > 0 && {
76699
- attachedArtifactIds
76700
- }
76741
+ targetRole: nextRole
76701
76742
  }).pipe(exports_Effect.mapError((cause3) => {
76702
76743
  let errorData;
76703
76744
  if (cause3 instanceof ConvexError) {
@@ -76720,12 +76761,6 @@ var handoffEffect = (chatroomId, options) => exports_Effect.gen(function* () {
76720
76761
  convexUrl,
76721
76762
  supportsNativeIntegration: result.supportsNativeIntegration
76722
76763
  }));
76723
- if (attachedArtifactIds.length > 0) {
76724
- console.log(`\uD83D\uDCCE Attached artifacts: ${attachedArtifactIds.length}`);
76725
- attachedArtifactIds.forEach((id3) => {
76726
- console.log(` • ${id3}`);
76727
- });
76728
- }
76729
76764
  });
76730
76765
  });
76731
76766
  var init_handoff = __esm(() => {
@@ -85912,7 +85947,7 @@ var init_crash_loop_tracker = __esm(() => {
85912
85947
  });
85913
85948
 
85914
85949
  // ../../services/backend/src/domain/entities/participant.ts
85915
- var NATIVE_WAITING_ACTION = "native:waiting", NATIVE_TASK_INJECTED_ACTION = "native:task-injected", ONLINE_OR_STARTING_STATUSES;
85950
+ var NATIVE_WAITING_ACTION = "native:waiting", NATIVE_TASK_INJECTED_ACTION = "native:task-injected", NATIVE_HANDOFF_REMINDER = "Reminder: Use the handoff command to send your response to the team.", ONLINE_OR_STARTING_STATUSES;
85916
85951
  var init_participant = __esm(() => {
85917
85952
  ONLINE_OR_STARTING_STATUSES = new Set([
85918
85953
  "agent.waiting",
@@ -86017,9 +86052,6 @@ function isInjectableNativeAction(action) {
86017
86052
  return true;
86018
86053
  return action === NATIVE_WAITING_ACTION;
86019
86054
  }
86020
- function shouldEmitNativeWaitingOnTurnEnd(lastStatus) {
86021
- return lastStatus !== "task.acknowledged" && lastStatus !== "task.inProgress";
86022
- }
86023
86055
  function isNativeIdleAfterTaskComplete(participant) {
86024
86056
  return participant.lastSeenAction === NATIVE_TASK_INJECTED_ACTION && participant.lastStatus === "task.completed";
86025
86057
  }
@@ -87137,6 +87169,16 @@ class AgentProcessManager {
87137
87169
  }
87138
87170
  await service3.resumeTurn(slot.pid, args2.prompt);
87139
87171
  }
87172
+ async injectHarnessReminder(chatroomId, role, prompt) {
87173
+ const key = agentKey3(chatroomId, role);
87174
+ const slot = this.slots.get(key);
87175
+ if (!slot?.pid || !slot.harness)
87176
+ return;
87177
+ const service3 = this.deps.agentServices.get(slot.harness);
87178
+ if (!service3?.resumeTurn)
87179
+ return;
87180
+ await service3.resumeTurn(slot.pid, prompt);
87181
+ }
87140
87182
  async stop(opts) {
87141
87183
  const key = agentKey3(opts.chatroomId, opts.role);
87142
87184
  const slot = this.slots.get(key);
@@ -87267,9 +87309,20 @@ class AgentProcessManager {
87267
87309
  console.log(`[AgentProcessManager] ⛔ Terminal provider error for ${opts.role} — emitted agent.startFailed`);
87268
87310
  return;
87269
87311
  }
87270
- const emitted = await this.emitNativeWaiting(opts.chatroomId, opts.role, opts.harness, "turn-end");
87271
- if (emitted) {
87272
- console.log(`[AgentProcessManager] ✅ Native harness idle for ${opts.role} (native:waiting)`);
87312
+ try {
87313
+ const result = await this.deps.backend.mutation(api.participants.handleNativeAgentEnd, {
87314
+ sessionId: this.deps.sessionId,
87315
+ chatroomId: opts.chatroomId,
87316
+ role: opts.role
87317
+ });
87318
+ if (result?.needsHandoffReminder) {
87319
+ await this.injectHarnessReminder(opts.chatroomId, opts.role, NATIVE_HANDOFF_REMINDER);
87320
+ console.log(`[AgentProcessManager] ⏩ Handoff reminder injected for ${opts.role}`);
87321
+ return;
87322
+ }
87323
+ console.log(`[AgentProcessManager] ✅ Native agent_end handled for ${opts.role}`);
87324
+ } catch (err) {
87325
+ console.log(` ⚠️ Failed native agent_end for ${opts.role}: ${err.message}`);
87273
87326
  }
87274
87327
  }
87275
87328
  async handleExit(opts) {
@@ -88035,25 +88088,9 @@ class AgentProcessManager {
88035
88088
  this.registerSpawnCallbacks(slot, opts, spawnResult, pid);
88036
88089
  await this.emitNativeWaiting(opts.chatroomId, opts.role, opts.agentHarness);
88037
88090
  }
88038
- async emitNativeWaiting(chatroomId, role, harness, reason = "spawn") {
88091
+ async emitNativeWaiting(chatroomId, role, harness) {
88039
88092
  if (!getHarnessCapabilities(harness).supportsNativeIntegration)
88040
88093
  return false;
88041
- if (reason === "turn-end") {
88042
- try {
88043
- const participant = await this.deps.backend.query(api.participants.getByRole, {
88044
- sessionId: this.deps.sessionId,
88045
- chatroomId,
88046
- role
88047
- });
88048
- if (!shouldEmitNativeWaitingOnTurnEnd(participant?.lastStatus)) {
88049
- console.log(`[AgentProcessManager] Skipping native:waiting for ${role} — active work (${participant?.lastStatus})`);
88050
- return false;
88051
- }
88052
- } catch (err) {
88053
- console.log(` ⚠️ Failed to check status before native:waiting for ${role}: ${err.message}`);
88054
- return false;
88055
- }
88056
- }
88057
88094
  try {
88058
88095
  await this.deps.backend.mutation(api.participants.join, {
88059
88096
  sessionId: this.deps.sessionId,
@@ -88224,7 +88261,6 @@ var init_agent_process_manager = __esm(() => {
88224
88261
  init_classify_resume_storm_reason();
88225
88262
  init_terminal_provider_error();
88226
88263
  init_handle_turn_completed();
88227
- init_predicates();
88228
88264
  init_spawn_policy();
88229
88265
  init_agent_lifecycle_runtime();
88230
88266
  init_agent_lifecycle_types();
@@ -105859,7 +105895,7 @@ handoffCommandGroup.command("view-template").description("Print the handoff mess
105859
105895
  process.exit(1);
105860
105896
  }
105861
105897
  });
105862
- handoffCommandGroup.requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role").requiredOption("--next-role <nextRole>", "Role to hand off to").option("--attach-artifact <artifactId>", "Attach artifact to handoff (can be used multiple times)", collectMultiValueOption, []).action(async (options) => {
105898
+ handoffCommandGroup.requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role").requiredOption("--next-role <nextRole>", "Role to hand off to").action(async (options) => {
105863
105899
  await maybeRequireAuth();
105864
105900
  const { decode: decode5 } = await Promise.resolve().then(() => exports_decode);
105865
105901
  const stdinContent = await readStdin();
@@ -105881,8 +105917,7 @@ handoffCommandGroup.requiredOption("--chatroom-id <id>", "Chatroom identifier").
105881
105917
  await handoff2(options.chatroomId, {
105882
105918
  role: options.role,
105883
105919
  message,
105884
- nextRole: options.nextRole,
105885
- attachedArtifactIds: options.attachArtifact || []
105920
+ nextRole: options.nextRole
105886
105921
  });
105887
105922
  });
105888
105923
  var backlogCommand = program2.command("backlog").description("Manage task queue and backlog");
@@ -106169,4 +106204,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
106169
106204
  });
106170
106205
  program2.parse();
106171
106206
 
106172
- //# debugId=2DFDF6706DFDE76764756E2164756E21
106207
+ //# debugId=2E6B4710975E536E64756E2164756E21