Repository navigation
fix(pi): restore args for placeholder-less commands #3835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
haelyra
merged 6 commits into
affaan-m:main
from
quark404:fix/pi-placeholderless-command-args
Nov 16, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a0d4f6c
fix(pi): restore args for placeholder-less commands
quark404 2c12e43
test(pi): exercise real input handler pass-through paths
quark404 818fc73
fix(pi): match Pi placeholders and require active ECC prompt
quark404 c8cbb0e
refactor(pi): make registered input handler directly testable
quark404 65e47bb
test(pi): pin command body cache immutability after file changes
quark404 c2a7bfe
fix(pi): report command read failures
quark404 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| const fs = require("node:fs") | ||
| const path = require("node:path") | ||
|
|
||
| /** | ||
| * Same placeholder set Pi's `substituteArgs` understands. | ||
| * | ||
| * Pi expands every form below, so a command body containing any of them must | ||
| * be left for Pi to expand rather than treated as placeholder-less: | ||
| * $ARGUMENTS, $@, $1, ${1:-default}, ${@:N}, ${@:N:L} | ||
| */ | ||
| const ARG_PLACEHOLDER = /\$\{(\d+|ARGUMENTS|@):-[^}]*\}|\$\{@:\d+(?::\d+)?\}|\$(ARGUMENTS|@|\d+)/ | ||
|
|
||
| /** Values ECC treats as "off" across its existing environment switches. */ | ||
| const DISABLED_VALUES = new Set(["0", "false", "off", "none", "disabled"]) | ||
|
|
||
| function isDisabledByEnv(value) { | ||
| return typeof value === "string" && DISABLED_VALUES.has(value.trim().toLowerCase()) | ||
| } | ||
|
|
||
| function stripFrontmatter(raw) { | ||
| return raw.replace(/^\uFEFF?---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim() | ||
| } | ||
|
|
||
| /** | ||
| * Body of an ECC command that has NO argument placeholder, or null. | ||
| * | ||
| * Claude Code appends `ARGUMENTS: <args>` when a command lacks `$ARGUMENTS`; | ||
| * Pi's template expansion silently drops the arguments instead. Most ECC | ||
| * commands rely on the Claude behaviour, so the adapter restores it. | ||
| */ | ||
| function loadPlaceholderlessCommand(name, eccRoot, commandPath) { | ||
| if (!/^[A-Za-z0-9._-]+$/.test(name)) { | ||
| return null | ||
| } | ||
|
|
||
| const resolvedPath = commandPath || path.join(eccRoot, "commands", `${name}.md`) | ||
| try { | ||
| const raw = fs.readFileSync(resolvedPath, "utf8") | ||
| const stripped = stripFrontmatter(raw) | ||
| return ARG_PLACEHOLDER.test(stripped) ? null : stripped | ||
| } catch { | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the canonical ECC command path only when Pi's active prompt for | ||
| * `name` resolves to ECC's canonical `commands/<name>.md`. | ||
| * | ||
| * The input event fires before Pi expands prompt templates and does not expose | ||
| * the selected template directly. `pi.getCommands()` does expose the active | ||
| * prompt list (including source metadata), so this is the provenance check | ||
| * that keeps ECC from overriding a disabled, differently resolved, or | ||
| * extension-registered command with the same name. | ||
| */ | ||
| function activeEccPromptPath(name, eccRoot, activeCommands) { | ||
| if (!/^[A-Za-z0-9._-]+$/.test(name)) { | ||
| return null | ||
| } | ||
|
|
||
| const activePrompt = (activeCommands || []).find( | ||
| command => command && command.name === name && command.source === "prompt" | ||
| ) | ||
| if (!activePrompt || !activePrompt.sourceInfo) { | ||
| return null | ||
| } | ||
|
|
||
| const expectedPath = path.resolve(path.join(eccRoot, "commands", `${name}.md`)) | ||
| if (path.resolve(activePrompt.sourceInfo.path || "") !== expectedPath) { | ||
| return null | ||
| } | ||
| return expectedPath | ||
| } | ||
|
|
||
| /** | ||
| * Pi input-handler transform shared by the TypeScript extension and tests. | ||
| * | ||
| * Keep this in a CommonJS module so the real registered handler can be loaded | ||
| * and exercised by the plain Node test suite; the extension itself delegates | ||
| * directly to this function. | ||
| */ | ||
| function handlePiInput({ text, eccRoot, env, activeCommands, getBody }) { | ||
| if (isDisabledByEnv(env.ECC_PI_COMMAND_ARGS)) { | ||
| return { action: "continue" } | ||
| } | ||
|
|
||
| const match = text.match(/^\/([^\s:]+)\s+([\s\S]*\S[\s\S]*)$/) | ||
| if (!match) { | ||
| return { action: "continue" } | ||
| } | ||
|
|
||
| const commandPath = activeEccPromptPath(match[1], eccRoot, activeCommands) | ||
| if (!commandPath) { | ||
| return { action: "continue" } | ||
| } | ||
|
|
||
| const body = getBody | ||
| ? getBody(match[1], commandPath) | ||
| : loadPlaceholderlessCommand(match[1], eccRoot, commandPath) | ||
| if (!body) { | ||
| return { action: "continue" } | ||
| } | ||
|
|
||
| return { action: "transform", text: `${body}\n\nARGUMENTS: ${match[2].trim()}` } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a body reader with its own cache. | ||
| * | ||
| * The returned function returns a fresh Map on each new lookup rather than | ||
| * mutating the previous cache, satisfying ECC's immutability rule. | ||
| */ | ||
| function createCommandBodyReader(eccRoot) { | ||
| let cache = new Map() | ||
| return name => { | ||
| if (cache.has(name)) { | ||
| return cache.get(name) ?? null | ||
| } | ||
| const body = loadPlaceholderlessCommand(name, eccRoot) | ||
| cache = new Map(cache).set(name, body) | ||
| return body | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| ARG_PLACEHOLDER, | ||
| DISABLED_VALUES, | ||
| isDisabledByEnv, | ||
| stripFrontmatter, | ||
| loadPlaceholderlessCommand, | ||
| createCommandBodyReader, | ||
| activeEccPromptPath, | ||
| handlePiInput, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.