-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpodguy-startup.ts
More file actions
143 lines (130 loc) · 5.75 KB
/
podguy-startup.ts
File metadata and controls
143 lines (130 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { relative, resolve } from "node:path";
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
const WIDGET_ID = "podguy-startup";
const cwd = process.cwd();
const home = homedir();
function toDisplayPath(filePath: string): string {
const normalized = filePath.replaceAll("\\", "/");
const normalizedCwd = cwd.replaceAll("\\", "/");
const normalizedHome = home.replaceAll("\\", "/");
if (normalized === normalizedCwd) return ".";
if (normalized.startsWith(`${normalizedCwd}/`)) {
return `./${relative(cwd, filePath).replaceAll("\\", "/")}`;
}
if (normalized.startsWith(`${normalizedHome}/`)) {
return `~/${relative(home, filePath).replaceAll("\\", "/")}`;
}
return normalized;
}
function readProfileSummary(): string | undefined {
for (const profilePath of [resolve(cwd, "podguy.toml"), resolve(cwd, "podcast.toml")]) {
if (!existsSync(profilePath)) continue;
try {
const text = readFileSync(profilePath, "utf8");
const showName = text.match(/^\s*show_name\s*=\s*["']([^"']+)["']/m)?.[1];
const displayPath = toDisplayPath(profilePath);
return showName ? `${showName} (${displayPath})` : displayPath;
} catch {
return toDisplayPath(profilePath);
}
}
return undefined;
}
function formatSection(
theme: { fg(color: "mdHeading" | "text" | "muted" | "dim", text: string): string },
label: string,
items: Array<{ path: string; scope: string }>,
): string[] {
if (items.length === 0) return [];
const prefix = `[${label}]`.padEnd(13, " ");
const indent = " ".repeat(prefix.length);
return items.map((item, index) => {
const labelText = index === 0 ? theme.fg("mdHeading", prefix) : indent;
const pathText = theme.fg("text", item.path);
const scopeText = theme.fg("muted", `[${item.scope}]`);
return `${labelText}${pathText} ${scopeText}`;
});
}
export default function podguyStartupExtension(pi: ExtensionAPI) {
pi.on("session_start", (_event, ctx) => {
if (!ctx.hasUI) return;
ctx.ui.setHeader((_tui, theme) => ({
render(_width: number): string[] {
const accent = (text: string) => theme.fg("accent", text);
const muted = (text: string) => theme.fg("muted", text);
const dim = (text: string) => theme.fg("dim", text);
const projectAgents = resolve(cwd, "AGENTS.md");
const userAgents = resolve(home, ".pi/agent/AGENTS.md");
const skillPaths = [
resolve(cwd, "src/podguy-post-production/SKILL.md"),
resolve(cwd, "src/podguy-clip-cutter/SKILL.md"),
];
const promptsPath = resolve(cwd, "prompts");
const extensionPath = resolve(cwd, "src/podguy-startup.ts");
const profilePath = [resolve(cwd, "podguy.toml"), resolve(cwd, "podcast.toml")].find(
(path) => existsSync(path),
);
const themePath = ctx.ui.theme.sourcePath;
const themeScope = ctx.ui.theme.sourceInfo?.scope;
const contextItems = [
...(existsSync(projectAgents)
? [{ path: toDisplayPath(projectAgents), scope: "project" }]
: []),
...(existsSync(userAgents) ? [{ path: toDisplayPath(userAgents), scope: "user" }] : []),
];
const skillItems = skillPaths
.filter((path) => existsSync(path))
.map((path) => ({ path: toDisplayPath(path), scope: "project" }));
const promptItems = existsSync(promptsPath)
? [{ path: toDisplayPath(promptsPath), scope: "project" }]
: [];
const extensionItems = existsSync(extensionPath)
? [{ path: toDisplayPath(extensionPath), scope: "project" }]
: [];
const profileItems = profilePath
? [{ path: toDisplayPath(profilePath), scope: "project" }]
: [];
const themeItems = themePath
? [{ path: toDisplayPath(themePath), scope: themeScope ?? "user" }]
: ctx.ui.theme.name
? [{ path: ctx.ui.theme.name, scope: "builtin" }]
: [];
const profileSummary = readProfileSummary();
return [
accent(" __ "),
accent(" ____ ____ ____/ /___ ___ ____ __"),
accent(" / __ \\/ __ \\/ __ / __ `/ / / / / / /"),
accent(" / /_/ / /_/ / /_/ / /_/ / /_/ / /_/ / "),
accent(" / .___/\\____/\\__,_/\\__, /\\__,_/\\__, / "),
accent("/_/ /____/ /____/"),
muted(" Podcast post-production"),
dim(profileSummary ? ` profile: ${profileSummary}` : " no podguy.toml profile yet"),
"",
...formatSection(theme, "Context", contextItems),
...formatSection(theme, "Profile", profileItems),
...formatSection(theme, "Skill", skillItems),
...formatSection(theme, "Prompts", promptItems),
...formatSection(theme, "Extension", extensionItems),
...formatSection(theme, "Theme", themeItems),
];
},
invalidate() {},
}));
ctx.ui.setWidget(WIDGET_ID, [
"Start here:",
'- Say: Analyze "episode-006-draft.mp4" as ep006',
"- Optional: copy podguy.example.toml to podguy.toml and set show_name/hosts/tone",
"- If your ask is broad, pi should clarify: quick pass or full review?",
"- Quick pass = optional scan + transcript + prep + short summary",
"- Full review = quick pass + chapters + clips + cuts + notes + quotes + cleanup",
"- Cut social exports after clips exist: /cut-clips ep006",
"- Optional shortcuts: /phase1 ep006 | /full-review ep006 | /chapters ep006 | /cuts ep006 | /cut-clips ep006",
]);
});
pi.on("agent_start", async (_event, ctx) => {
if (!ctx.hasUI) return;
ctx.ui.setWidget(WIDGET_ID, undefined);
});
}