@aiwg/cli 2026.11.3 → 2026.11.5
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/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +3 -2
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +12 -9
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +2 -0
- package/agentic/code/addons/composition-engine/lib/runtime.mjs +5 -26
- package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +22 -0
- package/agentic/code/providers/capability-matrix.yaml +85 -18
- package/agentic/code/providers/model-capabilities.v1.json +35 -27
- package/dist/src/a2a/hitl-authorization.js +46 -0
- package/dist/src/a2a/hitl-driver.js +5 -5
- package/dist/src/artifacts/browser-export.js +2 -0
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +9 -27
- package/dist/src/artifacts/index-capability.js +24 -0
- package/dist/src/artifacts/query-engine-discover-output.js +8 -3
- package/dist/src/artifacts/query-engine-rules.js +29 -11
- package/dist/src/artifacts/query-engine-scoring.js +5 -5
- package/dist/src/artifacts/query-engine-show-card.js +5 -1
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +3 -3
- package/dist/src/artifacts/query-engine-templates.js +10 -4
- package/dist/src/artifacts/query-engine-verbose.js +18 -4
- package/dist/src/artifacts/relations-builder.js +1 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/checkpoint-handoff.js +2 -1
- package/dist/src/cli/handlers/guided-setup.js +3 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +17 -5
- package/dist/src/cli/handlers/rules.js +1 -1
- package/dist/src/cli/handlers/script-runner.js +7 -4
- package/dist/src/cli/handlers/sessions.js +1 -1
- package/dist/src/cli/handlers/steward-format.js +12 -0
- package/dist/src/cli/handlers/steward.js +1 -1
- package/dist/src/cli/handlers/use.js +14 -6
- package/dist/src/cli/handlers/utility-doctor.js +9 -2
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/services/deployment-probe-scope.js +40 -0
- package/dist/src/cli/services/deployment-verification.js +4 -5
- package/dist/src/config/aiwg-config.js +6 -0
- package/dist/src/config/authorization-cli.js +61 -3
- package/dist/src/config/cli-help.js +1 -1
- package/dist/src/config/cli.js +4 -2
- package/dist/src/config/host-resource-runtime.mjs +1 -1
- package/dist/src/config/user-registry.js +9 -1
- package/dist/src/config/worker-owner-lock.js +90 -10
- package/dist/src/decision/graph-flow-adapter.js +1 -1
- package/dist/src/effects/authorization-grant.js +50 -0
- package/dist/src/effects/authorization-store.js +130 -0
- package/dist/src/effects/index.js +2 -0
- package/dist/src/effects/ledger.js +1 -0
- package/dist/src/effects/lifecycle.js +1 -1
- package/dist/src/effects/reader.js +4 -0
- package/dist/src/effects/records.js +4 -0
- package/dist/src/effects/schema.js +2 -0
- package/dist/src/extensions/claude-hooks-installer.js +7 -7
- package/dist/src/extensions/manifest.js +6 -0
- package/dist/src/extensions/muse-managed-hooks.js +11 -0
- package/dist/src/extensions/project-local-discovery.js +21 -1
- package/dist/src/extensions/project-local-scaffold.js +19 -7
- package/dist/src/extensions/user-hook-diagnostics.js +32 -0
- package/dist/src/extensions/verified-hook-command.js +32 -0
- package/dist/src/lint/rule-conflicts.js +52 -0
- package/dist/src/lint/runner.js +3 -0
- package/dist/src/mcp/cli.mjs +3 -1
- package/dist/src/mcp/elicitation.mjs +30 -0
- package/dist/src/mcp/grok-build-config.mjs +1 -1
- package/dist/src/mcp/muse-native-config.mjs +1 -0
- package/dist/src/mcp/server.mjs +2 -0
- package/dist/src/mcp/tools/authorization.mjs +78 -0
- package/dist/src/models/factory-models.js +144 -0
- package/dist/src/models/model-capabilities.v1.json +35 -27
- package/dist/src/models/model-discovery.js +7 -3
- package/dist/src/models/worker-installation.d.mts +2 -0
- package/dist/src/models/worker-installation.mjs +11 -2
- package/dist/src/models/worker-invocation-policy.js +25 -1
- package/dist/src/models/wrapper-enforcement.js +1 -1
- package/dist/src/policy/authorization-capture.js +64 -0
- package/dist/src/policy/authorization-operations.js +108 -0
- package/dist/src/policy/hitl-check.js +3 -2
- package/dist/src/policy/hitl-consume.js +14 -0
- package/dist/src/policy/hitl-durable-store.js +60 -0
- package/dist/src/policy/hitl-durable.js +60 -0
- package/dist/src/policy/hitl-receipt.js +5 -0
- package/dist/src/policy/hitl.js +44 -6
- package/dist/src/policy/repo-access.js +3 -1
- package/dist/src/process/bounded-child-process.mjs +49 -39
- package/dist/src/providers/capability-matrix.yaml +85 -18
- package/dist/src/providers/deployment-ownership.d.mts +1 -0
- package/dist/src/providers/deployment-ownership.mjs +29 -3
- package/dist/src/providers/deployment-preservation.mjs +44 -3
- package/dist/src/providers/grok-build-acp.js +13 -5
- package/dist/src/providers/grok-build-dispatch.js +35 -2
- package/dist/src/providers/grok-build-headless.js +171 -77
- package/dist/src/providers/grok-build-inspect.js +1 -0
- package/dist/src/providers/grok-build-paths.js +2 -0
- package/dist/src/providers/muse-paths.js +4 -2
- package/dist/src/providers/provider-context-contracts.js +12 -4
- package/dist/src/providers/provider-definition-schema.js +6 -0
- package/dist/src/providers/provider-seeds-1.js +3 -3
- package/dist/src/providers/provider-seeds-2.js +6 -4
- package/dist/src/providers/provider-seeds-3.js +6 -6
- package/dist/src/rules/activation.d.mts +2 -0
- package/dist/src/rules/activation.mjs +16 -7
- package/dist/src/rules/inline-budget.d.mts +2 -1
- package/dist/src/rules/inline-budget.mjs +4 -2
- package/dist/src/rules/inventory.js +3 -0
- package/dist/src/rules/precedence.d.mts +6 -0
- package/dist/src/rules/precedence.mjs +49 -0
- package/dist/src/rules/project-precedence.js +73 -0
- package/dist/src/rules/rule-frontmatter.schema.json +15 -0
- package/dist/src/serve/a2a-terminal-observer.js +12 -3
- package/dist/src/serve/mission-hitl.js +20 -1
- package/dist/src/serve/worker-stdin-frame.mjs +1 -1
- package/dist/src/sessions/adapters/grok-build-fallback.js +33 -0
- package/dist/src/sessions/adapters/grok-build-native-records.js +134 -0
- package/dist/src/sessions/adapters/grok-build-native.js +237 -98
- package/dist/src/sessions/adapters/grok-build.js +95 -32
- package/dist/src/sessions/grok-build-cli-output.js +113 -0
- package/dist/src/sessions/grok-build-cli.js +4 -28
- package/dist/src/sessions/normalization.js +1 -1
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +4 -3
- package/dist/src/smiths/context-pipeline/finalization.js +5 -0
- package/dist/src/smiths/context-pipeline/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +20 -17
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +6 -1
- package/dist/src/smiths/context-pipeline/workspace-document.js +6 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -12
- package/dist/src/smiths/hook-bridge/codex-translator.js +11 -14
- package/dist/src/smiths/hook-bridge/codex-trust.js +7 -2
- package/dist/src/smiths/hook-bridge/copilot-translator.js +2 -1
- package/dist/src/smiths/hook-bridge/factory-trust.js +2 -2
- package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +81 -0
- package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
- package/dist/src/smiths/hook-bridge/hermes-trust.js +65 -0
- package/dist/src/smiths/hook-bridge/index.js +3 -1
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +3 -2
- package/package.json +7 -1
- package/tools/agents/deploy-agents.mjs +9 -8
- package/tools/agents/deploy-options.mjs +3 -0
- package/tools/agents/providers/base-frontmatter.mjs +3 -2
- package/tools/agents/providers/base-inventory.mjs +3 -1
- package/tools/agents/providers/base-kernel-skills.mjs +11 -5
- package/tools/agents/providers/claude-post-deploy.mjs +1 -1
- package/tools/agents/providers/codex-post-deploy.mjs +1 -1
- package/tools/agents/providers/generic.mjs +66 -0
- package/tools/agents/providers/grok-build.mjs +34 -41
- package/tools/agents/providers/model-wrapper.mjs +2 -5
- package/tools/agents/providers/muse-hooks.mjs +13 -11
- package/tools/agents/providers/muse-prompt-discovery.mjs +5 -1
- package/tools/agents/providers/muse.mjs +2 -1
- package/tools/agents/providers/openclaw.mjs +2 -1
- package/tools/agents/providers/rule-deployment-commit.mjs +3 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +7 -5
- package/tools/agents/providers/rule-deployment-state.mjs +14 -6
- package/tools/agents/providers/rule-projection.mjs +39 -4
- package/tools/agents/providers/rule-startup.mjs +11 -10
- package/tools/agents/providers/skill-copy-prune.mjs +12 -0
- package/tools/agents/providers/staged-directory-reference.mjs +14 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +24 -10
- package/tools/agents/providers/user-hooks.mjs +26 -0
- package/tools/cli/authorization-health.mjs +20 -0
- package/tools/cli/workspace-status.mjs +7 -0
- package/tools/commands/deploy-prompts-codex.mjs +15 -1
- package/tools/ralph-external/lib/claude-adapter.mjs +2 -0
- package/tools/ralph-external/lib/factory-adapter.mjs +6 -2
- package/tools/ralph-external/lib/worker-inputs.mjs +20 -1
- package/tools/ralph-external/lib/worker-isolation.mjs +1 -0
- package/tools/ralph-external/lib/worker-termination.mjs +21 -12
- package/tools/ralph-external/session-launcher.mjs +22 -17
- package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
|
@@ -916,7 +916,7 @@ async function importSource(ctx, args) {
|
|
|
916
916
|
: isGrokbot
|
|
917
917
|
? new GrokbotSessionAdapter(limits)
|
|
918
918
|
: isGrokBuild
|
|
919
|
-
? new GrokBuildSessionAdapter(limits)
|
|
919
|
+
? new GrokBuildSessionAdapter(limits, undefined, { cwd: ctx.cwd, binary: args.values.get('--grok-bin') })
|
|
920
920
|
: isMuse
|
|
921
921
|
? new MuseSessionAdapter(limits)
|
|
922
922
|
: isPi
|
|
@@ -62,6 +62,18 @@ export function formatProvider(id, provider, matrix, meta) {
|
|
|
62
62
|
lines.push(` Status: ${provider.status}`);
|
|
63
63
|
lines.push(` Daemon: ${provider.daemon_tier}${provider.daemon_pty_adapter ? ' (+ pty-adapter)' : ''}`);
|
|
64
64
|
lines.push(` ${'─'.repeat(60)}`);
|
|
65
|
+
if (provider.byok) {
|
|
66
|
+
const byok = provider.byok;
|
|
67
|
+
lines.push(`\n Bring your own key (BYOK): ${byok.status}`);
|
|
68
|
+
for (const setting of byok.settings)
|
|
69
|
+
lines.push(` ${setting}`);
|
|
70
|
+
lines.push(` Verify: ${byok.verification}`);
|
|
71
|
+
lines.push(` ${byok.notes}`);
|
|
72
|
+
lines.push(' Security: aiwg show rule token-security --body; environment or secret-store command only.');
|
|
73
|
+
lines.push(' Never place keys on argv, in deployed AIWG files, harness config, logs or receipts; never print keys.');
|
|
74
|
+
lines.push(" Spend: BYOK runs bill the user's key; paid runs need explicit operator approval.");
|
|
75
|
+
lines.push(` Docs: ${byok.docs}`);
|
|
76
|
+
}
|
|
65
77
|
const featureKeys = Object.keys(matrix.features);
|
|
66
78
|
for (const featureId of featureKeys) {
|
|
67
79
|
const isNative = provider.native_features?.[featureId] === true;
|
|
@@ -111,7 +111,7 @@ async function handleSteward(args, ctx) {
|
|
|
111
111
|
aiwg steward models --route --capability-type <agent|skill|rule|workflow>
|
|
112
112
|
--capability <id> --assignment <text> [--provider <name>] [--json]
|
|
113
113
|
Emit a capability-bound wrapper launch envelope
|
|
114
|
-
aiwg steward authorization
|
|
114
|
+
aiwg steward authorization HITL policy and grants: inspect/validate/preview/enable/revoke/list/show/search/explain/verify
|
|
115
115
|
aiwg steward permissions audit Find normalized-model errors and legacy grants
|
|
116
116
|
aiwg steward permissions migrate --dry-run Preview legacy permission normalization
|
|
117
117
|
aiwg steward permissions migrate --apply Back up and atomically normalize config
|
|
@@ -2,6 +2,7 @@ import { ContextWriteJournal } from '../../smiths/context-pipeline/context-file-
|
|
|
2
2
|
import { trackTemporaryDirectory } from '../../utils/temporary-directory.js';
|
|
3
3
|
import { codexHookTrustNextStep, readCodexHookTrust } from '../../smiths/hook-bridge/codex-trust.js';
|
|
4
4
|
import { factoryHookTrustNextStep, readFactoryHookTrust } from '../../smiths/hook-bridge/factory-trust.js';
|
|
5
|
+
import { hermesHookAcceptanceNextStep, readHermesHookAcceptance } from '../../smiths/hook-bridge/hermes-trust.js';
|
|
5
6
|
/**
|
|
6
7
|
* Use Command Handler
|
|
7
8
|
*
|
|
@@ -43,7 +44,7 @@ import { bundleDeploymentScope, recordBundleDeployment, copyCleanupArgs, project
|
|
|
43
44
|
import { frameworkAdditiveBundles, getAllAddons, getAllExtensions } from './use-additive-bundles.js';
|
|
44
45
|
export { getAllAddons, getAllExtensions, USE_ALL_DISALLOW, USE_ALL_EXTENSIONS_DISALLOW } from './use-additive-bundles.js';
|
|
45
46
|
import { checkCollisions, formatCollisionReport, hasBlockingCollisions, } from '../../smiths/skillsmith/collision-detector.js';
|
|
46
|
-
import { discoverProjectLocalBundles, } from '../../extensions/project-local-discovery.js';
|
|
47
|
+
import { discoverProjectLocalBundles, formatProjectLocalTargetErrors, } from '../../extensions/project-local-discovery.js';
|
|
47
48
|
import { PROJECT_LOCAL_TYPE_TO_DIR } from '../../extensions/project-local-paths.js';
|
|
48
49
|
import { buildUpstreamRegistry } from '../../extensions/upstream-registry.js';
|
|
49
50
|
import { resolveShadows, formatShadowReport, } from '../../extensions/shadow-resolver.js';
|
|
@@ -1107,6 +1108,7 @@ async function deployOneProjectLocalBundle(opts) {
|
|
|
1107
1108
|
// whose desired set is the packaged framework corpus — deletes every
|
|
1108
1109
|
// project-local agent in the same run that re-deployed it.
|
|
1109
1110
|
'--deploy-source', 'project-local',
|
|
1111
|
+
...(opts.bundleOnly ? ['--bundle-only'] : []),
|
|
1110
1112
|
'--deploy-version', projectLocalDeployVersion(bundle),
|
|
1111
1113
|
...modelArgs,
|
|
1112
1114
|
];
|
|
@@ -1261,6 +1263,7 @@ async function deployProjectLocalBundles(opts) {
|
|
|
1261
1263
|
}
|
|
1262
1264
|
}
|
|
1263
1265
|
const result = await deployOneProjectLocalBundle({
|
|
1266
|
+
bundleOnly: Boolean(onlyBundleId),
|
|
1264
1267
|
bundle, ctx: await projectLocalDeploymentContext(ctx, projectDir, bundle.id, provider, Boolean(onlyBundleId)), frameworkRoot, provider, target, dryRun, verbose, quiet, modelArgs,
|
|
1265
1268
|
});
|
|
1266
1269
|
if (result.exitCode !== 0) {
|
|
@@ -1860,7 +1863,7 @@ function removeGlobalBootstrapFlags(args) {
|
|
|
1860
1863
|
const valueFlags = new Set(['--provider', '--platform', '--providers', '--scope', '--target', '--prefix']);
|
|
1861
1864
|
const booleanFlags = new Set([
|
|
1862
1865
|
'--global', '--user', '--ci-hooks-enabled', '--no-project-local',
|
|
1863
|
-
'--no-context-files', '--no-
|
|
1866
|
+
'--no-context-files', '--no-workspace-signals',
|
|
1864
1867
|
]);
|
|
1865
1868
|
for (let i = 0; i < args.length; i += 1) {
|
|
1866
1869
|
const arg = args[i];
|
|
@@ -2603,6 +2606,12 @@ export class UseHandler {
|
|
|
2603
2606
|
result.findings.push({
|
|
2604
2607
|
id: 'factory-hook-trust', provider: 'factory', severity: 'info', message: factoryTrustStep,
|
|
2605
2608
|
});
|
|
2609
|
+
const hermesAcceptanceStep = !dryRun && result.exitCode === 0 && providers.includes('hermes')
|
|
2610
|
+
? hermesHookAcceptanceNextStep(await readHermesHookAcceptance()) : '';
|
|
2611
|
+
if (hermesAcceptanceStep)
|
|
2612
|
+
result.findings.push({
|
|
2613
|
+
id: 'hermes-prompt-discovery-acceptance', provider: 'hermes', severity: 'info', message: hermesAcceptanceStep,
|
|
2614
|
+
});
|
|
2606
2615
|
if (json) {
|
|
2607
2616
|
return { exitCode: result.exitCode, message: JSON.stringify(result, null, 2), rawOutput: true };
|
|
2608
2617
|
}
|
|
@@ -2627,7 +2636,7 @@ export class UseHandler {
|
|
|
2627
2636
|
});
|
|
2628
2637
|
return {
|
|
2629
2638
|
exitCode: result.exitCode,
|
|
2630
|
-
message: [coreResult.message, rendered, ...(previewActions ? [...previewActions].sort() : []), codexTrustStep, factoryTrustStep].filter(Boolean).join('\n'),
|
|
2639
|
+
message: [coreResult.message, rendered, ...(previewActions ? [...previewActions].sort() : []), codexTrustStep, factoryTrustStep, hermesAcceptanceStep].filter(Boolean).join('\n'),
|
|
2631
2640
|
};
|
|
2632
2641
|
}
|
|
2633
2642
|
async executeCore(ctx, resolvedProviders) {
|
|
@@ -2723,7 +2732,6 @@ export class UseHandler {
|
|
|
2723
2732
|
'--target', stageRoot,
|
|
2724
2733
|
...(externalBundle ? [] : ['--no-project-local']),
|
|
2725
2734
|
'--no-context-files',
|
|
2726
|
-
'--no-hooks',
|
|
2727
2735
|
'--no-workspace-signals',
|
|
2728
2736
|
];
|
|
2729
2737
|
const result = await this.execute({ ...ctx, cwd: stageRoot, args: innerArgs });
|
|
@@ -3136,7 +3144,7 @@ export class UseHandler {
|
|
|
3136
3144
|
}
|
|
3137
3145
|
return {
|
|
3138
3146
|
exitCode: 1,
|
|
3139
|
-
message: `Error: Unknown target '${framework}'\nFrameworks: ${VALID_FRAMEWORKS.join(', ')}\n\n'all' deploys the kernel surface (kernel skills, kernel and core rules, behaviors).\nFor a single addon, run 'aiwg list' to see available addons.\nFor extensions (sys, net, it, sec, stream, dev), see $AIWG_ROOT/agentic/code/extensions/.\nFor project-local artifacts, run 'aiwg list --project-local'.\nRun 'aiwg help' for usage information.`,
|
|
3147
|
+
message: formatProjectLocalTargetErrors(projectDir, framework, discovery) ?? `Error: Unknown target '${framework}'\nFrameworks: ${VALID_FRAMEWORKS.join(', ')}\n\n'all' deploys the kernel surface (kernel skills, kernel and core rules, behaviors).\nFor a single addon, run 'aiwg list' to see available addons.\nFor extensions (sys, net, it, sec, stream, dev), see $AIWG_ROOT/agentic/code/extensions/.\nFor project-local artifacts, run 'aiwg list --project-local'.\nRun 'aiwg help' for usage information.`,
|
|
3140
3148
|
};
|
|
3141
3149
|
}
|
|
3142
3150
|
// Handle addon-only or extension-only deployment.
|
|
@@ -3171,7 +3179,7 @@ export class UseHandler {
|
|
|
3171
3179
|
};
|
|
3172
3180
|
}
|
|
3173
3181
|
const runner = createUseScriptRunner(frameworkRoot);
|
|
3174
|
-
const addonBaseArgs = ['--deploy-commands', '--deploy-skills', '--deploy-rules'];
|
|
3182
|
+
const addonBaseArgs = ['--deploy-commands', '--deploy-skills', '--deploy-rules', '--bundle-only'];
|
|
3175
3183
|
if (remainingArgs.includes('--allow-over-budget'))
|
|
3176
3184
|
addonBaseArgs.push('--allow-over-budget');
|
|
3177
3185
|
if (addonScope === 'user')
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Health diagnostics extracted from the utility handler collection.
|
|
2
2
|
import fsp from 'fs/promises';
|
|
3
|
+
import { diagnoseUserHookCommands } from '../../extensions/user-hook-diagnostics.js';
|
|
4
|
+
import { diagnoseHermesHookAcceptance } from '../../smiths/hook-bridge/hermes-trust.js';
|
|
3
5
|
import path from 'path';
|
|
4
6
|
import { createScriptRunner } from './script-runner.js';
|
|
5
7
|
import { getFrameworkRoot } from '../../channel/manager.mjs';
|
|
@@ -95,11 +97,16 @@ async function runUserScopeDoctor(verbose) {
|
|
|
95
97
|
lines.push('── User-scope registry validation ──');
|
|
96
98
|
lines.push(`Registry path: ${userRegistryPath()}`);
|
|
97
99
|
lines.push('');
|
|
100
|
+
const hookWarnings = await diagnoseUserHookCommands();
|
|
101
|
+
lines.push(...hookWarnings.map(warning => `⚠ ${warning.message}`));
|
|
102
|
+
const hermesAcceptance = await diagnoseHermesHookAcceptance();
|
|
103
|
+
if (hermesAcceptance)
|
|
104
|
+
lines.push(`⚠ ${hermesAcceptance.message}`);
|
|
98
105
|
if (frameworks.length === 0) {
|
|
99
106
|
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' };
|
|
107
|
+
return { exitCode: hookWarnings.length ? 1 : 0, message: lines.join('\n') + '\n' };
|
|
101
108
|
}
|
|
102
|
-
let driftCount =
|
|
109
|
+
let driftCount = hookWarnings.length;
|
|
103
110
|
let limitedCount = 0;
|
|
104
111
|
for (const [name, entry] of frameworks) {
|
|
105
112
|
lines.push(`▸ ${name} v${entry.version} [${entry.source}]`);
|
|
@@ -50,7 +50,7 @@ export const statusHandler = {
|
|
|
50
50
|
async execute(ctx) {
|
|
51
51
|
if (ctx.args.includes('--probe')) {
|
|
52
52
|
const projectRoot = statusProjectRoot(ctx.args, ctx.cwd ?? process.cwd());
|
|
53
|
-
const scope = detectScope(ctx.args);
|
|
53
|
+
const scope = ctx.args.includes('--scope') ? detectScope(ctx.args) : undefined;
|
|
54
54
|
const probe = await buildDeploymentStatusProbe(projectRoot, ctx.frameworkRoot, {
|
|
55
55
|
scope,
|
|
56
56
|
provider: statusFlagValue(ctx.args, '--provider'),
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Select registry authority for an unqualified deployment probe.
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { readAiwgConfig } from '../../config/aiwg-config.js';
|
|
6
|
+
import { inspectUserRegistry } from '../../config/user-registry.js';
|
|
7
|
+
export async function deploymentProbeScope(projectRoot, explicitScope) {
|
|
8
|
+
if (explicitScope)
|
|
9
|
+
return explicitScope;
|
|
10
|
+
// A global (user-scope) install lives in the home directory. Other projects keep project
|
|
11
|
+
// scope unless --scope user is passed, so a project without its own deployment is not
|
|
12
|
+
// reported as a broken user deployment.
|
|
13
|
+
const real = (dir) => { try {
|
|
14
|
+
return realpathSync(dir);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return path.resolve(dir);
|
|
18
|
+
} };
|
|
19
|
+
if (real(projectRoot) !== real(os.homedir()))
|
|
20
|
+
return 'project';
|
|
21
|
+
const config = await readAiwgConfig(projectRoot);
|
|
22
|
+
if (Object.values(config?.installed ?? {}).some(entry => Object.keys(entry.deployedTo ?? {}).length > 0)) {
|
|
23
|
+
return 'project';
|
|
24
|
+
}
|
|
25
|
+
const user = await inspectUserRegistry();
|
|
26
|
+
return Object.values(user.registry.installed).some(entry => Object.keys(entry?.deployedTo ?? {}).length > 0)
|
|
27
|
+
? 'user' : 'project';
|
|
28
|
+
}
|
|
29
|
+
export function deploymentProbeNextCommand(result, engaged, notConfigured) {
|
|
30
|
+
if (engaged)
|
|
31
|
+
return null;
|
|
32
|
+
if (notConfigured)
|
|
33
|
+
return 'aiwg wizard --dry-run';
|
|
34
|
+
const blocking = result.findings.filter(item => item.severity === 'blocking');
|
|
35
|
+
if (result.scope === 'user' && blocking.length > 0 && blocking.every(item => item.id.startsWith('context-'))) {
|
|
36
|
+
return result.providers.map(item => `aiwg regenerate --provider ${item.provider}`).join(' && ');
|
|
37
|
+
}
|
|
38
|
+
return `aiwg doctor --deployment${result.scope === 'user' ? ' --scope user' : ''}`;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=deployment-probe-scope.js.map
|
|
@@ -14,6 +14,7 @@ import { runGrokInspect } from '../../providers/grok-build-inspect.js';
|
|
|
14
14
|
import { diagnoseIntegratedProviderTransformationReceipt } from '../../providers/transformation-receipt-integration.js';
|
|
15
15
|
import { diagnoseWorkspaceContext, providerContextContract, } from '../../smiths/context-pipeline/workspace-context.js';
|
|
16
16
|
import { USER_SCOPE_PATHS } from '../scope-resolver.js';
|
|
17
|
+
import { deploymentProbeNextCommand, deploymentProbeScope } from './deployment-probe-scope.js';
|
|
17
18
|
const RESTART_NOTICES = {
|
|
18
19
|
flue: { policy: 'restart-required',
|
|
19
20
|
action: 'Restart the Flue app before checking deployed context and skills.',
|
|
@@ -350,9 +351,6 @@ async function collectRegistryFindings(options, provider, actualCounts) {
|
|
|
350
351
|
if (recordedTotal > 0 && actualTotal === 0) {
|
|
351
352
|
findings.push(finding(provider, `registry-artifacts-missing:${bundle}`, 'blocking', `Installed state records artifacts for '${bundle}', but no managed artifacts were found for ${provider}.`, `Re-run aiwg use ${bundle} --provider ${provider} to repair the managed deployment.`, { bundle, recordedTotal, actualTotal }));
|
|
352
353
|
}
|
|
353
|
-
if (useUserRegistry && !projectRecord) {
|
|
354
|
-
findings.push(finding(provider, `project-registry-missing:${bundle}`, 'advisory', `Project registry does not describe the additive user-scope deployment for '${bundle}'.`, 'Run aiwg status --probe --json from the originating project to inspect both registries.'));
|
|
355
|
-
}
|
|
356
354
|
}
|
|
357
355
|
return findings;
|
|
358
356
|
}
|
|
@@ -781,7 +779,8 @@ function probeInstallationIdentity() {
|
|
|
781
779
|
}
|
|
782
780
|
}
|
|
783
781
|
export async function buildDeploymentStatusProbe(projectRoot, frameworkRoot = process.env.AIWG_ROOT || projectRoot, filters = {}) {
|
|
784
|
-
const
|
|
782
|
+
const scope = await deploymentProbeScope(projectRoot, filters.scope);
|
|
783
|
+
const result = await verifyConfiguredDeployments(projectRoot, { ...filters, scope }, frameworkRoot);
|
|
785
784
|
const notConfigured = result.requestedBundles.length === 0
|
|
786
785
|
&& result.findings.length > 0
|
|
787
786
|
&& result.findings.every((item) => item.id === 'deployment-not-configured');
|
|
@@ -813,7 +812,7 @@ export async function buildDeploymentStatusProbe(projectRoot, frameworkRoot = pr
|
|
|
813
812
|
? 'Choose a provider and bundle to configure AIWG for this project.'
|
|
814
813
|
: 'Repair the blocking deployment findings, then run this probe again.',
|
|
815
814
|
command: 'aiwg status --probe --json',
|
|
816
|
-
next_command: engaged
|
|
815
|
+
next_command: deploymentProbeNextCommand(result, engaged, notConfigured),
|
|
817
816
|
},
|
|
818
817
|
provider_deployments: result.providers,
|
|
819
818
|
deployment_verification: result,
|
|
@@ -993,12 +993,15 @@ export async function readAiwgConfigCandidate(projectDir) {
|
|
|
993
993
|
if (authorizationErrors.length > 0) {
|
|
994
994
|
throw new Error(`Invalid .aiwg/aiwg.config:\n${authorizationErrors.map(item => item.message).join('\n')}`);
|
|
995
995
|
}
|
|
996
|
+
// Lazy: rule precedence loads the rule schema, which config readers should not pay for.
|
|
997
|
+
const { validateProjectRulePrecedence } = await import('../rules/project-precedence.js');
|
|
996
998
|
const threatAssessmentErrors = [
|
|
997
999
|
...validateThreatAssessmentConfig(parsed.security?.threatAssessment),
|
|
998
1000
|
...validateProjectConfig(parsed.project),
|
|
999
1001
|
...validateDeliverySettings(parsed),
|
|
1000
1002
|
...validateParallelismConfig(parsed.parallelism),
|
|
1001
1003
|
...validateDecisionConfig(parsed.decision),
|
|
1004
|
+
...validateProjectRulePrecedence(projectDir, parsed),
|
|
1002
1005
|
...validateRulePinCapabilities(parsed.rules, installedRuleCapabilities(loadRulePinConfigs(projectDir, parsed)), loadRulePinConfigs(projectDir, parsed).user.rules?.pin_groups),
|
|
1003
1006
|
];
|
|
1004
1007
|
if (threatAssessmentErrors.length > 0) {
|
|
@@ -1083,12 +1086,15 @@ async function writeAiwgConfigUnlocked(projectDir, config) {
|
|
|
1083
1086
|
config = { ...config, rules: { ...config.rules, pin_groups: pinGroups, always_load: selectors } };
|
|
1084
1087
|
console.warn(`Uninstalled ${removed.join(', ')}: their rules leave the effective pinned set; retired project capability selectors/groups. User pins remain visible as inactive warnings.`);
|
|
1085
1088
|
}
|
|
1089
|
+
// Lazy: rule precedence loads the rule schema, which config readers should not pay for.
|
|
1090
|
+
const { validateProjectRulePrecedence } = await import('../rules/project-precedence.js');
|
|
1086
1091
|
const threatAssessmentErrors = [
|
|
1087
1092
|
...validateThreatAssessmentConfig(config.security?.threatAssessment),
|
|
1088
1093
|
...validateProjectConfig(config.project),
|
|
1089
1094
|
...validateDeliverySettings(config),
|
|
1090
1095
|
...validateParallelismConfig(config.parallelism),
|
|
1091
1096
|
...validateDecisionConfig(config.decision),
|
|
1097
|
+
...validateProjectRulePrecedence(projectDir, config),
|
|
1092
1098
|
...validateRulePinCapabilities(config.rules, installedRuleCapabilities(loadRulePinConfigs(projectDir, config)), loadRulePinConfigs(projectDir, config).user.rules?.pin_groups),
|
|
1093
1099
|
];
|
|
1094
1100
|
if (threatAssessmentErrors.length > 0) {
|
|
@@ -7,6 +7,7 @@ import { ensureAuthorization, loadHitlLayers } from '../policy/hitl-config.js';
|
|
|
7
7
|
import { resolveHitlAuthorization } from '../policy/hitl.js';
|
|
8
8
|
import { validateHitlPolicy } from '../policy/hitl-validation.js';
|
|
9
9
|
import { checkHitlAuthorization } from '../policy/hitl-check.js';
|
|
10
|
+
import { listAuthorizationGrants, showAuthorizationGrant, searchAuthorizationGrants, explainAuthorization, revokeAuthorizationGrant } from '../policy/authorization-operations.js';
|
|
10
11
|
export const authorizationUsage = `aiwg config authorization (also aiwg steward authorization)
|
|
11
12
|
inspect | validate [--target DIRECTORY]
|
|
12
13
|
preview --action-file FILE [--target DIRECTORY]
|
|
@@ -14,10 +15,22 @@ export const authorizationUsage = `aiwg config authorization (also aiwg steward
|
|
|
14
15
|
enable --policy-file FILE [--target DIRECTORY]
|
|
15
16
|
revoke [--profile NAME] [--target DIRECTORY]
|
|
16
17
|
receipt --action-file FILE [--target DIRECTORY]
|
|
18
|
+
list [--active|--expired|--revoked] [--target DIRECTORY]
|
|
19
|
+
show <grantId> | search "<text>" [--target DIRECTORY]
|
|
20
|
+
explain --action-file FILE [--target DIRECTORY]
|
|
21
|
+
revoke <grantId> [--target DIRECTORY]
|
|
22
|
+
verify [--target DIRECTORY]
|
|
23
|
+
All operations accept --json; operator lookup output is JSON by default.
|
|
24
|
+
Search ranks up to 20 matches by token/field overlap, then grant/effect ID.
|
|
25
|
+
Explain is read-only: no receipts, uses, or index repairs.
|
|
26
|
+
Verify checks signed grant records and rebuilds/diffs their private descriptor index;
|
|
27
|
+
integrity failures exit 6. Missing indexes are rebuilt from verified records.
|
|
17
28
|
Preview is read-only. Receipt writes the decision to the existing signed effect ledger;
|
|
18
29
|
it does not perform the proposed action. Check writes a verified receipt before returning
|
|
19
30
|
auto-authorized; failures escalate. Action files must be host-classified descriptors,
|
|
20
|
-
never issue/model output.
|
|
31
|
+
never issue/model output. Check looks up verified durable grants before asking and
|
|
32
|
+
reports the nearest grant's differing fields when scope does not match.
|
|
33
|
+
Action files cannot supply session authorization. Platform prompts remain authoritative.`;
|
|
21
34
|
const usageError = (message) => new AiwgError({ code: 'ERR_AUTHORIZATION_USAGE', message, exitCode: EXIT_CODES.USAGE });
|
|
22
35
|
async function jsonFile(file) {
|
|
23
36
|
try {
|
|
@@ -33,16 +46,61 @@ export async function authorizationCli(args, cwd = process.cwd()) {
|
|
|
33
46
|
return;
|
|
34
47
|
}
|
|
35
48
|
const [operation, ...rest] = args;
|
|
49
|
+
let operand;
|
|
50
|
+
if (['show', 'search', 'revoke'].includes(operation) && rest[0] && !rest[0].startsWith('--'))
|
|
51
|
+
operand = rest.shift();
|
|
36
52
|
const flags = {};
|
|
37
53
|
const allowed = ['--target', ...(operation === 'enable' ? ['--policy-file'] : []),
|
|
38
|
-
...(['preview', 'receipt', 'check'].includes(operation) ? ['--action-file'] : []),
|
|
54
|
+
...(['preview', 'receipt', 'check', 'explain'].includes(operation) ? ['--action-file'] : []),
|
|
39
55
|
...(operation === 'check' ? ['--receipt-file', '--effect-id'] : []), ...(operation === 'revoke' ? ['--profile'] : [])];
|
|
40
|
-
for (let i = 0; i < rest.length; i
|
|
56
|
+
for (let i = 0; i < rest.length; i++) {
|
|
57
|
+
if (['--json', ...(operation === 'list' ? ['--active', '--expired', '--revoked'] : [])].includes(rest[i])) {
|
|
58
|
+
if (flags[rest[i]])
|
|
59
|
+
throw usageError('Invalid authorization option');
|
|
60
|
+
flags[rest[i]] = 'true';
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
41
63
|
if (!allowed.includes(rest[i]) || !rest[i + 1] || rest[i + 1].startsWith('--') || flags[rest[i]])
|
|
42
64
|
throw usageError('Invalid authorization option');
|
|
43
65
|
flags[rest[i]] = rest[i + 1];
|
|
66
|
+
i++;
|
|
44
67
|
}
|
|
45
68
|
const target = resolve(getProjectDir({ cwd }, rest));
|
|
69
|
+
if (['list', 'show', 'search', 'explain'].includes(operation) || (operation === 'revoke' && operand)) {
|
|
70
|
+
let result;
|
|
71
|
+
if (operation === 'list') {
|
|
72
|
+
const selected = ['active', 'expired', 'revoked'].filter(s => flags[`--${s}`]);
|
|
73
|
+
if (selected.length > 1)
|
|
74
|
+
throw usageError('Choose one grant status filter');
|
|
75
|
+
result = await listAuthorizationGrants(target, selected[0]);
|
|
76
|
+
}
|
|
77
|
+
else if (operation === 'explain') {
|
|
78
|
+
if (!flags['--action-file'])
|
|
79
|
+
throw usageError('--action-file is required');
|
|
80
|
+
result = await explainAuthorization(target, await jsonFile(resolve(cwd, flags['--action-file'])));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (!operand)
|
|
84
|
+
throw usageError('A grant ID or search text is required');
|
|
85
|
+
if (operation === 'revoke' && flags['--profile'])
|
|
86
|
+
throw usageError('Grant ID and --profile cannot be combined');
|
|
87
|
+
result = operation === 'show' ? await showAuthorizationGrant(target, operand)
|
|
88
|
+
: operation === 'search' ? await searchAuthorizationGrants(target, operand) : await revokeAuthorizationGrant(target, operand);
|
|
89
|
+
}
|
|
90
|
+
console.log(JSON.stringify(result, null, 2));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (operation === 'verify') {
|
|
94
|
+
const { effectSession } = await import('../effects/host.js');
|
|
95
|
+
const { openEffectLedger } = await import('../effects/ledger.js');
|
|
96
|
+
const { verifyAuthorizationGrants } = await import('../effects/authorization-store.js');
|
|
97
|
+
const session = await effectSession(target, 'custom');
|
|
98
|
+
const result = await verifyAuthorizationGrants(openEffectLedger({ projectDir: target, scope: session.scope, writer: 'cli' }));
|
|
99
|
+
console.log(JSON.stringify(result, null, 2));
|
|
100
|
+
if (!result.ok)
|
|
101
|
+
throw new AiwgError({ code: 'ERR_AUTHORIZATION_INTEGRITY', message: 'Authorization ledger verification failed', exitCode: result.exitCode });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
46
104
|
if (operation === 'inspect' || operation === 'validate') {
|
|
47
105
|
const loaded = await loadHitlLayers(target);
|
|
48
106
|
console.log(JSON.stringify(operation === 'inspect' ? loaded : { valid: true, layers: loaded.layers.length }, null, 2));
|
|
@@ -17,7 +17,7 @@ Subcommands:
|
|
|
17
17
|
path Print config directory path
|
|
18
18
|
edit Open config in $EDITOR/$VISUAL (requires a terminal)
|
|
19
19
|
edit --print-path Print the config file path instead of opening an editor
|
|
20
|
-
authorization Inspect/validate/preview/enable/revoke bounded HITL policy
|
|
20
|
+
authorization Inspect/validate/preview/enable/revoke bounded HITL policy; list/show/search/explain/verify grants
|
|
21
21
|
gitignore Show/check/fix .gitignore AIWG entries
|
|
22
22
|
|
|
23
23
|
Reviewed worker policy pair (project scope, no prompts):
|
package/dist/src/config/cli.js
CHANGED
|
@@ -501,7 +501,8 @@ async function handleValidate(config, args) {
|
|
|
501
501
|
try {
|
|
502
502
|
const { loadRulePinConfigs, installedRuleCapabilities, validateRulePinCapabilities } = await import('../rules/pins.mjs');
|
|
503
503
|
const configs = loadRulePinConfigs(process.cwd(), undefined, config.getPath());
|
|
504
|
-
|
|
504
|
+
const { validateProjectRulePrecedence } = await import('../rules/project-precedence.js');
|
|
505
|
+
for (const message of [...validateRulePinCapabilities(configs.user.rules, installedRuleCapabilities(configs), configs.project.rules?.pin_groups), ...validateProjectRulePrecedence(process.cwd(), configs.user, 'user', config.getPath())]) {
|
|
505
506
|
issues.push({ file: 'aiwg.config', severity: 'error', message });
|
|
506
507
|
}
|
|
507
508
|
}
|
|
@@ -919,7 +920,8 @@ export async function setRuleConfigKey(cwd, source, key, raw, userConfigDir) {
|
|
|
919
920
|
value = raw;
|
|
920
921
|
}
|
|
921
922
|
setDottedPath(configs.user, key, value);
|
|
922
|
-
const
|
|
923
|
+
const { validateProjectRulePrecedence } = await import('../rules/project-precedence.js');
|
|
924
|
+
const errors = [...validateRulePinCapabilities(configs.user.rules, installedRuleCapabilities(configs), configs.project.rules?.pin_groups), ...validateProjectRulePrecedence(cwd, configs.user, 'user', userConfigDir)];
|
|
923
925
|
if (errors.length)
|
|
924
926
|
throw new Error(errors.join('\n'));
|
|
925
927
|
const file = rulePinConfigPath(cwd, 'user', userConfigDir);
|
|
@@ -58,7 +58,7 @@ function listWorkerUnits({ spawn = spawnSync } = {}) {
|
|
|
58
58
|
try {
|
|
59
59
|
const result = spawn('systemctl', ['--user', 'list-units', '--type=service',
|
|
60
60
|
'--state=running,activating', '--no-legend', '--plain', 'aiwg-worker-*'],
|
|
61
|
-
{ encoding: 'utf8', timeout: 1000 });
|
|
61
|
+
{ encoding: 'utf8', timeout: 1000, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
62
62
|
if (result.error || result.status !== 0) return undefined;
|
|
63
63
|
return [...new Set(String(result.stdout ?? '').split('\n')
|
|
64
64
|
.map(line => /^(aiwg-worker-[^\s]+\.service)\s/.exec(line.trim())?.[1]).filter(Boolean))];
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* --scope user` works from any cwd.
|
|
13
13
|
*/
|
|
14
14
|
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
15
|
-
import { dirname } from 'node:path';
|
|
15
|
+
import { dirname, resolve } from 'node:path';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
16
17
|
import { userScopeConfigPath } from '../cli/scope-resolver.js';
|
|
17
18
|
/**
|
|
18
19
|
* Path to ~/.aiwg/installed.json. Distinct from `userScopeConfigPath()`
|
|
@@ -76,6 +77,13 @@ export async function inspectUserRegistry() {
|
|
|
76
77
|
export async function readUserRegistry() {
|
|
77
78
|
return (await inspectUserRegistry()).registry;
|
|
78
79
|
}
|
|
80
|
+
/** User receipts can describe project-relative provider trees only at HOME. */
|
|
81
|
+
export async function homeDeploymentReceipts(projectRoot) {
|
|
82
|
+
if (resolve(projectRoot) !== resolve(homedir()))
|
|
83
|
+
return [];
|
|
84
|
+
const registry = await readUserRegistry();
|
|
85
|
+
return Object.entries(registry.installed).map(([name, entry]) => [`user:${name}`, entry]);
|
|
86
|
+
}
|
|
79
87
|
/**
|
|
80
88
|
* Persist the user registry. Creates the parent directory if missing.
|
|
81
89
|
*/
|
|
@@ -2,11 +2,91 @@
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
4
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
-
import { mkdir, writeFile, symlink,
|
|
6
|
-
import { readFileSync, readlinkSync } from 'node:fs';
|
|
5
|
+
import { link, mkdir, open, writeFile, symlink, unlink, rm, readdir } from 'node:fs/promises';
|
|
6
|
+
import { lstatSync, readFileSync, readlinkSync, realpathSync } from 'node:fs';
|
|
7
7
|
import { projectControlPath } from './project-artifacts.js';
|
|
8
8
|
export const workerWriteLock = (project) => projectControlPath(project, 'aiwg.config.apply-lock');
|
|
9
9
|
const missing = (error) => error.code === 'ENOENT';
|
|
10
|
+
function samePath(left, right) {
|
|
11
|
+
const canonical = process.platform === 'win32' ? realpathSync.native : resolve;
|
|
12
|
+
return canonical(left) === canonical(right);
|
|
13
|
+
}
|
|
14
|
+
function lockDirectoryTarget(path) {
|
|
15
|
+
const target = resolve(dirname(path), readlinkSync(path));
|
|
16
|
+
const targetGeneration = basename(target).slice(`${basename(path)}.`.length);
|
|
17
|
+
if (!samePath(dirname(target), dirname(path)) ||
|
|
18
|
+
!basename(target).startsWith(`${basename(path)}.`) ||
|
|
19
|
+
!/^[a-f0-9-]{36}$/.test(targetGeneration))
|
|
20
|
+
throw new Error(`Invalid worker configuration lock target: ${target}`);
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
23
|
+
function generationValue(path) {
|
|
24
|
+
const stat = lstatSync(path);
|
|
25
|
+
if (stat.isSymbolicLink())
|
|
26
|
+
return readlinkSync(path);
|
|
27
|
+
if (stat.isFile())
|
|
28
|
+
return readFileSync(path, 'utf8');
|
|
29
|
+
throw new Error(`Invalid worker lock generation record: ${path}`);
|
|
30
|
+
}
|
|
31
|
+
async function publishOwnerDirectory(directory, path) {
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
// Junctions preserve directory traversal without requiring symlink privilege.
|
|
34
|
+
await symlink(resolve(directory), path, 'junction');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
await symlink(basename(directory), path);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function publishGeneration(path, value) {
|
|
41
|
+
if (process.platform !== 'win32')
|
|
42
|
+
return symlink(value, path);
|
|
43
|
+
// Publish a complete immutable record atomically. A Windows file symlink needs
|
|
44
|
+
// privilege, while a same-directory hard link is exclusive and works without it.
|
|
45
|
+
const temporary = join(dirname(path), `.worker-lock-record-${randomUUID()}.tmp`);
|
|
46
|
+
let temporaryCreated = false;
|
|
47
|
+
try {
|
|
48
|
+
const handle = await open(temporary, 'wx', 0o600);
|
|
49
|
+
temporaryCreated = true;
|
|
50
|
+
let writeError;
|
|
51
|
+
try {
|
|
52
|
+
await handle.writeFile(value);
|
|
53
|
+
await handle.sync();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
writeError = error;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await handle.close();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (writeError)
|
|
63
|
+
throw new AggregateError([writeError, error], 'Could not close a worker lock record', { cause: writeError });
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
if (writeError)
|
|
67
|
+
throw writeError;
|
|
68
|
+
await link(temporary, path);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (temporaryCreated) {
|
|
72
|
+
try {
|
|
73
|
+
await unlink(temporary);
|
|
74
|
+
}
|
|
75
|
+
catch (cleanupError) {
|
|
76
|
+
if (!missing(cleanupError))
|
|
77
|
+
throw new AggregateError([error, cleanupError], 'Could not clean up an unpublished worker lock record', { cause: error });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await unlink(temporary);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (!missing(error))
|
|
87
|
+
process.emitWarning(`Published worker lock record but could not remove its temporary hard-link name: ${String(error)}`, { code: 'AIWG_WORKER_LOCK_TEMP_CLEANUP' });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
10
90
|
function processStart(pid) {
|
|
11
91
|
try {
|
|
12
92
|
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
@@ -35,12 +115,12 @@ function provablyDead(owner) {
|
|
|
35
115
|
}
|
|
36
116
|
function latest(directory) {
|
|
37
117
|
let owner = JSON.parse(readFileSync(join(directory, 'owner.json'), 'utf8'));
|
|
38
|
-
// Immutable successor
|
|
118
|
+
// Immutable successor records are a compare-and-swap: only one contender can claim a generation.
|
|
39
119
|
for (;;) {
|
|
40
120
|
if (!/^[a-f0-9-]{36}$/.test(owner.generation))
|
|
41
121
|
throw new Error('Invalid worker lock generation');
|
|
42
122
|
try {
|
|
43
|
-
owner = JSON.parse(
|
|
123
|
+
owner = JSON.parse(generationValue(join(directory, `next-${owner.generation}`)));
|
|
44
124
|
}
|
|
45
125
|
catch (error) {
|
|
46
126
|
if (missing(error))
|
|
@@ -66,7 +146,7 @@ async function sweepOrphanedOwners(path) {
|
|
|
66
146
|
if (!provablyDead(owner))
|
|
67
147
|
continue;
|
|
68
148
|
try {
|
|
69
|
-
if (
|
|
149
|
+
if (samePath(lockDirectoryTarget(path), directory))
|
|
70
150
|
continue;
|
|
71
151
|
}
|
|
72
152
|
catch (error) {
|
|
@@ -79,7 +159,7 @@ async function sweepOrphanedOwners(path) {
|
|
|
79
159
|
function lease(path, directory, owner) {
|
|
80
160
|
const assertOwned = () => {
|
|
81
161
|
try {
|
|
82
|
-
if (
|
|
162
|
+
if (samePath(lockDirectoryTarget(path), directory) && latest(directory).generation === owner.generation)
|
|
83
163
|
return;
|
|
84
164
|
}
|
|
85
165
|
catch { /* Missing or replaced ownership must never authorize another write. */ }
|
|
@@ -89,7 +169,7 @@ function lease(path, directory, owner) {
|
|
|
89
169
|
assertOwned();
|
|
90
170
|
if (keepBlocked) {
|
|
91
171
|
// A caught failure can be retried even while this embedding process stays alive.
|
|
92
|
-
await
|
|
172
|
+
await publishGeneration(join(directory, `next-${owner.generation}`), JSON.stringify({ ...identity(), released: true }));
|
|
93
173
|
}
|
|
94
174
|
else {
|
|
95
175
|
// A live owner cannot be reclaimed; unlink only while we still own this exact generation.
|
|
@@ -110,7 +190,7 @@ export async function acquireWorkerWriteLock(project, block = false, proposalDig
|
|
|
110
190
|
if (block)
|
|
111
191
|
await writeFile(join(directory, 'blocked'), 'Worker policy apply/recovery in progress.\n', { mode: 0o600 });
|
|
112
192
|
// No visible lock can exist without an owner, even if initialization is interrupted.
|
|
113
|
-
await
|
|
193
|
+
await publishOwnerDirectory(directory, path);
|
|
114
194
|
}
|
|
115
195
|
catch (error) {
|
|
116
196
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -125,7 +205,7 @@ export async function reclaimWorkerWriteLock(project) {
|
|
|
125
205
|
let directory;
|
|
126
206
|
let previous;
|
|
127
207
|
try {
|
|
128
|
-
directory =
|
|
208
|
+
directory = lockDirectoryTarget(path);
|
|
129
209
|
previous = latest(directory);
|
|
130
210
|
}
|
|
131
211
|
catch (error) {
|
|
@@ -137,7 +217,7 @@ export async function reclaimWorkerWriteLock(project) {
|
|
|
137
217
|
throw new Error(`Worker configuration is locked by a live or unverifiable owner (${previous.host}:${previous.pid}); ${path}`);
|
|
138
218
|
const owner = identity();
|
|
139
219
|
try {
|
|
140
|
-
await
|
|
220
|
+
await publishGeneration(join(directory, `next-${previous.generation}`), JSON.stringify(owner));
|
|
141
221
|
}
|
|
142
222
|
catch (error) {
|
|
143
223
|
if (error.code === 'EEXIST')
|
|
@@ -9,7 +9,7 @@ export function admittedDecisionFlowAdapter(ledger, estimate, invoke, signal, on
|
|
|
9
9
|
ledger.cancel();
|
|
10
10
|
throw new DecisionGraphError('graph cancelled');
|
|
11
11
|
}
|
|
12
|
-
// Flow invokes a gate only after
|
|
12
|
+
// Flow invokes a gate only after host approval or a signed HITL check. The gate dispatches
|
|
13
13
|
// nothing, spends no decision budget and is not a decision observation.
|
|
14
14
|
if (request.node.kind === 'gate' && request.node.sideEffectMode === 'none' && request.node.ref === undefined) {
|
|
15
15
|
return { outputs: {}, attempts: 1, usage: { tokens: 0, costUsd: 0, timeMs: 0 } };
|