replicas-engine 0.1.1483 → 0.1.1485

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
  listCodexModelsForDetails,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-4G2LYMEB.js";
12
- import "./chunk-4NG26S2U.js";
13
- import "./chunk-TWBHAQGG.js";
14
- import "./chunk-LMU7L7FM.js";
11
+ } from "./chunk-AV6SAXMO.js";
12
+ import "./chunk-GPKTNFK6.js";
13
+ import "./chunk-JXHWGTUR.js";
14
+ import "./chunk-WQHZJA2S.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-IQQG6HNF.js";
16
+ import "./chunk-K2FAYKHI.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
  export {
19
19
  CODEX_ULTRAFAST_SERVICE_TIER,
@@ -11,15 +11,15 @@ import {
11
11
  resolveDiffBase,
12
12
  runGitCommand,
13
13
  setAgentCredentialSnapshot
14
- } from "./chunk-4NG26S2U.js";
14
+ } from "./chunk-GPKTNFK6.js";
15
15
  import {
16
16
  AppServerProcess,
17
17
  buildCodexAgentEnv
18
- } from "./chunk-TWBHAQGG.js";
18
+ } from "./chunk-JXHWGTUR.js";
19
19
  import {
20
20
  SUBPROCESS_MAX_BUFFER,
21
21
  execFileAsync
22
- } from "./chunk-LMU7L7FM.js";
22
+ } from "./chunk-WQHZJA2S.js";
23
23
  import {
24
24
  isRecord
25
25
  } from "./chunk-UZSNFLDQ.js";
@@ -57,7 +57,7 @@ import {
57
57
  resolveOpenAICompatibleModelsUrl,
58
58
  splitMothershipInstructions,
59
59
  withTimeout
60
- } from "./chunk-IQQG6HNF.js";
60
+ } from "./chunk-K2FAYKHI.js";
61
61
 
62
62
  // src/managers/codex-token-manager.ts
63
63
  import { promises as fs } from "fs";
@@ -320,7 +320,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
320
320
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
321
321
  await this.applyCredentialsResponse(data);
322
322
  setAgentCredentialSnapshot("codex", data);
323
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-KP42UBYG.js");
323
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-KWA3JTHY.js");
324
324
  await restartCodexAspHostIfRunning2();
325
325
  });
326
326
  await this.start(true);
@@ -342,7 +342,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
342
342
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
343
343
  await this.applyCredentialsResponse(data);
344
344
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
345
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-KP42UBYG.js");
345
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-KWA3JTHY.js");
346
346
  await restartCodexAspHostIfRunning2();
347
347
  }
348
348
  setAgentCredentialSnapshot("codex", data);
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-LMU7L7FM.js";
7
+ } from "./chunk-WQHZJA2S.js";
8
8
  import {
9
9
  isRecord as isRecord2
10
10
  } from "./chunk-UZSNFLDQ.js";
@@ -21,7 +21,7 @@ import {
21
21
  provisionedDeviceSchema,
22
22
  readReplicasRuntimeEnv,
23
23
  serializePosixEnvFile
24
- } from "./chunk-IQQG6HNF.js";
24
+ } from "./chunk-K2FAYKHI.js";
25
25
 
26
26
  // src/runtime-env-loader.ts
27
27
  import { readFileSync } from "fs";
@@ -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-TWBHAQGG.js";
6
+ } from "./chunk-JXHWGTUR.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -15,7 +15,7 @@ import {
15
15
  isRecord,
16
16
  readOllamaAuthEnv,
17
17
  readOpenAICompatibleAuthEnv
18
- } from "./chunk-IQQG6HNF.js";
18
+ } from "./chunk-K2FAYKHI.js";
19
19
 
20
20
  // src/managers/codex-asp/notification-dispatch.ts
21
21
  var TURN_STARTED_METHOD = "turn/started";
@@ -6,7 +6,7 @@ import {
6
6
  getOriginDefaultBranch,
7
7
  monolithRequest,
8
8
  runGitCommand
9
- } from "./chunk-4NG26S2U.js";
9
+ } from "./chunk-GPKTNFK6.js";
10
10
  import {
11
11
  extractCommandProtectionCommandText,
12
12
  findCommandProtectionGitLookups,
@@ -15,7 +15,7 @@ import {
15
15
  findScoutRepoWriteSignals,
16
16
  parseCommandProtectionRequest,
17
17
  withE2BRetry
18
- } from "./chunk-IQQG6HNF.js";
18
+ } from "./chunk-K2FAYKHI.js";
19
19
 
20
20
  // src/services/command-protection-service.ts
21
21
  import { readFile, stat } from "fs/promises";
@@ -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-LMU7L7FM.js";
6
+ } from "./chunk-WQHZJA2S.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-IQQG6HNF.js";
9
+ } from "./chunk-K2FAYKHI.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.1483";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1485";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -11459,6 +11459,7 @@ var ENGINE_PORT = 3737;
11459
11459
  var DESKTOP_STREAM_PORT = 6080;
11460
11460
  var DEVICES_DIR = ".ssh/replicas-devices";
11461
11461
  var DEVICE_SCREEN_FILE_SUFFIX = ".screen.json";
11462
+ var LOCAL_CONTROL_FILE_PREFIX = "desktop-";
11462
11463
 
11463
11464
  // ../shared/src/git.ts
11464
11465
  var GIT_CREDENTIAL_HELPER_FILENAME = ".git-credential-replicas";
@@ -14889,6 +14890,7 @@ var DEFAULT_USER_PREFERENCES = {
14889
14890
  open_prs_in_graphite: false,
14890
14891
  open_links_in_desktop_app: false,
14891
14892
  port_forwarding: false,
14893
+ local_control: false,
14892
14894
  spotify_controls: false,
14893
14895
  appshot_shortcut: "command",
14894
14896
  appshot_destination: "automatic",
@@ -14946,7 +14948,7 @@ function removeTag(text4, tag) {
14946
14948
  function stripReplicasInstructionBlock(text4) {
14947
14949
  return removeTag(text4, REPLICAS_INSTRUCTIONS_TAG);
14948
14950
  }
14949
- var MOTHERSHIP_EVENT_CHAT_NOTE = `The user doesn't see text you write in this turn. If it brings something they asked for, or a blocker that needs them, send it with ${REPLICAS_MCP_TOOLS.sendToChat}; otherwise update the board and end with a one-line note.`;
14951
+ var MOTHERSHIP_EVENT_CHAT_NOTE = `If a message the user typed in this turn is still unanswered, your final reply answers it and they see it. Otherwise they don't see text you write in this turn: if it brings something they asked for, or a blocker that needs them, send it with ${REPLICAS_MCP_TOOLS.sendToChat}; then update the board and end with a one-line note.`;
14950
14952
  var BOARD_ANSWER_NOTE = "The user answered on the board.";
14951
14953
  var BOARD_RULES = `- The board, a live status page you keep with \`${REPLICAS_MCP_TOOLS.updateBoard}\` in the Ships pane beside this chat, is the user's one view of the work: keep it covering every ship, pull request, deploy and blocker. Show ships, pull requests and Linear tickets as ship, pr and linear blocks, which stay current on their own, instead of describing their status. Keep exactly these sections, always in this order, leaving out any that are empty; when you add one, give it the position that keeps this order:
14952
14954
  - Questions (needs_you): only decisions you truly can't make, and blocked ships. Give each your recommendation and a choice. Make routine calls yourself, such as retries, small scope choices or test cleanup, and note them on the ship's row instead of asking.
@@ -14956,8 +14958,8 @@ var BOARD_RULES = `- The board, a live status page you keep with \`${REPLICAS_MC
14956
14958
  - On every \`finished\` and \`archived\` event, move that ship's rows out of Working, or remove them, so Working only lists ships that are working.
14957
14959
  - A ship with open pull requests is not done when it sends \`finished\`: Replicas fixes their CI failures and review comments automatically, then sends \`ready\` or \`needs_attention\`. On \`needs_attention\`, direct the ship, or add it to Questions only if you can't decide.
14958
14960
  - When a pull request should merge once it's approved and CI passes, call \`${REPLICAS_MCP_TOOLS.mergeWhenReady}\`: Replicas merges it and sends \`merged\`, or \`needs_attention\` saying why it can't. Never watch CI or pull requests with \`gh\`, sleep loops or wait scripts, and merge one yourself only when the user wants it merged right away.
14959
- - On every ship event and every answer the user gives on the board (marked "${BOARD_ANSWER_NOTE}"), act with tools on the answer or on any work the event unblocks, such as starting the next task once a pull request merges, and update the board. The user sees nothing you write in these turns: the only way to reach them is \`${REPLICAS_MCP_TOOLS.sendToChat}\`. Call it only for what they would want right now: a deliverable they asked for, with its media, links or answer (the finished video, the requested numbers); a failure or blocker that needs them, also on the board; or a request of theirs being done. Never for status, such as "PR #12 merged", "deploying", "it's on the board" or "I asked the ship to\u2026": the board and the chat's own rows show those. End the turn with a one-line note of what you did; only the activity log shows it.
14960
- - The chat is like texting an assistant: the user sees only your final reply to each message they type, plus what you send with \`${REPLICAS_MCP_TOOLS.sendToChat}\`, never your tool calls or earlier text. Write in a line or two with links, and include any media inline. Anything that needs the user later goes on the board. Never restate the board in chat: no status tables, per-ship lists or summaries of what ships did.
14961
+ - On every ship event and every answer the user gives on the board (marked "${BOARD_ANSWER_NOTE}"), act with tools on the answer or on any work the event unblocks, such as starting the next task once a pull request merges, and update the board. The user sees nothing you write in these turns, unless a message they typed is still unanswered because it arrived during the turn: then your final reply answers it, as in any turn they start. Otherwise the only way to reach them is \`${REPLICAS_MCP_TOOLS.sendToChat}\`. Call it only for what they would want right now: a deliverable they asked for, with its media, links or answer (the finished video, the requested numbers); a failure or blocker that needs them, also on the board; or a request of theirs being done. Never for status, such as "PR #12 merged", "deploying", "it's on the board" or "I asked the ship to\u2026": the board and the chat's own rows show those. End the turn with a one-line note of what you did; only the activity log shows it.
14962
+ - The chat is like texting an assistant: the user sees only your final reply to each message they type, plus what you send with \`${REPLICAS_MCP_TOOLS.sendToChat}\`, never your tool calls or earlier text. Answer every message they type in chat, even one that arrives during a ship event or board answer, and never only on the board: if they ask something while you handle an event, answer that question, not just the event. Write in a line or two with links, and include any media inline. Anything that needs the user later goes on the board. Never restate the board in chat: no status tables, per-ship lists or summaries of what ships did.
14961
14963
  - When the user picks a choice or clicks a button that messages or merges, Replicas removes that item from the board for you. Add it back, or a new item, only if the user is still needed.
14962
14964
  `;
14963
14965
  var MOTHERSHIP_INSTRUCTIONS_BLOCK = new RegExp(`\\s*<${MOTHERSHIP_INSTRUCTIONS_TAG}>\\n([\\s\\S]*?)\\n</${MOTHERSHIP_INSTRUCTIONS_TAG}>`);
@@ -19537,7 +19539,7 @@ var VOICE_WAVEFORM = {
19537
19539
  };
19538
19540
 
19539
19541
  // ../shared/src/e2b.ts
19540
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-11-11-v3";
19542
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-11-11-v5";
19541
19543
 
19542
19544
  // ../shared/src/e2b-retry.ts
19543
19545
  var DEFAULT_BACKOFFS_MS = [2e3, 5e3];
@@ -21988,6 +21990,7 @@ export {
21988
21990
  DESKTOP_STREAM_PORT,
21989
21991
  DEVICES_DIR,
21990
21992
  DEVICE_SCREEN_FILE_SUFFIX,
21993
+ LOCAL_CONTROL_FILE_PREFIX,
21991
21994
  GIT_CREDENTIAL_HELPER_FILENAME,
21992
21995
  GITHUB_CREDENTIAL_REFRESH_PATH,
21993
21996
  GITLAB_CREDENTIAL_REFRESH_PATH,
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-IQQG6HNF.js";
8
+ } from "./chunk-K2FAYKHI.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -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-IQQG6HNF.js";
6
+ } from "./chunk-K2FAYKHI.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -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-SP3N5LQ3.js";
7
- import "./chunk-4NG26S2U.js";
8
- import "./chunk-LMU7L7FM.js";
6
+ } from "./chunk-IL5H3ARK.js";
7
+ import "./chunk-GPKTNFK6.js";
8
+ import "./chunk-WQHZJA2S.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-IQQG6HNF.js";
12
+ import "./chunk-K2FAYKHI.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/command-protection-hook.ts
@@ -14,12 +14,12 @@ import {
14
14
  recoverCompletedTurn,
15
15
  spawnMuseMsp,
16
16
  startMuseSession
17
- } from "./chunk-NQUKBNPC.js";
17
+ } from "./chunk-H4EAIFP5.js";
18
18
  import {
19
19
  AppServerProcess,
20
20
  buildCodexAgentEnv
21
- } from "./chunk-TWBHAQGG.js";
22
- import "./chunk-LMU7L7FM.js";
21
+ } from "./chunk-JXHWGTUR.js";
22
+ import "./chunk-WQHZJA2S.js";
23
23
  import {
24
24
  AGENT,
25
25
  OPENCODE_GO_PROVIDER,
@@ -29,7 +29,7 @@ import {
29
29
  headlessAgentUsagePath,
30
30
  isRecord,
31
31
  withTimeout
32
- } from "./chunk-IQQG6HNF.js";
32
+ } from "./chunk-K2FAYKHI.js";
33
33
  import "./chunk-VEQXQN22.js";
34
34
 
35
35
  // 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-SP3N5LQ3.js";
30
+ } from "./chunk-IL5H3ARK.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -65,10 +65,10 @@ import {
65
65
  spawnMuseMsp,
66
66
  startMuseSession,
67
67
  uuidV7
68
- } from "./chunk-NQUKBNPC.js";
68
+ } from "./chunk-H4EAIFP5.js";
69
69
  import {
70
70
  publishedPullRequestUrls
71
- } from "./chunk-IVN3HEHP.js";
71
+ } from "./chunk-VEJ25S6F.js";
72
72
  import {
73
73
  ACCOUNT_RATE_LIMITS_READ_METHOD,
74
74
  AsyncLock,
@@ -143,7 +143,7 @@ import {
143
143
  timestampFromSeconds,
144
144
  upsertCredentialFileLines,
145
145
  writeSecureCredentialFile
146
- } from "./chunk-4G2LYMEB.js";
146
+ } from "./chunk-AV6SAXMO.js";
147
147
  import {
148
148
  ENGINE_ENV,
149
149
  UNQUOTED_PATHS_CONFIG,
@@ -154,15 +154,15 @@ import {
154
154
  resolveDiffBase,
155
155
  setAgentCredentialSnapshot,
156
156
  setLinearSessionId
157
- } from "./chunk-4NG26S2U.js";
157
+ } from "./chunk-GPKTNFK6.js";
158
158
  import {
159
159
  getCodexModelProvider
160
- } from "./chunk-TWBHAQGG.js";
160
+ } from "./chunk-JXHWGTUR.js";
161
161
  import {
162
162
  SUBPROCESS_MAX_BUFFER,
163
163
  execAsync,
164
164
  execFileAsync
165
- } from "./chunk-LMU7L7FM.js";
165
+ } from "./chunk-WQHZJA2S.js";
166
166
  import {
167
167
  isRecord as isRecord2
168
168
  } from "./chunk-UZSNFLDQ.js";
@@ -237,6 +237,7 @@ import {
237
237
  InFlightMap,
238
238
  LEARNED_SKILLS_MANIFEST_PATH,
239
239
  LEARNED_SKILL_DIR_PREFIX,
240
+ LOCAL_CONTROL_FILE_PREFIX,
240
241
  MAX_CANVAS_FILE_BYTES,
241
242
  MAX_CANVAS_PREVIEW_BYTES,
242
243
  MAX_CODEX_GOAL_OBJECTIVE_CHARS,
@@ -442,7 +443,7 @@ import {
442
443
  workspaceTokenRequestSchema,
443
444
  workspaceTokenResponseSchema,
444
445
  wrapInTag
445
- } from "./chunk-IQQG6HNF.js";
446
+ } from "./chunk-K2FAYKHI.js";
446
447
  import {
447
448
  cloneMcpConfig,
448
449
  ensureCompatibilityImports,
@@ -11021,7 +11022,8 @@ async function startDeviceRelays(names, paths, signal) {
11021
11022
  }
11022
11023
 
11023
11024
  // src/services/device-service.ts
11024
- import { mkdir as mkdir7, rm as rm3, writeFile as writeFile4 } from "fs/promises";
11025
+ import { readdirSync } from "fs";
11026
+ import { mkdir as mkdir7, readdir as readdir2, rm as rm3, writeFile as writeFile4 } from "fs/promises";
11025
11027
  import { join as join8 } from "path";
11026
11028
  var DEVICES_DIR2 = join8(ENGINE_ENV.HOME_DIR, DEVICES_DIR);
11027
11029
  var TAILSCALED_UNIT = "replicas-tailscaled";
@@ -11076,7 +11078,8 @@ async function joinTailnet(authKey, workspaceId, signal) {
11076
11078
  }
11077
11079
  async function connectDevices(signal) {
11078
11080
  const { REPLICAS_ENV_DEVICES: devices, TS_AUTHKEY: authKey, REPLICAS_WORKSPACE_ID: workspaceId } = ENGINE_ENV;
11079
- await rm3(DEVICES_DIR2, { recursive: true, force: true });
11081
+ const stale = (await readdir2(DEVICES_DIR2).catch(() => [])).filter((entry) => !entry.startsWith(LOCAL_CONTROL_FILE_PREFIX));
11082
+ await Promise.all(stale.map((entry) => rm3(join8(DEVICES_DIR2, entry), { recursive: true, force: true })));
11080
11083
  const tailnetKey = devices.some((device) => device.host !== null) ? authKey : void 0;
11081
11084
  if (!tailnetKey) await execFileAsync("sudo", ["systemctl", "stop", TAILSCALED_UNIT], { signal }).catch(() => void 0);
11082
11085
  if (devices.length === 0) return;
@@ -11107,6 +11110,21 @@ function devicesInstruction() {
11107
11110
  ...screens.length > 0 ? [`To see and control the screen of ${screens.join(", ")}, run \`replicas computer screen <name>\`: it shows on this desktop, where the other \`replicas computer\` commands drive it. Prefer \`ssh\` when a command does the job.`] : []
11108
11111
  ].join(" ");
11109
11112
  }
11113
+ function localControlInstruction() {
11114
+ let entries;
11115
+ try {
11116
+ entries = readdirSync(DEVICES_DIR2);
11117
+ } catch {
11118
+ return void 0;
11119
+ }
11120
+ const computers = entries.flatMap((entry) => entry.startsWith(LOCAL_CONTROL_FILE_PREFIX) && entry.endsWith(".conf") ? [`\`${entry.slice(LOCAL_CONTROL_FILE_PREFIX.length, -".conf".length)}\``] : []);
11121
+ if (computers.length === 0) return void 0;
11122
+ return [
11123
+ `The user turned on local control, so you can run commands on their own computer through the Replicas desktop app running there: ${computers.join(", ")}. Use \`ssh <name> '<command>'\`, \`scp\` and \`rsync\` as usual. Commands run as the user in their home directory with their login shell and no terminal, output streams back as it is produced, and a command stops if the connection drops.`,
11124
+ "It is a personal machine with the user's files and accounts: change only what the task needs, and ask before anything destructive or hard to undo.",
11125
+ 'It works only while the desktop app is running there with local control on. If `ssh` closes straight away, such as "Connection closed by UNKNOWN port 65535", the app isn\'t running or local control is off: tell the user and ask them to open it. If a command gets "Operation not permitted" on the user\'s files, macOS is blocking the app: ask the user to allow Replicas under System Settings \u2192 Privacy & Security \u2192 Full Disk Access.'
11126
+ ].join(" ");
11127
+ }
11110
11128
 
11111
11129
  // src/services/chat/chat-service.ts
11112
11130
  import { statSync as statSync4 } from "fs";
@@ -11169,6 +11187,7 @@ function workspaceChatEventSignals(event) {
11169
11187
  }
11170
11188
  return signals;
11171
11189
  }
11190
+ var mergeIndexes = /* @__PURE__ */ new WeakMap();
11172
11191
  var emptyIndex = () => ({
11173
11192
  byStreamId: /* @__PURE__ */ new Map(),
11174
11193
  byJson: /* @__PURE__ */ new Map(),
@@ -11235,29 +11254,44 @@ var CACHE_PLACEHOLDER_PAYLOAD_KEY = "replicasCachePlaceholder";
11235
11254
  function mergeWorkspaceChatHistoryEvents(primary, supplemental, removedMessageIds = []) {
11236
11255
  const [flush] = supplemental;
11237
11256
  const flushStreamId = supplemental.length === 1 && removedMessageIds.length === 0 ? getEventStreamId(flush) : null;
11257
+ const cached = mergeIndexes.get(primary);
11238
11258
  if (flushStreamId !== null && getUserMessageId(flush) === null && getComparableUserMessage(flush) === null) {
11239
- const slot = primary.findIndex((event) => getEventStreamId(event) === flushStreamId);
11240
- if (slot !== -1 && !primary.some((event) => event.type === QUEUED_MESSAGE_REMOVED_EVENT_TYPE)) {
11259
+ const slot = cached ? cached.index.byStreamId.get(flushStreamId) ?? -1 : primary.findIndex((event) => getEventStreamId(event) === flushStreamId);
11260
+ if (slot !== -1 && (cached ? cached.removedIds.size === 0 : !primary.some((event) => event.type === QUEUED_MESSAGE_REMOVED_EVENT_TYPE))) {
11241
11261
  const merged2 = [...primary];
11242
11262
  merged2[slot] = flush;
11263
+ if (cached) {
11264
+ mergeIndexes.delete(primary);
11265
+ unindexEvent(cached.index, primary[slot], slot);
11266
+ indexMergedEvent(cached.index, flush, slot);
11267
+ mergeIndexes.set(merged2, { ...cached, latestMs: Math.max(cached.latestMs, workspaceChatEventSignals(flush).timestampMs || 0) });
11268
+ }
11243
11269
  return merged2;
11244
11270
  }
11245
11271
  }
11246
11272
  const removed = new Set(removedMessageIds);
11247
- for (const events of [primary, supplemental]) {
11248
- for (const event of events) {
11249
- for (const messageId of getRemovedMessageIds(event)) removed.add(messageId);
11250
- }
11273
+ for (const messageId of cached?.removedIds ?? primary.flatMap(getRemovedMessageIds)) removed.add(messageId);
11274
+ for (const event of supplemental) {
11275
+ for (const messageId of getRemovedMessageIds(event)) removed.add(messageId);
11251
11276
  }
11252
11277
  if (removed.size > 0) {
11253
- primary = excludeQueuedAcceptedEvents(primary, [], [...removed]);
11278
+ if (!cached || [...removed].some((messageId) => !cached.removedIds.has(messageId))) {
11279
+ const kept2 = excludeQueuedAcceptedEvents(primary, [], [...removed]);
11280
+ if (kept2.length !== primary.length) primary = kept2;
11281
+ }
11254
11282
  supplemental = excludeQueuedAcceptedEvents(supplemental, [], [...removed]);
11255
11283
  }
11256
11284
  if (supplemental.length === 0) return [...primary];
11257
11285
  const merged = [...primary];
11258
- const index = emptyIndex();
11259
- for (let position = 0; position < primary.length; position++) {
11260
- indexMergedEvent(index, primary[position], position);
11286
+ const kept = mergeIndexes.get(primary);
11287
+ mergeIndexes.delete(primary);
11288
+ const index = kept?.index ?? emptyIndex();
11289
+ let latestMs = kept?.latestMs ?? 0;
11290
+ if (!kept) {
11291
+ for (let position = 0; position < primary.length; position++) {
11292
+ indexMergedEvent(index, primary[position], position);
11293
+ latestMs = Math.max(latestMs, workspaceChatEventSignals(primary[position]).timestampMs || 0);
11294
+ }
11261
11295
  }
11262
11296
  const additions = [];
11263
11297
  const additionsIndex = emptyIndex();
@@ -11293,10 +11327,20 @@ function mergeWorkspaceChatHistoryEvents(primary, supplemental, removedMessageId
11293
11327
  indexMergedEvent(listIndex, event, position);
11294
11328
  }
11295
11329
  }
11296
- return insertChronologically(
11297
- merged.filter((event) => event !== null),
11298
- additions.filter((event) => event !== null)
11299
- );
11330
+ const added = additions.filter((event) => event !== null);
11331
+ const addedSet = new Set(added);
11332
+ for (const event of supplemental) if (!addedSet.has(event)) latestMs = Math.max(latestMs, workspaceChatEventSignals(event).timestampMs || 0);
11333
+ const result = merged.filter((event) => event !== null);
11334
+ if (result.length === merged.length && added.every((event) => !(workspaceChatEventSignals(event).timestampMs < latestMs))) {
11335
+ for (const event of [...added].sort((a, b) => workspaceChatEventSignals(a).timestampMs - workspaceChatEventSignals(b).timestampMs)) {
11336
+ indexMergedEvent(index, event, result.length);
11337
+ latestMs = Math.max(latestMs, workspaceChatEventSignals(event).timestampMs || 0);
11338
+ result.push(event);
11339
+ }
11340
+ mergeIndexes.set(result, { index, latestMs, removedIds: removed });
11341
+ return result;
11342
+ }
11343
+ return insertChronologically(result, added);
11300
11344
  }
11301
11345
  function insertChronologically(existing, additions) {
11302
11346
  const timestampMs2 = (event) => workspaceChatEventSignals(event).timestampMs;
@@ -11325,7 +11369,7 @@ import {
11325
11369
  } from "@anthropic-ai/claude-agent-sdk";
11326
11370
  import { randomUUID as randomUUID3 } from "crypto";
11327
11371
  import { dirname as dirname3, join as join11 } from "path";
11328
- import { mkdir as mkdir8, readdir as readdir3, readFile as readFile7 } from "fs/promises";
11372
+ import { mkdir as mkdir8, readdir as readdir4, readFile as readFile7 } from "fs/promises";
11329
11373
  import { homedir as homedir7 } from "os";
11330
11374
 
11331
11375
  // src/utils/linear-converter.ts
@@ -12630,6 +12674,7 @@ ${note}` };
12630
12674
  const repositorySystemPromptInstruction = this.getRepositorySystemPromptInstruction();
12631
12675
  const environmentInstruction = this.getEnvironmentSystemPromptInstruction();
12632
12676
  const deviceInstruction = devicesInstruction();
12677
+ const localControlGuidance = localControlInstruction();
12633
12678
  const enginePortProtectionInstruction = this.getEnginePortProtectionInstruction();
12634
12679
  const memoryInstruction = includeMemory ? this.buildMemoryInstruction() : void 0;
12635
12680
  const parts = [];
@@ -12647,6 +12692,9 @@ ${note}` };
12647
12692
  if (deviceInstruction) {
12648
12693
  parts.push(deviceInstruction);
12649
12694
  }
12695
+ if (localControlGuidance) {
12696
+ parts.push(localControlGuidance);
12697
+ }
12650
12698
  if (repositorySystemPromptInstruction) {
12651
12699
  parts.push(repositorySystemPromptInstruction);
12652
12700
  }
@@ -12903,7 +12951,7 @@ var PullRequestCheckService = class {
12903
12951
  var pullRequestCheckService = new PullRequestCheckService();
12904
12952
 
12905
12953
  // src/services/skill-registry-service.ts
12906
- import { readFile as readFile6, readdir as readdir2, stat } from "fs/promises";
12954
+ import { readFile as readFile6, readdir as readdir3, stat } from "fs/promises";
12907
12955
  import { dirname as dirname2, isAbsolute, join as join10, relative, resolve } from "path";
12908
12956
  var REGISTRY_ROOT_DIR = ".replicas/skill-registries";
12909
12957
  var REGISTRY_MANIFEST = "manifest.json";
@@ -13097,7 +13145,7 @@ function uniqueStandaloneSkills(skills) {
13097
13145
  }
13098
13146
  async function safeReadDir(path7) {
13099
13147
  try {
13100
- return await readdir2(path7, { withFileTypes: true });
13148
+ return await readdir3(path7, { withFileTypes: true });
13101
13149
  } catch (error) {
13102
13150
  if (isNotFoundError(error)) return [];
13103
13151
  throw error;
@@ -14029,7 +14077,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14029
14077
  async forwardWorkflowAgentTranscripts(taskId) {
14030
14078
  const workflow = this.workflowTranscripts.get(taskId);
14031
14079
  if (!workflow || this.ambientTaskIds.has(taskId)) return;
14032
- for (const file of await readdir3(workflow.dir).catch(() => [])) {
14080
+ for (const file of await readdir4(workflow.dir).catch(() => [])) {
14033
14081
  const agentId = /^agent-(.+)\.jsonl$/.exec(file)?.[1];
14034
14082
  if (!agentId) continue;
14035
14083
  const offset = workflow.offsets.get(file) ?? 0;
@@ -16578,7 +16626,7 @@ ${text.slice(-24e3)}`
16578
16626
  };
16579
16627
 
16580
16628
  // src/managers/cursor-manager.ts
16581
- import { mkdir as mkdir11, readFile as readFile9, readdir as readdir4 } from "fs/promises";
16629
+ import { mkdir as mkdir11, readFile as readFile9, readdir as readdir5 } from "fs/promises";
16582
16630
  import { basename as basename2, dirname as dirname5, extname, join as join14 } from "path";
16583
16631
  import { Agent as CursorAgent2, AuthenticationError, CursorSdkError } from "@cursor/sdk";
16584
16632
 
@@ -16711,7 +16759,7 @@ function extractCursorCommandDescription(content) {
16711
16759
  async function listCursorCommandsInDirectory(directory) {
16712
16760
  let entries;
16713
16761
  try {
16714
- entries = await readdir4(directory, { withFileTypes: true });
16762
+ entries = await readdir5(directory, { withFileTypes: true });
16715
16763
  } catch (error) {
16716
16764
  if (isRecord2(error) && error.code === "ENOENT") return [];
16717
16765
  console.warn("[CursorManager] Failed to read slash command directory:", error);
@@ -41108,7 +41156,7 @@ async function probeMcpEndpoint(url3) {
41108
41156
  }
41109
41157
 
41110
41158
  // ../node_modules/.bun/pi-mcp-adapter@2.32.1+f2da34192be1730e/node_modules/pi-mcp-adapter/npx-resolver.ts
41111
- import { existsSync as existsSync9, readFileSync as readFileSync2, realpathSync, readdirSync, statSync as statSync2, writeFileSync as writeFileSync3, renameSync, mkdirSync as mkdirSync2, openSync, readSync, closeSync, unlinkSync } from "fs";
41159
+ import { existsSync as existsSync9, readFileSync as readFileSync2, realpathSync, readdirSync as readdirSync2, statSync as statSync2, writeFileSync as writeFileSync3, renameSync, mkdirSync as mkdirSync2, openSync, readSync, closeSync, unlinkSync } from "fs";
41112
41160
  import { join as join16, dirname as dirname8, extname as extname2, resolve as resolve2, sep } from "path";
41113
41161
 
41114
41162
  // ../node_modules/.bun/pi-mcp-adapter@2.32.1+f2da34192be1730e/node_modules/pi-mcp-adapter/abort.ts
@@ -41405,7 +41453,7 @@ function findCachedPackageDir(cacheDir, packageName, exactVersion) {
41405
41453
  const npxDir = join16(cacheDir, "_npx");
41406
41454
  if (!existsSync9(npxDir)) return null;
41407
41455
  const packagePathParts = packageName.startsWith("@") ? packageName.split("/") : [packageName];
41408
- const candidates = readdirSync(npxDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
41456
+ const candidates = readdirSync2(npxDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
41409
41457
  const full = join16(npxDir, entry.name);
41410
41458
  const mtime = safeStatMtime(full);
41411
41459
  return { name: entry.name, mtime };
@@ -59507,11 +59555,11 @@ import {
59507
59555
  appendFile as appendFile4,
59508
59556
  mkdir as mkdir17,
59509
59557
  readFile as readFile13,
59510
- readdir as readdir5,
59558
+ readdir as readdir6,
59511
59559
  rename as rename2,
59512
59560
  unlink
59513
59561
  } from "fs/promises";
59514
- import { existsSync as existsSync14, readFileSync as readFileSync5, readdirSync as readdirSync2 } from "fs";
59562
+ import { existsSync as existsSync14, readFileSync as readFileSync5, readdirSync as readdirSync3 } from "fs";
59515
59563
  import { join as join24 } from "path";
59516
59564
  var MAX_FAILED_RECORDS = 500;
59517
59565
  var FLUSH_DEBOUNCE_MS = 15e3;
@@ -59560,7 +59608,7 @@ var AnalyticsRecordBuffer = class {
59560
59608
  }
59561
59609
  readStoredRecords() {
59562
59610
  if (!existsSync14(ENGINE_DIR)) return [];
59563
- return readdirSync2(ENGINE_DIR, { withFileTypes: true }).filter((entry) => entry.isFile() && this.storageNames.some(
59611
+ return readdirSync3(ENGINE_DIR, { withFileTypes: true }).filter((entry) => entry.isFile() && this.storageNames.some(
59564
59612
  (storageName) => entry.name === `${storageName}.jsonl` || entry.name.startsWith(`${storageName}.`) && (entry.name.endsWith(".jsonl") || entry.name.endsWith(`.jsonl${UPLOADED_SUFFIX}`))
59565
59613
  )).map(({ name }) => name).sort().flatMap((name) => this.parseRecords(readFileSync5(join24(ENGINE_DIR, name), "utf-8"))).map((record3) => {
59566
59614
  const recordId = this.options.getRecordId?.(record3);
@@ -59602,7 +59650,7 @@ var AnalyticsRecordBuffer = class {
59602
59650
  ).catch(() => {
59603
59651
  });
59604
59652
  }
59605
- const entries = await readdir5(ENGINE_DIR).catch(() => []);
59653
+ const entries = await readdir6(ENGINE_DIR).catch(() => []);
59606
59654
  let flushed = 0;
59607
59655
  let failed = 0;
59608
59656
  for (const entry of entries) {
@@ -60449,7 +60497,7 @@ var KeepAliveService = class _KeepAliveService {
60449
60497
  var keepAliveService = new KeepAliveService();
60450
60498
 
60451
60499
  // src/services/canvas-service.ts
60452
- import { readdir as readdir6, readFile as readFile15, stat as stat3 } from "fs/promises";
60500
+ import { readdir as readdir7, readFile as readFile15, stat as stat3 } from "fs/promises";
60453
60501
  import { homedir as homedir8 } from "os";
60454
60502
  import { join as join25 } from "path";
60455
60503
 
@@ -60519,7 +60567,7 @@ var CanvasService = class {
60519
60567
  if (!current) continue;
60520
60568
  let entries;
60521
60569
  try {
60522
- entries = await readdir6(current.directory, { withFileTypes: true });
60570
+ entries = await readdir7(current.directory, { withFileTypes: true });
60523
60571
  } catch {
60524
60572
  continue;
60525
60573
  }
@@ -60726,7 +60774,7 @@ async function reconcileCanvasItems(filenames) {
60726
60774
  // src/services/upload-chat-transcripts.ts
60727
60775
  import { createReadStream as createReadStream3 } from "fs";
60728
60776
  import { createHash as createHash8 } from "crypto";
60729
- import { readFile as readFile16, readdir as readdir7, stat as stat4 } from "fs/promises";
60777
+ import { readFile as readFile16, readdir as readdir8, stat as stat4 } from "fs/promises";
60730
60778
  import { basename as basename3, join as join27 } from "path";
60731
60779
 
60732
60780
  // src/services/chat/chat-senders.ts
@@ -60810,7 +60858,7 @@ async function flushAllChatTranscripts(chatsById = /* @__PURE__ */ new Map(), ca
60810
60858
  for (const dir of HISTORY_DIRS) {
60811
60859
  let entries;
60812
60860
  try {
60813
- entries = await readdir7(dir);
60861
+ entries = await readdir8(dir);
60814
60862
  } catch {
60815
60863
  continue;
60816
60864
  }
@@ -60957,7 +61005,7 @@ async function flushRepoState() {
60957
61005
 
60958
61006
  // src/services/upload-engine-logs.ts
60959
61007
  import { createReadStream as createReadStream4 } from "fs";
60960
- import { readdir as readdir8, stat as stat5 } from "fs/promises";
61008
+ import { readdir as readdir9, stat as stat5 } from "fs/promises";
60961
61009
  import { join as join28 } from "path";
60962
61010
  var MAX_ENGINE_LOG_FLUSH_SESSIONS = 10;
60963
61011
  var MAX_ENGINE_LOG_FLUSH_BYTES = 5 * 1024 * 1024;
@@ -60968,7 +61016,7 @@ async function flushAllEngineLogs() {
60968
61016
  let failed = 0;
60969
61017
  const deadline = Date.now() + ENGINE_LOG_FLUSH_TIMEOUT_MS;
60970
61018
  await runBeforeDeadline((signal) => engineLogger.flush(signal), deadline);
60971
- const files = await runBeforeDeadline(() => readdir8(LOG_DIR), deadline).catch(() => []);
61019
+ const files = await runBeforeDeadline(() => readdir9(LOG_DIR), deadline).catch(() => []);
60972
61020
  const currentFilename = engineLogger.sessionId ? `${engineLogger.sessionId}.log` : null;
60973
61021
  const filenames = files.filter((filename) => {
60974
61022
  if (!filename.endsWith(".log")) return false;
@@ -63844,7 +63892,7 @@ var RepoFileService = class {
63844
63892
  // src/v1-routes.ts
63845
63893
  import { Hono } from "hono";
63846
63894
  import { z as z6 } from "zod";
63847
- import { readdir as readdir10, stat as stat7, readFile as readFile22 } from "fs/promises";
63895
+ import { readdir as readdir11, stat as stat7, readFile as readFile22 } from "fs/promises";
63848
63896
  import { openAsBlob } from "fs";
63849
63897
  import { join as join35, resolve as resolve5 } from "path";
63850
63898
 
@@ -63855,7 +63903,7 @@ import { existsSync as existsSync16 } from "fs";
63855
63903
  import { join as join34 } from "path";
63856
63904
 
63857
63905
  // src/services/warm-hook-logs-service.ts
63858
- import { mkdir as mkdir20, readFile as readFile20, writeFile as writeFile9, readdir as readdir9, appendFile as appendFile6, unlink as unlink2 } from "fs/promises";
63906
+ import { mkdir as mkdir20, readFile as readFile20, writeFile as writeFile9, readdir as readdir10, appendFile as appendFile6, unlink as unlink2 } from "fs/promises";
63859
63907
  import { homedir as homedir11 } from "os";
63860
63908
  import { join as join33 } from "path";
63861
63909
  var LOGS_DIR2 = join33(homedir11(), ".replicas", "warm-hook-logs");
@@ -63891,7 +63939,7 @@ var WarmHookLogsService = class {
63891
63939
  async getAllLogs() {
63892
63940
  let files;
63893
63941
  try {
63894
- files = await readdir9(LOGS_DIR2);
63942
+ files = await readdir10(LOGS_DIR2);
63895
63943
  } catch (err) {
63896
63944
  if (err.code === "ENOENT") {
63897
63945
  return [];
@@ -65330,7 +65378,7 @@ data: ${JSON.stringify("Terminal session not found")}
65330
65378
  });
65331
65379
  app2.get("/logs", async (c) => {
65332
65380
  try {
65333
- const files = await readdir10(LOG_DIR).catch(() => []);
65381
+ const files = await readdir11(LOG_DIR).catch(() => []);
65334
65382
  const logFiles = files.filter((f) => f.endsWith(".log"));
65335
65383
  const sessions = await Promise.all(
65336
65384
  logFiles.map(async (filename) => {
@@ -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-IVN3HEHP.js";
6
+ } from "./chunk-VEJ25S6F.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-IQQG6HNF.js";
12
+ } from "./chunk-K2FAYKHI.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/services/post-tool-pr-notifier.ts
@@ -11,7 +11,7 @@ import {
11
11
  spawnSubagentRequestSchema,
12
12
  subagentResponseSchema,
13
13
  waitSubagentRequestSchema
14
- } from "./chunk-IQQG6HNF.js";
14
+ } from "./chunk-K2FAYKHI.js";
15
15
  import "./chunk-VEQXQN22.js";
16
16
 
17
17
  // src/subagent-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1483",
3
+ "version": "0.1.1485",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",