feat(nudge): persist nudge injections as display-only session entries + single-line acp.log (closes #326) - #329
Open
ranxianglei wants to merge 1 commit into
Open
Conversation
… + single-line acp.log (closes #326) - pi.appendEntry("acp-nudge", {text}) on injection: compact one-line record ([ACP nudge] EMERGENCY 95% · T1 · top range m00120–m00168), deduped per user turn; survives restarts (session JSONL), visible in TUI scrollback via a registered entry renderer (pi-tui Box/Text, bundled inline), never sent to the model (type:"custom" entries are not projected into the sent view) - log.ts: escape \r/\n in string fields (incl. stacks) so every acp.log entry occupies one physical line -> nudge-injected entries self-contained for grep - devDep @earendil-works/pi-tui pinned exactly 0.83.0 (matches host); dist stays zero-runtime-deps - tests: formatNudgeRecord unit, persistence/dedup integration (emergency re-injection must not duplicate records), renderer unit, log single-line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #326.
Triage / verification
pi.sendMessage({customType})mid-turn is unsafe — while streaming, agent-session falls back tosteer()(injects as steering input). The/acpprecedent (commit 0ff701e, issue Show /acp-status as persistent output instead of a notification #255) only works because slash commands run idle; it cannot be reused from thecontexthandler.pi.appendEntry(customType, data)appends{type:"custom", ...}to the session JSONL — pure sync append, survives restarts, never sent to the model.entriesToCoreMessagesprojects onlytype:"custom_message"entries into the sent view ⇒type:"custom"records are display-only by construction. This satisfies the issue's "prefer a display-only entry type" constraint, so nodebuggating is needed (zero context cost).addCustomEntryToChat, and the restart-rebuild path (renderSessionEntries) includes them ⇒ registering an entry renderer makes records visible both live and afterpi --session <id>resume.Changes
src/index.ts): on nudge injection, append a compact one-line record (e.g.[ACP nudge] EMERGENCY 95% · T1 · top range m00120–m00168) viapi.appendEntry("acp-nudge", {text}). Deduped per user turn — emergency nudges re-inject on every LLM call until retry-capped and must not flood the session file.markNudgeRecordedruns only after a successful append (a failed append retries on the next fire). Recorded-state cleared at session start alongside nudge-shown tracking.src/index.ts):registerEntryRenderer("acp-nudge", ...)renders the record as a dim boxed line (pi-tuiBox/Text,customMessageBgbackground).@earendil-works/pi-tuiadded as devDependency pinned exactly0.83.0(matching the host) and bundled inline by tsup —diststays zero-runtime-deps (verified: no bare pi-tui import remains in the bundle).src/log.ts):\r/\nin string fields (includingError.stack) are escaped to literals, so every acp.log entry occupies exactly one physical line —grep nudge-injectednow returns the full nudge body instead of just the headline.Tests (4 new; full suite green)
formatNudgeRecordunit — exact-string assertions matching the issue example (emergency/non-emergency, tier, missing ranges).undefined(invisible but persisted).log.test.ts— multi-line field values (nudge text + stack trace) stay on one tagged physical line.Verification
npm run typecheck✅npm test✅ — 466 pass / 3 skipped / 0 fail (469 total)npm run build✅ — dist 627 KB, pi-tui fully inlineddist/index.jsin plain node ✅