Expand description
Script-tier adapter (P1) — the runtime law for global script tools
(script.{name}) and the plugin script form.
Spec text: phimint/notes/tool-socket-design.md, sections
“global script tool entry / script runtime semantics”:
- Absolute path pinning (anti-shadowing):
run[0]must be an absolute path. The only exception is the interpreter whitelist (powershell/pwsh/cmd), in which case the script file argument must be an absolute path (powershell: after-File/-f; cmd: after/c). A relative path = running that other project’s same-named script in that project; rejected at definition/install time. - Scripts inside plugins obey the same law: package-relative paths are
resolved to absolute paths at install time by
pin_from_plugin_rootand pinned (lexical normalization + escape from the plugin root → reject). - argv spawn, no shell:
runsubstitutes${param}per element; a missing or non-scalar parameter → tool error for that call (fail-closed); parameter values are not re-expanded. - cwd = current project root (pinned at product-layer registration in
ScriptToolEntry::cwd; the framework does not sniff paths); env = inherited + entry overrides. - timeout defaults to 60s; on timeout the whole process tree is killed
(POSIX process group +
killpg; Windowstaskkill /T /F+CREATE_NO_WINDOW). - Output exceeding
max_output_charsreuses the kernel-tools truncation convention (first 1/3 + last 2/3 +...[output truncated]; the convention is copied verbatim, no cross-crate code import). - exit ≠ 0 → tool error (with a stderr summary). If the script file is gone at execution time → a “script is gone” error, no silent file swap.
Structs§
- Param
Spec - A single parameter:
{ "type": "string", "description": "…" }. - Script
Provider - Global script tool supply: namespace
script.{name}, a name → entry table. - Script
Tool - A single script tool (plugs into the
Tooltable;Box::leaknaming follows the existingMcpToolAdapterprecedent). - Script
Tool Entry - A script tool entry (one row of tools.json / one row of the plugin manifest
scriptform).
Enums§
- Exposure
Spec - Tool-table budget tier (
ToolExposurehas no serde; the author-facing side uses this string form). - Param
Type - Parameter-table entry (the author-facing side of plugin manifest / tools.json): scalars only.
- Script
LawError - Path-law violation at definition/install time. Fail-closed: reject what is illegal, no compromises.
Constants§
- DEFAULT_
TIMEOUT_ MS - Default timeout (milliseconds).
- INTERPRETER_
WHITELIST - Interpreter whitelist: the only exception where
run[0]need not be an absolute path.
Functions§
- check_
run_ law - Path law (anti-shadowing):
run[0]is an absolute path, or the interpreter whitelist + an absolute script file argument. - check_
script_ file_ on_ disk - Script file check at install/mount time (fail-closed, the same law as a missing wasm file): it must be a regular file; when the script body is executed directly it must also have the executable bit on unix.
- execute_
entry - Execute one script entry (shared by
ScriptProvider/ScriptTool/ the future pluginscriptform). - parameters_
envelope - Parameter table → JSON Schema envelope:
type: object+ properties + required=all +additionalProperties: false(in v1 all parameters are de facto required, see contract §appendix 3). - pin_
from_ plugin_ root - Plugin script pinning at install time: resolve the script file element to an absolute path under the plugin root, then enforce the path law.
- resolve_
under_ root - Resolve an in-plugin path (relative to the plugin root) to an absolute path and pin it.
- script_
file_ index - Index of the “script file” element: interpreter → its script argument position; otherwise 0.
- script_
file_ is_ program - Whether the script body is
run[0]itself (non-interpreter form). Interpreter form →false(the script is read in, no executable bit needed). Invalid/empty errors out on the same criteria ascheck_run_law. - substitute_
params ${param}substitution per element (argv, no shell).