@yunhozz/arc 0.4.2 → 0.4.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.
Files changed (93) hide show
  1. package/MANIFEST.sha256 +91 -67
  2. package/README.md +7 -6
  3. package/claude/agents/arc-implementer.md +1 -0
  4. package/claude/agents/arc-planner.md +1 -0
  5. package/claude/agents/arc-qa.md +1 -0
  6. package/claude/agents/arc-reviewer.md +1 -0
  7. package/claude/agents/arc-scouter.md +1 -0
  8. package/claude/skill/SKILL.md +6 -3
  9. package/claude/skill/references/coordination.md +1 -1
  10. package/claude/skill/references/planning.md +36 -0
  11. package/codex/agents/arc-implementer.toml +1 -0
  12. package/codex/agents/arc-planner.toml +1 -0
  13. package/codex/agents/arc-qa.toml +1 -0
  14. package/codex/agents/arc-reviewer.toml +1 -0
  15. package/codex/agents/arc-scouter.toml +1 -0
  16. package/codex/skill/SKILL.md +6 -3
  17. package/codex/skill/references/coordination.md +1 -1
  18. package/codex/skill/references/planning.md +36 -0
  19. package/gemini/agents/arc-implementer.md +1 -0
  20. package/gemini/agents/arc-planner.md +1 -0
  21. package/gemini/agents/arc-qa.md +1 -0
  22. package/gemini/agents/arc-reviewer.md +1 -0
  23. package/gemini/agents/arc-scouter.md +1 -0
  24. package/gemini/skill/SKILL.md +6 -3
  25. package/gemini/skill/references/coordination.md +1 -1
  26. package/gemini/skill/references/planning.md +36 -0
  27. package/grok/AGENTS.md +8 -0
  28. package/grok/agents/arc-implementer.md +38 -0
  29. package/grok/agents/arc-planner.md +48 -0
  30. package/grok/agents/arc-qa.md +38 -0
  31. package/grok/agents/arc-reviewer.md +40 -0
  32. package/grok/agents/arc-scouter.md +39 -0
  33. package/grok/instructions.md +4 -0
  34. package/grok/skill/SKILL.md +81 -0
  35. package/grok/skill/models.toml +23 -0
  36. package/grok/skill/references/arc-visual-companion.md +28 -0
  37. package/grok/skill/references/commit.md +55 -0
  38. package/grok/skill/references/coordination.md +149 -0
  39. package/grok/skill/references/git-recovery.md +34 -0
  40. package/grok/skill/references/handoff-prep.md +110 -0
  41. package/grok/skill/references/handoff.md +227 -0
  42. package/grok/skill/references/limits.md +31 -0
  43. package/grok/skill/references/planning.md +204 -0
  44. package/grok/skill/references/verification.md +155 -0
  45. package/grok/skill/references/worktree-creation.md +8 -0
  46. package/lib/installer/global-config.mjs +8 -3
  47. package/lib/installer/grok-compat.mjs +107 -0
  48. package/lib/installer/language.mjs +54 -6
  49. package/lib/installer/plan.mjs +20 -14
  50. package/lib/installer/runtime-assets.mjs +1 -0
  51. package/lib/installer/uninstall.mjs +14 -1
  52. package/lib/installer/upgrade-state.mjs +13 -4
  53. package/lib/installer/upgrade.mjs +8 -3
  54. package/lib/management/operations.mjs +8 -5
  55. package/lib/management/status.mjs +26 -5
  56. package/lib/management/update.mjs +4 -4
  57. package/lib/models/codex-models.json +72 -0
  58. package/lib/models/grok-models.json +7 -0
  59. package/lib/platforms/formats/grok-markdown.mjs +49 -0
  60. package/lib/platforms/grok.mjs +14 -0
  61. package/lib/platforms/index.mjs +2 -1
  62. package/lib/policy/placement.mjs +2 -2
  63. package/lib/policy/render.mjs +1 -1
  64. package/lib/policy/role-policy.json +60 -15
  65. package/lib/prompts/agent-fragments.json +71 -1
  66. package/lib/prompts/render.mjs +7 -2
  67. package/lib/runtime/bootstrap.mjs +1 -1
  68. package/lib/runtime/grok-stream.mjs +46 -0
  69. package/lib/runtime/platform-registry.mjs +21 -0
  70. package/lib/runtime/role-bridge-args.mjs +40 -0
  71. package/lib/runtime/role-bridge.mjs +1 -1
  72. package/lib/runtime/role-dispatch-policy.mjs +4 -2
  73. package/lib/runtime/role-routing.mjs +2 -1
  74. package/lib/runtime/role-supervisor.mjs +57 -13
  75. package/lib/tui/app.mjs +18 -11
  76. package/lib/tui/custom-preset.mjs +6 -4
  77. package/lib/tui/mode.mjs +40 -5
  78. package/lib/tui/render.mjs +19 -8
  79. package/lib/tui/setup.mjs +53 -36
  80. package/lib/tui/terminal.mjs +1 -1
  81. package/lib/watch/status-line.mjs +10 -2
  82. package/package.json +2 -1
  83. package/scripts/update-manifest.mjs +2 -2
  84. package/shared/skill/references/superpowers-provenance.json +1 -1
  85. package/shared/skill/runtime/bootstrap.mjs +1 -1
  86. package/shared/skill/runtime/grok-stream.mjs +46 -0
  87. package/shared/skill/runtime/platform-registry.mjs +21 -0
  88. package/shared/skill/runtime/role-bridge-args.mjs +40 -0
  89. package/shared/skill/runtime/role-bridge.mjs +1 -1
  90. package/shared/skill/runtime/role-dispatch-policy.mjs +4 -2
  91. package/shared/skill/runtime/role-policy.json +60 -15
  92. package/shared/skill/runtime/role-routing.mjs +2 -1
  93. package/shared/skill/runtime/role-supervisor.mjs +57 -13
@@ -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. brief goes to stdin only.
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(invocation.stdinInstructions === undefined ? brief : `${invocation.stdinInstructions}\n\n${brief}`);
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.