@yunhozz/arc 0.4.1 → 0.4.3
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/MANIFEST.sha256 +66 -42
- package/README.md +6 -6
- package/claude/skill/references/coordination.md +1 -1
- package/codex/skill/references/coordination.md +1 -1
- package/gemini/skill/references/coordination.md +1 -1
- package/grok/AGENTS.md +8 -0
- package/grok/agents/arc-implementer.md +37 -0
- package/grok/agents/arc-planner.md +47 -0
- package/grok/agents/arc-qa.md +37 -0
- package/grok/agents/arc-reviewer.md +39 -0
- package/grok/agents/arc-scouter.md +38 -0
- package/grok/instructions.md +4 -0
- package/grok/skill/SKILL.md +78 -0
- package/grok/skill/models.toml +23 -0
- package/grok/skill/references/arc-visual-companion.md +28 -0
- package/grok/skill/references/commit.md +55 -0
- package/grok/skill/references/coordination.md +149 -0
- package/grok/skill/references/git-recovery.md +34 -0
- package/grok/skill/references/handoff-prep.md +110 -0
- package/grok/skill/references/handoff.md +227 -0
- package/grok/skill/references/limits.md +31 -0
- package/grok/skill/references/planning.md +168 -0
- package/grok/skill/references/verification.md +155 -0
- package/grok/skill/references/worktree-creation.md +8 -0
- package/lib/installer/grok-compat.mjs +107 -0
- package/lib/installer/plan.mjs +7 -3
- package/lib/installer/runtime-assets.mjs +1 -0
- package/lib/installer/uninstall.mjs +14 -1
- package/lib/installer/upgrade-state.mjs +4 -2
- package/lib/installer/upgrade.mjs +5 -0
- package/lib/management/operations.mjs +1 -1
- package/lib/management/status.mjs +4 -2
- package/lib/management/update.mjs +4 -4
- package/lib/models/codex-models.json +72 -0
- package/lib/models/grok-models.json +7 -0
- package/lib/platforms/formats/grok-markdown.mjs +49 -0
- package/lib/platforms/grok.mjs +14 -0
- package/lib/platforms/index.mjs +2 -1
- package/lib/policy/role-policy.json +34 -15
- package/lib/prompts/agent-fragments.json +70 -0
- package/lib/prompts/render.mjs +6 -1
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/grok-stream.mjs +46 -0
- package/lib/runtime/platform-registry.mjs +21 -0
- package/lib/runtime/role-bridge-args.mjs +40 -0
- package/lib/runtime/role-bridge.mjs +1 -1
- package/lib/runtime/role-dispatch-policy.mjs +4 -2
- package/lib/runtime/role-routing.mjs +2 -1
- package/lib/runtime/role-supervisor.mjs +57 -13
- package/lib/tui/app.mjs +18 -11
- package/lib/tui/custom-preset.mjs +6 -4
- package/lib/tui/mode.mjs +26 -3
- package/lib/tui/render.mjs +19 -8
- package/lib/tui/setup.mjs +5 -5
- package/lib/tui/terminal.mjs +1 -1
- package/lib/watch/status-line.mjs +10 -2
- package/package.json +2 -1
- package/scripts/update-manifest.mjs +2 -2
- package/shared/skill/references/superpowers-provenance.json +1 -1
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/grok-stream.mjs +46 -0
- package/shared/skill/runtime/platform-registry.mjs +21 -0
- package/shared/skill/runtime/role-bridge-args.mjs +40 -0
- package/shared/skill/runtime/role-bridge.mjs +1 -1
- package/shared/skill/runtime/role-dispatch-policy.mjs +4 -2
- package/shared/skill/runtime/role-policy.json +34 -15
- package/shared/skill/runtime/role-routing.mjs +2 -1
- package/shared/skill/runtime/role-supervisor.mjs +57 -13
package/lib/tui/terminal.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import {renderScreen} from './render.mjs';
|
|
|
3
3
|
import {toAnsi256} from '../color/palette.mjs';
|
|
4
4
|
export {toAnsi256};
|
|
5
5
|
|
|
6
|
-
const BASIC={logo:'92',shadow:'32',sparkle:'92',tagline:'32',version:'32',rule:'32',title:'1;92',spinner:'32',selected:'42;30',selectedPad:'42',hint:'2',hintSep:'2',position:'2',ok:'32',muted:'2',error:'31',warn:'33'};
|
|
6
|
+
const BASIC={logo:'92',shadow:'32',sparkle:'92',tagline:'32',version:'32',rule:'32',title:'1;92',spinner:'32',selected:'42;30',selectedPad:'42',actionConfirm:'1;32',actionCancel:'2',actionDanger:'31',hint:'2',hintSep:'2',position:'2',ok:'32',muted:'2',error:'31',warn:'33'};
|
|
7
7
|
const rgb=color=>[0,1,2].map(index=>Math.max(0,Math.min(255,Math.round(Number(color[index])||0))));
|
|
8
8
|
export function formatLine(line,style,depth){
|
|
9
9
|
if(depth==='none'||!style?.runs?.length)return line;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {gradientAt,
|
|
2
|
+
import {gradientAt, toAnsi256} from '../color/palette.mjs';
|
|
3
3
|
import {displayWidth} from './render.mjs';
|
|
4
4
|
import {sanitizeText} from './policy.mjs';
|
|
5
5
|
|
|
6
6
|
const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
|
|
7
|
+
const PERIOD = 18, SWEEP = 13, R = 2.5;
|
|
8
|
+
|
|
9
|
+
function watchShimmerIntensity(index, tick) {
|
|
10
|
+
const f = tick % PERIOD;
|
|
11
|
+
if (f >= SWEEP) return 0;
|
|
12
|
+
const c = -R + f;
|
|
13
|
+
return Math.max(0, 1 - Math.abs(index - c) / R) ** 2;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
export function watchLocationLabel({mode, dir, session, home}) {
|
|
9
17
|
let label = dir;
|
|
@@ -18,7 +26,7 @@ export function shimmerText(text, tick) {
|
|
|
18
26
|
const characters = [...text];
|
|
19
27
|
return characters.map((character, i) => {
|
|
20
28
|
const base = gradientAt(i / Math.max(1, characters.length - 1));
|
|
21
|
-
const intensity =
|
|
29
|
+
const intensity = watchShimmerIntensity(i, tick);
|
|
22
30
|
const rgb = base.map(value => Math.round(value + (255 - value) * intensity));
|
|
23
31
|
return `\x1b[38;5;${toAnsi256(rgb)}m${character}`;
|
|
24
32
|
}).join('') + '\x1b[0m';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunhozz/arc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"claude/skill/",
|
|
49
49
|
"claude/agents/",
|
|
50
50
|
"gemini/",
|
|
51
|
+
"grok/",
|
|
51
52
|
"MANIFEST.sha256",
|
|
52
53
|
"install.command",
|
|
53
54
|
"!**/__pycache__/**",
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
const i = process.argv.indexOf('--root');
|
|
6
6
|
const root = i < 0 ? fileURLToPath(new URL('../', import.meta.url)) : path.resolve(process.argv[i + 1]);
|
|
7
|
-
const mutable = new Set(['codex/skill/models.toml', 'claude/skill/models.toml', 'gemini/skill/models.toml']);
|
|
7
|
+
const mutable = new Set(['codex/skill/models.toml', 'claude/skill/models.toml', 'gemini/skill/models.toml', 'grok/skill/models.toml']);
|
|
8
8
|
const excluded = new Set(['.DS_Store', '__pycache__', 'build']);
|
|
9
9
|
const files = new Map();
|
|
10
10
|
function visit(relative) {
|
|
@@ -17,7 +17,7 @@ function visit(relative) {
|
|
|
17
17
|
} else if (stat.isFile() && !mutable.has(relative)) files.set(relative,fs.readFileSync(filename));
|
|
18
18
|
else if (!stat.isFile()) throw new Error(`Protected payload is not regular: ${relative}`);
|
|
19
19
|
}
|
|
20
|
-
for (const entry of ['README.md', 'install.command', 'package.json', 'bin', 'lib', 'native/binding.c', 'native/binding.gyp', 'scripts', 'vendor', 'prebuilds', 'shared/skill', 'codex/skill', 'codex/agents', 'claude/skill', 'claude/agents', 'gemini']) visit(entry);
|
|
20
|
+
for (const entry of ['README.md', 'install.command', 'package.json', 'bin', 'lib', 'native/binding.c', 'native/binding.gyp', 'scripts', 'vendor', 'prebuilds', 'shared/skill', 'codex/skill', 'codex/agents', 'claude/skill', 'claude/agents', 'gemini', 'grok']) visit(entry);
|
|
21
21
|
const content = renderManifest(files);
|
|
22
22
|
const manifest = path.join(root, 'MANIFEST.sha256');
|
|
23
23
|
if (process.argv.includes('--check')) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"repository": "https://github.com/obra/superpowers",
|
|
4
4
|
"revision": "22f0b463e7a5e579904dd6211a520321035526f7",
|
|
5
|
-
"fetchedAt": "2026-11-
|
|
5
|
+
"fetchedAt": "2026-11-18T17:04:05.407Z",
|
|
6
6
|
"skills": [
|
|
7
7
|
"brainstorming",
|
|
8
8
|
"writing-plans",
|
|
@@ -8,7 +8,7 @@ export const COOPERATIVE_RUNTIME_MODULES=Object.freeze([
|
|
|
8
8
|
'cli.mjs','command.mjs','bootstrap.mjs','cooperative-schema.mjs','cooperative.mjs','evaluate.mjs',
|
|
9
9
|
'scope.mjs','store.mjs','git-evidence.mjs','assignment.mjs','verification.mjs','acceptance.mjs','external.mjs','schema.mjs','operations.mjs','gate.mjs','adapters/codex.mjs','adapters/claude.mjs','capabilities.mjs','identity.mjs','git-query.mjs','target-preparation.mjs',
|
|
10
10
|
'local-cli.mjs','role-routing-config.mjs','role-routing.mjs','role-bridge.mjs',
|
|
11
|
-
'role-dispatch-policy.mjs','role-dispatch-store.mjs','role-bridge-args.mjs','role-observe.mjs','role-supervisor.mjs','platform-registry.mjs','gemini-stream.mjs'
|
|
11
|
+
'role-dispatch-policy.mjs','role-dispatch-store.mjs','role-bridge-args.mjs','role-observe.mjs','role-supervisor.mjs','platform-registry.mjs','gemini-stream.mjs','grok-stream.mjs'
|
|
12
12
|
]);
|
|
13
13
|
export const cooperativeCoverage=()=>({enforcement:'cooperative',provenance:'operator-attested',nativeVerified:false});
|
|
14
14
|
export function commandResult({workflowId,state,input,decision='allow',ruleId='cooperative.recorded',persisted=false,...extra}){
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Unverified CLI contract: public documentation only; no live enforcement evidence.
|
|
2
|
+
// Sources: https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-shell/README.md
|
|
3
|
+
// https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/22-permissions-and-safety.md
|
|
4
|
+
// U-K5: the shell README and permissions guide document rule syntax:
|
|
5
|
+
// ToolPrefix(glob_pattern), bare prefix matches the whole tool type; blocking effect unverified.
|
|
6
|
+
// https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/14-headless-mode.md
|
|
7
|
+
// U-K6: the headless guide example {"type":"text","data":…}.
|
|
8
|
+
// U-K7: the same guide lists end_turn, max_tokens, max_turn_requests, refusal, cancelled.
|
|
9
|
+
export const GROK_CONTRACT = Object.freeze({
|
|
10
|
+
outputFormat: 'streaming-json',
|
|
11
|
+
isolationArgs: Object.freeze(['--no-auto-update', '--no-subagents']),
|
|
12
|
+
childEnv: Object.freeze({
|
|
13
|
+
GROK_DISABLE_AUTOUPDATER: '1',
|
|
14
|
+
GROK_CLAUDE_AGENTS_ENABLED: 'false',
|
|
15
|
+
GROK_CLAUDE_SKILLS_ENABLED: 'false',
|
|
16
|
+
GROK_CLAUDE_RULES_ENABLED: 'false',
|
|
17
|
+
GROK_CLAUDE_MCPS_ENABLED: 'false',
|
|
18
|
+
GROK_CLAUDE_HOOKS_ENABLED: 'false',
|
|
19
|
+
}),
|
|
20
|
+
eventKinds: Object.freeze({text: 'text', thought: 'thought', tool_call: 'tool_call', tool_call_update: 'tool_call_update', usage: 'usage', plan: 'plan', available_commands: 'available_commands', error: 'error', end: 'end'}),
|
|
21
|
+
successStopReasons: Object.freeze(['end_turn']),
|
|
22
|
+
resumeFlag: '--resume',
|
|
23
|
+
delegation: 'undetectable',
|
|
24
|
+
readOnlyDeny: Object.freeze(['Bash', 'Edit', 'Write', 'MCPTool']),
|
|
25
|
+
});
|
|
26
|
+
export function normalizeGrokStreamEvent(line) {
|
|
27
|
+
let raw = line;
|
|
28
|
+
if (typeof line === 'string') {try {raw = JSON.parse(line);} catch {return {kind: 'unknown', raw};}}
|
|
29
|
+
const kind = raw && Object.hasOwn(GROK_CONTRACT.eventKinds, raw.type) ? GROK_CONTRACT.eventKinds[raw.type] : 'unknown';
|
|
30
|
+
if (kind === 'unknown') return {kind, raw};
|
|
31
|
+
return {kind, raw, ...(typeof raw.model === 'string' ? {model: raw.model} : {}),
|
|
32
|
+
...(kind === 'end' ? {...(typeof raw.sessionId === 'string' ? {sessionId: raw.sessionId} : {}), ...(typeof raw.stopReason === 'string' ? {stopReason: raw.stopReason} : {})} : {}),
|
|
33
|
+
...(kind === 'text' && typeof raw.data === 'string' ? {text: raw.data} : {})};
|
|
34
|
+
}
|
|
35
|
+
export function evaluateGrokObservation({state, expected, sessionId}) {
|
|
36
|
+
const observedSession = state.grokSessionId, model = state.grokModel;
|
|
37
|
+
const identityOk = observedSession === sessionId && !state.grokSessionMismatch;
|
|
38
|
+
const modelMismatch = state.grokModelMismatch || Boolean(model && model !== expected.model);
|
|
39
|
+
return {reason: !identityOk ? 'execution_identity_unverified' : modelMismatch ? 'model_effort_mismatch' : null,
|
|
40
|
+
claims: {
|
|
41
|
+
identity: identityOk ? {level: 'runtime-observed', source: 'grok-stream-session', observed: observedSession} : {level: 'unverified', source: 'none'},
|
|
42
|
+
model: {level: model && !modelMismatch ? 'runtime-observed' : 'unverified', source: model ? 'grok-stream-model' : 'none', requested: expected.model, observed: model ?? null},
|
|
43
|
+
effort: {level: 'unverified', source: 'none', requested: 'default', observed: null},
|
|
44
|
+
permissions: {level: 'runtime-observed', source: 'worktree-snapshot', details: 'git-visible worktree only'},
|
|
45
|
+
}};
|
|
46
|
+
}
|
|
@@ -58,6 +58,9 @@ function resolveHome(platform, {userHome, env = {}, cwd} = {}) {
|
|
|
58
58
|
const expanded = expand(raw ?? path.join(userHome, '.codex'));
|
|
59
59
|
if (path.isAbsolute(expanded)) home = path.resolve(expanded);
|
|
60
60
|
else { const base = cwd ?? process.cwd(); if (typeof base !== 'string' || !path.isAbsolute(base)) throw Error('cwd must be absolute for relative CODEX_HOME'); home = path.resolve(base, expanded); }
|
|
61
|
+
} else if (platform === 'grok') {
|
|
62
|
+
if (env.GROK_HOME !== undefined) throw Error('GROK_HOME is not verified');
|
|
63
|
+
home = path.join(userHome, '.grok');
|
|
61
64
|
} else if (platform === 'gemini') {
|
|
62
65
|
if (env.GEMINI_CLI_HOME !== undefined) throw Error('GEMINI_CLI_HOME is not verified');
|
|
63
66
|
home = path.join(userHome, '.gemini');
|
|
@@ -121,6 +124,24 @@ export const DEFAULT_PLATFORM_REGISTRY = createPlatformRegistry([
|
|
|
121
124
|
authProbe: 'no official auth status command', watch: 'watch support out of scope',
|
|
122
125
|
}).map(([key, reason]) => [key, {state: 'off', reason}]))},
|
|
123
126
|
},
|
|
127
|
+
{
|
|
128
|
+
id: 'grok', label: 'Grok', displayOrder: 3, anchorOrder: 3,
|
|
129
|
+
home: {env: 'GROK_HOME', resolve: context => resolveHome('grok', context)},
|
|
130
|
+
cli: {command: 'grok', supportedVersions: '>=1.0.0 <1.1.0'},
|
|
131
|
+
auth: {kind: 'none'},
|
|
132
|
+
models: {effortField: 'effort'},
|
|
133
|
+
profile: {
|
|
134
|
+
ext: 'md',
|
|
135
|
+
standaloneName: role => `arc-${role.slice(4)}`,
|
|
136
|
+
routingName: role => `arc-routing-${role.slice(4)}`,
|
|
137
|
+
},
|
|
138
|
+
executionEnvironments: ['grok-cli'],
|
|
139
|
+
routing: {validatePair: (model, effort) => validText(model) && /^[A-Za-z0-9][A-Za-z0-9._:/@+\-]*$/.test(model) && effort === 'default'},
|
|
140
|
+
capabilities: {install: {state: 'verified'}, nativeProfile: {state: 'verified'}, catalog: {state: 'verified'}, standalone: {state: 'verified'}, bridge: {state: 'verified'}, compositeRole: {state: 'verified'}, ...Object.fromEntries(Object.entries({
|
|
141
|
+
compositeHost: 'composite host not verified', authProbe: 'no official auth status command',
|
|
142
|
+
watch: 'watch support out of scope',
|
|
143
|
+
}).map(([key, reason]) => [key, {state: 'off', reason}]))},
|
|
144
|
+
},
|
|
124
145
|
]);
|
|
125
146
|
|
|
126
147
|
export const RUNTIME_PLATFORMS = DEFAULT_PLATFORM_REGISTRY.platforms;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Pure helpers that turn an installed arc-routing profile into role-specific Claude/Codex CLI arguments. No processes are started here.
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import {GROK_CONTRACT} from './grok-stream.mjs';
|
|
4
5
|
import {GEMINI_CONTRACT} from './gemini-stream.mjs';
|
|
5
6
|
import {DEFAULT_POLICY, effectiveClaudeSandboxSettings} from './role-dispatch-policy.mjs';
|
|
6
7
|
|
|
@@ -15,6 +16,13 @@ export const ROLE_BRIDGE_PERMISSIONS = deepFreeze({
|
|
|
15
16
|
arc_scouter: {approvalMode: 'plan', sandbox: false}, arc_planner: {approvalMode: 'plan', sandbox: false},
|
|
16
17
|
arc_implementer: {approvalMode: 'auto_edit', sandbox: true}, arc_qa: {approvalMode: 'auto_edit', sandbox: true}, arc_reviewer: {approvalMode: 'plan', sandbox: false}
|
|
17
18
|
},
|
|
19
|
+
grok: {
|
|
20
|
+
arc_scouter: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
21
|
+
arc_planner: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
22
|
+
arc_reviewer: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
23
|
+
arc_implementer: {permissionMode: 'acceptEdits', sandbox: 'workspace', deny: []},
|
|
24
|
+
arc_qa: {permissionMode: 'acceptEdits', sandbox: 'workspace', deny: []},
|
|
25
|
+
},
|
|
18
26
|
codex: {
|
|
19
27
|
arc_scouter: {sandboxMode: 'read-only', search: true}, arc_planner: {sandboxMode: 'read-only', search: false},
|
|
20
28
|
arc_implementer: {sandboxMode: 'workspace-write', search: false}, arc_qa: {sandboxMode: 'workspace-write', search: false}, arc_reviewer: {sandboxMode: 'read-only', search: false}
|
|
@@ -25,6 +33,7 @@ const BRIDGE_IMPLEMENTATIONS = new Map([
|
|
|
25
33
|
['claude', {parse: parseClaude, buildArgs: buildClaudeArgs}],
|
|
26
34
|
['codex', {parse: parseCodex, buildArgs: buildCodexArgs}],
|
|
27
35
|
['gemini', {parse: parseGemini, buildArgs: buildGeminiArgs}],
|
|
36
|
+
['grok', {parse: parseGrok, buildArgs: buildGrokArgs}],
|
|
28
37
|
]);
|
|
29
38
|
export const BRIDGE_PLATFORM_IDS = Object.freeze([...BRIDGE_IMPLEMENTATIONS.keys()]);
|
|
30
39
|
|
|
@@ -79,6 +88,26 @@ function parseGemini(text) {
|
|
|
79
88
|
return {name: fields.name, description: fields.description, model: fields.model, effort: 'default', tools: null, instructions: match[2].replaceAll('\r\n', '\n')};
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
// ARC Grok metadata uses the same scalar grammar with an exact key set.
|
|
92
|
+
export function parseGrok(text) {
|
|
93
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]+)$/.exec(text);
|
|
94
|
+
if (!match || !match[2].trim()) bad('missing Grok frontmatter or instructions');
|
|
95
|
+
const fields = {};
|
|
96
|
+
const nonStringScalar = /^(?:~|null|true|false|yes|no|on|off|[-+]?(?:\.inf|\.nan|0[xob][0-9a-f_]+|(?:\d[\d_]*(?:\.[\d_]*)?|\.[\d_]+)(?:e[-+]?\d+)?)|\d{4}-\d{2}-\d{2}(?:[Tt ].*)?)$/i;
|
|
97
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
98
|
+
const entry = /^([a-z][a-zA-Z0-9_-]*): (.+)$/.exec(line);
|
|
99
|
+
if (!entry || Object.hasOwn(fields, entry[1])) bad('malformed or duplicate Grok field');
|
|
100
|
+
const value = entry[2];
|
|
101
|
+
if (value !== value.trim() || /[\p{Cc}\u2028\u2029{}#&*!|>"']/u.test(value)
|
|
102
|
+
|| /^(?:[-?:](?:\s|$)|[\[\],%@`])/.test(value) || value.includes(': ') || nonStringScalar.test(value)) bad('unsupported Grok scalar');
|
|
103
|
+
fields[entry[1]] = value;
|
|
104
|
+
}
|
|
105
|
+
for (const key of ['name', 'description', 'model']) if (!fields[key]) bad(`missing ${key}`);
|
|
106
|
+
if (Object.keys(fields).length !== 3) bad('Grok fields must be exactly name, description, model');
|
|
107
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:/@+\-]*$/.test(fields.model)) bad('invalid Grok model');
|
|
108
|
+
return {name: fields.name, description: fields.description, model: fields.model, effort: 'default', tools: null, instructions: match[2].replaceAll('\r\n', '\n')};
|
|
109
|
+
}
|
|
110
|
+
|
|
82
111
|
const ESCAPES = {b: '\b', t: '\t', n: '\n', f: '\f', r: '\r', '"': '"', '\\': '\\'};
|
|
83
112
|
// Decodes a TOML multiline basic string body; returns null when it is not terminated by """ on the same logical line.
|
|
84
113
|
function readMultiline(lines, index, rest) {
|
|
@@ -201,3 +230,14 @@ export function buildGeminiArgs({role, model, profile, sessionId, policyFile, pr
|
|
|
201
230
|
if (resume) args.push(GEMINI_CONTRACT.resumeFlag, sessionId);
|
|
202
231
|
return args;
|
|
203
232
|
}
|
|
233
|
+
|
|
234
|
+
export function buildGrokArgs({role, profile, sessionId, promptFile}) {
|
|
235
|
+
const permissions = permissionsFor('grok', role);
|
|
236
|
+
if (typeof promptFile !== 'string' || !path.isAbsolute(promptFile)) throw Error('Absolute promptFile required');
|
|
237
|
+
if (typeof sessionId !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(sessionId)) throw Error('Grok sessionId must be a UUID');
|
|
238
|
+
const model = requireText(profile?.model, 'model');
|
|
239
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:/@+\-]*$/.test(model)) throw Error('Invalid Grok model');
|
|
240
|
+
return ['--prompt-file', promptFile, '--output-format', GROK_CONTRACT.outputFormat, '-m', model, '--session-id', sessionId,
|
|
241
|
+
'--permission-mode', permissions.permissionMode, '--sandbox', permissions.sandbox,
|
|
242
|
+
...permissions.deny.flatMap(rule => ['--deny', rule]), ...GROK_CONTRACT.isolationArgs];
|
|
243
|
+
}
|
|
@@ -143,7 +143,7 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
143
143
|
const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
|
|
144
144
|
if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform||lease.route!=='bridge'||!['completed','failed'].includes(lease.state)){result=blank(context,dispatchId,'deny','invalid_request');return;}
|
|
145
145
|
const targetPlatform=leaseTargetPlatform(lease,runtimePlatforms);
|
|
146
|
-
if(targetPlatform==='gemini'&&!['on','verified'].includes(supervisorImplementations.get(targetPlatform)?.resume)){result=blank(context,dispatchId,'hold','resume_unverified');return;}
|
|
146
|
+
if((targetPlatform==='gemini'||targetPlatform==='grok')&&!['on','verified'].includes(supervisorImplementations.get(targetPlatform)?.resume)){result=blank(context,dispatchId,'hold','resume_unverified');return;}
|
|
147
147
|
if(!lease.sessionId){result=blank(context,dispatchId,'hold','execution_identity_unverified');return;}
|
|
148
148
|
let config;
|
|
149
149
|
try{config=await readActivation(homes,lease.revision,{anchorHome,host:context.hostPlatform,runtimePlatforms});}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
2
2
|
// Fixed policy values for composite role dispatch. G2 'escalation' means the bridge runs only with per-call user escalation approval on a Codex host; it is not a verified pass.
|
|
3
|
-
export const BRIDGE_GATE_RESULTS = Object.freeze({G1: 'fail', G2: 'escalation', G3: 'pass', G4: 'pass', G5: 'wide', G6: 'strict', G7: 'pass', G8: 'pass', GG1: 'fail', GG2: 'fail'});
|
|
3
|
+
export const BRIDGE_GATE_RESULTS = Object.freeze({G1: 'fail', G2: 'escalation', G3: 'pass', G4: 'pass', G5: 'wide', G6: 'strict', G7: 'pass', G8: 'pass', GG1: 'fail', GG2: 'fail', GK1: 'fail', GK2: 'fail'});
|
|
4
4
|
// No sandbox settings JSON has been recorded: G1 failed, so there is nothing to apply.
|
|
5
5
|
const RECORDED_CLAUDE_SANDBOX_SETTINGS = null;
|
|
6
6
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
@@ -41,7 +41,7 @@ export const DEFAULT_POLICY = Object.freeze({
|
|
|
41
41
|
|
|
42
42
|
export const RELEASE_CONDITIONS = Object.freeze({
|
|
43
43
|
activation_unverified: 'Verify the active configuration, all prepared markers, installed bytes, host limits and the shared lock, and inspect the lease records in <anchor home>/arc-role-dispatch for unreadable or corrupted files.',
|
|
44
|
-
resume_unverified: 'Update ARC after verifying
|
|
44
|
+
resume_unverified: 'Update ARC after verifying platform session resume against the recorded session UUID.',
|
|
45
45
|
capability_not_verified: 'Update ARC to a release that verifies this platform capability.',
|
|
46
46
|
'Not Available': 'Install the target platform CLI so that it is found on PATH.',
|
|
47
47
|
Unauthorized: 'Authenticate the target platform CLI.',
|
|
@@ -87,6 +87,8 @@ export function bridgeGateReasons({platform, role, hostPlatform, policy = DEFAUL
|
|
|
87
87
|
const gates = policy.gates ?? BRIDGE_GATE_RESULTS, codes = [];
|
|
88
88
|
if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_qa') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
|
|
89
89
|
if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
|
|
90
|
+
if (platform === 'grok' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GK1 !== 'pass') codes.push('permission_scope_unverified');
|
|
91
|
+
if (hostPlatform === 'grok' && gates.GK2 !== 'pass') codes.push('host_sandbox_blocked');
|
|
90
92
|
if (hostPlatform === 'gemini' && gates.GG2 !== 'pass') codes.push('host_sandbox_blocked');
|
|
91
93
|
if (platform === 'codex' && gates.G4 === 'fail') codes.push('permission_scope_unverified');
|
|
92
94
|
if (hostPlatform === 'codex' && gates.G2 === 'fail') codes.push('host_sandbox_blocked');
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"controls": {
|
|
52
52
|
"codex": "prompt",
|
|
53
53
|
"claude": "prompt",
|
|
54
|
-
"gemini": "prompt"
|
|
54
|
+
"gemini": "prompt",
|
|
55
|
+
"grok": "prompt"
|
|
55
56
|
}
|
|
56
57
|
},
|
|
57
58
|
{
|
|
@@ -84,7 +85,8 @@
|
|
|
84
85
|
"controls": {
|
|
85
86
|
"codex": "prompt",
|
|
86
87
|
"claude": "prompt",
|
|
87
|
-
"gemini": "prompt"
|
|
88
|
+
"gemini": "prompt",
|
|
89
|
+
"grok": "prompt"
|
|
88
90
|
}
|
|
89
91
|
},
|
|
90
92
|
{
|
|
@@ -110,7 +112,8 @@
|
|
|
110
112
|
"controls": {
|
|
111
113
|
"codex": "prompt",
|
|
112
114
|
"claude": "prompt",
|
|
113
|
-
"gemini": "prompt"
|
|
115
|
+
"gemini": "prompt",
|
|
116
|
+
"grok": "prompt"
|
|
114
117
|
}
|
|
115
118
|
},
|
|
116
119
|
{
|
|
@@ -139,7 +142,8 @@
|
|
|
139
142
|
"controls": {
|
|
140
143
|
"codex": "prompt",
|
|
141
144
|
"claude": "prompt",
|
|
142
|
-
"gemini": "prompt"
|
|
145
|
+
"gemini": "prompt",
|
|
146
|
+
"grok": "prompt"
|
|
143
147
|
}
|
|
144
148
|
},
|
|
145
149
|
{
|
|
@@ -160,7 +164,8 @@
|
|
|
160
164
|
"controls": {
|
|
161
165
|
"codex": "prompt",
|
|
162
166
|
"claude": "prompt",
|
|
163
|
-
"gemini": "prompt"
|
|
167
|
+
"gemini": "prompt",
|
|
168
|
+
"grok": "prompt"
|
|
164
169
|
}
|
|
165
170
|
},
|
|
166
171
|
{
|
|
@@ -181,7 +186,8 @@
|
|
|
181
186
|
"controls": {
|
|
182
187
|
"codex": "prompt",
|
|
183
188
|
"claude": "prompt",
|
|
184
|
-
"gemini": "prompt"
|
|
189
|
+
"gemini": "prompt",
|
|
190
|
+
"grok": "prompt"
|
|
185
191
|
}
|
|
186
192
|
},
|
|
187
193
|
{
|
|
@@ -202,7 +208,8 @@
|
|
|
202
208
|
"controls": {
|
|
203
209
|
"codex": "prompt",
|
|
204
210
|
"claude": "prompt",
|
|
205
|
-
"gemini": "prompt"
|
|
211
|
+
"gemini": "prompt",
|
|
212
|
+
"grok": "prompt"
|
|
206
213
|
}
|
|
207
214
|
},
|
|
208
215
|
{
|
|
@@ -224,7 +231,8 @@
|
|
|
224
231
|
"controls": {
|
|
225
232
|
"codex": "prompt",
|
|
226
233
|
"claude": "prompt",
|
|
227
|
-
"gemini": "prompt"
|
|
234
|
+
"gemini": "prompt",
|
|
235
|
+
"grok": "prompt"
|
|
228
236
|
}
|
|
229
237
|
},
|
|
230
238
|
{
|
|
@@ -247,7 +255,8 @@
|
|
|
247
255
|
"controls": {
|
|
248
256
|
"codex": "prompt",
|
|
249
257
|
"claude": "prompt",
|
|
250
|
-
"gemini": "prompt"
|
|
258
|
+
"gemini": "prompt",
|
|
259
|
+
"grok": "prompt"
|
|
251
260
|
}
|
|
252
261
|
},
|
|
253
262
|
{
|
|
@@ -268,7 +277,8 @@
|
|
|
268
277
|
"controls": {
|
|
269
278
|
"codex": "prompt",
|
|
270
279
|
"claude": "prompt",
|
|
271
|
-
"gemini": "prompt"
|
|
280
|
+
"gemini": "prompt",
|
|
281
|
+
"grok": "prompt"
|
|
272
282
|
}
|
|
273
283
|
},
|
|
274
284
|
{
|
|
@@ -294,7 +304,8 @@
|
|
|
294
304
|
"controls": {
|
|
295
305
|
"codex": "prompt",
|
|
296
306
|
"claude": "prompt",
|
|
297
|
-
"gemini": "prompt"
|
|
307
|
+
"gemini": "prompt",
|
|
308
|
+
"grok": "prompt"
|
|
298
309
|
}
|
|
299
310
|
},
|
|
300
311
|
{
|
|
@@ -320,7 +331,8 @@
|
|
|
320
331
|
"controls": {
|
|
321
332
|
"codex": "prompt",
|
|
322
333
|
"claude": "prompt",
|
|
323
|
-
"gemini": "prompt"
|
|
334
|
+
"gemini": "prompt",
|
|
335
|
+
"grok": "prompt"
|
|
324
336
|
}
|
|
325
337
|
},
|
|
326
338
|
{
|
|
@@ -345,7 +357,8 @@
|
|
|
345
357
|
"controls": {
|
|
346
358
|
"codex": "prompt",
|
|
347
359
|
"claude": "prompt",
|
|
348
|
-
"gemini": "prompt"
|
|
360
|
+
"gemini": "prompt",
|
|
361
|
+
"grok": "prompt"
|
|
349
362
|
}
|
|
350
363
|
},
|
|
351
364
|
{
|
|
@@ -369,7 +382,8 @@
|
|
|
369
382
|
"controls": {
|
|
370
383
|
"codex": "prompt",
|
|
371
384
|
"claude": "prompt",
|
|
372
|
-
"gemini": "prompt"
|
|
385
|
+
"gemini": "prompt",
|
|
386
|
+
"grok": "prompt"
|
|
373
387
|
}
|
|
374
388
|
},
|
|
375
389
|
{
|
|
@@ -392,7 +406,8 @@
|
|
|
392
406
|
"controls": {
|
|
393
407
|
"codex": "prompt",
|
|
394
408
|
"claude": "prompt",
|
|
395
|
-
"gemini": "prompt"
|
|
409
|
+
"gemini": "prompt",
|
|
410
|
+
"grok": "prompt"
|
|
396
411
|
}
|
|
397
412
|
}
|
|
398
413
|
],
|
|
@@ -408,6 +423,10 @@
|
|
|
408
423
|
"gemini": {
|
|
409
424
|
"level": "prompt",
|
|
410
425
|
"notice": "Role restrictions are prompt-level contracts, not a filesystem sandbox. Native tool restriction fields, observer hooks and Git guards are unverified. Use only available authorized tools; ARC does not write Gemini settings.json."
|
|
426
|
+
},
|
|
427
|
+
"grok": {
|
|
428
|
+
"level": "prompt",
|
|
429
|
+
"notice": "Role restrictions are prompt-level contracts, not a filesystem sandbox. Grok sandboxing, native tool restriction fields, observer hooks and Git guards are unverified, and Grok may continue without its sandbox. Use only available authorized tools; ARC disables Grok Claude compatibility (agents, skills, rules in config.toml; also MCPs and hooks for bridge children), but whether Grok sessions honor these settings is unverified."
|
|
411
430
|
}
|
|
412
431
|
},
|
|
413
432
|
"review": {
|
|
@@ -231,6 +231,7 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
231
231
|
const leases=await listLeases(anchorHome,{runtimePlatforms});
|
|
232
232
|
const live=leases.filter(lease=>NON_TERMINAL_STATES.includes(lease.state));
|
|
233
233
|
if(leases.some(lease=>lease.requestId===assignment.requestId)||live.some(lease=>lease.workflowId===context.workflowId&&lease.taskId===assignment.taskId&&lease.role===role)){duplicate=true;codes.add('duplicate_dispatch');}
|
|
234
|
+
if(host==='grok'&&(policy.gates?.GK2??DEFAULT_POLICY.gates.GK2)!=='pass')codes.add('host_sandbox_blocked');
|
|
234
235
|
if(host==='gemini'&&(policy.gates?.GG2??DEFAULT_POLICY.gates.GG2)!=='pass')codes.add('host_sandbox_blocked');
|
|
235
236
|
if(route==='bridge'){
|
|
236
237
|
let limits;try{limits=readHostLimits(resolveConfigHome(host,context));}catch{codes.add('activation_unverified');}
|
|
@@ -243,7 +244,7 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
243
244
|
result.reasons=[...codes].map(reason);
|
|
244
245
|
if(codes.size){result.decision=duplicate?'deny':'hold';return;}
|
|
245
246
|
const claims=initialClaims(route,policy,requested),iso=new Date(now).toISOString(),dispatchId=crypto.randomUUID();
|
|
246
|
-
const lease=await createLease(anchorHome,{version:2,targetPlatform:route==='native'?host:requested.platform,dispatchId,workflowId:context.workflowId,taskId:assignment.taskId,requestId:assignment.requestId,role,route,hostPlatform:host,executionEnvironment:environment,revision:config.revision,profileHash:await readProfileHash(homes[requested.platform],role),argsDigest:null,state:'reserved',supervisor:null,child:null,sessionId:route==='bridge'&&requested.platform==='gemini'?crypto.randomUUID():null,timeoutMinutes:policy.roleTimeoutMinutes[role],claims,reasons:[],allowedPaths:assignment.allowedPaths??[],resultPath:null,segment:0,nativeAgentId:null,createdAt:iso,updatedAt:iso},{runtimePlatforms,config});
|
|
247
|
+
const lease=await createLease(anchorHome,{version:2,targetPlatform:route==='native'?host:requested.platform,dispatchId,workflowId:context.workflowId,taskId:assignment.taskId,requestId:assignment.requestId,role,route,hostPlatform:host,executionEnvironment:environment,revision:config.revision,profileHash:await readProfileHash(homes[requested.platform],role),argsDigest:null,state:'reserved',supervisor:null,child:null,sessionId:route==='bridge'&&(requested.platform==='gemini'||requested.platform==='grok')?crypto.randomUUID():null,timeoutMinutes:policy.roleTimeoutMinutes[role],claims,reasons:[],allowedPaths:assignment.allowedPaths??[],resultPath:null,segment:0,nativeAgentId:null,createdAt:iso,updatedAt:iso},{runtimePlatforms,config});
|
|
247
248
|
Object.assign(result,{decision:'allow',routeStatus:'reserved',dispatchId:lease.dispatchId,claims});
|
|
248
249
|
},{retryMs:policy.lockRetryMs});
|
|
249
250
|
}catch(error){
|
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import crypto from 'node:crypto';
|
|
7
7
|
import {spawn, spawnSync} from 'node:child_process';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {GROK_CONTRACT, normalizeGrokStreamEvent, evaluateGrokObservation} from './grok-stream.mjs';
|
|
9
10
|
import {GEMINI_CONTRACT, normalizeGeminiStreamEvent, evaluateGeminiObservation} from './gemini-stream.mjs';
|
|
10
11
|
import {DEFAULT_POLICY, reason, bridgeGateReasons} from './role-dispatch-policy.mjs';
|
|
11
12
|
import {readLease, writeLease, writeHeartbeat, cancelRequested, TERMINAL_STATES} from './role-dispatch-store.mjs';
|
|
@@ -49,6 +50,19 @@ export const SUPERVISOR_IMPLEMENTATIONS = new Map([
|
|
|
49
50
|
},
|
|
50
51
|
session: state => state.geminiSessionId ?? state.init?.sessionId,
|
|
51
52
|
}],
|
|
53
|
+
['grok', {
|
|
54
|
+
resume: 'off',
|
|
55
|
+
normalize: normalizeGrokStreamEvent,
|
|
56
|
+
async observe({state, invocation, terminalClaim, lease}) {
|
|
57
|
+
const evaluation = evaluateGrokObservation({state, expected: invocation.expected, sessionId: lease.sessionId});
|
|
58
|
+
return {...evaluation, claims: {...evaluation.claims, terminal: terminalClaim}, effortMismatch: false, sessionId: lease.sessionId};
|
|
59
|
+
},
|
|
60
|
+
async resultPath(state, resultFile) {
|
|
61
|
+
if (!state.terminal || state.terminalError || typeof state.resultText !== 'string' || !state.resultText.trim()) return null;
|
|
62
|
+
await fsp.writeFile(resultFile, state.resultText, {mode: 0o600}); return resultFile;
|
|
63
|
+
},
|
|
64
|
+
session: state => state.grokSessionId,
|
|
65
|
+
}],
|
|
52
66
|
['codex', {
|
|
53
67
|
normalize: normalizeCodexStreamEvent,
|
|
54
68
|
async observe({state, invocation, readContext, policy, terminalClaim, lease}) {
|
|
@@ -89,17 +103,19 @@ export const segmentDirectory = (target, workflowId, dispatchId, segment) => seg
|
|
|
89
103
|
// U-P1: reserved path only; policy contents and installation await live format verification.
|
|
90
104
|
export const geminiPolicyFile = (homes, role) => path.join(homes.gemini ?? '', 'skills', 'arc', 'policies', `${role}.toml`);
|
|
91
105
|
|
|
106
|
+
export const grokPromptFile = resultPath => path.join(path.dirname(resultPath), 'prompt.md');
|
|
107
|
+
|
|
92
108
|
/** Builds the child CLI arguments from the hash-verified target profile. Errors carry reasonCode. */
|
|
93
109
|
export async function buildBridgeInvocation({lease, config, homes, worktree, resultPath, policy = DEFAULT_POLICY, supervisorImplementations = SUPERVISOR_IMPLEMENTATIONS}) {
|
|
94
110
|
const fail = (reasonCode, message) => Object.assign(Error(message), {reasonCode});
|
|
95
111
|
const requested = config.roles[lease.role], platform = lease.version === 2 ? lease.targetPlatform : requested.platform;
|
|
96
112
|
if (platform !== requested.platform) throw fail('activation_unverified', 'Lease target differs from the active role target');
|
|
97
113
|
const implementation = supervisorImplementations.get(platform);
|
|
98
|
-
if (platform === 'gemini' || lease.hostPlatform === 'gemini') {
|
|
114
|
+
if (platform === 'gemini' || platform === 'grok' || lease.hostPlatform === 'gemini' || lease.hostPlatform === 'grok') {
|
|
99
115
|
const gates = bridgeGateReasons({platform, role: lease.role, hostPlatform: lease.hostPlatform, policy});
|
|
100
|
-
if (gates.length) throw fail(gates[0], 'Gemini bridge gates are not verified');
|
|
116
|
+
if (gates.length) throw fail(gates[0], platform === 'grok' || lease.hostPlatform === 'grok' ? 'Grok bridge gates are not verified' : 'Gemini bridge gates are not verified');
|
|
101
117
|
}
|
|
102
|
-
if (platform === 'gemini' && lease.segment > 0 && !['on', 'verified'].includes(implementation?.resume)) throw fail('resume_unverified', 'Gemini resume is not verified');
|
|
118
|
+
if ((platform === 'gemini' || platform === 'grok') && lease.segment > 0 && !['on', 'verified'].includes(implementation?.resume)) throw fail('resume_unverified', platform === 'grok' ? 'Grok resume is not verified' : 'Gemini resume is not verified');
|
|
103
119
|
if (!implementation) throw fail('permission_scope_unverified', 'Invalid composite profile: unknown platform');
|
|
104
120
|
const file = path.join(homes[platform], 'agents', routingProfileFile(getPlatform(platform), lease.role));
|
|
105
121
|
let bytes;
|
|
@@ -108,14 +124,14 @@ export async function buildBridgeInvocation({lease, config, homes, worktree, res
|
|
|
108
124
|
let profile, args;
|
|
109
125
|
try {
|
|
110
126
|
profile = parseCompositeProfile(platform, bytes);
|
|
111
|
-
args = buildBridgeArgs(platform, {role: lease.role, profile, sessionId: lease.sessionId, worktree, resultPath, threadId: lease.sessionId, policy, policyFile: geminiPolicyFile(homes, lease.role), resume: lease.segment > 0});
|
|
127
|
+
args = buildBridgeArgs(platform, {role: lease.role, profile, sessionId: lease.sessionId, worktree, resultPath, threadId: lease.sessionId, policy, policyFile: geminiPolicyFile(homes, lease.role), ...(platform === 'grok' ? {promptFile: grokPromptFile(resultPath)} : {}), resume: lease.segment > 0});
|
|
112
128
|
} catch { throw fail('permission_scope_unverified', 'Profile arguments unavailable'); }
|
|
113
129
|
const permissions = ROLE_BRIDGE_PERMISSIONS[platform][lease.role];
|
|
114
130
|
const expected = platform === 'claude'
|
|
115
131
|
? {model: requested.model, effort: requested.effort, tools: profile.tools, permissionMode: permissions.permissionMode}
|
|
116
|
-
: platform === 'gemini' ? {model: requested.model, effort: 'default'}
|
|
132
|
+
: platform === 'gemini' || platform === 'grok' ? {model: requested.model, effort: 'default'}
|
|
117
133
|
: {model: requested.model, effort: requested.effort, sandboxMode: permissions.sandboxMode, approvalPolicy: 'never'};
|
|
118
|
-
return {platform, args, argsDigest: argsDigest(args), expected, requested, ...(platform === 'gemini' ? {stdinInstructions: profile.instructions} : {})};
|
|
134
|
+
return {platform, args, argsDigest: argsDigest(args), expected, requested, ...(platform === 'gemini' ? {stdinInstructions: profile.instructions} : {}), ...(platform === 'grok' ? {promptFile: {path: grokPromptFile(resultPath), instructions: profile.instructions}, childEnv: GROK_CONTRACT.childEnv} : {})};
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
/** Starts this module as a detached supervisor process (own session, stdio ignored, unref'd). env defaults to the inherited environment. */
|
|
@@ -216,16 +232,26 @@ export async function runSupervisor(options) {
|
|
|
216
232
|
let before;
|
|
217
233
|
try { before = await snapshotWorktree(target.realpath); } catch { return await earlyFailure('execution_failed'); }
|
|
218
234
|
|
|
235
|
+
if (invocation.promptFile) {
|
|
236
|
+
let promptFd;
|
|
237
|
+
try {
|
|
238
|
+
promptFd = fs.openSync(invocation.promptFile.path, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL, 0o600);
|
|
239
|
+
fs.writeFileSync(promptFd, `${invocation.promptFile.instructions}\n\n${brief}`);
|
|
240
|
+
fs.fchmodSync(promptFd, 0o600);
|
|
241
|
+
} catch { return await earlyFailure('execution_failed'); }
|
|
242
|
+
finally { if (promptFd !== undefined) fs.closeSync(promptFd); }
|
|
243
|
+
}
|
|
219
244
|
eventsFd = fs.openSync(path.join(artifactDir, 'events.jsonl'), 'a', 0o600);
|
|
220
|
-
// The child is a process-group leader so one signal reaches its descendants.
|
|
221
|
-
child = spawn(cli.executable, invocation.args, {cwd: target.realpath, env: {...localCliEnvironment(cli), ARC_BRIDGE_CHILD: dispatchId}, detached: true, stdio: ['pipe', 'pipe', 'pipe'], shell: false});
|
|
245
|
+
// The child is a process-group leader so one signal reaches its descendants. The prompt uses the platform-specific input channel.
|
|
246
|
+
child = spawn(cli.executable, invocation.args, {cwd: target.realpath, env: {...localCliEnvironment(cli), ...invocation.childEnv, ARC_BRIDGE_CHILD: dispatchId}, detached: true, stdio: ['pipe', 'pipe', 'pipe'], shell: false});
|
|
222
247
|
let exitResolve, exited = false;
|
|
223
248
|
const exitPromise = new Promise(resolve => { exitResolve = resolve; });
|
|
224
249
|
child.on('exit', (code, signal) => { exited = true; exitResolve({code, signal}); });
|
|
225
250
|
child.on('error', () => { exited = true; exitResolve({code: null, signal: null, spawnError: true}); });
|
|
226
251
|
child.stdin.on('error', () => {});
|
|
227
252
|
if (options.afterSpawn) await options.afterSpawn(child); // test injection point for post-spawn failures
|
|
228
|
-
child.stdin.end(
|
|
253
|
+
if (platform === 'grok') child.stdin.end();
|
|
254
|
+
else child.stdin.end(invocation.stdinInstructions === undefined ? brief : `${invocation.stdinInstructions}\n\n${brief}`);
|
|
229
255
|
const stdoutClosed = new Promise(resolve => { child.stdout.on('close', resolve); child.stdout.on('error', resolve); });
|
|
230
256
|
|
|
231
257
|
const state = {init: null, initEval: null, threadId: null, codexEval: null, terminal: false, terminalError: false, resultText: undefined, messages: [], mismatch: null, internal: null};
|
|
@@ -273,6 +299,23 @@ export async function runSupervisor(options) {
|
|
|
273
299
|
const normalized = implementation.normalize(raw);
|
|
274
300
|
if (!normalized) return;
|
|
275
301
|
writeEvent(normalized);
|
|
302
|
+
if (platform === 'grok') {
|
|
303
|
+
if (normalized.kind !== 'unknown' && normalized.model !== undefined) {
|
|
304
|
+
if (normalized.model !== invocation.expected.model) state.grokModelMismatch = true;
|
|
305
|
+
state.grokModel = normalized.model;
|
|
306
|
+
}
|
|
307
|
+
if (normalized.kind === 'text' && typeof normalized.text === 'string') state.resultText = (state.resultText ?? '') + normalized.text;
|
|
308
|
+
if (normalized.kind === 'error') state.terminalError = true;
|
|
309
|
+
if (normalized.kind === 'end') {
|
|
310
|
+
state.terminal = true;
|
|
311
|
+
state.terminalError ||= !GROK_CONTRACT.successStopReasons.includes(normalized.stopReason);
|
|
312
|
+
if (normalized.sessionId !== undefined) {
|
|
313
|
+
if (normalized.sessionId !== lease.sessionId) state.grokSessionMismatch = true;
|
|
314
|
+
state.grokSessionId = normalized.sessionId;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
276
319
|
if (platform === 'gemini') {
|
|
277
320
|
if (normalized.kind !== 'unknown') {
|
|
278
321
|
if (normalized.sessionId) {
|
|
@@ -357,16 +400,17 @@ export async function runSupervisor(options) {
|
|
|
357
400
|
const observation = await implementation.observe({state, invocation, homes, requested, terminalClaim, lease, readContext, policy});
|
|
358
401
|
let {claims, sessionId} = observation;
|
|
359
402
|
const {effortMismatch} = observation;
|
|
360
|
-
const cancelledBeforeIdentity = platform === 'gemini' && terminating === 'cancel' && !implementation.session(state);
|
|
403
|
+
const cancelledBeforeIdentity = (platform === 'gemini' || platform === 'grok') && terminating === 'cancel' && !implementation.session(state);
|
|
361
404
|
if (observation.reason && !(cancelledBeforeIdentity && observation.reason === 'execution_identity_unverified') && !codes.includes(observation.reason)) codes.push(observation.reason);
|
|
362
405
|
if (platform === 'gemini' && terminating !== 'cancel' && (exit.code !== 0 || exit.signal || state.terminalError)) codes.push('execution_failed');
|
|
406
|
+
if (platform === 'grok' && terminating !== 'cancel' && (exit.code !== 0 || exit.signal || state.terminalError || !state.terminal)) codes.push('execution_failed');
|
|
363
407
|
if (effortMismatch) codes.push('model_effort_mismatch');
|
|
364
408
|
if (violations.reason) codes.push(violations.reason);
|
|
365
409
|
if (after === null) claims.permissions = {level: 'unverified', source: 'worktree-snapshot', details: 'post-run snapshot unavailable'};
|
|
366
410
|
else if (violations.reason) claims.permissions = {...claims.permissions, level: 'unverified', details: 'permission violation observed'};
|
|
367
411
|
if (terminating === 'timeout') codes.push('timeout');
|
|
368
412
|
|
|
369
|
-
const resultPath = await implementation.resultPath(state, resultFile);
|
|
413
|
+
const resultPath = platform === 'grok' && (exit.code !== 0 || exit.signal) ? null : await implementation.resultPath(state, resultFile);
|
|
370
414
|
if (resultPath) await fsp.chmod(resultPath, 0o600);
|
|
371
415
|
|
|
372
416
|
let finalState = 'failed';
|
|
@@ -383,14 +427,14 @@ export async function runSupervisor(options) {
|
|
|
383
427
|
claims.identity = {level: 'unverified', source: 'none'};
|
|
384
428
|
}
|
|
385
429
|
}
|
|
386
|
-
if (platform === 'gemini' && codes.includes('execution_identity_unverified') && terminating !== 'cancel') finalState = 'unknown';
|
|
430
|
+
if ((platform === 'gemini' || platform === 'grok') && codes.includes('execution_identity_unverified') && terminating !== 'cancel') finalState = 'unknown';
|
|
387
431
|
if (lease.sessionId && observedSession && observedSession !== lease.sessionId && finalState !== 'cancelled') {
|
|
388
432
|
// A resumed segment must continue the recorded session; a different observed id leaves the slot occupied.
|
|
389
433
|
finalState = 'unknown'; sessionId = lease.sessionId; if (!codes.includes('execution_identity_unverified')) codes.push('execution_identity_unverified');
|
|
390
434
|
claims.identity = {level: 'unverified', source: 'none'};
|
|
391
435
|
}
|
|
392
436
|
if (exit.spawnError && !codes.length) { codes.push('execution_failed'); finalState = 'failed'; }
|
|
393
|
-
await writeRecord({state: finalState, reasons: [...new Set(codes)], exit: {code: exit.code, signal: exit.signal}, terminatedBy: terminating, eventsTruncated, ignoredLines: parser.ignored, lineOverflow: parser.overflow, violations: {changedPaths: violations.changedPaths, headChanged: violations.headChanged, refsChanged: violations.refsChanged}, ...(orphanGroupReaped ? {orphanGroupReaped: true} : {}), argsDigest: invocation.argsDigest, resultPath, ...(platform === 'gemini' ? {unverifiedContracts: {delegation: GEMINI_CONTRACT.delegation}} : {})});
|
|
437
|
+
await writeRecord({state: finalState, reasons: [...new Set(codes)], exit: {code: exit.code, signal: exit.signal}, terminatedBy: terminating, eventsTruncated, ignoredLines: parser.ignored, lineOverflow: parser.overflow, violations: {changedPaths: violations.changedPaths, headChanged: violations.headChanged, refsChanged: violations.refsChanged}, ...(orphanGroupReaped ? {orphanGroupReaped: true} : {}), argsDigest: invocation.argsDigest, resultPath, ...(platform === 'gemini' ? {unverifiedContracts: {delegation: GEMINI_CONTRACT.delegation}} : platform === 'grok' ? {unverifiedContracts: {delegation: GROK_CONTRACT.delegation}} : {})});
|
|
394
438
|
await commit(finalState, codes, claims, {sessionId, resultPath});
|
|
395
439
|
} catch {
|
|
396
440
|
// Unexpected failure after the child started: stop it, then record a failed state if the child is gone.
|