Vendor all 4 Pi packages (tui, ai, agent-core, coding-agent) from pi-mono v0.57.1 as @gsd/* workspace packages under packages/. This replaces the compiled npm dependency (@mariozechner/pi-coding-agent) and patch-package workflow, giving direct source access for modifications. - Copy Pi source from pi-mono v0.57.1 into packages/ - Create workspace package.json + tsconfig.json for each package - Rename ~240 imports from @mariozechner/pi-* to @gsd/pi-* - Apply existing patches as source edits (setModel persist, VT input) - Remove @mariozechner/pi-coding-agent dep and patch-package - Update build pipeline to build packages in dependency order - Add pi-upstream git remote for future selective syncing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { parse } from "yaml";
|
|
|
|
type ParsedFrontmatter<T extends Record<string, unknown>> = {
|
|
frontmatter: T;
|
|
body: string;
|
|
};
|
|
|
|
const normalizeNewlines = (value: string): string => value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
|
|
const extractFrontmatter = (content: string): { yamlString: string | null; body: string } => {
|
|
const normalized = normalizeNewlines(content);
|
|
|
|
if (!normalized.startsWith("---")) {
|
|
return { yamlString: null, body: normalized };
|
|
}
|
|
|
|
const endIndex = normalized.indexOf("\n---", 3);
|
|
if (endIndex === -1) {
|
|
return { yamlString: null, body: normalized };
|
|
}
|
|
|
|
return {
|
|
yamlString: normalized.slice(4, endIndex),
|
|
body: normalized.slice(endIndex + 4).trim(),
|
|
};
|
|
};
|
|
|
|
export const parseFrontmatter = <T extends Record<string, unknown> = Record<string, unknown>>(
|
|
content: string,
|
|
): ParsedFrontmatter<T> => {
|
|
const { yamlString, body } = extractFrontmatter(content);
|
|
if (!yamlString) {
|
|
return { frontmatter: {} as T, body };
|
|
}
|
|
const parsed = parse(yamlString);
|
|
return { frontmatter: (parsed ?? {}) as T, body };
|
|
};
|
|
|
|
export const stripFrontmatter = (content: string): string => parseFrontmatter(content).body;
|