@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
64 lines • 2.21 kB
JavaScript
import { getAgentDir } from "../config.js";
import { hasTrustRequiringProjectResources, ProjectTrustStore } from "../core/trust-manager.js";
import { parseArgs, printHelp } from "./args.js";
import { readHelpFlagsCache } from "./help-flags-cache.js";
export function isPlainHelpRequest(parsed) {
return parsed.help === true && parsed.print !== true && parsed.mode === undefined;
}
/**
* A help screen never prompts for project trust and never runs project-local extension code
* the user has not already trusted: only a recorded decision, or an explicit override, lets
* project resources in.
*/
export function resolveHelpProjectTrust(parsed, cwd, agentDir) {
if (parsed.projectTrustOverride !== undefined)
return parsed.projectTrustOverride;
if (!hasTrustRequiringProjectResources(cwd))
return true;
return new ProjectTrustStore(agentDir).get(cwd) === true;
}
export function helpFlagsScope(parsed, cwd, agentDir, projectTrusted) {
return {
cwd,
agentDir,
cliExtensionPaths: [...(parsed.extensions ?? [])],
noExtensions: parsed.noExtensions === true,
projectTrusted,
};
}
/**
* Answer `--help` before the engine module graph is imported.
*
* Returns false for every launch it cannot answer from what is already known - a non-plain help
* request, or a scope whose cached flags are missing or stale - and the normal startup path then
* resolves the flags and refills the cache.
*/
export function tryPrintHelpWithoutEngine(argv) {
let parsed;
try {
parsed = parseArgs([...argv]);
}
catch {
return false;
}
if (!isPlainHelpRequest(parsed) || parsed.diagnostics.length > 0)
return false;
if (parsed.noExtensions === true) {
printHelp([]);
return true;
}
let flags;
try {
const cwd = process.cwd();
const agentDir = getAgentDir();
flags = readHelpFlagsCache(helpFlagsScope(parsed, cwd, agentDir, resolveHelpProjectTrust(parsed, cwd, agentDir)));
}
catch {
return false;
}
if (!flags)
return false;
printHelp(flags);
return true;
}
//# sourceMappingURL=help-fast-path.js.map