Commit Graph

204 Commits

Author SHA1 Message Date
NCBM 6e9e034de4 core/agent: derive pending_retry_text from trailing user message
Drop stored pending field; incomplete turns are just history ending in
UserChatMessage. Compact seeds use an assistant summary so they are not
mistaken for retryable orphans.
2026-07-15 11:27:29 +08:00
NCBM 00a8ed3a9c core/agent+cli: persist user immediately; /retry reuses DB turn
Keep incomplete user messages in memory/DB; roll back only
assistant/tool on failure. /retry and resume of orphan-user sessions
re-run without duplicating the user message.
2026-07-15 11:21:01 +08:00
NCBM b1223c8189 core/agent: calibrate soft-compact with last-request prompt_tokens
After the first model call, scale char-based token estimates by
API/resolved prompt size so budget checks track near-real tokens.
/compact uses the same calibration when available.
2026-07-15 11:11:15 +08:00
NCBM c9e805f38d core/agent+cli: treat last-request prompt_tokens as context size
context_tokens prefers API usage from the last model call; char est.
is only a pre-call fallback. Clarify billed turn/session totals in UI.
2026-07-15 11:07:52 +08:00
NCBM a61b536243 core/agent+cli: separate last-request usage from billed turn totals
Tool-loop rounds re-send history, so summed prompt tokens are billing
not context size. Track last_request_usage and label turn/session as
billed; clarify /status and end-of-turn lines.
2026-07-15 11:04:41 +08:00
NCBM 58041c6c87 core/agent+config: soft context budget in estimated tokens
Replace max_context_chars with max_context_tokens (default 200k est.
tokens via char/4); compact and /status use the token budget.
2026-07-15 10:58:01 +08:00
NCBM d2cab4198b core/cli: show estimated context tokens and usage source tags
/status adds context_tokens~=(est); docs note api/estimate/mixed labels.
2026-07-15 10:52:58 +08:00
NCBM 6bdf7ea283 core/agent: always emit UsageEvent with api or estimate
Every model round yields usage; prefer provider usage, else estimate
from request messages and assistant content.
2026-07-15 10:52:48 +08:00
NCBM 0a3127454d core/agent: char-based token estimate fallback for usage
When API usage is missing, estimate prompt/completion tokens at ~4
chars per token and mark source as estimate (or mixed when combined).
2026-07-15 10:52:37 +08:00
NCBM d81e168f3b core/agent+cli: accumulate usage and show on turn end /status
ChatAgent tracks session_usage and last_turn_usage; CLI prints a quiet
token line after successful turns and includes totals in /status.
2026-07-15 10:48:07 +08:00
NCBM 28b6767b32 core/agent: emit UsageEvent from stream and non-stream rounds
Request stream_options.include_usage; yield usage after each model
completion when the provider reports it.
2026-07-15 10:47:59 +08:00
NCBM 2ae7aa0e05 core/agent: add TokenUsage and API usage parser
Parse OpenAI-compatible usage dicts into prompt/completion/total counts
for session and turn aggregation.
2026-07-15 10:47:51 +08:00
NCBM d5e7c3aa53 core/lmproto: await async AsyncResponse.content
niquests exposes content as an async property; reading it without await
left a coroutine warning and skipped the body. Only load body on HTTP
errors for streams so SSE is not consumed early.
2026-07-15 10:41:33 +08:00
NCBM a78791b3a9 core/lmproto: extract pure SSE helpers; drop fake response tests
Test sse_data_payload and http_error_message with plain bytes instead
of a cast-heavy AsyncResponse double.
2026-07-15 10:38:17 +08:00
NCBM 5c13e06427 ci/lint: per-file ignores for tests in ruff and basedpyright
Relax ANN/ARG/PLR/C901 and related rules under tests/**; silence noisy
basedpyright reports for test fakes and private helpers.
2026-07-15 10:35:30 +08:00
NCBM c5745e0711 core/lmproto: stop SSE stream at data: [DONE]
Previously DONE was skipped with continue, so keep-alive connections
could hang forever after the model finished. Also fail fast on HTTP
error statuses for stream and non-stream completions.
2026-07-15 10:33:47 +08:00
NCBM 5a610f9280 core/cli: flush stdout on assistant text deltas
Ensure streamed tokens appear immediately in the TTY.
2026-07-15 10:27:56 +08:00
NCBM 4741341888 core/agent: yield stream text deltas as chunks arrive
Stop buffering the full SSE response before emitting TextDeltaEvent so
CLI/UI can render assistant output token-by-token.
2026-07-15 10:27:49 +08:00
NCBM 53ac1c8d44 docs: drop edit_patch from roadmap
Model-generated patches are unreliable; keep line/string edit tools
instead of a patch apply path.
2026-07-15 10:24:06 +08:00
NCBM 0ab1a7f953 core/tools: include VCS_TOOLS in DEFAULT_TOOLS
Wire vcs tools into the default agent registry and document the
extensible backend design.
2026-07-15 10:22:07 +08:00
NCBM 5b4d3985b7 core/tools/vcs: add read-only vcs_* agent tools
Expose vcs_kind/status/diff/log/branch over detect_vcs; cover git and
custom detector registration.
2026-07-15 10:22:00 +08:00
NCBM c402555778 core/tools/vcs: add VcsBackend protocol, detectors, and git backend
Read-only protocol with pluggable detectors; git via CLI (status,
diff, log, branch). Other VCS systems register detectors later.
2026-07-15 10:21:53 +08:00
NCBM f1ea392c1c core/tools: register glob_paths and grep_files in DEFAULT_TOOLS
Wire new search tools into FILE_TOOLS and document them.
2026-07-15 10:15:26 +08:00
NCBM c2d132de09 core/tools/file: add grep_files regex content search
Line-oriented regex search under the workspace; skip VCS/hidden/binary
and cap match count.
2026-07-15 10:15:20 +08:00
NCBM 007efdef5a core/tools/file: add glob_paths workspace search tool
Stdlib Path.glob with VCS/hidden skip and match cap; paths relative to
workspace root.
2026-07-15 10:15:13 +08:00
NCBM 6e1820d150 docs: roadmap notes for Phase D and usage v2 in F
Record that context is char-estimate-only for now; defer real usage
accounting to Phase F (no separate local-tokenizer stage).
2026-07-15 10:12:08 +08:00
NCBM 3215a5cc35 core/cli: show context char estimate in /status
Surface soft budget usage (context_chars and tool_result_max) for
Phase D without introducing a local tokenizer.
2026-07-15 10:12:01 +08:00
NCBM 001619d9dd core/cli+agent: /compact and resume latest by workspace recency
Soft-compact history, model-summarize without tools, seed a new session;
/resume with no id loads the lately-used session for this workspace.
2026-07-15 10:03:22 +08:00
NCBM 19128735a2 core/memory: order sessions by recency and touch on activity
List/get-latest by updated_at; bump updated_at when messages are
appended so workspace resume picks the lately-used session.
2026-07-15 10:03:15 +08:00
NCBM a7d9c9879b core/cli+agent: run TTY confirms off the event loop
Max-rounds and destructive-tool prompts use asyncio.to_thread with
cancel paused on the main thread so multi-tool turns no longer look
like user cancel. Hooks may be sync or async.
2026-07-15 09:41:32 +08:00
NCBM b80ebf783a core/cli+memory: prompt on session workspace mismatch
When /resume or --session hits a different directory, ask keep (switch
tools root), update binding to current, or abort. Legacy unbound
sessions attach to the current workspace.
2026-07-15 09:33:39 +08:00
NCBM ede7dcccd6 core/cli: scope sessions to workspace directory
Create/resume/list sessions for the current workspace; resume rejects
mismatched workspace bindings.
2026-07-15 00:01:00 +08:00
NCBM 0a2dac2561 core/memory: bind sessions to workspace path with SQLite migrate
Add session.workspace column, create/list filters, and ALTER TABLE
migration for existing chat databases.
2026-07-15 00:00:50 +08:00
NCBM 566a06c996 core/cli: pause turn cancel during TTY confirm prompts
Max-rounds and destructive-tool confirms no longer cancel the in-flight
turn; SIGINT during the prompt aborts only the confirm.
2026-07-15 00:00:40 +08:00
NCBM f31032b801 core/agent+cli: wire max_context_chars and re-raise CancelledError
Propagate context budget from [agent] config; preserve cancel through
tool invoke for mid-turn interruption.
2026-07-14 23:42:55 +08:00
NCBM 5cfe4d6a24 core/agent: soft context compact and cooperative cancel points
Shrink older tool dumps for model requests without mutating history;
check task cancellation between tool/model steps.
2026-07-14 23:42:50 +08:00
NCBM 1da3e92f7c core/agent: enrich ErrorEvent and CancelledEvent metadata
Add retryable/source on errors and optional reason on cancel; show them
in the CLI renderer.
2026-07-14 23:42:44 +08:00
NCBM bcfd1098f8 core/cli+config: confirm destructive tools and path denylist
Wire [agent] confirm_destructive / path_denylist into CLI; default
confirm prompt denies; document Phase C safety hooks.
2026-07-14 23:30:17 +08:00
NCBM 35e89c4dcc core/agent: optional confirm hook on ToolRegistry execute
Serialise dangerous-tool prompts under a lock so parallel tool rounds
cannot race the TTY confirm.
2026-07-14 23:30:10 +08:00
NCBM 510dd67a54 core/tools: classify destructive tools and clarify policy denies
Add classify_danger for delete/move/overwrite paths, get_path_denylist,
and clearer path/command denial messages.
2026-07-14 23:30:02 +08:00
NCBM 81a30d0e4d core/tools/file: add edit_lineno line-range edit tool
1-based inclusive range replace/delete/append; document Phase B agent
and tool updates in CLAUDE.md.
2026-07-14 23:24:34 +08:00
NCBM 3363ab928b core/agent+cli: wire system prompt and agent budgets
ChatAgent accepts system_prompt, result budget, and parallel_tools;
CLI loads them from config [agent].
2026-07-14 23:24:23 +08:00
NCBM 9ec06c7398 core/config: add [agent] section for profile defaults
Parse and sync system_prompt, max_tool_result_chars, and parallel_tools.
2026-07-14 23:24:17 +08:00
NCBM b1964951ea core/agent: parallel tool calls and tool-result char budget
Truncate large tool outputs and run multiple tool calls in one round
concurrently when enabled.
2026-07-14 23:24:11 +08:00
NCBM a1cfc54f8e core/lmproto: await streaming AsyncResponse close
Support both sync and async close/aclose so stream cleanup does not
leave un-awaited coroutines.
2026-07-14 23:24:05 +08:00
NCBM bd6d98ceda core/lmproto+agent: stream via chat_completions(stream=True)
Keep library async-def→async-iterator shape; remove raw-lines path;
typed StreamToolCallDelta merge; scripted clients emit real chunks.
2026-07-14 22:40:24 +08:00
NCBM 4548828354 core/lmproto+agent: use normal stream API for chat loop
Accept async-def returning async iterator; stream via
chat_completions(..., stream=True); typed StreamToolCallDelta merge;
update scripted test clients to emit real chunks.
2026-07-14 22:40:15 +08:00
NCBM e6300cde43 ci/lint: enable strictGenericNarrowing; type-clean stream merge
strictGenericNarrowing=true; rewrite raw SSE tool-call merge with
typed Mapping helpers so basedpyright is warning-free.
2026-07-14 22:27:44 +08:00
NCBM bdb52bdef5 test/agent: cover merge_stream_tool_calls accumulation 2026-07-14 22:22:22 +08:00
NCBM e063efda20 core/agent: fix Phase A streaming await bug and polish
Do not await async generators for raw SSE; close stream on cancel;
merge tool calls without relying only on finish_reason; quieter tool
output; /status slash command.
2026-07-14 22:22:14 +08:00