Skip to content

feat(tools): aggregate sema_search/sema_reindex/sema_stats into one action tool - #9

Open
dearbld wants to merge 2 commits into
JohnXu22786:mainfrom
dearbld:pr-1
Open

dearbld wants to merge 2 commits into
JohnXu22786:mainfrom
dearbld:pr-1

Conversation

@dearbld

@dearbld dearbld commented Sep 9, 2026

Copy link
Copy Markdown

Aggregate sema_search / sema_reindex / sema_stats into one action tool

Base: upstream 601c3f5 (the commit this fork tracks) · stacked series: this PR → pr-2 → pr-4 → pr-5 → pr-3

Motivation

Three flat tool registrations mean three JSON schemas injected into every model round, for a plugin whose actions share one subject (the index). The harness itself aggregates same-family tools behind an action parameter (its built-in code_intel), and this plugin fits the same shape naturally: sema(action=search|stats|reindex).

What changes

  • src/tools.ts: the three tools' execute and render logic is kept verbatim (moved into execSearch / execReindex / execStats and the three render helpers); only the tool surface collapses into one sema tool.
    • Parameters are the union of the three schemas with per-action descriptions.
    • The output schema root stays open (additionalProperties: true) because the canonical value shape differs per action; an internal __act field records which sub-tool produced the value so render dispatches. Note the schema compiler rejects an omitted additionalProperties, so the explicit value is required, not stylistic.
  • src/index.ts: header comment updated (registers one aggregated tool).
  • tests/plugin.test.ts: registration and end-to-end tests updated to call the aggregated tool with action.

Before / after

// before
return [searchTool, reindexTool, statsTool]   // 3 schemas every round

// after
return [semaTool]                             // 1 schema; action picks the sub-tool

Tool output rendering is unchanged from the model's perspective — each action renders exactly as its former flat tool did (including the sema_search: / sema_stats: render prefixes).

Testing

  • tsc --noEmit clean under the repo tsconfig (strict + noUncheckedIndexedAccess).
  • Full suite 80/80 pass with the updated tests.
  • Suggested: assert the rendered blocks of all three actions byte-identical to the pre-aggregation renders (the render helpers are lifted verbatim, so this should hold trivially).

…ction tool

Collapse the three flat tool registrations into a single
sema(action=search|stats|reindex) tool. The execute and render logic of
the three former tools is kept verbatim; only the tool surface changes,
so three per-round schema payloads become one. The open output schema
root records the producing sub-tool via __act so render dispatches; an
explicit additionalProperties value is required by the dsh schema
compiler.

【中文】将 sema_search/sema_reindex/sema_stats 三件平铺工具聚合为
sema(action=search|stats|reindex) 单件。三件原工具的 execute 与
render 逻辑逐字保留,仅收敛工具面——每轮注入 schema 从三件降为
一件。输出 schema 根保持开放(additionalProperties 显式声明——
dsh schema 编译器拒省略态),内部 __act 字段记录产出子工具供
render 分发。
@JohnXu22786

Copy link
Copy Markdown
Owner

DSH should remain the primary host, and I accept the single sema(action=...) direction. Please keep that direction, but tighten the contract: make action a required enum, reject unknown actions instead of silently treating them as search, require a non-empty query for search, and update both README.md and README.zh.md with the new API. Compatibility with the old tool names is secondary; it is not the main objection.

Per review: tighten the contract so action is a closed set instead of a
free-form string. The parameter schema now declares
enum: [search, stats, reindex] — the dsh tool wrapper enforces it before
execute runs (bogus actions throw ToolArgsError instead of silently
running a search). A runtime guard inside execute keeps the rejection
explicit even if args arrive unvalidated, and render surfaces rejected
values as plain text via the no-__act branch instead of falling through
to the search renderer. Test added covering both layers.

按评审意见收紧契约:action 从开放字符串改为必填枚举。参数 schema
声明 enum: [search, stats, reindex],由 dsh 工具包装层在 execute 前
强制(未知值抛 ToolArgsError,不再静默回退 search);execute 内保留
运行时拒绝作为防御纵深;render 对无 __act 的拒绝值走纯文本出口。
新增测试覆盖两层。
@dearbld

dearbld commented Sep 15, 2026

Copy link
Copy Markdown
Author

Addressed in 9cef5e0: action is now a required enum ([search, stats, reindex]) in the parameter schema. The dsh tool wrapper enforces it before execute runs — a bogus action now throws a validation error instead of silently running a search. A runtime guard inside execute keeps the rejection explicit as defense in depth, and render surfaces rejected values as plain text (the no-__act branch) instead of falling through to the search renderer. Test added covering both layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants