Parse SSH policies once at request admission
在请求接收处只解析一次 SSH 策略
The [`sandbox` and `fs.write`/`fs.edit` handlers](../../../../packages/ssh/ssh/src/helper.ts) are the private policy resolver's only callers. They validate requests with `policySchema`; the resolver repeats that parse, including a policy and extra-root array copy.
English
Problem
The sandbox and fs.write/fs.edit handlers are the private policy resolver's only callers. They validate requests with policySchema; the resolver repeats that parse, including a policy and extra-root array copy.
Proposal
Accept z.output<typeof policySchema> in the private resolver and remove its parse. Retain both wire parsers, execution-host path resolution, cancellation, SessionId branding, and explicit omission of undefined optional fields. The SSH execution decision continues to own remote policy enforcement.
Alternatives considered
Keep the resolver's unknown input. It protects future unparsed callers, but current callers already decode. A typed parameter states the required precondition without repeated runtime work.
Acceptance criteria
Both request handlers still reject malformed policies, relative roots, and unexpected fields. Remote physical-root checks and returned policies remain unchanged. Existing helper tests cover absent and supplied roots, read-only policy, and denied writes.
Risks
A future wire caller must validate before invoking the resolver. Preserve optional-field omission because Zod permits explicit undefined while the execution-policy type does not.
中文
Problem
sandbox 和 fs.write/fs.edit 处理函数 是私有策略解析器仅有的调用方。它们使用 policySchema 校验请求;解析器重复该解析,包括复制策略对象和额外根目录数组。
Proposal
让私有解析器接收 z.output<typeof policySchema>,移除其中的解析。保留两个线上请求解析器、执行主机上的路径解析、取消、SessionId 品牌类型转换,以及对值为 undefined 的可选字段的显式省略。SSH 执行决策 继续规定远程策略执行。
Alternatives considered
保留解析器的 unknown 输入。 它能保护未来未经解析的调用方,但当前调用方已经解码。类型化参数可表达必要前提,无需重复执行运行时工作。
Acceptance criteria
两个请求处理函数仍拒绝格式错误的策略、相对根目录和意外字段。远程物理根目录检查和返回策略保持不变。现有辅助进程测试覆盖未提供和已提供根目录、只读策略以及被拒绝的写入。
Risks
未来的线上请求调用方必须先校验,再调用解析器。保留可选字段省略,因为 Zod 允许显式 undefined,而执行策略类型不允许。