@aiwg/cli 2026.11.3 → 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 +15 -18
- 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/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 +1 -2
- 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 +4 -5
- package/dist/src/config/aiwg-config.js +6 -0
- package/dist/src/config/authorization-cli.js +61 -3
- package/dist/src/config/cli-help.js +1 -1
- package/dist/src/config/cli.js +4 -2
- package/dist/src/config/host-resource-runtime.mjs +1 -1
- package/dist/src/config/user-registry.js +9 -1
- package/dist/src/config/worker-owner-lock.js +90 -10
- package/dist/src/decision/graph-flow-adapter.js +1 -1
- package/dist/src/effects/authorization-grant.js +50 -0
- package/dist/src/effects/authorization-store.js +130 -0
- package/dist/src/effects/index.js +2 -0
- package/dist/src/effects/ledger.js +1 -0
- package/dist/src/effects/lifecycle.js +1 -1
- package/dist/src/effects/reader.js +4 -0
- package/dist/src/effects/records.js +4 -0
- package/dist/src/effects/schema.js +2 -0
- package/dist/src/extensions/claude-hooks-installer.js +7 -7
- package/dist/src/extensions/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/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 +15 -18
- 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 +2 -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/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/workspace-status.mjs +7 -0
- package/tools/commands/deploy-prompts-codex.mjs +15 -1
- package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Muse Code's documented user skill root is `$XDG_CONFIG_HOME/muse/skills`
|
|
5
5
|
* (default `~/.config/muse/skills` when XDG_CONFIG_HOME is unset). The
|
|
6
6
|
* project skill root (`<repo>/.agents/skills`) is static provider metadata
|
|
7
|
-
* on the `muse` skillNamespace; this module
|
|
8
|
-
* at deploy time.
|
|
7
|
+
* on the `muse` skillNamespace; this module shares the project bulk mirror
|
|
8
|
+
* path and resolves the XDG user root at deploy time.
|
|
9
9
|
*
|
|
10
10
|
* Unlike Grok Bot (AIWG_GROKBOT_SKILLS_DIR, fail-closed until configured),
|
|
11
11
|
* the Muse user root is documented, so an unset XDG_CONFIG_HOME falls back
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { homedir } from 'node:os';
|
|
23
23
|
import * as path from 'node:path';
|
|
24
|
+
/** Project-only opt-in bulk mirror, shared by the registry and deployment adapter. */
|
|
25
|
+
export const MUSE_STANDARD_SKILLS_PATH = '.agents/.aiwg/skills';
|
|
24
26
|
/** Muse's documented user skills subtree below the XDG config root. */
|
|
25
27
|
export const MUSE_XDG_SKILLS_SUBDIR = path.join('muse', 'skills');
|
|
26
28
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveHermesHomePath } from './hermes-home.js';
|
|
1
2
|
const VERIFIED_ON = '2026-07-21';
|
|
2
3
|
export const CONTEXT_CONTRACTS = {
|
|
3
4
|
flue: {
|
|
@@ -32,6 +33,7 @@ export const CONTEXT_CONTRACTS = {
|
|
|
32
33
|
verification: { method: 'official AGENTS.md discovery chain; no Markdown include claimed', source: 'https://developers.openai.com/codex/guides/agents-md', lastVerified: VERIFIED_ON },
|
|
33
34
|
},
|
|
34
35
|
copilot: {
|
|
36
|
+
promptDiscovery: { delivery: 'bootstrap-rule', files: ['.github/copilot-instructions.md'] },
|
|
35
37
|
startupFiles: ['.github/copilot-instructions.md', 'AGENTS.md', 'CLAUDE.md'], precedence: ['personal', 'repository', 'organization; CLI combines applicable files'],
|
|
36
38
|
loadMode: 'native-include', includeSyntax: '@WORKSPACE.md\n@AIWG.md', configRegistration: null,
|
|
37
39
|
bootstrapTargets: ['.github/copilot-instructions.md', 'AGENTS.md'], maxContextBytes: null, recommendedMaxLines: null, nestedContext: true, support: 'supported',
|
|
@@ -72,6 +74,7 @@ export const CONTEXT_CONTRACTS = {
|
|
|
72
74
|
},
|
|
73
75
|
},
|
|
74
76
|
'grok-build': {
|
|
77
|
+
promptDiscovery: { delivery: 'bootstrap-rule', files: ['AGENTS.md'] },
|
|
75
78
|
// config.toml is configuration (MCP/plugins/permissions), not a startup/context file.
|
|
76
79
|
// Hierarchical instructions: AGENTS.md + .grok/rules/*.md, root-to-cwd, deeper wins.
|
|
77
80
|
startupFiles: ['AGENTS.md', '.grok/rules/*.md'],
|
|
@@ -90,6 +93,9 @@ export const CONTEXT_CONTRACTS = {
|
|
|
90
93
|
},
|
|
91
94
|
},
|
|
92
95
|
hermes: {
|
|
96
|
+
promptDiscovery: { delivery: 'hook-bridge', event: 'pre_llm_call', optIn: true, files: [
|
|
97
|
+
resolveHermesHomePath('config.yaml'), resolveHermesHomePath('agent-hooks', 'aiwg-prompt-discovery.cjs'),
|
|
98
|
+
] },
|
|
93
99
|
startupFiles: ['.hermes.md', 'AGENTS.md'], precedence: ['provider/system', '.hermes.md', 'AGENTS.md'],
|
|
94
100
|
loadMode: 'prose-directive', includeSyntax: null, configRegistration: null,
|
|
95
101
|
bootstrapTargets: ['.hermes.md', 'AGENTS.md'], maxContextBytes: null, recommendedMaxLines: 30, nestedContext: false, support: 'degraded',
|
|
@@ -118,7 +124,9 @@ export const CONTEXT_CONTRACTS = {
|
|
|
118
124
|
openclaw: {
|
|
119
125
|
startupFiles: ['~/.openclaw/config.yaml'], precedence: ['provider/system', 'home configuration'],
|
|
120
126
|
loadMode: 'unsupported', includeSyntax: null, configRegistration: null,
|
|
121
|
-
|
|
127
|
+
// Default active workspace; the deployment adapter resolves profile/config overrides.
|
|
128
|
+
bootstrapTargets: ['~/.openclaw/workspace/AGENTS.md', '~/.openclaw/workspace/SOUL.md'],
|
|
129
|
+
maxContextBytes: null, recommendedMaxLines: null, nestedContext: false, support: 'degraded',
|
|
122
130
|
verification: { method: 'AIWG home-scope adapter contract; no verified project startup file', source: 'agentic/code/providers/capability-matrix.yaml', lastVerified: VERIFIED_ON },
|
|
123
131
|
},
|
|
124
132
|
openhuman: {
|
|
@@ -162,9 +170,9 @@ export const CONTEXT_CONTRACTS = {
|
|
|
162
170
|
verification: { method: 'AIWG Windsurf/Devin topology contract; provider-native rules retained', source: 'src/providers/provider-definitions.ts', lastVerified: VERIFIED_ON },
|
|
163
171
|
},
|
|
164
172
|
generic: {
|
|
165
|
-
startupFiles: [], precedence: ['host policy'], loadMode: '
|
|
166
|
-
bootstrapTargets: [], maxContextBytes: null, recommendedMaxLines: null, nestedContext: false, support: '
|
|
167
|
-
verification: { method: '
|
|
173
|
+
startupFiles: ['AGENTS.md'], precedence: ['host policy'], loadMode: 'prose-directive', includeSyntax: null, configRegistration: null,
|
|
174
|
+
bootstrapTargets: ['AGENTS.md'], maxContextBytes: null, recommendedMaxLines: null, nestedContext: false, support: 'degraded',
|
|
175
|
+
verification: { method: 'Portable Markdown adapter; host must explicitly load AGENTS.md; no automatic startup-file claim', source: 'tools/agents/providers/generic.mjs', lastVerified: VERIFIED_ON },
|
|
168
176
|
},
|
|
169
177
|
};
|
|
170
178
|
//# sourceMappingURL=provider-context-contracts.js.map
|
|
@@ -93,6 +93,12 @@ export const ProviderDefinitionSchema = z.object({
|
|
|
93
93
|
includeSyntax: z.string().nullable(),
|
|
94
94
|
configRegistration: z.object({ file: z.string().min(1), key: z.string().min(1) }).nullable(),
|
|
95
95
|
bootstrapTargets: z.array(z.string().min(1)),
|
|
96
|
+
promptDiscovery: z.object({
|
|
97
|
+
delivery: z.enum(['bootstrap-rule', 'hook-bridge']),
|
|
98
|
+
files: z.array(z.string().min(1)).min(1),
|
|
99
|
+
event: z.string().min(1).optional(),
|
|
100
|
+
optIn: z.boolean().optional(),
|
|
101
|
+
}).optional(),
|
|
96
102
|
maxContextBytes: integer().positive().nullable(),
|
|
97
103
|
recommendedMaxLines: integer().positive().nullable(),
|
|
98
104
|
nestedContext: z.boolean(),
|
|
@@ -162,8 +162,8 @@ export const BUILT_IN_SEEDS_1 = [
|
|
|
162
162
|
agents: '.github/agents',
|
|
163
163
|
commands: '.github/commands',
|
|
164
164
|
skills: '.github/.aiwg/skills',
|
|
165
|
-
rules: '.github/
|
|
166
|
-
behaviors: '.github/
|
|
165
|
+
rules: '.github/instructions',
|
|
166
|
+
behaviors: '.github/instructions',
|
|
167
167
|
},
|
|
168
168
|
kernelSkills: '.github/skills',
|
|
169
169
|
contextDiscovery: {
|
|
@@ -179,7 +179,7 @@ export const BUILT_IN_SEEDS_1 = [
|
|
|
179
179
|
agents: '.github/agents',
|
|
180
180
|
commands: '.github/agents',
|
|
181
181
|
skills: '.github/skills',
|
|
182
|
-
rules: '.github/
|
|
182
|
+
rules: '.github/instructions',
|
|
183
183
|
fileExtension: '.md',
|
|
184
184
|
configFile: 'copilot-instructions.md',
|
|
185
185
|
aggregated: false,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { resolveHermesHomePath } from './hermes-home.js';
|
|
2
|
+
import { GROK_BUILD_STANDARD_SKILLS_PATH } from './grok-build-paths.js';
|
|
3
|
+
import { MUSE_STANDARD_SKILLS_PATH } from './muse-paths.js';
|
|
2
4
|
export const BUILT_IN_SEEDS_2 = [
|
|
3
5
|
{
|
|
4
6
|
id: 'grok-build',
|
|
@@ -26,7 +28,7 @@ export const BUILT_IN_SEEDS_2 = [
|
|
|
26
28
|
artifacts: {
|
|
27
29
|
agents: '.grok/agents',
|
|
28
30
|
commands: null,
|
|
29
|
-
skills:
|
|
31
|
+
skills: GROK_BUILD_STANDARD_SKILLS_PATH,
|
|
30
32
|
rules: '.grok/rules',
|
|
31
33
|
behaviors: null,
|
|
32
34
|
},
|
|
@@ -133,11 +135,11 @@ export const BUILT_IN_SEEDS_2 = [
|
|
|
133
135
|
paths: {
|
|
134
136
|
deployTarget: 'mixed',
|
|
135
137
|
artifacts: {
|
|
136
|
-
//
|
|
137
|
-
// hook. Agents
|
|
138
|
+
// Bulk skills use an opt-in mirror; kernel skills stay native. Rule files
|
|
139
|
+
// use the AGENTS.md hook. Agents/commands stay indexed via discover/show.
|
|
138
140
|
agents: null,
|
|
139
141
|
commands: null,
|
|
140
|
-
skills:
|
|
142
|
+
skills: MUSE_STANDARD_SKILLS_PATH,
|
|
141
143
|
rules: '.muse/rules',
|
|
142
144
|
behaviors: null,
|
|
143
145
|
},
|
|
@@ -233,7 +233,7 @@ export const BUILT_IN_SEEDS_3 = [
|
|
|
233
233
|
status: 'stable',
|
|
234
234
|
aliases: [],
|
|
235
235
|
builtIn: true,
|
|
236
|
-
surfaces: { primary: 'generic', compatibility: [], precedence: ['agents/', 'skills/', 'rules/'], related: [] },
|
|
236
|
+
surfaces: { primary: 'generic', compatibility: [], precedence: ['AGENTS.md', 'agents/', '.agents/skills/', 'skills/', 'rules/'], related: [] },
|
|
237
237
|
detection: {
|
|
238
238
|
env: [],
|
|
239
239
|
process: [],
|
|
@@ -248,9 +248,9 @@ export const BUILT_IN_SEEDS_3 = [
|
|
|
248
248
|
rules: 'rules',
|
|
249
249
|
behaviors: null,
|
|
250
250
|
},
|
|
251
|
-
kernelSkills:
|
|
252
|
-
configFile: '
|
|
253
|
-
contextFiles: { aiwgMd: true, agentsMd:
|
|
251
|
+
kernelSkills: '.agents/skills',
|
|
252
|
+
configFile: 'AGENTS.md',
|
|
253
|
+
contextFiles: { aiwgMd: true, agentsMd: true, claudeMdHook: false, hookFile: null, contextFile: 'AGENTS.md' },
|
|
254
254
|
},
|
|
255
255
|
smithPaths: {
|
|
256
256
|
agents: 'agents',
|
|
@@ -258,7 +258,7 @@ export const BUILT_IN_SEEDS_3 = [
|
|
|
258
258
|
skills: 'skills',
|
|
259
259
|
rules: 'rules',
|
|
260
260
|
fileExtension: '.md',
|
|
261
|
-
configFile: '
|
|
261
|
+
configFile: 'AGENTS.md',
|
|
262
262
|
aggregated: false,
|
|
263
263
|
},
|
|
264
264
|
skillNamespace: {
|
|
@@ -271,7 +271,7 @@ export const BUILT_IN_SEEDS_3 = [
|
|
|
271
271
|
agentFormat: 'generic-markdown',
|
|
272
272
|
hookBridge: null,
|
|
273
273
|
mcpInjection: null,
|
|
274
|
-
contextAggregation:
|
|
274
|
+
contextAggregation: 'agents-md',
|
|
275
275
|
ruleFormat: 'markdown',
|
|
276
276
|
},
|
|
277
277
|
matrixRef: null,
|
|
@@ -4,6 +4,8 @@ export interface RuleBindings { skills: string[]; agents: string[]; flows: strin
|
|
|
4
4
|
export interface RuleFrontmatter extends Record<string, unknown> {
|
|
5
5
|
activation: RuleActivation;
|
|
6
6
|
tagged: boolean;
|
|
7
|
+
precedence: 'critical' | 'high' | 'medium' | 'low';
|
|
8
|
+
overridable: boolean;
|
|
7
9
|
summary?: string;
|
|
8
10
|
bound_to: RuleBindings;
|
|
9
11
|
paths?: string[];
|
|
@@ -51,6 +51,8 @@ export function validateRuleFrontmatter(data) {
|
|
|
51
51
|
...data,
|
|
52
52
|
activation: tagged ? data.activation : inferRuleActivation(data.enforcement),
|
|
53
53
|
tagged,
|
|
54
|
+
precedence: data.precedence ?? 'medium',
|
|
55
|
+
overridable: data.overridable ?? true,
|
|
54
56
|
...(typeof data.summary === 'string' ? { summary: data.summary.trim() } : {}),
|
|
55
57
|
bound_to: { skills: [], agents: [], flows: [], ...data.bound_to },
|
|
56
58
|
} } : {}),
|
|
@@ -98,22 +100,29 @@ export function coreBodyPath(ruleFile) {
|
|
|
98
100
|
return ruleFile.replace(/\.md$/, '.core.md');
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/** Normalize Markdown line endings before enforcing the canonical core-body budget. */
|
|
104
|
+
function normalizeCoreBody(text) {
|
|
105
|
+
return text.replace(/\r\n?/g, '\n').trim();
|
|
106
|
+
}
|
|
107
|
+
|
|
101
108
|
/** Validate one core body's text. Returns error strings (empty when valid). */
|
|
102
109
|
export function validateCoreBody(text, label = 'core body') {
|
|
103
110
|
const errors = [];
|
|
104
|
-
const
|
|
105
|
-
|
|
111
|
+
const body = normalizeCoreBody(text);
|
|
112
|
+
const bytes = Buffer.byteLength(body, 'utf8');
|
|
113
|
+
if (!body) errors.push(`${label}: core body is empty`);
|
|
106
114
|
if (bytes > CORE_BODY_MAX_BYTES) errors.push(`${label}: core body is ${bytes} bytes; the per-body cap is ${CORE_BODY_MAX_BYTES} bytes`);
|
|
107
|
-
if (/^---\r?\n/.test(
|
|
108
|
-
if (AT_IMPORT.test(
|
|
115
|
+
if (/^---\r?\n/.test(body)) errors.push(`${label}: core body must not carry frontmatter`);
|
|
116
|
+
if (AT_IMPORT.test(body)) errors.push(`${label}: core body must not contain an @ file reference/import; use a plain path or \`aiwg show rule <name>\``);
|
|
109
117
|
return errors;
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
/** Validate the whole core set against the reserved budget. */
|
|
113
121
|
export function validateCoreSet(bodies) {
|
|
114
|
-
const
|
|
122
|
+
const measured = bodies.map(item => ({ name: item.name, bytes: Buffer.byteLength(normalizeCoreBody(item.text), 'utf8') }));
|
|
123
|
+
const total = measured.reduce((sum, item) => sum + item.bytes, 0);
|
|
115
124
|
return total > CORE_TOTAL_MAX_BYTES
|
|
116
|
-
? [`Core rules total ${total} bytes; the reserved core budget is ${CORE_TOTAL_MAX_BYTES} bytes (${
|
|
125
|
+
? [`Core rules total ${total} bytes; the reserved core budget is ${CORE_TOTAL_MAX_BYTES} bytes (${measured.map(item => `${item.name}: ${item.bytes}`).join(', ')})`]
|
|
117
126
|
: [];
|
|
118
127
|
}
|
|
119
128
|
|
|
@@ -121,7 +130,7 @@ export function validateCoreSet(bodies) {
|
|
|
121
130
|
export function readCoreBody(ruleFile) {
|
|
122
131
|
const file = coreBodyPath(ruleFile);
|
|
123
132
|
if (!existsSync(file)) throw new Error(`${ruleFile}: activation core requires a compact body file ${path.basename(file)}`);
|
|
124
|
-
const text = readFileSync(file, 'utf8')
|
|
133
|
+
const text = normalizeCoreBody(readFileSync(file, 'utf8'));
|
|
125
134
|
const errors = validateCoreBody(text, file);
|
|
126
135
|
if (errors.length) throw new Error(errors.join('; '));
|
|
127
136
|
return text;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RuleDiagnostic } from './activation.mjs';
|
|
2
2
|
export interface RulePinSelector { rules?: string[]; enforcement?: Array<'critical' | 'high' | 'medium' | 'low'>; capabilities?: string[]; group?: string; all?: true }
|
|
3
|
-
export interface
|
|
3
|
+
export interface RulePrecedenceOverride { tier?: 'critical' | 'high' | 'medium' | 'low'; project_context?: boolean }
|
|
4
|
+
export interface RulesConfig { precedence?: Record<string, RulePrecedenceOverride>; inline_budget_tokens?: number; always_load?: RulePinSelector[]; pin_groups?: Record<string, string[]> }
|
|
4
5
|
export interface InlineBudgetConfig { rules?: RulesConfig }
|
|
5
6
|
export interface StartupContributor { path: string; bytes?: number; content?: string }
|
|
6
7
|
export interface InlineBudgetReport {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/** Configurable lint guard only. Call with the complete projected startup set. */
|
|
2
|
+
import { validateRulePrecedenceConfig } from './precedence.mjs';
|
|
3
|
+
|
|
2
4
|
export const DEFAULT_RULES_INLINE_BUDGET_TOKENS = 64000;
|
|
3
5
|
|
|
4
6
|
export function validateRulesConfig(rules) {
|
|
5
7
|
if (rules === undefined) return [];
|
|
6
8
|
if (rules === null || typeof rules !== 'object' || Array.isArray(rules)) return ['rules: must be an object'];
|
|
7
|
-
const errors = Object.keys(rules).filter(key => !['inline_budget_tokens', 'always_load', 'pin_groups'].includes(key)).map(key => `rules.${key}: unknown field`);
|
|
9
|
+
const errors = Object.keys(rules).filter(key => !['inline_budget_tokens', 'always_load', 'pin_groups', 'precedence'].includes(key)).map(key => `rules.${key}: unknown field`);
|
|
8
10
|
if (rules.inline_budget_tokens !== undefined && (!Number.isSafeInteger(rules.inline_budget_tokens) || rules.inline_budget_tokens < 0)) {
|
|
9
11
|
errors.push('rules.inline_budget_tokens: must be a non-negative safe integer');
|
|
10
12
|
}
|
|
@@ -27,7 +29,7 @@ export function validateRulesConfig(rules) {
|
|
|
27
29
|
if (selector.group !== undefined && selector.capabilities !== undefined) errors.push('rules.always_load: group and capabilities are mutually exclusive');
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return errors;
|
|
32
|
+
return [...errors, ...validateRulePrecedenceConfig(rules.precedence)];
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export function resolveRulesInlineBudget(config = {}, env = process.env) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveRulePrecedence } from './precedence.mjs';
|
|
2
|
+
import { ruleOrderingAliases } from './project-precedence.js';
|
|
1
3
|
import fs from 'node:fs';
|
|
2
4
|
import path from 'node:path';
|
|
3
5
|
import { loadRelations } from '../artifacts/relations.js';
|
|
@@ -116,6 +118,7 @@ export async function ruleInventory(cwd, root, options) {
|
|
|
116
118
|
return [{ id: stableId, name: rule.name, capability: cap, source: rule.path, summary: parsed.rule.summary ?? null,
|
|
117
119
|
configured: installed, configured_by: configuredBy, applicable: installed ? 'conditional' : 'not-configured',
|
|
118
120
|
canonical_activation: canonical, effective_activation: installed ? effective : null,
|
|
121
|
+
...resolveRulePrecedence({ ...parsed.rule, name: rule.name, id: stableId ?? undefined }, selected, ruleOrderingAliases(rule.path, root, cwd)),
|
|
119
122
|
enforcement, pin_reasons: pin?.matches ?? [],
|
|
120
123
|
bindings: relation ? relation[1].targets : null, binding_evidence: relation ? 'relationship-index' : 'unknown', bound_to: parsed.rule.bound_to, paths: parsed.rule.paths ?? [],
|
|
121
124
|
fetch_command: stableId ? `aiwg show rule ${stableId} --body` : null,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PinConfigs } from './pins.mjs';
|
|
2
|
+
export interface RuleOrdering { precedence?: unknown; overridable?: unknown; name?: string; id?: string }
|
|
3
|
+
export interface ResolvedRuleOrdering { precedence: string; overridable: boolean; precedence_source: string; project_context: boolean }
|
|
4
|
+
export function validateRulePrecedenceConfig(value: unknown): string[];
|
|
5
|
+
export function resolveRulePrecedence(rule: RuleOrdering, configs?: PinConfigs, aliases?: string[]): ResolvedRuleOrdering;
|
|
6
|
+
export const RULE_PRECEDENCE_TEXT: string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Resolve instruction ordering without changing activation, pinning, or enforcement.
|
|
2
|
+
import { RULE_PIN_TIERS } from './pins.mjs';
|
|
3
|
+
|
|
4
|
+
export function validateRulePrecedenceConfig(value) {
|
|
5
|
+
if (value === undefined) return [];
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return ['rules.precedence: must be an object'];
|
|
7
|
+
const errors = [];
|
|
8
|
+
for (const [id, override] of Object.entries(value)) {
|
|
9
|
+
const label = `rules.precedence.${id}`;
|
|
10
|
+
if (!id.length || ['__proto__', 'prototype', 'constructor'].includes(id)) errors.push(`${label}: invalid rule id`);
|
|
11
|
+
if (!override || typeof override !== 'object' || Array.isArray(override) || !Object.keys(override).length) {
|
|
12
|
+
errors.push(`${label}: expected a non-empty override object`); continue;
|
|
13
|
+
}
|
|
14
|
+
for (const key of Object.keys(override)) if (!['tier', 'project_context'].includes(key)) errors.push(`${label}.${key}: unknown field`);
|
|
15
|
+
if (override.tier !== undefined && !RULE_PIN_TIERS.includes(override.tier)) errors.push(`${label}.tier: expected ${RULE_PIN_TIERS.join(', ')}`);
|
|
16
|
+
if (override.project_context !== undefined && typeof override.project_context !== 'boolean') errors.push(`${label}.project_context: must be a boolean`);
|
|
17
|
+
}
|
|
18
|
+
return errors;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** IDs include a source slug and, when indexed, the stable rule identity. */
|
|
22
|
+
export function resolveRulePrecedence(rule, configs = { project: {}, user: {} }, aliases = []) {
|
|
23
|
+
if (rule.precedence !== undefined && !RULE_PIN_TIERS.includes(rule.precedence)) throw new Error(`Rule ${rule.name ?? rule.id}: invalid precedence`);
|
|
24
|
+
if (rule.overridable !== undefined && typeof rule.overridable !== 'boolean') throw new Error(`Rule ${rule.name ?? rule.id}: overridable must be a boolean`);
|
|
25
|
+
let result = { precedence: rule.precedence ?? 'medium', overridable: rule.overridable ?? true,
|
|
26
|
+
precedence_source: 'rule', project_context: false };
|
|
27
|
+
const ids = new Set([rule.name, rule.id, ...aliases].filter(Boolean));
|
|
28
|
+
for (const source of ['user', 'project']) {
|
|
29
|
+
const errors = validateRulePrecedenceConfig(configs[source]?.rules?.precedence);
|
|
30
|
+
if (errors.length) throw new Error(errors.join('\n'));
|
|
31
|
+
const matches = Object.entries(configs[source]?.rules?.precedence ?? {}).filter(([id]) => ids.has(id));
|
|
32
|
+
if (matches.length > 1) throw new Error(`Multiple precedence overrides name rule ${rule.name ?? rule.id} in ${source}`);
|
|
33
|
+
if (!matches.length) continue;
|
|
34
|
+
if (!result.overridable) throw new Error(`Rule ${rule.name ?? rule.id} is non-overridable (${source} rules.precedence)`);
|
|
35
|
+
const [, override] = matches[0];
|
|
36
|
+
result = { ...result, precedence: override.tier ?? result.precedence,
|
|
37
|
+
project_context: override.project_context ?? result.project_context, precedence_source: source };
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const RULE_PRECEDENCE_TEXT = [
|
|
43
|
+
'A skill follows its bound rules, even when its own instructions conflict.',
|
|
44
|
+
'Between rules, higher precedence wins: critical > high > medium > low (default medium).',
|
|
45
|
+
'At equal precedence, the narrower scope wins. When resolving a conflict, name the rule followed.',
|
|
46
|
+
'Only explicit rules.precedence overrides may let project context outrank a named overridable rule;',
|
|
47
|
+
'non-overridable rules cannot be overridden or demoted. Other layer ordering and platform constraints stay unchanged.',
|
|
48
|
+
'Effective project ordering and its source are listed in WORKSPACE.md; skills never weaken non-overridable rules.',
|
|
49
|
+
].join('\n');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Validate ordering against canonical rule sources, including installed project-local bundles.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseRuleFrontmatter } from './activation.mjs';
|
|
5
|
+
import { ruleFiles, rulePinState } from './pin-state.js';
|
|
6
|
+
import { loadRulePinConfigs } from './pins.mjs';
|
|
7
|
+
import { validateRulePrecedenceConfig } from './precedence.mjs';
|
|
8
|
+
import { resolveFrameworkIndexRoot } from '../artifacts/framework-index-paths.js';
|
|
9
|
+
import { stableRecordId } from '../artifacts/browser-export.js';
|
|
10
|
+
export function validateProjectRulePrecedence(cwd, config, source = 'project', userConfigDir) {
|
|
11
|
+
const overrides = config.rules?.precedence;
|
|
12
|
+
const errors = validateRulePrecedenceConfig(overrides);
|
|
13
|
+
if (errors.length || !overrides || !Object.keys(overrides).length)
|
|
14
|
+
return errors;
|
|
15
|
+
const root = resolveFrameworkIndexRoot(cwd);
|
|
16
|
+
const configs = loadRulePinConfigs(cwd, source === 'project' ? config : undefined, userConfigDir);
|
|
17
|
+
if (source === 'user')
|
|
18
|
+
configs.user = config;
|
|
19
|
+
const inventory = rulePinState(cwd, root, configs, true, false).inventory;
|
|
20
|
+
const files = new Map(inventory.map(rule => [rule.path, [rule.id, rule.name]]));
|
|
21
|
+
for (const kind of ['addons', 'frameworks', 'extensions']) {
|
|
22
|
+
const base = path.join(root, 'agentic/code', kind);
|
|
23
|
+
if (!fs.existsSync(base))
|
|
24
|
+
continue;
|
|
25
|
+
for (const name of fs.readdirSync(base))
|
|
26
|
+
for (const file of ruleFiles(path.join(base, name, 'rules'))) {
|
|
27
|
+
if (!files.has(file))
|
|
28
|
+
files.set(file, []);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const candidates = [...files].filter(([file]) => !/\.core\.md$|\/(?:README|RULES-INDEX|RULES-ONDEMAND)\.md$/.test(file)).map(([file, aliases]) => {
|
|
32
|
+
const parsed = parseRuleFrontmatter(fs.readFileSync(file, 'utf8'));
|
|
33
|
+
const slug = path.basename(file, '.md');
|
|
34
|
+
return { file, parsed, aliases: [...aliases, ...ruleOrderingAliases(file, root, cwd), String(parsed.data?.name ?? slug)] };
|
|
35
|
+
});
|
|
36
|
+
const selected = new Map();
|
|
37
|
+
for (const id of Object.keys(overrides)) {
|
|
38
|
+
const matches = candidates.filter(candidate => candidate.aliases.includes(id));
|
|
39
|
+
if (matches.length !== 1) {
|
|
40
|
+
errors.push(`rules.precedence.${id}: ${matches.length ? 'ambiguous' : 'unknown'} rule`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const { parsed, file } = matches[0];
|
|
44
|
+
if (selected.has(file))
|
|
45
|
+
errors.push(`rules.precedence.${id}: duplicates override ${selected.get(file)} for the same rule`);
|
|
46
|
+
selected.set(file, id);
|
|
47
|
+
if (!parsed.valid)
|
|
48
|
+
errors.push(`${file}: ${parsed.diagnostics.map(item => item.message).join('; ')}`);
|
|
49
|
+
else if (!parsed.rule.overridable)
|
|
50
|
+
errors.push(`Rule ${id} is non-overridable (rules.precedence)`);
|
|
51
|
+
}
|
|
52
|
+
return errors;
|
|
53
|
+
}
|
|
54
|
+
/** Source slugs and stable IDs share the same override identity in every read surface. */
|
|
55
|
+
export function ruleOrderingAliases(file, root, cwd = root) {
|
|
56
|
+
const paths = [file, path.relative(root, file), path.relative(cwd, file)];
|
|
57
|
+
return [path.basename(file, '.md'), ...paths, ...paths.map(value => stableRecordId('aiwg.rule', value))];
|
|
58
|
+
}
|
|
59
|
+
/** Render operator ordering where agents already load project context. */
|
|
60
|
+
export function projectRulePrecedenceText(cwd) {
|
|
61
|
+
const configs = loadRulePinConfigs(cwd);
|
|
62
|
+
const lines = [];
|
|
63
|
+
for (const source of ['user', 'project']) {
|
|
64
|
+
const errors = validateProjectRulePrecedence(cwd, configs[source], source);
|
|
65
|
+
if (errors.length)
|
|
66
|
+
throw new Error(errors.join('\n'));
|
|
67
|
+
for (const [id, override] of Object.entries(configs[source].rules?.precedence ?? {})) {
|
|
68
|
+
lines.push(`- Rule ${id}: ${override.tier ? `precedence ${override.tier}; ` : ''}${override.project_context === undefined ? '' : `project context outranks rule: ${override.project_context}; `}source: ${source} rules.precedence.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return lines.length ? `Configured rule ordering (project entries override user entries):\n${lines.join('\n')}` : '';
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=project-precedence.js.map
|
|
@@ -9,6 +9,21 @@
|
|
|
9
9
|
],
|
|
10
10
|
"additionalProperties": true,
|
|
11
11
|
"properties": {
|
|
12
|
+
"precedence": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"enum": ["critical", "high", "medium", "low"],
|
|
15
|
+
"default": "medium",
|
|
16
|
+
"description": "Conflict ordering, using RULE_PIN_TIERS vocabulary; independent of enforcement and activation."
|
|
17
|
+
},
|
|
18
|
+
"overridable": {
|
|
19
|
+
"type": "boolean",
|
|
20
|
+
"default": true,
|
|
21
|
+
"description": "Whether project or user ordering may override this rule."
|
|
22
|
+
},
|
|
23
|
+
"enforcement": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"enum": ["critical", "high", "medium", "low"]
|
|
26
|
+
},
|
|
12
27
|
"activation": {
|
|
13
28
|
"type": "string",
|
|
14
29
|
"enum": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { A2AClient, A2A_HITL_PROMPT_V1 } from '../a2a/client.js';
|
|
12
12
|
import { isTerminalTaskState, } from '../a2a/types.js';
|
|
13
13
|
import { extractGraphMetadata } from '../flow/graph-metadata.js';
|
|
14
|
+
import { autoRespondToA2AMission } from './mission-hitl.js';
|
|
14
15
|
import { extractHitlEnvelope } from '../a2a/hitl.js';
|
|
15
16
|
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
16
17
|
const DEFAULT_MAX_POLLS = 300;
|
|
@@ -24,8 +25,11 @@ export async function observeA2ATerminalState(registry, executor, missionId, a2a
|
|
|
24
25
|
protocolVersion: opts.protocolVersion ?? '0.3',
|
|
25
26
|
...(opts.selectedInterface ? { selectedInterface: opts.selectedInterface } : {}),
|
|
26
27
|
acceptedPrompts: new Set(),
|
|
28
|
+
authorization: opts.authorization,
|
|
27
29
|
};
|
|
28
30
|
}
|
|
31
|
+
if (mission?.a2a && opts.authorization && !mission.a2a.authorization)
|
|
32
|
+
mission.a2a.authorization = opts.authorization;
|
|
29
33
|
try {
|
|
30
34
|
const clientOpts = {
|
|
31
35
|
baseUrl: executor.transportEndpoints.rest,
|
|
@@ -41,7 +45,7 @@ export async function observeA2ATerminalState(registry, executor, missionId, a2a
|
|
|
41
45
|
clientOpts.fetch = opts.fetch;
|
|
42
46
|
const client = new A2AClient(clientOpts);
|
|
43
47
|
let task = initialTask;
|
|
44
|
-
emitNonTerminalProgress(registry, executor.executorId, missionId, task);
|
|
48
|
+
await emitNonTerminalProgress(registry, executor.executorId, missionId, task, opts);
|
|
45
49
|
for (let attempt = 0; attempt <= (opts.maxPolls ?? DEFAULT_MAX_POLLS); attempt++) {
|
|
46
50
|
if (isTerminalTaskState(task.status.state)) {
|
|
47
51
|
emitTerminalTask(registry, executor.executorId, missionId, task);
|
|
@@ -54,7 +58,7 @@ export async function observeA2ATerminalState(registry, executor, missionId, a2a
|
|
|
54
58
|
if (task.id !== initialTask.id || task.contextId !== initialTask.contextId) {
|
|
55
59
|
throw new Error('A2A observer task binding changed');
|
|
56
60
|
}
|
|
57
|
-
emitNonTerminalProgress(registry, executor.executorId, missionId, task);
|
|
61
|
+
await emitNonTerminalProgress(registry, executor.executorId, missionId, task, opts);
|
|
58
62
|
}
|
|
59
63
|
registry.failMission(missionId, `A2A task ${initialTask.id} did not reach a terminal state before observer timeout`);
|
|
60
64
|
}
|
|
@@ -63,7 +67,7 @@ export async function observeA2ATerminalState(registry, executor, missionId, a2a
|
|
|
63
67
|
opts.onError?.(err);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
|
-
function emitNonTerminalProgress(registry, executorId, missionId, task) {
|
|
70
|
+
async function emitNonTerminalProgress(registry, executorId, missionId, task, opts) {
|
|
67
71
|
const state = task.status.state;
|
|
68
72
|
if (state === 'working') {
|
|
69
73
|
registry.handleEvent(makeEnvelope('mission.started', executorId, missionId, task, {
|
|
@@ -75,6 +79,11 @@ function emitNonTerminalProgress(registry, executorId, missionId, task) {
|
|
|
75
79
|
}
|
|
76
80
|
if (state === 'input-required') {
|
|
77
81
|
const prompt = extractHitlEnvelope(task);
|
|
82
|
+
// Only a configured host binding source can authorize automatically. Without one, publish the
|
|
83
|
+
// prompt synchronously as before, so the mission shows hitl-required when dispatch returns.
|
|
84
|
+
const bound = opts.authorization ?? registry.getMission(missionId)?.a2a?.authorization;
|
|
85
|
+
if (prompt?.ok && bound && await autoRespondToA2AMission(registry, missionId, prompt.envelope.prompt_id, opts))
|
|
86
|
+
return;
|
|
78
87
|
registry.handleEvent(makeEnvelope('mission.hitl_required', executorId, missionId, task, {
|
|
79
88
|
state: 'hitl-required',
|
|
80
89
|
a2a_task_id: task.id,
|
|
@@ -3,6 +3,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
3
3
|
import Ajv from 'ajv';
|
|
4
4
|
import { A2AClient, A2A_HITL_PROMPT_V1 } from '../a2a/client.js';
|
|
5
5
|
import { buildHitlResponseMessage, extractHitlEnvelope } from '../a2a/hitl.js';
|
|
6
|
+
import { lookupPromptAuthorization } from '../a2a/hitl-authorization.js';
|
|
6
7
|
export async function respondToA2AMission(registry, missionId, promptId, response, opts = {}) {
|
|
7
8
|
const mission = registry.getMission(missionId);
|
|
8
9
|
const binding = mission?.a2a;
|
|
@@ -41,6 +42,15 @@ export async function respondToA2AMission(registry, missionId, promptId, respons
|
|
|
41
42
|
// accept a caller-supplied name as authority for a restricted prompt.
|
|
42
43
|
if (prompt.allowed_responders && !prompt.allowed_responders.includes('any'))
|
|
43
44
|
return reply(403, 'authenticated_responder_required');
|
|
45
|
+
let authorization;
|
|
46
|
+
if (opts.automatic) {
|
|
47
|
+
const authorized = await lookupPromptAuthorization({ envelope: prompt, taskId: binding.taskId,
|
|
48
|
+
contextId: binding.contextId, authorization: binding.authorization });
|
|
49
|
+
if (!authorized)
|
|
50
|
+
return reply(409, 'approval_requires_human');
|
|
51
|
+
response = authorized.response;
|
|
52
|
+
authorization = authorized.authorization;
|
|
53
|
+
}
|
|
44
54
|
try {
|
|
45
55
|
const validate = new Ajv({ allErrors: true, strict: true }).compile(prompt.response_schema);
|
|
46
56
|
if ('$async' in validate && validate.$async === true)
|
|
@@ -73,7 +83,8 @@ export async function respondToA2AMission(registry, missionId, promptId, respons
|
|
|
73
83
|
registry.handleEvent({
|
|
74
84
|
event: 'mission.progress', executor_id: mission.executorId, mission_id: missionId,
|
|
75
85
|
ts: new Date().toISOString(),
|
|
76
|
-
data: { action: 'hitl_response_accepted', hitl_id: promptId, a2a_task_id: binding.taskId
|
|
86
|
+
data: { action: 'hitl_response_accepted', hitl_id: promptId, a2a_task_id: binding.taskId,
|
|
87
|
+
...(authorization ? { authorization } : {}) },
|
|
77
88
|
});
|
|
78
89
|
return { status: 200, body: { ok: true } };
|
|
79
90
|
}
|
|
@@ -88,4 +99,12 @@ export async function respondToA2AMission(registry, missionId, promptId, respons
|
|
|
88
99
|
function reply(status, error) {
|
|
89
100
|
return { status, body: { error } };
|
|
90
101
|
}
|
|
102
|
+
/** Called before publishing a mission prompt. The HTTP response route never sets automatic. */
|
|
103
|
+
export async function autoRespondToA2AMission(registry, missionId, promptId, opts = {}) {
|
|
104
|
+
const binding = registry.getMission(missionId)?.a2a;
|
|
105
|
+
if (binding?.acceptedPrompts.has(promptId))
|
|
106
|
+
return true;
|
|
107
|
+
const result = await respondToA2AMission(registry, missionId, promptId, null, { ...opts, automatic: true });
|
|
108
|
+
return result.status === 200;
|
|
109
|
+
}
|
|
91
110
|
//# sourceMappingURL=mission-hitl.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Acquire a bounded CLI export when an authorized native projection is unavailable.
|
|
2
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { resolveGrokHomeResult } from '../../providers/grok-build-paths.js';
|
|
6
|
+
import { SessionContractError } from '../contracts.js';
|
|
7
|
+
import { authorizeGrokBuildNativeSource } from './grok-build-native.js';
|
|
8
|
+
export function canFallbackGrokNative(error, options) {
|
|
9
|
+
return options !== undefined && process.env.AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL === '1'
|
|
10
|
+
&& error instanceof SessionContractError
|
|
11
|
+
&& ['SCHEMA_DRIFT', 'UNKNOWN_SCHEMA_MAJOR', 'UNSUPPORTED_OPERATION', 'MALFORMED_SOURCE'].includes(error.code);
|
|
12
|
+
}
|
|
13
|
+
export async function withGrokCliFallback(source, options, operation) {
|
|
14
|
+
if (process.env.AIWG_GROK_BUILD_NATIVE_EXPERIMENTAL !== '1') {
|
|
15
|
+
throw new SessionContractError('UNSUPPORTED_OPERATION', 'Grok Build native fallback requires the experimental opt-in; use an explicit `grok export` instead.');
|
|
16
|
+
}
|
|
17
|
+
const { sessionId, cwd } = await authorizeGrokBuildNativeSource(source);
|
|
18
|
+
const home = resolveGrokHomeResult(options.env ?? process.env);
|
|
19
|
+
if (!home.ok || resolve(source.locator) !== join(home.path, 'sessions', encodeURIComponent(cwd), sessionId, 'chat_history.jsonl')) {
|
|
20
|
+
throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build CLI fallback requires the selected session to belong to $GROK_HOME/sessions; set GROK_HOME to the authorized source home.');
|
|
21
|
+
}
|
|
22
|
+
const directory = await mkdtemp(join(tmpdir(), 'aiwg-grok-fallback-'));
|
|
23
|
+
try {
|
|
24
|
+
const { grokBuildExport } = await import('../grok-build-cli.js');
|
|
25
|
+
const locator = await grokBuildExport({ ...options, cwd }, sessionId, directory);
|
|
26
|
+
return await operation({ ...source, locator, locatorClass: 'grok-build-cli-markdown-export',
|
|
27
|
+
authorizedScope: { ...source.authorizedScope, allowedRoots: [directory] } });
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
await rm(directory, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=grok-build-fallback.js.map
|