@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/watchdog.js
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
// The loop watchdog (design.md §10.1): code, not the model, decides that a session is going in circles.
|
|
2
|
+
//
|
|
3
|
+
// It is fed every tool call of a watched session (tool.execute.after) and every provider turn (the context hook,
|
|
4
|
+
// which carries the message history), and returns a signal when a limit or a loop signature fires. The plugin
|
|
5
|
+
// then interrupts the session; the runner never resumes it, but may start a fresh one with a handoff note.
|
|
6
|
+
// The signatures come from real failures: Kimi restarting its task, Gemini's read loops, and a local planner
|
|
7
|
+
// that read the same directory sixty times in this project's own test.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
// The thresholds, and what each one defends against (2026-10-06, after a live run in which nine signals fired on
|
|
10
|
+
// healthy sessions and three were escalated):
|
|
11
|
+
//
|
|
12
|
+
// - sameCall 3 in window 10, unchanged: the tightest loop there is, and the one the real failures showed first
|
|
13
|
+
// (Kimi restarting its task, Gemini rereading). Keeping the value means a genuinely stuck session still ends at
|
|
14
|
+
// three repeats; raising it to spare a TDD loop that runs `npm test` three times would let a real forever-loop
|
|
15
|
+
// (the same failing command, forever) run on to the step limit, which is a much more expensive mistake.
|
|
16
|
+
// - readRepeat 3 in readWindow 16: "the same file again and again" only means a loop *while it stays the recent
|
|
17
|
+
// work*. Before the window, reading a config file three times anywhere in a 200-call session was a hard stop, and
|
|
18
|
+
// normal work looked like the planner's loop. 16 calls is more than a read-explore-read cycle takes and less than
|
|
19
|
+
// a session's worth, so a real loop cannot hide outside it.
|
|
20
|
+
// - noNewFiles 16: calls in a row that make no progress. Three things count as progress: a new path, a search, and
|
|
21
|
+
// a command that actually did something. A command that runs is progress -- a worker verifying with `npm test` or
|
|
22
|
+
// `git status` ten times over is working, not stuck -- and the signature that actually catches a stuck command is
|
|
23
|
+
// sameCall, which compares the command itself rather than counting calls (live test, 2026-10-07: a worker was
|
|
24
|
+
// stopped after "8 calls in a row without a new file or a search" while it was eight calls into reading a source
|
|
25
|
+
// file it had already opened, before it had written anything). Only a command that keeps FAILING now counts
|
|
26
|
+
// towards the run, because that is the case sameCall cannot see. Readers, whose whole job is reading and who never
|
|
27
|
+
// write, are the extreme case: they would trip a low bar on ordinary work.
|
|
28
|
+
// - restartLength 4: the opening calls repeated verbatim at the tail of the *whole* session. That comparison is
|
|
29
|
+
// deliberately not windowed: starting over is by definition where the session began. Four is enough of an opening
|
|
30
|
+
// to be a shape rather than a coincidence (one read can repeat by chance, four calls rarely do).
|
|
31
|
+
// - monologue 3: a worker writing a long report in several messages was interrupted mid-report, so it only nudges.
|
|
32
|
+
// - maxSteps: the last safety net for a session that never ends (the user, 2026-10-05: a cut session wastes work).
|
|
33
|
+
// How many times a worker's failing checks are handed back for another try, on both gate paths (the runner's fix
|
|
34
|
+
// rounds and the native finish_task loop). The runner's own cap is configurable through RunnerDeps.fixRounds; this is
|
|
35
|
+
// the default both use. A check that cannot be satisfied in the environment -- a path that does not exist there, a
|
|
36
|
+
// command the gate refuses -- is the case this exists for: handed back forever, it burned a whole session.
|
|
37
|
+
export const FIX_ROUNDS = 2;
|
|
38
|
+
export const DEFAULT_LIMITS = { maxSteps: 60, sameCall: 3, window: 10, readRepeat: 3, readWindow: 16, noNewFiles: 16, restartLength: 4, monologue: 3 };
|
|
39
|
+
// The budget tier the decision model picks (design.md §8.1) maps to step limits; code keeps the ceiling.
|
|
40
|
+
export const TIER_STEPS = { S: 30, M: 60, L: 120 };
|
|
41
|
+
// The user's choice (2026-10-05): no budget estimates per task, since a cut session wastes what it did. Loops are
|
|
42
|
+
// caught by the signatures above; this is only the last safety net for a session that never ends.
|
|
43
|
+
export const MAX_STEPS = 400;
|
|
44
|
+
// Task checkpoints (the user's idea, 2026-10-05): every CHECKPOINT_STEPS steps a task is reviewed, not cut. The decider looks
|
|
45
|
+
// at the facts below and says whether it still makes progress (go on), needs another approach (a fresh session on
|
|
46
|
+
// another family), or goes back to the micromanager.
|
|
47
|
+
export const CHECKPOINT_STEPS = 60;
|
|
48
|
+
// The signs that pull a checkpoint forward (the user's choice after the Ralph spike, 2026-10-25).
|
|
49
|
+
export const PULL_GAP = 10;
|
|
50
|
+
export const PULL_SINCE_WRITE = 25;
|
|
51
|
+
export const PULL_FAILURES = 6;
|
|
52
|
+
// ... and to tokens per session (input + output over all turns), checked after each turn by the runner.
|
|
53
|
+
export const TIER_TOKENS = { S: 250_000, M: 600_000, L: 1_500_000 };
|
|
54
|
+
const READS = new Set(["read", "list"]);
|
|
55
|
+
const WRITES = new Set(["edit", "write", "patch", "multiedit", "apply_patch"]);
|
|
56
|
+
// Searching is work: a worker that greps and globs nine times in a row is exploring a repository, not going in
|
|
57
|
+
// circles, and none of those calls opens a path the noNewFiles counter could see. code_graph is in here because it
|
|
58
|
+
// is a search over the syntax tree that opens no path at all (added 2026-10-06, missed by this list until then).
|
|
59
|
+
const SEARCHES = new Set([
|
|
60
|
+
"grep", "glob", "ast-grep", "astgrep", "websearch", "webfetch", "search", "code_search", "code_graph",
|
|
61
|
+
]);
|
|
62
|
+
// Tools that act: they run something whose outcome is not a file this watchdog can see. A successful one is progress,
|
|
63
|
+
// whatever it touched. A failing one is not counted here -- it falls through and counts towards the run, which is
|
|
64
|
+
// what a worker repeatedly failing the same way looks like, and the one case sameCall cannot catch because the
|
|
65
|
+
// command text differs each time.
|
|
66
|
+
const ACTS = new Set(["shell", "bash", "execute", "task"]);
|
|
67
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
68
|
+
// A call key only needs to tell one input from another, not to carry it: a `write` with a 100 KB body would otherwise
|
|
69
|
+
// be sorted, concatenated and kept in the session for the whole run. Longer strings are hashed instead, so `same_call`
|
|
70
|
+
// stays exact (two different bodies need a SHA-256 collision to collide) while the key stays small.
|
|
71
|
+
const STABLE_INLINE = 512;
|
|
72
|
+
function stable(value) {
|
|
73
|
+
if (typeof value === "string") {
|
|
74
|
+
return value.length <= STABLE_INLINE ? JSON.stringify(value) : `"#sha256:${sha256(value)}:${value.length}"`;
|
|
75
|
+
}
|
|
76
|
+
if (value === null || typeof value !== "object")
|
|
77
|
+
return JSON.stringify(value);
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
return `[${value.map(stable).join(",")}]`;
|
|
80
|
+
return `{${Object.keys(value).sort().map((k) => `${k}:${stable(value[k])}`).join(",")}}`;
|
|
81
|
+
}
|
|
82
|
+
// The write probe reads a shell input in full (never the hashed form above): a command longer than STABLE_INLINE that
|
|
83
|
+
// commits is still a write. Shell commands are small, and this runs only for them.
|
|
84
|
+
function inputText(input) {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.stringify(input) ?? "";
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function pathOf(input) {
|
|
93
|
+
const i = input;
|
|
94
|
+
const p = i?.path ?? i?.filePath ?? i?.file_path;
|
|
95
|
+
return typeof p === "string" ? p.replace(/\/+$/, "") : undefined;
|
|
96
|
+
}
|
|
97
|
+
const normalize = (text) => text.toLowerCase().replace(/\s+/g, " ").trim();
|
|
98
|
+
// Only recent answers can realistically come back verbatim, and a long session must not grow its seen-text memory
|
|
99
|
+
// without bound. The set keeps insertion order, so evicting the first entry drops the oldest text in O(1).
|
|
100
|
+
const MAX_TEXTS = 512;
|
|
101
|
+
function resultTextSafe(result) {
|
|
102
|
+
try {
|
|
103
|
+
// Reuse the same shapes as hooks.resultText without importing (avoid cycle).
|
|
104
|
+
const r = result;
|
|
105
|
+
if (!r || typeof r !== "object")
|
|
106
|
+
return typeof result === "string" ? result : JSON.stringify(result ?? "");
|
|
107
|
+
const slots = [];
|
|
108
|
+
if (Array.isArray(r.content))
|
|
109
|
+
for (const part of r.content)
|
|
110
|
+
if (part && typeof part.text === "string")
|
|
111
|
+
slots.push(part.text);
|
|
112
|
+
if (typeof r.output === "string")
|
|
113
|
+
slots.push(r.output);
|
|
114
|
+
else if (r.output && typeof r.output === "object") {
|
|
115
|
+
const o = r.output;
|
|
116
|
+
for (const key of ["output", "content", "text"])
|
|
117
|
+
if (typeof o[key] === "string")
|
|
118
|
+
slots.push(o[key]);
|
|
119
|
+
}
|
|
120
|
+
return slots.length ? slots.join("\n") : JSON.stringify(result);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return String(result);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function detectCycle(ring) {
|
|
127
|
+
const n = ring.length;
|
|
128
|
+
for (let patLen = 1; patLen <= 3; patLen++) {
|
|
129
|
+
if (n < patLen * 2)
|
|
130
|
+
continue;
|
|
131
|
+
for (let cycles = 2; cycles <= Math.floor(n / patLen); cycles++) {
|
|
132
|
+
const seg = ring.slice(-cycles * patLen);
|
|
133
|
+
const pat = seg.slice(0, patLen);
|
|
134
|
+
let ok = true;
|
|
135
|
+
for (let i = 0; i < seg.length; i++)
|
|
136
|
+
if (seg[i] !== pat[i % patLen]) {
|
|
137
|
+
ok = false;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (ok)
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
function formatRepeat(tool, input, count) {
|
|
147
|
+
const i = input;
|
|
148
|
+
if (tool === "read") {
|
|
149
|
+
const path = i?.path ?? i?.filePath ?? i?.file_path;
|
|
150
|
+
const offset = i?.offset;
|
|
151
|
+
const limit = i?.limit;
|
|
152
|
+
const where = offset !== undefined ? ` from line ${String(offset)}` : "";
|
|
153
|
+
const span = limit !== undefined ? ` for ${String(limit)} lines` : "";
|
|
154
|
+
return `read ${String(path)}${where}${span} ${count}x`;
|
|
155
|
+
}
|
|
156
|
+
return `${tool} ${JSON.stringify(input)} ${count}x`;
|
|
157
|
+
}
|
|
158
|
+
export class Watchdog {
|
|
159
|
+
#sessions = new Map();
|
|
160
|
+
watch(sessionID, limits = {}) {
|
|
161
|
+
this.#sessions.set(sessionID, {
|
|
162
|
+
limits: { ...DEFAULT_LIMITS, ...limits },
|
|
163
|
+
calls: [],
|
|
164
|
+
readWindow: [],
|
|
165
|
+
readPaths: new Set(),
|
|
166
|
+
checkpointReadPaths: new Set(),
|
|
167
|
+
writtenPaths: new Set(),
|
|
168
|
+
quiet: 0,
|
|
169
|
+
steps: 0,
|
|
170
|
+
texts: new Set(),
|
|
171
|
+
writes: 0,
|
|
172
|
+
totalWrites: 0,
|
|
173
|
+
lastWrite: -1,
|
|
174
|
+
failed: [],
|
|
175
|
+
seenLines: new Map(),
|
|
176
|
+
newLines: 0,
|
|
177
|
+
ring: [],
|
|
178
|
+
lastCheck: 0,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// The session's first checkpoint interval, set once (from the task's class or difficulty, src/checkpoint.ts).
|
|
182
|
+
schedule(sessionID, interval) {
|
|
183
|
+
const s = this.#sessions.get(sessionID);
|
|
184
|
+
if (!s || s.interval !== undefined)
|
|
185
|
+
return;
|
|
186
|
+
s.interval = interval;
|
|
187
|
+
s.next = s.lastCheck + interval;
|
|
188
|
+
}
|
|
189
|
+
scheduled(sessionID) {
|
|
190
|
+
return this.#sessions.get(sessionID)?.interval;
|
|
191
|
+
}
|
|
192
|
+
// A checkpoint was held: the next one comes after interval more steps.
|
|
193
|
+
checked(sessionID, interval) {
|
|
194
|
+
const s = this.#sessions.get(sessionID);
|
|
195
|
+
if (!s)
|
|
196
|
+
return;
|
|
197
|
+
s.lastCheck = s.steps;
|
|
198
|
+
s.interval = interval;
|
|
199
|
+
s.next = s.steps + interval;
|
|
200
|
+
// Reset the novelty accumulators and the repeat window: the next review starts fresh.
|
|
201
|
+
s.newLines = 0;
|
|
202
|
+
s.writes = 0;
|
|
203
|
+
s.ring = [];
|
|
204
|
+
s.checkpointReadPaths = new Set(s.readPaths);
|
|
205
|
+
s.lastRepeatedKey = undefined;
|
|
206
|
+
s.lastRepeatedInput = undefined;
|
|
207
|
+
s.lastRepeatedCount = undefined;
|
|
208
|
+
}
|
|
209
|
+
unwatch(sessionID) {
|
|
210
|
+
this.#sessions.delete(sessionID);
|
|
211
|
+
}
|
|
212
|
+
watching(sessionID) {
|
|
213
|
+
return sessionID !== undefined && this.#sessions.has(sessionID);
|
|
214
|
+
}
|
|
215
|
+
// failed: the call's result reads like an error (for the checkpoint's facts).
|
|
216
|
+
onTool(sessionID, tool, input, failedOrResult = false, resultMaybe) {
|
|
217
|
+
// Accept either (..., failed, result) or (..., result, failed) or (..., result) or (..., {result, failed}).
|
|
218
|
+
let failed = false;
|
|
219
|
+
let result;
|
|
220
|
+
if (failedOrResult && typeof failedOrResult === "object" && !Array.isArray(failedOrResult) && ("result" in failedOrResult || "failed" in failedOrResult)) {
|
|
221
|
+
const o = failedOrResult;
|
|
222
|
+
result = o.result;
|
|
223
|
+
failed = Boolean(o.failed);
|
|
224
|
+
if (resultMaybe !== undefined)
|
|
225
|
+
result = resultMaybe;
|
|
226
|
+
}
|
|
227
|
+
else if (typeof failedOrResult === "boolean") {
|
|
228
|
+
failed = failedOrResult;
|
|
229
|
+
result = resultMaybe;
|
|
230
|
+
}
|
|
231
|
+
else if (typeof resultMaybe === "boolean") {
|
|
232
|
+
result = failedOrResult;
|
|
233
|
+
failed = resultMaybe;
|
|
234
|
+
}
|
|
235
|
+
else if (failedOrResult === undefined) {
|
|
236
|
+
result = resultMaybe;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
result = failedOrResult;
|
|
240
|
+
}
|
|
241
|
+
const s = this.#sessions.get(sessionID);
|
|
242
|
+
if (!s)
|
|
243
|
+
return undefined;
|
|
244
|
+
const key = `${tool} ${stable(input)}`;
|
|
245
|
+
s.calls.push(key);
|
|
246
|
+
s.failed.push(failed);
|
|
247
|
+
const resultTextStr = result === undefined ? "" : (typeof result === "string" ? result : resultTextSafe(result));
|
|
248
|
+
// One definition of "changed something": the writes counter and the re-read window reset on the same calls.
|
|
249
|
+
// A `git commit` or `git add` through the shell is a write too; without this a session that read a file,
|
|
250
|
+
// committed and read again kept its read count and looked like a loop.
|
|
251
|
+
const wrote = WRITES.has(tool) || (tool === "shell" && /\b(git (add|commit)|>|tee|sed -i|mv|cp)\b/.test(inputText(input)));
|
|
252
|
+
if (wrote) {
|
|
253
|
+
s.writes++;
|
|
254
|
+
s.totalWrites++;
|
|
255
|
+
s.lastWrite = s.calls.length - 1;
|
|
256
|
+
const path = pathOf(input);
|
|
257
|
+
if (path)
|
|
258
|
+
s.writtenPaths.add(path);
|
|
259
|
+
}
|
|
260
|
+
// The same call again is a loop only when nothing was written in between: running the task's check after each
|
|
261
|
+
// edit is the work, not a circle (live run, 2026-10-25: a worker was stopped for its third `node check.js` with an
|
|
262
|
+
// edit before each). A write repeated with the same input still counts over the whole window.
|
|
263
|
+
const recent = s.calls.slice(-s.limits.window);
|
|
264
|
+
const since = wrote ? recent : s.calls.slice(Math.max(s.lastWrite + 1, s.calls.length - s.limits.window));
|
|
265
|
+
const same = since.filter((c) => c === key).length;
|
|
266
|
+
if (same >= s.limits.sameCall) {
|
|
267
|
+
s.lastRepeatedKey = key;
|
|
268
|
+
s.lastRepeatedInput = { tool, input };
|
|
269
|
+
s.lastRepeatedCount = same;
|
|
270
|
+
return { kind: "same_call", severity: "stop", detail: `${tool} with the same input ${same}x in the last ${recent.length} calls` };
|
|
271
|
+
}
|
|
272
|
+
const path = pathOf(input);
|
|
273
|
+
const i = input;
|
|
274
|
+
// A long file read part by part (offset/limit) is no loop (live test: a reader stopped while reading
|
|
275
|
+
// conversation.py in three parts); the same part again is.
|
|
276
|
+
const part = READS.has(tool) && path ? `${path}@${String(i?.offset ?? 0)}+${String(i?.limit ?? "")}` : "";
|
|
277
|
+
s.readWindow.push(part);
|
|
278
|
+
if (s.readWindow.length > s.limits.readWindow)
|
|
279
|
+
s.readWindow.shift(); // only recent work counts as a repeat
|
|
280
|
+
if (wrote)
|
|
281
|
+
s.readWindow.length = 0; // a write changes what a re-read shows
|
|
282
|
+
if (part) {
|
|
283
|
+
const n = s.readWindow.filter((p) => p === part).length;
|
|
284
|
+
if (n >= s.limits.readRepeat) {
|
|
285
|
+
s.lastRepeatedKey = key;
|
|
286
|
+
s.lastRepeatedInput = { tool, input };
|
|
287
|
+
s.lastRepeatedCount = n;
|
|
288
|
+
return { kind: "read_loop", severity: "nudge", detail: `read ${path}${i?.offset !== undefined ? ` from line ${String(i.offset)}` : ""} ${n}x in a row with no write in between` };
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Progress, not only new files. A search counts, and so does a command that ran and did not fail -- including
|
|
292
|
+
// the `execute` tool, which is how a worker acts in code mode and which opens no path for the check below to
|
|
293
|
+
// see. Only a command that keeps failing counts towards the run (see ACTS above).
|
|
294
|
+
if (wrote || SEARCHES.has(tool))
|
|
295
|
+
s.quiet = 0;
|
|
296
|
+
else if (ACTS.has(tool) && !failed)
|
|
297
|
+
s.quiet = 0;
|
|
298
|
+
else if (path && READS.has(tool) && !s.readPaths.has(path)) {
|
|
299
|
+
s.readPaths.add(path);
|
|
300
|
+
s.quiet = 0;
|
|
301
|
+
}
|
|
302
|
+
else
|
|
303
|
+
s.quiet++;
|
|
304
|
+
if (s.limits.noNewFiles > 0 && s.quiet >= s.limits.noNewFiles) {
|
|
305
|
+
return { kind: "no_new_files", severity: "stop", detail: `${s.quiet} calls in a row without progress: no new file, no search, no command that worked` };
|
|
306
|
+
}
|
|
307
|
+
const k = s.limits.restartLength;
|
|
308
|
+
if (s.calls.length >= 2 * k && s.calls.slice(-k).join("\n") === s.calls.slice(0, k).join("\n")) {
|
|
309
|
+
return { kind: "restart", detail: `the first ${k} calls came again: the session started over` };
|
|
310
|
+
}
|
|
311
|
+
// --- novelty tracking (this task) ---------------------------------------------
|
|
312
|
+
if (READS.has(tool) && path) {
|
|
313
|
+
if (!s.readPaths.has(path))
|
|
314
|
+
s.readPaths.add(path);
|
|
315
|
+
// newFiles is computed in progress() from checkpointReadPaths; nothing to do here.
|
|
316
|
+
if (resultTextStr) {
|
|
317
|
+
const lines = resultTextStr.split(/\r?\n/).filter((l) => l.trim() !== "");
|
|
318
|
+
if (lines.length > 0) {
|
|
319
|
+
const seen = s.seenLines.get(path) ?? new Set();
|
|
320
|
+
// One hash per line, reused for the count and for `seen`: hashing each line twice was pure waste on the
|
|
321
|
+
// hottest path in the plugin (every read result of every watched session).
|
|
322
|
+
const hashes = lines.map((line) => sha256(line));
|
|
323
|
+
let unseen = 0;
|
|
324
|
+
for (const h of hashes)
|
|
325
|
+
if (!seen.has(h))
|
|
326
|
+
unseen++;
|
|
327
|
+
for (const h of hashes)
|
|
328
|
+
seen.add(h);
|
|
329
|
+
s.seenLines.set(path, seen);
|
|
330
|
+
const seenRatio = (lines.length - unseen) / lines.length;
|
|
331
|
+
if (seenRatio < 0.9)
|
|
332
|
+
s.newLines += unseen;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (ACTS.has(tool) || tool === "shell" || tool === "bash" || tool === "execute") {
|
|
337
|
+
const inp = input;
|
|
338
|
+
const cmd = typeof inp?.command === "string" ? inp.command : (typeof inp?.code === "string" ? inp.code : undefined);
|
|
339
|
+
if (cmd)
|
|
340
|
+
s.lastCommand = cmd;
|
|
341
|
+
}
|
|
342
|
+
// --- repeat tracking (ring buffer of last ~12 signatures with identical result) ---
|
|
343
|
+
const resultHash = sha256(resultTextStr).slice(0, 16);
|
|
344
|
+
const combined = `${key}#${resultHash}`;
|
|
345
|
+
s.ring.push(combined);
|
|
346
|
+
if (s.ring.length > 12)
|
|
347
|
+
s.ring.shift();
|
|
348
|
+
// Track the most repeated combined signature for a concrete nudge message.
|
|
349
|
+
const counts = new Map();
|
|
350
|
+
for (const e of s.ring)
|
|
351
|
+
counts.set(e, (counts.get(e) ?? 0) + 1);
|
|
352
|
+
let maxCount = 0;
|
|
353
|
+
let maxKey = "";
|
|
354
|
+
for (const [kk, v] of counts)
|
|
355
|
+
if (v > maxCount) {
|
|
356
|
+
maxCount = v;
|
|
357
|
+
maxKey = kk;
|
|
358
|
+
}
|
|
359
|
+
const repeatCount = Math.max(maxCount, same);
|
|
360
|
+
if (repeatCount >= 2) {
|
|
361
|
+
s.lastRepeatedKey = maxKey ? maxKey.split("#")[0] : key;
|
|
362
|
+
s.lastRepeatedInput = { tool, input };
|
|
363
|
+
s.lastRepeatedCount = repeatCount;
|
|
364
|
+
}
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
// A checkpoint is due when the session's interval is reached, or earlier when the watchdog sees signs of a stall: a
|
|
368
|
+
// long stretch without a write, or many failures among the last calls (at least PULL_GAP steps after the last
|
|
369
|
+
// review, so one bad patch does not ask the decider on every step). Unscheduled: every CHECKPOINT_STEPS steps.
|
|
370
|
+
checkpointDue(sessionID, every = CHECKPOINT_STEPS) {
|
|
371
|
+
const s = this.#sessions.get(sessionID);
|
|
372
|
+
if (!s || s.steps === 0)
|
|
373
|
+
return false;
|
|
374
|
+
if (s.next === undefined)
|
|
375
|
+
return s.steps % every === 0;
|
|
376
|
+
if (s.steps >= s.next)
|
|
377
|
+
return true;
|
|
378
|
+
const sinceWrite = s.calls.length - 1 - s.lastWrite;
|
|
379
|
+
const failing = s.failed.slice(-12).filter(Boolean).length;
|
|
380
|
+
return s.steps - s.lastCheck >= PULL_GAP && (sinceWrite >= PULL_SINCE_WRITE || failing >= PULL_FAILURES);
|
|
381
|
+
}
|
|
382
|
+
progress(sessionID) {
|
|
383
|
+
const s = this.#sessions.get(sessionID);
|
|
384
|
+
if (!s)
|
|
385
|
+
return undefined;
|
|
386
|
+
const tail = s.calls.slice(-12);
|
|
387
|
+
// newFiles: distinct paths first touched since the last checkpoint.
|
|
388
|
+
let newFiles = 0;
|
|
389
|
+
for (const p of s.readPaths)
|
|
390
|
+
if (!s.checkpointReadPaths.has(p))
|
|
391
|
+
newFiles++;
|
|
392
|
+
// repeats: max occurrences of one combined signature in the ring buffer.
|
|
393
|
+
const counts = new Map();
|
|
394
|
+
for (const e of s.ring)
|
|
395
|
+
counts.set(e, (counts.get(e) ?? 0) + 1);
|
|
396
|
+
let repeats = 0;
|
|
397
|
+
for (const v of counts.values())
|
|
398
|
+
if (v > repeats)
|
|
399
|
+
repeats = v;
|
|
400
|
+
// cycle over <=3 signatures?
|
|
401
|
+
const cycle = detectCycle(s.ring);
|
|
402
|
+
const filesTouched = [...new Set([...s.readPaths, ...s.writtenPaths])];
|
|
403
|
+
const repeatDetail = (repeats >= 2 || cycle)
|
|
404
|
+
? (s.lastRepeatedCount && s.lastRepeatedInput
|
|
405
|
+
? formatRepeat(s.lastRepeatedInput.tool, s.lastRepeatedInput.input, s.lastRepeatedCount)
|
|
406
|
+
: (s.lastRepeatedKey ? `${s.lastRepeatedKey} ${repeats}x` : undefined))
|
|
407
|
+
: undefined;
|
|
408
|
+
return {
|
|
409
|
+
steps: s.steps,
|
|
410
|
+
calls: s.calls.length,
|
|
411
|
+
writes: s.writes,
|
|
412
|
+
callsSinceWrite: s.calls.length - 1 - s.lastWrite,
|
|
413
|
+
filesRead: s.readPaths.size,
|
|
414
|
+
newLines: s.newLines,
|
|
415
|
+
newFiles,
|
|
416
|
+
repeats,
|
|
417
|
+
cycle,
|
|
418
|
+
filesTouched,
|
|
419
|
+
repeatDetail,
|
|
420
|
+
lastCommand: s.lastCommand,
|
|
421
|
+
seenLines: s.seenLines,
|
|
422
|
+
seenLineHashes: s.seenLines,
|
|
423
|
+
recent: tail.map((c) => c.slice(0, 120)),
|
|
424
|
+
recentFailures: s.failed.slice(-12).filter(Boolean).length,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
// One provider turn; messages as the context hook gives them (role + content parts).
|
|
428
|
+
onTurn(sessionID, messages) {
|
|
429
|
+
const s = this.#sessions.get(sessionID);
|
|
430
|
+
if (!s)
|
|
431
|
+
return undefined;
|
|
432
|
+
s.steps++;
|
|
433
|
+
if (s.steps > s.limits.maxSteps)
|
|
434
|
+
return { kind: "steps", detail: `more than ${s.limits.maxSteps} steps` };
|
|
435
|
+
if (!Array.isArray(messages))
|
|
436
|
+
return undefined;
|
|
437
|
+
const assistant = messages.filter((m) => m.role === "assistant");
|
|
438
|
+
const parts = (m) => (Array.isArray(m.content) ? m.content : []);
|
|
439
|
+
let silent = 0;
|
|
440
|
+
for (let i = assistant.length - 1; i >= 0 && !parts(assistant[i]).some((p) => p.type === "tool-call"); i--)
|
|
441
|
+
silent++;
|
|
442
|
+
// A nudge, not a stop: a worker that writes a long report in several messages was interrupted mid-report (live
|
|
443
|
+
// run, 2026-10-06), and three text turns say nothing about a loop.
|
|
444
|
+
if (silent >= s.limits.monologue)
|
|
445
|
+
return { kind: "monologue", severity: "nudge", detail: `${silent} replies in a row without a tool call` };
|
|
446
|
+
const last = assistant.at(-1);
|
|
447
|
+
const text = last ? normalize(parts(last).filter((p) => p.type === "text").map((p) => p.text ?? "").join(" ")) : "";
|
|
448
|
+
if (text.length > 40) {
|
|
449
|
+
if (s.texts.has(text))
|
|
450
|
+
return { kind: "repeat_text", detail: "the same answer text came again" };
|
|
451
|
+
if (s.texts.size >= MAX_TEXTS) {
|
|
452
|
+
const oldest = s.texts.values().next().value;
|
|
453
|
+
if (oldest !== undefined)
|
|
454
|
+
s.texts.delete(oldest);
|
|
455
|
+
}
|
|
456
|
+
s.texts.add(text);
|
|
457
|
+
}
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
// What a fresh session is told after the watchdog stopped (or nudged) the previous one.
|
|
462
|
+
export function handoffNote(signal, changed, progress) {
|
|
463
|
+
const what = signal.severity === "nudge" ? "drew a nudge from the loop watchdog, not a stop" : "was stopped by the loop watchdog";
|
|
464
|
+
const digest = [
|
|
465
|
+
"Digest:",
|
|
466
|
+
`Files touched: ${changed.join(", ") || (progress?.filesTouched?.join(", ") ?? "none")}`,
|
|
467
|
+
`Learned: ${progress?.newLines ?? 0} new lines, ${progress?.newFiles ?? 0} new files`,
|
|
468
|
+
`Last command: ${progress?.lastCommand ?? "none"}`,
|
|
469
|
+
].join("\n");
|
|
470
|
+
return [
|
|
471
|
+
`A previous attempt at this task ${what}: ${signal.detail}.`,
|
|
472
|
+
changed.length ? `Files already changed in this directory: ${changed.join(", ")}. Check them instead of starting over.` : "No file was changed yet.",
|
|
473
|
+
digest,
|
|
474
|
+
"Do not read the same file again and again: once you have read a file, use what you know. If something is missing, say so in your report.",
|
|
475
|
+
].join("\n");
|
|
476
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// modern-web-guidance as a skill agents can use (Google Chrome, Apache-2.0; installed by creative-tools.ts at its pin).
|
|
2
|
+
// The upstream skill tells an agent to run `npx -y modern-web-guidance@latest …` for every web task: that fetches and
|
|
3
|
+
// runs whatever version is newest, over the network, every time. omacode installs one pinned, checksum-checked copy
|
|
4
|
+
// and registers an adapted skill instead (Apache-2.0 §4: the change is stated in the skill itself):
|
|
5
|
+
//
|
|
6
|
+
// - every `npx -y modern-web-guidance@latest` becomes `node "<copy>/modern-web.mjs"`: local, pinned, offline;
|
|
7
|
+
// - the section on npx, pnpx and asking for network access is dropped (none is needed);
|
|
8
|
+
// - "MANDATORY … Do NOT skip" becomes a plain instruction, and a note asks for features that are Baseline widely
|
|
9
|
+
// available unless the user targets newer browsers (each guide states its support and a fallback).
|
|
10
|
+
//
|
|
11
|
+
// search and retrieve report nothing to Google; the commands that would (install, update, list, legacy-scan) run with
|
|
12
|
+
// DISABLE_TELEMETRY=1 in every agent shell (core/telemetry.ts).
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { home, PINS, webGuidanceDir } from "./creative-tools.js";
|
|
16
|
+
export const WEB_GUIDANCE_SKILL = "modern-web-guidance";
|
|
17
|
+
const NOTE = (dir) => `> Adapted by omacode from modern-web-guidance ${PINS.webGuidance} (Google Chrome, Apache-2.0; licence in ${dir}/LICENSE):
|
|
18
|
+
> the commands run the pinned local copy instead of \`npx … @latest\`, which needs no network; the npx section is left
|
|
19
|
+
> out. Prefer features that are Baseline widely available unless the user targets newer browsers: every guide states
|
|
20
|
+
> its browser support and gives a fallback.`;
|
|
21
|
+
export function adaptGuidance(text, dir) {
|
|
22
|
+
const cli = `node "${join(dir, "modern-web.mjs")}"`;
|
|
23
|
+
let out = text
|
|
24
|
+
.replace(/npx -y modern-web-guidance@latest/g, cli)
|
|
25
|
+
.replace(/npx modern-web-guidance@latest/g, cli)
|
|
26
|
+
.replace(/Run `modern-web-guidance` directly with `npx`/g, "Run the local `modern-web-guidance` (the command below)")
|
|
27
|
+
.replace(/MANDATORY: Execute FIRST for all HTML\/CSS and clientside JS tasks\. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns\./, "Use it first for HTML/CSS and client-side JS work: web APIs evolve rapidly and training data contains obsolete patterns.");
|
|
28
|
+
// The section about running it through npx/pnpx and asking for network access: not needed for the local copy.
|
|
29
|
+
out = out.replace(/\n## Using npx \/ pnpx\n[\s\S]*?(?=\n## )/, "\n");
|
|
30
|
+
// The note goes right after the front matter.
|
|
31
|
+
const end = out.indexOf("\n---", 3);
|
|
32
|
+
return end > 0 ? `${out.slice(0, end + 4)}\n\n${NOTE(dir)}\n${out.slice(end + 4)}` : `${NOTE(dir)}\n\n${out}`;
|
|
33
|
+
}
|
|
34
|
+
// The skill when the copy is installed, else nothing (it is an optional part).
|
|
35
|
+
export function webGuidanceSkill(h = home()) {
|
|
36
|
+
const dir = webGuidanceDir(h);
|
|
37
|
+
const path = join(dir, "SKILL.md");
|
|
38
|
+
if (!existsSync(path) || !existsSync(join(dir, "modern-web.mjs")))
|
|
39
|
+
return undefined;
|
|
40
|
+
const content = adaptGuidance(readFileSync(path, "utf8"), dir);
|
|
41
|
+
const description = /^description:\s*\|?\s*\n?\s*(.+)$/m.exec(content)?.[1]?.trim() ?? "modern web development best practices, searched offline";
|
|
42
|
+
return { name: WEB_GUIDANCE_SKILL, description, path, content };
|
|
43
|
+
}
|
package/dist/which.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// "Installed" has one meaning in this plugin: a file of that name on PATH. browser.ts used this test for ffmpeg and
|
|
2
|
+
// ffprobe; backends.ts asks it about the optional local decision servers (A2-T1), so the test lives in one place.
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
export function findTool(name, env = process.env) {
|
|
6
|
+
const exts = process.platform === "win32" ? [".exe", ".cmd", ""] : [""];
|
|
7
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) {
|
|
8
|
+
for (const ext of exts) {
|
|
9
|
+
const file = join(dir, name + ext);
|
|
10
|
+
try {
|
|
11
|
+
if (statSync(file).isFile())
|
|
12
|
+
return file;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// not here
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|