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.
92 lines
3.3 KiB
Go
92 lines
3.3 KiB
Go
package sessions
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Grok Build's tool calls and skills (MaxMooreMy on X: "grok build 的工具
|
|
// 调用啥的也没采集到"). The four sessions in testdata/grok-tools are real
|
|
// grok 1.0.67 sessions, run headless (grok -p) in a sandbox home, byte for
|
|
// byte; only the folder of their working directory is named shorter. In
|
|
// one the model runs `cat notes.txt` and reads the greet-user skill's
|
|
// SKILL.md with read_file; in one the user types /greet-user; one types
|
|
// /nonexistentzz, a skill no folder has; one types /compact, Grok Build's
|
|
// own command, marked hostTurn, which calls up no skill even with one of
|
|
// that name about.
|
|
func TestGrokToolsAndSkills(t *testing.T) {
|
|
inZone(t, 0)
|
|
claude, _ := setup(t)
|
|
home := filepath.Join(filepath.Dir(claude), "home")
|
|
copyTree(t, "testdata/grok-tools", filepath.Join(home, ".grok"))
|
|
compact := filepath.Join(home, ".grok", "skills", "compact")
|
|
os.MkdirAll(compact, 0o755)
|
|
os.WriteFile(filepath.Join(compact, "SKILL.md"), []byte("---\nname: compact\n---\n"), 0o644)
|
|
|
|
s := statsAt(0, time.Date(2026, 10, 29, 0, 0, 0, 0, time.UTC))
|
|
by := map[string]Summary{}
|
|
for _, x := range s.Sessions {
|
|
if x.Agent == "grok" {
|
|
by[x.ID] = x
|
|
}
|
|
}
|
|
if len(by) != 4 {
|
|
t.Fatalf("want the 4 Grok Build sessions, got %d", len(by))
|
|
}
|
|
called := by["01a1826b-5457-7d52-9706-c7e26b3fe171"]
|
|
if called.ToolCalls != 2 || called.tools.of("run_terminal_command") != 1 || called.tools.of("read_file") != 1 {
|
|
t.Fatalf("tools %d %v", called.ToolCalls, called.tools)
|
|
}
|
|
if called.skills.of("greet-user") != 1 || len(called.skills) != 1 {
|
|
t.Fatalf("the skill read: %v", called.skills)
|
|
}
|
|
typed := by["01a1826b-d49a-76b0-acf7-0a7a5a0a4dca"]
|
|
if typed.ToolCalls != 0 || typed.skills.of("greet-user") != 1 || len(typed.skills) != 1 {
|
|
t.Fatalf("/greet-user: %d %v", typed.ToolCalls, typed.skills)
|
|
}
|
|
for _, id := range []string{"01a1826c-64a3-7871-a4c1-5cfb6a077576", "01a1826c-7ff2-7f92-8ba4-feb3b83bad3a"} {
|
|
if x := by[id]; x.ToolCalls != 0 || len(x.skills) != 0 {
|
|
t.Fatalf("%s: %d %v", id, x.ToolCalls, x.skills)
|
|
}
|
|
}
|
|
o := s.Overview("", "", "", 10)
|
|
if o.Skills.Calls != 2 || o.Skills.Top[0].Name != "greet-user" || o.Skills.Top[0].Agents["grok"] != 2 {
|
|
t.Fatalf("overview skills %+v", o.Skills)
|
|
}
|
|
}
|
|
|
|
func TestGrokSlashSkill(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("GROK_HOME", "")
|
|
repo := filepath.Join(t.TempDir(), "repo")
|
|
cwd := filepath.Join(repo, "app")
|
|
for _, p := range []string{
|
|
filepath.Join(repo, ".claude", "skills", "frontend", "SKILL.md"),
|
|
filepath.Join(cwd, ".grok", "commands", "ship.md"),
|
|
filepath.Join(home, ".grok", "bundled", "skills", "review", "SKILL.md"),
|
|
filepath.Join(home, ".agents", "skills", "pdf", "SKILL.md"),
|
|
} {
|
|
os.MkdirAll(filepath.Dir(p), 0o755)
|
|
os.WriteFile(p, []byte("x"), 0o644)
|
|
}
|
|
for text, want := range map[string]string{
|
|
"/frontend": "frontend",
|
|
"/ship now please": "ship",
|
|
"/review\nthe diff": "review",
|
|
"/pdf": "pdf",
|
|
"/tmp is full": "",
|
|
"/../repo": "",
|
|
"please /review": "",
|
|
"/frontend/x": "",
|
|
"/nonexistentzz say ok": "",
|
|
} {
|
|
if got := grokSlashSkill(cwd, text); got != want {
|
|
t.Errorf("%q: %q, want %q", text, got, want)
|
|
}
|
|
}
|
|
}
|