




















@@ -1,3 +1,7 @@
1+/**
2+ * Analyzes injected workspace bootstrap files and builds warnings when context
3+ * was truncated before an agent sees it.
4+ */
15import path from "node:path";
26import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
37import type { EmbeddedContextFile } from "./embedded-agent-helpers.js";
@@ -103,6 +107,7 @@ function appendSeenSignature(signatures: string[], signature: string): string[]
103107return next.slice(-DEFAULT_BOOTSTRAP_PROMPT_WARNING_SIGNATURE_HISTORY_MAX);
104108}
105109110+/** Restores prompt-warning dedupe state from a previous bootstrap report. */
106111export function resolveBootstrapWarningSignaturesSeen(report?: {
107112bootstrapTruncation?: {
108113warningMode?: BootstrapPromptWarningMode;
@@ -126,6 +131,7 @@ export function resolveBootstrapWarningSignaturesSeen(report?: {
126131return single ? [single] : [];
127132}
128133134+/** Compares raw bootstrap files with the injected context files the agent received. */
129135export function buildBootstrapInjectionStats(params: {
130136bootstrapFiles: WorkspaceBootstrapFile[];
131137injectedFiles: EmbeddedContextFile[];
@@ -166,6 +172,7 @@ export function buildBootstrapInjectionStats(params: {
166172});
167173}
168174175+/** Classifies bootstrap truncation and near-limit pressure for prompt/report output. */
169176export function analyzeBootstrapBudget(params: {
170177files: BootstrapInjectionStat[];
171178bootstrapMaxChars: number;
@@ -225,6 +232,7 @@ export function analyzeBootstrapBudget(params: {
225232};
226233}
227234235+/** Builds a stable signature for once-per-truncation warning suppression. */
228236export function buildBootstrapTruncationSignature(
229237analysis: BootstrapBudgetAnalysis,
230238): string | undefined {
@@ -258,6 +266,7 @@ export function buildBootstrapTruncationSignature(
258266});
259267}
260268269+/** Formats human-readable warning lines for the most important truncated files. */
261270export function formatBootstrapTruncationWarningLines(params: {
262271analysis: BootstrapBudgetAnalysis;
263272maxFiles?: number;
@@ -306,6 +315,7 @@ export function formatBootstrapTruncationWarningLines(params: {
306315return lines;
307316}
308317318+/** Decides whether to show a prompt warning and returns the updated dedupe state. */
309319export function buildBootstrapPromptWarning(params: {
310320analysis: BootstrapBudgetAnalysis;
311321mode: BootstrapPromptWarningMode;
@@ -338,6 +348,7 @@ export function buildBootstrapPromptWarning(params: {
338348};
339349}
340350351+/** Appends a detailed truncation warning block to the agent prompt when needed. */
341352export function appendBootstrapPromptWarning(
342353prompt: string,
343354warningLines?: string[],
@@ -361,6 +372,7 @@ export function appendBootstrapPromptWarning(
361372return prompt ? `${prompt}\n\n${warningBlock}` : warningBlock;
362373}
363374375+/** Builds the compact truncation notice mirrored into run metadata. */
364376export function buildBootstrapPromptWarningNotice(warningLines?: string[]): string | undefined {
365377const hasWarning = (warningLines ?? []).some((line) => line.trim().length > 0);
366378if (!hasWarning) {
@@ -373,6 +385,7 @@ export function buildBootstrapPromptWarningNotice(warningLines?: string[]): stri
373385].join("\n");
374386}
375387388+/** Serializes truncation warning state for run reports and future dedupe. */
376389export function buildBootstrapTruncationReportMeta(params: {
377390analysis: BootstrapBudgetAnalysis;
378391warningMode: BootstrapPromptWarningMode;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。