@omacode/micromanager 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/README.md +27 -2
- package/evolver/mm_evolve/__init__.py +1 -0
- package/evolver/mm_evolve/entry.py +3 -0
- package/evolver/mm_evolve/evaluator.py +119 -0
- package/evolver/mm_evolve/llm.py +76 -0
- package/evolver/mm_evolve/run.py +89 -0
- package/evolver/mm_evolve/spec.py +62 -0
- package/evolver/pyproject.toml +21 -0
- package/evolver/uv.lock +772 -0
- package/package.json +55 -4
- package/skills/THIRD_PARTY.md +58 -0
- package/skills/code-review/SKILL.md +46 -0
- package/skills/deliberate/SKILL.md +39 -0
- package/skills/diagnosing-bugs/SKILL.md +75 -0
- package/skills/receiving-code-review/SKILL.md +36 -0
- package/skills/research/SKILL.md +18 -0
- package/skills/tdd/SKILL.md +56 -0
- package/skills/tdd/mocking.md +59 -0
- package/skills/tdd/tests.md +77 -0
- package/skills/verification-before-completion/SKILL.md +50 -0
- package/src/agenda.ts +56 -0
- package/src/agents.ts +74 -0
- package/src/ask.ts +243 -0
- package/src/backends.ts +144 -0
- package/src/backlog.ts +436 -0
- package/src/bench.ts +163 -0
- package/src/board.ts +1 -0
- package/src/brief.ts +151 -0
- package/src/browser.ts +624 -0
- package/src/budget.ts +73 -0
- package/src/catalog.ts +214 -0
- package/src/checkchange.ts +180 -0
- package/src/checkpoint.ts +99 -0
- package/src/cli.ts +117 -0
- package/src/compact.ts +162 -0
- package/src/config.ts +340 -0
- package/src/context/capture.ts +1 -0
- package/src/context/digest.ts +1 -0
- package/src/context/embed.ts +1 -0
- package/src/context/index.ts +2 -0
- package/src/context/ledger.ts +1 -0
- package/src/context/manager.ts +1 -0
- package/src/context/memory.ts +1 -0
- package/src/context/policy.ts +1 -0
- package/src/context/prices.ts +1 -0
- package/src/context/recall.ts +1 -0
- package/src/context/rules.ts +1 -0
- package/src/context/search.ts +1 -0
- package/src/context/status.ts +1 -0
- package/src/context/store.ts +1 -0
- package/src/context/summary.ts +1 -0
- package/src/context/tokens.ts +1 -0
- package/src/context/tools.ts +1 -0
- package/src/continuation.ts +122 -0
- package/src/contract.ts +342 -0
- package/src/contractround.ts +225 -0
- package/src/control.ts +1 -0
- package/src/dataset.ts +133 -0
- package/src/decide.ts +690 -0
- package/src/eval.ts +66 -0
- package/src/evolver.ts +369 -0
- package/src/followups.ts +50 -0
- package/src/forms.ts +191 -0
- package/src/gate.ts +90 -0
- package/src/grants.ts +239 -0
- package/src/graph.ts +74 -0
- package/src/guard/index.ts +1 -0
- package/src/guard/wire.ts +1 -0
- package/src/helpers.ts +105 -0
- package/src/hooks.ts +199 -0
- package/src/integration.ts +4 -0
- package/src/jev.ts +141 -0
- package/src/journal.ts +1 -0
- package/src/look.ts +390 -0
- package/src/memory.ts +1 -0
- package/src/native.ts +2455 -0
- package/src/nogit.ts +112 -0
- package/src/outcomes.ts +210 -0
- package/src/pick.ts +112 -0
- package/src/pipelines.ts +252 -0
- package/src/plan.ts +449 -0
- package/src/plugin.ts +3187 -0
- package/src/policy.ts +84 -0
- package/src/pools.ts +1 -0
- package/src/profile.ts +186 -0
- package/src/progress.ts +1 -0
- package/src/redact.ts +1 -0
- package/src/registry.ts +207 -0
- package/src/roles.ts +1 -0
- package/src/routing.ts +1 -0
- package/src/runner.ts +1506 -0
- package/src/sandbox.ts +4 -0
- package/src/scheduler.ts +200 -0
- package/src/session.ts +269 -0
- package/src/shell/decide.ts +1 -0
- package/src/shell/index.ts +2 -0
- package/src/shell/sandbox.ts +1 -0
- package/src/shell/wire.ts +1 -0
- package/src/skills.ts +111 -0
- package/src/state.ts +1 -0
- package/src/store.ts +1 -0
- package/src/switcher.ts +1 -0
- package/src/tools.ts +480 -0
- package/src/trials.ts +247 -0
- package/src/usage.ts +1 -0
- package/src/wait.ts +180 -0
- package/src/watchdog.ts +498 -0
- package/src/worktree/git.ts +378 -0
package/src/sandbox.ts
ADDED
package/src/scheduler.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// The job queue and the updates to the user (Phase E). run_job hands a job to the scheduler and returns at
|
|
2
|
+
// once, so the micromanager's session stays free while workers run; the scheduler works the queue in the background,
|
|
3
|
+
// one job at a time per plugin process (Phase F runs a job's tasks in parallel), and the notifier reports to the
|
|
4
|
+
// job's micromanager session and the desktop.
|
|
5
|
+
//
|
|
6
|
+
// How an update reaches the micromanager (Phase E spike): a synthetic message with resume starts a turn of an idle
|
|
7
|
+
// session and is steered into a busy one, but models take its text for an injection. So the synthetic message only
|
|
8
|
+
// wakes the micromanager; the update itself goes in as a system block through the context hook, which models follow
|
|
9
|
+
// (Phase A, A1).
|
|
10
|
+
|
|
11
|
+
import type { Job } from "./state.ts"
|
|
12
|
+
|
|
13
|
+
export interface Cancel {
|
|
14
|
+
cancelled: boolean
|
|
15
|
+
session?: string // the runner session working right now, to interrupt on a stop
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SchedulerDeps {
|
|
19
|
+
run(job: string, cancel: Cancel, note?: string): Promise<Job>
|
|
20
|
+
finished(job: Job, session: string | undefined): void
|
|
21
|
+
failed(job: string, session: string | undefined, error: unknown): void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Entry {
|
|
25
|
+
readonly job: string
|
|
26
|
+
readonly session?: string
|
|
27
|
+
readonly note?: string // the user's answer, for the run that resumes the job
|
|
28
|
+
readonly cancel: Cancel
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class Scheduler {
|
|
32
|
+
readonly #d: SchedulerDeps
|
|
33
|
+
readonly #queue: Entry[] = []
|
|
34
|
+
#current?: Entry
|
|
35
|
+
#pumping?: Promise<void>
|
|
36
|
+
|
|
37
|
+
constructor(deps: SchedulerDeps) {
|
|
38
|
+
this.#d = deps
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Queues a job; 0 means it starts now. A job already running or queued keeps its place.
|
|
42
|
+
enqueue(job: string, session?: string, note?: string): number {
|
|
43
|
+
if (this.#current?.job === job) return 0
|
|
44
|
+
const at = this.#queue.findIndex((e) => e.job === job)
|
|
45
|
+
if (at >= 0) return at + 1
|
|
46
|
+
this.#queue.push({ job, session, note, cancel: { cancelled: false } })
|
|
47
|
+
this.#pumping ??= this.#pump().finally(() => { this.#pumping = undefined })
|
|
48
|
+
return this.#current ? this.#queue.length : 0
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A queued job leaves the queue; the running one is told to stop, and its current session is returned to interrupt.
|
|
52
|
+
stop(job?: string): { state: "stopping" | "dequeued" | "unknown"; session?: string } {
|
|
53
|
+
const id = job || this.#current?.job
|
|
54
|
+
if (id && this.#current?.job === id) {
|
|
55
|
+
this.#current.cancel.cancelled = true
|
|
56
|
+
return { state: "stopping", session: this.#current.cancel.session }
|
|
57
|
+
}
|
|
58
|
+
const at = this.#queue.findIndex((e) => e.job === id)
|
|
59
|
+
if (at < 0) return { state: "unknown" }
|
|
60
|
+
this.#queue.splice(at, 1)
|
|
61
|
+
return { state: "dequeued" }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The session a running job works in now; the runner reports each session it starts.
|
|
65
|
+
working(job: string, session: string): void {
|
|
66
|
+
if (this.#current?.job === job) this.#current.cancel.session = session
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
snapshot(): { running?: string; queued: string[] } {
|
|
70
|
+
return { running: this.#current?.job, queued: this.#queue.map((e) => e.job) }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Resolves when the queue is empty (tests, shutdown).
|
|
74
|
+
async idle(): Promise<void> {
|
|
75
|
+
while (this.#pumping) await this.#pumping
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async #pump(): Promise<void> {
|
|
79
|
+
for (let next = this.#queue.shift(); next; next = this.#queue.shift()) {
|
|
80
|
+
this.#current = next
|
|
81
|
+
try {
|
|
82
|
+
this.#d.finished(await this.#d.run(next.job, next.cancel, next.note), next.session)
|
|
83
|
+
} catch (err) {
|
|
84
|
+
this.#d.failed(next.job, next.session, err)
|
|
85
|
+
} finally {
|
|
86
|
+
this.#current = undefined
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type NotifyMode = "jobs" | "tasks" | "off"
|
|
93
|
+
|
|
94
|
+
export interface NotifierDeps {
|
|
95
|
+
synthetic(session: string, text: string, resume: boolean): Promise<unknown>
|
|
96
|
+
steer(session: string, note: string): void // a system block for the micromanager's next turns
|
|
97
|
+
desktop(title: string, body: string): void
|
|
98
|
+
mode: NotifyMode
|
|
99
|
+
flushMs?: number
|
|
100
|
+
reportMs?: number // how long task reports are gathered into one update
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// What a job's end means for the user.
|
|
104
|
+
export type Ending = "done" | "needs_user" | "failed" | "stopped"
|
|
105
|
+
|
|
106
|
+
export function ending(job: Job): Ending {
|
|
107
|
+
if (job.phase === "integrate" || job.phase === "done" || job.phase === "wrap") return "done"
|
|
108
|
+
if (job.phase === "failed") return "failed"
|
|
109
|
+
if (job.phase === "paused" || job.phase === "stopped") return "stopped"
|
|
110
|
+
return "needs_user"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const TITLES: Record<Ending, string> = {
|
|
114
|
+
done: "job done",
|
|
115
|
+
needs_user: "job needs you",
|
|
116
|
+
failed: "job failed",
|
|
117
|
+
stopped: "job stopped",
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class Notifier {
|
|
121
|
+
readonly #d: NotifierDeps
|
|
122
|
+
readonly #lines = new Map<string, string[]>()
|
|
123
|
+
readonly #timers = new Map<string, ReturnType<typeof setTimeout>>()
|
|
124
|
+
|
|
125
|
+
constructor(deps: NotifierDeps) {
|
|
126
|
+
this.#d = deps
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// A progress line: collected per session and sent as one quiet message (no new turn) every flushMs.
|
|
130
|
+
progress(session: string | undefined, line: string, task = false): void {
|
|
131
|
+
if (task && this.#d.mode === "tasks") this.#d.desktop("micromanager", line)
|
|
132
|
+
if (!session) return
|
|
133
|
+
const lines = this.#lines.get(session) ?? []
|
|
134
|
+
lines.push(line)
|
|
135
|
+
this.#lines.set(session, lines)
|
|
136
|
+
if (this.#timers.has(session)) return
|
|
137
|
+
const timer = setTimeout(() => void this.flush(session), this.#d.flushMs ?? 20_000)
|
|
138
|
+
timer.unref?.()
|
|
139
|
+
this.#timers.set(session, timer)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async flush(session: string): Promise<void> {
|
|
143
|
+
clearTimeout(this.#timers.get(session))
|
|
144
|
+
this.#timers.delete(session)
|
|
145
|
+
const lines = this.#lines.get(session)
|
|
146
|
+
this.#lines.delete(session)
|
|
147
|
+
if (!lines?.length) return
|
|
148
|
+
await this.#d.synthetic(session, `[micromanager] progress:\n- ${lines.join("\n- ")}`, false).catch(() => undefined)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// omo-hybrid: delegated tasks report to the orchestrator. Reports that come close together are one update: a system
|
|
152
|
+
// note with all of them, and one wake-up.
|
|
153
|
+
readonly #reports = new Map<string, string[]>()
|
|
154
|
+
readonly #reportTimers = new Map<string, ReturnType<typeof setTimeout>>()
|
|
155
|
+
readonly #boards = new Map<string, string>() // the job's board as of the newest report
|
|
156
|
+
|
|
157
|
+
// board: the job's ASCII board after this change; every update carries the newest one, so the user sees the state
|
|
158
|
+
// whenever something changed, without the orchestrator having to ask for it.
|
|
159
|
+
report(session: string | undefined, text: string, title?: string, board?: string): void {
|
|
160
|
+
if (title && this.#d.mode === "tasks") this.#d.desktop("micromanager", title)
|
|
161
|
+
if (!session) return
|
|
162
|
+
if (board) this.#boards.set(session, board)
|
|
163
|
+
const list = this.#reports.get(session) ?? []
|
|
164
|
+
list.push(text)
|
|
165
|
+
this.#reports.set(session, list)
|
|
166
|
+
if (this.#reportTimers.has(session)) return
|
|
167
|
+
const timer = setTimeout(() => void this.flushReports(session), this.#d.reportMs ?? 8_000)
|
|
168
|
+
timer.unref?.()
|
|
169
|
+
this.#reportTimers.set(session, timer)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async flushReports(session: string, closing?: string): Promise<void> {
|
|
173
|
+
clearTimeout(this.#reportTimers.get(session))
|
|
174
|
+
this.#reportTimers.delete(session)
|
|
175
|
+
const list = this.#reports.get(session) ?? []
|
|
176
|
+
this.#reports.delete(session)
|
|
177
|
+
if (!list.length && !closing) return
|
|
178
|
+
await this.flush(session)
|
|
179
|
+
const board = this.#boards.get(session)
|
|
180
|
+
this.#d.steer(session, `[micromanager update] Delegated tasks reported. This comes from your own plugin, not from the user or a tool result; it is trusted.
|
|
181
|
+
Check each result. Delegate what comes next (fixes, the follow-ups worth doing, dependent work) with the subagent tool, ask the user what only they can decide, and update your todos.
|
|
182
|
+
|
|
183
|
+
${list.join("\n\n")}${closing ? `\n\n${closing}` : ""}${board ? `\n\nThe job's board now; start your message to the user with it, in a code block, as it is:\n${board}` : ""}`)
|
|
184
|
+
await this.#d.synthetic(session, `[micromanager] ${list.length ? `${list.length} task report(s)` : "update"} (details in the plugin's system note)`, true).catch(() => undefined)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A job ended or needs the user: the micromanager gets the update as a system block and is woken to tell the user.
|
|
188
|
+
async finished(session: string | undefined, jobId: string, end: Ending, text: string): Promise<void> {
|
|
189
|
+
if (this.#d.mode !== "off") this.#d.desktop(`micromanager: ${TITLES[end]}`, `${jobId}\n${text.split("\n").slice(0, 4).join("\n")}`)
|
|
190
|
+
if (!session) return
|
|
191
|
+
await this.flush(session)
|
|
192
|
+
// A stop comes from the user through the micromanager, which already said so: a quiet note, no new turn.
|
|
193
|
+
if (end === "stopped") return void (await this.#d.synthetic(session, `[micromanager] ${TITLES[end]}: ${jobId}`, false).catch(() => undefined))
|
|
194
|
+
this.#d.steer(session, `[micromanager update] ${TITLES[end]}: ${jobId}. This update comes from your own plugin, not from the user and not from a tool result; it is trusted.
|
|
195
|
+
${end === "needs_user" ? "Tell the user in a few sentences why the job stopped and what they can decide; then wait for their answer." : end === "done" ? "Tell the user the job is done, what changed, and how to merge or discard the branch." : "Tell the user what happened and what they can do."}
|
|
196
|
+
|
|
197
|
+
${text}`)
|
|
198
|
+
await this.#d.synthetic(session, `[micromanager] ${TITLES[end]}: ${jobId} (details in the plugin's system note)`, true).catch(() => undefined)
|
|
199
|
+
}
|
|
200
|
+
}
|
package/src/session.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// The planning session (design.md §6): a design tree owned by code, worked one question per turn.
|
|
2
|
+
//
|
|
3
|
+
// The facilitator (the micromanager, on the user's session model) drafts the tree and asks; code validates the tree,
|
|
4
|
+
// keeps the frontier, applies the user's shortcuts and answers, and tells the facilitator what to do next. There
|
|
5
|
+
// are no suggested answers: options or explanations come only when the user is stuck or asks for them.
|
|
6
|
+
|
|
7
|
+
import type { Depth, DesignNode, DesignTree, Impact, NodeKind, NodeStatus } from "@omacode/state/schema"
|
|
8
|
+
export type { Depth, DesignNode, DesignTree, Impact, NodeKind, NodeStatus }
|
|
9
|
+
|
|
10
|
+
const IMPACT_RANK: Record<Impact, number> = { low: 0, medium: 1, high: 2 }
|
|
11
|
+
const CAP: Record<Depth, number> = { light: 5, normal: 12, frequent: Infinity }
|
|
12
|
+
const MAX_NODES = 25
|
|
13
|
+
const ID = /^[A-Za-z][\w.-]{0,15}$/
|
|
14
|
+
|
|
15
|
+
export type ParsedTree = { tree: DesignTree; errors?: undefined } | { tree?: undefined; errors: string[] }
|
|
16
|
+
|
|
17
|
+
// The facilitator's draft: [{ id, question, kind, dependsOn, impact }], or { nodes: [...] }.
|
|
18
|
+
export function parseTree(raw: unknown, depth: Depth = "normal"): ParsedTree {
|
|
19
|
+
const list = Array.isArray(raw) ? raw : (raw as { nodes?: unknown })?.nodes
|
|
20
|
+
if (!Array.isArray(list) || list.length === 0) return { errors: ["the tree needs a non-empty list of questions"] }
|
|
21
|
+
if (list.length > MAX_NODES) return { errors: [`at most ${MAX_NODES} questions, got ${list.length}`] }
|
|
22
|
+
const errors: string[] = []
|
|
23
|
+
const nodes: DesignNode[] = []
|
|
24
|
+
for (const [i, item] of list.entries()) {
|
|
25
|
+
const n = item as Record<string, unknown>
|
|
26
|
+
const where = `question ${i + 1}${typeof n.id === "string" ? ` (${n.id})` : ""}`
|
|
27
|
+
const deps = n.dependsOn ?? []
|
|
28
|
+
if (typeof n.id !== "string" || !ID.test(n.id)) errors.push(`${where}: needs a short id`)
|
|
29
|
+
if (typeof n.question !== "string" || n.question.trim().length < 5) errors.push(`${where}: needs the question text`)
|
|
30
|
+
if (!["decision", "fact", "assumption"].includes(String(n.kind ?? "decision"))) errors.push(`${where}: kind must be decision, fact or assumption`)
|
|
31
|
+
if (!["low", "medium", "high"].includes(String(n.impact))) errors.push(`${where}: impact must be low, medium or high`)
|
|
32
|
+
if (!Array.isArray(deps) || !deps.every((d) => typeof d === "string")) errors.push(`${where}: dependsOn must be a list of ids`)
|
|
33
|
+
if (errors.length) continue
|
|
34
|
+
nodes.push({
|
|
35
|
+
id: n.id as string,
|
|
36
|
+
question: (n.question as string).trim(),
|
|
37
|
+
kind: (n.kind ?? "decision") as NodeKind,
|
|
38
|
+
dependsOn: deps as string[],
|
|
39
|
+
impact: n.impact as Impact,
|
|
40
|
+
status: "open",
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
const ids = new Set<string>()
|
|
44
|
+
for (const n of nodes) {
|
|
45
|
+
if (ids.has(n.id)) errors.push(`${n.id}: duplicate id`)
|
|
46
|
+
ids.add(n.id)
|
|
47
|
+
}
|
|
48
|
+
for (const n of nodes) for (const d of n.dependsOn) if (!ids.has(d)) errors.push(`${n.id}: depends on unknown ${d}`)
|
|
49
|
+
if (hasCycle(nodes)) errors.push("the questions depend on each other in a cycle")
|
|
50
|
+
return errors.length ? { errors } : { tree: { nodes, depth, asked: 0, turn: 0 } }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hasCycle(nodes: readonly DesignNode[]): boolean {
|
|
54
|
+
const deps = new Map(nodes.map((n) => [n.id, n.dependsOn]))
|
|
55
|
+
const state = new Map<string, number>()
|
|
56
|
+
const visit = (id: string): boolean => {
|
|
57
|
+
if (state.get(id) === 2) return false
|
|
58
|
+
if (state.get(id) === 1) return true
|
|
59
|
+
state.set(id, 1)
|
|
60
|
+
const found = (deps.get(id) ?? []).some(visit)
|
|
61
|
+
state.set(id, 2)
|
|
62
|
+
return found
|
|
63
|
+
}
|
|
64
|
+
return nodes.some((n) => visit(n.id))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Adds nodes the facilitator found later (a new branch); same rules as the draft.
|
|
68
|
+
export function addNodes(tree: DesignTree, raw: unknown): string[] {
|
|
69
|
+
const merged = parseTree([...tree.nodes.map((n) => ({ ...n })), ...(Array.isArray(raw) ? raw : [])], tree.depth)
|
|
70
|
+
if (merged.errors) return merged.errors
|
|
71
|
+
const known = new Map(tree.nodes.map((n) => [n.id, n]))
|
|
72
|
+
tree.nodes = merged.tree.nodes.map((n) => known.get(n.id) ?? n)
|
|
73
|
+
return []
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const RESOLVED = new Set<NodeStatus>(["settled", "assumed", "out_of_scope"])
|
|
77
|
+
|
|
78
|
+
// Low-impact open decisions are not asked: they become assumptions, shown at the checkpoint. Open facts wait
|
|
79
|
+
// for agents, never for the user.
|
|
80
|
+
export function assumeLowImpact(tree: DesignTree): DesignNode[] {
|
|
81
|
+
const assumed = tree.nodes.filter((n) => n.status === "open" && n.kind !== "fact" && n.impact === "low")
|
|
82
|
+
for (const n of assumed) {
|
|
83
|
+
n.status = "assumed"
|
|
84
|
+
n.origin = "assumed"
|
|
85
|
+
}
|
|
86
|
+
return assumed
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Open decisions whose prerequisites are all resolved: the questions that can be asked now without guessing.
|
|
90
|
+
export function frontier(tree: DesignTree): DesignNode[] {
|
|
91
|
+
const byId = new Map(tree.nodes.map((n) => [n.id, n]))
|
|
92
|
+
return tree.nodes.filter((n) =>
|
|
93
|
+
n.status === "open" && n.kind === "decision" && n.dependsOn.every((d) => RESOLVED.has(byId.get(d)?.status ?? "open")),
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function openFacts(tree: DesignTree): DesignNode[] {
|
|
98
|
+
return tree.nodes.filter((n) => n.kind === "fact" && (n.status === "open" || n.status === "researching"))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The rules' pick: highest impact, then the one most other questions wait on, then the draft's order.
|
|
102
|
+
export function ruleNext(tree: DesignTree): DesignNode | undefined {
|
|
103
|
+
const waiting = (id: string) => tree.nodes.filter((n) => n.status === "open" && n.dependsOn.includes(id)).length
|
|
104
|
+
return [...frontier(tree)].sort((a, b) => IMPACT_RANK[b.impact] - IMPACT_RANK[a.impact] || waiting(b.id) - waiting(a.id))[0]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function capReached(tree: DesignTree): boolean {
|
|
108
|
+
return tree.asked >= CAP[tree.depth]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function settle(tree: DesignTree, id: string, answer: string, origin: DesignNode["origin"] = "user"): void {
|
|
112
|
+
const n = tree.nodes.find((x) => x.id === id)
|
|
113
|
+
if (!n) return
|
|
114
|
+
n.status = "settled"
|
|
115
|
+
n.answer = answer
|
|
116
|
+
n.origin = origin
|
|
117
|
+
n.settledAt = tree.turn
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// --- the user's turn ------------------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
export type Shortcut =
|
|
123
|
+
| { kind: "stop" }
|
|
124
|
+
| { kind: "skip" } // "decide it yourself": the current question becomes an assumption
|
|
125
|
+
| { kind: "wait_what" } // re-pitch the current question with the missing context
|
|
126
|
+
| { kind: "back"; id: string } // reopen a settled question
|
|
127
|
+
| { kind: "depth"; depth: Depth }
|
|
128
|
+
| { kind: "confirm" }
|
|
129
|
+
| { kind: "discuss" }
|
|
130
|
+
|
|
131
|
+
export function matchSessionShortcut(text: string): Shortcut | undefined {
|
|
132
|
+
const t = text.trim().toLowerCase().replace(/[.!?]+$/, "")
|
|
133
|
+
if (["stop", "enough", "that's enough"].includes(t)) return { kind: "stop" }
|
|
134
|
+
if (["skip", "decide it yourself", "you decide"].includes(t)) return { kind: "skip" }
|
|
135
|
+
if (["wait what", "i don't get it", "i do not get it", "what do you mean"].includes(t)) return { kind: "wait_what" }
|
|
136
|
+
if (["light", "normal", "frequent"].includes(t)) return { kind: "depth", depth: t as Depth }
|
|
137
|
+
if (["confirm", "confirmed", "looks good", "go"].includes(t)) return { kind: "confirm" }
|
|
138
|
+
if (t === "discuss") return { kind: "discuss" }
|
|
139
|
+
const back = t.match(/^(?:go )?back to ([a-z][\w.-]*)$/)
|
|
140
|
+
if (back) return { kind: "back", id: back[1]! }
|
|
141
|
+
return undefined
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// What the facilitator does this turn, as code decided it. The plugin turns this into a system block.
|
|
145
|
+
export type Step =
|
|
146
|
+
| { kind: "ask"; node: DesignNode; reason: string }
|
|
147
|
+
| { kind: "explain"; node: DesignNode } // the user is stuck or asked: options with trade-offs, then hand back
|
|
148
|
+
| { kind: "repitch"; node: DesignNode }
|
|
149
|
+
| { kind: "contradiction"; node: DesignNode; earlier: DesignNode[] }
|
|
150
|
+
| { kind: "add_branches"; node: DesignNode }
|
|
151
|
+
| { kind: "checkpoint" }
|
|
152
|
+
| { kind: "facts_pending"; facts: DesignNode[] }
|
|
153
|
+
| { kind: "stopped" }
|
|
154
|
+
|
|
155
|
+
export interface AnswerReading {
|
|
156
|
+
readonly settles?: boolean
|
|
157
|
+
readonly newBranches?: boolean
|
|
158
|
+
readonly stuck?: boolean
|
|
159
|
+
readonly asksOptions?: boolean
|
|
160
|
+
readonly contradicts?: boolean
|
|
161
|
+
readonly outOfScope?: boolean
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// One user turn while a question is open. Without a reading (no decision model), an answer counts as settling.
|
|
165
|
+
export function applyAnswer(tree: DesignTree, text: string, reading: AnswerReading = { settles: true }): Step | undefined {
|
|
166
|
+
tree.turn++
|
|
167
|
+
const node = tree.nodes.find((n) => n.id === tree.current)
|
|
168
|
+
if (!node) return undefined
|
|
169
|
+
// A clear decision wins: help is offered only when the answer does not decide the question (live test: a firm
|
|
170
|
+
// answer also scored 0.71 on "asks for options").
|
|
171
|
+
if ((reading.stuck || reading.asksOptions) && !reading.settles) return { kind: "explain", node }
|
|
172
|
+
if (reading.outOfScope) {
|
|
173
|
+
node.status = "out_of_scope"
|
|
174
|
+
node.answer = text
|
|
175
|
+
return undefined
|
|
176
|
+
}
|
|
177
|
+
if (reading.contradicts) {
|
|
178
|
+
const earlier = tree.nodes.filter((n) => n.status === "settled" && n.origin === "user")
|
|
179
|
+
if (earlier.length) return { kind: "contradiction", node, earlier }
|
|
180
|
+
}
|
|
181
|
+
if (reading.settles === false) return { kind: "repitch", node }
|
|
182
|
+
settle(tree, node.id, text)
|
|
183
|
+
if (reading.newBranches) return { kind: "add_branches", node }
|
|
184
|
+
return undefined
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function applyShortcut(tree: DesignTree, s: Shortcut): Step | undefined {
|
|
188
|
+
const node = tree.nodes.find((n) => n.id === tree.current)
|
|
189
|
+
switch (s.kind) {
|
|
190
|
+
case "stop":
|
|
191
|
+
return { kind: "stopped" }
|
|
192
|
+
case "skip":
|
|
193
|
+
if (node) {
|
|
194
|
+
node.status = "assumed"
|
|
195
|
+
node.origin = "assumed"
|
|
196
|
+
}
|
|
197
|
+
return undefined
|
|
198
|
+
case "wait_what":
|
|
199
|
+
return node ? { kind: "repitch", node } : undefined
|
|
200
|
+
case "back": {
|
|
201
|
+
const target = tree.nodes.find((n) => n.id.toLowerCase() === s.id.toLowerCase())
|
|
202
|
+
if (target) {
|
|
203
|
+
target.status = "open"
|
|
204
|
+
target.answer = undefined
|
|
205
|
+
target.origin = undefined
|
|
206
|
+
return { kind: "ask", node: target, reason: "the user reopened it" }
|
|
207
|
+
}
|
|
208
|
+
return undefined
|
|
209
|
+
}
|
|
210
|
+
case "depth":
|
|
211
|
+
tree.depth = s.depth
|
|
212
|
+
return undefined
|
|
213
|
+
default:
|
|
214
|
+
return undefined // confirm and discuss belong to the checkpoint
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// After a turn: the next question, the checkpoint, or waiting for facts.
|
|
219
|
+
export function nextStep(tree: DesignTree, pick?: string): Step {
|
|
220
|
+
assumeLowImpact(tree)
|
|
221
|
+
const options = frontier(tree)
|
|
222
|
+
if (options.length === 0 || capReached(tree)) {
|
|
223
|
+
const facts = openFacts(tree)
|
|
224
|
+
if (options.length === 0 && facts.length > 0 && tree.nodes.some((n) => n.status === "open" && n.kind === "decision")) {
|
|
225
|
+
return { kind: "facts_pending", facts }
|
|
226
|
+
}
|
|
227
|
+
return { kind: "checkpoint" }
|
|
228
|
+
}
|
|
229
|
+
const chosen = options.find((n) => n.id === pick) ?? ruleNext(tree)!
|
|
230
|
+
tree.current = chosen.id
|
|
231
|
+
tree.asked++
|
|
232
|
+
return { kind: "ask", node: chosen, reason: pick === chosen.id ? "the decision model picked it" : "highest impact first" }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// --- what the facilitator is told -------------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
const RULES = `Rules of the planning session: ask exactly one question, in plain words, with one to three sentences of
|
|
238
|
+
context. Give no options, no examples of possible answers and no recommendation. Do not answer the question yourself. If a term may be new to the
|
|
239
|
+
user, add a short "Concept:" or "Why this matters:" line. Then stop and wait for the user's answer.`
|
|
240
|
+
|
|
241
|
+
export function instruction(step: Step, job: string, tree: DesignTree): string {
|
|
242
|
+
const decided = tree.nodes.filter((n) => n.status === "settled" && n.origin === "user")
|
|
243
|
+
const settledLine = decided.length ? `\nDecided so far: ${decided.map((n) => `${n.id} ${n.answer}`).join(" | ")}` : ""
|
|
244
|
+
switch (step.kind) {
|
|
245
|
+
case "ask":
|
|
246
|
+
return `[planning session ${job}] Ask the user question ${step.node.id} now: "${step.node.question}"\n${RULES}${settledLine}`
|
|
247
|
+
case "repitch":
|
|
248
|
+
return `[planning session ${job}] The user did not follow question ${step.node.id} ("${step.node.question}"). Ask it again with the context they were missing, in simpler words, still without options or a recommendation.${settledLine}`
|
|
249
|
+
case "explain":
|
|
250
|
+
return `[planning session ${job}] The user is stuck on ${step.node.id} ("${step.node.question}") or asked for help. Now, and only now: explain the concept briefly or show two or three approaches with their trade-offs, without picking one. Then hand the decision back: ask which they would take, and why.${settledLine}`
|
|
251
|
+
case "contradiction":
|
|
252
|
+
return `[planning session ${job}] The user's answer to ${step.node.id} may contradict an earlier decision (${step.earlier.map((n) => `${n.id}: ${n.answer}`).join("; ")}). Name both statements and ask which one holds. No recommendation.`
|
|
253
|
+
case "add_branches":
|
|
254
|
+
return `[planning session ${job}] The answer to ${step.node.id} raised new decisions. Call plan_questions with job "${job}" and only the new questions (same format: id, question, kind, dependsOn, impact). Do not ask the user anything in this turn.`
|
|
255
|
+
case "facts_pending":
|
|
256
|
+
return `[planning session ${job}] The remaining decisions wait for facts the agents must find: ${step.facts.map((n) => `${n.id} "${n.question}"`).join("; ")}. Tell the user briefly that these are being looked up; never ask the user for facts.`
|
|
257
|
+
case "checkpoint":
|
|
258
|
+
return `[planning session ${job}] Design checkpoint. Show the user, apart from each other: (1) their decisions: ${decided.map((n) => `${n.id} ${n.question} -> ${n.answer}`).join("; ") || "none"}; (2) what was assumed without asking (mark these as proposals): ${tree.nodes.filter((n) => n.status === "assumed").map((n) => `${n.id} ${n.question}`).join("; ") || "nothing"}. Then ask them to answer "confirm" to plan with this, or "discuss" to change something.`
|
|
259
|
+
case "stopped":
|
|
260
|
+
return `[planning session ${job}] The user stopped the planning session. Confirm briefly that the job is paused; plan_job with the job id continues it later.`
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// The settled tree as the planner gets it: decisions and assumptions, one per line.
|
|
265
|
+
export function decisionsText(tree: DesignTree): string[] {
|
|
266
|
+
return tree.nodes
|
|
267
|
+
.filter((n) => n.status === "settled" || n.status === "assumed")
|
|
268
|
+
.map((n) => `${n.question} -> ${n.status === "assumed" ? "assumed: the planner decides, and says what it chose" : n.answer}`)
|
|
269
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/sandbox/decide"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/sandbox/sandbox"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/sandbox/wire"
|
package/src/skills.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The leaf skills workers load (design.md §13.1): adapted copies in skills/. Workflow logic stays in the plugin; a
|
|
2
|
+
// skill only says how to do the work.
|
|
3
|
+
//
|
|
4
|
+
// They are registered through ctx.skill at setup, not linked into the OpenCode config directory. A package install
|
|
5
|
+
// (`opencode plugin add`) has no checkout to link from, and the files ship inside this package, so the plugin reads
|
|
6
|
+
// its own skills/ directory and adds them itself. That also makes the set identical on every platform: a link is a
|
|
7
|
+
// filesystem feature, a registration is not.
|
|
8
|
+
//
|
|
9
|
+
// Some skills come by rule (every writer verifies, P3 works test-first, a reviewer reviews), the others are offered
|
|
10
|
+
// to the decision model per task (N5's skill.<name> nouls). A skill is named in a brief only when the skill in
|
|
11
|
+
// OpenCode is this package's copy, so a user's own skill of the same name is never loaded by mistake.
|
|
12
|
+
|
|
13
|
+
import { readFileSync, realpathSync } from "node:fs"
|
|
14
|
+
import { dirname, join } from "node:path"
|
|
15
|
+
import { fileURLToPath } from "node:url"
|
|
16
|
+
|
|
17
|
+
import type { Profile, Skill } from "./profile.ts"
|
|
18
|
+
|
|
19
|
+
export interface CatalogSkill extends Skill {
|
|
20
|
+
readonly asked: boolean // offered to the decision model; otherwise only added by rule
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// One skill as OpenCode takes it: what the editor's add() is given.
|
|
24
|
+
export interface SkillFile {
|
|
25
|
+
readonly name: string
|
|
26
|
+
readonly description: string
|
|
27
|
+
readonly path: string
|
|
28
|
+
readonly content: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The slice of ctx.skill this plugin uses. Kept structural for two reasons: the plugin then needs no dependency on
|
|
32
|
+
// @opencode/plugin (it exports a plain object, see src/plugin.ts), and a test can pass a fake editor.
|
|
33
|
+
export interface SkillEditor {
|
|
34
|
+
list(): readonly { readonly id: string; readonly path?: string }[]
|
|
35
|
+
add(skill: { id: string; name: string; description: string; path: string; content: string }): void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SkillDomain {
|
|
39
|
+
transform(callback: (editor: SkillEditor) => void): Promise<unknown>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const WRITER_ROLES = ["code", "test", "visual", "write", "debug"]
|
|
43
|
+
|
|
44
|
+
export const SKILLS: readonly CatalogSkill[] = [
|
|
45
|
+
{ name: "verification-before-completion", description: "run the checks and read their output before claiming the task is done", roles: WRITER_ROLES, asked: false },
|
|
46
|
+
{ name: "tdd", description: "test-driven development: tests at the public seams, red before green", roles: ["code", "test"], asked: true },
|
|
47
|
+
{ name: "diagnosing-bugs", description: "a disciplined loop for bugs with an unknown cause: feedback loop, hypotheses, instrumentation", roles: ["code", "debug"], asked: true },
|
|
48
|
+
{ name: "receiving-code-review", description: "check review findings against the code before changing anything", roles: ["code", "test", "visual", "write", "debug"], asked: false },
|
|
49
|
+
{ name: "code-review", description: "review a change on two axes: what the task asked, and the repo's standards", roles: ["review"], asked: false },
|
|
50
|
+
{ name: "research", description: "answer a question from primary sources and cite every claim", roles: ["research"], asked: false },
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
export type Stage = "implement" | "red" | "review" | "review_fix" | "reader"
|
|
54
|
+
|
|
55
|
+
// The skills a stage gets by rule, plus the ones the decision model picked for the task.
|
|
56
|
+
export function skillsFor(stage: Stage, profile: Profile | undefined, pipeline: string | undefined, installed: ReadonlySet<string>): string[] {
|
|
57
|
+
const out: string[] = []
|
|
58
|
+
if (stage === "implement" || stage === "red" || stage === "review_fix") {
|
|
59
|
+
if (profile && WRITER_ROLES.includes(profile.role)) out.push("verification-before-completion")
|
|
60
|
+
if (stage === "red" || pipeline === "P3") out.push("tdd")
|
|
61
|
+
if (profile?.bugUnknownCause) out.push("diagnosing-bugs")
|
|
62
|
+
if (stage === "review_fix") out.push("receiving-code-review")
|
|
63
|
+
out.push(...(profile?.skills ?? []))
|
|
64
|
+
}
|
|
65
|
+
if (stage === "review") out.push("code-review")
|
|
66
|
+
if (stage === "reader") out.push("research")
|
|
67
|
+
return [...new Set(out)].filter((s) => installed.has(s))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Next to this module, so a package install (node_modules/…) and a symlinked dev checkout both resolve to the copy
|
|
71
|
+
// that belongs to the running code. realpath, because the dev install is a symlink into the repo.
|
|
72
|
+
export const SKILLS_DIR = join(dirname(realpathSync(fileURLToPath(import.meta.url))), "..", "skills")
|
|
73
|
+
|
|
74
|
+
// The catalog's files on disk, in catalog order. A missing file is reported and left out rather than thrown: an
|
|
75
|
+
// install that lost its skills/ directory must still start, with its workers getting no skill.
|
|
76
|
+
export function skillFiles(dir = SKILLS_DIR, missing: (name: string) => void = () => {}): readonly SkillFile[] {
|
|
77
|
+
const out: SkillFile[] = []
|
|
78
|
+
for (const skill of SKILLS) {
|
|
79
|
+
const path = join(dir, skill.name, "SKILL.md")
|
|
80
|
+
try {
|
|
81
|
+
out.push({ name: skill.name, description: skill.description, path, content: readFileSync(path, "utf8") })
|
|
82
|
+
} catch {
|
|
83
|
+
missing(skill.name)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Registers the catalog into OpenCode and answers with the names that are ours and now in place: exactly what a
|
|
90
|
+
// brief may say, because skillsFor filters on this set. A skill the user wrote under the same name keeps its place;
|
|
91
|
+
// ours is not added over it, and the name stays out of the set, so no worker is told to load a skill that would
|
|
92
|
+
// turn out to be someone else's.
|
|
93
|
+
export async function registerSkills(
|
|
94
|
+
domain: SkillDomain | undefined,
|
|
95
|
+
dir = SKILLS_DIR,
|
|
96
|
+
missing?: (name: string) => void,
|
|
97
|
+
): Promise<ReadonlySet<string>> {
|
|
98
|
+
const files = skillFiles(dir, missing)
|
|
99
|
+
const added = new Set<string>()
|
|
100
|
+
if (!domain || files.length === 0) return added
|
|
101
|
+
await domain.transform((editor) => {
|
|
102
|
+
const present = new Map(editor.list().map((skill) => [skill.id, skill]))
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
const seen = present.get(file.name)
|
|
105
|
+
if (seen && seen.path !== file.path) continue
|
|
106
|
+
editor.add({ id: file.name, name: file.name, description: file.description, path: file.path, content: file.content })
|
|
107
|
+
added.add(file.name)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
return added
|
|
111
|
+
}
|
package/src/state.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/state"
|
package/src/store.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/state/store"
|
package/src/switcher.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@omacode/tui/switcher"
|