Files
magpie/internal/sessions/testdata/grok-tools
yetone 7e58591dcf sessions: Grok Build's tool calls and skills are counted (MaxMooreMy on X)
MaxMooreMy on X, after v0.1.1870 counted Codex's skills: "grok build 好像
也不支持。grok build 的工具调用啥的也没采集到". Usage > Sessions showed no
tool use and no skills for Grok Build.

Cause: parseGrok only ever read the first prompt and "turn_completed"
usage from updates.jsonl; nothing counted a tool call or a skill.

What Grok Build writes (grok 1.0.67, run headless in a sandbox
HOME/GROK_HOME, never the live ~/.grok): each call is one
"sessionUpdate":"tool_call" line, its name in _meta["x.ai/tool"].name
(also the line's title), followed by "tool_call_update" lines for its
progress. Grok has no skill tool: its prompt lists every SKILL.md by
absolute path, and the model calls one up with read_file (rawInput
.target_file) or a run_terminal_command, as Codex does. A user's
/<name> prompt is written to updates.jsonl as typed; the skill's text is
put into the prompt only in chat_history.jsonl (<skills_referenced>).
An unknown /nonexistentzz is written the same way, and Grok's own
commands (/compact) carry _meta.hostTurn.

Fix: a tool_call line counts its tool, and the skills its read_file path
or command reads (skillReadsIn, the loop cxSkillReads already had, now
shared). A non-hostTurn /<name> prompt in the main session counts skill
<name> when a skill or command of that name exists where Grok finds them:
.grok/.agents/.claude/.cursor skills/<name>/SKILL.md or commands/<name>.md
from the session's cwd up and in the home folder, $GROK_HOME/skills and
commands, and $GROK_HOME/bundled/skills. cacheVersion 26 so kept parses
are read again.

Tests: TestGrokToolsAndSkills runs on four real sessions captured from
grok 1.0.67, updates.jsonl and summary.json byte for byte (only the
encoded cwd folder name shortened): a cat + a read of greet-user's
SKILL.md (2 tools, 1 skill), /greet-user (1 skill), /nonexistentzz and
/compact (none, with a "compact" skill present). TestGrokSlashSkill
covers repo-level .claude/skills, cwd .grok/commands, bundled skills,
~/.agents/skills, paths, "..", and mid-text slashes.

Run (on mote, through mote-run, at this tree on origin/main 27bf14790):
- new tests at the old grok.go/codex.go/sessions.go: red ("tools 0 []")
- hostTurn guard broken by hand: red (/compact counted as "compact")
- go test -count=1 -timeout 45m ./...: 76 packages ok; one red,
  internal/gui TestMainWindowCorners/macOS_26_SDK on mote's macOS 27,
  already filed as #3949 and unrelated (sessions isn't in its path)
- go vet, GOOS=linux go vet, GOOS=windows go vet ./internal/sessions: ok
- gofmt -l internal/: clean

Not tried: skills from Grok plugins/marketplace (installed-plugins was
empty here, layout unknown), so a /<plugin skill> isn't counted; a /name
skill whose folder was deleted since isn't counted when the file is read
again; the TUI (only headless grok -p sessions were captured); Windows
and Linux runs of the Grok CLI.
2026-10-28 20:28:27 +08:00
..