replicas-engine 0.1.1188 → 0.1.1190

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.
@@ -8,12 +8,12 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-DCCLTZ2Z.js";
12
- import "./chunk-VXPWAQR2.js";
13
- import "./chunk-WJLWPHUO.js";
14
- import "./chunk-R6I3LT27.js";
11
+ } from "./chunk-GBJVNN7M.js";
12
+ import "./chunk-6GGRJKT4.js";
13
+ import "./chunk-WUOSHIHP.js";
14
+ import "./chunk-IXT5Q2OM.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-4T2K6OBK.js";
16
+ import "./chunk-XCLNV3EB.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
  export {
19
19
  CODEX_ULTRAFAST_SERVICE_TIER,
@@ -5,14 +5,14 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-VXPWAQR2.js";
8
+ } from "./chunk-6GGRJKT4.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-4T2K6OBK.js";
15
+ } from "./chunk-XCLNV3EB.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-R6I3LT27.js";
7
+ } from "./chunk-IXT5Q2OM.js";
8
8
  import {
9
9
  isRecord as isRecord2
10
10
  } from "./chunk-UZSNFLDQ.js";
@@ -18,7 +18,7 @@ import {
18
18
  isValidAgentProvider,
19
19
  parsePosixEnvFile,
20
20
  readReplicasRuntimeEnv
21
- } from "./chunk-4T2K6OBK.js";
21
+ } from "./chunk-XCLNV3EB.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-VXPWAQR2.js";
13
+ } from "./chunk-6GGRJKT4.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-WJLWPHUO.js";
17
+ } from "./chunk-WUOSHIHP.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-R6I3LT27.js";
21
+ } from "./chunk-IXT5Q2OM.js";
22
22
  import {
23
23
  isRecord
24
24
  } from "./chunk-UZSNFLDQ.js";
@@ -55,7 +55,7 @@ import {
55
55
  resolveOpenAICompatibleModelsUrl,
56
56
  splitMothershipInstructions,
57
57
  withTimeout
58
- } from "./chunk-4T2K6OBK.js";
58
+ } from "./chunk-XCLNV3EB.js";
59
59
 
60
60
  // src/managers/codex-token-manager.ts
61
61
  import { promises as fs } from "fs";
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
291
291
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
292
292
  await this.applyCredentialsResponse(data);
293
293
  setAgentCredentialSnapshot("codex", data);
294
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-LSWA5KWR.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-I7VZCDSH.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
313
313
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
314
314
  await this.applyCredentialsResponse(data);
315
315
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
316
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-LSWA5KWR.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-I7VZCDSH.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -1773,7 +1773,7 @@ function turnsToAspTranscript(threadId, updatedAt, sourceTurns) {
1773
1773
  });
1774
1774
  return { threadId, updatedAt, turns };
1775
1775
  }
1776
- async function buildThreadStartParams(workingDirectory, request, developerInstructions, serviceTier, subagentMcpParentChatId, autoCompactTokens = null) {
1776
+ async function buildThreadStartParams(workingDirectory, request, developerInstructions, serviceTier, subagentMcpParentChatId, autoCompactTokens = null, originChatId) {
1777
1777
  const additionalDirectories = await getAgentAdditionalDirectories();
1778
1778
  return {
1779
1779
  model: request.model ?? DEFAULT_MODEL,
@@ -1787,6 +1787,7 @@ async function buildThreadStartParams(workingDirectory, request, developerInstru
1787
1787
  web_search: ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === "ollama" ? "disabled" : "live",
1788
1788
  model_reasoning_summary: "auto",
1789
1789
  ...autoCompactTokens ? { model_auto_compact_token_limit: autoCompactTokens } : {},
1790
+ ...originChatId ? { "shell_environment_policy.set.REPLICAS_CHAT_ID": originChatId } : {},
1790
1791
  ...subagentMcpParentChatId ? {
1791
1792
  // Codex gates its native collaboration tools on `agents.enabled`; `features.multi_agent` is now a no-op.
1792
1793
  "agents.enabled": false,
@@ -1796,7 +1797,7 @@ async function buildThreadStartParams(workingDirectory, request, developerInstru
1796
1797
  experimentalRawEvents: false
1797
1798
  };
1798
1799
  }
1799
- async function buildThreadResumeParams(workingDirectory, threadId, request, developerInstructions, serviceTier, subagentMcpParentChatId, autoCompactTokens = null) {
1800
+ async function buildThreadResumeParams(workingDirectory, threadId, request, developerInstructions, serviceTier, subagentMcpParentChatId, autoCompactTokens = null, originChatId) {
1800
1801
  const additionalDirectories = await getAgentAdditionalDirectories();
1801
1802
  return {
1802
1803
  threadId,
@@ -1811,6 +1812,7 @@ async function buildThreadResumeParams(workingDirectory, threadId, request, deve
1811
1812
  web_search: ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === "ollama" ? "disabled" : "live",
1812
1813
  model_reasoning_summary: "auto",
1813
1814
  ...autoCompactTokens ? { model_auto_compact_token_limit: autoCompactTokens } : {},
1815
+ ...originChatId ? { "shell_environment_policy.set.REPLICAS_CHAT_ID": originChatId } : {},
1814
1816
  ...subagentMcpParentChatId ? {
1815
1817
  // Codex gates its native collaboration tools on `agents.enabled`; `features.multi_agent` is now a no-op.
1816
1818
  "agents.enabled": false,
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES
6
- } from "./chunk-4T2K6OBK.js";
6
+ } from "./chunk-XCLNV3EB.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-4T2K6OBK.js";
8
+ } from "./chunk-XCLNV3EB.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  execFileAsync
6
- } from "./chunk-R6I3LT27.js";
6
+ } from "./chunk-IXT5Q2OM.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-4T2K6OBK.js";
9
+ } from "./chunk-XCLNV3EB.js";
10
10
 
11
11
  // src/utils/codex-agent-env.ts
12
12
  function buildCodexAgentEnv(source = process.env) {
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.1188";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1190";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -93,6 +93,9 @@ var THINKING_LEVELS_BY_AGENT = {
93
93
  opencode: STANDARD_THINKING_LEVELS,
94
94
  pi: STANDARD_THINKING_LEVELS
95
95
  };
96
+ function isValidThinkingLevel(value) {
97
+ return VALID_THINKING_LEVELS.some((l) => l === value);
98
+ }
96
99
  var CODEX_REASONING_EFFORT_BY_THINKING_LEVEL = {
97
100
  low: "low",
98
101
  medium: "medium",
@@ -1575,6 +1578,7 @@ var sendChatMessageRequestSchema = z4.object({
1575
1578
  })).optional(),
1576
1579
  canvasUploadIds: z4.array(z4.string().min(1)).optional(),
1577
1580
  thinkingLevel: z4.enum(VALID_THINKING_LEVELS).optional(),
1581
+ inheritThinkingLevel: z4.boolean().optional(),
1578
1582
  goalMode: z4.boolean().optional(),
1579
1583
  fastMode: z4.boolean().optional(),
1580
1584
  ultrafastMode: z4.boolean().optional(),
@@ -5391,6 +5395,7 @@ If \`@replicas/sdk\` cannot be imported, use the gateway with workspace authenti
5391
5395
  curl -sS --fail-with-body -X POST "\${REPLICAS_MONOLITH_URL:-$MONOLITH_URL}/v1/engine/slack/api" \\
5392
5396
  -H "Authorization: Bearer $REPLICAS_ENGINE_SECRET" \\
5393
5397
  -H "X-Workspace-Id: \${REPLICAS_WORKSPACE_ID:-$WORKSPACE_ID}" \\
5398
+ -H "X-Replicas-Chat-Id: \${REPLICAS_CHAT_ID:-}" \\
5394
5399
  -H "Content-Type: application/json" \\
5395
5400
  --data-binary @-
5396
5401
  \`\`\`
@@ -9913,6 +9918,7 @@ export {
9913
9918
  AGENT,
9914
9919
  SUBAGENT_MCP_HARNESSES,
9915
9920
  isValidAgentProvider,
9921
+ isValidThinkingLevel,
9916
9922
  codexReasoningEffortForThinkingLevel,
9917
9923
  getProviderDisplayName,
9918
9924
  detectAgentQuotaLimit,
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  AspClient
6
- } from "./chunk-WJLWPHUO.js";
6
+ } from "./chunk-WUOSHIHP.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -11,7 +11,7 @@ import {
11
11
  codexReasoningEffortForThinkingLevel,
12
12
  isRecord,
13
13
  readOllamaAuthEnv
14
- } from "./chunk-4T2K6OBK.js";
14
+ } from "./chunk-XCLNV3EB.js";
15
15
 
16
16
  // src/managers/codex-asp/notification-dispatch.ts
17
17
  var TURN_STARTED_METHOD = "turn/started";
@@ -172,10 +172,10 @@ function uuidV7() {
172
172
  }
173
173
 
174
174
  // src/managers/muse-msp.ts
175
- function spawnMuseMsp(workingDirectory) {
175
+ function spawnMuseMsp(workingDirectory, env) {
176
176
  const child = spawn("muse", ["serve", "--disable-sandbox", "--trust-workspace"], {
177
177
  cwd: workingDirectory,
178
- env: { ...process.env, MUSE_NO_AUTO_UPDATE: "1", NO_COLOR: "1" },
178
+ env: { ...process.env, MUSE_NO_AUTO_UPDATE: "1", NO_COLOR: "1", ...env },
179
179
  stdio: ["pipe", "pipe", "pipe"]
180
180
  });
181
181
  return { child, client: new AspClient({ stdin: child.stdin, stdout: child.stdout, jsonRpcVersion: "2.0" }) };
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-TUZLVYYH.js";
7
- import "./chunk-VXPWAQR2.js";
8
- import "./chunk-R6I3LT27.js";
6
+ } from "./chunk-2U32TFQX.js";
7
+ import "./chunk-6GGRJKT4.js";
8
+ import "./chunk-IXT5Q2OM.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-4T2K6OBK.js";
12
+ import "./chunk-XCLNV3EB.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/command-protection-hook.ts
@@ -13,12 +13,12 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-TBMJWQJX.js";
16
+ } from "./chunk-ZXUVZYHY.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-WJLWPHUO.js";
21
- import "./chunk-R6I3LT27.js";
20
+ } from "./chunk-WUOSHIHP.js";
21
+ import "./chunk-IXT5Q2OM.js";
22
22
  import {
23
23
  AGENT,
24
24
  OPENCODE_GO_PROVIDER,
@@ -28,7 +28,7 @@ import {
28
28
  headlessAgentUsagePath,
29
29
  isRecord,
30
30
  withTimeout
31
- } from "./chunk-4T2K6OBK.js";
31
+ } from "./chunk-XCLNV3EB.js";
32
32
  import "./chunk-VEQXQN22.js";
33
33
 
34
34
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  evaluateCommandProtection,
28
28
  extractToolCommand,
29
29
  reportCommandProtectionBlock
30
- } from "./chunk-TUZLVYYH.js";
30
+ } from "./chunk-2U32TFQX.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -64,10 +64,10 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-TBMJWQJX.js";
67
+ } from "./chunk-ZXUVZYHY.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
- } from "./chunk-NIT22CZW.js";
70
+ } from "./chunk-TX3C2WLH.js";
71
71
  import {
72
72
  ACCOUNT_RATE_LIMITS_READ_METHOD,
73
73
  AsyncLock,
@@ -139,7 +139,7 @@ import {
139
139
  timestampFromSeconds,
140
140
  upsertCredentialFileLines,
141
141
  writeSecureCredentialFile
142
- } from "./chunk-DCCLTZ2Z.js";
142
+ } from "./chunk-GBJVNN7M.js";
143
143
  import {
144
144
  ENGINE_ENV,
145
145
  monolithRequest,
@@ -148,15 +148,15 @@ import {
148
148
  reloadEngineEnv,
149
149
  resolveDiffBase,
150
150
  setAgentCredentialSnapshot
151
- } from "./chunk-VXPWAQR2.js";
151
+ } from "./chunk-6GGRJKT4.js";
152
152
  import {
153
153
  getCodexModelProvider
154
- } from "./chunk-WJLWPHUO.js";
154
+ } from "./chunk-WUOSHIHP.js";
155
155
  import {
156
156
  SUBPROCESS_MAX_BUFFER,
157
157
  execAsync,
158
158
  execFileAsync
159
- } from "./chunk-R6I3LT27.js";
159
+ } from "./chunk-IXT5Q2OM.js";
160
160
  import {
161
161
  isRecord as isRecord2
162
162
  } from "./chunk-UZSNFLDQ.js";
@@ -332,6 +332,7 @@ import {
332
332
  isTransientErrorText,
333
333
  isValidAgentProvider,
334
334
  isValidEngineLogSessionId,
335
+ isValidThinkingLevel,
335
336
  lastUserBlockText,
336
337
  learnedSkillFormatInstruction,
337
338
  learnedSkillsManifestSchema,
@@ -383,7 +384,7 @@ import {
383
384
  workspaceTokenRequestSchema,
384
385
  workspaceTokenResponseSchema,
385
386
  wrapInTag
386
- } from "./chunk-4T2K6OBK.js";
387
+ } from "./chunk-XCLNV3EB.js";
387
388
  import {
388
389
  cloneMcpConfig,
389
390
  ensureCompatibilityImports,
@@ -11405,6 +11406,7 @@ var CodingAgentManager = class {
11405
11406
  onUsageUpdate;
11406
11407
  linearSessionId;
11407
11408
  chatId;
11409
+ originChatId;
11408
11410
  hostOnTurnComplete;
11409
11411
  onProcessingChanged;
11410
11412
  onMessageStarted;
@@ -11418,6 +11420,9 @@ var CodingAgentManager = class {
11418
11420
  unreadSteers = /* @__PURE__ */ new Map();
11419
11421
  steersInFlight = /* @__PURE__ */ new Map();
11420
11422
  lastSenderKey;
11423
+ // Unset until this process sends a turn, so a restart can't mistake the first one for a change.
11424
+ sentTurn = false;
11425
+ lastCustomInstructions;
11421
11426
  onLastSenderKeyChanged;
11422
11427
  constructor(options) {
11423
11428
  this.workingDirectory = options.workingDirectory ?? ENGINE_ENV.WORKSPACE_ROOT;
@@ -11433,6 +11438,7 @@ var CodingAgentManager = class {
11433
11438
  this.usesAutoCompactTokens = options.provider === "claude" || options.provider === "codex";
11434
11439
  this.linearSessionId = options.linearSessionId;
11435
11440
  this.chatId = options.chatId;
11441
+ this.originChatId = options.originChatId;
11436
11442
  this.hostOnTurnComplete = options.onTurnComplete;
11437
11443
  this.onProcessingChanged = options.onProcessingChanged ?? (() => {
11438
11444
  });
@@ -11513,7 +11519,14 @@ var CodingAgentManager = class {
11513
11519
  const stopped = signal.aborted;
11514
11520
  if (stopped && !await this.keepStoppedRequest(delivered)) return;
11515
11521
  await this.saveLastSenderKey(senderKey);
11516
- if (!stopped) await processMessage(delivered, signal);
11522
+ if (stopped) return;
11523
+ const instructionsChanged = this.sentTurn && this.lastCustomInstructions !== request.customInstructions && !request.goalMode && !request.message.trimStart().startsWith("/");
11524
+ this.sentTurn = true;
11525
+ this.lastCustomInstructions = request.customInstructions;
11526
+ const note = wrapInTag("Your instructions changed since your previous turn. Earlier turns followed the old version: follow the current instructions from here on, and leave earlier replies as they are.", REPLICAS_INSTRUCTIONS_TAG);
11527
+ await processMessage(instructionsChanged ? { ...delivered, message: `${delivered.message}
11528
+
11529
+ ${note}` } : delivered, signal);
11517
11530
  },
11518
11531
  this.onProcessingChanged,
11519
11532
  this.onMessageStarted,
@@ -13379,7 +13392,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13379
13392
  }
13380
13393
  /** Query inputs shared by real sessions and slash-command discovery. */
13381
13394
  async buildSharedQueryOptions() {
13382
- const env = buildClaudeAgentEnv(this.subagentMcpParentChatId() ? { CLAUDE_CODE_STREAM_CLOSE_TIMEOUT: "900000" } : void 0);
13395
+ const env = buildClaudeAgentEnv({
13396
+ ...this.subagentMcpParentChatId() && { CLAUDE_CODE_STREAM_CLOSE_TIMEOUT: "900000" },
13397
+ ...this.originChatId && { REPLICAS_CHAT_ID: this.originChatId }
13398
+ });
13383
13399
  const additionalDirectories = await getAgentAdditionalDirectories();
13384
13400
  let plugins = [];
13385
13401
  let enableAllSkills = false;
@@ -13407,7 +13423,9 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13407
13423
  const systemPrompt = {
13408
13424
  type: "preset",
13409
13425
  preset: "claude_code",
13410
- append: combinedInstructions
13426
+ append: combinedInstructions,
13427
+ // A recorded prompt ignores a new append on resume, so edited instructions would never apply.
13428
+ snapshot: false
13411
13429
  };
13412
13430
  const shared = await this.buildSharedQueryOptions();
13413
13431
  const interactiveAllowed = enableInteractiveTools && resolvedPermissionMode === "plan";
@@ -14563,10 +14581,16 @@ var CodexAspManager = class extends CodingAgentManager {
14563
14581
  const previous = coldResume ? await host.client.request(THREAD_READ_METHOD, { threadId: existingThreadId, includeTurns: true }).catch(() => null) : null;
14564
14582
  const response = previous?.thread.modelProvider && previous.thread.modelProvider !== getCodexModelProvider(ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD) ? await this.continueWithNewProvider(host, previous.thread, request, developerInstructions, serviceTier2) : await host.client.request(
14565
14583
  THREAD_RESUME_METHOD,
14566
- await buildThreadResumeParams(this.workingDirectory, existingThreadId, request, developerInstructions, serviceTier2, subagentMcpParentChatId, this.autoCompactTokens)
14584
+ await buildThreadResumeParams(this.workingDirectory, existingThreadId, request, developerInstructions, serviceTier2, subagentMcpParentChatId, this.autoCompactTokens, this.originChatId)
14567
14585
  );
14568
14586
  this.currentThreadId = response.thread.id;
14569
14587
  this.activeServiceTier = response.serviceTier;
14588
+ if (this.attachedClient === host.client && developerInstructions && developerInstructions !== this.attachedDeveloperInstructions) {
14589
+ await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
14590
+ threadId: this.currentThreadId,
14591
+ items: [{ type: "message", role: "developer", content: [{ type: "input_text", text: developerInstructions }] }]
14592
+ });
14593
+ }
14570
14594
  this.attachedClient = host.client;
14571
14595
  this.attachedModel = requestedModel;
14572
14596
  this.attachedDeveloperInstructions = developerInstructions ?? null;
@@ -14578,7 +14602,7 @@ var CodexAspManager = class extends CodingAgentManager {
14578
14602
  const serviceTier = await this.resolveRequestedServiceTier(host, request);
14579
14603
  const threadStartResponse = await host.client.request(
14580
14604
  THREAD_START_METHOD,
14581
- await buildThreadStartParams(this.workingDirectory, request, developerInstructions, serviceTier, subagentMcpParentChatId, this.autoCompactTokens)
14605
+ await buildThreadStartParams(this.workingDirectory, request, developerInstructions, serviceTier, subagentMcpParentChatId, this.autoCompactTokens, this.originChatId)
14582
14606
  );
14583
14607
  const threadId = threadStartResponse.thread.id;
14584
14608
  this.currentThreadId = threadId;
@@ -14600,7 +14624,7 @@ var CodexAspManager = class extends CodingAgentManager {
14600
14624
  await writeFile4(transcriptPath, text, "utf8");
14601
14625
  const response = await host.client.request(
14602
14626
  THREAD_START_METHOD,
14603
- await buildThreadStartParams(this.workingDirectory, request, developerInstructions, serviceTier, this.subagentMcpParentChatId(), this.autoCompactTokens)
14627
+ await buildThreadStartParams(this.workingDirectory, request, developerInstructions, serviceTier, this.subagentMcpParentChatId(), this.autoCompactTokens, this.originChatId)
14604
14628
  );
14605
14629
  await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
14606
14630
  threadId: response.thread.id,
@@ -15850,7 +15874,7 @@ var MuseManager = class extends CodingAgentManager {
15850
15874
  }
15851
15875
  async start(model) {
15852
15876
  if (this.process) return;
15853
- const { child, client } = spawnMuseMsp(this.workingDirectory);
15877
+ const { child, client } = spawnMuseMsp(this.workingDirectory, this.originChatId ? { REPLICAS_CHAT_ID: this.originChatId } : void 0);
15854
15878
  this.process = child;
15855
15879
  this.client = client;
15856
15880
  client.on("notification", (notification) => this.handleNotification(notification));
@@ -16595,11 +16619,14 @@ var OpencodeManager = class extends CodingAgentManager {
16595
16619
  }
16596
16620
  };
16597
16621
  }
16598
- const server3 = await createOpencodeServer({
16622
+ if (this.originChatId) process.env.REPLICAS_CHAT_ID = this.originChatId;
16623
+ const serverStart = createOpencodeServer({
16599
16624
  port: 0,
16600
16625
  timeout: OPENCODE_SERVER_STARTUP_TIMEOUT_MS,
16601
16626
  config
16602
16627
  });
16628
+ delete process.env.REPLICAS_CHAT_ID;
16629
+ const server3 = await serverStart;
16603
16630
  const client = createOpencodeClient({
16604
16631
  baseUrl: server3.url,
16605
16632
  fetch: opencodeFetch,
@@ -59458,6 +59485,7 @@ function normalizePersistedChat(chat) {
59458
59485
  id: chat.id,
59459
59486
  provider: chat.provider,
59460
59487
  ...typeof chat.model === "string" && chat.model ? { model: chat.model } : {},
59488
+ ...isValidThinkingLevel(chat.thinkingLevel) ? { thinkingLevel: chat.thinkingLevel } : {},
59461
59489
  title: chat.title,
59462
59490
  ...chat.displayName ? { displayName: chat.displayName } : {},
59463
59491
  createdAt: chat.createdAt,
@@ -59752,7 +59780,11 @@ var ChatService = class {
59752
59780
  };
59753
59781
  }
59754
59782
  const savedModel = chat.persisted.model ?? (!request.model ? extractLatestContextUsage((await chat.provider.getHistory()).events, chat.persisted.provider)?.model : void 0);
59755
- request = { ...request, model: request.model ?? savedModel ?? void 0 };
59783
+ request = {
59784
+ ...request,
59785
+ model: request.model ?? savedModel ?? void 0,
59786
+ thinkingLevel: request.thinkingLevel ?? (request.inheritThinkingLevel ? chat.persisted.thinkingLevel : void 0)
59787
+ };
59756
59788
  return await chat.provider.enqueueMessage(
59757
59789
  request,
59758
59790
  (result, acceptedMessage) => this.handleMessageAccepted(
@@ -59801,6 +59833,7 @@ var ChatService = class {
59801
59833
  const previousPersistedResponses = chat.persisted.acceptedSendResponses;
59802
59834
  const previousLastMessageText = chat.persisted.lastMessageText;
59803
59835
  const previousModel = chat.persisted.model;
59836
+ const previousThinkingLevel = chat.persisted.thinkingLevel;
59804
59837
  const previousUpdatedAt = chat.persisted.updatedAt;
59805
59838
  const previousFork = chat.persisted.fork;
59806
59839
  const previousPendingForkHandoff = chat.persisted.pendingForkHandoff;
@@ -59821,6 +59854,7 @@ var ChatService = class {
59821
59854
  }
59822
59855
  chat.persisted.lastMessageText = typedMessage.trim().slice(0, LAST_MESSAGE_PREVIEW_MAX) || null;
59823
59856
  chat.persisted.model = acceptedMessage.model ?? previousModel;
59857
+ chat.persisted.thinkingLevel = acceptedMessage.thinkingLevel;
59824
59858
  chat.persisted.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
59825
59859
  if (chat.persisted.pendingForkHandoff && chat.persisted.fork) {
59826
59860
  chat.persisted.pendingForkHandoff = false;
@@ -59839,6 +59873,7 @@ var ChatService = class {
59839
59873
  chat.persisted.acceptedSendResponses = previousPersistedResponses;
59840
59874
  chat.persisted.lastMessageText = previousLastMessageText;
59841
59875
  chat.persisted.model = previousModel;
59876
+ chat.persisted.thinkingLevel = previousThinkingLevel;
59842
59877
  chat.persisted.updatedAt = previousUpdatedAt;
59843
59878
  chat.persisted.fork = previousFork;
59844
59879
  chat.persisted.pendingForkHandoff = previousPendingForkHandoff;
@@ -59873,7 +59908,7 @@ var ChatService = class {
59873
59908
  }).catch((error) => {
59874
59909
  console.error("[ChatService] Failed to publish accepted turn:", { chatId, messageId: result.messageId, error });
59875
59910
  });
59876
- if (chat.persisted.model !== previousModel || previousPendingForkHandoff) {
59911
+ if (chat.persisted.model !== previousModel || chat.persisted.thinkingLevel !== previousThinkingLevel || previousPendingForkHandoff) {
59877
59912
  await this.publish({ type: "chat.updated", payload: { chat: this.toSummary(chat) } }).catch((error) => {
59878
59913
  console.error("[ChatService] Failed to publish accepted chat update:", { chatId, error });
59879
59914
  });
@@ -60493,6 +60528,13 @@ var ChatService = class {
60493
60528
  if (persisted.parentChatId === void 0) {
60494
60529
  persisted.parentChatId = null;
60495
60530
  }
60531
+ let originChatId = persisted.id;
60532
+ for (let chat = persisted; chat; ) {
60533
+ const next = chat.parentChatId ?? chat.fork?.source.chatId;
60534
+ if (!next) break;
60535
+ originChatId = next;
60536
+ chat = this.chats.get(next)?.persisted;
60537
+ }
60496
60538
  const baseProvider = persisted.provider;
60497
60539
  const historyFilePath = join28(HISTORY_DIR_BY_PROVIDER[persisted.provider], `${persisted.id}.jsonl`);
60498
60540
  const managerOptions = {
@@ -60509,6 +60551,7 @@ var ChatService = class {
60509
60551
  onUsageUpdate: onProviderUsage,
60510
60552
  fallbackContext,
60511
60553
  chatId: persisted.id,
60554
+ originChatId,
60512
60555
  onModelSwitched,
60513
60556
  onChatCredential,
60514
60557
  lastSenderKey: persisted.lastSenderKey,
@@ -60576,6 +60619,7 @@ var ChatService = class {
60576
60619
  id: chat.persisted.id,
60577
60620
  provider: chat.persisted.provider,
60578
60621
  model: chat.persisted.model,
60622
+ thinkingLevel: chat.persisted.thinkingLevel,
60579
60623
  title: chat.persisted.title,
60580
60624
  displayName: chat.persisted.displayName,
60581
60625
  createdAt: chat.persisted.createdAt,
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  publishedPullRequestUrls
6
- } from "./chunk-NIT22CZW.js";
6
+ } from "./chunk-TX3C2WLH.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-4T2K6OBK.js";
12
+ } from "./chunk-XCLNV3EB.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/services/post-tool-pr-notifier.ts
@@ -9,7 +9,7 @@ import {
9
9
  spawnSubagentRequestSchema,
10
10
  subagentResponseSchema,
11
11
  waitSubagentRequestSchema
12
- } from "./chunk-4T2K6OBK.js";
12
+ } from "./chunk-XCLNV3EB.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/subagent-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1188",
3
+ "version": "0.1.1190",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -22,6 +22,7 @@ async function requestResponse(path, options = {}) {
22
22
  const headers = new Headers(options.headers);
23
23
  headers.set('Authorization', `Bearer ${engineSecret}`);
24
24
  headers.set('X-Workspace-Id', workspaceId);
25
+ if (process.env.REPLICAS_CHAT_ID) headers.set('X-Replicas-Chat-Id', process.env.REPLICAS_CHAT_ID);
25
26
  if (options.body !== undefined) headers.set('Content-Type', 'application/json');
26
27
  const response = await fetch(`${monolithUrl}${path}`, {
27
28
  ...options,