@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
71 lines • 3.17 kB
JavaScript
import { APP_NAME, CONFIG_DIR_NAME } from "../config.js";
import { emitProjectTrustEvent } from "./extensions/runner.js";
import { getProjectTrustOptions, getSavedProjectTrust, hasTrustRequiringProjectResources, } from "./trust-manager.js";
/**
* Full access means no prompt anywhere (sisyphuslabs/omo-desktop-app#2465): a session whose
* permission preset is explicitly `full-access` trusts its project for that session. Explicit
* means the session's `permission-preset` flag (CLI, or `open_session.permissionPreset` through
* the launch profile), else the user's global setting. Project settings never count: they are what
* trust gates. The implicit default never counts either, so a plain launch keeps asking.
*/
export function presetTrustsProject(presetFlag, globalPreset) {
if (typeof presetFlag === "string")
return presetFlag === "full-access";
return globalPreset === "full-access";
}
function formatProjectTrustPrompt(cwd) {
return `Trust project folder?\n${cwd}\n\nThis allows ${APP_NAME} to load ${CONFIG_DIR_NAME} settings and resources, install missing project packages, and execute project extensions.`;
}
async function selectProjectTrustOption(cwd, ctx) {
const options = getProjectTrustOptions(cwd, { includeSessionOnly: true });
const selected = await ctx.ui.select(formatProjectTrustPrompt(cwd), options.map((option) => option.label));
return options.find((option) => option.label === selected);
}
async function saveProjectTrustPromptResult(trustStore, result) {
if (result.updates.length > 0) {
await trustStore.setMany(result.updates);
}
}
export async function resolveProjectTrusted(options) {
if (options.trustOverride !== undefined) {
return options.trustOverride;
}
if (!hasTrustRequiringProjectResources(options.cwd)) {
return true;
}
if (options.extensionsResult) {
const { result, errors } = await emitProjectTrustEvent(options.extensionsResult, { type: "project_trust", cwd: options.cwd }, options.projectTrustContext);
for (const error of errors) {
options.onExtensionError?.(`Extension "${error.extensionPath}" project_trust error: ${error.error}`);
}
if (result) {
const trusted = result.trusted === "yes";
if (result.remember === true) {
await options.trustStore.set(options.cwd, trusted);
}
return trusted;
}
}
const decision = await getSavedProjectTrust(options.trustStore, options.cwd);
if (decision !== null) {
return decision;
}
switch (options.defaultProjectTrust ?? "ask") {
case "always":
return true;
case "never":
return false;
case "ask":
break;
}
if (!options.projectTrustContext.hasUI) {
return false;
}
const selected = await selectProjectTrustOption(options.cwd, options.projectTrustContext);
if (selected !== undefined) {
await saveProjectTrustPromptResult(options.trustStore, selected);
return selected.trusted;
}
return false;
}
//# sourceMappingURL=project-trust.js.map