replicas-engine 0.1.925 → 0.1.927

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.
@@ -5,11 +5,11 @@ import {
5
5
  getCodexAspHost,
6
6
  restartCodexAspHost,
7
7
  restartCodexAspHostIfRunning
8
- } from "./chunk-ARAD76EY.js";
9
- import "./chunk-Y3ZAG37O.js";
10
- import "./chunk-JLRNRGG3.js";
8
+ } from "./chunk-2EY45XUX.js";
9
+ import "./chunk-TD44XVMK.js";
10
+ import "./chunk-CI54RNOV.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-RLBC7EZ4.js";
12
+ import "./chunk-NJPKCNNS.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
  export {
15
15
  getCodexAspHost,
@@ -5,13 +5,13 @@ import {
5
5
  ENGINE_ENV,
6
6
  monolithRequest,
7
7
  setAgentCredentialSnapshot
8
- } from "./chunk-Y3ZAG37O.js";
8
+ } from "./chunk-TD44XVMK.js";
9
9
  import {
10
10
  AppServerProcess,
11
11
  SUBPROCESS_MAX_BUFFER,
12
12
  buildCodexAgentEnv,
13
13
  execFileAsync
14
- } from "./chunk-JLRNRGG3.js";
14
+ } from "./chunk-CI54RNOV.js";
15
15
  import {
16
16
  isRecord
17
17
  } from "./chunk-UZSNFLDQ.js";
@@ -25,7 +25,7 @@ import {
25
25
  listOpenAICompatibleModels,
26
26
  readOllamaAuthEnv,
27
27
  resolveOpenAICompatibleModelsUrl
28
- } from "./chunk-RLBC7EZ4.js";
28
+ } from "./chunk-NJPKCNNS.js";
29
29
 
30
30
  // src/managers/codex-token-manager.ts
31
31
  import { promises as fs } from "fs";
@@ -258,7 +258,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
258
258
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
259
259
  await this.applyCredentialsResponse(data);
260
260
  setAgentCredentialSnapshot("codex", data);
261
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7Q4EG2HV.js");
261
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-AWAX5F6X.js");
262
262
  await restartCodexAspHostIfRunning2();
263
263
  });
264
264
  await this.start(true);
@@ -278,7 +278,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
278
278
  await this.applyCredentialUpdate(generation, async () => {
279
279
  await this.applyCredentialsResponse(data);
280
280
  if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
281
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7Q4EG2HV.js");
281
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-AWAX5F6X.js");
282
282
  await restartCodexAspHostIfRunning2();
283
283
  }
284
284
  setAgentCredentialSnapshot("codex", data);
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES,
6
6
  isVersionBelow
7
- } from "./chunk-RLBC7EZ4.js";
7
+ } from "./chunk-NJPKCNNS.js";
8
8
 
9
9
  // src/utils/codex-agent-env.ts
10
10
  function buildCodexAgentEnv(source = process.env) {
@@ -245,7 +245,7 @@ function getCodexModelProvider(method) {
245
245
  if (method === "foundry") return "azure";
246
246
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
247
247
  }
248
- var ENGINE_PACKAGE_VERSION = "0.1.925";
248
+ var ENGINE_PACKAGE_VERSION = "0.1.927";
249
249
  var INITIALIZE_METHOD = "initialize";
250
250
  var INITIALIZED_NOTIFICATION = "initialized";
251
251
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-RLBC7EZ4.js";
8
+ } from "./chunk-NJPKCNNS.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -989,13 +989,13 @@ function coerceClaudePartialMessagePayload(payload) {
989
989
  const streamId = payload.streamId;
990
990
  if (typeof streamId !== "string" || !streamId) return null;
991
991
  const parentToolUseId = payload.parent_tool_use_id;
992
- const text = typeof payload.text === "string" && payload.text ? payload.text : void 0;
992
+ const text2 = typeof payload.text === "string" && payload.text ? payload.text : void 0;
993
993
  const thinking = typeof payload.thinking === "string" && payload.thinking ? payload.thinking : void 0;
994
- if (!text && !thinking) return null;
994
+ if (!text2 && !thinking) return null;
995
995
  return {
996
996
  streamId,
997
997
  parent_tool_use_id: typeof parentToolUseId === "string" ? parentToolUseId : null,
998
- ...text ? { text } : {},
998
+ ...text2 ? { text: text2 } : {},
999
999
  ...thinking ? { thinking } : {},
1000
1000
  status: payload.status === "completed" ? "completed" : "in_progress"
1001
1001
  };
@@ -1444,7 +1444,7 @@ function containsSecret(value) {
1444
1444
  });
1445
1445
  }
1446
1446
  function redactSecrets(value) {
1447
- return SECRET_PATTERNS.reduce((text, pattern) => text.replace(pattern, "[REDACTED]"), value);
1447
+ return SECRET_PATTERNS.reduce((text2, pattern) => text2.replace(pattern, "[REDACTED]"), value);
1448
1448
  }
1449
1449
  function secretEncodings(secret) {
1450
1450
  const bytes = new TextEncoder().encode(secret);
@@ -1852,8 +1852,8 @@ var RATE_LIMIT_PATTERNS = [
1852
1852
  ];
1853
1853
  var HTTP_429_PATTERN = /(?:^|[^0-9])429(?:$|[^0-9])/;
1854
1854
  var HTTP_CONTEXT_PATTERN = /(api error|request|response|status|http)/;
1855
- function detectAgentQuotaLimit(text) {
1856
- const normalized = text.toLowerCase();
1855
+ function detectAgentQuotaLimit(text2) {
1856
+ const normalized = text2.toLowerCase();
1857
1857
  if (!normalized) return null;
1858
1858
  if (OUT_OF_CREDITS_PATTERNS.some((pattern) => pattern.test(normalized))) return "out_of_credits";
1859
1859
  if (RATE_LIMIT_PATTERNS.some((pattern) => pattern.test(normalized))) return "rate_limit";
@@ -1914,7 +1914,11 @@ var fallbackHarnessStepSchema = z7.object({
1914
1914
  thinkingLevel: z7.enum(VALID_THINKING_LEVELS).optional()
1915
1915
  });
1916
1916
  var fallbackPlanStepSchema = z7.discriminatedUnion("kind", [
1917
- z7.object({ kind: z7.literal("credentials"), methods: z7.array(z7.custom(isAuthMethod)).min(1) }),
1917
+ z7.object({
1918
+ kind: z7.literal("credentials"),
1919
+ methods: z7.array(z7.custom(isAuthMethod)).min(1),
1920
+ models: z7.record(z7.string(), z7.string().min(1)).optional()
1921
+ }),
1918
1922
  fallbackHarnessStepSchema
1919
1923
  ]);
1920
1924
  var fallbackPlanResponseSchema = z7.object({ steps: z7.array(fallbackPlanStepSchema) });
@@ -4106,12 +4110,12 @@ var DEFAULT_DEFAULT_SKILLS = {
4106
4110
 
4107
4111
  // ../shared/src/prompts.ts
4108
4112
  var REPLICAS_INSTRUCTIONS_TAG = "replicas_instructions";
4109
- function removeTag(text, tag) {
4113
+ function removeTag(text2, tag) {
4110
4114
  const regex = new RegExp(`<${tag}>[\\s\\S]*?</${tag}>`, "g");
4111
- return text.replace(regex, "").trim();
4115
+ return text2.replace(regex, "").trim();
4112
4116
  }
4113
- function removeReplicasInstructions(text) {
4114
- return removeTag(text, REPLICAS_INSTRUCTIONS_TAG);
4117
+ function removeReplicasInstructions(text2) {
4118
+ return removeTag(text2, REPLICAS_INSTRUCTIONS_TAG);
4115
4119
  }
4116
4120
 
4117
4121
  // ../shared/src/user-message-matching.ts
@@ -4164,7 +4168,7 @@ function messagesForCodexTurn(turn) {
4164
4168
  return [{
4165
4169
  type: "reasoning",
4166
4170
  id: turn.id,
4167
- text: reasoning.map(({ text }) => text.trim()).join("\n\n"),
4171
+ text: reasoning.map(({ text: text2 }) => text2.trim()).join("\n\n"),
4168
4172
  timestamp: reasoning[0].timestamp,
4169
4173
  status: reasoning.at(-1)?.status ?? "completed"
4170
4174
  }];
@@ -4640,8 +4644,8 @@ function getCursorAssistantText(event) {
4640
4644
  return getTextContent(message?.content);
4641
4645
  }
4642
4646
  function getCursorThinkingText(event) {
4643
- const text = event.payload.text;
4644
- if (typeof text === "string") return text;
4647
+ const text2 = event.payload.text;
4648
+ if (typeof text2 === "string") return text2;
4645
4649
  const message = isRecord(event.payload.message) ? event.payload.message : null;
4646
4650
  return typeof message?.text === "string" ? message.text : "";
4647
4651
  }
@@ -4692,8 +4696,8 @@ function parseCursorEvents(events) {
4692
4696
  continue;
4693
4697
  }
4694
4698
  if (event.type === "cursor-assistant") {
4695
- const text = getCursorAssistantText(event);
4696
- if (text) {
4699
+ const text2 = getCursorAssistantText(event);
4700
+ if (text2) {
4697
4701
  const runId = cursorRunId(event);
4698
4702
  if (!activeAssistant || activeAssistant.runId !== runId) {
4699
4703
  const segment = runAssistantSegments.get(runId) ?? 0;
@@ -4712,15 +4716,15 @@ function parseCursorEvents(events) {
4712
4716
  if (message?.type === "agent") {
4713
4717
  messages[activeAssistant.index] = {
4714
4718
  ...message,
4715
- content: `${message.content}${text}`
4719
+ content: `${message.content}${text2}`
4716
4720
  };
4717
4721
  }
4718
4722
  }
4719
4723
  continue;
4720
4724
  }
4721
4725
  if (event.type === "cursor-thinking") {
4722
- const text = getCursorThinkingText(event);
4723
- if (text.trim()) {
4726
+ const text2 = getCursorThinkingText(event);
4727
+ if (text2.trim()) {
4724
4728
  const runId = cursorRunId(event);
4725
4729
  if (!activeThinking || activeThinking.runId !== runId) {
4726
4730
  const segment = runThinkingSegments.get(runId) ?? 0;
@@ -4740,7 +4744,7 @@ function parseCursorEvents(events) {
4740
4744
  if (message?.type === "reasoning") {
4741
4745
  messages[activeThinking.index] = {
4742
4746
  ...message,
4743
- content: `${message.content}${text}`,
4747
+ content: `${message.content}${text2}`,
4744
4748
  status: "in_progress"
4745
4749
  };
4746
4750
  }
@@ -4772,12 +4776,12 @@ function parseCursorEvents(events) {
4772
4776
  }
4773
4777
  if (event.type === "cursor-task") {
4774
4778
  activeAssistant = null;
4775
- const text = event.payload.text;
4776
- if (typeof text === "string" && text.trim()) {
4779
+ const text2 = event.payload.text;
4780
+ if (typeof text2 === "string" && text2.trim()) {
4777
4781
  messages.push({
4778
4782
  id: `cursor-task-${event.timestamp}-${messages.length}`,
4779
4783
  type: "agent",
4780
- content: text,
4784
+ content: text2,
4781
4785
  timestamp: event.timestamp
4782
4786
  });
4783
4787
  }
@@ -4863,8 +4867,8 @@ function extractErrorText(error) {
4863
4867
  collect(error);
4864
4868
  return parts.filter(Boolean).join("\n");
4865
4869
  }
4866
- function isTransientErrorText(text, options = {}) {
4867
- const normalized = text.toLowerCase();
4870
+ function isTransientErrorText(text2, options = {}) {
4871
+ const normalized = text2.toLowerCase();
4868
4872
  if (!normalized) return false;
4869
4873
  if (TRANSIENT_NETWORK_ERROR_PATTERNS.some((pattern) => pattern.test(normalized))) return true;
4870
4874
  if (options.includeRateLimit && /rate limit/.test(normalized)) return true;
@@ -4987,24 +4991,24 @@ function parseOpencodeEvents(events) {
4987
4991
  const time = isRecord(part.time) ? part.time : null;
4988
4992
  const timestamp = timestampFromMs(time?.start, event.timestamp);
4989
4993
  if (part.type === "text") {
4990
- const text = typeof part.text === "string" ? part.text : "";
4991
- if (text.trim()) {
4994
+ const text2 = typeof part.text === "string" ? part.text : "";
4995
+ if (text2.trim()) {
4992
4996
  upsertDisplayMessage(messages, {
4993
4997
  id,
4994
4998
  type: "agent",
4995
- content: text,
4999
+ content: text2,
4996
5000
  timestamp
4997
5001
  });
4998
5002
  }
4999
5003
  continue;
5000
5004
  }
5001
5005
  if (part.type === "reasoning") {
5002
- const text = typeof part.text === "string" ? part.text : "";
5003
- if (text.trim()) {
5006
+ const text2 = typeof part.text === "string" ? part.text : "";
5007
+ if (text2.trim()) {
5004
5008
  upsertDisplayMessage(messages, {
5005
5009
  id,
5006
5010
  type: "reasoning",
5007
- content: text,
5011
+ content: text2,
5008
5012
  status: time?.end ? "completed" : "in_progress",
5009
5013
  timestamp
5010
5014
  });
@@ -5163,7 +5167,7 @@ function assistantErrorMessage(value) {
5163
5167
  }
5164
5168
  function parsePiEvents(events) {
5165
5169
  const messages = [];
5166
- const text = /* @__PURE__ */ new Map();
5170
+ const text2 = /* @__PURE__ */ new Map();
5167
5171
  const thinking = /* @__PURE__ */ new Map();
5168
5172
  let activeMessageId = "assistant";
5169
5173
  for (const event of events) {
@@ -5194,9 +5198,9 @@ function parsePiEvents(events) {
5194
5198
  if (event.type === "pi-message_update") {
5195
5199
  const payload = nestedPayload(event);
5196
5200
  const id = typeof payload.id === "string" ? payload.id : activeMessageId;
5197
- if (payload.type === "text_delta" && typeof payload.delta === "string") text.set(id, `${text.get(id) ?? ""}${payload.delta}`);
5201
+ if (payload.type === "text_delta" && typeof payload.delta === "string") text2.set(id, `${text2.get(id) ?? ""}${payload.delta}`);
5198
5202
  if (payload.type === "thinking_delta" && typeof payload.delta === "string") thinking.set(id, `${thinking.get(id) ?? ""}${payload.delta}`);
5199
- const textContent = text.get(id);
5203
+ const textContent = text2.get(id);
5200
5204
  const thinkingContent = thinking.get(id);
5201
5205
  if (textContent !== void 0) upsertDisplayMessage(messages, { id: `pi-${id}`, type: "agent", content: textContent, timestamp: event.timestamp });
5202
5206
  if (thinkingContent !== void 0) upsertDisplayMessage(messages, { id: `pi-thinking-${id}`, type: "reasoning", content: thinkingContent, status: "in_progress", timestamp: event.timestamp });
@@ -6738,24 +6742,24 @@ function clampWarmHookTimeoutMs(timeoutMs) {
6738
6742
  }
6739
6743
  return Math.min(timeoutMs, MAX_WARM_HOOK_TIMEOUT_MS);
6740
6744
  }
6741
- function buildOutputPreview(text, {
6745
+ function buildOutputPreview(text2, {
6742
6746
  maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS,
6743
6747
  truncateFrom = "head",
6744
6748
  marker = "\n...[truncated \u2014 download the full log to see the rest]"
6745
6749
  } = {}) {
6746
- if (text.length <= maxChars) {
6747
- return { output: text, outputTruncated: false, outputTotalChars: text.length };
6750
+ if (text2.length <= maxChars) {
6751
+ return { output: text2, outputTruncated: false, outputTotalChars: text2.length };
6748
6752
  }
6749
6753
  const previewChars = Math.max(0, maxChars - marker.length);
6750
- const output = previewChars === 0 ? marker.slice(0, maxChars) : truncateFrom === "tail" ? `${marker}${text.slice(-previewChars)}` : `${text.slice(0, previewChars)}${marker}`;
6754
+ const output = previewChars === 0 ? marker.slice(0, maxChars) : truncateFrom === "tail" ? `${marker}${text2.slice(-previewChars)}` : `${text2.slice(0, previewChars)}${marker}`;
6751
6755
  return {
6752
6756
  output,
6753
6757
  outputTruncated: true,
6754
- outputTotalChars: text.length
6758
+ outputTotalChars: text2.length
6755
6759
  };
6756
6760
  }
6757
- function buildHookOutputPreview(text, maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS) {
6758
- return buildOutputPreview(text, { maxChars });
6761
+ function buildHookOutputPreview(text2, maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS) {
6762
+ return buildOutputPreview(text2, { maxChars });
6759
6763
  }
6760
6764
  function parseWarmHookConfig(value, filename = "replicas.json") {
6761
6765
  if (typeof value === "string") {
@@ -6844,6 +6848,7 @@ function parseReplicasConfigString(content, filename) {
6844
6848
  function createUuidFromHex(value) {
6845
6849
  return `${value.slice(0, 8)}-${value.slice(8, 12)}-5${value.slice(13, 16)}-${(Number.parseInt(value.slice(16, 17), 16) & 3 | 8).toString(16)}${value.slice(17, 20)}-${value.slice(20, 32)}`;
6846
6850
  }
6851
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6847
6852
 
6848
6853
  // ../shared/src/auth-errors.ts
6849
6854
  var AUTHENTICATION_ERROR_PATTERNS = [
@@ -6851,14 +6856,14 @@ var AUTHENTICATION_ERROR_PATTERNS = [
6851
6856
  /authentication error/,
6852
6857
  /invalid api key/
6853
6858
  ];
6854
- function isAuthenticationErrorText(text, extraPatterns = []) {
6855
- const normalized = text.toLowerCase();
6859
+ function isAuthenticationErrorText(text2, extraPatterns = []) {
6860
+ const normalized = text2.toLowerCase();
6856
6861
  return AUTHENTICATION_ERROR_PATTERNS.some((pattern) => pattern.test(normalized)) || extraPatterns.some((pattern) => pattern.test(normalized));
6857
6862
  }
6858
6863
 
6859
6864
  // ../shared/src/claude-auth.ts
6860
- function isClaudeAuthErrorText(text) {
6861
- const lower = text.toLowerCase();
6865
+ function isClaudeAuthErrorText(text2) {
6866
+ const lower = text2.toLowerCase();
6862
6867
  return lower.includes("failed to authenticate") || lower.includes("authentication_error") || lower.includes("authentication_failed") || lower.includes("authentication failed") || lower.includes("invalid authentication credentials") || lower.includes("not logged in") || lower.includes("please run /login") || lower.includes("401") && lower.includes("authentic");
6863
6868
  }
6864
6869
 
@@ -7060,8 +7065,8 @@ function stringifyCommandProtectionInput(value) {
7060
7065
  return String(value);
7061
7066
  }
7062
7067
  }
7063
- function normalizeCommandProtectionText(text) {
7064
- return text.replace(/\\\n/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
7068
+ function normalizeCommandProtectionText(text2) {
7069
+ return text2.replace(/\\\n/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
7065
7070
  }
7066
7071
  function extractCommandProtectionCommandText(request, options = {}) {
7067
7072
  if (request.command && request.command.trim()) return request.command;
@@ -7868,6 +7873,186 @@ function isSkillRegistryManifest(value) {
7868
7873
  );
7869
7874
  }
7870
7875
 
7876
+ // ../shared/src/routes/environment-setups.ts
7877
+ import { z as z13 } from "zod";
7878
+ var ENVIRONMENT_SETUP_STEPS = [
7879
+ { key: "understand", label: "Understand the codebase" },
7880
+ { key: "install", label: "Install dependencies and run the app" },
7881
+ { key: "verify", label: "Verify checks and record a walkthrough" },
7882
+ { key: "configure", label: "Draft hooks, system prompt, and automations" },
7883
+ { key: "propose", label: "Propose the configuration for review" }
7884
+ ];
7885
+ var ENVIRONMENT_SETUP_STEP_STATUSES = ["pending", "in_progress", "completed", "skipped"];
7886
+ var ENVIRONMENT_SETUP_RUN_STATUSES = ["running", "proposed", "applied", "failed", "cancelled"];
7887
+ var ENVIRONMENT_SETUP_AUTOMATION_ACTIONS = ["create", "update", "keep", "disable"];
7888
+ var ENVIRONMENT_SETUP_VERIFICATION_STATUSES = ["passed", "failed", "skipped"];
7889
+ var ENVIRONMENT_SETUP_LIMITS = {
7890
+ summaryChars: 600,
7891
+ stackItems: 30,
7892
+ nameChars: 120,
7893
+ descriptionChars: 1e3,
7894
+ systemPromptChars: 2e4,
7895
+ hookChars: 5e4,
7896
+ variables: 50,
7897
+ variableKeyChars: 128,
7898
+ variableDescriptionChars: 500,
7899
+ automations: 8,
7900
+ automationKeyChars: 80,
7901
+ automationPromptChars: 1e4,
7902
+ automationTriggers: 5,
7903
+ automationNoteChars: 300,
7904
+ verificationItems: 8,
7905
+ verificationDetailChars: 300,
7906
+ mediaItems: 8
7907
+ };
7908
+ var ENVIRONMENT_SETUP_VARIABLE_WAIT = { defaultMs: 5 * 6e4, maxMs: 15 * 6e4, pollMs: 5e3 };
7909
+ var VARIABLE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
7910
+ var text = (max) => max === void 0 ? z13.string().trim() : z13.string().trim().max(max);
7911
+ var requiredText = (max) => text(max).min(1, "must not be empty");
7912
+ var optionalText = (max) => text(max).nullish().transform((value) => value || null);
7913
+ var clearableText = (max) => text(max).nullish().transform((value) => value === void 0 ? void 0 : value || null);
7914
+ var list = (item, max) => max === void 0 ? z13.array(item) : z13.array(item).max(max);
7915
+ var ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES = ["cron", "github", "gitlab"];
7916
+ function isEnvironmentSetupAuthoredTriggerType(type) {
7917
+ return ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES.some((authored) => authored === type);
7918
+ }
7919
+ var repositoryTriggerConfigSchema = z13.object({
7920
+ event: z13.string(),
7921
+ repository_ids: z13.array(z13.string().regex(UUID_RE, "must be a repository id")).optional(),
7922
+ group_pr_events: z13.boolean().optional(),
7923
+ excluded_actors: z13.array(z13.string()).optional()
7924
+ });
7925
+ var proposalTriggerSchema = z13.discriminatedUnion("type", [
7926
+ z13.object({ type: z13.literal("cron"), config: z13.object({ schedule: z13.string(), timezone: z13.string().optional() }) }),
7927
+ z13.object({ type: z13.literal("github"), config: repositoryTriggerConfigSchema }),
7928
+ z13.object({ type: z13.literal("gitlab"), config: repositoryTriggerConfigSchema })
7929
+ ]);
7930
+ var existingTriggerSchema = z13.custom(
7931
+ (value) => isRecord(value) && typeof value.type === "string" && isRecord(value.config),
7932
+ "must be an automation trigger"
7933
+ );
7934
+ var carriedTriggerSchema = existingTriggerSchema.refine(
7935
+ (trigger) => !isEnvironmentSetupAuthoredTriggerType(trigger.type)
7936
+ );
7937
+ function automationSchema(limits) {
7938
+ const authored = z13.object({
7939
+ name: text(limits.nameChars),
7940
+ description: text(limits.descriptionChars),
7941
+ prompt: text(limits.automationPromptChars),
7942
+ triggers: list(proposalTriggerSchema, limits.automationTriggers)
7943
+ });
7944
+ const updated = authored.extend({ triggers: list(z13.union([proposalTriggerSchema, carriedTriggerSchema]), limits.automationTriggers) });
7945
+ return z13.object({
7946
+ key: requiredText(limits.automationKeyChars),
7947
+ action: z13.enum(ENVIRONMENT_SETUP_AUTOMATION_ACTIONS).default("create"),
7948
+ automation_id: z13.string().regex(UUID_RE, "must be an automation id").nullable().default(null),
7949
+ name: text().default(""),
7950
+ description: optionalText().transform((value) => value ?? ""),
7951
+ prompt: text().default(""),
7952
+ triggers: list(existingTriggerSchema).default([]),
7953
+ note: optionalText(limits.automationNoteChars)
7954
+ }).superRefine((automation, ctx) => {
7955
+ if (automation.action === "create" && automation.automation_id) {
7956
+ ctx.addIssue({ code: "custom", path: ["automation_id"], message: "belongs on an update, keep, or disable entry" });
7957
+ }
7958
+ if (automation.action !== "create" && !automation.automation_id) {
7959
+ ctx.addIssue({ code: "custom", path: ["automation_id"], message: "must be the id of an automation attached to this environment" });
7960
+ }
7961
+ if (automation.action === "create" || automation.action === "update") {
7962
+ if (!automation.name) ctx.addIssue({ code: "custom", path: ["name"], message: "must not be empty" });
7963
+ if (!automation.prompt) ctx.addIssue({ code: "custom", path: ["prompt"], message: "must not be empty" });
7964
+ if (automation.triggers.length === 0) ctx.addIssue({ code: "custom", path: ["triggers"], message: "must not be empty" });
7965
+ }
7966
+ }).transform((automation, ctx) => {
7967
+ if (automation.action === "keep" || automation.action === "disable") return automation;
7968
+ const content = (automation.action === "update" ? updated : authored).safeParse(automation);
7969
+ if (content.success) return { ...automation, ...content.data };
7970
+ for (const issue of content.error.issues) ctx.addIssue({ ...issue, code: "custom" });
7971
+ return z13.NEVER;
7972
+ });
7973
+ }
7974
+ function automationListSchema(limits) {
7975
+ return list(automationSchema(limits)).default([]).superRefine((automations, ctx) => {
7976
+ if (new Set(automations.map((automation) => automation.key)).size !== automations.length) {
7977
+ ctx.addIssue({ code: "custom", message: "must have unique keys" });
7978
+ }
7979
+ const targets = automations.flatMap((automation) => automation.automation_id ?? []);
7980
+ if (new Set(targets).size !== targets.length) {
7981
+ ctx.addIssue({ code: "custom", message: "must mention each existing automation once" });
7982
+ }
7983
+ if (limits.automations !== void 0 && automations.filter((automation) => automation.action === "create").length > limits.automations) {
7984
+ ctx.addIssue({ code: "custom", message: `must create at most ${limits.automations} new automations` });
7985
+ }
7986
+ });
7987
+ }
7988
+ function environmentSchema(limits) {
7989
+ return z13.object({
7990
+ name: optionalText(limits.nameChars).transform((value) => value ?? void 0),
7991
+ description: clearableText(limits.descriptionChars),
7992
+ system_prompt: clearableText(limits.systemPromptChars),
7993
+ start_hook: clearableText(limits.hookChars),
7994
+ warm_hook: clearableText(limits.hookChars)
7995
+ });
7996
+ }
7997
+ function variableSchema(limits, requiredDefault) {
7998
+ return z13.object({
7999
+ key: z13.string().regex(VARIABLE_KEY_RE, "must be a valid environment variable name").max(limits.variableKeyChars ?? Number.POSITIVE_INFINITY),
8000
+ description: optionalText(limits.variableDescriptionChars).transform((value) => value ?? ""),
8001
+ required: z13.boolean().default(requiredDefault)
8002
+ });
8003
+ }
8004
+ function proposalSchema(limits) {
8005
+ return z13.object({
8006
+ summary: requiredText(limits.summaryChars),
8007
+ stack: list(text(), limits.stackItems).default([]).transform((items) => items.filter(Boolean)),
8008
+ environment: environmentSchema(limits),
8009
+ variables: list(variableSchema(limits, false), limits.variables).default([]),
8010
+ automations: automationListSchema(limits),
8011
+ verification: list(z13.object({
8012
+ label: requiredText(limits.nameChars),
8013
+ status: z13.enum(ENVIRONMENT_SETUP_VERIFICATION_STATUSES),
8014
+ detail: optionalText(limits.verificationDetailChars).transform((value) => value ?? void 0)
8015
+ }), limits.verificationItems).default([]),
8016
+ media: list(z13.object({
8017
+ media_id: z13.string().regex(UUID_RE, "must be a media id"),
8018
+ title: requiredText(limits.nameChars)
8019
+ }), limits.mediaItems).default([])
8020
+ });
8021
+ }
8022
+ var environmentSetupProposalSchema = proposalSchema({});
8023
+ var environmentSetupProposalSubmissionSchema = proposalSchema(ENVIRONMENT_SETUP_LIMITS);
8024
+ var environmentSetupVariableRequestSchema = variableSchema({}, false).extend({
8025
+ status: z13.enum(["pending", "provided", "skipped"]),
8026
+ requested_at: z13.string(),
8027
+ resolved_at: z13.string().nullable().default(null)
8028
+ });
8029
+ var environmentSetupRunStateSchema = z13.object({
8030
+ status: z13.enum(ENVIRONMENT_SETUP_RUN_STATUSES),
8031
+ steps: z13.partialRecord(z13.enum(ENVIRONMENT_SETUP_STEPS.map((step) => step.key)), z13.enum(ENVIRONMENT_SETUP_STEP_STATUSES)).default({}),
8032
+ proposal: environmentSetupProposalSchema.nullable().default(null),
8033
+ applied: z13.object({
8034
+ applied_at: z13.string(),
8035
+ automation_ids: z13.array(z13.string())
8036
+ }).nullable().default(null),
8037
+ variable_requests: z13.array(environmentSetupVariableRequestSchema).default([])
8038
+ });
8039
+ var applyEnvironmentSetupRequestSchema = z13.object({
8040
+ environment: environmentSchema(ENVIRONMENT_SETUP_LIMITS).extend({ name: requiredText(ENVIRONMENT_SETUP_LIMITS.nameChars) }),
8041
+ variables: list(z13.object({ key: z13.string().regex(VARIABLE_KEY_RE), value: z13.string() }), ENVIRONMENT_SETUP_LIMITS.variables).default([]).refine((variables) => new Set(variables.map((variable) => variable.key)).size === variables.length, "must have unique keys").transform((variables) => variables.filter((variable) => variable.value.length > 0)),
8042
+ automations: automationListSchema(ENVIRONMENT_SETUP_LIMITS)
8043
+ });
8044
+ var requestEnvironmentSetupVariablesSchema = z13.object({
8045
+ variables: list(variableSchema(ENVIRONMENT_SETUP_LIMITS, true), ENVIRONMENT_SETUP_LIMITS.variables).min(1, "must not be empty")
8046
+ }).superRefine(({ variables }, ctx) => {
8047
+ if (new Set(variables.map((variable) => variable.key)).size !== variables.length) {
8048
+ ctx.addIssue({ code: "custom", path: ["variables"], message: "must have unique keys" });
8049
+ }
8050
+ });
8051
+ var respondEnvironmentSetupVariablesSchema = z13.object({
8052
+ values: z13.record(z13.string().regex(VARIABLE_KEY_RE), z13.string()).default({}),
8053
+ skipped: z13.array(z13.string().regex(VARIABLE_KEY_RE)).default([])
8054
+ });
8055
+
7871
8056
  export {
7872
8057
  isRecord,
7873
8058
  isNonEmptyString,
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  monolithRequest
6
- } from "./chunk-Y3ZAG37O.js";
6
+ } from "./chunk-TD44XVMK.js";
7
7
  import {
8
8
  extractCommandProtectionCommandText,
9
9
  findGitCommitSignals,
10
10
  findPrMergeSignals
11
- } from "./chunk-RLBC7EZ4.js";
11
+ } from "./chunk-NJPKCNNS.js";
12
12
 
13
13
  // src/services/command-protection-service.ts
14
14
  var DEFAULT_COMMAND_PROTECTION_BLOCK_MESSAGE = "Blocked by Replicas command protection.";
@@ -15,7 +15,7 @@ import {
15
15
  isValidRelayBaseProvider,
16
16
  parsePosixEnvFile,
17
17
  readReplicasRuntimeEnv
18
- } from "./chunk-RLBC7EZ4.js";
18
+ } from "./chunk-NJPKCNNS.js";
19
19
 
20
20
  // src/runtime-env-loader.ts
21
21
  import { readFileSync } from "fs";
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-P56H3PGY.js";
7
- import "./chunk-Y3ZAG37O.js";
6
+ } from "./chunk-SQ24WMMC.js";
7
+ import "./chunk-TD44XVMK.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./chunk-UZSNFLDQ.js";
11
- import "./chunk-RLBC7EZ4.js";
11
+ import "./chunk-NJPKCNNS.js";
12
12
  import "./chunk-VEQXQN22.js";
13
13
 
14
14
  // src/command-protection-hook.ts
@@ -8,12 +8,12 @@ import {
8
8
  import {
9
9
  AppServerProcess,
10
10
  buildCodexAgentEnv
11
- } from "./chunk-JLRNRGG3.js";
11
+ } from "./chunk-CI54RNOV.js";
12
12
  import {
13
13
  AGENT,
14
14
  getMemoryOutputSafetyViolation,
15
15
  headlessAgentRequestSchema
16
- } from "./chunk-RLBC7EZ4.js";
16
+ } from "./chunk-NJPKCNNS.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
 
19
19
  // 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-P56H3PGY.js";
30
+ } from "./chunk-SQ24WMMC.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -52,7 +52,7 @@ import {
52
52
  } from "./chunk-FLDA7BX3.js";
53
53
  import {
54
54
  publishedPullRequestUrls
55
- } from "./chunk-4Q7E2QOZ.js";
55
+ } from "./chunk-GHJBMCNR.js";
56
56
  import {
57
57
  RELAY_MCP_TOOLS,
58
58
  RELAY_MCP_TOOL_NAMES,
@@ -74,7 +74,7 @@ import {
74
74
  refreshDelayMs,
75
75
  restartCodexAspHost,
76
76
  routineRefreshExclusions
77
- } from "./chunk-ARAD76EY.js";
77
+ } from "./chunk-2EY45XUX.js";
78
78
  import {
79
79
  ENGINE_ENV,
80
80
  monolithRequest,
@@ -82,14 +82,14 @@ import {
82
82
  readRuntimeEnvFile,
83
83
  reloadEngineEnv,
84
84
  setAgentCredentialSnapshot
85
- } from "./chunk-Y3ZAG37O.js";
85
+ } from "./chunk-TD44XVMK.js";
86
86
  import {
87
87
  AspClient,
88
88
  SUBPROCESS_MAX_BUFFER,
89
89
  execAsync,
90
90
  execFileAsync,
91
91
  getCodexModelProvider
92
- } from "./chunk-JLRNRGG3.js";
92
+ } from "./chunk-CI54RNOV.js";
93
93
  import {
94
94
  isRecord as isRecord2
95
95
  } from "./chunk-UZSNFLDQ.js";
@@ -316,7 +316,7 @@ import {
316
316
  workspaceCredentialProviderSchema,
317
317
  workspaceTokenRequestSchema,
318
318
  workspaceTokenResponseSchema
319
- } from "./chunk-RLBC7EZ4.js";
319
+ } from "./chunk-NJPKCNNS.js";
320
320
  import {
321
321
  cloneMcpConfig,
322
322
  ensureCompatibilityImports,
@@ -11745,7 +11745,8 @@ var AuthFallbackCoordinator = class {
11745
11745
  continue;
11746
11746
  }
11747
11747
  this.recordNotice(reason, exhausted, applied, "switched", detail, !chatCredentials);
11748
- return { outcome: "switched" };
11748
+ const model = step.models?.[applied.method];
11749
+ return { outcome: "switched", ...model ? { model } : {} };
11749
11750
  }
11750
11751
  if (!tokenManager || !exhausted) return { outcome: "unavailable" };
11751
11752
  if (!failed) return { outcome: "not_configured" };
@@ -11999,6 +12000,7 @@ var CodingAgentManager = class {
11999
12000
  hostOnTurnComplete;
12000
12001
  onProcessingChanged;
12001
12002
  onMessageStarted;
12003
+ onModelSwitched;
12002
12004
  authFallback;
12003
12005
  additionalInstructions;
12004
12006
  compacting = false;
@@ -12018,6 +12020,8 @@ var CodingAgentManager = class {
12018
12020
  });
12019
12021
  this.onMessageStarted = options.onMessageStarted ?? (async () => {
12020
12022
  });
12023
+ this.onModelSwitched = options.onModelSwitched ?? (async () => {
12024
+ });
12021
12025
  this.authFallback = options.provider ? new AuthFallbackCoordinator(options.provider, (event) => {
12022
12026
  this.onEvent(event);
12023
12027
  this.getHistorySink()?.append(event);
@@ -12025,7 +12029,9 @@ var CodingAgentManager = class {
12025
12029
  }
12026
12030
  async fallBackCredential(reason, detail, chatCredentials) {
12027
12031
  if (!this.authFallback) return { outcome: "unavailable" };
12028
- return this.authFallback.fallBack(reason, detail, chatCredentials);
12032
+ const result = await this.authFallback.fallBack(reason, detail, chatCredentials);
12033
+ if (result.outcome === "switched" && result.model) await this.onModelSwitched(result.model);
12034
+ return result;
12029
12035
  }
12030
12036
  onTurnComplete = async () => {
12031
12037
  if (this.compacting) {
@@ -13649,6 +13655,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13649
13655
  const detail = error instanceof ClaudeQuotaError ? error.message : extractErrorText(error);
13650
13656
  const fallback = quotaFallbacks < MAX_QUOTA_FALLBACKS ? await this.fallBackCredential(quotaKind, detail, this.turnCredentials ?? void 0) : { outcome: "unavailable" };
13651
13657
  if (fallback.outcome === "switched") {
13658
+ if (fallback.model) currentRequest = { ...currentRequest, model: fallback.model };
13652
13659
  quotaFallbacks++;
13653
13660
  await this.tearDownSession();
13654
13661
  attempt++;
@@ -15552,6 +15559,7 @@ var CodexAspManager = class extends CodingAgentManager {
15552
15559
  terminalError.message
15553
15560
  );
15554
15561
  if (fallback.outcome === "switched") {
15562
+ if (fallback.model) request = { ...request, model: fallback.model };
15555
15563
  attemptedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex;
15556
15564
  const retryFailure = await this.restartAndRetry(dispatch);
15557
15565
  if (!retryFailure) return;
@@ -61490,6 +61498,15 @@ var ChatService = class {
61490
61498
  forkable: (chat?.persisted ?? persisted).parentChatId === null
61491
61499
  };
61492
61500
  };
61501
+ const onModelSwitched = async (model) => {
61502
+ const chat = this.chats.get(persisted.id);
61503
+ if (!chat || chat.persisted.model === model) return;
61504
+ chat.persisted.model = model;
61505
+ await this.persistAllChats();
61506
+ await this.publish({ type: "chat.updated", payload: { chat: this.toSummary(chat) } }).catch((error) => {
61507
+ console.error("[ChatService] Failed to publish switched chat model:", { chatId: persisted.id, error });
61508
+ });
61509
+ };
61493
61510
  if (persisted.parentChatId === void 0) {
61494
61511
  persisted.parentChatId = null;
61495
61512
  }
@@ -61509,6 +61526,7 @@ var ChatService = class {
61509
61526
  onUsageUpdate: onProviderUsage,
61510
61527
  fallbackContext,
61511
61528
  chatId: persisted.id,
61529
+ onModelSwitched,
61512
61530
  additionalInstructions,
61513
61531
  linearSessionId: persisted.parentChatId === null ? ENGINE_ENV.REPLICAS_LINEAR_SESSION_ID : void 0,
61514
61532
  ...persisted.provider === "relay" ? { relayParentChatId: persisted.id } : {}
@@ -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-4Q7E2QOZ.js";
6
+ } from "./chunk-GHJBMCNR.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-RLBC7EZ4.js";
12
+ } from "./chunk-NJPKCNNS.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
  relaySubagentResponseSchema,
12
12
  spawnRelaySubagentRequestSchema,
13
13
  waitRelaySubagentRequestSchema
14
- } from "./chunk-RLBC7EZ4.js";
14
+ } from "./chunk-NJPKCNNS.js";
15
15
  import "./chunk-VEQXQN22.js";
16
16
 
17
17
  // src/relay-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.925",
3
+ "version": "0.1.927",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",