Skip to content

Skill tool names + tools-disabled mode in BuildSystemPrompt - #51

Merged
FMXExpress merged 1 commit into
claude/pr46-system-prompt-builderfrom
claude/pr51-skill-names-notools
May 28, 2026
Merged

FMXExpress merged 1 commit into
claude/pr46-system-prompt-builderfrom
claude/pr51-skill-names-notools

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Stacked on top of #50. Two real bugs in the prompt builder from #50, both caught in review.

When #50 lands, this PR's base can be retargeted to main (one-click in the GitHub UI) and the diff will collapse to just the one fix commit.

Bug 1 — Skill catalog advertised the wrong tool names

RegisterSkills in PasClaw.Skills.Loader.pas:269 registers each manifest as 'skill_' + Skills[i].Name, so the actual callable identifier is skill_weather, not weather. PR #50's BuildSkillsSection was advertising the bare name — every skill invocation would have hit "tool not found" and the model would either retry in a loop or avoid the skill entirely.

Fix: prefix skill_ in BuildSkillsSection so the bullet matches what the registry exposes.

Bug 2 — Prompt told the model to use tools when tools were disabled

pasclaw agent --no-tools (Cmd.Agent line 185), TPasClawAgent with UseTools=False (Component line 224), and pasclaw serve --no-tools (Cmd.Serve line 111) all leave the tool registry nil, so RunToolLoop sends an empty tool list. But PR #50's system prompt still emitted the SKILLS catalog and a RULES block whose top rule was "ALWAYS use tools." The model would then either invent tool calls the loop refused to pass through, or oscillate between the no-tools reality and the system prompt's tool-use directive — producing confused or unusable responses.

Fix: new ToolsEnabled parameter on BuildSystemPrompt (default True so existing callers stay byte-identical), gates tool-dependent content:

Mode Sections emitted
ToolsEnabled = True (default) Identity + Workspace + Memory + Skills + 5-rule block (use tools / be precise / verify / truncated tool calls / memory) + user-supplied --system text
ToolsEnabled = False Identity + Workspace + Memory + 2-rule block (be precise + new "No tools in this session — do not claim to read files, run commands, or modify state. Answer from what is in this conversation.") + user-supplied text

Identity, workspace paths, and memory contents stay in either mode — they're useful as plain context regardless of whether tools are wired up.

Wiring at every call site

  • Cmd.Agent.pas passes not A.NoTools
  • Component.pas passes FUseTools
  • Gateway.Server.pas passes FRegistry <> nil (covers both /v1/chat and /v1/chat/completions; the latter still gated on HasSystemMessage(Msgs) for client-supplied personas)

Test plan

  • pasclaw agent --no-tools "hi" — system prompt has no SKILLS section, no "ALWAYS use tools" rule, contains the new "No tools in this session" rule
  • pasclaw agent "hi" (with tools) — system prompt advertises any installed skills as skill_<name>, not <name>
  • Install a skill named weather, then pasclaw agent "what's my weather skill called?" — model answers skill_weather and can actually call it
  • pasclaw serve --no-tools + curl a chat completion — composed prompt is in no-tools mode
  • Component constructed with UseTools := False — same effect

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Two real bugs in the prompt builder from the previous commit on this
branch, both caught in review.

1. Skill catalog advertised the wrong tool names. RegisterSkills in
   PasClaw.Skills.Loader registers each manifest as `'skill_' +
   Skills[i].Name` (line 269), so the actual callable identifier is
   `skill_weather`, not `weather`. The prompt was telling the model
   to call the bare name — every skill invocation would have hit
   "tool not found" and the model would have either retried in a
   loop or avoided skills entirely. Fixed by prefixing `skill_` in
   BuildSkillsSection so the bullet line matches what the registry
   exposes.

2. The prompt was telling the model to use tools when tools were
   explicitly disabled. `pasclaw agent --no-tools` (Cmd.Agent line
   185), TPasClawAgent with UseTools=False (Component line 224), and
   `pasclaw serve --no-tools` (Cmd.Serve line 111) all leave the tool
   registry nil, so RunToolLoop sends an empty tool list. But the
   system prompt was still emitting the SKILLS catalog and a "RULES"
   block whose top rule is "ALWAYS use tools when an action is
   needed". The model would then either invent tool calls that the
   loop refused to pass through, or get stuck oscillating between
   the no-tools reality and the system prompt's tool-use directive.

   Fixed by adding a ToolsEnabled parameter (default True) to
   BuildSystemPrompt and gating tool-dependent content on it:

     ToolsEnabled = True   (default — unchanged from previous commit)
       Identity + Workspace + Memory + Skills + 5-rule block
       + user-supplied --system text.

     ToolsEnabled = False
       Identity + Workspace + Memory + 2-rule block ("Be precise"
       and a new "No tools in this session — do not claim to read
       files, run commands, or modify state. Answer from what is in
       this conversation."). Skills catalog suppressed entirely.

   Identity, workspace paths, and memory contents stay in either
   mode — they are useful as plain context regardless of whether
   tools are wired up.

   Wired through every call site:
     - Cmd.Agent passes `not A.NoTools`
     - Component passes FUseTools
     - Gateway passes `FRegistry <> nil` (covers both
       /v1/chat and /v1/chat/completions, the latter still gated
       on HasSystemMessage(Msgs) for client-supplied personas)

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit e1ee881 into claude/pr46-system-prompt-builder May 28, 2026

@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: a7726d5ae6

ℹ️ 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".

Cfg.MaxIterations := FMaxIterations;
Cfg.Options := DefaultChatOptions;
Cfg.Options.SystemPrompt := BuildSystemPrompt(FConfig, FSystemPrompt);
Cfg.Options.SystemPrompt := BuildSystemPrompt(FConfig, FSystemPrompt, FUseTools);

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 Keep no-tools prompt in sync with the registry

If a TPasClawAgent is used once with tools enabled and then UseTools is set to False, EnsureRegistry keeps the existing FRegistry because it returns before checking FUseTools, and line 291 still passes that registry to RunToolLoop. This changed line then builds a “No tools in this session” prompt while the provider still receives the tool definitions, so the supposed no-tools turn can still invoke tools and has contradictory instructions; derive this flag from the registry actually sent, or clear/omit the registry when tools are disabled.

Useful? React with 👍 / 👎.

FMXExpress pushed a commit that referenced this pull request May 28, 2026
Windows commands, regex allow-lists, stale-registry no-tools prompt,
sample build instructions

Five legitimate issues raised in review of the prior commit.

1. Case-sensitive path comparison on POSIX
   PathInsideDirectory used SameText, which treats
   /tmp/workspace and /tmp/Workspace as the same prefix on
   case-sensitive filesystems. If both happen to exist, a
   restricted fs_read for /tmp/Workspace/secret would pass the
   prefix check, then the actual ReadFileText opens the
   differently-cased path — sandbox bypass. New PathsEqual
   helper does the right thing per OS:
     {$IFDEF MSWINDOWS}  SameText (Windows is case-insensitive)
     {$ELSE}             A = B    (case-sensitive)

2. Relative-path bypass in shell sandbox
   HasOutsideAbsolutePath only fired on '/'-prefixed tokens, so
   `cd .. && cat secret` slipped through silently with
   restrict_to_workspace=true: no absolute path appeared, and
   RunOneShot inherited the parent's cwd so the relative paths
   resolved wherever pasclaw was launched.

   Three defenses, layered:
     a) cd / chdir / pushd / popd added to ForbiddenTokens so
        the model cannot change cwd inside the shell.
     b) New HasTraversalToken refuses any whitespace-separated
        token containing '..'. Catches `cat ../secret`,
        `(cd ..)`, `bash -c '...cd..'`, etc.
     c) RunOneShot grows a WorkingDir parameter, plumbed through
        all four platform impls (FPC POSIX/Windows via
        TProcess.CurrentDirectory; Delphi Windows + Delphi POSIX
        via ChDir/restore around TStdioProcess.Spawn). Tool_Shell
        passes CurrentWorkspace when RestrictionActive, so even
        a token the denylist missed runs from the workspace and
        cannot reach files above it via relative paths.

3. Windows command coverage
   The denylist was POSIX-shaped: rm, mkfs, dd, etc. cmd.exe and
   PowerShell users had no equivalent. Added 9 Windows tokens
   (del, erase, rd, rmdir, format, attrib, takeown, icacls,
   runas) and 17 PowerShell substrings (del /f|q|s, rd /s,
   rmdir /s, format /q, powershell -e/-en/-enc/-ec,
   -encodedcommand, iex (, invoke-expression,
   [convert]::frombase64, [text.encoding],
   .getstring([byte[], set-executionpolicy). Picoclaw's
   windowsDenyPatterns set is the reference. Patterns are
   checked unconditionally — running shell_exec on Linux today
   does not mean a portable policy should let `format c:`
   through if the same config is deployed on Windows tomorrow.

4. Regex allow-lists (FPC + Delphi)
   New unit src/pkg/tools/PasClaw.Tools.Regex.pas wraps the two
   regex engines behind one call:
     {$IFDEF FPC}   uses RegExpr.TRegExpr
     {$ELSE}        uses System.RegularExpressions.TRegEx

   Both are bundled with their respective compilers (no extra
   package install needed; FPC ships RegExpr in fcl-regexpr,
   Delphi has System.RegularExpressions since XE). Invalid
   patterns return False rather than raising so a malformed
   regex in config.json does not crash the agent — the sandbox
   layer treats False the same as "no allowlist match" and
   falls through to the workspace check.

   AllowReadPaths / AllowWritePaths now match via the regex
   wrapper instead of the in-unit glob matcher. PCRE syntax —
   ^/tmp/.*, ^/usr/(include|share)/.*, etc. README updated.
   Existing glob users migrate: '/tmp/*' becomes '^/tmp/.*'
   (anchor the prefix, replace * with .*).

5. Stale FRegistry leaks tools into "no tools" prompt
   TPasClawAgent.EnsureRegistry caches FRegistry and only
   honours FUseTools when the registry is nil. A component used
   with UseTools=True, then flipped to False, would build a
   "No tools in this session" prompt while still sending the
   cached registry to RunToolLoop — contradictory instructions
   plus actual tool access. Single source of truth is the
   registry handed to RunToolLoop. Every BuildSystemPrompt call
   site now derives the third arg from `<scope>.Registry <> nil`:
     Cmd.Agent   - Reg parameter
     Component   - Cfg.Registry
     Gateway     - LoopCfg.Registry

   PR #51's content (skill_ tool name prefix + no-tools rules +
   ToolsEnabled parameter) was also reapplied here. The PR was
   merged but the squash collapsed only PR #50's commits into
   main, so the actual changes were lost.

Sample (samples/component-console/SampleConsole.dpr):
  The header comment shipped a literal
  `fpc -Fu../../src/cmd -Fu../../src/pkg/...` instruction. The
  '...' isn't an FPC wildcard — it tried to use '...' as a
  directory name and failed. Also the sample needs ~25 unit
  search paths plus three Indy paths, not just two. Replaced
  the broken instruction with a real Makefile at
  samples/component-console/Makefile that re-uses the top-level
  UNIT_DIRS list re-rooted at the repo root. Comment now points
  at it.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
FMXExpress pushed a commit that referenced this pull request May 28, 2026
Windows commands, regex allow-lists, stale-registry no-tools prompt,
sample build instructions

Five legitimate issues raised in review of the prior commit.

1. Case-sensitive path comparison on POSIX
   PathInsideDirectory used SameText, which treats
   /tmp/workspace and /tmp/Workspace as the same prefix on
   case-sensitive filesystems. If both happen to exist, a
   restricted fs_read for /tmp/Workspace/secret would pass the
   prefix check, then the actual ReadFileText opens the
   differently-cased path — sandbox bypass. New PathsEqual
   helper does the right thing per OS:
     {$IFDEF MSWINDOWS}  SameText (Windows is case-insensitive)
     {$ELSE}             A = B    (case-sensitive)

2. Relative-path bypass in shell sandbox
   HasOutsideAbsolutePath only fired on '/'-prefixed tokens, so
   `cd .. && cat secret` slipped through silently with
   restrict_to_workspace=true: no absolute path appeared, and
   RunOneShot inherited the parent's cwd so the relative paths
   resolved wherever pasclaw was launched.

   Three defenses, layered:
     a) cd / chdir / pushd / popd added to ForbiddenTokens so
        the model cannot change cwd inside the shell.
     b) New HasTraversalToken refuses any whitespace-separated
        token containing '..'. Catches `cat ../secret`,
        `(cd ..)`, `bash -c '...cd..'`, etc.
     c) RunOneShot grows a WorkingDir parameter, plumbed through
        all four platform impls (FPC POSIX/Windows via
        TProcess.CurrentDirectory; Delphi Windows + Delphi POSIX
        via ChDir/restore around TStdioProcess.Spawn). Tool_Shell
        passes CurrentWorkspace when RestrictionActive, so even
        a token the denylist missed runs from the workspace and
        cannot reach files above it via relative paths.

3. Windows command coverage
   The denylist was POSIX-shaped: rm, mkfs, dd, etc. cmd.exe and
   PowerShell users had no equivalent. Added 9 Windows tokens
   (del, erase, rd, rmdir, format, attrib, takeown, icacls,
   runas) and 17 PowerShell substrings (del /f|q|s, rd /s,
   rmdir /s, format /q, powershell -e/-en/-enc/-ec,
   -encodedcommand, iex (, invoke-expression,
   [convert]::frombase64, [text.encoding],
   .getstring([byte[], set-executionpolicy). Picoclaw's
   windowsDenyPatterns set is the reference. Patterns are
   checked unconditionally — running shell_exec on Linux today
   does not mean a portable policy should let `format c:`
   through if the same config is deployed on Windows tomorrow.

4. Regex allow-lists (FPC + Delphi)
   New unit src/pkg/tools/PasClaw.Tools.Regex.pas wraps the two
   regex engines behind one call:
     {$IFDEF FPC}   uses RegExpr.TRegExpr
     {$ELSE}        uses System.RegularExpressions.TRegEx

   Both are bundled with their respective compilers (no extra
   package install needed; FPC ships RegExpr in fcl-regexpr,
   Delphi has System.RegularExpressions since XE). Invalid
   patterns return False rather than raising so a malformed
   regex in config.json does not crash the agent — the sandbox
   layer treats False the same as "no allowlist match" and
   falls through to the workspace check.

   AllowReadPaths / AllowWritePaths now match via the regex
   wrapper instead of the in-unit glob matcher. PCRE syntax —
   ^/tmp/.*, ^/usr/(include|share)/.*, etc. README updated.
   Existing glob users migrate: '/tmp/*' becomes '^/tmp/.*'
   (anchor the prefix, replace * with .*).

5. Stale FRegistry leaks tools into "no tools" prompt
   TPasClawAgent.EnsureRegistry caches FRegistry and only
   honours FUseTools when the registry is nil. A component used
   with UseTools=True, then flipped to False, would build a
   "No tools in this session" prompt while still sending the
   cached registry to RunToolLoop — contradictory instructions
   plus actual tool access. Single source of truth is the
   registry handed to RunToolLoop. Every BuildSystemPrompt call
   site now derives the third arg from `<scope>.Registry <> nil`:
     Cmd.Agent   - Reg parameter
     Component   - Cfg.Registry
     Gateway     - LoopCfg.Registry

   PR #51's content (skill_ tool name prefix + no-tools rules +
   ToolsEnabled parameter) was also reapplied here. The PR was
   merged but the squash collapsed only PR #50's commits into
   main, so the actual changes were lost.

Sample (samples/component-console/SampleConsole.dpr):
  The header comment shipped a literal
  `fpc -Fu../../src/cmd -Fu../../src/pkg/...` instruction. The
  '...' isn't an FPC wildcard — it tried to use '...' as a
  directory name and failed. Also the sample needs ~25 unit
  search paths plus three Indy paths, not just two. Replaced
  the broken instruction with a real Makefile at
  samples/component-console/Makefile that re-uses the top-level
  UNIT_DIRS list re-rooted at the repo root. Comment now points
  at it.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
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