Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

1.3 KB
Raw Blame
import { sensitiveReadBoundary } from "@pibot/execution";
import type { ExecutionLocationTarget } from "@pibot/protocol-base";
import { abortable } from "../../core/abort.ts";
import type { LocalService } from "../../local-service.ts";

/**
 * Brain's part of the protected write list, handed to policy and read only when a
 * write leaves every workplace or Windows scans command text. Exec's sensitive roots are the same
 * list the command sandbox denies reading; the data directory holds every Bot's files, keys and databases.
 *
 * Only for this computer: a runner's paths are not checkable on a card and an editor terminal
 * (ACP) has no sandbox to open a single folder in, so both keep the hard refusal.
 */
export function protectedWriteRoots(
  local: LocalService,
  target: ExecutionLocationTarget | undefined,
  workplaceHome: string,
) {
  if (target !== undefined && target !== "local") return undefined;
  return async (signal: AbortSignal): Promise<readonly string[]> => {
    const boundary = await abortable(
      sensitiveReadBoundary(
        local.deps.platform,
        [local.deps.userHome, workplaceHome],
        local.deps.env,
      ),
      AbortSignal.any([signal, AbortSignal.timeout(20_000)]),
    );
    return [...boundary.denyRead, local.deps.dataDir];
  };
}