Skip to content

Experience-Driven Black-Box Cost Control for Coding Agents

Plugin fixes from the interactive check on all four agents

Aaron92cfc422643c
diff --git a/CLAUDE.md b/CLAUDE.md
index 23e7a69..56db567 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -14,8 +14,10 @@ behavior, and `docs/METHOD.md` for the method.
- `plugin/` — the runtime: hook dispatch, per-repository state, settings, the `te` CLI
- `config.py`, `ledger.py`, `pricing.py`, `domain.py`, `stage.py` — shared by all three
- `plugin/` — the installable plugin directory: manifests per agent, hook files, launchers
- (`scripts/te`, `scripts/te-hook`), slash commands, Codex skills (`codex-skills/`, Codex having
- no plugin slash commands), the Pi extension; `lib/` links the package
+ (`scripts/te`, `scripts/te-hook`), slash commands (`slash-commands/`, named in the Claude Code
+ and Copilot manifests, since Codex would turn a `commands/` folder into duplicate skills), Codex
+ skills (`codex-skills/`, Codex having no plugin slash commands), the Pi extension; `lib/` links
+ the package
- `experiments/` — benchmark-only: `te_bench/` (adapters, arms, facade, benchmark-only
controllers), `te_harness/` (Docker runners), `scripts/`, `docs/`, its own `tests/`
- `package.json` — the repository as a Pi package (`pi install git:github.com/…`); it names
diff --git a/docs/PLUGIN.md b/docs/PLUGIN.md
index df8faca..f40b29f 100644
--- a/docs/PLUGIN.md
+++ b/docs/PLUGIN.md
@@ -334,7 +334,10 @@ or `--zip` it for `claude --plugin-url`).
**Codex** — the plugin carries `.codex-plugin/plugin.json`, `hooks/codex-hooks.json` and, as
Codex has no plugin slash commands, its commands as Codex skills (`codex-skills/`:
`tokeneconomizer-status`, `-microskills`, `-toolprune`, `-config`, each running the matching
-`te --host codex` command). Codex copies an installed plugin; the copy finds the package in the
+`te --host codex` command). Codex 0.153.1 also turns a plugin's `commands/` folder into skills
+(`source-command-status`, …), which listed every command twice in its skill picker; the slash
+commands therefore live in `slash-commands/`, which the Claude Code and Copilot manifests name and
+Codex does not read. Codex copies an installed plugin; the copy finds the package in the
checkout it was added from (or carries it, from the bundle):
```bash
diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json
index 15166f0..9fcb1c6 100644
--- a/plugin/.claude-plugin/plugin.json
+++ b/plugin/.claude-plugin/plugin.json
@@ -8,6 +8,7 @@
},
"repository": "https://github.com/microsoft/TokenEconomizer",
"license": "Apache-2.0",
+ "commands": "./slash-commands/",
"keywords": [
"cost",
"tokens",
diff --git a/plugin/.github/plugin/plugin.json b/plugin/.github/plugin/plugin.json
index d44559d..ee8ceae 100644
--- a/plugin/.github/plugin/plugin.json
+++ b/plugin/.github/plugin/plugin.json
@@ -16,5 +16,6 @@
"tool-pruning",
"failure-loops"
],
+ "commands": "./slash-commands/",
"hooks": "hooks/copilot-hooks.json"
}
diff --git a/plugin/README.md b/plugin/README.md
index 82cb145..a3402b3 100644
--- a/plugin/README.md
+++ b/plugin/README.md
@@ -164,8 +164,8 @@ copilot plugin list # tokeneconomizer@tokeneconomizer ... (enabled)
Copilot loads the plugin from the clone directly, without copying it.
**2. Check it.** In Copilot's interactive mode, type `/tokeneconomizer:status`. Each slash command
-is a model turn and asks permission the first time; allow it always. Slash commands work only
-in interactive mode; the plugin's notices also appear under `copilot -p`.
+is a model turn, and Copilot asks before running the plugin's script; choose **Yes**. Slash
+commands work only in interactive mode; the plugin's notices also appear under `copilot -p`.
**3. Record the tool list, once.**
diff --git a/plugin/commands/config.md b/plugin/slash-commands/config.md
similarity index 100%
rename from plugin/commands/config.md
rename to plugin/slash-commands/config.md
diff --git a/plugin/commands/facts.md b/plugin/slash-commands/facts.md
similarity index 100%
rename from plugin/commands/facts.md
rename to plugin/slash-commands/facts.md
diff --git a/plugin/commands/microskills.md b/plugin/slash-commands/microskills.md
similarity index 100%
rename from plugin/commands/microskills.md
rename to plugin/slash-commands/microskills.md
diff --git a/plugin/commands/status.md b/plugin/slash-commands/status.md
similarity index 100%
rename from plugin/commands/status.md
rename to plugin/slash-commands/status.md
diff --git a/plugin/commands/toolprune.md b/plugin/slash-commands/toolprune.md
similarity index 100%
rename from plugin/commands/toolprune.md
rename to plugin/slash-commands/toolprune.md
diff --git a/plugin/commands/untool.md b/plugin/slash-commands/untool.md
similarity index 100%
rename from plugin/commands/untool.md
rename to plugin/slash-commands/untool.md
diff --git a/tests/test_plugin_package.py b/tests/test_plugin_package.py
index 4e6b10b..d5b20d7 100644
--- a/tests/test_plugin_package.py
+++ b/tests/test_plugin_package.py
@@ -361,6 +361,33 @@ def test_the_commands_keep_their_earlier_names(tmp_path, monkeypatch, capsys):
assert outs[0] == outs[1] and outs[0]
body = {}
for name in (new, old):
- text = open(os.path.join(PLUGIN, "commands", f"{name}.md"), encoding="utf-8").read()
+ text = open(os.path.join(PLUGIN, "slash-commands", f"{name}.md"), encoding="utf-8").read()
body[name] = re.search(r'"\$te" --cwd "\$\(pwd\)" (\w+)', text).group(1)
assert body[new] == body[old] == new
+
+
+def test_toolprune_note_after_refresh_catalog(tmp_path, monkeypatch, capsys):
+ """Right after `refresh-catalog`, the repository has not folded a session with the catalog
+ yet; the note says so instead of asking for the command just run."""
+ from tokeneconomizer.plugin import cli
+ home = tmp_path / "home"
+ monkeypatch.setenv("TOKENECONOMIZER_HOME", str(home))
+ work = tmp_path / "work"
+ work.mkdir()
+ assert cli.main(["--cwd", str(work), "--host", "claude", "toolprune"]) == 0
+ assert "without `te --host claude toolprune refresh-catalog`" in capsys.readouterr().out
+ (home / "hosts" / "claude").mkdir(parents=True)
+ (home / "hosts" / "claude" / "catalog.json").write_text("{}", encoding="utf-8")
+ assert cli.main(["--cwd", str(work), "--host", "claude", "toolprune"]) == 0
+ out = capsys.readouterr().out
+ assert "joins this repository's evidence from its next session" in out
+ assert "without `te --host" not in out
+
+
+def test_codex_sees_no_claude_format_commands_folder():
+ """Codex turns a plugin's `commands/` folder into skills of its own, which would list every
+ command twice beside `codex-skills/`; Claude Code and Copilot read `slash-commands/` instead."""
+ assert not os.path.exists(os.path.join(PLUGIN, "commands"))
+ for manifest in (".claude-plugin/plugin.json", ".github/plugin/plugin.json"):
+ with open(os.path.join(PLUGIN, manifest), encoding="utf-8") as fh:
+ assert json.load(fh)["commands"] == "./slash-commands/"
diff --git a/tokeneconomizer/plugin/cli.py b/tokeneconomizer/plugin/cli.py
index 4e52409..cff09ba 100644
--- a/tokeneconomizer/plugin/cli.py
+++ b/tokeneconomizer/plugin/cli.py
@@ -156,9 +156,14 @@ def _toolprune_show(ctx, unt):
used = "used" if t in set(unt.get("used_tools", [])) else ""
print(f" {n:4d} {t} {used}")
if not unt.get("catalog_source") or unt.get("catalog_source") == "observed":
- print(f"note: without `te --host {host} toolprune refresh-catalog` only "
- + ("deferred and observed" if host == "claude" else "observed")
- + " tools are known, which leaves the always-loaded tools out of the evidence.")
+ if os.path.exists(os.path.join(ctx.root, "hosts", host, "catalog.json")):
+ # Recorded, but a repository reads the catalog when its next session is folded.
+ print("note: the catalog `toolprune refresh-catalog` recorded joins this repository's "
+ "evidence from its next session.")
+ else:
+ print(f"note: without `te --host {host} toolprune refresh-catalog` only "
+ + ("deferred and observed" if host == "claude" else "observed")
+ + " tools are known, which leaves the always-loaded tools out of the evidence.")
return 0