Skip to content

feat(plugin): local scene-memory reader (tdai_read_local) + guarded read_cos - #774

Open
YOMXXX wants to merge 2 commits into
TencentCloud:feat/server_teamfrom
YOMXXX:fix/762-local-scene-reader
Open

feat(plugin): local scene-memory reader (tdai_read_local) + guarded read_cos#774
YOMXXX wants to merge 2 commits into
TencentCloud:feat/server_teamfrom
YOMXXX:fix/762-local-scene-reader

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Aug 4, 2026

Copy link
Copy Markdown

Closes #762.

Problem

For COS-less local deployments the scene-detail read tool tdai_read_cos is the only way to open scene-memory files, but it always fails without COS:

  • format.ts injects only the scene path index, and the guide advertises tdai_read_cos
  • index.ts registers tdai_read_cos unconditionally — a tool that is guaranteed to fail, wasting AI call budget

Result: the AI "knows a scene exists but can't recall the details".

Change

Commit 1 — feat(plugin): add tdai_read_local tool with path-safety checks

  • New src/tools/read-local.ts: reads a local file by relative path from a configured root
  • Security: rejects empty/absolute (POSIX + Windows drive-letter/UNC) and any .. traversal, plus a resolve+relative containment check (defense-in-depth)

Commit 2 — feat(plugin): guard scene-detail tools by storage.localDir

  • openclaw.plugin.json: new storage.localDir config field
  • index.ts: registers exactly one read tool — tdai_read_local when storage.localDir is set (local mode), otherwise tdai_read_cos (default COS mode). No longer registers a tool that is guaranteed to fail.
  • format.ts / recall.ts: the memory-tools guide and Scene Navigation hint are now dynamic, guiding the tool that is actually registered (tdai_read_cos / tdai_read_local, or neither)
  • README (CN/EN): document storage.localDir

Tests

vitest added to openclaw-plugin (first tests for this package):

  • src/tools/read-local.test.ts — 9 tests: path-safety (traversal, absolute, drive-letter, UNC, blank) + local reads (nested block, missing file, rejected paths)
  • src/format.test.ts — 4 tests: guide/hint reflect readTool (local / default cos / none)

npm test: 2 files, 13 tests, all passing. npm run build (tsc) passes.

Behavior summary

storage.localDir registered read tool prompt guide
unset (default) tdai_read_cos tdai_read_cos
set to a local dir tdai_read_local tdai_read_local
(both missing) no read-tool guidance

YOMXXX added 2 commits August 4, 2026 20:21
New tool for COS-less deployments: reads scene-memory files (persona.md,
scene_blocks/*.md) from a configured local directory by relative path.
Security checks reject absolute paths (POSIX + Windows drive-letter/UNC)
and any ".." traversal, with a resolve+relative containment check as
defense-in-depth.

Part of TencentCloud#762

Signed-off-by: 李冠辰 <liguanchen@xiaomi.com>
The scene-detail read tool is now registered based on deployment:
- storage.localDir set -> register tdai_read_local (local mode)
- otherwise -> register tdai_read_cos (default COS mode)

This stops registering a read tool that is guaranteed to fail, and the
memory-tools guide + Scene Navigation hint in the injected prompt now
reflect the tool that actually exists.

- openclaw.plugin.json: new storage.localDir config field
- format.ts / recall.ts: dynamic tools guide by ReadTool
- README (CN/EN): document storage.localDir
- vitest added for the plugin; 13 tests cover path safety + dynamic guide

Closes TencentCloud#762

Signed-off-by: 李冠辰 <liguanchen@xiaomi.com>
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thanks for your attention! We will schedule an internal review as soon as possible.

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.

[Feature] Add a local scene-memory read tool for COS-less deployments, and guard read_cos registration

2 participants