Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ convert(({ body, frontmatter, stem }) => ({
}));
```

For targets with required fields, validate them in `convert.js` and exit non-zero with a clear message. For example, Codex TOML agents require `description`, so `extensions/codex-agents` rejects inputs without `description` frontmatter instead of generating a TOML file that Codex cannot load.

Plain values become TOML strings:

```toml
Expand Down
20 changes: 14 additions & 6 deletions extensions/codex-agents/convert.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#!/usr/bin/env node
const { block, convert } = require("./md-toml");

convert(({ body, frontmatter, stem }) => ({
name: frontmatter.name || stem,
description: frontmatter.description,
model: frontmatter.model,
developer_instructions: block(body),
}));
convert(({ body, frontmatter, stem }) => {
if (!frontmatter.description || !frontmatter.description.trim()) {
throw new Error(
"codex-agents: missing required frontmatter 'description' (Codex custom agents require description)"
);
}

return {
name: frontmatter.name || stem,
description: frontmatter.description,
model: frontmatter.model,
developer_instructions: block(body),
};
});
3 changes: 3 additions & 0 deletions extensions/codex-agents/md-toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function convert(mapFields) {
}

process.stdout.write(lines.join("\n") + (lines.length ? "\n" : ""));
}).catch((err) => {
process.stderr.write((err && err.message ? err.message : String(err)) + "\n");
process.exit(1);
});
}

Expand Down
88 changes: 88 additions & 0 deletions internal/sync/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sync

import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -439,3 +440,90 @@ func TestSyncExtra_TransformRejectsNonCopyMode(t *testing.T) {
}
}
}

func TestBundledCodexAgentExtension_TransformsRequiredFields(t *testing.T) {
node := requireNode(t)
root := testRepoRoot(t)

cmd := exec.Command(node, filepath.Join(root, "extensions", "codex-agents", "convert.js"))
cmd.Env = append(os.Environ(), "SS_REL_PATH=reviewer.md")
cmd.Stdin = strings.NewReader("---\nname: reviewer\ndescription: Review PRs for correctness\nmodel: gpt-5.4\n---\nReview code like an owner.\n")

out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("codex-agents convert failed: %v\n%s", err, out)
}

got := string(out)
for _, want := range []string{
`name = "reviewer"`,
`description = "Review PRs for correctness"`,
`model = "gpt-5.4"`,
`developer_instructions = """`,
`Review code like an owner.`,
} {
if !strings.Contains(got, want) {
t.Errorf("converted output missing %q:\n%s", want, got)
}
}
}

func TestBundledCodexAgentExtension_RequiresDescription(t *testing.T) {
node := requireNode(t)
root := testRepoRoot(t)

for _, tc := range []struct {
name string
input string
}{
{
name: "missing",
input: "# Reviewer\nReview code like an owner.\n",
},
{
name: "whitespace-only",
input: "---\ndescription: \" \"\n---\nReview code like an owner.\n",
},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := exec.Command(node, filepath.Join(root, "extensions", "codex-agents", "convert.js"))
cmd.Env = append(os.Environ(), "SS_REL_PATH=reviewer.md")
cmd.Stdin = strings.NewReader(tc.input)

out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("expected missing description to fail, got success:\n%s", out)
}
if !strings.Contains(string(out), "missing required frontmatter 'description'") {
t.Fatalf("expected missing description error, got:\n%s", out)
}
})
}
}

func requireNode(t *testing.T) string {
t.Helper()
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node not available; skipping bundled JavaScript extension check")
}
return node
}

func testRepoRoot(t *testing.T) string {
t.Helper()
dir, err := os.Getwd()
if err != nil {
t.Fatalf("getwd: %v", err)
}
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir
}
parent := filepath.Dir(dir)
if parent == dir {
t.Fatal("could not find repo root")
}
dir = parent
}
}
2 changes: 1 addition & 1 deletion website/docs/reference/commands/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ extras:
extension: codex-agents
```

`skillshare sync extras` converts each `<agent>.md` into `~/.codex/agents/<agent>.toml`, mapping frontmatter `name`, `description`, and `model` and folding the markdown body into `developer_instructions` (other frontmatter keys are dropped). No separate copy of the agents is needed.
`skillshare sync extras` converts each `<agent>.md` into `~/.codex/agents/<agent>.toml`, mapping frontmatter `name`, `description`, and `model` and folding the markdown body into `developer_instructions` (other frontmatter keys are dropped). Codex requires `description`, so the reference transform reports a clear error when that frontmatter field is missing. No separate copy of the agents is needed.

---

Expand Down
Loading