Skip to main content

Module script_tool

Module script_tool 

Source
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_root and pinned (lexical normalization + escape from the plugin root → reject).
  • argv spawn, no shell: run substitutes ${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; Windows taskkill /T /F + CREATE_NO_WINDOW).
  • Output exceeding max_output_chars reuses 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§

ParamSpec
A single parameter: { "type": "string", "description": "…" }.
ScriptProvider
Global script tool supply: namespace script.{name}, a name → entry table.
ScriptTool
A single script tool (plugs into the Tool table; Box::leak naming follows the existing McpToolAdapter precedent).
ScriptToolEntry
A script tool entry (one row of tools.json / one row of the plugin manifest script form).

Enums§

ExposureSpec
Tool-table budget tier (ToolExposure has no serde; the author-facing side uses this string form).
ParamType
Parameter-table entry (the author-facing side of plugin manifest / tools.json): scalars only.
ScriptLawError
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 plugin script form).
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 as check_run_law.
substitute_params
${param} substitution per element (argv, no shell).