@caupulican/pi-adaptative 0.80.57 → 0.80.59
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/CHANGELOG.md +15 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +5 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +116 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +260 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +5 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +19 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +57 -0
- package/dist/core/learning/reflection-engine.d.ts.map +1 -0
- package/dist/core/learning/reflection-engine.js +118 -0
- package/dist/core/learning/reflection-engine.js.map +1 -0
- package/dist/core/memory/memory-manager.d.ts +8 -0
- package/dist/core/memory/memory-manager.d.ts.map +1 -1
- package/dist/core/memory/memory-manager.js +14 -2
- package/dist/core/memory/memory-manager.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +11 -3
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +63 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts +13 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +18 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAqFxF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAYhF;AAiBD,qBAAa,eAAgB,YAAW,SAAS;IAChD,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,aAAa,CAAC,CAAsB;IAE5C,YAAY,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAGxE;IAED,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGtC;IAED,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED;;OAEG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,gBAAgB;IA+CxB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAoI9B;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\nfunction stripAnsi(text: string): string {\n\treturn text.replace(/\\u001b\\[[0-?]*[ -/]*[@-~]/g, \"\");\n}\n\nfunction normalizeLearningPhase(phase: string): string {\n\tconst normalized = phase\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"\")\n\t\t.trim();\n\tif (!normalized) return \"active\";\n\tif (normalized === \"starting\") return \"start\";\n\tif (normalized === \"mapping\") return \"map\";\n\tif (normalized === \"scanning\") return \"scan\";\n\tif (normalized === \"auditing\") return \"audit\";\n\tif (normalized === \"learning\") return \"run\";\n\tif (normalized === \"pruning\") return \"prune\";\n\treturn normalized.slice(0, 16);\n}\n\nfunction formatExtensionStatuses(statuses: ReadonlyMap<string, string>): string[] {\n\tconst regularStatuses: string[] = [];\n\tconst learningPhases = new Set<string>();\n\tlet sawLearningStatus = false;\n\n\tfor (const [key, rawText] of Array.from(statuses.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n\t\tconst text = sanitizeStatusText(rawText);\n\t\tconst plain = stripAnsi(text).trim();\n\t\tconst plainLower = plain.toLowerCase();\n\t\tlet phase: string | undefined;\n\n\t\tif (plainLower.startsWith(\"(learning)\")) {\n\t\t\tphase = plain.slice(\"(learning)\".length).trim();\n\t\t} else if (plainLower === \"learning\") {\n\t\t\tphase = \"active\";\n\t\t} else if (/^learn(?:ing)?\\s*[: ]/.test(plainLower)) {\n\t\t\tphase = plain.replace(/^learn(?:ing)?\\s*[: ]/i, \"\").trim();\n\t\t}\n\n\t\tif (phase !== undefined) {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(normalizeLearningPhase(phase));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (key === \"auto-learn\" || key === \"continuous-learning\") {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(\"active\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tregularStatuses.push(text);\n\t}\n\n\tif (!sawLearningStatus) return regularStatuses;\n\tconst phases = Array.from(learningPhases).filter((phase) => phase !== \"active\");\n\tconst phaseText = phases.length > 0 ? phases.join(\"/\") : \"active\";\n\treturn [theme.fg(\"warning\", \"learn\") + theme.fg(\"dim\", `:${phaseText}`), ...regularStatuses];\n}\n\n/**\n * Format token counts for compact footer display.\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\ntype FooterUsageSnapshot = {\n\tentryCount: number;\n\tmessageCount: number;\n\ttotalInput: number;\n\ttotalOutput: number;\n\ttotalCacheRead: number;\n\ttotalCacheWrite: number;\n\ttotalCost: number;\n\tcontextUsage: ReturnType<AgentSession[\"getContextUsage\"]>;\n};\n\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\tprivate usageSnapshot?: FooterUsageSnapshot;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * Invalidate cached footer stats when session state changes.\n\t */\n\tinvalidate(): void {\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageSnapshot(messageCount: number): FooterUsageSnapshot {\n\t\tconst sessionManager = this.session.sessionManager as AgentSession[\"sessionManager\"] & {\n\t\t\tgetEntryCount?: () => number;\n\t\t};\n\t\tconst entryCount = sessionManager.getEntryCount?.() ?? sessionManager.getEntries().length;\n\t\tconst cached = this.usageSnapshot;\n\t\tif (cached && cached.entryCount === entryCount && cached.messageCount === messageCount) {\n\t\t\treturn cached;\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries in one batched pass.\n\t\t// This avoids per-frame defensive array allocation when only the TUI redraws.\n\t\tlet totalInput = 0;\n\t\tlet totalOutput = 0;\n\t\tlet totalCacheRead = 0;\n\t\tlet totalCacheWrite = 0;\n\t\tlet totalCost = 0;\n\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\tconst entry = entries[i];\n\t\t\tif (entry.type !== \"message\" || entry.message.role !== \"assistant\") continue;\n\t\t\tconst usage = entry.message.usage;\n\t\t\tif (!usage) continue;\n\t\t\ttotalInput += usage.input;\n\t\t\ttotalOutput += usage.output;\n\t\t\ttotalCacheRead += usage.cacheRead;\n\t\t\ttotalCacheWrite += usage.cacheWrite;\n\t\t\ttotalCost += usage.cost.total;\n\t\t}\n\n\t\tconst snapshot: FooterUsageSnapshot = {\n\t\t\tentryCount,\n\t\t\tmessageCount,\n\t\t\ttotalInput,\n\t\t\ttotalOutput,\n\t\t\ttotalCacheRead,\n\t\t\ttotalCacheWrite,\n\t\t\ttotalCost,\n\t\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\t\tcontextUsage: this.session.getContextUsage(),\n\t\t};\n\t\tthis.usageSnapshot = snapshot;\n\t\treturn snapshot;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst usageSnapshot = this.getUsageSnapshot(state.messages?.length ?? 0);\n\t\tconst { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, contextUsage } = usageSnapshot;\n\t\tconst contextWindow = contextUsage?.contextWindow ?? state.model?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line\n\t\tconst statsParts = [];\n\t\tif (totalInput) statsParts.push(`↑${formatTokens(totalInput)}`);\n\t\tif (totalOutput) statsParts.push(`↓${formatTokens(totalOutput)}`);\n\t\tif (totalCacheRead) statsParts.push(`R${formatTokens(totalCacheRead)}`);\n\t\tif (totalCacheWrite) statsParts.push(`W${formatTokens(totalCacheWrite)}`);\n\n\t\t// Show cost with \"(sub)\" indicator if using OAuth subscription\n\t\tconst usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;\n\t\tif (totalCost || usingSubscription) {\n\t\t\tconst costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tstatsParts.push(costStr);\n\t\t}\n\n\t\t// Colorize context percentage based on usage\n\t\tlet contextPercentStr: string;\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst contextPercentDisplay =\n\t\t\tcontextPercent === \"?\"\n\t\t\t\t? `?/${formatTokens(contextWindow)}${autoIndicator}`\n\t\t\t\t: `${contextPercent}%/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tif (contextPercentValue > 90) {\n\t\t\tcontextPercentStr = theme.fg(\"error\", contextPercentDisplay);\n\t\t} else if (contextPercentValue > 70) {\n\t\t\tcontextPercentStr = theme.fg(\"warning\", contextPercentDisplay);\n\t\t} else {\n\t\t\tcontextPercentStr = contextPercentDisplay;\n\t\t}\n\t\tstatsParts.push(contextPercentStr);\n\n\t\tlet statsLeft = statsParts.join(\" \");\n\n\t\t// Add model display name on the right side, plus thinking level if model supports it\n\t\tconst modelName = state.model?.name || state.model?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\trightSide = `(${state.model!.provider}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide, fall back\n\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t}\n\t\t}\n\n\t\tconst rightSideWidth = visibleWidth(rightSide);\n\t\tconst totalNeeded = statsLeftWidth + minPadding + rightSideWidth;\n\n\t\tlet statsLine: string;\n\t\tif (totalNeeded <= width) {\n\t\t\t// Both fit - add padding to right-align model\n\t\t\tconst padding = \" \".repeat(width - statsLeftWidth - rightSideWidth);\n\t\t\tstatsLine = statsLeft + padding + rightSide;\n\t\t} else {\n\t\t\t// Need to truncate right side\n\t\t\tconst availableForRight = width - statsLeftWidth - minPadding;\n\t\t\tif (availableForRight > 0) {\n\t\t\t\tconst truncatedRight = truncateToWidth(rightSide, availableForRight, \"\");\n\t\t\t\tconst truncatedRightWidth = visibleWidth(truncatedRight);\n\t\t\t\tconst padding = \" \".repeat(Math.max(0, width - statsLeftWidth - truncatedRightWidth));\n\t\t\t\tstatsLine = statsLeft + padding + truncatedRight;\n\t\t\t} else {\n\t\t\t\t// Not enough space for right side at all\n\t\t\t\tstatsLine = statsLeft;\n\t\t\t}\n\t\t}\n\n\t\t// Apply dim to each part separately. statsLeft may contain color codes (for context %)\n\t\t// that end with a reset, which would clear an outer dim wrapper. So we dim the parts\n\t\t// before and after the colored section independently.\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\t\tconst remainder = statsLine.slice(statsLeft.length); // padding + rightSide\n\t\tconst dimRemainder = theme.fg(\"dim\", remainder);\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine, dimStatsLeft + dimRemainder];\n\n\t\t// Add extension statuses on a single line. Learning-related statuses are\n\t\t// folded into one compact chip so independent learning systems do not render\n\t\t// brittle duplicates like \"(learning) (learning) auto\".\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst statusLine = formatExtensionStatuses(extensionStatuses).join(\" \");\n\t\t\tif (statusLine) {\n\t\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t\t}\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAqFxF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAYhF;AAmBD,qBAAa,eAAgB,YAAW,SAAS;IAChD,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,aAAa,CAAC,CAAsB;IAE5C,YAAY,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAGxE;IAED,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGtC;IAED,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED;;OAEG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,gBAAgB;IAoDxB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAyI9B;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\nfunction stripAnsi(text: string): string {\n\treturn text.replace(/\\u001b\\[[0-?]*[ -/]*[@-~]/g, \"\");\n}\n\nfunction normalizeLearningPhase(phase: string): string {\n\tconst normalized = phase\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"\")\n\t\t.trim();\n\tif (!normalized) return \"active\";\n\tif (normalized === \"starting\") return \"start\";\n\tif (normalized === \"mapping\") return \"map\";\n\tif (normalized === \"scanning\") return \"scan\";\n\tif (normalized === \"auditing\") return \"audit\";\n\tif (normalized === \"learning\") return \"run\";\n\tif (normalized === \"pruning\") return \"prune\";\n\treturn normalized.slice(0, 16);\n}\n\nfunction formatExtensionStatuses(statuses: ReadonlyMap<string, string>): string[] {\n\tconst regularStatuses: string[] = [];\n\tconst learningPhases = new Set<string>();\n\tlet sawLearningStatus = false;\n\n\tfor (const [key, rawText] of Array.from(statuses.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n\t\tconst text = sanitizeStatusText(rawText);\n\t\tconst plain = stripAnsi(text).trim();\n\t\tconst plainLower = plain.toLowerCase();\n\t\tlet phase: string | undefined;\n\n\t\tif (plainLower.startsWith(\"(learning)\")) {\n\t\t\tphase = plain.slice(\"(learning)\".length).trim();\n\t\t} else if (plainLower === \"learning\") {\n\t\t\tphase = \"active\";\n\t\t} else if (/^learn(?:ing)?\\s*[: ]/.test(plainLower)) {\n\t\t\tphase = plain.replace(/^learn(?:ing)?\\s*[: ]/i, \"\").trim();\n\t\t}\n\n\t\tif (phase !== undefined) {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(normalizeLearningPhase(phase));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (key === \"auto-learn\" || key === \"continuous-learning\") {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(\"active\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tregularStatuses.push(text);\n\t}\n\n\tif (!sawLearningStatus) return regularStatuses;\n\tconst phases = Array.from(learningPhases).filter((phase) => phase !== \"active\");\n\tconst phaseText = phases.length > 0 ? phases.join(\"/\") : \"active\";\n\treturn [theme.fg(\"warning\", \"learn\") + theme.fg(\"dim\", `:${phaseText}`), ...regularStatuses];\n}\n\n/**\n * Format token counts for compact footer display.\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\ntype FooterUsageSnapshot = {\n\tentryCount: number;\n\tmessageCount: number;\n\ttotalInput: number;\n\ttotalOutput: number;\n\ttotalCacheRead: number;\n\ttotalCacheWrite: number;\n\ttotalCost: number;\n\t/** Rolled-up cost of spawned/subagent sessions (Cost Aggregation). 0 when none. */\n\ttotalSpawnedCost: number;\n\tcontextUsage: ReturnType<AgentSession[\"getContextUsage\"]>;\n};\n\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\tprivate usageSnapshot?: FooterUsageSnapshot;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * Invalidate cached footer stats when session state changes.\n\t */\n\tinvalidate(): void {\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageSnapshot(messageCount: number): FooterUsageSnapshot {\n\t\tconst sessionManager = this.session.sessionManager as AgentSession[\"sessionManager\"] & {\n\t\t\tgetEntryCount?: () => number;\n\t\t};\n\t\tconst entryCount = sessionManager.getEntryCount?.() ?? sessionManager.getEntries().length;\n\t\tconst cached = this.usageSnapshot;\n\t\tif (cached && cached.entryCount === entryCount && cached.messageCount === messageCount) {\n\t\t\treturn cached;\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries in one batched pass.\n\t\t// This avoids per-frame defensive array allocation when only the TUI redraws.\n\t\tlet totalInput = 0;\n\t\tlet totalOutput = 0;\n\t\tlet totalCacheRead = 0;\n\t\tlet totalCacheWrite = 0;\n\t\tlet totalCost = 0;\n\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\tconst entry = entries[i];\n\t\t\tif (entry.type !== \"message\" || entry.message.role !== \"assistant\") continue;\n\t\t\tconst usage = entry.message.usage;\n\t\t\tif (!usage) continue;\n\t\t\ttotalInput += usage.input;\n\t\t\ttotalOutput += usage.output;\n\t\t\ttotalCacheRead += usage.cacheRead;\n\t\t\ttotalCacheWrite += usage.cacheWrite;\n\t\t\ttotalCost += usage.cost.total;\n\t\t}\n\n\t\t// Roll up spawned/subagent cost (Cost Aggregation, Model A). Derived from the same\n\t\t// session entries, so the {entryCount} cache key above busts when new reports land.\n\t\tconst totalSpawnedCost = this.session.getSpawnedUsage().cost;\n\n\t\tconst snapshot: FooterUsageSnapshot = {\n\t\t\tentryCount,\n\t\t\tmessageCount,\n\t\t\ttotalInput,\n\t\t\ttotalOutput,\n\t\t\ttotalCacheRead,\n\t\t\ttotalCacheWrite,\n\t\t\ttotalCost,\n\t\t\ttotalSpawnedCost,\n\t\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\t\tcontextUsage: this.session.getContextUsage(),\n\t\t};\n\t\tthis.usageSnapshot = snapshot;\n\t\treturn snapshot;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst usageSnapshot = this.getUsageSnapshot(state.messages?.length ?? 0);\n\t\tconst { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, totalSpawnedCost, contextUsage } =\n\t\t\tusageSnapshot;\n\t\tconst contextWindow = contextUsage?.contextWindow ?? state.model?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line\n\t\tconst statsParts = [];\n\t\tif (totalInput) statsParts.push(`↑${formatTokens(totalInput)}`);\n\t\tif (totalOutput) statsParts.push(`↓${formatTokens(totalOutput)}`);\n\t\tif (totalCacheRead) statsParts.push(`R${formatTokens(totalCacheRead)}`);\n\t\tif (totalCacheWrite) statsParts.push(`W${formatTokens(totalCacheWrite)}`);\n\n\t\t// Show cost with \"(sub)\" indicator if using OAuth subscription\n\t\tconst usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;\n\t\tif (totalCost || totalSpawnedCost || usingSubscription) {\n\t\t\t// Main cost, then the spawned/subagent roll-up: `$0.842 (sub) (+$0.310 sub)`.\n\t\t\tlet costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tif (totalSpawnedCost) {\n\t\t\t\tcostStr += ` (+$${totalSpawnedCost.toFixed(3)} sub)`;\n\t\t\t}\n\t\t\tstatsParts.push(costStr);\n\t\t}\n\n\t\t// Colorize context percentage based on usage\n\t\tlet contextPercentStr: string;\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst contextPercentDisplay =\n\t\t\tcontextPercent === \"?\"\n\t\t\t\t? `?/${formatTokens(contextWindow)}${autoIndicator}`\n\t\t\t\t: `${contextPercent}%/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tif (contextPercentValue > 90) {\n\t\t\tcontextPercentStr = theme.fg(\"error\", contextPercentDisplay);\n\t\t} else if (contextPercentValue > 70) {\n\t\t\tcontextPercentStr = theme.fg(\"warning\", contextPercentDisplay);\n\t\t} else {\n\t\t\tcontextPercentStr = contextPercentDisplay;\n\t\t}\n\t\tstatsParts.push(contextPercentStr);\n\n\t\tlet statsLeft = statsParts.join(\" \");\n\n\t\t// Add model display name on the right side, plus thinking level if model supports it\n\t\tconst modelName = state.model?.name || state.model?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\trightSide = `(${state.model!.provider}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide, fall back\n\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t}\n\t\t}\n\n\t\tconst rightSideWidth = visibleWidth(rightSide);\n\t\tconst totalNeeded = statsLeftWidth + minPadding + rightSideWidth;\n\n\t\tlet statsLine: string;\n\t\tif (totalNeeded <= width) {\n\t\t\t// Both fit - add padding to right-align model\n\t\t\tconst padding = \" \".repeat(width - statsLeftWidth - rightSideWidth);\n\t\t\tstatsLine = statsLeft + padding + rightSide;\n\t\t} else {\n\t\t\t// Need to truncate right side\n\t\t\tconst availableForRight = width - statsLeftWidth - minPadding;\n\t\t\tif (availableForRight > 0) {\n\t\t\t\tconst truncatedRight = truncateToWidth(rightSide, availableForRight, \"\");\n\t\t\t\tconst truncatedRightWidth = visibleWidth(truncatedRight);\n\t\t\t\tconst padding = \" \".repeat(Math.max(0, width - statsLeftWidth - truncatedRightWidth));\n\t\t\t\tstatsLine = statsLeft + padding + truncatedRight;\n\t\t\t} else {\n\t\t\t\t// Not enough space for right side at all\n\t\t\t\tstatsLine = statsLeft;\n\t\t\t}\n\t\t}\n\n\t\t// Apply dim to each part separately. statsLeft may contain color codes (for context %)\n\t\t// that end with a reset, which would clear an outer dim wrapper. So we dim the parts\n\t\t// before and after the colored section independently.\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\t\tconst remainder = statsLine.slice(statsLeft.length); // padding + rightSide\n\t\tconst dimRemainder = theme.fg(\"dim\", remainder);\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine, dimStatsLeft + dimRemainder];\n\n\t\t// Add extension statuses on a single line. Learning-related statuses are\n\t\t// folded into one compact chip so independent learning systems do not render\n\t\t// brittle duplicates like \"(learning) (learning) auto\".\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst statusLine = formatExtensionStatuses(extensionStatuses).join(\" \");\n\t\t\tif (statusLine) {\n\t\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t\t}\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -155,6 +155,9 @@ export class FooterComponent {
|
|
|
155
155
|
totalCacheWrite += usage.cacheWrite;
|
|
156
156
|
totalCost += usage.cost.total;
|
|
157
157
|
}
|
|
158
|
+
// Roll up spawned/subagent cost (Cost Aggregation, Model A). Derived from the same
|
|
159
|
+
// session entries, so the {entryCount} cache key above busts when new reports land.
|
|
160
|
+
const totalSpawnedCost = this.session.getSpawnedUsage().cost;
|
|
158
161
|
const snapshot = {
|
|
159
162
|
entryCount,
|
|
160
163
|
messageCount,
|
|
@@ -163,6 +166,7 @@ export class FooterComponent {
|
|
|
163
166
|
totalCacheRead,
|
|
164
167
|
totalCacheWrite,
|
|
165
168
|
totalCost,
|
|
169
|
+
totalSpawnedCost,
|
|
166
170
|
// Calculate context usage from session (handles compaction correctly).
|
|
167
171
|
// After compaction, tokens are unknown until the next LLM response.
|
|
168
172
|
contextUsage: this.session.getContextUsage(),
|
|
@@ -173,7 +177,7 @@ export class FooterComponent {
|
|
|
173
177
|
render(width) {
|
|
174
178
|
const state = this.session.state;
|
|
175
179
|
const usageSnapshot = this.getUsageSnapshot(state.messages?.length ?? 0);
|
|
176
|
-
const { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, contextUsage } = usageSnapshot;
|
|
180
|
+
const { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, totalSpawnedCost, contextUsage } = usageSnapshot;
|
|
177
181
|
const contextWindow = contextUsage?.contextWindow ?? state.model?.contextWindow ?? 0;
|
|
178
182
|
const contextPercentValue = contextUsage?.percent ?? 0;
|
|
179
183
|
const contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : "?";
|
|
@@ -201,8 +205,12 @@ export class FooterComponent {
|
|
|
201
205
|
statsParts.push(`W${formatTokens(totalCacheWrite)}`);
|
|
202
206
|
// Show cost with "(sub)" indicator if using OAuth subscription
|
|
203
207
|
const usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;
|
|
204
|
-
if (totalCost || usingSubscription) {
|
|
205
|
-
|
|
208
|
+
if (totalCost || totalSpawnedCost || usingSubscription) {
|
|
209
|
+
// Main cost, then the spawned/subagent roll-up: `$0.842 (sub) (+$0.310 sub)`.
|
|
210
|
+
let costStr = `$${totalCost.toFixed(3)}${usingSubscription ? " (sub)" : ""}`;
|
|
211
|
+
if (totalSpawnedCost) {
|
|
212
|
+
costStr += ` (+$${totalSpawnedCost.toFixed(3)} sub)`;
|
|
213
|
+
}
|
|
206
214
|
statsParts.push(costStr);
|
|
207
215
|
}
|
|
208
216
|
// Colorize context percentage based on usage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAU;IACjD,qFAAqF;IACrF,OAAO,IAAI;SACT,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;SACzB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,IAAI,EAAE,CAAC;AAAA,CACT;AAED,SAAS,SAAS,CAAC,IAAY,EAAU;IACxC,OAAO,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC,CAAC;AAAA,CACtD;AAED,SAAS,sBAAsB,CAAC,KAAa,EAAU;IACtD,MAAM,UAAU,GAAG,KAAK;SACtB,WAAW,EAAE;SACb,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;SAC5B,IAAI,EAAE,CAAC;IACT,IAAI,CAAC,UAAU;QAAE,OAAO,QAAQ,CAAC;IACjC,IAAI,UAAU,KAAK,UAAU;QAAE,OAAO,OAAO,CAAC;IAC9C,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO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,CAAC,oBAAoB,EAAE,CAAC;QACjE,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,UAAU,GAAG,uBAAuB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACxE,IAAI,UAAU,EAAE,CAAC;gBAChB,iFAAiF;gBACjF,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\nfunction stripAnsi(text: string): string {\n\treturn text.replace(/\\u001b\\[[0-?]*[ -/]*[@-~]/g, \"\");\n}\n\nfunction normalizeLearningPhase(phase: string): string {\n\tconst normalized = phase\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"\")\n\t\t.trim();\n\tif (!normalized) return \"active\";\n\tif (normalized === \"starting\") return \"start\";\n\tif (normalized === \"mapping\") return \"map\";\n\tif (normalized === \"scanning\") return \"scan\";\n\tif (normalized === \"auditing\") return \"audit\";\n\tif (normalized === \"learning\") return \"run\";\n\tif (normalized === \"pruning\") return \"prune\";\n\treturn normalized.slice(0, 16);\n}\n\nfunction formatExtensionStatuses(statuses: ReadonlyMap<string, string>): string[] {\n\tconst regularStatuses: string[] = [];\n\tconst learningPhases = new Set<string>();\n\tlet sawLearningStatus = false;\n\n\tfor (const [key, rawText] of Array.from(statuses.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n\t\tconst text = sanitizeStatusText(rawText);\n\t\tconst plain = stripAnsi(text).trim();\n\t\tconst plainLower = plain.toLowerCase();\n\t\tlet phase: string | undefined;\n\n\t\tif (plainLower.startsWith(\"(learning)\")) {\n\t\t\tphase = plain.slice(\"(learning)\".length).trim();\n\t\t} else if (plainLower === \"learning\") {\n\t\t\tphase = \"active\";\n\t\t} else if (/^learn(?:ing)?\\s*[: ]/.test(plainLower)) {\n\t\t\tphase = plain.replace(/^learn(?:ing)?\\s*[: ]/i, \"\").trim();\n\t\t}\n\n\t\tif (phase !== undefined) {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(normalizeLearningPhase(phase));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (key === \"auto-learn\" || key === \"continuous-learning\") {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(\"active\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tregularStatuses.push(text);\n\t}\n\n\tif (!sawLearningStatus) return regularStatuses;\n\tconst phases = Array.from(learningPhases).filter((phase) => phase !== \"active\");\n\tconst phaseText = phases.length > 0 ? phases.join(\"/\") : \"active\";\n\treturn [theme.fg(\"warning\", \"learn\") + theme.fg(\"dim\", `:${phaseText}`), ...regularStatuses];\n}\n\n/**\n * Format token counts for compact footer display.\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\ntype FooterUsageSnapshot = {\n\tentryCount: number;\n\tmessageCount: number;\n\ttotalInput: number;\n\ttotalOutput: number;\n\ttotalCacheRead: number;\n\ttotalCacheWrite: number;\n\ttotalCost: number;\n\tcontextUsage: ReturnType<AgentSession[\"getContextUsage\"]>;\n};\n\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\tprivate usageSnapshot?: FooterUsageSnapshot;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * Invalidate cached footer stats when session state changes.\n\t */\n\tinvalidate(): void {\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageSnapshot(messageCount: number): FooterUsageSnapshot {\n\t\tconst sessionManager = this.session.sessionManager as AgentSession[\"sessionManager\"] & {\n\t\t\tgetEntryCount?: () => number;\n\t\t};\n\t\tconst entryCount = sessionManager.getEntryCount?.() ?? sessionManager.getEntries().length;\n\t\tconst cached = this.usageSnapshot;\n\t\tif (cached && cached.entryCount === entryCount && cached.messageCount === messageCount) {\n\t\t\treturn cached;\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries in one batched pass.\n\t\t// This avoids per-frame defensive array allocation when only the TUI redraws.\n\t\tlet totalInput = 0;\n\t\tlet totalOutput = 0;\n\t\tlet totalCacheRead = 0;\n\t\tlet totalCacheWrite = 0;\n\t\tlet totalCost = 0;\n\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\tconst entry = entries[i];\n\t\t\tif (entry.type !== \"message\" || entry.message.role !== \"assistant\") continue;\n\t\t\tconst usage = entry.message.usage;\n\t\t\tif (!usage) continue;\n\t\t\ttotalInput += usage.input;\n\t\t\ttotalOutput += usage.output;\n\t\t\ttotalCacheRead += usage.cacheRead;\n\t\t\ttotalCacheWrite += usage.cacheWrite;\n\t\t\ttotalCost += usage.cost.total;\n\t\t}\n\n\t\tconst snapshot: FooterUsageSnapshot = {\n\t\t\tentryCount,\n\t\t\tmessageCount,\n\t\t\ttotalInput,\n\t\t\ttotalOutput,\n\t\t\ttotalCacheRead,\n\t\t\ttotalCacheWrite,\n\t\t\ttotalCost,\n\t\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\t\tcontextUsage: this.session.getContextUsage(),\n\t\t};\n\t\tthis.usageSnapshot = snapshot;\n\t\treturn snapshot;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst usageSnapshot = this.getUsageSnapshot(state.messages?.length ?? 0);\n\t\tconst { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, contextUsage } = usageSnapshot;\n\t\tconst contextWindow = contextUsage?.contextWindow ?? state.model?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line\n\t\tconst statsParts = [];\n\t\tif (totalInput) statsParts.push(`↑${formatTokens(totalInput)}`);\n\t\tif (totalOutput) statsParts.push(`↓${formatTokens(totalOutput)}`);\n\t\tif (totalCacheRead) statsParts.push(`R${formatTokens(totalCacheRead)}`);\n\t\tif (totalCacheWrite) statsParts.push(`W${formatTokens(totalCacheWrite)}`);\n\n\t\t// Show cost with \"(sub)\" indicator if using OAuth subscription\n\t\tconst usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;\n\t\tif (totalCost || usingSubscription) {\n\t\t\tconst costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tstatsParts.push(costStr);\n\t\t}\n\n\t\t// Colorize context percentage based on usage\n\t\tlet contextPercentStr: string;\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst contextPercentDisplay =\n\t\t\tcontextPercent === \"?\"\n\t\t\t\t? `?/${formatTokens(contextWindow)}${autoIndicator}`\n\t\t\t\t: `${contextPercent}%/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tif (contextPercentValue > 90) {\n\t\t\tcontextPercentStr = theme.fg(\"error\", contextPercentDisplay);\n\t\t} else if (contextPercentValue > 70) {\n\t\t\tcontextPercentStr = theme.fg(\"warning\", contextPercentDisplay);\n\t\t} else {\n\t\t\tcontextPercentStr = contextPercentDisplay;\n\t\t}\n\t\tstatsParts.push(contextPercentStr);\n\n\t\tlet statsLeft = statsParts.join(\" \");\n\n\t\t// Add model display name on the right side, plus thinking level if model supports it\n\t\tconst modelName = state.model?.name || state.model?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\trightSide = `(${state.model!.provider}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide, fall back\n\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t}\n\t\t}\n\n\t\tconst rightSideWidth = visibleWidth(rightSide);\n\t\tconst totalNeeded = statsLeftWidth + minPadding + rightSideWidth;\n\n\t\tlet statsLine: string;\n\t\tif (totalNeeded <= width) {\n\t\t\t// Both fit - add padding to right-align model\n\t\t\tconst padding = \" \".repeat(width - statsLeftWidth - rightSideWidth);\n\t\t\tstatsLine = statsLeft + padding + rightSide;\n\t\t} else {\n\t\t\t// Need to truncate right side\n\t\t\tconst availableForRight = width - statsLeftWidth - minPadding;\n\t\t\tif (availableForRight > 0) {\n\t\t\t\tconst truncatedRight = truncateToWidth(rightSide, availableForRight, \"\");\n\t\t\t\tconst truncatedRightWidth = visibleWidth(truncatedRight);\n\t\t\t\tconst padding = \" \".repeat(Math.max(0, width - statsLeftWidth - truncatedRightWidth));\n\t\t\t\tstatsLine = statsLeft + padding + truncatedRight;\n\t\t\t} else {\n\t\t\t\t// Not enough space for right side at all\n\t\t\t\tstatsLine = statsLeft;\n\t\t\t}\n\t\t}\n\n\t\t// Apply dim to each part separately. statsLeft may contain color codes (for context %)\n\t\t// that end with a reset, which would clear an outer dim wrapper. So we dim the parts\n\t\t// before and after the colored section independently.\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\t\tconst remainder = statsLine.slice(statsLeft.length); // padding + rightSide\n\t\tconst dimRemainder = theme.fg(\"dim\", remainder);\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine, dimStatsLeft + dimRemainder];\n\n\t\t// Add extension statuses on a single line. Learning-related statuses are\n\t\t// folded into one compact chip so independent learning systems do not render\n\t\t// brittle duplicates like \"(learning) (learning) auto\".\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst statusLine = formatExtensionStatuses(extensionStatuses).join(\" \");\n\t\t\tif (statusLine) {\n\t\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t\t}\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnF,OAAO,EAAE,KAAK,E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CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\nfunction stripAnsi(text: string): string {\n\treturn text.replace(/\\u001b\\[[0-?]*[ -/]*[@-~]/g, \"\");\n}\n\nfunction normalizeLearningPhase(phase: string): string {\n\tconst normalized = phase\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"\")\n\t\t.trim();\n\tif (!normalized) return \"active\";\n\tif (normalized === \"starting\") return \"start\";\n\tif (normalized === \"mapping\") return \"map\";\n\tif (normalized === \"scanning\") return \"scan\";\n\tif (normalized === \"auditing\") return \"audit\";\n\tif (normalized === \"learning\") return \"run\";\n\tif (normalized === \"pruning\") return \"prune\";\n\treturn normalized.slice(0, 16);\n}\n\nfunction formatExtensionStatuses(statuses: ReadonlyMap<string, string>): string[] {\n\tconst regularStatuses: string[] = [];\n\tconst learningPhases = new Set<string>();\n\tlet sawLearningStatus = false;\n\n\tfor (const [key, rawText] of Array.from(statuses.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n\t\tconst text = sanitizeStatusText(rawText);\n\t\tconst plain = stripAnsi(text).trim();\n\t\tconst plainLower = plain.toLowerCase();\n\t\tlet phase: string | undefined;\n\n\t\tif (plainLower.startsWith(\"(learning)\")) {\n\t\t\tphase = plain.slice(\"(learning)\".length).trim();\n\t\t} else if (plainLower === \"learning\") {\n\t\t\tphase = \"active\";\n\t\t} else if (/^learn(?:ing)?\\s*[: ]/.test(plainLower)) {\n\t\t\tphase = plain.replace(/^learn(?:ing)?\\s*[: ]/i, \"\").trim();\n\t\t}\n\n\t\tif (phase !== undefined) {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(normalizeLearningPhase(phase));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (key === \"auto-learn\" || key === \"continuous-learning\") {\n\t\t\tsawLearningStatus = true;\n\t\t\tlearningPhases.add(\"active\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tregularStatuses.push(text);\n\t}\n\n\tif (!sawLearningStatus) return regularStatuses;\n\tconst phases = Array.from(learningPhases).filter((phase) => phase !== \"active\");\n\tconst phaseText = phases.length > 0 ? phases.join(\"/\") : \"active\";\n\treturn [theme.fg(\"warning\", \"learn\") + theme.fg(\"dim\", `:${phaseText}`), ...regularStatuses];\n}\n\n/**\n * Format token counts for compact footer display.\n */\nfunction formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\ntype FooterUsageSnapshot = {\n\tentryCount: number;\n\tmessageCount: number;\n\ttotalInput: number;\n\ttotalOutput: number;\n\ttotalCacheRead: number;\n\ttotalCacheWrite: number;\n\ttotalCost: number;\n\t/** Rolled-up cost of spawned/subagent sessions (Cost Aggregation). 0 when none. */\n\ttotalSpawnedCost: number;\n\tcontextUsage: ReturnType<AgentSession[\"getContextUsage\"]>;\n};\n\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\tprivate usageSnapshot?: FooterUsageSnapshot;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * Invalidate cached footer stats when session state changes.\n\t */\n\tinvalidate(): void {\n\t\tthis.usageSnapshot = undefined;\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageSnapshot(messageCount: number): FooterUsageSnapshot {\n\t\tconst sessionManager = this.session.sessionManager as AgentSession[\"sessionManager\"] & {\n\t\t\tgetEntryCount?: () => number;\n\t\t};\n\t\tconst entryCount = sessionManager.getEntryCount?.() ?? sessionManager.getEntries().length;\n\t\tconst cached = this.usageSnapshot;\n\t\tif (cached && cached.entryCount === entryCount && cached.messageCount === messageCount) {\n\t\t\treturn cached;\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries in one batched pass.\n\t\t// This avoids per-frame defensive array allocation when only the TUI redraws.\n\t\tlet totalInput = 0;\n\t\tlet totalOutput = 0;\n\t\tlet totalCacheRead = 0;\n\t\tlet totalCacheWrite = 0;\n\t\tlet totalCost = 0;\n\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\tconst entry = entries[i];\n\t\t\tif (entry.type !== \"message\" || entry.message.role !== \"assistant\") continue;\n\t\t\tconst usage = entry.message.usage;\n\t\t\tif (!usage) continue;\n\t\t\ttotalInput += usage.input;\n\t\t\ttotalOutput += usage.output;\n\t\t\ttotalCacheRead += usage.cacheRead;\n\t\t\ttotalCacheWrite += usage.cacheWrite;\n\t\t\ttotalCost += usage.cost.total;\n\t\t}\n\n\t\t// Roll up spawned/subagent cost (Cost Aggregation, Model A). Derived from the same\n\t\t// session entries, so the {entryCount} cache key above busts when new reports land.\n\t\tconst totalSpawnedCost = this.session.getSpawnedUsage().cost;\n\n\t\tconst snapshot: FooterUsageSnapshot = {\n\t\t\tentryCount,\n\t\t\tmessageCount,\n\t\t\ttotalInput,\n\t\t\ttotalOutput,\n\t\t\ttotalCacheRead,\n\t\t\ttotalCacheWrite,\n\t\t\ttotalCost,\n\t\t\ttotalSpawnedCost,\n\t\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\t\tcontextUsage: this.session.getContextUsage(),\n\t\t};\n\t\tthis.usageSnapshot = snapshot;\n\t\treturn snapshot;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst usageSnapshot = this.getUsageSnapshot(state.messages?.length ?? 0);\n\t\tconst { totalInput, totalOutput, totalCacheRead, totalCacheWrite, totalCost, totalSpawnedCost, contextUsage } =\n\t\t\tusageSnapshot;\n\t\tconst contextWindow = contextUsage?.contextWindow ?? state.model?.contextWindow ?? 0;\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\t// Build stats line\n\t\tconst statsParts = [];\n\t\tif (totalInput) statsParts.push(`↑${formatTokens(totalInput)}`);\n\t\tif (totalOutput) statsParts.push(`↓${formatTokens(totalOutput)}`);\n\t\tif (totalCacheRead) statsParts.push(`R${formatTokens(totalCacheRead)}`);\n\t\tif (totalCacheWrite) statsParts.push(`W${formatTokens(totalCacheWrite)}`);\n\n\t\t// Show cost with \"(sub)\" indicator if using OAuth subscription\n\t\tconst usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;\n\t\tif (totalCost || totalSpawnedCost || usingSubscription) {\n\t\t\t// Main cost, then the spawned/subagent roll-up: `$0.842 (sub) (+$0.310 sub)`.\n\t\t\tlet costStr = `$${totalCost.toFixed(3)}${usingSubscription ? \" (sub)\" : \"\"}`;\n\t\t\tif (totalSpawnedCost) {\n\t\t\t\tcostStr += ` (+$${totalSpawnedCost.toFixed(3)} sub)`;\n\t\t\t}\n\t\t\tstatsParts.push(costStr);\n\t\t}\n\n\t\t// Colorize context percentage based on usage\n\t\tlet contextPercentStr: string;\n\t\tconst autoIndicator = this.autoCompactEnabled ? \" (auto)\" : \"\";\n\t\tconst contextPercentDisplay =\n\t\t\tcontextPercent === \"?\"\n\t\t\t\t? `?/${formatTokens(contextWindow)}${autoIndicator}`\n\t\t\t\t: `${contextPercent}%/${formatTokens(contextWindow)}${autoIndicator}`;\n\t\tif (contextPercentValue > 90) {\n\t\t\tcontextPercentStr = theme.fg(\"error\", contextPercentDisplay);\n\t\t} else if (contextPercentValue > 70) {\n\t\t\tcontextPercentStr = theme.fg(\"warning\", contextPercentDisplay);\n\t\t} else {\n\t\t\tcontextPercentStr = contextPercentDisplay;\n\t\t}\n\t\tstatsParts.push(contextPercentStr);\n\n\t\tlet statsLeft = statsParts.join(\" \");\n\n\t\t// Add model display name on the right side, plus thinking level if model supports it\n\t\tconst modelName = state.model?.name || state.model?.id || \"no-model\";\n\n\t\tlet statsLeftWidth = visibleWidth(statsLeft);\n\n\t\t// If statsLeft is too wide, truncate it\n\t\tif (statsLeftWidth > width) {\n\t\t\tstatsLeft = truncateToWidth(statsLeft, width, \"...\");\n\t\t\tstatsLeftWidth = visibleWidth(statsLeft);\n\t\t}\n\n\t\t// Calculate available space for padding (minimum 2 spaces between stats and model)\n\t\tconst minPadding = 2;\n\n\t\t// Add thinking level indicator if model supports reasoning\n\t\tlet rightSideWithoutProvider = modelName;\n\t\tif (state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\trightSideWithoutProvider =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} • thinking off` : `${modelName} • ${thinkingLevel}`;\n\t\t}\n\n\t\t// Prepend the provider in parentheses if there are multiple providers and there's enough room\n\t\tlet rightSide = rightSideWithoutProvider;\n\t\tif (this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\trightSide = `(${state.model!.provider}) ${rightSideWithoutProvider}`;\n\t\t\tif (statsLeftWidth + minPadding + visibleWidth(rightSide) > width) {\n\t\t\t\t// Too wide, fall back\n\t\t\t\trightSide = rightSideWithoutProvider;\n\t\t\t}\n\t\t}\n\n\t\tconst rightSideWidth = visibleWidth(rightSide);\n\t\tconst totalNeeded = statsLeftWidth + minPadding + rightSideWidth;\n\n\t\tlet statsLine: string;\n\t\tif (totalNeeded <= width) {\n\t\t\t// Both fit - add padding to right-align model\n\t\t\tconst padding = \" \".repeat(width - statsLeftWidth - rightSideWidth);\n\t\t\tstatsLine = statsLeft + padding + rightSide;\n\t\t} else {\n\t\t\t// Need to truncate right side\n\t\t\tconst availableForRight = width - statsLeftWidth - minPadding;\n\t\t\tif (availableForRight > 0) {\n\t\t\t\tconst truncatedRight = truncateToWidth(rightSide, availableForRight, \"\");\n\t\t\t\tconst truncatedRightWidth = visibleWidth(truncatedRight);\n\t\t\t\tconst padding = \" \".repeat(Math.max(0, width - statsLeftWidth - truncatedRightWidth));\n\t\t\t\tstatsLine = statsLeft + padding + truncatedRight;\n\t\t\t} else {\n\t\t\t\t// Not enough space for right side at all\n\t\t\t\tstatsLine = statsLeft;\n\t\t\t}\n\t\t}\n\n\t\t// Apply dim to each part separately. statsLeft may contain color codes (for context %)\n\t\t// that end with a reset, which would clear an outer dim wrapper. So we dim the parts\n\t\t// before and after the colored section independently.\n\t\tconst dimStatsLeft = theme.fg(\"dim\", statsLeft);\n\t\tconst remainder = statsLine.slice(statsLeft.length); // padding + rightSide\n\t\tconst dimRemainder = theme.fg(\"dim\", remainder);\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine, dimStatsLeft + dimRemainder];\n\n\t\t// Add extension statuses on a single line. Learning-related statuses are\n\t\t// folded into one compact chip so independent learning systems do not render\n\t\t// brittle duplicates like \"(learning) (learning) auto\".\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst statusLine = formatExtensionStatuses(extensionStatuses).join(\" \");\n\t\t\tif (statusLine) {\n\t\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t\t}\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -433,6 +433,19 @@ export declare class InteractiveMode {
|
|
|
433
433
|
private countAgentToolCalls;
|
|
434
434
|
private buildAutonomyReviewDigest;
|
|
435
435
|
private evaluateAutonomyReview;
|
|
436
|
+
/**
|
|
437
|
+
* Native reflection (R2) is the in-process replacement for the buggy `continuous-learning`
|
|
438
|
+
* subprocess. It runs when auto-learn is enabled and is not killed via `PI_NATIVE_REFLECTION=0`.
|
|
439
|
+
*/
|
|
440
|
+
private isNativeReflectionEnabled;
|
|
441
|
+
/** Heuristic: does the user's turn text read like a correction/steer worth learning from? */
|
|
442
|
+
private hasCorrectionSignal;
|
|
443
|
+
/**
|
|
444
|
+
* End-of-loop native reflection: demand-gate the just-finished turn (zero-I/O) and, when
|
|
445
|
+
* warranted, run the in-process {@link AgentSession.runReflectionPass} as a fire-and-forget
|
|
446
|
+
* background microtask. No subprocess, no blocking of the UI.
|
|
447
|
+
*/
|
|
448
|
+
private maybeRunNativeReflection;
|
|
436
449
|
private maybeStartAutoLearn;
|
|
437
450
|
private maybeStartAutonomyReview;
|
|
438
451
|
private updateAutoLearnFooter;
|