import type { ToolContext } from "@opencode-ai/plugin"; import type { PluginContext } from "../types.js"; /** * Execute a `ctx.ask(...)` result. * * As of `@opencode-ai/plugin@1.15.5`, `ask()` returns `Promise` again * (it briefly returned `Effect.Effect` in 1.14.x–1.15.4; the Promise * shape is what the SDK originally used and what AFT supports today). * * On deny, the Promise rejects with `DeniedError` / `RejectedError`, so * callers can rely on a normal `try/catch` to detect denial. This helper * stays as a single chokepoint so that if the SDK ever changes its return * shape again, only this function needs to be touched. */ export declare function runAsk(maybe: Promise): Promise; export declare function resolveAbsolutePath(context: ToolContext, target: string): string; export declare function permissionPath(context: ToolContext, target: string): string; export declare function resolveRelativePattern(context: ToolContext, target: string): string; export declare function resolveRelativePatternFromAbsolute(context: ToolContext, absolutePath: string): string; export declare function resolveRelativePatterns(context: ToolContext, targets: string[]): string[]; export declare function workspacePattern(_context: ToolContext): string; export declare function askEditPermission(context: ToolContext, patterns: string[], metadata?: Record): Promise; /** * Check if `child` is inside `parent`. Mirrors `AppFileSystem.contains` in * opencode core (uses `path.relative` and ensures it doesn't start with `..`). */ declare function containsPath(parent: string, child: string): boolean; declare function isSystemTempPath(target: string): boolean; /** * Normalize a path pattern (which may end in `*`) for the same reasons * normalizePath() exists, but without trying to realpath a pattern that * doesn't correspond to a real entry. * * Mirrors `AppFileSystem.normalizePathPattern` in opencode core. * * `*` → `*` * `~/projects/*` → `~/projects/*` (`~` is expanded by opencode's matcher) * `C:\some\dir\*` → `C:\some\dir\*` (drive case canonicalized via realpath of the dir part) * * Non-Windows callers build patterns from an already-canonical parent path. */ declare function normalizePathPattern(p: string): string; export declare const _permissionsInternalsForTest: { containsPath: typeof containsPath; isSystemTempPath: typeof isSystemTempPath; normalizePathPattern: typeof normalizePathPattern; }; /** * Trigger OpenCode's host-side `external_directory` permission check when the * target path falls outside the current project's directory and worktree. * Mirrors `opencode/src/tool/external-directory.ts::assertExternalDirectoryEffect`. * * Why this exists: AFT hoisted tools previously only called `permission: "edit"`, * which bypassed OpenCode's separate `external_directory` rule (default `ask`). * This helper keeps that rule active for ordinary out-of-root paths while * suppressing asks for system temp directories, which are unstable world-writable * scratch space. * * Returns `undefined` on allow (or when target is inside project), or a * denial message string on deny so callers can wrap with * `permissionDeniedResponse(...)`. * * Always call this BEFORE the regular `askEditPermission` so any required * external-directory prompt appears before the edit/read prompt. */ export declare function assertExternalDirectoryPermission(ctx: PluginContext, context: ToolContext, target: string, options?: { kind?: "file" | "directory"; serverValidatedRead?: boolean; }): Promise; /** * Ask OpenCode for permission to expose indexed content from a different git root. * This deliberately uses a tool-specific permission id rather than * `external_directory`: a user may allow ordinary path reads while still wanting * a separate audit point for search results produced from borrowed indexes. */ export declare function assertAftSearchExternalPermission(ctx: PluginContext, context: ToolContext, target: string): Promise; /** * Trigger the host OpenCode permission check for grep. * * Uses the same request shape as OpenCode's built-in grep tool so a user's * `"permission": { "grep": { "*": "ask" } }` (or "deny") setting behaves * the same for the plugin-provided grep tool and OpenCode's native grep tool. */ export declare function askGrepPermission(context: ToolContext, pattern: string, metadata?: { path?: string; include?: string; }): Promise; /** * Trigger the host OpenCode permission check for aft_search. * * Passes the same pattern value and metadata as askGrepPermission but registers * under the `aft_search` permission id so rules targeting only `grep` do not * apply. */ export declare function askSearchPermission(context: ToolContext, pattern: string, metadata?: { path?: string; include?: string; }): Promise; /** * Trigger OpenCode's host-side `glob` permission check. * * Mirrors `opencode/src/tool/glob.ts` shape exactly so users with * `"permission": { "glob": { "*": "ask" } }` see the same prompt * regardless of which glob tool is used. */ export declare function askGlobPermission(context: ToolContext, pattern: string, metadata?: { path?: string; }): Promise; export declare function permissionDeniedResponse(message: string): string; export {}; //# sourceMappingURL=permissions.d.ts.map