replicas-engine 0.1.926 → 0.1.928

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-2TUMNESB.js";
9
- import "./chunk-IJXBOFTY.js";
10
- import "./chunk-QQ2ENBZT.js";
8
+ } from "./chunk-FNPITBXU.js";
9
+ import "./chunk-TD44XVMK.js";
10
+ import "./chunk-N2PL5F67.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-O7V7LVOY.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-IJXBOFTY.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-QQ2ENBZT.js";
14
+ } from "./chunk-N2PL5F67.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-O7V7LVOY.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-DQEMHOBE.js");
261
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-JOS2DJ54.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-DQEMHOBE.js");
281
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-JOS2DJ54.js");
282
282
  await restartCodexAspHostIfRunning2();
283
283
  }
284
284
  setAgentCredentialSnapshot("codex", data);
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-O7V7LVOY.js";
8
+ } from "./chunk-NJPKCNNS.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -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-O7V7LVOY.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.926";
248
+ var ENGINE_PACKAGE_VERSION = "0.1.928";
249
249
  var INITIALIZE_METHOD = "initialize";
250
250
  var INITIALIZED_NOTIFICATION = "initialized";
251
251
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -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";
@@ -4110,12 +4110,12 @@ var DEFAULT_DEFAULT_SKILLS = {
4110
4110
 
4111
4111
  // ../shared/src/prompts.ts
4112
4112
  var REPLICAS_INSTRUCTIONS_TAG = "replicas_instructions";
4113
- function removeTag(text, tag) {
4113
+ function removeTag(text2, tag) {
4114
4114
  const regex = new RegExp(`<${tag}>[\\s\\S]*?</${tag}>`, "g");
4115
- return text.replace(regex, "").trim();
4115
+ return text2.replace(regex, "").trim();
4116
4116
  }
4117
- function removeReplicasInstructions(text) {
4118
- return removeTag(text, REPLICAS_INSTRUCTIONS_TAG);
4117
+ function removeReplicasInstructions(text2) {
4118
+ return removeTag(text2, REPLICAS_INSTRUCTIONS_TAG);
4119
4119
  }
4120
4120
 
4121
4121
  // ../shared/src/user-message-matching.ts
@@ -4168,7 +4168,7 @@ function messagesForCodexTurn(turn) {
4168
4168
  return [{
4169
4169
  type: "reasoning",
4170
4170
  id: turn.id,
4171
- text: reasoning.map(({ text }) => text.trim()).join("\n\n"),
4171
+ text: reasoning.map(({ text: text2 }) => text2.trim()).join("\n\n"),
4172
4172
  timestamp: reasoning[0].timestamp,
4173
4173
  status: reasoning.at(-1)?.status ?? "completed"
4174
4174
  }];
@@ -4644,8 +4644,8 @@ function getCursorAssistantText(event) {
4644
4644
  return getTextContent(message?.content);
4645
4645
  }
4646
4646
  function getCursorThinkingText(event) {
4647
- const text = event.payload.text;
4648
- if (typeof text === "string") return text;
4647
+ const text2 = event.payload.text;
4648
+ if (typeof text2 === "string") return text2;
4649
4649
  const message = isRecord(event.payload.message) ? event.payload.message : null;
4650
4650
  return typeof message?.text === "string" ? message.text : "";
4651
4651
  }
@@ -4696,8 +4696,8 @@ function parseCursorEvents(events) {
4696
4696
  continue;
4697
4697
  }
4698
4698
  if (event.type === "cursor-assistant") {
4699
- const text = getCursorAssistantText(event);
4700
- if (text) {
4699
+ const text2 = getCursorAssistantText(event);
4700
+ if (text2) {
4701
4701
  const runId = cursorRunId(event);
4702
4702
  if (!activeAssistant || activeAssistant.runId !== runId) {
4703
4703
  const segment = runAssistantSegments.get(runId) ?? 0;
@@ -4716,15 +4716,15 @@ function parseCursorEvents(events) {
4716
4716
  if (message?.type === "agent") {
4717
4717
  messages[activeAssistant.index] = {
4718
4718
  ...message,
4719
- content: `${message.content}${text}`
4719
+ content: `${message.content}${text2}`
4720
4720
  };
4721
4721
  }
4722
4722
  }
4723
4723
  continue;
4724
4724
  }
4725
4725
  if (event.type === "cursor-thinking") {
4726
- const text = getCursorThinkingText(event);
4727
- if (text.trim()) {
4726
+ const text2 = getCursorThinkingText(event);
4727
+ if (text2.trim()) {
4728
4728
  const runId = cursorRunId(event);
4729
4729
  if (!activeThinking || activeThinking.runId !== runId) {
4730
4730
  const segment = runThinkingSegments.get(runId) ?? 0;
@@ -4744,7 +4744,7 @@ function parseCursorEvents(events) {
4744
4744
  if (message?.type === "reasoning") {
4745
4745
  messages[activeThinking.index] = {
4746
4746
  ...message,
4747
- content: `${message.content}${text}`,
4747
+ content: `${message.content}${text2}`,
4748
4748
  status: "in_progress"
4749
4749
  };
4750
4750
  }
@@ -4776,12 +4776,12 @@ function parseCursorEvents(events) {
4776
4776
  }
4777
4777
  if (event.type === "cursor-task") {
4778
4778
  activeAssistant = null;
4779
- const text = event.payload.text;
4780
- if (typeof text === "string" && text.trim()) {
4779
+ const text2 = event.payload.text;
4780
+ if (typeof text2 === "string" && text2.trim()) {
4781
4781
  messages.push({
4782
4782
  id: `cursor-task-${event.timestamp}-${messages.length}`,
4783
4783
  type: "agent",
4784
- content: text,
4784
+ content: text2,
4785
4785
  timestamp: event.timestamp
4786
4786
  });
4787
4787
  }
@@ -4867,8 +4867,8 @@ function extractErrorText(error) {
4867
4867
  collect(error);
4868
4868
  return parts.filter(Boolean).join("\n");
4869
4869
  }
4870
- function isTransientErrorText(text, options = {}) {
4871
- const normalized = text.toLowerCase();
4870
+ function isTransientErrorText(text2, options = {}) {
4871
+ const normalized = text2.toLowerCase();
4872
4872
  if (!normalized) return false;
4873
4873
  if (TRANSIENT_NETWORK_ERROR_PATTERNS.some((pattern) => pattern.test(normalized))) return true;
4874
4874
  if (options.includeRateLimit && /rate limit/.test(normalized)) return true;
@@ -4991,24 +4991,24 @@ function parseOpencodeEvents(events) {
4991
4991
  const time = isRecord(part.time) ? part.time : null;
4992
4992
  const timestamp = timestampFromMs(time?.start, event.timestamp);
4993
4993
  if (part.type === "text") {
4994
- const text = typeof part.text === "string" ? part.text : "";
4995
- if (text.trim()) {
4994
+ const text2 = typeof part.text === "string" ? part.text : "";
4995
+ if (text2.trim()) {
4996
4996
  upsertDisplayMessage(messages, {
4997
4997
  id,
4998
4998
  type: "agent",
4999
- content: text,
4999
+ content: text2,
5000
5000
  timestamp
5001
5001
  });
5002
5002
  }
5003
5003
  continue;
5004
5004
  }
5005
5005
  if (part.type === "reasoning") {
5006
- const text = typeof part.text === "string" ? part.text : "";
5007
- if (text.trim()) {
5006
+ const text2 = typeof part.text === "string" ? part.text : "";
5007
+ if (text2.trim()) {
5008
5008
  upsertDisplayMessage(messages, {
5009
5009
  id,
5010
5010
  type: "reasoning",
5011
- content: text,
5011
+ content: text2,
5012
5012
  status: time?.end ? "completed" : "in_progress",
5013
5013
  timestamp
5014
5014
  });
@@ -5167,7 +5167,7 @@ function assistantErrorMessage(value) {
5167
5167
  }
5168
5168
  function parsePiEvents(events) {
5169
5169
  const messages = [];
5170
- const text = /* @__PURE__ */ new Map();
5170
+ const text2 = /* @__PURE__ */ new Map();
5171
5171
  const thinking = /* @__PURE__ */ new Map();
5172
5172
  let activeMessageId = "assistant";
5173
5173
  for (const event of events) {
@@ -5198,9 +5198,9 @@ function parsePiEvents(events) {
5198
5198
  if (event.type === "pi-message_update") {
5199
5199
  const payload = nestedPayload(event);
5200
5200
  const id = typeof payload.id === "string" ? payload.id : activeMessageId;
5201
- 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}`);
5202
5202
  if (payload.type === "thinking_delta" && typeof payload.delta === "string") thinking.set(id, `${thinking.get(id) ?? ""}${payload.delta}`);
5203
- const textContent = text.get(id);
5203
+ const textContent = text2.get(id);
5204
5204
  const thinkingContent = thinking.get(id);
5205
5205
  if (textContent !== void 0) upsertDisplayMessage(messages, { id: `pi-${id}`, type: "agent", content: textContent, timestamp: event.timestamp });
5206
5206
  if (thinkingContent !== void 0) upsertDisplayMessage(messages, { id: `pi-thinking-${id}`, type: "reasoning", content: thinkingContent, status: "in_progress", timestamp: event.timestamp });
@@ -6742,24 +6742,24 @@ function clampWarmHookTimeoutMs(timeoutMs) {
6742
6742
  }
6743
6743
  return Math.min(timeoutMs, MAX_WARM_HOOK_TIMEOUT_MS);
6744
6744
  }
6745
- function buildOutputPreview(text, {
6745
+ function buildOutputPreview(text2, {
6746
6746
  maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS,
6747
6747
  truncateFrom = "head",
6748
6748
  marker = "\n...[truncated \u2014 download the full log to see the rest]"
6749
6749
  } = {}) {
6750
- if (text.length <= maxChars) {
6751
- return { output: text, outputTruncated: false, outputTotalChars: text.length };
6750
+ if (text2.length <= maxChars) {
6751
+ return { output: text2, outputTruncated: false, outputTotalChars: text2.length };
6752
6752
  }
6753
6753
  const previewChars = Math.max(0, maxChars - marker.length);
6754
- 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}`;
6755
6755
  return {
6756
6756
  output,
6757
6757
  outputTruncated: true,
6758
- outputTotalChars: text.length
6758
+ outputTotalChars: text2.length
6759
6759
  };
6760
6760
  }
6761
- function buildHookOutputPreview(text, maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS) {
6762
- return buildOutputPreview(text, { maxChars });
6761
+ function buildHookOutputPreview(text2, maxChars = DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS) {
6762
+ return buildOutputPreview(text2, { maxChars });
6763
6763
  }
6764
6764
  function parseWarmHookConfig(value, filename = "replicas.json") {
6765
6765
  if (typeof value === "string") {
@@ -6848,6 +6848,7 @@ function parseReplicasConfigString(content, filename) {
6848
6848
  function createUuidFromHex(value) {
6849
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)}`;
6850
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;
6851
6852
 
6852
6853
  // ../shared/src/auth-errors.ts
6853
6854
  var AUTHENTICATION_ERROR_PATTERNS = [
@@ -6855,14 +6856,14 @@ var AUTHENTICATION_ERROR_PATTERNS = [
6855
6856
  /authentication error/,
6856
6857
  /invalid api key/
6857
6858
  ];
6858
- function isAuthenticationErrorText(text, extraPatterns = []) {
6859
- const normalized = text.toLowerCase();
6859
+ function isAuthenticationErrorText(text2, extraPatterns = []) {
6860
+ const normalized = text2.toLowerCase();
6860
6861
  return AUTHENTICATION_ERROR_PATTERNS.some((pattern) => pattern.test(normalized)) || extraPatterns.some((pattern) => pattern.test(normalized));
6861
6862
  }
6862
6863
 
6863
6864
  // ../shared/src/claude-auth.ts
6864
- function isClaudeAuthErrorText(text) {
6865
- const lower = text.toLowerCase();
6865
+ function isClaudeAuthErrorText(text2) {
6866
+ const lower = text2.toLowerCase();
6866
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");
6867
6868
  }
6868
6869
 
@@ -7064,8 +7065,8 @@ function stringifyCommandProtectionInput(value) {
7064
7065
  return String(value);
7065
7066
  }
7066
7067
  }
7067
- function normalizeCommandProtectionText(text) {
7068
- 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();
7069
7070
  }
7070
7071
  function extractCommandProtectionCommandText(request, options = {}) {
7071
7072
  if (request.command && request.command.trim()) return request.command;
@@ -7872,6 +7873,186 @@ function isSkillRegistryManifest(value) {
7872
7873
  );
7873
7874
  }
7874
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
+
7875
8056
  export {
7876
8057
  isRecord,
7877
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-IJXBOFTY.js";
6
+ } from "./chunk-TD44XVMK.js";
7
7
  import {
8
8
  extractCommandProtectionCommandText,
9
9
  findGitCommitSignals,
10
10
  findPrMergeSignals
11
- } from "./chunk-O7V7LVOY.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-O7V7LVOY.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-YVIDUOHO.js";
7
- import "./chunk-IJXBOFTY.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-O7V7LVOY.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-QQ2ENBZT.js";
11
+ } from "./chunk-N2PL5F67.js";
12
12
  import {
13
13
  AGENT,
14
14
  getMemoryOutputSafetyViolation,
15
15
  headlessAgentRequestSchema
16
- } from "./chunk-O7V7LVOY.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-YVIDUOHO.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-HT56CL2D.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-2TUMNESB.js";
77
+ } from "./chunk-FNPITBXU.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-IJXBOFTY.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-QQ2ENBZT.js";
92
+ } from "./chunk-N2PL5F67.js";
93
93
  import {
94
94
  isRecord as isRecord2
95
95
  } from "./chunk-UZSNFLDQ.js";
@@ -183,6 +183,7 @@ import {
183
183
  USER_MESSAGE_ID_PAYLOAD_KEY,
184
184
  VALID_AGENT_PROVIDERS,
185
185
  WORKSPACE_IDENTITY_AUDIENCE,
186
+ agentCredentialSnapshotSchema,
186
187
  agentQuotaExhaustedPayloadSchema,
187
188
  areSameUserMessageEvents,
188
189
  areUserMessagesWithinMatchWindow,
@@ -316,7 +317,7 @@ import {
316
317
  workspaceCredentialProviderSchema,
317
318
  workspaceTokenRequestSchema,
318
319
  workspaceTokenResponseSchema
319
- } from "./chunk-O7V7LVOY.js";
320
+ } from "./chunk-NJPKCNNS.js";
320
321
  import {
321
322
  cloneMcpConfig,
322
323
  ensureCompatibilityImports,
@@ -10194,6 +10195,7 @@ var EnvironmentDetailsService = class {
10194
10195
  details.supportsChatForkMessage = true;
10195
10196
  details.supportsDeferredChatForking = true;
10196
10197
  details.supportsCredentialSwitching = true;
10198
+ details.supportsChatCredentials = true;
10197
10199
  details.agentCredentials = { ...ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS };
10198
10200
  details.claudeAuthMethod = detectAgentAuthMethod(AGENT.CLAUDE);
10199
10201
  details.codexAuthMethod = detectAgentAuthMethod(AGENT.CODEX);
@@ -13340,11 +13342,14 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13340
13342
  goalClear = null;
13341
13343
  lastRequest = null;
13342
13344
  chatId;
13345
+ onChatCredential;
13343
13346
  chatCredentials = null;
13344
13347
  turnCredentials = null;
13345
13348
  constructor(options) {
13346
13349
  super({ ...options, provider: AGENT.CLAUDE });
13347
13350
  this.chatId = options.chatId;
13351
+ this.onChatCredential = options.onChatCredential ?? (() => {
13352
+ });
13348
13353
  this.historyFilePath = options.historyFilePath ?? join16(homedir11(), ".replicas", "claude", "history.jsonl");
13349
13354
  this.historyFile = new CodexHistoryFile(this.historyFilePath);
13350
13355
  this.initializeManager(this.processMessageInternal.bind(this));
@@ -13834,6 +13839,12 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13834
13839
  const claudeCodeModel = toClaudeCodeModel(resolvedModel, this.turnCredentials ? this.turnCredentials.method === "bedrock" : ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || ENGINE_ENV.CLAUDE_CODE_USE_BEDROCK === "1");
13835
13840
  const resolvedPermissionMode = planMode ? "plan" : "bypassPermissions";
13836
13841
  const resolvedFastMode = Boolean(fastMode && canUseClaudeFastMode(resolvedModel));
13842
+ const chatCredential = this.turnCredentials?.snapshot();
13843
+ this.onChatCredential(chatCredential ? {
13844
+ method: chatCredential.method,
13845
+ scope: chatCredential.scope,
13846
+ ...chatCredential.account ? { account: chatCredential.account } : {}
13847
+ } : "workspace");
13837
13848
  const signature = {
13838
13849
  // Prefixed so a session never carries one side's auth env over to the other.
13839
13850
  credential: this.turnCredentials ? `chat:${JSON.stringify(this.turnCredentials.snapshot())}` : JSON.stringify(ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude),
@@ -60568,6 +60579,7 @@ function normalizePersistedChat(chat) {
60568
60579
  deletedAt: chat.deletedAt ?? null,
60569
60580
  fork: coerceChatForkInfo(chat.fork),
60570
60581
  pendingForkHandoff: chat.pendingForkHandoff === true,
60582
+ ...chat.chatCredential === "workspace" || agentCredentialSnapshotSchema.safeParse(chat.chatCredential).success ? { chatCredential: chat.chatCredential } : {},
60571
60583
  removedMessageIds: Array.isArray(chat.removedMessageIds) ? chat.removedMessageIds.filter((id) => typeof id === "string").slice(-MAX_REMOVED_MESSAGE_IDS) : [],
60572
60584
  acceptedSendResponses: isRecord2(chat.acceptedSendResponses) ? Object.fromEntries(Object.entries(chat.acceptedSendResponses).filter((entry) => {
60573
60585
  const response = entry[1];
@@ -61485,6 +61497,17 @@ var ChatService = class {
61485
61497
  this.agentTokenUsageTracker.noteUsage(persisted.id, payload, occurredAt);
61486
61498
  };
61487
61499
  const onMessageStarted = (message) => this.handleTurnStarted(persisted.id, message);
61500
+ const onChatCredential = (credential) => {
61501
+ if (JSON.stringify(persisted.chatCredential) === JSON.stringify(credential)) return;
61502
+ persisted.chatCredential = credential;
61503
+ void (async () => {
61504
+ await this.persistAllChats();
61505
+ const chat = this.getRuntimeChat(persisted.id);
61506
+ if (chat) await this.publish({ type: "chat.updated", payload: { chat: this.toSummary(chat) } });
61507
+ })().catch((error) => {
61508
+ console.error("[ChatService] Failed to record chat credential:", { chatId: persisted.id, error });
61509
+ });
61510
+ };
61488
61511
  const onProcessingChanged = (processing) => {
61489
61512
  if (processing) return;
61490
61513
  this.handleProcessingStopped(persisted.id);
@@ -61527,6 +61550,7 @@ var ChatService = class {
61527
61550
  fallbackContext,
61528
61551
  chatId: persisted.id,
61529
61552
  onModelSwitched,
61553
+ onChatCredential,
61530
61554
  additionalInstructions,
61531
61555
  linearSessionId: persisted.parentChatId === null ? ENGINE_ENV.REPLICAS_LINEAR_SESSION_ID : void 0,
61532
61556
  ...persisted.provider === "relay" ? { relayParentChatId: persisted.id } : {}
@@ -61601,7 +61625,8 @@ var ChatService = class {
61601
61625
  parentChatId: chat.persisted.parentChatId,
61602
61626
  lastMessageText: chat.persisted.lastMessageText ?? null,
61603
61627
  deletedAt: chat.persisted.deletedAt ?? null,
61604
- fork: chat.persisted.fork ?? null
61628
+ fork: chat.persisted.fork ?? null,
61629
+ ...chat.persisted.chatCredential ? { chatCredential: chat.persisted.chatCredential } : {}
61605
61630
  };
61606
61631
  }
61607
61632
  requireChat(chatId) {
@@ -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-HT56CL2D.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-O7V7LVOY.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-O7V7LVOY.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.926",
3
+ "version": "0.1.928",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",