@ours.network/fleet 1.0.5 → 1.1.0-nightly.2
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 +90 -112
- package/dist/application/capabilities.d.ts +0 -1
- package/dist/application/capabilities.js +3 -13
- package/dist/application/fleet-query-service.d.ts +0 -3
- package/dist/application/fleet-query-service.js +1 -24
- package/dist/application/role-creation-service.d.ts +5 -5
- package/dist/application/role-creation-service.js +14 -9
- package/dist/application/role-removal-service.js +6 -3
- package/dist/application/role-repository.d.ts +1 -2
- package/dist/application/role-repository.js +7 -7
- package/dist/application/session-control.d.ts +0 -12
- package/dist/application/session-control.js +0 -42
- package/dist/application/session-mutations.d.ts +5 -5
- package/dist/application/types.d.ts +1 -8
- package/dist/briefing.js +3 -6
- package/dist/build-info.json +5 -5
- package/dist/cli.js +17 -28
- package/dist/config.d.ts +29 -6
- package/dist/config.js +320 -40
- package/dist/creation.d.ts +1 -1
- package/dist/creation.js +2 -2
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +51 -95
- package/dist/doctor.js +1 -8
- package/dist/fleet-proxy.d.ts +1 -1
- package/dist/generated-agent-source.d.ts +9 -0
- package/dist/generated-agent-source.js +53 -0
- package/dist/harness/acp-session-transport.d.ts +8 -0
- package/dist/harness/acp-session-transport.js +3 -0
- package/dist/harness/agent-session.d.ts +46 -0
- package/dist/harness/agent-session.js +1 -0
- package/dist/harness/claude-code-session.d.ts +22 -0
- package/dist/harness/claude-code-session.js +32 -0
- package/dist/harness/claude-code.d.ts +2 -1
- package/dist/harness/claude-code.js +39 -81
- package/dist/harness/codex-session.d.ts +22 -0
- package/dist/harness/codex-session.js +32 -0
- package/dist/harness/codex.d.ts +2 -1
- package/dist/harness/codex.js +49 -45
- package/dist/harness/registry.js +4 -0
- package/dist/harness/types.d.ts +6 -38
- package/dist/index.d.ts +3 -5
- package/dist/index.js +1 -3
- package/dist/init-guidance.d.ts +1 -0
- package/dist/init-guidance.js +5 -0
- package/dist/isolation/resources.d.ts +3 -7
- package/dist/isolation/resources.js +3 -7
- package/dist/model-env.d.ts +2 -4
- package/dist/model-env.js +4 -7
- package/dist/monitor.d.ts +1 -24
- package/dist/monitor.js +5 -140
- package/dist/ops.js +4 -2
- package/dist/owner-channel/channel.d.ts +2 -2
- package/dist/resolved-plan.d.ts +3 -2
- package/dist/resolved-plan.js +21 -5
- package/dist/runner.d.ts +5 -15
- package/dist/runner.js +26 -102
- package/dist/sensitive-config.d.ts +2 -0
- package/dist/sensitive-config.js +4 -0
- package/dist/session/acp.d.ts +2 -2
- package/dist/session/acp.js +2 -3
- package/dist/session/activity.d.ts +2 -3
- package/dist/session/activity.js +2 -3
- package/dist/session/arbiter.d.ts +4 -4
- package/dist/session/control.d.ts +3 -3
- package/dist/session/types.d.ts +11 -5
- package/dist/spawn.d.ts +4 -4
- package/dist/spawn.js +60 -32
- package/dist/supervisor/none.d.ts +1 -1
- package/dist/supervisor/none.js +2 -2
- package/dist/tmux.d.ts +1 -14
- package/dist/tmux.js +1 -51
- package/dist/watchdog/config.js +6 -4
- package/dist/watchdog/run.js +8 -23
- package/dist/web/auth.d.ts +1 -1
- package/dist/web/fleet-config-service.d.ts +11 -8
- package/dist/web/fleet-config-service.js +383 -183
- package/dist/web/runtime.js +4 -15
- package/dist/web/server.d.ts +1 -3
- package/dist/web/server.js +3 -14
- package/dist/web/topology-promote.js +18 -18
- package/dist/web/topology.js +2 -2
- package/dist/web/yaml-document-edit.js +2 -0
- package/dist/web-app/assets/index-59GF-gsZ.css +1 -0
- package/dist/web-app/assets/index-BbE9EX6n.js +10 -0
- package/dist/web-app/index.html +2 -2
- package/examples/fleet/agents/Alice.yaml +11 -0
- package/examples/fleet/agents/FleetCoordinator.yaml +7 -0
- package/examples/fleet/brains/claude-default.yaml +5 -0
- package/examples/fleet/roles/coordinator.yaml +5 -0
- package/examples/fleet/roles/developer.yaml +3 -0
- package/examples/fleet.yaml +74 -0
- package/package.json +4 -8
- package/dist/session/tmux.d.ts +0 -28
- package/dist/session/tmux.js +0 -80
- package/dist/web/terminal/bridge.d.ts +0 -27
- package/dist/web/terminal/bridge.js +0 -317
- package/dist/web-app/assets/TerminalView-C_G1ID2P.js +0 -9
- package/dist/web-app/assets/index-BCBK78hw.js +0 -10
- package/dist/web-app/assets/index-DuC-xnX4.css +0 -1
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, join, resolve, sep } from 'node:path';
|
|
3
3
|
import { agentDir, defaultConfigPath, fleetDDir, home } from './paths.js';
|
|
4
4
|
import { parseFleetDocument, } from './config-yaml.js';
|
|
5
5
|
import { harnessRuntimeDir, resolveIsolation, validateIsolationConfig, } from './isolation/policy.js';
|
|
@@ -10,6 +10,7 @@ import { resolveLoops } from './loops/config.js';
|
|
|
10
10
|
import { validateRoomsConfig, validateTasksConfig, validateRoomTemplatesConfig, } from './rooms-tasks/config.js';
|
|
11
11
|
import { CAPABILITIES, CAP_MONITOR_INTERRUPT_AFTER_TOOL } from './capabilities.js';
|
|
12
12
|
import { runningLabel } from './provenance.js';
|
|
13
|
+
import { parseDuration } from './duration.js';
|
|
13
14
|
/** Conservative built-in policy; `worklog: false` is the explicit opt-out. */
|
|
14
15
|
export const DEFAULT_WORKLOG_POLICY = Object.freeze({
|
|
15
16
|
max_kb: 1024,
|
|
@@ -126,12 +127,276 @@ export function isolationContextFor(role) {
|
|
|
126
127
|
harnessSharedPaths: split?.shared,
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
|
-
export const ROLE_NAME_RE = /^[A-Za-z0-9_-]
|
|
130
|
+
export const ROLE_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
130
131
|
const ROLE_KEYS = [
|
|
131
132
|
'harness', 'session', 'session_options', 'permissions', 'identity', 'cwd', 'coordinator', 'mission', 'persona', 'bio',
|
|
132
|
-
'briefing_file', 'model', 'model_chain', 'max_tokens', 'autocompact_pct', 'env', 'oversee', 'harness_options',
|
|
133
|
+
'briefing_file', 'model', 'effort', 'model_chain', 'max_tokens', 'autocompact_pct', 'env', 'oversee', 'harness_options',
|
|
133
134
|
'isolation', 'monitor', 'owner_channel', 'worklog', 'auth_proxy',
|
|
134
135
|
];
|
|
136
|
+
const ROLE_PRESET_KEYS = ['mission', 'persona', 'bio', 'briefing_file'];
|
|
137
|
+
const BRAIN_PRESET_KEYS = [
|
|
138
|
+
'harness', 'session', 'session_options', 'model', 'model_chain', 'max_tokens',
|
|
139
|
+
'autocompact_pct', 'harness_options', 'effort',
|
|
140
|
+
];
|
|
141
|
+
const AGENT_KEYS = [
|
|
142
|
+
'role', 'brain', 'permissions', 'identity', 'cwd', 'coordinator', 'env', 'oversee',
|
|
143
|
+
'isolation', 'monitor', 'owner_channel', 'worklog', 'auth_proxy',
|
|
144
|
+
];
|
|
145
|
+
const V2_API_VERSION = 'ours.network/fleet/v2';
|
|
146
|
+
const utf8Bytes = (value) => Buffer.byteLength(value, 'utf8');
|
|
147
|
+
function schemaError(file, pointer, summary) {
|
|
148
|
+
throw new ConfigError(`${file}: E_SCHEMA ${pointer}: ${summary}`);
|
|
149
|
+
}
|
|
150
|
+
function validateRoleValue(value, file, pointer) {
|
|
151
|
+
const limits = {
|
|
152
|
+
mission: { bytes: 16 * 1024, nonblank: true },
|
|
153
|
+
persona: { bytes: 16 * 1024 },
|
|
154
|
+
bio: { bytes: 4 * 1024 },
|
|
155
|
+
};
|
|
156
|
+
for (const [key, rule] of Object.entries(limits)) {
|
|
157
|
+
const current = value[key];
|
|
158
|
+
if (current === undefined)
|
|
159
|
+
continue;
|
|
160
|
+
if (typeof current !== 'string')
|
|
161
|
+
schemaError(file, `${pointer}/${key}`, 'must be a string');
|
|
162
|
+
if (rule.nonblank && !current.trim())
|
|
163
|
+
schemaError(file, `${pointer}/${key}`, 'must be non-blank');
|
|
164
|
+
if (utf8Bytes(current) > rule.bytes)
|
|
165
|
+
schemaError(file, `${pointer}/${key}`, `must be at most ${rule.bytes} UTF-8 bytes`);
|
|
166
|
+
}
|
|
167
|
+
if (value.briefing_file !== undefined
|
|
168
|
+
&& (typeof value.briefing_file !== 'string' || !value.briefing_file.trim()))
|
|
169
|
+
schemaError(file, `${pointer}/briefing_file`, 'must be a non-blank relative path');
|
|
170
|
+
}
|
|
171
|
+
function validateBrainValue(value, file, pointer) {
|
|
172
|
+
if (typeof value.harness !== 'string' || !value.harness.trim())
|
|
173
|
+
schemaError(file, `${pointer}/harness`, 'is required and must be a registered non-blank harness ID');
|
|
174
|
+
if (value.model !== undefined && value.model !== null
|
|
175
|
+
&& (typeof value.model !== 'string' || !value.model.trim()))
|
|
176
|
+
schemaError(file, `${pointer}/model`, 'must be a non-blank string or null');
|
|
177
|
+
for (const key of ['harness_options', 'session_options']) {
|
|
178
|
+
if (value[key] !== undefined && !isPlainObject(value[key]))
|
|
179
|
+
schemaError(file, `${pointer}/${key}`, 'must be a mapping');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function validateAgentScalars(value, file, id) {
|
|
183
|
+
for (const key of ['identity', 'cwd']) {
|
|
184
|
+
const current = value[key];
|
|
185
|
+
if (current !== undefined && (typeof current !== 'string' || !current.trim()))
|
|
186
|
+
schemaError(file, `/agents/${id}/${key}`, 'must be a non-blank string');
|
|
187
|
+
}
|
|
188
|
+
if (value.coordinator !== undefined
|
|
189
|
+
&& (typeof value.coordinator !== 'string' || !ROLE_NAME_RE.test(value.coordinator)))
|
|
190
|
+
schemaError(file, `/agents/${id}/coordinator`, 'must be a valid Agent ID');
|
|
191
|
+
if (value.oversee !== undefined) {
|
|
192
|
+
if (!Array.isArray(value.oversee))
|
|
193
|
+
schemaError(file, `/agents/${id}/oversee`, 'must be an array');
|
|
194
|
+
const seen = new Set();
|
|
195
|
+
value.oversee.forEach((entry, index) => {
|
|
196
|
+
const pointer = `/agents/${id}/oversee/${index}`;
|
|
197
|
+
if (!isPlainObject(entry))
|
|
198
|
+
schemaError(file, pointer, 'must be a mapping');
|
|
199
|
+
const keys = Object.keys(entry);
|
|
200
|
+
const bad = keys.filter(key => key !== 'agent' && key !== 'interval');
|
|
201
|
+
if (bad.length || keys.length !== 2 || !keys.includes('agent') || !keys.includes('interval'))
|
|
202
|
+
schemaError(file, pointer, 'must contain exactly agent and interval');
|
|
203
|
+
if (typeof entry.agent !== 'string' || !ROLE_NAME_RE.test(entry.agent))
|
|
204
|
+
schemaError(file, `${pointer}/agent`, 'must be a valid Agent ID');
|
|
205
|
+
if (typeof entry.interval !== 'string')
|
|
206
|
+
schemaError(file, `${pointer}/interval`, 'must be a valid duration');
|
|
207
|
+
try {
|
|
208
|
+
parseDuration(entry.interval, { name: 'oversee interval' });
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
schemaError(file, `${pointer}/interval`, 'must be a valid duration such as 5m');
|
|
212
|
+
}
|
|
213
|
+
if (seen.has(entry.agent))
|
|
214
|
+
schemaError(file, `${pointer}/agent`, 'must be unique');
|
|
215
|
+
seen.add(entry.agent);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function assertTrustedPath(path, expected) {
|
|
220
|
+
const st = lstatSync(path);
|
|
221
|
+
if (st.isSymbolicLink())
|
|
222
|
+
throw new ConfigError(`E_SYMLINK: trusted configuration path is a symlink: ${path}`);
|
|
223
|
+
if (expected === 'file' ? !st.isFile() : !st.isDirectory())
|
|
224
|
+
throw new ConfigError(`E_FILE_TRUST: expected ${expected}: ${path}`);
|
|
225
|
+
const uid = process.getuid?.();
|
|
226
|
+
if (uid !== undefined && st.uid !== uid)
|
|
227
|
+
throw new ConfigError(`E_FILE_TRUST: ${path} is owned by uid ${st.uid}; required uid ${uid}`);
|
|
228
|
+
if ((st.mode & 0o022) !== 0)
|
|
229
|
+
throw new ConfigError(`E_FILE_TRUST: ${path} is group/world writable (mode ${(st.mode & 0o777).toString(8)})`);
|
|
230
|
+
}
|
|
231
|
+
function assertBareKeys(value, allowed, label) {
|
|
232
|
+
if (!isPlainObject(value))
|
|
233
|
+
throw new ConfigError(`${label}: E_SCHEMA: must be a mapping`);
|
|
234
|
+
const bad = Object.keys(value).filter(key => !allowed.includes(key));
|
|
235
|
+
if (bad.length)
|
|
236
|
+
throw new ConfigError(`${label}: E_UNKNOWN_KEY: unknown key(s) ${bad.join(', ')}; allowed: ${allowed.join(', ')}`);
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
export function splitRootFor(base) {
|
|
240
|
+
const extension = extname(base).toLowerCase();
|
|
241
|
+
return extension === '.yaml' || extension === '.yml' ? base.slice(0, -extension.length) : `${base}.d`;
|
|
242
|
+
}
|
|
243
|
+
function readKindDirectory(root, kind, required, yamlMode, diagnostics, files) {
|
|
244
|
+
if (!existsSync(root)) {
|
|
245
|
+
if (required)
|
|
246
|
+
throw new ConfigError(`E_ROOT_MISSING: required ${kind} root not found: ${root}`);
|
|
247
|
+
return new Map();
|
|
248
|
+
}
|
|
249
|
+
assertTrustedPath(root, 'directory');
|
|
250
|
+
const result = new Map();
|
|
251
|
+
const names = readdirSync(root).filter(name => ['.yaml', '.yml'].includes(extname(name).toLowerCase())).sort();
|
|
252
|
+
for (const name of names) {
|
|
253
|
+
const file = join(root, name);
|
|
254
|
+
assertTrustedPath(file, 'file');
|
|
255
|
+
const id = basename(name, extname(name));
|
|
256
|
+
if (!ROLE_NAME_RE.test(id))
|
|
257
|
+
throw new ConfigError(`${file}: invalid ${kind} id '${id}' (allowed: [A-Za-z0-9_-])`);
|
|
258
|
+
const previous = result.get(id);
|
|
259
|
+
if (previous)
|
|
260
|
+
throw new ConfigError(`E_DUPLICATE_ID: ${kind} '${id}' defined by both ${previous.file} and ${file}`);
|
|
261
|
+
const parsed = parseFleetDocument(file, readFileSync(file, 'utf8'), yamlMode);
|
|
262
|
+
diagnostics.push(...parsed.diagnostics);
|
|
263
|
+
files.push(file);
|
|
264
|
+
result.set(id, { file, value: parsed.value });
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
function selection(raw, kind, agentFile, presets, allowed) {
|
|
269
|
+
if (!isPlainObject(raw))
|
|
270
|
+
schemaError(agentFile, `/${kind}`, 'must be { ref } or { inline }');
|
|
271
|
+
const keys = Object.keys(raw);
|
|
272
|
+
if (keys.length !== 1 || (keys[0] !== 'ref' && keys[0] !== 'inline'))
|
|
273
|
+
throw new ConfigError(`${agentFile}: E_UNION /${kind}: must contain exactly one of ref or inline`);
|
|
274
|
+
if ('ref' in raw) {
|
|
275
|
+
if (typeof raw.ref !== 'string' || !ROLE_NAME_RE.test(raw.ref))
|
|
276
|
+
schemaError(agentFile, `/${kind}/ref`, 'must be a valid case-sensitive ID');
|
|
277
|
+
const preset = presets.get(raw.ref);
|
|
278
|
+
if (!preset)
|
|
279
|
+
throw new ConfigError(`${agentFile}: E_REF_MISSING: ${kind} '${raw.ref}' not found`);
|
|
280
|
+
return {
|
|
281
|
+
value: assertBareKeys(preset.value, allowed, `${preset.file}: ${kind} '${raw.ref}'`),
|
|
282
|
+
file: preset.file,
|
|
283
|
+
pointer: `/${kind}s/${raw.ref}`,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
value: assertBareKeys(raw.inline, allowed, `${agentFile}: agent.${kind}.inline`),
|
|
288
|
+
file: agentFile,
|
|
289
|
+
pointer: `/${kind}/inline`,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function deepSubStrict(value, vars, file, pointer) {
|
|
293
|
+
if (typeof value === 'string') {
|
|
294
|
+
return value.replace(/\$\{(\w+)\}/g, (_match, key) => {
|
|
295
|
+
if (!(key in vars))
|
|
296
|
+
schemaError(file, pointer, `unknown variable \${${key}}`);
|
|
297
|
+
return String(vars[key]);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (Array.isArray(value))
|
|
301
|
+
return value.map((item, index) => deepSubStrict(item, vars, file, `${pointer}/${index}`));
|
|
302
|
+
if (isPlainObject(value))
|
|
303
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [
|
|
304
|
+
key, deepSubStrict(child, vars, file, `${pointer}/${key}`),
|
|
305
|
+
]));
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
function composeSplitRoles(base, baseDoc, yamlMode, diagnostics, files) {
|
|
309
|
+
if (baseDoc.api_version !== V2_API_VERSION)
|
|
310
|
+
throw new ConfigError(`${base}: legacy fleet configuration is unsupported; run 'ours-fleet doctor' and rewrite it as ${V2_API_VERSION}`);
|
|
311
|
+
if ('roles' in baseDoc)
|
|
312
|
+
throw new ConfigError(`${base}: legacy top-level roles: is unsupported; define bare Agent files under ${splitRootFor(base)}/agents/`);
|
|
313
|
+
const root = splitRootFor(base);
|
|
314
|
+
if (!existsSync(root))
|
|
315
|
+
throw new ConfigError(`E_ROOT_MISSING: required configuration root not found: ${root}`);
|
|
316
|
+
assertTrustedPath(root, 'directory');
|
|
317
|
+
const brains = readKindDirectory(join(root, 'brains'), 'brain', false, yamlMode, diagnostics, files);
|
|
318
|
+
const roles = readKindDirectory(join(root, 'roles'), 'role', false, yamlMode, diagnostics, files);
|
|
319
|
+
const agents = readKindDirectory(join(root, 'agents'), 'agent', true, yamlMode, diagnostics, files);
|
|
320
|
+
const vars = (baseDoc.vars ?? {});
|
|
321
|
+
const documents = [];
|
|
322
|
+
for (const [id, agent] of agents) {
|
|
323
|
+
const a = assertBareKeys(agent.value, AGENT_KEYS, `${agent.file}: agent '${id}'`);
|
|
324
|
+
if (!('role' in a) || !('brain' in a))
|
|
325
|
+
throw new ConfigError(`${agent.file}: agent '${id}' requires role and brain`);
|
|
326
|
+
const role = selection(a.role, 'role', agent.file, roles, ROLE_PRESET_KEYS);
|
|
327
|
+
const brain = selection(a.brain, 'brain', agent.file, brains, BRAIN_PRESET_KEYS);
|
|
328
|
+
const operational = deepSubStrict(Object.fromEntries(Object.entries(a).filter(([key]) => key !== 'role' && key !== 'brain')), vars, agent.file, `/agents/${id}`);
|
|
329
|
+
validateAgentScalars(operational, agent.file, id);
|
|
330
|
+
const brainValue = deepSubStrict({ ...brain.value }, vars, brain.file, brain.pointer);
|
|
331
|
+
validateBrainValue(brainValue, brain.file, brain.pointer);
|
|
332
|
+
const effort = brainValue.effort;
|
|
333
|
+
delete brainValue.effort;
|
|
334
|
+
const harness = brainValue.harness;
|
|
335
|
+
{
|
|
336
|
+
let adapter;
|
|
337
|
+
try {
|
|
338
|
+
adapter = getAdapter(harness);
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
schemaError(brain.file, `${brain.pointer}/harness`, `unregistered harness '${harness}'`);
|
|
342
|
+
}
|
|
343
|
+
let resolved;
|
|
344
|
+
try {
|
|
345
|
+
resolved = adapter.agentSession.resolveBrain({
|
|
346
|
+
model: brainValue.model,
|
|
347
|
+
effort: effort,
|
|
348
|
+
harnessOptions: brainValue.harness_options,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
schemaError(brain.file, `${brain.pointer}/effort`, error.message);
|
|
353
|
+
}
|
|
354
|
+
brainValue.model = resolved.model;
|
|
355
|
+
brainValue.harness_options = resolved.harnessOptions;
|
|
356
|
+
brainValue.effort = effort;
|
|
357
|
+
}
|
|
358
|
+
const roleValue = deepSubStrict({ ...role.value }, vars, role.file, role.pointer);
|
|
359
|
+
validateRoleValue(roleValue, role.file, role.pointer);
|
|
360
|
+
if (typeof roleValue.briefing_file === 'string') {
|
|
361
|
+
const containmentRoot = realpathSync(dirname(role.file));
|
|
362
|
+
const briefing = resolve(dirname(role.file), roleValue.briefing_file);
|
|
363
|
+
if (briefing !== containmentRoot && !briefing.startsWith(`${containmentRoot}${sep}`))
|
|
364
|
+
throw new ConfigError(`${role.file}: E_PATH_ESCAPE: briefing_file escapes its ${role.file === agent.file ? 'Agent' : 'Role'} root`);
|
|
365
|
+
assertTrustedPath(briefing, 'file');
|
|
366
|
+
const real = realpathSync(briefing);
|
|
367
|
+
if (real !== containmentRoot && !real.startsWith(`${containmentRoot}${sep}`))
|
|
368
|
+
throw new ConfigError(`${role.file}: E_PATH_ESCAPE: briefing_file realpath escapes its root`);
|
|
369
|
+
roleValue.briefing_file = real;
|
|
370
|
+
}
|
|
371
|
+
const provenance = {};
|
|
372
|
+
const record = (values, source, kind, via) => {
|
|
373
|
+
for (const [key, raw] of Object.entries(values))
|
|
374
|
+
provenance[key] = {
|
|
375
|
+
sourceFile: source.file, sourcePointer: `${source.pointer}/${key}`,
|
|
376
|
+
sourceKind: kind, sourceId: via?.id ?? id, origin: 'explicit',
|
|
377
|
+
...(via ? { viaReference: via } : {}),
|
|
378
|
+
transforms: [
|
|
379
|
+
...(JSON.stringify(raw).includes('${')
|
|
380
|
+
? [{ kind: 'substitution', detail: 'manifest variable substitution' }] : []),
|
|
381
|
+
...(['model', 'harness_options', 'effort'].includes(key)
|
|
382
|
+
? [{ kind: 'adapter-normalization', detail: 'AgentSession Brain resolution' }] : []),
|
|
383
|
+
],
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
record(a, { file: agent.file, pointer: `/agents/${id}` }, 'Agent');
|
|
387
|
+
record(role.value, { file: role.file, pointer: role.pointer }, 'Role', 'ref' in a.role
|
|
388
|
+
? { sourcePointer: `/agents/${id}/role/ref`, kind: 'Role', id: String(a.role.ref) }
|
|
389
|
+
: undefined);
|
|
390
|
+
record(brain.value, { file: brain.file, pointer: brain.pointer }, 'Brain', 'ref' in a.brain
|
|
391
|
+
? { sourcePointer: `/agents/${id}/brain/ref`, kind: 'Brain', id: String(a.brain.ref) }
|
|
392
|
+
: undefined);
|
|
393
|
+
delete provenance.role;
|
|
394
|
+
delete provenance.brain;
|
|
395
|
+
documents.push({ file: agent.file,
|
|
396
|
+
doc: { roles: { [id]: { ...brainValue, ...roleValue, ...operational } } }, provenance });
|
|
397
|
+
}
|
|
398
|
+
return documents;
|
|
399
|
+
}
|
|
135
400
|
function deepSub(v, vars) {
|
|
136
401
|
if (typeof v === 'string')
|
|
137
402
|
return v.replace(/\$\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
|
|
@@ -141,43 +406,37 @@ function deepSub(v, vars) {
|
|
|
141
406
|
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, deepSub(x, vars)]));
|
|
142
407
|
return v;
|
|
143
408
|
}
|
|
144
|
-
/** Load
|
|
409
|
+
/** Load a v2 manifest and bare Agent/Role/Brain documents from its stem directory. */
|
|
145
410
|
export function loadConfig(configPath, options = {}) {
|
|
146
411
|
const base = configPath ?? defaultConfigPath();
|
|
147
412
|
const files = [];
|
|
148
413
|
const diagnostics = [];
|
|
149
|
-
|
|
414
|
+
let docs = [];
|
|
415
|
+
let manifestDoc = {};
|
|
150
416
|
if (existsSync(base)) {
|
|
417
|
+
assertTrustedPath(base, 'file');
|
|
151
418
|
const parsed = parseFleetDocument(base, readFileSync(base, 'utf8'), options.yamlMode);
|
|
152
|
-
|
|
419
|
+
manifestDoc = parsed.value;
|
|
153
420
|
diagnostics.push(...parsed.diagnostics);
|
|
154
421
|
files.push(base);
|
|
155
422
|
}
|
|
156
423
|
else if (configPath) {
|
|
157
424
|
throw new ConfigError(`config not found: ${base}`);
|
|
158
425
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
for (const f of readdirSync(dd).filter(f => f.endsWith('.yaml') || f.endsWith('.yml')).sort()) {
|
|
162
|
-
const p = join(dd, f);
|
|
163
|
-
const parsed = parseFleetDocument(p, readFileSync(p, 'utf8'), options.yamlMode);
|
|
164
|
-
const doc = parsed.value;
|
|
165
|
-
diagnostics.push(...parsed.diagnostics);
|
|
166
|
-
const FLEET_D_ALLOWED = ['roles', 'rooms', 'room_templates', 'tasks'];
|
|
167
|
-
const extra = Object.keys(doc).filter(k => !FLEET_D_ALLOWED.includes(k));
|
|
168
|
-
if (extra.length)
|
|
169
|
-
throw new ConfigError(`${p}: fleet.d files may only define ${FLEET_D_ALLOWED.join(', ')}: (found: ${extra.join(', ')})`);
|
|
170
|
-
docs.push({ file: p, doc });
|
|
171
|
-
files.push(p);
|
|
172
|
-
}
|
|
426
|
+
else {
|
|
427
|
+
throw new ConfigError(`config not found: ${base}`);
|
|
173
428
|
}
|
|
174
|
-
const
|
|
429
|
+
const dd = fleetDDir();
|
|
430
|
+
if (existsSync(dd) && readdirSync(dd).some(f => f.endsWith('.yaml') || f.endsWith('.yml')))
|
|
431
|
+
throw new ConfigError(`${dd}: legacy fleet.d configuration is unsupported; run 'ours-fleet doctor' and move agents to ${splitRootFor(base)}/agents/`);
|
|
432
|
+
docs = [{ file: base, doc: manifestDoc }, ...composeSplitRoles(base, manifestDoc, options.yamlMode ?? 'compat', diagnostics, files)];
|
|
433
|
+
const baseDoc = manifestDoc;
|
|
175
434
|
const vars = (baseDoc.vars ?? {});
|
|
176
435
|
const defaults = (baseDoc.defaults ?? {});
|
|
177
436
|
const startStaggerMs = resolveStartStaggerMs(baseDoc.start_stagger_ms, base);
|
|
178
437
|
const seen = new Map();
|
|
179
438
|
const roles = [];
|
|
180
|
-
for (const { file, doc } of docs) {
|
|
439
|
+
for (const { file, doc, provenance } of docs) {
|
|
181
440
|
for (const [name, raw] of Object.entries((doc.roles ?? {}))) {
|
|
182
441
|
if (!ROLE_NAME_RE.test(name))
|
|
183
442
|
throw new ConfigError(`${file}: invalid role name '${name}' (allowed: [A-Za-z0-9_-])`);
|
|
@@ -234,6 +493,21 @@ export function loadConfig(configPath, options = {}) {
|
|
|
234
493
|
const modelChain = resolveModelChain(model, r.model_chain ?? (inheritsModelDefaults
|
|
235
494
|
? defaults.model_chain
|
|
236
495
|
: undefined), file, name);
|
|
496
|
+
const fieldProvenance = { ...(provenance ?? {}) };
|
|
497
|
+
const defaulted = (key, explicit, builtIn = false) => {
|
|
498
|
+
if (fieldProvenance[key])
|
|
499
|
+
return;
|
|
500
|
+
fieldProvenance[key] = {
|
|
501
|
+
sourceFile: builtIn ? '(built-in)' : base,
|
|
502
|
+
sourcePointer: builtIn ? `/${key}` : `/defaults/${key}`,
|
|
503
|
+
sourceKind: builtIn ? 'built-in' : 'Manifest',
|
|
504
|
+
origin: builtIn ? 'built-in' : explicit ? 'explicit' : 'typed-default',
|
|
505
|
+
transforms: [{ kind: 'validation-default', detail: builtIn ? 'built-in default' : 'manifest operational default' }],
|
|
506
|
+
};
|
|
507
|
+
};
|
|
508
|
+
defaulted('identity', r.identity !== undefined, r.identity === undefined);
|
|
509
|
+
defaulted('permissions', defaults.permissions !== undefined, defaults.permissions === undefined);
|
|
510
|
+
defaulted('monitor', defaults.monitor !== undefined, defaults.monitor === undefined);
|
|
237
511
|
roles.push({
|
|
238
512
|
...r,
|
|
239
513
|
name,
|
|
@@ -252,6 +526,7 @@ export function loadConfig(configPath, options = {}) {
|
|
|
252
526
|
monitor,
|
|
253
527
|
owner_channel: ownerChannel,
|
|
254
528
|
worklog,
|
|
529
|
+
provenance: fieldProvenance,
|
|
255
530
|
auth_proxy: authProxy,
|
|
256
531
|
env: Object.keys(env).length ? env : undefined,
|
|
257
532
|
loops: [],
|
|
@@ -307,6 +582,15 @@ export function loadConfig(configPath, options = {}) {
|
|
|
307
582
|
roles, vars, defaults, files, startStaggerMs, diagnostics, watchdogs,
|
|
308
583
|
loops: resolvedLoops.loops,
|
|
309
584
|
rooms, roomTemplates, tasks, ownerInviteFingerprint,
|
|
585
|
+
configMode: 'split-v2',
|
|
586
|
+
sourceDocuments: files.map(path => {
|
|
587
|
+
if (path === base)
|
|
588
|
+
return { kind: 'Manifest', path };
|
|
589
|
+
const parent = basename(dirname(path));
|
|
590
|
+
const kind = parent === 'agents' ? 'Agent'
|
|
591
|
+
: parent === 'roles' ? 'Role' : 'Brain';
|
|
592
|
+
return { kind, id: basename(path, extname(path)), path };
|
|
593
|
+
}),
|
|
310
594
|
};
|
|
311
595
|
if (ownerInvite !== undefined) {
|
|
312
596
|
Object.defineProperty(result, 'ownerInvite', {
|
|
@@ -524,9 +808,12 @@ export function resolveWorklogPolicy(defaults, role, file = 'config', name = 'ro
|
|
|
524
808
|
return merged;
|
|
525
809
|
}
|
|
526
810
|
function resolveSession(raw, file, name) {
|
|
527
|
-
const value = raw ?? '
|
|
528
|
-
if (value
|
|
529
|
-
throw new ConfigError(`${file}: role '${name}' session:
|
|
811
|
+
const value = raw ?? 'acp';
|
|
812
|
+
if (value === 'tmux')
|
|
813
|
+
throw new ConfigError(`${file}: role '${name}' session: tmux is no longer supported; use session: acp `
|
|
814
|
+
+ 'with the Codex or Claude Code adapter');
|
|
815
|
+
if (value !== 'acp')
|
|
816
|
+
throw new ConfigError(`${file}: role '${name}' session: must be: acp`);
|
|
530
817
|
return value;
|
|
531
818
|
}
|
|
532
819
|
function resolveSessionOptions(defaults, role, session, file, name) {
|
|
@@ -541,33 +828,26 @@ function resolveSessionOptions(defaults, role, session, file, name) {
|
|
|
541
828
|
...((defaults?.acp) ?? {}),
|
|
542
829
|
...(role?.acp ?? {}),
|
|
543
830
|
},
|
|
544
|
-
tmux: {
|
|
545
|
-
...((defaults?.tmux) ?? {}),
|
|
546
|
-
...(role?.tmux ?? {}),
|
|
547
|
-
},
|
|
548
831
|
};
|
|
549
|
-
|
|
832
|
+
if (defaults?.tmux !== undefined
|
|
833
|
+
|| role?.tmux !== undefined)
|
|
834
|
+
throw new ConfigError(`${file}: role '${name}' session_options.tmux is no longer supported; `
|
|
835
|
+
+ 'use session: acp with session_options.acp');
|
|
836
|
+
const bad = Object.keys(merged).filter(k => k !== 'acp');
|
|
550
837
|
if (bad.length)
|
|
551
838
|
throw new ConfigError(`${file}: role '${name}' session_options: unknown key(s) ${bad.join(', ')}`);
|
|
552
|
-
if (!isPlainObject(merged.acp)
|
|
839
|
+
if (!isPlainObject(merged.acp))
|
|
553
840
|
throw new ConfigError(`${file}: role '${name}' session_options.${session} must be a map`);
|
|
554
841
|
const acpBad = Object.keys(merged.acp).filter(k => k !== 'command');
|
|
555
|
-
const tmuxBad = Object.keys(merged.tmux).filter(k => k !== 'boot_grace_ms');
|
|
556
842
|
if (acpBad.length)
|
|
557
843
|
throw new ConfigError(`${file}: role '${name}' session_options.acp: unknown key(s) ${acpBad.join(', ')}`);
|
|
558
|
-
if (tmuxBad.length)
|
|
559
|
-
throw new ConfigError(`${file}: role '${name}' session_options.tmux: unknown key(s) ${tmuxBad.join(', ')}`);
|
|
560
844
|
const command = merged.acp.command;
|
|
561
845
|
if (command !== undefined
|
|
562
846
|
&& !(typeof command === 'string' && command.trim())
|
|
563
847
|
&& !(Array.isArray(command) && command.length > 0
|
|
564
848
|
&& command.every(v => typeof v === 'string' && v.length > 0)))
|
|
565
849
|
throw new ConfigError(`${file}: role '${name}' session_options.acp.command must be a non-empty string or string list`);
|
|
566
|
-
|
|
567
|
-
if (grace !== undefined
|
|
568
|
-
&& (typeof grace !== 'number' || !Number.isFinite(grace) || grace < 0))
|
|
569
|
-
throw new ConfigError(`${file}: role '${name}' session_options.tmux.boot_grace_ms must be a non-negative number`);
|
|
570
|
-
return Object.keys(merged.acp).length || Object.keys(merged.tmux).length ? merged : undefined;
|
|
850
|
+
return Object.keys(merged.acp).length ? merged : undefined;
|
|
571
851
|
}
|
|
572
852
|
export function resolvePermissions(defaults, role, file = 'config', name = 'role') {
|
|
573
853
|
if (defaults !== undefined && !isPlainObject(defaults))
|
package/dist/creation.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ export interface DaemonIdentityProvisionerOptions {
|
|
|
153
153
|
export declare function daemonIdentityProvisioner(env?: NodeJS.ProcessEnv, attachClient?: (options: AttachOursClientOptions) => Promise<IdentityInventoryClient>, options?: DaemonIdentityProvisionerOptions): IdentityProvisioner;
|
|
154
154
|
/** Inventory-only variant for session-owned temporary identity lifecycles. */
|
|
155
155
|
export declare function daemonIdentityInventoryProvisioner(env?: NodeJS.ProcessEnv, attachClient?: (options: AttachOursClientOptions) => Promise<IdentityInventoryClient>): IdentityProvisioner;
|
|
156
|
-
/** Atomically write a
|
|
156
|
+
/** Atomically write a bare Agent file, journalling it for rollback. */
|
|
157
157
|
export declare function writeRoleFile(tx: CreationTransaction, file: string, contents: string): void;
|
|
158
158
|
/** Where a setting's effective value came from. */
|
|
159
159
|
export type ProvenanceSource = 'cli' | 'fleet-default' | 'caller-role' | 'built-in';
|
package/dist/creation.js
CHANGED
|
@@ -300,12 +300,12 @@ export function daemonIdentityInventoryProvisioner(env = process.env, attachClie
|
|
|
300
300
|
acceptTemporaryExisting: true,
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
-
/** Atomically write a
|
|
303
|
+
/** Atomically write a bare Agent file, journalling it for rollback. */
|
|
304
304
|
export function writeRoleFile(tx, file, contents) {
|
|
305
305
|
const existed = existsSync(file);
|
|
306
306
|
replaceFileAtomically(file, contents, 0o644);
|
|
307
307
|
tx.record({
|
|
308
|
-
stage: `
|
|
308
|
+
stage: `Agent file ${file}`,
|
|
309
309
|
// Only remove what THIS transaction created; never delete a file the
|
|
310
310
|
// operator already had.
|
|
311
311
|
undo: () => { if (!existed)
|