177 Commits

Author SHA1 Message Date
我也有友人账
53a827ba9f fix(mastery): keep mastery choice clarifications from blocking fresh practice (#3150)
Co-authored-by: wyyyrz <227647791+wyyyrz@users.noreply.github.com>
2026-12-01 21:38:42 +08:00
zszz3
eaf23617b0 fix(prompt): reread shared fragments on cache reset and reject braces
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
2026-12-01 11:17:29 +08:00
zszz3
5961d252e2 refactor: keep each mastery rule in one place, playbook or tool schema
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
2026-12-01 11:17:29 +08:00
zszz3
12e9809a6e fix: reach loaded tools through call_tool instead of growing tools[] mid-turn
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.
2026-11-30 23:35:59 +08:00
zszz3
8f6875225b refactor: move setup turn notes into prompt files
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.
2026-11-30 23:35:08 +08:00
zszz3
d5ac66781f fix: keep chat tools[] and system prompt stable within a session 2026-11-30 23:35:08 +08:00
wojiecihuo
fed428e46a Merge pull request #3079 from zszz3/fix/chat-runtime-snapshots
fix: keep turn data out of the chat system prompt and drop the duplicate tool manifest
2026-11-30 23:21:32 +08:00
Benjamin Schwing
b7dd96d453 fix(mastery): grade concept objectives within covered and own scope (#2363, #2364) (#2366)
* fix(mastery): grade within the objective's covered and own scope

- Reuse the preserved objective-scoped packet for an objective request
  after a focus preparation replaced the live slot, and do not rebuild
  an incomplete objective packet whose fingerprints are unchanged (#2363).
- mastery_assess grades a concept/design explanation against the covered
  facets of an incomplete objective packet, records that scope, and
  returns a structured coverage_gap result instead of a bare refusal.
- Tell the learner when an answer was not recorded or was graded only
  against the covered part.
- Give the judge sibling objectives as out of scope and return the
  single missing element with a next_step to ask for exactly it (#2364).

* test(mastery): cover the focus-only assessment deadlock from #2905

A complete focus-scoped packet with no assessment slot gets a structured
coverage_gap on every repeated mastery_assess, with no judge call and no
recorded evidence. One objective preparation then grades the retained
explanation together with the next reply.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): make the missing-element step the assess instruction

Since dev added a generic instruction to every final mastery_assess
payload, a non-passing verdict carried two competing moves: next_step
asked for exactly the named missing element (#2364) and instruction
asked the learner to explain the objective again. While the gate is not
cleared, the targeted step is now also the instruction, and it says to
record the reply with mastery_assess.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): say when an unclear explanation is kept for grading

A non-final verdict in a session keeps the explanation and grades it
together with the follow-up, so the generic "not recorded, progress
unchanged" notice misled the learner into repeating the whole answer.
Add an assessment_needs_clarification notice (en/zh) for that case; an
explanation outside a session keeps the not_recorded notice.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): preserve the missing assessment element on replay

---------

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
Co-authored-by: Qiuner <wdst3635@163.com>
2026-11-30 06:32:56 -03:00
Alex Castillo González
218dbe31b9 fix(mastery): document observation-only fields in the teaching_updates schema (#2872)
TeachingUpdate.model_json_schema() gave knowledge_point_id, strategy and outcome no description, so models filling a preference also set strategy and the call is rejected by check_semantics. Add per-field descriptions (flat schema kept) and a test.
2026-11-30 01:42:44 +08:00
zszz3
2026ee4f18 fix: keep per-session data out of capability system blocks 2026-11-29 16:32:47 +08:00
Benjamin Schwing
7938c6f40c fix(mastery): accept retained archive ids in tutoring memory coverage (#2947)
The fold prompt lets memory entries cite previously retained archive IDs,
but covered_archive_ids had to equal the newly supplied set exactly. A
model that also lists retained IDs as covered failed every fold, so the
watermark never moved and the session stayed on degraded raw history.

Accept covered IDs that are the newly supplied ones plus IDs the prior
memory already covered or cited. Still reject omitted, invented or unseen
IDs, and store only the newly folded IDs as covered.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
2026-11-28 18:24:06 +08:00
Chih-Kai Wang
1d8be0ddf7 fix(mastery): bind settlement_recovery to lesson_evidence_id instead of path version (#2869)
Co-authored-by: f0909172434 <290806361+f0909172434@users.noreply.github.com>
2026-11-28 18:23:50 +08:00
greenhand-fjm
ffda598f01 fix(setup): require qualified model/engine terms for setup intent (#2986)
Bare 'model', 'engine', 'embedding' and 'vector' are everyday words in a tutoring product (physical models, ML models, word embeddings). A learning question such as '把理想气体模型换成范德瓦尔斯模型,熵的表达式要怎么调整' matched an action word plus one of them, mounted the setup capability, and rewrote the system prompt and tool list mid-conversation. Only qualified forms (language/chat/embedding model, parsing/search engine) now count as a configuration object.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 18:21:11 +08:00
Botong
5f4d878735 fix: 将预读附件全文放在来源清单之前 (#3006)
* fix: 将预读附件全文放在来源清单之前

* fix(explore): tell the model the preloaded text needs no read_source

Without the note the model re-reads the preloaded lecture with read_source on
the upload turn, sending the whole text a second time.

---------

Co-authored-by: zszz3 <91608029+zszz3@users.noreply.github.com>
2026-11-28 13:51:00 +08:00
wojiecihuo
ce831dd4c3 fix: keep sent runtime snapshots in mastery replay, and keep them small (#2992)
* fix: keep sent runtime snapshots in mastery replay

Mastery replay dropped every runtime snapshot from history and the loop
re-appended them after it, so each follow-up request diverged from the
previous one at message 1 and only tools + system hit the prompt cache.

- project_mastery_replay(keep_snapshots=True) for the tutor request and
  its token accounting; memory material still drops snapshots
- replay_group no longer blanks a tagged mastery_status_snapshot while
  removing the legacy fused suffix
- status snapshot anchors are numbered from the start (occurrence), so a
  later snapshot never changes how an earlier turn is projected

Refs #2922

* fix: keep runtime snapshots out of the mastery history budget

Replayed snapshots stay in the request so follow-up turns extend the cached prefix, but counting them made a large mastery_status snapshot push the history over its 20k budget after two turns; the next turn then paid a memory rewrite and a full prefix miss. The budget now measures the learning history only, as before. Refs #2922

* fix: bound the runtime snapshots kept in mastery history

Keeping sent snapshots out of the history budget entirely let many short
exchanges accumulate them without limit (80 quiz-style turns: 5.4k counted,
62k sent). Dialogue still keeps to the plan; dialogue plus snapshots keep to
twice the plan, and only as far as the model's window allows. Refs #2922

* fix: keep only this turn's state in the mastery status snapshot

Every mastery turn sends a fresh mastery_status snapshot and, since the
replay change, keeps earlier ones in history, so whatever a snapshot
carries is paid for once per turn and then kept. A full status read
repeats fixed guidance (open question, question group, working brief,
intake, teaching guidance and focus) and every default value of every
knowledge point.

The snapshot now drops empty and default values and the fixed guidance.
That guidance lives in named constants and is stated once in a new
mastery_status_guide system block, which also explains the omitted
defaults. Snapshots start with a one-line header; history sharing reads
both the header and the longer notice older sessions stored. An explicit
mastery_status call still returns the full payload.

Measured over 54 recorded snapshots: working briefs 1,454 -> 645 tokens
(median), full outline snapshots 6,352 -> 2,954. The guide adds 861
tokens (en) to the cached system prompt.

Refs #2922

* fix: size the exact tail the way the plan does, and share full reads with compact snapshots

Two gaps left by keeping snapshots in mastery replay (review on #2992):

- Recent-history selection counted kept snapshots in full while the plan
  discounted them, so a session of short exchanges with large snapshots
  archived most of them as soon as selection ran. ContextBuilder now sizes
  the candidate tail through _recent_history_tokens(), and the mastery
  builder answers with the same _plan_tokens() measure.
- Snapshots carry the compact form of map, learner_profile, learning_stages
  and visual_requirements, so a later full mastery_status result never matched
  them exactly. Sharing now also compares a full field's compact form and
  marks such references with "defaults_omitted": true, which the state
  reference notice explains.

Also: rename _next to _compact_next_step, and say in the status guide that
the omitted-default rules cover only what the snapshot includes.

Refs #2922
2026-11-28 12:57:21 +08:00
wojiecihuo
779e9da342 fix: keep the mastery prompt prefix stable across mode switches (#2991)
* fix: keep mastery prompt prefix stable across mode switches

* fix: load the outline tools together when a turn switches to outline

A study turn that switched to outline loaded mastery_build alone through load_tools; the next turn, in outline mode, mounts every outline tool eagerly, so its tools[] carried one schema more than the previous request and missed the whole cached prefix. The mode switch now loads the outline group into the live request at once. Refs #2922

* fix: close loaded tool schemas the same way as mounted ones

Mounted schemas go out with additionalProperties: false; a tool loaded through load_tools did not, so the same tool had two byte forms in tools[]. A tool that moved between mounted and loaded across turns (mastery_build/mastery_revise after an outline->study switch) rewrote the start of the cached prefix. Refs #2922

* fix: keep the outline tools on the deferred loader in outline mode too

Outline mode mounted mastery_build/mastery_revise eagerly and skipped the
loader, while study and review reached them through it. On an install with
no other deferred tool that also dropped load_tools on outline turns, so
tools[] changed in both directions around every switch. Refs #2922

* fix: mount mastery navigation from the first mastery turn

The first mastery turn usually creates the topic; navigation mounted only
once a topic existed, so the second turn's tools[] grew by three schemas and
missed the whole cached prefix. Refs #2922

* fix: send only the current mastery mode's rules, as a runtime snapshot

The system prompt carried all three mode sections so a mode switch would
not rewrite the cached prefix, but that showed the model three conflicting
rule sets and relied on a one-line snapshot to pick one. Keep only a short
frame in the system prompt and send the current mode's own section inside
the mastery_session_mode snapshot, which is appended only when the mode
changes.

Refs #2922

* fix: keep capability tools recorded by another turn in the session's loaded set

A mastery turn records its outline tools (mastery_build, mastery_revise) in
the session's loaded_tools.json so a later study turn keeps the same tools[].
A plain chat turn of the same session builds a provider loader without
capability names; with an unrestricted caller it treated those names as
stale and persisted the set without them, so the next mastery turn mounted
fewer tools and re-paid the cached prefix.

DeferredToolLoader now keeps names it cannot serve (registered tools it does
not own, or names outside its allowlist) as retained: never mounted or
reported, but written back with the session state. Only names whose tool is
gone from the registry are dropped.

Refs #2922
2026-11-28 12:20:01 +08:00
Botong
d1ca4f0b55 fix: 按请求统计附件预读的流式 Token 用量 (#3007) 2026-11-27 16:31:24 +08:00
Bingxi Zhao (Frank)
e81f9c866d fix(mastery): save a standalone reference answer for qualitative practice 2026-11-15 01:00:14 +08:00
Bingxi Zhao (Frank)
be4f36c166 fix(mastery): normalize option arrays and clarify grading evidence
Local dev repairs for #2687, #2691. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Bingxi Zhao (Frank)
461093db5f Merge PR #2657: fix: register fresh mastery questions across conversations
Update the status contract for session_id and prove concurrent retries in a fresh session create only one card while retaining the archived question (139 passed).
2026-11-14 23:11:02 +08:00
Bingxi Zhao (Frank)
b1054a2517 Merge PR #2626: fix(mastery): register choice answer by exact option body 2026-11-14 22:58:02 +08:00
Bingxi Zhao (Frank)
ef44b97564 Merge PR #2651: fix(mastery): keep an issued question gradable after its KB is re-indexed (#2650) 2026-11-14 22:58:02 +08:00
Bingxi Zhao (Frank)
97b3d41084 Merge PR #2510: fix(mastery): stop tutoring-memory retries from growing every turn 2026-11-14 22:58:01 +08:00
Bingxi Zhao (Frank)
a76c661bd6 Merge PR #2614: fix(tools): keep web_search/web_fetch mounted in exclusive knowledge turns 2026-11-14 22:52:57 +08:00
maxsheng215-cyber
8f96d48bad fix: register fresh mastery questions across conversations 2026-11-12 16:34:05 -08:00
Benjamin Schwing
2ba6b5d75c fix(mastery): keep an issued question gradable after its KB is re-indexed (#2650)
A pending quiz card stores the source snapshot it was verified against,
including a fingerprint of the whole published KB index. Adding any
document to that KB changed the fingerprint, so every grade failed with
"Prepare the lesson again" - which refreshes only the lesson packet,
never the card - and the learner's answer could not be recorded.

An issued question is now bound to the pages it cites: when the index
changed but each cited page (KB, document, page, source digest) is still
published unchanged, the question validates and is graded. If a cited
page did change, the error says so and names the recovery tools.
Lesson packets and question issuance keep the strict whole-index check;
objective, answer-key and scope gates are unchanged.
2026-11-12 16:49:56 +00:00
JohnnnSinaaa
c4e50815ac test(mastery): cover body-based expected_answer registration 2026-11-11 02:40:01 -08:00
AleFlyX
c26140abf3 fix(explore): bound the pre-pass connection as well as its reads
Opening the response stream was still unbounded, so a provider that hangs
while connecting parked the turn the same way a mid-stream stall did. The
answer loop bounds both halves (agent_loop.py:886 pairs the create() call with
the same _STREAM_IDLE_TIMEOUT_SECONDS the reader uses); mirror that here.
2026-11-11 18:33:25 +08:00
AleFlyX
13164c8200 fix(explore): bound the pre-pass stream so a stalled CLI cannot park a turn
ContextExplorer._call_llm iterated the provider stream with a bare
``async for``. A provider that connects and then stops yielding frames left
that await pending forever, so ``pre_loop`` never returned, the capability
never finished, and the turn stayed ``running``. The lease kept renewing, so
TurnRecoveryService saw a live owner and never claimed it; only an explicit
cancel freed the turn.

The answer loop already bounds its own reads (``_bounded_stream_chunks``,
90s), but the pre-pass runs before that loop starts, so it never inherited
the bound. Give it the same watchdog: on idle, raise
LLMProviderTransportError, which the existing ``except Exception`` around
``_run_loop`` turns into the single-pass briefing fallback.

Refs #2539 (the third attempt left ``running`` is a separate, pre-existing
bug, not the empty-error-message one this session's other PR fixes).
2026-11-11 18:24:57 +08:00
Harsh
f76de28db9 fix(mastery): count the whole memory request against the history plan
The fold loop counted only each exchange's archive text and always folded
the oldest exchange, so one exchange over the plan was sent whole, and
prior learner memory could push a fitting exchange over it.

Fold the longest prefix of whole exchanges whose complete request fits:
prior memory, the system instruction and the exchanges as _summarize()
serializes them, plus a reserve for the length line. If even the oldest
exchange doesn't fit, send no memory call; the watermark stays and the
exchange stays in exact recall.
2026-11-11 11:32:20 +05:30
evan188199-tech
9782043ab3 fix(tools): keep web_search/web_fetch mounted in exclusive knowledge turns
Exclusive knowledge capabilities (obsidian, marginnote4, subagent) dropped
the whole chat built-in surface, including web_search (still shown on in
settings) and the always-on web_fetch. Add a coexisting_tools declaration
to KnowledgeCapability (default empty; the product KBs declare the web
pair), honoured in compose_enabled_tools' exclusive branch under each
tool's usual gate (user toggle / always-on / conditional flag) and the
partner builtin_whitelist, mirroring the #650 KB coexistence. The
capability's system prompt now also names what actually mounted via
coexisting_tools_block, so the model no longer disclaims mounted tools.

Fixes #2612

Signed-off-by: evan188199-tech <238371241+evan188199-tech@users.noreply.github.com>
2026-11-11 11:18:04 +08:00
Harsh
4ddaf9c0aa fix(mastery): stop tutoring-memory retries from growing every turn
A failed tutoring-memory call keeps the watermark, so the next turn
retried with the same backlog plus the newest exchange, and the call
grew without limit (#2496). Fold in only the oldest whole exchanges
that fit one history plan, at least one, and leave the rest
unsummarized so the watermark moves only past what was covered.

Related to #2496
2026-11-07 10:40:37 +05:30
Bingxi Zhao (Frank)
f7041045f3 Merge #2430 visual placeholder handling on the shared tool schema contract 2026-11-06 02:04:52 +08:00
Bingxi Zhao (Frank)
8bda305a43 Merge #2415 from maxsheng215-cyber 2026-11-06 01:56:26 +08:00
Bairan Zhang
a9705b3cc7 fix(mastery): read a source-less placeholder visual as absent
An endpoint that makes optional properties required forces the model to
send visual even for a text card, with every source left blank.
prepare_visual always rejects an unnamed source, so mastery_quiz failed
on every call and no answer card appeared (#2427).

Treat a visual whose sources name no knowledge base, asset, path, hash
or figure as absent, for single cards and group leaves, as #2170 does
for blank resume ids and empty groups. A visual naming any source still
goes through prepare_visual unchanged.
2026-11-04 20:38:45 +08:00
我也有友人账
7b5390ffe0 fix: retry mismatched mastery assessment quotes 2026-11-03 14:46:55 -08:00
x-labb
15c79b4356 fix(mastery): stop retrying a truncated tutoring memory on every turn 2026-11-02 18:44:34 +01:00
Bingxi Zhao
5f5f189c36 Merge pull request #2137 from nandanadileep/oss-harness/issue-2073
fix: Mastery Path re-poses a question the learner already answered correctly (fallback to the one source-verifiable item
2026-10-31 18:59:28 +08:00
Bingxi Zhao
e2625fcd57 Merge pull request #2170 from maxsheng215-cyber/fix/codex-optional-tool-arguments
fix: preserve optional Codex tool arguments for mastery quizzes
2026-10-31 18:28:02 +08:00
Bingxi Zhao
13b63a44f6 Merge pull request #2210 from Rimcat-JA/fix/side-chat-blank-answer-by
fix(turn): accept a blank answer_by so "Ask Dito" side chats start
2026-10-31 17:50:31 +08:00
Bingxi Zhao (Frank)
083a9c9b72 fix(mastery): scope duplicate evidence to exact source and objective 2026-10-31 16:56:13 +08:00
Eapp1e
de8b935df3 fix(capabilities): escape LIKE wildcards in the MarginNote store
search() and linked_objects() fed the caller's text straight into a LIKE
pattern without an ESCAPE clause, so "%" matched every object, "_" matched
every object with a character, and linked_objects("100%") also linked the
object that stores 1000.

Escape the value once and declare ESCAPE '\' on every clause, matching
the other LIKE call sites in the repository.

Signed-off-by: Eapp1e <163811520+Eapp1e@users.noreply.github.com>
2026-10-30 17:40:50 +00:00
Rimcat-JA
f5b288912d fix(turn): accept a blank answer_by so "Ask Dito" side chats start
The web client restates answer_by on every turn and sends "" when Dito
answers (sideChatTurnConfig, QuizFollowupContext). TurnRequest only
accepted an omitted value or partner:/subagent:, so every Dito side chat
failed with "Command does not match the turn protocol."

Read a blank value as None. The field stays in fields_set, so
to_payload() still carries it and the stored hand-off is cleared as the
client intends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 01:49:07 +09:00
我也有友人账
d24648d5ed fix: preserve optional Codex tool arguments for mastery quizzes 2026-10-29 11:42:59 -07:00
Bingxi Zhao (Frank)
e495fd6002 Merge origin/dev and reconcile creation contracts and replay tests 2026-10-29 18:13:47 +08:00
Bingxi Zhao (Frank)
01d7c0ed55 feat: add conversational creation drafts and refresh local dev UI 2026-10-29 18:11:52 +08:00
nandanadileep
7c98b9c1b0 fix: refuse restating a correctly answered mastery 2026-10-28 23:36:28 +00:00
Frank-zhu2000
9a04808c33 fix: follow the OS theme until the user picks one
The first visit stored the detected palette and never listened for
prefers-color-scheme changes, so the theme stopped tracking the OS and
Settings had no System choice.

Do not write that fallback. Subscribe while the preference is missing or
"system", and add a System option in Appearance. New accounts default to
system so Apply does not freeze the snow palette.
2026-10-28 16:31:49 +08:00
Bingxi Zhao (Frank)
9aadac3e3b merge: integrate current dev with modular installation 2026-10-28 01:23:48 +08:00
Bingxi Zhao (Frank)
fbab59acbf feat: modularize installation and enforce feature dependency boundaries 2026-10-28 01:02:29 +08:00