Skip to content

fix(cli): hide internal compaction summaries and drafts in CLI history - #1790

Open
Plastic-time wants to merge 2 commits into
Prism-Shadow:mainfrom
Plastic-time:rrfz/fix-cli-history-internal-records
Open

Plastic-time wants to merge 2 commits into
Prism-Shadow:mainfrom
Plastic-time:rrfz/fix-cli-history-internal-records

Conversation

@Plastic-time

Copy link
Copy Markdown
Contributor

What this changes

After a long conversation compacts, penguin session log and penguin chat --resume currently print the internal compaction summary as if the user typed it (> [context_summary]...) and leak the compaction turn's internal prompt, intermediate thoughts, tool calls, and [summary] draft into the conversation transcript.

This change aligns renderHistory (and adds the same defensive guard to StreamRenderer) in packages/cli/src/render.ts with the Web App's packages/web/src/lib/amsp/stream-model.ts and packages/server/src/services/message-window.ts for compaction records:

  1. Skip [context_summary] and legacy <context_summary> context openings via a shared isContextSummary(text) helper in renderHistory (and defensively in StreamRenderer.renderNow when echoInput is enabled, so replayed/fed compaction openings are never echoed as user input or clear expectedInput). Ordinary user messages that merely mention [context_summary] mid-sentence remain untouched.
  2. Track compaction_begin..compaction_end per origin (originKey) during renderHistory so compaction-internal model_msg records (compaction prompt, thinking, tool calls/outputs, and [summary] draft) stay out of the transcript for both the parent session and nested subagents without interfering with one another. A session_meta for an origin also clears its active compaction span in case a truncated history lacks compaction_end.

Verification

  • Environment: Windows 11, Node v24.22.1, pnpm 11.18.0, baseline commit 437df9d01, verified on commit 73286e960.
  • Before fix (new regression tests in packages/cli/test/render.test.ts on baseline 437df9d01):
    pnpm --filter @prismshadow/penguin-cli exec vitest run test/render.test.ts
    3 failed | 77 passed (80) — all three new tests failed because renderHistory printed [context_summary]/<context_summary> openings and compaction-internal messages, and StreamRenderer with echoInput echoed [context_summary]/<context_summary>.
  • After fix (commit 73286e960):
    • Focused suite:
      pnpm --filter @prismshadow/penguin-cli exec vitest run test/render.test.ts
      1 passed (1) — 80 passed (80).
    • Typecheck, formatting, and lint:
      • pnpm --filter @prismshadow/penguin-cli typecheck: passed (src/ifaces.json unchanged (283 interfaces, 766 types)).
      • pnpm exec prettier --check packages/cli/src/render.ts packages/cli/test/render.test.ts changelog/unreleased/2026-11-23-cli-history-compaction.md changelog/unreleased/2026-11-23-cli-history-compaction.zh.md: passed.
      • pnpm exec oxlint packages/cli/src/render.ts packages/cli/test/render.test.ts: passed (0 warnings and 0 errors).
  • Scope: No new dependencies, runtime capabilities, or network access; changes are confined to packages/cli/src/render.ts, packages/cli/test/render.test.ts, and the changelog pair. Open draft PRs #1550 and #289 also touch packages/cli/src/render.ts for unrelated refactors/features.
    • Full CLI suite (pnpm exec vitest run in packages/cli): 42 passed (42) files, 652 passed | 8 skipped (660) tests.
  • Not verified locally: Linux/macOS runs and GitHub Actions CI.

Checklist

  • Changelog entry pair under changelog/unreleased/ — YYYY-MM-DD-<slug>.md and its .zh.md counterpart, in the format changelog/README.md describes.
  • Docs updated where this changes documented behavior (README, packages/docs/content/). (N/A — aligns CLI history rendering with existing Web App and live CLI compaction rules.)
  • No API key, bot token or other credential in the diff, the logs, or the screenshots.

Align renderHistory (used by penguin session log and penguin chat --resume)
and StreamRenderer (echoInput) with Web's stream-model on compaction records:
- Skip [context_summary] and legacy <context_summary> context openings in
  renderHistory (and defensively in StreamRenderer when echoInput is enabled),
  while keeping ordinary user messages that mention [context_summary]
  mid-sentence.
- Track compaction_begin..compaction_end per origin in renderHistory (resetting
  on session_meta for that origin) so internal compaction prompts, thoughts,
  tool calls, and draft summaries stay out of the transcript without parent
  and nested subagent spans interfering with one another.
@Plastic-time
Plastic-time marked this pull request as ready for review November 24, 2026 02:35

This branch has not been deployed

No deployments
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.

1 participant