@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
108 lines • 6.33 kB
TypeScript
import { type Decision, type DecisionOptions } from "./decide-target.ts";
import { type PermissionEventEmitter } from "./events.ts";
import { type IdentityInput, type KernelCanonical } from "./identity-decision.ts";
import type { IdentityMatcher } from "./evaluate.ts";
import type { PathIdentityResolver } from "./path-identity-host.ts";
import { type RuleIdentityEntry } from "./rule-identity-cache.ts";
import { type PermissionPresetName, type ReplyInput, type Request, type Ruleset } from "./types.ts";
export type { IdentityInput, KernelCanonical } from "./identity-decision.ts";
type RequestInput = Omit<Request, "id"> & {
id?: string;
};
/** Core service for managing permission requests and rule evaluation */
export declare class PermissionService {
private readonly pendingRequests;
/** The approved rules every session shares: the persisted store and the rules this service was seeded with. */
private approved;
/**
* The "Always" answers given to this service, keyed by the session (the request's `sessionID`) that
* answered, so one service serving several sessions never lets one session's answer approve another's call.
*/
private readonly answers;
/** The session whose reply is being applied; the pending-request callbacks below run inside `reply`. */
private replyScope;
private staticRuleset;
private emitter;
private idCounter;
constructor(staticRuleset: Ruleset, approved: Ruleset, emitter?: PermissionEventEmitter, preset?: PermissionPresetName, projectDir?: string, agentDir?: string, resolver?: PathIdentityResolver);
private readonly preset?;
private readonly projectDir?;
private readonly agentDir?;
private readonly protectedStorePath?;
private approvedVersion;
private readonly resolver?;
private readonly mountRewrite;
private readonly ruleIdentities;
private readonly releaseResolverState;
/** Stops forwarding resolver state to this service's emitter; decisions keep working. */
dispose(): void;
identityWanted(permission: string, kernel?: KernelCanonical): boolean;
private pathRules;
private remember;
/** The shared approved rules, then the given session's answers; with no session, every session's answers. */
private approvedFor;
ruleIdentityState(pattern: string): RuleIdentityEntry;
ruleAliasBearing(pattern: string): boolean;
noteMutation(mutated?: string): void;
identitySettled(): Promise<void>;
prepareIdentity(permission: string, executed: readonly string[], cwd?: string, kernel?: KernelCanonical): IdentityInput | Promise<IdentityInput>;
private get identityContext();
/** Identity inputs by request id, so a refusal can name the layer of an identity-matched deny. */
private readonly requestIdentities;
requestIdentity(requestID: string): IdentityInput | undefined;
identityMatcher(permission: string, identity: IdentityInput | undefined): IdentityMatcher | undefined;
/**
* An "Always" answer another open session just persisted is honored on this session's very next
* decision (senpi#2465): the approved store is re-read only when its mtime+size changed, and the
* re-read replaces the shared rules while keeping every session's own answers.
*/
private refreshApproved;
/**
* The one decision for a call, used when it is asked and again whenever an "Always" reply re-checks
* the requests still pending. External paths use last-match-wins separately for the absolute
* lexical path, physical-prefix spellings from the component walk and their proven on-disk case; the most restrictive
* decision wins (deny > ask > allow). More than 16 spellings or 40 hops asks instead.
* Raw originalPaths are display-only. Remembered approvals
* match the resolved target and cannot override a deny from any spelling.
* Without `presetBound` it is last-match-wins over every rule. With
* `presetBound` the preset's rules and the user's settings and CLI rules are evaluated apart and
* the more restrictive wins, so no configured rule, in any order or layer, can widen the preset;
* only an "Always" answer given in this or an earlier session (`permissions-approved.jsonl`,
* explicit consent for that pattern) can then turn a remaining ask into allow.
*/
private decide;
/**
* Share the decision and its relevant rules with the final dispatch fence. `scope` is the session
* the call belongs to (its requests' `sessionID`): only that session's answers can approve it.
* Without one, every session's answers count, which is one session's answers on a service that
* serves a single session; a caller deciding for one session of a shared service passes it.
*/
dispatchDecision(permission: string, target: string | readonly string[], options?: DecisionOptions, scope?: string): Decision;
private decideTarget;
/** Request permission for a tool call. Resolves if allowed, throws on denial. */
ask(request: RequestInput, { autoApproveAsk, approveBlanketAsk, presetBound, ruleAliases, executed, }?: {
readonly autoApproveAsk?: boolean;
readonly approveBlanketAsk?: boolean;
/**
* Decide as the more restrictive of the preset's decision and the user's (deny > ask > allow),
* so no user rule, in any order or layer, can widen the preset.
*/
readonly presetBound?: boolean;
readonly ruleAliases?: readonly string[];
/** The strings the tool opens (design 6.2): matched literally as aliases and by identity. */
readonly executed?: readonly string[];
}): Promise<void>;
/** Reply to a pending permission request; an "Always" answer is remembered for the request's session only. */
reply(input: ReplyInput): void;
/** List all pending permission requests */
list(): Request[];
/** Get the current approved ruleset: the shared rules, then every session's answers. */
getApproved(): Ruleset;
/**
* The answers given to this service (every session's), kept apart from the shared rules: a refresh
* that grows or shrinks the persisted store never duplicates or drops them.
*/
getSessionApproved(): Ruleset;
private nextRequestID;
}
//# sourceMappingURL=service.d.ts.map