Merge branch 'badlogic:main' into fix/async-extension-factories

This commit is contained in:
Austin 2026-01-06 15:47:30 -08:00 committed by GitHub
commit c2eb8d0f92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 461 additions and 85 deletions

View file

@ -2057,9 +2057,9 @@ export class AgentSession {
* @param outputPath Optional output path (defaults to session directory)
* @returns Path to exported file
*/
exportToHtml(outputPath?: string): string {
async exportToHtml(outputPath?: string): Promise<string> {
const themeName = this.settingsManager.getTheme();
return exportSessionToHtml(this.sessionManager, this.state, { outputPath, themeName });
return await exportSessionToHtml(this.sessionManager, this.state, { outputPath, themeName });
}
// =========================================================================

View file

@ -1,4 +1,5 @@
import type { AgentState } from "@mariozechner/pi-agent-core";
import type { AgentState, AgentTool } from "@mariozechner/pi-agent-core";
import { buildCodexPiBridge, getCodexInstructions } from "@mariozechner/pi-ai";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { basename, join } from "path";
import { APP_NAME, getExportTemplateDir } from "../../config.js";
@ -10,6 +11,37 @@ export interface ExportOptions {
themeName?: string;
}
/** Info about Codex injection to show inline with model_change entries */
interface CodexInjectionInfo {
/** Codex instructions text */
instructions: string;
/** Bridge text (tool list) */
bridge: string;
}
/**
* Build Codex injection info for display inline with model_change entries.
*/
async function buildCodexInjectionInfo(tools?: AgentTool[]): Promise<CodexInjectionInfo | undefined> {
// Try to get cached instructions for default model family
let instructions: string | null = null;
try {
instructions = await getCodexInstructions("gpt-5.1-codex");
} catch {
// Cache miss - that's fine
}
const bridgeText = buildCodexPiBridge(tools);
const instructionsText =
instructions || "(Codex instructions not cached. Run a Codex request to populate the local cache.)";
return {
instructions: instructionsText,
bridge: bridgeText,
};
}
/** Parse a color string to RGB values. Supports hex (#RRGGBB) and rgb(r,g,b) formats. */
function parseColor(color: string): { r: number; g: number; b: number } | undefined {
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
@ -103,6 +135,8 @@ interface SessionData {
entries: ReturnType<SessionManager["getEntries"]>;
leafId: string | null;
systemPrompt?: string;
/** Info for rendering Codex injection inline with model_change entries */
codexInjectionInfo?: CodexInjectionInfo;
tools?: { name: string; description: string }[];
}
@ -146,7 +180,11 @@ function generateHtml(sessionData: SessionData, themeName?: string): string {
* Export session to HTML using SessionManager and AgentState.
* Used by TUI's /export command.
*/
export function exportSessionToHtml(sm: SessionManager, state?: AgentState, options?: ExportOptions | string): string {
export async function exportSessionToHtml(
sm: SessionManager,
state?: AgentState,
options?: ExportOptions | string,
): Promise<string> {
const opts: ExportOptions = typeof options === "string" ? { outputPath: options } : options || {};
const sessionFile = sm.getSessionFile();
@ -162,6 +200,7 @@ export function exportSessionToHtml(sm: SessionManager, state?: AgentState, opti
entries: sm.getEntries(),
leafId: sm.getLeafId(),
systemPrompt: state?.systemPrompt,
codexInjectionInfo: await buildCodexInjectionInfo(state?.tools),
tools: state?.tools?.map((t) => ({ name: t.name, description: t.description })),
};
@ -181,7 +220,7 @@ export function exportSessionToHtml(sm: SessionManager, state?: AgentState, opti
* Export session file to HTML (standalone, without AgentState).
* Used by CLI for exporting arbitrary session files.
*/
export function exportFromFile(inputPath: string, options?: ExportOptions | string): string {
export async function exportFromFile(inputPath: string, options?: ExportOptions | string): Promise<string> {
const opts: ExportOptions = typeof options === "string" ? { outputPath: options } : options || {};
if (!existsSync(inputPath)) {
@ -195,6 +234,7 @@ export function exportFromFile(inputPath: string, options?: ExportOptions | stri
entries: sm.getEntries(),
leafId: sm.getLeafId(),
systemPrompt: undefined,
codexInjectionInfo: await buildCodexInjectionInfo(undefined),
tools: undefined,
};

View file

@ -512,6 +512,39 @@
font-weight: bold;
}
.codex-bridge-toggle {
color: var(--muted);
cursor: pointer;
text-decoration: underline;
font-size: 10px;
}
.codex-bridge-toggle:hover {
color: var(--accent);
}
.codex-bridge-content {
display: none;
margin-top: 8px;
padding: 8px;
background: var(--exportCardBg);
border-radius: 4px;
font-size: 11px;
max-height: 300px;
overflow: auto;
}
.codex-bridge-content pre {
margin: 0;
white-space: pre-wrap;
word-break: break-word;
color: var(--muted);
}
.model-change.show-bridge .codex-bridge-content {
display: block;
}
/* Compaction / Branch Summary - matches customMessage colors from TUI */
.compaction {
background: var(--customMessageBg);
@ -593,6 +626,17 @@
display: block;
}
.system-prompt.provider-prompt {
border-left: 3px solid var(--warning);
}
.system-prompt-note {
font-size: 10px;
font-style: italic;
color: var(--muted);
margin-top: 4px;
}
/* Tools list */
.tools-list {
background: var(--customMessageBg);

View file

@ -12,7 +12,7 @@
bytes[i] = binary.charCodeAt(i);
}
const data = JSON.parse(new TextDecoder('utf-8').decode(bytes));
const { header, entries, leafId: defaultLeafId, systemPrompt, tools } = data;
const { header, entries, leafId: defaultLeafId, systemPrompt, codexInjectionInfo, tools } = data;
// ============================================================
// URL PARAMETER HANDLING
@ -954,7 +954,17 @@
}
if (entry.type === 'model_change') {
return `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span></div>`;
let html = `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span>`;
// Show expandable bridge prompt info when switching to openai-codex
if (entry.provider === 'openai-codex' && codexInjectionInfo) {
const fullContent = `# Codex Instructions\n${codexInjectionInfo.instructions}\n\n# Codex-Pi Bridge\n${codexInjectionInfo.bridge}`;
html += ` <span class="codex-bridge-toggle" onclick="event.stopPropagation(); this.parentElement.classList.toggle('show-bridge')">[bridge prompt]</span>`;
html += `<div class="codex-bridge-content"><pre>${escapeHtml(fullContent)}</pre></div>`;
}
html += '</div>';
return html;
}
if (entry.type === 'compaction') {
@ -1060,6 +1070,7 @@
</div>
</div>`;
// Render system prompt (user's base prompt, applies to all providers)
if (systemPrompt) {
const lines = systemPrompt.split('\n');
const previewLines = 10;

View file

@ -52,13 +52,13 @@ export type { AgentToolResult, AgentToolUpdateCallback };
*/
export interface ExtensionUIContext {
/** Show a selector and return the user's choice. */
select(title: string, options: string[]): Promise<string | undefined>;
select(title: string, options: string[], opts?: { signal?: AbortSignal }): Promise<string | undefined>;
/** Show a confirmation dialog. */
confirm(title: string, message: string): Promise<boolean>;
confirm(title: string, message: string, opts?: { signal?: AbortSignal }): Promise<boolean>;
/** Show a text input dialog. */
input(title: string, placeholder?: string): Promise<string | undefined>;
input(title: string, placeholder?: string, opts?: { signal?: AbortSignal }): Promise<string | undefined>;
/** Show a notification to the user. */
notify(message: string, type?: "info" | "warning" | "error"): void;