@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.
Files changed (109) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +27 -2
  3. package/evolver/mm_evolve/__init__.py +1 -0
  4. package/evolver/mm_evolve/entry.py +3 -0
  5. package/evolver/mm_evolve/evaluator.py +119 -0
  6. package/evolver/mm_evolve/llm.py +76 -0
  7. package/evolver/mm_evolve/run.py +89 -0
  8. package/evolver/mm_evolve/spec.py +62 -0
  9. package/evolver/pyproject.toml +21 -0
  10. package/evolver/uv.lock +772 -0
  11. package/package.json +55 -4
  12. package/skills/THIRD_PARTY.md +58 -0
  13. package/skills/code-review/SKILL.md +46 -0
  14. package/skills/deliberate/SKILL.md +39 -0
  15. package/skills/diagnosing-bugs/SKILL.md +75 -0
  16. package/skills/receiving-code-review/SKILL.md +36 -0
  17. package/skills/research/SKILL.md +18 -0
  18. package/skills/tdd/SKILL.md +56 -0
  19. package/skills/tdd/mocking.md +59 -0
  20. package/skills/tdd/tests.md +77 -0
  21. package/skills/verification-before-completion/SKILL.md +50 -0
  22. package/src/agenda.ts +56 -0
  23. package/src/agents.ts +74 -0
  24. package/src/ask.ts +243 -0
  25. package/src/backends.ts +144 -0
  26. package/src/backlog.ts +436 -0
  27. package/src/bench.ts +163 -0
  28. package/src/board.ts +1 -0
  29. package/src/brief.ts +151 -0
  30. package/src/browser.ts +624 -0
  31. package/src/budget.ts +73 -0
  32. package/src/catalog.ts +214 -0
  33. package/src/checkchange.ts +180 -0
  34. package/src/checkpoint.ts +99 -0
  35. package/src/cli.ts +117 -0
  36. package/src/compact.ts +162 -0
  37. package/src/config.ts +340 -0
  38. package/src/context/capture.ts +1 -0
  39. package/src/context/digest.ts +1 -0
  40. package/src/context/embed.ts +1 -0
  41. package/src/context/index.ts +2 -0
  42. package/src/context/ledger.ts +1 -0
  43. package/src/context/manager.ts +1 -0
  44. package/src/context/memory.ts +1 -0
  45. package/src/context/policy.ts +1 -0
  46. package/src/context/prices.ts +1 -0
  47. package/src/context/recall.ts +1 -0
  48. package/src/context/rules.ts +1 -0
  49. package/src/context/search.ts +1 -0
  50. package/src/context/status.ts +1 -0
  51. package/src/context/store.ts +1 -0
  52. package/src/context/summary.ts +1 -0
  53. package/src/context/tokens.ts +1 -0
  54. package/src/context/tools.ts +1 -0
  55. package/src/continuation.ts +122 -0
  56. package/src/contract.ts +342 -0
  57. package/src/contractround.ts +225 -0
  58. package/src/control.ts +1 -0
  59. package/src/dataset.ts +133 -0
  60. package/src/decide.ts +690 -0
  61. package/src/eval.ts +66 -0
  62. package/src/evolver.ts +369 -0
  63. package/src/followups.ts +50 -0
  64. package/src/forms.ts +191 -0
  65. package/src/gate.ts +90 -0
  66. package/src/grants.ts +239 -0
  67. package/src/graph.ts +74 -0
  68. package/src/guard/index.ts +1 -0
  69. package/src/guard/wire.ts +1 -0
  70. package/src/helpers.ts +105 -0
  71. package/src/hooks.ts +199 -0
  72. package/src/integration.ts +4 -0
  73. package/src/jev.ts +141 -0
  74. package/src/journal.ts +1 -0
  75. package/src/look.ts +390 -0
  76. package/src/memory.ts +1 -0
  77. package/src/native.ts +2455 -0
  78. package/src/nogit.ts +112 -0
  79. package/src/outcomes.ts +210 -0
  80. package/src/pick.ts +112 -0
  81. package/src/pipelines.ts +252 -0
  82. package/src/plan.ts +449 -0
  83. package/src/plugin.ts +3187 -0
  84. package/src/policy.ts +84 -0
  85. package/src/pools.ts +1 -0
  86. package/src/profile.ts +186 -0
  87. package/src/progress.ts +1 -0
  88. package/src/redact.ts +1 -0
  89. package/src/registry.ts +207 -0
  90. package/src/roles.ts +1 -0
  91. package/src/routing.ts +1 -0
  92. package/src/runner.ts +1506 -0
  93. package/src/sandbox.ts +4 -0
  94. package/src/scheduler.ts +200 -0
  95. package/src/session.ts +269 -0
  96. package/src/shell/decide.ts +1 -0
  97. package/src/shell/index.ts +2 -0
  98. package/src/shell/sandbox.ts +1 -0
  99. package/src/shell/wire.ts +1 -0
  100. package/src/skills.ts +111 -0
  101. package/src/state.ts +1 -0
  102. package/src/store.ts +1 -0
  103. package/src/switcher.ts +1 -0
  104. package/src/tools.ts +480 -0
  105. package/src/trials.ts +247 -0
  106. package/src/usage.ts +1 -0
  107. package/src/wait.ts +180 -0
  108. package/src/watchdog.ts +498 -0
  109. package/src/worktree/git.ts +378 -0
package/src/brief.ts ADDED
@@ -0,0 +1,151 @@
1
+ // What a worker is told, and what it reports back (design.md §8.2). The brief is plain instructions: acceptance
2
+ // points and files go in verbatim. The report is short and fixed, so code can read it.
3
+
4
+ import { HEADER } from "./hooks.ts"
5
+ import type { Acceptance, FollowUp, Job, Task } from "./state.ts"
6
+
7
+ export type WorkerStatus = "DONE" | "DONE_WITH_CONCERNS" | "NEEDS_CONTEXT" | "BLOCKED"
8
+
9
+ export interface Report {
10
+ readonly status?: WorkerStatus
11
+ readonly files: string[]
12
+ readonly evidence: string
13
+ readonly open: string
14
+ readonly followUps: FollowUp[]
15
+ readonly learned: string[]
16
+ readonly text: string
17
+ }
18
+
19
+ // Caveman (design.md §13.2): text that only code or another agent reads is terse. Briefs to workers stay plain.
20
+ export const CAVEMAN = `Style (only code reads this): answer first; no greeting, recap or filler; fragments are fine. Keep every
21
+ "not", number, path, command and quote exact.`
22
+
23
+ const REPORT_FORMAT = `End your answer with this report, nothing after it:
24
+ STATUS: DONE | DONE_WITH_CONCERNS | NEEDS_CONTEXT | BLOCKED
25
+ FILES: the files you changed, comma separated, or none
26
+ EVIDENCE: the commands you ran and their results, short
27
+ OPEN: what is left open or what you need, or nothing
28
+ FOLLOWUP: work the job needs that is outside your task | why | the files it would change (one line each; leave out if none)
29
+ LEARNED: a lasting fact about this project that later tasks will need, e.g. how to run its tests or where something lives (one line each; leave out if none)
30
+ ${CAVEMAN}`
31
+
32
+ export function taskAcceptance(job: Job, task: Task): Acceptance[] {
33
+ return job.acceptance.filter((a) => task.acceptance.includes(a.id))
34
+ }
35
+
36
+ // An acceptance point several tasks cover: each task does and is judged on its own part only.
37
+ export function sharedNote(job: Job, task: Task, id: string): string {
38
+ const others = job.tasks.filter((t) => t.id !== task.id && t.acceptance.includes(id)).map((t) => t.id)
39
+ return others.length ? ` [shared with ${others.join(", ")}: only this task's part counts here]` : ""
40
+ }
41
+
42
+ export function brief(job: Job, task: Task, model: string, directory: string, skills: readonly string[] = []): string {
43
+ const acceptance = taskAcceptance(job, task)
44
+ .map((a) => `- ${a.id}: ${a.text}${a.verify ? ` (checked with: ${a.verify})` : ""}${sharedNote(job, task, a.id)}`)
45
+ .join("\n")
46
+ const done = job.tasks.filter((t) => t.status === "passed" || t.status === "merged")
47
+ const others = job.tasks.filter((t) => t.id !== task.id && !done.includes(t) && t.status !== "cancelled")
48
+ return [
49
+ `${HEADER} task ${task.id} · role ${task.role} · model ${model}`,
50
+ "",
51
+ `The job: ${job.goal}`,
52
+ "",
53
+ `Your task (${task.id}): ${task.title}`,
54
+ task.description,
55
+ "",
56
+ "Acceptance points:",
57
+ acceptance || "- none given",
58
+ "",
59
+ task.files.length ? `Files you may change: ${task.files.join(", ")}` : "Change no files.",
60
+ `Work only in ${directory}. Do only this task.`,
61
+ "Keys and tokens show as <secret> in what you read; never write <secret> into a file, leave such lines as they are.",
62
+ done.length ? `Already done: ${done.map((t) => `${t.id} ${t.title}`).join("; ")}` : "",
63
+ others.length ? `Other tasks of this job, done by others (not yours, and not follow-ups): ${others.map((t) => `${t.id} ${t.title}`).join("; ")}` : "",
64
+ job.decisions.length ? `Decisions that apply: ${job.decisions.map((d) => d.text).join("; ")}` : "",
65
+ job.lessons.length ? `Learned earlier in this job: ${job.lessons.slice(-3).join("; ")}` : "",
66
+ task.profile?.recall?.length ? `Known about this project:\n${task.profile.recall.map((r) => `- ${r}`).join("\n")}` : "",
67
+ skillLine(skills),
68
+ "",
69
+ REPORT_FORMAT,
70
+ ].filter((line, i, all) => line !== "" || all[i - 1] !== "").join("\n").trim()
71
+ }
72
+
73
+ export function skillLine(skills: readonly string[]): string {
74
+ return skills.length ? `Load these skills before you start: ${skills.join(", ")}.` : ""
75
+ }
76
+
77
+ // What a fresh session on another model is told after the previous one failed (N9 rung 2, design.md §8.2).
78
+ export function handoffText(reason: string, details: string, changed: readonly string[]): string {
79
+ return [
80
+ `A previous attempt at this task, by another model, failed: ${reason}.`,
81
+ details ? `What it ran into:\n${details.slice(0, 3000)}` : "",
82
+ changed.length ? `Files it already changed in this directory: ${changed.join(", ")}. Check them: keep what is right, fix what is wrong, and do not start over blindly.` : "It changed no file.",
83
+ `Digest: files touched: ${changed.join(", ") || "none"}; learned: ${changed.slice(-3).join(", ") || "none"}; last command: ${details.slice(0, 120) || "none"}`,
84
+ "Try another way than the previous attempt if its way kept failing.",
85
+ ].filter(Boolean).join("\n\n")
86
+ }
87
+
88
+ export function fixPrompt(failures: readonly { command: string; code: number; output: string }[]): string {
89
+ const parts = failures.map((f) => `$ ${f.command} (exit ${f.code})\n${f.output}`)
90
+ return `${HEADER} The checks of your task failed:\n\n${parts.join("\n\n")}\n\nFix the cause in your task's files, then report again in the same format.`
91
+ }
92
+
93
+ const STATUSES: readonly WorkerStatus[] = ["DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED", "DONE"]
94
+
95
+ export function parseReport(text: string): Report {
96
+ const field = (name: string) => text.match(new RegExp(`^\\s*\\**${name}\\**\\s*:\\**\\s*(.*)$`, "im"))?.[1]?.trim() ?? ""
97
+ const statusText = field("STATUS").toUpperCase()
98
+ const status = STATUSES.find((s) => statusText.startsWith(s))
99
+ const files = field("FILES")
100
+ const followUps = [...text.matchAll(/^\s*\**FOLLOWUP\**\s*:\**\s*(.+)$/gim)]
101
+ .map((m) => m[1]!.split("|").map((p) => p.trim()))
102
+ .filter(([what]) => what && !/^(none|nothing|-)$/i.test(what))
103
+ .map(([what, why, paths]): FollowUp => ({
104
+ what: what!,
105
+ why: why ?? "",
106
+ files: !paths || /^none$/i.test(paths) ? [] : paths.split(/[,\s]+/).map((f) => f.replace(/[`*]/g, "")).filter(Boolean),
107
+ }))
108
+ const learned = [...text.matchAll(/^\s*\**LEARNED\**\s*:\**\s*(.+)$/gim)].map((m) => m[1]!.trim()).filter((l) => l && !/^(none|nothing|-)$/i.test(l))
109
+ return {
110
+ status,
111
+ files: !files || /^none$/i.test(files) ? [] : files.split(/[,\s]+/).map((f) => f.replace(/[`*]/g, "")).filter(Boolean),
112
+ evidence: field("EVIDENCE"),
113
+ open: field("OPEN"),
114
+ followUps,
115
+ learned,
116
+ text,
117
+ }
118
+ }
119
+
120
+ // worker_refused (design.md §10.2): a reply without a report that reads like a safety refusal. Code decides, by
121
+ // phrasing; the patterns are conservative until the refusal probe set (A10) calibrates them.
122
+ const REFUSAL = /\b(I can(?:'|no)t (?:help|assist|do|comply|provide|write|create)|I(?:'m| am) (?:not able|unable) to (?:help|assist|comply|do)|I won't (?:help|do|write|create|be able)|I must decline|I(?:'m| am) sorry, but I can|against (?:my|the|our) (?:guidelines|policies|policy|usage policies))/i
123
+
124
+ export function refused(text: string): boolean {
125
+ return REFUSAL.test(text) && parseReport(text).status === undefined
126
+ }
127
+
128
+ // The last assistant message's text, from ctx.session.context() (shape seen in Phase A).
129
+ export function lastAssistantText(messages: unknown): string {
130
+ if (!Array.isArray(messages)) return ""
131
+ for (let i = messages.length - 1; i >= 0; i--) {
132
+ const m = messages[i] as { type?: string; content?: { type?: string; text?: string }[] }
133
+ if (m.type !== "assistant" || !Array.isArray(m.content)) continue
134
+ const text = m.content.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n").trim()
135
+ if (text) return text
136
+ }
137
+ return ""
138
+ }
139
+
140
+ // Tokens and cost of a session, summed over its assistant messages.
141
+ export function usage(messages: unknown): { tokens: number; cost: number } {
142
+ if (!Array.isArray(messages)) return { tokens: 0, cost: 0 }
143
+ let tokens = 0
144
+ let cost = 0
145
+ for (const m of messages as { type?: string; tokens?: { input?: number; output?: number }; cost?: number }[]) {
146
+ if (m.type !== "assistant") continue
147
+ tokens += (m.tokens?.input ?? 0) + (m.tokens?.output ?? 0)
148
+ cost += m.cost ?? 0
149
+ }
150
+ return { tokens, cost }
151
+ }