@omacode/micromanager 0.1.1 → 1.0.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.
Files changed (213) hide show
  1. package/README.md +7 -4
  2. package/THIRD_PARTY.md +100 -0
  3. package/decider/.python-version +1 -0
  4. package/decider/README.md +35 -0
  5. package/decider/decider/__init__.py +1 -0
  6. package/decider/decider/server.py +327 -0
  7. package/decider/pyproject.toml +34 -0
  8. package/decider/uv.lock +1255 -0
  9. package/dist/agenda.js +51 -0
  10. package/dist/agents.js +58 -0
  11. package/dist/artifact/handoff.js +281 -0
  12. package/dist/ask.js +200 -0
  13. package/dist/backends.js +219 -0
  14. package/dist/backlog.js +414 -0
  15. package/dist/bench.js +427 -0
  16. package/dist/board.js +1 -0
  17. package/dist/brief.js +202 -0
  18. package/dist/browser.js +679 -0
  19. package/dist/budget.js +61 -0
  20. package/dist/catalog.js +187 -0
  21. package/dist/checkchange.js +145 -0
  22. package/dist/checkpoint.js +94 -0
  23. package/dist/cli.js +764 -0
  24. package/dist/comfy-gate.js +258 -0
  25. package/dist/compact.js +142 -0
  26. package/dist/config.js +344 -0
  27. package/dist/context/capture.js +1 -0
  28. package/dist/context/digest.js +1 -0
  29. package/dist/context/embed.js +1 -0
  30. package/dist/context/index.js +2 -0
  31. package/dist/context/ledger.js +1 -0
  32. package/dist/context/manager.js +1 -0
  33. package/dist/context/memory.js +1 -0
  34. package/dist/context/policy.js +1 -0
  35. package/dist/context/prices.js +1 -0
  36. package/dist/context/recall.js +1 -0
  37. package/dist/context/rules.js +1 -0
  38. package/dist/context/search.js +1 -0
  39. package/dist/context/status.js +1 -0
  40. package/dist/context/store.js +1 -0
  41. package/dist/context/summary.js +1 -0
  42. package/dist/context/tokens.js +1 -0
  43. package/dist/context/tools.js +1 -0
  44. package/dist/continuation.js +184 -0
  45. package/dist/contract.js +294 -0
  46. package/dist/contractround.js +178 -0
  47. package/dist/control.js +1 -0
  48. package/dist/creative-tools.js +237 -0
  49. package/dist/dataset.js +175 -0
  50. package/dist/decide.js +676 -0
  51. package/dist/decider.js +171 -0
  52. package/dist/design-shell.js +448 -0
  53. package/dist/design.js +1410 -0
  54. package/dist/desktop.js +44 -0
  55. package/dist/egress.js +156 -0
  56. package/dist/eval.js +60 -0
  57. package/dist/evolver.js +302 -0
  58. package/dist/features.js +193 -0
  59. package/dist/followups.js +32 -0
  60. package/dist/forms.js +195 -0
  61. package/dist/gate.js +108 -0
  62. package/dist/gatebox.js +46 -0
  63. package/dist/grants.js +189 -0
  64. package/dist/graph.js +65 -0
  65. package/dist/guard/index.js +1 -0
  66. package/dist/guard/wire.js +1 -0
  67. package/dist/helpers.js +85 -0
  68. package/dist/hooks.js +158 -0
  69. package/dist/image-models.js +117 -0
  70. package/{src/integration.ts → dist/integration.js} +1 -2
  71. package/dist/journal.js +1 -0
  72. package/dist/look.js +363 -0
  73. package/dist/memory.js +1 -0
  74. package/dist/mode.js +97 -0
  75. package/dist/native.js +3348 -0
  76. package/dist/nogit.js +259 -0
  77. package/dist/outcomes.js +148 -0
  78. package/dist/permission.js +35 -0
  79. package/dist/pick.js +89 -0
  80. package/dist/pipelines.js +262 -0
  81. package/dist/plan.js +641 -0
  82. package/dist/plandoc.js +211 -0
  83. package/dist/plugin.js +4736 -0
  84. package/dist/policy.js +58 -0
  85. package/dist/pools.js +1 -0
  86. package/dist/preview.js +274 -0
  87. package/dist/profile.js +165 -0
  88. package/dist/progress.js +1 -0
  89. package/dist/promote.js +313 -0
  90. package/dist/redact.js +1 -0
  91. package/dist/registry.js +179 -0
  92. package/dist/riskscore.js +126 -0
  93. package/dist/roles.js +1 -0
  94. package/dist/routing.js +1 -0
  95. package/dist/runner.js +1892 -0
  96. package/{src/sandbox.ts → dist/sandbox.js} +1 -2
  97. package/dist/sandboxgate.js +90 -0
  98. package/dist/scheduler.js +170 -0
  99. package/dist/services-main.js +131 -0
  100. package/dist/services.js +265 -0
  101. package/dist/session.js +241 -0
  102. package/dist/setup.js +423 -0
  103. package/dist/shell/decide.js +1 -0
  104. package/dist/shell/index.js +2 -0
  105. package/dist/shell/sandbox.js +1 -0
  106. package/dist/shell/wire.js +1 -0
  107. package/dist/skills.js +103 -0
  108. package/dist/state.js +1 -0
  109. package/dist/store.js +1 -0
  110. package/dist/switcher.js +1 -0
  111. package/dist/synth.js +418 -0
  112. package/dist/tools.js +477 -0
  113. package/dist/trials.js +223 -0
  114. package/dist/usage.js +1 -0
  115. package/dist/wait.js +167 -0
  116. package/dist/watchdog.js +476 -0
  117. package/dist/web-guidance.js +43 -0
  118. package/dist/which.js +20 -0
  119. package/dist/worktree/git.js +545 -0
  120. package/dist/writeguard.js +311 -0
  121. package/package.json +36 -17
  122. package/skills/deck/SKILL.md +98 -0
  123. package/skills/design/SKILL.md +150 -0
  124. package/skills/image/SKILL.md +66 -0
  125. package/skills/orchestrator/SKILL.md +107 -0
  126. package/skills/video/SKILL.md +97 -0
  127. package/skills/web/SKILL.md +60 -0
  128. package/src/agenda.ts +0 -56
  129. package/src/agents.ts +0 -74
  130. package/src/ask.ts +0 -243
  131. package/src/backends.ts +0 -144
  132. package/src/backlog.ts +0 -436
  133. package/src/bench.ts +0 -163
  134. package/src/board.ts +0 -1
  135. package/src/brief.ts +0 -151
  136. package/src/browser.ts +0 -624
  137. package/src/budget.ts +0 -73
  138. package/src/catalog.ts +0 -214
  139. package/src/checkchange.ts +0 -180
  140. package/src/checkpoint.ts +0 -99
  141. package/src/cli.ts +0 -117
  142. package/src/compact.ts +0 -162
  143. package/src/config.ts +0 -340
  144. package/src/context/capture.ts +0 -1
  145. package/src/context/digest.ts +0 -1
  146. package/src/context/embed.ts +0 -1
  147. package/src/context/index.ts +0 -2
  148. package/src/context/ledger.ts +0 -1
  149. package/src/context/manager.ts +0 -1
  150. package/src/context/memory.ts +0 -1
  151. package/src/context/policy.ts +0 -1
  152. package/src/context/prices.ts +0 -1
  153. package/src/context/recall.ts +0 -1
  154. package/src/context/rules.ts +0 -1
  155. package/src/context/search.ts +0 -1
  156. package/src/context/status.ts +0 -1
  157. package/src/context/store.ts +0 -1
  158. package/src/context/summary.ts +0 -1
  159. package/src/context/tokens.ts +0 -1
  160. package/src/context/tools.ts +0 -1
  161. package/src/continuation.ts +0 -122
  162. package/src/contract.ts +0 -342
  163. package/src/contractround.ts +0 -225
  164. package/src/control.ts +0 -1
  165. package/src/dataset.ts +0 -133
  166. package/src/decide.ts +0 -690
  167. package/src/eval.ts +0 -66
  168. package/src/evolver.ts +0 -369
  169. package/src/followups.ts +0 -50
  170. package/src/forms.ts +0 -191
  171. package/src/gate.ts +0 -90
  172. package/src/grants.ts +0 -239
  173. package/src/graph.ts +0 -74
  174. package/src/guard/index.ts +0 -1
  175. package/src/guard/wire.ts +0 -1
  176. package/src/helpers.ts +0 -105
  177. package/src/hooks.ts +0 -199
  178. package/src/jev.ts +0 -141
  179. package/src/journal.ts +0 -1
  180. package/src/look.ts +0 -390
  181. package/src/memory.ts +0 -1
  182. package/src/native.ts +0 -2455
  183. package/src/nogit.ts +0 -112
  184. package/src/outcomes.ts +0 -210
  185. package/src/pick.ts +0 -112
  186. package/src/pipelines.ts +0 -252
  187. package/src/plan.ts +0 -449
  188. package/src/plugin.ts +0 -3187
  189. package/src/policy.ts +0 -84
  190. package/src/pools.ts +0 -1
  191. package/src/profile.ts +0 -186
  192. package/src/progress.ts +0 -1
  193. package/src/redact.ts +0 -1
  194. package/src/registry.ts +0 -207
  195. package/src/roles.ts +0 -1
  196. package/src/routing.ts +0 -1
  197. package/src/runner.ts +0 -1506
  198. package/src/scheduler.ts +0 -200
  199. package/src/session.ts +0 -269
  200. package/src/shell/decide.ts +0 -1
  201. package/src/shell/index.ts +0 -2
  202. package/src/shell/sandbox.ts +0 -1
  203. package/src/shell/wire.ts +0 -1
  204. package/src/skills.ts +0 -111
  205. package/src/state.ts +0 -1
  206. package/src/store.ts +0 -1
  207. package/src/switcher.ts +0 -1
  208. package/src/tools.ts +0 -480
  209. package/src/trials.ts +0 -247
  210. package/src/usage.ts +0 -1
  211. package/src/wait.ts +0 -180
  212. package/src/watchdog.ts +0 -498
  213. package/src/worktree/git.ts +0 -378
package/src/scheduler.ts DELETED
@@ -1,200 +0,0 @@
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 DELETED
@@ -1,269 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from "@omacode/sandbox/decide"
@@ -1,2 +0,0 @@
1
- export { default } from "@omacode/sandbox"
2
- export * from "@omacode/sandbox"
@@ -1 +0,0 @@
1
- export * from "@omacode/sandbox/sandbox"
package/src/shell/wire.ts DELETED
@@ -1 +0,0 @@
1
- export * from "@omacode/sandbox/wire"
package/src/skills.ts DELETED
@@ -1,111 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export * from "@omacode/state"
package/src/store.ts DELETED
@@ -1 +0,0 @@
1
- export * from "@omacode/state/store"
package/src/switcher.ts DELETED
@@ -1 +0,0 @@
1
- export * from "@omacode/tui/switcher"