TIA / guided.ts
DJ-Goanna-Coding's picture
Add TIA backend
a3aed04 verified
/**
* TIA-∞ Guided Builder Interface
* Converts resurrection and drift data into human-readable prompts.
* Allows TIA to ask for approval before taking any action.
*/
import { ResurrectionPlan, ResurrectionProposal } from "./resurrection";
import { DriftReport, DriftIssue } from "./drift";
export interface BuilderPrompt {
id: string;
path: string;
issue: string;
recommendation: string;
type: "resurrection" | "drift";
}
export interface BuilderQueue {
generatedAt: number;
prompts: BuilderPrompt[];
}
function convertResurrection(proposal: ResurrectionProposal, index: number): BuilderPrompt {
return {
id: `res-${index}`,
path: proposal.path,
issue: proposal.issue,
recommendation: proposal.recommendedAction,
type: "resurrection",
};
}
function convertDrift(issue: DriftIssue, index: number): BuilderPrompt {
return {
id: `drift-${index}`,
path: issue.path,
issue: issue.type,
recommendation: issue.description,
type: "drift",
};
}
export function buildGuidedQueue(
resurrection: ResurrectionPlan,
drift: DriftReport
): BuilderQueue {
const prompts: BuilderPrompt[] = [];
resurrection.proposals.forEach((p, i) =>
prompts.push(convertResurrection(p, i))
);
drift.issues.forEach((d, i) =>
prompts.push(convertDrift(d, i))
);
return {
generatedAt: Date.now(),
prompts,
};
}
export function formatPrompt(prompt: BuilderPrompt): string {
return `
Issue detected:
- Path: ${prompt.path}
- Type: ${prompt.type}
- Problem: ${prompt.issue}
- Recommendation: ${prompt.recommendation}
Would you like me to proceed?
(approve / decline / defer)
`.trim();
}