@aiwg/cli 2026.11.1 → 2026.11.3

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.
Files changed (120) hide show
  1. package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +9 -0
  2. package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +136 -0
  3. package/agentic/code/providers/capability-matrix.yaml +2 -2
  4. package/agentic/code/providers/model-capabilities.v1.json +44 -39
  5. package/agentic/code/providers/model-catalog.v1.json +3 -3
  6. package/dist/src/artifacts/cli.js +10 -11
  7. package/dist/src/artifacts/discover-cli-help.js +25 -0
  8. package/dist/src/artifacts/discover-session-facets.js +2 -1
  9. package/dist/src/artifacts/fortemi-core-prebuilt-freshness.js +28 -0
  10. package/dist/src/artifacts/fortemi-core-sync.js +3 -0
  11. package/dist/src/artifacts/framework-capabilities.js +4 -0
  12. package/dist/src/artifacts/framework-source-digest.js +1 -1
  13. package/dist/src/artifacts/index-builder.js +10 -10
  14. package/dist/src/artifacts/index-dependencies.js +72 -0
  15. package/dist/src/artifacts/query-engine-discover-output.js +13 -5
  16. package/dist/src/artifacts/query-engine-discover.js +49 -21
  17. package/dist/src/artifacts/query-engine-entries.js +56 -2
  18. package/dist/src/artifacts/query-engine-options.js +14 -1
  19. package/dist/src/artifacts/query-engine-scoring.js +8 -4
  20. package/dist/src/artifacts/query-engine-show-card.js +2 -0
  21. package/dist/src/artifacts/query-engine-show-load.js +1 -1
  22. package/dist/src/artifacts/query-engine-show.js +3 -1
  23. package/dist/src/artifacts/query-engine-templates.js +33 -0
  24. package/dist/src/artifacts/query-engine-verbose.js +25 -0
  25. package/dist/src/artifacts/relations-builder.js +49 -4
  26. package/dist/src/artifacts/relations.js +9 -0
  27. package/dist/src/artifacts/template-references.js +42 -0
  28. package/dist/src/artifacts/types.js +1 -1
  29. package/dist/src/cli/handlers/bundle-reconciliation.js +7 -3
  30. package/dist/src/cli/handlers/checkpoint-handoff.js +48 -0
  31. package/dist/src/cli/handlers/checkpoint-record.js +20 -0
  32. package/dist/src/cli/handlers/checkpoint.js +50 -17
  33. package/dist/src/cli/handlers/dataset.js +17 -0
  34. package/dist/src/cli/handlers/decision.js +1 -1
  35. package/dist/src/cli/handlers/doctor-args.js +3 -1
  36. package/dist/src/cli/handlers/doctor-help.js +2 -1
  37. package/dist/src/cli/handlers/help.js +1 -1
  38. package/dist/src/cli/handlers/refresh-bundles.js +2 -1
  39. package/dist/src/cli/handlers/refresh-managed-deployment.js +196 -0
  40. package/dist/src/cli/handlers/refresh.js +10 -2
  41. package/dist/src/cli/handlers/subcommands-discovery.js +8 -1
  42. package/dist/src/cli/handlers/use.js +26 -5
  43. package/dist/src/cli/services/deployment-verification.js +11 -7
  44. package/dist/src/config/decision-config.js +2 -1
  45. package/dist/src/config/jev-credential-reference.js +56 -0
  46. package/dist/src/config/user-config.js +13 -19
  47. package/dist/src/config/worker-write.js +4 -10
  48. package/dist/src/decision/ask.js +3 -2
  49. package/dist/src/decision/jev-credentials.js +22 -0
  50. package/dist/src/decision/ledger.js +15 -15
  51. package/dist/src/decision/offload.js +7 -8
  52. package/dist/src/decision/openbao-kv-resolver.mjs +96 -0
  53. package/dist/src/decision/openbao-runtime.js +101 -0
  54. package/dist/src/delivery/pr.js +2 -0
  55. package/dist/src/delivery/template-sections.js +56 -0
  56. package/dist/src/extensions/claude-hooks-installer.js +61 -53
  57. package/dist/src/extensions/managed-hook-script-state.js +48 -0
  58. package/dist/src/extensions/muse-managed-hooks.js +49 -0
  59. package/dist/src/issues/cli.js +3 -0
  60. package/dist/src/issues/external-cli.js +4 -1
  61. package/dist/src/issues/live.js +9 -2
  62. package/dist/src/issues/local.js +5 -1
  63. package/dist/src/issues/tracker-policy.js +11 -1
  64. package/dist/src/mcp/json-document.d.mts +2 -0
  65. package/dist/src/models/model-capabilities.v1.json +44 -39
  66. package/dist/src/models/model-catalog.v1.json +3 -3
  67. package/dist/src/models/provider-policy.js +8 -0
  68. package/dist/src/models/worker-health-readiness.js +20 -4
  69. package/dist/src/models/worker-health-snapshot.js +29 -0
  70. package/dist/src/models/worker-installation.d.mts +5 -1
  71. package/dist/src/models/worker-installation.mjs +11 -5
  72. package/dist/src/models/worker-qualification-policy.js +54 -0
  73. package/dist/src/providers/capability-matrix.yaml +2 -2
  74. package/dist/src/providers/skill-ownership.d.mts +1 -0
  75. package/dist/src/providers/transformation-receipt-integration.js +4 -2
  76. package/dist/src/providers/transformation-receipt.js +4 -2
  77. package/dist/src/serve/worker-invocation.js +4 -2
  78. package/dist/src/smiths/context-pipeline/workspace-audit.js +34 -17
  79. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +12 -6
  80. package/dist/src/smiths/context-pipeline/workspace-doctor.js +48 -4
  81. package/dist/src/smiths/context-pipeline/workspace-document.js +5 -2
  82. package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -1
  83. package/dist/src/smiths/hook-bridge/codex-translator.js +150 -94
  84. package/dist/src/smiths/hook-bridge/codex-trust.js +50 -0
  85. package/dist/src/smiths/hook-bridge/factory-hook-config.js +132 -0
  86. package/dist/src/smiths/hook-bridge/factory-translator.js +88 -33
  87. package/dist/src/smiths/hook-bridge/factory-trust.js +56 -0
  88. package/dist/src/smiths/hook-bridge/index.js +3 -3
  89. package/dist/src/smiths/hook-bridge/loader.js +10 -2
  90. package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +0 -1
  91. package/dist/src/storage/workspace-permissions-health.js +64 -0
  92. package/dist/src/storage/workspace-permissions.js +51 -0
  93. package/package.json +6 -1
  94. package/tools/agents/providers/base-files.mjs +2 -1
  95. package/tools/agents/providers/base-flat-artifacts.mjs +6 -3
  96. package/tools/agents/providers/base-models-platforms.mjs +3 -3
  97. package/tools/agents/providers/base-skill-copy.mjs +2 -0
  98. package/tools/agents/providers/bound-rules-pointer.mjs +21 -0
  99. package/tools/agents/providers/claude-post-deploy.mjs +9 -5
  100. package/tools/agents/providers/codex-post-deploy.mjs +10 -0
  101. package/tools/agents/providers/factory-hooks.mjs +43 -0
  102. package/tools/agents/providers/factory.mjs +4 -91
  103. package/tools/agents/providers/muse-hooks.mjs +4 -43
  104. package/tools/agents/providers/muse-prompt-discovery.mjs +3 -7
  105. package/tools/agents/providers/packaged-codex-agents.mjs +48 -0
  106. package/tools/agents/providers/rule-delivery-surface.mjs +4 -4
  107. package/tools/agents/providers/rule-presentation.mjs +6 -5
  108. package/tools/agents/providers/rule-projection.mjs +10 -2
  109. package/tools/agents/providers/rule-startup.mjs +8 -1
  110. package/tools/cli/decision-offload-report.mjs +9 -2
  111. package/tools/plugin/issue-template-copies.mjs +24 -0
  112. package/tools/plugin/package-plugins.mjs +17 -4
  113. package/tools/ralph-external/lib/claude-adapter.mjs +2 -2
  114. package/tools/ralph-external/lib/factory-adapter.mjs +7 -8
  115. package/tools/ralph-external/lib/worker-artifacts.mjs +4 -2
  116. package/tools/ralph-external/lib/worker-final.mjs +43 -8
  117. package/tools/ralph-external/lib/worker-launch-cli.mjs +10 -1
  118. package/tools/ralph-external/lib/worker-prompt.mjs +35 -0
  119. package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +8 -0
  120. package/tools/ralph-external/session-launcher.mjs +10 -7
@@ -0,0 +1,196 @@
1
+ // Detect managed hook registration/script drift and outdated rule headers without writes.
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { isDeepStrictEqual } from 'node:util';
5
+ import { lt, valid } from 'semver';
6
+ import { managedClaudeHooks } from '../../extensions/claude-hooks-installer.js';
7
+ import { AIWG_MANAGED_HOOKS } from '../../extensions/muse-managed-hooks.js';
8
+ import { managedHookScriptState } from '../../extensions/managed-hook-script-state.js';
9
+ import { managedFactoryHooks } from '../../smiths/hook-bridge/factory-translator.js';
10
+ import { readFactoryDocument } from '../../smiths/hook-bridge/factory-hook-config.js';
11
+ import { loadHookSources } from '../../smiths/hook-bridge/loader.js';
12
+ import { parseJson } from '../../mcp/json-document.mjs';
13
+ import { getProviderArtifactPathStrings } from '../../providers/provider-definitions.js';
14
+ import * as ui from '../ui.js';
15
+ import { getFortemiCorePrebuiltStatus } from '../../artifacts/fortemi-core-sync.js';
16
+ import { fortemiCorePrebuiltRepairHint } from '../../artifacts/fortemi-core-prebuilt-freshness.js';
17
+ import { inferInstallationMethod } from '../../installation/manager.mjs';
18
+ export function sourcePrebuiltIndexRepairHint(frameworkRoot) {
19
+ if (inferInstallationMethod(frameworkRoot) !== 'source')
20
+ return null;
21
+ const status = getFortemiCorePrebuiltStatus('framework', frameworkRoot);
22
+ if (status.built && !status.stale)
23
+ return null;
24
+ return `${status.reason ?? 'prebuilt framework index is missing'} — ${fortemiCorePrebuiltRepairHint(frameworkRoot)}`;
25
+ }
26
+ async function readJson(file) {
27
+ try {
28
+ const doc = parseJson(await fs.readFile(file, 'utf8'));
29
+ if (!doc || typeof doc !== 'object' || Array.isArray(doc))
30
+ throw new Error('Expected an object');
31
+ return doc;
32
+ }
33
+ catch (error) {
34
+ if (error.code === 'ENOENT')
35
+ return {};
36
+ throw error;
37
+ }
38
+ }
39
+ function groups(doc, event) {
40
+ const hooks = doc.hooks;
41
+ return Array.isArray(hooks?.[event]) ? hooks[event] : [];
42
+ }
43
+ async function staleHooks(projectRoot, frameworkRoot, provider) {
44
+ if (!['claude', 'muse', 'factory'].includes(provider))
45
+ return [];
46
+ const file = provider === 'claude' ? '.claude/settings.json' : `.${provider}/hooks.json`;
47
+ let doc;
48
+ // Factory hooks.json is a top-level event map (older AIWG wrote it nested); normalize both (#3971).
49
+ try {
50
+ doc = provider === 'factory' ? readFactoryDocument(path.join(projectRoot, file)) : await readJson(path.join(projectRoot, file));
51
+ }
52
+ catch {
53
+ return [{ name: `${provider} managed hooks`, file, reason: 'unreadable' }];
54
+ }
55
+ const stale = [];
56
+ if (provider === 'factory') {
57
+ for (const hook of managedFactoryHooks()) {
58
+ const candidates = groups(doc, hook.event).flatMap(group => Array.isArray(group?.hooks) ? group.hooks : [])
59
+ .filter(entry => entry && (entry._aiwg_id === hook.id || entry.command === hook.command));
60
+ if (!candidates.some(entry => entry.type === 'command' && entry.command === hook.command
61
+ && entry._aiwg_managed === true && entry._aiwg_id === hook.id)) {
62
+ stale.push({ name: `${hook.event} → ${hook.id}`, file, reason: candidates.length ? 'outdated' : 'missing' });
63
+ }
64
+ }
65
+ }
66
+ else if (provider === 'claude') {
67
+ const source = path.join(frameworkRoot, 'agentic/code/addons/aiwg-hooks/hooks');
68
+ let sourceFiles;
69
+ try {
70
+ sourceFiles = await fs.readdir(source);
71
+ }
72
+ catch (error) {
73
+ if (error.code === 'ENOENT')
74
+ return [];
75
+ throw error;
76
+ }
77
+ for (const hook of managedClaudeHooks(sourceFiles)) {
78
+ const candidates = groups(doc, hook.event).flatMap(group => Array.isArray(group?.hooks) ? group.hooks : [])
79
+ .filter(entry => entry && (entry._aiwg_id === hook.hookId ||
80
+ (typeof entry.command === 'string' && entry.command.includes(hook.script))));
81
+ const current = candidates.some(entry => entry.type === 'command' && entry.command === hook.command &&
82
+ entry._aiwg_managed === true && entry._aiwg_id === hook.hookId);
83
+ if (!current)
84
+ stale.push({ name: `${hook.event} → ${hook.hookId}`, file, reason: candidates.length ? 'outdated' : 'missing' });
85
+ }
86
+ }
87
+ else {
88
+ // Muse cannot carry in-band ids. Its sidecar supplies identity for older commands.
89
+ let recorded = [];
90
+ try {
91
+ const sidecar = await readJson(path.join(projectRoot, '.muse/.aiwg-hooks.json'));
92
+ if (Array.isArray(sidecar.hooks))
93
+ recorded = sidecar.hooks;
94
+ }
95
+ catch { /* The live document still proves canonical registrations without a sidecar. */ }
96
+ for (const hook of AIWG_MANAGED_HOOKS) {
97
+ const deployed = groups(doc, hook.event);
98
+ if (deployed.some(group => isDeepStrictEqual(group, hook.group)))
99
+ continue;
100
+ const previous = recorded.find(entry => entry?.id === hook.id);
101
+ const exists = deployed.some(group => isDeepStrictEqual(group, previous?.group) ||
102
+ group?.hooks?.some(entry => entry?.command === hook.group.hooks[0].command));
103
+ stale.push({ name: `${hook.event} → ${hook.id}`, file, reason: exists ? 'outdated' : 'missing' });
104
+ }
105
+ }
106
+ return stale;
107
+ }
108
+ async function staleRules(projectRoot, provider, version) {
109
+ const directory = getProviderArtifactPathStrings(provider)?.rules;
110
+ if (!directory || path.isAbsolute(directory) || directory.startsWith('~'))
111
+ return [];
112
+ const stale = [];
113
+ async function visit(relative) {
114
+ let entries;
115
+ try {
116
+ entries = await fs.readdir(path.join(projectRoot, relative), { withFileTypes: true });
117
+ }
118
+ catch (error) {
119
+ if (error.code !== 'ENOENT')
120
+ throw error;
121
+ return;
122
+ }
123
+ await Promise.all(entries.map(async (entry) => {
124
+ const file = path.join(relative, entry.name);
125
+ if (entry.isDirectory())
126
+ return visit(file);
127
+ if (!entry.isFile() || !/\.(md|mdc)$/.test(entry.name))
128
+ return;
129
+ const content = await fs.readFile(path.join(projectRoot, file), 'utf8');
130
+ const marker = /^(?:#|<!--)\s*aiwg:managed\s+v([^\s>]+)([^\r\n]*)/m.exec(content);
131
+ if (!marker || /\bproject-local\b/.test(marker[2]))
132
+ return;
133
+ const older = valid(marker[1]) && valid(version) ? lt(marker[1], version) : marker[1] !== version;
134
+ if (older)
135
+ stale.push({ name: `${file} (v${marker[1]} → v${version})`, file, reason: 'outdated' });
136
+ }));
137
+ }
138
+ await visit(directory);
139
+ return stale;
140
+ }
141
+ async function staleHookScripts(projectRoot, frameworkRoot, provider) {
142
+ const source = path.join(frameworkRoot, 'agentic/code/addons/aiwg-hooks/hooks');
143
+ const scripts = new Map();
144
+ if (provider === 'claude') {
145
+ let files;
146
+ try {
147
+ files = await fs.readdir(source);
148
+ }
149
+ catch (error) {
150
+ if (error.code === 'ENOENT')
151
+ return [];
152
+ throw error;
153
+ }
154
+ for (const hook of managedClaudeHooks(files))
155
+ scripts.set(hook.script, path.join(source, path.basename(hook.script)));
156
+ }
157
+ else if (provider === 'muse') {
158
+ scripts.set('.muse/hooks/aiwg-prompt-discovery.cjs', path.join(source, 'aiwg-prompt-discovery.cjs'));
159
+ }
160
+ else if (provider === 'codex' || provider === 'factory') {
161
+ // Match installCodexPromptDiscovery: resolve packaged canonical arguments,
162
+ // not the portable launcher command emitted into hooks.json.
163
+ const { sources, errors } = await loadHookSources(frameworkRoot);
164
+ if (errors.length)
165
+ throw new Error(errors.join('\n'));
166
+ const hook = sources.find(entry => entry.id === 'aiwg-prompt-discovery');
167
+ if (hook?.args?.[0])
168
+ scripts.set(`.${provider}/hooks/aiwg-prompt-discovery.cjs`, hook.args[0]);
169
+ }
170
+ const stale = [];
171
+ for (const [file, sourceFile] of scripts) {
172
+ // Each provider currently copies these bytes verbatim; registrations may
173
+ // transform commands independently (notably Codex's portable launcher).
174
+ const reason = await managedHookScriptState(projectRoot, file, await fs.readFile(sourceFile));
175
+ if (reason)
176
+ stale.push({ name: file, file, reason });
177
+ }
178
+ return stale;
179
+ }
180
+ export async function checkManagedDeployment(options) {
181
+ const { projectRoot, frameworkRoot, provider, quiet } = options;
182
+ const pkg = await readJson(path.join(frameworkRoot, 'package.json'));
183
+ const [hooks, scripts, rules] = await Promise.all([
184
+ staleHooks(projectRoot, frameworkRoot, provider),
185
+ staleHookScripts(projectRoot, frameworkRoot, provider),
186
+ typeof pkg.version === 'string' ? staleRules(projectRoot, provider, pkg.version) : [],
187
+ ]);
188
+ const stale = [...hooks, ...scripts, ...rules].sort((a, b) => a.name.localeCompare(b.name));
189
+ if (stale.length && !quiet) {
190
+ for (const item of stale)
191
+ ui.warn(`Stale deployment: ${item.reason} ${item.name} — ${item.file}${item.reason === 'operator-edited' ? ' (kept; review operator edits before redeploying)' : ''}`);
192
+ ui.warn(`Fix this deployment: aiwg use all --provider ${provider}`);
193
+ }
194
+ return stale;
195
+ }
196
+ //# sourceMappingURL=refresh-managed-deployment.js.map
@@ -22,6 +22,7 @@ import { createUseHandler } from './use.js';
22
22
  import { automaticRemovalAllowed } from '../../providers/deployment-preservation.mjs';
23
23
  import { refreshDeclaredBundles } from './refresh-bundles.js';
24
24
  import { bundledRuleOutputNames } from './refresh-rule-inventory.js';
25
+ import { checkManagedDeployment, sourcePrebuiltIndexRepairHint } from './refresh-managed-deployment.js';
25
26
  import { getFrameworkRoot } from '../../channel/manager.mjs';
26
27
  import { refreshAllPackages } from '../../packages/registry.js';
27
28
  import { resolveActiveProvider } from '../provider-resolution.js';
@@ -606,6 +607,7 @@ export const refreshHandler = {
606
607
  ui.warn('--prune-tracked has no effect without --prune-other-providers; nothing was removed.');
607
608
  }
608
609
  let staleAgentRemovals = [];
610
+ let staleManagedDeployments = [];
609
611
  let trackedSkipped = [];
610
612
  // A dry run still reports what a real run would remove. Skipping the pass
611
613
  // entirely meant `refresh --dry-run` printed "Checking for stale deployments..."
@@ -688,7 +690,7 @@ export const refreshHandler = {
688
690
  try {
689
691
  const { getFrameworkRoot } = await import('../../channel/manager.mjs');
690
692
  const { join } = await import('path');
691
- const config = await readAiwgConfig(process.cwd());
693
+ const config = await readAiwgConfig(ctx.cwd);
692
694
  if (config) {
693
695
  const MANIFEST_PATHS = {
694
696
  sdlc: 'agentic/code/frameworks/sdlc-complete/manifest.json',
@@ -697,6 +699,7 @@ export const refreshHandler = {
697
699
  research: 'agentic/code/frameworks/research-complete/manifest.json',
698
700
  };
699
701
  const frameworkRoot = await getFrameworkRoot();
702
+ staleManagedDeployments = await checkManagedDeployment({ projectRoot: ctx.cwd, frameworkRoot, provider: detectedProvider, quiet });
700
703
  // Batch-hash manifests in parallel instead of serially awaiting each
701
704
  // one. For ~10 frameworks this cuts refresh latency from ~N*I/O to
702
705
  // max-single-I/O on a warm filesystem (#919 cleanup).
@@ -724,7 +727,7 @@ export const refreshHandler = {
724
727
  : `Deployments current, but ${removed} stale artifact(s) were removed this run — review the list above`);
725
728
  }
726
729
  }
727
- else {
730
+ else if (staleManagedDeployments.length === 0) {
728
731
  if (!quiet)
729
732
  ui.success('All deployments up to date');
730
733
  }
@@ -778,6 +781,9 @@ export const refreshHandler = {
778
781
  }
779
782
  }
780
783
  // Step 5: Health check
784
+ const prebuiltIndexRepair = dryRun ? null : sourcePrebuiltIndexRepairHint(frameworkRoot);
785
+ if (prebuiltIndexRepair && !quiet)
786
+ ui.warn(prebuiltIndexRepair);
781
787
  if (!quiet)
782
788
  ui.info(dryRun ? 'Would run health check...' : 'Running health check...');
783
789
  if (!dryRun) {
@@ -819,8 +825,10 @@ export const refreshHandler = {
819
825
  skipUpdate,
820
826
  channel: channel || undefined,
821
827
  staleAgentRemovals,
828
+ staleManagedDeployments,
822
829
  deploymentFailures,
823
830
  updateFailure,
831
+ prebuiltIndexRepair,
824
832
  });
825
833
  console.log(output);
826
834
  }
@@ -5,7 +5,9 @@ export const indexHandler = {
5
5
  description: "Artifact index commands (build, query, deps, stats)",
6
6
  category: "index",
7
7
  aliases: [],
8
- async help() {
8
+ async help(ctx) {
9
+ if (ctx.args[0] === "discover")
10
+ return discoverHandler.help(ctx);
9
11
  const { printIndexUsage } = await import("../../artifacts/cli.js");
10
12
  printIndexUsage();
11
13
  return { exitCode: 0 };
@@ -67,6 +69,11 @@ export const discoverHandler = {
67
69
  description: "Find AIWG operational assets by capability — index-driven on-demand discovery",
68
70
  category: "index",
69
71
  aliases: [],
72
+ async help() {
73
+ const { printDiscoverUsage } = await import("../../artifacts/discover-cli-help.js");
74
+ printDiscoverUsage();
75
+ return { exitCode: 0 };
76
+ },
70
77
  async execute(ctx) {
71
78
  try {
72
79
  // Delegate to the same handler `aiwg index discover` uses, by
@@ -1,5 +1,7 @@
1
1
  import { ContextWriteJournal } from '../../smiths/context-pipeline/context-file-safety.js';
2
2
  import { trackTemporaryDirectory } from '../../utils/temporary-directory.js';
3
+ import { codexHookTrustNextStep, readCodexHookTrust } from '../../smiths/hook-bridge/codex-trust.js';
4
+ import { factoryHookTrustNextStep, readFactoryHookTrust } from '../../smiths/hook-bridge/factory-trust.js';
3
5
  /**
4
6
  * Use Command Handler
5
7
  *
@@ -1412,6 +1414,9 @@ export function validateUseOptions(args, preparedCapabilities = new Set()) {
1412
1414
  if (USE_FLAGS_WITH_VALUES.has(arg)) {
1413
1415
  if (!args[i + 1] || args[i + 1].startsWith('-'))
1414
1416
  return `Missing value for option '${arg}'. See aiwg use --help.`;
1417
+ if ((arg === '--provider' || arg === '--platform') && args[i + 1].includes(',')) {
1418
+ return `Option '${arg}' accepts one provider. Use --providers for a comma-separated list. See aiwg use --help.`;
1419
+ }
1415
1420
  i++;
1416
1421
  }
1417
1422
  else if (arg.startsWith('-') && !USE_BOOLEAN_FLAGS.has(arg)) {
@@ -2586,6 +2591,18 @@ export class UseHandler {
2586
2591
  result.exitClassification = 'failure';
2587
2592
  }
2588
2593
  }
2594
+ const codexTrustStep = !dryRun && result.exitCode === 0 && requestedScope === 'project' && providers.includes('codex')
2595
+ ? codexHookTrustNextStep(await readCodexHookTrust(projectDir)) : '';
2596
+ if (codexTrustStep)
2597
+ result.findings.push({
2598
+ id: 'codex-prompt-discovery-trust', provider: 'codex', severity: 'info', message: codexTrustStep,
2599
+ });
2600
+ const factoryTrustStep = !dryRun && result.exitCode === 0 && requestedScope === 'project' && providers.includes('factory')
2601
+ ? factoryHookTrustNextStep(await readFactoryHookTrust(projectDir)) : '';
2602
+ if (factoryTrustStep)
2603
+ result.findings.push({
2604
+ id: 'factory-hook-trust', provider: 'factory', severity: 'info', message: factoryTrustStep,
2605
+ });
2589
2606
  if (json) {
2590
2607
  return { exitCode: result.exitCode, message: JSON.stringify(result, null, 2), rawOutput: true };
2591
2608
  }
@@ -2610,7 +2627,7 @@ export class UseHandler {
2610
2627
  });
2611
2628
  return {
2612
2629
  exitCode: result.exitCode,
2613
- message: [coreResult.message, rendered, ...(previewActions ? [...previewActions].sort() : [])].filter(Boolean).join('\n'),
2630
+ message: [coreResult.message, rendered, ...(previewActions ? [...previewActions].sort() : []), codexTrustStep, factoryTrustStep].filter(Boolean).join('\n'),
2614
2631
  };
2615
2632
  }
2616
2633
  async executeCore(ctx, resolvedProviders) {
@@ -2758,10 +2775,14 @@ export class UseHandler {
2758
2775
  : null;
2759
2776
  const projectDir = getProjectDir(ctx, remainingArgs);
2760
2777
  let config = await readAiwgConfig(projectDir);
2761
- if (detectScope(remainingArgs) === 'project' && remainingArgs.includes('--scope')) {
2778
+ // Validate the entire selection before auto-init can persist provider IDs (#3958).
2779
+ {
2762
2780
  for (const requested of configuredGlobalProviders(remainingArgs, config)) {
2763
2781
  const resolved = await resolveProjectLocalProviderAdapter(projectDir, requested);
2764
- if (normalizeProviderDefinitionId(resolved.provider) === 'hermes') {
2782
+ const provider = normalizeProviderDefinitionId(resolved.provider);
2783
+ if (!provider)
2784
+ return { exitCode: 1, message: unsupportedProviderMessage(requested) ?? `Unknown provider: ${requested}` };
2785
+ if (detectScope(remainingArgs) === 'project' && remainingArgs.includes('--scope') && provider === 'hermes') {
2765
2786
  return { exitCode: 1, message: "Hermes does not support --scope project: it discovers skills only under HERMES_HOME/skills (default ~/.hermes/skills). Use --scope user or an isolated HERMES_HOME profile shared with Hermes." };
2766
2787
  }
2767
2788
  }
@@ -4088,10 +4109,10 @@ export class UseHandler {
4088
4109
  // PUW-018 (#1119) cross-provider hook bridge — opt-in via
4089
4110
  // --enable-cross-provider-hooks. When enabled and at least one canonical
4090
4111
  // hook source exists at agentic/code/addons/aiwg-hooks/canonical/*.yaml,
4091
- // translate to provider-native artifacts (Codex TOML, Copilot JSON,
4112
+ // translate to provider-native artifacts (Codex project JSON, Copilot JSON,
4092
4113
  // Factory shell, Hermes Python plugin). Per ADR-3 §7 autoInstall policy
4093
4114
  // this is opt-in.
4094
- if (remainingArgs.includes('--enable-cross-provider-hooks') && !dryRun) {
4115
+ if (remainingArgs.includes('--enable-cross-provider-hooks') && !remainingArgs.includes('--no-hooks') && !dryRun) {
4095
4116
  try {
4096
4117
  const { loadHookSources, bridgeAll } = await import('../../smiths/hook-bridge/index.js');
4097
4118
  const { sources, errors } = await loadHookSources(frameworkRoot);
@@ -594,6 +594,8 @@ export async function verifyProviderDeployment(options) {
594
594
  }
595
595
  const diagnostics = await diagnoseWorkspaceContext(options.projectRoot);
596
596
  for (const diagnostic of diagnostics) {
597
+ if (['codex-prompt-discovery-trust', 'factory-hook-trust'].includes(diagnostic.code))
598
+ continue; // Doctor advisory; use appends its short next step.
597
599
  if (diagnostic.severity === 'info')
598
600
  continue;
599
601
  findings.push(finding(normalized, `context-diagnostic:${diagnostic.code}`, diagnostic.severity === 'error' ? 'blocking' : 'advisory', diagnostic.message, diagnostic.severity === 'error'
@@ -895,13 +897,15 @@ export function renderUseDeploymentResult(result, options = {}) {
895
897
  else {
896
898
  lines.push(' Unavailable — the framework index could not be read.');
897
899
  }
898
- const visibleFindings = result.findings.filter((candidate) => candidate.severity !== 'info');
899
- if (visibleFindings.length > 0) {
900
- lines.push('', result.outcome === 'failed' ? 'Blocking findings' : 'Advisories');
901
- for (const item of visibleFindings) {
902
- lines.push(...wrapParagraph(`${item.provider}: ${item.message}`, width));
903
- if (item.remediation)
904
- lines.push(...wrapParagraph(`Fix: ${item.remediation}`, width, ' '));
900
+ for (const severity of ['blocking', 'advisory']) {
901
+ const visibleFindings = result.findings.filter((candidate) => candidate.severity === severity);
902
+ if (visibleFindings.length > 0) {
903
+ lines.push('', severity === 'blocking' ? 'Blocking findings' : 'Advisories');
904
+ for (const item of visibleFindings) {
905
+ lines.push(...wrapParagraph(`${item.provider}: ${item.message}`, width));
906
+ if (item.remediation)
907
+ lines.push(...wrapParagraph(`Fix: ${item.remediation}`, width, ' '));
908
+ }
905
909
  }
906
910
  }
907
911
  if (options.verbose) {
@@ -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');
@@ -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 (2 levels).
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
- let currentSection = null;
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
- if (indent === 0) {
325
- if (rawValue === '' || rawValue === undefined) {
326
- // Section header
327
- currentSection = key;
328
- if (!Object.hasOwn(result, key)) {
329
- result[key] = {};
330
- }
331
- }
332
- else {
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 if (currentSection && indent >= 2) {
339
- // Nested key under current section
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;
@@ -1,6 +1,7 @@
1
1
  // Shares atomic replacement and serialization across worker configuration owners.
2
+ import { workspaceFileMode, preserveReplacementMode } from '../storage/workspace-permissions.js';
2
3
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { mkdir, writeFile, rename, unlink, stat } from 'node:fs/promises';
4
+ import { mkdir, writeFile, rename, unlink } from 'node:fs/promises';
4
5
  import { statSync, readFileSync } from 'node:fs';
5
6
  import { randomBytes } from 'node:crypto';
6
7
  import { dirname, join } from 'node:path';
@@ -24,17 +25,10 @@ export async function atomicConfigWrite(file, content, assertOwned) {
24
25
  assertOwned?.();
25
26
  await mkdir(dirname(file), { recursive: true });
26
27
  const temporary = `${file}.${randomBytes(6).toString('hex')}.tmp`;
27
- let mode = 0o600;
28
- try {
29
- mode = (await stat(file)).mode;
30
- }
31
- catch (error) {
32
- if (error.code !== 'ENOENT')
33
- throw error;
34
- }
35
28
  try {
36
29
  assertOwned?.();
37
- await writeFile(temporary, content, { encoding: 'utf8', mode });
30
+ await writeFile(temporary, content, { encoding: 'utf8', mode: workspaceFileMode(file), flag: 'wx' });
31
+ await preserveReplacementMode(temporary, file);
38
32
  assertOwned?.();
39
33
  await rename(temporary, file);
40
34
  }
@@ -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');
@@ -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' };