@runtypelabs/sdk 1.9.0 → 1.9.2

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.
package/dist/index.cjs CHANGED
@@ -2856,6 +2856,57 @@ var executionPhase = {
2856
2856
  };
2857
2857
  function classifyVariant(message) {
2858
2858
  const lower = message.toLowerCase();
2859
+ const modificationVerbs = [
2860
+ "fix",
2861
+ "update",
2862
+ "change",
2863
+ "modify",
2864
+ "edit",
2865
+ "refactor",
2866
+ "improve",
2867
+ "add to",
2868
+ "remove",
2869
+ "delete",
2870
+ "rename",
2871
+ "migrate"
2872
+ ];
2873
+ const hasModificationVerb = modificationVerbs.some(
2874
+ (v) => lower.startsWith(v) || new RegExp(`\\b${v}\\b`).test(lower)
2875
+ );
2876
+ const creationPatterns = [
2877
+ /^create\b/,
2878
+ /^build\b/,
2879
+ /^make\b/,
2880
+ /^generate\b/,
2881
+ /^scaffold\b/,
2882
+ /^set up\b/,
2883
+ /^setup\b/,
2884
+ /^bootstrap\b/,
2885
+ /^initialize\b/,
2886
+ /^init\b/,
2887
+ /^write a\b/,
2888
+ /^write an\b/,
2889
+ /^implement a\b/,
2890
+ /^implement an\b/,
2891
+ /^start a\b/,
2892
+ /^start an\b/,
2893
+ /^new\b/
2894
+ ];
2895
+ const hasCreationStart = creationPatterns.some((p) => p.test(lower));
2896
+ const creationVerbs = [
2897
+ "build",
2898
+ "create",
2899
+ "make",
2900
+ "generate",
2901
+ "scaffold",
2902
+ "implement"
2903
+ ];
2904
+ const hasCreationVerb = creationVerbs.some(
2905
+ (v) => new RegExp(`\\b${v}\\b`).test(lower)
2906
+ );
2907
+ if ((hasCreationStart || hasCreationVerb) && !hasModificationVerb) {
2908
+ return "create";
2909
+ }
2859
2910
  const externalVerbs = [
2860
2911
  "fetch",
2861
2912
  "browse",
@@ -2895,49 +2946,9 @@ function classifyVariant(message) {
2895
2946
  ];
2896
2947
  const hasExternalVerb = externalVerbs.some((v) => lower.includes(v));
2897
2948
  const hasExternalTarget = externalTargets.some((t) => lower.includes(t));
2898
- const modificationVerbs = [
2899
- "fix",
2900
- "update",
2901
- "change",
2902
- "modify",
2903
- "edit",
2904
- "refactor",
2905
- "improve",
2906
- "add to",
2907
- "remove",
2908
- "delete",
2909
- "rename",
2910
- "migrate"
2911
- ];
2912
- const hasModificationVerb = modificationVerbs.some(
2913
- (v) => lower.startsWith(v) || new RegExp(`\\b${v}\\b`).test(lower)
2914
- );
2915
2949
  if (hasExternalVerb && hasExternalTarget && !hasModificationVerb) {
2916
2950
  return "external";
2917
2951
  }
2918
- const creationPatterns = [
2919
- /^create\b/,
2920
- /^build\b/,
2921
- /^make\b/,
2922
- /^generate\b/,
2923
- /^scaffold\b/,
2924
- /^set up\b/,
2925
- /^setup\b/,
2926
- /^bootstrap\b/,
2927
- /^initialize\b/,
2928
- /^init\b/,
2929
- /^write a\b/,
2930
- /^write an\b/,
2931
- /^implement a\b/,
2932
- /^implement an\b/,
2933
- /^start a\b/,
2934
- /^start an\b/,
2935
- /^new\b/
2936
- ];
2937
- const hasCreationStart = creationPatterns.some((p) => p.test(lower));
2938
- if (hasCreationStart && !hasModificationVerb) {
2939
- return "create";
2940
- }
2941
2952
  return "modify";
2942
2953
  }
2943
2954
  async function generateBootstrapContext(message, localTools, variant) {
@@ -3084,7 +3095,9 @@ var deployPhase = {
3084
3095
  " 4. If the deploy fails, read the error output, fix the code, and call deploy_sandbox again.",
3085
3096
  " 5. The sandbox is persistent \u2014 subsequent calls reuse the same sandbox.",
3086
3097
  " 6. When the deploy succeeds and the preview URL is live, tell the user and end with TASK_COMPLETE.",
3087
- " 7. For apps with HTML frontends, use the `files` parameter to write HTML/CSS/JS to separate files and serve them with express.static, rather than embedding HTML in template literals."
3098
+ " 7. For apps with HTML frontends, use the `files` parameter to write HTML/CSS/JS to separate files and serve them with express.static, rather than embedding HTML in template literals.",
3099
+ " 8. If the prompt asks for a multi-route app or names concrete output paths (for example `public/v1/index.html`), mirror that structure in the `files` payload.",
3100
+ " 9. If the prompt asks you to verify specific routes after deploy, check those paths against the preview URL before TASK_COMPLETE and iterate until they work."
3088
3101
  ].join("\n");
3089
3102
  },
3090
3103
  buildToolGuidance(_state) {
@@ -3092,6 +3105,7 @@ var deployPhase = {
3092
3105
  "Your primary tool is deploy_sandbox. Call it with code, packageJson, language, and port.",
3093
3106
  "Do NOT use write_file, read_file, search_repo, glob_files, tree_directory, or list_directory \u2014 you are deploying to a sandbox, not editing local files.",
3094
3107
  "You may use run_sandbox_code for quick one-off script execution if needed.",
3108
+ "For static or multi-page sites, use `files` to create the requested folder structure and have the server expose those routes.",
3095
3109
  "When deploy_sandbox returns successfully with a previewUrl, tell the user the URL and end with TASK_COMPLETE."
3096
3110
  ];
3097
3111
  },
@@ -3141,34 +3155,7 @@ var deployPhase = {
3141
3155
  return void 0;
3142
3156
  }
3143
3157
  };
3144
- function classifyVariant2(message) {
3145
- const lower = message.toLowerCase();
3146
- const deployPatterns = [
3147
- /\bdeploy\b/,
3148
- /\bsandbox\b/,
3149
- /\bpreview\s*url\b/,
3150
- /\blive\s*preview\b/,
3151
- /\bhost\b.*\b(?:app|server|api|site)\b/,
3152
- /\b(?:app|server|api|site)\b.*\bhost\b/,
3153
- /\brun\b.*\b(?:server|web\s*app)\b/,
3154
- /\blaunch\b.*\b(?:app|server|api|site)\b/,
3155
- /\bstart\b.*\b(?:server|web\s*app)\b/
3156
- ];
3157
- if (deployPatterns.some((p) => p.test(lower))) {
3158
- return "deploy";
3159
- }
3160
- const webAppPatterns = [
3161
- /\bbuild\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/,
3162
- /\bcreate\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/,
3163
- /\bmake\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/
3164
- ];
3165
- const repoPatterns = [
3166
- /\b(?:file|repo|repository|codebase|project|directory|folder)\b/,
3167
- /\b(?:edit|modify|update|fix|refactor|change)\b/
3168
- ];
3169
- if (webAppPatterns.some((p) => p.test(lower)) && !repoPatterns.some((p) => p.test(lower))) {
3170
- return "deploy";
3171
- }
3158
+ function classifyVariant2(_message) {
3172
3159
  return "deploy";
3173
3160
  }
3174
3161
  var deployWorkflow = {
@@ -4280,6 +4267,12 @@ function dispatchAgentEvent(event, callbacks) {
4280
4267
  case "agent_tool_delta":
4281
4268
  callbacks.onToolDelta?.(typedData);
4282
4269
  break;
4270
+ case "agent_tool_input_delta":
4271
+ callbacks.onToolInputDelta?.(typedData);
4272
+ break;
4273
+ case "agent_tool_input_complete":
4274
+ callbacks.onToolInputComplete?.(typedData);
4275
+ break;
4283
4276
  case "agent_tool_complete":
4284
4277
  callbacks.onToolComplete?.(typedData);
4285
4278
  break;
@@ -4663,6 +4656,15 @@ var _AgentsEndpoint = class _AgentsEndpoint {
4663
4656
  String(current).slice(0, 200)
4664
4657
  );
4665
4658
  }
4659
+ const localExecutionStartedAt = (/* @__PURE__ */ new Date()).toISOString();
4660
+ const localExecutionStartedAtMs = Date.now();
4661
+ callbacks?.onLocalToolExecutionStart?.({
4662
+ executionId,
4663
+ toolCallId: toolId,
4664
+ toolName,
4665
+ parameters: parsedParams,
4666
+ startedAt: localExecutionStartedAt
4667
+ });
4666
4668
  let toolResult;
4667
4669
  try {
4668
4670
  toolResult = await toolDef.execute(parsedParams);
@@ -4672,20 +4674,24 @@ var _AgentsEndpoint = class _AgentsEndpoint {
4672
4674
  toolMessages.push({
4673
4675
  role: "assistant",
4674
4676
  content: "",
4675
- toolCalls: [{
4676
- toolCallId: toolId,
4677
- toolName,
4678
- args: parsedParams
4679
- }]
4677
+ toolCalls: [
4678
+ {
4679
+ toolCallId: toolId,
4680
+ toolName,
4681
+ args: parsedParams
4682
+ }
4683
+ ]
4680
4684
  });
4681
4685
  toolMessages.push({
4682
4686
  role: "tool",
4683
4687
  content: "",
4684
- toolResults: [{
4685
- toolCallId: toolId,
4686
- toolName,
4687
- result: toolResult
4688
- }]
4688
+ toolResults: [
4689
+ {
4690
+ toolCallId: toolId,
4691
+ toolName,
4692
+ result: toolResult
4693
+ }
4694
+ ]
4689
4695
  });
4690
4696
  pauseCount += 1;
4691
4697
  const toolNameCount = (toolNameCounts[toolName] || 0) + 1;
@@ -4717,6 +4723,16 @@ var _AgentsEndpoint = class _AgentsEndpoint {
4717
4723
  recentActionKeys
4718
4724
  });
4719
4725
  if (forcedCompleteEvent) {
4726
+ callbacks?.onLocalToolExecutionComplete?.({
4727
+ executionId,
4728
+ toolCallId: toolId,
4729
+ toolName,
4730
+ parameters: parsedParams,
4731
+ result: toolResult,
4732
+ success: true,
4733
+ completedAt: (/* @__PURE__ */ new Date()).toISOString(),
4734
+ durationMs: Date.now() - localExecutionStartedAtMs
4735
+ });
4720
4736
  if (!forcedCompleteEvent.finalOutput && accumulatedOutput) {
4721
4737
  forcedCompleteEvent.finalOutput = accumulatedOutput;
4722
4738
  }
@@ -4736,6 +4752,16 @@ var _AgentsEndpoint = class _AgentsEndpoint {
4736
4752
  const error = await resumeResponse.json().catch(() => ({ error: "Unknown error" }));
4737
4753
  throw new Error(error.error || `HTTP ${resumeResponse.status}`);
4738
4754
  }
4755
+ callbacks?.onLocalToolExecutionComplete?.({
4756
+ executionId,
4757
+ toolCallId: toolId,
4758
+ toolName,
4759
+ parameters: parsedParams,
4760
+ result: toolResult,
4761
+ success: true,
4762
+ completedAt: (/* @__PURE__ */ new Date()).toISOString(),
4763
+ durationMs: Date.now() - localExecutionStartedAtMs
4764
+ });
4739
4765
  currentBody = resumeResponse.body;
4740
4766
  continue;
4741
4767
  }
@@ -4958,7 +4984,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
4958
4984
  }
4959
4985
  const currentPhase = workflow.phases.find((p) => p.name === state.workflowPhase);
4960
4986
  if (currentPhase?.canAcceptCompletion) {
4961
- return currentPhase.canAcceptCompletion(state, sessionTrace);
4987
+ return currentPhase.canAcceptCompletion(
4988
+ state,
4989
+ sessionTrace
4990
+ );
4962
4991
  }
4963
4992
  return true;
4964
4993
  }
@@ -5030,7 +5059,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5030
5059
  compactOneResult(tr, taskName, mode) {
5031
5060
  if (typeof tr.result === "string" && tr.result.startsWith("[")) return tr;
5032
5061
  if (mode === "hot-tail") {
5033
- return { ...tr, result: this.offloadToolResult(taskName, tr.toolCallId, tr.toolName, tr.result) };
5062
+ return {
5063
+ ...tr,
5064
+ result: this.offloadToolResult(taskName, tr.toolCallId, tr.toolName, tr.result)
5065
+ };
5034
5066
  }
5035
5067
  return { ...tr, result: `[Output from ${tr.toolName} masked \u2014 re-run the tool if needed]` };
5036
5068
  }
@@ -5129,7 +5161,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5129
5161
  }
5130
5162
  };
5131
5163
  const baseDir = sourcePath ? this.dirnameOfCandidatePath(sourcePath) : "";
5132
- for (const match of text.matchAll(/(?:href|src)=["']([^"']+\.(?:html|tsx|ts|jsx|js|md|json))["']/gi)) {
5164
+ for (const match of text.matchAll(
5165
+ /(?:href|src)=["']([^"']+\.(?:html|tsx|ts|jsx|js|md|json))["']/gi
5166
+ )) {
5133
5167
  const target = match[1] || "";
5134
5168
  const resolved = baseDir ? this.joinCandidatePath(baseDir, target) : target;
5135
5169
  add(resolved, `linked from ${sourcePath || "discovery result"} via ${target}`);
@@ -5169,7 +5203,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5169
5203
  if (!bootstrapContext) return void 0;
5170
5204
  const candidates = this.parseSearchRepoResultForCandidates(bootstrapContext);
5171
5205
  if (candidates.length === 0) return void 0;
5172
- return candidates.sort((a, b) => this.scoreCandidatePath(b.path) - this.scoreCandidatePath(a.path))[0];
5206
+ return candidates.sort(
5207
+ (a, b) => this.scoreCandidatePath(b.path) - this.scoreCandidatePath(a.path)
5208
+ )[0];
5173
5209
  }
5174
5210
  sanitizeResumeState(resumeState, taskName) {
5175
5211
  if (!resumeState) return void 0;
@@ -5276,10 +5312,17 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5276
5312
  isArtifactPath: this.isMarathonArtifactPath.bind(this),
5277
5313
  isDiscoveryTool: this.isDiscoveryToolName.bind(this)
5278
5314
  };
5279
- const blockedMessage = currentPhase.interceptToolCall(toolName, args, ctx);
5315
+ const blockedMessage = currentPhase.interceptToolCall(
5316
+ toolName,
5317
+ args,
5318
+ ctx
5319
+ );
5280
5320
  if (blockedMessage) {
5281
5321
  if (isWriteLikeTool) trace.attemptedWrite = true;
5282
- this.pushToolTraceEntry(trace, `${toolName}${pathArg}${queryArg}${patternArg} -> ${blockedMessage}`);
5322
+ this.pushToolTraceEntry(
5323
+ trace,
5324
+ `${toolName}${pathArg}${queryArg}${patternArg} -> ${blockedMessage}`
5325
+ );
5283
5326
  return blockedMessage;
5284
5327
  }
5285
5328
  }
@@ -5336,7 +5379,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5336
5379
  verificationResult.error || verificationResult.output
5337
5380
  ].filter(Boolean).join(" | ").slice(0, 240) : this.summarizeTextBlockForTrace(result);
5338
5381
  const resultSuffix = summarizedResult ? ` -> ${summarizedResult}` : "";
5339
- this.pushToolTraceEntry(trace, `${toolName}${pathArg}${queryArg}${patternArg}${resultSuffix}`);
5382
+ this.pushToolTraceEntry(
5383
+ trace,
5384
+ `${toolName}${pathArg}${queryArg}${patternArg}${resultSuffix}`
5385
+ );
5340
5386
  const textResult = typeof result === "string" ? result : "";
5341
5387
  if (toolName === "read_file" && normalizedPathArg && normalizedBestCandidatePath && normalizedPathArg === normalizedBestCandidatePath && (trace.bestCandidateWritten || state.bestCandidateNeedsVerification)) {
5342
5388
  trace.bestCandidateVerified = true;
@@ -5427,7 +5473,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5427
5473
  return [
5428
5474
  "Session working memory:",
5429
5475
  ...flags.length > 0 ? [`- ${flags.join("; ")}`] : [],
5430
- ...trace.bestCandidatePath ? [`- best candidate: ${trace.bestCandidatePath}${trace.bestCandidateReason ? ` (${trace.bestCandidateReason})` : ""}`] : [],
5476
+ ...trace.bestCandidatePath ? [
5477
+ `- best candidate: ${trace.bestCandidatePath}${trace.bestCandidateReason ? ` (${trace.bestCandidateReason})` : ""}`
5478
+ ] : [],
5431
5479
  ...lines
5432
5480
  ].join("\n").slice(0, 1200);
5433
5481
  }
@@ -5501,12 +5549,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5501
5549
  }
5502
5550
  };
5503
5551
  const lowerMessage = message.toLowerCase();
5504
- const phraseHints = [
5505
- "agent editor",
5506
- "theme.html",
5507
- "/theme.html",
5508
- "style it visually"
5509
- ];
5552
+ const phraseHints = ["agent editor", "theme.html", "/theme.html", "style it visually"];
5510
5553
  for (const hint of phraseHints) {
5511
5554
  if (lowerMessage.includes(hint.toLowerCase())) push(hint);
5512
5555
  }
@@ -5533,7 +5576,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5533
5576
  for (const match of message.matchAll(/\b([a-z0-9]+(?:\s+[a-z0-9]+){1,2})\b/gi)) {
5534
5577
  const phrase = (match[1] || "").toLowerCase();
5535
5578
  const words = phrase.split(" ");
5536
- if (words.some((word) => ["editor", "page", "screen", "view", "route", "component"].includes(word))) {
5579
+ if (words.some(
5580
+ (word) => ["editor", "page", "screen", "view", "route", "component"].includes(word)
5581
+ )) {
5537
5582
  push(match[1] || "");
5538
5583
  }
5539
5584
  }
@@ -5563,7 +5608,11 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5563
5608
  }
5564
5609
  if (globTool && /\./.test(query)) {
5565
5610
  try {
5566
- const result = await globTool.execute({ pattern: `**/${query}`, path: ".", maxResults: 5 });
5611
+ const result = await globTool.execute({
5612
+ pattern: `**/${query}`,
5613
+ path: ".",
5614
+ maxResults: 5
5615
+ });
5567
5616
  const summary = this.summarizeTextBlockForTrace(result, 3);
5568
5617
  if (summary && !summary.startsWith("No files matched")) {
5569
5618
  lines.push(`glob_files "**/${query}": ${summary}`);
@@ -5664,7 +5713,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5664
5713
  state.isCreationTask || state.workflowVariant === "external"
5665
5714
  );
5666
5715
  }
5667
- const bootstrapCandidate = this.extractBestCandidateFromBootstrapContext(state.bootstrapContext);
5716
+ const bootstrapCandidate = this.extractBestCandidateFromBootstrapContext(
5717
+ state.bootstrapContext
5718
+ );
5668
5719
  if (bootstrapCandidate) {
5669
5720
  state.bestCandidatePath = bootstrapCandidate.path;
5670
5721
  state.bestCandidateReason = bootstrapCandidate.reason;
@@ -5673,7 +5724,12 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5673
5724
  }
5674
5725
  for (let session = 0; session < maxSessions; session++) {
5675
5726
  const sessionTrace = this.createEmptyToolTrace();
5676
- const sessionLocalTools = this.wrapLocalToolsForTrace(options.localTools, sessionTrace, state, workflow);
5727
+ const sessionLocalTools = this.wrapLocalToolsForTrace(
5728
+ options.localTools,
5729
+ sessionTrace,
5730
+ state,
5731
+ workflow
5732
+ );
5677
5733
  const sessionCallbacks = this.createTraceCallbacks(options.streamCallbacks, sessionTrace);
5678
5734
  const continuationContext = session === 0 && options.previousMessages ? {
5679
5735
  previousMessages: options.previousMessages,
@@ -5704,16 +5760,13 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5704
5760
  onContextNotice: options.onContextNotice
5705
5761
  }
5706
5762
  );
5707
- const {
5708
- messages,
5709
- requestContextManagement,
5710
- pendingNativeCompactionEvent
5711
- } = preparedSession;
5763
+ const { messages, requestContextManagement, pendingNativeCompactionEvent } = preparedSession;
5712
5764
  let sessionResult;
5713
5765
  const sessionData = {
5714
5766
  messages,
5715
5767
  debugMode: options.debugMode,
5716
5768
  model: options.model,
5769
+ ...options.reasoning !== void 0 ? { reasoning: options.reasoning } : {},
5717
5770
  ...options.toolIds?.length ? { tools: { toolIds: options.toolIds } } : {},
5718
5771
  ...requestContextManagement ? { contextManagement: requestContextManagement } : {}
5719
5772
  };
@@ -5831,7 +5884,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5831
5884
  ).slice(-20);
5832
5885
  }
5833
5886
  if (sessionTrace.actionKeys.length > 0) {
5834
- state.recentActionKeys = [...state.recentActionKeys || [], ...sessionTrace.actionKeys].slice(-20);
5887
+ state.recentActionKeys = [
5888
+ ...state.recentActionKeys || [],
5889
+ ...sessionTrace.actionKeys
5890
+ ].slice(-20);
5835
5891
  }
5836
5892
  if (sessionTrace.planWritten) {
5837
5893
  state.planWritten = true;
@@ -5860,7 +5916,11 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5860
5916
  const latestSession = state.sessions[state.sessions.length - 1];
5861
5917
  if (latestSession) {
5862
5918
  latestSession.outputPreview = [phaseTransitionSummary, "", latestSession.outputPreview].join("\n").slice(0, 300);
5863
- latestSession.toolTraceSummary = [phaseTransitionSummary, "", latestSession.toolTraceSummary || ""].join("\n").trim().slice(0, 1200);
5919
+ latestSession.toolTraceSummary = [
5920
+ phaseTransitionSummary,
5921
+ "",
5922
+ latestSession.toolTraceSummary || ""
5923
+ ].join("\n").trim().slice(0, 1200);
5864
5924
  }
5865
5925
  }
5866
5926
  if (!state.messages) state.messages = [];
@@ -6097,7 +6157,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
6097
6157
  details.builtinToolSchemas
6098
6158
  );
6099
6159
  const reservedOutputTokens = this.resolveReservedOutputTokens(details.contextLimitTokens);
6100
- const effectiveInputBudgetTokens = this.resolveEffectiveInputBudgetTokens(details.contextLimitTokens);
6160
+ const effectiveInputBudgetTokens = this.resolveEffectiveInputBudgetTokens(
6161
+ details.contextLimitTokens
6162
+ );
6101
6163
  const summaryTokens = details.summaryText ? this.estimateTextTokens(
6102
6164
  `${_AgentsEndpoint.AUTO_COMPACT_SUMMARY_PREFIX}
6103
6165
 
@@ -6218,7 +6280,9 @@ Do NOT redo any of the above work.`
6218
6280
  "",
6219
6281
  "Changed Files / Candidate Paths",
6220
6282
  ...candidatePaths.length > 0 ? candidatePaths.map((candidatePath) => `- ${candidatePath}`) : ["- No candidate paths recorded yet."],
6221
- ...state.planPath ? [`- ${state.workflowVariant === "external" ? "Report path" : "Plan path"}: ${state.planPath}`] : [],
6283
+ ...state.planPath ? [
6284
+ `- ${state.workflowVariant === "external" ? "Report path" : "Plan path"}: ${state.planPath}`
6285
+ ] : [],
6222
6286
  ...state.planWritten ? ["- Planning artifact has been written."] : [],
6223
6287
  ...state.bestCandidateReason ? [`- Best candidate rationale: ${state.bestCandidateReason}`] : [],
6224
6288
  "",
@@ -6240,10 +6304,14 @@ Do NOT redo any of the above work.`
6240
6304
  ].join("\n");
6241
6305
  }
6242
6306
  isAssistantToolCallMessage(message) {
6243
- return Boolean(message?.role === "assistant" && message.toolCalls && message.toolCalls.length > 0);
6307
+ return Boolean(
6308
+ message?.role === "assistant" && message.toolCalls && message.toolCalls.length > 0
6309
+ );
6244
6310
  }
6245
6311
  isToolResultMessage(message) {
6246
- return Boolean(message?.role === "tool" && message.toolResults && message.toolResults.length > 0);
6312
+ return Boolean(
6313
+ message?.role === "tool" && message.toolResults && message.toolResults.length > 0
6314
+ );
6247
6315
  }
6248
6316
  /**
6249
6317
  * Replay only complete adjacent tool-call/result pairs so provider validation
@@ -6391,7 +6459,9 @@ Do NOT redo any of the above work.`
6391
6459
  "Use these tools to inspect the existing repository and make real file edits \u2014 not just code in your response."
6392
6460
  ],
6393
6461
  ...toolGuidanceLines,
6394
- ...isDeployWorkflow ? [] : isExternalTask2 ? ["Use write_file only if you want to save the final deliverable into the workspace."] : ["Always use write_file to save your output so the user can run it immediately."]
6462
+ ...isDeployWorkflow ? [] : isExternalTask2 ? [
6463
+ "Use write_file only if you want to save the final deliverable into the workspace."
6464
+ ] : ["Always use write_file to save your output so the user can run it immediately."]
6395
6465
  ].join("\n") : "";
6396
6466
  const builtinToolNames = builtinToolIds?.map((id) => id.replace(/^builtin:/, ""));
6397
6467
  const builtinToolsBlock = builtinToolNames?.length ? [
@@ -6413,9 +6483,12 @@ Do NOT redo any of the above work.`
6413
6483
  const replayHistoryMessages = this.sanitizeReplayHistoryMessages(
6414
6484
  continuationContext.previousMessages
6415
6485
  );
6486
+ const continuationGuardrail = "IMPORTANT: You are continuing a previously completed task. The conversation above shows your prior work. Do NOT redo any of it. Build on what was already accomplished. If there is nothing new to do, respond with TASK_COMPLETE.";
6416
6487
  const defaultContinueMessage = "Continue the task. Review your prior work above and proceed with any remaining work. If everything is already complete, respond with TASK_COMPLETE.";
6417
6488
  const userMessage = continuationContext.newUserMessage || defaultContinueMessage;
6418
6489
  const userContent = [
6490
+ continuationGuardrail,
6491
+ "",
6419
6492
  userMessage,
6420
6493
  phaseBlock,
6421
6494
  toolsBlock,
@@ -6426,10 +6499,6 @@ Do NOT redo any of the above work.`
6426
6499
  ].join("\n");
6427
6500
  const fullHistoryMessages = [
6428
6501
  ...replayHistoryMessages,
6429
- {
6430
- role: "system",
6431
- content: "IMPORTANT: You are continuing a previously completed task. The conversation above shows your prior work. Do NOT redo any of it. Build on what was already accomplished. If there is nothing new to do, respond with TASK_COMPLETE."
6432
- },
6433
6502
  {
6434
6503
  role: "user",
6435
6504
  content: userContent
@@ -6500,7 +6569,15 @@ Do NOT redo any of the above work.`
6500
6569
  };
6501
6570
  }
6502
6571
  if (sessionIndex === 0) {
6503
- const content2 = [originalMessage, phaseBlock, toolsBlock, bootstrapBlock, candidateBlock, "", multiSessionInstruction].join("\n");
6572
+ const content2 = [
6573
+ originalMessage,
6574
+ phaseBlock,
6575
+ toolsBlock,
6576
+ bootstrapBlock,
6577
+ candidateBlock,
6578
+ "",
6579
+ multiSessionInstruction
6580
+ ].join("\n");
6504
6581
  return {
6505
6582
  messages: [{ role: "user", content: content2 }],
6506
6583
  requestContextManagement
@@ -6551,10 +6628,7 @@ Do NOT redo any of the above work.`
6551
6628
  contextLimitTokens: compactionOptions?.contextLimitTokens
6552
6629
  });
6553
6630
  await maybeEmitToolDefinitionWarning(breakdown);
6554
- const messages = [
6555
- ...historyMessages,
6556
- { role: "user", content: continuationContent }
6557
- ];
6631
+ const messages = [...historyMessages, { role: "user", content: continuationContent }];
6558
6632
  if (resolvedStrategy === "summary_fallback" && typeof compactionOptions?.autoCompactTokenThreshold === "number" && compactionOptions.autoCompactTokenThreshold > 0 && breakdown.estimatedInputTokens >= compactionOptions.autoCompactTokenThreshold) {
6559
6633
  return {
6560
6634
  messages: await this.buildCompactHistoryMessagesWithLifecycle(