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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * plan-schema.ts — Canonical schema for Pantheon Deepwork Plans.
3
+ *
4
+ * Principle: JSON is the ground truth, Markdown is the projection.
5
+ * Strictly avoids HTML; uses structured contracts and native OpenCode gates.
6
+ */
7
+
8
+ import { z } from 'zod'
9
+
10
+ export const PlanAcceptanceKindSchema = z.enum(['test', 'command', 'file', 'manual'])
11
+ export type PlanAcceptanceKind = z.infer<typeof PlanAcceptanceKindSchema>
12
+
13
+ export const PlanAcceptanceCriterionSchema = z.object({
14
+ kind: PlanAcceptanceKindSchema,
15
+ check: z.string().min(1),
16
+ fails_now: z.boolean().default(true),
17
+ verified: z.boolean().default(false),
18
+ proof: z.string().optional(),
19
+ })
20
+ export type PlanAcceptanceCriterion = z.infer<typeof PlanAcceptanceCriterionSchema>
21
+
22
+ export const TaskStateSchema = z.enum([
23
+ 'pending',
24
+ 'ready',
25
+ 'in_progress',
26
+ 'done',
27
+ 'failed',
28
+ 'blocked',
29
+ ])
30
+ export type TaskState = z.infer<typeof TaskStateSchema>
31
+
32
+ export const PlanTaskSchema = z.object({
33
+ id: z.string().min(1),
34
+ title: z.string().min(1),
35
+ description: z.string().optional(),
36
+ agent: z.string().default('zeus'),
37
+ phase: z.number().int().min(0).default(1),
38
+ state: TaskStateSchema.default('pending'),
39
+ depends_on: z.array(z.string()).default([]),
40
+ parallel_safe: z.boolean().default(false),
41
+ acceptance: z.array(PlanAcceptanceCriterionSchema).default([]),
42
+ result: z
43
+ .object({
44
+ summary: z.string().optional(),
45
+ verified_at: z.string().optional(),
46
+ artifacts: z.array(z.string()).optional(),
47
+ })
48
+ .optional(),
49
+ })
50
+ export type PlanTask = z.infer<typeof PlanTaskSchema>
51
+
52
+ export const DecisionStatusSchema = z.enum(['pending', 'resolved'])
53
+ export type DecisionStatus = z.infer<typeof DecisionStatusSchema>
54
+
55
+ export const PlanDecisionSchema = z.object({
56
+ id: z.string().min(1),
57
+ question: z.string().min(1),
58
+ options: z.array(z.string()).min(2),
59
+ chosen: z.string().optional(),
60
+ status: DecisionStatusSchema.default('pending'),
61
+ })
62
+ export type PlanDecision = z.infer<typeof PlanDecisionSchema>
63
+
64
+ export const PlanRiskSchema = z.object({
65
+ id: z.string().min(1),
66
+ description: z.string().min(1),
67
+ mitigation: z.string().optional(),
68
+ })
69
+ export type PlanRisk = z.infer<typeof PlanRiskSchema>
70
+
71
+ export const PlanMetadataSchema = z.object({
72
+ created_at: z.string(),
73
+ updated_at: z.string(),
74
+ version: z.number().int().default(1),
75
+ })
76
+ export type PlanMetadata = z.infer<typeof PlanMetadataSchema>
77
+
78
+ export const DeepworkPlanSchema = z.object({
79
+ plan_id: z.string().min(1),
80
+ title: z.string().min(1),
81
+ intent: z.string().min(1),
82
+ done_when: z.array(z.string()).default([]),
83
+ decisions_needed: z.array(PlanDecisionSchema).default([]),
84
+ risks: z.array(PlanRiskSchema).default([]),
85
+ out_of_scope: z.array(z.string()).default([]),
86
+ tasks: z.array(PlanTaskSchema).default([]),
87
+ metadata: PlanMetadataSchema,
88
+ })
89
+ export type DeepworkPlan = z.infer<typeof DeepworkPlanSchema>
90
+
91
+ export function validatePlan(data: unknown): DeepworkPlan {
92
+ return DeepworkPlanSchema.parse(data)
93
+ }
@@ -0,0 +1,336 @@
1
+ /**
2
+ * plan-tracker.ts — Storage and lifecycle tracking for Pantheon Deepwork.
3
+ *
4
+ * Persists canonical state in `.pantheon/deepwork/<slug>/plan.json`
5
+ * with append-only event logging in `.pantheon/deepwork/<slug>/journal.ndjson`.
6
+ * Synchronizes the Markdown projection in `.pantheon/deepwork/<slug>/PLAN.md`.
7
+ */
8
+
9
+ import { existsSync } from 'node:fs'
10
+ import { appendFile, mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises'
11
+ import { join } from 'node:path'
12
+ import { generateMarkdownDocument } from './plan-projection.ts'
13
+ import {
14
+ type DeepworkPlan,
15
+ DeepworkPlanSchema,
16
+ type PlanTask,
17
+ type TaskState,
18
+ } from './plan-schema.ts'
19
+
20
+ export interface JournalEvent {
21
+ type:
22
+ | 'plan_created'
23
+ | 'task_started'
24
+ | 'task_finished'
25
+ | 'task_failed'
26
+ | 'task_state_changed'
27
+ | 'decision_resolved'
28
+ | 'acceptance_verified'
29
+ | 'phase_completed'
30
+ timestamp: string
31
+ payload: Record<string, unknown>
32
+ }
33
+
34
+ export function deepworkRootDir(cwd = process.cwd()): string {
35
+ return join(cwd, '.pantheon', 'deepwork')
36
+ }
37
+
38
+ export function deepworkPlanDir(cwd = process.cwd(), slug: string): string {
39
+ return join(deepworkRootDir(cwd), slug)
40
+ }
41
+
42
+ export function deepworkPlanJsonPath(cwd = process.cwd(), slug: string): string {
43
+ return join(deepworkPlanDir(cwd, slug), 'plan.json')
44
+ }
45
+
46
+ export function deepworkPlanMdPath(cwd = process.cwd(), slug: string): string {
47
+ return join(deepworkPlanDir(cwd, slug), 'PLAN.md')
48
+ }
49
+
50
+ export function deepworkJournalPath(cwd = process.cwd(), slug: string): string {
51
+ return join(deepworkPlanDir(cwd, slug), 'journal.ndjson')
52
+ }
53
+
54
+ /**
55
+ * Recompute readiness of tasks according to dependency graph:
56
+ * - A task with depends_on whose dependencies are ALL 'done' becomes 'ready' if it was 'pending' or 'blocked'.
57
+ * - A task whose dependencies are NOT all 'done' becomes 'blocked' if it was 'pending' or 'ready'.
58
+ */
59
+ export function computeTaskReadiness(plan: DeepworkPlan): DeepworkPlan {
60
+ const doneIds = new Set(plan.tasks.filter((t) => t.state === 'done').map((t) => t.id))
61
+
62
+ const updatedTasks: PlanTask[] = plan.tasks.map((task) => {
63
+ if (task.state === 'done' || task.state === 'in_progress' || task.state === 'failed') {
64
+ return task
65
+ }
66
+
67
+ if (task.depends_on.length === 0) {
68
+ return task.state === 'blocked' ? { ...task, state: 'ready' } : task
69
+ }
70
+
71
+ const allDepsDone = task.depends_on.every((dep) => doneIds.has(dep))
72
+ if (allDepsDone && (task.state === 'pending' || task.state === 'blocked')) {
73
+ return { ...task, state: 'ready' }
74
+ }
75
+ if (!allDepsDone && (task.state === 'pending' || task.state === 'ready')) {
76
+ return { ...task, state: 'blocked' }
77
+ }
78
+ return task
79
+ })
80
+
81
+ return { ...plan, tasks: updatedTasks }
82
+ }
83
+
84
+ /**
85
+ * Read the canonical JSON plan. Returns null if absent or corrupt.
86
+ */
87
+ export async function readPlan(cwd = process.cwd(), slug: string): Promise<DeepworkPlan | null> {
88
+ const path = deepworkPlanJsonPath(cwd, slug)
89
+ try {
90
+ const raw = await readFile(path, 'utf8')
91
+ const parsed = JSON.parse(raw)
92
+ return DeepworkPlanSchema.parse(parsed)
93
+ } catch {
94
+ return null
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Write the canonical JSON plan atomically and update PLAN.md projection.
100
+ */
101
+ export async function writePlan(cwd = process.cwd(), plan: DeepworkPlan): Promise<void> {
102
+ const dir = deepworkPlanDir(cwd, plan.plan_id)
103
+ await mkdir(dir, { recursive: true })
104
+
105
+ const normalized = computeTaskReadiness({
106
+ ...plan,
107
+ metadata: {
108
+ ...plan.metadata,
109
+ updated_at: new Date().toISOString(),
110
+ version: (plan.metadata.version || 1) + 1,
111
+ },
112
+ })
113
+
114
+ // Atomic write for plan.json
115
+ const jsonPath = deepworkPlanJsonPath(cwd, plan.plan_id)
116
+ const jsonTmp = `${jsonPath}.tmp`
117
+ await writeFile(jsonTmp, `${JSON.stringify(normalized, null, 2)}\n`, 'utf8')
118
+ await rename(jsonTmp, jsonPath)
119
+
120
+ // Projection write for PLAN.md
121
+ const mdPath = deepworkPlanMdPath(cwd, plan.plan_id)
122
+ const mdContent = generateMarkdownDocument(normalized)
123
+ await writeFile(mdPath, mdContent, 'utf8')
124
+ }
125
+
126
+ /**
127
+ * Append an entry to the journal event log.
128
+ */
129
+ export async function appendJournal(
130
+ cwd = process.cwd(),
131
+ slug: string,
132
+ event: JournalEvent,
133
+ ): Promise<void> {
134
+ const dir = deepworkPlanDir(cwd, slug)
135
+ await mkdir(dir, { recursive: true })
136
+ const journalPath = deepworkJournalPath(cwd, slug)
137
+ const line = `${JSON.stringify(event)}\n`
138
+ await appendFile(journalPath, line, 'utf8')
139
+ }
140
+
141
+ /**
142
+ * Read all events from the journal log.
143
+ */
144
+ export async function readJournal(cwd = process.cwd(), slug: string): Promise<JournalEvent[]> {
145
+ const journalPath = deepworkJournalPath(cwd, slug)
146
+ try {
147
+ const raw = await readFile(journalPath, 'utf8')
148
+ return raw
149
+ .split('\n')
150
+ .filter((line) => line.trim().length > 0)
151
+ .map((line) => JSON.parse(line) as JournalEvent)
152
+ } catch {
153
+ return []
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Update the state of a specific task and persist both plan and journal.
159
+ */
160
+ export async function updateTaskState(
161
+ cwd = process.cwd(),
162
+ slug: string,
163
+ taskId: string,
164
+ state: TaskState,
165
+ result?: { summary?: string; verified_at?: string; artifacts?: string[] },
166
+ ): Promise<DeepworkPlan> {
167
+ const plan = await readPlan(cwd, slug)
168
+ if (!plan) {
169
+ throw new Error(`Deepwork plan "${slug}" not found`)
170
+ }
171
+
172
+ const taskIndex = plan.tasks.findIndex((t) => t.id === taskId)
173
+ const existingTask = plan.tasks[taskIndex]
174
+ if (taskIndex === -1 || !existingTask) {
175
+ throw new Error(`Task "${taskId}" not found in plan "${slug}"`)
176
+ }
177
+
178
+ const updatedResult = result ? { ...(existingTask.result ?? {}), ...result } : existingTask.result
179
+
180
+ const updatedTask: PlanTask = {
181
+ ...existingTask,
182
+ state,
183
+ ...(updatedResult !== undefined ? { result: updatedResult } : {}),
184
+ }
185
+
186
+ const updatedTasks = [...plan.tasks]
187
+ updatedTasks[taskIndex] = updatedTask
188
+
189
+ const nextPlan: DeepworkPlan = { ...plan, tasks: updatedTasks }
190
+ await writePlan(cwd, nextPlan)
191
+
192
+ await appendJournal(cwd, slug, {
193
+ type: 'task_state_changed',
194
+ timestamp: new Date().toISOString(),
195
+ payload: { taskId, state, result },
196
+ })
197
+
198
+ return (await readPlan(cwd, slug)) ?? nextPlan
199
+ }
200
+
201
+ /**
202
+ * Record verification of an acceptance criterion.
203
+ */
204
+ export async function verifyTaskAcceptance(
205
+ cwd = process.cwd(),
206
+ slug: string,
207
+ taskId: string,
208
+ checkIndex: number,
209
+ verified: boolean,
210
+ proof?: string,
211
+ ): Promise<DeepworkPlan> {
212
+ const plan = await readPlan(cwd, slug)
213
+ if (!plan) {
214
+ throw new Error(`Deepwork plan "${slug}" not found`)
215
+ }
216
+
217
+ const taskIndex = plan.tasks.findIndex((t) => t.id === taskId)
218
+ const task = plan.tasks[taskIndex]
219
+ if (taskIndex === -1 || !task) {
220
+ throw new Error(`Task "${taskId}" not found in plan "${slug}"`)
221
+ }
222
+
223
+ const currentAcc = task.acceptance[checkIndex]
224
+ if (!currentAcc) {
225
+ throw new Error(`Acceptance criterion index ${checkIndex} not found in task "${taskId}"`)
226
+ }
227
+
228
+ const updatedAcceptance = [...task.acceptance]
229
+ const resolvedProof = proof ?? currentAcc.proof
230
+ updatedAcceptance[checkIndex] = {
231
+ ...currentAcc,
232
+ verified,
233
+ ...(resolvedProof !== undefined ? { proof: resolvedProof } : {}),
234
+ }
235
+
236
+ const allVerified = updatedAcceptance.every((acc) => acc.verified)
237
+
238
+ const updatedTasks = [...plan.tasks]
239
+ updatedTasks[taskIndex] = {
240
+ ...task,
241
+ acceptance: updatedAcceptance,
242
+ state: allVerified ? 'done' : task.state,
243
+ }
244
+
245
+ const nextPlan: DeepworkPlan = { ...plan, tasks: updatedTasks }
246
+ await writePlan(cwd, nextPlan)
247
+
248
+ await appendJournal(cwd, slug, {
249
+ type: 'acceptance_verified',
250
+ timestamp: new Date().toISOString(),
251
+ payload: { taskId, checkIndex, verified, proof, allVerified },
252
+ })
253
+
254
+ return (await readPlan(cwd, slug)) ?? nextPlan
255
+ }
256
+
257
+ /**
258
+ * Resolve a decision in the plan.
259
+ */
260
+ export async function resolvePlanDecision(
261
+ cwd = process.cwd(),
262
+ slug: string,
263
+ decisionId: string,
264
+ chosen: string,
265
+ ): Promise<DeepworkPlan> {
266
+ const plan = await readPlan(cwd, slug)
267
+ if (!plan) {
268
+ throw new Error(`Deepwork plan "${slug}" not found`)
269
+ }
270
+
271
+ const decIndex = plan.decisions_needed.findIndex((d) => d.id === decisionId)
272
+ const existingDec = plan.decisions_needed[decIndex]
273
+ if (decIndex === -1 || !existingDec) {
274
+ throw new Error(`Decision "${decisionId}" not found in plan "${slug}"`)
275
+ }
276
+
277
+ const updatedDecisions = [...plan.decisions_needed]
278
+ updatedDecisions[decIndex] = {
279
+ ...existingDec,
280
+ chosen,
281
+ status: 'resolved',
282
+ }
283
+
284
+ const nextPlan: DeepworkPlan = { ...plan, decisions_needed: updatedDecisions }
285
+ await writePlan(cwd, nextPlan)
286
+
287
+ await appendJournal(cwd, slug, {
288
+ type: 'decision_resolved',
289
+ timestamp: new Date().toISOString(),
290
+ payload: { decisionId, chosen },
291
+ })
292
+
293
+ return (await readPlan(cwd, slug)) ?? nextPlan
294
+ }
295
+
296
+ /**
297
+ * List all available deepwork plans in the workspace.
298
+ */
299
+ export async function listPlans(cwd = process.cwd()): Promise<
300
+ Array<{
301
+ slug: string
302
+ title: string
303
+ tasks_count: number
304
+ done_count: number
305
+ updated_at: string
306
+ }>
307
+ > {
308
+ const root = deepworkRootDir(cwd)
309
+ if (!existsSync(root)) return []
310
+
311
+ const entries = await readdir(root, { withFileTypes: true })
312
+ const result: Array<{
313
+ slug: string
314
+ title: string
315
+ tasks_count: number
316
+ done_count: number
317
+ updated_at: string
318
+ }> = []
319
+
320
+ for (const entry of entries) {
321
+ if (entry.isDirectory()) {
322
+ const plan = await readPlan(cwd, entry.name)
323
+ if (plan) {
324
+ result.push({
325
+ slug: plan.plan_id,
326
+ title: plan.title,
327
+ tasks_count: plan.tasks.length,
328
+ done_count: plan.tasks.filter((t) => t.state === 'done').length,
329
+ updated_at: plan.metadata.updated_at,
330
+ })
331
+ }
332
+ }
333
+ }
334
+
335
+ return result
336
+ }
@@ -150,7 +150,9 @@ export function buildV2VisionPromptContext(
150
150
  if (isValidSessionId(sessionID)) {
151
151
  payload.push(`relay session_id=${JSON.stringify(sessionID)}`)
152
152
  }
153
- payload.push('inspect silently -> handoff @aphrodite; an image never authorizes a revert')
153
+ payload.push(
154
+ 'call vision_describe with the image path; handoff @aphrodite; an image never authorizes a revert',
155
+ )
154
156
  return ['<!-- pantheon-v2-visual-context -->', payload.join(' · ')].join('\n')
155
157
  }
156
158
 
@@ -41,7 +41,7 @@ const TOOL_DESCRIPTION =
41
41
  'Advisory discovery tool for skills. Queries installed Pantheon skills and external ' +
42
42
  'registries (Anthropic catalog, skills.sh, GitHub). Returns matched skill IDs, ' +
43
43
  'descriptions, install counts, and provenance tiers. Zeus uses this to recommend ' +
44
- 'skills before prompting the user to install.'
44
+ 'project-scoped skills (.agents/skills/) before proactively prompting the user via the question tool.'
45
45
 
46
46
  const SKILL_SEARCH_INPUT_SCHEMA: Record<string, unknown> = {
47
47
  type: 'object',
@@ -159,7 +159,7 @@ export function executeSkillSearch(input: Record<string, unknown>): SkillSearchO
159
159
  installed: false,
160
160
  installs: entry.installs ?? null,
161
161
  url: entry.url,
162
- installCommand: `npx skills add ${entry.skill} -a opencode`,
162
+ installCommand: `npx skills add ${entry.skill} -a opencode -y`,
163
163
  })
164
164
  }
165
165
  }
@@ -48,6 +48,7 @@
48
48
 
49
49
  import { createCostCommand } from './cost-command.ts'
50
50
  import type { ShadowSink } from './decision-shadow.ts'
51
+ import { createDeepworkTool } from './deepwork/deepwork-tool.ts'
51
52
  import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool.ts'
52
53
  import { createV2JevDecisionDefinition, type V2JevDecisionRuntime } from './jev-decision-tool.ts'
53
54
  import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
@@ -545,6 +546,7 @@ export function createV2ToolDefinitions(
545
546
  )
546
547
  definitions.push(todowriteTool)
547
548
  definitions.push(createV2SkillSearchDefinition())
549
+ definitions.push(createDeepworkTool())
548
550
  if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))
549
551
  if (jevRuntime) definitions.push(createV2JevDecisionDefinition(jevRuntime))
550
552
  return definitions