@aiwg/cli 2026.11.3 → 2026.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +3 -2
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +12 -9
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +2 -0
- package/agentic/code/addons/composition-engine/lib/runtime.mjs +5 -26
- package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +22 -0
- package/agentic/code/providers/capability-matrix.yaml +15 -18
- package/dist/src/a2a/hitl-authorization.js +46 -0
- package/dist/src/a2a/hitl-driver.js +5 -5
- package/dist/src/artifacts/browser-export.js +2 -0
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +5 -25
- package/dist/src/artifacts/index-capability.js +24 -0
- package/dist/src/artifacts/query-engine-discover-output.js +8 -3
- package/dist/src/artifacts/query-engine-rules.js +27 -9
- package/dist/src/artifacts/query-engine-scoring.js +5 -5
- package/dist/src/artifacts/query-engine-show-card.js +5 -1
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +3 -3
- package/dist/src/artifacts/query-engine-templates.js +10 -4
- package/dist/src/artifacts/query-engine-verbose.js +18 -4
- package/dist/src/artifacts/relations-builder.js +1 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/checkpoint-handoff.js +2 -1
- package/dist/src/cli/handlers/guided-setup.js +3 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +17 -5
- package/dist/src/cli/handlers/rules.js +1 -1
- package/dist/src/cli/handlers/sessions.js +1 -1
- package/dist/src/cli/handlers/steward.js +1 -1
- package/dist/src/cli/handlers/use.js +1 -2
- package/dist/src/cli/handlers/utility-doctor.js +5 -2
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/services/deployment-probe-scope.js +40 -0
- package/dist/src/cli/services/deployment-verification.js +4 -5
- package/dist/src/config/aiwg-config.js +6 -0
- package/dist/src/config/authorization-cli.js +61 -3
- package/dist/src/config/cli-help.js +1 -1
- package/dist/src/config/cli.js +4 -2
- package/dist/src/config/host-resource-runtime.mjs +1 -1
- package/dist/src/config/user-registry.js +9 -1
- package/dist/src/config/worker-owner-lock.js +90 -10
- package/dist/src/decision/graph-flow-adapter.js +1 -1
- package/dist/src/effects/authorization-grant.js +50 -0
- package/dist/src/effects/authorization-store.js +130 -0
- package/dist/src/effects/index.js +2 -0
- package/dist/src/effects/ledger.js +1 -0
- package/dist/src/effects/lifecycle.js +1 -1
- package/dist/src/effects/reader.js +4 -0
- package/dist/src/effects/records.js +4 -0
- package/dist/src/effects/schema.js +2 -0
- package/dist/src/extensions/claude-hooks-installer.js +7 -7
- package/dist/src/extensions/muse-managed-hooks.js +11 -0
- package/dist/src/extensions/user-hook-diagnostics.js +32 -0
- package/dist/src/extensions/verified-hook-command.js +32 -0
- package/dist/src/lint/rule-conflicts.js +52 -0
- package/dist/src/lint/runner.js +3 -0
- package/dist/src/mcp/cli.mjs +3 -1
- package/dist/src/mcp/elicitation.mjs +30 -0
- package/dist/src/mcp/grok-build-config.mjs +1 -1
- package/dist/src/mcp/muse-native-config.mjs +1 -0
- package/dist/src/mcp/server.mjs +2 -0
- package/dist/src/mcp/tools/authorization.mjs +78 -0
- package/dist/src/policy/authorization-capture.js +64 -0
- package/dist/src/policy/authorization-operations.js +108 -0
- package/dist/src/policy/hitl-check.js +3 -2
- package/dist/src/policy/hitl-consume.js +14 -0
- package/dist/src/policy/hitl-durable-store.js +60 -0
- package/dist/src/policy/hitl-durable.js +60 -0
- package/dist/src/policy/hitl-receipt.js +5 -0
- package/dist/src/policy/hitl.js +44 -6
- package/dist/src/process/bounded-child-process.mjs +49 -39
- package/dist/src/providers/capability-matrix.yaml +15 -18
- package/dist/src/providers/deployment-ownership.d.mts +1 -0
- package/dist/src/providers/deployment-ownership.mjs +21 -2
- package/dist/src/providers/grok-build-headless.js +170 -77
- package/dist/src/providers/grok-build-inspect.js +1 -0
- package/dist/src/providers/grok-build-paths.js +2 -0
- package/dist/src/providers/muse-paths.js +4 -2
- package/dist/src/providers/provider-context-contracts.js +12 -4
- package/dist/src/providers/provider-definition-schema.js +6 -0
- package/dist/src/providers/provider-seeds-1.js +3 -3
- package/dist/src/providers/provider-seeds-2.js +6 -4
- package/dist/src/providers/provider-seeds-3.js +6 -6
- package/dist/src/rules/activation.d.mts +2 -0
- package/dist/src/rules/activation.mjs +16 -7
- package/dist/src/rules/inline-budget.d.mts +2 -1
- package/dist/src/rules/inline-budget.mjs +4 -2
- package/dist/src/rules/inventory.js +3 -0
- package/dist/src/rules/precedence.d.mts +6 -0
- package/dist/src/rules/precedence.mjs +49 -0
- package/dist/src/rules/project-precedence.js +73 -0
- package/dist/src/rules/rule-frontmatter.schema.json +15 -0
- package/dist/src/serve/a2a-terminal-observer.js +12 -3
- package/dist/src/serve/mission-hitl.js +20 -1
- package/dist/src/sessions/adapters/grok-build-fallback.js +33 -0
- package/dist/src/sessions/adapters/grok-build-native-records.js +64 -0
- package/dist/src/sessions/adapters/grok-build-native.js +92 -100
- package/dist/src/sessions/adapters/grok-build.js +65 -24
- package/dist/src/sessions/grok-build-cli-output.js +113 -0
- package/dist/src/sessions/grok-build-cli.js +4 -28
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +4 -3
- package/dist/src/smiths/context-pipeline/finalization.js +5 -0
- package/dist/src/smiths/context-pipeline/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +20 -17
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +2 -1
- package/dist/src/smiths/context-pipeline/workspace-document.js +6 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -12
- package/dist/src/smiths/hook-bridge/codex-translator.js +11 -14
- package/dist/src/smiths/hook-bridge/codex-trust.js +7 -2
- package/dist/src/smiths/hook-bridge/copilot-translator.js +2 -1
- package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +78 -0
- package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
- package/dist/src/smiths/hook-bridge/index.js +3 -1
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +3 -2
- package/package.json +7 -1
- package/tools/agents/deploy-agents.mjs +5 -6
- package/tools/agents/deploy-options.mjs +1 -0
- package/tools/agents/providers/base-frontmatter.mjs +3 -2
- package/tools/agents/providers/claude-post-deploy.mjs +1 -1
- package/tools/agents/providers/codex-post-deploy.mjs +1 -1
- package/tools/agents/providers/generic.mjs +66 -0
- package/tools/agents/providers/grok-build.mjs +3 -1
- package/tools/agents/providers/muse-hooks.mjs +13 -11
- package/tools/agents/providers/muse-prompt-discovery.mjs +5 -1
- package/tools/agents/providers/muse.mjs +2 -1
- package/tools/agents/providers/openclaw.mjs +2 -1
- package/tools/agents/providers/rule-deployment-prepare.mjs +5 -3
- package/tools/agents/providers/rule-deployment-state.mjs +14 -6
- package/tools/agents/providers/rule-startup.mjs +11 -10
- package/tools/agents/providers/staged-directory-reference.mjs +14 -0
- package/tools/agents/providers/user-hooks.mjs +26 -0
- package/tools/cli/authorization-health.mjs +20 -0
- package/tools/cli/workspace-status.mjs +7 -0
- package/tools/commands/deploy-prompts-codex.mjs +15 -1
- package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* normal Node `ETIMEDOUT` error/result with a message that names the
|
|
11
11
|
* command, tier and bound.
|
|
12
12
|
*
|
|
13
|
+
* Stdin defaults to ignore. Synchronous `input` is delivered through a private
|
|
14
|
+
* mode-0600 temporary file descriptor, closed and removed after each call.
|
|
15
|
+
* This avoids synchronous stdin pipes that fail in Codex sandboxes (#4032).
|
|
16
|
+
*
|
|
13
17
|
* Tiers (see `SYNC_PROCESS_TIER_BOUNDS_MS`):
|
|
14
18
|
* - `quick` 30s — local queries: git status/rev-parse/config, version
|
|
15
19
|
* probes, `which`/`where`, `df`, tmux queries.
|
|
@@ -75,6 +79,9 @@ import {
|
|
|
75
79
|
execFileSync as nodeExecFileSync,
|
|
76
80
|
spawnSync as nodeSpawnSync,
|
|
77
81
|
} from 'node:child_process';
|
|
82
|
+
import { closeSync, mkdtempSync, openSync, rmSync, writeFileSync } from 'node:fs';
|
|
83
|
+
import { tmpdir } from 'node:os';
|
|
84
|
+
import { join } from 'node:path';
|
|
78
85
|
import { signalChild } from './signal-child.mjs';
|
|
79
86
|
|
|
80
87
|
/** Env var that raises or disables the `long` tier bound. `0` disables it (no timeout). */
|
|
@@ -208,45 +215,41 @@ function isParentStdinDescriptor(value) {
|
|
|
208
215
|
return value === 'inherit' || value === 0 || value === process.stdin;
|
|
209
216
|
}
|
|
210
217
|
|
|
211
|
-
/**
|
|
212
|
-
* A bounded call never inherits stdin; stdout/stderr may still be inherited
|
|
213
|
-
* for progress output. When the caller supplies `input`, an inherited
|
|
214
|
-
* stdin form is normalized to `'pipe'` instead of `'ignore'` — `input`
|
|
215
|
-
* needs a real pipe to deliver its payload through, and `'ignore'` would
|
|
216
|
-
* silently drop it (#3062 B/C finding 9). `options` is otherwise left
|
|
217
|
-
* untouched when stdin was not going to be inherited anyway.
|
|
218
|
-
*
|
|
219
|
-
* @param {Record<string, unknown>} options
|
|
220
|
-
* @returns {Record<string, unknown>}
|
|
221
|
-
*/
|
|
218
|
+
/** Normalize stdin without changing output streams or caller-owned options. */
|
|
222
219
|
function withoutInheritedStdin(options) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// `stdio: 'inherit'`/fd `0`/`process.stdin` could still leave stdin
|
|
229
|
-
// connected to the parent's real stdin instead of the pipe `input`
|
|
230
|
-
// is written to). stdout/stderr and the payload itself are untouched.
|
|
231
|
-
if (options.stdio === 'inherit') {
|
|
232
|
-
return { ...options, stdio: ['pipe', 'inherit', 'inherit'] };
|
|
233
|
-
}
|
|
234
|
-
if (Array.isArray(options.stdio) && isParentStdinDescriptor(options.stdio[0])) {
|
|
235
|
-
const stdio = options.stdio.slice();
|
|
236
|
-
stdio[0] = 'pipe';
|
|
237
|
-
return { ...options, stdio };
|
|
238
|
-
}
|
|
239
|
-
return options;
|
|
240
|
-
}
|
|
241
|
-
if (options.stdio === 'inherit') {
|
|
242
|
-
return { ...options, stdio: ['ignore', 'inherit', 'inherit'] };
|
|
220
|
+
const stdio = Array.isArray(options.stdio)
|
|
221
|
+
? options.stdio.slice()
|
|
222
|
+
: [options.stdio, options.stdio ?? 'pipe', options.stdio ?? 'pipe'];
|
|
223
|
+
if (stdio[0] == null || stdio[0] === 'pipe' || stdio[0] === 'overlapped' || isParentStdinDescriptor(stdio[0])) {
|
|
224
|
+
stdio[0] = options.input === undefined ? 'ignore' : 'pipe';
|
|
243
225
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
226
|
+
return { ...options, stdio };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Deliver synchronous input without Node's sandbox-sensitive stdin pipe (#4032). */
|
|
230
|
+
function withSyncStdin(options, run) {
|
|
231
|
+
if (options.input === undefined) return run(options);
|
|
232
|
+
// Never fall back to Node's synchronous input pipe: in sandboxes it blocks the
|
|
233
|
+
// child until the timeout. Without writable temp storage the call fails fast;
|
|
234
|
+
// boundedSpawnSync turns this into a returned error, as spawnSync does.
|
|
235
|
+
let directory;
|
|
236
|
+
try { directory = mkdtempSync(join(tmpdir(), 'aiwg-sync-stdin-')); }
|
|
237
|
+
catch (error) { throw Object.assign(error, { aiwgStdinTempUnavailable: true }); }
|
|
238
|
+
let fd;
|
|
239
|
+
try {
|
|
240
|
+
const filename = join(directory, 'stdin');
|
|
241
|
+
writeFileSync(filename, options.input, {
|
|
242
|
+
flag: 'wx', mode: 0o600, encoding: options.encoding ?? 'utf8',
|
|
243
|
+
});
|
|
244
|
+
fd = openSync(filename, 'r');
|
|
245
|
+
const { input: _input, ...nodeOptions } = options;
|
|
246
|
+
nodeOptions.stdio = options.stdio.slice();
|
|
247
|
+
nodeOptions.stdio[0] = fd;
|
|
248
|
+
return run(nodeOptions);
|
|
249
|
+
} finally {
|
|
250
|
+
try { if (fd !== undefined) closeSync(fd); }
|
|
251
|
+
finally { rmSync(directory, { recursive: true, force: true }); }
|
|
248
252
|
}
|
|
249
|
-
return options;
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
/**
|
|
@@ -328,7 +331,7 @@ export function boundedExecSync(command, tier, options) {
|
|
|
328
331
|
const boundMs = effectiveTimeoutMs(tier, options);
|
|
329
332
|
const nodeOptions = toNodeOptions(options, boundMs);
|
|
330
333
|
try {
|
|
331
|
-
return nodeExecSync(command,
|
|
334
|
+
return withSyncStdin(nodeOptions, prepared => nodeExecSync(command, prepared));
|
|
332
335
|
} catch (error) {
|
|
333
336
|
throw enrichTimeoutError(error, { description: command, tier, boundMs });
|
|
334
337
|
}
|
|
@@ -351,7 +354,7 @@ export function boundedExecFileSync(file, args, tier, options) {
|
|
|
351
354
|
const boundMs = effectiveTimeoutMs(tier, options);
|
|
352
355
|
const nodeOptions = toNodeOptions(options, boundMs);
|
|
353
356
|
try {
|
|
354
|
-
return nodeExecFileSync(file, args,
|
|
357
|
+
return withSyncStdin(nodeOptions, prepared => nodeExecFileSync(file, args, prepared));
|
|
355
358
|
} catch (error) {
|
|
356
359
|
throw enrichTimeoutError(error, { description: describeCommand(file, args), tier, boundMs });
|
|
357
360
|
}
|
|
@@ -383,7 +386,14 @@ export function boundedSpawnSync(command, args, tier, options) {
|
|
|
383
386
|
assertValidTier(tier);
|
|
384
387
|
const boundMs = effectiveTimeoutMs(tier, options);
|
|
385
388
|
const nodeOptions = toNodeOptions(options, boundMs);
|
|
386
|
-
|
|
389
|
+
let result;
|
|
390
|
+
try {
|
|
391
|
+
result = withSyncStdin(nodeOptions, prepared => nodeSpawnSync(command, args, prepared));
|
|
392
|
+
} catch (error) {
|
|
393
|
+
// Like spawnSync, report a missing temp directory for input as a returned error; other throws propagate.
|
|
394
|
+
if (!error?.aiwgStdinTempUnavailable) throw error;
|
|
395
|
+
result = { pid: 0, output: [null, null, null], stdout: null, stderr: null, status: null, signal: null, error };
|
|
396
|
+
}
|
|
387
397
|
enrichTimeoutError(result.error, { description: describeCommand(command, args), tier, boundMs, signal: result.signal });
|
|
388
398
|
return result;
|
|
389
399
|
}
|
|
@@ -549,7 +549,7 @@ providers:
|
|
|
549
549
|
scope: in
|
|
550
550
|
identity: runtime-configured-only
|
|
551
551
|
evidence: R
|
|
552
|
-
channel: "grok -p --output-format streaming-json; bounded parser
|
|
552
|
+
channel: "grok -p --output-format streaming-json; 1.0.77 adds --no-auto-update; bounded parser (model/effort pins unverified by captures)"
|
|
553
553
|
fanout: unknown
|
|
554
554
|
probe_budget: { status: authorized, calls: 3, tokens: 30000, authorized_by: operator, authorized_at: "2026-10-07", hosts: [titan, noodle] }
|
|
555
555
|
coverage:
|
|
@@ -560,35 +560,32 @@ providers:
|
|
|
560
560
|
- "src/providers/grok-build-headless.ts"
|
|
561
561
|
status: experimental
|
|
562
562
|
# xAI Grok Build CLI/TUI. Distinct from Grok Bot (`grokbot`).
|
|
563
|
-
# #2577:
|
|
564
|
-
#
|
|
565
|
-
# test/unit/providers/grok-build-
|
|
566
|
-
#
|
|
567
|
-
#
|
|
568
|
-
# and grok-build-acp.test.ts. ACP does not establish a daemon lifecycle.
|
|
569
|
-
# No fixture supports native cron, multi-agent teams, mission control,
|
|
570
|
-
# or AIWG behavior registration; those claims remain false.
|
|
563
|
+
# #2577: every claim and its limits are recorded in
|
|
564
|
+
# docs/providers/grok-build-native-agents.md (1.0.77 evidence table).
|
|
565
|
+
# Captured headless shapes: test/unit/providers/grok-build-headless.test.ts.
|
|
566
|
+
# Agent compilation, native fan-out/worktrees and ACP remain unverified by
|
|
567
|
+
# these captures; pre-existing synthetic tests establish AIWG behavior only.
|
|
571
568
|
daemon_tier: unsupported
|
|
572
569
|
daemon_pty_adapter: false
|
|
573
570
|
artifact_paths:
|
|
574
|
-
agents: .grok/agents/ #
|
|
571
|
+
agents: .grok/agents/ # writer path; native frontmatter unverified by captures
|
|
575
572
|
commands: null
|
|
576
573
|
skills: .grok/skills/
|
|
577
574
|
skills_cross_agent: .grok/.aiwg/skills/ # --copy-all opt-in mirror
|
|
578
575
|
rules: "Indexed: aiwg show rule + AGENTS.md / host .grok/rules (AIWG writer deferred #2577)"
|
|
579
576
|
behaviors: null
|
|
580
577
|
native_features:
|
|
581
|
-
cron: false
|
|
582
|
-
agent_teams: false
|
|
583
|
-
tasks:
|
|
584
|
-
mcp: true
|
|
585
|
-
behaviors: false
|
|
586
|
-
mission_control: false
|
|
587
|
-
daemon: false
|
|
578
|
+
cron: false # unverified: needs recurring-loop execution capture
|
|
579
|
+
agent_teams: false # unverified: needs team lifecycle capture
|
|
580
|
+
tasks: false # unverified: headless tool calls do not prove background task lifecycle
|
|
581
|
+
mcp: true # fixture-backed config only: grok-build-native-integration.test.ts; live MCP unverified
|
|
582
|
+
behaviors: false # unverified: needs behavior registration/execution capture
|
|
583
|
+
mission_control: false # unverified: needs mission lifecycle capture
|
|
584
|
+
daemon: false # unverified: ACP is separate and needs agent-stdio capture
|
|
588
585
|
emulation:
|
|
589
586
|
cron: null
|
|
590
587
|
agent_teams: aiwg-mc
|
|
591
|
-
tasks:
|
|
588
|
+
tasks: aiwg-mc
|
|
592
589
|
mcp: null
|
|
593
590
|
behaviors: aiwg-mc
|
|
594
591
|
mission_control: aiwg-mc
|
|
@@ -23,6 +23,7 @@ export class DeploymentOutputState {
|
|
|
23
23
|
export type DeploymentOutputSnapshot = Map<string, Buffer | DeploymentOutputState>;
|
|
24
24
|
export function outputDigest(entry: Buffer | DeploymentOutputState | undefined): string | undefined;
|
|
25
25
|
export function sameOutput(a: Buffer | DeploymentOutputState | undefined, b: Buffer | DeploymentOutputState | undefined): boolean;
|
|
26
|
+
export function legacyCodexPromptOwner(file: string, entry: Buffer | DeploymentOutputState | undefined): string | undefined;
|
|
26
27
|
export function captureDeploymentOutputs(roots: PathLike[], options?: { previous?: DeploymentOutputSnapshot }): DeploymentOutputSnapshot;
|
|
27
28
|
export function recordDeploymentOutputs(before: DeploymentOutputSnapshot, roots: PathLike[], opts?: DeploymentOwnershipOptions): void;
|
|
28
29
|
export function refreshSettingsDigests(record: { settings?: Record<string, unknown> }): void;
|
|
@@ -58,6 +58,22 @@ const digestOf = entry => {
|
|
|
58
58
|
export const outputDigest = entry => digestOf(entry);
|
|
59
59
|
/** Content equality; a stat-only entry never equals a different entry. */
|
|
60
60
|
export const sameOutput = (a, b) => a != null && b != null && (a === b || (digestOf(a) !== undefined && digestOf(a) === digestOf(b)));
|
|
61
|
+
|
|
62
|
+
// v2026.10.0–v2026.10.19: deploy-prompts-codex.mjs emitted these exact
|
|
63
|
+
// unmarked bytes (description frontmatter + trimmed command body, no final LF).
|
|
64
|
+
// Sources: addons/{dataset-intelligence,schema-governance,aiwg-utils}/commands/
|
|
65
|
+
// {dataset,schema,sessions}.md. Fixtures retain v2026.10.3 sources and outputs.
|
|
66
|
+
const LEGACY_CODEX_PROMPTS = {
|
|
67
|
+
'aiwg-dataset.md': ['sha256:652469f0023144af5597cb6571f9ff498e5a11e5795de4074480f814dc106a87', 'dataset-intelligence'],
|
|
68
|
+
'aiwg-schema.md': ['sha256:65000b74de7149b70229f5c8409e2c6a6c4d5e45086f776e0db2ae8633c176f9', 'schema-governance'],
|
|
69
|
+
'aiwg-sessions.md': ['sha256:ad0591041932dbbb8a08a5d0e946490b2ef3e18a1b65f610df3555b6b67eb690', 'aiwg-utils'],
|
|
70
|
+
};
|
|
71
|
+
/** Recognize only historical bytes at their original Codex prompt names. */
|
|
72
|
+
export function legacyCodexPromptOwner(file, entry) {
|
|
73
|
+
if (path.basename(path.dirname(file)) !== 'prompts' || path.basename(path.dirname(path.dirname(file))) !== '.codex') return undefined;
|
|
74
|
+
const known = LEGACY_CODEX_PROMPTS[path.basename(file)];
|
|
75
|
+
return known && known[0] === digestOf(entry) ? known[1] : undefined;
|
|
76
|
+
}
|
|
61
77
|
const bytesOf = (file, entry) => {
|
|
62
78
|
if (entry == null || Buffer.isBuffer(entry)) return entry;
|
|
63
79
|
throw new Error(`Deployment snapshot did not retain bytes for ${file}`);
|
|
@@ -270,10 +286,13 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
270
286
|
if (path.basename(file) === SIDECAR || /(?:^|[/\\])aiwg\.config$/.test(file)
|
|
271
287
|
|| /(?:\.bak\.|\.aiwg-backup-)/.test(path.basename(file))) continue;
|
|
272
288
|
if (preserved.has(file)) continue;
|
|
289
|
+
const legacyOwner = opts.provider === 'codex'
|
|
290
|
+
&& !parse(before.get(path.join(path.dirname(file), SIDECAR))).managed?.[path.basename(file)]
|
|
291
|
+
&& legacyCodexPromptOwner(file, before.get(file));
|
|
273
292
|
const changed = !sameOutput(before.get(file), bytes);
|
|
274
293
|
const declaration = declared.get(file);
|
|
275
294
|
if (opts.onlyDeclared && !declaration) continue;
|
|
276
|
-
if (!changed && !declaration && !opts.writtenFiles?.includes(file)) continue;
|
|
295
|
+
if (!changed && !declaration && !legacyOwner && !opts.writtenFiles?.includes(file)) continue;
|
|
277
296
|
// Existing integrity receipts that disagree with bytes never bless operator edits.
|
|
278
297
|
if (declaration?.entry.hash && declaration.entry.hash !== digestOf(bytes)) continue;
|
|
279
298
|
let skillRoot = path.dirname(file);
|
|
@@ -298,7 +317,7 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
298
317
|
|| skillReceipt.managed?.['SKILL.md']?.frameworkSlug;
|
|
299
318
|
const generatedIndex = /^RULES-(?:INDEX|ONDEMAND)\.(?:md|mdc)$/.test(path.basename(file));
|
|
300
319
|
const kind = generatedIndex ? 'rule-index' : current.kind || artifactKind(file);
|
|
301
|
-
const selectedOwner = opts.provider === 'flue' ? owner : sourceOwner || (opts.onlyDeclared ? current.owners?.[0] : owner);
|
|
320
|
+
const selectedOwner = opts.provider === 'flue' ? owner : sourceOwner || legacyOwner || (opts.onlyDeclared ? current.owners?.[0] : owner);
|
|
302
321
|
if (!selectedOwner) {
|
|
303
322
|
console.warn(`Ownership not recorded for ${file}: no framework owner resolved.`);
|
|
304
323
|
continue;
|
|
@@ -1,75 +1,105 @@
|
|
|
1
1
|
/** Bounded Grok Build headless transport. The caller owns task authorization. */
|
|
2
2
|
import { signalChild } from '../process/signal-child.mjs';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
+
/** Failed runs retain redacted partial output and observed accounting. */
|
|
5
|
+
export class GrokHeadlessError extends Error {
|
|
6
|
+
result;
|
|
7
|
+
constructor(message, result) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.result = result;
|
|
10
|
+
this.name = 'GrokHeadlessError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
const MAX_TIMEOUT_MS = 10 * 60_000;
|
|
5
14
|
const DEFAULT_TIMEOUT_MS = 2 * 60_000;
|
|
6
15
|
const DEFAULT_MAX_OUTPUT = 8 * 1024 * 1024;
|
|
7
|
-
//
|
|
8
|
-
// See docs/providers/grok-build-cli-evidence.md; json is a separate result object.
|
|
16
|
+
// Captured 1.0.77 headless events; this is not the agent-stdio ACP contract.
|
|
9
17
|
const STREAM_EVENT_TYPES = new Set(['text', 'thought', 'tool_call', 'tool_call_update',
|
|
10
18
|
'usage', 'plan', 'available_commands', 'end', 'error']);
|
|
19
|
+
const MESSAGE_EVENT_TYPES = new Set(['system', 'assistant', 'user', 'result', 'error']);
|
|
11
20
|
export function redactGrokOutput(value, env = process.env) {
|
|
12
21
|
let redacted = value
|
|
22
|
+
.replace(/("(?:api[_-]?key|access[_-]?token|authorization)"\s*:\s*)"(?:\\.|[^"\\])*"/gi, '$1"[REDACTED]"')
|
|
13
23
|
.replace(/\b(Bearer\s+)[A-Za-z0-9._~+/-]+/gi, '$1[REDACTED]')
|
|
14
24
|
.replace(/\b(xai-[A-Za-z0-9_-]{8,})\b/g, '[REDACTED]')
|
|
15
25
|
.replace(/\b((?:api[_-]?key|access[_-]?token|authorization)\s*[:=]\s*)[^\s,}"']+/gi, '$1[REDACTED]');
|
|
16
26
|
for (const key of ['XAI_API_KEY', 'GROK_CODE_XAI_API_KEY']) {
|
|
17
27
|
const secret = env[key];
|
|
18
|
-
if (secret && secret.length >= 4)
|
|
28
|
+
if (secret && secret.length >= 4) {
|
|
19
29
|
redacted = redacted.split(secret).join('[REDACTED]');
|
|
30
|
+
redacted = redacted.split(JSON.stringify(secret).slice(1, -1)).join('[REDACTED]');
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
return redacted;
|
|
22
34
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
function scrub(value, env) {
|
|
36
|
+
if (typeof value === 'string')
|
|
37
|
+
return redactGrokOutput(value, env);
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value.map(item => scrub(item, env));
|
|
40
|
+
if (value && typeof value === 'object') {
|
|
41
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [redactGrokOutput(key, env),
|
|
42
|
+
/^(?:api[_-]?key|access[_-]?token|authorization)$/i.test(key) ? '[REDACTED]' : scrub(item, env)]));
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
26
45
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
46
|
+
function record(value) {
|
|
47
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
29
48
|
}
|
|
30
49
|
function isError(event) {
|
|
31
50
|
return event.type === 'error' || event.is_error === true || event.error != null
|
|
32
|
-
|| (event.
|
|
51
|
+
|| (Array.isArray(event.errors) && event.errors.length > 0)
|
|
52
|
+
|| (event.type === 'result' && event.subtype !== 'success')
|
|
33
53
|
|| (['tool_call', 'tool_call_update'].includes(String(event.type)) && event.status === 'failed');
|
|
34
54
|
}
|
|
35
|
-
function
|
|
55
|
+
function signalProcess(child, signal) {
|
|
36
56
|
if (Number.isSafeInteger(child.pid) && child.pid > 0 && process.platform !== 'win32') {
|
|
37
57
|
try {
|
|
38
|
-
process.kill(-child.pid,
|
|
58
|
+
process.kill(-child.pid, signal);
|
|
39
59
|
return;
|
|
40
60
|
}
|
|
41
61
|
catch { /* process already exited */ }
|
|
42
62
|
}
|
|
43
|
-
signalChild(child,
|
|
63
|
+
signalChild(child, signal);
|
|
44
64
|
}
|
|
45
65
|
export async function runGrokHeadless(options) {
|
|
46
66
|
if (!options.prompt.trim())
|
|
47
67
|
throw new Error('Grok Build prompt is required');
|
|
48
68
|
const format = options.format ?? 'streaming-json';
|
|
49
|
-
if (!['plain', 'json', 'streaming-json'].includes(format))
|
|
69
|
+
if (!['plain', 'json', 'streaming-json', 'streaming-messages-json'].includes(format))
|
|
50
70
|
throw new Error(`Unsupported Grok output format: ${format}`);
|
|
51
|
-
const
|
|
71
|
+
for (const key of ['timeoutMs', 'maxOutputBytes']) {
|
|
72
|
+
if (options[key] !== undefined && (!Number.isFinite(options[key]) || options[key] <= 0)) {
|
|
73
|
+
throw new Error(`Grok Build ${key} must be a positive finite number`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const timeoutMs = Math.min(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS);
|
|
52
77
|
const maxBytes = Math.min(Math.max(options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT, 1024), DEFAULT_MAX_OUTPUT);
|
|
53
78
|
const env = options.env ?? process.env;
|
|
54
|
-
const args = [...(options.prefixArgs ?? []), ...(options.disableSubagents ? ['--no-subagents'] : []), '-p', options.prompt, '--output-format', format];
|
|
79
|
+
const args = [...(options.prefixArgs ?? []), '--no-auto-update', ...(options.disableSubagents ? ['--no-subagents'] : []), '-p', options.prompt, '--output-format', format];
|
|
80
|
+
const streaming = format === 'streaming-json' || format === 'streaming-messages-json';
|
|
55
81
|
return new Promise((resolve, reject) => {
|
|
56
82
|
const child = spawn(options.command ?? 'grok', args, {
|
|
57
|
-
cwd: options.cwd,
|
|
58
|
-
|
|
59
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
60
|
-
detached: process.platform !== 'win32',
|
|
61
|
-
shell: false,
|
|
83
|
+
cwd: options.cwd, env, stdio: ['ignore', 'pipe', 'pipe'],
|
|
84
|
+
detached: process.platform !== 'win32', shell: false,
|
|
62
85
|
});
|
|
86
|
+
// Stateful decoders preserve code points split across pipe reads.
|
|
87
|
+
child.stdout.setEncoding('utf8');
|
|
88
|
+
child.stderr.setEncoding('utf8');
|
|
63
89
|
let stdout = '';
|
|
64
90
|
let stderr = '';
|
|
65
91
|
let pending = '';
|
|
66
92
|
let bytes = 0;
|
|
93
|
+
let stderrBytes = 0;
|
|
67
94
|
let settled = false;
|
|
95
|
+
let closed = false;
|
|
96
|
+
let exitCode;
|
|
97
|
+
let exitSignal = null;
|
|
68
98
|
let terminalSeen = false;
|
|
69
99
|
let terminalError = false;
|
|
70
100
|
const events = [];
|
|
71
101
|
let drainTimer;
|
|
72
|
-
const finish = (error, code = 0) => {
|
|
102
|
+
const finish = (error, code = exitCode ?? 0) => {
|
|
73
103
|
if (settled)
|
|
74
104
|
return;
|
|
75
105
|
settled = true;
|
|
@@ -77,86 +107,126 @@ export async function runGrokHeadless(options) {
|
|
|
77
107
|
if (drainTimer)
|
|
78
108
|
clearTimeout(drainTimer);
|
|
79
109
|
options.signal?.removeEventListener('abort', abort);
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
if (format === 'json') {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(stdout);
|
|
113
|
+
if (!record(parsed) || typeof parsed.text !== 'string')
|
|
114
|
+
throw new Error('Invalid result');
|
|
115
|
+
const safe = scrub(parsed, env);
|
|
116
|
+
events.push(safe);
|
|
117
|
+
if (isError(safe) || safe.stopReason !== 'end_turn')
|
|
118
|
+
error ??= new Error('Grok Build returned a JSON error result');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
error ??= new Error('Invalid Grok Build JSON error result');
|
|
122
|
+
}
|
|
84
123
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
124
|
+
if (code !== 0 || exitSignal || terminalError) {
|
|
125
|
+
error ??= new Error(`Grok Build headless failed (exit ${code}${exitSignal ? `, signal ${exitSignal}` : ''}): ${stderr || 'provider error event'}`);
|
|
126
|
+
}
|
|
127
|
+
if (streaming && !terminalSeen)
|
|
128
|
+
error ??= new Error(`Grok Build ${format} ended without a terminal event`);
|
|
129
|
+
const result = { format, text: redactGrokOutput(stdout, env), events,
|
|
130
|
+
exitCode: code, stderr: redactGrokOutput(stderr, env) };
|
|
131
|
+
// Terminal totals supersede per-turn usage; never sum cumulative frames.
|
|
132
|
+
for (const event of events) {
|
|
133
|
+
const reason = event.stopReason ?? event.stop_reason;
|
|
134
|
+
if (typeof reason === 'string')
|
|
135
|
+
result.stopReason = reason;
|
|
136
|
+
for (const key of ['usage', 'modelUsage']) {
|
|
137
|
+
const value = event[key] ?? (key === 'usage' && record(event.message) ? event.message.usage : undefined);
|
|
138
|
+
if (record(value))
|
|
139
|
+
result[key] = value;
|
|
140
|
+
}
|
|
141
|
+
for (const key of ['num_turns', 'total_cost_usd', 'total_cost_usd_ticks']) {
|
|
142
|
+
if (typeof event[key] === 'number' && Number.isFinite(event[key]))
|
|
143
|
+
result[key] = event[key];
|
|
144
|
+
}
|
|
90
145
|
}
|
|
91
|
-
|
|
92
|
-
|
|
146
|
+
const complete = () => {
|
|
147
|
+
if (error)
|
|
148
|
+
reject(new GrokHeadlessError(redactGrokOutput(error.message, env), result));
|
|
149
|
+
else
|
|
150
|
+
resolve(result);
|
|
151
|
+
};
|
|
152
|
+
if (closed) {
|
|
153
|
+
complete();
|
|
93
154
|
return;
|
|
94
155
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
156
|
+
// Bound cleanup even for a child ignoring TERM or descendants holding pipes.
|
|
157
|
+
signalProcess(child, 'SIGTERM');
|
|
158
|
+
setTimeout(() => {
|
|
159
|
+
signalProcess(child, 'SIGKILL');
|
|
160
|
+
child.stdout.destroy();
|
|
161
|
+
child.stderr.destroy();
|
|
162
|
+
complete();
|
|
163
|
+
}, 150);
|
|
164
|
+
};
|
|
165
|
+
const abort = () => finish(new Error('Grok Build headless aborted'), 1);
|
|
166
|
+
const timer = setTimeout(() => finish(new Error(`Grok Build headless timed out after ${timeoutMs}ms`), 1), timeoutMs);
|
|
167
|
+
const drain = () => {
|
|
168
|
+
drainTimer ??= setTimeout(() => {
|
|
169
|
+
if (streaming && pending.trim()) {
|
|
170
|
+
finish(new Error(`Invalid trailing Grok Build ${format} event`));
|
|
106
171
|
return;
|
|
107
172
|
}
|
|
108
|
-
|
|
109
|
-
|
|
173
|
+
finish();
|
|
174
|
+
}, 300);
|
|
110
175
|
};
|
|
111
|
-
const abort = () => finish(new Error('Grok Build headless aborted'));
|
|
112
|
-
const timer = setTimeout(() => finish(new Error(`Grok Build headless timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
113
176
|
options.signal?.addEventListener('abort', abort, { once: true });
|
|
114
177
|
if (options.signal?.aborted)
|
|
115
178
|
abort();
|
|
116
|
-
child.on('error', error => finish(new Error(`Grok Build headless launch failed: ${error.message}`)));
|
|
179
|
+
child.on('error', error => finish(new Error(`Grok Build headless launch failed: ${error.message}`), 1));
|
|
117
180
|
const acceptEvent = (event) => {
|
|
118
181
|
if (settled)
|
|
119
182
|
return;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
finish(new Error(
|
|
183
|
+
const types = format === 'streaming-messages-json' ? MESSAGE_EVENT_TYPES : STREAM_EVENT_TYPES;
|
|
184
|
+
if (!record(event) || typeof event.type !== 'string' || !types.has(event.type)) {
|
|
185
|
+
finish(new Error(`Invalid Grok Build ${format} event`));
|
|
123
186
|
return;
|
|
124
187
|
}
|
|
125
|
-
// ACP end is always last. Failure is latched across the whole stream.
|
|
126
188
|
if (terminalSeen) {
|
|
127
189
|
finish(new Error('Grok Build event after terminal event'));
|
|
128
190
|
return;
|
|
129
191
|
}
|
|
130
|
-
|
|
192
|
+
if (['assistant', 'user'].includes(event.type) && (!record(event.message) || !Array.isArray(event.message.content))) {
|
|
193
|
+
finish(new Error('Invalid Grok Build message envelope'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const safe = scrub(event, env);
|
|
131
197
|
events.push(safe);
|
|
132
|
-
|
|
133
|
-
if (isError(safe))
|
|
198
|
+
const terminal = event.type === 'error' || event.type === (format === 'streaming-messages-json' ? 'result' : 'end');
|
|
199
|
+
if (isError(safe) || (terminal && (safe.stopReason ?? safe.stop_reason) !== 'end_turn'))
|
|
134
200
|
terminalError = true;
|
|
135
|
-
if (
|
|
201
|
+
if (terminal) {
|
|
136
202
|
terminalSeen = true;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
stopProcess(child);
|
|
145
|
-
finish(undefined, terminalError ? 1 : 0);
|
|
146
|
-
}, 300);
|
|
203
|
+
drain();
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
options.onEvent?.(safe);
|
|
207
|
+
}
|
|
208
|
+
catch (cause) {
|
|
209
|
+
finish(new Error(`Grok Build event callback failed: ${cause instanceof Error ? cause.message : String(cause)}`));
|
|
147
210
|
}
|
|
148
211
|
};
|
|
149
|
-
child.stdout.on('data', (
|
|
212
|
+
child.stdout.on('data', (part) => {
|
|
150
213
|
if (settled)
|
|
151
214
|
return;
|
|
152
|
-
bytes +=
|
|
215
|
+
bytes += Buffer.byteLength(part);
|
|
153
216
|
if (bytes > maxBytes) {
|
|
154
217
|
finish(new Error(`Grok Build headless output exceeded ${maxBytes} bytes`));
|
|
155
218
|
return;
|
|
156
219
|
}
|
|
157
|
-
const part = chunk.toString('utf8');
|
|
158
220
|
stdout += part;
|
|
159
|
-
if (format
|
|
221
|
+
if (format === 'json') {
|
|
222
|
+
// A complete result can arrive without a newline or process exit.
|
|
223
|
+
try {
|
|
224
|
+
if (record(JSON.parse(stdout)))
|
|
225
|
+
drain();
|
|
226
|
+
}
|
|
227
|
+
catch { /* wait for the remainder */ }
|
|
228
|
+
}
|
|
229
|
+
if (!streaming)
|
|
160
230
|
return;
|
|
161
231
|
pending += part;
|
|
162
232
|
let end;
|
|
@@ -170,26 +240,49 @@ export async function runGrokHeadless(options) {
|
|
|
170
240
|
event = JSON.parse(line);
|
|
171
241
|
}
|
|
172
242
|
catch {
|
|
173
|
-
finish(new Error(
|
|
243
|
+
finish(new Error(`Invalid Grok Build ${format} event`));
|
|
174
244
|
return;
|
|
175
245
|
}
|
|
176
246
|
acceptEvent(event);
|
|
177
247
|
if (settled)
|
|
178
248
|
return;
|
|
179
249
|
}
|
|
250
|
+
// Parse complete newline-free frames now so background work cannot hold us.
|
|
251
|
+
if (pending.trim()) {
|
|
252
|
+
let event;
|
|
253
|
+
try {
|
|
254
|
+
event = JSON.parse(pending);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
pending = '';
|
|
260
|
+
acceptEvent(event);
|
|
261
|
+
}
|
|
180
262
|
});
|
|
181
|
-
child.stderr.on('data', (
|
|
182
|
-
|
|
183
|
-
|
|
263
|
+
child.stderr.on('data', (part) => {
|
|
264
|
+
if (settled)
|
|
265
|
+
return;
|
|
266
|
+
stderrBytes += Buffer.byteLength(part);
|
|
267
|
+
if (stderrBytes > maxBytes) {
|
|
184
268
|
finish(new Error(`Grok Build stderr exceeded ${maxBytes} bytes`));
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
stderr += part;
|
|
185
272
|
});
|
|
273
|
+
child.on('exit', (code, signal) => { exitCode = code ?? 1; exitSignal = signal; });
|
|
186
274
|
child.on('close', code => {
|
|
187
|
-
|
|
275
|
+
closed = true;
|
|
276
|
+
if (settled)
|
|
277
|
+
return;
|
|
278
|
+
if (streaming && pending.trim()) {
|
|
279
|
+
const line = pending;
|
|
280
|
+
pending = '';
|
|
188
281
|
try {
|
|
189
|
-
acceptEvent(JSON.parse(
|
|
282
|
+
acceptEvent(JSON.parse(line));
|
|
190
283
|
}
|
|
191
284
|
catch {
|
|
192
|
-
finish(new Error(
|
|
285
|
+
finish(new Error(`Invalid trailing Grok Build ${format} event`));
|
|
193
286
|
return;
|
|
194
287
|
}
|
|
195
288
|
}
|
|
@@ -169,6 +169,7 @@ export function runGrokInspect(envOrOptions = process.env) {
|
|
|
169
169
|
const args = argSets[i];
|
|
170
170
|
const wantsJson = args.length > 1 && args[1] === '--json';
|
|
171
171
|
const result = spawnSync(binary, [...args], {
|
|
172
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
172
173
|
encoding: 'utf8',
|
|
173
174
|
env,
|
|
174
175
|
cwd,
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { homedir } from 'node:os';
|
|
14
14
|
import * as path from 'node:path';
|
|
15
|
+
/** Project-only opt-in bulk mirror, shared by the registry and deployment adapter. */
|
|
16
|
+
export const GROK_BUILD_STANDARD_SKILLS_PATH = '.grok/.aiwg/skills';
|
|
15
17
|
export const GROK_HOME_ENV = 'GROK_HOME';
|
|
16
18
|
export function isGrokFilesystemRoot(resolved, pathFlavor = path) {
|
|
17
19
|
return pathFlavor.parse(resolved).root === resolved;
|