@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/dist/nogit.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// A project folder that is no git repository (the user, 2026-10-20: the micromanager could not work there at all).
|
|
2
|
+
// Workers normally get a git worktree each, so they run in parallel and a change is checked and merged on its own;
|
|
3
|
+
// OpenCode's own worktrees are git worktrees too. So the user is asked, with a form: create a repository, or let the
|
|
4
|
+
// workers change the folder directly, one task after another, checks only (src/native.ts, isolation "none").
|
|
5
|
+
//
|
|
6
|
+
// Whether it is a repository is a fact the code checks. What to recommend is judgement (the decider, src/plugin.ts): a code
|
|
7
|
+
// project wants git, a config folder or notes may not. What the first commit must leave out is decided here, by rules
|
|
8
|
+
// that do not guess: secrets, dependency and build folders, and files too large for a repository.
|
|
9
|
+
import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmdirSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { join, resolve } from "node:path";
|
|
11
|
+
import { inStateDir, STATE_DIRS } from "@omacode/core/paths";
|
|
12
|
+
import { exec as defaultExec } from "./integration.js";
|
|
13
|
+
export async function gitState(project, run = defaultExec) {
|
|
14
|
+
const inside = await run("git", ["rev-parse", "--is-inside-work-tree"], { cwd: project }).catch(() => undefined);
|
|
15
|
+
if (!inside || inside.code !== 0 || inside.stdout.trim() !== "true")
|
|
16
|
+
return "no-repo";
|
|
17
|
+
const head = await run("git", ["rev-parse", "--verify", "--quiet", "HEAD"], { cwd: project }).catch(() => undefined);
|
|
18
|
+
return head && head.code === 0 ? "repo" : "no-commit";
|
|
19
|
+
}
|
|
20
|
+
// Folders that are installed, built or archived by a tool, never written by hand. `run_logs` and `worktrees` hold the
|
|
21
|
+
// plugin's own archived checkouts: they are stale or linked and say nothing about the project's files.
|
|
22
|
+
const SKIP_DIRS = new Set(["node_modules", ".venv", "venv", "__pycache__", "dist", "build", "target", ".cache", ".next", ".pytest_cache", ".mypy_cache", ".tox", ".gradle", "run_logs", "worktrees"]);
|
|
23
|
+
// Names that hold secrets: keys, certificates, environment files, credentials.
|
|
24
|
+
export const SECRET = [/^\.env(\..+)?$/i, /\.(pem|key|p12|pfx|kdbx|keystore|jks)$/i, /^id_(rsa|ed25519|ecdsa|dsa)(\.pub)?$/i, /^(credentials|secrets?)(\..+)?$/i, /^\.netrc$/i, /^\.npmrc$/i, /^\.pypirc$/i];
|
|
25
|
+
// The plugin's own state and anything above this size stay out.
|
|
26
|
+
// The state directory under any of its names (inStateDir) and git's own.
|
|
27
|
+
const own = (relPath, name) => name === ".git" || inStateDir(relPath);
|
|
28
|
+
export const MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
29
|
+
const MAX_ENTRIES = 20_000; // a folder this large is surveyed only so far
|
|
30
|
+
// A directory that holds its own .git (a directory, or a file for a worktree/submodule) is a repository of its own:
|
|
31
|
+
// committing it from the folder above would record an empty gitlink instead of its files.
|
|
32
|
+
//
|
|
33
|
+
// A .git entry alone proves nothing: archived checkouts keep a gitfile whose target is gone, and a linked worktree is a
|
|
34
|
+
// checkout of another repository, not a repository of its own. So the .git entry must be a real directory with HEAD, or
|
|
35
|
+
// a regular file whose gitdir points at a live repository. Linked worktrees are refused: their gitdir lives under
|
|
36
|
+
// `<repo>/.git/worktrees/<name>` and holds both `commondir` and a `gitdir` file back to the checkout, unlike a repository's
|
|
37
|
+
// .git or a submodule's .git/modules/<name>. The path segment check catches a link even when a stale layout hides those.
|
|
38
|
+
export function isRepoRoot(dir) {
|
|
39
|
+
const dot = join(dir, ".git");
|
|
40
|
+
let st;
|
|
41
|
+
try {
|
|
42
|
+
st = lstatSync(dot);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (st.isSymbolicLink())
|
|
48
|
+
return false;
|
|
49
|
+
if (st.isDirectory())
|
|
50
|
+
return existsSync(join(dot, "HEAD"));
|
|
51
|
+
if (!st.isFile())
|
|
52
|
+
return false;
|
|
53
|
+
let body;
|
|
54
|
+
try {
|
|
55
|
+
body = readFileSync(dot, "utf8");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const match = /^gitdir:\s*(.+)$/m.exec(body);
|
|
61
|
+
if (!match)
|
|
62
|
+
return false;
|
|
63
|
+
const gitdir = resolve(dir, match[1].trim());
|
|
64
|
+
if (!existsSync(join(gitdir, "HEAD")))
|
|
65
|
+
return false;
|
|
66
|
+
if (existsSync(join(gitdir, "commondir")) && existsSync(join(gitdir, "gitdir")))
|
|
67
|
+
return false;
|
|
68
|
+
if (/[\\/]worktrees[\\/]/.test(gitdir))
|
|
69
|
+
return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
export function surveyFolder(project) {
|
|
73
|
+
let files = 0;
|
|
74
|
+
let bytes = 0;
|
|
75
|
+
let seen = 0;
|
|
76
|
+
const excluded = [];
|
|
77
|
+
const repos = [];
|
|
78
|
+
const extensions = {};
|
|
79
|
+
const walk = (dir, rel) => {
|
|
80
|
+
let names;
|
|
81
|
+
try {
|
|
82
|
+
names = readdirSync(dir);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
if (++seen > MAX_ENTRIES)
|
|
89
|
+
return;
|
|
90
|
+
const path = join(dir, name);
|
|
91
|
+
const relPath = rel ? `${rel}/${name}` : name;
|
|
92
|
+
let st;
|
|
93
|
+
try {
|
|
94
|
+
st = lstatSync(path);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (st.isSymbolicLink())
|
|
100
|
+
continue;
|
|
101
|
+
if (st.isDirectory()) {
|
|
102
|
+
if (own(relPath, name))
|
|
103
|
+
continue;
|
|
104
|
+
if (SKIP_DIRS.has(name)) {
|
|
105
|
+
excluded.push(`${relPath}/`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (isRepoRoot(path)) {
|
|
109
|
+
repos.push(`${relPath}/`);
|
|
110
|
+
excluded.push(`${relPath}/`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
walk(path, relPath);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (SECRET.some((re) => re.test(name)) || st.size > MAX_FILE_BYTES) {
|
|
117
|
+
excluded.push(relPath);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
files++;
|
|
121
|
+
bytes += st.size;
|
|
122
|
+
const ext = name.includes(".") ? name.split(".").pop().toLowerCase() : "(none)";
|
|
123
|
+
extensions[ext] = (extensions[ext] ?? 0) + 1;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
walk(project, "");
|
|
127
|
+
let top = [];
|
|
128
|
+
try {
|
|
129
|
+
top = readdirSync(project).filter((n) => !own(n, n)).slice(0, 40);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// an unreadable folder: nothing to show
|
|
133
|
+
}
|
|
134
|
+
return { files, bytes, excluded, top, extensions, repos };
|
|
135
|
+
}
|
|
136
|
+
export function humanSize(bytes) {
|
|
137
|
+
return bytes < 1024 ? `${bytes} B` : bytes < 1024 ** 2 ? `${(bytes / 1024).toFixed(0)} KB` : bytes < 1024 ** 3 ? `${(bytes / 1024 ** 2).toFixed(1)} MB` : `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
138
|
+
}
|
|
139
|
+
// A plan worktree for a project that is no repository: a copy, since there is no commit to branch from. The same rules
|
|
140
|
+
// as the first commit's keep it safe and small, and lstat means a symlink is never followed: a link back to the project
|
|
141
|
+
// would recurse without end, and a link out of it would copy files that are not the project's.
|
|
142
|
+
export function copyForPlan(project, dest) {
|
|
143
|
+
let files = 0;
|
|
144
|
+
let bytes = 0;
|
|
145
|
+
let seen = 0;
|
|
146
|
+
const excluded = [];
|
|
147
|
+
mkdirSync(dest, { recursive: true });
|
|
148
|
+
const walk = (dir, out, rel) => {
|
|
149
|
+
let names;
|
|
150
|
+
try {
|
|
151
|
+
names = readdirSync(dir);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (const name of names) {
|
|
157
|
+
if (++seen > MAX_ENTRIES)
|
|
158
|
+
return;
|
|
159
|
+
const path = join(dir, name);
|
|
160
|
+
const target = join(out, name);
|
|
161
|
+
const relPath = rel ? `${rel}/${name}` : name;
|
|
162
|
+
let st;
|
|
163
|
+
try {
|
|
164
|
+
st = lstatSync(path);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (st.isSymbolicLink()) {
|
|
170
|
+
excluded.push(relPath);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (st.isDirectory()) {
|
|
174
|
+
// The state directory holds dest itself, so skipping it is also what keeps the copy from recursing into it.
|
|
175
|
+
if (own(relPath, name)) {
|
|
176
|
+
excluded.push(`${relPath}/`);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (SKIP_DIRS.has(name)) {
|
|
180
|
+
excluded.push(`${relPath}/`);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
mkdirSync(target, { recursive: true });
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
excluded.push(`${relPath}/`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
walk(path, target, relPath);
|
|
191
|
+
// A directory that holds the state directory (.opencode) and nothing else the copy takes is not left behind
|
|
192
|
+
// empty: the state directory was all it had for the plan.
|
|
193
|
+
if (STATE_DIRS.some((dir) => dir.startsWith(`${relPath}/`))) {
|
|
194
|
+
try {
|
|
195
|
+
if (readdirSync(target).length === 0)
|
|
196
|
+
rmdirSync(target);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// left as it is
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// A FIFO or a device is not something a project is made of: copying it would block or copy the machine.
|
|
205
|
+
if (!st.isFile()) {
|
|
206
|
+
excluded.push(relPath);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (SECRET.some((re) => re.test(name)) || st.size > MAX_FILE_BYTES) {
|
|
210
|
+
excluded.push(relPath);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
copyFileSync(path, target);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
excluded.push(relPath);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
files++;
|
|
221
|
+
bytes += st.size;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
walk(project, dest, "");
|
|
225
|
+
return { files, bytes, excluded };
|
|
226
|
+
}
|
|
227
|
+
// git init, a .gitignore with what stays out (kept and extended when there is one), and a first commit of the rest.
|
|
228
|
+
export async function initRepo(project, excluded, run = defaultExec) {
|
|
229
|
+
const state = await gitState(project, run);
|
|
230
|
+
if (state === "no-repo") {
|
|
231
|
+
const init = await run("git", ["init", "-q"], { cwd: project });
|
|
232
|
+
if (init.code !== 0)
|
|
233
|
+
return { ok: false, text: `git init failed: ${init.stderr.trim()}` };
|
|
234
|
+
}
|
|
235
|
+
// A repository inside the folder is its own history; committing it from here would record an empty gitlink. Its
|
|
236
|
+
// files stay out of this repository, and the survey normally listed it already.
|
|
237
|
+
const nested = surveyFolder(project).repos.map((r) => `/${r}`);
|
|
238
|
+
const ignore = join(project, ".gitignore");
|
|
239
|
+
const had = existsSync(ignore) ? readFileSync(ignore, "utf8") : "";
|
|
240
|
+
const lines = had.split("\n").map((l) => l.trim());
|
|
241
|
+
// The plugin's state stays out, except its backlog and contracts, which are the user's to commit (design.md §25).
|
|
242
|
+
const ours = STATE_DIRS.flatMap((n) => [`${n}/*`, `!${n}/backlog/`, `!${n}/contracts/`]);
|
|
243
|
+
const add = [...new Set(ours.concat(excluded.map((p) => `/${p}`), nested))].filter((p) => !lines.includes(p));
|
|
244
|
+
if (add.length)
|
|
245
|
+
writeFileSync(ignore, `${had}${had && !had.endsWith("\n") ? "\n" : ""}${had ? "\n" : ""}# left out of the first commit by micromanager\n${add.join("\n")}\n`);
|
|
246
|
+
const staged = await run("git", ["add", "-A"], { cwd: project });
|
|
247
|
+
if (staged.code !== 0)
|
|
248
|
+
return { ok: false, text: `git add failed: ${staged.stderr.trim()}` };
|
|
249
|
+
const links = await run("git", ["ls-files", "--stage"], { cwd: project });
|
|
250
|
+
if (links.code === 0 && links.stdout.split("\n").some((line) => line.startsWith("160000 "))) {
|
|
251
|
+
await run("git", ["reset", "-q"], { cwd: project });
|
|
252
|
+
return { ok: false, text: `Nothing was committed: ${project} contains a repository that .gitignore did not leave out, and git would record an empty gitlink instead of its files.` };
|
|
253
|
+
}
|
|
254
|
+
// The user's own identity, as git resolves it: without one the commit fails and they see git's own message.
|
|
255
|
+
const commit = await run("git", ["commit", "-qm", "Initial commit", "--allow-empty"], { cwd: project });
|
|
256
|
+
if (commit.code !== 0)
|
|
257
|
+
return { ok: false, text: `git commit failed: ${commit.stderr.trim()}` };
|
|
258
|
+
return { ok: true, text: `Created a git repository in ${project} with a first commit${excluded.length ? `; left out (in .gitignore): ${excluded.join(", ")}` : ""}.` };
|
|
259
|
+
}
|
package/dist/outcomes.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// What every writer attempt cost and whether its checks passed, one JSON line per worker end: the data a router can
|
|
2
|
+
// learn from later (phase 2 of the trials plan: a small local model that picks tier, n and families, trained on
|
|
3
|
+
// success minus cost, with tasks compared inside their class). Until then it answers one question for src/trials.ts:
|
|
4
|
+
// does this class of task mostly fail on a single worker?
|
|
5
|
+
// <userStateDir>/outcomes.jsonl (${XDG_STATE_HOME:-~/.local/state}/omacode, core/paths.ts)
|
|
6
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { contractHash, reward } from "./contract.js";
|
|
10
|
+
import { journalPath } from "./journal.js";
|
|
11
|
+
import { family } from "./roles.js";
|
|
12
|
+
import { tierFor } from "./registry.js";
|
|
13
|
+
import { pickOf } from "./trials.js";
|
|
14
|
+
export function outcomesPath() {
|
|
15
|
+
return join(dirname(journalPath()), "outcomes.jsonl");
|
|
16
|
+
}
|
|
17
|
+
// The class a task is compared in: what a router could know before it starts.
|
|
18
|
+
export function classOf(role, difficulty, files) {
|
|
19
|
+
return `${role}:${difficulty === undefined ? "unknown" : tierFor(difficulty)}:${files <= 1 ? "1" : files <= 3 ? "2-3" : "4+"}`;
|
|
20
|
+
}
|
|
21
|
+
// The row for a writer task whose worker ended. usage: the session's tokens and cost, when the caller could read them.
|
|
22
|
+
export function outcomeOf(project, job, task, usage, now = new Date()) {
|
|
23
|
+
const gates = task.stages.filter((s) => s.stage === "gate");
|
|
24
|
+
const last = gates.at(-1);
|
|
25
|
+
const gate = !last ? "none" : last.result === "pass" ? "pass" : /changed no file/.test(last.evidence ?? "") ? "unverified" : "fail";
|
|
26
|
+
const won = task.stages.some((s) => s.stage === "trial" && s.result === "pass" && /won by/.test(s.evidence ?? ""));
|
|
27
|
+
const pick = task.trial ? pickOf(task) : undefined;
|
|
28
|
+
const lost = pick === "best" ? "lost_on_quality" : pick === "user" ? "lost_on_pick" : "lost_on_score";
|
|
29
|
+
const combined = task.stages.some((s) => s.stage === "trial" && /^combined into /.test(s.evidence ?? ""));
|
|
30
|
+
const end = task.status === "merged" ? "merged" : task.status === "cancelled" ? (won ? (task.held ? lost : "sibling_won") : combined ? "combined" : "cancelled") : task.status === "blocked" ? "blocked" : "unfinished";
|
|
31
|
+
const winning = task.status === "merged" && task.trial ? task.stages.findLast((s) => s.stage === "trial" && /^won the trial/.test(s.evidence ?? ""))?.evidence : undefined;
|
|
32
|
+
// A combination the user asked for won by its next pass, a "first" pick after the fact: the user chose it.
|
|
33
|
+
const asked = task.stages.some((s) => s.stage === "trial" && /^the user asked for a combination/.test(s.evidence ?? ""));
|
|
34
|
+
const chosenBy = !winning ? undefined : asked || /as the user's pick/.test(winning) ? "user" : /on quality \(on review/.test(winning) ? "review" : /on quality/.test(winning) ? "quality" : /on score/.test(winning) ? "score" : "first";
|
|
35
|
+
const started = task.stages.find((s) => s.stage === "delegate")?.at;
|
|
36
|
+
const verify = job.acceptance.filter((a) => task.acceptance.includes(a.id)).map((a) => a.verify).filter((v) => Boolean(v));
|
|
37
|
+
const contract = task.contract && job.contracts?.find((c) => c.id === task.contract.id);
|
|
38
|
+
const r = contract && task.score ? reward(contract, task.score) : undefined;
|
|
39
|
+
return {
|
|
40
|
+
time: now.toISOString(),
|
|
41
|
+
project,
|
|
42
|
+
job: job.id,
|
|
43
|
+
task: task.id,
|
|
44
|
+
...(task.trial ? { trial: task.trial.of } : {}),
|
|
45
|
+
n: task.trial?.n ?? 1,
|
|
46
|
+
role: task.role,
|
|
47
|
+
...(task.model ? { model: task.model, family: family(task.model) } : {}),
|
|
48
|
+
...(task.difficulty !== undefined ? { difficulty: task.difficulty } : {}),
|
|
49
|
+
cls: classOf(task.role, task.difficulty, task.files.length),
|
|
50
|
+
files: task.files.length,
|
|
51
|
+
checks: verify,
|
|
52
|
+
brief: task.description.slice(0, 2000),
|
|
53
|
+
briefHash: createHash("sha256").update(task.description).digest("hex").slice(0, 16),
|
|
54
|
+
gate,
|
|
55
|
+
// A failed fitness measurement is a fix round as much as a failing check (src/native.ts finish).
|
|
56
|
+
fixRounds: task.stages.filter((s) => (s.stage === "gate" || s.stage === "fitness") && s.result === "fail").length,
|
|
57
|
+
merged: task.status === "merged",
|
|
58
|
+
end,
|
|
59
|
+
...(chosenBy ? { chosenBy } : {}),
|
|
60
|
+
...(started ? { seconds: Math.round((now.getTime() - Date.parse(started)) / 1000) } : {}),
|
|
61
|
+
...(usage ? { tokens: usage.tokens, cost: usage.cost } : {}),
|
|
62
|
+
...(contract ? { contract: { id: contract.id, version: task.contract.version, hash: contractHash(contract) } } : {}),
|
|
63
|
+
...(task.score ? { score: { valid: task.score.valid, values: task.score.values } } : {}),
|
|
64
|
+
...(r !== undefined ? { reward: r } : {}),
|
|
65
|
+
...(task.graded ? { graded: Math.round((task.graded.passed / task.graded.total) * 1000) / 1000 } : {}),
|
|
66
|
+
...(task.checkChanges?.length ? { checkChanges: task.checkChanges } : {}),
|
|
67
|
+
...(task.steps ? { steps: task.steps } : {}),
|
|
68
|
+
...(task.evolve ? { method: "evolver", evolve: { evaluations: task.evolve.evaluations, valid: task.evolve.valid, calls: task.evolve.calls } } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function recordOutcome(row, path = outcomesPath()) {
|
|
72
|
+
try {
|
|
73
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
74
|
+
appendFileSync(path, JSON.stringify(row) + "\n");
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// the log must never break a worker's end
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function readOutcomes(path = outcomesPath()) {
|
|
81
|
+
if (!existsSync(path))
|
|
82
|
+
return [];
|
|
83
|
+
return readFileSync(path, "utf8").split("\n").flatMap((line) => {
|
|
84
|
+
if (!line.trim())
|
|
85
|
+
return [];
|
|
86
|
+
try {
|
|
87
|
+
return [JSON.parse(line)];
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Whether tasks of this class mostly fail on a single worker: of its last `window` single attempts (no trial), at least
|
|
95
|
+
// `min` ended, and fewer than half merged. A class that won trials after failed attempts counts too: a trial where
|
|
96
|
+
// some attempt failed and one won says one worker alone would likely have failed.
|
|
97
|
+
export function needsTrials(rows, cls, window = 20, min = 4) {
|
|
98
|
+
const mine = rows.filter((r) => r.cls === cls && r.end !== "cancelled");
|
|
99
|
+
const singles = mine.filter((r) => r.n === 1).slice(-window);
|
|
100
|
+
const trials = groupTrials(mine.filter((r) => r.n > 1)).slice(-window);
|
|
101
|
+
const tries = singles.length + trials.reduce((s, t) => s + t.attempts.filter((a) => a.end !== "sibling_won").length, 0);
|
|
102
|
+
if (tries < min)
|
|
103
|
+
return false;
|
|
104
|
+
const passed = singles.filter((r) => r.merged).length + trials.filter((t) => t.k > 0).length;
|
|
105
|
+
return passed / tries < 0.5;
|
|
106
|
+
}
|
|
107
|
+
// The steps merged tasks of a class needed, at their 75th percentile: when a task like it is usually done. Undefined
|
|
108
|
+
// below min rows, where a percentile says nothing.
|
|
109
|
+
export function learnedSteps(rows, cls, min = 5) {
|
|
110
|
+
const steps = rows.filter((r) => r.cls === cls && r.merged && r.steps).map((r) => r.steps).sort((a, b) => a - b);
|
|
111
|
+
if (steps.length < min)
|
|
112
|
+
return undefined;
|
|
113
|
+
return steps[Math.min(steps.length - 1, Math.ceil(steps.length * 0.75) - 1)];
|
|
114
|
+
}
|
|
115
|
+
function groupTrials(rows) {
|
|
116
|
+
const by = new Map();
|
|
117
|
+
for (const r of rows) {
|
|
118
|
+
const k = `${r.job}/${r.trial ?? r.task}`;
|
|
119
|
+
by.set(k, [...(by.get(k) ?? []), r]);
|
|
120
|
+
}
|
|
121
|
+
return [...by.entries()].map(([key, attempts]) => ({ key, cls: attempts[0].cls, n: attempts[0].n, k: attempts.filter((a) => a.gate === "pass").length, attempts }));
|
|
122
|
+
}
|
|
123
|
+
// export-dataset --target router: one row per task (a trial's attempts joined), with what a router sees before the
|
|
124
|
+
// start, what it chose, and what came of it. Censored attempts (stopped because a sibling won) are kept as such; an
|
|
125
|
+
// attempt that passed and lost on quality, score or the user's pick is an observed result, and the row says which
|
|
126
|
+
// model won and how it was chosen.
|
|
127
|
+
export function routerRows(rows) {
|
|
128
|
+
return groupTrials(rows).map((t) => {
|
|
129
|
+
const first = t.attempts[0];
|
|
130
|
+
return {
|
|
131
|
+
key: t.key,
|
|
132
|
+
cls: t.cls,
|
|
133
|
+
features: { role: first.role, difficulty: first.difficulty, files: first.files, checks: first.checks, brief: first.brief },
|
|
134
|
+
allocation: { n: t.n, models: t.attempts.map((a) => a.model) },
|
|
135
|
+
outcome: {
|
|
136
|
+
k: t.k,
|
|
137
|
+
merged: t.attempts.some((a) => a.merged),
|
|
138
|
+
censored: t.attempts.filter((a) => a.end === "sibling_won").length,
|
|
139
|
+
tokens: t.attempts.reduce((s, a) => s + (a.tokens ?? 0), 0),
|
|
140
|
+
cost: Math.round(t.attempts.reduce((s, a) => s + (a.cost ?? 0), 0) * 1e6) / 1e6,
|
|
141
|
+
seconds: Math.max(0, ...t.attempts.map((a) => a.seconds ?? 0)),
|
|
142
|
+
...(t.attempts.some((a) => a.reward !== undefined) ? { reward: Math.max(...t.attempts.map((a) => a.reward ?? 0)) } : {}),
|
|
143
|
+
...(t.attempts.some((a) => a.chosenBy) ? { winner: t.attempts.find((a) => a.chosenBy).model, chosenBy: t.attempts.find((a) => a.chosenBy).chosenBy } : {}),
|
|
144
|
+
...(t.attempts.some((a) => a.end.startsWith("lost_on_")) ? { lost: t.attempts.filter((a) => a.end.startsWith("lost_on_")).map((a) => a.model) } : {}),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The two cloud questions a permission case asks besides decide()'s own three, in one place so their journal shape cannot
|
|
2
|
+
// drift apart (A2-T2b). Both used to call the raw client, which journalled nothing: the answer reached the decision and
|
|
3
|
+
// the inputs were gone. Through the decider, each case records the request, the text that was sent (redacted by the
|
|
4
|
+
// egress gate), the question and the answer — which is what a label factory and an eval need.
|
|
5
|
+
//
|
|
6
|
+
// The permission nodes are cloud-only (`cloudAnswers`): A2b exports their cases for the local model and measures it on
|
|
7
|
+
// them, but the gate has not passed and the routing has not flipped, so a local model would still be answering
|
|
8
|
+
// something nobody has checked.
|
|
9
|
+
import { CHECK_BUG } from "./catalog.js";
|
|
10
|
+
import { grantState, harmlessQuestion } from "./grants.js";
|
|
11
|
+
// The decider's opinion on whether a requested variable or host is harmless, as a probability. 0 when nothing answered: the
|
|
12
|
+
// caller then asks the user, exactly as it did before the ask existed.
|
|
13
|
+
export async function askGrantHarmless(decider, input) {
|
|
14
|
+
const asked = await decider.ask("N13.grant", { text: grantState(input.kind, input.name, input.why, input.task, input.value) }, { harmless: harmlessQuestion(input.kind) }, {
|
|
15
|
+
cloudAnswers: true,
|
|
16
|
+
session: input.session,
|
|
17
|
+
job: input.job,
|
|
18
|
+
request: { kind: "grant", grant: input.kind, name: input.name, why: input.why.slice(0, 300), sessionID: input.session, job: input.job },
|
|
19
|
+
});
|
|
20
|
+
const answer = asked.decision.answers.harmless;
|
|
21
|
+
return answer?.type === "noul" ? answer.noul : 0;
|
|
22
|
+
}
|
|
23
|
+
// The decider's opinion on a worker's claim that a failing check is itself wrong. 1 when nothing answered: the check stands,
|
|
24
|
+
// and the request goes on to whoever decides this kind of change.
|
|
25
|
+
export async function askCheckBug(decider, input) {
|
|
26
|
+
const state = `A worker's check failed and the worker says the check itself is wrong.\nTask: ${input.task}\nCheck: ${input.target}\nProblem: ${input.problem}\nEvidence: ${input.evidence.slice(0, 2000)}`;
|
|
27
|
+
const asked = await decider.ask("N13.check_bug", { text: state }, { check_bug: CHECK_BUG }, {
|
|
28
|
+
cloudAnswers: true,
|
|
29
|
+
session: input.session,
|
|
30
|
+
job: input.job,
|
|
31
|
+
request: { kind: "check_bug", target: input.target, problem: input.problem.slice(0, 300), sessionID: input.session, job: input.job, task: input.taskId },
|
|
32
|
+
});
|
|
33
|
+
const answer = asked.decision.answers.check_bug;
|
|
34
|
+
return answer?.type === "noul" ? answer.noul : 1;
|
|
35
|
+
}
|
package/dist/pick.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A trial the user decides (src/trials.ts pick "user"; the user, 2026-10-27: design drafts are a matter of taste). Once
|
|
2
|
+
// every attempt has ended, those that passed are put side by side on a comparison page, and the micromanager asks the
|
|
3
|
+
// user with a form: one of the attempts, a combination ("the layout of T2 with the colours of T3"), or none of them.
|
|
4
|
+
// The answer is read from the form's result, which only the user fills in; the micromanager cannot pick for them.
|
|
5
|
+
import { formInput } from "./forms.js";
|
|
6
|
+
import { HEADER } from "./hooks.js";
|
|
7
|
+
const COMBINE = "Combine";
|
|
8
|
+
const NONE = "None of them";
|
|
9
|
+
const NOTHING = "Nothing to add";
|
|
10
|
+
export const pickHeader = (head) => `Pick ${head}`;
|
|
11
|
+
const notesHeader = (head) => `Pick ${head} notes`;
|
|
12
|
+
const money = (n) => (n === undefined ? "cost unknown" : `$${n.toFixed(3)}`);
|
|
13
|
+
// The form: which attempt, and the user's words for a combination or for none.
|
|
14
|
+
export function pickForm(head, title, candidates, page) {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
header: pickHeader(head),
|
|
18
|
+
question: `Which version of "${title.slice(0, 120)}" do you want? The comparison with pictures is in ${page}.`,
|
|
19
|
+
options: [
|
|
20
|
+
...candidates.map((c) => ({ label: c.id, description: `${c.model ?? "?"} · ${money(c.cost)} · +${c.lines.added}/-${c.lines.removed} lines` })),
|
|
21
|
+
{ label: COMBINE, description: "Take parts of several; say which in the next question" },
|
|
22
|
+
{ label: NONE, description: "None fits; say why in the next question, and the task is tried again" },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
header: notesHeader(head),
|
|
27
|
+
question: `For ${COMBINE} or ${NONE}: what should change? Name the versions you mean (e.g. "layout of T2, colours of T3").`,
|
|
28
|
+
options: [{ label: NOTHING, description: "I picked one version above" }],
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
// The answer to a pick form, or undefined when the form is none. head: the trial's first attempt, from the header.
|
|
33
|
+
export function readPick(questions, answers) {
|
|
34
|
+
const at = questions.findIndex((q) => /^Pick T\d+(?:\.\w+)*$/.test(q.header ?? ""));
|
|
35
|
+
if (at < 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
const head = questions[at].header.slice(5);
|
|
38
|
+
const labels = new Set((questions[at].options ?? []).map((o) => o.label));
|
|
39
|
+
const chosen = (answers[at] ?? []).map((a) => a.trim());
|
|
40
|
+
const n = questions.findIndex((q) => q.header === notesHeader(head));
|
|
41
|
+
const typed = (n >= 0 ? answers[n] ?? [] : []).map((a) => a.trim()).filter((a) => a && a !== NOTHING);
|
|
42
|
+
const notes = typed.join(" ") || undefined;
|
|
43
|
+
const one = chosen.find((c) => labels.has(c));
|
|
44
|
+
if (!one)
|
|
45
|
+
return { head, answer: { kind: "unclear", ...(chosen[0] ? { said: chosen[0] } : {}) } };
|
|
46
|
+
if (one === COMBINE)
|
|
47
|
+
return { head, answer: { kind: "combine", ...(notes ? { notes } : {}) } };
|
|
48
|
+
if (one === NONE)
|
|
49
|
+
return { head, answer: { kind: "none", ...(notes ? { notes } : {}) } };
|
|
50
|
+
return { head, answer: { kind: "attempt", id: one, ...(notes ? { notes } : {}) } };
|
|
51
|
+
}
|
|
52
|
+
// What the micromanager reads when every attempt has ended: the form to put to the user.
|
|
53
|
+
export function pickNote(head, title, candidates, page) {
|
|
54
|
+
return [
|
|
55
|
+
`${HEADER} Every attempt at ${head} (${title.slice(0, 120)}) has ended, and ${candidates.length} passed their checks: ${candidates.map((c) => c.id).join(", ")}. The user picks the version to merge.`,
|
|
56
|
+
`Ask them with the question tool, with exactly this input (a form that waits for their answer; it reaches the plugin by itself), then end your turn; tell them the comparison page is ${page}:`,
|
|
57
|
+
formInput(pickForm(head, title, candidates, page)),
|
|
58
|
+
"Do not pick for them, and do not merge anything yourself: nothing that depends on this task starts before they answer.",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
// The base of a combination: the first attempt the user's words name, else the first candidate.
|
|
62
|
+
export function combineBase(notes, ids) {
|
|
63
|
+
const named = (notes ?? "").toUpperCase().match(/\bT\d+(?:\.\w+)*\b/g) ?? [];
|
|
64
|
+
return named.find((id) => ids.includes(id)) ?? ids[0];
|
|
65
|
+
}
|
|
66
|
+
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
67
|
+
// The comparison page: one column per passed attempt, its picture first. Self-contained, pictures inline.
|
|
68
|
+
export function comparisonPage(head, title, candidates) {
|
|
69
|
+
const cards = candidates.map((c) => {
|
|
70
|
+
const pic = c.preview?.png
|
|
71
|
+
? `<img src="data:image/png;base64,${c.preview.png.toString("base64")}" alt="${esc(c.id)}: ${esc(c.preview.path)}">`
|
|
72
|
+
: `<p class="none">${esc(c.preview?.problem ?? "No picture: the task named no preview.")}</p>`;
|
|
73
|
+
return `<section><h2>${esc(c.id)}</h2><p class="meta">${esc(c.model ?? "?")} · ${esc(money(c.cost))} · +${c.lines.added}/-${c.lines.removed} lines · ${c.files.length} file${c.files.length === 1 ? "" : "s"}</p>${pic}${c.summary ? `<p>${esc(c.summary)}</p>` : ""}<details><summary>Files</summary><ul>${c.files.map((f) => `<li><code>${esc(f)}</code></li>`).join("")}</ul></details></section>`;
|
|
74
|
+
}).join("\n");
|
|
75
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Pick ${esc(head)}</title>
|
|
76
|
+
<style>
|
|
77
|
+
:root{--bg:#f4f5f7;--card:#fff;--ink:#1b1f24;--muted:#5c6570;--line:#d6dbe1;color-scheme:light}
|
|
78
|
+
@media (prefers-color-scheme:dark){:root{--bg:#111418;--card:#1a1f25;--ink:#e6eaef;--muted:#98a2ad;--line:#2c343d;color-scheme:dark}}
|
|
79
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 system-ui,sans-serif;padding:20px}
|
|
80
|
+
h1{font-size:22px;margin:0 0 4px}.lead{color:var(--muted);margin:0 0 18px}
|
|
81
|
+
main{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px;align-items:start}
|
|
82
|
+
section{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px;min-width:0}
|
|
83
|
+
h2{margin:0;font-size:18px}.meta{color:var(--muted);font-size:13px;margin:2px 0 10px}
|
|
84
|
+
img{width:100%;border:1px solid var(--line);border-radius:6px;display:block}.none{color:var(--muted);font-style:italic}
|
|
85
|
+
code{font-size:12px}
|
|
86
|
+
</style></head><body><h1>Pick a version of ${esc(head)}</h1><p class="lead">${esc(title)}: every version below passed its checks. Answer in the form in OpenCode.</p><main>
|
|
87
|
+
${cards}
|
|
88
|
+
</main></body></html>`;
|
|
89
|
+
}
|