Repository navigation
features: slash commands + provider fallback chain + email channel - #101
Conversation
Three Tier-1 features from the gap analysis against picoclaw,
nanobot, and openclaw, plus a confirmation that /v1/models was
already shipped.
1. Slash commands in `pasclaw agent`'s RunInteractive loop
(TUI also gets the help text; deeper TUI integration is a
follow-up since the TUI's slash handler is per-build under
Delphi vs FPC):
/help show the command list
/status provider + model + message count + thinking
state + compaction state
/new clear conversation history (alias: /reset)
/reset clear conversation history
/compact force a one-shot summariser pass on the history
by calling CompactMessages with threshold=1
/think toggle ThinkingLevel := 'medium' for the next
turn (only when Provider.SupportsThinking)
/tools list registered tools (pre-existing)
/quit exit (pre-existing)
/think clears itself after sending so subsequent turns reset
— matches openclaw's single-turn /think semantic.
2. Provider fallback chain. New TConfig.Fallbacks: array of
string (saved as "fallbacks": [...] in config.json); new
PasClaw.Providers.Factory.ResolveFallbacks(Cfg) helper.
TToolLoopConfig grows a Fallbacks: array of ILLMProvider
field; RunToolLoop wraps Cfg.Provider.Chat in a status-code
check and walks Fallbacks on retryable failure
(StatusCode <= 0 / 408 / 429 / 5xx — any other 4xx is a
config bug the fallback wouldn't fix). Wired in:
src/cmd/PasClaw.Cmd.Agent.BuildLoopConfig
src/pkg/agent/PasClaw.Agent.ChatHistory
src/pkg/gateway/PasClaw.Gateway.Server (3 sites)
Channels (Telegram, Discord, LINE, etc.) and TUI not wired
yet — follow-up. The agent + gateway cover the high-volume
paths.
Plumbing: TLLMResponse gets a new StatusCode: Integer field
(default 0 = unset); Anthropic / OpenAI / Gemini provider
adapters set it from the HTTP response code so RunToolLoop's
IsRetryableStatus helper can classify failures structurally
rather than parsing the "anthropic error 429: ..." string
that used to land in Content.
3. Email channel (bidirectional). New
PasClaw.Channels.Email with TEmailChannel + TEmailWorker:
Push(recipient, subject, body) outbound via TIdSMTP,
STARTTLS by default,
sslvTLSv1_2
Run inbound IMAP poll loop;
TIdIMAP4 SelectMailBox
INBOX, walks messages,
filters by PASCLAW_EMAIL_
ALLOW substring matches,
routes each through
RunToolLoop (with Parallel
+ Fallbacks), sends reply,
marks Seen so we don't
reprocess
Spawn Run on a dedicated TThread
so the gateway main loop
stays free
Configuration via env vars (all SMTP_* required for outbound,
all IMAP_* additionally required for inbound):
PASCLAW_EMAIL_SMTP_{HOST,PORT,USER,PASS,TLS}
PASCLAW_EMAIL_IMAP_{HOST,PORT,USER,PASS}
PASCLAW_EMAIL_FROM
PASCLAW_EMAIL_POLL e.g. "30s" / "5m" / "1h" — min 5s
PASCLAW_EMAIL_ALLOW comma-separated sender substrings
Gateway flag: `pasclaw gateway --email`. Without an allowlist
every unread message is auto-replied to — fine for a personal
mailbox, dangerous for a shared one, so the docstring calls
it out explicitly.
4. `/v1/models` — already implemented (gateway has it as an
OpenAI-compatible model list at line 295 of PasClaw.Gateway
.Server, registered alongside the chat-completions routes).
Nothing to add.
README updated to mention all three new features in the Features
section + an `Interactive chat` entry for the slash commands.
Verified `make smoke` 11/11 green; `pasclaw agent` interactive
input piped `/help` correctly prints the new command list.
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94cc0da5f3
ℹ️ 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".
| MsgCount := IMAP.MailBox.TotalMsgs; | ||
| if MsgCount = 0 then Exit; | ||
| for i := 1 to MsgCount do |
There was a problem hiding this comment.
Select unread messages before replying
When pasclaw gateway --email is enabled, every poll iterates from 1 through IMAP.MailBox.TotalMsgs and later runs each allowed message through the agent loop without checking mfSeen or issuing an UNSEEN search. Marking a message Seen at the end therefore does not prevent it from being processed again on the next poll. Any allowed email left in INBOX will receive repeated replies indefinitely, consuming model calls and potentially starting reply loops.
Useful? React with 👍 / 👎.
| Resp := Cfg.Fallbacks[fbi].Chat(Hist, Tools, Cfg.Model, LiveOptions); | ||
| if not IsRetryableStatus(Resp.StatusCode) then |
There was a problem hiding this comment.
Use each fallback provider's configured model
When the primary fails and the fallback belongs to another provider family, this passes the primary Cfg.Model into the fallback instead of allowing the fallback to use its own configured default. For example, the default claude-opus-4-7 model is sent to an OpenAI fallback, which normally returns a 4xx invalid-model response; because the loop treats that response as non-retryable, it also stops before trying later fallbacks. The advertised cross-provider chain therefore fails in the common Anthropic-to-OpenAI or Anthropic-to-Gemini configuration.
Useful? React with 👍 / 👎.
| if not Push(FromAddr, 'Re: ' + Subj, Reply, PushErr) then | ||
| LogWarn('email reply send failed to %s: %s', [FromAddr, PushErr]); | ||
| end; | ||
| { Mark Seen so we don't reprocess. } | ||
| IMAP.StoreFlags([UInt32(i)], sdAdd, [mfSeen]); |
There was a problem hiding this comment.
Keep failed email replies eligible for retry
When SMTP delivery fails, Push returns False and the failure is only logged, but the inbound message is still marked Seen immediately afterward. A transient SMTP outage or authentication failure therefore permanently drops the reply instead of retrying it during a later poll. Only add mfSeen after a successful send, or record a separate terminal state for messages that intentionally receive no reply.
Useful? React with 👍 / 👎.
| if Args.Email then | ||
| begin | ||
| Email := TEmailChannel.Create(Cfg, Provider, Reg); | ||
| Email.Spawn; { runs Email.Run on a dedicated TThread } | ||
| end; |
There was a problem hiding this comment.
Stop the email worker before freeing gateway dependencies
When --email is enabled and the gateway stops, this detached worker is never signaled, joined, or freed in the cleanup block at PasClaw.Cmd.Gateway.pas:291-302. That cleanup frees Reg and then Cfg while the worker may still be polling or executing RunToolLoop with FRegistry and FCfg, creating a shutdown race with use-after-free access. Retain the channel, call RequestStop, wait for its worker to exit, and free it before releasing the shared objects.
Useful? React with 👍 / 👎.
| while (WaitedSec < FPollSec) and (not FStop) do | ||
| begin | ||
| Sleep(500); | ||
| Inc(WaitedSec); { coarse — 500ms ticks; close enough for an email poller } |
There was a problem hiding this comment.
Count full seconds in the email polling delay
For any configured PASCLAW_EMAIL_POLL value, the delay is only half of the requested interval: the loop sleeps for 500 ms but increments WaitedSec as though a full second elapsed. The documented default of 30 seconds therefore polls every 15 seconds, and a configured minimum of 5 seconds polls every 2.5 seconds, increasing IMAP traffic and model-call amplification when messages remain eligible for processing.
Useful? React with 👍 / 👎.
email/toolloop: fix PR #101 review — UNSEEN-only, fallback model, worker join
Summary
Three Tier-1 features from the gap analysis against picoclaw / nanobot / openclaw, plus a confirmation that the fourth (
/v1/models) was already shipped.1. Slash commands in
pasclaw agent/help/status/new/reset)/reset/compactCompactMessageswith threshold=1/thinkThinkingLevel := 'medium'for the next turn (Anthropic Claude only)/tools/quit/thinkclears itself after sending — single-turn semantic matching openclaw.2. Provider fallback chain
TConfig.Fallbacks: array of string(serialised as"fallbacks": [...]inconfig.json)PasClaw.Providers.Factory.ResolveFallbacks(Cfg)helperTToolLoopConfiggrows aFallbacks: array of ILLMProviderfieldRunToolLoopwrapsCfg.Provider.Chatin a status-code check and walksFallbackson retryable failure (StatusCode <= 0 / 408 / 429 / 5xx); 4xx other than rate-limit is a config bug the fallback wouldn't fixTLLMResponse.StatusCode: Integerfield; Anthropic / OpenAI / Gemini adapters populate it from the HTTP response so the retry logic classifies failures structurally rather than parsing the error stringWired in
Cmd.Agent.BuildLoopConfig,TPasClawAgent.ChatHistory, and gateway (3 sites — chat-completions, responses endpoint, gateway proxy). Channels and TUI not wired yet — follow-up; the agent + gateway cover the high-volume paths.3. Email channel (bidirectional)
New
PasClaw.Channels.EmailwithTEmailChannel+TEmailWorker:Push(recipient, subject, body)TIdSMTP, STARTTLS by default,sslvTLSv1_2RunTIdIMAP4 SelectMailBox INBOX, walks messages, filters byPASCLAW_EMAIL_ALLOWsubstring match, routes each throughRunToolLoop(withParallel+Fallbacks), sends reply, marks Seen so we don't reprocessSpawnRunon a dedicatedTThreadso the gateway main loop stays freeConfig via env vars:
Gateway flag:
pasclaw gateway --email. Without an allowlist every unread message is auto-replied to — fine for a personal mailbox, dangerous for a shared one, so the docstring calls it out explicitly.4.
/v1/modelsAlready implemented — the gateway has it at line 295 of
PasClaw.Gateway.Serveras an OpenAI-compatible model list, registered alongside the chat-completions routes. Nothing to add.README
Added an "Interactive chat" entry under Features for the slash commands, mentioned the fallback chain in the LLM providers row, and added Email to the bidirectional channels list.
Verification
make smoke11/11 green;pasclaw agentwith/helppiped over stdin correctly prints the new command list.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code