agent_works/script_tool/mod.rs
1//! Script-tier adapter (P1) — the runtime law for global script tools
2//! (`script.{name}`) and the plugin `script` form.
3//!
4//! Spec text: `phimint/notes/tool-socket-design.md`, sections
5//! "global script tool entry / script runtime semantics":
6//!
7//! - **Absolute path pinning (anti-shadowing)**: `run[0]` must be an absolute
8//! path. The only exception is the interpreter whitelist
9//! (`powershell` / `pwsh` / `cmd`), in which case the **script file argument**
10//! must be an absolute path (powershell: after `-File`/`-f`; cmd: after `/c`).
11//! A relative path = running that other project's same-named script in that
12//! project; rejected at definition/install time.
13//! - **Scripts inside plugins obey the same law**: package-relative paths are
14//! resolved to absolute paths at install time by [`pin_from_plugin_root`]
15//! and pinned (lexical normalization + escape from the plugin root → reject).
16//! - **argv spawn, no shell**: `run` substitutes `${param}` per element; a
17//! missing or non-scalar parameter → tool error for that call (fail-closed);
18//! parameter values are not re-expanded.
19//! - cwd = current project root (pinned at product-layer registration in
20//! [`ScriptToolEntry::cwd`]; the framework does not sniff paths);
21//! env = inherited + entry overrides.
22//! - timeout defaults to 60s; on timeout the **whole process tree** is killed
23//! (POSIX process group + `killpg`; Windows `taskkill /T /F` +
24//! `CREATE_NO_WINDOW`).
25//! - Output exceeding `max_output_chars` reuses the kernel-tools truncation
26//! convention (first 1/3 + last 2/3 + `...[output truncated]`; the convention
27//! is copied verbatim, no cross-crate code import).
28//! - exit ≠ 0 → tool error (with a stderr summary). If the script file is gone
29//! at execution time → a "script is gone" error, **no silent file swap**.
30
31/// Default timeout (milliseconds).
32pub const DEFAULT_TIMEOUT_MS: u64 = 60_000;
33
34/// Interpreter whitelist: the **only** exception where `run[0]` need not be an absolute path.
35pub const INTERPRETER_WHITELIST: [&str; 3] = ["powershell", "pwsh", "cmd"];
36
37/// Output truncation marker (same convention as phi-kernel-tools `local_shell::truncate_output`).
38/// The elision marker of the output truncation convention (one vocabulary
39/// across the family: kernel tools, script tools, code cells).
40pub(crate) const TRUNCATION_MARKER: &str = "...[output truncated]";
41
42mod exec;
43mod law;
44mod provider;
45mod subst;
46mod types;
47
48pub use exec::execute_entry;
49pub use law::{
50 ScriptLawError, check_run_law, check_script_file_on_disk, pin_from_plugin_root,
51 resolve_under_root, script_file_index, script_file_is_program,
52};
53pub use provider::{ScriptProvider, ScriptTool};
54pub use subst::substitute_params;
55pub use types::{ExposureSpec, ParamSpec, ParamType, ScriptToolEntry, parameters_envelope};
56
57// The `code-exec` feature form consumes this re-export (code_act /
58// code_cell); the default-form lint cannot see those consumers.
59#[allow(unused_imports)]
60pub(crate) use exec::truncate_output;
61
62#[cfg(test)]
63mod tests;