pantheon-opencode 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.global.md +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +33 -0
- package/README.md +8 -5
- package/README.pt-BR.md +8 -5
- package/commands/pantheon-deepwork.md +11 -2
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/prompts/orchestrate-with-zeus.prompt.md +2 -0
- package/pyproject.toml +1 -1
- package/scripts/cost.mjs +4 -5
- package/src/agents/athena.md +1 -0
- package/src/agents/themis.md +1 -0
- package/src/agents/zeus.md +29 -2
- package/src/mcp/pantheon_vision.py +33 -2
- package/src/pantheon/cost-command.ts +4 -1
- package/src/pantheon/deepwork/deepwork-tool.ts +370 -0
- package/src/pantheon/deepwork/plan-projection.ts +274 -0
- package/src/pantheon/deepwork/plan-schema.ts +93 -0
- package/src/pantheon/deepwork/plan-tracker.ts +336 -0
- package/src/pantheon/native-vision.ts +3 -1
- package/src/pantheon/skill-search-tool.ts +2 -2
- package/src/pantheon/tools.ts +2 -0
- package/src/plugin/index.js +919 -39
- package/src/plugins/tui/dist/tui.js +461 -289
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/autonomy-state.ts +14 -16
- package/src/plugins/tui/src/decision-router-state.ts +22 -10
- package/src/plugins/tui/src/pantheon-settings-state.ts +119 -35
- package/src/plugins/tui/src/pantheon-settings.tsx +142 -48
- package/src/plugins/tui/src/preset-state.ts +96 -6
- package/src/plugins/tui/src/update-status.ts +62 -22
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deepwork-tool.ts — OpenCode V2 tool for Pantheon Deepwork.
|
|
3
|
+
*
|
|
4
|
+
* Implements canonical JSON-driven plan tracking, DAG generation,
|
|
5
|
+
* fail-first acceptance verification, and native OpenCode gates.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import type { ToolContextLike } from '../tool-context.ts'
|
|
10
|
+
import type { V2ToolDef, V2ToolResult } from '../tools.ts'
|
|
11
|
+
import {
|
|
12
|
+
buildApprovalQuestion,
|
|
13
|
+
generateChatProjection,
|
|
14
|
+
generateMermaidDag,
|
|
15
|
+
} from './plan-projection.ts'
|
|
16
|
+
import {
|
|
17
|
+
appendJournal,
|
|
18
|
+
computeTaskReadiness,
|
|
19
|
+
deepworkPlanJsonPath,
|
|
20
|
+
deepworkPlanMdPath,
|
|
21
|
+
listPlans,
|
|
22
|
+
readPlan,
|
|
23
|
+
resolvePlanDecision,
|
|
24
|
+
updateTaskState,
|
|
25
|
+
verifyTaskAcceptance,
|
|
26
|
+
writePlan,
|
|
27
|
+
} from './plan-tracker.ts'
|
|
28
|
+
|
|
29
|
+
const DeepworkToolInputSchema = z.object({
|
|
30
|
+
action: z
|
|
31
|
+
.enum([
|
|
32
|
+
'init',
|
|
33
|
+
'status',
|
|
34
|
+
'update_task',
|
|
35
|
+
'verify_acceptance',
|
|
36
|
+
'resolve_decision',
|
|
37
|
+
'list',
|
|
38
|
+
'get_approval_question',
|
|
39
|
+
])
|
|
40
|
+
.default('list'),
|
|
41
|
+
slug: z.string().optional(),
|
|
42
|
+
title: z.string().optional(),
|
|
43
|
+
intent: z.string().optional(),
|
|
44
|
+
tasks: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
45
|
+
decisions: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
46
|
+
done_when: z.array(z.string()).optional(),
|
|
47
|
+
taskId: z.string().optional(),
|
|
48
|
+
state: z.enum(['pending', 'ready', 'in_progress', 'done', 'failed', 'blocked']).optional(),
|
|
49
|
+
checkIndex: z.number().int().min(0).optional(),
|
|
50
|
+
verified: z.boolean().optional(),
|
|
51
|
+
proof: z.string().optional(),
|
|
52
|
+
decisionId: z.string().optional(),
|
|
53
|
+
choice: z.string().optional(),
|
|
54
|
+
summary: z.string().optional(),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export type DeepworkToolInput = z.infer<typeof DeepworkToolInputSchema>
|
|
58
|
+
|
|
59
|
+
export function createDeepworkTool(cwd = process.cwd()): V2ToolDef {
|
|
60
|
+
return {
|
|
61
|
+
name: 'pantheon_deepwork',
|
|
62
|
+
description:
|
|
63
|
+
'Manage canonical Deepwork plans (.pantheon/deepwork/<slug>/plan.json, journal.ndjson, PLAN.md). Track DAG dependencies, update task states, record fail-first verification receipts, and inspect compact chat projections.',
|
|
64
|
+
input: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
action: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
enum: [
|
|
70
|
+
'init',
|
|
71
|
+
'status',
|
|
72
|
+
'update_task',
|
|
73
|
+
'verify_acceptance',
|
|
74
|
+
'resolve_decision',
|
|
75
|
+
'list',
|
|
76
|
+
'get_approval_question',
|
|
77
|
+
],
|
|
78
|
+
description: 'The Deepwork plan management action to perform.',
|
|
79
|
+
},
|
|
80
|
+
slug: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'Unique plan slug / directory name (e.g. auth-jwt, dashboard-ui).',
|
|
83
|
+
},
|
|
84
|
+
title: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'Human-readable title of the deepwork plan (for init).',
|
|
87
|
+
},
|
|
88
|
+
intent: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'The intent, problem description, and objectives (for init).',
|
|
91
|
+
},
|
|
92
|
+
tasks: {
|
|
93
|
+
type: 'array',
|
|
94
|
+
description: 'List of structured tasks with acceptance criteria (for init).',
|
|
95
|
+
},
|
|
96
|
+
decisions: {
|
|
97
|
+
type: 'array',
|
|
98
|
+
description: 'List of required architectural decisions (for init).',
|
|
99
|
+
},
|
|
100
|
+
done_when: {
|
|
101
|
+
type: 'array',
|
|
102
|
+
description: 'List of done criteria strings (for init).',
|
|
103
|
+
},
|
|
104
|
+
taskId: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: 'Target task ID (e.g. T01, T02) for updates or verification.',
|
|
107
|
+
},
|
|
108
|
+
state: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
enum: ['pending', 'ready', 'in_progress', 'done', 'failed', 'blocked'],
|
|
111
|
+
description: 'New state for the specified task.',
|
|
112
|
+
},
|
|
113
|
+
checkIndex: {
|
|
114
|
+
type: 'number',
|
|
115
|
+
description: 'Zero-based index of the acceptance criterion to verify.',
|
|
116
|
+
},
|
|
117
|
+
verified: {
|
|
118
|
+
type: 'boolean',
|
|
119
|
+
description: 'Whether the acceptance criterion check passed.',
|
|
120
|
+
},
|
|
121
|
+
proof: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
description: 'Evidence snippet, command output, or test receipt.',
|
|
124
|
+
},
|
|
125
|
+
decisionId: {
|
|
126
|
+
type: 'string',
|
|
127
|
+
description: 'Target decision ID (e.g. D01) for resolution.',
|
|
128
|
+
},
|
|
129
|
+
choice: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
description: 'The chosen option for the decision.',
|
|
132
|
+
},
|
|
133
|
+
summary: {
|
|
134
|
+
type: 'string',
|
|
135
|
+
description: 'Summary of results or deliverable for a completed task.',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
required: [],
|
|
139
|
+
},
|
|
140
|
+
output: {},
|
|
141
|
+
async execute(input: Record<string, unknown>, context: unknown): Promise<V2ToolResult> {
|
|
142
|
+
const parsed = DeepworkToolInputSchema.parse(input)
|
|
143
|
+
const effectiveCwd =
|
|
144
|
+
typeof (context as ToolContextLike)?.directory === 'string'
|
|
145
|
+
? (context as ToolContextLike).directory
|
|
146
|
+
: cwd
|
|
147
|
+
|
|
148
|
+
if (parsed.action === 'list') {
|
|
149
|
+
const plans = await listPlans(effectiveCwd)
|
|
150
|
+
if (plans.length === 0) {
|
|
151
|
+
return {
|
|
152
|
+
output: 'Nenhum plano de Deepwork encontrado em .pantheon/deepwork/.',
|
|
153
|
+
title: 'Deepwork: List',
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const lines = [
|
|
157
|
+
'### Planos de Deepwork Disponíveis:',
|
|
158
|
+
'| Slug | Título | Progresso | Atualizado em |',
|
|
159
|
+
'|---|---|---|---|',
|
|
160
|
+
]
|
|
161
|
+
for (const p of plans) {
|
|
162
|
+
lines.push(
|
|
163
|
+
`| \`${p.slug}\` | ${p.title} | ${p.done_count}/${p.tasks_count} tarefas | ${p.updated_at} |`,
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
output: lines.join('\n'),
|
|
168
|
+
title: 'Deepwork: List',
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const slug = parsed.slug?.trim()
|
|
173
|
+
if (!slug) {
|
|
174
|
+
throw new Error(`O parâmetro 'slug' é obrigatório para a ação '${parsed.action}'.`)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (parsed.action === 'init') {
|
|
178
|
+
const title = parsed.title?.trim() || slug
|
|
179
|
+
const intent = parsed.intent?.trim() || 'Plano de deepwork estruturado.'
|
|
180
|
+
const rawTasks = parsed.tasks ?? []
|
|
181
|
+
const rawDecisions = parsed.decisions ?? []
|
|
182
|
+
const doneWhen = parsed.done_when ?? []
|
|
183
|
+
|
|
184
|
+
const tasks = rawTasks.map((t, idx) => ({
|
|
185
|
+
id: typeof t.id === 'string' ? t.id : `T${String(idx + 1).padStart(2, '0')}`,
|
|
186
|
+
title: typeof t.title === 'string' ? t.title : `Task ${idx + 1}`,
|
|
187
|
+
description: typeof t.description === 'string' ? t.description : undefined,
|
|
188
|
+
agent: typeof t.agent === 'string' ? t.agent : 'zeus',
|
|
189
|
+
phase: typeof t.phase === 'number' ? t.phase : 1,
|
|
190
|
+
state: (typeof t.state === 'string' ? t.state : 'pending') as
|
|
191
|
+
| 'pending'
|
|
192
|
+
| 'ready'
|
|
193
|
+
| 'in_progress'
|
|
194
|
+
| 'done'
|
|
195
|
+
| 'failed'
|
|
196
|
+
| 'blocked',
|
|
197
|
+
depends_on: Array.isArray(t.depends_on) ? (t.depends_on as string[]) : [],
|
|
198
|
+
parallel_safe: Boolean(t.parallel_safe),
|
|
199
|
+
acceptance: Array.isArray(t.acceptance)
|
|
200
|
+
? (
|
|
201
|
+
t.acceptance as Array<{
|
|
202
|
+
kind: 'test' | 'command' | 'file' | 'manual'
|
|
203
|
+
check: string
|
|
204
|
+
fails_now?: boolean
|
|
205
|
+
verified?: boolean
|
|
206
|
+
proof?: string
|
|
207
|
+
}>
|
|
208
|
+
).map((a) => ({
|
|
209
|
+
kind: a.kind || 'command',
|
|
210
|
+
check: a.check || 'verify',
|
|
211
|
+
fails_now: a.fails_now ?? true,
|
|
212
|
+
verified: a.verified ?? false,
|
|
213
|
+
proof: a.proof,
|
|
214
|
+
}))
|
|
215
|
+
: [],
|
|
216
|
+
}))
|
|
217
|
+
|
|
218
|
+
const decisions = rawDecisions.map((d, idx) => ({
|
|
219
|
+
id: typeof d.id === 'string' ? d.id : `D${String(idx + 1).padStart(2, '0')}`,
|
|
220
|
+
question: typeof d.question === 'string' ? d.question : 'Decisão necessária',
|
|
221
|
+
options: Array.isArray(d.options) ? (d.options as string[]) : ['Sim', 'Não'],
|
|
222
|
+
chosen: typeof d.chosen === 'string' ? d.chosen : undefined,
|
|
223
|
+
status: (d.chosen ? 'resolved' : 'pending') as 'pending' | 'resolved',
|
|
224
|
+
}))
|
|
225
|
+
|
|
226
|
+
const initialPlan = computeTaskReadiness({
|
|
227
|
+
plan_id: slug,
|
|
228
|
+
title,
|
|
229
|
+
intent,
|
|
230
|
+
done_when: doneWhen,
|
|
231
|
+
decisions_needed: decisions,
|
|
232
|
+
risks: [],
|
|
233
|
+
out_of_scope: [],
|
|
234
|
+
tasks,
|
|
235
|
+
metadata: {
|
|
236
|
+
created_at: new Date().toISOString(),
|
|
237
|
+
updated_at: new Date().toISOString(),
|
|
238
|
+
version: 1,
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
await writePlan(effectiveCwd, initialPlan)
|
|
243
|
+
await appendJournal(effectiveCwd, slug, {
|
|
244
|
+
type: 'plan_created',
|
|
245
|
+
timestamp: new Date().toISOString(),
|
|
246
|
+
payload: { slug, title, tasks_count: tasks.length },
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
const projection = generateChatProjection(initialPlan, effectiveCwd)
|
|
250
|
+
const approvalQ = buildApprovalQuestion(initialPlan)
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
output: [
|
|
254
|
+
`✅ Plano de Deepwork '${title}' inicializado com sucesso em \`.pantheon/deepwork/${slug}/\`!`,
|
|
255
|
+
`- 🔗 **Deeplink PLAN.md:** [Abrir PLAN.md](file://${deepworkPlanMdPath(effectiveCwd, slug)})`,
|
|
256
|
+
`- 🔗 **Deeplink plan.json:** [Abrir plan.json](file://${deepworkPlanJsonPath(effectiveCwd, slug)})`,
|
|
257
|
+
'',
|
|
258
|
+
projection,
|
|
259
|
+
'',
|
|
260
|
+
'**Pergunta de Aprovação Nativa (Gate 1):**',
|
|
261
|
+
`\`${JSON.stringify(approvalQ)}\``,
|
|
262
|
+
].join('\n'),
|
|
263
|
+
title: `Deepwork Init: ${slug}`,
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const currentPlan = await readPlan(effectiveCwd, slug)
|
|
268
|
+
if (!currentPlan) {
|
|
269
|
+
throw new Error(`Plano de Deepwork '${slug}' não encontrado.`)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (parsed.action === 'status') {
|
|
273
|
+
const projection = generateChatProjection(currentPlan, effectiveCwd)
|
|
274
|
+
const dag = generateMermaidDag(currentPlan)
|
|
275
|
+
return {
|
|
276
|
+
output: [projection, '', '#### Grafo de Dependências (DAG):', dag].join('\n'),
|
|
277
|
+
title: `Deepwork Status: ${slug}`,
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (parsed.action === 'get_approval_question') {
|
|
282
|
+
const q = buildApprovalQuestion(currentPlan)
|
|
283
|
+
return {
|
|
284
|
+
output: JSON.stringify(q, null, 2),
|
|
285
|
+
title: `Deepwork Approval Question: ${slug}`,
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (parsed.action === 'update_task') {
|
|
290
|
+
if (!parsed.taskId) throw new Error("Parâmetro 'taskId' obrigatório para update_task.")
|
|
291
|
+
if (!parsed.state) throw new Error("Parâmetro 'state' obrigatório para update_task.")
|
|
292
|
+
|
|
293
|
+
const resultMeta: { summary?: string } = {}
|
|
294
|
+
if (parsed.summary !== undefined) {
|
|
295
|
+
resultMeta.summary = parsed.summary
|
|
296
|
+
}
|
|
297
|
+
const updated = await updateTaskState(
|
|
298
|
+
effectiveCwd,
|
|
299
|
+
slug,
|
|
300
|
+
parsed.taskId,
|
|
301
|
+
parsed.state,
|
|
302
|
+
resultMeta,
|
|
303
|
+
)
|
|
304
|
+
const projection = generateChatProjection(updated, effectiveCwd)
|
|
305
|
+
return {
|
|
306
|
+
output: [
|
|
307
|
+
`Tarefa **[${parsed.taskId}]** atualizada para \`${parsed.state}\`.`,
|
|
308
|
+
'',
|
|
309
|
+
projection,
|
|
310
|
+
].join('\n'),
|
|
311
|
+
title: `Deepwork Task: ${parsed.taskId} -> ${parsed.state}`,
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (parsed.action === 'verify_acceptance') {
|
|
316
|
+
if (!parsed.taskId)
|
|
317
|
+
throw new Error("Parâmetro 'taskId' obrigatório para verify_acceptance.")
|
|
318
|
+
if (parsed.checkIndex === undefined)
|
|
319
|
+
throw new Error("Parâmetro 'checkIndex' obrigatório para verify_acceptance.")
|
|
320
|
+
if (parsed.verified === undefined)
|
|
321
|
+
throw new Error("Parâmetro 'verified' obrigatório para verify_acceptance.")
|
|
322
|
+
|
|
323
|
+
const updated = await verifyTaskAcceptance(
|
|
324
|
+
effectiveCwd,
|
|
325
|
+
slug,
|
|
326
|
+
parsed.taskId,
|
|
327
|
+
parsed.checkIndex,
|
|
328
|
+
parsed.verified,
|
|
329
|
+
parsed.proof,
|
|
330
|
+
)
|
|
331
|
+
const projection = generateChatProjection(updated, effectiveCwd)
|
|
332
|
+
return {
|
|
333
|
+
output: [
|
|
334
|
+
`Critério de aceite #${parsed.checkIndex} da tarefa **[${parsed.taskId}]** verificado: ${parsed.verified ? '✅ PASS' : '❌ FAIL'}.`,
|
|
335
|
+
parsed.proof ? `*Evidência/Receipt:* \`${parsed.proof}\`` : '',
|
|
336
|
+
'',
|
|
337
|
+
projection,
|
|
338
|
+
]
|
|
339
|
+
.filter(Boolean)
|
|
340
|
+
.join('\n'),
|
|
341
|
+
title: `Deepwork Verify: ${parsed.taskId} [${parsed.checkIndex}]`,
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (parsed.action === 'resolve_decision') {
|
|
346
|
+
if (!parsed.decisionId)
|
|
347
|
+
throw new Error("Parâmetro 'decisionId' obrigatório para resolve_decision.")
|
|
348
|
+
if (!parsed.choice) throw new Error("Parâmetro 'choice' obrigatório para resolve_decision.")
|
|
349
|
+
|
|
350
|
+
const updated = await resolvePlanDecision(
|
|
351
|
+
effectiveCwd,
|
|
352
|
+
slug,
|
|
353
|
+
parsed.decisionId,
|
|
354
|
+
parsed.choice,
|
|
355
|
+
)
|
|
356
|
+
const projection = generateChatProjection(updated, effectiveCwd)
|
|
357
|
+
return {
|
|
358
|
+
output: [
|
|
359
|
+
`Decisão **[${parsed.decisionId}]** resolvida com a opção: "${parsed.choice}".`,
|
|
360
|
+
'',
|
|
361
|
+
projection,
|
|
362
|
+
].join('\n'),
|
|
363
|
+
title: `Deepwork Decision: ${parsed.decisionId}`,
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
throw new Error(`Ação '${parsed.action}' não reconhecida.`)
|
|
368
|
+
},
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* plan-projection.ts — Generates projections from canonical Deepwork JSON plans.
|
|
3
|
+
*
|
|
4
|
+
* Rules:
|
|
5
|
+
* - JSON is truth, Markdown is projection.
|
|
6
|
+
* - STRICTLY NO HTML. Everything renders natively in OpenCode Desktop & TUI.
|
|
7
|
+
* - Native OpenCode `question` tool formats for approval and decisions.
|
|
8
|
+
* - DAG representation using Mermaid.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { join } from 'node:path'
|
|
12
|
+
import type { DeepworkPlan, PlanDecision } from './plan-schema.ts'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generate a compact status projection for chat (<= 15 lines).
|
|
16
|
+
* Puts "Needs you" (decisions) first, followed by Next task, Blocked, and Progress.
|
|
17
|
+
* Includes direct clickable deeplinks (file://) to open the complete PLAN.md and plan.json.
|
|
18
|
+
*/
|
|
19
|
+
export function generateChatProjection(plan: DeepworkPlan, cwd = process.cwd()): string {
|
|
20
|
+
const pendingDecisions = plan.decisions_needed.filter((d) => d.status === 'pending')
|
|
21
|
+
const totalTasks = plan.tasks.length
|
|
22
|
+
const doneTasks = plan.tasks.filter((t) => t.state === 'done').length
|
|
23
|
+
const inProgressTasks = plan.tasks.filter((t) => t.state === 'in_progress')
|
|
24
|
+
const blockedTasks = plan.tasks.filter((t) => t.state === 'blocked')
|
|
25
|
+
const readyTasks = plan.tasks.filter((t) => t.state === 'ready')
|
|
26
|
+
|
|
27
|
+
const nextTask =
|
|
28
|
+
inProgressTasks[0] || readyTasks[0] || plan.tasks.find((t) => t.state === 'pending')
|
|
29
|
+
|
|
30
|
+
const percent = totalTasks > 0 ? Math.round((doneTasks / totalTasks) * 100) : 0
|
|
31
|
+
|
|
32
|
+
const absPlanMd = join(cwd, '.pantheon', 'deepwork', plan.plan_id, 'PLAN.md')
|
|
33
|
+
const absPlanJson = join(cwd, '.pantheon', 'deepwork', plan.plan_id, 'plan.json')
|
|
34
|
+
|
|
35
|
+
const lines: string[] = []
|
|
36
|
+
lines.push(`### Deepwork: ${plan.title} (\`${plan.plan_id}\`)`)
|
|
37
|
+
lines.push(
|
|
38
|
+
`🔗 **Deeplink:** [Abrir PLAN.md](file://${absPlanMd}) · [plan.json](file://${absPlanJson})`,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
if (pendingDecisions.length > 0) {
|
|
42
|
+
lines.push(`🔴 **Decisões necessárias (${pendingDecisions.length})**:`)
|
|
43
|
+
for (const dec of pendingDecisions.slice(0, 3)) {
|
|
44
|
+
lines.push(`- **[${dec.id}]** ${dec.question}`)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (nextTask) {
|
|
49
|
+
lines.push(
|
|
50
|
+
`🎯 **Próxima tarefa**: **[${nextTask.id}]** ${nextTask.title} (@${nextTask.agent} · Fase ${nextTask.phase})`,
|
|
51
|
+
)
|
|
52
|
+
} else if (doneTasks === totalTasks && totalTasks > 0) {
|
|
53
|
+
lines.push('🎉 **Todas as tarefas foram concluídas!**')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (blockedTasks.length > 0) {
|
|
57
|
+
lines.push(`🟡 **Bloqueadas**: ${blockedTasks.length} tarefa(s) aguardando dependências`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
lines.push(
|
|
61
|
+
`🟢 **Progresso**: ${doneTasks}/${totalTasks} concluída(s) (${percent}%)` +
|
|
62
|
+
(inProgressTasks.length > 0 ? ` · ${inProgressTasks.length} em andamento` : ''),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return lines.join('\n')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Generate a Mermaid dependency DAG (`flowchart LR`) with state-based styling.
|
|
70
|
+
*/
|
|
71
|
+
export function generateMermaidDag(plan: DeepworkPlan): string {
|
|
72
|
+
if (plan.tasks.length === 0) {
|
|
73
|
+
return '```mermaid\nflowchart LR\n empty["(Sem tarefas no plano)"]\n```'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const lines: string[] = ['```mermaid', 'flowchart LR']
|
|
77
|
+
|
|
78
|
+
// Nodes definition
|
|
79
|
+
for (const task of plan.tasks) {
|
|
80
|
+
const cleanTitle = task.title.replace(/["\\]/g, "'")
|
|
81
|
+
lines.push(` ${task.id}["[${task.id}] ${cleanTitle}"]`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Edges definition
|
|
85
|
+
let hasEdges = false
|
|
86
|
+
for (const task of plan.tasks) {
|
|
87
|
+
for (const depId of task.depends_on) {
|
|
88
|
+
if (plan.tasks.some((t) => t.id === depId)) {
|
|
89
|
+
lines.push(` ${depId} --> ${task.id}`)
|
|
90
|
+
hasEdges = true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// If no dependencies specified, link sequentially across phases for readable visual flow
|
|
96
|
+
if (!hasEdges && plan.tasks.length > 1) {
|
|
97
|
+
for (let i = 0; i < plan.tasks.length - 1; i++) {
|
|
98
|
+
const current = plan.tasks[i]
|
|
99
|
+
const next = plan.tasks[i + 1]
|
|
100
|
+
if (current && next) {
|
|
101
|
+
lines.push(` ${current.id} -.-> ${next.id}`)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Classes styling
|
|
107
|
+
lines.push(' classDef done fill:#22c55e,stroke:#15803d,color:#ffffff;')
|
|
108
|
+
lines.push(' classDef in_progress fill:#3b82f6,stroke:#1d4ed8,color:#ffffff;')
|
|
109
|
+
lines.push(' classDef blocked fill:#eab308,stroke:#a16207,color:#000000;')
|
|
110
|
+
lines.push(' classDef failed fill:#ef4444,stroke:#b91c1c,color:#ffffff;')
|
|
111
|
+
lines.push(' classDef ready fill:#64748b,stroke:#334155,color:#ffffff;')
|
|
112
|
+
|
|
113
|
+
const byState: Record<string, string[]> = {
|
|
114
|
+
done: [],
|
|
115
|
+
in_progress: [],
|
|
116
|
+
blocked: [],
|
|
117
|
+
failed: [],
|
|
118
|
+
ready: [],
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const task of plan.tasks) {
|
|
122
|
+
const stateList = byState[task.state]
|
|
123
|
+
if (stateList) {
|
|
124
|
+
stateList.push(task.id)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (const [state, ids] of Object.entries(byState)) {
|
|
129
|
+
if (ids.length > 0) {
|
|
130
|
+
lines.push(` class ${ids.join(',')} ${state};`)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
lines.push('```')
|
|
135
|
+
return lines.join('\n')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Generate full Markdown document for `PLAN.md`.
|
|
140
|
+
* Strictly zero HTML. Renders in Markdown viewers, Desktop, and TUI.
|
|
141
|
+
*/
|
|
142
|
+
export function generateMarkdownDocument(plan: DeepworkPlan): string {
|
|
143
|
+
const lines: string[] = []
|
|
144
|
+
|
|
145
|
+
lines.push(`# Deepwork: ${plan.title}`)
|
|
146
|
+
lines.push('')
|
|
147
|
+
lines.push(`> **ID do Plano:** \`${plan.plan_id}\` `)
|
|
148
|
+
lines.push(
|
|
149
|
+
`> **Criado em:** ${plan.metadata.created_at} · **Atualizado em:** ${plan.metadata.updated_at}`,
|
|
150
|
+
)
|
|
151
|
+
lines.push('')
|
|
152
|
+
|
|
153
|
+
lines.push('## 1. Intenção & Objetivos')
|
|
154
|
+
lines.push(plan.intent.trim())
|
|
155
|
+
lines.push('')
|
|
156
|
+
|
|
157
|
+
if (plan.done_when.length > 0) {
|
|
158
|
+
lines.push('## 2. Critérios de Conclusão (Done When)')
|
|
159
|
+
for (const item of plan.done_when) {
|
|
160
|
+
lines.push(`- [ ] ${item}`)
|
|
161
|
+
}
|
|
162
|
+
lines.push('')
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (plan.decisions_needed.length > 0) {
|
|
166
|
+
lines.push('## 3. Decisões do Plano (Needs You)')
|
|
167
|
+
lines.push('| ID | Pergunta | Status | Decisão Escolhida |')
|
|
168
|
+
lines.push('|---|---|---|---|')
|
|
169
|
+
for (const dec of plan.decisions_needed) {
|
|
170
|
+
const statusIcon = dec.status === 'resolved' ? '✅ Resolvida' : '🔴 Pendente'
|
|
171
|
+
const chosen = dec.chosen ?? '*(Aguardando decisão)*'
|
|
172
|
+
lines.push(`| \`${dec.id}\` | ${dec.question} | ${statusIcon} | ${chosen} |`)
|
|
173
|
+
}
|
|
174
|
+
lines.push('')
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
lines.push('## 4. Grafo de Dependências (DAG)')
|
|
178
|
+
lines.push(generateMermaidDag(plan))
|
|
179
|
+
lines.push('')
|
|
180
|
+
|
|
181
|
+
lines.push('## 5. Tarefas & Critérios de Aceite')
|
|
182
|
+
for (const task of plan.tasks) {
|
|
183
|
+
const stateIcon =
|
|
184
|
+
task.state === 'done'
|
|
185
|
+
? '✅'
|
|
186
|
+
: task.state === 'in_progress'
|
|
187
|
+
? '⏳'
|
|
188
|
+
: task.state === 'blocked'
|
|
189
|
+
? '🚫'
|
|
190
|
+
: task.state === 'failed'
|
|
191
|
+
? '❌'
|
|
192
|
+
: '📋'
|
|
193
|
+
lines.push(`### ${stateIcon} [${task.id}] ${task.title}`)
|
|
194
|
+
lines.push(
|
|
195
|
+
`- **Fase:** ${task.phase} | **Agente Responsável:** @${task.agent} | **Estado:** \`${task.state}\``,
|
|
196
|
+
)
|
|
197
|
+
if (task.depends_on.length > 0) {
|
|
198
|
+
lines.push(`- **Depende de:** ${task.depends_on.map((d) => `\`${d}\``).join(', ')}`)
|
|
199
|
+
}
|
|
200
|
+
if (task.parallel_safe) {
|
|
201
|
+
lines.push('- **Execução Paralela:** Isolado em worktree (`parallel_safe: true`)')
|
|
202
|
+
}
|
|
203
|
+
if (task.description) {
|
|
204
|
+
lines.push(`- **Descrição:** ${task.description}`)
|
|
205
|
+
}
|
|
206
|
+
if (task.acceptance.length > 0) {
|
|
207
|
+
lines.push('- **Critérios de Aceite (Fail-First):**')
|
|
208
|
+
for (const acc of task.acceptance) {
|
|
209
|
+
const mark = acc.verified ? '[x]' : '[ ]'
|
|
210
|
+
const failFirst = acc.fails_now ? ' *(falha antes da implementação)*' : ''
|
|
211
|
+
lines.push(` - ${mark} \`${acc.kind}\`: ${acc.check}${failFirst}`)
|
|
212
|
+
if (acc.proof) {
|
|
213
|
+
lines.push(` - *Evidência/Receipt:* \`${acc.proof}\``)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (task.result?.summary) {
|
|
218
|
+
lines.push(`- **Resultado:** ${task.result.summary}`)
|
|
219
|
+
}
|
|
220
|
+
lines.push('')
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (plan.risks.length > 0) {
|
|
224
|
+
lines.push('## 6. Riscos & Mitigações')
|
|
225
|
+
for (const r of plan.risks) {
|
|
226
|
+
lines.push(`- **${r.id}:** ${r.description}`)
|
|
227
|
+
if (r.mitigation) lines.push(` - *Mitigação:* ${r.mitigation}`)
|
|
228
|
+
}
|
|
229
|
+
lines.push('')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (plan.out_of_scope.length > 0) {
|
|
233
|
+
lines.push('## 7. Fora de Escopo')
|
|
234
|
+
for (const item of plan.out_of_scope) {
|
|
235
|
+
lines.push(`- ${item}`)
|
|
236
|
+
}
|
|
237
|
+
lines.push('')
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return lines.join('\n')
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Build parameters for the native OpenCode `question` tool for Gate 1 approval.
|
|
245
|
+
*/
|
|
246
|
+
export function buildApprovalQuestion(plan: DeepworkPlan): {
|
|
247
|
+
question: string
|
|
248
|
+
options: string[]
|
|
249
|
+
} {
|
|
250
|
+
return {
|
|
251
|
+
question: `Deseja aprovar o plano de Deepwork "${plan.title}" (${plan.tasks.length} tarefas)?`,
|
|
252
|
+
options: [
|
|
253
|
+
'(Recomendado) Aprovar e iniciar execução (Fase 1)',
|
|
254
|
+
'Solicitar ajustes ou refinar tarefas',
|
|
255
|
+
'Rejeitar / Cancelar plano',
|
|
256
|
+
],
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Build parameters for the native OpenCode `question` tool for a pending decision.
|
|
262
|
+
*/
|
|
263
|
+
export function buildDecisionQuestion(decision: PlanDecision): {
|
|
264
|
+
question: string
|
|
265
|
+
options: string[]
|
|
266
|
+
} {
|
|
267
|
+
const options = decision.options.map((opt, index) =>
|
|
268
|
+
index === 0 && !opt.startsWith('(') ? `(Recomendado) ${opt}` : opt,
|
|
269
|
+
)
|
|
270
|
+
return {
|
|
271
|
+
question: `Decisão necessária [${decision.id}]: ${decision.question}`,
|
|
272
|
+
options,
|
|
273
|
+
}
|
|
274
|
+
}
|