The sanitizer deleted every quote character to unwrap a quoted reply,
so "What's ...?" was shown as "Whats ...?". Only unwrap a matching
outer pair, as the chat and reading hints already do.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix: ignore code fences inside <think> reasoning when parsing JSON
A fence drafted inside a <think> block was picked as the payload before
the reasoning was stripped, so the real JSON after the block was lost.
* fix: decode fence-in-string JSON from the chosen block's offset
The fence-in-string fallback searched the response for the truncated
block text, which can also appear inside a <think> draft, so the draft
was decoded instead of the payload. Keep the chosen fence match's start
offset and decode from there, allowing raw newlines in string values.
Closes#2909.
Omit the fewest eligible historical tool-argument payloads so oversized completed exchanges remain replayable, without touching signed/native provider rounds or durable history.
IndexingRun.document() re-reads the journal and atomically rewrites the
whole .indexing-run.json on every call. The LlamaIndex loader marks each
accepted source "embedding" in a synchronous loop on the event loop, and
publication marks every loaded Document (one per page) "completed" the
same way, so recording n statuses costs O(n^2) bytes of I/O with no
await in between. On a 4,320-document reindex this held the loop for
over 100 s, /health/ready stopped answering, and the desktop supervisor
killed the core.
Add IndexingRun.documents(sources, status, **details), which applies one
status to many sources under a single ownership check and a single
journal write, and use it from the loader, the LlamaIndex publication
step and the RAG service's indexed-file callback. document() now
delegates to it, so single updates behave as before.
Fixes#3046
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Forward embedding-batch progress through DocumentAdder so LlamaIndex folder
syncs and multi-file uploads no longer stay at 0% until the whole batch returns.
Co-authored-by: zhouyao01 <zhouyao01@mucang.cn>
Automatic book language detection matched its English-word cues as bare
substrings, so a topic that only mentioned a place or a subject forced
the book into another language: "energy policy in Germany" and "Berlin
German dialects" became German, "the main English clubs" became English
over the interface language, and any mention of "Traditional Chinese
Medicine" became Traditional Chinese.
Bound the Latin and Cyrillic cues with word boundaries and require the
phrased "in Traditional Chinese" form, matching how every other English
cue is written. CJK cues are unchanged.
Omit optional status on message/reasoning/function_call items when building
Responses requests for the custom binding, so gateways that reject
unknown_parameter inside an HTTP 200 stream no longer fail durable turns.
Keep the bounded HTTP-error retry for other cases.
Co-authored-by: zhouyao01 <zhouyao01@mucang.cn>
Mistral reasoning models return `content` as a list of typed blocks
(thinking + text). `_parse_chunks` joined those lists directly and raised
TypeError, and `_parse` / the streaming content callback passed the raw
list through. Normalise with the existing `_extract_text_content` helper.
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
The quiz panel sends per_type_counts (e.g. choice=3, fill_in_blank=2)
and the planner prompt asks for that exact mix, but _parse_plan only
enforced the allowed types and difficulty. A planner that returned five
choice templates produced a five-choice quiz.
Retype the surplus templates to the types that are still short, keeping
topics, order and difficulty.
* feat(providers): add LiteLLM as a local OpenAI-compatible provider
* test(web): keep LiteLLM on the generic provider-branding fallback
---------
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
* fix(imagegen): prefill image models the providers still serve
The OpenAI image provider prefilled gpt-image-1, which OpenAI retired on 2026-10-23, and OpenRouter prefilled google/gemini-2.5-flash-image-preview, which OpenRouter no longer lists, so a user who kept the prefill got a failing first request. They now prefill gpt-image-2 and google/gemini-3.1-flash-image.
* fix(imagegen): prefill gpt-image-2.6-flare instead of gpt-image-2
OpenAI shuts gpt-image-2 down on 2027-02-10 and names gpt-image-2.6-flare or -sunburst as the replacement; its image guide recommends the 2.6 models for new integrations. Flare is the general, fast-iteration model and uses the same Images API, so the OpenAI prefill moves to it now instead of to another retiring model.
AnthropicProvider and the agentic client's Anthropic adapter fell back to claude-sonnet-4-20250514, which Anthropic retired on 2026-06-15, so an Anthropic binding with no model failed with not_found_error. Both now use one DEFAULT_ANTHROPIC_MODEL constant, claude-sonnet-5-5.
The maths single-source scan reads only prompt packs, capability modules,
capability Markdown prompts (such as notes/prompts/*/system.md) and the
fragment files instead of every file in the package. The zh/en playbook
comparison already checks line by line in
tests/capabilities/test_mastery_prompt_slimming.py.
Refs #2975
PromptManager.clear_cache() and reload_prompts() dropped cached packs but
the fragment lru_cache kept serving the old fragments/*.yaml, so a
reloaded pack still carried the previous rule text. Both now clear it.
Fragments are checked for "{" and "}" when loaded (the expanded text can
pass through str.format()), with a test over every fragment in en and
zh. The notes capability gets a test that its en and zh instructions
include the shared maths rule.
Refs #2975
PromptManager expanded shared fragments inside the try block that guards
reading a prompt file, so an unknown fragment name was caught as a load
failure and the manager quietly served another language's pack (or {}).
A marker that does not match the lowercase name pattern, such as
{{shared:Math}}, was left in the prompt as literal text. Expansion now
runs after the read; unknown names raise KeyError and leftover markers
raise ValueError. A repo scan checks that every marker in a prompt pack
names a fragment present in both en and zh.
Refs #2975
Tool mechanics (teaching_updates evidence, note_explained, grouped quiz
replace/resume, visual sources, option shuffling, repair, skip/defer,
prepare_lesson) now live only in the tool descriptions; the playbook
keeps teaching strategy and when to call which tool. mastery_quiz group
items and the nested revise/profile shapes keep their structure but no
longer repeat every parameter description.
The assessment-result rules added for #2366 move into mastery_assess:
follow a non-passing result's next_step, a coverage_gap result records
nothing and must not trigger unchanged preparation again, and an
incomplete packet is assessed on its covered facets only. The playbook
no longer asks for `passed: true`, which the schema marks as ignored.
An answered pending question is graded from the loop protocol with its
learner_answer and question_id.
The zh playbook is aligned with en line by line: the PDF evidence and
exam practice paragraphs, the multi-turn explanation bullet in its
English position, the registered-assessment wording and the backticked
identifiers. tests/capabilities/test_mastery_prompt_slimming.py checks
the alignment, that each rule is still stated somewhere, and that tool
mechanics are not repeated in the playbook.
Refs #2975
Chat, mastery, question FINISH and notes each carried their own copy of
the dollar-delimiter rule. They now reference {{shared:math_latex}}
(deeptutor/services/prompt/fragments), expanded by PromptManager at load
time; the notes capability expands the marker in its system.md, and
code-built prompts use shared_fragment(). The English notes prompt gains
the rule (and the mermaid line) its Chinese twin already had. The chat
loop no longer repeats the 'concise Markdown' line that runtime_policy
states.
Refs #2975
* fix(mcp): let operators declare Fake-IP ranges for self-service servers
A local proxy in Fake-IP mode (Loon, Clash, Surge) answers DNS for public
hostnames with synthetic private addresses, e.g. fd27:712::/32 from Loon,
and routes the connection by hostname. Strict validation then rejects
public MCP Store entries such as GitMCP as private-network targets.
Add DEEPTUTOR_MCP_FAKE_IP_RANGES (comma separated CIDRs, opt-in, read from
the process environment). In strict mode an address a hostname resolves to
inside a declared range is no longer rejected as private. IP-literal URLs,
loopback and the link-local/metadata ranges stay blocked regardless, and
any other private answer for the same host still fails validation.
Closes#2789
Assisted-by: Claude <noreply@anthropic.com>
* fix(mcp): warn on Fake-IP opt-in and document single-user SSRF trade-offs
Address review feedback from JinhangHE126 on #2857:
Document clearly that DEEPTUTOR_MCP_FAKE_IP_RANGES relaxes hostname-based SSRF protection for hostnames resolving into declared ranges (as the proxy resolves targets and connects).
Emit a startup security warning when DEEPTUTOR_MCP_FAKE_IP_RANGES is set, noting that the setting is intended strictly for single-user/desktop installations.
Assisted-by: Gemini (Google Vertex AI)
OpenAICodexProvider._request_codex called consume_sse without an
on_provider_event hook and built LLMResponse without usage, so Codex turns
were counted as 0 tokens/cost. Collect the terminal usage event and attach it
to the response, as the openai_compat Responses path already does.
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Notebook names, descriptions, record titles and IDs were interpolated
into Rich markup strings, so `notebook show` and `notebook list` altered
bracketed text and crashed with MarkupError on an unmatched closing tag.
Render those values as rich.text.Text instead.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The composer-hint sanitizers used lstrip("-•*# ") to drop list markers,
which also ate the sign of "-3 squared...?", the star of "*args" and
the hash of "#include". Strip a marker only when whitespace follows it.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
CallToolTool answered every unforwarded call with "load it first". That
was wrong for a tool already in tools[] (an MCP tool, a built-in) and for
malformed arguments, and for the former it sent the model round in a
loop. DeferredToolLoader.proxy_refusal now names the reason (missing
name, call_tool itself, already in the tool list, proxy off, unknown,
not loaded) and proxy_arguments checks the arguments: an object, or a
string holding valid JSON for one; anything else is refused. The
pipeline's _resolve_proxied_tool_calls and CallToolTool both go through
proxy_call_refusal, so the message matches the decision.
Setup tools loaded through load_tools are proxied. Opening setup mode
later left them proxied: not in tools[], no rules (already loaded), and
a note that never mentioned call_tool. An opened mode's tools are now
made native, like mastery's outline tools; a setup turn whose tools are
still proxied gets a hint to reach them through call_tool.
Also: call_tool is mounted only when the loader has built-in/capability
tools to proxy; its manifest order no longer duplicates load_tools'; a
forwarded call without an id is not marked for renaming.
Refs #2972
load_tools appended the loaded schema to the end of tools[]. tools[] is the
first thing in the provider's prompt-cache key, so the next request of the
same turn re-processed the system prompt and the whole history.
When the turn mounts the new call_tool builtin, load_tools now returns the
loaded tools' definitions in its result and leaves tools[] alone; the loop
forwards each call_tool call to the named tool before dispatch, so the tool
runs with its own argument checks, injected kwargs and trace, while the
history keeps the model's own call. Tools loaded this way stay proxied for
the session (loaded_tools.json gains proxied_tools). Runtime loads that must
land in tools[] pass native=True; the TypeScript engine keeps the old
behaviour.
The setup protocol (confirm with ask_user before apply_setting, never
handle secrets, ...) reached the model only in the load_tools result or
the turn that opened setup mode. Once history snipping or summarisation
dropped that message, the setup tools stayed in tools[] without their
rules. A setup turn (explicit mode or an intent message) whose capability
already has tools loaded now gets the protocol repeated in its turn note,
and the intent wording says the tools are already loaded.
A partner turn refuses every setup write (setup/access.py can_write), so
the setup tools are no longer listed under Extended Tools or pointed at
by the turn note there. Non-admin users keep them: personal preferences
are still theirs to change.
Also correct the comment about when set_deferral_available runs:
is_active is already asked by the exclusive-capability checks before it.
Refs #2972
The deferred-tool notes imported deeptutor.tools.research_tools on every
turn that had local deferred tools, so a minimal install (setup tools
deferred, no research module) failed the chat turn with
ModuleNotFoundError. Import it only when the research module is enabled,
as the rest of the pipeline already does.
Refs #2972
SetupCapability.turn_note and the legacy setup system block now read the
header, gap-list heading, intro section and explicit/intent/intro leads from
capabilities/setup/prompts/{en,zh}/notes.yaml (overridable under
setup.notes.<key>); the intro section gains a Chinese version. The Extended
Tools manifest header no longer says every entry is supplied by an external
service, since built-in setup and research tools are listed there too.
A KB-list / get_info sweep probes every version-N directory of every KB,
because the UI renders readiness per version. The docstore count cache is
keyed per version directory, so its capacity has to cover the whole
catalogue, not a single KB's worth.
At the old fixed 128 slots a real installation (13 KBs, 310 version
directories -- #2772) exceeded the working set on every sweep: each probe
evicted exactly what it had just read, the hit rate stayed at a permanent
0%, and every UI navigation re-parsed every multi-MB docstore.json. On a
memory-constrained host that showed up as a pinned event loop and hundreds
of GB of disk reads.
Raise the capacity to 4096. Each entry is a path plus an int, so this costs
about a megabyte even well above the working set.
Reproduced against v1.7.3 with a fixture matching the report (13 KBs, 310
versions, 52 MiB of docstore.json), replaying inspect_kb_versions() per KB:
before: 310 / 310 / 310 / 310 / 310 docstore parses per sweep, 0.0% hit rate
after: 310 / 0 / 0 / 0 / 0 docstore parses per sweep, 100% warm
A rewritten docstore still invalidates correctly (doc_count 400 -> 1), and
unchanged versions stay cached. The new regression test builds 2 KBs x 100
versions, which is above the old cap, and fails on the unfixed code
(400 parses instead of 200).
Closes#2772