@@ -1,3 +1,4 @@
|
||||
import { isAbsolute, relative, resolve, sep } from "node:path";
|
||||
import { type Component, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
||||
import type { AgentSession } from "../../../core/agent-session.ts";
|
||||
import type { ReadonlyFooterDataProvider } from "../../../core/footer-data-provider.ts";
|
||||
@@ -26,6 +27,20 @@ function formatTokens(count: number): string {
|
||||
return `${Math.round(count / 1000000)}M`;
|
||||
}
|
||||
|
||||
export function formatCwdForFooter(cwd: string, home: string | undefined): string {
|
||||
if (!home) return cwd;
|
||||
|
||||
const resolvedCwd = resolve(cwd);
|
||||
const resolvedHome = resolve(home);
|
||||
const relativeToHome = relative(resolvedHome, resolvedCwd);
|
||||
const isInsideHome =
|
||||
relativeToHome === "" ||
|
||||
(relativeToHome !== ".." && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));
|
||||
|
||||
if (!isInsideHome) return cwd;
|
||||
return relativeToHome === "" ? "~" : `~${sep}${relativeToHome}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Footer component that shows pwd, token stats, and context usage.
|
||||
* Computes token/context stats from session, gets git branch and extension statuses from provider.
|
||||
@@ -92,11 +107,7 @@ export class FooterComponent implements Component {
|
||||
const contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : "?";
|
||||
|
||||
// Replace home directory with ~
|
||||
let pwd = this.session.sessionManager.getCwd();
|
||||
const home = process.env.HOME || process.env.USERPROFILE;
|
||||
if (home && pwd.startsWith(home)) {
|
||||
pwd = `~${pwd.slice(home.length)}`;
|
||||
}
|
||||
let pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);
|
||||
|
||||
// Add git branch if available
|
||||
const branch = this.footerData.getGitBranch();
|
||||
|
||||
Reference in New Issue
Block a user