replicas-engine 0.1.303 → 0.1.304

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.
Files changed (2) hide show
  1. package/dist/src/index.js +100 -5
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -41,6 +41,7 @@ function codexReasoningEffortForThinkingLevel(thinkingLevel) {
41
41
  }
42
42
 
43
43
  // ../shared/src/event.ts
44
+ var CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE = "claude-partial-message";
44
45
  var ACCEPTED_USER_MESSAGE_SOURCE = "replicas-chat-turn-accepted";
45
46
  var USER_MESSAGE_ID_PAYLOAD_KEY = "replicasMessageId";
46
47
  var CODEX_ASP_ITEM_ID_PAYLOAD_KEY = "codexAspItemId";
@@ -301,7 +302,7 @@ var WORKSPACE_SIZES = ["small", "large"];
301
302
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
302
303
 
303
304
  // ../shared/src/e2b.ts
304
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-12-v6";
305
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-12-v7";
305
306
 
306
307
  // ../shared/src/runtime-env.ts
307
308
  function parsePosixEnvFile(content) {
@@ -5825,6 +5826,11 @@ var COMMAND_PROTECTION_SAFE_TOOLS = /* @__PURE__ */ new Set([
5825
5826
  "WebFetch",
5826
5827
  "LS"
5827
5828
  ]);
5829
+ var CLAUDE_PARTIAL_MESSAGE_FLUSH_MS = 500;
5830
+ function supportsClaudeThinkingDisplay(model) {
5831
+ const normalized = model.toLowerCase();
5832
+ return AGENT_MODELS.claude.includes(normalized) || normalized === "opus" || /^claude-(?:opus|sonnet|haiku)-4/.test(normalized);
5833
+ }
5828
5834
  var TOOL_INPUT_HANDLERS = {
5829
5835
  ExitPlanMode: {
5830
5836
  getRequest: () => ({
@@ -5919,6 +5925,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
5919
5925
  pendingTurn = null;
5920
5926
  pendingInterrupt = false;
5921
5927
  activeBackgroundTasks = /* @__PURE__ */ new Set();
5928
+ partialMessageStreams = /* @__PURE__ */ new Map();
5929
+ partialMessageFlushTimers = /* @__PURE__ */ new Map();
5922
5930
  systemPromptOverride;
5923
5931
  toolsOverride;
5924
5932
  mcpServersConfig;
@@ -6300,6 +6308,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6300
6308
  ...this.mcpServersConfig ? { mcpServers: this.mcpServersConfig } : {},
6301
6309
  env: queryEnv,
6302
6310
  model: resolvedModel,
6311
+ includePartialMessages: true,
6312
+ ...supportsClaudeThinkingDisplay(resolvedModel) ? { thinking: { type: "adaptive", display: "summarized" } } : {},
6303
6313
  ...thinkingLevel ? { effort: thinkingLevel } : {},
6304
6314
  canUseTool: this.buildCanUseTool(),
6305
6315
  ...ENGINE_ENV.REPLICAS_DISABLE_GH_PR_MERGE ? {
@@ -6372,6 +6382,11 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6372
6382
  this.sessionLinearForwarder = null;
6373
6383
  this.sessionLoop = null;
6374
6384
  this.activeBackgroundTasks.clear();
6385
+ for (const timer of this.partialMessageFlushTimers.values()) {
6386
+ clearTimeout(timer);
6387
+ }
6388
+ this.partialMessageFlushTimers.clear();
6389
+ this.partialMessageStreams.clear();
6375
6390
  }
6376
6391
  resolvePendingTurn() {
6377
6392
  const pending = this.pendingTurn;
@@ -6498,6 +6513,80 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6498
6513
  events
6499
6514
  };
6500
6515
  }
6516
+ partialMessageStreamKey(message) {
6517
+ return `${message.session_id}:${message.parent_tool_use_id ?? "root"}`;
6518
+ }
6519
+ clearPartialMessageFlush(key) {
6520
+ const timer = this.partialMessageFlushTimers.get(key);
6521
+ if (!timer) return;
6522
+ clearTimeout(timer);
6523
+ this.partialMessageFlushTimers.delete(key);
6524
+ }
6525
+ flushPartialMessageStream(key, status = "in_progress") {
6526
+ this.clearPartialMessageFlush(key);
6527
+ const stream = this.partialMessageStreams.get(key);
6528
+ if (!stream || !stream.text && !stream.thinking) return;
6529
+ this.onEvent({
6530
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
6531
+ type: CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE,
6532
+ payload: {
6533
+ streamId: stream.streamId,
6534
+ parent_tool_use_id: stream.parent_tool_use_id,
6535
+ ...stream.text ? { text: stream.text } : {},
6536
+ ...stream.thinking ? { thinking: stream.thinking } : {},
6537
+ status
6538
+ }
6539
+ });
6540
+ }
6541
+ schedulePartialMessageFlush(key) {
6542
+ if (this.partialMessageFlushTimers.has(key)) return;
6543
+ this.partialMessageFlushTimers.set(key, setTimeout(() => {
6544
+ this.partialMessageFlushTimers.delete(key);
6545
+ this.flushPartialMessageStream(key);
6546
+ }, CLAUDE_PARTIAL_MESSAGE_FLUSH_MS));
6547
+ }
6548
+ handlePartialAssistantMessage(message) {
6549
+ const key = this.partialMessageStreamKey(message);
6550
+ const streamEvent = message.event;
6551
+ if (streamEvent.type === "message_start") {
6552
+ this.clearPartialMessageFlush(key);
6553
+ this.partialMessageStreams.set(key, {
6554
+ streamId: streamEvent.message.id || key,
6555
+ parent_tool_use_id: message.parent_tool_use_id,
6556
+ text: "",
6557
+ thinking: ""
6558
+ });
6559
+ return;
6560
+ }
6561
+ const stream = this.partialMessageStreams.get(key);
6562
+ if (!stream) return;
6563
+ if (streamEvent.type === "content_block_start") {
6564
+ const block = streamEvent.content_block;
6565
+ if (block.type === "text" && block.text) {
6566
+ stream.text += block.text;
6567
+ this.schedulePartialMessageFlush(key);
6568
+ } else if (block.type === "thinking" && block.thinking) {
6569
+ stream.thinking += block.thinking;
6570
+ this.schedulePartialMessageFlush(key);
6571
+ }
6572
+ return;
6573
+ }
6574
+ if (streamEvent.type === "content_block_delta") {
6575
+ const delta = streamEvent.delta;
6576
+ if (delta.type === "text_delta") {
6577
+ stream.text += delta.text;
6578
+ this.schedulePartialMessageFlush(key);
6579
+ } else if (delta.type === "thinking_delta") {
6580
+ stream.thinking += delta.thinking;
6581
+ this.schedulePartialMessageFlush(key);
6582
+ }
6583
+ return;
6584
+ }
6585
+ if (streamEvent.type === "message_stop") {
6586
+ this.flushPartialMessageStream(key, "completed");
6587
+ this.partialMessageStreams.delete(key);
6588
+ }
6589
+ }
6501
6590
  async initialize() {
6502
6591
  const historyDir = join13(homedir11(), ".replicas", "claude");
6503
6592
  await mkdir10(historyDir, { recursive: true });
@@ -6512,6 +6601,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6512
6601
  await this.onSaveSessionId(this.sessionId);
6513
6602
  console.log(`[ClaudeManager] Captured and persisted session ID: ${this.sessionId}`);
6514
6603
  }
6604
+ if (message.type === "stream_event") {
6605
+ this.handlePartialAssistantMessage(message);
6606
+ return;
6607
+ }
6515
6608
  this.trackNativeCompaction(message);
6516
6609
  await this.recordEvent(message);
6517
6610
  }
@@ -6734,7 +6827,7 @@ var AspClient = class {
6734
6827
  // src/managers/codex-asp/app-server-process.ts
6735
6828
  var DEFAULT_CODEX_BINARY = "codex";
6736
6829
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
6737
- var ENGINE_PACKAGE_VERSION = "0.1.303";
6830
+ var ENGINE_PACKAGE_VERSION = "0.1.304";
6738
6831
  var INITIALIZE_METHOD = "initialize";
6739
6832
  var INITIALIZED_NOTIFICATION = "initialized";
6740
6833
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -9660,9 +9753,11 @@ var ChatService = class {
9660
9753
  }
9661
9754
  }
9662
9755
  }
9663
- this.touch(chat);
9664
- this.observeCurrentBranches(chat).catch(() => {
9665
- });
9756
+ if (event.type !== CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE) {
9757
+ this.touch(chat);
9758
+ this.observeCurrentBranches(chat).catch(() => {
9759
+ });
9760
+ }
9666
9761
  this.publish({
9667
9762
  type: "chat.turn.delta",
9668
9763
  payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.303",
3
+ "version": "0.1.304",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",