Commit Graph

12 Commits (37837c00a92d976efe2373c74bd3c232bea8a2aa)

Author SHA1 Message Date
wizardchen b581094c7b fix(web_fetch): address review follow-ups for structured fetch results
Restore HTTP-only 15s pipeline fetching, reject SPA shell pages when
browser rendering fails, surface per-URL failure fields in the UI, and
keep structured model output when all URLs fail.
2026-07-28 22:17:31 +08:00
langcaiye 75a2eabe20 fix(agent): restore safe rendered web fetch fallback 2026-07-28 22:17:31 +08:00
langcaiye a3da5cb57a fix(agent): preserve web evidence when page fetches fail 2026-07-28 22:17:31 +08:00
wizardchen 1320c50bde refactor(knowledge): keep metadata document scoped 2026-07-28 20:23:48 +08:00
wizardchen 718b7347d0 fix(agent): harden search-target scope and model-handle policies
Single SearchTarget must intersect document whitelists with tag scope
instead of treating tags as an independent authorization path. SQL scope
filters now AND document and tag constraints; Agent tools use an explicit
scopeEnforced flag so empty targets fail closed. Also add missing built-in
tool handle policies with drift tests, cache handle regexes at registration,
encode tool error text, and avoid wikiKBIDs slice aliasing.
2026-07-27 11:05:43 +08:00
wizardchen 6663268504 refactor(modelcontext): unify handle terminology and document the merged package
Internal-only rename of the remaining alias-era names (ChunkAlias ->
ChunkHandle, aliasForRealValue -> handleForDurable, realForAlias ->
durableForHandle, OrphanAliases -> OrphanHandles, shortSourceAliasRE ->
shortSourceHandleRE, locals and comments). Exported API names are
unchanged. The README now describes the single-package layout, the
handleTable/streamHold primitives and the sourceKeySpaces policy table.
2026-07-27 11:05:43 +08:00
wizardchen 69b792398e refactor(modelcontext): consolidate stream decoding on one suffix-hold primitive
streamHold captures the shared shape of streaming-safe handle decoding
(withhold a trailing byte run that could still become a handle, decode
what is released, decide the fate of a held tail at close). The resource
decoder, HandleStreamDecoder and the orphan-resource filter become
instances whose hold/flush functions are the original logic moved
verbatim; the citation stream expander stays a dedicated tag parser.

The duplicate res://\d+ regexes merge into resourceHandleShapeRE, all
stream types now live in stream.go, and orphan_stream.go is removed.
2026-07-27 11:05:43 +08:00
wizardchen 213ca0b42e refactor(modelcontext): rebuild every handle space on one generic table
handleTable[M] is the single bidirectional primitive behind all model
handles: source chunks/documents/KBs/web pages, res:// resource handles,
and the exported HandleTable (iN issue handles, ingest ref-N/c000
handles). Metadata lives under the same lock as the mapping, web
references dedup on the canonical URL while decoding to the raw URL, and
the append-only counter preserves historical numbering exactly.

Behavior is unchanged and proven by the moved test suites; the per-space
text-rewrite strategies (plain substring for resources, word-boundary
regex for HandleTable, shape-regex lookup for sources) deliberately stay
in their wrappers because each is load-bearing wire behavior. The unused
ChunkReference.Alias field is dropped — handles are derived from the
table, never stored in metadata.
2026-07-27 11:05:43 +08:00
wizardchen 286eadac0a refactor(modelcontext): unify source-key gating behind one dispatch table
sourceKeySpaces becomes the single table of ID-bearing keys: it drives
handle registration (registerSourceIDByKey) and the alias-decode gate
(walkJSON / unresolved-handle audit), replacing the separate decodableKeys
list that had to be kept in sync by hand. The per-tool sourceIDKeys policy
remains the outer gate; a new test asserts every policy key has a
registration space.

The generic nil-policy wrappers (sourceRegistry.DecodeToolCalls,
EncodeMessages) are removed; the two tests that exercised anonymous-tool
decoding now go through the public Registry with real tool names.
2026-07-27 11:05:43 +08:00
wizardchen 3b9de5de8e refactor(modelcontext): fold llmreference into modelcontext as source codec
Mechanical move: internal/llmreference becomes in-package code.
registry.go splits into sources.go (handle registration, tool-argument
codec, replay encoding) and citations.go (protocol prompts, <ref/> ->
<kb/>/<web/> expansion, stream expander); model_output.go moves verbatim.

Renames only: Registry -> sourceRegistry, StreamExpander ->
citationStreamExpander, ProtocolPrompt -> sourceProtocolPrompt,
ToolArgumentPolicy -> toolArgumentPolicy. ChunkReference becomes a native
modelcontext type (was an alias). Unreferenced DocumentAlias,
KnowledgeBaseAlias and ExpandResponse are dropped. Tests move intact.
2026-07-27 11:05:43 +08:00
wizardchen c01b00313b refactor(modelcontext): fold llmresource into modelcontext as resource codec
Mechanical move: internal/llmresource/registry.go becomes
internal/modelcontext/resources.go with Registry renamed to
resourceRegistry and StreamDecoder to resourceStreamDecoder. No logic
changes; the unused DecodeResponse method is dropped. Tests move intact.
2026-07-27 11:05:43 +08:00
wizardchen 5e413c6478 refactor(agent): introduce modelcontext registry and fix handle-codec bugs
Unify request-local model-handle handling behind a single
modelcontext.Registry (source citations, durable resource handles, wiki
issue handles) with per-tool argument policies and unresolved-handle
rejection before tool execution.

Also fixes issues found in review:
- decode wiki_read_issue's iN issue_id argument (was never resolved)
- preserve stored wiki page aliases when wiki_write_page omits aliases
- validate http/https scheme before registering url fields as web sources
- gate tool-role MultiContent text behind the tool result policy
- dedup KB IDs in NewWikiScopesFromKBIDs to avoid false ambiguity
- remove dead codec facades (decodeJSON, EncodeMessagesWithPolicy,
  UnresolvedToolHandles)
2026-07-27 11:05:43 +08:00