refactor(sandbox-policy): resolve policies only for Sessions; callers build maintenance policies
Review of the consumers layer: - `SandboxPolicyRequest.root` is removed. `resolve` answers only for a Session. `prepare` accepts a Session or a checkout directory and returns that checkout's validated Git administration directories. The worktree service builds the policy of removal and restoration itself: the Session's mode and grants, the source checkout as the root, and that checkout's derived directories. The forge panel swaps the root for its two reads of the source repository. - The Git layout reads move to `src/linked-checkout.ts` with direct tests; the security rationale stays in the README, which the function comment links. - `resolve` and the model-visible policy share one merge of configured, registered, and derived writable roots. - `workspace-files` takes a live Session's root from the sandbox policy instead of repeating its fallback chain. - `TurnRecorder` takes a fixed directory and an explicit `moveTo`, which the plugin calls on `workspace-root/change`; each turn keeps its own canonical paths. A real-sandbox test restores a missing worktree of a linked source checkout in a process that never worked in it.
This commit is contained in:
1 parent
0ae2613c98
commit
e3cd2edebf
33 files changed
+373
-256
No files matched your search
@@ -2907,8 +2907,8 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
{
|
||||
signature: 'resolve(request: SandboxPolicyRequest = {}): SandboxExecutionPolicy',
|
||||
description: 'Resolve the complete policy for one capability call. An approved explicit mode outranks the session\'s last `sandbox/mode` event, which outranks the deployment default. A session\'s workspace root is its workspace-write boundary, and the Git administration directories prepare derived for that root join the configured extra writable directories; the configured root is the fallback for agentless calls and, without the working-directory service, sessions without a header directory, and a requested `root` replaces the session\'s root for the call. Configured extra roots, this Session\'s active registrations, and the derived Git directories are snapshotted together; existing operations and processes keep their policy.',
|
||||
parameters: [{ name: 'request', description: 'optional session, approved mode override, and root override.' }],
|
||||
description: 'Resolve the complete policy for one capability call. An approved explicit mode outranks the session\'s last `sandbox/mode` event, which outranks the deployment default. A session\'s workspace root is its workspace-write boundary, and the Git administration directories prepare derived for that root join the configured extra writable directories; the configured root is the fallback for agentless calls and, without the working-directory service, sessions without a header directory. Configured extra roots, this Session\'s active registrations, and the derived Git directories are snapshotted together; existing operations and processes keep their policy.',
|
||||
parameters: [{ name: 'request', description: 'optional session and approved mode override.' }],
|
||||
returns: 'the fully resolved per-call mode, absolute workspace root, and extra writable directories.',
|
||||
throws: ['`SandboxInvalidRootError` (`SANDBOX_INVALID_ROOT`) when the selected root is relative or contains a NUL byte.'],
|
||||
},
|
||||
@@ -2926,10 +2926,11 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
returns: 'the last logged mode, or `undefined` without one.',
|
||||
},
|
||||
{
|
||||
signature: 'async prepare(request: Pick<SandboxPolicyRequest, \'session\' | \'root\'>, signal?: AbortSignal): Promise<readonly string[]>',
|
||||
description: 'Derive the Git administration directories of the session\'s workspace root so the next resolve grants them: a linked checkout\'s `.git` file names `<common>/worktrees/<name>`, whose `commondir` names the repository\'s common directory and whose `gitdir` names the checkout\'s `.git` again; only that layout grants the common directory, since the checkout\'s own `.git` pointer is writable under workspace-write. Any other layout, a root without `.git`, and a common directory containing the root add nothing. One derivation runs per root and its result is kept once the layout was read, so a pointer written later does not widen the policy until a Host operation moves a Session\'s workspace to that root again; a derived directory that disappears is derived again, and a failed read is logged once per root and retried on the next call.',
|
||||
parameters: [{ name: 'request', description: 'session whose workspace root is inspected, or the root {@link resolve} would select for the same request.' }, { name: 'signal', description: 'caller cancellation, checked before and after the shared derivation.' }],
|
||||
returns: 'the derived directories outside the root, canonical in the execution world.',
|
||||
signature: 'async prepare(target: { session: Session } | { directory: string }, signal?: AbortSignal): Promise<readonly string[]>',
|
||||
description: 'Derive the Git administration directories a linked checkout writes outside itself, as `./linked-checkout.ts` reads them. For a Session the checkout is its workspace root, and the next resolve for that Session grants the result. For a named `directory`, a Host operation that runs in a checkout no Session works in adds the result to the policy it builds; `resolve` is unaffected. One derivation runs per directory and its result is kept once the layout was read, so a pointer written later does not widen a policy until a Host operation moves a Session\'s workspace to that directory again; a derived directory that disappears is derived again, and a failed read is logged once per directory and retried on the next call.',
|
||||
parameters: [{ name: 'target', description: 'Session whose workspace root is inspected, or the checkout directory itself.' }, { name: 'signal', description: 'caller cancellation, checked before and after the shared derivation.' }],
|
||||
returns: 'the derived directories outside the checkout, canonical in the execution world.',
|
||||
throws: ['`SandboxInvalidRootError` (`SANDBOX_INVALID_ROOT`) when the directory is relative or contains a NUL byte.'],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -4984,7 +4985,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
methods: [
|
||||
{
|
||||
signature: 'scopeOf(sessionId: SessionId, signal?: AbortSignal): Promise<WorkspaceFileScope | undefined>',
|
||||
description: 'Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses: a live Session\'s directory, else a stored Session\'s cached directory, else its header directory.',
|
||||
description: 'Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses: a live Session\'s sandbox workspace root, else a stored Session\'s cached directory, else its header directory.',
|
||||
parameters: [{ name: 'sessionId', description: 'Session identity received on the wire.' }, { name: 'signal', description: 'cancellation for the persistence read of a stored Session.' }],
|
||||
returns: 'the scope, or undefined when no live or stored Session has that identity.',
|
||||
},
|
||||
@@ -9000,7 +9001,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
},
|
||||
{
|
||||
name: 'SandboxPolicyRequest',
|
||||
declaration: 'export interface SandboxPolicyRequest {\n session?: Session;\n mode?: SandboxMode;\n root?: string;\n}',
|
||||
declaration: 'export interface SandboxPolicyRequest {\n session?: Session;\n mode?: SandboxMode;\n}',
|
||||
},
|
||||
{
|
||||
name: 'SaveFileAttachment',
|
||||
|
||||
Reference in new issue
Block a user