mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { hasTrustRequiringProjectResources, ProjectTrustStore } from "@earendil-works/pi-coding-agent";
|
||||
import type { ProjectTrustStatus } from "./api-types";
|
||||
import { isManagedRuntime } from "./app-runtime";
|
||||
|
||||
export function getProjectTrustStatus(cwd: string, agentDir: string): ProjectTrustStatus {
|
||||
if (isManagedRuntime()) return { requiresTrust: false, trusted: false };
|
||||
const requiresTrust = Boolean(cwd) && hasTrustRequiringProjectResources(cwd);
|
||||
if (!requiresTrust) return { requiresTrust: false, trusted: true };
|
||||
|
||||
const trustStore = new ProjectTrustStore(agentDir);
|
||||
return {
|
||||
requiresTrust: true,
|
||||
trusted: trustStore.get(cwd) === true,
|
||||
};
|
||||
}
|
||||
|
||||
export function trustProject(cwd: string, agentDir: string): ProjectTrustStatus {
|
||||
if (isManagedRuntime()) return { requiresTrust: false, trusted: false };
|
||||
const status = getProjectTrustStatus(cwd, agentDir);
|
||||
if (!status.requiresTrust) return status;
|
||||
|
||||
new ProjectTrustStore(agentDir).set(cwd, true);
|
||||
return { requiresTrust: true, trusted: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload options that gate project-local, trust-requiring resources — a
|
||||
* repository's `.pi/extensions`, project `.pi/settings.json` extension
|
||||
* entries, and `.agents/skills` — behind the SDK's project-trust store.
|
||||
*
|
||||
* Pi Web *executes* project extensions when it builds session services: their
|
||||
* factory runs on import and their `session_start` handlers run on startup.
|
||||
* Without a trust gate, merely opening an untrusted repository in Pi Web runs
|
||||
* repository-controlled code locally (issue #236). The SDK's resource loader
|
||||
* only imports project extensions once `resolveProjectTrust` resolves true, so
|
||||
* denying trust keeps them dormant.
|
||||
*
|
||||
* Pi Web and the `pi` CLI share the same trust store. Projects with gated
|
||||
* resources default to untrusted until either client records a trust decision.
|
||||
* Returns `undefined` when the project has no trust-requiring resources,
|
||||
* leaving ordinary projects on their existing load path.
|
||||
*/
|
||||
export function projectTrustReloadOptions(
|
||||
cwd: string,
|
||||
agentDir: string,
|
||||
): { resolveProjectTrust: () => Promise<boolean> } | undefined {
|
||||
if (isManagedRuntime()) return { resolveProjectTrust: async () => false };
|
||||
const status = getProjectTrustStatus(cwd, agentDir);
|
||||
if (!status.requiresTrust) return undefined;
|
||||
const trustStore = new ProjectTrustStore(agentDir);
|
||||
return { resolveProjectTrust: async () => trustStore.get(cwd) === true };
|
||||
}
|
||||
Reference in New Issue
Block a user