@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/services.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// The local services on a host (roadmap A6, the 1.0 cut): the decider and the memory's embedding service, run by the
|
|
2
|
+
// supervisor (@omacode/core/supervisor) as one user service, `omacode-services`. The supervisor starts a service on its
|
|
3
|
+
// first request, stops it after ten idle minutes and starts it again on the next one, so a laptop does not keep two
|
|
4
|
+
// models in memory nobody asks; its fronts listen on the services' usual ports (8781, 8093) behind a token, and the
|
|
5
|
+
// plugin finds the token in $XDG_RUNTIME_DIR/omacode (@omacode/core/services).
|
|
6
|
+
//
|
|
7
|
+
// omacode services install [--embedding 0.6b|4b|8b] [--replace] copy the decider, sync it, write and start the unit
|
|
8
|
+
// omacode services status what runs, from the supervisor's status file
|
|
9
|
+
// omacode services remove [--purge] stop and remove the unit; --purge also the files
|
|
10
|
+
//
|
|
11
|
+
// Nothing a model needs is downloaded at install time: the decider's weights come on its first start (from Hugging
|
|
12
|
+
// Face, or the tuned checkpoint shipped in the plugin's decider/models/), the embedding weights the same way unless a
|
|
13
|
+
// file of the size is already on the machine.
|
|
14
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
17
|
+
import { userDataDir } from "@omacode/core/paths";
|
|
18
|
+
import { serviceLabel } from "@omacode/core/service-control";
|
|
19
|
+
import { runDir } from "@omacode/core/services";
|
|
20
|
+
export const UNIT = "omacode-services";
|
|
21
|
+
export const PORTS = { decider: 8781, embedding: 8093, comfyui: 8188 };
|
|
22
|
+
export const EMBEDDING_SIZES = { "0.6b": "0.6B", "4b": "4B", "8b": "8B" };
|
|
23
|
+
// The services this replaces: what install.sh and decider/decider.service set up before A6.
|
|
24
|
+
export const OLD_UNITS = ["decider", "micromanager-embedding"];
|
|
25
|
+
// The decider before the tuned one, for a plugin that ships no checkpoint.
|
|
26
|
+
export const BASE_DECIDER_MODEL = "fastino/GLiNER2.5-multi-Decide";
|
|
27
|
+
// Where the installed services live: the decider's copy and its environment, the model files, the config the
|
|
28
|
+
// supervisor reads. Under the user's data directory, so `remove --purge` knows what is its own.
|
|
29
|
+
export function servicesHome() {
|
|
30
|
+
return join(userDataDir(), "services");
|
|
31
|
+
}
|
|
32
|
+
export const configPath = (home = servicesHome()) => join(home, "config.json");
|
|
33
|
+
export function readConfig(home = servicesHome()) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(readFileSync(configPath(home), "utf8"));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Adds ComfyUI to an installed services config, in auto (started by its first request). Without omacode-services
|
|
42
|
+
// installed there is nothing to add it to, and the caller says so.
|
|
43
|
+
export function registerComfy(comfy, home = servicesHome()) {
|
|
44
|
+
const config = readConfig(home);
|
|
45
|
+
if (!config)
|
|
46
|
+
return false;
|
|
47
|
+
const next = { ...config, comfyui: comfy, modes: { ...(config.modes ?? {}), comfyui: config.modes?.comfyui ?? "auto" } };
|
|
48
|
+
writeFileSync(configPath(home), JSON.stringify(next, null, 2) + "\n", { mode: 0o600 });
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
// The plugin's own decider/ directory: in the published package beside dist/ (scripts/pack-js.mjs copies it in), in a
|
|
52
|
+
// checkout at the repository root beside packages/.
|
|
53
|
+
export function deciderSource() {
|
|
54
|
+
const packed = resolve(import.meta.dirname, "..", "decider");
|
|
55
|
+
return existsSync(join(packed, "uv.lock")) ? packed : resolve(import.meta.dirname, "..", "..", "..", "decider");
|
|
56
|
+
}
|
|
57
|
+
// The newest tuned checkpoint the plugin ships (decider/models/<name>/model.safetensors), if any.
|
|
58
|
+
export function shippedModel(source = deciderSource()) {
|
|
59
|
+
const dir = join(source, "models");
|
|
60
|
+
if (!existsSync(dir))
|
|
61
|
+
return undefined;
|
|
62
|
+
const names = readdirSync(dir).filter((n) => existsSync(join(dir, n, "model.safetensors"))).sort();
|
|
63
|
+
return names.length ? names[names.length - 1] : undefined;
|
|
64
|
+
}
|
|
65
|
+
// The llama.cpp server: LLAMA_SERVER as a command line, llama-server on PATH, or the llama-vulkan build's serve verb
|
|
66
|
+
// (what install.sh used). As argv, never a shell string.
|
|
67
|
+
export function findLlamaServer(env = process.env) {
|
|
68
|
+
if (env.LLAMA_SERVER?.trim())
|
|
69
|
+
return env.LLAMA_SERVER.trim().split(/\s+/);
|
|
70
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) {
|
|
71
|
+
const file = join(dir, "llama-server");
|
|
72
|
+
if (isExecutable(file))
|
|
73
|
+
return [file];
|
|
74
|
+
}
|
|
75
|
+
const vulkan = join(env.HOME || homedir(), ".local", "bin", "llama-vulkan");
|
|
76
|
+
return isExecutable(vulkan) ? [vulkan, "serve"] : undefined;
|
|
77
|
+
}
|
|
78
|
+
function isExecutable(file) {
|
|
79
|
+
try {
|
|
80
|
+
const info = statSync(file);
|
|
81
|
+
return info.isFile() && (info.mode & 0o111) !== 0;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// An embedding file of this size already on the machine (install.sh put them under ~/Models/gguf), else the place a
|
|
88
|
+
// first start downloads it to.
|
|
89
|
+
export function ggufFor(size, home = servicesHome(), env = process.env) {
|
|
90
|
+
const name = `Qwen3-Embedding-${EMBEDDING_SIZES[size]}-Q8_0.gguf`;
|
|
91
|
+
const dir = `qwen3-embedding-${size}`;
|
|
92
|
+
const old = join(env.MICROMANAGER_MODELS || join(env.HOME || homedir(), "Models", "gguf"), dir, name);
|
|
93
|
+
if (existsSync(old))
|
|
94
|
+
return { path: old, present: true };
|
|
95
|
+
const own = join(home, "models", dir, name);
|
|
96
|
+
return { path: own, present: existsSync(own) };
|
|
97
|
+
}
|
|
98
|
+
export const embeddingUrl = (size) => `https://huggingface.co/Qwen/Qwen3-Embedding-${EMBEDDING_SIZES[size]}-GGUF/resolve/main/Qwen3-Embedding-${EMBEDDING_SIZES[size]}-Q8_0.gguf`;
|
|
99
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
100
|
+
// The unit files. Both run the supervisor with the node that runs this command, so a version manager's node keeps
|
|
101
|
+
// working after a reboot, and both name nothing of the user's checkout but the plugin's own entry file.
|
|
102
|
+
export function supervisorEntry() {
|
|
103
|
+
// .ts in a checkout, .js in the published package (Node runs no TypeScript from node_modules)
|
|
104
|
+
return resolve(import.meta.dirname, `services-main${extname(import.meta.filename)}`);
|
|
105
|
+
}
|
|
106
|
+
export function systemdUnit(node, entry, home) {
|
|
107
|
+
return `# Written by \`omacode services install\` (packages/micromanager/src/services.ts); \`omacode services remove\` takes it away.
|
|
108
|
+
[Unit]
|
|
109
|
+
Description=Omacode local services: decider and memory embeddings, started on demand
|
|
110
|
+
|
|
111
|
+
[Service]
|
|
112
|
+
Environment=OMACODE_SERVICES_HOME=${home}
|
|
113
|
+
Environment=OMACODE_RUN_DIR=%t/omacode
|
|
114
|
+
ExecStart=${node} ${entry}
|
|
115
|
+
Restart=on-failure
|
|
116
|
+
RestartSec=5
|
|
117
|
+
# The decider peaked at 2.6 GB, a 4B embedding model takes about 5 GB, and ComfyUI loads an image model through system
|
|
118
|
+
# RAM (on an integrated GPU it stays there); past this the unit is restarted instead of pushing the desktop into swap.
|
|
119
|
+
# No CUDA_VISIBLE_DEVICES here: ROCm reads it too, and the decider hides the GPUs from itself in its own environment.
|
|
120
|
+
MemoryMax=20G
|
|
121
|
+
MemorySwapMax=0
|
|
122
|
+
|
|
123
|
+
[Install]
|
|
124
|
+
WantedBy=default.target
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
export function launchdPlist(node, entry, home, runDirPath) {
|
|
128
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<");
|
|
129
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
130
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
131
|
+
<plist version="1.0">
|
|
132
|
+
<dict>
|
|
133
|
+
<key>Label</key><string>dev.omacode.services</string>
|
|
134
|
+
<key>ProgramArguments</key><array><string>${esc(node)}</string><string>${esc(entry)}</string></array>
|
|
135
|
+
<key>EnvironmentVariables</key><dict>
|
|
136
|
+
<key>OMACODE_SERVICES_HOME</key><string>${esc(home)}</string>
|
|
137
|
+
<key>OMACODE_RUN_DIR</key><string>${esc(runDirPath)}</string>
|
|
138
|
+
</dict>
|
|
139
|
+
<key>RunAtLoad</key><true/>
|
|
140
|
+
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
141
|
+
</dict>
|
|
142
|
+
</plist>
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
export function unitPath(platform = process.platform, env = process.env) {
|
|
146
|
+
const home = env.HOME || homedir();
|
|
147
|
+
return platform === "darwin"
|
|
148
|
+
? join(home, "Library", "LaunchAgents", "dev.omacode.services.plist")
|
|
149
|
+
: join(env.XDG_CONFIG_HOME || join(home, ".config"), "systemd", "user", `${UNIT}.service`);
|
|
150
|
+
}
|
|
151
|
+
const ok = (r) => r.code === 0;
|
|
152
|
+
// Which of the old units exist on this machine, so install can say what it would replace.
|
|
153
|
+
export async function oldUnits(run, env = process.env) {
|
|
154
|
+
const dir = join(env.XDG_CONFIG_HOME || join(env.HOME || homedir(), ".config"), "systemd", "user");
|
|
155
|
+
return OLD_UNITS.filter((u) => existsSync(join(dir, `${u}.service`)));
|
|
156
|
+
}
|
|
157
|
+
export async function install(run, o = {}) {
|
|
158
|
+
const log = o.log ?? (() => { });
|
|
159
|
+
const env = o.env ?? process.env;
|
|
160
|
+
const platform = o.platform ?? process.platform;
|
|
161
|
+
const home = o.home ?? servicesHome();
|
|
162
|
+
const source = o.source ?? deciderSource();
|
|
163
|
+
const node = o.node ?? process.execPath;
|
|
164
|
+
const lines = [];
|
|
165
|
+
const say = (line) => {
|
|
166
|
+
lines.push(line);
|
|
167
|
+
log(line);
|
|
168
|
+
};
|
|
169
|
+
// Preflight: what has to be there before anything is written.
|
|
170
|
+
if (!existsSync(join(source, "uv.lock")))
|
|
171
|
+
return { ok: false, text: `the plugin's decider is not at ${source} (no uv.lock)` };
|
|
172
|
+
if (!ok(await run("uv", ["--version"], { cwd: process.cwd() }).catch(() => ({ code: 1 })))) {
|
|
173
|
+
return { ok: false, text: "uv is not installed; the decider's environment is made with it: https://docs.astral.sh/uv/getting-started/installation/" };
|
|
174
|
+
}
|
|
175
|
+
const old = platform === "linux" ? await oldUnits(run, env) : [];
|
|
176
|
+
if (old.length && !o.replace) {
|
|
177
|
+
return { ok: false, text: `this machine runs ${old.map((u) => `${u}.service`).join(" and ")} on the same ports; run again with --replace to stop and disable them (their files stay)` };
|
|
178
|
+
}
|
|
179
|
+
// The decider: a copy of the plugin's decider/ without its environments, then its own environment from the lock.
|
|
180
|
+
const decider = join(home, "decider");
|
|
181
|
+
mkdirSync(home, { recursive: true });
|
|
182
|
+
rmSync(decider, { recursive: true, force: true });
|
|
183
|
+
cpSync(source, decider, { recursive: true, filter: (from) => !/\/(\.venv|train|tests|__pycache__|runs)(\/|$)/.test(from.slice(source.length)) });
|
|
184
|
+
say(`copied the decider to ${decider}`);
|
|
185
|
+
const synced = await run("uv", ["sync", "--frozen", "--no-dev"], { cwd: decider, timeoutMs: 30 * 60_000 });
|
|
186
|
+
if (!ok(synced))
|
|
187
|
+
return { ok: false, text: `uv sync failed in ${decider}: ${synced.stderr.trim().slice(-500)}` };
|
|
188
|
+
const shipped = shippedModel(decider);
|
|
189
|
+
const model = shipped ? join(decider, "models", shipped) : BASE_DECIDER_MODEL;
|
|
190
|
+
say(`decider model: ${shipped ? `the tuned ${shipped}` : `${BASE_DECIDER_MODEL}, downloaded on its first start`}`);
|
|
191
|
+
// The embedding service: a size already on the machine wins over the default, so stored vectors keep their model.
|
|
192
|
+
const size = o.embedding ?? (["4b", "8b", "0.6b"].find((s) => ggufFor(s, home, env).present) ?? "0.6b");
|
|
193
|
+
const gguf = ggufFor(size, home, env);
|
|
194
|
+
const server = findLlamaServer(env);
|
|
195
|
+
if (!server)
|
|
196
|
+
say("no llama.cpp server found (llama-server on PATH, or LLAMA_SERVER): memory search runs on keywords until one is installed");
|
|
197
|
+
say(`embedding: Qwen3-Embedding-${EMBEDDING_SIZES[size]}${gguf.present ? ` from ${gguf.path}` : ", downloaded on its first start"}`);
|
|
198
|
+
// A ComfyUI registered before stays: it was installed on its own (`omacode tools install comfyui`).
|
|
199
|
+
const before = readConfig(home);
|
|
200
|
+
const config = {
|
|
201
|
+
...(before?.comfyui ? { comfyui: before.comfyui } : {}),
|
|
202
|
+
decider: { bin: join(decider, ".venv", "bin", "decider"), model },
|
|
203
|
+
embedding: { server: server ?? [], gguf: gguf.path, url: embeddingUrl(size), model: `qwen3-embedding-${size}` },
|
|
204
|
+
// The embedding service is off until the user switches it on (/services): a fresh install must not load a
|
|
205
|
+
// multi-GB model on the first message nobody asked for. A mode the user chose survives a re-install while a
|
|
206
|
+
// llama.cpp server is on the machine, as a registered ComfyUI does; without a server the service cannot run.
|
|
207
|
+
// The decider stays on demand; a decision is a few ms.
|
|
208
|
+
modes: { decider: "auto", embedding: server ? (before?.modes?.embedding ?? "off") : "off", ...(before?.comfyui ? { comfyui: before.modes?.comfyui ?? "auto" } : {}) },
|
|
209
|
+
idleMinutes: 10,
|
|
210
|
+
};
|
|
211
|
+
writeFileSync(configPath(home), JSON.stringify(config, null, 2) + "\n", { mode: 0o600 });
|
|
212
|
+
// The unit, and the old units out of the way.
|
|
213
|
+
const unit = unitPath(platform, env);
|
|
214
|
+
mkdirSync(dirname(unit), { recursive: true });
|
|
215
|
+
const entry = supervisorEntry();
|
|
216
|
+
if (platform === "darwin") {
|
|
217
|
+
writeFileSync(unit, launchdPlist(node, entry, home, join(env.TMPDIR || "/tmp", "omacode")));
|
|
218
|
+
await run("launchctl", ["unload", unit], { cwd: home }).catch(() => undefined);
|
|
219
|
+
const loaded = await run("launchctl", ["load", "-w", unit], { cwd: home });
|
|
220
|
+
if (!ok(loaded))
|
|
221
|
+
return { ok: false, text: `launchctl load failed: ${loaded.stderr.trim()}` };
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
for (const u of old) {
|
|
225
|
+
await run("systemctl", ["--user", "disable", "--now", `${u}.service`], { cwd: home });
|
|
226
|
+
say(`stopped and disabled ${u}.service (its file stays)`);
|
|
227
|
+
}
|
|
228
|
+
writeFileSync(unit, systemdUnit(node, entry, home));
|
|
229
|
+
await run("systemctl", ["--user", "daemon-reload"], { cwd: home });
|
|
230
|
+
const started = await run("systemctl", ["--user", "enable", "--now", `${UNIT}.service`], { cwd: home });
|
|
231
|
+
if (!ok(started))
|
|
232
|
+
return { ok: false, text: `systemctl could not start ${UNIT}: ${started.stderr.trim()}` };
|
|
233
|
+
}
|
|
234
|
+
say(`${UNIT} runs; the decider listens on ${PORTS.decider} and starts with the unit; the embedding service on ${PORTS.embedding} is off until /services switches it on`);
|
|
235
|
+
return { ok: true, text: lines.join("\n") };
|
|
236
|
+
}
|
|
237
|
+
export function status(env = process.env) {
|
|
238
|
+
const file = join(runDir(env), "status.json");
|
|
239
|
+
if (!existsSync(file))
|
|
240
|
+
return `${UNIT} is not running (no ${file})`;
|
|
241
|
+
try {
|
|
242
|
+
const s = JSON.parse(readFileSync(file, "utf8"));
|
|
243
|
+
return Object.entries(s.services ?? {}).map(([name, v]) => `${serviceLabel(name)}: ${v.mode ?? "?"} · ${v.state ?? "?"}${v.device ? ` · on ${v.device}` : ""} · ${v.url ?? ""}${v.detail ? ` · ${v.detail}` : ""}`).join("\n") + `\n(as of ${s.updated ?? "?"})`;
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return `${file} cannot be read`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export async function remove(run, o = {}) {
|
|
250
|
+
const platform = o.platform ?? process.platform;
|
|
251
|
+
const unit = unitPath(platform, o.env);
|
|
252
|
+
const home = o.home ?? servicesHome();
|
|
253
|
+
if (platform === "darwin")
|
|
254
|
+
await run("launchctl", ["unload", "-w", unit], { cwd: dirname(unit) }).catch(() => undefined);
|
|
255
|
+
else
|
|
256
|
+
await run("systemctl", ["--user", "disable", "--now", `${UNIT}.service`], { cwd: dirname(unit) }).catch(() => undefined);
|
|
257
|
+
rmSync(unit, { force: true });
|
|
258
|
+
if (platform !== "darwin")
|
|
259
|
+
await run("systemctl", ["--user", "daemon-reload"], { cwd: dirname(unit) }).catch(() => undefined);
|
|
260
|
+
if (o.purge) {
|
|
261
|
+
rmSync(home, { recursive: true, force: true });
|
|
262
|
+
return `removed ${UNIT} and ${home}`;
|
|
263
|
+
}
|
|
264
|
+
return `removed ${UNIT}; the decider's copy and the downloaded models stay in ${home} (--purge removes them)`;
|
|
265
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// The planning session (design.md §6): a design tree owned by code, worked one question per turn.
|
|
2
|
+
//
|
|
3
|
+
// The facilitator (the micromanager, on the user's session model) drafts the tree and asks; code validates the tree,
|
|
4
|
+
// keeps the frontier, applies the user's shortcuts and answers, and tells the facilitator what to do next. There
|
|
5
|
+
// are no suggested answers: options or explanations come only when the user is stuck or asks for them.
|
|
6
|
+
const IMPACT_RANK = { low: 0, medium: 1, high: 2 };
|
|
7
|
+
const CAP = { light: 5, normal: 12, frequent: Infinity };
|
|
8
|
+
const MAX_NODES = 25;
|
|
9
|
+
const ID = /^[A-Za-z][\w.-]{0,15}$/;
|
|
10
|
+
// The facilitator's draft: [{ id, question, kind, dependsOn, impact }], or { nodes: [...] }.
|
|
11
|
+
export function parseTree(raw, depth = "normal") {
|
|
12
|
+
const list = Array.isArray(raw) ? raw : raw?.nodes;
|
|
13
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
14
|
+
return { errors: ["the tree needs a non-empty list of questions"] };
|
|
15
|
+
if (list.length > MAX_NODES)
|
|
16
|
+
return { errors: [`at most ${MAX_NODES} questions, got ${list.length}`] };
|
|
17
|
+
const errors = [];
|
|
18
|
+
const nodes = [];
|
|
19
|
+
for (const [i, item] of list.entries()) {
|
|
20
|
+
const n = item;
|
|
21
|
+
const where = `question ${i + 1}${typeof n.id === "string" ? ` (${n.id})` : ""}`;
|
|
22
|
+
const deps = n.dependsOn ?? [];
|
|
23
|
+
if (typeof n.id !== "string" || !ID.test(n.id))
|
|
24
|
+
errors.push(`${where}: needs a short id`);
|
|
25
|
+
if (typeof n.question !== "string" || n.question.trim().length < 5)
|
|
26
|
+
errors.push(`${where}: needs the question text`);
|
|
27
|
+
if (!["decision", "fact", "assumption"].includes(String(n.kind ?? "decision")))
|
|
28
|
+
errors.push(`${where}: kind must be decision, fact or assumption`);
|
|
29
|
+
if (!["low", "medium", "high"].includes(String(n.impact)))
|
|
30
|
+
errors.push(`${where}: impact must be low, medium or high`);
|
|
31
|
+
if (!Array.isArray(deps) || !deps.every((d) => typeof d === "string"))
|
|
32
|
+
errors.push(`${where}: dependsOn must be a list of ids`);
|
|
33
|
+
if (errors.length)
|
|
34
|
+
continue;
|
|
35
|
+
nodes.push({
|
|
36
|
+
id: n.id,
|
|
37
|
+
question: n.question.trim(),
|
|
38
|
+
kind: (n.kind ?? "decision"),
|
|
39
|
+
dependsOn: deps,
|
|
40
|
+
impact: n.impact,
|
|
41
|
+
status: "open",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const ids = new Set();
|
|
45
|
+
for (const n of nodes) {
|
|
46
|
+
if (ids.has(n.id))
|
|
47
|
+
errors.push(`${n.id}: duplicate id`);
|
|
48
|
+
ids.add(n.id);
|
|
49
|
+
}
|
|
50
|
+
for (const n of nodes)
|
|
51
|
+
for (const d of n.dependsOn)
|
|
52
|
+
if (!ids.has(d))
|
|
53
|
+
errors.push(`${n.id}: depends on unknown ${d}`);
|
|
54
|
+
if (hasCycle(nodes))
|
|
55
|
+
errors.push("the questions depend on each other in a cycle");
|
|
56
|
+
return errors.length ? { errors } : { tree: { nodes, depth, asked: 0, turn: 0 } };
|
|
57
|
+
}
|
|
58
|
+
function hasCycle(nodes) {
|
|
59
|
+
const deps = new Map(nodes.map((n) => [n.id, n.dependsOn]));
|
|
60
|
+
const state = new Map();
|
|
61
|
+
const visit = (id) => {
|
|
62
|
+
if (state.get(id) === 2)
|
|
63
|
+
return false;
|
|
64
|
+
if (state.get(id) === 1)
|
|
65
|
+
return true;
|
|
66
|
+
state.set(id, 1);
|
|
67
|
+
const found = (deps.get(id) ?? []).some(visit);
|
|
68
|
+
state.set(id, 2);
|
|
69
|
+
return found;
|
|
70
|
+
};
|
|
71
|
+
return nodes.some((n) => visit(n.id));
|
|
72
|
+
}
|
|
73
|
+
// Adds nodes the facilitator found later (a new branch); same rules as the draft.
|
|
74
|
+
export function addNodes(tree, raw) {
|
|
75
|
+
const merged = parseTree([...tree.nodes.map((n) => ({ ...n })), ...(Array.isArray(raw) ? raw : [])], tree.depth);
|
|
76
|
+
if (merged.errors)
|
|
77
|
+
return merged.errors;
|
|
78
|
+
const known = new Map(tree.nodes.map((n) => [n.id, n]));
|
|
79
|
+
tree.nodes = merged.tree.nodes.map((n) => known.get(n.id) ?? n);
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
const RESOLVED = new Set(["settled", "assumed", "out_of_scope"]);
|
|
83
|
+
// Low-impact open decisions are not asked: they become assumptions, shown at the checkpoint. Open facts wait
|
|
84
|
+
// for agents, never for the user.
|
|
85
|
+
export function assumeLowImpact(tree) {
|
|
86
|
+
const assumed = tree.nodes.filter((n) => n.status === "open" && n.kind !== "fact" && n.impact === "low");
|
|
87
|
+
for (const n of assumed) {
|
|
88
|
+
n.status = "assumed";
|
|
89
|
+
n.origin = "assumed";
|
|
90
|
+
}
|
|
91
|
+
return assumed;
|
|
92
|
+
}
|
|
93
|
+
// Open decisions whose prerequisites are all resolved: the questions that can be asked now without guessing.
|
|
94
|
+
export function frontier(tree) {
|
|
95
|
+
const byId = new Map(tree.nodes.map((n) => [n.id, n]));
|
|
96
|
+
return tree.nodes.filter((n) => n.status === "open" && n.kind === "decision" && n.dependsOn.every((d) => RESOLVED.has(byId.get(d)?.status ?? "open")));
|
|
97
|
+
}
|
|
98
|
+
export function openFacts(tree) {
|
|
99
|
+
return tree.nodes.filter((n) => n.kind === "fact" && (n.status === "open" || n.status === "researching"));
|
|
100
|
+
}
|
|
101
|
+
// The rules' pick: highest impact, then the one most other questions wait on, then the draft's order.
|
|
102
|
+
export function ruleNext(tree) {
|
|
103
|
+
const waiting = (id) => tree.nodes.filter((n) => n.status === "open" && n.dependsOn.includes(id)).length;
|
|
104
|
+
return [...frontier(tree)].sort((a, b) => IMPACT_RANK[b.impact] - IMPACT_RANK[a.impact] || waiting(b.id) - waiting(a.id))[0];
|
|
105
|
+
}
|
|
106
|
+
export function capReached(tree) {
|
|
107
|
+
return tree.asked >= CAP[tree.depth];
|
|
108
|
+
}
|
|
109
|
+
export function settle(tree, id, answer, origin = "user") {
|
|
110
|
+
const n = tree.nodes.find((x) => x.id === id);
|
|
111
|
+
if (!n)
|
|
112
|
+
return;
|
|
113
|
+
n.status = "settled";
|
|
114
|
+
n.answer = answer;
|
|
115
|
+
n.origin = origin;
|
|
116
|
+
n.settledAt = tree.turn;
|
|
117
|
+
}
|
|
118
|
+
export function matchSessionShortcut(text) {
|
|
119
|
+
const t = text.trim().toLowerCase().replace(/[.!?]+$/, "");
|
|
120
|
+
if (["stop", "enough", "that's enough"].includes(t))
|
|
121
|
+
return { kind: "stop" };
|
|
122
|
+
if (["skip", "decide it yourself", "you decide"].includes(t))
|
|
123
|
+
return { kind: "skip" };
|
|
124
|
+
if (["wait what", "i don't get it", "i do not get it", "what do you mean"].includes(t))
|
|
125
|
+
return { kind: "wait_what" };
|
|
126
|
+
if (["light", "normal", "frequent"].includes(t))
|
|
127
|
+
return { kind: "depth", depth: t };
|
|
128
|
+
if (["confirm", "confirmed", "looks good", "go"].includes(t))
|
|
129
|
+
return { kind: "confirm" };
|
|
130
|
+
if (t === "discuss")
|
|
131
|
+
return { kind: "discuss" };
|
|
132
|
+
const back = t.match(/^(?:go )?back to ([a-z][\w.-]*)$/);
|
|
133
|
+
if (back)
|
|
134
|
+
return { kind: "back", id: back[1] };
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
// One user turn while a question is open. Without a reading (no decision model), an answer counts as settling.
|
|
138
|
+
export function applyAnswer(tree, text, reading = { settles: true }) {
|
|
139
|
+
tree.turn++;
|
|
140
|
+
const node = tree.nodes.find((n) => n.id === tree.current);
|
|
141
|
+
if (!node)
|
|
142
|
+
return undefined;
|
|
143
|
+
// A clear decision wins: help is offered only when the answer does not decide the question (live test: a firm
|
|
144
|
+
// answer also scored 0.71 on "asks for options").
|
|
145
|
+
if ((reading.stuck || reading.asksOptions) && !reading.settles)
|
|
146
|
+
return { kind: "explain", node };
|
|
147
|
+
if (reading.outOfScope) {
|
|
148
|
+
node.status = "out_of_scope";
|
|
149
|
+
node.answer = text;
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
if (reading.contradicts) {
|
|
153
|
+
const earlier = tree.nodes.filter((n) => n.status === "settled" && n.origin === "user");
|
|
154
|
+
if (earlier.length)
|
|
155
|
+
return { kind: "contradiction", node, earlier };
|
|
156
|
+
}
|
|
157
|
+
if (reading.settles === false)
|
|
158
|
+
return { kind: "repitch", node };
|
|
159
|
+
settle(tree, node.id, text);
|
|
160
|
+
if (reading.newBranches)
|
|
161
|
+
return { kind: "add_branches", node };
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
export function applyShortcut(tree, s) {
|
|
165
|
+
const node = tree.nodes.find((n) => n.id === tree.current);
|
|
166
|
+
switch (s.kind) {
|
|
167
|
+
case "stop":
|
|
168
|
+
return { kind: "stopped" };
|
|
169
|
+
case "skip":
|
|
170
|
+
if (node) {
|
|
171
|
+
node.status = "assumed";
|
|
172
|
+
node.origin = "assumed";
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
case "wait_what":
|
|
176
|
+
return node ? { kind: "repitch", node } : undefined;
|
|
177
|
+
case "back": {
|
|
178
|
+
const target = tree.nodes.find((n) => n.id.toLowerCase() === s.id.toLowerCase());
|
|
179
|
+
if (target) {
|
|
180
|
+
target.status = "open";
|
|
181
|
+
target.answer = undefined;
|
|
182
|
+
target.origin = undefined;
|
|
183
|
+
return { kind: "ask", node: target, reason: "the user reopened it" };
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
case "depth":
|
|
188
|
+
tree.depth = s.depth;
|
|
189
|
+
return undefined;
|
|
190
|
+
default:
|
|
191
|
+
return undefined; // confirm and discuss belong to the checkpoint
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// After a turn: the next question, the checkpoint, or waiting for facts.
|
|
195
|
+
export function nextStep(tree, pick) {
|
|
196
|
+
assumeLowImpact(tree);
|
|
197
|
+
const options = frontier(tree);
|
|
198
|
+
if (options.length === 0 || capReached(tree)) {
|
|
199
|
+
const facts = openFacts(tree);
|
|
200
|
+
if (options.length === 0 && facts.length > 0 && tree.nodes.some((n) => n.status === "open" && n.kind === "decision")) {
|
|
201
|
+
return { kind: "facts_pending", facts };
|
|
202
|
+
}
|
|
203
|
+
return { kind: "checkpoint" };
|
|
204
|
+
}
|
|
205
|
+
const chosen = options.find((n) => n.id === pick) ?? ruleNext(tree);
|
|
206
|
+
tree.current = chosen.id;
|
|
207
|
+
tree.asked++;
|
|
208
|
+
return { kind: "ask", node: chosen, reason: pick === chosen.id ? "the decision model picked it" : "highest impact first" };
|
|
209
|
+
}
|
|
210
|
+
// --- what the facilitator is told -------------------------------------------------------------------------
|
|
211
|
+
const RULES = `Rules of the planning session: ask exactly one question, in plain words, with one to three sentences of
|
|
212
|
+
context. Give no options, no examples of possible answers and no recommendation. Do not answer the question yourself. If a term may be new to the
|
|
213
|
+
user, add a short "Concept:" or "Why this matters:" line. Then stop and wait for the user's answer.`;
|
|
214
|
+
export function instruction(step, job, tree) {
|
|
215
|
+
const decided = tree.nodes.filter((n) => n.status === "settled" && n.origin === "user");
|
|
216
|
+
const settledLine = decided.length ? `\nDecided so far: ${decided.map((n) => `${n.id} ${n.answer}`).join(" | ")}` : "";
|
|
217
|
+
switch (step.kind) {
|
|
218
|
+
case "ask":
|
|
219
|
+
return `[planning session ${job}] Ask the user question ${step.node.id} now: "${step.node.question}"\n${RULES}${settledLine}`;
|
|
220
|
+
case "repitch":
|
|
221
|
+
return `[planning session ${job}] The user did not follow question ${step.node.id} ("${step.node.question}"). Ask it again with the context they were missing, in simpler words, still without options or a recommendation.${settledLine}`;
|
|
222
|
+
case "explain":
|
|
223
|
+
return `[planning session ${job}] The user is stuck on ${step.node.id} ("${step.node.question}") or asked for help. Now, and only now: explain the concept briefly or show two or three approaches with their trade-offs, without picking one. Then hand the decision back: ask which they would take, and why.${settledLine}`;
|
|
224
|
+
case "contradiction":
|
|
225
|
+
return `[planning session ${job}] The user's answer to ${step.node.id} may contradict an earlier decision (${step.earlier.map((n) => `${n.id}: ${n.answer}`).join("; ")}). Name both statements and ask which one holds. No recommendation.`;
|
|
226
|
+
case "add_branches":
|
|
227
|
+
return `[planning session ${job}] The answer to ${step.node.id} raised new decisions. Call plan_questions with job "${job}" and only the new questions (same format: id, question, kind, dependsOn, impact). Do not ask the user anything in this turn.`;
|
|
228
|
+
case "facts_pending":
|
|
229
|
+
return `[planning session ${job}] The remaining decisions wait for facts the agents must find: ${step.facts.map((n) => `${n.id} "${n.question}"`).join("; ")}. Tell the user briefly that these are being looked up; never ask the user for facts.`;
|
|
230
|
+
case "checkpoint":
|
|
231
|
+
return `[planning session ${job}] Design checkpoint. Show the user, apart from each other: (1) their decisions: ${decided.map((n) => `${n.id} ${n.question} -> ${n.answer}`).join("; ") || "none"}; (2) what was assumed without asking (mark these as proposals): ${tree.nodes.filter((n) => n.status === "assumed").map((n) => `${n.id} ${n.question}`).join("; ") || "nothing"}. Then ask them to answer "confirm" to plan with this, or "discuss" to change something.`;
|
|
232
|
+
case "stopped":
|
|
233
|
+
return `[planning session ${job}] The user stopped the planning session. Confirm briefly that the job is paused; plan_job with the job id continues it later.`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// The settled tree as the planner gets it: decisions and assumptions, one per line.
|
|
237
|
+
export function decisionsText(tree) {
|
|
238
|
+
return tree.nodes
|
|
239
|
+
.filter((n) => n.status === "settled" || n.status === "assumed")
|
|
240
|
+
.map((n) => `${n.question} -> ${n.status === "assumed" ? "assumed: the planner decides, and says what it chose" : n.answer}`);
|
|
241
|
+
}
|