forked from bristena-op/opencode-session-handoff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.ts
More file actions
86 lines (76 loc) · 2.44 KB
/
prompt.ts
File metadata and controls
86 lines (76 loc) · 2.44 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
interface Todo {
content: string;
status: string;
}
interface Decision {
decision: string;
reason: string;
}
interface TriedFailed {
approach: string;
why_failed: string;
}
export interface HandoffArgs {
previousSessionId: string;
summary: string;
blocked: string;
modified_files: string[];
reference_files: string[];
decisions: Decision[];
tried_failed: TriedFailed[];
next_steps: string[];
user_prefs: string[];
todos?: Todo[];
goal?: string;
}
function buildBlockedSection(blocked: string): string[] {
if (!blocked || blocked === "none") return [];
return ["", "**Blocked:** " + blocked];
}
function buildTodosSection(todos: Todo[] | undefined): string[] {
if (!todos || todos.length === 0) return [];
const completed = todos.filter((t) => t.status === "completed").length;
const inProgress = todos.filter((t) => t.status === "in_progress");
const pending = todos.filter((t) => t.status === "pending");
const lines = ["", `**Todos:** ${completed}/${todos.length} done`];
if (inProgress.length > 0) {
lines.push(`- In progress: ${inProgress.map((t) => t.content).join(", ")}`);
}
if (pending.length > 0) {
lines.push(`- Pending: ${pending.map((t) => t.content).join(", ")}`);
}
return lines;
}
function buildFilesSection(modified: string[]): string[] {
if (modified.length === 0) return [];
return ["", `**Files:** ${modified.join(", ")}`];
}
function buildDecisionsSection(decisions: Decision[]): string[] {
if (decisions.length === 0) return [];
const items = decisions.map((d) => (d.reason ? `${d.decision} (${d.reason})` : d.decision));
return ["", `**Decisions:** ${items.join("; ")}`];
}
function buildNextStepsSection(steps: string[]): string[] {
if (steps.length === 0) return [];
return ["", "**Next:** " + steps.map((s, i) => `${i + 1}. ${s}`).join(" ")];
}
function buildGoalSection(goal: string | undefined): string[] {
if (!goal) return [];
return ["", `**Goal:** ${goal}`];
}
export function buildHandoffPrompt(args: HandoffArgs): string {
return [
"## Session Handoff",
"",
args.summary,
...buildGoalSection(args.goal),
...buildBlockedSection(args.blocked),
...buildTodosSection(args.todos),
...buildFilesSection(args.modified_files),
...buildDecisionsSection(args.decisions),
...buildNextStepsSection(args.next_steps),
"",
`---`,
`Previous: \`${args.previousSessionId}\` · Use \`read_session\` if you need more context.`,
].join("\n");
}