replicas-engine 0.1.651 → 0.1.653

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.
@@ -782,6 +782,12 @@ function createAcceptedUserMessageEvent(message, messageId, timestamp, images) {
782
782
  }
783
783
  };
784
784
  }
785
+ function getCodexAspTurnResponse(turn) {
786
+ const finalAnswer = turn.items.find((item) => item.type === "agentMessage" && item.phase === "final_answer");
787
+ if (finalAnswer) return finalAnswer;
788
+ if (normalizeCodexAspTranscriptStatus(turn.status) === "in_progress") return null;
789
+ return turn.items.findLast((item) => item.type === "agentMessage") ?? null;
790
+ }
785
791
  function isCodexAspTranscript(value) {
786
792
  if (!isRecord(value)) return false;
787
793
  return typeof value.threadId === "string" && typeof value.updatedAt === "string" && Array.isArray(value.turns);
@@ -949,8 +955,11 @@ function containsKnownSecret(value, secrets) {
949
955
  return flattened.length >= MIN_SECRET_MATCH_CHARS && haystack.includes(flattened);
950
956
  }));
951
957
  }
952
- function isUnsafeMemoryOutput(value, secrets, maxChars) {
953
- return maxChars !== void 0 && value.length > maxChars || containsSecret(value) || containsKnownSecret(value, secrets);
958
+ function getMemoryOutputSafetyViolation(value, secrets, maxChars) {
959
+ if (maxChars !== void 0 && value.length > maxChars) return "max_chars";
960
+ if (containsSecret(value)) return "secret_pattern";
961
+ if (containsKnownSecret(value, secrets)) return "known_secret";
962
+ return null;
954
963
  }
955
964
 
956
965
  // ../shared/src/async.ts
@@ -5397,10 +5406,11 @@ function parseCodexAspTranscript(transcript) {
5397
5406
  for (const turn of transcript.turns) {
5398
5407
  const reasoningIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "reasoning");
5399
5408
  if (reasoningIndex === -1) continue;
5400
- let finalAnswerIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage" && item.phase === "final_answer");
5401
- if (finalAnswerIndex === -1 && normalizeCodexAspTranscriptStatus(turn.status) !== "in_progress") {
5402
- finalAnswerIndex = coalescedItems.findLastIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage");
5403
- }
5409
+ const responseItem = getCodexAspTurnResponse({
5410
+ status: turn.status,
5411
+ items: coalescedItems.filter(({ turn: itemTurn }) => itemTurn.id === turn.id).map(({ item }) => item)
5412
+ });
5413
+ const finalAnswerIndex = responseItem ? coalescedItems.findIndex(({ item }) => item === responseItem) : -1;
5404
5414
  if (finalAnswerIndex === -1 || reasoningIndex < finalAnswerIndex) continue;
5405
5415
  const [reasoning] = coalescedItems.splice(reasoningIndex, 1);
5406
5416
  coalescedItems.splice(finalAnswerIndex, 0, reasoning);
@@ -5922,7 +5932,7 @@ var DEFAULT_CODEX_ARGS = [
5922
5932
  var MIN_CODEX_CLI_VERSION = "0.144.6";
5923
5933
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
5924
5934
  var codexCliVersionEnsured = null;
5925
- var ENGINE_PACKAGE_VERSION = "0.1.651";
5935
+ var ENGINE_PACKAGE_VERSION = "0.1.653";
5926
5936
  var INITIALIZE_METHOD = "initialize";
5927
5937
  var INITIALIZED_NOTIFICATION = "initialized";
5928
5938
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -6250,6 +6260,7 @@ export {
6250
6260
  normalizeCodexAspTranscriptStatus,
6251
6261
  imageContentToUserMessageImages,
6252
6262
  createAcceptedUserMessageEvent,
6263
+ getCodexAspTurnResponse,
6253
6264
  isCodexAspTranscript,
6254
6265
  isCodexAspTranscriptDelta,
6255
6266
  applyCodexAspTranscriptDelta,
@@ -6286,7 +6297,7 @@ export {
6286
6297
  MEMORY_ROOT,
6287
6298
  MEMORY_SUMMARY_FILENAME,
6288
6299
  MEMORY_INDEX_FILENAME,
6289
- isUnsafeMemoryOutput,
6300
+ getMemoryOutputSafetyViolation,
6290
6301
  isSkillRegistryManifest,
6291
6302
  putPresignedFile,
6292
6303
  buildCodexAgentEnv,
@@ -3,11 +3,11 @@ import {
3
3
  AGENT,
4
4
  AppServerProcess,
5
5
  buildCodexAgentEnv,
6
+ getMemoryOutputSafetyViolation,
6
7
  headlessAgentRequestSchema,
7
- isUnsafeMemoryOutput,
8
8
  putPresignedFile,
9
9
  recoverCompletedTurn
10
- } from "./chunk-CJKDLHFP.js";
10
+ } from "./chunk-KWNVQJRM.js";
11
11
 
12
12
  // src/headless-agent.ts
13
13
  import { createHash } from "crypto";
@@ -59,8 +59,13 @@ async function publishFilesystemOutputs(request) {
59
59
  for (const output of request.outputFiles) {
60
60
  const filePath = resolveFile(request.workingDirectory, output.path);
61
61
  const content = (await readFile(filePath, "utf8")).trim();
62
- if (output.minChars !== void 0 && content.length < output.minChars || isUnsafeMemoryOutput(content, request.sensitiveValues, output.maxChars)) {
63
- throw new Error(`Headless agent output failed validation: ${output.path}`);
62
+ if (output.minChars !== void 0 && content.length < output.minChars) {
63
+ throw new Error(`Headless agent output failed validation: ${output.path} has ${content.length} characters; minimum is ${output.minChars}`);
64
+ }
65
+ const safetyViolation = getMemoryOutputSafetyViolation(content, request.sensitiveValues, output.maxChars);
66
+ if (safetyViolation) {
67
+ const reason = safetyViolation === "max_chars" ? `has ${content.length} characters; maximum is ${output.maxChars}` : safetyViolation === "secret_pattern" ? "contains secret-like content" : "contains an installed credential";
68
+ throw new Error(`Headless agent output failed validation: ${output.path} ${reason}`);
64
69
  }
65
70
  await writeFile(filePath, content, { mode: 384 });
66
71
  const { size } = await stat(filePath);
package/dist/src/index.js CHANGED
@@ -119,6 +119,7 @@ import {
119
119
  findPrMergeSignals,
120
120
  getChatHistoryPageWindow,
121
121
  getClaudeModelContextWindow,
122
+ getCodexAspTurnResponse,
122
123
  getDefaultAgentModel,
123
124
  getEventTimestampMs,
124
125
  getGoalCommand,
@@ -172,7 +173,7 @@ import {
172
173
  serializeCanvasContentResponse,
173
174
  shellQuotePosix,
174
175
  stripAgentDiagnosticErrors
175
- } from "./chunk-CJKDLHFP.js";
176
+ } from "./chunk-KWNVQJRM.js";
176
177
 
177
178
  // src/index.ts
178
179
  import { serve } from "@hono/node-server";
@@ -9181,16 +9182,11 @@ async function waitForChatCompletion(chatId, timeoutMs = DEFAULT_SUBAGENT_TIMEOU
9181
9182
  }
9182
9183
  throw new Error(`Subagent chat ${chatId} timed out after ${timeoutMs}ms`);
9183
9184
  }
9184
- async function getChatFinalResponse(chatId) {
9185
- const res = await engineFetch(`/chats/${chatId}/history`);
9186
- if (!res.ok) {
9187
- return "[Failed to retrieve subagent history]";
9188
- }
9189
- let history;
9190
- try {
9191
- history = await res.json();
9192
- } catch {
9193
- return "[Failed to parse subagent history (response may have been interrupted)]";
9185
+ function extractFinalResponse(history) {
9186
+ const turns = history.codexAspTranscript?.turns ?? [];
9187
+ for (let turnIndex = turns.length - 1; turnIndex >= 0; turnIndex--) {
9188
+ const response = getCodexAspTurnResponse(turns[turnIndex]);
9189
+ if (response?.text) return response.text;
9194
9190
  }
9195
9191
  const events = history.events || [];
9196
9192
  for (let i = events.length - 1; i >= 0; i--) {
@@ -9226,7 +9222,20 @@ async function getChatFinalResponse(chatId) {
9226
9222
  if (text) return text;
9227
9223
  }
9228
9224
  }
9229
- return "[No response from subagent]";
9225
+ return null;
9226
+ }
9227
+ async function getChatFinalResponse(chatId) {
9228
+ const res = await engineFetch(`/chats/${chatId}/history`);
9229
+ if (!res.ok) {
9230
+ return "[Failed to retrieve subagent history]";
9231
+ }
9232
+ let history;
9233
+ try {
9234
+ history = await res.json();
9235
+ } catch {
9236
+ return "[Failed to parse subagent history (response may have been interrupted)]";
9237
+ }
9238
+ return extractFinalResponse(history) ?? "[No response from subagent]";
9230
9239
  }
9231
9240
  function buildSpawnAgentTool(parentChatId, availability = {}, getAllowedProviders = () => monolithService.getRelaySubagentProviders()) {
9232
9241
  const codexAvailable = availability.codexAvailable ?? false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.651",
3
+ "version": "0.1.653",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",