@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
106 lines • 4.19 kB
JavaScript
import { CustomEditor } from "../components/custom-editor.js";
import { WorkingStatusIndicator } from "../components/status-indicator.js";
import { getReservedKeywordHighlight, theme } from "../theme/theme.js";
import { getGrokChromeTokens } from "./chrome-tokens.js";
import { GrokFooter } from "./footer.js";
import { GrokInputCard } from "./input-card.js";
import { GROK_GLYPHS } from "./palette.js";
import { GrokWelcomeCard } from "./welcome-card.js";
class GrokFooterSurface {
constructor(content) {
this.content = content;
}
invalidate() {
this.content.invalidate();
}
render(width) {
const surface = getGrokChromeTokens().surface;
return this.content.render(width).map(surface);
}
dispose() {
this.content.dispose?.();
}
}
class GrokRootSpacer {
constructor(ui, content) {
this.ui = ui;
this.content = content;
}
invalidate() {
// The spacer derives its height from the current terminal dimensions.
}
render(width) {
const contentHeight = this.content.reduce((height, component) => height + component.render(width).length, 0);
return Array.from({ length: Math.max(0, this.ui.terminal.rows - contentHeight) }, () => "");
}
}
class GrokEditor extends CustomEditor {
constructor(ui, editorTheme, keybindings, options) {
super(ui, editorTheme, keybindings, options);
this.card = new GrokInputCard({
render: (width) => this.renderBase(width),
invalidate: () => super.invalidate(),
});
}
render(width) {
return this.card.render(width);
}
renderBase(width) {
return super.render(width);
}
}
export class GrokChrome {
constructor() {
this.toolPresentation = "grok";
}
createBaseEditor({ ui, keybindings, editorOptions, }) {
return new GrokEditor(ui, this.getEditorTheme(), keybindings, editorOptions);
}
getEditorTheme() {
const tokens = getGrokChromeTokens();
return {
borderColor: tokens.inputBorder,
keywordHighlight: getReservedKeywordHighlight(),
selectList: {
selectedPrefix: (text) => theme.fg("accent", text),
selectedText: (text) => tokens.primaryText(text),
description: (text) => tokens.mutedText(text),
scrollInfo: (text) => tokens.mutedText(text),
noMatch: (text) => tokens.mutedText(text),
renderRow: ({ prefix, primary, description, isSelected }) => {
const row = `${prefix}${tokens.primaryText(primary)}${description ? tokens.mutedText(description) : ""}`;
return isSelected ? theme.bg("selectedBg", row) : row;
},
},
};
}
createFooter(session, footerData) {
return new GrokFooter(session, footerData);
}
createWelcomeContent(appName, version) {
return new GrokWelcomeCard(appName, version);
}
createWorkingIndicator(ui, message, indicator) {
return new WorkingStatusIndicator(ui, message, {
...indicator,
frames: [GROK_GLYPHS.spinner],
indicatorFormatter: (frame) => theme.fg("accent", frame),
});
}
getEditorBorderColor(_context) {
return getGrokChromeTokens().inputBorder;
}
arrangeRoot(children, ui) {
// pi-tui concatenates root children without a layout pass. Keep transcript
// content first and calculate the remaining rows at render time from the TUI's
// terminal height, so the input tail is truly bottom-anchored when it fits.
const inputTailStart = Math.max(0, children.length - 3);
const content = children.slice(0, inputTailStart);
const inputTail = children.slice(inputTailStart);
const footer = inputTail.at(-1);
const tail = footer ? [...inputTail.slice(0, -1), new GrokFooterSurface(footer)] : [...inputTail];
const arranged = [...content, ...tail];
return ui ? [...content, new GrokRootSpacer(ui, arranged), ...tail] : arranged;
}
}
//# sourceMappingURL=chrome.js.map