@aiwg/cli 2026.10.15 → 2026.10.16
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/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +23 -9
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- package/dist/src/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +3 -2
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands.js +8 -0
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +19 -0
- package/dist/src/config/host-resource-report.mjs +80 -0
- package/dist/src/config/host-resource-runtime.d.mts +34 -0
- package/dist/src/config/host-resource-runtime.mjs +293 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- package/dist/src/decision/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +115 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/heldout.js +17 -7
- package/dist/src/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- package/dist/src/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -0
- package/dist/src/research/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +34 -2
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +70 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/serve/mission-conductor.js +48 -4
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +16 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +9 -10
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/package.json +10 -1
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +10 -0
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// Health diagnostics extracted from the utility handler collection.
|
|
2
|
+
import fsp from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { createScriptRunner } from './script-runner.js';
|
|
5
|
+
import { getFrameworkRoot } from '../../channel/manager.mjs';
|
|
6
|
+
import { parsePublicDoctorFlags } from './doctor-args.js';
|
|
7
|
+
import { DOCTOR_HELP } from './doctor-help.js';
|
|
8
|
+
import { checkCollisions } from '../../smiths/skillsmith/collision-detector.js';
|
|
9
|
+
import { renderUseDeploymentResult, verifyConfiguredDeployments } from '../services/deployment-verification.js';
|
|
10
|
+
function flagValue(args, flag) {
|
|
11
|
+
const index = args.indexOf(flag);
|
|
12
|
+
if (index >= 0)
|
|
13
|
+
return args[index + 1];
|
|
14
|
+
const prefix = `${flag}=`;
|
|
15
|
+
return args.find((arg) => arg.startsWith(prefix))?.slice(prefix.length);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A directory is a deployed skill only if it carries a SKILL.md manifest —
|
|
19
|
+
* the same marker `isOwnedByNamespace()` in collision-detector.ts reads for
|
|
20
|
+
* ownership. Harness container/bucket directories (e.g. Claude Code's own
|
|
21
|
+
* `.claude/skills/synced/` sync storage, which holds UUID-named dirs with
|
|
22
|
+
* `manifest.json`, not SKILL.md) have no manifest of their own and must
|
|
23
|
+
* never be reported as a colliding skill (#278).
|
|
24
|
+
*
|
|
25
|
+
* A container directory without its own SKILL.md is still descended exactly
|
|
26
|
+
* one level: a real skill nested inside it (`<container>/<skill>/SKILL.md`)
|
|
27
|
+
* is reported as `<container>/<skill>`, while the container itself never is.
|
|
28
|
+
*/
|
|
29
|
+
async function hasSkillManifest(dirPath) {
|
|
30
|
+
try {
|
|
31
|
+
await fsp.access(path.join(dirPath, 'SKILL.md'));
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function collectDeployedSkillDirNames(skillsDir) {
|
|
39
|
+
let topEntries;
|
|
40
|
+
try {
|
|
41
|
+
topEntries = await fsp.readdir(skillsDir, { withFileTypes: true });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
const names = [];
|
|
47
|
+
for (const entry of topEntries) {
|
|
48
|
+
if (!entry.isDirectory())
|
|
49
|
+
continue;
|
|
50
|
+
const dirPath = path.join(skillsDir, entry.name);
|
|
51
|
+
if (await hasSkillManifest(dirPath)) {
|
|
52
|
+
names.push(entry.name);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let nestedEntries;
|
|
56
|
+
try {
|
|
57
|
+
nestedEntries = await fsp.readdir(dirPath, { withFileTypes: true });
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const nested of nestedEntries) {
|
|
63
|
+
if (!nested.isDirectory())
|
|
64
|
+
continue;
|
|
65
|
+
const nestedPath = path.join(dirPath, nested.name);
|
|
66
|
+
if (await hasSkillManifest(nestedPath)) {
|
|
67
|
+
names.push(path.join(entry.name, nested.name));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return names;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* #1156 Phase 1 — Validate the per-user registry at `~/.aiwg/installed.json`.
|
|
75
|
+
*
|
|
76
|
+
* Checks each registered framework+provider deploy:
|
|
77
|
+
* - Registry entry parses correctly
|
|
78
|
+
* - Recorded artifact entries (Cycle 3 mirrors) still exist on disk
|
|
79
|
+
* - Per-artifact-type counts match the actual entry-name list length
|
|
80
|
+
* - Pre-Cycle-3 entries (no `entries` snapshot) are surfaced as "limited
|
|
81
|
+
* drift detection" rather than failures
|
|
82
|
+
*
|
|
83
|
+
* Returns exit 1 when drift is detected, exit 0 otherwise. Output is plain
|
|
84
|
+
* text suitable for terminal consumption.
|
|
85
|
+
*/
|
|
86
|
+
async function runUserScopeDoctor(verbose) {
|
|
87
|
+
const { readUserRegistry, userRegistryPath } = await import('../../config/user-registry.js');
|
|
88
|
+
const { USER_SCOPE_PATHS } = await import('../scope-resolver.js');
|
|
89
|
+
const fsp2 = await import('node:fs/promises');
|
|
90
|
+
const path2 = await import('node:path');
|
|
91
|
+
const registry = await readUserRegistry();
|
|
92
|
+
const frameworks = Object.entries(registry.installed);
|
|
93
|
+
const lines = [];
|
|
94
|
+
lines.push('');
|
|
95
|
+
lines.push('── User-scope registry validation ──');
|
|
96
|
+
lines.push(`Registry path: ${userRegistryPath()}`);
|
|
97
|
+
lines.push('');
|
|
98
|
+
if (frameworks.length === 0) {
|
|
99
|
+
lines.push('No frameworks deployed at user scope. Run `aiwg use <fw> --scope user` to install.');
|
|
100
|
+
return { exitCode: 0, message: lines.join('\n') + '\n' };
|
|
101
|
+
}
|
|
102
|
+
let driftCount = 0;
|
|
103
|
+
let limitedCount = 0;
|
|
104
|
+
for (const [name, entry] of frameworks) {
|
|
105
|
+
lines.push(`▸ ${name} v${entry.version} [${entry.source}]`);
|
|
106
|
+
for (const [provider, providerDeployRaw] of Object.entries(entry.deployedTo)) {
|
|
107
|
+
// Cast through unknown for the optional `entries` snapshot.
|
|
108
|
+
const providerDeploy = providerDeployRaw;
|
|
109
|
+
const userPaths = USER_SCOPE_PATHS[provider];
|
|
110
|
+
if (!userPaths) {
|
|
111
|
+
lines.push(` ${provider}: ⚠ no user-scope path map registered for this provider`);
|
|
112
|
+
driftCount++;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const recorded = providerDeploy.entries;
|
|
116
|
+
if (!recorded) {
|
|
117
|
+
lines.push(` ${provider}: ⚠ pre-Cycle-3 entry — no per-artifact manifest, drift detection limited`);
|
|
118
|
+
lines.push(` counts: agents=${providerDeploy.agents} commands=${providerDeploy.commands} skills=${providerDeploy.skills} rules=${providerDeploy.rules}`);
|
|
119
|
+
limitedCount++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// Walk the recorded entry names and check each one exists on disk.
|
|
123
|
+
const checks = [
|
|
124
|
+
['agents', userPaths.agents, recorded.agents, providerDeploy.agents],
|
|
125
|
+
['commands', userPaths.commands, recorded.commands, providerDeploy.commands],
|
|
126
|
+
['skills', userPaths.skills, recorded.skills, providerDeploy.skills],
|
|
127
|
+
['rules', userPaths.rules, recorded.rules, providerDeploy.rules],
|
|
128
|
+
];
|
|
129
|
+
const issues = [];
|
|
130
|
+
for (const [type, dir, names, expectedCount] of checks) {
|
|
131
|
+
if (!dir || !names)
|
|
132
|
+
continue;
|
|
133
|
+
let present = 0;
|
|
134
|
+
const missing = [];
|
|
135
|
+
for (const n of names) {
|
|
136
|
+
const target = path2.join(dir, n);
|
|
137
|
+
const stat = await fsp2.stat(target).catch(() => null);
|
|
138
|
+
if (stat)
|
|
139
|
+
present++;
|
|
140
|
+
else
|
|
141
|
+
missing.push(n);
|
|
142
|
+
}
|
|
143
|
+
if (names.length !== expectedCount) {
|
|
144
|
+
issues.push(`count drift on ${type}: registry says ${expectedCount}, manifest lists ${names.length}`);
|
|
145
|
+
}
|
|
146
|
+
if (missing.length > 0) {
|
|
147
|
+
issues.push(`${type}: ${missing.length}/${names.length} entries missing from ${dir}`);
|
|
148
|
+
if (verbose) {
|
|
149
|
+
for (const m of missing)
|
|
150
|
+
issues.push(` missing: ${path2.join(dir, m)}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (verbose) {
|
|
154
|
+
issues.push(`${type}: ${present}/${names.length} present at ${dir}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (issues.length === 0) {
|
|
158
|
+
lines.push(` ${provider}: ✓ all recorded artifacts present`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const hasMissing = issues.some(i => i.includes('missing') || i.includes('drift'));
|
|
162
|
+
const marker = hasMissing ? '✗' : 'ℹ';
|
|
163
|
+
lines.push(` ${provider}: ${marker}`);
|
|
164
|
+
for (const i of issues)
|
|
165
|
+
lines.push(` ${i}`);
|
|
166
|
+
if (hasMissing)
|
|
167
|
+
driftCount++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
lines.push('');
|
|
172
|
+
lines.push('═'.repeat(60));
|
|
173
|
+
lines.push(`Frameworks: ${frameworks.length} Drift: ${driftCount} Limited (pre-Cycle-3): ${limitedCount}`);
|
|
174
|
+
if (driftCount > 0) {
|
|
175
|
+
lines.push('');
|
|
176
|
+
lines.push('Drift detected. To repair, re-run `aiwg use <framework> --scope user --provider <p>`.');
|
|
177
|
+
lines.push('To remove a stale registry entry, run `aiwg remove <framework> --scope user`.');
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
exitCode: driftCount > 0 ? 1 : 0,
|
|
181
|
+
message: lines.join('\n') + '\n',
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Handler for doctor command
|
|
186
|
+
*
|
|
187
|
+
* Runs health diagnostics on the AIWG installation and workspace.
|
|
188
|
+
*
|
|
189
|
+
* Usage:
|
|
190
|
+
* aiwg doctor
|
|
191
|
+
* aiwg -doctor
|
|
192
|
+
* aiwg --doctor
|
|
193
|
+
* aiwg doctor --verbose
|
|
194
|
+
* aiwg doctor --scope user # validate ~/.aiwg/installed.json
|
|
195
|
+
*/
|
|
196
|
+
export const doctorHandler = {
|
|
197
|
+
id: 'doctor',
|
|
198
|
+
name: 'Doctor',
|
|
199
|
+
description: 'Run health diagnostics',
|
|
200
|
+
category: 'maintenance',
|
|
201
|
+
aliases: ['-doctor', '--doctor'],
|
|
202
|
+
async help() {
|
|
203
|
+
return { exitCode: 0, message: DOCTOR_HELP, rawOutput: true };
|
|
204
|
+
},
|
|
205
|
+
async execute(ctx) {
|
|
206
|
+
// Validate before any early-return mode: deployment and user-scope doctor
|
|
207
|
+
// never invoke doctor.mjs, so they must enforce the same flag contract.
|
|
208
|
+
let flags;
|
|
209
|
+
try {
|
|
210
|
+
flags = parsePublicDoctorFlags(ctx.args);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
return { exitCode: 2, message: `${error instanceof Error ? error.message : String(error)}. See 'aiwg doctor --help'.` };
|
|
214
|
+
}
|
|
215
|
+
const { hasSwitch, values } = flags;
|
|
216
|
+
if (hasSwitch('--help') || hasSwitch('-h')) {
|
|
217
|
+
return { exitCode: 0, message: DOCTOR_HELP, rawOutput: true };
|
|
218
|
+
}
|
|
219
|
+
if (hasSwitch('--deployment')) {
|
|
220
|
+
const scopeValue = values.get('--scope');
|
|
221
|
+
if (scopeValue && scopeValue !== 'project' && scopeValue !== 'user') {
|
|
222
|
+
return { exitCode: 2, message: `Invalid deployment verification scope: ${scopeValue}` };
|
|
223
|
+
}
|
|
224
|
+
const result = await verifyConfiguredDeployments(ctx.cwd || process.cwd(), {
|
|
225
|
+
provider: values.get('--provider'),
|
|
226
|
+
bundle: values.get('--bundle'),
|
|
227
|
+
scope: scopeValue,
|
|
228
|
+
}, ctx.frameworkRoot);
|
|
229
|
+
const { rulePinState } = await import('../../rules/pin-state.js');
|
|
230
|
+
const pins = rulePinState(ctx.cwd, ctx.frameworkRoot);
|
|
231
|
+
return {
|
|
232
|
+
exitCode: result.exitCode,
|
|
233
|
+
message: hasSwitch('--json')
|
|
234
|
+
? JSON.stringify({ ...result, rule_pins: { rules: pins.rules, warnings: pins.warnings } }, null, 2)
|
|
235
|
+
: renderUseDeploymentResult(result) + '\n' + pins.rules.map(rule => `${rule.name}: pinned kernel (canonical ${rule.canonical_activation})`).concat(pins.warnings).join('\n'),
|
|
236
|
+
rawOutput: hasSwitch('--json'),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
// #1156 Phase 1 — `aiwg doctor --scope user` / `aiwg doctor --user`
|
|
240
|
+
// validates the per-user registry (~/.aiwg/installed.json) without
|
|
241
|
+
// running the project-scope diagnostics. Operators need this to verify
|
|
242
|
+
// their user-scope deployments from any cwd, including shells with no
|
|
243
|
+
// project at all.
|
|
244
|
+
const userScopeRequested = hasSwitch('--user') || values.get('--scope') === 'user';
|
|
245
|
+
if (userScopeRequested && !hasSwitch('--probe-workers')) {
|
|
246
|
+
return await runUserScopeDoctor(hasSwitch('--verbose') || hasSwitch('-v'));
|
|
247
|
+
}
|
|
248
|
+
const frameworkRoot = (hasSwitch('--decision-offload') || hasSwitch('--resources')) ? ctx.frameworkRoot : await getFrameworkRoot();
|
|
249
|
+
const runner = createScriptRunner(frameworkRoot);
|
|
250
|
+
// Run core doctor diagnostics
|
|
251
|
+
const result = await runner.run('tools/cli/doctor.mjs', ctx.args, { cwd: ctx.cwd });
|
|
252
|
+
// Machine-readable worker probes (#3066): tools/cli/doctor.mjs already
|
|
253
|
+
// printed exactly one JSON document (or a usage error) on its own
|
|
254
|
+
// stdio — every section below writes human-readable text, so returning
|
|
255
|
+
// here keeps stdout to the JSON document alone.
|
|
256
|
+
if (hasSwitch('--resources') || hasSwitch('--list-approvals') || values.get('--forget-approval') || hasSwitch('--decision-offload') || hasSwitch('--json') || hasSwitch('--qualify') || hasSwitch('--cli') || hasSwitch('--dry-run') || result.exitCode === 2)
|
|
257
|
+
return result;
|
|
258
|
+
let agentSkillsFailure = false;
|
|
259
|
+
try {
|
|
260
|
+
const { inspectGrokBuildNative } = await import('../../mcp/grok-build-config.mjs');
|
|
261
|
+
const native = await inspectGrokBuildNative({ projectDir: ctx.cwd || process.cwd() });
|
|
262
|
+
console.log(`\n── Grok Build native extensions ──\n MCP: ${native.mcp}\n Hooks: ${native.hooks}`);
|
|
263
|
+
for (const diagnostic of native.diagnostics)
|
|
264
|
+
console.log(` ⚠ ${diagnostic}`);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
console.log(`\n── Grok Build native extensions ──\n ⚠ unable to audit: ${error instanceof Error ? error.message : String(error)}`);
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const projectDir = ctx.cwd || process.cwd();
|
|
271
|
+
const provider = flagValue(ctx.args, '--provider');
|
|
272
|
+
const requested = provider === 'muse' || ctx.args.includes('--all-providers');
|
|
273
|
+
const { inspectMuseNative, isMuseDeployedProject } = await import('../../mcp/muse-native-config.mjs');
|
|
274
|
+
if (requested || await isMuseDeployedProject(projectDir)) {
|
|
275
|
+
const native = await inspectMuseNative({ projectDir });
|
|
276
|
+
console.log(`\n── Muse Code native extensions ──\n CLI: ${native.cli}\n Hooks: ${native.hooks}\n MCP: ${native.mcp}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
console.log(`\n── Muse Code native extensions ──\n ⚠ unable to audit: ${error instanceof Error ? error.message : String(error)}`);
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const { buildAgentSkillsDoctorSection } = await import('../../skills/doctor.js');
|
|
284
|
+
const section = buildAgentSkillsDoctorSection(ctx.cwd || process.cwd());
|
|
285
|
+
console.log(section.output);
|
|
286
|
+
agentSkillsFailure = section.hasFailures;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
console.log(`\n── Agent Skills conformance ──\n ⚠ unable to audit: ${error instanceof Error ? error.message : String(error)}`);
|
|
290
|
+
}
|
|
291
|
+
// Surface feedback escape hatch when doctor finds issues
|
|
292
|
+
if (result.exitCode !== 0) {
|
|
293
|
+
console.log(`
|
|
294
|
+
── Recovery options ──
|
|
295
|
+
aiwg session --no-repair — launch anyway (skip auto-repair)
|
|
296
|
+
aiwg sync — sync to latest and redeploy
|
|
297
|
+
aiwg feedback --type bug — report this issue to GitHub
|
|
298
|
+
`);
|
|
299
|
+
}
|
|
300
|
+
// Append collision scan: check deployed skills dir for bad-state collisions
|
|
301
|
+
// (platform built-ins and AIWG CLI command shadows)
|
|
302
|
+
try {
|
|
303
|
+
const projectDir = ctx.cwd || process.cwd();
|
|
304
|
+
const skillsDir = path.join(projectDir, '.claude', 'skills');
|
|
305
|
+
const deployedSkillNames = await collectDeployedSkillDirNames(skillsDir);
|
|
306
|
+
if (deployedSkillNames.length > 0) {
|
|
307
|
+
const collisions = await checkCollisions({
|
|
308
|
+
platform: 'claude',
|
|
309
|
+
projectPath: projectDir,
|
|
310
|
+
skillNames: deployedSkillNames,
|
|
311
|
+
namespace: 'aiwg',
|
|
312
|
+
skillsBaseDir: skillsDir,
|
|
313
|
+
});
|
|
314
|
+
// Two distinct causes share this scan, and conflating them mislabels
|
|
315
|
+
// one as the other: an `error` is a name that shadows a Claude
|
|
316
|
+
// built-in; a `warn` is a deployed skill this namespace does not own
|
|
317
|
+
// (#2504). Report each under its own heading with its own remedy.
|
|
318
|
+
const builtinCollisions = collisions.filter(r => r.severity === 'error');
|
|
319
|
+
const unownedCollisions = collisions.filter(r => r.severity === 'warn');
|
|
320
|
+
if (builtinCollisions.length > 0 || unownedCollisions.length > 0) {
|
|
321
|
+
console.log('\n── Skill collision scan ──');
|
|
322
|
+
if (builtinCollisions.length > 0) {
|
|
323
|
+
console.log('');
|
|
324
|
+
console.log('⚠ Stale skills detected (names collide with Claude built-ins):');
|
|
325
|
+
for (const r of builtinCollisions) {
|
|
326
|
+
console.log(` ✗ ${r.skillName}: ${r.reason}`);
|
|
327
|
+
}
|
|
328
|
+
console.log('');
|
|
329
|
+
console.log(' Fix: run `aiwg use <framework>` to redeploy and auto-clean stale skill directories.');
|
|
330
|
+
}
|
|
331
|
+
if (unownedCollisions.length > 0) {
|
|
332
|
+
console.log('');
|
|
333
|
+
console.log("⚠ Deployed skills not owned by namespace 'aiwg' (a redeploy would overwrite them):");
|
|
334
|
+
for (const r of unownedCollisions) {
|
|
335
|
+
console.log(` ✗ ${r.skillName}: ${r.reason}`);
|
|
336
|
+
}
|
|
337
|
+
console.log('');
|
|
338
|
+
console.log(" Fix: if the skill is yours, move it out of the AIWG-managed skills directory");
|
|
339
|
+
console.log(" or give it its own namespace. If AIWG generated it, re-run `aiwg use` to");
|
|
340
|
+
console.log(' restore the ownership marker.');
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
// Collision scan is non-fatal for doctor
|
|
347
|
+
}
|
|
348
|
+
// #1037 / #1049 — Project-local artifacts section: per-type counts,
|
|
349
|
+
// validation errors, shadows, denylist violations, drift detection,
|
|
350
|
+
// and provider deployment matrix. Replaces the older inline shadow
|
|
351
|
+
// scan with the richer section spec'd by design-doctor-log-promote.md.
|
|
352
|
+
try {
|
|
353
|
+
const projectDir = ctx.cwd || process.cwd();
|
|
354
|
+
const fr = await getFrameworkRoot();
|
|
355
|
+
const { readAiwgConfig } = await import('../../config/aiwg-config.js');
|
|
356
|
+
const config = await readAiwgConfig(projectDir);
|
|
357
|
+
const { buildProjectLocalDoctorSection } = await import('../../extensions/project-local-doctor.js');
|
|
358
|
+
const onlyProjectLocal = ctx.args.includes('--project-local');
|
|
359
|
+
const quiet = ctx.args.includes('--quiet');
|
|
360
|
+
const section = await buildProjectLocalDoctorSection({
|
|
361
|
+
projectDir, frameworkRoot: fr, config, quiet,
|
|
362
|
+
});
|
|
363
|
+
if (section.output) {
|
|
364
|
+
console.log(section.output);
|
|
365
|
+
}
|
|
366
|
+
// When --project-local is requested as the only output and the rest
|
|
367
|
+
// of doctor printed nothing project-local-specific, fold result exit
|
|
368
|
+
// into our own findings.
|
|
369
|
+
if (onlyProjectLocal && section.hasFailures) {
|
|
370
|
+
return { exitCode: 1, message: '' };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
// Project-local section is non-fatal for doctor
|
|
375
|
+
}
|
|
376
|
+
// Web-backed resource lock/cache diagnostics (#1850). Report lock source
|
|
377
|
+
// mode, cold cache, and digest drift without requiring web mode to be in use.
|
|
378
|
+
try {
|
|
379
|
+
const { buildWebResourceDoctorSection } = await import('../../resources/doctor.js');
|
|
380
|
+
const section = buildWebResourceDoctorSection(ctx.cwd || process.cwd(), {
|
|
381
|
+
cacheRoot: process.env.AIWG_RESOURCE_CACHE_ROOT,
|
|
382
|
+
});
|
|
383
|
+
if (section.output)
|
|
384
|
+
console.log(section.output);
|
|
385
|
+
if (section.hasFailures)
|
|
386
|
+
return { exitCode: 1, message: '' };
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
console.log(`\n── Web resource cache ──\n ⚠ unable to audit: ${error instanceof Error ? error.message : String(error)}`);
|
|
390
|
+
}
|
|
391
|
+
// Canonical workspace-context graph diagnostics (#1811). Legacy projects
|
|
392
|
+
// remain valid; drift, loops, conflicts, and possible credentials fail.
|
|
393
|
+
try {
|
|
394
|
+
const { diagnoseWorkspaceContext } = await import('../../smiths/context-pipeline/workspace-context.js');
|
|
395
|
+
const diagnostics = await diagnoseWorkspaceContext(ctx.cwd || process.cwd());
|
|
396
|
+
console.log('\n── Workspace context graph ──');
|
|
397
|
+
for (const diagnostic of diagnostics) {
|
|
398
|
+
const mark = diagnostic.severity === 'error' ? '✗' : diagnostic.severity === 'warning' ? '⚠' : '✓';
|
|
399
|
+
console.log(` ${mark} ${diagnostic.message}`);
|
|
400
|
+
}
|
|
401
|
+
if (diagnostics.some((item) => item.severity === 'error'))
|
|
402
|
+
return { exitCode: 1, message: '' };
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
console.log(`\n── Workspace context graph ──\n ⚠ unable to audit: ${error instanceof Error ? error.message : String(error)}`);
|
|
406
|
+
}
|
|
407
|
+
return agentSkillsFailure
|
|
408
|
+
? { exitCode: 1, message: '' }
|
|
409
|
+
: result;
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=utility-doctor.js.map
|
|
@@ -577,7 +577,6 @@ export async function verifyProviderDeployment(options) {
|
|
|
577
577
|
const requiredContext = [
|
|
578
578
|
path.join(options.projectRoot, 'WORKSPACE.md'),
|
|
579
579
|
...(definition?.paths.contextFiles.aiwgMd === false ? [] : [path.join(options.projectRoot, 'AIWG.md')]),
|
|
580
|
-
path.join(options.projectRoot, '.aiwg', 'AIWG.md'),
|
|
581
580
|
];
|
|
582
581
|
for (const contextPath of requiredContext) {
|
|
583
582
|
if (!(await exists(contextPath))) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { preserveInstalledSelection } from './installed-selection.js';
|
|
1
2
|
import { validateHitlPolicy } from '../policy/hitl-validation.js';
|
|
2
3
|
import { normalizeAiwgConfigCandidate } from './config-normalization.js';
|
|
3
4
|
import { atomicConfigWrite, withWorkerWriteLock } from './worker-write.js';
|
|
@@ -1038,7 +1039,7 @@ export async function readAiwgConfig(projectDir, options) {
|
|
|
1038
1039
|
* sync so split-root health remains deterministic.
|
|
1039
1040
|
*/
|
|
1040
1041
|
export async function writeAiwgConfig(projectDir, config) {
|
|
1041
|
-
return withWorkerWriteLock(projectDir, () => writeAiwgConfigUnlocked(projectDir, config));
|
|
1042
|
+
return withWorkerWriteLock(projectDir, () => writeAiwgConfigUnlocked(projectDir, preserveInstalledSelection(projectDir, config)));
|
|
1042
1043
|
}
|
|
1043
1044
|
async function writeAiwgConfigUnlocked(projectDir, config) {
|
|
1044
1045
|
// Uninstall is an explicit capability change. Retire project selectors for
|
|
@@ -10,7 +10,7 @@ import { checkHitlAuthorization } from '../policy/hitl-check.js';
|
|
|
10
10
|
export const authorizationUsage = `aiwg config authorization (also aiwg steward authorization)
|
|
11
11
|
inspect | validate [--target DIRECTORY]
|
|
12
12
|
preview --action-file FILE [--target DIRECTORY]
|
|
13
|
-
check --action-file FILE [--target DIRECTORY]
|
|
13
|
+
check --action-file FILE [--receipt-file FILE --effect-id ID] [--target DIRECTORY]
|
|
14
14
|
enable --policy-file FILE [--target DIRECTORY]
|
|
15
15
|
revoke [--profile NAME] [--target DIRECTORY]
|
|
16
16
|
receipt --action-file FILE [--target DIRECTORY]
|
|
@@ -35,7 +35,8 @@ export async function authorizationCli(args, cwd = process.cwd()) {
|
|
|
35
35
|
const [operation, ...rest] = args;
|
|
36
36
|
const flags = {};
|
|
37
37
|
const allowed = ['--target', ...(operation === 'enable' ? ['--policy-file'] : []),
|
|
38
|
-
...(['preview', 'receipt', 'check'].includes(operation) ? ['--action-file'] : []),
|
|
38
|
+
...(['preview', 'receipt', 'check'].includes(operation) ? ['--action-file'] : []),
|
|
39
|
+
...(operation === 'check' ? ['--receipt-file', '--effect-id'] : []), ...(operation === 'revoke' ? ['--profile'] : [])];
|
|
39
40
|
for (let i = 0; i < rest.length; i += 2) {
|
|
40
41
|
if (!allowed.includes(rest[i]) || !rest[i + 1] || rest[i + 1].startsWith('--') || flags[rest[i]])
|
|
41
42
|
throw usageError('Invalid authorization option');
|
|
@@ -52,7 +53,10 @@ export async function authorizationCli(args, cwd = process.cwd()) {
|
|
|
52
53
|
throw usageError('--action-file is required');
|
|
53
54
|
const action = await jsonFile(resolve(cwd, flags['--action-file']));
|
|
54
55
|
if (operation === 'check') {
|
|
55
|
-
|
|
56
|
+
if (Boolean(flags['--receipt-file']) !== Boolean(flags['--effect-id']))
|
|
57
|
+
throw usageError('--receipt-file and --effect-id are required together');
|
|
58
|
+
const receipt = flags['--receipt-file'] ? { file: resolve(cwd, flags['--receipt-file']), effectId: flags['--effect-id'] } : undefined;
|
|
59
|
+
console.log(JSON.stringify(await checkHitlAuthorization(target, action, { receipt }), null, 2));
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
const loaded = await loadHitlLayers(target);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { DispatchHostThresholds } from './aiwg-config.js';
|
|
2
2
|
|
|
3
|
-
export const DEFAULT_DISPATCH_HOST_THRESHOLDS: Readonly<Required<
|
|
3
|
+
export const DEFAULT_DISPATCH_HOST_THRESHOLDS: Readonly<Required<DispatchHostThresholds>>;
|
|
4
4
|
export function resolveDispatchHostThresholds(
|
|
5
5
|
buildDispatch?: DispatchHostThresholds,
|
|
6
6
|
admissionHostResources?: DispatchHostThresholds,
|
|
7
7
|
overlay?: DispatchHostThresholds,
|
|
8
|
-
|
|
8
|
+
origins?: Record<string, string[]>,
|
|
9
|
+
): Required<DispatchHostThresholds>;
|
|
@@ -6,17 +6,22 @@ export const DEFAULT_DISPATCH_HOST_THRESHOLDS = Object.freeze({
|
|
|
6
6
|
max_mem_psi_avg60: 10,
|
|
7
7
|
// 08 brief/evidence retention: stop new admissions when less than 2 GiB free remains.
|
|
8
8
|
min_free_disk_gb: 2,
|
|
9
|
+
max_workers: 5,
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* Layers tighten defaults: minimums take MAX and maximums take MIN.
|
|
14
|
+
* Exception: the first configured max_workers replaces its default (even above 5);
|
|
15
|
+
* configured worker caps still take MIN across build, admission and task.
|
|
14
16
|
* Validate each layer before merging so an invalid value cannot be hidden.
|
|
15
17
|
*/
|
|
16
|
-
export function resolveDispatchHostThresholds(buildDispatch, admissionHostResources, overlay) {
|
|
18
|
+
export function resolveDispatchHostThresholds(buildDispatch, admissionHostResources, overlay, origins) {
|
|
17
19
|
const configured = { ...DEFAULT_DISPATCH_HOST_THRESHOLDS };
|
|
18
|
-
const keys =
|
|
19
|
-
|
|
20
|
+
const keys = Object.keys(DEFAULT_DISPATCH_HOST_THRESHOLDS);
|
|
21
|
+
let workerCapConfigured = false;
|
|
22
|
+
if (origins) for (const key of Object.keys(configured)) origins[key] = ['default'];
|
|
23
|
+
for (const [layer, origin] of [[buildDispatch, 'project:build.resource_preflight.dispatch'],
|
|
24
|
+
[admissionHostResources, 'project:parallelism.admission.hostResources'], [overlay, 'task']]) {
|
|
20
25
|
if (layer === undefined) continue;
|
|
21
26
|
if (layer === null || typeof layer !== 'object' || Array.isArray(layer)) {
|
|
22
27
|
throw new Error('OG_CONFIG_REFERENCE dispatch thresholds: must be an object');
|
|
@@ -30,8 +35,13 @@ export function resolveDispatchHostThresholds(buildDispatch, admissionHostResour
|
|
|
30
35
|
if (key === 'max_workers' && (!Number.isInteger(value) || value < 1)) {
|
|
31
36
|
throw new Error('OG_CONFIG_REFERENCE dispatch threshold max_workers: must be an integer >= 1 when set');
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
const previous = key === 'max_workers' && !workerCapConfigured ? undefined : configured[key];
|
|
39
|
+
if (key === 'max_workers') workerCapConfigured = true;
|
|
40
|
+
configured[key] = previous === undefined ? value
|
|
41
|
+
: key.startsWith('min_') ? Math.max(previous, value) : Math.min(previous, value);
|
|
42
|
+
if (origins && configured[key] === value) {
|
|
43
|
+
origins[key] = previous === value ? [...origins[key], origin] : [origin];
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
return { ...DEFAULT_DISPATCH_HOST_THRESHOLDS, ...configured };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Share legacy registry aliases between update planning and config persistence.
|
|
2
|
+
/**
|
|
3
|
+
* Maps framework registry IDs (e.g. 'sdlc-complete') to `aiwg use` names (e.g. 'sdlc').
|
|
4
|
+
*/
|
|
5
|
+
export const REGISTRY_ID_TO_USE_NAME = {
|
|
6
|
+
'sdlc-complete': 'sdlc',
|
|
7
|
+
'media-marketing-kit': 'marketing',
|
|
8
|
+
'media-curator': 'media-curator',
|
|
9
|
+
'research-complete': 'research',
|
|
10
|
+
'forensics-complete': 'forensics',
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=framework-aliases.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AiwgConfig, DispatchHostThresholds } from './aiwg-config.js';
|
|
2
|
+
import type { HostResourceSample, HostResourceReaders } from './host-resource-runtime.mjs';
|
|
3
|
+
export interface HostResourceCap { threshold: string; limit?: number | null; running?: number }
|
|
4
|
+
export interface HostResourceReport {
|
|
5
|
+
measured: HostResourceSample;
|
|
6
|
+
thresholds: DispatchHostThresholds | null;
|
|
7
|
+
origins: Record<string, string[]>;
|
|
8
|
+
slots: number;
|
|
9
|
+
ok: boolean;
|
|
10
|
+
limits: Array<{ threshold: string; slots: number }>;
|
|
11
|
+
failures: Array<{ signal: string; reason: string; actual?: number; threshold?: number }>;
|
|
12
|
+
counting?: string;
|
|
13
|
+
limitingThreshold?: string;
|
|
14
|
+
groups: Array<{ group: string; maxParallel: number | null; slots: number | null; reason: string }>;
|
|
15
|
+
}
|
|
16
|
+
export function hostResourceReport(input?: {
|
|
17
|
+
group?: string; config?: AiwgConfig; live?: HostResourceSample; readers?: HostResourceReaders; paths?: string[];
|
|
18
|
+
thresholdOverlay?: DispatchHostThresholds; caps?: HostResourceCap[];
|
|
19
|
+
}): HostResourceReport;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Normalize host measurements, tighten-only thresholds and remaining worker capacity.
|
|
2
|
+
import { getProviderParallelismDefaults } from './aiwg-config.js';
|
|
3
|
+
import { expandWorkerGroupTemplates } from './worker-group-templates.js';
|
|
4
|
+
import { resolveDispatchHostThresholds } from './dispatch-thresholds-runtime.mjs';
|
|
5
|
+
import { evaluateDispatchGate, readLiveHostResources } from './host-resource-runtime.mjs';
|
|
6
|
+
|
|
7
|
+
export function hostResourceReport({ config, live, readers, paths, thresholdOverlay, caps, group } = {}) {
|
|
8
|
+
const expansion = expandWorkerGroupTemplates(config?.parallelism);
|
|
9
|
+
if (expansion.errors.length) throw new Error(expansion.errors.join('; '));
|
|
10
|
+
const parallelism = expansion.parallelism;
|
|
11
|
+
const configured = parallelism?.groups ?? {};
|
|
12
|
+
if (group !== undefined && !Object.hasOwn(configured, group)) {
|
|
13
|
+
throw new Error(`Unknown group "${group}"; configured groups: ${Object.keys(configured).join(', ') || '(none)'}`);
|
|
14
|
+
}
|
|
15
|
+
const measured = live ?? readLiveHostResources({ ...readers, paths, groupNames: Object.keys(configured) });
|
|
16
|
+
const origins = {};
|
|
17
|
+
let thresholds;
|
|
18
|
+
try {
|
|
19
|
+
thresholds = resolveDispatchHostThresholds(config?.build?.resource_preflight?.dispatch,
|
|
20
|
+
config?.parallelism?.admission?.hostResources, thresholdOverlay, origins);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return { measured, thresholds: null, origins, slots: 0, ok: false, limits: [], groups: [],
|
|
23
|
+
failures: [{ signal: 'thresholds', reason: error.message }] };
|
|
24
|
+
}
|
|
25
|
+
const gate = evaluateDispatchGate(measured, thresholds);
|
|
26
|
+
const names = { 'avail-mem': 'min_avail_mem_gb', load: 'max_load_ratio',
|
|
27
|
+
'mem-psi-avg10': 'max_mem_psi_avg10', 'mem-psi-avg60': 'max_mem_psi_avg60',
|
|
28
|
+
'free-disk': 'min_free_disk_gb', workers: 'max_workers' };
|
|
29
|
+
const failures = gate.failures.map(failure => ({ ...failure, signal: names[failure.signal] ?? failure.signal }));
|
|
30
|
+
const limits = [];
|
|
31
|
+
const add = (threshold, available, reason) => {
|
|
32
|
+
const slots = Number.isFinite(available) ? Math.max(0, Math.floor(available)) : 0;
|
|
33
|
+
limits.push({ threshold, slots });
|
|
34
|
+
if (slots === 0) failures.push({ signal: threshold, reason });
|
|
35
|
+
};
|
|
36
|
+
// Floors act as conservative per-slot budgets; PSI is a binary pressure gate.
|
|
37
|
+
if (thresholds.min_avail_mem_gb > 0) add('min_avail_mem_gb', measured.availMemGb / thresholds.min_avail_mem_gb,
|
|
38
|
+
'insufficient available memory for another worker');
|
|
39
|
+
if (thresholds.min_free_disk_gb > 0) add('min_free_disk_gb', measured.freeDiskGb / thresholds.min_free_disk_gb,
|
|
40
|
+
'insufficient free disk for another worker');
|
|
41
|
+
add('max_load_ratio', thresholds.max_load_ratio * measured.cores - measured.load1,
|
|
42
|
+
'less than one core of load headroom');
|
|
43
|
+
if (thresholds.max_workers !== undefined) add('max_workers', thresholds.max_workers - measured.workers,
|
|
44
|
+
'running workers exhaust the host ceiling or cannot be counted');
|
|
45
|
+
const admission = [
|
|
46
|
+
{ threshold: 'max_parallel_subagents', limit: parallelism?.max_parallel_subagents
|
|
47
|
+
?? (parallelism?.worker_dispatch ? getProviderParallelismDefaults(config?.providers?.[0]).max_parallel_subagents : undefined) },
|
|
48
|
+
...(caps ?? []),
|
|
49
|
+
];
|
|
50
|
+
// Tuple-specific caps are supplied by the resolver, never inferred globally.
|
|
51
|
+
for (const { threshold, limit, running = measured.workers } of admission) {
|
|
52
|
+
if (limit !== undefined && limit !== null) add(threshold, limit - running,
|
|
53
|
+
'admission capacity exhausted or worker count unavailable');
|
|
54
|
+
}
|
|
55
|
+
const groups = Object.entries(configured).map(([id, settings]) => {
|
|
56
|
+
const unknown = measured.workers - Object.values(measured.workerGroups ?? {}).reduce((sum, count) => sum + count, 0);
|
|
57
|
+
const running = (measured.workerGroups?.[id] ?? 0) + unknown;
|
|
58
|
+
const candidates = [
|
|
59
|
+
{ threshold: `groups.${id}.maxParallel`, limit: settings.maxParallel },
|
|
60
|
+
{ threshold: `admission.groupCaps.${id}`, limit: parallelism?.admission?.groupCaps?.[id] },
|
|
61
|
+
].filter(entry => entry.limit !== undefined);
|
|
62
|
+
const capacities = candidates.map(entry => ({ ...entry,
|
|
63
|
+
slots: Number.isFinite(running) ? Math.max(0, entry.limit - running) : 0 }));
|
|
64
|
+
const binding = capacities.sort((a, b) => a.slots - b.slots)[0];
|
|
65
|
+
const disabled = settings.enabled === false;
|
|
66
|
+
const slots = disabled ? 0 : binding?.slots ?? null;
|
|
67
|
+
const threshold = disabled ? `groups.${id}.enabled` : binding?.threshold;
|
|
68
|
+
const reason = disabled ? 'group disabled' : slots === null ? 'no group ceiling configured'
|
|
69
|
+
: slots === 0 ? 'admission capacity exhausted or worker count unavailable' : 'remaining group capacity';
|
|
70
|
+
if (id === group && threshold) add(threshold, slots, reason);
|
|
71
|
+
return { group: id, maxParallel: settings.maxParallel ?? null, slots,
|
|
72
|
+
reason: threshold ? `${threshold}: ${reason}` : reason };
|
|
73
|
+
});
|
|
74
|
+
const slots = failures.length ? 0 : Math.min(...limits.map(limit => limit.slots));
|
|
75
|
+
const limitingThreshold = failures[0]?.signal ?? [...limits].sort((a, b) => a.slots - b.slots)[0]?.threshold;
|
|
76
|
+
return { measured, thresholds, origins, slots, ok: slots > 0, limits, failures, groups, limitingThreshold,
|
|
77
|
+
counting: 'current UID AIWG worker units plus distinct AIWG_WORKER_INVOCATION_ID markers outside those units; '
|
|
78
|
+
+ (measured.workerCountingSource === 'owned-process-fallback' ? 'systemd unavailable: owned-process fallback; ' : '')
|
|
79
|
+
+ 'hostCliProcesses: exact codex/muse/muse-bin comm, informational, not used for admission; group attribution uses unambiguous configured prefixes in existing invocation markers or unit names; unattributed workers count against every group; tuple caps without attribution use owned worker total' };
|
|
80
|
+
}
|