Skip to content

Skill arguments and slash commands, an instructions list, a prompt-cache keep-alive - #614

Merged
FMXExpress merged 3 commits into
mainfrom
claude/opencode2-g-small
Oct 23, 2026
Merged

FMXExpress merged 3 commits into
mainfrom
claude/opencode2-g-small

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

PR G of docs/opencode2-plan.md, the three small ones. Targets main directly: A through F (#608, #609, #619, #611, #612, #613) are merged, and main is merged in here, so the diff is this PR only.

What

Skill arguments and slash commands. A prompt skill's template knew only {{key}} from the model's JSON. It now also takes $ARGUMENTS (the whole string) and $1..$9, split like a shell (quotes group, backslash escapes), with the highest $N the template uses absorbing the rest: Deploy $1 with $2 given staging --fast --quiet sees $2 = --fast --quiet. Both kinds of placeholder are filled in one pass, so a substituted value is never read as template. The text arrives as the JSON key arguments; a template that uses the placeholders and declared no schema gets a one-string schema automatically. Frontmatter gains agent:, model: and subagent:. In pasclaw agent and both TUI builds (including tui --no-tools), /name rest of line runs the installed prompt skill with that text (PasClaw.Skills.Slash; built-ins win on a clash, /help lists the skills). In the REPL agent: goes through the spawn tool, subagent: runs a fresh child loop on the current tools, and model: sets the model for that run and only that run, which the auto-router leaves alone. The transcript records the typed command and the child's reply. The TUI honours model: and turns agent: / subagent: into an instruction at the top of the message.

instructions. Beside AGENTS.md discovery, config instructions lists files and globs relative to the workspace and http(s) URLs. Each body is appended after the project rules under its own heading, capped like AGENTS.md. URLs go through web_fetch's SSRF guard (FetchTextGuarded, factored out of the tool) and are cached 24 h under <home>/cache/instructions, with a stale copy served when a refresh fails. A download stops at its cap however large the response, and a body the server cuts short is a failure, not a cached fragment. Missing files are skipped.

prompt_cache.warm (default off). After four idle minutes the gateway sends one minimal request, the last real turn's system block and tools so the cached prefix matches, max_tokens 1, every four minutes until thirty minutes after the last turn (PasClaw.Gateway.Warm, on the existing 30 s tick). Each ping is a billed request; /v1/stats reports prompt_cache_warm_pings.

Skipped from the plan's list: image limits for fs_read (the plan says only if the desktop's reads hit provider limits, which nothing reports yet).

Review fixes

  • P2, a JSON value was read back as template. RenderTemplate ran the $-placeholder pass over the already-filled output, so Pay {{amount}} with {"amount":"$50"} became Pay 0. It is one pass over the template now, and the highest $N comes from the template alone.
  • P2, the auto-router overrode a slash skill's model:. TToolLoopConfig gains ModelPinned (False by default). ApplyAutoRoute leaves a pinned turn alone, as it does in plan mode, and all three surfaces that apply a skill model set it. Re-applying the model after routing was not an option: that would send a model name meant for this provider to the cheap one.
  • P2, a steered skill's model leaked into the next TUI turn. The FTurnModel field is gone. The model is now an argument of StartTurn / HandleUserInput, so it cannot outlive its turn; steering joins the running turn on that turn's model, and the footer says so.
  • P2, the instructions download was capped only after it finished. It now downloads into a stream that keeps at most MaxBytes and ends the transfer at the cap. The stream also ignores Indy's pre-size from Content-Length, which would otherwise reserve the whole declared length up front, and raise past 2 GB.
  • P2, tui --no-tools knew no slash skills. The manifests now load outside the tool-registration block.
  • Also: under the cap, a transfer that dies mid-body is a failure (stale copy served) rather than a fragment cached for a day. Indy stops quietly when the peer hangs up, so this compares the bytes received with Content-Length.

Tests

skill_args_tests and instructions_tests (make test-skill-args, make test-instructions):

  • Skill arguments and slash commands: tokeniser; $ARGUMENTS / $N / last-absorbs / missing / $0; RenderTemplate doing both substitutions; frontmatter parse; slash resolution with dashes and case; expansion appending args to a plain template; shell skills and built-ins not resolving; registration schema; a tool call with arguments.
  • Instructions: file, sorted glob, missing file, cap, a URL served from a fresh cache file with no network, config round-trip.
  • Warm pings: a WarmPingDue table, and WarmTick against a counting provider: disabled, not idle, due with max_tokens 1 and the noted model and tools, spacing, the 30-minute stop, a new turn resetting the clock.

The review fixes add these, each checked by reverting its fix and watching it fail:

  • Values stay text: $50, $ARGUMENTS and $2 inside JSON values, and {{k}} inside the arguments string. The old renderer fails with exactly Pay 0.
  • Pinned turns: autoroute_apply_tests checks that a pinned turn is not routed and that provider, model and fallbacks are untouched.
  • Surface wiring (source shape): every line that applies a skill model is followed by the pin, the TUI keeps no skill-model field, and both TUI call sites pass the model to the turn they start. The positioned TUI is Delphi-only and the REPLs are interactive, so this is checked from the source. The Delphi-only code was not compiled here (no Delphi compiler in this environment).
  • Download cap: a local server declares 3 GB and streams up to 256 MB. The fetch returns exactly MaxBytes, and the server gets out only what the socket buffers hold (about 1 MB). The old code pulls all 256 MB, and without the SetSize override the declared length fails the fetch with an empty body.
  • Mid-body failure: a server that declares 1000 bytes and sends 500 makes the fetch fail; without the length check it succeeds.

Full make test green (51 passes). Smoke-tested /deploy staging --fast in the offline REPL.

Docs

docs/skills.md ("Arguments and slash commands", now also on value substitution and model: scope), docs/configuration.md (prompt_cache.warm, instructions), docs/gateway.md, docs/commands.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U

…che keep-alive

PR G of docs/opencode2-plan.md: the three small ones.

Skill arguments. A prompt skill's template knew only {{key}} from the
model's JSON. It now also takes $ARGUMENTS (the whole string) and
$1..$9, split like a shell -- quotes group, backslash escapes -- with
the highest $N the template uses absorbing the rest, so "Deploy $1
with $2" given "staging --fast --quiet" sees $2 = "--fast --quiet". The
text arrives as the JSON key `arguments`; a template that uses the
placeholders and declared no schema gets a one-string schema, so the
model can call skill_deploy with the text an operator would type.
Frontmatter gains agent:, model: and subagent:. In pasclaw agent and
both TUI builds, /name rest-of-line runs the installed prompt skill
with that text (PasClaw.Skills.Slash; built-ins win on a clash, /help
lists the skills). In the REPL agent: goes through the spawn tool,
subagent: runs a fresh child loop on the current tools, model: sets the
model for that run; the transcript records the typed command and the
child's reply, not the child's tool traffic. The TUI honours model:
and turns agent: / subagent: into an instruction at the top of the
message.

instructions. Beside AGENTS.md discovery, config `instructions` lists
files and globs relative to the workspace and http(s) URLs. Each body
is appended after the project rules under its own heading, capped like
AGENTS.md; URLs go through web_fetch's SSRF guard (FetchTextGuarded,
factored out of the tool) and are cached for 24 hours under
<home>/cache/instructions, with a stale copy served when a refresh
fails. Missing files are skipped.

prompt_cache.warm. Off by default. After four idle minutes the gateway
sends one minimal request -- the last real turn's system block and
tools, so the cached prefix matches, user text "ping", max_tokens 1 --
every four minutes until thirty minutes after the last turn
(PasClaw.Gateway.Warm, on the existing 30 s tick). Each ping is a
billed request; /v1/stats reports prompt_cache_warm_pings.

Tested in skill_args_tests (tokeniser, $ARGUMENTS / $N / last-absorbs
/ missing / $0, RenderTemplate doing both substitutions, frontmatter
parse, slash resolution with dashes and case, expansion appending
args to a plain template, shell skills and built-ins not resolving,
registration schema, a tool call with arguments) and
instructions_tests (file, sorted glob, missing skipped, cap, a URL
served from a fresh cache file with no network, config round-trip;
WarmPingDue table and WarmTick against a counting provider: disabled,
not idle, due with max_tokens 1 and the noted model and tools, spacing,
the 30-minute stop, a new turn resetting the clock).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T18:20:03.219838Z 6f9ae53 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f9ae53127

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

{ Command-style arguments ride in as one string ("arguments"), the
way a slash invocation or a model call with a single free-text
argument supplies them. }
Result := RenderSkillArguments(Out_, Obj.GetStr('arguments', ''));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Substitute argument placeholders before JSON values

When a pre-existing {{key}} value contains text such as $50 or $ARGUMENTS, this post-processing pass interprets that user-provided value as a template placeholder and corrupts it—for example, Pay {{amount}} with {"amount":"$50"} renders as Pay 0. Apply command-style substitution only to placeholders originating in the template, rather than to the fully interpolated output.

Useful? React with 👍 / 👎.

Comment thread src/cmd/PasClaw.Cmd.Agent.pas Outdated
end;

LoopCfg := BuildLoopConfig(Cfg, Provider, Reg, Model, A, Handlers, Line);
if SkModel <> '' then LoopCfg.Model := SkModel; { a slash skill's model: for this turn }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the skill model through auto-routing

When auto_router.enabled is set and an inline slash-skill prompt classifies as easy, the later ApplyAutoRoute call overwrites this model: override with the configured easy model. The documented per-skill model therefore is not used for exactly those invocations; either bypass routing for an explicit skill model or reapply the override after routing.

Useful? React with 👍 / 👎.

Comment on lines +1925 to +1928
else if ResolveSlashSkill(Text, Skills, SkSpec, SkArgs) then
begin
FTurnModel := SkSpec.Model;
Text := ExpandSlashSkill(SkSpec, SkArgs);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not leak a steered skill model into the next turn

In the positioned TUI, invoking a model-qualified slash skill while FLoopThread is active sets FTurnModel, but the input is then queued as steering and exits without calling StartTurn, which is the only place that clears this field. Consequently, the next unrelated turn runs on the skill's model; clear the override on the steering path or associate it only with an immediately started turn.

Useful? React with 👍 / 👎.

Comment on lines +284 to +285
N := MS.Size;
if (MaxBytes > 0) and (N > MaxBytes) then N := MaxBytes;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the instruction download limit while streaming

For an instructions URL that returns a very large body, GetURLToStreamGuarded downloads the entire response into MS before MaxBytes is applied, so a server can consume unbounded process memory even though callers request a roughly 128 KB cap. The stream itself needs to stop or reject writes at the limit rather than truncating only after the response completes.

Useful? React with 👍 / 👎.

end;

TUIInst := TTUI.Create(Provider, Reg, Model);
TUIInst.Skills := Skills; { prompt skills as /name in the chat input }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Load TUI slash skills independently of tool registration

With pasclaw tui --no-tools, Skills is never populated because LoadSkillManifests is inside the not A.NoTools block, so this new assignment gives the TUI an empty catalog and every prompt slash command is reported unknown. Inline prompt expansion does not require a registry—the agent REPL already loads slash skills separately—so manifests should be loaded even when tool registration is disabled.

Useful? React with 👍 / 👎.

main now carries #608 through #613, which this branch was stacked on.
One conflict, in the Makefile: this branch's new test-skill-args and
test-instructions targets sat beside test-runfile, which #613 made
depend on $(BIN). Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
…nd the instructions download stops at its cap

Five review findings, all real.

**P2: a JSON value was read back as template.** RenderTemplate filled
{{key}} and then ran the $ARGUMENTS / $N pass over the RESULT, so
"Pay {{amount}}" with {"amount":"$50"} rendered "Pay 0", a value
holding $ARGUMENTS pulled the arguments in, and a $N inside a value
moved which token absorbs the rest. Both kinds of placeholder are now
filled in one pass over the template, and the highest $N comes from
the template alone: only placeholders written in the template are
placeholders. The test that documented "use a JSON key for literal
dollars" now holds.

**P2: the auto-router overrode a slash skill's model.** `model:` was set
on the turn, then ApplyAutoRoute swapped in the easy model whenever the
command looked easy -- which short commands do. Re-applying it after
routing would send a model name meant for this provider to the cheap
one, so the turn is not routed instead: TToolLoopConfig gains
ModelPinned (False by Default, so every other caller routes as before),
ApplyAutoRoute leaves a pinned turn alone, as it already does in plan
mode, and the three places a skill model is applied -- `pasclaw agent`
and both TUI builds, which had the same ordering -- set it.

**P2: in the positioned TUI, a skill's model leaked into the next turn.**
It waited in FTurnModel until StartTurn cleared it, and a skill typed
while a turn was running is queued as steering without starting one.
The next, unrelated turn then ran on the skill's model. StartTurn's own
early exits and the line REPL's offline exit left it set the same way.
The field is gone: the model is a StartTurn / HandleUserInput argument,
so it cannot outlive the turn it was typed for. Steering joins the
running turn on that turn's model, and the footer now says so.

**P2: the instructions download was capped only after it finished.**
FetchTextGuarded downloaded into a TMemoryStream and cut at MaxBytes
afterwards, so a URL answering with a huge body -- or an endless one --
was buffered whole. It now downloads into a stream that keeps at most
MaxBytes: the write that would cross the cap keeps what fits and raises,
which ends the transfer (the exception unwind TEventStream already uses,
since Indy has no cancel hook). The stream also ignores Indy's pre-size
from Content-Length, which on a memory stream reserves the whole
declared length before a byte arrives -- and past 2 GB made TStream's
SetSize raise, failing the fetch with an empty body.

On the way, because a success is cached for a day as the project's
instructions: under the cap, a transfer that died mid-body is now a
failure (the stale copy, if any, is served), not a fragment. Indy stops
quietly when the peer hangs up, so that is detected by comparing what
arrived with Content-Length, as well as by an error alongside a 2xx.

**P2: `tui --no-tools` knew no slash skills.** The manifests were loaded
inside the tool-registration block, so with --no-tools every prompt
skill was "unknown". Expanding one into a message needs no registry, and
the agent REPL already loads them on their own; now the TUI does too.

Tested, each fix negative-verified by reverting it:

  - skill_args_tests: "Pay {{amount}}" / $50, $ARGUMENTS in a value, a
    $2 in a value beside a template $1, {{k}} in the arguments string.
    The old renderer fails with exactly "Pay 0".
  - autoroute_apply_tests: a pinned turn with an easy message and a
    resolvable easy provider is not routed; provider, model and
    fallbacks untouched. Without the rule it routes.
  - skill_args_tests, source shape: every line that applies a skill's
    model is followed by the pin (Cmd.Agent, both TUI builds), the TUI
    no longer keeps it in a field, and both TUI call sites pass it to
    the turn they start. Two of the three surfaces are the Delphi-only
    positioned TUI and an interactive REPL; neither can be driven here,
    and the Delphi-only code was not compiled (no Delphi compiler in
    this environment). The old Cmd.Agent and the old TUI each fail it.
  - instructions_tests: a local server declares 3 GB and streams up to
    256 MB. The fetch returns exactly MaxBytes, and the server gets out
    only what the socket buffers hold before the client hangs up (0.6
    to 1.5 MB in runs here; asserted under 64 MB). The old code pulls all 256
    MB; without the SetSize override the declared length fails the fetch
    with an empty body. A server that declares 1000 bytes and sends 500
    makes the fetch fail; without the length check it "succeeds".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress
FMXExpress changed the base branch from claude/opencode2-f-attach to main October 23, 2026 06:34
@FMXExpress
FMXExpress merged commit e637c14 into main Oct 23, 2026
1 check passed
FMXExpress pushed a commit that referenced this pull request Oct 23, 2026
main moved on by #608 through #614 since this branch was cut. Five
conflicts, all two independent additions side by side, all kept:

  - Cmd.Gateway / Cmd.Serve / Cmd.TUI uses clauses: this branch's
    PasClaw.MCP.Disclosure (for the --no-mcp registration) beside
    main's PasClaw.Gateway.RunFile, and in the TUI beside Worktree,
    Cmd.Attach and Client.Api.
  - docs/configuration.md: the builtin_progressive_disclosure row beside
    main's code-mode, background-jobs, permissions, worktree, cli.attach
    and shell-timeout rows.
  - docs/mcp.md: "Built-in long tail" beside main's "Code Mode".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
FMXExpress pushed a commit that referenced this pull request Oct 26, 2026
main moved on by #608 through #615 since this branch was cut. Two
conflicts:

  - Makefile, the .PHONY list and the `test` prerequisites: main's lines,
    plus this branch's one target, test-workspace-listing (which the
    branch's .PHONY line also carried twice).
  - PasClaw.Agent.Prompt interface: this branch's WorkspaceTopLevel /
    SafeEntryName beside #614's BuildInstructionsSection. Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants