@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/helpers.ts DELETED
@@ -1,105 +0,0 @@
1
- // Helpers: a worker that writes asks an explorer or a researcher one question and gets the answer back as a tool result
2
- // (the explore and research tools).
3
- //
4
- // A writer used to have no way to learn anything its own tools did not reach: no web (a coder that needed an API's
5
- // docs could not read them) and no sub-agents (only the micromanager delegates, so it can count the workers). Opening
6
- // the subagent tool to workers would make every such call a new task of the job, with a worktree, a merge and a place
7
- // on the micromanager's list. A helper is none of that: it reads in the asking writer's own directory (so it sees the
8
- // writer's uncommitted change), it runs while the writer waits, it cannot ask a helper of its own, and a writer gets a
9
- // few per task. The plugin treats it like any other worker: the permission hook, the guards on web content, the watchdog
10
- // and the journal. It is not shown under the writer: the plugin's session.create drops parentID (opencode 2.0.18 passes
11
- // only id, title, agent, model, metadata, permissions and location on), so the title and the metadata name the writer.
12
-
13
- import { lastAssistantText } from "./brief.ts"
14
- import { redact } from "./jev.ts"
15
- import { roleById, type Role } from "./roles.ts"
16
- import { toModel, type SessionApi } from "./runner.ts"
17
-
18
- export type HelperRole = "explore" | "research"
19
- export const HELPER_ROLES: readonly HelperRole[] = ["explore", "research"]
20
- export const MAX_HELPERS = 3 // per writer session: enough for the questions a task raises, not a second job
21
- export const HELPER_STEPS = 60
22
- const MAX_ANSWER = 12_000
23
- const TIMEOUT_MS = 10 * 60_000
24
-
25
- // The writer asking, as the plugin knows it.
26
- export interface Caller {
27
- readonly dir: string // where the writer works: the helper reads there
28
- readonly label: string // "T3 of job-…", for the helper's title and brief
29
- readonly task: string // what the writer is working on
30
- }
31
-
32
- export interface HelperDeps {
33
- readonly session: SessionApi
34
- readonly caller: (sessionID: string) => Caller | undefined // undefined: not a writer of the micromanager
35
- readonly model: (role: Role) => Promise<string>
36
- // The helper session exists: the plugin registers it with the permission hook and the watchdog before its first turn.
37
- readonly started: (helper: string, caller: string, dir: string, brief: string) => void
38
- readonly ended?: (helper: string) => void
39
- readonly journal?: (entry: Record<string, unknown>) => void
40
- readonly timeoutMs?: number
41
- }
42
-
43
- export function helperBrief(role: HelperRole, caller: Caller, question: string): string {
44
- const how = role === "explore"
45
- ? "Answer it from the code and the git history in your directory, which holds the worker's change as it is right now, uncommitted edits included."
46
- : "Look it up in the documentation and sources on the web, and in your directory where it helps; cite the URLs you used."
47
- return [
48
- `A worker on ${caller.label} asks you one question and waits for your answer. Its task: ${caller.task}`,
49
- "",
50
- `Question: ${question}`,
51
- "",
52
- how,
53
- "Answer only what was asked, as briefly as the answer allows: paths with line numbers and short excerpts, at most about 40 lines. Change nothing. If you cannot answer it, say what you found and what is missing.",
54
- ].join("\n")
55
- }
56
-
57
- export class Helpers {
58
- readonly #d: HelperDeps
59
- readonly #used = new Map<string, number>()
60
-
61
- constructor(deps: HelperDeps) {
62
- this.#d = deps
63
- }
64
-
65
- async ask(callerSession: string, role: HelperRole, question: string): Promise<string> {
66
- const caller = this.#d.caller(callerSession)
67
- if (!caller) return "Only a worker that changes files for the micromanager may ask a helper."
68
- if (!question.trim()) return "Ask one question, in a sentence."
69
- const used = this.#used.get(callerSession) ?? 0
70
- if (used >= MAX_HELPERS) {
71
- return `You asked ${MAX_HELPERS} helpers in this task already. Work with what you have, and name what you still need in your report.`
72
- }
73
- this.#used.set(callerSession, used + 1)
74
- const r = roleById(role)!
75
- const model = await this.#d.model(r)
76
- const brief = helperBrief(role, caller, question.trim())
77
- const s = await this.#d.session.create({
78
- title: `${caller.label} · ${r.agent} · ${question.trim().slice(0, 60)}`,
79
- agent: r.agent,
80
- model: toModel(model),
81
- location: { directory: caller.dir },
82
- metadata: { micromanager: { helperOf: callerSession, task: caller.label } },
83
- })
84
- this.#d.started(s.id, callerSession, caller.dir, brief)
85
- const start = Date.now()
86
- let timer: ReturnType<typeof setTimeout> | undefined
87
- let timedOut = false
88
- try {
89
- await this.#d.session.prompt({ sessionID: s.id, text: redact(brief) })
90
- timedOut = await Promise.race([
91
- this.#d.session.wait({ sessionID: s.id }).then(() => false),
92
- new Promise<boolean>((resolve) => { timer = setTimeout(() => resolve(true), this.#d.timeoutMs ?? TIMEOUT_MS) }),
93
- ])
94
- } finally {
95
- clearTimeout(timer)
96
- }
97
- if (timedOut) await this.#d.session.interrupt({ sessionID: s.id }).catch(() => undefined)
98
- const answer = lastAssistantText(await this.#d.session.context({ sessionID: s.id }).catch(() => undefined))
99
- this.#d.ended?.(s.id)
100
- this.#d.journal?.({ kind: "helper", sessionID: callerSession, helper: s.id, role, model, question: question.slice(0, 300), chars: answer.length, ms: Date.now() - start, timedOut })
101
- if (!answer) return `The ${r.agent} ended without an answer${timedOut ? " (it ran out of time)" : ""}. Go on without it, and name the open question in your report.`
102
- const cut = answer.length > MAX_ANSWER ? `${answer.slice(0, MAX_ANSWER)}\n[cut at ${MAX_ANSWER} characters]` : answer
103
- return `${timedOut ? "[the helper ran out of time; this is what it had]\n" : ""}${cut}`
104
- }
105
- }
package/src/hooks.ts DELETED
@@ -1,199 +0,0 @@
1
- // Before the micromanager's subagent call runs: the routed model goes into the call, and the call runs in the
2
- // background (OpenCode notifies the micromanager when the worker ends; src/native.ts keeps writers in worktrees).
3
-
4
- import { chooseModel, guessNeeds, type Available, type Routing, type Spread } from "./routing.ts"
5
- import { MICROMANAGER, ROLES, roleByAgent, type Role, type RoleId } from "./roles.ts"
6
-
7
- export interface ToolCall {
8
- tool: string
9
- agent?: string // the agent making the call
10
- sessionID?: string
11
- input: Record<string, unknown>
12
- result?: unknown // tool.execute.after: what the model will see
13
- error?: unknown // tool.execute.after: why the tool failed (a hook's throw lands here too)
14
- }
15
-
16
- // The tool a delegation arrives under.
17
- //
18
- // Read in the bundled server (~/.opencode/bin/opencode, the @opencode/Tool service): opencode registers exactly one
19
- // delegation tool, `subagent`, and it carries `options.codemode:false`. That one flag settles the question of a
20
- // nested shape — Tool.snapshot builds the code-mode catalog from the tools whose codemode option is not false, so a
21
- // delegation cannot be issued from inside the code-mode `execute` tool at all. There is no second shape to
22
- // recognise, and parsing the code string would be a parser for an event that cannot happen.
23
- //
24
- // (Nested calls that do exist are surfaced individually with their real tool name, so the hook sees them normally:
25
- // Tool.execute triggers tool.execute.before per nested call, with that call's own name, input and the outer
26
- // session's id and agent. The same code path also confirms the fields a call carries: tool, sessionID, agent,
27
- // messageID, id and input.)
28
- export const DELEGATION_TOOL = "subagent"
29
-
30
- // Every tool name the delegation hook recognises, so the setup record can name them (a field operator has to be able
31
- // to read off the journal what the hook thinks it is looking at).
32
- export const DELEGATION_TOOLS: readonly string[] = [DELEGATION_TOOL]
33
-
34
- export interface Routed {
35
- readonly role: RoleId
36
- readonly model: string
37
- readonly reason: string
38
- // The chain entries the host cannot run. Absent unless the catalog said so, so an ordinary delegation is unchanged.
39
- readonly skipped?: readonly string[]
40
- }
41
-
42
- export const HEADER = "[micromanager]"
43
-
44
- // The role a call delegates to, when it delegates to one of this plugin's own role agents; undefined otherwise.
45
- //
46
- // The caller is deliberately not part of the question, and that is the whole fix for a live run of 2026-10-06: the
47
- // caller used to have to be the micromanager agent, the user switched the parent session's agent from `micromanager`
48
- // to `build`, and the ten delegations that followed (coder, tester, explorer, oracle) all returned early from that
49
- // one check. No task, no worktree, no claim, no move, no gate, no merge and not one word of it — the workers ran in
50
- // the user's checkout. The agent is a property of the session the user happens to be sitting in, not a property of
51
- // the delegation.
52
- //
53
- // What makes widening this safe is that the discriminator is the *target*: a target that is one of this plugin's own
54
- // agents cannot be anything but a delegation, and routing one can only ever narrow what the worker may do. A built-in
55
- // agent (`explore`, `general`) is not one of ours, so nothing is routed on its behalf and the call is left exactly as
56
- // its caller wrote it.
57
- export function delegationRole(call: ToolCall): Role | undefined {
58
- if (!DELEGATION_TOOLS.includes(call.tool)) return undefined
59
- return roleByAgent(String(call.input.agent ?? ""))
60
- }
61
-
62
- // Whether this call is a delegation attempt the plugin cannot isolate: the subagent tool, aimed at an agent it does
63
- // not own or at none. It is worth a journal record of its own, because a delegation that reached neither the routing
64
- // nor a refusal is precisely how a live run wrote into the user's checkout in silence.
65
- export function unownedDelegation(call: ToolCall): boolean {
66
- return call.tool === DELEGATION_TOOL && !roleByAgent(String(call.input.agent ?? ""))
67
- }
68
-
69
- // Rewrites `call.input` in place; returns what was decided, or undefined when the call is not the micromanager's.
70
- export async function routeSubagentCall(call: ToolCall, routing: Routing, workerModel?: string, available?: Available, spread?: Spread): Promise<Routed | undefined> {
71
- if (call.tool !== DELEGATION_TOOL || call.agent !== MICROMANAGER.agent) return undefined
72
- return await route(call, routing, workerModel, available, spread)
73
- }
74
-
75
- // The same routing for a delegation that the micromanager agent did not make. Narrower than the caller alone would
76
- // suggest and never wider: it returns nothing at all for a tool that is not the delegation tool.
77
- export async function routeDelegation(call: ToolCall, routing: Routing, workerModel?: string, available?: Available, spread?: Spread): Promise<Routed | undefined> {
78
- if (call.tool !== DELEGATION_TOOL) return undefined
79
- return await route(call, routing, workerModel, available, spread)
80
- }
81
-
82
- async function route(call: ToolCall, routing: Routing, workerModel?: string, available?: Available, spread?: Spread): Promise<Routed | undefined> {
83
- const role = roleByAgent(String(call.input.agent ?? ""))
84
- if (!role) return undefined // a built-in agent: left as the caller asked
85
- const prompt = String(call.input.prompt ?? "")
86
- const choice = await chooseModel(role, guessNeeds(prompt), routing, workerModel, available, spread)
87
- call.input.model = choice.model
88
- call.input.background = true
89
- if (!prompt.startsWith(HEADER)) {
90
- call.input.prompt = `${HEADER} role: ${role.id} · model: ${choice.model}\n\n${prompt}`
91
- }
92
- // skipped travels with the decision so the plugin can journal why this model and not the first of the chain.
93
- return { role: role.id, model: choice.model, reason: choice.reason, ...(choice.skipped ? { skipped: choice.skipped } : {}) }
94
- }
95
-
96
- // --- the backstop: a child of a micromanager session that no worktree ever got must not be able to write ---
97
-
98
- // The write-capable actions a permission evaluation can carry. The names are the ones opencode asserts for its own
99
- // tools (opencode.tool.edit and opencode.tool.patch both assert action "edit", the shell tool asserts "shell"), plus
100
- // the code-mode `execute` tool, which reaches everything else: a worker that may run `execute` may run a shell inside
101
- // it. Anything not listed here is a read, and a read cannot damage the checkout.
102
- const WRITES = new Set(["shell", "edit", "write", "patch", "execute"])
103
-
104
- // What the permission hook knows about a session before it lets anything change the tree.
105
- //
106
- // `parent` is the session that started it — OpenCode's own Session record, whose parentID is in the SDK's Session
107
- // type — and `parentIsMicromanager` says whether that parent is a session this plugin owns. The relation is the
108
- // discriminator because it is the one thing a delegation cannot fake and cannot lose: a plugin-recognised delegation
109
- // rewrites the child's prompt, and an unrecognised one does not, so the prompt text cannot tell them apart (and a
110
- // child's prompt is not even visible to the permission hook).
111
- export interface ChildSession {
112
- readonly sessionID: string
113
- readonly directory?: string // where the session would write
114
- readonly parent?: string // the session that started it
115
- readonly parentIsMicromanager: boolean // that parent is a session this plugin owns
116
- readonly job?: string // the job of that parent, for the journal line
117
- }
118
-
119
- export interface Denial {
120
- readonly reason: string // greppable, and says the thing that failed
121
- readonly message: string // what the agent reads instead of its write
122
- }
123
-
124
- // The refusal an unclaimed child of a micromanager session gets instead of its write, and undefined for every other
125
- // session and every other action.
126
- //
127
- // This is the part that holds when the delegation hook did not engage, which is why it does not depend on knowing how
128
- // the delegation was made: it asks only whether this session is a child of a session the plugin owns and whether the
129
- // plugin claimed it as a worker. The live run this exists for had no task, no worktree, no claim and no session move,
130
- // and nothing complained — the children were ordinary sessions of a micromanager session, and every one of their
131
- // writes went straight into the user's checkout.
132
- //
133
- // It never keys on the agent name. A user who picks a role agent by hand and works in their own checkout is not a
134
- // delegated child — it is a root session, or a child of a session that is not the plugin's — and keeps working
135
- // exactly as before. Only a session that was *started by* a micromanager session is ever caught.
136
- export function backstop(facts: ChildSession, action: string, claimed: boolean): Denial | undefined {
137
- if (claimed || !facts.parent || !facts.parentIsMicromanager) return undefined
138
- if (!WRITES.has(action)) return undefined
139
- return {
140
- reason: "isolation did not engage: a child of a micromanager session that is not a claimed worker",
141
- message: `Stopped: you were started as a sub-agent of micromanager session ${facts.parent}${facts.job ? ` (job ${facts.job})` : ""}, but the plugin never gave you a task and never put you in a worktree, so nothing of yours is checked and nothing of yours can be merged. You are in ${facts.directory ?? "a directory the plugin does not know"}; writing there would change the user's own checkout. Do not work around this and do not write anything. Stop now and report: STATUS: NEEDS_CONTEXT — say that the delegation was not isolated, that you were never placed in a worktree, and what you were asked to do.`,
142
- }
143
- }
144
-
145
- // Why a call of the micromanager was not routed, when it is about the agent name at all; undefined for every other
146
- // reason routeSubagentCall returns nothing (a call that is not the micromanager's, or one it already routed).
147
- //
148
- // routeSubagentCall leaves a built-in agent alone on purpose (it routes nothing it does not own), so the caller got
149
- // "Not started: use one of the role agents (coder, …)" for `explore` and looked for a `explore` role agent that does
150
- // not exist. The two cases need different fixes: rename the agent, or install the plugin's agents.
151
- export function notRouted(call: ToolCall): string | undefined {
152
- if (call.tool !== "subagent" || call.agent !== MICROMANAGER.agent) return undefined
153
- const asked = String(call.input.agent ?? "").trim()
154
- if (roleByAgent(asked)) return undefined // a role agent: routed, or nothing to say about the name
155
- if (asked) {
156
- return `"${asked}" is not a role agent, so nothing was started. Use one of this plugin's role agents (${ROLES.map((r) => r.agent).join(", ")}); OpenCode's own agents (explore, general, …) are not role agents here.`
157
- }
158
- return `No agent was named, so nothing was started. Name one of this plugin's role agents (${ROLES.map((r) => r.agent).join(", ")}).`
159
- }
160
-
161
- // The text of a tool result as the model sees it: result.content[] text parts, plus string fields of result.output
162
- // (shapes seen in the Phase E spike for read, shell, execute and custom tools).
163
- function textSlots(result: unknown): { get(): string; set(v: string): void }[] {
164
- const slots: { get(): string; set(v: string): void }[] = []
165
- const r = result as { content?: unknown; output?: unknown } | undefined
166
- if (!r || typeof r !== "object") return slots
167
- if (Array.isArray(r.content)) {
168
- for (const part of r.content as { text?: unknown }[]) {
169
- if (part && typeof part.text === "string") slots.push({ get: () => part.text as string, set: (v) => { part.text = v } })
170
- }
171
- }
172
- if (typeof r.output === "string") slots.push({ get: () => r.output as string, set: (v) => { r.output = v } })
173
- else if (r.output && typeof r.output === "object") {
174
- const o = r.output as Record<string, unknown>
175
- for (const key of ["output", "content", "text"]) {
176
- if (typeof o[key] === "string") slots.push({ get: () => o[key] as string, set: (v) => { o[key] = v } })
177
- }
178
- }
179
- return slots
180
- }
181
-
182
- export function resultText(result: unknown): string {
183
- return textSlots(result).map((s) => s.get()).join("\n")
184
- }
185
-
186
- // Rewrites a tool result in place before the model sees it (tool.execute.after is awaited, Phase E spike); returns
187
- // whether anything changed.
188
- export function rewriteResult(result: unknown, fn: (text: string) => string): boolean {
189
- let changed = false
190
- for (const slot of textSlots(result)) {
191
- const before = slot.get()
192
- const after = fn(before)
193
- if (after !== before) {
194
- slot.set(after)
195
- changed = true
196
- }
197
- }
198
- return changed
199
- }
package/src/jev.ts DELETED
@@ -1,141 +0,0 @@
1
- // TypeSafe Jev (System One): program state + typed questions in, typed answers with probabilities out.
2
- // Wire format: POST https://api.typesafe.ai/v1/systemone {model, state, questions} -> {model, answers, usage}
3
- // (the same shape the oc-voice project uses in decision/systemone.py).
4
-
5
- import { execFileSync } from "node:child_process"
6
-
7
- import { mapStrings, scrub } from "./redact.ts"
8
-
9
- export type Question =
10
- | { type: "choice"; instructions: string; criteria: Record<string, string> } // option id -> meaning
11
- | { type: "score"; instructions: string; criteria: string[] } // rubric levels, lowest first
12
- | { type: "noul"; instructions: string } // a statement; Jev returns the probability that it is true
13
-
14
- export type Answer =
15
- | { type: "choice"; choice: string; confidence: number; probabilities: Record<string, number> }
16
- | { type: "score"; score: number; confidence: number; probabilities: Record<string, number> }
17
- | { type: "noul"; noul: number }
18
-
19
- export interface Decision {
20
- readonly answers: Record<string, Answer>
21
- readonly model: string
22
- readonly latencyMs: number
23
- }
24
-
25
- export class JevError extends Error {}
26
-
27
- export interface JevOptions {
28
- readonly url?: string
29
- readonly model?: string
30
- readonly timeoutMs?: number
31
- readonly retries?: number // on 429/529 only
32
- readonly maxStateChars?: number
33
- readonly fetch?: typeof fetch
34
- }
35
-
36
- // The key: JEV_API_KEY, else the desktop keyring (secret-tool store --label="TypeSafe Jev API key" service typesafe key jev).
37
- export function apiKey(env: NodeJS.ProcessEnv = process.env): string | undefined {
38
- if (env.JEV_API_KEY) return env.JEV_API_KEY
39
- try {
40
- const key = execFileSync("secret-tool", ["lookup", "service", "typesafe", "key", "jev"], {
41
- encoding: "utf8",
42
- timeout: 3000,
43
- stdio: ["ignore", "pipe", "ignore"],
44
- }).trim()
45
- return key || undefined
46
- } catch {
47
- return undefined
48
- }
49
- }
50
-
51
- // Private data is swapped for the vault's placeholders before the state leaves the machine (src/redact.ts); with
52
- // redaction off, keys and tokens are still masked.
53
- export function redact(text: string): string {
54
- return scrub(text)
55
- }
56
-
57
- // The question texts carry the same private data the state does, so the wire body gets a redacted copy. The caller's
58
- // questions stay as they are: the ask flow journals them, and the local backends read them too.
59
- function wireQuestions(questions: Record<string, Question>): Record<string, Question> {
60
- const copy = JSON.parse(JSON.stringify(questions)) as Record<string, Question>
61
- mapStrings(copy, redact)
62
- return copy
63
- }
64
-
65
- export class Jev {
66
- readonly #key: string
67
- readonly #url: string
68
- readonly #model: string
69
- readonly #timeoutMs: number
70
- readonly #retries: number
71
- readonly #maxStateChars: number
72
- readonly #fetch: typeof fetch
73
-
74
- constructor(key: string, options: JevOptions = {}) {
75
- this.#key = key
76
- this.#url = options.url ?? "https://api.typesafe.ai/v1/systemone"
77
- this.#model = options.model ?? "jev-latest"
78
- this.#timeoutMs = options.timeoutMs ?? 3000
79
- this.#retries = options.retries ?? 1
80
- this.#maxStateChars = options.maxStateChars ?? 24000
81
- this.#fetch = options.fetch ?? fetch
82
- }
83
-
84
- async ask(state: string, questions: Record<string, Question>): Promise<Decision> {
85
- // The newest part of the state is at the end; a cut keeps it.
86
- const cut = state.length > this.#maxStateChars ? state.slice(-this.#maxStateChars) : state
87
- const body = JSON.stringify({ model: this.#model, state: redact(cut), questions: wireQuestions(questions) })
88
- const started = Date.now()
89
- for (let attempt = 0; ; attempt++) {
90
- let response: Response
91
- try {
92
- response = await this.#fetch(this.#url, {
93
- method: "POST",
94
- headers: { Authorization: `Bearer ${this.#key}`, "Content-Type": "application/json" },
95
- body,
96
- signal: AbortSignal.timeout(this.#timeoutMs),
97
- })
98
- } catch (err) {
99
- throw new JevError(`Jev unreachable: ${err instanceof Error ? err.name : String(err)}`)
100
- }
101
- if ((response.status === 429 || response.status === 529) && attempt < this.#retries) {
102
- await new Promise((resolve) => setTimeout(resolve, 200 * 2 ** attempt))
103
- continue
104
- }
105
- if (response.status === 401) throw new JevError("Jev: API key rejected (401)")
106
- if (response.status !== 200) throw new JevError(`Jev: HTTP ${response.status}`)
107
- const payload = (await response.json()) as { model?: string; answers?: Record<string, unknown> }
108
- return { answers: parseAnswers(questions, payload.answers ?? {}), model: payload.model ?? this.#model, latencyMs: Date.now() - started }
109
- }
110
- }
111
- }
112
-
113
- function num(value: unknown, what: string): number {
114
- if (typeof value !== "number" || Number.isNaN(value)) throw new JevError(`Jev: missing numeric ${what}`)
115
- return value
116
- }
117
-
118
- function probs(value: unknown): Record<string, number> {
119
- if (!value || typeof value !== "object") return {}
120
- return Object.fromEntries(Object.entries(value).filter(([, v]) => typeof v === "number")) as Record<string, number>
121
- }
122
-
123
- export function parseAnswers(questions: Record<string, Question>, raw: Record<string, unknown>): Record<string, Answer> {
124
- const answers: Record<string, Answer> = {}
125
- for (const [id, question] of Object.entries(questions)) {
126
- const data = raw[id] as Record<string, unknown> | undefined
127
- if (!data) continue
128
- if (question.type === "choice") {
129
- const choice = data.choice
130
- if (typeof choice !== "string" || !(choice in question.criteria)) throw new JevError(`Jev: ${id}: choice not offered`)
131
- answers[id] = { type: "choice", choice, confidence: num(data.confidence, `${id}.confidence`), probabilities: probs(data.probabilities) }
132
- } else if (question.type === "score") {
133
- answers[id] = { type: "score", score: num(data.score, `${id}.score`), confidence: num(data.confidence, `${id}.confidence`), probabilities: probs(data.probabilities) }
134
- } else {
135
- const noul = num(data.noul, `${id}.noul`)
136
- if (noul < 0 || noul > 1) throw new JevError(`Jev: ${id}: noul outside 0..1`)
137
- answers[id] = { type: "noul", noul }
138
- }
139
- }
140
- return answers
141
- }
package/src/journal.ts DELETED
@@ -1 +0,0 @@
1
- export * from "@omacode/core/journal"