master-orchestrator 0.0.0-stage → 0.1.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +174 -2
- package/package.json +56 -4
- package/src/adapters/agy.ts +285 -0
- package/src/adapters/claude.ts +317 -0
- package/src/adapters/codex.ts +162 -0
- package/src/adapters/common.ts +211 -0
- package/src/adapters/cursor.ts +242 -0
- package/src/adapters/dsh.ts +356 -0
- package/src/adapters/fake-agent.mjs +50 -0
- package/src/adapters/fake.ts +88 -0
- package/src/adapters/gemini.ts +225 -0
- package/src/adapters/grok.ts +328 -0
- package/src/adapters/muse.ts +281 -0
- package/src/adapters/omp.ts +119 -0
- package/src/adapters/opencode.ts +228 -0
- package/src/adapters/pi.ts +284 -0
- package/src/adapters/registry.ts +31 -0
- package/src/adapters/types.ts +201 -0
- package/src/config/load.ts +290 -0
- package/src/config/profiles.ts +64 -0
- package/src/config/schema.ts +158 -0
- package/src/config/write.ts +83 -0
- package/src/engine/artifacts.ts +145 -0
- package/src/engine/baseline.ts +132 -0
- package/src/engine/execute.ts +437 -0
- package/src/engine/git.ts +32 -0
- package/src/engine/hostenv.ts +54 -0
- package/src/engine/registry.ts +280 -0
- package/src/engine/runner.ts +203 -0
- package/src/engine/types.ts +55 -0
- package/src/engine/verify.ts +100 -0
- package/src/index.ts +602 -0
- package/src/prompts/envelope.ts +29 -0
- package/src/prompts/templates.ts +389 -0
- package/src/ui/configure.ts +174 -0
- package/src/ui/dialogs.ts +88 -0
- package/src/ui/doctor.ts +120 -0
- package/src/ui/format.ts +94 -0
- package/src/ui/host.ts +100 -0
- package/src/ui/render.ts +86 -0
- package/src/ui/widget.ts +70 -0
- package/src/workflows/budget.ts +66 -0
- package/src/workflows/common.ts +100 -0
- package/src/workflows/debate.ts +488 -0
- package/src/workflows/host.ts +78 -0
- package/src/workflows/plan-exec.ts +807 -0
- package/src/workflows/plan.ts +407 -0
- package/src/workflows/planfile.ts +380 -0
- package/src/workflows/planstate.ts +229 -0
- package/src/workflows/verdict.ts +74 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { Value } from "typebox/value";
|
|
4
|
+
import type { AgentAdapter } from "../adapters/types.ts";
|
|
5
|
+
import {
|
|
6
|
+
ConfigFileSchema,
|
|
7
|
+
defaultConfig,
|
|
8
|
+
ROLE_NAMES,
|
|
9
|
+
type ConfigFile,
|
|
10
|
+
type OrchestratorConfig,
|
|
11
|
+
} from "./schema.ts";
|
|
12
|
+
|
|
13
|
+
export const CONFIG_FILE_NAME = "master-orchestrator.json";
|
|
14
|
+
|
|
15
|
+
export interface ConfigError {
|
|
16
|
+
file: string;
|
|
17
|
+
pointer: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ConfigSource {
|
|
22
|
+
scope: "user" | "project";
|
|
23
|
+
path: string;
|
|
24
|
+
present: boolean;
|
|
25
|
+
/** Project files of untrusted projects are not read. */
|
|
26
|
+
ignored?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface LoadedConfig {
|
|
30
|
+
config: OrchestratorConfig;
|
|
31
|
+
errors: ConfigError[];
|
|
32
|
+
warnings: string[];
|
|
33
|
+
sources: ConfigSource[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface LoadOptions {
|
|
37
|
+
agentDir: string;
|
|
38
|
+
cwd: string;
|
|
39
|
+
configDirName: string;
|
|
40
|
+
projectTrusted: boolean;
|
|
41
|
+
adapters: ReadonlyMap<string, AgentAdapter>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function userConfigPath(agentDir: string): string {
|
|
45
|
+
return join(agentDir, CONFIG_FILE_NAME);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function projectConfigPath(cwd: string, configDirName: string): string {
|
|
49
|
+
return join(cwd, configDirName, CONFIG_FILE_NAME);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Removes `//` and `/* *\/` comments and trailing commas outside strings, so commented examples load. */
|
|
53
|
+
export function stripJsonComments(text: string): string {
|
|
54
|
+
let out = "";
|
|
55
|
+
let inString = false;
|
|
56
|
+
for (let i = 0; i < text.length; i++) {
|
|
57
|
+
const char = text[i];
|
|
58
|
+
if (inString) {
|
|
59
|
+
out += char;
|
|
60
|
+
if (char === "\\") {
|
|
61
|
+
out += text[i + 1] ?? "";
|
|
62
|
+
i++;
|
|
63
|
+
} else if (char === '"') inString = false;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (char === '"') {
|
|
67
|
+
inString = true;
|
|
68
|
+
out += char;
|
|
69
|
+
} else if (char === "/" && text[i + 1] === "/") {
|
|
70
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
71
|
+
out += "\n";
|
|
72
|
+
} else if (char === "/" && text[i + 1] === "*") {
|
|
73
|
+
i += 2;
|
|
74
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
|
|
75
|
+
i++;
|
|
76
|
+
} else {
|
|
77
|
+
out += char;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return out.replace(/,(\s*[}\]])/g, "$1");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function readConfigFile(path: string): Promise<{ present: boolean; value?: unknown; error?: string }> {
|
|
84
|
+
let text: string;
|
|
85
|
+
try {
|
|
86
|
+
text = await readFile(path, "utf8");
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { present: false };
|
|
89
|
+
return { present: true, error: `cannot read: ${(error as Error).message}` };
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return { present: true, value: JSON.parse(stripJsonComments(text)) };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return { present: true, error: `invalid JSON: ${(error as Error).message}` };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Schema errors, one per JSON pointer. */
|
|
99
|
+
export function validateConfigFile(value: unknown, file: string): ConfigError[] {
|
|
100
|
+
if (Value.Check(ConfigFileSchema, value)) return [];
|
|
101
|
+
const byPointer = new Map<string, string[]>();
|
|
102
|
+
for (const error of Value.Errors(ConfigFileSchema, value)) {
|
|
103
|
+
if (error.keyword === "boolean") continue; // duplicate of additionalProperties
|
|
104
|
+
let message = error.message;
|
|
105
|
+
if (error.keyword === "additionalProperties") {
|
|
106
|
+
const extra = (error.params as { additionalProperties?: string[] }).additionalProperties ?? [];
|
|
107
|
+
message = `unknown key${extra.length > 1 ? "s" : ""}: ${extra.join(", ")}`;
|
|
108
|
+
}
|
|
109
|
+
if (error.keyword === "const") {
|
|
110
|
+
const allowed = (error.params as { allowedValue?: unknown }).allowedValue;
|
|
111
|
+
message = `must be one of the allowed values (for example ${JSON.stringify(allowed)})`;
|
|
112
|
+
}
|
|
113
|
+
const pointer = error.instancePath || "/";
|
|
114
|
+
const list = byPointer.get(pointer) ?? [];
|
|
115
|
+
if (!list.includes(message)) list.push(message);
|
|
116
|
+
byPointer.set(pointer, list);
|
|
117
|
+
}
|
|
118
|
+
return [...byPointer].map(([pointer, messages]) => ({ file, pointer, message: messages.join("; ") }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type Json = Record<string, unknown>;
|
|
122
|
+
|
|
123
|
+
function isPlainObject(value: unknown): value is Json {
|
|
124
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Objects merge key by key; arrays and scalars replace. */
|
|
128
|
+
export function mergeConfig<T>(base: T, override: unknown): T {
|
|
129
|
+
if (!isPlainObject(base) || !isPlainObject(override)) return (override === undefined ? base : override) as T;
|
|
130
|
+
const result: Json = { ...base };
|
|
131
|
+
for (const [key, value] of Object.entries(override)) {
|
|
132
|
+
if (value === undefined) continue;
|
|
133
|
+
result[key] = isPlainObject(result[key]) && isPlainObject(value) ? mergeConfig(result[key], value) : value;
|
|
134
|
+
}
|
|
135
|
+
return result as T;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const STRICTNESS: Record<string, string[]> = {
|
|
139
|
+
implementFromTool: ["auto", "ask"],
|
|
140
|
+
workflowStart: ["auto", "ask"],
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A project must not choose executables, flags, environment or overlay files, and must not loosen approval.
|
|
145
|
+
*/
|
|
146
|
+
export function checkProjectRestrictions(project: ConfigFile, userEffective: OrchestratorConfig, file: string): ConfigError[] {
|
|
147
|
+
const errors: ConfigError[] = [];
|
|
148
|
+
for (const [agent, settings] of Object.entries(project.agents ?? {})) {
|
|
149
|
+
for (const key of ["bin", "env", "extraArgs"] as const) {
|
|
150
|
+
if (settings[key] !== undefined) {
|
|
151
|
+
errors.push({ file, pointer: `/agents/${agent}/${key}`, message: "not allowed in project configuration (user configuration only)" });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const [name, profile] of Object.entries(project.profiles ?? {})) {
|
|
156
|
+
if (profile.options !== undefined) {
|
|
157
|
+
errors.push({ file, pointer: `/profiles/${name}/options`, message: "not allowed in project configuration (user configuration only)" });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const [key, levels] of Object.entries(STRICTNESS)) {
|
|
161
|
+
const projectValue = (project.approval as Record<string, string> | undefined)?.[key];
|
|
162
|
+
if (projectValue === undefined) continue;
|
|
163
|
+
const userValue = (userEffective.approval as Record<string, string>)[key];
|
|
164
|
+
if (levels.indexOf(projectValue) < levels.indexOf(userValue)) {
|
|
165
|
+
errors.push({ file, pointer: `/approval/${key}`, message: `cannot loosen the user setting "${userValue}" to "${projectValue}"` });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return errors;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Checks references between sections and against the adapters. */
|
|
172
|
+
export function crossValidate(config: OrchestratorConfig, adapters: ReadonlyMap<string, AgentAdapter>, file: string): ConfigError[] {
|
|
173
|
+
const errors: ConfigError[] = [];
|
|
174
|
+
for (const [agent, settings] of Object.entries(config.agents)) {
|
|
175
|
+
if (!adapters.has(agent)) {
|
|
176
|
+
errors.push({ file, pointer: `/agents/${agent}`, message: `unknown agent; known: ${[...adapters.keys()].join(", ")}` });
|
|
177
|
+
}
|
|
178
|
+
if (settings.persistTrust !== undefined && agent !== "grok") {
|
|
179
|
+
errors.push({ file, pointer: `/agents/${agent}/persistTrust`, message: "only valid for grok" });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const [name, profile] of Object.entries(config.profiles)) {
|
|
183
|
+
const adapter = adapters.get(profile.agent);
|
|
184
|
+
if (!adapter) {
|
|
185
|
+
errors.push({ file, pointer: `/profiles/${name}/agent`, message: `unknown agent "${profile.agent}"` });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const levels = adapter.capabilities.effortLevels;
|
|
189
|
+
if (profile.effort !== undefined) {
|
|
190
|
+
if (!levels) errors.push({ file, pointer: `/profiles/${name}/effort`, message: `${adapter.displayName} has no effort setting` });
|
|
191
|
+
else if (!levels.includes(profile.effort)) {
|
|
192
|
+
errors.push({ file, pointer: `/profiles/${name}/effort`, message: `must be one of: ${levels.join(", ")}` });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (profile.options !== undefined) {
|
|
196
|
+
if (!adapter.optionsSchema) {
|
|
197
|
+
errors.push({ file, pointer: `/profiles/${name}/options`, message: `${adapter.displayName} takes no options` });
|
|
198
|
+
} else if (!Value.Check(adapter.optionsSchema, profile.options)) {
|
|
199
|
+
const messages = [...Value.Errors(adapter.optionsSchema, profile.options)]
|
|
200
|
+
.filter((error) => error.keyword !== "boolean")
|
|
201
|
+
.map((error) => {
|
|
202
|
+
if (error.keyword === "additionalProperties") {
|
|
203
|
+
return `unknown option: ${((error.params as { additionalProperties?: string[] }).additionalProperties ?? []).join(", ")}`;
|
|
204
|
+
}
|
|
205
|
+
return `${error.instancePath || "/"} ${error.message}`;
|
|
206
|
+
});
|
|
207
|
+
errors.push({ file, pointer: `/profiles/${name}/options`, message: [...new Set(messages)].join("; ") });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const role of ROLE_NAMES) {
|
|
212
|
+
for (const entry of config.roles[role] ?? []) {
|
|
213
|
+
if (!config.profiles[entry] && !adapters.has(entry)) {
|
|
214
|
+
errors.push({ file, pointer: `/roles/${role}`, message: `unknown profile or agent "${entry}"` });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (config.planning.execution.commit === "per-block" && !config.planning.execution.requireCleanTree) {
|
|
219
|
+
errors.push({
|
|
220
|
+
file,
|
|
221
|
+
pointer: "/planning/execution/commit",
|
|
222
|
+
message: '"per-block" requires requireCleanTree: true, so nothing that predates the plan can enter a commit',
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return errors;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function resolvePromptsDir(fileValue: ConfigFile, file: string): string | null | undefined {
|
|
229
|
+
const dir = fileValue.prompts?.dir;
|
|
230
|
+
if (dir === undefined || dir === null) return dir;
|
|
231
|
+
return isAbsolute(dir) ? dir : resolve(dirname(file), dir);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Built-in defaults, then the user file, then the project file when the project is trusted. */
|
|
235
|
+
export async function loadConfig(options: LoadOptions): Promise<LoadedConfig> {
|
|
236
|
+
const errors: ConfigError[] = [];
|
|
237
|
+
const warnings: string[] = [];
|
|
238
|
+
const sources: ConfigSource[] = [];
|
|
239
|
+
let config = defaultConfig();
|
|
240
|
+
|
|
241
|
+
const userPath = userConfigPath(options.agentDir);
|
|
242
|
+
const user = await readConfigFile(userPath);
|
|
243
|
+
sources.push({ scope: "user", path: userPath, present: user.present });
|
|
244
|
+
if (user.error) errors.push({ file: userPath, pointer: "/", message: user.error });
|
|
245
|
+
else if (user.present) {
|
|
246
|
+
const schemaErrors = validateConfigFile(user.value, userPath);
|
|
247
|
+
errors.push(...schemaErrors);
|
|
248
|
+
if (schemaErrors.length === 0) {
|
|
249
|
+
const value = user.value as ConfigFile;
|
|
250
|
+
const { $schema: _ignored, ...rest } = value;
|
|
251
|
+
config = mergeConfig(config, rest);
|
|
252
|
+
const dir = resolvePromptsDir(value, userPath);
|
|
253
|
+
if (dir !== undefined) config.prompts.dir = dir;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const projectPath = projectConfigPath(options.cwd, options.configDirName);
|
|
258
|
+
if (!options.projectTrusted) {
|
|
259
|
+
sources.push({ scope: "project", path: projectPath, present: false, ignored: "project not trusted" });
|
|
260
|
+
} else {
|
|
261
|
+
const project = await readConfigFile(projectPath);
|
|
262
|
+
sources.push({ scope: "project", path: projectPath, present: project.present });
|
|
263
|
+
if (project.error) errors.push({ file: projectPath, pointer: "/", message: project.error });
|
|
264
|
+
else if (project.present) {
|
|
265
|
+
const schemaErrors = validateConfigFile(project.value, projectPath);
|
|
266
|
+
errors.push(...schemaErrors);
|
|
267
|
+
if (schemaErrors.length === 0) {
|
|
268
|
+
const value = project.value as ConfigFile;
|
|
269
|
+
const restrictionErrors = checkProjectRestrictions(value, config, projectPath);
|
|
270
|
+
errors.push(...restrictionErrors);
|
|
271
|
+
if (restrictionErrors.length === 0) {
|
|
272
|
+
const { $schema: _ignored, ...rest } = value;
|
|
273
|
+
config = mergeConfig(config, rest);
|
|
274
|
+
const dir = resolvePromptsDir(value, projectPath);
|
|
275
|
+
if (dir !== undefined) config.prompts.dir = dir;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (errors.length === 0) {
|
|
282
|
+
const file = sources.filter((source) => source.present).map((source) => source.path).join(" + ") || "built-in defaults";
|
|
283
|
+
errors.push(...crossValidate(config, options.adapters, file));
|
|
284
|
+
}
|
|
285
|
+
return { config, errors, warnings, sources };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function formatConfigErrors(errors: readonly ConfigError[]): string {
|
|
289
|
+
return errors.map((error) => `${error.file}: ${error.pointer}: ${error.message}`).join("\n");
|
|
290
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AgentAdapter } from "../adapters/types.ts";
|
|
2
|
+
import { MULTI_ROLES, type OrchestratorConfig, type RoleName } from "./schema.ts";
|
|
3
|
+
|
|
4
|
+
export interface ResolvedProfile {
|
|
5
|
+
name: string;
|
|
6
|
+
agent: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
effort?: string;
|
|
9
|
+
timeoutMinutes?: number;
|
|
10
|
+
options?: Record<string, unknown>;
|
|
11
|
+
/** True for the profile every agent gets, named after it, with no model or effort. */
|
|
12
|
+
implicit: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A configured profile, or the implicit profile of an agent id. */
|
|
16
|
+
export function resolveProfile(
|
|
17
|
+
config: OrchestratorConfig,
|
|
18
|
+
adapters: ReadonlyMap<string, AgentAdapter>,
|
|
19
|
+
name: string,
|
|
20
|
+
): ResolvedProfile | undefined {
|
|
21
|
+
const profile = config.profiles[name];
|
|
22
|
+
if (profile) {
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
agent: profile.agent,
|
|
26
|
+
model: profile.model,
|
|
27
|
+
effort: profile.effort,
|
|
28
|
+
timeoutMinutes: profile.timeoutMinutes,
|
|
29
|
+
options: profile.options,
|
|
30
|
+
implicit: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (adapters.has(name)) return { name, agent: name, implicit: true };
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** All selectable profiles: configured ones first, then one implicit profile per agent. */
|
|
38
|
+
export function listProfiles(config: OrchestratorConfig, adapters: ReadonlyMap<string, AgentAdapter>): ResolvedProfile[] {
|
|
39
|
+
const result: ResolvedProfile[] = [];
|
|
40
|
+
for (const name of Object.keys(config.profiles)) {
|
|
41
|
+
const profile = resolveProfile(config, adapters, name);
|
|
42
|
+
if (profile) result.push(profile);
|
|
43
|
+
}
|
|
44
|
+
for (const id of adapters.keys()) {
|
|
45
|
+
if (!config.profiles[id]) result.push({ name: id, agent: id, implicit: true });
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function roleProfiles(config: OrchestratorConfig, role: RoleName): string[] | undefined {
|
|
51
|
+
const list = config.roles[role];
|
|
52
|
+
return list && list.length > 0 ? [...list] : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isMultiRole(role: RoleName): boolean {
|
|
56
|
+
return MULTI_ROLES.includes(role);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function describeProfile(profile: ResolvedProfile): string {
|
|
60
|
+
const parts = [profile.agent];
|
|
61
|
+
if (profile.model) parts.push(profile.model);
|
|
62
|
+
if (profile.effort) parts.push(`effort ${profile.effort}`);
|
|
63
|
+
return profile.implicit ? `${profile.name} (agent defaults)` : `${profile.name} (${parts.join(", ")})`;
|
|
64
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Type, type Static } from "typebox";
|
|
2
|
+
|
|
3
|
+
const Int = (minimum: number, maximum: number, description: string) => Type.Integer({ minimum, maximum, description });
|
|
4
|
+
const NonEmpty = (description: string) => Type.String({ minLength: 1, description });
|
|
5
|
+
const Choice = <T extends string>(values: readonly T[], description: string) =>
|
|
6
|
+
Type.Union(
|
|
7
|
+
values.map((value) => Type.Literal(value)),
|
|
8
|
+
{ description },
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const ROLE_NAMES = ["planner", "critic", "implementer", "reviewer", "debater"] as const;
|
|
12
|
+
export type RoleName = (typeof ROLE_NAMES)[number];
|
|
13
|
+
|
|
14
|
+
/** Roles whose listed profiles all take part; the others are ordered fallback chains. */
|
|
15
|
+
export const MULTI_ROLES: readonly RoleName[] = ["critic", "debater"];
|
|
16
|
+
|
|
17
|
+
export const AgentSettingsSchema = Type.Object(
|
|
18
|
+
{
|
|
19
|
+
enabled: Type.Optional(Type.Boolean({ description: "Default: true when the agent is detected" })),
|
|
20
|
+
bin: Type.Optional(NonEmpty("Executable name or absolute path")),
|
|
21
|
+
env: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Environment additions for every run" })),
|
|
22
|
+
extraArgs: Type.Optional(Type.Array(Type.String(), { description: "Arguments appended to every invocation" })),
|
|
23
|
+
allowUntestedVersion: Type.Optional(Type.Boolean({ description: "Run with a warning outside testedVersions" })),
|
|
24
|
+
persistTrust: Type.Optional(Type.Boolean({ description: "grok only: pass --trust, which persists the grant" })),
|
|
25
|
+
},
|
|
26
|
+
{ additionalProperties: false },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const ProfileSchema = Type.Object(
|
|
30
|
+
{
|
|
31
|
+
agent: NonEmpty("Agent id (codex, claude, opencode, pi, agy, grok, muse, dsh, gemini, omp, cursor)"),
|
|
32
|
+
model: Type.Optional(NonEmpty("Model id passed verbatim to the agent")),
|
|
33
|
+
effort: Type.Optional(NonEmpty("Effort or thinking level, validated against the adapter's levels")),
|
|
34
|
+
timeoutMinutes: Type.Optional(Int(1, 720, "Run timeout")),
|
|
35
|
+
options: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Adapter-specific options" })),
|
|
36
|
+
description: Type.Optional(Type.String()),
|
|
37
|
+
},
|
|
38
|
+
{ additionalProperties: false },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const RoleList = Type.Array(NonEmpty("Profile name or agent id"), { minItems: 1 });
|
|
42
|
+
|
|
43
|
+
export const ConfigFileSchema = Type.Object(
|
|
44
|
+
{
|
|
45
|
+
$schema: Type.Optional(Type.String()),
|
|
46
|
+
agents: Type.Optional(Type.Record(Type.String(), AgentSettingsSchema)),
|
|
47
|
+
profiles: Type.Optional(Type.Record(Type.String({ pattern: "^[A-Za-z0-9][A-Za-z0-9._-]*$" }), ProfileSchema)),
|
|
48
|
+
roles: Type.Optional(
|
|
49
|
+
Type.Object(
|
|
50
|
+
{
|
|
51
|
+
planner: Type.Optional(RoleList),
|
|
52
|
+
critic: Type.Optional(RoleList),
|
|
53
|
+
implementer: Type.Optional(RoleList),
|
|
54
|
+
reviewer: Type.Optional(RoleList),
|
|
55
|
+
debater: Type.Optional(RoleList),
|
|
56
|
+
},
|
|
57
|
+
{ additionalProperties: false },
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
defaults: Type.Optional(
|
|
61
|
+
Type.Object(
|
|
62
|
+
{
|
|
63
|
+
timeoutMinutes: Type.Optional(Int(1, 720, "Default run timeout")),
|
|
64
|
+
maxParallel: Type.Optional(Int(1, 16, "Parallel analyze runs")),
|
|
65
|
+
artifactRetentionDays: Type.Optional(Int(1, 365, "Days run artifacts are kept")),
|
|
66
|
+
},
|
|
67
|
+
{ additionalProperties: false },
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
approval: Type.Optional(
|
|
71
|
+
Type.Object(
|
|
72
|
+
{
|
|
73
|
+
implementFromTool: Type.Optional(Choice(["auto", "ask"], "Model-initiated implement runs")),
|
|
74
|
+
workflowStart: Type.Optional(Choice(["ask", "auto"], "Cost gate before a debate or plan")),
|
|
75
|
+
},
|
|
76
|
+
{ additionalProperties: false },
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
debate: Type.Optional(
|
|
80
|
+
Type.Object(
|
|
81
|
+
{
|
|
82
|
+
maxRounds: Type.Optional(Int(0, 5, "Rebuttal rounds after the opening")),
|
|
83
|
+
anonymize: Type.Optional(Type.Boolean()),
|
|
84
|
+
minParticipants: Type.Optional(Int(2, 11, "Minimum debaters")),
|
|
85
|
+
},
|
|
86
|
+
{ additionalProperties: false },
|
|
87
|
+
),
|
|
88
|
+
),
|
|
89
|
+
planning: Type.Optional(
|
|
90
|
+
Type.Object(
|
|
91
|
+
{
|
|
92
|
+
maxRevisions: Type.Optional(Int(0, 3, "Revision loops after critique")),
|
|
93
|
+
execution: Type.Optional(
|
|
94
|
+
Type.Object(
|
|
95
|
+
{
|
|
96
|
+
mode: Type.Optional(Choice(["auto", "block"], "auto: stop on failure; block: confirm each block")),
|
|
97
|
+
maxFixAttempts: Type.Optional(Int(0, 5, "Fix cycles per block")),
|
|
98
|
+
review: Type.Optional(Choice(["per-block", "none"], "Independent review")),
|
|
99
|
+
commit: Type.Optional(Choice(["none", "per-block"], "Commit accepted blocks")),
|
|
100
|
+
requireCleanTree: Type.Optional(Type.Boolean()),
|
|
101
|
+
},
|
|
102
|
+
{ additionalProperties: false },
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
},
|
|
106
|
+
{ additionalProperties: false },
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
prompts: Type.Optional(
|
|
110
|
+
Type.Object(
|
|
111
|
+
{ dir: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "Template override directory" })) },
|
|
112
|
+
{ additionalProperties: false },
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
},
|
|
116
|
+
{ additionalProperties: false },
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
export type ConfigFile = Static<typeof ConfigFileSchema>;
|
|
120
|
+
export type AgentSettings = Static<typeof AgentSettingsSchema>;
|
|
121
|
+
export type ProfileSettings = Static<typeof ProfileSchema>;
|
|
122
|
+
|
|
123
|
+
export interface OrchestratorConfig {
|
|
124
|
+
agents: Record<string, AgentSettings>;
|
|
125
|
+
profiles: Record<string, ProfileSettings>;
|
|
126
|
+
roles: Partial<Record<RoleName, string[]>>;
|
|
127
|
+
defaults: { timeoutMinutes: number; maxParallel: number; artifactRetentionDays: number };
|
|
128
|
+
approval: { implementFromTool: "auto" | "ask"; workflowStart: "ask" | "auto" };
|
|
129
|
+
debate: { maxRounds: number; anonymize: boolean; minParticipants: number };
|
|
130
|
+
planning: {
|
|
131
|
+
maxRevisions: number;
|
|
132
|
+
execution: {
|
|
133
|
+
mode: "auto" | "block";
|
|
134
|
+
maxFixAttempts: number;
|
|
135
|
+
review: "per-block" | "none";
|
|
136
|
+
commit: "none" | "per-block";
|
|
137
|
+
requireCleanTree: boolean;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
/** Absolute directory of template overrides, or null. */
|
|
141
|
+
prompts: { dir: string | null };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function defaultConfig(): OrchestratorConfig {
|
|
145
|
+
return {
|
|
146
|
+
agents: {},
|
|
147
|
+
profiles: {},
|
|
148
|
+
roles: {},
|
|
149
|
+
defaults: { timeoutMinutes: 30, maxParallel: 4, artifactRetentionDays: 14 },
|
|
150
|
+
approval: { implementFromTool: "auto", workflowStart: "ask" },
|
|
151
|
+
debate: { maxRounds: 2, anonymize: true, minParticipants: 2 },
|
|
152
|
+
planning: {
|
|
153
|
+
maxRevisions: 1,
|
|
154
|
+
execution: { mode: "auto", maxFixAttempts: 2, review: "per-block", commit: "none", requireCleanTree: true },
|
|
155
|
+
},
|
|
156
|
+
prompts: { dir: null },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import type { AgentAdapter } from "../adapters/types.ts";
|
|
4
|
+
import { crossValidate, mergeConfig, stripJsonComments, userConfigPath, validateConfigFile, type ConfigError } from "./load.ts";
|
|
5
|
+
import { defaultConfig, type ConfigFile, type RoleName } from "./schema.ts";
|
|
6
|
+
|
|
7
|
+
export interface UserConfigFile {
|
|
8
|
+
path: string;
|
|
9
|
+
present: boolean;
|
|
10
|
+
value: ConfigFile;
|
|
11
|
+
/** Rewriting the file drops its comments. */
|
|
12
|
+
hasComments: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function readUserConfig(agentDir: string): Promise<UserConfigFile> {
|
|
17
|
+
const path = userConfigPath(agentDir);
|
|
18
|
+
let text: string;
|
|
19
|
+
try {
|
|
20
|
+
text = await readFile(path, "utf8");
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { path, present: false, value: {}, hasComments: false };
|
|
23
|
+
return { path, present: true, value: {}, hasComments: false, error: `cannot read: ${(error as Error).message}` };
|
|
24
|
+
}
|
|
25
|
+
const stripped = stripJsonComments(text);
|
|
26
|
+
try {
|
|
27
|
+
return { path, present: true, value: JSON.parse(stripped) as ConfigFile, hasComments: stripped !== text };
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return { path, present: true, value: {}, hasComments: false, error: `invalid JSON: ${(error as Error).message}` };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Schema and cross-reference errors of a user file on its own (the project file is not involved). */
|
|
34
|
+
export function checkUserConfig(value: unknown, path: string, adapters: ReadonlyMap<string, AgentAdapter>): ConfigError[] {
|
|
35
|
+
const schemaErrors = validateConfigFile(value, path);
|
|
36
|
+
if (schemaErrors.length > 0) return schemaErrors;
|
|
37
|
+
const { $schema: _ignored, ...rest } = value as ConfigFile;
|
|
38
|
+
return crossValidate(mergeConfig(defaultConfig(), rest), adapters, path);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Writes the user file atomically after validating it. Throws with the errors when it does not validate. */
|
|
42
|
+
export async function writeUserConfig(agentDir: string, value: ConfigFile, adapters: ReadonlyMap<string, AgentAdapter>): Promise<string> {
|
|
43
|
+
const path = userConfigPath(agentDir);
|
|
44
|
+
const errors = checkUserConfig(value, path, adapters);
|
|
45
|
+
if (errors.length > 0) throw new Error(errors.map((error) => `${error.pointer}: ${error.message}`).join("\n"));
|
|
46
|
+
await mkdir(dirname(path), { recursive: true });
|
|
47
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
48
|
+
await writeFile(temp, `${JSON.stringify(value, null, 2)}\n`);
|
|
49
|
+
await rename(temp, path);
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function withRole(value: ConfigFile, role: RoleName, profiles: string[]): ConfigFile {
|
|
54
|
+
return { ...value, roles: { ...(value.roles ?? {}), [role]: profiles } };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A starter file from the detected agents: each agent enabled, and roles filled from them in the order given so the
|
|
59
|
+
* user has something to review. The implicit profiles (one per agent) need no entry.
|
|
60
|
+
*/
|
|
61
|
+
export function starterConfig(detected: readonly string[]): ConfigFile {
|
|
62
|
+
const agents: Record<string, { enabled: boolean; persistTrust?: boolean }> = {};
|
|
63
|
+
for (const id of detected) agents[id] = id === "grok" ? { enabled: true, persistTrust: false } : { enabled: true };
|
|
64
|
+
const [first, second, third] = detected;
|
|
65
|
+
const roles: Partial<Record<RoleName, string[]>> = {};
|
|
66
|
+
if (first) {
|
|
67
|
+
roles.planner = second ? [first, second] : [first];
|
|
68
|
+
roles.implementer = second ? [first, second] : [first];
|
|
69
|
+
roles.reviewer = [second ?? first];
|
|
70
|
+
roles.critic = [second ?? first];
|
|
71
|
+
if (second) roles.debater = third ? [first, second, third] : [first, second];
|
|
72
|
+
}
|
|
73
|
+
const defaults = defaultConfig();
|
|
74
|
+
return {
|
|
75
|
+
agents,
|
|
76
|
+
profiles: {},
|
|
77
|
+
roles,
|
|
78
|
+
defaults: defaults.defaults,
|
|
79
|
+
approval: defaults.approval,
|
|
80
|
+
debate: defaults.debate,
|
|
81
|
+
planning: defaults.planning,
|
|
82
|
+
} as unknown as ConfigFile;
|
|
83
|
+
}
|