@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.
- package/README.md +7 -4
- package/THIRD_PARTY.md +100 -0
- package/decider/.python-version +1 -0
- package/decider/README.md +35 -0
- package/decider/decider/__init__.py +1 -0
- package/decider/decider/server.py +327 -0
- package/decider/pyproject.toml +34 -0
- package/decider/uv.lock +1255 -0
- package/dist/agenda.js +51 -0
- package/dist/agents.js +58 -0
- package/dist/artifact/handoff.js +281 -0
- package/dist/ask.js +200 -0
- package/dist/backends.js +219 -0
- package/dist/backlog.js +414 -0
- package/dist/bench.js +427 -0
- package/dist/board.js +1 -0
- package/dist/brief.js +202 -0
- package/dist/browser.js +679 -0
- package/dist/budget.js +61 -0
- package/dist/catalog.js +187 -0
- package/dist/checkchange.js +145 -0
- package/dist/checkpoint.js +94 -0
- package/dist/cli.js +764 -0
- package/dist/comfy-gate.js +258 -0
- package/dist/compact.js +142 -0
- package/dist/config.js +344 -0
- package/dist/context/capture.js +1 -0
- package/dist/context/digest.js +1 -0
- package/dist/context/embed.js +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/ledger.js +1 -0
- package/dist/context/manager.js +1 -0
- package/dist/context/memory.js +1 -0
- package/dist/context/policy.js +1 -0
- package/dist/context/prices.js +1 -0
- package/dist/context/recall.js +1 -0
- package/dist/context/rules.js +1 -0
- package/dist/context/search.js +1 -0
- package/dist/context/status.js +1 -0
- package/dist/context/store.js +1 -0
- package/dist/context/summary.js +1 -0
- package/dist/context/tokens.js +1 -0
- package/dist/context/tools.js +1 -0
- package/dist/continuation.js +184 -0
- package/dist/contract.js +294 -0
- package/dist/contractround.js +178 -0
- package/dist/control.js +1 -0
- package/dist/creative-tools.js +237 -0
- package/dist/dataset.js +175 -0
- package/dist/decide.js +676 -0
- package/dist/decider.js +171 -0
- package/dist/design-shell.js +448 -0
- package/dist/design.js +1410 -0
- package/dist/desktop.js +44 -0
- package/dist/egress.js +156 -0
- package/dist/eval.js +60 -0
- package/dist/evolver.js +302 -0
- package/dist/features.js +193 -0
- package/dist/followups.js +32 -0
- package/dist/forms.js +195 -0
- package/dist/gate.js +108 -0
- package/dist/gatebox.js +46 -0
- package/dist/grants.js +189 -0
- package/dist/graph.js +65 -0
- package/dist/guard/index.js +1 -0
- package/dist/guard/wire.js +1 -0
- package/dist/helpers.js +85 -0
- package/dist/hooks.js +158 -0
- package/dist/image-models.js +117 -0
- package/{src/integration.ts → dist/integration.js} +1 -2
- package/dist/journal.js +1 -0
- package/dist/look.js +363 -0
- package/dist/memory.js +1 -0
- package/dist/mode.js +97 -0
- package/dist/native.js +3348 -0
- package/dist/nogit.js +259 -0
- package/dist/outcomes.js +148 -0
- package/dist/permission.js +35 -0
- package/dist/pick.js +89 -0
- package/dist/pipelines.js +262 -0
- package/dist/plan.js +641 -0
- package/dist/plandoc.js +211 -0
- package/dist/plugin.js +4736 -0
- package/dist/policy.js +58 -0
- package/dist/pools.js +1 -0
- package/dist/preview.js +274 -0
- package/dist/profile.js +165 -0
- package/dist/progress.js +1 -0
- package/dist/promote.js +313 -0
- package/dist/redact.js +1 -0
- package/dist/registry.js +179 -0
- package/dist/riskscore.js +126 -0
- package/dist/roles.js +1 -0
- package/dist/routing.js +1 -0
- package/dist/runner.js +1892 -0
- package/{src/sandbox.ts → dist/sandbox.js} +1 -2
- package/dist/sandboxgate.js +90 -0
- package/dist/scheduler.js +170 -0
- package/dist/services-main.js +131 -0
- package/dist/services.js +265 -0
- package/dist/session.js +241 -0
- package/dist/setup.js +423 -0
- package/dist/shell/decide.js +1 -0
- package/dist/shell/index.js +2 -0
- package/dist/shell/sandbox.js +1 -0
- package/dist/shell/wire.js +1 -0
- package/dist/skills.js +103 -0
- package/dist/state.js +1 -0
- package/dist/store.js +1 -0
- package/dist/switcher.js +1 -0
- package/dist/synth.js +418 -0
- package/dist/tools.js +477 -0
- package/dist/trials.js +223 -0
- package/dist/usage.js +1 -0
- package/dist/wait.js +167 -0
- package/dist/watchdog.js +476 -0
- package/dist/web-guidance.js +43 -0
- package/dist/which.js +20 -0
- package/dist/worktree/git.js +545 -0
- package/dist/writeguard.js +311 -0
- package/package.json +36 -17
- package/skills/deck/SKILL.md +98 -0
- package/skills/design/SKILL.md +150 -0
- package/skills/image/SKILL.md +66 -0
- package/skills/orchestrator/SKILL.md +107 -0
- package/skills/video/SKILL.md +97 -0
- package/skills/web/SKILL.md +60 -0
- package/src/agenda.ts +0 -56
- package/src/agents.ts +0 -74
- package/src/ask.ts +0 -243
- package/src/backends.ts +0 -144
- package/src/backlog.ts +0 -436
- package/src/bench.ts +0 -163
- package/src/board.ts +0 -1
- package/src/brief.ts +0 -151
- package/src/browser.ts +0 -624
- package/src/budget.ts +0 -73
- package/src/catalog.ts +0 -214
- package/src/checkchange.ts +0 -180
- package/src/checkpoint.ts +0 -99
- package/src/cli.ts +0 -117
- package/src/compact.ts +0 -162
- package/src/config.ts +0 -340
- package/src/context/capture.ts +0 -1
- package/src/context/digest.ts +0 -1
- package/src/context/embed.ts +0 -1
- package/src/context/index.ts +0 -2
- package/src/context/ledger.ts +0 -1
- package/src/context/manager.ts +0 -1
- package/src/context/memory.ts +0 -1
- package/src/context/policy.ts +0 -1
- package/src/context/prices.ts +0 -1
- package/src/context/recall.ts +0 -1
- package/src/context/rules.ts +0 -1
- package/src/context/search.ts +0 -1
- package/src/context/status.ts +0 -1
- package/src/context/store.ts +0 -1
- package/src/context/summary.ts +0 -1
- package/src/context/tokens.ts +0 -1
- package/src/context/tools.ts +0 -1
- package/src/continuation.ts +0 -122
- package/src/contract.ts +0 -342
- package/src/contractround.ts +0 -225
- package/src/control.ts +0 -1
- package/src/dataset.ts +0 -133
- package/src/decide.ts +0 -690
- package/src/eval.ts +0 -66
- package/src/evolver.ts +0 -369
- package/src/followups.ts +0 -50
- package/src/forms.ts +0 -191
- package/src/gate.ts +0 -90
- package/src/grants.ts +0 -239
- package/src/graph.ts +0 -74
- package/src/guard/index.ts +0 -1
- package/src/guard/wire.ts +0 -1
- package/src/helpers.ts +0 -105
- package/src/hooks.ts +0 -199
- package/src/jev.ts +0 -141
- package/src/journal.ts +0 -1
- package/src/look.ts +0 -390
- package/src/memory.ts +0 -1
- package/src/native.ts +0 -2455
- package/src/nogit.ts +0 -112
- package/src/outcomes.ts +0 -210
- package/src/pick.ts +0 -112
- package/src/pipelines.ts +0 -252
- package/src/plan.ts +0 -449
- package/src/plugin.ts +0 -3187
- package/src/policy.ts +0 -84
- package/src/pools.ts +0 -1
- package/src/profile.ts +0 -186
- package/src/progress.ts +0 -1
- package/src/redact.ts +0 -1
- package/src/registry.ts +0 -207
- package/src/roles.ts +0 -1
- package/src/routing.ts +0 -1
- package/src/runner.ts +0 -1506
- package/src/scheduler.ts +0 -200
- package/src/session.ts +0 -269
- package/src/shell/decide.ts +0 -1
- package/src/shell/index.ts +0 -2
- package/src/shell/sandbox.ts +0 -1
- package/src/shell/wire.ts +0 -1
- package/src/skills.ts +0 -111
- package/src/state.ts +0 -1
- package/src/store.ts +0 -1
- package/src/switcher.ts +0 -1
- package/src/tools.ts +0 -480
- package/src/trials.ts +0 -247
- package/src/usage.ts +0 -1
- package/src/wait.ts +0 -180
- package/src/watchdog.ts +0 -498
- package/src/worktree/git.ts +0 -378
package/src/contractround.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
// The contract round (design.md §25, P5): how a fitness contract is worked out before any writer is measured against
|
|
2
|
-
// it. A draft contract says what one model thinks "better" means; the round makes it the user's:
|
|
3
|
-
// 1. draft: a reader reads the code, the tests and the data and writes the contract as JSON (the contract tool
|
|
4
|
-
// measures its baseline);
|
|
5
|
-
// 2. prefs: the user picks what decides, which guards stay and how far they may give, and the target, in a form;
|
|
6
|
-
// 3. redteam: a writer of another model family tries to raise the score WITHOUT improving the goal, in its own
|
|
7
|
-
// worktree, never merged; every loophole it reports can become a guard;
|
|
8
|
-
// 4. loopholes: the user picks the loopholes to close, in a form;
|
|
9
|
-
// 5. baseline: today's code measured again, three times on both corpora, and shown with its spread: "does this measure
|
|
10
|
-
// what I mean?";
|
|
11
|
-
// 6. frozen: the evaluator and the visible corpus are hashed (a worker cannot change them), and writers may be
|
|
12
|
-
// measured against it from now on.
|
|
13
|
-
// The micromanager drives it with contract_round and the forms; the plugin keeps the state on the contract.
|
|
14
|
-
|
|
15
|
-
import { formInput, type Question } from "./forms.ts"
|
|
16
|
-
import type { Contract, Direction, Guard, Measured } from "./contract.ts"
|
|
17
|
-
|
|
18
|
-
export type RoundStep = "prefs" | "redteam" | "loopholes" | "baseline" | "frozen"
|
|
19
|
-
|
|
20
|
-
export interface Loophole {
|
|
21
|
-
readonly what: string
|
|
22
|
-
readonly guard?: Guard // the guard that closes it, when the red team could name one
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Round {
|
|
26
|
-
step: RoundStep
|
|
27
|
-
loopholes: Loophole[]
|
|
28
|
-
redteam?: string // the red team's task id
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
declare module "./contract.ts" {
|
|
32
|
-
interface Contract {
|
|
33
|
-
round?: Round
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare module "./state.ts" {
|
|
38
|
-
interface Task {
|
|
39
|
-
redteam?: string // the contract this writer tries to game, for its round; never merged
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// What the drafter is asked: a contract as the contract tool takes it, from what the project has.
|
|
44
|
-
export function draftPrompt(goal: string): string {
|
|
45
|
-
return [
|
|
46
|
-
`Work out a fitness contract for this goal: ${goal}`,
|
|
47
|
-
"Read the code, the tests, the benchmarks and the data the project has, then write what \"better\" means as JSON, in a ```json fence at the end of your answer:",
|
|
48
|
-
'{"goal": what the work is for; "evaluator": one shell command, run in the project directory, that prints a line MM_SCORE {"scores": {"<name>": <number>, …}, "cases": {"passed": n, "total": m}} and exits 0 (a crash, a timeout or a wrong output must make it exit non-zero); "scores": [{"name", "direction": "min"|"max", "noise": the relative spread two runs of the same code show}] (the first decides); "guards": [{"name", "direction", "tolerance": 0.05}] (values that must not get worse: correctness counts, sizes, memory; each one a way to raise the score without improving the goal that it closes); "corpus": {"visible": [the project paths it measures on]}; "repeats": 3 for timings, 1 otherwise; "timeoutSeconds"; "stop": {"evaluations": n}}',
|
|
49
|
-
"If the project has no command that measures this yet, say so plainly and describe the script that would (its path, what it runs, what it prints): a writer makes it first. Do not invent numbers.",
|
|
50
|
-
"Name what you are unsure about: which inputs matter, which thresholds are good enough. The user decides those next.",
|
|
51
|
-
].join("\n")
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// What the red team is told: game the number, report how.
|
|
55
|
-
export function redteamPrompt(c: Contract): string {
|
|
56
|
-
return [
|
|
57
|
-
`You are the red team of fitness contract ${c.id}: ${c.goal}`,
|
|
58
|
-
`Try to raise its score without improving the goal itself: special-case the inputs it measures, skip the work when it is measured, cache what it reads, weaken what it checks, change what it counts. The plugin measures your change with \`${c.evaluator}\` when your checks pass; your work is never merged.`,
|
|
59
|
-
"End your report with one line per way you found, whether it worked or not:",
|
|
60
|
-
"LOOPHOLE: what you did and what the score did | guard: <a measured value> <min|max> <tolerance> (the guard that would catch it, if a value the evaluator prints already shows it; leave out the part after | if none does)",
|
|
61
|
-
].join("\n")
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// The red team's LOOPHOLE lines, with the guard each one names when it names one the contract can measure.
|
|
65
|
-
export function parseLoopholes(report: string): Loophole[] {
|
|
66
|
-
return [...report.matchAll(/^\s*\**LOOPHOLE\**\s*:\**\s*(.+)$/gim)]
|
|
67
|
-
.map((m) => m[1]!.split("|").map((p) => p.trim()))
|
|
68
|
-
.filter(([what]) => what && !/^(none|nothing|-)$/i.test(what))
|
|
69
|
-
.slice(0, 8)
|
|
70
|
-
.map(([what, guard]) => {
|
|
71
|
-
const g = guard?.match(/^guard:\s*([A-Za-z_][\w.-]*)\s+(min|max)\s+([\d.]+)\s*%?$/i)
|
|
72
|
-
if (!g) return { what: what! }
|
|
73
|
-
const tolerance = Number(g[3]) > 1 ? Number(g[3]) / 100 : Number(g[3])
|
|
74
|
-
return { what: what!, guard: { name: g[1]!, direction: g[2]!.toLowerCase() as Direction, tolerance, origin: "redteam" as const } }
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const KEEP = { none: "No target: run to the budget" } as const
|
|
79
|
-
const BASELINE = { plausible: "Plausible: freeze it", again: "Measure again", change: "Change the contract" } as const
|
|
80
|
-
const TOLERANCE: Record<string, number> = { "Not at all (0 %)": 0, "A little (5 %)": 0.05, "Some (20 %)": 0.2 }
|
|
81
|
-
const TARGETS: Record<string, number> = { "10 % better": 0.1, "25 % better": 0.25, "50 % better": 0.5 }
|
|
82
|
-
|
|
83
|
-
export const roundHeader = (c: Pick<Contract, "id">, part: "preferences" | "decides" | "guards" | "target" | "red team" | "loopholes" | "baseline") => `${c.id} ${part}`
|
|
84
|
-
|
|
85
|
-
// The user's preferences: what decides, which guards stay and how far they may give, the target, and whether a red
|
|
86
|
-
// team tries the contract first.
|
|
87
|
-
export function prefsForm(c: Contract): Question[] {
|
|
88
|
-
const form: Question[] = [{
|
|
89
|
-
header: roundHeader(c, "decides"),
|
|
90
|
-
question: `Contract ${c.id} (${c.goal.slice(0, 120)}): which score decides? Today: ${c.scores.map((s) => `${s.name} ${c.baseline?.values[s.name] ?? "?"} (${s.direction === "min" ? "lower" : "higher"} is better)`).join(", ")}.`,
|
|
91
|
-
options: c.scores.map((s, i) => ({ label: s.name, description: `${s.direction === "min" ? "Lower" : "Higher"} is better${i === 0 ? " (the draft's choice)" : ""}` })),
|
|
92
|
-
}]
|
|
93
|
-
if (c.guards.length) {
|
|
94
|
-
form.push({
|
|
95
|
-
header: roundHeader(c, "guards"),
|
|
96
|
-
question: "Which of these must not get worse? Each closes a way to raise the score without improving the goal. Tick the ones to keep; none ticked keeps none.",
|
|
97
|
-
multiple: true,
|
|
98
|
-
options: c.guards.map((g) => ({ label: g.name, description: `${g.direction === "min" ? "lower" : "higher"} is better; today ${c.baseline?.values[g.name] ?? "?"}` })),
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
form.push(
|
|
102
|
-
{
|
|
103
|
-
header: roundHeader(c, "preferences"),
|
|
104
|
-
question: "How much may a guard get worse than today?",
|
|
105
|
-
options: Object.keys(TOLERANCE).map((label) => ({ label, description: label.startsWith("Not") ? "Any change for the worse fails" : "Room for noise and small trade-offs" })),
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
header: roundHeader(c, "target"),
|
|
109
|
-
question: `When is it good enough? The work stops early once the deciding score is this much better than today${c.stop.evaluations ? `, and after ${c.stop.evaluations} evaluations in any case` : ""}.`,
|
|
110
|
-
options: [...Object.keys(TARGETS).map((label) => ({ label, description: "Than today's value of the deciding score" })), { label: KEEP.none, description: "Keep improving until the budget or the stop rule ends it" }],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
header: roundHeader(c, "red team"),
|
|
114
|
-
question: "Should a red team try to game the score first (a worker on another model, about one task's cost)?",
|
|
115
|
-
options: [{ label: "Yes, red team first", description: "Each loophole it finds can become a guard" }, { label: "No, skip it", description: "Go straight to the baseline check" }],
|
|
116
|
-
},
|
|
117
|
-
)
|
|
118
|
-
return form
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface Prefs {
|
|
122
|
-
readonly decides?: string
|
|
123
|
-
readonly guards?: readonly string[] // undefined: the question was not asked
|
|
124
|
-
readonly tolerance?: number
|
|
125
|
-
readonly target?: number | null // null: no target
|
|
126
|
-
readonly redteam: boolean
|
|
127
|
-
readonly said?: string // text the user typed instead of a label
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const clean = (a: string) => a.trim().replace(/\s*\(recommended\)\s*$/i, "")
|
|
131
|
-
|
|
132
|
-
// The answers to the preferences form; typed text in place of a target or a tolerance is read as a number where it is
|
|
133
|
-
// one ("15", "15 %").
|
|
134
|
-
export function readPrefs(c: Contract, questions: readonly Partial<Question>[], answers: readonly (readonly string[])[]): Prefs {
|
|
135
|
-
const of = (part: Parameters<typeof roundHeader>[1]) => {
|
|
136
|
-
const i = questions.findIndex((q) => q.header === roundHeader(c, part))
|
|
137
|
-
return i >= 0 ? (answers[i] ?? []).map(clean) : undefined
|
|
138
|
-
}
|
|
139
|
-
const pct = (s: string) => {
|
|
140
|
-
const m = s.match(/^(\d+(?:\.\d+)?)\s*%?$/)
|
|
141
|
-
return m ? Number(m[1]) / 100 : undefined
|
|
142
|
-
}
|
|
143
|
-
const decides = of("decides")?.find((a) => c.scores.some((s) => s.name === a))
|
|
144
|
-
const guards = of("guards")?.filter((a) => c.guards.some((g) => g.name === a))
|
|
145
|
-
const tol = of("preferences")?.[0]
|
|
146
|
-
const tolerance = tol === undefined ? undefined : TOLERANCE[tol] ?? pct(tol)
|
|
147
|
-
const tg = of("target")?.[0]
|
|
148
|
-
const target = tg === undefined ? undefined : tg === KEEP.none ? null : TARGETS[tg] ?? pct(tg) ?? undefined
|
|
149
|
-
const said = [...(of("decides") ?? []), ...(of("target") ?? [])].find((a) => a && !c.scores.some((s) => s.name === a) && TARGETS[a] === undefined && a !== KEEP.none && pct(a) === undefined)
|
|
150
|
-
return { ...(decides ? { decides } : {}), ...(guards ? { guards } : {}), ...(tolerance !== undefined ? { tolerance } : {}), ...(target !== undefined ? { target } : {}), redteam: !(of("red team") ?? []).some((a) => a.startsWith("No")), ...(said ? { said } : {}) }
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// The preferences, applied: the deciding score first, the guards the user kept with their tolerance, and the target
|
|
154
|
-
// as a value of the deciding score.
|
|
155
|
-
export function applyPrefs(c: Contract, p: Prefs): void {
|
|
156
|
-
if (p.decides) c.scores = [...c.scores.filter((s) => s.name === p.decides), ...c.scores.filter((s) => s.name !== p.decides)]
|
|
157
|
-
if (p.guards) c.guards = c.guards.filter((g) => p.guards!.includes(g.name))
|
|
158
|
-
if (p.tolerance !== undefined) c.guards = c.guards.map((g) => ({ ...g, tolerance: p.tolerance! }))
|
|
159
|
-
const first = c.scores[0]!
|
|
160
|
-
const base = c.baseline?.values[first.name]
|
|
161
|
-
if (p.target === null) c.stop = { ...c.stop, target: undefined }
|
|
162
|
-
else if (p.target !== undefined && base !== undefined) {
|
|
163
|
-
const goal = first.direction === "min" ? base * (1 - p.target) : base * (1 + p.target)
|
|
164
|
-
c.stop = { ...c.stop, target: { [first.name]: Math.round(goal * 1000) / 1000 } }
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// The loopholes the red team found, for the user to close.
|
|
169
|
-
export function loopholeForm(c: Contract): Question[] {
|
|
170
|
-
return [{
|
|
171
|
-
header: roundHeader(c, "loopholes"),
|
|
172
|
-
question: `The red team of contract ${c.id} found these ways to raise the score without improving the goal. Tick the ones to close (a guard is added where it named one; the others are noted for the corpus):`,
|
|
173
|
-
multiple: true,
|
|
174
|
-
options: (c.round?.loopholes ?? []).map((l, i) => ({ label: `L${i + 1}`, description: `${l.what.slice(0, 160)}${l.guard ? ` (guard: ${l.guard.name} ${l.guard.direction} ${Math.round(l.guard.tolerance * 100)} %)` : ""}` })),
|
|
175
|
-
}]
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function readLoopholes(answers: readonly string[]): number[] {
|
|
179
|
-
return answers.map(clean).flatMap((a) => (/^L\d+$/.test(a) ? [Number(a.slice(1)) - 1] : []))
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// The baseline as the user sees it before the freeze: each score's median and spread over the runs, on both corpora.
|
|
183
|
-
export function baselineForm(c: Contract, runs: { visible: readonly Measured[]; heldOut: readonly Measured[] }, seconds: number): Question[] {
|
|
184
|
-
const spread = (ms: readonly Measured[], name: string) => {
|
|
185
|
-
const xs = ms.filter((m) => m.valid).map((m) => m.values[name]).filter((v): v is number => v !== undefined)
|
|
186
|
-
if (!xs.length) return "no valid run"
|
|
187
|
-
const lo = Math.min(...xs)
|
|
188
|
-
const hi = Math.max(...xs)
|
|
189
|
-
return lo === hi ? `${lo}` : `${lo} to ${hi}`
|
|
190
|
-
}
|
|
191
|
-
const values = c.scores.map((s) => `${s.name}: ${spread(runs.visible, s.name)}${runs.heldOut.length ? `, held-out ${spread(runs.heldOut, s.name)}` : ""}`).join("; ")
|
|
192
|
-
return [{
|
|
193
|
-
header: roundHeader(c, "baseline"),
|
|
194
|
-
question: `Today's code under contract ${c.id}, ${runs.visible.length} runs (${seconds}s in all): ${values}. Does this measure what you mean?`,
|
|
195
|
-
options: [
|
|
196
|
-
{ label: BASELINE.plausible, description: "The evaluator and its corpus are frozen; writers are measured against it from now on" },
|
|
197
|
-
{ label: BASELINE.again, description: "Run the baseline again" },
|
|
198
|
-
{ label: BASELINE.change, description: "Say what is wrong; the contract comes back as a new draft" },
|
|
199
|
-
],
|
|
200
|
-
}]
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function readBaseline(answers: readonly string[]): { decision?: "plausible" | "again" | "change"; said?: string } {
|
|
204
|
-
for (const a of answers.map(clean)) {
|
|
205
|
-
const k = (Object.keys(BASELINE) as (keyof typeof BASELINE)[]).find((x) => BASELINE[x].toLowerCase() === a.toLowerCase())
|
|
206
|
-
if (k) return { decision: k }
|
|
207
|
-
}
|
|
208
|
-
const said = answers.find((a) => a.trim())
|
|
209
|
-
return said ? { said: said.trim() } : {}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Which contract and which of its forms a submitted form is, from its headers; undefined for any other form.
|
|
213
|
-
export function roundFormOf(questions: readonly Partial<Question>[]): { id: string; part: "prefs" | "loopholes" | "baseline" } | undefined {
|
|
214
|
-
for (const q of questions) {
|
|
215
|
-
const m = q.header?.match(/^(C\d+) (decides|guards|preferences|target|red team|loopholes|baseline)$/)
|
|
216
|
-
if (!m) continue
|
|
217
|
-
return { id: m[1]!, part: m[2] === "loopholes" ? "loopholes" : m[2] === "baseline" ? "baseline" : "prefs" }
|
|
218
|
-
}
|
|
219
|
-
return undefined
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// The instruction that puts a form to the user.
|
|
223
|
-
export function askWith(form: readonly Question[], what: string): string {
|
|
224
|
-
return `${what} Ask the user with the question tool, with exactly this input (a form; its answer reaches the plugin by itself), then end your turn:\n${formInput(form)}`
|
|
225
|
-
}
|
package/src/control.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@omacode/state/control"
|
package/src/dataset.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Training rows from the journal (design.md §15, §20): Open-Jev JSONL for a local Jev, GLiNER2 JSO lines for the
|
|
2
|
-
// decision server's fine-tune.
|
|
3
|
-
//
|
|
4
|
-
// A row's target is, in this order: a label the user gave or an outcome (one-hot, the strongest), else the cloud
|
|
5
|
-
// Jev's own probabilities (a soft distillation target). Answers of GLiNER or the rules are never targets.
|
|
6
|
-
|
|
7
|
-
import { createHash } from "node:crypto"
|
|
8
|
-
|
|
9
|
-
import type { Answer, Question } from "./jev.ts"
|
|
10
|
-
import type { Entry } from "./journal.ts"
|
|
11
|
-
|
|
12
|
-
export interface Labeled {
|
|
13
|
-
readonly entry: Entry // the decision
|
|
14
|
-
readonly qid: string
|
|
15
|
-
readonly question: Question
|
|
16
|
-
readonly answer?: Answer
|
|
17
|
-
readonly label?: { readonly value: string | number; readonly source: string }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Joins every decision question with its newest label.
|
|
21
|
-
export function labeled(entries: readonly Entry[]): Labeled[] {
|
|
22
|
-
const labels = new Map<string, { value: string | number; source: string }>()
|
|
23
|
-
for (const e of entries) {
|
|
24
|
-
if (e.kind === "label" && typeof e.decision === "string" && typeof e.question === "string") {
|
|
25
|
-
labels.set(`${e.decision}/${e.question}`, { value: e.value as string | number, source: String(e.source) })
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const out: Labeled[] = []
|
|
29
|
-
for (const e of entries) {
|
|
30
|
-
if (e.kind !== "decision" || typeof e.id !== "string") continue
|
|
31
|
-
const questions = (e.questions ?? {}) as Record<string, Question>
|
|
32
|
-
const answers = (e.answers ?? {}) as Record<string, Answer>
|
|
33
|
-
for (const [qid, question] of Object.entries(questions)) {
|
|
34
|
-
out.push({ entry: e, qid, question, answer: answers[qid], label: labels.get(`${e.id}/${qid}`) })
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return out
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function options(q: Question): string[] {
|
|
41
|
-
if (q.type === "choice") return Object.keys(q.criteria)
|
|
42
|
-
if (q.type === "noul") return ["no", "yes"]
|
|
43
|
-
return [...q.criteria]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// The target distribution over options(), or undefined when nothing may serve as a target.
|
|
47
|
-
export function target(row: Labeled): { probs: number[]; source: string } | undefined {
|
|
48
|
-
const opts = options(row.question)
|
|
49
|
-
if (row.label) {
|
|
50
|
-
const v = row.label.value
|
|
51
|
-
const index = row.question.type === "noul"
|
|
52
|
-
? (v === "yes" || v === 1 ? 1 : 0)
|
|
53
|
-
: row.question.type === "score" && typeof v === "number" ? Math.round(v) : opts.indexOf(String(v))
|
|
54
|
-
if (index < 0 || index >= opts.length) return undefined
|
|
55
|
-
return { probs: opts.map((_, i) => (i === index ? 1 : 0)), source: row.label.source }
|
|
56
|
-
}
|
|
57
|
-
if (row.entry.backend !== "typesafe" || !row.answer) return undefined
|
|
58
|
-
const a = row.answer
|
|
59
|
-
if (a.type === "noul") return { probs: [1 - a.noul, a.noul], source: "jev" }
|
|
60
|
-
const p = opts.map((o, i) => a.probabilities[o] ?? a.probabilities[String(i)] ?? 0)
|
|
61
|
-
const sum = p.reduce((x, y) => x + y, 0)
|
|
62
|
-
if (sum <= 0) return undefined
|
|
63
|
-
return { probs: p.map((x) => x / sum), source: "jev" }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 80 / 5 / 5 / 10 by a hash of the group, so one job or task never spans two splits.
|
|
67
|
-
export function splitOf(group: string): "train" | "calibration" | "validation" | "test" {
|
|
68
|
-
const n = parseInt(createHash("sha256").update(group).digest("hex").slice(0, 8), 16) % 100
|
|
69
|
-
return n < 80 ? "train" : n < 85 ? "calibration" : n < 90 ? "validation" : "test"
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const groupOf = (e: Entry) => String(e.task ?? e.job ?? e.id)
|
|
73
|
-
|
|
74
|
-
export function openJevRows(entries: readonly Entry[]): Record<string, unknown>[] {
|
|
75
|
-
return labeled(entries).flatMap((row) => {
|
|
76
|
-
const t = target(row)
|
|
77
|
-
if (!t) return []
|
|
78
|
-
const group = groupOf(row.entry)
|
|
79
|
-
return [{
|
|
80
|
-
id: `${row.entry.id}/${row.qid}`,
|
|
81
|
-
group_id: group,
|
|
82
|
-
split: splitOf(group),
|
|
83
|
-
source: "micromanager",
|
|
84
|
-
state: row.entry.state,
|
|
85
|
-
question: row.question.instructions,
|
|
86
|
-
kind: row.question.type,
|
|
87
|
-
options: options(row.question),
|
|
88
|
-
target: t.probs,
|
|
89
|
-
metadata: {
|
|
90
|
-
node: row.entry.node,
|
|
91
|
-
qid: row.qid,
|
|
92
|
-
backend: row.entry.backend,
|
|
93
|
-
label_source: t.source,
|
|
94
|
-
time: row.entry.time,
|
|
95
|
-
...(row.question.type === "choice" ? { option_meanings: row.question.criteria } : {}),
|
|
96
|
-
...(row.question.type === "score" ? { score_values: options(row.question).map((_, i) => i) } : {}),
|
|
97
|
-
},
|
|
98
|
-
}]
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// The text the decision server builds from a state object: the task text first, so a short GLiNER window keeps
|
|
103
|
-
// it. decider/decider/server.py renders the same way.
|
|
104
|
-
const FIRST = ["text", "utterance", "task", "question"]
|
|
105
|
-
export function renderState(state: unknown): string {
|
|
106
|
-
if (typeof state === "string") return state
|
|
107
|
-
if (!state || typeof state !== "object") return String(state)
|
|
108
|
-
const entries = Object.entries(state as Record<string, unknown>)
|
|
109
|
-
entries.sort(([a], [b]) => {
|
|
110
|
-
const ia = FIRST.indexOf(a), ib = FIRST.indexOf(b)
|
|
111
|
-
return (ia < 0 ? FIRST.length : ia) - (ib < 0 ? FIRST.length : ib)
|
|
112
|
-
})
|
|
113
|
-
return entries.map(([k, v]) => `${k}: ${typeof v === "string" ? v : JSON.stringify(v)}`).join("\n")
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const YES_NO = { yes: "Yes, the statement is true for this text.", no: "No, the statement is false for this text." }
|
|
117
|
-
const safe = (s: string) => s.replace(/\(/g, ", ").replace(/[)[\]]/g, "")
|
|
118
|
-
|
|
119
|
-
// GLiNER2 JSO lines (oc-voice training/tasks.py): hard labels only, the argmax of the target.
|
|
120
|
-
export function glinerRows(entries: readonly Entry[]): Record<string, unknown>[] {
|
|
121
|
-
return labeled(entries).flatMap((row) => {
|
|
122
|
-
const t = target(row)
|
|
123
|
-
if (!t || row.question.type === "score") return []
|
|
124
|
-
const labels = row.question.type === "choice" ? row.question.criteria : YES_NO
|
|
125
|
-
const names = options(row.question)
|
|
126
|
-
const trueLabel = names[t.probs.indexOf(Math.max(...t.probs))]
|
|
127
|
-
const described = Object.fromEntries(Object.entries(labels).map(([k, v]) => [k, safe(v)]))
|
|
128
|
-
return [{
|
|
129
|
-
input: renderState(row.entry.state),
|
|
130
|
-
output: { classifications: [{ task: row.qid, labels: described, true_label: trueLabel, prompt: safe(row.question.instructions), label_descriptions: described }] },
|
|
131
|
-
}]
|
|
132
|
-
})
|
|
133
|
-
}
|