@aiwg/cli 2026.11.3 → 2026.11.5
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 +85 -18
- package/agentic/code/providers/model-capabilities.v1.json +35 -27
- 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 +9 -27
- 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 +29 -11
- 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/script-runner.js +7 -4
- package/dist/src/cli/handlers/sessions.js +1 -1
- package/dist/src/cli/handlers/steward-format.js +12 -0
- package/dist/src/cli/handlers/steward.js +1 -1
- package/dist/src/cli/handlers/use.js +14 -6
- package/dist/src/cli/handlers/utility-doctor.js +9 -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/manifest.js +6 -0
- package/dist/src/extensions/muse-managed-hooks.js +11 -0
- package/dist/src/extensions/project-local-discovery.js +21 -1
- package/dist/src/extensions/project-local-scaffold.js +19 -7
- package/dist/src/extensions/user-hook-diagnostics.js +32 -0
- package/dist/src/extensions/verified-hook-command.js +32 -0
- package/dist/src/lint/rule-conflicts.js +52 -0
- package/dist/src/lint/runner.js +3 -0
- package/dist/src/mcp/cli.mjs +3 -1
- package/dist/src/mcp/elicitation.mjs +30 -0
- package/dist/src/mcp/grok-build-config.mjs +1 -1
- package/dist/src/mcp/muse-native-config.mjs +1 -0
- package/dist/src/mcp/server.mjs +2 -0
- package/dist/src/mcp/tools/authorization.mjs +78 -0
- package/dist/src/models/factory-models.js +144 -0
- package/dist/src/models/model-capabilities.v1.json +35 -27
- package/dist/src/models/model-discovery.js +7 -3
- package/dist/src/models/worker-installation.d.mts +2 -0
- package/dist/src/models/worker-installation.mjs +11 -2
- package/dist/src/models/worker-invocation-policy.js +25 -1
- package/dist/src/models/wrapper-enforcement.js +1 -1
- 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/policy/repo-access.js +3 -1
- package/dist/src/process/bounded-child-process.mjs +49 -39
- package/dist/src/providers/capability-matrix.yaml +85 -18
- package/dist/src/providers/deployment-ownership.d.mts +1 -0
- package/dist/src/providers/deployment-ownership.mjs +29 -3
- package/dist/src/providers/deployment-preservation.mjs +44 -3
- package/dist/src/providers/grok-build-acp.js +13 -5
- package/dist/src/providers/grok-build-dispatch.js +35 -2
- package/dist/src/providers/grok-build-headless.js +171 -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/serve/worker-stdin-frame.mjs +1 -1
- package/dist/src/sessions/adapters/grok-build-fallback.js +33 -0
- package/dist/src/sessions/adapters/grok-build-native-records.js +134 -0
- package/dist/src/sessions/adapters/grok-build-native.js +237 -98
- package/dist/src/sessions/adapters/grok-build.js +95 -32
- package/dist/src/sessions/grok-build-cli-output.js +113 -0
- package/dist/src/sessions/grok-build-cli.js +4 -28
- package/dist/src/sessions/normalization.js +1 -1
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +4 -3
- package/dist/src/smiths/context-pipeline/finalization.js +5 -0
- package/dist/src/smiths/context-pipeline/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +20 -17
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +6 -1
- package/dist/src/smiths/context-pipeline/workspace-document.js +6 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -12
- package/dist/src/smiths/hook-bridge/codex-translator.js +11 -14
- package/dist/src/smiths/hook-bridge/codex-trust.js +7 -2
- package/dist/src/smiths/hook-bridge/copilot-translator.js +2 -1
- package/dist/src/smiths/hook-bridge/factory-trust.js +2 -2
- package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +81 -0
- package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
- package/dist/src/smiths/hook-bridge/hermes-trust.js +65 -0
- 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 +9 -8
- package/tools/agents/deploy-options.mjs +3 -0
- package/tools/agents/providers/base-frontmatter.mjs +3 -2
- package/tools/agents/providers/base-inventory.mjs +3 -1
- package/tools/agents/providers/base-kernel-skills.mjs +11 -5
- 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 +34 -41
- package/tools/agents/providers/model-wrapper.mjs +2 -5
- 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-commit.mjs +3 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +7 -5
- package/tools/agents/providers/rule-deployment-state.mjs +14 -6
- package/tools/agents/providers/rule-projection.mjs +39 -4
- package/tools/agents/providers/rule-startup.mjs +11 -10
- package/tools/agents/providers/skill-copy-prune.mjs +12 -0
- package/tools/agents/providers/staged-directory-reference.mjs +14 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +24 -10
- 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/tools/ralph-external/lib/claude-adapter.mjs +2 -0
- package/tools/ralph-external/lib/factory-adapter.mjs +6 -2
- package/tools/ralph-external/lib/worker-inputs.mjs +20 -1
- package/tools/ralph-external/lib/worker-isolation.mjs +1 -0
- package/tools/ralph-external/lib/worker-termination.mjs +21 -12
- package/tools/ralph-external/session-launcher.mjs +22 -17
- package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Fail-closed parsers for the captured Grok Build 1.0.77 public CLI output.
|
|
2
|
+
import { SessionContractError } from './contracts.js';
|
|
3
|
+
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}';
|
|
4
|
+
const listRow = new RegExp(`^(${UUID}) \\d{4}-\\d{2}-\\d{2} \\d{4}-\\d{2}-\\d{2} local .+$`, 'i');
|
|
5
|
+
const searchRow = new RegExp(`^(${UUID}) \\(score: \\d+\\.\\d+\\) [A-Z][a-z]{2} \\d{2}, +\\d{1,2}:\\d{2}[ap]m$`, 'i');
|
|
6
|
+
const drift = (message) => { throw new SessionContractError('SCHEMA_DRIFT', `unrecognized Grok Build ${message}; check CLI version and use a supported export`); };
|
|
7
|
+
export function parseGrokSessionIds(stdout, mode) {
|
|
8
|
+
const lines = stdout.split(/\r?\n/).filter(line => line.trim());
|
|
9
|
+
if (lines.length === 1 && lines[0] === 'No sessions found.')
|
|
10
|
+
return [];
|
|
11
|
+
const ids = [];
|
|
12
|
+
let header = false;
|
|
13
|
+
let total;
|
|
14
|
+
let label = false;
|
|
15
|
+
for (const line of lines) {
|
|
16
|
+
if (mode === 'list') {
|
|
17
|
+
if (line === '(no label)' || /^Label: .+$/.test(line)) {
|
|
18
|
+
if (label)
|
|
19
|
+
drift('list label');
|
|
20
|
+
label = true;
|
|
21
|
+
header = false;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (/^SESSION ID +CREATED +UPDATED +STATUS +SUMMARY$/.test(line)) {
|
|
25
|
+
if (header)
|
|
26
|
+
drift('list header');
|
|
27
|
+
header = true;
|
|
28
|
+
label = false;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const row = listRow.exec(line);
|
|
32
|
+
if (!header || !row)
|
|
33
|
+
drift('list row');
|
|
34
|
+
ids.push(row[1].toLowerCase());
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (total !== undefined)
|
|
38
|
+
drift('search trailer');
|
|
39
|
+
const row = searchRow.exec(line);
|
|
40
|
+
if (row) {
|
|
41
|
+
ids.push(row[1].toLowerCase());
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (/^Total: \d+$/.test(line)) {
|
|
45
|
+
total = Number(line.slice(7));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (/^ \S/.test(line) && ids.length)
|
|
49
|
+
continue;
|
|
50
|
+
drift('search row');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (mode === 'list' ? !header || label : total !== ids.length)
|
|
54
|
+
drift(`${mode} output`);
|
|
55
|
+
if (new Set(ids).size !== ids.length)
|
|
56
|
+
drift(`${mode} duplicate session IDs`);
|
|
57
|
+
return ids;
|
|
58
|
+
}
|
|
59
|
+
const resultKeys = ['text', 'stopReason', 'sessionId', 'requestId', 'cwd', 'thought', 'usage', 'num_turns', 'total_cost_usd', 'total_cost_usd_ticks', 'modelUsage'];
|
|
60
|
+
const eventKeys = {
|
|
61
|
+
text: ['type', 'data'], thought: ['type', 'data'],
|
|
62
|
+
available_commands: ['type', 'tools', 'commands'],
|
|
63
|
+
usage: ['type', 'usage', 'signature'],
|
|
64
|
+
tool_call: ['type', 'toolCallId', 'title', 'kind', 'status', 'toolName', 'rawInput', 'content', 'locations'],
|
|
65
|
+
tool_call_update: ['type', 'toolCallId', 'status', 'content', 'rawOutput', 'locations'],
|
|
66
|
+
end: ['type', ...resultKeys.filter(k => k !== 'text' && k !== 'thought')],
|
|
67
|
+
};
|
|
68
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
69
|
+
export function validateGrokHeadlessEnvelope(value, format) {
|
|
70
|
+
const type = format === 'json' ? 'result' : String(value.type);
|
|
71
|
+
const keys = type === 'result' ? resultKeys : eventKeys[type];
|
|
72
|
+
if (!keys || Object.keys(value).some(key => !keys.includes(key)))
|
|
73
|
+
drift('headless event');
|
|
74
|
+
if (type === 'result' || type === 'end') {
|
|
75
|
+
for (const key of ['sessionId', 'requestId', 'cwd', 'stopReason'])
|
|
76
|
+
if (typeof value[key] !== 'string')
|
|
77
|
+
drift('headless result');
|
|
78
|
+
for (const key of ['usage', 'modelUsage'])
|
|
79
|
+
if (!object(value[key]))
|
|
80
|
+
drift('headless usage');
|
|
81
|
+
for (const key of ['num_turns', 'total_cost_usd', 'total_cost_usd_ticks'])
|
|
82
|
+
if (typeof value[key] !== 'number' || !Number.isFinite(value[key]))
|
|
83
|
+
drift('headless usage');
|
|
84
|
+
if (type === 'result' && (typeof value.text !== 'string' || typeof value.thought !== 'string'))
|
|
85
|
+
drift('headless result');
|
|
86
|
+
}
|
|
87
|
+
else if (type === 'text' || type === 'thought') {
|
|
88
|
+
if (typeof value.data !== 'string')
|
|
89
|
+
drift('headless text');
|
|
90
|
+
}
|
|
91
|
+
else if (type === 'available_commands') {
|
|
92
|
+
if (!Array.isArray(value.tools) || !Array.isArray(value.commands))
|
|
93
|
+
drift('headless commands');
|
|
94
|
+
}
|
|
95
|
+
else if (type === 'usage') {
|
|
96
|
+
if (!object(value.usage) || typeof value.signature !== 'string')
|
|
97
|
+
drift('headless usage');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (typeof value.toolCallId !== 'string' || !value.toolCallId || !Array.isArray(value.content) || !Array.isArray(value.locations))
|
|
101
|
+
drift('headless tool call');
|
|
102
|
+
if (type === 'tool_call') {
|
|
103
|
+
for (const key of ['title', 'kind', 'status', 'toolName'])
|
|
104
|
+
if (typeof value[key] !== 'string')
|
|
105
|
+
drift('headless tool call');
|
|
106
|
+
if (!object(value.rawInput))
|
|
107
|
+
drift('headless tool call');
|
|
108
|
+
}
|
|
109
|
+
else if (!(value.status === null || typeof value.status === 'string') || !(value.rawOutput === null || object(value.rawOutput)))
|
|
110
|
+
drift('headless tool update');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=grok-build-cli-output.js.map
|
|
@@ -5,6 +5,7 @@ import { delimiter, dirname, isAbsolute, join, parse, resolve } from 'node:path'
|
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
6
|
import { resolveGrokHomeResult } from '../providers/grok-build-paths.js';
|
|
7
7
|
import { SessionContractError } from './contracts.js';
|
|
8
|
+
import { validateGrokHeadlessEnvelope, parseGrokSessionIds } from './grok-build-cli-output.js';
|
|
8
9
|
import { validateGrokBuildMarkdown } from './adapters/grok-build.js';
|
|
9
10
|
const execFile = promisify(execFileCallback);
|
|
10
11
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
@@ -15,7 +16,7 @@ export async function grokBuildList(options, limit = 20) {
|
|
|
15
16
|
throw new SessionContractError('INVALID_ARGUMENT', 'Grok Build list limit must be 1..500');
|
|
16
17
|
}
|
|
17
18
|
const stdout = await runGrok(options, ['sessions', 'list', '--limit', String(limit)]);
|
|
18
|
-
return
|
|
19
|
+
return parseGrokSessionIds(stdout, 'list');
|
|
19
20
|
}
|
|
20
21
|
export async function grokBuildSearch(options, query, limit = 20) {
|
|
21
22
|
if (!query.trim() || query.length > 500 || /[\x00-\x1f\x7f]/.test(query)) {
|
|
@@ -25,7 +26,7 @@ export async function grokBuildSearch(options, query, limit = 20) {
|
|
|
25
26
|
throw new SessionContractError('INVALID_ARGUMENT', 'Grok Build search limit must be 1..500');
|
|
26
27
|
}
|
|
27
28
|
const stdout = await runGrok(options, ['sessions', 'search', query, '--limit', String(limit)]);
|
|
28
|
-
return
|
|
29
|
+
return parseGrokSessionIds(stdout, 'search');
|
|
29
30
|
}
|
|
30
31
|
export async function grokBuildExport(options, sessionId, outputDirectory) {
|
|
31
32
|
const id = assertGrokSessionId(sessionId);
|
|
@@ -70,6 +71,7 @@ export function parseGrokHeadlessSessionId(output, format) {
|
|
|
70
71
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
71
72
|
throw new SessionContractError('SCHEMA_DRIFT', 'Grok Build headless event must be an object');
|
|
72
73
|
}
|
|
74
|
+
validateGrokHeadlessEnvelope(value, format);
|
|
73
75
|
const id = value.sessionId;
|
|
74
76
|
if (id !== undefined) {
|
|
75
77
|
if (typeof id !== 'string' || !UUID.test(id)) {
|
|
@@ -201,32 +203,6 @@ async function isExecutableFile(path) {
|
|
|
201
203
|
return false;
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
|
-
function parseSessionIds(stdout, mode) {
|
|
205
|
-
const ids = [];
|
|
206
|
-
let recognized = false;
|
|
207
|
-
for (const line of stdout.split(/\r?\n/)) {
|
|
208
|
-
if (!line.trim())
|
|
209
|
-
continue;
|
|
210
|
-
if (line === 'No sessions found.' || line.startsWith('SESSION ID ') || line.startsWith('Label: ')
|
|
211
|
-
|| line === '(no label)' || /^Total: \d+$/.test(line)) {
|
|
212
|
-
recognized = true;
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
const id = /^([0-9a-f-]{36})(?:\s|$)/i.exec(line)?.[1];
|
|
216
|
-
if (id && UUID.test(id)) {
|
|
217
|
-
ids.push(id.toLowerCase());
|
|
218
|
-
recognized = true;
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (mode === 'search' && /^ \S/.test(line) && recognized)
|
|
222
|
-
continue;
|
|
223
|
-
throw new SessionContractError('SCHEMA_DRIFT', `unrecognized Grok Build ${mode} output; check CLI version`);
|
|
224
|
-
}
|
|
225
|
-
if (!recognized) {
|
|
226
|
-
throw new SessionContractError('SCHEMA_DRIFT', `empty Grok Build ${mode} output; check CLI version`);
|
|
227
|
-
}
|
|
228
|
-
return [...new Set(ids)];
|
|
229
|
-
}
|
|
230
206
|
async function safeDirectory(input) {
|
|
231
207
|
if (!isAbsolute(input) || parse(resolve(input)).root === resolve(input)) {
|
|
232
208
|
throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Grok Build directory must be an absolute non-root path');
|
|
@@ -13,7 +13,7 @@ export function normalizeSessionBatch(request, records, digests, importRunId, so
|
|
|
13
13
|
const events = records.map((record, index) => {
|
|
14
14
|
const sessionId = stableSessionId(request.source.provider, request.source.sourceId, record.nativeSessionId);
|
|
15
15
|
const native = sanitizeNativeExtensions(record.extensions ?? {});
|
|
16
|
-
const lineage = request.source.provider
|
|
16
|
+
const lineage = ['codex', 'grok-build'].includes(request.source.provider) && native.value.lineage
|
|
17
17
|
? { lineage: native.value.lineage } : {};
|
|
18
18
|
const images = extractEventImages({
|
|
19
19
|
searchableText: record.text,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Migrate startup ownership without nesting markers or discarding operator text.
|
|
2
|
+
import { buildRuleStartupBootstrapBlock } from './workspace-bootstrap.js';
|
|
2
3
|
export const AGENTS_HEADER = '# AGENTS.md\n<!-- aiwg-managed -->\n<!-- Generated by AIWG. Edit AGENTS.override.md for operator additions. -->\n';
|
|
3
4
|
const bootstrapBlock = /<!-- AIWG:provider-bootstrap:start -->[\s\S]*?<!-- AIWG:provider-bootstrap:end -->/g;
|
|
4
5
|
export const hasRuleStartup = (content) => /<!-- AIWG:rule-hook-[\w-]+:start -->/.test(content);
|
|
@@ -42,9 +43,9 @@ export function preserveBridgeOperatorText(existing, generated) {
|
|
|
42
43
|
const fallback = generated.match(bootstrapBlock)?.[0];
|
|
43
44
|
if (!fallback)
|
|
44
45
|
return generated;
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
const bootstrap = hasRuleStartup(existing) ?
|
|
46
|
+
// Refresh the shared rule-deployment bootstrap too; retain core and harness
|
|
47
|
+
// hooks independently rather than preserving obsolete startup instructions.
|
|
48
|
+
const bootstrap = hasRuleStartup(existing) ? buildRuleStartupBootstrapBlock() : fallback;
|
|
48
49
|
return normalizeRuleStartup(existing, bootstrap, true);
|
|
49
50
|
}
|
|
50
51
|
//# sourceMappingURL=bridge-ownership.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RULE_PRECEDENCE_TEXT } from '../../rules/precedence.mjs';
|
|
1
2
|
import { maskCodeRegions } from './code-regions.js';
|
|
2
3
|
import { assertSafeContextFile, writeContextFileSync } from './context-file-safety.js';
|
|
3
4
|
/**
|
|
@@ -68,6 +69,10 @@ export async function buildContextFinalizationBlock(projectPath, documentPath =
|
|
|
68
69
|
`- Recorded deployments: ${formatList([...providerDeployments].sort())}`,
|
|
69
70
|
'- Generated framework context: `AIWG.md`',
|
|
70
71
|
'',
|
|
72
|
+
'### Rule Precedence',
|
|
73
|
+
'',
|
|
74
|
+
RULE_PRECEDENCE_TEXT,
|
|
75
|
+
'',
|
|
71
76
|
'### Capability Routing',
|
|
72
77
|
'',
|
|
73
78
|
'Routing authority: `aiwg show rule skill-discovery` (kernel); capability phrases: `aiwg show skill aiwg-utils-quickref`.',
|
|
@@ -319,7 +319,7 @@ export async function generate(opts) {
|
|
|
319
319
|
// AGENTS.md emission is gated on the provider's link-mechanism: codex/copilot/
|
|
320
320
|
// cursor/windsurf/hermes/warp/factory/opencode use AGENTS.md as their bridge
|
|
321
321
|
// to AIWG.md. Claude uses CLAUDE.md hook instead (#1437); openclaw is
|
|
322
|
-
// home-dir-only
|
|
322
|
+
// home-dir-only; generic emits a portable, host-loaded AGENTS.md bridge.
|
|
323
323
|
if (opts.provider !== 'flue' && !opts.skip?.agentsMd && shouldEmitAgentsMd(opts.provider)) {
|
|
324
324
|
const agentsMdPath = path.join(opts.projectPath, 'AGENTS.md');
|
|
325
325
|
let canWrite = true;
|
|
@@ -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
|
-
|
|
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,8 +7,10 @@ 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';
|
|
11
12
|
import { diagnoseFactoryHookTrust } from '../hook-bridge/factory-trust.js';
|
|
13
|
+
import { diagnoseHermesHookAcceptance } from '../hook-bridge/hermes-trust.js';
|
|
12
14
|
import { maskCodeRegions } from './code-regions.js';
|
|
13
15
|
export { maskCodeRegions } from './code-regions.js';
|
|
14
16
|
export function markdownLinks(content) {
|
|
@@ -37,13 +39,16 @@ export async function workspaceLinkedFiles(projectPath) {
|
|
|
37
39
|
return [...new Set(files)].sort();
|
|
38
40
|
}
|
|
39
41
|
export async function diagnoseWorkspaceContext(projectPath) {
|
|
40
|
-
const diagnostics =
|
|
42
|
+
const diagnostics = await diagnoseUserHookCommands();
|
|
41
43
|
const codexTrust = await diagnoseCodexHookTrust(projectPath);
|
|
42
44
|
if (codexTrust)
|
|
43
45
|
diagnostics.push(codexTrust);
|
|
44
46
|
const factoryTrust = await diagnoseFactoryHookTrust(projectPath);
|
|
45
47
|
if (factoryTrust)
|
|
46
48
|
diagnostics.push(factoryTrust);
|
|
49
|
+
const hermesAcceptance = await diagnoseHermesHookAcceptance();
|
|
50
|
+
if (hermesAcceptance)
|
|
51
|
+
diagnostics.push(hermesAcceptance);
|
|
47
52
|
const root = path.resolve(projectPath);
|
|
48
53
|
const scopes = new Map();
|
|
49
54
|
// 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,
|
|
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
|
|
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
|
|
23
|
+
function commandHook(source) {
|
|
32
24
|
const command = substituteEnvVars(source.command, 'codex');
|
|
33
|
-
const args = (source.args || []).map(a => shellArgument(substituteEnvVars(a, 'codex')
|
|
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
|
-
|
|
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: [
|
|
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
|
-
|
|
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');
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
7
|
import { isFactoryManaged, readFactoryDocument } from './factory-hook-config.js';
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
|
-
export const FACTORY_HOOK_TRUST_NEXT_STEP = 'Trust this folder in droid;
|
|
9
|
+
export const FACTORY_HOOK_TRUST_NEXT_STEP = 'Trust this folder in droid; hooks need a git repo with at least one commit.';
|
|
10
10
|
export function factoryHookTrustNextStep(trust) {
|
|
11
11
|
return trust && (trust.project !== 'trusted' || !trust.gitCommit) ? FACTORY_HOOK_TRUST_NEXT_STEP : '';
|
|
12
12
|
}
|
|
@@ -34,7 +34,7 @@ export async function readFactoryHookTrust(projectPath) {
|
|
|
34
34
|
// Missing, unreadable, or malformed settings cannot establish trust.
|
|
35
35
|
}
|
|
36
36
|
try {
|
|
37
|
-
await execFileAsync('git', ['rev-parse', '--verify', 'HEAD'], {
|
|
37
|
+
await execFileAsync('git', ['rev-parse', '--verify', 'HEAD^{commit}'], {
|
|
38
38
|
cwd: root, timeout: 2000, maxBuffer: 4096, windowsHide: true,
|
|
39
39
|
});
|
|
40
40
|
trust.gitCommit = true;
|
|
@@ -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,
|
|
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,81 @@
|
|
|
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
|
+
import { verifiedHookCommand } from '../../extensions/verified-hook-command.js';
|
|
9
|
+
import { hermesHookAcceptanceNextStep, readHermesHookAcceptance } from './hermes-trust.js';
|
|
10
|
+
export async function translateHermesPromptDiscovery(source, options) {
|
|
11
|
+
const home = resolveHermesHomePath();
|
|
12
|
+
const directory = path.join(home, 'agent-hooks');
|
|
13
|
+
const script = path.join(directory, 'aiwg-prompt-discovery.cjs');
|
|
14
|
+
const config = path.join(home, 'config.yaml');
|
|
15
|
+
const result = { provider: 'hermes', skipped: false, warnings: [], emittedPaths: [] };
|
|
16
|
+
if (options.dryRun)
|
|
17
|
+
return { ...result, emittedPaths: [script, config].map(file => `${file} (dry-run)`) };
|
|
18
|
+
for (const file of [home, directory, script, config]) {
|
|
19
|
+
try {
|
|
20
|
+
if ((await fs.lstat(file)).isSymbolicLink())
|
|
21
|
+
throw new Error(`Refusing symlinked Hermes hook target: ${file}`);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code !== 'ENOENT')
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const original = await fs.readFile(config, 'utf8').catch(error => {
|
|
29
|
+
if (error.code !== 'ENOENT')
|
|
30
|
+
throw error;
|
|
31
|
+
return '';
|
|
32
|
+
});
|
|
33
|
+
const doc = parseDocument(original || '{}');
|
|
34
|
+
if (doc.errors.length || !isMap(doc.contents))
|
|
35
|
+
throw new Error(`Invalid Hermes config: ${config}`);
|
|
36
|
+
if (!doc.has('hooks'))
|
|
37
|
+
doc.set('hooks', doc.createNode({}));
|
|
38
|
+
const hooks = doc.get('hooks', true);
|
|
39
|
+
if (!isMap(hooks))
|
|
40
|
+
throw new Error('Invalid Hermes hooks mapping');
|
|
41
|
+
if (!hooks.has('pre_llm_call'))
|
|
42
|
+
hooks.set('pre_llm_call', doc.createNode([]));
|
|
43
|
+
const entries = hooks.get('pre_llm_call', true);
|
|
44
|
+
if (!isSeq(entries) || entries.items.some(entry => !isMap(entry) || typeof entry.get('command') !== 'string')) {
|
|
45
|
+
throw new Error('Invalid Hermes pre_llm_call hooks');
|
|
46
|
+
}
|
|
47
|
+
const sourceScript = source.args?.[0];
|
|
48
|
+
if (!sourceScript)
|
|
49
|
+
throw new Error('Missing shared prompt discovery script');
|
|
50
|
+
const bytes = await fs.readFile(sourceScript);
|
|
51
|
+
const registration = { command: verifiedHookCommand(home, 'agent-hooks/aiwg-prompt-discovery.cjs', bytes, [], 'user'), timeout: source.timeout ?? 2,
|
|
52
|
+
_aiwg_managed: true, _aiwg_id: source.id };
|
|
53
|
+
const managed = entries.items.filter(entry => isMap(entry) && entry.get('_aiwg_managed') === true && entry.get('_aiwg_id') === source.id);
|
|
54
|
+
const current = managed[0];
|
|
55
|
+
// Leave matching nodes intact to preserve comments and byte-stable redeployment.
|
|
56
|
+
if (managed.length !== 1 || !isMap(current) || JSON.stringify(current.toJSON()) !== JSON.stringify(registration)) {
|
|
57
|
+
entries.items = entries.items.filter(entry => !managed.includes(entry));
|
|
58
|
+
entries.add(doc.createNode(registration));
|
|
59
|
+
}
|
|
60
|
+
const roots = [config, directory, path.join(home, '.aiwg-manifest.json')];
|
|
61
|
+
const before = captureDeploymentOutputs(roots);
|
|
62
|
+
const state = await managedHookScriptState(home, path.relative(home, script), bytes);
|
|
63
|
+
if (state === 'operator-edited' || state === 'unreadable')
|
|
64
|
+
result.warnings.push(`${script}: kept (${state})`);
|
|
65
|
+
else {
|
|
66
|
+
await fs.mkdir(directory, { recursive: true });
|
|
67
|
+
if (state)
|
|
68
|
+
await fs.writeFile(script, bytes, { mode: 0o755 });
|
|
69
|
+
result.emittedPaths.push(script);
|
|
70
|
+
}
|
|
71
|
+
const text = doc.toString();
|
|
72
|
+
if (text !== original)
|
|
73
|
+
await fs.writeFile(config, text);
|
|
74
|
+
result.emittedPaths.push(config);
|
|
75
|
+
recordDeploymentOutputs(before, roots, { frameworkSlug: 'aiwg-hooks', claimUnchangedSettings: false, writtenFiles: result.emittedPaths });
|
|
76
|
+
const nextStep = hermesHookAcceptanceNextStep(await readHermesHookAcceptance());
|
|
77
|
+
if (nextStep)
|
|
78
|
+
result.warnings.push(nextStep);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
//# 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 {
|
|
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 =
|
|
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));
|