- Plan card (📋): per-session message-scan with `plan_scan_baseline` so
`/continue` of a finished session doesn't auto-resurrect old plan cards;
prefers `<summary>当前步骤:` over the long plan-item echo; placeholder
while enter_plan_mode is armed but plan.md hasn't been written yet.
- Done annotation (⠿ {Verb} for Xm Ys · ↑ N · ↓ M): post-turn elapsed
+ per-call token deltas, frozen at done so the line stays put across
re-mounts. Spinner annotation gated on cumulative deltas past stream-start
baselines — fixes `↓ 16` showing immediately on prompt submit.
- fold_turns regex anchored to line-start (`^` + MULTILINE) so embedded
backticks in tool output (e.g. `N|\`\`\`\`` gutter from file_read) don't
pair with later real fences. ~100x faster on long /continue sessions.
- /cost: per-session card + `/cost all`; `Context window` line now reads
GA's actual char cap via `cost_tracker.context_window_chars(backend)` =
`backend.context_win * 3` (the `trim_messages_history` trigger threshold
in llmcore.py), so the percentage reflects real budget and respects
`mykey.py` overrides. Unit changes from token to character. Dropped the
model-theoretical `_CTX_LIMITS` table (never actually constrained anything).
Subagent log scan via `cost_tracker.scan_subagent_logs` aggregates
`temp/*/stdout.log` since TUI start.
- /review: standalone in-session reviewer; reuses `review_cmd.handle`
to render the inline prompt and submits as a normal user task.
- llmcore: emit `[Output] tokens=N` for chat_completions / responses modes
(already emitted for `messages` SSE) so cost_tracker scopes output
tokens uniformly across all three API modes.
- review_inline_prompt.{txt,en.txt}: filled out the in-session review
discipline — Three Iron Rules, Q1-Q4 framing, severity examples,
8 false-positive rules expanded, 8 wording rules expanded, 8-item
self-check. ZH/EN both grow ~80 lines.
- memory/review_sop.md: rewrite 52 → 191 lines, 11 sections covering
quick-start, entry files, Three Iron Rules, 5-step workflow, severity,
output protocol, relationship to plan_sop / verify_sop. Style mirrors
plan_sop.md + autonomous_operation_sop.md.
Files: frontends/{tuiapp_v2,tuiapp,cost_tracker,plan_state}.py, llmcore.py,
memory/review_sop.md, memory/review_sop/review_inline_prompt.{txt,en.txt},
.gitignore (allowlist new SOP).
Co-authored-by: Shen Hao <shenhao-stu@users.noreply.github.com>
`self.model` was pinned to `_sessions[0].model` at init; after failover the
topbar (and any other reader of `agent.get_llm_name(model=True)`) kept showing
the primary's model name even when `_cur_idx` had moved to a fallback session.
Convert to a property returning the current session's model. `_BROADCAST_ATTRS`
doesn't include `model`, and grep finds no external writes, so making it
read-only is safe.
Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com>
When the model only outputs tool calls with no meaningful text,
combined_content may contain only whitespace text blocks (e.g. '\n').
Strict API proxies reject this with HTTP 400 'empty content' error.
Filter out such blocks before sending to the API.
- llmcore: prefix all error outputs with !!! marker
- ga: detect !!!Error: [SSL: in tail of content as incomplete response and retry
- add len(content)>100 guard to avoid false positives on short responses
Anthropic's extended thinking streaming protocol emits two delta types
for a single thinking block: `thinking_delta` (the textual reasoning)
and `signature_delta` (a base64 HMAC tag appended at the end of the
block). Both must be accumulated into the same `content_block`.
Current code only handles `thinking_delta`, so `signature_delta` events
are silently dropped. When the assistant's reply (with thinking) is
echoed back on the next turn, Anthropic's server validates the
signature and rejects the request with 400:
"Invalid `signature` in `thinking` block"
Downstream effects observed in production (via sub2api relay logs):
- Every request with history triggers a 400 signature error
- The relay strips thinking blocks and retries, which changes the
cache prefix and invalidates prompt caching, forcing a full rebuild
of cache_creation_tokens (~20k-30k per affected request)
- Measured in a 5h window: 5/25 requests suffered cache invalidation,
accounting for 53.5% of total spend that was otherwise avoidable
Fix:
1. Initialize `current_block` with an empty `signature` field when a
thinking block starts, so the dict shape matches Anthropic's spec
(`{type, thinking, signature}`).
2. Handle `signature_delta` events by appending `delta.signature` to
`current_block["signature"]`. Using `+=` (rather than assignment)
mirrors how `thinking_delta` is accumulated and is robust against
future chunked signatures.
No behavior change for clients that disable extended thinking, or for
upstreams that don't emit `signature_delta`. For `tool_use` threads
that require valid thinking signatures to preserve reasoning context,
this fix is required — the previous behavior silently corrupted them.
Verification:
- Before fix: upstream returns 400 + retry; cache_creation_tokens
spike to ~25k on every 4th-5th request in a conversation
- After fix: upstream accepts the first attempt; cache_read_tokens
dominate, cache_creation_tokens only appear on the first request
of a fresh 5m prompt-cache window