openfox 2.0.0-beta.1 → 2.0.0-beta.10

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.
Files changed (48) hide show
  1. package/dist/agent-defaults/code-reviewer.agent.md +2 -1
  2. package/dist/{chat-handler-IVIWOR3D.js → chat-handler-6COBLIDR.js} +14 -27
  3. package/dist/{chunk-CEZNMLOO.js → chunk-7TTEGAO6.js} +12 -13
  4. package/dist/{chunk-4U4CSRBE.js → chunk-BE2S4NJX.js} +6 -6
  5. package/dist/{chunk-FQLK5GL5.js → chunk-BVHFMAVN.js} +1 -1
  6. package/dist/{chunk-UFY4I643.js → chunk-C75I2KZM.js} +135 -147
  7. package/dist/{chunk-QFSSKIQ3.js → chunk-CDDMHSZF.js} +4 -4
  8. package/dist/{chunk-RF2JGDSS.js → chunk-DMH6JVPF.js} +13 -10
  9. package/dist/{chunk-NNEHZT3V.js → chunk-EZUR7OEP.js} +11 -3
  10. package/dist/{chunk-ZLUBZ4K4.js → chunk-G4SACK4E.js} +221 -104
  11. package/dist/{chunk-ALH4KM2Y.js → chunk-LR5R7EEE.js} +2962 -3249
  12. package/dist/{chunk-XKR3HCAL.js → chunk-NPHYEUYE.js} +128 -34
  13. package/dist/{chunk-PSJIT5LZ.js → chunk-RFNEDBVO.js} +4 -4
  14. package/dist/chunk-RI6GAMNP.js +13 -0
  15. package/dist/{chunk-HHAJ3QF6.js → chunk-UKTPL5ZG.js} +16 -28
  16. package/dist/{chunk-HGAMIPFO.js → chunk-VIIRNJDT.js} +39 -178
  17. package/dist/{chunk-NONI4CRP.js → chunk-XJEOP6XU.js} +5 -32
  18. package/dist/cli/dev.js +1 -1
  19. package/dist/cli/index.js +1 -1
  20. package/dist/compactor-TDNRM3A7.js +9 -0
  21. package/dist/{config-YU7NYZYG.js → config-TDVA7MQN.js} +9 -8
  22. package/dist/{events-OHJWCI3S.js → events-PQ3KTI5H.js} +8 -7
  23. package/dist/{folding-U6UHQAS5.js → folding-CXORTBAU.js} +2 -2
  24. package/dist/{orchestrator-7ZXM4J22.js → orchestrator-ZNGTMZ7W.js} +18 -22
  25. package/dist/package.json +1 -1
  26. package/dist/{processor-TKBJLQ2N.js → processor-WMAU4C2N.js} +8 -9
  27. package/dist/{protocol-BQ12Aw5J.d.ts → protocol-CDOV1pyc.d.ts} +13 -38
  28. package/dist/{protocol-K62EPEGS.js → protocol-CN24IKQN.js} +3 -5
  29. package/dist/{provider-HTJEB3ON.js → provider-BGH4MBLH.js} +25 -10
  30. package/dist/{serve-5KA6SSSP.js → serve-7VMTNIXT.js} +25 -26
  31. package/dist/server/index.d.ts +1 -6
  32. package/dist/server/index.js +15 -16
  33. package/dist/{settings-VRAOAPLA.js → settings-6XX56F3F.js} +2 -2
  34. package/dist/shared/index.d.ts +2 -2
  35. package/dist/shared/index.js +1 -1
  36. package/dist/{tools-Z7X4HXZN.js → tools-CQGEU3JK.js} +11 -13
  37. package/dist/web/assets/index-BF6jgTAb.js +299 -0
  38. package/dist/web/assets/{index-BY8EbT5Z.css → index-CSOB8dwI.css} +1 -1
  39. package/dist/web/index.html +2 -2
  40. package/dist/web/sw.js +1 -1
  41. package/dist/workflow-defaults/default.workflow.json +9 -4
  42. package/package.json +1 -1
  43. package/dist/auto-compaction-UIWTO3H5.js +0 -27
  44. package/dist/chunk-CGZHLM3K.js +0 -70
  45. package/dist/chunk-SZKEGZIB.js +0 -140
  46. package/dist/runtime-config-NPSPMRDA.js +0 -9
  47. package/dist/vision-fallback-3MIZZ6NQ.js +0 -22
  48. package/dist/web/assets/index-CqOJgw7l.js +0 -299
@@ -6,11 +6,12 @@ subagent: true
6
6
  color: '#ef4444'
7
7
  allowedTools:
8
8
  - read_file
9
+ - run_command
9
10
  - web_fetch
10
11
  - session_metadata:get,add,update,remove
11
12
  ---
12
13
 
13
- You are a code reviewer. Review all current changes.
14
+ You are a code reviewer. Review the **git diff** of the modified files rather than reading the full files.
14
15
  You're mostly interested in:
15
16
 
16
17
  1. **For the user (UX interaction)** — does this feel good to use? Any rough edges, confusing behavior, or unnecessary friction?
@@ -5,40 +5,38 @@ import {
5
5
  generateSessionName,
6
6
  getSessionMessageCount,
7
7
  needsNameGenerationCheck
8
- } from "./chunk-QFSSKIQ3.js";
8
+ } from "./chunk-CDDMHSZF.js";
9
9
  import {
10
10
  runChatTurn
11
- } from "./chunk-UFY4I643.js";
12
- import "./chunk-ALH4KM2Y.js";
13
- import "./chunk-PSJIT5LZ.js";
14
- import "./chunk-XAMAYRDA.js";
11
+ } from "./chunk-C75I2KZM.js";
12
+ import "./chunk-LR5R7EEE.js";
15
13
  import "./chunk-DL6ZILAF.js";
16
14
  import "./chunk-PBGOZMVY.js";
17
15
  import "./chunk-VRGRAQDG.js";
18
- import "./chunk-HGAMIPFO.js";
19
16
  import {
20
17
  getEventStore
21
- } from "./chunk-XKR3HCAL.js";
22
- import "./chunk-FBGWG4N6.js";
23
- import "./chunk-NONI4CRP.js";
18
+ } from "./chunk-NPHYEUYE.js";
19
+ import "./chunk-XJEOP6XU.js";
24
20
  import {
25
21
  createChatMessageMessage,
26
22
  createPhaseChangedMessage,
27
23
  createSessionRunningMessage
28
- } from "./chunk-CEZNMLOO.js";
24
+ } from "./chunk-7TTEGAO6.js";
29
25
  import "./chunk-BJYPTN5S.js";
30
- import "./chunk-FQLK5GL5.js";
31
- import "./chunk-CQGTEGKL.js";
32
- import "./chunk-CGZHLM3K.js";
33
- import "./chunk-SZKEGZIB.js";
26
+ import "./chunk-RFNEDBVO.js";
27
+ import "./chunk-XAMAYRDA.js";
28
+ import "./chunk-FBGWG4N6.js";
29
+ import "./chunk-BVHFMAVN.js";
30
+ import "./chunk-VIIRNJDT.js";
34
31
  import {
35
32
  logger
36
33
  } from "./chunk-K44MW7JJ.js";
34
+ import "./chunk-CQGTEGKL.js";
37
35
 
38
36
  // src/server/session/chat-handler.ts
39
37
  var activeAgents = /* @__PURE__ */ new Map();
40
38
  async function startChatSession(sessionId, content, deps, options) {
41
- const { sessionManager, llmClient, statsIdentity, broadcastForSession } = deps;
39
+ const { sessionManager, llmClient, broadcastForSession } = deps;
42
40
  const session = sessionManager.getSession(sessionId);
43
41
  if (!session) {
44
42
  throw new Error("Session not found");
@@ -60,17 +58,6 @@ async function startChatSession(sessionId, content, deps, options) {
60
58
  sessionManager.setRunning(sessionId, true);
61
59
  broadcastForSession(sessionId, createSessionRunningMessage(true));
62
60
  try {
63
- const { maybeAutoCompactContext } = await import("./auto-compaction-UIWTO3H5.js");
64
- await maybeAutoCompactContext({
65
- sessionManager,
66
- sessionId,
67
- llmClient,
68
- statsIdentity,
69
- signal: controller.signal
70
- });
71
- if (controller.signal.aborted) {
72
- return;
73
- }
74
61
  const userMessage = sessionManager.addMessage(sessionId, {
75
62
  role: "user",
76
63
  content,
@@ -174,4 +161,4 @@ export {
174
161
  startChatSession,
175
162
  stopSessionExecution
176
163
  };
177
- //# sourceMappingURL=chat-handler-IVIWOR3D.js.map
164
+ //# sourceMappingURL=chat-handler-6COBLIDR.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createServerMessage,
3
3
  isClientMessage
4
- } from "./chunk-FQLK5GL5.js";
4
+ } from "./chunk-BVHFMAVN.js";
5
5
 
6
6
  // src/server/ws/protocol.ts
7
7
  function enrichMessagesWithToolResults(messages) {
@@ -94,8 +94,14 @@ function createChatTodoMessage(todos) {
94
94
  function createChatProgressMessage(message, phase) {
95
95
  return createServerMessage("chat.progress", { message, ...phase ? { phase } : {} });
96
96
  }
97
- function createChatFormatRetryMessage(attempt, maxAttempts) {
98
- return createServerMessage("chat.format_retry", { attempt, maxAttempts });
97
+ function createChatFormatRetryMessage(attempt, maxAttempts, pattern, field, matchedContent) {
98
+ return createServerMessage("chat.format_retry", {
99
+ attempt,
100
+ maxAttempts,
101
+ ...pattern !== void 0 ? { pattern } : {},
102
+ ...field !== void 0 ? { field } : {},
103
+ ...matchedContent !== void 0 ? { matchedContent } : {}
104
+ });
99
105
  }
100
106
  function createChatMessageMessage(message) {
101
107
  return createServerMessage("chat.message", { message });
@@ -120,9 +126,6 @@ function createChatPathConfirmationMessage(callId, tool, paths, workdir, reason)
120
126
  function createChatAskUserMessage(callId, question) {
121
127
  return createServerMessage("chat.ask_user", { callId, question });
122
128
  }
123
- function createChatVisionFallbackMessage(payload) {
124
- return createServerMessage("chat.vision_fallback", payload);
125
- }
126
129
  function createModeChangedMessage(mode, auto, reason) {
127
130
  return createServerMessage("mode.changed", { mode, auto, ...reason ? { reason } : {} });
128
131
  }
@@ -198,9 +201,6 @@ function storedEventToServerMessage(event) {
198
201
  if (data.stats) {
199
202
  updates.stats = data.stats;
200
203
  }
201
- if (data.promptContext) {
202
- updates.promptContext = data.promptContext;
203
- }
204
204
  return createChatMessageUpdatedMessage(data.messageId, updates);
205
205
  }
206
206
  case "tool.preparing": {
@@ -283,9 +283,9 @@ function storedEventToServerMessage(event) {
283
283
  const data = event.data;
284
284
  return createChatAskUserMessage(data.callId, data.question);
285
285
  }
286
- case "format.retry": {
286
+ case "pattern.retry": {
287
287
  const data = event.data;
288
- return createChatFormatRetryMessage(data.attempt, data.maxAttempts);
288
+ return createChatFormatRetryMessage(data.attempt, data.maxAttempts, data.pattern, data.field, data.matchedContent);
289
289
  }
290
290
  case "turn.snapshot":
291
291
  case "context.compacted":
@@ -320,7 +320,6 @@ export {
320
320
  createChatErrorMessage,
321
321
  createChatPathConfirmationMessage,
322
322
  createChatAskUserMessage,
323
- createChatVisionFallbackMessage,
324
323
  createModeChangedMessage,
325
324
  createPhaseChangedMessage,
326
325
  createCriteriaUpdatedMessage,
@@ -334,4 +333,4 @@ export {
334
333
  createQueueStateMessage,
335
334
  storedEventToServerMessage
336
335
  };
337
- //# sourceMappingURL=chunk-CEZNMLOO.js.map
336
+ //# sourceMappingURL=chunk-7TTEGAO6.js.map
@@ -33,7 +33,7 @@ Options:
33
33
  }
34
34
  async function runNetworkSetup(mode) {
35
35
  const { loadAuthConfig, saveAuthConfig, encryptPassword } = await import("./auth-56SIRACI.js");
36
- const { saveGlobalConfig } = await import("./config-YU7NYZYG.js");
36
+ const { saveGlobalConfig } = await import("./config-TDVA7MQN.js");
37
37
  const { getAuthKeyPath } = await import("./paths-X46PPOI2.js");
38
38
  const existingAuth = await loadAuthConfig(mode);
39
39
  if (existingAuth) {
@@ -94,7 +94,7 @@ async function runNetworkSetup(mode) {
94
94
  console.log("\u2713 Configuration saved!\n");
95
95
  }
96
96
  async function runConfig(mode) {
97
- const { loadGlobalConfig, getActiveProvider, getDefaultModel } = await import("./config-YU7NYZYG.js");
97
+ const { loadGlobalConfig, getActiveProvider, getDefaultModel } = await import("./config-TDVA7MQN.js");
98
98
  const { getGlobalConfigPath } = await import("./paths-X46PPOI2.js");
99
99
  const config = await loadGlobalConfig(mode);
100
100
  const configPath = getGlobalConfigPath(mode);
@@ -151,7 +151,7 @@ async function runCli(options) {
151
151
  break;
152
152
  }
153
153
  case "provider": {
154
- const { runProviderCommand } = await import("./provider-HTJEB3ON.js");
154
+ const { runProviderCommand } = await import("./provider-BGH4MBLH.js");
155
155
  const [, subcommand] = positionals;
156
156
  await runProviderCommand(mode, subcommand);
157
157
  break;
@@ -188,12 +188,12 @@ async function runCli(options) {
188
188
  break;
189
189
  }
190
190
  default: {
191
- const { configFileExists } = await import("./config-YU7NYZYG.js");
191
+ const { configFileExists } = await import("./config-TDVA7MQN.js");
192
192
  const configExists = await configFileExists(mode);
193
193
  if (!configExists) {
194
194
  await runNetworkSetup(mode);
195
195
  }
196
- const { runServe } = await import("./serve-5KA6SSSP.js");
196
+ const { runServe } = await import("./serve-7VMTNIXT.js");
197
197
  const serveOptions = { mode };
198
198
  if (values.port) serveOptions.port = parseInt(values.port);
199
199
  if (values["no-browser"] === true) serveOptions.openBrowser = false;
@@ -205,4 +205,4 @@ async function runCli(options) {
205
205
  export {
206
206
  runCli
207
207
  };
208
- //# sourceMappingURL=chunk-4U4CSRBE.js.map
208
+ //# sourceMappingURL=chunk-BE2S4NJX.js.map
@@ -26,4 +26,4 @@ export {
26
26
  isClientMessage,
27
27
  isServerMessage
28
28
  };
29
- //# sourceMappingURL=chunk-FQLK5GL5.js.map
29
+ //# sourceMappingURL=chunk-BVHFMAVN.js.map
@@ -1,57 +1,78 @@
1
1
  import {
2
- BUILDER_KICKOFF_PROMPT,
3
2
  PathAccessDeniedError,
4
3
  TurnMetrics,
5
- VERIFIER_KICKOFF_PROMPT,
4
+ WORKFLOW_KICKOFF_PROMPT,
6
5
  assembleAgentRequest,
7
6
  buildAgentReminder,
7
+ createAssemblyResult,
8
8
  createChatDoneEvent,
9
9
  createMessageStartEvent,
10
- executeSubAgent,
11
10
  findAgentById,
11
+ getAllInstructions,
12
+ getConversationMessages,
13
+ getEnabledSkillMetadata,
12
14
  getSubAgents,
13
15
  getToolRegistryForAgent,
14
16
  loadAllAgentsDefault,
17
+ processEventsForConversation,
15
18
  runTopLevelAgentLoop
16
- } from "./chunk-ALH4KM2Y.js";
19
+ } from "./chunk-LR5R7EEE.js";
17
20
  import {
18
21
  getCurrentContextWindowId,
19
- getEventStore
20
- } from "./chunk-XKR3HCAL.js";
22
+ getCurrentWindowMessageOptions,
23
+ getEventStore,
24
+ getRuntimeConfig
25
+ } from "./chunk-NPHYEUYE.js";
21
26
  import {
22
27
  buildSnapshotFromSessionState
23
- } from "./chunk-NONI4CRP.js";
28
+ } from "./chunk-XJEOP6XU.js";
24
29
  import {
25
30
  logger
26
31
  } from "./chunk-K44MW7JJ.js";
32
+ import {
33
+ getGlobalConfigDir
34
+ } from "./chunk-CQGTEGKL.js";
27
35
 
28
- // src/server/sub-agents/verifier-helpers.ts
29
- var MAX_CONSECUTIVE_VERIFIER_NUDGES = 10;
30
- var VERIFIER_STALL_REASON = "Verifier stopped repeatedly before terminalizing verification after repeated nudges.";
31
- function getCriteriaAwaitingVerification(criteria) {
32
- return criteria.filter((criterion) => criterion.status.type === "completed");
33
- }
34
- function buildVerifierNudgeContent(criteria) {
35
- const ids = criteria.map((criterion) => criterion.id).join(", ");
36
- return `You stopped before finalizing verification. ${criteria.length} criteria still need a terminal verification result. Use criterion with action "pass" or "fail" for each remaining criterion: ${ids}.`;
37
- }
38
- function buildVerifierRestartContent(criteria) {
39
- const ids = criteria.map((criterion) => criterion.id).join(", ");
40
- return `${VERIFIER_STALL_REASON} Leaving remaining criteria unchanged so verification can restart in a fresh window: ${ids}.`;
41
- }
42
- function createVerifierNudgeConfig() {
43
- return {
44
- maxConsecutiveNudges: MAX_CONSECUTIVE_VERIFIER_NUDGES,
45
- getCriteriaAwaiting: getCriteriaAwaitingVerification,
46
- buildNudgeContent: buildVerifierNudgeContent,
47
- buildRestartContent: buildVerifierRestartContent
48
- };
36
+ // src/server/chat/dynamic-context.ts
37
+ import { createHash } from "crypto";
38
+ function computeDynamicContextHash(instructionContent, skills) {
39
+ const dynamicInputs = JSON.stringify({
40
+ instructions: instructionContent,
41
+ skills: skills.map((s) => s.id).sort()
42
+ });
43
+ return createHash("sha256").update(dynamicInputs).digest("hex");
49
44
  }
50
45
 
51
46
  // src/server/chat/orchestrator.ts
52
- function getCurrentWindowMessageOptions(sessionId) {
53
- const contextWindowId = getCurrentContextWindowId(sessionId);
54
- return contextWindowId ? { contextWindowId } : void 0;
47
+ async function buildRetryPatterns() {
48
+ const { getSetting, SETTINGS_KEYS } = await import("./settings-6XX56F3F.js");
49
+ const raw = getSetting(SETTINGS_KEYS.RETRY_PATTERNS);
50
+ if (!raw) {
51
+ const oldXmlProtection = getSetting("llm.disableXmlProtection");
52
+ if (oldXmlProtection !== null) {
53
+ const disabled = oldXmlProtection === "true";
54
+ return {
55
+ retryPatterns: disabled ? [] : [{ field: "both", pattern: "<(tool_call|function=|/tool_call|parameter=)", action: "retry", active: true }],
56
+ maxRetriesPerTurn: 10
57
+ };
58
+ }
59
+ return { retryPatterns: [], maxRetriesPerTurn: 10 };
60
+ }
61
+ try {
62
+ const parsed = JSON.parse(raw);
63
+ return {
64
+ retryPatterns: Array.isArray(parsed.patterns) ? parsed.patterns : [],
65
+ maxRetriesPerTurn: typeof parsed.maxRetriesPerTurn === "number" ? parsed.maxRetriesPerTurn : 10
66
+ };
67
+ } catch {
68
+ return { retryPatterns: [], maxRetriesPerTurn: 10 };
69
+ }
70
+ }
71
+ function buildGetConversationMessages(sessionId, llmClient, append) {
72
+ return async () => {
73
+ const processedEvents = await processEventsForConversation(sessionId, llmClient, (event) => append(event));
74
+ return getConversationMessages({ type: "toplevel", sessionId }, { events: processedEvents });
75
+ };
55
76
  }
56
77
  function resolveStatsIdentity(options) {
57
78
  const model = options.llmClient.getModel();
@@ -75,13 +96,11 @@ async function runChatTurn(options) {
75
96
  const session = sessionManager.requireSession(sessionId);
76
97
  const mode = session.mode;
77
98
  logger.debug("Starting chat turn", { sessionId, mode });
99
+ sessionManager.setRunning(sessionId, true);
100
+ const append = (event) => eventStore.append(sessionId, event);
78
101
  const turnMetrics = new TurnMetrics();
79
102
  try {
80
- if (mode === "builder") {
81
- await runBuilderTurn(options, turnMetrics);
82
- } else {
83
- await runGenericAgentTurn(options, turnMetrics, mode);
84
- }
103
+ await runAgentTurn(options, turnMetrics, mode, append);
85
104
  const snapshot = buildSnapshot(sessionManager, sessionId, turnMetrics.buildStats(statsIdentity, mode));
86
105
  const snapshotEvent = eventStore.append(sessionId, { type: "turn.snapshot", data: snapshot });
87
106
  const deletedCount = eventStore.cleanupOldEvents(sessionId);
@@ -147,18 +166,30 @@ async function runChatTurn(options) {
147
166
  eventStore.append(sessionId, { type: "running.changed", data: { isRunning: false } });
148
167
  }
149
168
  }
169
+ function windowHasReminder(sessionId, windowId) {
170
+ const eventStore = getEventStore();
171
+ const events = eventStore.getEvents(sessionId);
172
+ return events.some((event) => {
173
+ if (event.type !== "message.start") return false;
174
+ const data = event.data;
175
+ return data.contextWindowId === windowId && data.messageKind === "auto-prompt" && typeof data.content === "string" && data.content.includes("<system-reminder>");
176
+ });
177
+ }
150
178
  function injectModeReminderIfNeeded(sessionManager, sessionId, agentId, allAgents, _onMessage) {
151
179
  const eventStore = getEventStore();
152
180
  const session = sessionManager.requireSession(sessionId);
181
+ const currentWindowId = getCurrentContextWindowId(sessionId);
153
182
  const lastModeReminder = session.executionState?.lastModeWithReminder;
154
183
  if (lastModeReminder === agentId) {
155
- return;
184
+ if (!currentWindowId || windowHasReminder(sessionId, currentWindowId)) {
185
+ return;
186
+ }
156
187
  }
157
188
  const agentDef = findAgentById(agentId, allAgents);
158
189
  if (!agentDef) return;
159
190
  const reminderContent = buildAgentReminder(agentDef);
160
191
  const reminderMsgId = crypto.randomUUID();
161
- const currentWindowMessageOptions = getCurrentContextWindowId(sessionId) ? { contextWindowId: getCurrentContextWindowId(sessionId) } : void 0;
192
+ const currentWindowMessageOptions = currentWindowId ? { contextWindowId: currentWindowId } : void 0;
162
193
  eventStore.append(sessionId, {
163
194
  type: "message.start",
164
195
  data: {
@@ -183,130 +214,88 @@ function injectModeReminderIfNeeded(sessionManager, sessionId, agentId, allAgent
183
214
  lastModeWithReminder: agentId
184
215
  });
185
216
  }
186
- async function runGenericAgentTurn(options, turnMetrics, agentId) {
217
+ async function runAgentTurn(options, turnMetrics, agentId, append, callbacks) {
187
218
  const statsIdentity = resolveStatsIdentity(options);
188
219
  const allAgents = await loadAllAgentsDefault();
189
220
  injectModeReminderIfNeeded(options.sessionManager, options.sessionId, agentId, allAgents, options.onMessage);
190
221
  const agentDef = findAgentById(agentId, allAgents) ?? findAgentById("planner", allAgents);
191
222
  const subAgentDefs = getSubAgents(allAgents);
192
- await runTopLevelAgentLoop(
223
+ const { content: instructionContent } = await getAllInstructions(
224
+ options.sessionManager.requireSession(options.sessionId).workdir,
225
+ options.sessionManager.requireSession(options.sessionId).projectId
226
+ );
227
+ const runtimeConfig = getRuntimeConfig();
228
+ const configDir = getGlobalConfigDir(runtimeConfig.mode ?? "production");
229
+ const skills = await getEnabledSkillMetadata(configDir, runtimeConfig.workdir);
230
+ return runTopLevelAgentLoop(
193
231
  {
194
232
  mode: agentId,
233
+ append,
234
+ ...await buildRetryPatterns(),
195
235
  sessionManager: options.sessionManager,
196
236
  sessionId: options.sessionId,
197
237
  llmClient: options.llmClient,
198
238
  statsIdentity,
199
239
  signal: options.signal,
200
240
  onMessage: options.onMessage,
201
- assembleRequest: (input) => assembleAgentRequest({ ...input, agentDef, subAgentDefs, modelName: options.llmClient.getModel() }),
202
- getToolRegistry: () => getToolRegistryForAgent(agentDef)
203
- },
204
- turnMetrics
205
- );
206
- }
207
- function filterToolRegistryForStepDone(baseRegistry, _injectStepDone) {
208
- return baseRegistry;
209
- }
210
- async function runBuilderTurn(options, turnMetrics) {
211
- const { sessionManager, sessionId } = options;
212
- const statsIdentity = resolveStatsIdentity(options);
213
- const eventStore = getEventStore();
214
- const allAgents = await loadAllAgentsDefault();
215
- injectModeReminderIfNeeded(options.sessionManager, options.sessionId, "builder", allAgents, options.onMessage);
216
- const builderDef = findAgentById("builder", allAgents);
217
- const subAgentDefs = getSubAgents(allAgents);
218
- let stepDoneCalled = false;
219
- return {
220
- ...await runTopLevelAgentLoop(
221
- {
222
- mode: "builder",
223
- sessionManager,
224
- sessionId,
225
- llmClient: options.llmClient,
226
- statsIdentity,
227
- signal: options.signal,
228
- onMessage: options.onMessage,
229
- assembleRequest: (input) => assembleAgentRequest({
230
- ...input,
231
- agentDef: builderDef,
232
- subAgentDefs,
233
- modelName: options.llmClient.getModel()
234
- }),
235
- getToolRegistry: () => {
236
- const baseRegistry = getToolRegistryForAgent(builderDef);
237
- return filterToolRegistryForStepDone(baseRegistry, options.injectStepDone === true);
238
- },
239
- onToolExecuted: (toolCall, toolResult) => {
240
- if (toolCall.name === "step_done" && toolResult.success) {
241
- stepDoneCalled = true;
242
- }
243
- if (toolResult.success && ["write_file", "edit_file"].includes(toolCall.name)) {
244
- const path = toolCall.arguments["path"];
245
- sessionManager.addModifiedFile(sessionId, path);
241
+ assembleRequest: (input) => {
242
+ const cached = options.sessionManager.getCachedPrompt(options.sessionId);
243
+ if (cached) {
244
+ const currentHash = computeDynamicContextHash(instructionContent ?? "", skills);
245
+ if (cached.hash !== currentHash) {
246
+ options.sessionManager.setDynamicContextChanged(options.sessionId, true);
246
247
  }
247
- },
248
- injectKickoff: () => {
249
- if (options.injectBuilderKickoff !== true) return;
250
- const session = sessionManager.requireSession(sessionId);
251
- const currentWindowMessageOptions = getCurrentContextWindowId(sessionId) ? { contextWindowId: getCurrentContextWindowId(sessionId) } : void 0;
252
- const events = eventStore.getEvents(sessionId);
253
- const hasBuilderKickoff = events.some((e) => {
254
- if (e.type !== "message.start") return false;
255
- const data = e.data;
256
- return data.messageKind === "auto-prompt" && data.content?.includes("fulfil the");
248
+ return createAssemblyResult({
249
+ systemPrompt: cached.systemPrompt,
250
+ messages: input.messages,
251
+ injectedFiles: input.injectedFiles,
252
+ requestTools: input.promptTools,
253
+ toolChoice: input.toolChoice,
254
+ disableThinking: false
257
255
  });
258
- if (!hasBuilderKickoff) {
259
- const kickoffMsgId = crypto.randomUUID();
260
- const kickoffContent = BUILDER_KICKOFF_PROMPT(session.criteria.length);
261
- const msgMetadata = { type: "workflow", name: "Workflow", color: "#f59e0b" };
262
- eventStore.append(
263
- sessionId,
264
- createMessageStartEvent(kickoffMsgId, "user", kickoffContent, {
265
- ...currentWindowMessageOptions ?? {},
266
- isSystemGenerated: true,
267
- messageKind: "auto-prompt",
268
- metadata: msgMetadata
269
- })
270
- );
271
- eventStore.append(sessionId, { type: "message.done", data: { messageId: kickoffMsgId } });
272
- }
273
256
  }
257
+ const result = assembleAgentRequest({
258
+ ...input,
259
+ agentDef,
260
+ subAgentDefs,
261
+ modelName: options.llmClient.getModel()
262
+ });
263
+ const hash = computeDynamicContextHash(instructionContent ?? "", skills);
264
+ options.sessionManager.setCachedPrompt(options.sessionId, result.systemPrompt, hash);
265
+ return result;
274
266
  },
275
- turnMetrics
276
- ),
277
- stepDoneCalled
278
- };
267
+ getToolRegistry: () => getToolRegistryForAgent(agentDef),
268
+ getConversationMessages: buildGetConversationMessages(options.sessionId, options.llmClient, append),
269
+ injectModeReminder: () => injectModeReminderIfNeeded(options.sessionManager, options.sessionId, agentId, allAgents, options.onMessage),
270
+ ...callbacks?.injectKickoff ? { injectKickoff: callbacks.injectKickoff } : {},
271
+ ...callbacks?.onToolExecuted ? { onToolExecuted: callbacks.onToolExecuted } : {}
272
+ },
273
+ turnMetrics
274
+ );
279
275
  }
280
- async function runVerifierTurn(options, turnMetrics) {
281
- const { sessionManager, sessionId, llmClient, signal, onMessage } = options;
282
- const statsIdentity = resolveStatsIdentity(options);
276
+ function injectWorkflowKickoffIfNeeded(sessionManager, sessionId, eventStore) {
283
277
  const session = sessionManager.requireSession(sessionId);
284
- const toVerify = session.criteria.filter((c) => c.status.type === "completed");
285
- if (toVerify.length === 0) {
286
- logger.debug("Nothing to verify", { sessionId });
287
- return { allPassed: true, failed: [] };
288
- }
289
- const allAgents = await loadAllAgentsDefault();
290
- const verifierDef = findAgentById("verifier", allAgents);
291
- const toolRegistry = getToolRegistryForAgent(verifierDef);
292
- const result = await executeSubAgent({
293
- subAgentType: "verifier",
294
- prompt: VERIFIER_KICKOFF_PROMPT,
295
- sessionManager,
296
- sessionId,
297
- llmClient,
298
- toolRegistry,
299
- turnMetrics,
300
- statsIdentity,
301
- signal,
302
- onMessage,
303
- nudgeConfig: createVerifierNudgeConfig()
278
+ const currentWindowMessageOptions = getCurrentContextWindowId(sessionId) ? { contextWindowId: getCurrentContextWindowId(sessionId) } : void 0;
279
+ const events = eventStore.getEvents(sessionId);
280
+ const hasKickoff = events.some((e) => {
281
+ if (e.type !== "message.start") return false;
282
+ const data = e.data;
283
+ return data.messageKind === "auto-prompt" && data.content?.includes("fulfil the");
304
284
  });
305
- return {
306
- allPassed: result.allPassed ?? true,
307
- failed: result.failed ?? [],
308
- content: result.content
309
- };
285
+ if (!hasKickoff) {
286
+ const kickoffMsgId = crypto.randomUUID();
287
+ const kickoffContent = WORKFLOW_KICKOFF_PROMPT(session.criteria.length);
288
+ eventStore.append(
289
+ sessionId,
290
+ createMessageStartEvent(kickoffMsgId, "user", kickoffContent, {
291
+ ...currentWindowMessageOptions ?? {},
292
+ isSystemGenerated: true,
293
+ messageKind: "auto-prompt",
294
+ metadata: { type: "workflow", name: "Workflow", color: "#f59e0b" }
295
+ })
296
+ );
297
+ eventStore.append(sessionId, { type: "message.done", data: { messageId: kickoffMsgId } });
298
+ }
310
299
  }
311
300
  function buildSnapshot(sessionManager, sessionId, _lastStats) {
312
301
  const eventStore = getEventStore();
@@ -323,10 +312,9 @@ function buildSnapshot(sessionManager, sessionId, _lastStats) {
323
312
  }
324
313
 
325
314
  export {
326
- createVerifierNudgeConfig,
315
+ computeDynamicContextHash,
327
316
  runChatTurn,
328
- filterToolRegistryForStepDone,
329
- runBuilderTurn,
330
- runVerifierTurn
317
+ runAgentTurn,
318
+ injectWorkflowKickoffIfNeeded
331
319
  };
332
- //# sourceMappingURL=chunk-UFY4I643.js.map
320
+ //# sourceMappingURL=chunk-C75I2KZM.js.map
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  getEventStore,
3
3
  updateSessionMetadata
4
- } from "./chunk-XKR3HCAL.js";
4
+ } from "./chunk-NPHYEUYE.js";
5
5
  import {
6
6
  buildMessagesFromStoredEvents,
7
7
  foldPendingConfirmations
8
- } from "./chunk-NONI4CRP.js";
8
+ } from "./chunk-XJEOP6XU.js";
9
9
  import {
10
10
  createContextStateMessage,
11
11
  createSessionStateMessage
12
- } from "./chunk-CEZNMLOO.js";
12
+ } from "./chunk-7TTEGAO6.js";
13
13
  import {
14
14
  logger
15
15
  } from "./chunk-K44MW7JJ.js";
@@ -143,4 +143,4 @@ export {
143
143
  needsNameGenerationCheck,
144
144
  applyGeneratedSessionName
145
145
  };
146
- //# sourceMappingURL=chunk-QFSSKIQ3.js.map
146
+ //# sourceMappingURL=chunk-CDDMHSZF.js.map