replicas-engine 0.1.903 → 0.1.904

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-GAA77UNT.js";
9
- import "./chunk-OBD4D4AW.js";
10
- import "./chunk-6YQDDPWU.js";
8
+ } from "./chunk-WC7COMCW.js";
9
+ import "./chunk-2VZVUDQM.js";
10
+ import "./chunk-5R4AAJD5.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-2ROQAUB6.js";
12
+ import "./chunk-TPOJS4TI.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
  export {
15
15
  getCodexAspHost,
@@ -15,7 +15,7 @@ import {
15
15
  isValidRelayBaseProvider,
16
16
  parsePosixEnvFile,
17
17
  readReplicasRuntimeEnv
18
- } from "./chunk-2ROQAUB6.js";
18
+ } from "./chunk-TPOJS4TI.js";
19
19
 
20
20
  // src/engine-env.ts
21
21
  import { readFileSync as readFileSync2 } from "fs";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-2ROQAUB6.js";
8
+ } from "./chunk-TPOJS4TI.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-2ROQAUB6.js";
7
+ } from "./chunk-TPOJS4TI.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.903";
248
+ var ENGINE_PACKAGE_VERSION = "0.1.904";
249
249
  var INITIALIZE_METHOD = "initialize";
250
250
  var INITIALIZED_NOTIFICATION = "initialized";
251
251
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  publishedPullRequestUrls
6
- } from "./chunk-GFIDOFFP.js";
6
+ } from "./chunk-4M3ZD5FV.js";
7
7
  import {
8
8
  shouldRefreshPullRequests
9
- } from "./chunk-2ROQAUB6.js";
9
+ } from "./chunk-TPOJS4TI.js";
10
10
 
11
11
  // src/services/post-tool-pr-notifier.ts
12
12
  async function notifyPostToolUse(toolName, toolInput, result) {
@@ -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-OBD4D4AW.js";
6
+ } from "./chunk-2VZVUDQM.js";
7
7
  import {
8
8
  extractCommandProtectionCommandText,
9
9
  findGitCommitSignals,
10
10
  findPrMergeSignals
11
- } from "./chunk-2ROQAUB6.js";
11
+ } from "./chunk-TPOJS4TI.js";
12
12
 
13
13
  // src/services/command-protection-service.ts
14
14
  var DEFAULT_COMMAND_PROTECTION_BLOCK_MESSAGE = "Blocked by Replicas command protection.";
@@ -6963,6 +6963,12 @@ var SLASH_COMMANDS = [
6963
6963
  argumentHint: "<objective | pause | resume | clear>",
6964
6964
  providers: ["codex"]
6965
6965
  },
6966
+ {
6967
+ command: "/goal",
6968
+ description: "Set or clear a completion condition to keep working toward.",
6969
+ argumentHint: "<condition | clear>",
6970
+ providers: ["claude"]
6971
+ },
6966
6972
  {
6967
6973
  command: "/compact",
6968
6974
  description: "Compact the conversation context.",
@@ -5,13 +5,13 @@ import {
5
5
  ENGINE_ENV,
6
6
  monolithRequest,
7
7
  setAgentCredentialSnapshot
8
- } from "./chunk-OBD4D4AW.js";
8
+ } from "./chunk-2VZVUDQM.js";
9
9
  import {
10
10
  AppServerProcess,
11
11
  SUBPROCESS_MAX_BUFFER,
12
12
  buildCodexAgentEnv,
13
13
  execFileAsync
14
- } from "./chunk-6YQDDPWU.js";
14
+ } from "./chunk-5R4AAJD5.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-2ROQAUB6.js";
28
+ } from "./chunk-TPOJS4TI.js";
29
29
 
30
30
  // src/managers/codex-token-manager.ts
31
31
  import { promises as fs } from "fs";
@@ -255,7 +255,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
255
255
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
256
256
  await this.applyCredentialsResponse(data);
257
257
  if (data.scope) setAgentCredentialSnapshot("codex", { method: data.type, scope: data.scope, revision: data.revision });
258
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-FPOYHV6O.js");
258
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-75MC3P3L.js");
259
259
  await restartCodexAspHostIfRunning2();
260
260
  });
261
261
  await this.start(true);
@@ -275,7 +275,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
275
275
  await this.applyCredentialUpdate(generation, async () => {
276
276
  await this.applyCredentialsResponse(data);
277
277
  if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
278
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-FPOYHV6O.js");
278
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-75MC3P3L.js");
279
279
  await restartCodexAspHostIfRunning2();
280
280
  }
281
281
  if (data.scope) {
@@ -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-D4UQZM5D.js";
7
- import "./chunk-OBD4D4AW.js";
6
+ } from "./chunk-7W5IP2MX.js";
7
+ import "./chunk-2VZVUDQM.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./chunk-UZSNFLDQ.js";
11
- import "./chunk-2ROQAUB6.js";
11
+ import "./chunk-TPOJS4TI.js";
12
12
  import "./chunk-VEQXQN22.js";
13
13
 
14
14
  // src/command-protection-hook.ts
@@ -3,14 +3,14 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-D4UQZM5D.js";
6
+ } from "./chunk-7W5IP2MX.js";
7
7
  import {
8
8
  notifyPostToolUse
9
- } from "./chunk-YICM7VI4.js";
10
- import "./chunk-GFIDOFFP.js";
11
- import "./chunk-OBD4D4AW.js";
9
+ } from "./chunk-7TNL7LE7.js";
10
+ import "./chunk-4M3ZD5FV.js";
11
+ import "./chunk-2VZVUDQM.js";
12
12
  import "./chunk-UZSNFLDQ.js";
13
- import "./chunk-2ROQAUB6.js";
13
+ import "./chunk-TPOJS4TI.js";
14
14
  import "./chunk-VEQXQN22.js";
15
15
 
16
16
  // src/deepseek-command-protection-plugin.ts
@@ -8,12 +8,12 @@ import {
8
8
  import {
9
9
  AppServerProcess,
10
10
  buildCodexAgentEnv
11
- } from "./chunk-6YQDDPWU.js";
11
+ } from "./chunk-5R4AAJD5.js";
12
12
  import {
13
13
  AGENT,
14
14
  getMemoryOutputSafetyViolation,
15
15
  headlessAgentRequestSchema
16
- } from "./chunk-2ROQAUB6.js";
16
+ } from "./chunk-TPOJS4TI.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
 
19
19
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  evaluateCommandProtection,
92
92
  extractToolCommand,
93
93
  reportCommandProtectionBlock
94
- } from "./chunk-D4UQZM5D.js";
94
+ } from "./chunk-7W5IP2MX.js";
95
95
  import {
96
96
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
97
97
  AGENT_MESSAGE_DELTA_METHOD,
@@ -116,7 +116,7 @@ import {
116
116
  } from "./chunk-FLDA7BX3.js";
117
117
  import {
118
118
  publishedPullRequestUrls
119
- } from "./chunk-GFIDOFFP.js";
119
+ } from "./chunk-4M3ZD5FV.js";
120
120
  import {
121
121
  RELAY_MCP_TOOLS,
122
122
  RELAY_MCP_TOOL_NAMES,
@@ -137,21 +137,21 @@ import {
137
137
  refreshDelayMs,
138
138
  restartCodexAspHost,
139
139
  routineRefreshExclusions
140
- } from "./chunk-GAA77UNT.js";
140
+ } from "./chunk-WC7COMCW.js";
141
141
  import {
142
142
  ENGINE_ENV,
143
143
  IS_WARMING_MODE,
144
144
  monolithRequest,
145
145
  monolithService,
146
146
  setAgentCredentialSnapshot
147
- } from "./chunk-OBD4D4AW.js";
147
+ } from "./chunk-2VZVUDQM.js";
148
148
  import {
149
149
  AspClient,
150
150
  SUBPROCESS_MAX_BUFFER,
151
151
  execAsync,
152
152
  execFileAsync,
153
153
  getCodexModelProvider
154
- } from "./chunk-6YQDDPWU.js";
154
+ } from "./chunk-5R4AAJD5.js";
155
155
  import {
156
156
  isRecord as isRecord2
157
157
  } from "./chunk-UZSNFLDQ.js";
@@ -378,7 +378,7 @@ import {
378
378
  workspaceCredentialProviderSchema,
379
379
  workspaceTokenRequestSchema,
380
380
  workspaceTokenResponseSchema
381
- } from "./chunk-2ROQAUB6.js";
381
+ } from "./chunk-TPOJS4TI.js";
382
382
  import {
383
383
  __commonJS,
384
384
  __export,
@@ -10140,6 +10140,7 @@ var EnvironmentDetailsService = class {
10140
10140
  details.engineVersion = ENGINE_ENV.REPLICAS_SANDBOX_IMAGE_VERSION;
10141
10141
  details.supportsMidTurnSteering = true;
10142
10142
  details.supportsClaudeMidTurnSteering = true;
10143
+ details.supportsClaudeGoals = true;
10143
10144
  details.supportsGoalUpdates = true;
10144
10145
  details.supportsQueuedMessageEditing = true;
10145
10146
  details.supportsChatForking = true;
@@ -12741,6 +12742,7 @@ var CodexHistoryFile = class {
12741
12742
  let found = null;
12742
12743
  try {
12743
12744
  for await (const line of createInterface({ input: createReadStream(this.filePath), crlfDelay: Infinity })) {
12745
+ if (!line.includes(type)) continue;
12744
12746
  const event = parseAgentEventJsonlLine(line);
12745
12747
  if (event?.type === type) found = event;
12746
12748
  }
@@ -13165,6 +13167,9 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13165
13167
  slashCommandsDiscoveredAt = 0;
13166
13168
  slashCommandsDiscovery = null;
13167
13169
  authRetrying = false;
13170
+ currentGoal = null;
13171
+ goalClear = null;
13172
+ lastRequest = null;
13168
13173
  constructor(options) {
13169
13174
  super({ ...options, provider: AGENT.CLAUDE });
13170
13175
  this.historyFilePath = options.historyFilePath ?? join16(homedir11(), ".replicas", "claude", "history.jsonl");
@@ -13184,6 +13189,11 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13184
13189
  const pendingTurn = this.pendingTurn;
13185
13190
  const promptStream = this.activePromptStream;
13186
13191
  if (!pendingTurn || !promptStream) return false;
13192
+ if (getGoalCommand(request.message, request.goalMode)) {
13193
+ this.messageQueue.restoreToQueue(request, 0);
13194
+ await this.interruptActiveTurn();
13195
+ return true;
13196
+ }
13187
13197
  const userMessage = await this.buildUserMessage(request);
13188
13198
  if (this.pendingTurn !== pendingTurn || this.activePromptStream !== promptStream) return false;
13189
13199
  pendingTurn.userMessageUuids.add(userMessage.uuid);
@@ -13213,6 +13223,35 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13213
13223
  isProcessing() {
13214
13224
  return super.isProcessing() || isClaudeSessionActive(this.sessionActivity) || this.hasActiveBackgroundTasks();
13215
13225
  }
13226
+ getGoal() {
13227
+ return this.currentGoal;
13228
+ }
13229
+ async clearGoal(model) {
13230
+ await this.initialized;
13231
+ const previousGoal = this.currentGoal;
13232
+ if (!previousGoal) return null;
13233
+ this.recordGoalChange(null);
13234
+ if (this.sessionId) {
13235
+ this.goalClear = this.executeQuery(
13236
+ { model, ...this.lastRequest, message: "/goal clear", images: void 0, goalMode: false },
13237
+ { skipUserMessageRecord: true }
13238
+ ).finally(() => {
13239
+ this.goalClear = null;
13240
+ });
13241
+ try {
13242
+ await this.goalClear;
13243
+ } catch (error) {
13244
+ this.recordGoalChange(previousGoal);
13245
+ throw error;
13246
+ }
13247
+ }
13248
+ return null;
13249
+ }
13250
+ recordGoalChange(goal) {
13251
+ if (!goal && !this.currentGoal) return;
13252
+ this.currentGoal = goal;
13253
+ this.recordHistoryEvent(CHAT_GOAL_EVENT_TYPE, { goal }, this.historyFile);
13254
+ }
13216
13255
  hasActiveBackgroundTasks() {
13217
13256
  return this.backgroundTasks.active.size > 0 || this.pendingBackgroundCompletion && (isClaudeSessionActive(this.sessionActivity) || this.backgroundContinuationTimer !== null) && !this.messageQueue.isProcessing();
13218
13257
  }
@@ -13426,6 +13465,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13426
13465
  let transientRetries = 0;
13427
13466
  let midTurnContinues = 0;
13428
13467
  let currentRequest = request;
13468
+ await this.goalClear?.catch(() => {
13469
+ });
13429
13470
  try {
13430
13471
  while (true) {
13431
13472
  const attemptedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude;
@@ -13483,7 +13524,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13483
13524
  );
13484
13525
  await this.tearDownSession();
13485
13526
  await new Promise((resolve8) => setTimeout(resolve8, delayMs));
13486
- currentRequest = { ...request, message: CLAUDE_MIDTURN_CONTINUE_PROMPT, images: [] };
13527
+ currentRequest = { ...request, message: CLAUDE_MIDTURN_CONTINUE_PROMPT, images: [], goalMode: false };
13487
13528
  attempt++;
13488
13529
  continue;
13489
13530
  }
@@ -13587,11 +13628,27 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13587
13628
  throw new Error("Message cannot be empty");
13588
13629
  }
13589
13630
  await this.initialized;
13631
+ this.lastRequest = request;
13590
13632
  this.pendingInterrupt = false;
13591
13633
  const userMessage = await this.buildUserMessage(request);
13592
13634
  if (!options.skipUserMessageRecord) {
13593
13635
  await this.recordEvent(userMessage, request.messageId);
13594
13636
  }
13637
+ const goalCommand = getGoalCommand(message, request.goalMode);
13638
+ const goalObjective = goalCommand?.type === "set" ? goalCommand.objective : goalCommand?.type === "resume" ? this.currentGoal?.objective : void 0;
13639
+ if (goalCommand && !options.skipUserMessageRecord) {
13640
+ const now = (/* @__PURE__ */ new Date()).toISOString();
13641
+ this.recordGoalChange(goalObjective ? {
13642
+ threadId: this.sessionId ?? "",
13643
+ objective: goalObjective,
13644
+ status: "active",
13645
+ tokenBudget: null,
13646
+ tokensUsed: 0,
13647
+ timeUsedSeconds: 0,
13648
+ createdAt: now,
13649
+ updatedAt: now
13650
+ } : null);
13651
+ }
13595
13652
  const combinedInstructions = [
13596
13653
  this.buildCombinedInstructions(customInstructions, true),
13597
13654
  "Background tasks must have a concrete completion condition. Use foreground commands for sequential work and managed workspace services for servers. Reserve persistent Monitor tasks for ongoing watches the user requested. You may end a turn while actual background work continues, but do not promise a later update unless a task was successfully launched. Report completion or failure when its notification arrives; do not restart timed-out work automatically."
@@ -13628,7 +13685,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13628
13685
  }
13629
13686
  await new Promise((resolve8, reject) => {
13630
13687
  this.pendingTurn = { resolve: resolve8, reject, sawActivity: false, userMessageUuids: /* @__PURE__ */ new Set([userMessage.uuid]) };
13631
- promptStream.push(userMessage);
13688
+ promptStream.push(goalCommand ? { ...userMessage, message: { role: "user", content: `/goal ${goalObjective ?? "clear"}` } } : userMessage);
13632
13689
  });
13633
13690
  }
13634
13691
  async buildUserMessage({ message, images }) {
@@ -14327,6 +14384,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14327
14384
  }
14328
14385
  async initialize() {
14329
14386
  await mkdir10(dirname4(this.historyFilePath), { recursive: true });
14387
+ const goalEvent = await this.historyFile.findLastEventOfType(CHAT_GOAL_EVENT_TYPE);
14388
+ if (goalEvent) this.currentGoal = coerceChatGoalPayload(goalEvent.payload);
14330
14389
  if (this.initialSessionId) {
14331
14390
  this.sessionId = this.initialSessionId;
14332
14391
  console.log(`[ClaudeManager] Restored session ID from persisted state: ${this.sessionId}`);
@@ -14360,6 +14419,27 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14360
14419
  await this.forwardWorkflowAgentTranscripts(message.task_id);
14361
14420
  }
14362
14421
  await this.recordEvent(message);
14422
+ this.trackGoalProgress(message);
14423
+ }
14424
+ // The SDK doesn't stream goal state, so it is inferred from the evaluator's "not met" feedback and the run's final result.
14425
+ trackGoalProgress(message) {
14426
+ const goal = this.currentGoal;
14427
+ if (!goal) return;
14428
+ if (message.type === "user" && message.isSynthetic) {
14429
+ const content = message.message.content;
14430
+ const text = typeof content === "string" ? content : content[0]?.type === "text" ? content[0].text : "";
14431
+ if (!text.startsWith("Stop hook feedback:")) return;
14432
+ const now = /* @__PURE__ */ new Date();
14433
+ this.recordGoalChange({
14434
+ ...goal,
14435
+ timeUsedSeconds: Math.round((now.getTime() - Date.parse(goal.createdAt)) / 1e3),
14436
+ updatedAt: now.toISOString()
14437
+ });
14438
+ return;
14439
+ }
14440
+ if (message.type === "result" && message.subtype === "success" && message.num_turns > 0 && this.backgroundTasks.active.size === 0) {
14441
+ this.recordGoalChange(null);
14442
+ }
14363
14443
  }
14364
14444
  // Claude Code intercepts /compact and auto-compaction inside the SDK process; we just observe the status messages to mirror state to the UI.
14365
14445
  trackNativeCompaction(message) {
@@ -62010,7 +62090,7 @@ var ChatService = class {
62010
62090
  chat.activeMessageId = null;
62011
62091
  chat.pendingMessageIds = [];
62012
62092
  chat.acceptedUserEvents.clear();
62013
- const goal = await chat.provider.clearGoal();
62093
+ const goal = await chat.provider.clearGoal(chat.persisted.model);
62014
62094
  this.touch(chat);
62015
62095
  await this.publish({
62016
62096
  type: "chat.interrupted",
@@ -64313,7 +64393,7 @@ function createV1Routes(deps) {
64313
64393
  if (error instanceof ChatNotFoundError) {
64314
64394
  return c.json(jsonError("Failed to clear goal", error.message), 404);
64315
64395
  }
64316
- return c.json(jsonError("Failed to clear goal", error instanceof Error ? error.message : "Unknown error"), 404);
64396
+ return c.json(jsonError("Failed to clear goal", error instanceof Error ? error.message : "Unknown error"), 500);
64317
64397
  }
64318
64398
  });
64319
64399
  app2.post("/chat-transcripts/flush-all", async (c) => {
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  notifyPostToolUse
6
- } from "./chunk-YICM7VI4.js";
7
- import "./chunk-GFIDOFFP.js";
6
+ } from "./chunk-7TNL7LE7.js";
7
+ import "./chunk-4M3ZD5FV.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./chunk-UZSNFLDQ.js";
11
- import "./chunk-2ROQAUB6.js";
11
+ import "./chunk-TPOJS4TI.js";
12
12
  import "./chunk-VEQXQN22.js";
13
13
 
14
14
  // src/post-tool-pr-hook.ts
@@ -11,7 +11,7 @@ import {
11
11
  relaySubagentResponseSchema,
12
12
  spawnRelaySubagentRequestSchema,
13
13
  waitRelaySubagentRequestSchema
14
- } from "./chunk-2ROQAUB6.js";
14
+ } from "./chunk-TPOJS4TI.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.903",
3
+ "version": "0.1.904",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",