openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
6 lines • 5.14 kB
JavaScript
import{i as listAgentIds,u as tryResolveDefaultAgentId}from"./agent-roster-4XrgUgPK.mjs";import{f as resolveAgentWorkspaceDir,k as tryResolveConfiguredAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{t as resolveDefaultAgentWorkspaceDir}from"./workspace-default-path-ULYbn-EL.mjs";import"./workspace-default-Cb7cQoAN.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{a as resolveBootstrapTotalMaxChars,i as resolveBootstrapMaxChars,t as USER_BOOTSTRAP_MAX_CHARS}from"./bootstrap-CbSK3Geh.mjs";import{a as resolveBootstrapContextWithProjectedHookFiles}from"./bootstrap-files-S_tG2cje.mjs";import{o as isFixedUserCapFile,r as buildBootstrapInjectionStats,t as analyzeBootstrapBudget}from"./bootstrap-budget-DI6CkaLC.mjs";import{t as loadDeclaredExtraBootstrapFiles}from"./declared-files-8EdXibov.mjs";import{t as loadWorkspaceHookEntries}from"./workspace-BN88LYQB.mjs";import{r as resolveInternalHookSelection,t as isHookLoadable}from"./configured-BCq_2Ag4.mjs";
//!src/agents/bootstrap-files-diagnostics.ts
async function isBundledExtraFilesHookSelected(e){if(!e)return false;const t=await resolveInternalHookSelection(e);if(!t.configured)return false;const n=tryResolveConfiguredAgentWorkspaceDir(e)??resolveDefaultAgentWorkspaceDir();const r=loadWorkspaceHookEntries(n,{config:e}).find(e=>e.hook.name===`bootstrap-extra-files`);return r?.hook.source===`openclaw-bundled`&&isHookLoadable({entry:r,config:e,names:t.names})}async function resolveBootstrapContextForDiagnostics(e){if(!await isBundledExtraFilesHookSelected(e.config))return resolveBootstrapContextWithProjectedHookFiles(e,[]);const t=await loadDeclaredExtraBootstrapFiles({config:e.config,workspaceDir:e.workspaceDir});return resolveBootstrapContextWithProjectedHookFiles(e,t.files)}
//!src/commands/doctor-bootstrap-size.ts
let integerFormatter;function formatInt(e){return(integerFormatter??=new Intl.NumberFormat(`en-US`)).format(Math.max(0,Math.floor(e)))}function formatPercent(e,t){if(!Number.isFinite(t)||t<=0)return`0%`;return`${Math.min(100,Math.max(0,Math.round(e/t*100)))}%`}function formatCauses(e){if(e.length===0)return`unknown`;return e.map(e=>e===`per-file-limit`?`max/file`:`max/total`).join(`, `)}async function collectBootstrapFileSize(e,t,n){const r=resolveBootstrapMaxChars(e,n);const i=resolveBootstrapTotalMaxChars(e,n);const{bootstrapFiles:a,contextFiles:o}=await resolveBootstrapContextForDiagnostics({workspaceDir:t,config:e,agentId:n});const s=analyzeBootstrapBudget({files:buildBootstrapInjectionStats({bootstrapFiles:a,injectedFiles:o}),bootstrapMaxChars:r,bootstrapTotalMaxChars:i});return{bootstrapTotalMaxChars:i,analysis:{...s,truncatedFiles:s.truncatedFiles.map(e=>Object.assign(e,{retention:e.injectedChars===0?`No content from this file reaches the model.`:e.name.toLowerCase()===`agents.md`?`The model receives start/end excerpts as space permits, plus a bounded policy digest when available; other middle text is omitted.`:`The model receives start/end excerpts as space permits; middle text is omitted.`}))}}}async function noteBootstrapFileSize(e){const t=tryResolveDefaultAgentId(e);const n=listAgentIds(e);let r;for(const i of n){const{analysis:a,bootstrapTotalMaxChars:o}=await collectBootstrapFileSize(e,resolveAgentWorkspaceDir(e,i),i);if(i===t)r=a;if(!a.hasTruncation&&a.nearLimitFiles.length===0&&!a.totalNearLimit)continue;const s=n.length>1?[`Agent "${i}":`]:[];if(a.hasTruncation){s.push(`Workspace bootstrap files exceed limits and will be truncated:`);for(const e of a.truncatedFiles){const t=Math.max(0,e.rawChars-e.injectedChars);s.push(`- ${e.name}: ${formatInt(e.rawChars)} raw / ${formatInt(e.injectedChars)} injected (${formatPercent(t,e.rawChars)} truncated; ${formatCauses(e.causes)})`,` ${e.retention}`)}}else s.push(`Workspace bootstrap files are near configured limits:`);for(const e of a.nearLimitFiles.filter(e=>!e.truncated))s.push(`- ${e.name}: ${formatInt(e.rawChars)} chars (${formatPercent(e.rawChars,e.effectiveFileLimit)} of max/file ${formatInt(e.effectiveFileLimit)})`);s.push(`Total bootstrap injected chars: ${formatInt(a.totals.injectedChars)} (${formatPercent(a.totals.injectedChars,o)} of max/total ${formatInt(o)}).`);s.push(`Total bootstrap raw chars (before truncation): ${formatInt(a.totals.rawChars)}.`);const c=[...a.truncatedFiles.filter(e=>e.causes.includes(`per-file-limit`)),...a.nearLimitFiles];const l=c.some(isFixedUserCapFile);const u=c.some(e=>!isFixedUserCapFile(e));const d=a.truncatedFiles.some(e=>e.causes.includes(`total-limit`))||a.totalNearLimit;const f=[l?`USER.md has a fixed ${formatInt(USER_BOOTSTRAP_MAX_CHARS)}-character bootstrap cap; keep it compact.`:``,u?"- Tip: tune `agents.entries.*.bootstrapMaxChars` for this agent, or `agents.defaults.bootstrapMaxChars` as fallback, for per-file limits.":``,d?"- Tip: tune `agents.entries.*.bootstrapTotalMaxChars` for this agent, or `agents.defaults.bootstrapTotalMaxChars` as fallback, for total-budget limits.":``].filter(Boolean);if(f.length>0)s.push(``,...f);note(s.join(`
`),`Bootstrap file size`)}return r}export{collectBootstrapFileSize,noteBootstrapFileSize};