@aiwg/cli 2026.11.4 → 2026.11.6
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 +44 -36
- package/bin/aiwg.mjs +6 -4
- package/dist/src/activity-log/cli.js +1 -1
- package/dist/src/agents/agent-deployer.js +1 -1
- package/dist/src/artifacts/audit/types.js +1 -1
- package/dist/src/artifacts/discover-facets.js +1 -1
- package/dist/src/artifacts/enrichment/prompt.js +1 -1
- package/dist/src/artifacts/enrichment/types.js +1 -1
- 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/artifacts/views/definition.js +1 -1
- package/dist/src/artifacts/views/types.js +1 -1
- package/dist/src/catalog/cli.js +1 -1
- package/dist/src/catalog/cli.mjs +1 -1
- package/dist/src/catalog/loader.js +1 -1
- package/dist/src/catalog/loader.mjs +1 -1
- package/dist/src/catalog/types.js +1 -1
- package/dist/src/cli/cli-extension-loader.js +19 -5
- package/dist/src/cli/cli-extension-paths.js +65 -0
- package/dist/src/cli/handlers/best-practices-audit.js +1 -1
- package/dist/src/cli/handlers/help.js +3 -4
- package/dist/src/cli/handlers/index.js +1 -1
- package/dist/src/cli/handlers/marketplace-plugin-search.js +37 -0
- package/dist/src/cli/handlers/marketplace.js +3 -1
- package/dist/src/cli/handlers/models.js +1 -1
- package/dist/src/cli/handlers/ralph-launcher.js +8 -2
- package/dist/src/cli/handlers/ralph.js +1 -1
- package/dist/src/cli/handlers/runtime-info.js +1 -1
- package/dist/src/cli/handlers/scaffolding.js +2 -2
- package/dist/src/cli/handlers/script-runner.js +8 -5
- package/dist/src/cli/handlers/sdlc-accelerate.js +1 -1
- package/dist/src/cli/handlers/steward-format.js +12 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +1 -1
- package/dist/src/cli/handlers/subcommands-list-format.js +19 -1
- package/dist/src/cli/handlers/types.js +1 -1
- package/dist/src/cli/handlers/use.js +15 -6
- package/dist/src/cli/handlers/utilities.js +1 -1
- package/dist/src/cli/handlers/utility-doctor.js +4 -0
- package/dist/src/cli/handlers/version.js +1 -1
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/help-generator.js +9 -11
- package/dist/src/cli/hooks/builtin/activity-log-hook.js +1 -1
- package/dist/src/cli/router.js +1 -1
- package/dist/src/cli/workflow-orchestrator.js +1 -1
- package/dist/src/config/worker-context.js +37 -7
- package/dist/src/config/worker-parallelism.js +11 -0
- package/dist/src/contributors/detect.js +1 -1
- package/dist/src/contributors/discover.js +1 -1
- package/dist/src/contributors/heuristic.js +1 -1
- package/dist/src/contributors/index.js +1 -1
- package/dist/src/contributors/types.js +1 -1
- package/dist/src/contributors/validation.js +1 -1
- package/dist/src/effects/worker-delivery.js +83 -0
- package/dist/src/extensions/capability-index.js +1 -1
- package/dist/src/extensions/commands/definitions.js +2 -2
- package/dist/src/extensions/deployment-registration.js +1 -1
- package/dist/src/extensions/index.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/manifest.js +10 -2
- package/dist/src/extensions/project-local-activity.js +1 -1
- package/dist/src/extensions/project-local-discovery.js +23 -3
- package/dist/src/extensions/project-local-doctor.js +7 -3
- package/dist/src/extensions/project-local-promote.js +3 -3
- package/dist/src/extensions/project-local-remove.js +3 -3
- package/dist/src/extensions/project-local-scaffold.js +20 -8
- package/dist/src/extensions/registry.js +1 -1
- package/dist/src/extensions/shadow-resolver.js +1 -1
- package/dist/src/extensions/types.js +1 -1
- package/dist/src/extensions/upstream-registry.js +1 -1
- package/dist/src/extensions/validation.js +1 -1
- package/dist/src/intake/git-history-analyzer.js +1 -1
- package/dist/src/kb/cli.js +1 -1
- package/dist/src/marketplace/plugin-directory.js +36 -0
- package/dist/src/marketplace/plugin-search.js +180 -0
- package/dist/src/mcp/cli.mjs +2 -2
- package/dist/src/mcp/helpers.mjs +1 -1
- package/dist/src/mcp/http-tools.mjs +8 -6
- package/dist/src/mcp/http-transport.mjs +3 -1
- package/dist/src/mcp/server.mjs +1 -1
- package/dist/src/mcp/tools/command-run.mjs +1 -1
- package/dist/src/mcp/tools/discovery.mjs +1 -1
- package/dist/src/mcp/tools/subsystems.mjs +1 -1
- package/dist/src/mcp/tools/worker-invoke.mjs +68 -22
- package/dist/src/mcp/tools/worker-local-only-preflight.mjs +79 -0
- package/dist/src/mcp/tools/worker-recorded-launch.mjs +26 -0
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +33 -6
- package/dist/src/mcp/tools/worker-verify-deliver-schema.mjs +33 -0
- package/dist/src/mcp/tools/worker-verify-deliver.mjs +27 -0
- package/dist/src/models/catalog-policy.js +2 -2
- package/dist/src/models/conductor-data-policy.mjs +83 -14
- package/dist/src/models/config-loader.js +2 -2
- package/dist/src/models/factory-models.js +144 -0
- package/dist/src/models/index.js +2 -2
- package/dist/src/models/local-endpoint-models.js +155 -0
- package/dist/src/models/model-capabilities.v1.json +44 -36
- package/dist/src/models/model-discovery.js +16 -8
- package/dist/src/models/opencode-worker-model.mjs +16 -0
- package/dist/src/models/resolver.js +2 -2
- package/dist/src/models/worker-installation.d.mts +2 -0
- package/dist/src/models/worker-installation.mjs +16 -5
- package/dist/src/models/worker-invocation-policy.js +25 -1
- package/dist/src/models/worker-plan.js +1 -1
- package/dist/src/models/wrapper-enforcement.js +1 -1
- package/dist/src/plugin/plugin-installer.js +2 -2
- package/dist/src/plugin/registry-validator.js +2 -2
- package/dist/src/plugin/skill-command-translator.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/rlm/cache/hash.js +1 -1
- package/dist/src/rlm/cache/store.js +1 -1
- package/dist/src/rlm/cache/types.js +1 -1
- package/dist/src/serve/worker-invocation-preparation.js +13 -0
- package/dist/src/serve/worker-invocation.js +21 -6
- 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/skills/run.js +0 -11
- package/dist/src/smiths/agentsmith/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/index.js +1 -1
- package/dist/src/smiths/context-pipeline/provider-policy.js +1 -1
- package/dist/src/smiths/context-pipeline/types.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/dist/src/smiths/mcpsmith/analyzers/cli-analyzer.js +2 -2
- package/dist/src/smiths/mcpsmith/generator.js +2 -2
- package/dist/src/smiths/mcpsmith/index.js +2 -2
- package/dist/src/smiths/mcpsmith/types.js +2 -2
- package/dist/src/smiths/skillsmith/collision-detector.js +1 -1
- package/dist/src/smiths/skillsmith/namespace-adapter.js +1 -1
- package/dist/src/smiths/toolsmith/runtime-discovery.mjs +2 -2
- package/dist/src/smiths/toolsmith/types.js +2 -2
- package/dist/src/storage/backends/fortemi.js +1 -1
- package/dist/src/storage/backends/fs.js +1 -1
- package/dist/src/storage/backends/logseq.js +1 -1
- package/dist/src/storage/backends/obsidian.js +1 -1
- package/dist/src/storage/cli.js +2 -2
- package/dist/src/storage/config.js +1 -1
- package/dist/src/storage/index.js +1 -1
- package/dist/src/storage/subsystem-cli.js +1 -1
- package/dist/src/storage/types.js +1 -1
- package/dist/src/testing/generators/test-case-generator.js +1 -1
- package/dist/src/writing/validation-engine.js +1 -1
- package/package.json +11 -1
- package/schemas/models/model-catalog.v1.schema.json +6 -3
- 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/conductor-data-guard.mjs +1 -1
- 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/mcp-worker-launch.mjs +67 -0
- package/tools/ralph-external/lib/opencode-adapter.mjs +9 -7
- package/tools/ralph-external/lib/trusted-verification.mjs +1021 -0
- package/tools/ralph-external/lib/typed-stop-delivery.mjs +46 -0
- package/tools/ralph-external/lib/verification-isolation.mjs +509 -0
- package/tools/ralph-external/lib/worker-context.mjs +3 -3
- package/tools/ralph-external/lib/worker-delivery-guards.mjs +95 -0
- package/tools/ralph-external/lib/worker-delivery-record.mjs +15 -0
- package/tools/ralph-external/lib/worker-final.mjs +4 -1
- package/tools/ralph-external/lib/worker-inputs.mjs +20 -1
- package/tools/ralph-external/lib/worker-isolation-status.mjs +3 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +1 -0
- package/tools/ralph-external/lib/worker-launch-cli.mjs +8 -0
- package/tools/ralph-external/lib/worker-local-only-paths.mjs +45 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +4 -1
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory.mjs +45 -0
- package/tools/ralph-external/lib/worker-termination.mjs +21 -12
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +10 -2
- package/tools/ralph-external/lib/worker-verification-cli.mjs +164 -0
- package/tools/ralph-external/lib/worktree-preparation.mjs +417 -0
- package/tools/ralph-external/session-launcher.mjs +30 -32
- package/vscode-extension/schemas/aiwg.config.v1.json +27 -0
|
@@ -4,7 +4,7 @@ import { SessionContractError } from '../contracts.js';
|
|
|
4
4
|
const text = z.strictObject({ type: z.literal('text'), text: z.string() });
|
|
5
5
|
const tool = z.strictObject({ id: z.string().min(1), name: z.string().min(1), arguments: z.string() });
|
|
6
6
|
const recordSchema = z.discriminatedUnion('type', [
|
|
7
|
-
z.strictObject({ type: z.literal('user'), content: z.array(text), prompt_index: z.number().int().nonnegative().optional(), synthetic_reason: z.
|
|
7
|
+
z.strictObject({ type: z.literal('user'), content: z.array(text), prompt_index: z.number().int().nonnegative().optional(), synthetic_reason: z.enum(['system_reminder', 'compaction_meta']).optional() }),
|
|
8
8
|
z.strictObject({ type: z.literal('assistant'), content: z.string(), tool_calls: z.array(tool).max(999).optional(), model_id: z.string().optional(), model_fingerprint: z.string().optional(), reasoning_effort: z.string().optional() }),
|
|
9
9
|
z.strictObject({ type: z.literal('tool_result'), tool_call_id: z.string(), content: z.string() }),
|
|
10
10
|
z.strictObject({ type: z.literal('system'), content: z.string() }),
|
|
@@ -14,6 +14,8 @@ const summarySchema = z.looseObject({
|
|
|
14
14
|
chat_format_version: z.literal(1),
|
|
15
15
|
info: z.strictObject({ id: z.string().uuid(), cwd: z.string().min(1) }),
|
|
16
16
|
created_at: z.string(), updated_at: z.string(), current_model_id: z.string(),
|
|
17
|
+
session_kind: z.enum(['headless', 'interactive', 'subagent']).nullish(),
|
|
18
|
+
parent_session_id: z.string().uuid().optional(), forked_at: z.string().optional(),
|
|
17
19
|
});
|
|
18
20
|
export function nativeDrift() {
|
|
19
21
|
throw new SessionContractError('SCHEMA_DRIFT', 'Unrecognized Grok Build 1.0.77 native schema; fall back to `grok export <session-id> <session-id>.md`.');
|
|
@@ -25,7 +27,13 @@ export function parseNativeSummary(value, sessionId, cwd) {
|
|
|
25
27
|
for (const time of [parsed.data.created_at, parsed.data.updated_at])
|
|
26
28
|
if (!Number.isFinite(Date.parse(time)))
|
|
27
29
|
nativeDrift();
|
|
28
|
-
|
|
30
|
+
const data = parsed.data;
|
|
31
|
+
if (data.forked_at !== undefined && (!data.parent_session_id || !Number.isFinite(Date.parse(data.forked_at))))
|
|
32
|
+
nativeDrift();
|
|
33
|
+
if (data.parent_session_id?.toLowerCase() === sessionId)
|
|
34
|
+
nativeDrift();
|
|
35
|
+
const lineage = data.parent_session_id ? { parentSessionId: data.parent_session_id.toLowerCase(), ...(data.forked_at ? { forkedAt: data.forked_at } : {}) } : undefined;
|
|
36
|
+
return { sessionCreatedAt: data.created_at, sessionUpdatedAt: data.updated_at, currentModelId: data.current_model_id, ...(data.session_kind ? { sessionKind: data.session_kind } : {}), ...(lineage ? { lineage } : {}) };
|
|
29
37
|
}
|
|
30
38
|
export function projectNativeLine(line, cwd, metadata) {
|
|
31
39
|
const parsed = recordSchema.safeParse(line.value);
|
|
@@ -49,16 +57,78 @@ export function projectNativeLine(line, cwd, metadata) {
|
|
|
49
57
|
export function nativeProjectionRecord(sessionId, entry) {
|
|
50
58
|
const { record, line } = entry;
|
|
51
59
|
return {
|
|
52
|
-
nativeSessionId: sessionId, nativeEventId: `${sessionId}:${record.sequence}`, sequence: record.sequence,
|
|
53
|
-
kind: record.kind, role: record.role, occurredAt:
|
|
60
|
+
nativeSessionId: sessionId, nativeEventId: `${sessionId}:${record.acquisition === 'grok-build-native-updates' ? 'updates:' : ''}${record.sequence}`, sequence: record.sequence,
|
|
61
|
+
kind: record.kind, role: record.role, occurredAt: record.occurredAt, text: record.content, model: record.model,
|
|
54
62
|
toolName: record.toolName, toolCallId: record.toolCallId,
|
|
55
|
-
rawReference: { locatorClass: 'grok-build-native-chat-history', sequence: line.sequence },
|
|
63
|
+
rawReference: { locatorClass: record.acquisition ?? 'grok-build-native-chat-history', sequence: line.sequence },
|
|
56
64
|
extensions: {
|
|
57
65
|
lifecycle: 'unknown-at-import',
|
|
58
|
-
provenance: { product: 'grok-build', acquisition: 'grok-build-native-chat-history', sourceSchema: '1.0.0', nativeStoreInspected: true, toolOutputAvailable: true, grokVersion: '1.0.77', workingDirectory: record.cwd, sessionCreatedAt: record.sessionCreatedAt, sessionUpdatedAt: record.sessionUpdatedAt, sessionCreatedAtMs: Date.parse(record.sessionCreatedAt), sessionUpdatedAtMs: Date.parse(record.sessionUpdatedAt), currentModelId: record.currentModelId },
|
|
66
|
+
provenance: { product: 'grok-build', acquisition: record.acquisition ?? 'grok-build-native-chat-history', sourceSchema: '1.0.0', nativeStoreInspected: true, toolOutputAvailable: true, grokVersion: '1.0.77', workingDirectory: record.cwd, sessionCreatedAt: record.sessionCreatedAt, sessionUpdatedAt: record.sessionUpdatedAt, sessionCreatedAtMs: Date.parse(record.sessionCreatedAt), sessionUpdatedAtMs: Date.parse(record.sessionUpdatedAt), currentModelId: record.currentModelId, ...(record.sessionKind ? { sessionKind: record.sessionKind } : {}) },
|
|
67
|
+
...(record.lineage ? { lineage: record.lineage } : {}),
|
|
68
|
+
...(record.compaction ? { compaction: record.compaction } : {}),
|
|
59
69
|
identity: { nativeSessionIdKnown: true, nativeEventIdKnown: false, eventIdentityBasis: 'source-position' },
|
|
60
|
-
lossReport: { lossless: false, excludedRecordTypes: ['system', 'system_reminder', 'reasoning'], unavailable: ['eventTimestamps', 'attachments', 'fileSnapshots'
|
|
70
|
+
lossReport: { lossless: false, excludedRecordTypes: ['system', 'system_reminder', 'reasoning', ...(record.acquisition ? ['compaction_meta'] : [])], unavailable: [...(record.occurredAt ? [] : ['eventTimestamps']), 'attachments', 'fileSnapshots'] },
|
|
61
71
|
},
|
|
62
72
|
};
|
|
63
73
|
}
|
|
74
|
+
const updateEnvelope = z.looseObject({
|
|
75
|
+
timestamp: z.number().finite(),
|
|
76
|
+
method: z.enum(['session/update', '_x.ai/session/update']),
|
|
77
|
+
params: z.looseObject({
|
|
78
|
+
sessionId: z.string().uuid(),
|
|
79
|
+
update: z.looseObject({ sessionUpdate: z.string() }),
|
|
80
|
+
_meta: z.looseObject({ agentTimestampMs: z.number().finite().nonnegative().max(8_640_000_000_000_000).optional() }).optional(),
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
const messageUpdate = z.looseObject({
|
|
84
|
+
content: text,
|
|
85
|
+
_meta: z.looseObject({ modelId: z.string().optional(), promptIndex: z.number().int().nonnegative().optional(), hostTurn: z.boolean().optional() }).optional(),
|
|
86
|
+
});
|
|
87
|
+
const compactUpdate = z.strictObject({
|
|
88
|
+
sessionUpdate: z.literal('auto_compact_completed'),
|
|
89
|
+
tokens_before: z.number().int().nonnegative(), tokens_after: z.number().int().nonnegative(),
|
|
90
|
+
summary_preview: z.string().nullable(),
|
|
91
|
+
});
|
|
92
|
+
const checkpointUpdate = z.strictObject({
|
|
93
|
+
sessionUpdate: z.literal('compaction_checkpoint'), checkpoint_id: z.string().uuid(),
|
|
94
|
+
prompt_index_at_compaction: z.number().int().nonnegative(), checkpoint_file: z.string(),
|
|
95
|
+
schema_version: z.literal(1), created_at: z.string(),
|
|
96
|
+
});
|
|
97
|
+
/** Validate checkpoint references without opening their private context files. */
|
|
98
|
+
export function parseNativeCompactionCheckpoint(value) {
|
|
99
|
+
const parsed = checkpointUpdate.safeParse(value);
|
|
100
|
+
if (!parsed.success || !Number.isFinite(Date.parse(parsed.data.created_at))
|
|
101
|
+
|| parsed.data.checkpoint_file !== `compaction_checkpoints/${parsed.data.checkpoint_id}.json`)
|
|
102
|
+
nativeDrift();
|
|
103
|
+
return { checkpointId: parsed.data.checkpoint_id.toLowerCase(), promptIndexAtCompaction: parsed.data.prompt_index_at_compaction };
|
|
104
|
+
}
|
|
105
|
+
const omittedUpdates = new Set(['agent_thought_chunk', 'turn_completed', 'hook_execution', 'background_tasks',
|
|
106
|
+
'compaction_checkpoint', 'subagent_spawned', 'subagent_finished', 'workflow_updated']);
|
|
107
|
+
/** Text-only update logs retain original turns when compaction rewrites chat history. */
|
|
108
|
+
export function projectNativeUpdate(line, sessionId, cwd, metadata) {
|
|
109
|
+
const parsed = updateEnvelope.safeParse(line.value);
|
|
110
|
+
if (!parsed.success || parsed.data.params.sessionId.toLowerCase() !== sessionId)
|
|
111
|
+
nativeDrift();
|
|
112
|
+
const { update, _meta } = parsed.data.params;
|
|
113
|
+
const type = update.sessionUpdate;
|
|
114
|
+
const base = { ...metadata, cwd, sequence: line.sequence * 1_000, acquisition: 'grok-build-native-updates',
|
|
115
|
+
...(_meta?.agentTimestampMs !== undefined ? { occurredAt: new Date(_meta.agentTimestampMs).toISOString() } : {}) };
|
|
116
|
+
if (type === 'user_message_chunk' || type === 'agent_message_chunk') {
|
|
117
|
+
const message = messageUpdate.safeParse(update);
|
|
118
|
+
if (!message.success)
|
|
119
|
+
nativeDrift();
|
|
120
|
+
return { record: { ...base, kind: 'message', role: type === 'user_message_chunk' ? 'user' : 'assistant',
|
|
121
|
+
content: message.data.content.text, ...(message.data._meta?.modelId ? { model: message.data._meta.modelId } : {}) }, line };
|
|
122
|
+
}
|
|
123
|
+
if (type === 'auto_compact_completed') {
|
|
124
|
+
const compact = compactUpdate.safeParse(update);
|
|
125
|
+
if (!compact.success)
|
|
126
|
+
nativeDrift();
|
|
127
|
+
return { record: { ...base, kind: 'compaction', content: '',
|
|
128
|
+
compaction: { tokensBefore: compact.data.tokens_before, tokensAfter: compact.data.tokens_after } }, line };
|
|
129
|
+
}
|
|
130
|
+
if (!omittedUpdates.has(type) && type !== 'tool_call' && type !== 'tool_call_update')
|
|
131
|
+
nativeDrift();
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
64
134
|
//# sourceMappingURL=grok-build-native-records.js.map
|
|
@@ -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,
|
package/dist/src/skills/run.js
CHANGED
|
@@ -159,17 +159,6 @@ export async function runSkill(opts) {
|
|
|
159
159
|
...(aiwgRoot ? { AIWG_ROOT: aiwgRoot } : {}),
|
|
160
160
|
...opts.env,
|
|
161
161
|
};
|
|
162
|
-
// Native source owner shares the same indexed script declaration and project CWD.
|
|
163
|
-
if (entry.path.replaceAll('\\', '/').endsWith('agentic/code/frameworks/sdlc-complete/skills/issue-audit/SKILL.md')
|
|
164
|
-
&& entry.script.entrypoint === 'scripts/audit.mjs') {
|
|
165
|
-
const audit = await import('../issues/audit-cli.js');
|
|
166
|
-
return audit.main(opts.args, runCwd, { env });
|
|
167
|
-
}
|
|
168
|
-
if (/agentic\/code\/(addons\/aiwg-utils|plugins\/utils)\/skills\/aiwg-pr\/SKILL\.md$/.test(entry.path.replaceAll('\\', '/'))
|
|
169
|
-
&& entry.script.entrypoint === 'scripts/deliver.mjs') {
|
|
170
|
-
const delivery = await import('../delivery/pr.js');
|
|
171
|
-
return delivery.main(opts.args, runCwd);
|
|
172
|
-
}
|
|
173
162
|
const fullArgs = [...invocation.prefixArgs, entrypointPath, ...opts.args];
|
|
174
163
|
return new Promise((resolve) => {
|
|
175
164
|
const child = spawn(invocation.command, fullArgs, {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generates agents following the 10 Golden Rules from the Agent Design Bible.
|
|
5
5
|
*
|
|
6
|
-
* @architecture
|
|
6
|
+
* @architecture @docs/architecture/cli/index.md
|
|
7
7
|
*/
|
|
8
8
|
import { AgentPackager } from '../../agents/agent-packager.js';
|
|
9
9
|
import { getProviderDefinition } from '../../providers/provider-definitions.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* context-pipeline — canonical workspace graph and provider adapter generator.
|
|
3
3
|
*
|
|
4
4
|
* Implements the cross-platform context delivery pipeline defined in
|
|
5
|
-
*
|
|
5
|
+
* `docs/configuration/workspace-context.md`. Emits a project graph:
|
|
6
6
|
*
|
|
7
7
|
* - WORKSPACE.md — protected provider-neutral project/operator context
|
|
8
8
|
* - AIWG.md — generated framework/discovery context
|
|
@@ -21,7 +21,7 @@ import { getProviderDefinition, listProviderDefinitions } from '../../providers/
|
|
|
21
21
|
* Providers that receive AGENTS.md emission at project root.
|
|
22
22
|
*
|
|
23
23
|
* Sources kept in sync:
|
|
24
|
-
* - ADR-1 §3 default-on rollout (
|
|
24
|
+
* - ADR-1 §3 default-on rollout (`docs/configuration/workspace-context.md`)
|
|
25
25
|
* - ADR-1 §4 per-provider variants table (file-name + twin-file emission)
|
|
26
26
|
*/
|
|
27
27
|
export const AGENTS_MD_PROVIDERS = new Set(listProviderDefinitions()
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - AIWG.md — generated framework context
|
|
8
8
|
* - provider startup files — minimal adapters that load WORKSPACE.md, then AIWG.md
|
|
9
9
|
*
|
|
10
|
-
* Per ADR-1 (
|
|
10
|
+
* Per ADR-1 (docs/configuration/workspace-context.md). NOT part of agentsmith;
|
|
11
11
|
* agentsmith creates subagent personas, this module assembles cross-platform context.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
@@ -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
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Parses CLI tool help output to extract tool definitions.
|
|
5
5
|
*
|
|
6
|
-
* @architecture
|
|
7
|
-
* @implements
|
|
6
|
+
* @architecture @docs/smithing/mcpsmith.md
|
|
7
|
+
* @implements @docs/smithing/mcpsmith.md
|
|
8
8
|
*/
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
10
|
/**
|