mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 12:03:23 +00:00
feat(coding-agent): add --export CLI flag to convert session files to HTML
Closes #80
This commit is contained in:
parent
dd71f877e5
commit
8900897840
4 changed files with 747 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ import { homedir } from "os";
|
|||
import { dirname, extname, join, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { getChangelogPath, getNewEntries, parseChangelog } from "./changelog.js";
|
||||
import { exportFromFile } from "./export-html.js";
|
||||
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
|
||||
import { SessionManager } from "./session-manager.js";
|
||||
import { SettingsManager } from "./settings-manager.js";
|
||||
|
|
@ -50,6 +51,7 @@ interface Args {
|
|||
models?: string[];
|
||||
tools?: ToolName[];
|
||||
print?: boolean;
|
||||
export?: string;
|
||||
messages: string[];
|
||||
fileArgs: string[];
|
||||
}
|
||||
|
|
@ -114,6 +116,8 @@ function parseArgs(args: string[]): Args {
|
|||
}
|
||||
} else if (arg === "--print" || arg === "-p") {
|
||||
result.print = true;
|
||||
} else if (arg === "--export" && i + 1 < args.length) {
|
||||
result.export = args[++i];
|
||||
} else if (arg.startsWith("@")) {
|
||||
result.fileArgs.push(arg.slice(1)); // Remove @ prefix
|
||||
} else if (!arg.startsWith("-")) {
|
||||
|
|
@ -237,6 +241,7 @@ ${chalk.bold("Options:")}
|
|||
--tools <tools> Comma-separated list of tools to enable (default: read,bash,edit,write)
|
||||
Available: read, bash, edit, write, grep, find, ls
|
||||
--thinking <level> Set thinking level: off, minimal, low, medium, high
|
||||
--export <file> Export session file to HTML and exit
|
||||
--help, -h Show this help
|
||||
|
||||
${chalk.bold("Examples:")}
|
||||
|
|
@ -273,6 +278,10 @@ ${chalk.bold("Examples:")}
|
|||
# Read-only mode (no file modifications possible)
|
||||
pi --tools read,grep,find,ls -p "Review the code in src/"
|
||||
|
||||
# Export a session file to HTML
|
||||
pi --export ~/.pi/agent/sessions/--path--/session.jsonl
|
||||
pi --export session.jsonl output.html
|
||||
|
||||
${chalk.bold("Environment Variables:")}
|
||||
ANTHROPIC_API_KEY - Anthropic Claude API key
|
||||
ANTHROPIC_OAUTH_TOKEN - Anthropic OAuth token (alternative to API key)
|
||||
|
|
@ -839,6 +848,20 @@ export async function main(args: string[]) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Handle --export flag: convert session file to HTML and exit
|
||||
if (parsed.export) {
|
||||
try {
|
||||
// Use first message as output path if provided
|
||||
const outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;
|
||||
const result = exportFromFile(parsed.export, outputPath);
|
||||
console.log(`Exported to: ${result}`);
|
||||
return;
|
||||
} catch (error: any) {
|
||||
console.error(chalk.red(`Error: ${error.message || "Failed to export session"}`));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate: RPC mode doesn't support @file arguments
|
||||
if (parsed.mode === "rpc" && parsed.fileArgs.length > 0) {
|
||||
console.error(chalk.red("Error: @file arguments are not supported in RPC mode"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue