MaxMooreMy on X: "magpie的skill调用统计是不是坏了。用了一天,一个都没统计到".
The screenshot is Usage → Sessions, Codex (gpt-6-astra), 10 sessions,
Tool use "exec 488": Top skills says no skill was called up.
Cause: nothing ever counted a Codex skill. Codex has no tool for skills:
its <skills_instructions> list each skill's SKILL.md, and the model calls
one up by reading that file through a shell command, now from inside a
code-mode exec script (tools.exec_command({cmd:"cat '.../imagegen/
SKILL.md'"})), before that through exec_command, shell or a
local_shell_call. codexHead counted each call's tool and passed "" for
the skill, so only Claude Code (Skill tool), Alma and Pi/omp had skills.
Not a regression: efd1b697e and the other recent sessions commits don't
touch this; no version of codex.go counted one.
Now cxSkillReads reads a call line that holds "SKILL.md" (only those are
decoded) and counts each skill whose SKILL.md path it names, by its
folder, once a call: the exec script's input, a function call's
arguments, a local_shell_call's command. A patch writing a SKILL.md, a
redirect or tee into one, a bare SKILL.md with no folder (find -name,
grep) and a glob count none. The sessions cache goes to 25 so cached
Codex files are read again.
Run (all on mote, through mote-run, at this tree):
- go test -tags nogui ./internal/sessions/: ok.
- TestCodexSkillReads: two real call lines from this Mac's rollouts, byte
for byte (2026-08-07's code-mode exec, 2026-07-26's exec_command, its
timestamp moved to the same day), plus a patch, a heredoc redirect and
a find. TestCxSkillReads: shell, local_shell_call, a Windows
Get-Content path, and the reads that count none.
- Real sessions in a sandbox CODEX_HOME: 19 rollouts copied read-only
from ~/.codex/sessions (15 August ones with an imagegen read through
exec, today's 4). Old code: skills calls=0. New: imagegen 15 calls in
15 sessions, agent codex.
- Across all 11,846 compressed rollouts here, the exec calls naming a
SKILL.md were grouped by how they read it (cat, /bin/cat, sed -n, awk,
perl, wc && sed, `done < file`); each form is a read the rule counts.
- Broken by hand: with the loop that counts cxSkillReads' skills taken
out, TestCodexSkillReads fails ("skills []") and the real sandbox reads
0.
- go test -tags nogui of the packages importing sessions: usage, cli,
tui, tune, otlp, davsync ok; gui had TestRestartHandsTheGatewayOver red
once in the parallel run (#3451, open), 3 of 3 alone.
- gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows -tags nogui
of internal/sessions ok.
Not tried: the GUI against a live magpie (the page only shows what
Overview returns; app.js unchanged, so no GUI suite run); a SKILL.md read
through tools the rule doesn't know (a plugin's own read tool) and a
skill whose SKILL.md sits in a nested folder (clawra-selfie/skill/
SKILL.md counts as "skill"); internal/gateway and internal/agent, which
import sessions for other things. Other agents with no skill count
(Droid, Kimi Code, Hermes, Cursor, Antigravity) have no real session
here to build from: #4037.
70 lines
4.7 KiB
Go
70 lines
4.7 KiB
Go
package sessions
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// Codex has no tool for skills: the model calls one up by reading its
|
|
// SKILL.md through a shell command. The two calls here are real lines from
|
|
// Codex rollouts, byte for byte: one through code mode's exec script
|
|
// (tools.exec_command), the tool every call goes through in Codex's current
|
|
// sessions (MaxMooreMy on X: a day of Codex use, "exec" 488 calls, no
|
|
// skill), and one through exec_command itself. Each calls up imagegen; a
|
|
// patch writing a SKILL.md, a redirect into one and a find for them call
|
|
// up none.
|
|
func TestCodexSkillReads(t *testing.T) {
|
|
inZone(t, 0)
|
|
_, codex := setup(t)
|
|
id := "019fdaf9-90aa-78b1-8db0-2ff9edf69052"
|
|
cx := filepath.Join(codex, "sessions", "2026", "08", "07", "rollout-2026-08-07T14-46-56-"+id+".jsonl")
|
|
os.MkdirAll(filepath.Dir(cx), 0o755)
|
|
os.WriteFile(cx, []byte(
|
|
`{"timestamp":"2026-08-07T06:46:56.000Z","type":"session_meta","payload":{"id":"`+id+`","cwd":"/work/skills"}}`+"\n"+
|
|
`{"timestamp":"2026-08-07T06:46:57.000Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"draw a cat"}]}}`+"\n"+
|
|
// real: code mode
|
|
`{"timestamp":"2026-08-07T06:47:06.196Z","ordinal":14,"type":"response_item","payload":{"type":"custom_tool_call","id":"ctc_02280df79713d205016a757f695740819bbb199e7e518fc531","status":"completed","call_id":"call_meBGaRczwfCsNl9FQOEhhCMu","name":"exec","input":"const r = await tools.exec_command({cmd:\"cat '/Users/yetone/.codex/skills/.system/imagegen/SKILL.md'\",\"yield_time_ms\":10000,\"max_output_tokens\":12000}); text(r.output)\n","internal_chat_message_metadata_passthrough":{"turn_id":"019fdaf9-9764-74e0-b3f7-99cabf4e015c"}}}`+"\n"+
|
|
// real: exec_command (2026-07-26, its timestamp moved to this session's day)
|
|
`{"timestamp":"2026-08-07T06:47:35.723Z","ordinal":14,"type":"response_item","payload":{"type":"function_call","id":"fc_02a31ee780cd8312016a6634fe3e9c819a99ec3bbf765da4e9","name":"exec_command","arguments":"{\"cmd\":\"cat '/Users/yetone/.codex/skills/.system/imagegen/SKILL.md'\",\"workdir\":\"/Users/yetone/Library/Application Support/Codex Image Session Helper/inputs/2026-07-26T16-21-48-987Z\",\"yield_time_ms\":10000,\"max_output_tokens\":20000}","call_id":"call_1YSUTjeI9CNi9YVoHIYhODVH","internal_chat_message_metadata_passthrough":{"turn_id":"019f9f3e-e6e9-7b01-ad7e-858c2bfeaaf7"}}}`+"\n"+
|
|
// writes and searches call up nothing
|
|
`{"timestamp":"2026-08-07T06:48:00.000Z","type":"response_item","payload":{"type":"custom_tool_call","status":"completed","call_id":"c3","name":"apply_patch","input":"*** Begin Patch\n*** Add File: /Users/u/.codex/skills/mine/SKILL.md\n+---\n*** End Patch\n"}}`+"\n"+
|
|
`{"timestamp":"2026-08-07T06:48:01.000Z","type":"response_item","payload":{"type":"function_call","name":"exec_command","arguments":"{\"cmd\":\"cat > /Users/u/.codex/skills/mine/SKILL.md <<'EOF'\\nx\\nEOF\"}","call_id":"c4"}}`+"\n"+
|
|
`{"timestamp":"2026-08-07T06:48:02.000Z","type":"response_item","payload":{"type":"function_call","name":"exec_command","arguments":"{\"cmd\":\"find ~/.codex/skills -name SKILL.md\"}","call_id":"c5"}}`+"\n"), 0o644)
|
|
|
|
s := statsAt(0, statsNow)
|
|
var got Summary
|
|
for _, x := range s.Sessions {
|
|
if x.Cwd == "/work/skills" {
|
|
got = x
|
|
}
|
|
}
|
|
if got.ToolCalls != 5 || got.tools.of("exec") != 1 || got.tools.of("exec_command") != 3 {
|
|
t.Fatalf("tools %d %v", got.ToolCalls, got.tools)
|
|
}
|
|
if got.skills.of("imagegen") != 2 || len(got.skills) != 1 {
|
|
t.Fatalf("skills %v", got.skills)
|
|
}
|
|
o := s.Overview("", "", "", 10)
|
|
if o.Skills.Calls != 2 || o.Skills.Top[0].Name != "imagegen" || o.Skills.Top[0].Agents["codex"] != 2 || o.Skills.Top[0].Last != "2026-08-07" {
|
|
t.Fatalf("overview skills %+v", o.Skills)
|
|
}
|
|
}
|
|
|
|
func TestCxSkillReads(t *testing.T) {
|
|
for _, c := range []struct {
|
|
line, name string
|
|
want []string
|
|
}{
|
|
{`{"payload":{"type":"function_call","name":"shell","arguments":"{\"command\":[\"bash\",\"-lc\",\"sed -n '1,200p' /a/skills/pdf/SKILL.md; cat /a/skills/pdf/SKILL.md /a/skills/docx/SKILL.md\"]}"}}`, "shell", []string{"pdf", "docx"}},
|
|
{`{"payload":{"type":"local_shell_call","action":{"type":"exec","command":["cat","/a/skills/xlsx/SKILL.md"]}}}`, "local_shell_call", []string{"xlsx"}},
|
|
{`{"payload":{"type":"function_call","name":"shell_command","arguments":"{\"command\":\"Get-Content C:\\\\Users\\\\u\\\\.codex\\\\skills\\\\pptx\\\\SKILL.md\"}"}}`, "shell_command", []string{"pptx"}},
|
|
{`{"payload":{"type":"function_call","name":"exec_command","arguments":"{\"cmd\":\"cat SKILL.md /a/*/SKILL.md /a/x/SKILL.md.bak | tee /a/y/SKILL.md\"}"}}`, "exec_command", nil},
|
|
} {
|
|
if got := cxSkillReads([]byte(c.line), c.name); !slices.Equal(got, c.want) {
|
|
t.Errorf("%s: %v, want %v", c.line, got, c.want)
|
|
}
|
|
}
|
|
}
|