Skip to content

Heartbeat daemon (off by default, onboard opt-in) + reversible condensation (CCR) - #232

Merged
FMXExpress merged 2 commits into
mainfrom
claude/heartbeat-and-reversible-condense
Jun 12, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/heartbeat-and-reversible-condense

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Two features from the recent gap analysis, side-by-side.

1. Heartbeat — proactive periodic wake-up (off by default, onboarding opt-in)

The picoclaw / openclaw "agent that comes to you" pattern. A standalone pasclaw heartbeat daemon reads workspace/heartbeat.md every N minutes, runs the full agent loop on the file's body as the user message, and optionally posts the reply to a named channel.

Off by default. Onboarding adds a PromptHeartbeat step after PromptCheckpoints with explicit y/N + interval + channel-name follow-ups. The command refuses to start without Cfg.Heartbeat.Enabled (or --force) so an operator who skipped onboarding never ends up with unsolicited model spend.

  • PasClaw.Heartbeat — standalone class + thread, content file re-read on every tick (operator edits land without restart), skips empty/missing files cleanly, tight 4-iter loop.
  • pasclaw heartbeat command: foreground daemon (blocks until Ctrl-C) + --once for testing + --interval N / --content PATH overrides + --force.
  • Channel post reuses Cfg.Channels (same name→kind/target mapping send_message uses) — operator pre-declares targets, model can't exfiltrate to an arbitrary URL.
  • heartbeat_tests (4 cases): missing/empty/non-empty content, default-path fallback, no double-call on empty body. Scripted fake ILLMProvider keeps the suite model-free.

2. Reversible condensation (CCR)

The destructive flip of #230's condensers. The JSON condenser + 20 shell-filter families collapse a 200 KB tool result to a 4 KB structural summary — great for context, but the original bytes are gone. headroom's CCR keeps both: condense for the default view, stash the original under a tool_output_get handle for retrieval when the shape isn't enough.

  • PasClaw.Tools.OutputCache.AttachReversibleStashFooter(Original, Condensed, MinSavingsBytes) — when the saving exceeds the floor (default 256 bytes), stash the original under a fresh handle and append [condensed N -> M bytes; full original at handle="..." via tool_output_get]. No-op below the floor, no-op when SetCondenseReversible(False).
  • Wired at the two condensation points: RunToolLoop after MaybeCondenseJSON (every tool result) and Tool_Shell after ApplyShellFilter (shell_exec only). Tee-on-failure already means failed-command output is byte-identical and no stash attaches.
  • tool_output_get registration generalised: now registers when Cfg.ToolOutputCap > 0 OR Cfg.CondenseReversible (default True). All five registry builders updated (CLI agent, TUI, Serve, Gateway, embedder × 2).
  • LoadConfig propagates SetCondenseReversible() symmetrically with the existing SetPromptwareEnabled() pattern.
  • TUI /stats overlay grows a ccr N stash(es), M bytes preserved row alongside the promptware/shell-filter rows; box height bumped 11 → 12.
  • condense_reversible_tests (6 cases): no-op same-size, sub-floor skip, real saving stash + dereferenceable handle, disable switch, counter accumulation, MinSavingsBytes override.

Test plan

  • FPC make smoke clean.
  • Full make test green (33 targets, 2 new: test-condense-reversible, test-heartbeat).
  • New units registered in PasClaw.dproj for the Delphi build.
  • Manual: write workspace/heartbeat.md, run pasclaw heartbeat --once, see the reply land. Run a large JSON-returning tool, check the result footer carries a handle, tool_output_get it back to verify the original bytes round-trip.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

…sation (CCR)

Two features from the recent gap analysis against picoclaw / openclaw
and chopratejas/headroom respectively.

1. Heartbeat -- proactive periodic wake-up. The picoclaw/openclaw
   "agent that comes to you" pattern: read workspace/heartbeat.md
   every N minutes, run the agent on its body, optionally post the
   result to a named channel.

   - PasClaw.Heartbeat: standalone THeartbeat class + thread; reads
     content file fresh on every tick (operator edits land without
     restart), skips empty/missing files cleanly, tight 4-iter loop
     to keep ticks bounded.
   - pasclaw heartbeat command: foreground daemon mode (blocks until
     Ctrl-C) + --once for testing + --interval / --content overrides
     + --force to override the config gate.
   - Off by default in TConfig.Heartbeat. Onboarding adds a
     PromptHeartbeat step after PromptCheckpoints: explicit y/N with
     interval and channel-name follow-ups. Refuses to run without
     the flag (or --force) so an operator who skipped onboarding
     doesn't end up with unsolicited model spend.
   - Channel post reuses Cfg.Channels (the same name->kind/target
     mapping send_message uses): operator pre-declares targets, model
     can't exfiltrate to an arbitrary URL.
   - heartbeat_tests pins: missing/empty/non-empty content paths,
     default-path fallback, no double-call when no body. Scripted
     fake ILLMProvider keeps the suite model-free.

2. Reversible condensation (CCR). PR #230 added the JSON condenser
   and 20-ish shell-filter families -- all DESTRUCTIVE: a 200 KB
   tool result that collapses to a 4 KB structural summary loses
   the original bytes. headroom's CCR layer keeps both: condense
   for the model's default view, stash the original under a handle
   for retrieval when the shape isn't enough.

   - PasClaw.Tools.OutputCache gets AttachReversibleStashFooter:
     when (Original - Condensed) >= MinSavingsBytes, stash the
     ORIGINAL under a fresh handle and append a one-line footer
     naming it. No-op below the floor, no-op when
     SetCondenseReversible(False).
   - Wired at the two condensation points:
       * RunToolLoop after MaybeCondenseJSON (every tool result)
       * Tool_Shell after ApplyShellFilter (shell_exec only)
     Both pass (RawBody, FilteredBody) -- tee-on-failure already
     means the bytes are byte-identical on failure and no stash
     attaches.
   - tool_output_get registration generalised: it now registers
     when Cfg.ToolOutputCap > 0 OR Cfg.CondenseReversible (default
     True). All five registry builders (CLI agent, TUI, Serve,
     Gateway, embedder x2) updated.
   - LoadConfig propagates SetCondenseReversible() symmetrically
     with the existing SetPromptwareEnabled() pattern.
   - condense_reversible_tests pins: no-op same-size, sub-floor
     skip, real saving stash + dereferenceable handle, disable
     switch, counter accumulation, MinSavingsBytes override.
   - TUI /stats overlay grows a "ccr N stash(es), M bytes preserved"
     row alongside the existing promptware/shell-filter rows; box
     height bumped from 11 to 12.

FPC make smoke + full make test (33 targets, +2 new) green. New
units registered in PasClaw.dproj. README updated.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon

@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: 137483ee93

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

Comment on lines +78 to +79
RegisterFSTools(Result, True);
RegisterShellTool(Result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Honor sandbox policy in heartbeat tools

When pasclaw heartbeat is run with sandbox.restrict_to_workspace=true, this new registry registers fs_* and shell_exec without first calling ConfigureSandbox(Cfg.Sandbox, '') (I checked the existing Agent/TUI/Serve/Gateway startup paths, which do call it). PasClaw.Tools.Sandbox defaults RestrictToWorkspace to False until configured, so a heartbeat prompt can read/write or shell against paths outside the configured workspace despite the operator's sandbox settings.

Useful? React with 👍 / 👎.

Codex P1, legit: Cmd_Heartbeat_Run built a registry with fs_* and
shell_exec but never called ConfigureSandbox(Cfg.Sandbox, ''), which
every other entry point (Agent, TUI, Serve, Gateway, embedder) does
at startup. PasClaw.Tools.Sandbox defaults RestrictToWorkspace to
False until configured, so a heartbeat prompt could read/write or
shell against paths outside the workspace regardless of the
operator's sandbox.restrict_to_workspace setting. ConfigureSandbox
now runs immediately after LoadConfig, before the enabled-gate and
registry construction.

FPC make smoke + full make test green.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit 331b99e into main Jun 12, 2026
FMXExpress pushed a commit that referenced this pull request Jun 13, 2026
Both changelog files were stuck at the 2026-06-10 TUI / background-
subagent / session_search / tool-RPC entries. ~7 weeks of merged
PRs (#214 through #244) had landed without a corresponding entry in
either file -- the git log was the only record of features like the
knowledgebase, inbound MCP server mode, checkpoints + /undo,
heartbeat daemon, shell backends (local | docker), send_message,
promptware defense, Windows shell-output encoding fixes, fs_grep
ripgrep optimisations, OpenTelemetry traces, and `pasclaw agent
--quiet`.

Added (newest first):

  2026-06-13
    #244  agent --quiet log-level clamp

  2026-06-12
    #243  dcc64 search path + agent --quiet / -q
    #242  OpenTelemetry traces (OTLP/HTTP+JSON)
    #241  fs_grep tier 5+6 (byte walker + Boyer-Moore-Horspool)
    #240  fs_grep tier 1-4 (deferred hash + skip-dirs + binary
          sniff + size cap)

  2026-06-11
    #239  Windows shell output: auto-detect UTF-8 vs OEM
    #238  Hashline fs_read header mojibake fix (¶ vs ¶)
    #237  Windows shell output: OEM codepage decode

  2026-06-10
    #233  Shell backends (local | docker via IShellBackend)
    #232  Heartbeat daemon + reversible condensation (CCR)
    #230  send_message tool + condenser families + promptware
          defense + task-aware MEMORY.md slicing

  2026-06-09
    #223  /goal Ralph loop + judge model + JSON-aware condenser
    #222  /undo wired into agent + sample dprojs
    #221  Checkpoints (auto-snapshot + TUI /undo)
    #220  mcp catalog: lenient hub projector
    #219  mcp: SSE / Streamable HTTP / stdio hub transports
    #218  Inbound MCP server mode
    #217  onboard: offer to index docs into the knowledgebase
    #214  Knowledgebase (RAG over operator-curated docs)

Skipped from this changelog (build-system / Delphi-fix / FPC-fix
PRs visible in the git log but not user-facing features):
#215, #216, #224, #225, #226, #227, #228, #229, #231, #234, #236.

Both files (README.md and docs/changelog.md) updated with the same
entries -- intentional mirror so a reader on either surface sees
the same history. Same prose in both; same footnote refs at the
bottom.

Validated: every [#N] reference in both files has a matching [#N]:
URL footnote (no broken links).
FMXExpress pushed a commit that referenced this pull request Jun 21, 2026
Per review feedback: early changelog entries are typically 60-200
chars; entries I added in the catch-up commit ran 250-1111 chars.
Trimmed each of the 20 new entries to fit the historical band:

  Before  count: 20  min: 252  max: 1111  avg: 580
  After   count: 20  min: 208  max:  580  avg: 359

Cuts applied:

  - Drop implementation detail (file paths, internal field names,
    "the only X tool in Y that does Z" asides)
  - Drop test-count call-outs
  - Drop future-facing notes ("plus follow-up work that ...")
  - Collapse aspect-by-aspect breakdowns into single-clause WHAT +
    one constraint
  - Keep the PR's headline change + its most distinctive token
    (config flag, command name, endpoint path, file convention)

Both README.md and docs/changelog.md updated identically. Same 20
PRs, same dates, same order, same link-ref block -- just leaner
prose. Going forward I'll target ~200-400 char entries for new
feature PRs, with up to ~600 only for actual big-feature parents
(matches existing entries like #232 Heartbeat at 844 chars or
#233 shell backends at 783).
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