@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,6 +4,7 @@ events: [UserPromptSubmit]
|
|
|
4
4
|
command: node
|
|
5
5
|
args: ['$AIWG_ROOT/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs']
|
|
6
6
|
timeout: 2
|
|
7
|
-
# These bridges
|
|
7
|
+
# These bridges cannot inject prompt context; their startup rules require discovery.
|
|
8
8
|
# Muse uses its project hook owner; Claude uses claude-hooks-installer.
|
|
9
|
-
|
|
9
|
+
# Hermes uses pre_llm_call shell hooks with a native {context} response.
|
|
10
|
+
degrade-on: [copilot, grok-build]
|
|
@@ -49,18 +49,18 @@ function contextFor(envelope, prompt) {
|
|
|
49
49
|
const prefix = 'AIWG candidates:\n';
|
|
50
50
|
const next = '\nFirst call: aiwg show <type> <name> (best fit) -> rules (--rules --with-rule-bodies; --body) -> apply.'
|
|
51
51
|
+ '\nIf none fit, run aiwg discover; never decline without it.';
|
|
52
|
-
|
|
52
|
+
let candidates = (Array.isArray(envelope?.results) ? envelope.results : [])
|
|
53
53
|
.filter(r => typeof r?.score === 'number' && Number.isFinite(r.score) && r.score >= 0.20
|
|
54
54
|
&& /^[a-z][a-z-]{0,19}$/.test(r.type) && /^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,69}$/.test(r.name))
|
|
55
55
|
.sort((a, b) => b.score - a.score).slice(0, 3);
|
|
56
|
-
const
|
|
56
|
+
const strong = candidates.filter(r => r.score >= 0.70);
|
|
57
|
+
const template = (strong.length ? strong : candidates).find(candidate => candidate.templates?.length)?.templates?.[0];
|
|
57
58
|
const templateHint = template && /^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,69}$/.test(template.name)
|
|
58
59
|
&& /^aiwg show template [a-zA-Z0-9][a-zA-Z0-9_.:-]{0,149}$/.test(template.show_command)
|
|
59
60
|
? `\nTemplate ${template.name}: ${template.show_command}` : '';
|
|
60
|
-
// 0.70 excludes
|
|
61
|
-
// only when at least one candidate supplies a stronger signal.
|
|
61
|
+
// 0.70 excludes weak hits; each displayed candidate must supply a strong signal.
|
|
62
62
|
// Muse UAT (2026-11-06): advisory wording was ignored; first-call wording was followed.
|
|
63
|
-
if (!
|
|
63
|
+
if (!strong.length) {
|
|
64
64
|
// Restrict by type only when the request asks for an AIWG component of that type, not when a
|
|
65
65
|
// type word merely appears ("removes every managed Claude hook" is not a hook search).
|
|
66
66
|
const namedType = prompt.match(/\b(?:aiwg|is there an?|are there any|find|list|which|what)\s+(?:aiwg\s+)?(decision-definition|decision-ruleset|decision-binding|gate-pack|skill|agent|command|rule|schema|flow|runbook|template|behavior|hook|workflow)s?\b/i)?.[1].toLowerCase();
|
|
@@ -72,6 +72,7 @@ function contextFor(envelope, prompt) {
|
|
|
72
72
|
while (instruction().length > 599 && need.length) need = need.slice(0, -1);
|
|
73
73
|
return instruction();
|
|
74
74
|
}
|
|
75
|
+
candidates = strong;
|
|
75
76
|
// Leave room for the template drill-in even when candidate names are long.
|
|
76
77
|
while (candidates.length > 1 && prefix.length + next.length + templateHint.length
|
|
77
78
|
+ candidates.map(r => `${r.type} ${r.name} (${r.score.toFixed(2).slice(0, 6)}): `).join('\n').length > 599) candidates.pop();
|
|
@@ -94,10 +95,12 @@ async function main() {
|
|
|
94
95
|
chunks.push(chunk);
|
|
95
96
|
}
|
|
96
97
|
const event = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
97
|
-
|
|
98
|
+
const hermes = event.hook_event_name === 'pre_llm_call';
|
|
99
|
+
if (event.hook_event_name && event.hook_event_name !== 'UserPromptSubmit' && !hermes) return finish();
|
|
98
100
|
if ([event.role, event.message?.role].some(role => role && role !== 'user')
|
|
99
101
|
|| /^(system|notification|tool[_-]result)$/.test(event.type || '')) return finish();
|
|
100
|
-
const
|
|
102
|
+
const text = hermes ? event.extra?.user_message : event.prompt;
|
|
103
|
+
const prompt = typeof text === 'string' ? text.trim() : '';
|
|
101
104
|
if (!shouldDiscover(prompt)) return finish();
|
|
102
105
|
const moduleUrl = runtimeModule();
|
|
103
106
|
if (!moduleUrl || Date.now() >= deadline) return finish();
|
|
@@ -119,12 +122,12 @@ async function main() {
|
|
|
119
122
|
})().catch(() => process.exit(0));
|
|
120
123
|
`, {
|
|
121
124
|
eval: true, stdout: true, stderr: true,
|
|
122
|
-
workerData: { moduleUrl, prompt, cwd: process.cwd() },
|
|
125
|
+
workerData: { moduleUrl, prompt, cwd: hermes && typeof event.cwd === 'string' ? event.cwd : process.cwd() },
|
|
123
126
|
});
|
|
124
127
|
worker.on('message', envelope => {
|
|
125
128
|
if (Date.now() >= deadline) return finish();
|
|
126
129
|
const context = contextFor(envelope, prompt);
|
|
127
|
-
if (context) process.stdout.write(JSON.stringify({
|
|
130
|
+
if (context) process.stdout.write(JSON.stringify(hermes ? { context } : {
|
|
128
131
|
hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: context },
|
|
129
132
|
}) + '\n', finish);
|
|
130
133
|
else finish();
|
|
@@ -6,6 +6,7 @@ import Ajv from 'ajv';
|
|
|
6
6
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
7
7
|
import addFormats from 'ajv-formats';
|
|
8
8
|
import { validateFlowGraph } from './validator.mjs';
|
|
9
|
+
import { createFlowAuthority } from './authority.mjs';
|
|
9
10
|
|
|
10
11
|
const RESOURCE_KEYS = ['activations', 'tokens', 'costUsd', 'timeMs'];
|
|
11
12
|
|
|
@@ -514,9 +515,6 @@ export async function executeFlowGraph(manifest, options = {}) {
|
|
|
514
515
|
const graphId = validation.normalized.identity.graphId;
|
|
515
516
|
const runId = options.runId ?? `${graphId}:run`;
|
|
516
517
|
const evaluatePredicate = options.evaluatePredicate ?? defaultPredicate;
|
|
517
|
-
const allowedCapabilities = new Set(options.allowedCapabilities ?? manifest.spec.capabilities.map((item) => item.id));
|
|
518
|
-
const allowedPermissions = new Set(options.allowedPermissions ?? manifest.spec.permissions);
|
|
519
|
-
const approvedGates = new Set(options.approvedGates ?? []);
|
|
520
518
|
const nodeOrder = new Map(manifest.spec.nodes.map((node, index) => [node.id, index]));
|
|
521
519
|
const nodes = new Map(manifest.spec.nodes.map((node) => [node.id, node]));
|
|
522
520
|
const stateFields = new Map(manifest.spec.state.fields.map((field) => [field.name, field]));
|
|
@@ -624,26 +622,7 @@ export async function executeFlowGraph(manifest, options = {}) {
|
|
|
624
622
|
}));
|
|
625
623
|
}
|
|
626
624
|
|
|
627
|
-
|
|
628
|
-
const missingCapability = node.capabilities.find((id) => !allowedCapabilities.has(id));
|
|
629
|
-
if (missingCapability) throw new FlowGraphRuntimeError('CAPABILITY_DENIED', `Node '${node.id}' is not authorized for capability '${missingCapability}'.`);
|
|
630
|
-
const missingPermission = node.permissions.find((id) => !allowedPermissions.has(id));
|
|
631
|
-
if (missingPermission) throw new FlowGraphRuntimeError('PERMISSION_DENIED', `Node '${node.id}' is not authorized for permission '${missingPermission}'.`);
|
|
632
|
-
if (node.kind === 'gate' && new Set(options.cancelledGates ?? []).has(node.id)) {
|
|
633
|
-
throw new FlowGraphRuntimeError('APPROVAL_CANCELLED', `Approval gate '${node.id}' was cancelled.`);
|
|
634
|
-
}
|
|
635
|
-
if (node.kind === 'gate' && !approvedGates.has(node.id)) {
|
|
636
|
-
throw new FlowGraphRuntimeError('APPROVAL_REQUIRED', `Gate '${node.id}' has not been approved.`);
|
|
637
|
-
}
|
|
638
|
-
if (node.sideEffectMode === 'approval-required') {
|
|
639
|
-
if (new Set(options.cancelledGates ?? []).has(node.approvalGate)) {
|
|
640
|
-
throw new FlowGraphRuntimeError('APPROVAL_CANCELLED', `Approval gate '${node.approvalGate}' was cancelled.`);
|
|
641
|
-
}
|
|
642
|
-
if (!approvedGates.has(node.approvalGate)) {
|
|
643
|
-
throw new FlowGraphRuntimeError('APPROVAL_REQUIRED', `Node '${node.id}' is waiting for approval gate '${node.approvalGate}'.`);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
625
|
+
const enforceAuthority = createFlowAuthority(manifest, options, evidence, FlowGraphRuntimeError);
|
|
647
626
|
|
|
648
627
|
function validateInputs(node, inputs) {
|
|
649
628
|
if (!managed) return assertNoWorkerValues(inputs);
|
|
@@ -706,7 +685,7 @@ export async function executeFlowGraph(manifest, options = {}) {
|
|
|
706
685
|
}
|
|
707
686
|
|
|
708
687
|
async function invoke(node, activationTick, iteration = 1) {
|
|
709
|
-
enforceAuthority(node);
|
|
688
|
+
await enforceAuthority(node);
|
|
710
689
|
const inputs = inputsFor(node);
|
|
711
690
|
validateInputs(node, inputs);
|
|
712
691
|
const inputSnapshot = clone(inputs);
|
|
@@ -997,8 +976,8 @@ export async function executeFlowGraph(manifest, options = {}) {
|
|
|
997
976
|
for (const node of nodesToRun) recordJoinEvidence(joinFor(node.id));
|
|
998
977
|
let settled;
|
|
999
978
|
if (parallelEligible && managed) {
|
|
979
|
+
for (const node of nodesToRun) await enforceAuthority(node);
|
|
1000
980
|
const requests = nodesToRun.map((node) => {
|
|
1001
|
-
enforceAuthority(node);
|
|
1002
981
|
const inputs = inputsFor(node);
|
|
1003
982
|
validateInputs(node, inputs);
|
|
1004
983
|
const requested = requestedResources(node);
|
|
@@ -1070,8 +1049,8 @@ export async function executeFlowGraph(manifest, options = {}) {
|
|
|
1070
1049
|
}
|
|
1071
1050
|
await persist();
|
|
1072
1051
|
} else if (parallelEligible) {
|
|
1052
|
+
for (const node of nodesToRun) await enforceAuthority(node);
|
|
1073
1053
|
const requests = nodesToRun.map((node) => {
|
|
1074
|
-
enforceAuthority(node);
|
|
1075
1054
|
const inputs = inputsFor(node);
|
|
1076
1055
|
validateInputs(node, inputs);
|
|
1077
1056
|
const nodeRunId = `${runId}:${node.id}:${tick}:${iteration}`;
|
|
@@ -170,9 +170,31 @@
|
|
|
170
170
|
"idempotencyKey": { "type": "string", "minLength": 1 },
|
|
171
171
|
"approvalGate": { "$ref": "#/definitions/id" },
|
|
172
172
|
"scope": { "$ref": "#/definitions/observationScope" },
|
|
173
|
+
"hitlAction": { "$ref": "#/definitions/hitlAction" },
|
|
173
174
|
"retry": { "$ref": "#/definitions/retryPolicy" },
|
|
174
175
|
"fallback": { "$ref": "#/definitions/fallbackPolicy" },
|
|
175
176
|
"ceilings": { "$ref": "#/definitions/ceilings" }
|
|
177
|
+
},
|
|
178
|
+
"allOf": [
|
|
179
|
+
{ "if": { "required": ["hitlAction"] }, "then": { "properties": { "kind": { "const": "gate" } } } }
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
"hitlAction": {
|
|
183
|
+
"description": "Host-authored classification of the exact pending execution plan. Never populate from node inputs, worker output or model text; unknown effects retain human review.",
|
|
184
|
+
"type": "object",
|
|
185
|
+
"required": ["category", "repo", "environment", "resources", "reversible", "impact"],
|
|
186
|
+
"additionalProperties": false,
|
|
187
|
+
"properties": {
|
|
188
|
+
"category": { "type": "string", "minLength": 1 },
|
|
189
|
+
"repo": { "type": "string", "minLength": 1 },
|
|
190
|
+
"target": { "type": "string", "minLength": 1 },
|
|
191
|
+
"environment": { "type": "string", "minLength": 1 },
|
|
192
|
+
"resources": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
|
|
193
|
+
"verb": { "type": "string", "minLength": 1 },
|
|
194
|
+
"reversible": { "type": "boolean" },
|
|
195
|
+
"impact": { "enum": ["low", "medium", "high"] },
|
|
196
|
+
"actor": { "type": "string", "minLength": 1 },
|
|
197
|
+
"inputDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
|
|
176
198
|
}
|
|
177
199
|
},
|
|
178
200
|
"inputBinding": {
|
|
@@ -549,7 +549,7 @@ providers:
|
|
|
549
549
|
scope: in
|
|
550
550
|
identity: runtime-configured-only
|
|
551
551
|
evidence: R
|
|
552
|
-
channel: "grok -p --output-format streaming-json; bounded parser
|
|
552
|
+
channel: "grok -p --output-format streaming-json; 1.0.77 adds --no-auto-update; bounded parser (model/effort pins unverified by captures)"
|
|
553
553
|
fanout: unknown
|
|
554
554
|
probe_budget: { status: authorized, calls: 3, tokens: 30000, authorized_by: operator, authorized_at: "2026-10-07", hosts: [titan, noodle] }
|
|
555
555
|
coverage:
|
|
@@ -560,35 +560,32 @@ providers:
|
|
|
560
560
|
- "src/providers/grok-build-headless.ts"
|
|
561
561
|
status: experimental
|
|
562
562
|
# xAI Grok Build CLI/TUI. Distinct from Grok Bot (`grokbot`).
|
|
563
|
-
# #2577:
|
|
564
|
-
#
|
|
565
|
-
# test/unit/providers/grok-build-
|
|
566
|
-
#
|
|
567
|
-
#
|
|
568
|
-
# and grok-build-acp.test.ts. ACP does not establish a daemon lifecycle.
|
|
569
|
-
# No fixture supports native cron, multi-agent teams, mission control,
|
|
570
|
-
# or AIWG behavior registration; those claims remain false.
|
|
563
|
+
# #2577: every claim and its limits are recorded in
|
|
564
|
+
# docs/providers/grok-build-native-agents.md (1.0.77 evidence table).
|
|
565
|
+
# Captured headless shapes: test/unit/providers/grok-build-headless.test.ts.
|
|
566
|
+
# Agent compilation, native fan-out/worktrees and ACP remain unverified by
|
|
567
|
+
# these captures; pre-existing synthetic tests establish AIWG behavior only.
|
|
571
568
|
daemon_tier: unsupported
|
|
572
569
|
daemon_pty_adapter: false
|
|
573
570
|
artifact_paths:
|
|
574
|
-
agents: .grok/agents/ #
|
|
571
|
+
agents: .grok/agents/ # writer path; native frontmatter unverified by captures
|
|
575
572
|
commands: null
|
|
576
573
|
skills: .grok/skills/
|
|
577
574
|
skills_cross_agent: .grok/.aiwg/skills/ # --copy-all opt-in mirror
|
|
578
575
|
rules: "Indexed: aiwg show rule + AGENTS.md / host .grok/rules (AIWG writer deferred #2577)"
|
|
579
576
|
behaviors: null
|
|
580
577
|
native_features:
|
|
581
|
-
cron: false
|
|
582
|
-
agent_teams: false
|
|
583
|
-
tasks:
|
|
584
|
-
mcp: true
|
|
585
|
-
behaviors: false
|
|
586
|
-
mission_control: false
|
|
587
|
-
daemon: false
|
|
578
|
+
cron: false # unverified: needs recurring-loop execution capture
|
|
579
|
+
agent_teams: false # unverified: needs team lifecycle capture
|
|
580
|
+
tasks: false # unverified: headless tool calls do not prove background task lifecycle
|
|
581
|
+
mcp: true # fixture-backed config only: grok-build-native-integration.test.ts; live MCP unverified
|
|
582
|
+
behaviors: false # unverified: needs behavior registration/execution capture
|
|
583
|
+
mission_control: false # unverified: needs mission lifecycle capture
|
|
584
|
+
daemon: false # unverified: ACP is separate and needs agent-stdio capture
|
|
588
585
|
emulation:
|
|
589
586
|
cron: null
|
|
590
587
|
agent_teams: aiwg-mc
|
|
591
|
-
tasks:
|
|
588
|
+
tasks: aiwg-mc
|
|
592
589
|
mcp: null
|
|
593
590
|
behaviors: aiwg-mc
|
|
594
591
|
mission_control: aiwg-mc
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Resolves host-bound prompt actions without deriving authority from executor text or schemas.
|
|
2
|
+
import Ajv from 'ajv';
|
|
3
|
+
export async function lookupPromptAuthorization(opts) {
|
|
4
|
+
try {
|
|
5
|
+
const { checkHitlAuthorization } = await import('../policy/hitl-check.js');
|
|
6
|
+
const { hitlDigest } = await import('../policy/hitl.js');
|
|
7
|
+
const envelope = structuredClone(opts.envelope);
|
|
8
|
+
const supplied = opts.authorization?.bindings.get(envelope.prompt_id);
|
|
9
|
+
const binding = supplied && structuredClone(supplied);
|
|
10
|
+
let eligible = binding && binding.taskId === opts.taskId && binding.contextId === opts.contextId
|
|
11
|
+
&& binding.promptId === envelope.prompt_id && binding.promptDigest === hitlDigest(envelope)
|
|
12
|
+
&& (!envelope.allowed_responders || envelope.allowed_responders.includes('any'))
|
|
13
|
+
&& (!envelope.deadline || Date.parse(envelope.deadline) > Date.now());
|
|
14
|
+
if (eligible) {
|
|
15
|
+
try {
|
|
16
|
+
const validate = new Ajv({ strict: true }).compile(envelope.response_schema);
|
|
17
|
+
eligible = !('$async' in validate && validate.$async === true) && !!validate(binding.response);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
eligible = false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// No host classification means unknown effects. Still consult the resolver,
|
|
24
|
+
// which retains review rather than treating prompt text as a safe action.
|
|
25
|
+
const checked = await checkHitlAuthorization(opts.authorization?.projectDir ?? process.cwd(), eligible ? binding.action : null);
|
|
26
|
+
if (!eligible || checked.decision !== 'auto-authorized' || !checked.receipt?.file || !checked.receipt.effectId)
|
|
27
|
+
return;
|
|
28
|
+
if (envelope.deadline && Date.parse(envelope.deadline) <= Date.now())
|
|
29
|
+
return;
|
|
30
|
+
return { response: binding.response, authorization: { receipt: checked.receipt,
|
|
31
|
+
provenance: checked.provenance, ...(checked.authorizationGrant ? { authorizationGrant: checked.authorizationGrant } : {}) } };
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return; // Lookup failures retain the existing human collection path.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function collectAuthorizedHitlResponse(opts, signal) {
|
|
38
|
+
const authorized = signal.aborted ? undefined : await lookupPromptAuthorization(opts);
|
|
39
|
+
if (authorized && !signal.aborted)
|
|
40
|
+
return authorized;
|
|
41
|
+
return { response: await opts.adapter.collect(opts.envelope, {
|
|
42
|
+
...(opts.taskId !== undefined ? { taskId: opts.taskId } : {}),
|
|
43
|
+
...(opts.contextId !== undefined ? { contextId: opts.contextId } : {}), signal,
|
|
44
|
+
}), authorization: undefined };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=hitl-authorization.js.map
|
|
@@ -39,6 +39,7 @@ import { existsSync } from 'node:fs';
|
|
|
39
39
|
import { dirname, join, resolve as resolvePath } from 'node:path';
|
|
40
40
|
import { fileURLToPath } from 'node:url';
|
|
41
41
|
import { buildHitlResponseMessage, extractHitlEnvelope, validateResponseStructurally, } from './hitl.js';
|
|
42
|
+
import { collectAuthorizedHitlResponse } from './hitl-authorization.js';
|
|
42
43
|
import { digestDecisionContext } from '../audit/operator-decision.js';
|
|
43
44
|
/** Default audit log — writes to stderr as JSONL. Replace with a file/HTTP sink in production. */
|
|
44
45
|
export class StderrHitlAuditLog {
|
|
@@ -162,6 +163,7 @@ export async function driveHitlPromptsForTask(opts) {
|
|
|
162
163
|
const ctx = inferEventContext(event);
|
|
163
164
|
await driveOnePrompt({
|
|
164
165
|
envelope,
|
|
166
|
+
authorization: opts.authorization,
|
|
165
167
|
client: opts.client,
|
|
166
168
|
adapter: opts.adapter,
|
|
167
169
|
auditLog,
|
|
@@ -222,12 +224,9 @@ export async function driveOnePrompt(opts) {
|
|
|
222
224
|
try {
|
|
223
225
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
224
226
|
let response;
|
|
227
|
+
let authorization;
|
|
225
228
|
try {
|
|
226
|
-
response = await
|
|
227
|
-
...(opts.taskId !== undefined ? { taskId: opts.taskId } : {}),
|
|
228
|
-
...(opts.contextId !== undefined ? { contextId: opts.contextId } : {}),
|
|
229
|
-
signal: controller.signal,
|
|
230
|
-
});
|
|
229
|
+
({ response, authorization } = await collectAuthorizedHitlResponse(opts, controller.signal));
|
|
231
230
|
}
|
|
232
231
|
catch (err) {
|
|
233
232
|
if (controller.signal.aborted) {
|
|
@@ -312,6 +311,7 @@ export async function driveOnePrompt(opts) {
|
|
|
312
311
|
...(opts.taskId !== undefined ? { task_id: opts.taskId } : {}),
|
|
313
312
|
...(opts.contextId !== undefined ? { context_id: opts.contextId } : {}),
|
|
314
313
|
outcome: 'responded',
|
|
314
|
+
...(authorization ? { authorization } : {}),
|
|
315
315
|
response_digest: digestDecisionContext(response),
|
|
316
316
|
duration_ms: Date.now() - startedAt,
|
|
317
317
|
});
|
|
@@ -459,6 +459,8 @@ function recordForEntry(cwd, entry, graphName, dependencyGraph, privacy, schemaV
|
|
|
459
459
|
...(entry.activation ? { activation: entry.activation } : {}),
|
|
460
460
|
...(entry.bound_to ? { bound_to: entry.bound_to } : {}),
|
|
461
461
|
...(entry.ruleEnforcement ? { enforcement: entry.ruleEnforcement } : {}),
|
|
462
|
+
...(entry.rulePrecedence ? { precedence: entry.rulePrecedence } : {}),
|
|
463
|
+
...(entry.ruleOverridable === undefined ? {} : { overridable: entry.ruleOverridable }),
|
|
462
464
|
...(entry.rulePaths ? { paths: entry.rulePaths } : {}),
|
|
463
465
|
...(entry.governedPaths ? { aiwg_governed_paths: entry.governedPaths } : {}),
|
|
464
466
|
...(entry.ruleSummary !== undefined ? { summary: entry.ruleSummary } : {}),
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
import { BUILTIN_GRAPH_CONFIGS, INDEX_EXTRACTOR_VERSION, getGraphIndexDir } from './types.js';
|
|
6
|
-
export const FRAMEWORK_RELATIONS_REVISION =
|
|
6
|
+
export const FRAMEWORK_RELATIONS_REVISION = 5;
|
|
7
7
|
const REVISION = FRAMEWORK_RELATIONS_REVISION;
|
|
8
8
|
const sha256 = (value) => createHash('sha256').update(value).digest('hex');
|
|
9
9
|
/** No absolute paths, git revision or mtimes enter the portable digest. */
|
|
@@ -30,6 +30,8 @@ import { collectGraphIndexFiles, findArtifactFiles, indexPathFor } from './index
|
|
|
30
30
|
import { acquireDirectoryLock } from './prebuilt-build-lock.js';
|
|
31
31
|
import { graphIndexDigest, indexAdapterRegistry, recordIndexVerification } from './index-adapters.js';
|
|
32
32
|
import { loadMemoryRecord } from '../memory/maintenance-record.js';
|
|
33
|
+
import { extractCapability } from './index-capability.js';
|
|
34
|
+
export { extractCapability } from './index-capability.js';
|
|
33
35
|
import { extractTemplateReferences, isTemplateReference } from './template-references.js';
|
|
34
36
|
import { createDependencyResolver, extractFlowDependencies } from './index-dependencies.js';
|
|
35
37
|
function absoluteEntryPath(cwd, entryPath, graph) {
|
|
@@ -81,6 +83,8 @@ export function extractRuleBindings(data, body = '') {
|
|
|
81
83
|
const enforcement = typeof data.enforcement === 'string' ? data.enforcement
|
|
82
84
|
: body.match(/^\*\*Enforcement Level\*\*:\s*([A-Za-z]+)/m)?.[1];
|
|
83
85
|
return {
|
|
86
|
+
rulePrecedence: typeof data.precedence === 'string' ? data.precedence : 'medium',
|
|
87
|
+
ruleOverridable: typeof data.overridable === 'boolean' ? data.overridable : true,
|
|
84
88
|
...(enforcement ? { ruleEnforcement: enforcement.trim().toLowerCase() } : {}),
|
|
85
89
|
...(Array.isArray(data.paths) ? { rulePaths: data.paths.filter((value) => typeof value === 'string') } : {}),
|
|
86
90
|
...(typeof data.activation === 'string' ? { activation: data.activation } : {}),
|
|
@@ -559,30 +563,6 @@ export function extractTriggers(body, frontmatter) {
|
|
|
559
563
|
}
|
|
560
564
|
return [...new Set(phrases)];
|
|
561
565
|
}
|
|
562
|
-
/**
|
|
563
|
-
* Extract a capability summary for a skill/agent/command/rule.
|
|
564
|
-
*
|
|
565
|
-
* Prefers the frontmatter `description` field (used uniformly across
|
|
566
|
-
* AIWG SKILL.md / agent files). Falls back to the first non-heading
|
|
567
|
-
* paragraph of the body. Capped at 240 chars so the index stays
|
|
568
|
-
* token-tight when surfaced via `aiwg index discover`.
|
|
569
|
-
*
|
|
570
|
-
* @implements #1214
|
|
571
|
-
*/
|
|
572
|
-
export function extractCapability(data, body) {
|
|
573
|
-
if (typeof data.description === 'string' && data.description.trim().length > 0) {
|
|
574
|
-
return data.description.trim().slice(0, 240);
|
|
575
|
-
}
|
|
576
|
-
// Fallback: first non-empty paragraph that isn't a heading.
|
|
577
|
-
const stripped = body.replace(/^---\n[\s\S]*?\n---\n/, '');
|
|
578
|
-
for (const block of stripped.split(/\n\s*\n/)) {
|
|
579
|
-
const trimmed = block.trim();
|
|
580
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
581
|
-
continue;
|
|
582
|
-
return trimmed.replace(/\s+/g, ' ').slice(0, 240);
|
|
583
|
-
}
|
|
584
|
-
return undefined;
|
|
585
|
-
}
|
|
586
566
|
/**
|
|
587
567
|
* Extract a SkillScriptSpec from skill frontmatter (#1227).
|
|
588
568
|
*
|
|
@@ -923,7 +903,7 @@ function extractIndexArtifact(job, bindingOnly, warnings = []) {
|
|
|
923
903
|
// Declarative processes have no trigger phrases — they rely on their
|
|
924
904
|
// capability and structure-aware search terms.
|
|
925
905
|
const triggers = isDiscoverable && !flow ? extractTriggers(body, data) : undefined;
|
|
926
|
-
const capability = flow?.capability ?? decision?.capability ?? gatePack?.capability ?? schemaDoc?.capability ?? runbook?.capability ?? (isDiscoverable ? extractCapability(data, body) : undefined);
|
|
906
|
+
const capability = flow?.capability ?? decision?.capability ?? gatePack?.capability ?? schemaDoc?.capability ?? runbook?.capability ?? (isDiscoverable ? extractCapability(data, body, type === 'template' ? extractCanonicalName(data, relativePath) : undefined) : undefined);
|
|
927
907
|
const kind = flow?.kind ?? decision?.kind ?? gatePack?.kind ?? runbook?.kind;
|
|
928
908
|
const sourceType = runbook && physicalType !== 'runbook' ? physicalType : undefined;
|
|
929
909
|
const searchTerms = flow?.searchTerms ?? decision?.searchTerms ?? gatePack?.searchTerms ?? schemaDoc?.searchTerms ?? runbook?.searchTerms;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Derive discovery capabilities from usable prose, with safe title fallbacks for templates.
|
|
2
|
+
function usableText(value) {
|
|
3
|
+
if (typeof value !== 'string')
|
|
4
|
+
return undefined;
|
|
5
|
+
const text = value.trim();
|
|
6
|
+
if (!text || /\{\{[^}]*\}\}|^#/.test(text))
|
|
7
|
+
return undefined;
|
|
8
|
+
return text.replace(/\s+/g, ' ').slice(0, 240);
|
|
9
|
+
}
|
|
10
|
+
export function extractCapability(data, body, fallbackTitle) {
|
|
11
|
+
const description = usableText(data.description);
|
|
12
|
+
if (description)
|
|
13
|
+
return description;
|
|
14
|
+
const stripped = body.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '');
|
|
15
|
+
for (const block of stripped.split(/\r?\n\s*\r?\n/)) {
|
|
16
|
+
const text = usableText(block);
|
|
17
|
+
if (text)
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
// Strip heading markers before considering a title; never surface a raw heading.
|
|
21
|
+
const heading = stripped.match(/^\s*#{1,6}\s+(.+?)(?:\s+#+)?\s*$/m)?.[1];
|
|
22
|
+
return usableText(data.title) ?? usableText(heading) ?? usableText(fallbackTitle);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index-capability.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { diagnoseFacetActivations } from './discover-facets.js';
|
|
4
4
|
import { buildRunHint, DISCOVER_TYPE_ORDER, discoveryIdForEntry, normalizeIndexedPath, scopeRank, showHintForDiscoverResult, } from './query-engine-entries.js';
|
|
5
|
-
import { boundRuleDescriptor, compoundGoverningRules, governingRuleFields, governingRuleStats, RULE_CHECK_OBLIGATION, statsText, } from './query-engine-rules.js';
|
|
5
|
+
import { ruleOrderingFields, boundRuleDescriptor, compoundGoverningRules, governingRuleFields, governingRuleStats, RULE_CHECK_OBLIGATION, statsText, } from './query-engine-rules.js';
|
|
6
6
|
import { tokenize } from './query-engine-scoring.js';
|
|
7
7
|
import { ensureRelations, loadRelations } from './relations.js';
|
|
8
8
|
import { templateRelationFields } from './query-engine-templates.js';
|
|
@@ -47,13 +47,14 @@ export async function emitDiscoverResults(context) {
|
|
|
47
47
|
const relations = resourceSource === 'local' && (!params.graph || params.graph === 'framework')
|
|
48
48
|
? prebuiltRelations ?? (readOnly ? loadRelations(cwd, cwd, false)
|
|
49
49
|
: await ensureRelations(cwd, cwd, { verbose: params.verbose, selection: prebuiltSelection, reconciled: frameworkReconciled })) : undefined;
|
|
50
|
+
const orderingFor = (entry) => ruleOrderingFields(cwd, aiwgRoot ?? cwd, entry, resourceSource === 'local' ? resolvePath(entry) : undefined);
|
|
50
51
|
const governing = scored.map(result => compoundGoverningRules(entries, result.entry, relations ?? undefined, params.phrase));
|
|
51
52
|
const responseRules = new Map();
|
|
52
53
|
for (const item of governing.flat()) {
|
|
53
54
|
const key = `${item.rule.type}:${item.rule.path}`, prior = responseRules.get(key);
|
|
54
55
|
responseRules.set(key, { rule: item.rule, applicability: [...new Set([...(prior?.applicability ?? []), ...item.applicability])] });
|
|
55
56
|
}
|
|
56
|
-
const responseFields = governingRuleFields([...responseRules.values()]);
|
|
57
|
+
const responseFields = governingRuleFields([...responseRules.values()], orderingFor);
|
|
57
58
|
const responseRuleStats = governingRuleStats([...responseRules.values()]);
|
|
58
59
|
const includePaths = params.includePaths ?? true;
|
|
59
60
|
const facetActivations = diagnoseFacetActivations(params.phrase);
|
|
@@ -121,10 +122,11 @@ export async function emitDiscoverResults(context) {
|
|
|
121
122
|
type: r.entry.type,
|
|
122
123
|
name: r.entry.name,
|
|
123
124
|
title: r.entry.title,
|
|
125
|
+
...orderingFor(r.entry),
|
|
124
126
|
...templateRelationFields(r.entry, ruleRelations, 3, includePaths),
|
|
125
127
|
score: Math.round(r.score * 100) / 100,
|
|
126
128
|
ranking: rankingDiagnostic(r.entry, r.score, r.facetDiagnostics),
|
|
127
|
-
...governingRuleFields(governing[resultIndex]),
|
|
129
|
+
...governingRuleFields(governing[resultIndex], orderingFor),
|
|
128
130
|
triggers: r.entry.triggers ?? [],
|
|
129
131
|
capability: r.entry.capability ?? r.entry.summary,
|
|
130
132
|
kernel: r.entry.kernel ?? false,
|
|
@@ -194,6 +196,9 @@ export async function emitDiscoverResults(context) {
|
|
|
194
196
|
const topTrigger = topTriggerMatch?.value ??
|
|
195
197
|
(r.entry.triggers && r.entry.triggers.length > 0 ? r.entry.triggers[0] : '');
|
|
196
198
|
console.log(`${i + 1}. ${r.entry.title}`);
|
|
199
|
+
const ordering = orderingFor(r.entry);
|
|
200
|
+
if ('precedence' in ordering)
|
|
201
|
+
console.log(` precedence: ${ordering.precedence} | overridable: ${ordering.overridable} | source: ${ordering.precedence_source} | project context: ${ordering.project_context}`);
|
|
197
202
|
console.log(` type: ${r.entry.type} score: ${score}${flags ? ` flags: ${flags}` : ''}`);
|
|
198
203
|
console.log(` ${includePaths ? 'path' : 'id'}: ${locator}`);
|
|
199
204
|
if (r.entry.name) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// Resolve governing rules and shape bound-rule checks and summaries.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { parseRuleFrontmatter } from '../rules/activation.mjs';
|
|
4
|
+
import { resolveRulePrecedence } from '../rules/precedence.mjs';
|
|
5
|
+
import { loadRulePinConfigs } from '../rules/pins.mjs';
|
|
6
|
+
import { ruleOrderingAliases } from '../rules/project-precedence.js';
|
|
2
7
|
import { minimatch } from 'minimatch';
|
|
3
8
|
import * as path from 'node:path';
|
|
4
9
|
import { inferRuleActivation } from '../rules/activation.mjs';
|
|
@@ -36,7 +41,7 @@ export function relationshipRules(entries, target, relations) {
|
|
|
36
41
|
const asMetadata = (id) => {
|
|
37
42
|
const rule = relations.index.rules[id];
|
|
38
43
|
return { path: rule.path, type: rule.type, name: rule.name, activation: rule.activation ?? undefined,
|
|
39
|
-
bound_to: rule.bound_to, ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined, rulePaths: rule.paths, triggers: rule.triggers };
|
|
44
|
+
bound_to: rule.bound_to, ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined, rulePrecedence: rule.precedence, ruleOverridable: rule.overridable, rulePaths: rule.paths, triggers: rule.triggers };
|
|
40
45
|
};
|
|
41
46
|
const key = `${target.type}:${discoveryIdForEntry(target)}`;
|
|
42
47
|
const shipped = Object.hasOwn(relations.index.targets, key)
|
|
@@ -49,7 +54,7 @@ export function relationshipRules(entries, target, relations) {
|
|
|
49
54
|
export const RULE_CHECK_OBLIGATION = 'Before governed work, fetch and follow every required rule below; a discovery summary is not the full rule.';
|
|
50
55
|
export function relationMetadata(relations) {
|
|
51
56
|
return Object.values(relations.index.rules).map(rule => ({ path: rule.path, type: rule.type, name: rule.name,
|
|
52
|
-
activation: rule.activation ?? undefined, ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined,
|
|
57
|
+
activation: rule.activation ?? undefined, ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined, rulePrecedence: rule.precedence, ruleOverridable: rule.overridable,
|
|
53
58
|
bound_to: rule.bound_to, rulePaths: rule.paths, triggers: rule.triggers }));
|
|
54
59
|
}
|
|
55
60
|
/** Post-ranking enrichment: relationship lookup never loads the full metadata index. */
|
|
@@ -108,8 +113,9 @@ export function compoundGoverningRules(entries, target, relations, phrase = '',
|
|
|
108
113
|
}
|
|
109
114
|
return [...found.values()].sort((a, b) => (a.rule.name ?? a.rule.path).localeCompare(b.rule.name ?? b.rule.path) || a.rule.path.localeCompare(b.rule.path));
|
|
110
115
|
}
|
|
111
|
-
export function boundRuleDescriptor(rule) {
|
|
116
|
+
export function boundRuleDescriptor(rule, ordering) {
|
|
112
117
|
return { name: rule.name ?? path.basename(rule.path, '.md'), activation: rule.activation ?? null, enforcement: rule.ruleEnforcement ?? null,
|
|
118
|
+
precedence: rule.rulePrecedence ?? 'medium', overridable: rule.ruleOverridable ?? true, precedence_source: 'rule', project_context: false, ...ordering,
|
|
113
119
|
summary: (rule.ruleSummary ?? '').replace(/\s+/g, ' ').trim(), show_command: `aiwg show ${rule.type} ${rule.name ?? path.basename(rule.path, '.md')} --body` };
|
|
114
120
|
}
|
|
115
121
|
/** Counts unique attached contracts; every emitted check is required irrespective of severity. */
|
|
@@ -123,10 +129,10 @@ export function governingRuleStats(governing) {
|
|
|
123
129
|
}
|
|
124
130
|
return stats;
|
|
125
131
|
}
|
|
126
|
-
export function governingRuleFields(governing) {
|
|
132
|
+
export function governingRuleFields(governing, ordering) {
|
|
127
133
|
if (!governing.length)
|
|
128
134
|
return {};
|
|
129
|
-
return { bound_rules: governing.map(({ rule }) => boundRuleDescriptor(rule)), rule_stats: governingRuleStats(governing),
|
|
135
|
+
return { bound_rules: governing.map(({ rule }) => boundRuleDescriptor(rule, ordering?.(rule))), rule_stats: governingRuleStats(governing),
|
|
130
136
|
required_rule_checks: governing.map(({ rule, applicability }) => ({ rule_id: discoveryIdForEntry(rule),
|
|
131
137
|
applicability, fetch_command: `aiwg show ${rule.type} ${discoveryIdForEntry(rule)} --body` })), rule_check_obligation: RULE_CHECK_OBLIGATION };
|
|
132
138
|
}
|
|
@@ -149,11 +155,11 @@ export function relationshipRuleStats(entries, target, relations) {
|
|
|
149
155
|
}
|
|
150
156
|
return stats;
|
|
151
157
|
}
|
|
152
|
-
export async function showBindings(entries, target, content, params, read, relations) {
|
|
158
|
+
export async function showBindings(entries, target, content, params, read, relations, ordering) {
|
|
153
159
|
const governing = compoundGoverningRules(entries, target, relations, '', false, false);
|
|
154
160
|
const rules = governing.map(item => item.rule);
|
|
155
161
|
const boundRules = await Promise.all(rules.map(async (rule) => ({
|
|
156
|
-
...boundRuleDescriptor(rule),
|
|
162
|
+
...boundRuleDescriptor(rule, ordering?.(rule)),
|
|
157
163
|
...((params.boundRuleBodies || params.withRuleBodies) ? { content: await read(rule) } : {}),
|
|
158
164
|
})));
|
|
159
165
|
// Parse the selected rule for reverse lookup, including corpus-only rules.
|
|
@@ -182,7 +188,7 @@ export async function showBindings(entries, target, content, params, read, relat
|
|
|
182
188
|
if (boundRules.length) {
|
|
183
189
|
// Cards already print these stats in the header; body/section output has no header.
|
|
184
190
|
const stats = params.body || params.sections?.length ? `${statsText(governingRuleStats(governing))}\n\n` : '';
|
|
185
|
-
text += `\n## Bound rules\n\n${RULE_CHECK_OBLIGATION}\n\n${stats}` + boundRules.map(rule => `- **${rule.name}** [${rule.activation ?? 'unknown'} / ${rule.enforcement ?? 'unknown'}]: ${rule.summary} (\`${rule.show_command}\`)`
|
|
191
|
+
text += `\n## Bound rules\n\n${RULE_CHECK_OBLIGATION}\n\n${stats}` + boundRules.map(rule => `- **${rule.name}** [${rule.activation ?? 'unknown'} / ${rule.enforcement ?? 'unknown'}; precedence ${rule.precedence}; overridable ${rule.overridable}; source ${rule.precedence_source}]: ${rule.summary} (\`${rule.show_command}\`)`
|
|
186
192
|
+ ('content' in rule ? `\n\n${rule.content}` : '')).join('\n') + '\n';
|
|
187
193
|
}
|
|
188
194
|
if (Object.keys(boundTo).length) {
|
|
@@ -192,10 +198,22 @@ export async function showBindings(entries, target, content, params, read, relat
|
|
|
192
198
|
if (boundTargets.size)
|
|
193
199
|
text += '\nResolved targets: ' + [...boundTargets.values()].map(target => `${target.type} ${target.name ?? target.id}`).join(', ') + '\n';
|
|
194
200
|
return { fields: {
|
|
195
|
-
...governingRuleFields(governing),
|
|
201
|
+
...governingRuleFields(governing, ordering),
|
|
196
202
|
...(['rule', 'behavior'].includes(target.type) ? { bound_to: boundTo, bound_targets: [...boundTargets.values()] } : {}),
|
|
197
203
|
...(boundRules.length ? { bound_rules: boundRules } : {}),
|
|
198
204
|
...(Object.keys(boundTo).length ? { bound_to: boundTo } : {}),
|
|
199
205
|
}, text };
|
|
200
206
|
}
|
|
207
|
+
/** Cards use canonical source when available, so a stale index cannot weaken a rule. */
|
|
208
|
+
export function ruleOrderingFields(cwd, root, entry, file) {
|
|
209
|
+
if (!['rule', 'behavior'].includes(entry.type))
|
|
210
|
+
return {};
|
|
211
|
+
let ordering = { precedence: entry.rulePrecedence, overridable: entry.ruleOverridable };
|
|
212
|
+
if (file && fs.existsSync(file)) {
|
|
213
|
+
const parsed = parseRuleFrontmatter(fs.readFileSync(file, 'utf8'));
|
|
214
|
+
// Discovery preserves legacy binding syntax; ordering itself is validated below.
|
|
215
|
+
ordering = parsed.data && typeof parsed.data === 'object' ? parsed.data : {};
|
|
216
|
+
}
|
|
217
|
+
return resolveRulePrecedence({ ...ordering, name: entry.name, id: discoveryIdForEntry(entry) }, loadRulePinConfigs(cwd), ruleOrderingAliases(file ?? path.resolve(root, entry.path), root, cwd));
|
|
218
|
+
}
|
|
201
219
|
//# sourceMappingURL=query-engine-rules.js.map
|
|
@@ -226,16 +226,16 @@ export function scoreEntryDetailed(entry, text, opts = {}) {
|
|
|
226
226
|
});
|
|
227
227
|
return finish(1.001, 1.001);
|
|
228
228
|
}
|
|
229
|
-
if (nearNameMatch(text, entry.name)) {
|
|
229
|
+
if (nearNameMatch(text, entry.name) || verbose?.names(entry.name)) {
|
|
230
230
|
matches.push({
|
|
231
231
|
field: 'name',
|
|
232
|
-
match: 'near-name',
|
|
232
|
+
match: verbose?.names(entry.name) ? 'contained-phrase' : 'near-name',
|
|
233
233
|
value: entry.name,
|
|
234
234
|
contribution: 0.951,
|
|
235
|
-
matched_tokens: tokens,
|
|
236
|
-
query_token_coverage: 1,
|
|
235
|
+
matched_tokens: verbose?.names(entry.name) ? tokenize(entry.name) : tokens,
|
|
236
|
+
query_token_coverage: verbose?.names(entry.name) ? tokenize(entry.name).length / tokens.length : 1,
|
|
237
237
|
});
|
|
238
|
-
return finish(0.951);
|
|
238
|
+
return finish(0.951, verbose?.names(entry.name) ? 0.951 : undefined);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
// Searchable text — joined once so per-token includes() is cheap
|