File size: 1,666 Bytes
a3aed04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * 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();
}