@aiwg/cli 2026.10.15 → 2026.10.18
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 +42 -11
- 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/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/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/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-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +5 -3
- package/dist/src/cli/handlers/regenerate.js +8 -16
- 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/sessions.js +7 -7
- 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 -1976
- 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/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +24 -0
- package/dist/src/config/host-resource-report.mjs +110 -0
- package/dist/src/config/host-resource-runtime.d.mts +37 -0
- package/dist/src/config/host-resource-runtime.mjs +296 -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/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/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/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- 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 +133 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/heldout.js +17 -7
- 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/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/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- 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/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/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/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +19 -0
- package/dist/src/providers/deployment-ownership.mjs +226 -0
- package/dist/src/providers/deployment-removal.js +200 -0
- 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/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 +19 -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/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +42 -4
- 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 +105 -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/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +52 -4
- package/dist/src/serve/mission-summary.js +56 -0
- 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 +39 -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/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +10 -11
- 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/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +13 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +24 -675
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +258 -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 +20 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/agents/providers/rule-projection.mjs +3 -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 +7 -4
- 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-termination.mjs +15 -8
- 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
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Mirror provider artifacts while retaining only evidenced native ownership.
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
const SIDECAR = '.aiwg-manifest.json';
|
|
4
|
+
const object = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
+
? value : {};
|
|
6
|
+
function receipt(bytes) {
|
|
7
|
+
try {
|
|
8
|
+
return object(JSON.parse(bytes?.toString() || '{}'));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function assertGrokUserMirrorPaths(projectPaths, userPaths) {
|
|
15
|
+
const fs = await import('node:fs/promises');
|
|
16
|
+
const statIfPresent = async (target) => {
|
|
17
|
+
try {
|
|
18
|
+
return await fs.lstat(target);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code === 'ENOENT')
|
|
22
|
+
return null;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const checkTarget = async (target) => {
|
|
27
|
+
const stat = await statIfPresent(target);
|
|
28
|
+
if (!stat)
|
|
29
|
+
return;
|
|
30
|
+
if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) {
|
|
31
|
+
throw new Error(`Refusing unsafe Grok Build user mirror target: ${target}`);
|
|
32
|
+
}
|
|
33
|
+
if (stat.isDirectory()) {
|
|
34
|
+
for (const name of await fs.readdir(target))
|
|
35
|
+
await checkTarget(path.join(target, name));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
for (const [destination, sources] of [
|
|
39
|
+
[userPaths.agents, [projectPaths.agents]],
|
|
40
|
+
[userPaths.skills, [projectPaths.skills, projectPaths.kernelSkills ?? '']],
|
|
41
|
+
]) {
|
|
42
|
+
if (!destination)
|
|
43
|
+
continue;
|
|
44
|
+
const rootStat = await statIfPresent(destination);
|
|
45
|
+
if (rootStat && (rootStat.isSymbolicLink() || !rootStat.isDirectory())) {
|
|
46
|
+
throw new Error(`Refusing unsafe Grok Build user mirror root: ${destination}`);
|
|
47
|
+
}
|
|
48
|
+
for (const source of sources) {
|
|
49
|
+
if (!source)
|
|
50
|
+
continue;
|
|
51
|
+
let names;
|
|
52
|
+
try {
|
|
53
|
+
names = await fs.readdir(source);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT')
|
|
57
|
+
continue;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
for (const name of names)
|
|
61
|
+
await checkTarget(path.join(destination, name));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Copy every directory or file under `src` into `dst` (creating `dst` if
|
|
67
|
+
* needed). Returns the count of top-level entries successfully copied and
|
|
68
|
+
* the entry names themselves — the names are needed by callers that record
|
|
69
|
+
* a per-framework manifest at user scope so `aiwg remove --scope user` can
|
|
70
|
+
* delete only what this deploy created.
|
|
71
|
+
*
|
|
72
|
+
* Used by the user-scope mirror to cover both directory-style artifacts
|
|
73
|
+
* (skills, agents) and file-style artifacts (commands, rules in some
|
|
74
|
+
* providers). Failures on individual entries are swallowed so a single bad
|
|
75
|
+
* entry doesn't fail the whole mirror.
|
|
76
|
+
*/
|
|
77
|
+
export async function mirrorArtifactDir(src, dst, ownedThisCall = new Set()) {
|
|
78
|
+
if (!src || !dst)
|
|
79
|
+
return { count: 0, targetDir: dst, entries: [] };
|
|
80
|
+
const fs = await import('node:fs/promises');
|
|
81
|
+
let dirents;
|
|
82
|
+
try {
|
|
83
|
+
dirents = await fs.readdir(src, { withFileTypes: true });
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return { count: 0, targetDir: dst, entries: [] };
|
|
87
|
+
}
|
|
88
|
+
// Some providers already deploy kernel skills to an absolute user-level
|
|
89
|
+
// path. Inventory that source for registry accounting instead of trying to
|
|
90
|
+
// recursively copy each entry onto itself.
|
|
91
|
+
if (path.resolve(src) === path.resolve(dst)) {
|
|
92
|
+
const entries = [];
|
|
93
|
+
for (const entry of dirents) {
|
|
94
|
+
if ((entry.isDirectory() || entry.isFile()) && await isAiwgManagedEntry(path.join(dst, entry.name), entry.isDirectory())) {
|
|
95
|
+
entries.push(entry.name);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { count: entries.length, targetDir: dst, entries };
|
|
99
|
+
}
|
|
100
|
+
const { captureDeploymentOutputs, recordDeploymentOutputs } = await import('../providers/deployment-ownership.mjs');
|
|
101
|
+
const before = captureDeploymentOutputs([dst]);
|
|
102
|
+
const sourceReceipt = receipt(await fs.readFile(path.join(src, SIDECAR)).catch(() => undefined));
|
|
103
|
+
const copiedRecords = {};
|
|
104
|
+
await fs.mkdir(dst, { recursive: true });
|
|
105
|
+
let count = 0;
|
|
106
|
+
const entries = [];
|
|
107
|
+
for (const entry of dirents) {
|
|
108
|
+
if (entry.name === SIDECAR)
|
|
109
|
+
continue;
|
|
110
|
+
const s = path.join(src, entry.name);
|
|
111
|
+
const d = path.join(dst, entry.name);
|
|
112
|
+
try {
|
|
113
|
+
// User-scope directories are shared with operator-created artifacts.
|
|
114
|
+
// A same-named unmanaged entry belongs to the operator, even when a
|
|
115
|
+
// project has an AIWG-managed source with that name.
|
|
116
|
+
try {
|
|
117
|
+
const existing = await fs.lstat(d);
|
|
118
|
+
if (!ownedThisCall.has(entry.name) && !await isAiwgManagedEntry(d, existing.isDirectory()))
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error.code !== 'ENOENT')
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (entry.isDirectory()) {
|
|
126
|
+
await fs.cp(s, d, { recursive: true, force: true });
|
|
127
|
+
}
|
|
128
|
+
else if (entry.isFile()) {
|
|
129
|
+
await fs.copyFile(s, d);
|
|
130
|
+
if (sourceReceipt.managed?.[entry.name])
|
|
131
|
+
copiedRecords[entry.name] = sourceReceipt.managed[entry.name];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
count++;
|
|
137
|
+
entries.push(entry.name);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// ignore individual failures
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (Object.keys(copiedRecords).length) {
|
|
144
|
+
const sidecarPath = path.resolve(dst, SIDECAR);
|
|
145
|
+
const prior = receipt(before.get(sidecarPath));
|
|
146
|
+
const next = { ...prior, managed: { ...object(prior.managed), ...copiedRecords } };
|
|
147
|
+
await fs.writeFile(sidecarPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
148
|
+
}
|
|
149
|
+
// Copied skill sidecars retain their directory-local shape. The same merge
|
|
150
|
+
// handles flat files, and never adopts an unrecorded legacy/operator file.
|
|
151
|
+
recordDeploymentOutputs(before, [dst], { onlyDeclared: true });
|
|
152
|
+
return { count, targetDir: dst, entries };
|
|
153
|
+
}
|
|
154
|
+
async function isAiwgManagedEntry(target, directory) {
|
|
155
|
+
const fs = await import('node:fs/promises');
|
|
156
|
+
if (directory) {
|
|
157
|
+
try {
|
|
158
|
+
const marker = await fs.readFile(path.join(target, '.aiwg-managed'), 'utf8');
|
|
159
|
+
if (marker.trim() === 'aiwg')
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch { /* legacy deployed skill may use an inline marker */ }
|
|
163
|
+
}
|
|
164
|
+
const markerFile = directory ? path.join(target, 'SKILL.md') : target;
|
|
165
|
+
try {
|
|
166
|
+
const text = await fs.readFile(markerFile, 'utf8');
|
|
167
|
+
return /(?:#|<!--) aiwg:managed v[^\s]+ [^\r\n]+/.test(text.slice(0, 2048));
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=user-scope-mirror.js.map
|
|
@@ -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,23 @@ 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,
|
|
10
|
+
max_snapshot_age_seconds: 300,
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* Layers tighten defaults: minimums take MAX and maximums take MIN.
|
|
15
|
+
* Exception: the first configured max_workers replaces its default (even above 5);
|
|
16
|
+
* configured worker caps still take MIN across build, admission and task.
|
|
14
17
|
* Validate each layer before merging so an invalid value cannot be hidden.
|
|
15
18
|
*/
|
|
16
|
-
export function resolveDispatchHostThresholds(buildDispatch, admissionHostResources, overlay) {
|
|
19
|
+
export function resolveDispatchHostThresholds(buildDispatch, admissionHostResources, overlay, origins) {
|
|
17
20
|
const configured = { ...DEFAULT_DISPATCH_HOST_THRESHOLDS };
|
|
18
|
-
const keys =
|
|
19
|
-
|
|
21
|
+
const keys = Object.keys(DEFAULT_DISPATCH_HOST_THRESHOLDS);
|
|
22
|
+
let workerCapConfigured = false;
|
|
23
|
+
if (origins) for (const key of Object.keys(configured)) origins[key] = ['default'];
|
|
24
|
+
for (const [layer, origin] of [[buildDispatch, 'project:build.resource_preflight.dispatch'],
|
|
25
|
+
[admissionHostResources, 'project:parallelism.admission.hostResources'], [overlay, 'task']]) {
|
|
20
26
|
if (layer === undefined) continue;
|
|
21
27
|
if (layer === null || typeof layer !== 'object' || Array.isArray(layer)) {
|
|
22
28
|
throw new Error('OG_CONFIG_REFERENCE dispatch thresholds: must be an object');
|
|
@@ -27,11 +33,19 @@ export function resolveDispatchHostThresholds(buildDispatch, admissionHostResour
|
|
|
27
33
|
if (!Number.isFinite(value) || value < 0) {
|
|
28
34
|
throw new Error(`OG_CONFIG_REFERENCE dispatch threshold ${key}: must be a non-negative number`);
|
|
29
35
|
}
|
|
36
|
+
if (key === 'max_snapshot_age_seconds' && value <= 0) {
|
|
37
|
+
throw new Error('OG_CONFIG_REFERENCE dispatch threshold max_snapshot_age_seconds: must be a positive number');
|
|
38
|
+
}
|
|
30
39
|
if (key === 'max_workers' && (!Number.isInteger(value) || value < 1)) {
|
|
31
40
|
throw new Error('OG_CONFIG_REFERENCE dispatch threshold max_workers: must be an integer >= 1 when set');
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const previous = key === 'max_workers' && !workerCapConfigured ? undefined : configured[key];
|
|
43
|
+
if (key === 'max_workers') workerCapConfigured = true;
|
|
44
|
+
configured[key] = previous === undefined ? value
|
|
45
|
+
: key.startsWith('min_') ? Math.max(previous, value) : Math.min(previous, value);
|
|
46
|
+
if (origins && configured[key] === value) {
|
|
47
|
+
origins[key] = previous === value ? [...origins[key], origin] : [origin];
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
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,24 @@
|
|
|
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
|
+
freshness: {
|
|
7
|
+
collectedAt: string | null; evaluatedAt: string | null; ageMs: number | null; maxAgeMs: number;
|
|
8
|
+
status: 'fresh' | 'stale' | 'unavailable'; reason?: string;
|
|
9
|
+
};
|
|
10
|
+
thresholds: DispatchHostThresholds | null;
|
|
11
|
+
origins: Record<string, string[]>;
|
|
12
|
+
slots: number;
|
|
13
|
+
ok: boolean;
|
|
14
|
+
limits: Array<{ threshold: string; slots: number }>;
|
|
15
|
+
failures: Array<{ signal: string; reason: string; actual?: number; threshold?: number }>;
|
|
16
|
+
counting?: string;
|
|
17
|
+
limitingThreshold?: string;
|
|
18
|
+
groups: Array<{ group: string; maxParallel: number | null; slots: number | null; reason: string }>;
|
|
19
|
+
}
|
|
20
|
+
export function hostResourceReport(input?: {
|
|
21
|
+
group?: string; config?: AiwgConfig; live?: HostResourceSample; readers?: HostResourceReaders; paths?: string[];
|
|
22
|
+
thresholdOverlay?: DispatchHostThresholds; caps?: HostResourceCap[];
|
|
23
|
+
now?: () => number;
|
|
24
|
+
}): HostResourceReport;
|
|
@@ -0,0 +1,110 @@
|
|
|
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 { DEFAULT_DISPATCH_HOST_THRESHOLDS, resolveDispatchHostThresholds } from './dispatch-thresholds-runtime.mjs';
|
|
5
|
+
import { evaluateDispatchGate, readLiveHostResources } from './host-resource-runtime.mjs';
|
|
6
|
+
|
|
7
|
+
// Re-evaluate persisted/remote collection times; never stamp them with the read time.
|
|
8
|
+
function snapshotFreshness(measured, evaluated, maxSnapshotAgeSeconds) {
|
|
9
|
+
const collected = Date.parse(measured.collectedAt);
|
|
10
|
+
const ageMs = evaluated - collected;
|
|
11
|
+
const maxAgeMs = maxSnapshotAgeSeconds * 1000;
|
|
12
|
+
const result = { collectedAt: Number.isFinite(collected) ? new Date(collected).toISOString() : null,
|
|
13
|
+
evaluatedAt: Number.isFinite(evaluated) ? new Date(evaluated).toISOString() : null,
|
|
14
|
+
ageMs: Number.isFinite(ageMs) ? ageMs : null, maxAgeMs, status: 'fresh' };
|
|
15
|
+
if (!Number.isFinite(ageMs)) {
|
|
16
|
+
result.status = 'unavailable'; result.reason = 'collection time or evaluation clock missing or invalid';
|
|
17
|
+
} else if (ageMs < 0) {
|
|
18
|
+
result.status = 'unavailable'; result.reason = 'collection time is in the future';
|
|
19
|
+
} else if (ageMs > maxAgeMs) {
|
|
20
|
+
result.status = 'stale'; result.reason = `resource snapshot age ${ageMs}ms exceeds ${maxAgeMs}ms`;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function hostResourceReport({ config, live, readers, paths, thresholdOverlay, caps, group, now = readers?.now ?? Date.now } = {}) {
|
|
26
|
+
const expansion = expandWorkerGroupTemplates(config?.parallelism);
|
|
27
|
+
if (expansion.errors.length) throw new Error(expansion.errors.join('; '));
|
|
28
|
+
const parallelism = expansion.parallelism;
|
|
29
|
+
const configured = parallelism?.groups ?? {};
|
|
30
|
+
if (group !== undefined && !Object.hasOwn(configured, group)) {
|
|
31
|
+
throw new Error(`Unknown group "${group}"; configured groups: ${Object.keys(configured).join(', ') || '(none)'}`);
|
|
32
|
+
}
|
|
33
|
+
// Local collection and evaluation share one clock; supplied snapshots retain their source time.
|
|
34
|
+
const measured = live ?? readLiveHostResources({ ...readers, now, paths, groupNames: Object.keys(configured) });
|
|
35
|
+
const evaluated = now();
|
|
36
|
+
const origins = {};
|
|
37
|
+
let thresholds;
|
|
38
|
+
try {
|
|
39
|
+
thresholds = resolveDispatchHostThresholds(config?.build?.resource_preflight?.dispatch,
|
|
40
|
+
config?.parallelism?.admission?.hostResources, thresholdOverlay, origins);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const snapshot = snapshotFreshness(measured, evaluated, DEFAULT_DISPATCH_HOST_THRESHOLDS.max_snapshot_age_seconds);
|
|
43
|
+
return { measured, freshness: snapshot, thresholds: null, origins, slots: 0, ok: false, limits: [], groups: [],
|
|
44
|
+
failures: [{ signal: 'thresholds', reason: error.message }] };
|
|
45
|
+
}
|
|
46
|
+
const snapshot = snapshotFreshness(measured, evaluated, thresholds.max_snapshot_age_seconds);
|
|
47
|
+
const gate = evaluateDispatchGate(measured, thresholds);
|
|
48
|
+
if (!Number.isFinite(measured.load1) || !Number.isFinite(measured.cores) || measured.cores <= 0) {
|
|
49
|
+
gate.failures.push({ signal: 'load', reason: 'load headroom requires detectable load1 and positive cores' });
|
|
50
|
+
}
|
|
51
|
+
const names = { 'avail-mem': 'min_avail_mem_gb', load: 'max_load_ratio',
|
|
52
|
+
'mem-psi-avg10': 'max_mem_psi_avg10', 'mem-psi-avg60': 'max_mem_psi_avg60',
|
|
53
|
+
'free-disk': 'min_free_disk_gb', workers: 'max_workers' };
|
|
54
|
+
const failures = gate.failures.map(failure => ({ ...failure, signal: names[failure.signal] ?? failure.signal,
|
|
55
|
+
reason: failure.actual === undefined ? `unavailable: ${failure.reason}` : failure.reason }));
|
|
56
|
+
if (snapshot.status !== 'fresh') failures.unshift({ signal: 'snapshot', reason: `${snapshot.status}: ${snapshot.reason}` });
|
|
57
|
+
else if (failures.some(failure => failure.reason.startsWith('unavailable:'))) {
|
|
58
|
+
snapshot.status = 'unavailable'; snapshot.reason = 'required host signals unavailable';
|
|
59
|
+
}
|
|
60
|
+
const limits = [];
|
|
61
|
+
const add = (threshold, available, reason) => {
|
|
62
|
+
const slots = Number.isFinite(available) ? Math.max(0, Math.floor(available)) : 0;
|
|
63
|
+
limits.push({ threshold, slots });
|
|
64
|
+
if (slots === 0) failures.push({ signal: threshold, reason });
|
|
65
|
+
};
|
|
66
|
+
// Floors act as conservative per-slot budgets; PSI is a binary pressure gate.
|
|
67
|
+
if (thresholds.min_avail_mem_gb > 0) add('min_avail_mem_gb', measured.availMemGb / thresholds.min_avail_mem_gb,
|
|
68
|
+
'insufficient available memory for another worker');
|
|
69
|
+
if (thresholds.min_free_disk_gb > 0) add('min_free_disk_gb', measured.freeDiskGb / thresholds.min_free_disk_gb,
|
|
70
|
+
'insufficient free disk for another worker');
|
|
71
|
+
add('max_load_ratio', thresholds.max_load_ratio * measured.cores - measured.load1,
|
|
72
|
+
'less than one core of load headroom');
|
|
73
|
+
if (thresholds.max_workers !== undefined) add('max_workers', thresholds.max_workers - measured.workers,
|
|
74
|
+
'running workers exhaust the host ceiling or cannot be counted');
|
|
75
|
+
const admission = [
|
|
76
|
+
{ threshold: 'max_parallel_subagents', limit: parallelism?.max_parallel_subagents
|
|
77
|
+
?? (parallelism?.worker_dispatch ? getProviderParallelismDefaults(config?.providers?.[0]).max_parallel_subagents : undefined) },
|
|
78
|
+
...(caps ?? []),
|
|
79
|
+
];
|
|
80
|
+
// Tuple-specific caps are supplied by the resolver, never inferred globally.
|
|
81
|
+
for (const { threshold, limit, running = measured.workers } of admission) {
|
|
82
|
+
if (limit !== undefined && limit !== null) add(threshold, limit - running,
|
|
83
|
+
'admission capacity exhausted or worker count unavailable');
|
|
84
|
+
}
|
|
85
|
+
const groups = Object.entries(configured).map(([id, settings]) => {
|
|
86
|
+
const unknown = measured.workers - Object.values(measured.workerGroups ?? {}).reduce((sum, count) => sum + count, 0);
|
|
87
|
+
const running = (measured.workerGroups?.[id] ?? 0) + unknown;
|
|
88
|
+
const candidates = [
|
|
89
|
+
{ threshold: `groups.${id}.maxParallel`, limit: settings.maxParallel },
|
|
90
|
+
{ threshold: `admission.groupCaps.${id}`, limit: parallelism?.admission?.groupCaps?.[id] },
|
|
91
|
+
].filter(entry => entry.limit !== undefined);
|
|
92
|
+
const capacities = candidates.map(entry => ({ ...entry,
|
|
93
|
+
slots: Number.isFinite(running) ? Math.max(0, entry.limit - running) : 0 }));
|
|
94
|
+
const binding = capacities.sort((a, b) => a.slots - b.slots)[0];
|
|
95
|
+
const disabled = settings.enabled === false;
|
|
96
|
+
const slots = disabled ? 0 : binding?.slots ?? null;
|
|
97
|
+
const threshold = disabled ? `groups.${id}.enabled` : binding?.threshold;
|
|
98
|
+
const reason = disabled ? 'group disabled' : slots === null ? 'no group ceiling configured'
|
|
99
|
+
: slots === 0 ? 'admission capacity exhausted or worker count unavailable' : 'remaining group capacity';
|
|
100
|
+
if (id === group && threshold) add(threshold, slots, reason);
|
|
101
|
+
return { group: id, maxParallel: settings.maxParallel ?? null, slots,
|
|
102
|
+
reason: threshold ? `${threshold}: ${reason}` : reason };
|
|
103
|
+
});
|
|
104
|
+
const slots = failures.length ? 0 : Math.min(...limits.map(limit => limit.slots));
|
|
105
|
+
const limitingThreshold = failures[0]?.signal ?? [...limits].sort((a, b) => a.slots - b.slots)[0]?.threshold;
|
|
106
|
+
return { measured, freshness: snapshot, thresholds, origins, slots, ok: slots > 0, limits, failures, groups, limitingThreshold,
|
|
107
|
+
counting: 'current UID AIWG worker units plus distinct AIWG_WORKER_INVOCATION_ID markers outside those units; '
|
|
108
|
+
+ (measured.workerCountingSource === 'owned-process-fallback' ? 'systemd unavailable: owned-process fallback; ' : '')
|
|
109
|
+
+ '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' };
|
|
110
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface HostResourceSample {
|
|
2
|
+
/** Start of collection on the source host; absent on legacy/unavailable snapshots. */
|
|
3
|
+
collectedAt?: string;
|
|
4
|
+
supported: boolean; reason?: string; availMemGb?: number; load1?: number; cores?: number;
|
|
5
|
+
loadRatio?: number; memPsiAvg10?: number; memPsiAvg60?: number; memPsiAvg300?: number;
|
|
6
|
+
workerGroups?: Record<string, number>;
|
|
7
|
+
workers?: number; hostCliProcesses?: Record<string, number>; workerUnits?: number; freeDiskGb?: number;
|
|
8
|
+
workerCountingSource?: 'systemd-units-and-marked-processes' | 'owned-process-fallback';
|
|
9
|
+
}
|
|
10
|
+
export interface WorkerCensus {
|
|
11
|
+
byGroup?: Record<string, number>;
|
|
12
|
+
total: number; hostCliProcesses?: Record<string, number>; units?: number;
|
|
13
|
+
source?: HostResourceSample['workerCountingSource'];
|
|
14
|
+
}
|
|
15
|
+
export interface HostResourceReaders {
|
|
16
|
+
now?: () => number;
|
|
17
|
+
readText?: (path: string) => string;
|
|
18
|
+
readDir?: (path: string) => string[];
|
|
19
|
+
uid?: number;
|
|
20
|
+
groupNames?: string[];
|
|
21
|
+
coreCount?: () => number;
|
|
22
|
+
countWorkers?: () => number | undefined | WorkerCensus;
|
|
23
|
+
countWorkerUnits?: () => number | undefined;
|
|
24
|
+
listWorkerUnits?: () => string[] | undefined;
|
|
25
|
+
statfs?: () => { bavail: number | bigint; bsize: number | bigint };
|
|
26
|
+
statfsPath?: (path: string) => { bavail: number | bigint; bsize: number | bigint };
|
|
27
|
+
paths?: string[];
|
|
28
|
+
}
|
|
29
|
+
export function readLiveHostResources(readers?: HostResourceReaders): HostResourceSample;
|
|
30
|
+
export function countWorkerProcesses(readers?: HostResourceReaders): WorkerCensus | undefined;
|
|
31
|
+
export function defaultCountWorkers(readers?: HostResourceReaders): number | undefined;
|
|
32
|
+
export function countWorkerUnits(options?: { spawn?: (...args: any[]) => any }): number | undefined;
|
|
33
|
+
export function listWorkerUnits(options?: { spawn?: (...args: any[]) => any }): string[] | undefined;
|
|
34
|
+
export function parseMemAvailableGb(text: unknown): number | undefined;
|
|
35
|
+
export function parseMemoryPsi(text: unknown): { avg10: number; avg60: number; avg300: number } | null;
|
|
36
|
+
export function parseLoadAverages(text: unknown): { load1: number; load5: number; load15: number } | null;
|
|
37
|
+
export function evaluateDispatchGate(live: HostResourceSample, thresholds: any): { ok: boolean; failures: any[]; thresholds: any };
|