@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.
Files changed (150) hide show
  1. package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +3 -2
  2. package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +12 -9
  3. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +2 -0
  4. package/agentic/code/addons/composition-engine/lib/runtime.mjs +5 -26
  5. package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +22 -0
  6. package/agentic/code/providers/capability-matrix.yaml +17 -20
  7. package/agentic/code/providers/model-capabilities.v1.json +17 -16
  8. package/dist/src/a2a/hitl-authorization.js +46 -0
  9. package/dist/src/a2a/hitl-driver.js +5 -5
  10. package/dist/src/artifacts/browser-export.js +2 -0
  11. package/dist/src/artifacts/framework-source-digest.js +1 -1
  12. package/dist/src/artifacts/index-builder.js +5 -25
  13. package/dist/src/artifacts/index-capability.js +24 -0
  14. package/dist/src/artifacts/query-engine-discover-output.js +8 -3
  15. package/dist/src/artifacts/query-engine-rules.js +27 -9
  16. package/dist/src/artifacts/query-engine-scoring.js +5 -5
  17. package/dist/src/artifacts/query-engine-show-card.js +5 -1
  18. package/dist/src/artifacts/query-engine-show-load.js +1 -1
  19. package/dist/src/artifacts/query-engine-show.js +3 -3
  20. package/dist/src/artifacts/query-engine-templates.js +10 -4
  21. package/dist/src/artifacts/query-engine-verbose.js +18 -4
  22. package/dist/src/artifacts/relations-builder.js +1 -0
  23. package/dist/src/artifacts/types.js +1 -1
  24. package/dist/src/cli/handlers/checkpoint-handoff.js +2 -1
  25. package/dist/src/cli/handlers/dataset.js +17 -0
  26. package/dist/src/cli/handlers/guided-setup.js +3 -1
  27. package/dist/src/cli/handlers/refresh-managed-deployment.js +17 -5
  28. package/dist/src/cli/handlers/rules.js +1 -1
  29. package/dist/src/cli/handlers/sessions.js +1 -1
  30. package/dist/src/cli/handlers/steward.js +1 -1
  31. package/dist/src/cli/handlers/use.js +18 -5
  32. package/dist/src/cli/handlers/utility-doctor.js +5 -2
  33. package/dist/src/cli/handlers/workspace.js +1 -1
  34. package/dist/src/cli/services/deployment-probe-scope.js +40 -0
  35. package/dist/src/cli/services/deployment-verification.js +5 -6
  36. package/dist/src/config/aiwg-config.js +6 -0
  37. package/dist/src/config/authorization-cli.js +61 -3
  38. package/dist/src/config/cli-help.js +1 -1
  39. package/dist/src/config/cli.js +4 -2
  40. package/dist/src/config/decision-config.js +2 -1
  41. package/dist/src/config/host-resource-runtime.mjs +1 -1
  42. package/dist/src/config/jev-credential-reference.js +56 -0
  43. package/dist/src/config/user-config.js +13 -19
  44. package/dist/src/config/user-registry.js +9 -1
  45. package/dist/src/config/worker-owner-lock.js +90 -10
  46. package/dist/src/decision/ask.js +3 -2
  47. package/dist/src/decision/graph-flow-adapter.js +1 -1
  48. package/dist/src/decision/jev-credentials.js +22 -0
  49. package/dist/src/decision/offload.js +1 -1
  50. package/dist/src/decision/openbao-kv-resolver.mjs +96 -0
  51. package/dist/src/decision/openbao-runtime.js +101 -0
  52. package/dist/src/effects/authorization-grant.js +50 -0
  53. package/dist/src/effects/authorization-store.js +130 -0
  54. package/dist/src/effects/index.js +2 -0
  55. package/dist/src/effects/ledger.js +1 -0
  56. package/dist/src/effects/lifecycle.js +1 -1
  57. package/dist/src/effects/reader.js +4 -0
  58. package/dist/src/effects/records.js +4 -0
  59. package/dist/src/effects/schema.js +2 -0
  60. package/dist/src/extensions/claude-hooks-installer.js +7 -7
  61. package/dist/src/extensions/muse-managed-hooks.js +11 -0
  62. package/dist/src/extensions/user-hook-diagnostics.js +32 -0
  63. package/dist/src/extensions/verified-hook-command.js +32 -0
  64. package/dist/src/lint/rule-conflicts.js +52 -0
  65. package/dist/src/lint/runner.js +3 -0
  66. package/dist/src/mcp/cli.mjs +3 -1
  67. package/dist/src/mcp/elicitation.mjs +30 -0
  68. package/dist/src/mcp/grok-build-config.mjs +1 -1
  69. package/dist/src/mcp/muse-native-config.mjs +1 -0
  70. package/dist/src/mcp/server.mjs +2 -0
  71. package/dist/src/mcp/tools/authorization.mjs +78 -0
  72. package/dist/src/models/model-capabilities.v1.json +17 -16
  73. package/dist/src/policy/authorization-capture.js +64 -0
  74. package/dist/src/policy/authorization-operations.js +108 -0
  75. package/dist/src/policy/hitl-check.js +3 -2
  76. package/dist/src/policy/hitl-consume.js +14 -0
  77. package/dist/src/policy/hitl-durable-store.js +60 -0
  78. package/dist/src/policy/hitl-durable.js +60 -0
  79. package/dist/src/policy/hitl-receipt.js +5 -0
  80. package/dist/src/policy/hitl.js +44 -6
  81. package/dist/src/process/bounded-child-process.mjs +49 -39
  82. package/dist/src/providers/capability-matrix.yaml +17 -20
  83. package/dist/src/providers/deployment-ownership.d.mts +1 -0
  84. package/dist/src/providers/deployment-ownership.mjs +21 -2
  85. package/dist/src/providers/grok-build-headless.js +170 -77
  86. package/dist/src/providers/grok-build-inspect.js +1 -0
  87. package/dist/src/providers/grok-build-paths.js +2 -0
  88. package/dist/src/providers/muse-paths.js +4 -2
  89. package/dist/src/providers/provider-context-contracts.js +12 -4
  90. package/dist/src/providers/provider-definition-schema.js +6 -0
  91. package/dist/src/providers/provider-seeds-1.js +3 -3
  92. package/dist/src/providers/provider-seeds-2.js +6 -4
  93. package/dist/src/providers/provider-seeds-3.js +6 -6
  94. package/dist/src/rules/activation.d.mts +2 -0
  95. package/dist/src/rules/activation.mjs +16 -7
  96. package/dist/src/rules/inline-budget.d.mts +2 -1
  97. package/dist/src/rules/inline-budget.mjs +4 -2
  98. package/dist/src/rules/inventory.js +3 -0
  99. package/dist/src/rules/precedence.d.mts +6 -0
  100. package/dist/src/rules/precedence.mjs +49 -0
  101. package/dist/src/rules/project-precedence.js +73 -0
  102. package/dist/src/rules/rule-frontmatter.schema.json +15 -0
  103. package/dist/src/serve/a2a-terminal-observer.js +12 -3
  104. package/dist/src/serve/mission-hitl.js +20 -1
  105. package/dist/src/sessions/adapters/grok-build-fallback.js +33 -0
  106. package/dist/src/sessions/adapters/grok-build-native-records.js +64 -0
  107. package/dist/src/sessions/adapters/grok-build-native.js +92 -100
  108. package/dist/src/sessions/adapters/grok-build.js +65 -24
  109. package/dist/src/sessions/grok-build-cli-output.js +113 -0
  110. package/dist/src/sessions/grok-build-cli.js +4 -28
  111. package/dist/src/smiths/context-pipeline/bridge-ownership.js +4 -3
  112. package/dist/src/smiths/context-pipeline/finalization.js +5 -0
  113. package/dist/src/smiths/context-pipeline/generator.js +1 -1
  114. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +20 -17
  115. package/dist/src/smiths/context-pipeline/workspace-doctor.js +6 -1
  116. package/dist/src/smiths/context-pipeline/workspace-document.js +6 -0
  117. package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -12
  118. package/dist/src/smiths/hook-bridge/codex-translator.js +11 -14
  119. package/dist/src/smiths/hook-bridge/codex-trust.js +7 -2
  120. package/dist/src/smiths/hook-bridge/copilot-translator.js +2 -1
  121. package/dist/src/smiths/hook-bridge/factory-trust.js +56 -0
  122. package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
  123. package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +78 -0
  124. package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
  125. package/dist/src/smiths/hook-bridge/index.js +3 -1
  126. package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +3 -2
  127. package/package.json +7 -1
  128. package/tools/agents/deploy-agents.mjs +5 -6
  129. package/tools/agents/deploy-options.mjs +1 -0
  130. package/tools/agents/providers/base-frontmatter.mjs +3 -2
  131. package/tools/agents/providers/claude-post-deploy.mjs +1 -1
  132. package/tools/agents/providers/codex-post-deploy.mjs +1 -1
  133. package/tools/agents/providers/generic.mjs +66 -0
  134. package/tools/agents/providers/grok-build.mjs +3 -1
  135. package/tools/agents/providers/muse-hooks.mjs +13 -11
  136. package/tools/agents/providers/muse-prompt-discovery.mjs +5 -1
  137. package/tools/agents/providers/muse.mjs +2 -1
  138. package/tools/agents/providers/openclaw.mjs +2 -1
  139. package/tools/agents/providers/rule-deployment-prepare.mjs +5 -3
  140. package/tools/agents/providers/rule-deployment-state.mjs +14 -6
  141. package/tools/agents/providers/rule-startup.mjs +11 -10
  142. package/tools/agents/providers/staged-directory-reference.mjs +14 -0
  143. package/tools/agents/providers/user-hooks.mjs +26 -0
  144. package/tools/cli/authorization-health.mjs +20 -0
  145. package/tools/cli/decision-offload-report.mjs +2 -0
  146. package/tools/cli/workspace-status.mjs +7 -0
  147. package/tools/commands/deploy-prompts-codex.mjs +15 -1
  148. package/tools/plugin/package-plugins.mjs +6 -1
  149. package/tools/ralph-external/lib/claude-adapter.mjs +2 -2
  150. package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
@@ -11,6 +11,24 @@ export const PROVIDER_RULE_AUTHORITY = [
11
11
  'guidance. Platform capability and safety constraints remain absolute; see WORKSPACE.md',
12
12
  '"Precedence" for the capability-versus-directive distinction.',
13
13
  ];
14
+ const PROSE_LOADING = [
15
+ "On a new task, first run discovery for the request (`aiwg discover --stdin <<'AIWG_REQUEST'`, the request, then `AIWG_REQUEST`) before any other tool call or answer. Pass the request literally on heredoc lines, never as a quoted command argument.",
16
+ '',
17
+ 'After discovery, read and follow [WORKSPACE.md](./WORKSPACE.md) for project context.',
18
+ 'Then read [AIWG.md](./AIWG.md) for AIWG discovery, quickrefs, and framework routing.',
19
+ '',
20
+ 'These are explicit reading instructions. Plain Markdown links are not claimed to auto-load.',
21
+ ];
22
+ function wrapProviderBootstrap(loading) {
23
+ return [
24
+ PROVIDER_BOOTSTRAP_START, '', '# Provider workspace bootstrap', '',
25
+ ...loading, ...PROVIDER_RULE_AUTHORITY, '', PROVIDER_BOOTSTRAP_END,
26
+ ].join('\n');
27
+ }
28
+ // Rule projection can use a synthetic corpus without the provider capability matrix.
29
+ export function buildRuleStartupBootstrapBlock() {
30
+ return wrapProviderBootstrap(PROSE_LOADING);
31
+ }
14
32
  export function buildProviderBootstrapBlock(provider) {
15
33
  const definition = getProviderDefinition(provider);
16
34
  const contract = definition?.context;
@@ -34,7 +52,6 @@ export function buildProviderBootstrapBlock(provider) {
34
52
  // is asserted here rather than left to be inferred once WORKSPACE.md loads.
35
53
  // A session directive that arrives later cannot claim precedence it was never
36
54
  // granted (#2512).
37
- const authority = PROVIDER_RULE_AUTHORITY;
38
55
  // #227: Muse gets its own discover-first bridge text — Muse-native
39
56
  // instruction order (this AGENTS.md first, then WORKSPACE.md, then AIWG.md)
40
57
  // plus the trust-gated load caveat — instead of the generic prose-directive.
@@ -52,22 +69,8 @@ export function buildProviderBootstrapBlock(provider) {
52
69
  'WORKSPACE.md and AIWG.md are registered through the provider configuration.',
53
70
  'Read and follow WORKSPACE.md first; use AIWG.md second for AIWG discovery and routing.',
54
71
  ]
55
- : [
56
- 'Read and follow [WORKSPACE.md](./WORKSPACE.md) first.',
57
- 'Then read [AIWG.md](./AIWG.md) for AIWG discovery, quickrefs, and framework routing.',
58
- '',
59
- 'These are explicit reading instructions. Plain Markdown links are not claimed to auto-load.',
60
- ];
61
- return [
62
- PROVIDER_BOOTSTRAP_START,
63
- '',
64
- '# Provider workspace bootstrap',
65
- '',
66
- ...loading,
67
- ...authority,
68
- '',
69
- PROVIDER_BOOTSTRAP_END,
70
- ].join('\n');
72
+ : PROSE_LOADING;
73
+ return wrapProviderBootstrap(loading);
71
74
  }
72
75
  export const PROVIDER_BOOTSTRAP_HEADING = '# Provider workspace bootstrap';
73
76
  /**
@@ -7,7 +7,9 @@ import { auditWorkspaceContext } from './workspace-audit.js';
7
7
  import { PROVIDER_BOOTSTRAP_START, readOptional, resolveProjectRelative, WORKSPACE_MANAGED_START, WORKSPACE_OPERATOR_START, WORKSPACE_SIGNATURE, } from './workspace-context-shared.js';
8
8
  import { BOOTSTRAP_AUTHORITY_SIGNATURE, WORKSPACE_PRECEDENCE_SIGNATURE, WORKSPACE_PRECEDENCE_SUPERSEDED } from './workspace-document.js';
9
9
  import { configuredProviders } from './workspace-migration.js';
10
+ import { diagnoseUserHookCommands } from '../../extensions/user-hook-diagnostics.js';
10
11
  import { diagnoseCodexHookTrust } from '../hook-bridge/codex-trust.js';
12
+ import { diagnoseFactoryHookTrust } from '../hook-bridge/factory-trust.js';
11
13
  import { maskCodeRegions } from './code-regions.js';
12
14
  export { maskCodeRegions } from './code-regions.js';
13
15
  export function markdownLinks(content) {
@@ -36,10 +38,13 @@ export async function workspaceLinkedFiles(projectPath) {
36
38
  return [...new Set(files)].sort();
37
39
  }
38
40
  export async function diagnoseWorkspaceContext(projectPath) {
39
- const diagnostics = [];
41
+ const diagnostics = await diagnoseUserHookCommands();
40
42
  const codexTrust = await diagnoseCodexHookTrust(projectPath);
41
43
  if (codexTrust)
42
44
  diagnostics.push(codexTrust);
45
+ const factoryTrust = await diagnoseFactoryHookTrust(projectPath);
46
+ if (factoryTrust)
47
+ diagnostics.push(factoryTrust);
43
48
  const root = path.resolve(projectPath);
44
49
  const scopes = new Map();
45
50
  // Ordinary subdirectories share root policy; repository/project markers start a separate scope.
@@ -1,3 +1,5 @@
1
+ import { projectRulePrecedenceText } from '../../rules/project-precedence.js';
2
+ import { RULE_PRECEDENCE_TEXT } from '../../rules/precedence.mjs';
1
3
  // Render and preserve the canonical WORKSPACE document and resident memory.
2
4
  import * as path from 'node:path';
3
5
  import { readAiwgConfigCandidate } from '../../config/aiwg-config.js';
@@ -94,6 +96,7 @@ export async function providerCopiesStatus(projectPath) {
94
96
  }
95
97
  export function buildWorkspaceManagedBlock(projectPath, providerFiles = [], residentMemory = '') {
96
98
  const links = workspaceLinks(projectPath, providerFiles);
99
+ const ordering = projectRulePrecedenceText(projectPath);
97
100
  return [
98
101
  WORKSPACE_MANAGED_START,
99
102
  '',
@@ -119,6 +122,9 @@ export function buildWorkspaceManagedBlock(projectPath, providerFiles = [], resi
119
122
  'constraint. "Format commits this way" is a directive, and an AIWG rule on commit content wins.',
120
123
  'When a directive and an AIWG rule conflict, follow the rule and say plainly that you did.',
121
124
  '',
125
+ RULE_PRECEDENCE_TEXT,
126
+ ...(ordering ? ['', ordering] : []),
127
+ '',
122
128
  '### Ownership',
123
129
  '',
124
130
  '- Edit project-neutral notes only inside the protected Project Context section below.',
@@ -9,7 +9,7 @@ import { writeContextFileSync } from './context-file-safety.js';
9
9
  import { readAiwgOperatorNotes } from './finalization.js';
10
10
  import { auditWorkspaceContext } from './workspace-audit.js';
11
11
  import { buildProviderBootstrapFile } from './workspace-bootstrap.js';
12
- import { atomicWrite, PROJECT_CONTEXT_PLACEHOLDER, PROVIDER_BOOTSTRAP_END, PROVIDER_BOOTSTRAP_START, readOptional, resolveProjectRelative, sha256, WORKSPACE_SIGNATURE, } from './workspace-context-shared.js';
12
+ import { atomicWrite, PROJECT_CONTEXT_PLACEHOLDER, readOptional, resolveProjectRelative, sha256, } from './workspace-context-shared.js';
13
13
  import { buildWorkspaceDocument, residentMemoryForRegeneration } from './workspace-document.js';
14
14
  import { extractExistingProjectContext, mergeProjectExtraction } from './workspace-extraction.js';
15
15
  export function projectOutputPath(projectPath, absPath) {
@@ -94,17 +94,7 @@ export async function stageMigrationWrites(projectPath, audit, options = {}) {
94
94
  // Shared AGENTS.md is deliberately provider-neutral prose so sequential
95
95
  // multi-provider deployment cannot make the last provider win.
96
96
  const provider = targetProviderIds.length === 1 ? targetProviderIds[0] : 'generic';
97
- const content = provider === 'generic'
98
- ? [
99
- '# Provider workspace bootstrap', WORKSPACE_SIGNATURE,
100
- '<!-- Generated by AIWG. Project/operator context belongs in WORKSPACE.md. -->', '',
101
- PROVIDER_BOOTSTRAP_START, '',
102
- 'Read and follow [WORKSPACE.md](./WORKSPACE.md) first.',
103
- 'Then read [AIWG.md](./AIWG.md) for AIWG discovery and framework routing.',
104
- 'These are explicit reading instructions; a plain Markdown link is not claimed to auto-load.', '',
105
- PROVIDER_BOOTSTRAP_END, '',
106
- ].join('\n')
107
- : buildProviderBootstrapFile(provider);
97
+ const content = buildProviderBootstrapFile(provider);
108
98
  writes.set(target, content);
109
99
  }
110
100
  // Any detected operator-owned root startup file participates in the explicit
@@ -4,6 +4,7 @@ import * as path from 'node:path';
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { substituteEnvVars } from './shim.js';
6
6
  import { loadHookSources } from './loader.js';
7
+ import { verifiedHookCommand } from '../../extensions/verified-hook-command.js';
7
8
  import { tomlString } from '../../mcp/toml-string.mjs';
8
9
  // Verified with the installed 0.165.0 app-server hooks/list. Config keys use
9
10
  // PascalCase; snake_case names (user_prompt_submit, pre_tool_use, etc.) are IDs
@@ -12,15 +13,6 @@ const CODEX_EVENTS = new Set([
12
13
  'PreToolUse', 'PostToolUse', 'UserPromptSubmit', 'SessionStart', 'SessionEnd',
13
14
  'PermissionRequest', 'PreCompact', 'PostCompact', 'SubagentStart', 'SubagentStop', 'Stop',
14
15
  ]);
15
- // Codex runs hooks in the session cwd, which may be below the hooks.json root.
16
- const PROMPT_DISCOVERY_LAUNCHER = [
17
- 'const fs=require("node:fs"),path=require("node:path");',
18
- 'for(let dir=process.cwd();;dir=path.dirname(dir)){',
19
- 'const script=path.join(dir,".codex/hooks/aiwg-prompt-discovery.cjs");',
20
- 'if(fs.existsSync(script)){require(script);break;}',
21
- 'if(path.dirname(dir)===dir)break;',
22
- '}',
23
- ].join('');
24
16
  function shellArgument(value, expandEnvironment = true) {
25
17
  // Preserve environment references, but never evaluate argument substitutions.
26
18
  const escaped = value.replace(/[\\"`$]/g, '\\$&');
@@ -28,9 +20,9 @@ function shellArgument(value, expandEnvironment = true) {
28
20
  ? escaped.replace(/\\\$(\{[A-Z_][A-Z0-9_]*\}|[A-Z_][A-Z0-9_]*)/g, '$$$1') : escaped;
29
21
  return `"${argument}"`;
30
22
  }
31
- function commandHook(source, literalArgs = false) {
23
+ function commandHook(source) {
32
24
  const command = substituteEnvVars(source.command, 'codex');
33
- const args = (source.args || []).map(a => shellArgument(substituteEnvVars(a, 'codex'), !literalArgs));
25
+ const args = (source.args || []).map(a => shellArgument(substituteEnvVars(a, 'codex')));
34
26
  return {
35
27
  type: 'command', command: [command, ...args].join(' '),
36
28
  ...(source.timeout === undefined ? {} : { timeout: source.timeout }),
@@ -105,7 +97,7 @@ export async function translateForCodex(source, options) {
105
97
  const events = source.events.filter(event => CODEX_EVENTS.has(event));
106
98
  if (!events.length)
107
99
  return { ...result, skipped: true, skipReason: 'no Codex-mapped events' };
108
- const directory = path.join(options.projectPath, '.codex');
100
+ const directory = options.hookDirectory ?? path.join(options.projectPath, '.codex');
109
101
  const configPath = path.join(directory, 'hooks.json');
110
102
  const promptHook = source.id === 'aiwg-prompt-discovery';
111
103
  const scriptPath = path.join(directory, 'hooks', 'aiwg-prompt-discovery.cjs');
@@ -153,10 +145,15 @@ export async function translateForCodex(source, options) {
153
145
  throw new Error('Prompt discovery source is missing its shared script');
154
146
  await fs.mkdir(path.dirname(scriptPath), { recursive: true });
155
147
  await fs.copyFile(source.args[0], scriptPath);
156
- source = { ...source, args: ['-e', PROMPT_DISCOVERY_LAUNCHER] };
148
+ }
149
+ const hook = commandHook(source);
150
+ if (promptHook) {
151
+ const anchor = options.hookDirectory ? directory : options.commandRoot ?? options.projectPath;
152
+ hook.command = verifiedHookCommand(anchor, path.relative(options.hookDirectory ? directory : options.projectPath, scriptPath).replaceAll('\\', '/'), await fs.readFile(scriptPath), [], options.scope);
153
+ hook.statusMessage = 'AIWG prompt discovery';
157
154
  }
158
155
  for (const event of events)
159
- (hooks[event] ??= []).push({ hooks: [commandHook(source, promptHook)] });
156
+ (hooks[event] ??= []).push({ hooks: [hook] });
160
157
  doc.hooks = hooks;
161
158
  await fs.mkdir(directory, { recursive: true });
162
159
  if (existing && !managed) {
@@ -3,7 +3,12 @@ import { promises as fs } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import * as path from 'node:path';
5
5
  import { getStaticTOMLValue, parseTOML } from 'toml-eslint-parser';
6
- export const CODEX_HOOK_TRUST_NEXT_STEP = 'Trust this project in Codex, then approve the AIWG hook when Codex asks.';
6
+ // Printed after deploy: one line that fits an 80-column terminal.
7
+ export const CODEX_HOOK_TRUST_NEXT_STEP = 'Trust this project in Codex and approve its AIWG hook; codex exec needs both.';
8
+ // Full explanation for doctor and docs (#4035).
9
+ export const CODEX_EXEC_HOOK_TRUST_DETAIL = 'Codex 0.167 requires saved folder and hook trust for codex exec; a per-run -c project trust override '
10
+ + 'does not enable project hooks, even with --dangerously-bypass-hook-trust. '
11
+ + 'Review and save trust interactively for each worker worktree before automation; AIWG never grants trust.';
7
12
  export function codexHookTrustNextStep(trust) {
8
13
  return trust && (trust.project !== 'trusted' || trust.hookReview !== 'approved')
9
14
  ? CODEX_HOOK_TRUST_NEXT_STEP : '';
@@ -44,7 +49,7 @@ export async function diagnoseCodexHookTrust(projectPath) {
44
49
  // Review state is never observable offline, so a trusted project is only advisory.
45
50
  severity: trust.project === 'trusted' ? 'info' : 'warning', code: 'codex-prompt-discovery-trust', path: '.codex/hooks.json',
46
51
  message: 'Codex prompt-discovery hook installed but inactive or unverified (untrusted project or unreviewed hook). '
47
- + `Project trust: ${trust.project}; hook review: ${trust.hookReview}. ${nextStep}`,
52
+ + `Project trust: ${trust.project}; hook review: ${trust.hookReview}. ${nextStep} ${CODEX_EXEC_HOOK_TRUST_DETAIL}`,
48
53
  } : null;
49
54
  }
50
55
  //# sourceMappingURL=codex-trust.js.map
@@ -11,6 +11,7 @@
11
11
  import { promises as fs } from 'node:fs';
12
12
  import * as path from 'node:path';
13
13
  import { substituteEnvVars } from './shim.js';
14
+ import { PROMPT_DISCOVERY_GAPS } from './prompt-discovery-gaps.js';
14
15
  const COPILOT_EVENT_MAP = {
15
16
  PreToolUse: 'pre_tool_use',
16
17
  PostToolUse: 'post_tool_use',
@@ -28,7 +29,7 @@ export async function translateForCopilot(source, options) {
28
29
  };
29
30
  if (source.degradeOn?.includes('copilot')) {
30
31
  result.skipped = true;
31
- result.skipReason = 'degrade-on declared copilot';
32
+ result.skipReason = source.id === 'aiwg-prompt-discovery' ? PROMPT_DISCOVERY_GAPS.copilot : 'degrade-on declared copilot';
32
33
  return result;
33
34
  }
34
35
  const hooksDir = path.join(options.projectPath, '.github', 'hooks');
@@ -0,0 +1,56 @@
1
+ // Read Factory project hook prerequisites without granting trust or creating commits.
2
+ import { execFile } from 'node:child_process';
3
+ import { promises as fs } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import path from 'node:path';
6
+ import { promisify } from 'node:util';
7
+ import { isFactoryManaged, readFactoryDocument } from './factory-hook-config.js';
8
+ const execFileAsync = promisify(execFile);
9
+ export const FACTORY_HOOK_TRUST_NEXT_STEP = 'Trust this folder in droid; project hooks load only in a git repository with at least one commit.';
10
+ export function factoryHookTrustNextStep(trust) {
11
+ return trust && (trust.project !== 'trusted' || !trust.gitCommit) ? FACTORY_HOOK_TRUST_NEXT_STEP : '';
12
+ }
13
+ export async function readFactoryHookTrust(projectPath) {
14
+ const root = path.resolve(projectPath);
15
+ try {
16
+ const doc = readFactoryDocument(path.join(root, '.factory/hooks.json'));
17
+ if (!Object.values(doc.hooks ?? {}).some(groups => groups.some(group => group.hooks.some(hook => hook.type === 'command' && isFactoryManaged(hook)))))
18
+ return null;
19
+ }
20
+ catch {
21
+ // Missing/broken installations are handled by deployment drift checks.
22
+ return null;
23
+ }
24
+ const trust = { project: 'unknown', gitCommit: false };
25
+ try {
26
+ const config = JSON.parse(await fs.readFile(path.join(process.env.HOME || homedir(), '.factory/settings.json'), 'utf8'));
27
+ const folders = config?.trustedFolders;
28
+ // Droid records trust as object keys; values are not trust booleans.
29
+ if (folders && typeof folders === 'object' && !Array.isArray(folders)) {
30
+ trust.project = Object.hasOwn(folders, root) ? 'trusted' : 'untrusted';
31
+ }
32
+ }
33
+ catch {
34
+ // Missing, unreadable, or malformed settings cannot establish trust.
35
+ }
36
+ try {
37
+ await execFileAsync('git', ['rev-parse', '--verify', 'HEAD'], {
38
+ cwd: root, timeout: 2000, maxBuffer: 4096, windowsHide: true,
39
+ });
40
+ trust.gitCommit = true;
41
+ }
42
+ catch {
43
+ // Non-repositories, unborn HEAD, missing git, and timeouts leave this unverified.
44
+ }
45
+ return trust;
46
+ }
47
+ export async function diagnoseFactoryHookTrust(projectPath) {
48
+ const trust = await readFactoryHookTrust(projectPath);
49
+ const nextStep = factoryHookTrustNextStep(trust);
50
+ return trust && nextStep ? {
51
+ severity: 'warning', code: 'factory-hook-trust', path: '.factory/hooks.json',
52
+ message: 'Factory project hooks installed but inactive or unverified. '
53
+ + `Project trust: ${trust.project}; Git commit: ${trust.gitCommit ? 'present' : 'missing or unverified'}. ${nextStep}`,
54
+ } : null;
55
+ }
56
+ //# sourceMappingURL=factory-trust.js.map
@@ -1,6 +1,7 @@
1
1
  /** Grok Build hook translator. Deployment writes project JSON only; trust remains an operator action. */
2
2
  import { promises as fs } from 'node:fs';
3
3
  import * as path from 'node:path';
4
+ import { PROMPT_DISCOVERY_GAPS } from './prompt-discovery-gaps.js';
4
5
  export const GROK_EVENT_MAP = {
5
6
  SessionStart: 'SessionStart',
6
7
  SessionEnd: 'SessionEnd',
@@ -15,7 +16,8 @@ function safeId(id) {
15
16
  export async function translateForGrokBuild(source, options) {
16
17
  const result = { provider: 'grok-build', emittedPaths: [], warnings: [], skipped: false };
17
18
  if (source.degradeOn?.includes('grok-build'))
18
- return { ...result, skipped: true, skipReason: 'degrade-on declared grok-build' };
19
+ return { ...result, skipped: true,
20
+ skipReason: source.id === 'aiwg-prompt-discovery' ? PROMPT_DISCOVERY_GAPS['grok-build'] : 'degrade-on declared grok-build' };
19
21
  const id = safeId(source.id);
20
22
  if (!id)
21
23
  return { ...result, skipped: true, skipReason: 'hook id is not a safe Grok file name' };
@@ -0,0 +1,78 @@
1
+ // Deploy prompt discovery through Hermes's documented pre_llm_call shell hook.
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { isMap, isSeq, parseDocument } from 'yaml';
5
+ import { resolveHermesHomePath } from '../../providers/hermes-home.js';
6
+ import { captureDeploymentOutputs, recordDeploymentOutputs } from '../../providers/deployment-ownership.mjs';
7
+ import { managedHookScriptState } from '../../extensions/managed-hook-script-state.js';
8
+ export async function translateHermesPromptDiscovery(source, options) {
9
+ const home = resolveHermesHomePath();
10
+ const directory = path.join(home, 'agent-hooks');
11
+ const script = path.join(directory, 'aiwg-prompt-discovery.cjs');
12
+ const config = path.join(home, 'config.yaml');
13
+ const result = { provider: 'hermes', skipped: false, warnings: [], emittedPaths: [] };
14
+ if (options.dryRun)
15
+ return { ...result, emittedPaths: [script, config].map(file => `${file} (dry-run)`) };
16
+ for (const file of [home, directory, script, config]) {
17
+ try {
18
+ if ((await fs.lstat(file)).isSymbolicLink())
19
+ throw new Error(`Refusing symlinked Hermes hook target: ${file}`);
20
+ }
21
+ catch (error) {
22
+ if (error.code !== 'ENOENT')
23
+ throw error;
24
+ }
25
+ }
26
+ const original = await fs.readFile(config, 'utf8').catch(error => {
27
+ if (error.code !== 'ENOENT')
28
+ throw error;
29
+ return '';
30
+ });
31
+ const doc = parseDocument(original || '{}');
32
+ if (doc.errors.length || !isMap(doc.contents))
33
+ throw new Error(`Invalid Hermes config: ${config}`);
34
+ if (!doc.has('hooks'))
35
+ doc.set('hooks', doc.createNode({}));
36
+ const hooks = doc.get('hooks', true);
37
+ if (!isMap(hooks))
38
+ throw new Error('Invalid Hermes hooks mapping');
39
+ if (!hooks.has('pre_llm_call'))
40
+ hooks.set('pre_llm_call', doc.createNode([]));
41
+ const entries = hooks.get('pre_llm_call', true);
42
+ if (!isSeq(entries) || entries.items.some(entry => !isMap(entry) || typeof entry.get('command') !== 'string')) {
43
+ throw new Error('Invalid Hermes pre_llm_call hooks');
44
+ }
45
+ const quote = (value) => `'${value.replaceAll("'", "'\"'\"'")}'`;
46
+ const registration = { command: `node ${quote(script)}`, timeout: source.timeout ?? 2,
47
+ _aiwg_managed: true, _aiwg_id: source.id };
48
+ const managed = entries.items.filter(entry => isMap(entry) && entry.get('_aiwg_managed') === true && entry.get('_aiwg_id') === source.id);
49
+ const current = managed[0];
50
+ // Leave matching nodes intact to preserve comments and byte-stable redeployment.
51
+ if (managed.length !== 1 || !isMap(current) || JSON.stringify(current.toJSON()) !== JSON.stringify(registration)) {
52
+ entries.items = entries.items.filter(entry => !managed.includes(entry));
53
+ entries.add(doc.createNode(registration));
54
+ }
55
+ const sourceScript = source.args?.[0];
56
+ if (!sourceScript)
57
+ throw new Error('Missing shared prompt discovery script');
58
+ const bytes = await fs.readFile(sourceScript);
59
+ const roots = [config, directory, path.join(home, '.aiwg-manifest.json')];
60
+ const before = captureDeploymentOutputs(roots);
61
+ const state = await managedHookScriptState(home, path.relative(home, script), bytes);
62
+ if (state === 'operator-edited' || state === 'unreadable')
63
+ result.warnings.push(`${script}: kept (${state})`);
64
+ else {
65
+ await fs.mkdir(directory, { recursive: true });
66
+ if (state)
67
+ await fs.writeFile(script, bytes, { mode: 0o755 });
68
+ result.emittedPaths.push(script);
69
+ }
70
+ const text = doc.toString();
71
+ if (text !== original)
72
+ await fs.writeFile(config, text);
73
+ result.emittedPaths.push(config);
74
+ recordDeploymentOutputs(before, roots, { frameworkSlug: 'aiwg-hooks', claimUnchangedSettings: false, writtenFiles: result.emittedPaths });
75
+ result.warnings.push('Hermes pre_llm_call hook configured; approve the command in Hermes before use. Consent and safe mode are unchanged.');
76
+ return result;
77
+ }
78
+ //# sourceMappingURL=hermes-prompt-discovery.js.map
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * Prompt discovery uses documented pre_llm_call shell hooks and native context JSON.
2
3
  * Hermes hook translator — emits a Python plugin stub at
3
4
  * ~/.hermes/plugins/<id>.py that registers itself with Hermes' Python
4
5
  * plugin system and shells out to the AIWG hook command.
@@ -11,7 +12,7 @@ import { promises as fs } from 'node:fs';
11
12
  import * as path from 'node:path';
12
13
  import { homedir } from 'node:os';
13
14
  import { substituteEnvVars } from './shim.js';
14
- import { PROMPT_DISCOVERY_GAPS } from './prompt-discovery-gaps.js';
15
+ import { translateHermesPromptDiscovery } from './hermes-prompt-discovery.js';
15
16
  const HERMES_EVENT_MAP = {
16
17
  PreToolUse: 'pre_tool',
17
18
  PostToolUse: 'post_tool',
@@ -64,10 +65,11 @@ export async function translateForHermes(source, options) {
64
65
  };
65
66
  if (source.degradeOn?.includes('hermes')) {
66
67
  result.skipped = true;
67
- result.skipReason = source.id === 'aiwg-prompt-discovery'
68
- ? PROMPT_DISCOVERY_GAPS['hermes'] : 'degrade-on declared hermes';
68
+ result.skipReason = 'degrade-on declared hermes';
69
69
  return result;
70
70
  }
71
+ if (source.id === 'aiwg-prompt-discovery')
72
+ return translateHermesPromptDiscovery(source, options);
71
73
  const events = source.events
72
74
  .map((e) => HERMES_EVENT_MAP[e])
73
75
  .filter((e) => Boolean(e));
@@ -18,6 +18,7 @@ import { translateForFactory } from './factory-translator.js';
18
18
  import { translateForHermes } from './hermes-translator.js';
19
19
  import { translateForGrokBuild } from './grok-build-translator.js';
20
20
  import { getProviderDefinition } from '../../providers/provider-definitions.js';
21
+ import { resolveHermesHomePath } from '../../providers/hermes-home.js';
21
22
  export { AIWG_ENV_VARS, NATIVE_ENV_VAR_MAP } from './types.js';
22
23
  export { substituteEnvVars, generateShimBash, EXIT_CODE_MAP } from './shim.js';
23
24
  export { translateForCodex, renderCodexHookToml, injectHookBlock as injectCodexHookBlock } from './codex-translator.js';
@@ -68,7 +69,8 @@ export async function bridgeAll(sources, providers, options) {
68
69
  try {
69
70
  const roots = [path.join(options.projectPath, '.factory/hooks'), path.join(options.projectPath, '.factory/hooks.json'), path.join(options.projectPath, '.github/hooks'),
70
71
  path.join(options.projectPath, '.grok/hooks'), path.join(options.projectPath, '.codex/hooks.json'), path.join(options.projectPath, '.codex/hooks'),
71
- path.join(homedir(), '.hermes/plugins')];
72
+ path.join(homedir(), '.hermes/plugins'), resolveHermesHomePath('config.yaml'), resolveHermesHomePath('agent-hooks'),
73
+ resolveHermesHomePath('.aiwg-manifest.json')];
72
74
  const before = options.dryRun ? undefined : captureDeploymentOutputs(roots);
73
75
  const r = await translator(source, options);
74
76
  if (before)
@@ -1,5 +1,6 @@
1
- // Explain prompt discovery gaps where an event mapping has no context contract.
1
+ // Explain bootstrap fallbacks where an event mapping has no prompt context contract.
2
2
  export const PROMPT_DISCOVERY_GAPS = {
3
- hermes: 'Prompt discovery unavailable: the Hermes bridge returns an exit code without forwarding prompt JSON or injecting additionalContext.',
3
+ copilot: 'Prompt discovery uses the .github/copilot-instructions.md bootstrap rule; installed help documents no prompt-context injection contract.',
4
+ 'grok-build': 'Prompt discovery uses the AGENTS.md bootstrap rule; Grok discards allowing UserPromptSubmit stdout (no additionalContext).',
4
5
  };
5
6
  //# sourceMappingURL=prompt-discovery-gaps.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwg/cli",
3
- "version": "2026.11.2",
3
+ "version": "2026.11.4",
4
4
  "description": "Lightweight AIWG CLI for signed, versioned web-backed resources.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,6 +32,7 @@
32
32
  "agentic/code/addons/aiwg-utils/rules/anti-laziness.md",
33
33
  "agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md",
34
34
  "agentic/code/addons/composition-engine/lib/runtime.mjs",
35
+ "agentic/code/addons/composition-engine/lib/authority.mjs",
35
36
  "agentic/code/addons/composition-engine/lib/validator.mjs",
36
37
  "agentic/code/addons/composition-engine/schemas/flow-graph.schema.json",
37
38
  "schemas/security/",
@@ -41,6 +42,7 @@
41
42
  "schemas/models/",
42
43
  "vscode-extension/schemas/aiwg.config.v1.json",
43
44
  "dist/src/",
45
+ "dist/src/cli/services/deployment-probe-scope.js",
44
46
  "!dist/**/*.d.ts",
45
47
  "!dist/**/*.map",
46
48
  "dist/src/api/index.d.ts",
@@ -57,6 +59,7 @@
57
59
  "tools/ralph-external/lib/behavior-registry.mjs",
58
60
  "tools/warp/warp-content.mjs",
59
61
  "tools/cli/decision-offload-report.mjs",
62
+ "tools/cli/authorization-health.mjs",
60
63
  "tools/cli/workspace-status.mjs",
61
64
  "tools/ralph-external/session-launcher.mjs",
62
65
  "tools/ralph-external/process-monitor.mjs",
@@ -106,6 +109,9 @@
106
109
  "tools/agents/deploy-options.mjs",
107
110
  "tools/agents/deploy-support.mjs",
108
111
  "tools/agents/use-rule-selection.mjs",
112
+ "dist/src/extensions/verified-hook-command.js",
113
+ "dist/src/extensions/user-hook-diagnostics.js",
114
+ "tools/agents/providers/user-hooks.mjs",
109
115
  "tools/agents/providers/",
110
116
  "tools/providers/antigravity-transport.mjs",
111
117
  "tools/commands/deploy-prompts-codex.mjs",
@@ -101,7 +101,7 @@ const PROVIDER_ALIASES = {
101
101
  'dsh': 'deepseek-harness',
102
102
  };
103
103
 
104
- const AVAILABLE_PROVIDERS = ['antigravity', 'claude', 'factory', 'codex', 'opencode', 'copilot', 'cursor', 'flue', 'pi', 'omp', 'deepseek-harness', 'warp', 'windsurf', 'hermes', 'openclaw', 'openhuman', 'grokbot', 'grok-build', 'muse'];
104
+ const AVAILABLE_PROVIDERS = ['antigravity', 'claude', 'factory', 'codex', 'opencode', 'copilot', 'cursor', 'flue', 'pi', 'omp', 'deepseek-harness', 'warp', 'windsurf', 'hermes', 'openclaw', 'openhuman', 'grokbot', 'grok-build', 'muse', 'generic'];
105
105
 
106
106
  const UNSUPPORTED_PROVIDER_HINTS = {
107
107
  'devin-cli': [
@@ -369,7 +369,7 @@ async function mainUnlocked(args, internal) {
369
369
  try {
370
370
  if (!internal.finalizeOnly) {
371
371
  if (cfg.kernelOnly && (!cfg.deferRuleProjection || preparationActive)
372
- && !['claude', 'codex', 'cursor', 'hermes', 'warp', 'openclaw', 'flue', 'pi', 'copilot', 'factory', 'opencode', 'windsurf', 'antigravity', 'muse', 'omp', 'grok-build'].includes(provider.name)) {
372
+ && !['claude', 'codex', 'cursor', 'hermes', 'warp', 'openclaw', 'flue', 'pi', 'copilot', 'factory', 'opencode', 'windsurf', 'antigravity', 'muse', 'omp', 'grok-build', 'generic'].includes(provider.name)) {
373
373
  const { deployWithRuleDelivery } = await import('./providers/rule-delivery.mjs');
374
374
  await deployWithRuleDelivery(opts, provider, staged => provider.deploy(staged));
375
375
  } else await provider.deploy(opts);
@@ -377,10 +377,9 @@ async function mainUnlocked(args, internal) {
377
377
  if (preparationActive) return;
378
378
 
379
379
  // User settings are outside staging: write only after a real promotion.
380
- if (provider.name === 'claude' && cfg.userScope && !cfg.dryRun && cfg.attribution !== false) {
381
- const { installAiwgHooks } = await importImpl(import.meta.url, 'extensions/claude-hooks-installer.js');
382
- const result = await installAiwgHooks({ projectPath: os.homedir(), frameworkRoot: srcRoot, hooks: false });
383
- for (const warning of result?.warnings || []) console.warn(`Claude settings: ${warning}`);
380
+ if (cfg.userScope && !cfg.dryRun) {
381
+ const { installUserHooks } = await import('./providers/user-hooks.mjs');
382
+ await installUserHooks(provider.name, cfg);
384
383
  }
385
384
 
386
385
  const mirroredCommandCount = mirrorSkillsAsCommands(provider, cfg.target, srcRoot, opts);
@@ -234,6 +234,7 @@ Providers (all deploy agents, commands, skills, and rules):
234
234
  grokbot - Grok Bot (AGENTS.md bridge; skills only with AIWG_GROKBOT_SKILLS_DIR)
235
235
  grok-build - Grok Build (experimental; .grok paths + $GROK_HOME; no bare grok alias)
236
236
  muse - Muse Code (stable; AGENTS.md bridge; .agents/skills + XDG user root; managed hooks, opt-in --mcp; no aliases)
237
+ generic - Portable Markdown (AGENTS.md + rules; .agents/skills kernel; host must load explicitly)
237
238
  hermes - Hermes Agent (MCP-based integration)
238
239
  Skills: $HERMES_HOME/skills/ (user-global; defaults to ~/.hermes/skills/) | Agents: AGENTS.md
239
240
  Commands/Rules: served via MCP, not file-deployed
@@ -7,12 +7,13 @@ import { path } from './base-runtime.mjs';
7
7
  * Returns { frontmatter: string, body: string, metadata: object }
8
8
  */
9
9
  export function parseFrontmatter(content) {
10
- const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
10
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
11
11
  if (!fmMatch) {
12
12
  return { frontmatter: null, body: content, metadata: {} };
13
13
  }
14
14
 
15
- const [, frontmatter, body] = fmMatch;
15
+ const [, rawFrontmatter, body] = fmMatch;
16
+ const frontmatter = rawFrontmatter.replace(/\r\n/g, '\n');
16
17
 
17
18
  // Parse simple YAML key-value pairs
18
19
  const metadata = {};
@@ -43,7 +43,7 @@ export async function postDeploy(targetDir, opts) {
43
43
  if (opts.attribution !== false || hooks) {
44
44
  const { installAiwgHooks } = await importImpl(import.meta.url, 'extensions/claude-hooks-installer.js');
45
45
  const { deploymentOwner } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
46
- const result = await installAiwgHooks({ frameworkSlug: deploymentOwner(opts), claimUnchangedSettings: !addonPass, projectPath: targetDir,
46
+ const result = await installAiwgHooks({ frameworkSlug: deploymentOwner(opts), claimUnchangedSettings: !addonPass, projectPath: targetDir, commandRoot: opts.logicalOutputPath?.(targetDir),
47
47
  frameworkRoot: fileURLToPath(new URL('../../../', import.meta.url)),
48
48
  attribution: opts.attribution !== false, hooks, dryRun: opts.dryRun });
49
49
  if (!opts.dryRun && result) opts.writtenFiles?.push(result.settingsPath, ...result.installedScripts);
@@ -14,7 +14,7 @@ export async function postDeploy(targetDir, opts) {
14
14
  const { installCodexPromptDiscovery } = await importImpl(import.meta.url, 'smiths/hook-bridge/codex-translator.js');
15
15
  const packageRoot = fileURLToPath(new URL('../../../', import.meta.url));
16
16
  // Runtime hooks belong to this package, even when deploying an external bundle.
17
- await installCodexPromptDiscovery({ projectPath: targetDir, frameworkRoot: packageRoot, dryRun: opts.dryRun });
17
+ await installCodexPromptDiscovery({ projectPath: targetDir, commandRoot: opts.logicalOutputPath?.(targetDir), frameworkRoot: packageRoot, dryRun: opts.dryRun });
18
18
  }
19
19
 
20
20
  if (opts.createAgentsMd) {