@aiwg/cli 2026.11.4 → 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/providers/capability-matrix.yaml +75 -5
- package/agentic/code/providers/model-capabilities.v1.json +35 -27
- package/dist/src/artifacts/index-builder.js +4 -2
- package/dist/src/artifacts/query-engine-rules.js +2 -2
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/script-runner.js +7 -4
- package/dist/src/cli/handlers/steward-format.js +12 -0
- package/dist/src/cli/handlers/use.js +13 -4
- package/dist/src/cli/handlers/utility-doctor.js +4 -0
- package/dist/src/extensions/manifest.js +6 -0
- package/dist/src/extensions/project-local-discovery.js +21 -1
- package/dist/src/extensions/project-local-scaffold.js +19 -7
- 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/repo-access.js +3 -1
- package/dist/src/providers/capability-matrix.yaml +75 -5
- package/dist/src/providers/deployment-ownership.mjs +8 -1
- 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 +2 -1
- package/dist/src/serve/worker-stdin-frame.mjs +1 -1
- package/dist/src/sessions/adapters/grok-build-native-records.js +77 -7
- package/dist/src/sessions/adapters/grok-build-native.js +148 -1
- package/dist/src/sessions/adapters/grok-build.js +36 -14
- package/dist/src/sessions/normalization.js +1 -1
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +4 -0
- package/dist/src/smiths/hook-bridge/factory-trust.js +2 -2
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +10 -7
- package/dist/src/smiths/hook-bridge/hermes-trust.js +65 -0
- package/package.json +1 -1
- package/tools/agents/deploy-agents.mjs +4 -2
- package/tools/agents/deploy-options.mjs +2 -0
- package/tools/agents/providers/base-inventory.mjs +3 -1
- package/tools/agents/providers/base-kernel-skills.mjs +11 -5
- package/tools/agents/providers/grok-build.mjs +31 -40
- package/tools/agents/providers/model-wrapper.mjs +2 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +3 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +2 -2
- package/tools/agents/providers/rule-projection.mjs +39 -4
- package/tools/agents/providers/skill-copy-prune.mjs +12 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +24 -10
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Bounded native projection pinned to the captured Grok Build 1.0.77 store.
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { lstat, opendir, readFile } from 'node:fs/promises';
|
|
3
4
|
import { basename, dirname, isAbsolute, parse, resolve } from 'node:path';
|
|
4
5
|
import { z } from 'zod';
|
|
@@ -7,7 +8,7 @@ import { schemaIssueDetail, schemaRejectionDetail, SessionContractError, assertS
|
|
|
7
8
|
import { matchSessionWorkspace } from '../workspace-matching.js';
|
|
8
9
|
import { authorizeSourceFile } from '../policy.js';
|
|
9
10
|
import { streamBoundedJsonLines, readBoundedText, } from '../readers.js';
|
|
10
|
-
import { nativeDrift, parseNativeSummary, projectNativeLine, nativeProjectionRecord } from './grok-build-native-records.js';
|
|
11
|
+
import { nativeDrift, parseNativeSummary, parseNativeCompactionCheckpoint, projectNativeLine, nativeProjectionRecord, projectNativeUpdate } from './grok-build-native-records.js';
|
|
11
12
|
export const GROK_BUILD_NATIVE_SCHEMA_VERSION = '1.0.0';
|
|
12
13
|
export const GROK_BUILD_NATIVE_SCHEMA_MAJOR = 1;
|
|
13
14
|
export const GROK_BUILD_NATIVE_LOCATOR_CLASS = 'grok-build-native-chat-history';
|
|
@@ -156,12 +157,18 @@ export async function readGrokBuildNativeChatHistory(source, limits) {
|
|
|
156
157
|
nativeDrift();
|
|
157
158
|
}
|
|
158
159
|
const sessionMetadata = parseNativeSummary(metadata, sessionId, cwd);
|
|
160
|
+
const subagents = await readNativeSubagents(source, sessionId, limits);
|
|
161
|
+
if (subagents.length)
|
|
162
|
+
sessionMetadata.lineage = { ...sessionMetadata.lineage, subagents };
|
|
159
163
|
const input = await streamBoundedJsonLines({ selectedPath: source.locator, allowedRoots: source.authorizedScope.allowedRoots }, { consistency: 'complete', limits });
|
|
160
164
|
const records = [];
|
|
161
165
|
const calls = new Set();
|
|
162
166
|
const results = new Set();
|
|
163
167
|
let promptIndex = -1;
|
|
168
|
+
let compacted = false;
|
|
164
169
|
for await (const line of input) {
|
|
170
|
+
if (line.value?.synthetic_reason === 'compaction_meta')
|
|
171
|
+
compacted = true;
|
|
165
172
|
const projected = projectNativeLine(line, cwd, sessionMetadata);
|
|
166
173
|
const raw = line.value;
|
|
167
174
|
if (raw.prompt_index !== undefined) {
|
|
@@ -184,10 +191,150 @@ export async function readGrokBuildNativeChatHistory(source, limits) {
|
|
|
184
191
|
records.push(entry);
|
|
185
192
|
}
|
|
186
193
|
}
|
|
194
|
+
const updates = await readNativeUpdates(source, sessionId, cwd, sessionMetadata, records, compacted, limits);
|
|
195
|
+
if (updates)
|
|
196
|
+
return { records: updates, incompleteTail: false };
|
|
187
197
|
if (records.length === 0)
|
|
188
198
|
throw new SessionContractError('MALFORMED_SOURCE', 'Grok Build native chat history is empty; use `grok export <session-id> <session-id>.md`.');
|
|
189
199
|
return { records, incompleteTail: input.incompleteTail };
|
|
190
200
|
}
|
|
201
|
+
/** Read optional siblings with the same bounded authorization and symlink policy. */
|
|
202
|
+
async function nativeSibling(source, path, limits) {
|
|
203
|
+
try {
|
|
204
|
+
await rejectNativeSymlinks(path);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error.code === 'ENOENT')
|
|
208
|
+
return undefined;
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
const input = await readBoundedText({ selectedPath: path, allowedRoots: source.authorizedScope.allowedRoots }, limits);
|
|
212
|
+
try {
|
|
213
|
+
return JSON.parse(input.value);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
nativeDrift();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const subagentSchema = z.looseObject({
|
|
220
|
+
subagent_id: z.string().uuid(), parent_session_id: z.string().uuid().optional(),
|
|
221
|
+
child_session_id: z.string().uuid().optional(), status: z.enum(['running', 'completed', 'cancelled', 'failed']).optional(),
|
|
222
|
+
});
|
|
223
|
+
const outputSchema = z.strictObject({ schema_version: z.literal(1), output: z.string() });
|
|
224
|
+
async function readNativeSubagents(source, sessionId, limits) {
|
|
225
|
+
const path = resolve(dirname(source.locator), 'subagents');
|
|
226
|
+
try {
|
|
227
|
+
await rejectNativeSymlinks(path);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
if (error.code === 'ENOENT')
|
|
231
|
+
return [];
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
const directory = await opendir(path);
|
|
235
|
+
const names = [];
|
|
236
|
+
for await (const entry of directory) {
|
|
237
|
+
if (!UUID.test(entry.name))
|
|
238
|
+
nativeDrift();
|
|
239
|
+
if (entry.isSymbolicLink())
|
|
240
|
+
throw new SessionContractError('SOURCE_SYMLINK', 'Grok Build subagent paths cannot contain symlinks');
|
|
241
|
+
if (!entry.isDirectory())
|
|
242
|
+
nativeDrift();
|
|
243
|
+
if (names.length >= (limits?.maxRecords ?? GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES)) {
|
|
244
|
+
throw new SessionContractError('RESOURCE_LIMIT_EXCEEDED', 'Grok Build subagent metadata exceeds maxRecords');
|
|
245
|
+
}
|
|
246
|
+
names.push(entry.name);
|
|
247
|
+
}
|
|
248
|
+
const subagents = [];
|
|
249
|
+
for (const name of names.sort()) {
|
|
250
|
+
const meta = subagentSchema.safeParse(await nativeSibling(source, resolve(path, name, 'meta.json'), limits));
|
|
251
|
+
if (!meta.success || meta.data.subagent_id.toLowerCase() !== name.toLowerCase()
|
|
252
|
+
|| (meta.data.parent_session_id !== undefined && meta.data.parent_session_id.toLowerCase() !== sessionId)
|
|
253
|
+
|| meta.data.child_session_id?.toLowerCase() === sessionId)
|
|
254
|
+
nativeDrift();
|
|
255
|
+
const value = await nativeSibling(source, resolve(path, name, 'output.json'), limits);
|
|
256
|
+
const output = value === undefined ? undefined : outputSchema.safeParse(value);
|
|
257
|
+
if (output && !output.success)
|
|
258
|
+
nativeDrift();
|
|
259
|
+
subagents.push({ subagentId: meta.data.subagent_id.toLowerCase(),
|
|
260
|
+
...(meta.data.parent_session_id ? { parentSessionId: meta.data.parent_session_id.toLowerCase() } : {}),
|
|
261
|
+
...(meta.data.child_session_id ? { childSessionId: meta.data.child_session_id.toLowerCase() } : {}),
|
|
262
|
+
...(meta.data.status ? { status: meta.data.status } : {}),
|
|
263
|
+
...(output?.success ? { output: output.data.output } : {}) });
|
|
264
|
+
}
|
|
265
|
+
return subagents;
|
|
266
|
+
}
|
|
267
|
+
async function readNativeUpdates(source, sessionId, cwd, metadata, history, compacted, limits) {
|
|
268
|
+
const path = resolve(dirname(source.locator), 'updates.jsonl');
|
|
269
|
+
try {
|
|
270
|
+
await rejectNativeSymlinks(path);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
if (error.code === 'ENOENT') {
|
|
274
|
+
// A compacted history alone cannot recover the removed turns.
|
|
275
|
+
if (compacted)
|
|
276
|
+
nativeDrift();
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
const input = await streamBoundedJsonLines({ selectedPath: path, allowedRoots: source.authorizedScope.allowedRoots }, { consistency: 'complete', limits });
|
|
282
|
+
const records = [];
|
|
283
|
+
let hasTools = history.some(entry => entry.record.kind !== 'message');
|
|
284
|
+
let hasCompaction = false;
|
|
285
|
+
let nextPromptIndex = 0;
|
|
286
|
+
let checkpoint;
|
|
287
|
+
const checkpointIds = new Set();
|
|
288
|
+
for await (const line of input) {
|
|
289
|
+
const entry = projectNativeUpdate(line, sessionId, cwd, metadata);
|
|
290
|
+
const update = line.value.params.update;
|
|
291
|
+
const type = update.sessionUpdate;
|
|
292
|
+
if (type === 'compaction_checkpoint') {
|
|
293
|
+
const parsed = parseNativeCompactionCheckpoint(update);
|
|
294
|
+
if (checkpoint || checkpointIds.has(parsed.checkpointId) || parsed.promptIndexAtCompaction !== nextPromptIndex)
|
|
295
|
+
nativeDrift();
|
|
296
|
+
checkpoint = parsed;
|
|
297
|
+
checkpointIds.add(parsed.checkpointId);
|
|
298
|
+
}
|
|
299
|
+
if (type === 'user_message_chunk') {
|
|
300
|
+
const meta = line.value.params.update._meta;
|
|
301
|
+
if (!meta?.hostTurn) {
|
|
302
|
+
if (meta?.promptIndex !== nextPromptIndex)
|
|
303
|
+
nativeDrift();
|
|
304
|
+
nextPromptIndex += 1;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (type === 'tool_call' || type === 'tool_call_update')
|
|
308
|
+
hasTools = true;
|
|
309
|
+
if (entry) {
|
|
310
|
+
if (entry.record.kind === 'compaction') {
|
|
311
|
+
hasCompaction = true;
|
|
312
|
+
if (checkpoint) {
|
|
313
|
+
if (checkpoint.promptIndexAtCompaction !== nextPromptIndex)
|
|
314
|
+
nativeDrift();
|
|
315
|
+
entry.record.compaction = { ...entry.record.compaction, ...checkpoint };
|
|
316
|
+
checkpoint = undefined;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
records.push(entry);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// Compacted tool histories need a qualified update-tool projection; never drop calls.
|
|
323
|
+
if (checkpoint || (compacted && (!hasCompaction || nextPromptIndex === 0)) || (hasTools && (compacted || hasCompaction)))
|
|
324
|
+
nativeDrift();
|
|
325
|
+
return hasTools || !records.length ? null : records;
|
|
326
|
+
}
|
|
327
|
+
/** Hash only stable source evidence, excluding mutable summary and subagent status. */
|
|
328
|
+
export function nativeRecordPrefixes(records) {
|
|
329
|
+
const hash = createHash('sha256');
|
|
330
|
+
const prefixes = [hash.copy().digest('hex')];
|
|
331
|
+
for (const { record, line } of records) {
|
|
332
|
+
hash.update(JSON.stringify([record.sequence, record.kind, record.acquisition, line.value,
|
|
333
|
+
...(record.compaction?.checkpointId ? [record.compaction] : [])]) + '\n');
|
|
334
|
+
prefixes.push(hash.copy().digest('hex'));
|
|
335
|
+
}
|
|
336
|
+
return prefixes;
|
|
337
|
+
}
|
|
191
338
|
/** Authorize native identity/path before a caller may use the CLI fallback. */
|
|
192
339
|
export async function authorizeGrokBuildNativeSource(source) {
|
|
193
340
|
const sessionId = grokBuildNativeSessionId(source.locator);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { basename, extname } from 'node:path';
|
|
2
3
|
import { canFallbackGrokNative, withGrokCliFallback } from './grok-build-fallback.js';
|
|
3
4
|
import { SessionContractError, schemaIssueDetail, } from '../contracts.js';
|
|
4
5
|
import { readBoundedText } from '../readers.js';
|
|
5
|
-
import { assertGrokBuildNativeEnabled, discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, grokBuildNativeEnabled, parseGrokBuildNativeCursor, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
|
|
6
|
-
export const GROK_BUILD_ADAPTER_VERSION = '1.
|
|
6
|
+
import { assertGrokBuildNativeEnabled, discoverGrokBuildNativeChatHistories, GROK_BUILD_NATIVE_DISCOVERY_MAX_FILES, GROK_BUILD_NATIVE_LOCATOR_CLASS, GROK_BUILD_NATIVE_SCHEMA_VERSION, grokBuildNativeSessionId, grokBuildNativeEnabled, parseGrokBuildNativeCursor, nativeRecordPrefixes, readGrokBuildNativeChatHistory, toGrokBuildNativeRecord, } from './grok-build-native.js';
|
|
7
|
+
export const GROK_BUILD_ADAPTER_VERSION = '1.3.0';
|
|
7
8
|
export const GROK_BUILD_CLI_EXPORT_SCHEMA_VERSION = '1.0.0';
|
|
8
9
|
export const GROK_BUILD_CLI_EXPORT_LOCATOR_CLASS = 'grok-build-cli-markdown-export';
|
|
9
10
|
/**
|
|
@@ -23,6 +24,8 @@ export class GrokBuildSessionAdapter {
|
|
|
23
24
|
provider = 'grok-build';
|
|
24
25
|
adapterVersion = GROK_BUILD_ADAPTER_VERSION;
|
|
25
26
|
disposition = 'implemented';
|
|
27
|
+
// Compaction rewrites chat history; native cursors validate the retained projection.
|
|
28
|
+
sourceContinuity = 'snapshot';
|
|
26
29
|
get supportedOperations() {
|
|
27
30
|
return grokBuildNativeEnabled() ? ['discover', 'inspect', 'stream'] : ['inspect', 'stream'];
|
|
28
31
|
}
|
|
@@ -86,7 +89,13 @@ export class GrokBuildSessionAdapter {
|
|
|
86
89
|
return;
|
|
87
90
|
}
|
|
88
91
|
const sessionId = grokBuildNativeSessionId(source.locator);
|
|
89
|
-
const
|
|
92
|
+
const prefixes = nativeRecordPrefixes(native.records);
|
|
93
|
+
const acquisition = native.records[0]?.record.acquisition === 'grok-build-native-updates' ? 'updates' : 'chat';
|
|
94
|
+
const saved = cursor?.value?.match(/^grok-native:(chat|updates):(\d+):([a-f0-9]{64})$/);
|
|
95
|
+
const start = parseGrokBuildNativeCursor(saved?.[2] ?? cursor?.value);
|
|
96
|
+
if (start > native.records.length || (saved && (saved[1] !== acquisition || saved[3] !== prefixes[start]))) {
|
|
97
|
+
throw new SessionContractError('SCHEMA_DRIFT', 'Grok Build native checkpoint projection changed; use a separate source and `grok export` for review.');
|
|
98
|
+
}
|
|
90
99
|
let outputIndex = 0;
|
|
91
100
|
for (const entry of native.records) {
|
|
92
101
|
const position = outputIndex;
|
|
@@ -94,19 +103,34 @@ export class GrokBuildSessionAdapter {
|
|
|
94
103
|
if (position < start)
|
|
95
104
|
continue;
|
|
96
105
|
const record = toGrokBuildNativeRecord(sessionId, entry);
|
|
97
|
-
record.sourceCursor =
|
|
106
|
+
record.sourceCursor = `grok-native:${acquisition}:${outputIndex}:${prefixes[outputIndex]}`;
|
|
98
107
|
yield record;
|
|
99
108
|
}
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
102
|
-
const
|
|
103
|
-
const start = parseCursor(cursor?.value);
|
|
111
|
+
const saved = cursor?.value?.match(/^grok-export:(\d+):([a-f0-9]{64})$/);
|
|
112
|
+
const start = parseCursor(saved?.[1] ?? cursor?.value);
|
|
113
|
+
const hash = createHash('sha256');
|
|
104
114
|
let outputIndex = 0;
|
|
115
|
+
for await (const record of this.exportRecords(source)) {
|
|
116
|
+
hash.update(JSON.stringify(record) + '\n');
|
|
117
|
+
outputIndex += 1;
|
|
118
|
+
const digest = hash.copy().digest('hex');
|
|
119
|
+
if (outputIndex === start && saved && digest !== saved[2]) {
|
|
120
|
+
throw new SessionContractError('SCHEMA_DRIFT', 'Grok Build export checkpoint prefix changed; review and import a separate export source.');
|
|
121
|
+
}
|
|
122
|
+
if (outputIndex <= start)
|
|
123
|
+
continue;
|
|
124
|
+
yield { ...record, sourceCursor: `grok-export:${outputIndex}:${digest}` };
|
|
125
|
+
}
|
|
126
|
+
if (start > outputIndex)
|
|
127
|
+
throw new SessionContractError('SCHEMA_DRIFT', 'Grok Build export checkpoint is beyond the retained transcript; use a separate export source.');
|
|
128
|
+
}
|
|
129
|
+
async *exportRecords(source) {
|
|
130
|
+
const parsed = await this.readSource(source);
|
|
105
131
|
for (const [sequence, block] of parsed.blocks.entries()) {
|
|
106
132
|
if (block.heading === 'Tools') {
|
|
107
133
|
for (const tool of parseTools(block.text, sequence)) {
|
|
108
|
-
if (outputIndex++ < start)
|
|
109
|
-
continue;
|
|
110
134
|
yield {
|
|
111
135
|
nativeSessionId: parsed.sessionId,
|
|
112
136
|
nativeEventId: undefined,
|
|
@@ -122,8 +146,6 @@ export class GrokBuildSessionAdapter {
|
|
|
122
146
|
}
|
|
123
147
|
continue;
|
|
124
148
|
}
|
|
125
|
-
if (outputIndex++ < start)
|
|
126
|
-
continue;
|
|
127
149
|
yield {
|
|
128
150
|
nativeSessionId: parsed.sessionId,
|
|
129
151
|
nativeEventId: undefined,
|
|
@@ -138,15 +160,15 @@ export class GrokBuildSessionAdapter {
|
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
162
|
async fallbackRecords(source, cursor) {
|
|
141
|
-
const
|
|
163
|
+
const saved = cursor?.match(/^(\d+):([a-f0-9]{64})$/);
|
|
164
|
+
const start = parseCursor(saved?.[1] ?? cursor);
|
|
142
165
|
if (!this.cliFallback)
|
|
143
166
|
throw new SessionContractError('UNSUPPORTED_OPERATION', 'Grok Build CLI fallback is unavailable; use an explicit `grok export`.');
|
|
144
167
|
return withGrokCliFallback(source, this.cliFallback, async (selected) => {
|
|
145
168
|
const records = [];
|
|
146
|
-
|
|
147
|
-
for await (const record of this.stream(selected, { value: String(start) })) {
|
|
169
|
+
for await (const record of this.stream(selected, { value: saved ? `grok-export:${cursor}` : String(start) })) {
|
|
148
170
|
const extensions = record.extensions ?? {};
|
|
149
|
-
records.push({ ...record, sourceCursor:
|
|
171
|
+
records.push({ ...record, sourceCursor: record.sourceCursor.replace('grok-export:', 'grok-cli:'), extensions: { ...extensions,
|
|
150
172
|
provenance: { ...extensions.provenance, nativeFallback: true },
|
|
151
173
|
} });
|
|
152
174
|
}
|
|
@@ -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,
|
|
@@ -10,6 +10,7 @@ import { configuredProviders } from './workspace-migration.js';
|
|
|
10
10
|
import { diagnoseUserHookCommands } from '../../extensions/user-hook-diagnostics.js';
|
|
11
11
|
import { diagnoseCodexHookTrust } from '../hook-bridge/codex-trust.js';
|
|
12
12
|
import { diagnoseFactoryHookTrust } from '../hook-bridge/factory-trust.js';
|
|
13
|
+
import { diagnoseHermesHookAcceptance } from '../hook-bridge/hermes-trust.js';
|
|
13
14
|
import { maskCodeRegions } from './code-regions.js';
|
|
14
15
|
export { maskCodeRegions } from './code-regions.js';
|
|
15
16
|
export function markdownLinks(content) {
|
|
@@ -45,6 +46,9 @@ export async function diagnoseWorkspaceContext(projectPath) {
|
|
|
45
46
|
const factoryTrust = await diagnoseFactoryHookTrust(projectPath);
|
|
46
47
|
if (factoryTrust)
|
|
47
48
|
diagnostics.push(factoryTrust);
|
|
49
|
+
const hermesAcceptance = await diagnoseHermesHookAcceptance();
|
|
50
|
+
if (hermesAcceptance)
|
|
51
|
+
diagnostics.push(hermesAcceptance);
|
|
48
52
|
const root = path.resolve(projectPath);
|
|
49
53
|
const scopes = new Map();
|
|
50
54
|
// Ordinary subdirectories share root policy; repository/project markers start a separate scope.
|
|
@@ -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;
|
|
@@ -5,6 +5,8 @@ import { isMap, isSeq, parseDocument } from 'yaml';
|
|
|
5
5
|
import { resolveHermesHomePath } from '../../providers/hermes-home.js';
|
|
6
6
|
import { captureDeploymentOutputs, recordDeploymentOutputs } from '../../providers/deployment-ownership.mjs';
|
|
7
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';
|
|
8
10
|
export async function translateHermesPromptDiscovery(source, options) {
|
|
9
11
|
const home = resolveHermesHomePath();
|
|
10
12
|
const directory = path.join(home, 'agent-hooks');
|
|
@@ -42,8 +44,11 @@ export async function translateHermesPromptDiscovery(source, options) {
|
|
|
42
44
|
if (!isSeq(entries) || entries.items.some(entry => !isMap(entry) || typeof entry.get('command') !== 'string')) {
|
|
43
45
|
throw new Error('Invalid Hermes pre_llm_call hooks');
|
|
44
46
|
}
|
|
45
|
-
const
|
|
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,
|
|
47
52
|
_aiwg_managed: true, _aiwg_id: source.id };
|
|
48
53
|
const managed = entries.items.filter(entry => isMap(entry) && entry.get('_aiwg_managed') === true && entry.get('_aiwg_id') === source.id);
|
|
49
54
|
const current = managed[0];
|
|
@@ -52,10 +57,6 @@ export async function translateHermesPromptDiscovery(source, options) {
|
|
|
52
57
|
entries.items = entries.items.filter(entry => !managed.includes(entry));
|
|
53
58
|
entries.add(doc.createNode(registration));
|
|
54
59
|
}
|
|
55
|
-
const sourceScript = source.args?.[0];
|
|
56
|
-
if (!sourceScript)
|
|
57
|
-
throw new Error('Missing shared prompt discovery script');
|
|
58
|
-
const bytes = await fs.readFile(sourceScript);
|
|
59
60
|
const roots = [config, directory, path.join(home, '.aiwg-manifest.json')];
|
|
60
61
|
const before = captureDeploymentOutputs(roots);
|
|
61
62
|
const state = await managedHookScriptState(home, path.relative(home, script), bytes);
|
|
@@ -72,7 +73,9 @@ export async function translateHermesPromptDiscovery(source, options) {
|
|
|
72
73
|
await fs.writeFile(config, text);
|
|
73
74
|
result.emittedPaths.push(config);
|
|
74
75
|
recordDeploymentOutputs(before, roots, { frameworkSlug: 'aiwg-hooks', claimUnchangedSettings: false, writtenFiles: result.emittedPaths });
|
|
75
|
-
|
|
76
|
+
const nextStep = hermesHookAcceptanceNextStep(await readHermesHookAcceptance());
|
|
77
|
+
if (nextStep)
|
|
78
|
+
result.warnings.push(nextStep);
|
|
76
79
|
return result;
|
|
77
80
|
}
|
|
78
81
|
//# sourceMappingURL=hermes-prompt-discovery.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Read Hermes shell-hook consent without accepting commands or changing config.
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseDocument } from 'yaml';
|
|
5
|
+
import { resolveHermesHomePath } from '../../providers/hermes-home.js';
|
|
6
|
+
// One short deploy line; doctor carries the complete set of acceptance options.
|
|
7
|
+
export const HERMES_HOOK_ACCEPTANCE_NEXT_STEP = 'Accept the Hermes hook (--accept-hooks); see aiwg doctor.';
|
|
8
|
+
export const HERMES_HOOK_ACCEPTANCE_DETAIL = 'Hermes skips unaccepted pre_llm_call hooks. Review and accept at the TTY prompt, '
|
|
9
|
+
+ 'or explicitly opt in with --accept-hooks, HERMES_ACCEPT_HOOKS=1 or hooks_auto_accept: true. '
|
|
10
|
+
+ 'AIWG never accepts hooks for you. Acceptance matches the exact event and command string; '
|
|
11
|
+
+ 'a script change changes the fingerprinted command on redeploy and requires re-acceptance.';
|
|
12
|
+
export function hermesHookAcceptanceNextStep(state) {
|
|
13
|
+
return state && state !== 'accepted' ? HERMES_HOOK_ACCEPTANCE_NEXT_STEP : '';
|
|
14
|
+
}
|
|
15
|
+
export async function readHermesHookAcceptance() {
|
|
16
|
+
const home = resolveHermesHomePath();
|
|
17
|
+
let commands;
|
|
18
|
+
let autoAccept;
|
|
19
|
+
try {
|
|
20
|
+
const doc = parseDocument(await fs.readFile(path.join(home, 'config.yaml'), 'utf8'));
|
|
21
|
+
if (doc.errors.length)
|
|
22
|
+
return null;
|
|
23
|
+
const config = doc.toJS();
|
|
24
|
+
const entries = config?.hooks?.pre_llm_call;
|
|
25
|
+
if (!Array.isArray(entries))
|
|
26
|
+
return null;
|
|
27
|
+
commands = entries.filter(entry => entry?._aiwg_managed === true
|
|
28
|
+
&& entry._aiwg_id === 'aiwg-prompt-discovery' && typeof entry.command === 'string')
|
|
29
|
+
.map(entry => entry.command);
|
|
30
|
+
if (!commands.length)
|
|
31
|
+
return null;
|
|
32
|
+
await fs.access(path.join(home, 'agent-hooks/aiwg-prompt-discovery.cjs'));
|
|
33
|
+
autoAccept = config.hooks_auto_accept;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Broken deployments are handled by the existing drift diagnostics.
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Match Hermes's existing config opt-in, without setting it or assuming a CLI flag.
|
|
40
|
+
if (autoAccept === true || typeof autoAccept === 'string'
|
|
41
|
+
&& ['1', 'true', 'yes', 'on'].includes(autoAccept.trim().toLowerCase()))
|
|
42
|
+
return 'accepted';
|
|
43
|
+
try {
|
|
44
|
+
const data = JSON.parse((await fs.readFile(path.join(home, 'shell-hooks-allowlist.json'), 'utf8')).replace(/^\uFEFF/, ''));
|
|
45
|
+
if (!Array.isArray(data?.approvals))
|
|
46
|
+
return 'unknown';
|
|
47
|
+
// Hermes agent/shell_hooks.py _entry_matches compares both strings exactly.
|
|
48
|
+
return commands.every(command => data.approvals.some((entry) => entry?.event === 'pre_llm_call' && entry.command === command)) ? 'accepted' : 'unaccepted';
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return error.code === 'ENOENT' ? 'unaccepted' : 'unknown';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function diagnoseHermesHookAcceptance() {
|
|
55
|
+
const state = await readHermesHookAcceptance();
|
|
56
|
+
if (!hermesHookAcceptanceNextStep(state))
|
|
57
|
+
return null;
|
|
58
|
+
return {
|
|
59
|
+
severity: state === 'unaccepted' ? 'warning' : 'info', code: 'hermes-prompt-discovery-acceptance',
|
|
60
|
+
path: resolveHermesHomePath('config.yaml'),
|
|
61
|
+
message: `Hermes prompt-discovery hook deployed but ${state === 'unaccepted' ? 'not accepted' : 'acceptance unverified'}. `
|
|
62
|
+
+ HERMES_HOOK_ACCEPTANCE_DETAIL,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=hermes-trust.js.map
|
package/package.json
CHANGED
|
@@ -292,13 +292,15 @@ async function mainUnlocked(args, internal) {
|
|
|
292
292
|
deployRules: !cfg.deferRuleProjection && (cfg.kernelOnly || cfg.deployRules),
|
|
293
293
|
deployBehaviors: cfg.kernelOnly ? false : cfg.deployBehaviors,
|
|
294
294
|
commandsOnly: cfg.commandsOnly,
|
|
295
|
-
|
|
295
|
+
// Grok bulk deployment includes native agents alongside kernel skills (#2577).
|
|
296
|
+
skillsOnly: cfg.skillsOnly || (cfg.kernelOnly && provider.name !== 'grok-build'),
|
|
296
297
|
rulesOnly: cfg.rulesOnly,
|
|
297
298
|
strict: cfg.strict,
|
|
298
299
|
reportOnly: cfg.reportOnly,
|
|
299
300
|
allowOverBudget: cfg.allowOverBudget === true,
|
|
300
301
|
kernelOnly: cfg.kernelOnly,
|
|
301
302
|
deferRuleProjection: cfg.deferRuleProjection,
|
|
303
|
+
bundleOnly: cfg.bundleOnly,
|
|
302
304
|
additionalSources: cfg.additionalSources,
|
|
303
305
|
filter: cfg.filter,
|
|
304
306
|
filterRole: cfg.filterRole,
|
|
@@ -391,7 +393,7 @@ async function mainUnlocked(args, internal) {
|
|
|
391
393
|
// or removed (the flat-file analogue of the skills holistic prune). #1627.
|
|
392
394
|
pruneStaleAiwgArtifacts(provider, cfg.target, srcRoot, opts, cfg.source);
|
|
393
395
|
|
|
394
|
-
if (!['claude', 'codex', 'cursor', 'hermes', 'warp', 'openclaw'].includes(provider.name) && !opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly) {
|
|
396
|
+
if (!opts.kernelOnly && !['claude', 'codex', 'cursor', 'hermes', 'warp', 'openclaw'].includes(provider.name) && !opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly) {
|
|
395
397
|
const behaviorDirs = collectBehaviorDirs(srcRoot);
|
|
396
398
|
const behaviorCount = deployEmulatedBehaviors(behaviorDirs, provider.name, cfg.target, opts);
|
|
397
399
|
if (behaviorCount > 0 && !cfg.quiet) {
|
|
@@ -29,6 +29,7 @@ export function parseArgs(args = process.argv.slice(2)) {
|
|
|
29
29
|
reportOnly: true,
|
|
30
30
|
kernelOnly: false,
|
|
31
31
|
deferRuleProjection: false,
|
|
32
|
+
bundleOnly: false,
|
|
32
33
|
ruleSelectionMode: null,
|
|
33
34
|
additionalSources: [],
|
|
34
35
|
filter: null, // Glob pattern for agent names
|
|
@@ -99,6 +100,7 @@ export function parseArgs(args = process.argv.slice(2)) {
|
|
|
99
100
|
else if (a === '--kernel-only') cfg.kernelOnly = true;
|
|
100
101
|
// Internal use orchestration: the final source owns rule presentation.
|
|
101
102
|
else if (a === '--defer-rule-projection') cfg.deferRuleProjection = true;
|
|
103
|
+
else if (a === '--bundle-only') cfg.bundleOnly = true;
|
|
102
104
|
else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
|
|
103
105
|
else if (a === '--filter' && args[i + 1]) cfg.filter = args[++i];
|
|
104
106
|
else if (a === '--filter-role' && args[i + 1]) cfg.filterRole = args[++i];
|
|
@@ -244,6 +244,7 @@ export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
|
|
|
244
244
|
const record = managed[name];
|
|
245
245
|
const owners = [record?.frameworkSlug, ...(Array.isArray(record?.owners) ? record.owners : [])]
|
|
246
246
|
.filter(owner => typeof owner === 'string' && owner.length > 0);
|
|
247
|
+
if (opts.onlyOwner && (!owners.length || owners.some(owner => owner !== opts.onlyOwner))) continue;
|
|
247
248
|
// Wrappers belong to the skill inventory below, not the command inventory.
|
|
248
249
|
const ownerAware = opts.ownerStems instanceof Map && owners.length > 0 && record?.kind !== 'skill-command';
|
|
249
250
|
if (ownerAware ? owners.some(owner => opts.ownerStems.get(owner)?.has(stem)) : desired.has(stem)) continue;
|
|
@@ -275,7 +276,8 @@ export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
|
|
|
275
276
|
}
|
|
276
277
|
removed.push(target);
|
|
277
278
|
if (dryRun) {
|
|
278
|
-
if (
|
|
279
|
+
if (opts.onlyOwner) console.log(`[dry-run] Would remove ${target} (recorded owner ${opts.onlyOwner} no longer ships this artifact)`);
|
|
280
|
+
else if (verbose) console.log(`[dry-run] would prune stale AIWG artifact: ${path.relative(process.cwd(), target)}`);
|
|
279
281
|
continue;
|
|
280
282
|
}
|
|
281
283
|
try {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { removeSkillCopy } from './skill-copy-prune.mjs';
|
|
3
3
|
import { fs, path } from './base-runtime.mjs';
|
|
4
4
|
import { parseFrontmatter } from './base-frontmatter.mjs';
|
|
5
|
-
import { ensureDir } from './base-files.mjs';
|
|
5
|
+
import { ensureDir, listSkillDirs, readSidecarManifest } from './base-files.mjs';
|
|
6
6
|
import { deploySkillDir, pruneMissingStandardSkills } from './base-skill-copy.mjs';
|
|
7
7
|
|
|
8
8
|
|
|
@@ -30,7 +30,8 @@ export function isKernelSkill(skillDir) {
|
|
|
30
30
|
* Deploy skills with kernel-vs-standard routing (#1212/#1216/#1217).
|
|
31
31
|
*
|
|
32
32
|
* Partitions `skillDirs` into kernel skills (frontmatter `kernel: true`)
|
|
33
|
-
* and standard skills.
|
|
33
|
+
* and standard skills. Project-local skills use the native kernel destination
|
|
34
|
+
* too, so the provider can load them without a framework-index lookup (#4086).
|
|
34
35
|
*
|
|
35
36
|
* **Kernel skills** copy to `kernelDestDir` (platform-native dir,
|
|
36
37
|
* always-loaded by the platform). Small set: currently 24 skills spanning
|
|
@@ -88,7 +89,7 @@ export function deploySkillsWithKernelRouting(
|
|
|
88
89
|
const kernel = [];
|
|
89
90
|
const standard = [];
|
|
90
91
|
for (const dir of skillDirs) {
|
|
91
|
-
if (kernelDestDir && isKernelSkill(dir)) kernel.push(dir);
|
|
92
|
+
if (kernelDestDir && (opts?.deploySource === 'project-local' || isKernelSkill(dir))) kernel.push(dir);
|
|
92
93
|
else standard.push(dir);
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -322,13 +323,18 @@ export function computeAllKernelNames(srcRoot) {
|
|
|
322
323
|
export function pruneStaleAiwgSkills(kernelDestDir, desiredKernelNames, opts = {}) {
|
|
323
324
|
if ((opts.copyMode ?? opts.copyStandardSkills) || !kernelDestDir || !fs.existsSync(kernelDestDir)) return 0;
|
|
324
325
|
// No global desired set — skip pruning rather than delete everything (#123).
|
|
325
|
-
if (desiredKernelNames == null) return 0;
|
|
326
|
+
if (desiredKernelNames == null && !opts.bundleOnly) return 0;
|
|
326
327
|
if (opts.dryRun) return 0;
|
|
327
|
-
const desired = new Set(desiredKernelNames);
|
|
328
|
+
const desired = new Set(desiredKernelNames || []);
|
|
329
|
+
if (opts.bundleOnly) for (const dir of listSkillDirs(path.join(opts.srcRoot, 'skills')).filter(isKernelSkill)) {
|
|
330
|
+
desired.add(path.basename(dir));
|
|
331
|
+
}
|
|
328
332
|
let pruned = 0;
|
|
329
333
|
for (const entry of fs.readdirSync(kernelDestDir, { withFileTypes: true })) {
|
|
330
334
|
if (!entry.isDirectory()) continue;
|
|
331
335
|
if (desired.has(entry.name)) continue;
|
|
336
|
+
// The bundled corpus cannot declare project-local skills obsolete (#4086).
|
|
337
|
+
if (readSidecarManifest(path.join(kernelDestDir, entry.name))?.managed?.['SKILL.md']?.source === 'project-local') continue;
|
|
332
338
|
|
|
333
339
|
const skillMd = path.join(kernelDestDir, entry.name, 'SKILL.md');
|
|
334
340
|
if (!fs.existsSync(skillMd)) continue;
|