Commit Graph
117 Commits
Author SHA1 Message Date
Shen HaoandShen Hao 3b67919561 feat(tui v2): plan card + done annotation + /cost + /review wiring (#411)
- 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>
2026-05-18 08:20:52 +08:00
d 🔹andd 🔹 1f83fd11ea fix(llmcore): MixinSession.model tracks current session, not first (closes #394) (#401)
`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>
2026-05-17 21:26:29 +08:00
Liang Jiaqing eecb8ee35a refactor: parameterize compress/trim intervals, add stop/kill subagent actions, remove web/pet CLI commands 2026-05-15 12:18:33 +08:00
Liang Jiaqing 438e8fc4dd conductor: cleanup style, filter aborted agents, add auto-cleanup thread; llmcore: conditional _drop_unsigned_thinking for non-claude models; task_planning: minor edit 2026-05-14 22:55:50 +08:00
Liang Jiaqing a9c6ab42c7 feat: add conductor system, code_review_principles; update llmcore, supervisor_sop, goal_mode constraints, gitignore whitelist 2026-05-13 23:02:52 +08:00
Jiaqing Liang e4c39b16d3 feat: tighten context budget - maxlen 15k, trim refactor with staged compress 2026-05-13 23:02:52 +08:00
Liang Jiaqing b6617afb2e fix: prevent empty response from corrupting history & add _fix_messages to non-native paths 2026-05-09 17:28:11 +08:00
Liang Jiaqing 14f50a2a59 fix: avoid empty content messages in native tool flow 2026-05-09 16:28:44 +08:00
wangjc683 1416f70efb fix: filter whitespace-only text blocks in NativeToolClient.chat() (#307)
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.
2026-05-09 10:41:29 +08:00
Liang Jiaqing e5265a03dc tuiapp: cache rendered panels; llmcore: simplify fast_ask 2026-05-07 22:18:25 +08:00
Liang Jiaqing 0a2be47c00 refactor: simplify LLM client init with resolve_client; add fast_ask; auto-fold old tasks in TUI 2026-05-07 21:06:14 +08:00
Liang Jiaqing 6fd7e2d7a0 feat: add Textual TUI frontend + minor fixes to agentmain/llmcore/stapp 2026-05-07 17:38:58 +08:00
Liang Jiaqing 5aaa26e69b file_write: support content arg in native mode, strip it in text-emulated mode 2026-05-06 10:30:08 +08:00
Liang Jiaqing 26d5fc6781 feat: auto-inject summary text block when model outputs thinking+tool_use without text; stapp fallback uses content preview 2026-05-03 12:22:05 +08:00
Liang Jiaqing 52a53e44c0 fix: clear _pending_tool_ids when history is empty to prevent orphan tool_result after /new 2026-05-02 21:05:51 +08:00
Liang Jiaqing 60b1112960 fix: include earlier_context in compress_history_tags pattern 2026-05-02 20:46:16 +08:00
Liang Jiaqing a405a02238 add official channel disclaimer; fix scroll/wechat-md/llm-msg 2026-05-01 08:41:10 +08:00
Liang Jiaqing 3da34d2f58 cleanup: remove NextWillSummary, add supervisor_sop, fix streaming fence protection, tighten L1 rules 2026-04-29 13:29:03 +08:00
Liang Jiaqing 0f2d1d3165 refactor: deduplicate _parse_mixed_response by reusing _parse_text_tool_calls; fix orphan tool_result in _fix_messages 2026-04-28 22:15:07 +08:00
Liang Jiaqing 4e41b15972 统一流重试行为: 不管mixin/非mixin中途断连都重试; 更新ga.py错误检测条件 2026-04-28 20:41:14 +08:00
Liang Jiaqing 2e4775f98a refactor: extract _stream_with_retry, MixinSession failover on stream abort 2026-04-28 17:54:37 +08:00
Liang Jiaqing 340d663b77 feat: add SSL verify option and enable TG draft 2026-04-27 18:15:57 +08:00
Jiaqing Liang eb3fa0041f feat: ensure thinking blocks for deepseek models in history 2026-04-27 15:11:09 +08:00
Jiaqing Liang 624058d25c refactor: _openai_stream takes sess+messages; add service_tier support 2026-04-27 15:11:08 +08:00
Liang Jiaqing e07c1b046b hotreload mykeys, fix SSE residual block, unify context_win, cleanup 2026-04-26 17:46:24 +08:00
Liang Jiaqing ea757b4ea3 fix: summary提取与fold_turns防误切,强化thinking模型summary输出 2026-04-26 00:01:42 +08:00
Liang Jiaqing f1537de52b tg: support document upload, disable draft streaming; wx: streaming flush during task; llmcore: safeprint, max_tokens fixes 2026-04-25 21:33:38 +08:00
Jiaqing Liang 1686312f93 Remove responses max output token limit 2026-04-25 14:03:21 +08:00
Jiaqing Liang 5c9a60c1d1 fix: _drop_unsigned_thinking对str content崩溃 + _to_responses_input丢弃thinking-only assistant消息导致tool_call被吞 2026-04-25 13:53:08 +08:00
Liang Jiaqing 53e2f0a4d5 fix: use correct token limit params for OpenAI APIs 2026-04-25 10:54:44 +08:00
Liang Jiaqing 492d55788a feat: reasoning/thinking互通适配 + history窗口扩大 + summary提示强化 2026-04-25 10:33:42 +08:00
Liang Jiaqing 7ac7538181 add uv install guide & pyproject.toml; unify error prefix to !!!Error: 2026-04-24 10:00:23 +08:00
Liang Jiaqing ef82265f4a fix: SSE tool_call streaming compat for non-standard index/id, MockToolCall handle list args & None fallback; sop: CDP bringToFront note 2026-04-23 23:44:50 +08:00
Liang Jiaqing 1444a273fe Fix responses call_id mapping for converted tool history 2026-04-23 20:53:44 +08:00
Liang Jiaqing 6e68fa41cf refactor: unify system prompt injection into _openai_stream; disable gpt done_hooks 2026-04-23 20:07:20 +08:00
Jiaqing Liang a5aca5988e fix: add requests to pip install & tune max_turns/prompt 2026-04-23 17:21:22 +08:00
Liang Jiaqing 7a88664733 fix: split concatenated JSON tool args in _parse_openai_sse to prevent _raw death spiral 2026-04-23 11:53:35 +08:00
Liang Jiaqing 5b886ccf7b fix: agent-level retry for intermittent SSL errors during streaming
- 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
2026-04-23 11:24:54 +08:00
Liang Jiaqing 4c1268d821 fix: guard all id/call_id fields with or "" to prevent None leaking into payload 2026-04-23 11:00:04 +08:00
Liang Jiaqing 63dac0406c fix: filter empty text blocks in message conversion & add prompt continuation line 2026-04-22 19:37:06 +08:00
Liang Jiaqing 8ec9d6015b Normalize OAI messages before conversion and update tool-call prompt 2026-04-22 17:16:05 +08:00
song b4e7c88d5e fix(llmcore): preserve thinking block signature in streaming SSE parser (#123)
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
2026-04-21 12:07:14 +08:00
Jiaqing Liang 27203ee5e6 refactor: plugins dir + opt-in langfuse via __getattr__ guard
- mv langfuse_tracing.py -> plugins/langfuse_tracing.py
- llmcore: load plugin lazily inside __getattr__ when langfuse_config present
  (PEP 562 module __getattr__ naturally fires only once after globals().update)
- llmcore: extract _record_usage() from 4 scattered [Cache] print sites
- agentmain: /resume scans only latest 10 files
2026-04-20 15:56:06 +08:00
totoyangandtotoyang 793a0637a8 feat: optional Langfuse tracing for agent execution (#115)
Self-activating langfuse tracing via monkey-patch: independent module, zero impact when langfuse_config unset. Captures LLM generation, tool calls, token usage from SSE streams.

Co-authored-by: totoyang
2026-04-20 15:27:55 +08:00
Liang Jiaqing 5869022302 refactor: simplify HTTP error handling in _openai_stream, add non-stream support, broadcast history in MixinSession 2026-04-19 20:57:07 +08:00
Liang Jiaqing ba3c5144e9 Revert "Merge pull request #108 from ggandmee-cloud/feat/cch-signing"
This reverts commit 3e61155b33, reversing
changes made to 4abb8e205d.
2026-04-19 16:18:45 +08:00
Shen Hao 8632afaec8 [feat]: Add user agent configuration to llmcore 2026-04-19 15:38:41 +08:00
LJQ 599a1b6536 Merge pull request #108 from ggandmee-cloud/feat/cch-signing
feat: NativeClaudeSession 在 fake_cc_system_prompt 模式下支持可选 CCH 签名
2026-04-19 15:27:13 +08:00
ggandmee-cloud 9bb7570f43 feat: NativeClaudeSession 加入 CCH 签名
匹配真实 Claude Code 客户端协议,兼容需要验证客户端身份的代理。
2026-04-19 01:20:01 -04:00
Liang Jiaqing 638c7f5a0e 清理SOP: web_setup去TM方案, tmwebdriver排查流程优化 2026-04-19 11:16:29 +08:00