Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(grok): Grok Build workflows, usage, rewind — supersedes #6383 #7070

Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 28 commits intomain fromrefs/pull/7070/headopened View on GitHub

Supersedes #6383.

#6383 wired effort, login, rewind, and a thin token parse. Grok Build was already streaming workflows, subagents, PromptUsage, compact, hooks, and queue over ACP. T3 dropped those notifications, so a Rhai workflow still looked like one chat turn.

This PR rebases the useful #6383 commits onto current main and maps the live Grok wire onto surfaces T3 already has. No Rhai host. No third Agents UI.

Rule

Complexity stays at the adapter. Claude workflow members use parentAgentId + timelineBypass. Codex collab children do the same. Grok uses that shape. Child tokens stay on typedUsage. They never replace the thread context window.

What you get

In T3On the wire
Model + Reasoning in the composerLive ACP menu. session/set_model _meta.reasoningEffort. No new thread. Product slug grok-build is an alias for the current model — T3 does not send it.
Plan / Defaultsession/set_mode onto advertised plan/architect vs code/agent. ACP plan entries already fill the turn plan list.
Composer /workflow pause|resume|stop and named scriptsLists ~/.grok/workflows and <project>/.grok/workflows. Picking one sends that slash text as a prompt. The Grok CLI runs it. Project scripts override user scripts.
Agents panel for a workflow runx.ai/session_notification / _x.ai/session/update workflow_updated → local_workflow + child subagent rows.
Agents panel for agent()subagent_spawned / progress / finished → the same child-task path.
Context meter + Usage pagePromptUsage (totals, cached_read_tokens, incomplete flag). Usage page scans ~/.grok/sessions/**/updates.jsonl. Contract v5 adds grok.
DollarsComplete costUsdTicks only (1e10 = $1). Incomplete bills stay token-only. Never $0.
Undo N turns_x.ai/rewind. Target from remaining history so a cancelled in-flight prompt cannot ghost. Local turns trim only after execute succeeds.
Compact / hooks / queue / recap / background shellsExisting events: context meter + compacted, hook.*, session queue length, thread metadata, local_bash.

Login: grok login or XAI_API_KEY. Probe reports unauthenticated vs missing CLI.

From #6383

Theo's three commits (effort menu, set_model effort, rewind, auth probe, in-thread model change) are cherry-picked. Author stays Theo. This branch is the one to review.

Not this PR

Plugins and marketplace updates are accepted and ignored. T3 has no plugin surface. Grok TUI /usage is still the CLI's own screen; T3's Usage page is the transcript scan.

Tests

Adapter, workflow mapper, extras, slash-command discovery, usage transcripts, usage chart. CI Check failed on exactOptionalPropertyTypes (T \| undefined into optional bags). CI Test failed because the usage chart now emits a zero Grok band. Both fixed.

Made with Grok 4.6.


Note

High Risk Touches the Grok adapter’s session/turn lifecycle, rewind, permissions, and usage contract v5 (older clients miss Grok usage). Permission fallback to allow_once can change auto-approval when Grok omits allow_always.

Overview Grok Build now uses the same composer, Agents, usage, and undo surfaces as Claude/Codex instead of dropping ACP extras as a single chat turn.

The adapter maps live x.ai session notifications onto existing events: workflows and agent() as local_workflow/subagent tasks (parentAgentId + timelineBypass), plus compact, hooks, queue, recap, and background shells. Reasoning effort and plan/code modes go through session/set_model _meta and session/set_mode; grok-build aliases the live model so in-thread switches work. Undo uses _x.ai/rewind after cancelling in-flight prompts. Workflow .rhai scripts from home/project .grok/workflows become slash commands.

Usage contract v5 adds grok: prompt usage and complete costUsdTicks on the thread, plus scanning ~/.grok/sessions/**/updates.jsonl for the Usage page. Tool-call ticks are rate-limited and truncated. Permission acceptForSession falls back to allow_once when Grok omits allow_always. Auth probe distinguishes login vs missing CLI.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1a3608f4211f999d3ab290847fcffc37a31e482b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add Grok Build provider workflows, usage, and rewind support

  • Adds Grok as a new usage provider kind, parsing updates.jsonl transcripts and bumping USAGE_CONTRACT_VERSION to 5.
  • Introduces ACP mapping for Grok workflows, subagent lifecycles, session extras (hooks, auto-compact, recaps), and tool update gating.
  • Implements conversation rewind via _x.ai/rewind/points and _x.ai/rewind/execute RPC methods, including active prompt cancellation and state trimming.
  • Adds reasoning effort menu handling, model resolution, and fallback capabilities for the grok-build model.
  • Risk: bumps USAGE_CONTRACT_VERSION in usage.ts; clients must negotiate version 5 to report Grok usage.
Macroscope summarized 1a3608f.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 219cc4f4-51d5-4477-a535-cddbdffedc68

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Skipped

      Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

      Not approved because:

      • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
    4. Follow-up `1d45fdb2` after auditing this against how T3 actually integrates Claude and Codex.

      What T3 expects (and the first ingest got wrong)

      • Claude workflow members use `parentAgentId` + `timelineBypass` + a stable `:wf:` slot. Codex collab children do the same. The first Grok mapper set `agentId = runId`, which T3 reads as “launched from inside a subagent,” and it did not bypass the parent timeline.
      • Child tokens belong on `typedUsage`. Claude never folds member tokens into `thread.token-usage.updated`. Codex rewrites child usage to `collabAgent/tokenUsage` so it cannot clobber the parent context window. The first Grok mapper emitted `usedTokens: workflowSum`, which ingestion treats as the new context-window snapshot (latest-wins on the client).
      • A first notification that is already terminal must still emit `task.completed`. Claude/Codex both handle first-seen terminal; we only completed if we had already seen a start.

      What this commit does

      • Pure mapper in `GrokAcpWorkflow.ts` (same seam as Claude’s `parseWorkflowProgress` / Codex’s `mapCollabAgentEvent`).
      • Members match Claude linkage. Unchanged ticks are fingerprinted and skipped.
      • Prompt usage stays the context-window snapshot; child tokens stay on the task.
      • Standalone Grok `subagent_spawned|progress|finished` updates use that same child-task path.

      58 Grok tests passing (workflow mapper, adapter, extension, support).

    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/615135ece51b1a83a1aab67c5e227c769a281f9d/apps/server/src/provider/Layers/GrokAdapter.ts#L1416

      When sendTurn is interrupted after the prompt succeeds, the Effect.ensuring fallback retains promptResult but does not update token usage, so thread.token-usage.updated is never emitted and usage remains stale or absent. Extract and emit usage in this fallback path as well.

      ✅ Resolved in 5c8bd7c6f745f0adb4197a29611f8a74fb354ee4

    6. Fixed in 5c8bd7c6: the Effect.ensuring success fallback now publishes thread.token-usage.updated from the retained prompt result, same helper as the happy path.

    7. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    8. Reviewed the Grok ACP changes against the Effect service conventions. Three findings in apps/server/src/provider/Layers/GrokAdapter.ts; the new pure modules (GrokAcpWorkflow.ts, GrokAcpToolUpdates.ts, XAiAcpExtension.ts) and the new FileSystem/Path acquisition in GrokProvider.ts follow the conventions (namespace subpath imports, dependencies acquired from the environment, requirements surfaced in the signature).

      Posted via Macroscope — Effect Service Conventions
    9. One finding on the new Grok auth classification helper. The earlier Date.now() throttle, the selectPermissionOptionId pass-through wrapper, and the unbounded rewind detail all look resolved at this head.

      Posted via Macroscope — Effect Service Conventions
    10. One finding: adding grok to PROVIDER_ORDER makes the hardcoded colSpan={5} in the Usage cost breakdown table's empty row short by one column. Details inline.

      Posted via Macroscope — UI Consistency
      @@ -24,3 +24,8 @@
      2424 color: "#d97757",
      2525 mark: ClaudeAI,
      2626 },
      27+ grok: {
      28+ label: "Grok Build",
      29+ color: "#8884d8",
      30+ mark: GrokIcon,
      31+ },
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Adding a third provider here widens every PROVIDER_ORDER-driven table, but the cost breakdown's empty row in UsagePage.tsx still hardcodes its span:

      // apps/web/src/components/usage/UsagePage.tsx:393
      <td colSpan={5} className="py-6 text-center text-muted-foreground">
        No activity in this window.
      </td>

      That header row is now Day + 3 providers + Total + Tokens = 6 columns, so the "No activity in this window." cell no longer spans the table and its centered text is offset by the leftover cell. Consider deriving the span from the order so it stays correct as providers are added:

      -                            <td colSpan={5} className="py-6 text-center text-muted-foreground">
      +                            <td
      +                              colSpan={PROVIDER_ORDER.length + 3}
      +                              className="py-6 text-center text-muted-foreground"
      +                            >
      Posted via Macroscope — UI Consistency
    11. @@ -129,3 +130,5 @@
      129130 continue;
      130131 }
      131132
      133+ if (provider === "grok") {
      134+ if (!mightCarryUsage(line, provider)) continue;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium usage/usageTranscriptReader.ts:134

      Camel-case Grok completion events are dropped before parsing, so transcripts with sessionUpdate: "turnCompleted" contribute no usage to the dashboard. parseGrokLine accepts both spellings, but mightCarryUsage only matches turn_completed; include turnCompleted in this prefilter.

      Suggested change
      134- if (!mightCarryUsage(line, provider)) continue;
      134+ if (!mightCarryUsage(line, provider) && !line.includes("turnCompleted")) continue;
      Also found in 1 other location(s)

      apps/server/src/usage/UsageService.ts:134

      The new Grok reader prefilters with mightCarryUsage before calling parseGrokLine. parseGrokLine explicitly accepts both turn_completed and turnCompleted, but mightCarryUsage only searches for turn_completed; therefore every camel-case turnCompleted transcript record is silently skipped and its usage is omitted from the dashboard.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/usage/usageTranscriptReader.ts around line 134:
      
      Camel-case Grok completion events are dropped before parsing, so transcripts with `sessionUpdate: "turnCompleted"` contribute no usage to the dashboard. `parseGrokLine` accepts both spellings, but `mightCarryUsage` only matches `turn_completed`; include `turnCompleted` in this prefilter.
      
      Also found in 1 other location(s):
      - apps/server/src/usage/UsageService.ts:134 -- The new Grok reader prefilters with `mightCarryUsage` before calling `parseGrokLine`. `parseGrokLine` explicitly accepts both `turn_completed` and `turnCompleted`, but `mightCarryUsage` only searches for `turn_completed`; therefore every camel-case `turnCompleted` transcript record is silently skipped and its usage is omitted from the dashboard.
      

Sign in to join this conversation.