@aiwg/cli 2026.11.2 → 2026.11.4
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 +17 -20
- package/agentic/code/providers/model-capabilities.v1.json +17 -16
- 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 +5 -25
- 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 +27 -9
- 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/dataset.js +17 -0
- 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/sessions.js +1 -1
- package/dist/src/cli/handlers/steward.js +1 -1
- package/dist/src/cli/handlers/use.js +18 -5
- package/dist/src/cli/handlers/utility-doctor.js +5 -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 +5 -6
- 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/decision-config.js +2 -1
- package/dist/src/config/host-resource-runtime.mjs +1 -1
- package/dist/src/config/jev-credential-reference.js +56 -0
- package/dist/src/config/user-config.js +13 -19
- package/dist/src/config/user-registry.js +9 -1
- package/dist/src/config/worker-owner-lock.js +90 -10
- package/dist/src/decision/ask.js +3 -2
- package/dist/src/decision/graph-flow-adapter.js +1 -1
- package/dist/src/decision/jev-credentials.js +22 -0
- package/dist/src/decision/offload.js +1 -1
- package/dist/src/decision/openbao-kv-resolver.mjs +96 -0
- package/dist/src/decision/openbao-runtime.js +101 -0
- 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/muse-managed-hooks.js +11 -0
- 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/model-capabilities.v1.json +17 -16
- 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/process/bounded-child-process.mjs +49 -39
- package/dist/src/providers/capability-matrix.yaml +17 -20
- package/dist/src/providers/deployment-ownership.d.mts +1 -0
- package/dist/src/providers/deployment-ownership.mjs +21 -2
- package/dist/src/providers/grok-build-headless.js +170 -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/sessions/adapters/grok-build-fallback.js +33 -0
- package/dist/src/sessions/adapters/grok-build-native-records.js +64 -0
- package/dist/src/sessions/adapters/grok-build-native.js +92 -100
- package/dist/src/sessions/adapters/grok-build.js +65 -24
- package/dist/src/sessions/grok-build-cli-output.js +113 -0
- package/dist/src/sessions/grok-build-cli.js +4 -28
- 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 +56 -0
- package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +78 -0
- package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
- 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 +5 -6
- package/tools/agents/deploy-options.mjs +1 -0
- package/tools/agents/providers/base-frontmatter.mjs +3 -2
- 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 +3 -1
- 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-prepare.mjs +5 -3
- package/tools/agents/providers/rule-deployment-state.mjs +14 -6
- package/tools/agents/providers/rule-startup.mjs +11 -10
- package/tools/agents/providers/staged-directory-reference.mjs +14 -0
- package/tools/agents/providers/user-hooks.mjs +26 -0
- package/tools/cli/authorization-health.mjs +20 -0
- package/tools/cli/decision-offload-report.mjs +2 -0
- package/tools/cli/workspace-status.mjs +7 -0
- package/tools/commands/deploy-prompts-codex.mjs +15 -1
- package/tools/plugin/package-plugins.mjs +6 -1
- package/tools/ralph-external/lib/claude-adapter.mjs +2 -2
- package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
|
@@ -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);
|
|
@@ -2,12 +2,13 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { parseYamlSimple } from './user-config.js';
|
|
4
4
|
import { resolveUserConfigDir } from './user-config-dir.mjs';
|
|
5
|
+
import { validateJevConfig } from './jev-credential-reference.js';
|
|
5
6
|
export function validateDecisionConfig(value) {
|
|
6
7
|
if (value === undefined)
|
|
7
8
|
return [];
|
|
8
9
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
9
10
|
return ['decision must be an object'];
|
|
10
|
-
const errors =
|
|
11
|
+
const errors = validateJevConfig(value.jev);
|
|
11
12
|
const { enabled, ask, offload_report: report } = value;
|
|
12
13
|
if (enabled !== undefined && typeof enabled !== 'boolean')
|
|
13
14
|
errors.push('decision.enabled must be a boolean');
|
|
@@ -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))];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Validate and load reference-only Jev configuration in the existing decision scope.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseYamlSimple } from './user-config.js';
|
|
5
|
+
import { resolveUserConfigDir } from './user-config-dir.mjs';
|
|
6
|
+
const segment = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
|
|
7
|
+
const object = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
const only = (value, keys) => Object.keys(value).every(key => keys.includes(key));
|
|
9
|
+
function validOrigin(value) {
|
|
10
|
+
if (typeof value !== 'string')
|
|
11
|
+
return false;
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(value);
|
|
14
|
+
return url.protocol === 'https:' && !url.username && !url.password && !url.search && !url.hash && url.pathname === '/';
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function validJevReference(value) {
|
|
21
|
+
if (!object(value) || !only(value, ['source', 'addr', 'path', 'field', 'auth']) || value.source !== 'openbao'
|
|
22
|
+
|| (value.addr !== undefined && !validOrigin(value.addr)))
|
|
23
|
+
return false;
|
|
24
|
+
const parts = typeof value.path === 'string' ? value.path.split('/') : [];
|
|
25
|
+
return parts.length >= 3 && parts[1] === 'data' && parts.every(part => segment.test(part))
|
|
26
|
+
&& typeof value.field === 'string' && segment.test(value.field)
|
|
27
|
+
&& object(value.auth) && only(value.auth, ['method', 'role']) && value.auth.method === 'approle'
|
|
28
|
+
&& typeof value.auth.role === 'string' && segment.test(value.auth.role);
|
|
29
|
+
}
|
|
30
|
+
export function validateJevConfig(value) {
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return [];
|
|
33
|
+
return object(value) && only(value, ['credential']) && validJevReference(value.credential)
|
|
34
|
+
? [] : ['decision.jev.credential must be an OpenBao KV v2 reference with field and AppRole; values and extra keys are forbidden'];
|
|
35
|
+
}
|
|
36
|
+
export function readJevReference(options = {}) {
|
|
37
|
+
const read = (file, yaml = false) => {
|
|
38
|
+
let raw;
|
|
39
|
+
try {
|
|
40
|
+
raw = readFileSync(file, 'utf8');
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code === 'ENOENT')
|
|
44
|
+
return undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
const config = (yaml ? parseYamlSimple(raw) : JSON.parse(raw));
|
|
48
|
+
const value = config.decision?.jev;
|
|
49
|
+
if (validateJevConfig(value).length)
|
|
50
|
+
throw new Error('credential-unavailable');
|
|
51
|
+
return value?.credential;
|
|
52
|
+
};
|
|
53
|
+
return read(path.join(options.cwd ?? process.cwd(), '.aiwg', 'aiwg.config'))
|
|
54
|
+
?? read(path.join(resolveUserConfigDir(options), 'config.yaml'), true);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=jev-credential-reference.js.map
|
|
@@ -299,12 +299,12 @@ export class UserConfig {
|
|
|
299
299
|
// ============================================
|
|
300
300
|
/**
|
|
301
301
|
* Minimal YAML parser for flat/nested config files.
|
|
302
|
-
* Handles the subset we use: scalars, nested objects
|
|
302
|
+
* Handles the subset we use: scalars, nested objects.
|
|
303
303
|
* For complex YAML, users should use a full parser.
|
|
304
304
|
*/
|
|
305
305
|
export function parseYamlSimple(content) {
|
|
306
306
|
const result = {};
|
|
307
|
-
|
|
307
|
+
const sections = [{ indent: -1, value: result }];
|
|
308
308
|
for (const line of content.split('\n')) {
|
|
309
309
|
// Skip comments and empty lines
|
|
310
310
|
if (line.trim().startsWith('#') || line.trim() === '')
|
|
@@ -321,24 +321,18 @@ export function parseYamlSimple(content) {
|
|
|
321
321
|
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
322
322
|
throw new Error('Unsafe config key: prototype-related names are not allowed');
|
|
323
323
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
// Top-level key-value
|
|
334
|
-
currentSection = null;
|
|
335
|
-
result[key] = parseScalar(rawValue);
|
|
336
|
-
}
|
|
324
|
+
while (sections.length > 1 && sections.at(-1).indent >= indent)
|
|
325
|
+
sections.pop();
|
|
326
|
+
const parent = sections.at(-1);
|
|
327
|
+
if (indent !== 0 && (indent < 2 || sections.length === 1))
|
|
328
|
+
continue;
|
|
329
|
+
if (rawValue === '') {
|
|
330
|
+
const section = {};
|
|
331
|
+
parent.value[key] = section;
|
|
332
|
+
sections.push({ indent, value: section });
|
|
337
333
|
}
|
|
338
|
-
else
|
|
339
|
-
|
|
340
|
-
const section = result[currentSection];
|
|
341
|
-
section[key] = parseScalar(rawValue);
|
|
334
|
+
else {
|
|
335
|
+
parent.value[key] = parseScalar(rawValue);
|
|
342
336
|
}
|
|
343
337
|
}
|
|
344
338
|
return result;
|
|
@@ -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')
|
package/dist/src/decision/ask.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { aggregateModalAnswers } from './ensemble/aggregate.js';
|
|
2
|
+
import { JevReferenceUnavailable } from './openbao-runtime.js';
|
|
2
3
|
import { readAiwgConfigCandidate } from '../config/aiwg-config.js';
|
|
3
4
|
import { readFile } from 'node:fs/promises';
|
|
4
5
|
import { JEV_ENDPOINT, JevDecisionAdapter } from './adapters/jev.js';
|
|
@@ -358,8 +359,8 @@ export async function askDecision(input, options = {}) {
|
|
|
358
359
|
try {
|
|
359
360
|
credential = await lookupJevCredential(options);
|
|
360
361
|
}
|
|
361
|
-
catch {
|
|
362
|
-
return finish('not-configured');
|
|
362
|
+
catch (error) {
|
|
363
|
+
return finish(error instanceof JevReferenceUnavailable ? 'credential-unavailable' : 'not-configured');
|
|
363
364
|
}
|
|
364
365
|
if (!credential?.enabled || !credential.token)
|
|
365
366
|
return finish('not-configured');
|
|
@@ -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 } };
|
|
@@ -6,6 +6,8 @@ import path from 'node:path';
|
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { JevCredentialError } from './adapters/jev.js';
|
|
8
8
|
import { readPrivateValueFile } from '../auth/sensitive-input.js';
|
|
9
|
+
import { readJevReference } from '../config/jev-credential-reference.js';
|
|
10
|
+
import { JevReferenceUnavailable, resolveOpenBaoJev } from './openbao-runtime.js';
|
|
9
11
|
export const JEV_CREDENTIAL_REF = 'typesafe-api';
|
|
10
12
|
export const JEV_DEFAULT_REGION = 'us';
|
|
11
13
|
function env(options) {
|
|
@@ -77,6 +79,20 @@ export async function lookupJevCredential(options = {}) {
|
|
|
77
79
|
const environment = env(options);
|
|
78
80
|
const forced = environment.AIWG_DECISION_ENABLED;
|
|
79
81
|
const envToken = environment.JEV_API_KEY?.trim() || environment.AIWG_DECISION_JEV_API_KEY?.trim();
|
|
82
|
+
if (!envToken) {
|
|
83
|
+
try {
|
|
84
|
+
const reference = readJevReference(options);
|
|
85
|
+
if (reference) {
|
|
86
|
+
const { enabled } = resolveDecisionEnablement(options);
|
|
87
|
+
return { source: 'openbao', token: enabled ? await resolveOpenBaoJev(reference, environment) : '', enabled,
|
|
88
|
+
region: environment.AIWG_DECISION_JEV_REGION?.trim() || JEV_DEFAULT_REGION,
|
|
89
|
+
...(environment.AIWG_DECISION_JEV_ENDPOINT?.trim() ? { endpoint: environment.AIWG_DECISION_JEV_ENDPOINT.trim() } : {}) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
throw new JevReferenceUnavailable();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
80
96
|
const fileRecord = envToken && (forced === '0' || forced === '1') ? null : await readCredentialFile(options);
|
|
81
97
|
const enablement = resolveDecisionEnablement(options);
|
|
82
98
|
const enabled = enablement.source === 'default' ? fileRecord?.enabled === true : enablement.enabled;
|
|
@@ -96,6 +112,12 @@ export async function lookupJevCredential(options = {}) {
|
|
|
96
112
|
/** Offline metadata-only inspection. Never probes Jev and never returns credential bytes. */
|
|
97
113
|
export async function inspectJevCredential(options = {}) {
|
|
98
114
|
try {
|
|
115
|
+
const environment = env(options);
|
|
116
|
+
if (!(environment.JEV_API_KEY?.trim() || environment.AIWG_DECISION_JEV_API_KEY?.trim())) {
|
|
117
|
+
const reference = readJevReference(options);
|
|
118
|
+
if (reference)
|
|
119
|
+
return { configured: true, enabled: resolveDecisionEnablement(options).enabled, source: 'openbao', path: reference.path };
|
|
120
|
+
}
|
|
99
121
|
const credential = await lookupJevCredential(options);
|
|
100
122
|
if (!credential)
|
|
101
123
|
return { configured: false, enabled: false, source: 'none' };
|
|
@@ -509,7 +509,7 @@ export async function buildDecisionOffloadSnapshot(options) {
|
|
|
509
509
|
since: sessionId ? null : since.toISOString(), windowHours: sessionId ? null : windowHours, generatedAt: now.toISOString() },
|
|
510
510
|
readiness: {
|
|
511
511
|
ask: { state: askReadinessState(askConfigured, latestTransportEvidence), configured: credential.configured,
|
|
512
|
-
enabled: credential.enabled, source: credential.source, probed: false },
|
|
512
|
+
enabled: credential.enabled, source: credential.source, ...(credential.path ? { path: credential.path } : {}), probed: false },
|
|
513
513
|
evaluate: { state: evaluateState, enabled: enablement?.enabled ?? null,
|
|
514
514
|
source: configReadable && enablement ? enablement.source : 'unknown', probed: false },
|
|
515
515
|
observed: latestObserved ? {
|