@aiwg/cli 2026.10.16 → 2026.10.19
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/agentic/code/providers/capability-matrix.yaml +51 -0
- package/agentic/code/providers/flue/README.md +62 -0
- package/agentic/code/providers/flue/templates/aiwg/tools.ts +120 -0
- package/agentic/code/providers/model-capabilities.v1.json +23 -0
- package/agentic/code/providers/model-catalog.v1.json +9 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +28 -6
- package/dist/src/artifacts/query-engine-corpus.js +217 -0
- package/dist/src/artifacts/query-engine-discover-output.js +229 -0
- package/dist/src/artifacts/query-engine-discover.js +285 -0
- package/dist/src/artifacts/query-engine-entries.js +188 -0
- package/dist/src/artifacts/query-engine-index.js +249 -0
- package/dist/src/artifacts/query-engine-matching.js +143 -0
- package/dist/src/artifacts/query-engine-options.js +2 -0
- package/dist/src/artifacts/query-engine-rules.js +202 -0
- package/dist/src/artifacts/query-engine-scoring.js +436 -0
- package/dist/src/artifacts/query-engine-show-card.js +194 -0
- package/dist/src/artifacts/query-engine-show-load.js +211 -0
- package/dist/src/artifacts/query-engine-show.js +300 -0
- package/dist/src/artifacts/query-engine.js +7 -2576
- package/dist/src/cli/handlers/help.js +1 -1
- package/dist/src/cli/handlers/init.js +1 -0
- package/dist/src/cli/handlers/mc-agents.js +111 -0
- package/dist/src/cli/handlers/mc-args.js +54 -0
- package/dist/src/cli/handlers/mc-control.js +227 -0
- package/dist/src/cli/handlers/mc-dispatch.js +203 -0
- package/dist/src/cli/handlers/mc-help.js +171 -0
- package/dist/src/cli/handlers/mc-run.js +343 -0
- package/dist/src/cli/handlers/mc-session.js +138 -0
- package/dist/src/cli/handlers/mc-status.js +258 -0
- package/dist/src/cli/handlers/mc-summary.js +43 -0
- package/dist/src/cli/handlers/mc-types.js +3 -0
- package/dist/src/cli/handlers/mc-worker.js +205 -0
- package/dist/src/cli/handlers/mc.js +12 -1665
- package/dist/src/cli/handlers/models-refusal.js +13 -0
- package/dist/src/cli/handlers/models.js +2 -1
- package/dist/src/cli/handlers/remove-bundled.js +133 -0
- package/dist/src/cli/handlers/remove-options.js +31 -0
- package/dist/src/cli/handlers/remove-user.js +174 -0
- package/dist/src/cli/handlers/remove.js +201 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
- package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
- package/dist/src/cli/handlers/subcommands-list.js +250 -0
- package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
- package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
- package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
- package/dist/src/cli/handlers/subcommands-services.js +66 -0
- package/dist/src/cli/handlers/subcommands-storage.js +259 -0
- package/dist/src/cli/handlers/subcommands.js +18 -1984
- package/dist/src/cli/handlers/use.js +11 -5
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +3 -0
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
- package/dist/src/config/host-resource-report.d.mts +5 -0
- package/dist/src/config/host-resource-report.mjs +36 -6
- package/dist/src/config/host-resource-runtime.d.mts +3 -0
- package/dist/src/config/host-resource-runtime.mjs +9 -6
- package/dist/src/decision/ensemble-study/artifacts.js +7 -0
- package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
- package/dist/src/decision/ensemble-study/gates.js +78 -0
- package/dist/src/decision/ensemble-study/protocol.js +18 -21
- package/dist/src/decision/ensemble-study/score.js +3 -2
- package/dist/src/decision/ensemble-study/statistics.js +7 -26
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/extensions/claude-hooks-installer.js +18 -0
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/observations.js +363 -0
- package/dist/src/gates/pack-composition.js +270 -0
- package/dist/src/gates/pack-tightening.js +197 -0
- package/dist/src/gates/pack-validation.js +262 -0
- package/dist/src/gates/registry-error.js +5 -0
- package/dist/src/gates/registry.js +13 -685
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/provider-memory-adapter.js +1 -0
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/model-capabilities.v1.json +23 -0
- package/dist/src/models/model-catalog.v1.json +9 -0
- package/dist/src/models/policy-resources.js +1 -1
- package/dist/src/models/worker-plan.js +5 -5
- package/dist/src/plugin/command-ownership.js +34 -0
- package/dist/src/plugin/skill-command-frontmatter.js +197 -0
- package/dist/src/plugin/skill-command-translator.js +6 -232
- package/dist/src/providers/capability-matrix.yaml +51 -0
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +20 -0
- package/dist/src/providers/deployment-ownership.mjs +236 -0
- package/dist/src/providers/deployment-removal.js +222 -0
- package/dist/src/providers/provider-context-contracts.js +8 -0
- package/dist/src/providers/provider-definition-schema.js +1 -0
- package/dist/src/providers/provider-definitions.js +1 -0
- package/dist/src/providers/provider-seeds-3.js +18 -0
- package/dist/src/providers/removal-transaction.js +86 -0
- package/dist/src/providers/settings-document.d.mts +3 -0
- package/dist/src/providers/settings-document.mjs +47 -0
- package/dist/src/providers/settings-removal.js +190 -0
- package/dist/src/providers/skill-ownership.d.mts +20 -2
- package/dist/src/providers/skill-ownership.mjs +12 -4
- package/dist/src/providers/transformation-receipt-integration.js +15 -271
- package/dist/src/providers/transformation-receipt-outputs.js +99 -0
- package/dist/src/providers/transformation-receipt-source.js +194 -0
- package/dist/src/research/identity.js +8 -2
- package/dist/src/research/reference-match.js +66 -8
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +4 -0
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/skills/deployment-ownership.js +2 -2
- package/dist/src/skills/deployment-policy.js +9 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/flue-context.js +25 -0
- package/dist/src/smiths/context-pipeline/generator.js +7 -2
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +9 -7
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +5 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +21 -680
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +267 -0
- package/tools/agents/deploy-support.mjs +165 -0
- package/tools/agents/providers/base-addon-discovery.mjs +139 -0
- package/tools/agents/providers/base-behaviors.mjs +168 -0
- package/tools/agents/providers/base-context.mjs +205 -0
- package/tools/agents/providers/base-contract.mjs +116 -0
- package/tools/agents/providers/base-files.mjs +252 -0
- package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
- package/tools/agents/providers/base-framework-discovery.mjs +309 -0
- package/tools/agents/providers/base-frontmatter.mjs +196 -0
- package/tools/agents/providers/base-inventory.mjs +269 -0
- package/tools/agents/providers/base-kernel-skills.mjs +354 -0
- package/tools/agents/providers/base-migrations.mjs +258 -0
- package/tools/agents/providers/base-models-platforms.mjs +273 -0
- package/tools/agents/providers/base-rule-index.mjs +450 -0
- package/tools/agents/providers/base-runtime.mjs +60 -0
- package/tools/agents/providers/base-skill-copy.mjs +273 -0
- package/tools/agents/providers/base.mjs +16 -3364
- package/tools/agents/providers/claude-post-deploy.mjs +10 -2
- package/tools/agents/providers/flue-project.mjs +79 -0
- package/tools/agents/providers/flue-specialists.mjs +64 -0
- package/tools/agents/providers/flue.mjs +50 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +33 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +13 -3
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/agents/providers/rule-startup.mjs +3 -3
- package/tools/agents/use-rule-selection.mjs +17 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import * as ui from '../ui.js';
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { validateWorkerPayload } from '../../mission-protocol/codecs.js';
|
|
5
|
+
import { createMcAdmissionScheduler } from './mc-admission.js';
|
|
6
|
+
import { writeSession, listSessions, findActiveSession } from './mc-session.js';
|
|
7
|
+
import { hasFlag, getPositionalArgs } from './mc-args.js';
|
|
8
|
+
import { readAdmissionConfig, readManagedWorkerState } from './mc-worker.js';
|
|
9
|
+
/**
|
|
10
|
+
* Sync mission statuses from their backing ralph loop state files (#1439).
|
|
11
|
+
*
|
|
12
|
+
* Each mission launched by `mc run` carries a `ralphLoopId`. The ralph loop
|
|
13
|
+
* writes its own session-state.json with a `status` field
|
|
14
|
+
* (running|completed|failed|paused|aborted). This helper polls those files
|
|
15
|
+
* and reflects the truth back into the mc session.json so `mc status` and
|
|
16
|
+
* `mc watch` show actual progress without manual intervention.
|
|
17
|
+
*
|
|
18
|
+
* Sync is best-effort — a missing or unreadable ralph state file leaves the
|
|
19
|
+
* mission status unchanged (typically 'running' until the ralph process
|
|
20
|
+
* actually writes state).
|
|
21
|
+
*/
|
|
22
|
+
export async function syncMissionsFromRalph(session, projectRoot) {
|
|
23
|
+
let mutated = false;
|
|
24
|
+
const cfg = await readAdmissionConfig(projectRoot);
|
|
25
|
+
const scheduler = await createMcAdmissionScheduler(projectRoot, cfg);
|
|
26
|
+
const managed = cfg?.parallelism?.worker_dispatch && cfg.parallelism.worker_mode === 'managed';
|
|
27
|
+
for (const mission of session.missions) {
|
|
28
|
+
const wasRunning = mission.status === 'running';
|
|
29
|
+
if (!wasRunning && !(managed && mission.managedWorker && mission.admissionState === 'uncertain'))
|
|
30
|
+
continue;
|
|
31
|
+
if (!mission.ralphLoopId)
|
|
32
|
+
continue;
|
|
33
|
+
const ralphStatePath = join(projectRoot, '.aiwg', 'ralph-external', 'loops', mission.ralphLoopId, 'session-state.json');
|
|
34
|
+
if (managed) {
|
|
35
|
+
const current = mission.admissionRequestId ? scheduler.snapshot().records[mission.admissionRequestId] : undefined;
|
|
36
|
+
if (!current || !mission.admissionGeneration || current.leaseGeneration !== mission.admissionGeneration)
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const state = managed && mission.managedWorker
|
|
41
|
+
? await readManagedWorkerState(mission, scheduler)
|
|
42
|
+
: JSON.parse(await fs.readFile(ralphStatePath, 'utf-8'));
|
|
43
|
+
const ralphStatus = String(state.status || '').toLowerCase();
|
|
44
|
+
if (managed && mission.admissionRequestId && state.health !== undefined) {
|
|
45
|
+
if (!validateWorkerPayload('workerHealthSummary', state.health).valid)
|
|
46
|
+
throw new Error('invalid Ralph worker health');
|
|
47
|
+
const observed = scheduler.observeHealth(mission.admissionRequestId, mission.admissionGeneration, state.health);
|
|
48
|
+
mission.admissionState = observed.state;
|
|
49
|
+
mutated = true;
|
|
50
|
+
}
|
|
51
|
+
// Map ralph status → mc mission status
|
|
52
|
+
let nextStatus = null;
|
|
53
|
+
if (ralphStatus === 'completed')
|
|
54
|
+
nextStatus = 'done';
|
|
55
|
+
else if (ralphStatus === 'failed' || ralphStatus === 'crashed')
|
|
56
|
+
nextStatus = 'failed';
|
|
57
|
+
else if (ralphStatus === 'aborted')
|
|
58
|
+
nextStatus = 'aborted';
|
|
59
|
+
else if (ralphStatus === 'paused')
|
|
60
|
+
nextStatus = 'paused';
|
|
61
|
+
if (!wasRunning)
|
|
62
|
+
nextStatus = null;
|
|
63
|
+
// 'running' stays running
|
|
64
|
+
// Reflect iteration count if available
|
|
65
|
+
const iter = typeof state.iteration === 'number' ? state.iteration : (typeof state.currentIteration === 'number' ? state.currentIteration : null);
|
|
66
|
+
if (iter !== null && iter !== mission.loop) {
|
|
67
|
+
mission.loop = iter;
|
|
68
|
+
mutated = true;
|
|
69
|
+
}
|
|
70
|
+
// mission.status is narrowed to 'running' by the early-continue above,
|
|
71
|
+
// and nextStatus is one of {done, failed, aborted, paused}. So the
|
|
72
|
+
// transition is always real when nextStatus is set — no equality
|
|
73
|
+
// check needed.
|
|
74
|
+
if (nextStatus) {
|
|
75
|
+
mission.status = nextStatus;
|
|
76
|
+
mission.completedAt = new Date().toISOString();
|
|
77
|
+
if (nextStatus === 'failed' && typeof state.error === 'string') {
|
|
78
|
+
mission.error = state.error;
|
|
79
|
+
}
|
|
80
|
+
mutated = true;
|
|
81
|
+
if (mission.admissionRequestId) {
|
|
82
|
+
if (managed) {
|
|
83
|
+
if (!mission.managedWorker) {
|
|
84
|
+
if (state.health)
|
|
85
|
+
scheduler.acceptFinal(mission.admissionRequestId, mission.admissionGeneration, state.health);
|
|
86
|
+
}
|
|
87
|
+
if (mission.admissionState !== 'settled')
|
|
88
|
+
mission.admissionState = scheduler.stop(mission.admissionRequestId, mission.admissionGeneration, 'observer-loss').state;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
try {
|
|
92
|
+
scheduler.release(mission.admissionRequestId);
|
|
93
|
+
}
|
|
94
|
+
catch { /* already expired or released */ }
|
|
95
|
+
mission.admissionState = 'released';
|
|
96
|
+
}
|
|
97
|
+
mission.admissionLeaseExpiresAt = undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (mission.admissionRequestId) {
|
|
101
|
+
try {
|
|
102
|
+
const renewed = managed
|
|
103
|
+
? scheduler.renew(mission.admissionRequestId, mission.admissionGeneration)
|
|
104
|
+
: scheduler.renew(mission.admissionRequestId);
|
|
105
|
+
mission.admissionState = renewed.state;
|
|
106
|
+
mission.admissionLeaseExpiresAt = renewed.leaseExpiresAt;
|
|
107
|
+
mutated = true;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// An expired lease is reconciled on the next run; status remains best-effort.
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
if (managed && mission.admissionRequestId) {
|
|
116
|
+
mission.admissionState = scheduler.disconnect(mission.admissionRequestId, mission.admissionGeneration).state;
|
|
117
|
+
mission.admissionLeaseExpiresAt = undefined;
|
|
118
|
+
mutated = true;
|
|
119
|
+
}
|
|
120
|
+
// Missing supervision preserves the last task status and all artifacts.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (mutated) {
|
|
124
|
+
session.updatedAt = new Date().toISOString();
|
|
125
|
+
await writeSession(session);
|
|
126
|
+
}
|
|
127
|
+
return mutated;
|
|
128
|
+
}
|
|
129
|
+
export async function mcStatus(ctx) {
|
|
130
|
+
const positional = getPositionalArgs(ctx.args);
|
|
131
|
+
const sessionId = positional[0];
|
|
132
|
+
const json = hasFlag(ctx.args, '--json');
|
|
133
|
+
const session = await findActiveSession(sessionId);
|
|
134
|
+
if (!session) {
|
|
135
|
+
if (json) {
|
|
136
|
+
console.log(JSON.stringify({ error: 'no_active_session' }));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
ui.error(sessionId ? `Session not found: ${sessionId}` : 'No active session.');
|
|
140
|
+
}
|
|
141
|
+
return { exitCode: 1 };
|
|
142
|
+
}
|
|
143
|
+
// #1439: Sync mission statuses from ralph loop state files BEFORE display
|
|
144
|
+
// so 'mc status' reflects the true state of any in-flight ralph processes
|
|
145
|
+
// (otherwise missions launched by 'mc run' stay 'running' in mc.session.json
|
|
146
|
+
// even after the ralph loop has completed).
|
|
147
|
+
await syncMissionsFromRalph(session, ctx.cwd || process.cwd());
|
|
148
|
+
if (json) {
|
|
149
|
+
console.log(JSON.stringify(session, null, 2));
|
|
150
|
+
return { exitCode: 0 };
|
|
151
|
+
}
|
|
152
|
+
const statusIcons = {
|
|
153
|
+
done: '✓',
|
|
154
|
+
running: '⏳',
|
|
155
|
+
queued: '⏺',
|
|
156
|
+
failed: '✗',
|
|
157
|
+
aborted: '⊘',
|
|
158
|
+
paused: '⏸',
|
|
159
|
+
};
|
|
160
|
+
ui.blank();
|
|
161
|
+
console.log(` ${ui.brandMark()} ${ui.bold('MISSION CONTROL')} — ${ui.accent(session.name)} [${session.id}]`);
|
|
162
|
+
ui.rule(60);
|
|
163
|
+
// Header
|
|
164
|
+
// #1441: ui.dim() returns void (it prints) — wrapping in console.log emitted
|
|
165
|
+
// a literal "undefined" between the header and the separator. Use dimText()
|
|
166
|
+
// (returns a string) for inline styling.
|
|
167
|
+
const header = ` ${'#'.padEnd(4)} ${'Mission'.padEnd(32)} ${'Mode'.padEnd(6)} ${'Status'.padEnd(12)} ${'Loop'.padEnd(8)} ${'Started'.padEnd(8)}`;
|
|
168
|
+
console.log(ui.dimText(header));
|
|
169
|
+
ui.rule(68);
|
|
170
|
+
for (let i = 0; i < session.missions.length; i++) {
|
|
171
|
+
const m = session.missions[i];
|
|
172
|
+
const icon = statusIcons[m.status] || '?';
|
|
173
|
+
const num = String(i + 1).padEnd(4);
|
|
174
|
+
const obj = m.objective.length > 30 ? m.objective.slice(0, 27) + '...' : m.objective.padEnd(32);
|
|
175
|
+
const modeTag = m.mode === 'pty-orchestrator' ? 'PTY'.padEnd(6) : '—'.padEnd(6);
|
|
176
|
+
const status = `${icon} ${m.status.toUpperCase()}`.padEnd(12);
|
|
177
|
+
const loop = m.status === 'queued' ? '—'.padEnd(8) : `${m.loop}/${m.maxIterations}`.padEnd(8);
|
|
178
|
+
const started = m.startedAt ? new Date(m.startedAt).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }) : '—';
|
|
179
|
+
console.log(` ${num} ${obj} ${modeTag} ${status} ${loop} ${started}`);
|
|
180
|
+
// Show last action for PTY-orchestrated missions
|
|
181
|
+
if (m.mode === 'pty-orchestrator' && m.lastAction && m.status === 'running') {
|
|
182
|
+
console.log(ui.dimText(` └─ Last: ${m.lastAction}`));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
ui.rule(68);
|
|
186
|
+
const counts = {
|
|
187
|
+
done: session.missions.filter(m => m.status === 'done').length,
|
|
188
|
+
running: session.missions.filter(m => m.status === 'running').length,
|
|
189
|
+
queued: session.missions.filter(m => m.status === 'queued').length,
|
|
190
|
+
failed: session.missions.filter(m => m.status === 'failed').length,
|
|
191
|
+
};
|
|
192
|
+
console.log(` ${session.missions.length} missions | ${counts.done} done | ${counts.running} running | ${counts.queued} queued | ${counts.failed} failed`);
|
|
193
|
+
// #1361: Show project parallelism cap when one is configured.
|
|
194
|
+
try {
|
|
195
|
+
const { readAiwgConfig, resolveParallelism } = await import('../../config/aiwg-config.js');
|
|
196
|
+
const cfg = await readAiwgConfig(ctx.cwd || process.cwd());
|
|
197
|
+
if (cfg) {
|
|
198
|
+
const resolved = resolveParallelism(cfg.parallelism, cfg.providers[0]);
|
|
199
|
+
const active = counts.running + counts.queued;
|
|
200
|
+
const cap = resolved.max_parallel_mc_missions;
|
|
201
|
+
const overCap = active > cap ? ` ${ui.dim(`(${active - cap} over cap — queued)`)}` : '';
|
|
202
|
+
console.log(` Parallelism cap: ${active}/${cap} active${overCap}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
// Non-fatal
|
|
207
|
+
}
|
|
208
|
+
ui.blank();
|
|
209
|
+
return { exitCode: 0 };
|
|
210
|
+
}
|
|
211
|
+
export async function mcList(ctx) {
|
|
212
|
+
const json = hasFlag(ctx.args, '--json');
|
|
213
|
+
const sessions = await listSessions();
|
|
214
|
+
if (json) {
|
|
215
|
+
console.log(JSON.stringify(sessions.map(s => ({
|
|
216
|
+
id: s.id,
|
|
217
|
+
name: s.name,
|
|
218
|
+
state: s.state,
|
|
219
|
+
missions: s.missions.length,
|
|
220
|
+
created: s.createdAt,
|
|
221
|
+
updated: s.updatedAt,
|
|
222
|
+
})), null, 2));
|
|
223
|
+
return { exitCode: 0 };
|
|
224
|
+
}
|
|
225
|
+
if (sessions.length === 0) {
|
|
226
|
+
ui.info('No Mission Control sessions. Run `aiwg mc start` to create one.');
|
|
227
|
+
return { exitCode: 0 };
|
|
228
|
+
}
|
|
229
|
+
ui.blank();
|
|
230
|
+
console.log(` ${ui.brandMark()} ${ui.bold('Mission Control Sessions')}`);
|
|
231
|
+
ui.rule();
|
|
232
|
+
for (const s of sessions) {
|
|
233
|
+
const stateIcon = s.state === 'active' ? '●' : s.state === 'paused' ? '⏸' : '○';
|
|
234
|
+
const missionCount = s.missions.length;
|
|
235
|
+
const done = s.missions.filter(m => m.status === 'done').length;
|
|
236
|
+
console.log(` ${stateIcon} ${s.id} ${ui.accent(s.name)} (${done}/${missionCount} done) [${s.state}]`);
|
|
237
|
+
}
|
|
238
|
+
ui.blank();
|
|
239
|
+
return { exitCode: 0 };
|
|
240
|
+
}
|
|
241
|
+
export async function mcWatch(ctx) {
|
|
242
|
+
const positional = getPositionalArgs(ctx.args);
|
|
243
|
+
const sessionId = positional[0];
|
|
244
|
+
const session = await findActiveSession(sessionId);
|
|
245
|
+
if (!session) {
|
|
246
|
+
ui.error('No active session to watch.');
|
|
247
|
+
return { exitCode: 1 };
|
|
248
|
+
}
|
|
249
|
+
// For non-interactive contexts, show status once with a note
|
|
250
|
+
// Real streaming would use fs.watch on the session file
|
|
251
|
+
ui.info(`Watch mode: polling session ${session.id}`);
|
|
252
|
+
ui.info('Press Ctrl+C to stop watching.');
|
|
253
|
+
ui.blank();
|
|
254
|
+
// Show current status
|
|
255
|
+
ctx.args = [session.id];
|
|
256
|
+
return mcStatus(ctx);
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=mc-status.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Read an existing conductor ledger without session synchronization or persistence.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { summarizeMissionLedger } from '../../serve/mission-conductor.js';
|
|
5
|
+
import { parseFlag, hasFlag } from './mc-args.js';
|
|
6
|
+
import * as ui from '../ui.js';
|
|
7
|
+
function ledgerShape(value) {
|
|
8
|
+
return value !== null && typeof value === 'object' && typeof value.missionId === 'string'
|
|
9
|
+
&& Array.isArray(value.cycles) && value.cycles.every((cycle) => cycle
|
|
10
|
+
&& typeof cycle.cycleId === 'string' && typeof cycle.routed === 'boolean')
|
|
11
|
+
&& new Set(value.cycles.map((cycle) => cycle.cycleId)).size === value.cycles.length
|
|
12
|
+
&& value.checkpoint && ['completed', 'failed', 'pending'].every(key => Array.isArray(value.checkpoint[key]) && value.checkpoint[key].every((id) => typeof id === 'string'))
|
|
13
|
+
// A future execution mode is classified unknown by the summary, not rejected.
|
|
14
|
+
&& (value.executionMode === undefined || typeof value.executionMode === 'string');
|
|
15
|
+
}
|
|
16
|
+
export async function mcSummary(ctx) {
|
|
17
|
+
const path = parseFlag(ctx.args, '--ledger');
|
|
18
|
+
if (!path || path.startsWith('--')) {
|
|
19
|
+
ui.error('Usage: aiwg mc summary --ledger <path> [--json]');
|
|
20
|
+
return { exitCode: 1 };
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const ledger = JSON.parse(await readFile(resolve(ctx.cwd, path), 'utf8'));
|
|
24
|
+
if (!ledgerShape(ledger))
|
|
25
|
+
throw new Error('Invalid Mission ledger: cycles and checkpoints are required');
|
|
26
|
+
const summary = summarizeMissionLedger(ledger);
|
|
27
|
+
if (hasFlag(ctx.args, '--json'))
|
|
28
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
29
|
+
else {
|
|
30
|
+
console.log(`Mission ${summary.missionId}`);
|
|
31
|
+
console.log(Object.entries(summary.counts).map(([status, count]) => `${status}: ${count}`).join(', '));
|
|
32
|
+
for (const cycle of summary.cycles)
|
|
33
|
+
console.log(`${cycle.cycleId}: ${cycle.status} — ${cycle.reason}`);
|
|
34
|
+
}
|
|
35
|
+
return { exitCode: 0 };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
ui.error(message);
|
|
40
|
+
return { exitCode: 1, message };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=mc-summary.js.map
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { constants as fsConstants, promises as fs } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join, relative } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { assertValidWorkerPayload, workerConsumerSupport } from '../../mission-protocol/codecs.js';
|
|
6
|
+
import { WORKER_BASELINE_FEATURES } from '../../mission-protocol/types.js';
|
|
7
|
+
import { createMcAdmissionScheduler } from './mc-admission.js';
|
|
8
|
+
/** Managed callers fail closed on invalid configuration; legacy reads keep their
|
|
9
|
+
* historical best-effort behavior. No activation is installed by a caller. */
|
|
10
|
+
export async function readAdmissionConfig(projectRoot) {
|
|
11
|
+
const { readAiwgConfig, readAiwgConfigCandidate } = await import('../../config/aiwg-config.js');
|
|
12
|
+
try {
|
|
13
|
+
return await readAiwgConfig(projectRoot);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
const candidate = await readAiwgConfigCandidate(projectRoot);
|
|
17
|
+
if (candidate?.parallelism?.worker_mode === 'managed')
|
|
18
|
+
throw error;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const mcWorkerSupport = () => workerConsumerSupport([...WORKER_BASELINE_FEATURES, 'worker-health.v1']);
|
|
23
|
+
export function workerDispatch(mission) {
|
|
24
|
+
const bindings = new Set();
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
function visit(value) {
|
|
27
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
28
|
+
return;
|
|
29
|
+
seen.add(value);
|
|
30
|
+
const record = value;
|
|
31
|
+
if (record['aiwg.worker-dispatch'])
|
|
32
|
+
bindings.add(record['aiwg.worker-dispatch']);
|
|
33
|
+
visit(record.extensions);
|
|
34
|
+
visit(record.metadata);
|
|
35
|
+
for (const [key, child] of Object.entries(record))
|
|
36
|
+
if (key.startsWith('aiwg.source.'))
|
|
37
|
+
visit(child);
|
|
38
|
+
}
|
|
39
|
+
visit(mission);
|
|
40
|
+
if (bindings.size > 1)
|
|
41
|
+
throw new Error('Managed task contains multiple dispatch bindings');
|
|
42
|
+
return [...bindings][0];
|
|
43
|
+
}
|
|
44
|
+
export async function readWorkerArtifact(artifact, projectRoot) {
|
|
45
|
+
const filename = artifact.ref.startsWith('file:') ? fileURLToPath(artifact.ref) : artifact.ref;
|
|
46
|
+
const inside = relative(projectRoot, filename);
|
|
47
|
+
if (!isAbsolute(filename) || inside.startsWith('..') || isAbsolute(inside))
|
|
48
|
+
throw new Error('Managed worker artifacts must be inside the project');
|
|
49
|
+
const bytes = await readWorkerBytes(filename);
|
|
50
|
+
if (`sha256:${createHash('sha256').update(bytes).digest('hex')}` !== artifact.digest)
|
|
51
|
+
throw new Error('Managed worker artifact digest changed');
|
|
52
|
+
return JSON.parse(bytes.toString('utf8'));
|
|
53
|
+
}
|
|
54
|
+
export async function readWorkerBytes(filename) {
|
|
55
|
+
const { inspectWorkerPath } = await import('../../serve/worker-invocation.js');
|
|
56
|
+
if (!await inspectWorkerPath(filename, 'file'))
|
|
57
|
+
throw Object.assign(new Error('Managed worker artifact is missing'), { code: 'ENOENT' });
|
|
58
|
+
const handle = await fs.open(filename, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
|
59
|
+
try {
|
|
60
|
+
const stat = await handle.stat();
|
|
61
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.size > 1048576)
|
|
62
|
+
throw new Error('Invalid managed worker artifact');
|
|
63
|
+
const bytes = Buffer.alloc(1048577);
|
|
64
|
+
const { bytesRead } = await handle.read(bytes, 0, bytes.length, 0);
|
|
65
|
+
if (bytesRead > 1048576)
|
|
66
|
+
throw new Error('Managed worker artifact exceeds its size bound');
|
|
67
|
+
return bytes.subarray(0, bytesRead);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await handle.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export async function readWorkerJson(filename) {
|
|
74
|
+
return JSON.parse((await readWorkerBytes(filename)).toString('utf8'));
|
|
75
|
+
}
|
|
76
|
+
export async function resolveMcWorker(ctx, session, mission, parentKind = 'mission') {
|
|
77
|
+
const dispatch = workerDispatch(mission);
|
|
78
|
+
if (!dispatch)
|
|
79
|
+
return undefined;
|
|
80
|
+
const projectRoot = ctx.cwd || process.cwd();
|
|
81
|
+
const intent = await readWorkerArtifact(dispatch.intent, projectRoot);
|
|
82
|
+
assertValidWorkerPayload('workerSelectionIntent', intent);
|
|
83
|
+
if (!dispatch.brief)
|
|
84
|
+
throw new Error('Managed worker requires a prepared brief');
|
|
85
|
+
const brief = await readWorkerArtifact(dispatch.brief, projectRoot);
|
|
86
|
+
assertValidWorkerPayload('workerBrief', brief);
|
|
87
|
+
const { workerConfigDigest } = await import('../../config/aiwg-config.js');
|
|
88
|
+
if (intent.parent.kind !== parentKind || intent.parent.id !== session.id || intent.objective !== mission.objective
|
|
89
|
+
|| intent.taskId !== dispatch.taskId || intent.requestId !== dispatch.requestId
|
|
90
|
+
|| brief.invocationId !== dispatch.invocationId || workerConfigDigest(brief.intent) !== workerConfigDigest(intent)
|
|
91
|
+
|| brief.intentDigest !== workerConfigDigest(intent))
|
|
92
|
+
throw new Error('Managed worker task authority differs from its parent');
|
|
93
|
+
const { loadWorkerInputs } = await import('./models.js');
|
|
94
|
+
const { resolveWorkerInvocation } = await import('../../serve/worker-invocation.js');
|
|
95
|
+
const inputs = await loadWorkerInputs(ctx);
|
|
96
|
+
const plan = await resolveWorkerInvocation(inputs.snapshot, { role: intent.role, task: intent.taskClass, group: intent.group,
|
|
97
|
+
brief: dispatch.brief.ref.startsWith('file:') ? fileURLToPath(dispatch.brief.ref) : dispatch.brief.ref,
|
|
98
|
+
workdir: brief.workspace.path, final_output: brief.output.resultPath, managedIntent: intent }, inputs.drivers);
|
|
99
|
+
if (!plan.invocation || plan.status !== 'eligible' || plan.invocation.readiness !== 'launchable') {
|
|
100
|
+
throw new Error(`Managed worker is ineligible: ${plan.diagnostics.map(item => item.message).join('; ')}`);
|
|
101
|
+
}
|
|
102
|
+
if (parentKind === 'mission' && plan.invocation.transport !== 'shell')
|
|
103
|
+
throw new Error('Managed Ralph capture requires a qualified shell transport');
|
|
104
|
+
return { dispatch, intent, brief, plan };
|
|
105
|
+
}
|
|
106
|
+
/** Flow adapters use the same eligibility, project authority and allowance owner. */
|
|
107
|
+
export async function createMcFlowAdapter(ctx, bindings) {
|
|
108
|
+
const cfg = await readAdmissionConfig(ctx.cwd);
|
|
109
|
+
if (!cfg?.parallelism?.worker_dispatch || cfg.parallelism.worker_mode !== 'managed') {
|
|
110
|
+
throw new Error('OG_CONTRACT_UNSUPPORTED: Flow shared dispatch requires managed mode');
|
|
111
|
+
}
|
|
112
|
+
const scheduler = await createMcAdmissionScheduler(ctx.cwd, cfg);
|
|
113
|
+
const { managedAllowanceFromOwner } = await import('../../serve/shared-host-scheduler.js');
|
|
114
|
+
const { createManagedCompositionAdapter } = await import(join(ctx.frameworkRoot, 'agentic/code/addons/composition-engine/lib/runtime.mjs'));
|
|
115
|
+
return createManagedCompositionAdapter({ scheduler, allowanceFromOwner: managedAllowanceFromOwner,
|
|
116
|
+
invokeNode: bindings.invokeNode,
|
|
117
|
+
prepareNode: async (request) => {
|
|
118
|
+
const binding = await bindings.prepareNode(request);
|
|
119
|
+
const worker = await resolveMcWorker(ctx, { id: request.runId }, {
|
|
120
|
+
id: request.node.id, objective: binding.objective, status: 'queued', loop: 0,
|
|
121
|
+
maxIterations: 1, priority: 'normal', mode: 'direct', extensions: { 'aiwg.worker-dispatch': binding.dispatch },
|
|
122
|
+
}, 'flow');
|
|
123
|
+
if (!worker || worker.intent.taskId !== request.node.id)
|
|
124
|
+
throw new Error('Flow task authority differs from node identity');
|
|
125
|
+
const selected = worker.plan.selected;
|
|
126
|
+
return { invocation: worker.plan.invocation, plan: worker.plan, brief: worker.brief,
|
|
127
|
+
admission: { requestId: worker.dispatch.requestId, orchestratorId: request.runId,
|
|
128
|
+
environment: process.env.AIWG_ENVIRONMENT ?? 'default', provider: selected.inferenceProvider, runtimeKind: 'host',
|
|
129
|
+
priority: 10, submittedAt: new Date().toISOString(), queueTimeoutMs: (cfg.parallelism.admission?.queueTimeoutSeconds ?? 300) * 1000,
|
|
130
|
+
preemptible: false, metadata: { nodeId: request.node.id, invocationId: worker.dispatch.invocationId },
|
|
131
|
+
managed: { kind: 'external', group: selected.group, member: selected.member, cli: selected.cli,
|
|
132
|
+
model: selected.modelKey, quotaScope: cfg.parallelism.clis[selected.cli].quotaScope },
|
|
133
|
+
allowance: { runId: request.runId, taskId: request.node.id,
|
|
134
|
+
taskBudgets: { maxAttempts: worker.intent.limits.maxAttempts, maxTokens: worker.intent.limits.tokens,
|
|
135
|
+
maxCostUsd: worker.intent.limits.costUsd ?? undefined, timeoutSeconds: worker.intent.limits.wallSeconds },
|
|
136
|
+
reservation: { tokens: worker.plan.invocation.limits.tokens, costUsd: worker.plan.invocation.limits.costUsd } },
|
|
137
|
+
} };
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** Capture completion is evidence for the parent, never an independent gate. */
|
|
142
|
+
export async function readManagedWorkerState(mission, scheduler) {
|
|
143
|
+
const binding = mission.managedWorker;
|
|
144
|
+
const observation = await readWorkerJson(join(binding.runDir, 'health.json'));
|
|
145
|
+
assertValidWorkerPayload('workerHealthSummary', observation.health);
|
|
146
|
+
const dispatch = workerDispatch(mission);
|
|
147
|
+
if (observation.invocationId !== dispatch.invocationId || observation.health.observerGeneration !== mission.admissionGeneration) {
|
|
148
|
+
throw new Error('Stale managed worker observation');
|
|
149
|
+
}
|
|
150
|
+
let exit;
|
|
151
|
+
try {
|
|
152
|
+
exit = await readWorkerJson(join(binding.runDir, 'exit.json'));
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error.code !== 'ENOENT')
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
if (!exit)
|
|
159
|
+
return { status: 'running', health: observation.health };
|
|
160
|
+
if (exit.invocationId !== dispatch.invocationId || exit.managedAdmission?.requestId !== mission.admissionRequestId
|
|
161
|
+
|| exit.managedAdmission?.generation !== mission.admissionGeneration)
|
|
162
|
+
throw new Error('Stale managed worker exit evidence');
|
|
163
|
+
const record = scheduler.snapshot().records[mission.admissionRequestId];
|
|
164
|
+
const usage = { inputTokens: null, outputTokens: null, cacheTokens: null, reasoningTokens: null,
|
|
165
|
+
costUsd: null, quality: 'unknown', reservedTokens: record.accounting.reservation.tokens,
|
|
166
|
+
reservedUsd: record.accounting.reservation.costUsd };
|
|
167
|
+
const plan = await readWorkerJson(binding.invocationPath);
|
|
168
|
+
const succeeded = exit.exitCode === 0 && !exit.errorCode && !exit.timedOut && !exit.cancelled;
|
|
169
|
+
const result = { version: 1, taskId: dispatch.taskId, invocationId: dispatch.invocationId,
|
|
170
|
+
briefDigest: plan.invocation.briefDigest, worker: null,
|
|
171
|
+
execution: { status: succeeded ? 'completed' : 'failed', exitCode: exit.exitCode,
|
|
172
|
+
requested: plan.invocation.selected, observedModel: null, observedFamily: null, observedEffort: null,
|
|
173
|
+
identityEvidence: [], identityQuality: 'unavailable', startedAt: mission.startedAt, endedAt: exit.endedAt,
|
|
174
|
+
termination: exit.termination, usage, failure: null, health: observation.health },
|
|
175
|
+
verification: { status: 'pending', verifierId: null, runnerRef: null, artifactDigest: null, evidence: [], findings: [] } };
|
|
176
|
+
try {
|
|
177
|
+
const claims = await readWorkerJson(plan.invocation.finalPath);
|
|
178
|
+
assertValidWorkerPayload('workerClaims', claims);
|
|
179
|
+
result.worker = claims;
|
|
180
|
+
}
|
|
181
|
+
catch { /* Invalid or absent claims remain separate from execution evidence. */ }
|
|
182
|
+
assertValidWorkerPayload('workerResult', result);
|
|
183
|
+
// Use the checkpoint's own directory; request IDs need not contain a session ID.
|
|
184
|
+
const destination = `${binding.invocationPath}.result.json`;
|
|
185
|
+
const bytes = JSON.stringify(result);
|
|
186
|
+
await fs.writeFile(destination, bytes, { mode: 0o600 });
|
|
187
|
+
dispatch.result = { ref: pathToFileURL(destination).href, digest: `sha256:${createHash('sha256').update(bytes).digest('hex')}` };
|
|
188
|
+
scheduler.acceptFinal(mission.admissionRequestId, mission.admissionGeneration, observation.health, usage);
|
|
189
|
+
// A surviving or unobservable outer supervisor cannot prove its own stop.
|
|
190
|
+
let supervisorGone = false;
|
|
191
|
+
try {
|
|
192
|
+
process.kill(mission.admissionExecution.pid, 0);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
supervisorGone = error.code === 'ESRCH';
|
|
196
|
+
}
|
|
197
|
+
if (supervisorGone && exit.termination === 'confirmed' && exit.descendants === 'stopped') {
|
|
198
|
+
const settled = scheduler.settle(mission.admissionRequestId, mission.admissionGeneration, observation.health, usage, undefined, mission.admissionExecution);
|
|
199
|
+
mission.admissionState = settled.state;
|
|
200
|
+
}
|
|
201
|
+
dispatch.state = mission.admissionState === 'settled' ? succeeded ? 'completed' : 'failed' : 'uncertain';
|
|
202
|
+
// Verification and original completion criteria remain with the parent.
|
|
203
|
+
return { status: succeeded && result.worker?.status === 'completed' ? 'paused' : 'failed', health: observation.health };
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=mc-worker.js.map
|