[PR #6290] [MERGED] feat: let capability packages contribute tools the model can call #7127

Closed
opened 2026-10-23 04:16:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6290
Author: @BiBoBaBe
Created: 9/17/2026
Status: ✅ Merged
Merged: 9/17/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/capability-tools


📝 Commits (10+)

  • ad64851 feat: let capability packages contribute tools the model can call
  • 6a34791 fix: resolve review findings on package-contributed tools
  • 1363f9a fix: enforce the capability API floor for the tools permission
  • ad97d80 fix: bound package tools in time, size and lifetime
  • 16c9652 fix: bound package tool contracts and preserve activation ownership
  • 609f40b fix: reserve custom tool names when chat tools are disabled
  • bd0c51e fix: keep enabled custom tool ownership while schemas are repaired
  • 64de526 test: handle an empty resolved tool set in collision proof
  • f6441eb fix(tools): keep turns without tools free of custom-tool reads
  • a03b64a docs(capabilities): clarify cooperative deadline limits

📊 Changes

11 files changed (+931 additions, -46 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/development/optional-agent-packages.md (+82 -0)
📝 packages/server/src/services/capability-packages/capability-module-runtime.service.ts (+43 -5)
➕ packages/server/src/services/capability-packages/capability-tool-registry.service.ts (+214 -0)
📝 packages/server/src/services/generation/tool-resolution-runtime.ts (+63 -4)
➕ packages/server/src/services/tools/tool-arguments-validator.ts (+38 -0)
📝 packages/server/src/services/tools/tool-executor.ts (+27 -31)
📝 packages/shared/src/schemas/capability-package.schema.ts (+20 -1)
📝 scripts/regressions/capability-package-lifecycle.regression.ts (+5 -5)
➕ scripts/regressions/capability-tool-runtime.regression.ts (+366 -0)
📝 scripts/regressions/game-mode-dice-tool.regression.ts (+71 -0)

📄 Description

Linked issue

Closes #6292. Original contribution by @BiBoBaBe; maintainer follow-up by @SpicyMarinara with Codex.

Why this change

Packages that manage a world, clock or inventory need structured model actions. They can now register tools with JSON Schema arguments, receive validated calls and return results while narration continues to stream.

What changed

  • Add api.registerTool behind the explicit tools permission, manifest schema v2 and Capability API 1.19. Reuse the existing argument validator and tool executor.
  • Preserve built-in and enabled custom-tool ownership, including while a custom schema needs repair. Respect provider support for native tools even when ordinary chat tools are disabled.
  • Snapshot schemas at registration and bound names, definitions and results. Stop waiting after 10 seconds; remove the retiring activation's tools before bounded cleanup, preserving newer registrations.

Maintainer decisions: registration is global while the package is active, consistent with prompt-context contributions. Handlers receive chatId and must check their own state. The verified server entrypoint already pins the registration code; this change adds no second declarative manifest. Descriptions and results are trusted package content; results are limited to 64 KiB. A timed-out handler continues running, although the turn stops waiting.

Validation

Combined staging candidate 44b7363f4: all 290/290 Node regressions passed, with final server type/lint checks passing. The package-tool regression found by the full suite is fixed with the existing early return when no tools need loading. The schedule browser flow passes on desktop Chromium, mobile Chromium and mobile WebKit.

Executed: pnpm check, subsequent server type/lint checks, package lifecycle, tool execution and Game tool resolution regressions. New cases cover schema mutation, provider capability, custom/package collisions with tools enabled and disabled, invalid custom schemas, lifecycle cleanup and result limits. The schema mutation and unsupported-provider cases reproduced failures before the fixes.

Local CodeRabbit completed the combined feature review. The remaining GitHub suggestion requests synchronous package isolation; the documented trusted in-process contract is retained. Its asynchronous deadlines cannot interrupt an event-loop-blocking callback. The code comment and API documentation now state that ceiling explicitly, including all ten translated packs. A worker/process RPC redesign is outside this tool-registration feature and the maintainer’s minimal-change request.

Contributor checklist retained from the original submission

These are the contributor's existing checkbox states, retained unchanged. They are not new maintainer attestations. Current maintainer verification is described above; the unchecked maintainer checklist remains below.

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Maintainer checklist

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Manually verify a real package with a native-tool provider: narration, valid and invalid arguments, deactivation and a chat without installed package tools. Runtime tests use synthetic handlers; they do not exercise a live model provider.

Docs and release impact

Canonical API documentation and CHANGELOG are updated. All ten translated packs are in #6297, resolving #6296. No product version bump.

UI evidence (if applicable)

No client UI changes.

Final local review

CodeRabbit reviewed all 36 files of the combined staging candidate. This PR had no substantive findings. Its suggestion to replace narrow source guards for private activation wiring is deferred: runtime registration, execution, collisions and lifecycle behavior already have runnable coverage, and changing the fixture architecture would broaden this feature. Final pnpm check and all 290 Node regressions passed on the combined candidate.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6290 **Author:** [@BiBoBaBe](https://github.com/BiBoBaBe) **Created:** 9/17/2026 **Status:** ✅ Merged **Merged:** 9/17/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/capability-tools` --- ### 📝 Commits (10+) - [`ad64851`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad64851692a979d58855c99f284c34b2b217c524) feat: let capability packages contribute tools the model can call - [`6a34791`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6a34791bc9d6b0e788295942269a3f5803ca00cd) fix: resolve review findings on package-contributed tools - [`1363f9a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1363f9a75089066ffca5a85025bf1a5da1618e70) fix: enforce the capability API floor for the tools permission - [`ad97d80`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad97d80b2eea8cc0ab7142e9834a1cb35fd685f0) fix: bound package tools in time, size and lifetime - [`16c9652`](https://github.com/Pasta-Devs/Marinara-Engine/commit/16c9652faade52be24b12f39fa07ed37d82871b2) fix: bound package tool contracts and preserve activation ownership - [`609f40b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/609f40b87a931c239b56977f9b1e8de1ad4a72d6) fix: reserve custom tool names when chat tools are disabled - [`bd0c51e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd0c51e48ddbc5d70e75d6ed3260dd9ec2e2b390) fix: keep enabled custom tool ownership while schemas are repaired - [`64de526`](https://github.com/Pasta-Devs/Marinara-Engine/commit/64de526e0b1430b3307a3e4d8d0975fa112250d2) test: handle an empty resolved tool set in collision proof - [`f6441eb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f6441eb8e836a84821b3671d02ceded5d6e7eb70) fix(tools): keep turns without tools free of custom-tool reads - [`a03b64a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a03b64ad907dfa02c3b970ed2241ff44f238c724) docs(capabilities): clarify cooperative deadline limits ### 📊 Changes **11 files changed** (+931 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/development/optional-agent-packages.md` (+82 -0) 📝 `packages/server/src/services/capability-packages/capability-module-runtime.service.ts` (+43 -5) ➕ `packages/server/src/services/capability-packages/capability-tool-registry.service.ts` (+214 -0) 📝 `packages/server/src/services/generation/tool-resolution-runtime.ts` (+63 -4) ➕ `packages/server/src/services/tools/tool-arguments-validator.ts` (+38 -0) 📝 `packages/server/src/services/tools/tool-executor.ts` (+27 -31) 📝 `packages/shared/src/schemas/capability-package.schema.ts` (+20 -1) 📝 `scripts/regressions/capability-package-lifecycle.regression.ts` (+5 -5) ➕ `scripts/regressions/capability-tool-runtime.regression.ts` (+366 -0) 📝 `scripts/regressions/game-mode-dice-tool.regression.ts` (+71 -0) </details> ### 📄 Description ## Linked issue Closes #6292. Original contribution by @BiBoBaBe; maintainer follow-up by @SpicyMarinara with Codex. ## Why this change Packages that manage a world, clock or inventory need structured model actions. They can now register tools with JSON Schema arguments, receive validated calls and return results while narration continues to stream. ## What changed - Add `api.registerTool` behind the explicit `tools` permission, manifest schema v2 and Capability API 1.19. Reuse the existing argument validator and tool executor. - Preserve built-in and enabled custom-tool ownership, including while a custom schema needs repair. Respect provider support for native tools even when ordinary chat tools are disabled. - Snapshot schemas at registration and bound names, definitions and results. Stop waiting after 10 seconds; remove the retiring activation's tools before bounded cleanup, preserving newer registrations. Maintainer decisions: registration is global while the package is active, consistent with prompt-context contributions. Handlers receive `chatId` and must check their own state. The verified server entrypoint already pins the registration code; this change adds no second declarative manifest. Descriptions and results are trusted package content; results are limited to 64 KiB. A timed-out handler continues running, although the turn stops waiting. ## Validation Combined staging candidate `44b7363f4`: all **290/290 Node regressions passed**, with final server type/lint checks passing. The package-tool regression found by the full suite is fixed with the existing early return when no tools need loading. The schedule browser flow passes on desktop Chromium, mobile Chromium and mobile WebKit. Executed: `pnpm check`, subsequent server type/lint checks, package lifecycle, tool execution and Game tool resolution regressions. New cases cover schema mutation, provider capability, custom/package collisions with tools enabled and disabled, invalid custom schemas, lifecycle cleanup and result limits. The schema mutation and unsupported-provider cases reproduced failures before the fixes. Local CodeRabbit completed the combined feature review. The remaining GitHub suggestion requests synchronous package isolation; the documented trusted in-process contract is retained. Its asynchronous deadlines cannot interrupt an event-loop-blocking callback. The code comment and API documentation now state that ceiling explicitly, including all ten translated packs. A worker/process RPC redesign is outside this tool-registration feature and the maintainer’s minimal-change request. ### Contributor checklist retained from the original submission These are the contributor's existing checkbox states, retained unchanged. They are not new maintainer attestations. Current maintainer verification is described above; the unchecked maintainer checklist remains below. - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Maintainer checklist - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Manually verify a real package with a native-tool provider: narration, valid and invalid arguments, deactivation and a chat without installed package tools. Runtime tests use synthetic handlers; they do not exercise a live model provider. ## Docs and release impact Canonical API documentation and CHANGELOG are updated. All ten translated packs are in #6297, resolving #6296. No product version bump. ## UI evidence (if applicable) No client UI changes. ### Final local review CodeRabbit reviewed all 36 files of the combined staging candidate. This PR had no substantive findings. Its suggestion to replace narrow source guards for private activation wiring is deferred: runtime registration, execution, collisions and lifecycle behavior already have runnable coverage, and changing the fixture architecture would broaden this feature. Final `pnpm check` and all 290 Node regressions passed on the combined candidate. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:16:46 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7127
No description provided.