@vibedgc/sdk 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ import type { PermissionAction, PermissionMode, PermissionRequest, RuntimePolicy, SandboxRequirement, SandboxSetting, SandboxStatus, UnhandledPolicy } from "./types.ts";
2
+ export declare const DISPLAY: Readonly<Record<string, string>>;
3
+ export declare const SESSION_POLICY_ENV = "DGC_SESSION_POLICY";
4
+ /** Quote fnmatch metacharacters so a literal path or route matches only itself. */
5
+ export declare function escapeGlob(text: string): string;
6
+ /**
7
+ * fnmatch patterns that match every string except the allowed ones. An entry ending in `*`
8
+ * allows every string starting with the text before it. DGC rules can only deny, so an allowlist
9
+ * becomes denies of everything else.
10
+ */
11
+ export declare function complementPatterns(allowed: Iterable<string>): string[];
12
+ /** Like Python's Path.resolve(strict=False): symlinks resolved for the part that exists. */
13
+ export declare function resolvePath(raw: string, cwd?: string | null): string | null;
14
+ export declare function within(child: string, parent: string): boolean;
15
+ export declare function looksLikeNetwork(command: string): boolean;
16
+ /** True when a shell/python snippet is a file-write, not merely a read or `2>&1`. */
17
+ export declare function looksLikeWrite(command: string): boolean;
18
+ /** A validated {@link RuntimePolicy}. */
19
+ export declare class Policy {
20
+ readonly network: "deny" | "allow";
21
+ readonly extraReadDirs: readonly string[];
22
+ readonly denyPathPrefixes: readonly string[];
23
+ readonly denyTools: readonly string[];
24
+ readonly allowTools: readonly string[] | null;
25
+ readonly redactEvents: boolean;
26
+ readonly shell: "sandboxed" | "screened";
27
+ constructor(options: RuntimePolicy);
28
+ writesDenied(): boolean;
29
+ /** True when this policy forbids the tool by name, independent of command screening. */
30
+ namedToolDenied(name: string, args?: Record<string, unknown>): boolean;
31
+ /** Throw when an `mcp__app__` route names none of the session's own tools. */
32
+ checkSessionTools(customTools: readonly string[]): void;
33
+ namedRules(): string[];
34
+ /**
35
+ * Named-tool, network-tool and write-path rules, plus command-screening globs (best-effort
36
+ * screening, not a boundary; what `shell: "screened"` applies in auto mode).
37
+ */
38
+ engineDenyRules(inspectBash?: boolean): string[];
39
+ /**
40
+ * Classify one permission request: "deny" (the policy forbids it), "once" (the policy itself
41
+ * allows it: a read in extraReadDirs, or a search clear of denied paths), "screen" (command
42
+ * text looks like a network call or file write; best effort), or null (no opinion).
43
+ */
44
+ evaluate(request: PermissionRequest, cwd: string | null): "deny" | "once" | "screen" | null;
45
+ /** "deny" when this policy forbids the call, "once" when it allows it itself, else null. */
46
+ decision(request: PermissionRequest, cwd?: string | null): PermissionAction | null;
47
+ pathVerdict(name: string, args: Record<string, unknown>, cwd: string | null): "deny" | "once" | null;
48
+ deniedPrefixes(cwd: string | null): string[];
49
+ extraDirs(cwd: string | null): string[];
50
+ /** True when a denied prefix sits inside a tree the agent may search. */
51
+ searchGuard(cwd: string | null): boolean;
52
+ }
53
+ /** Normalize the public policy option. */
54
+ export declare function toPolicy(value: RuntimePolicy | Policy | undefined | null): Policy | null;
55
+ /**
56
+ * Compile bash write/network globs only when nobody will answer a permission_request. Auto mode
57
+ * never raises one, so the engine must deny by itself. Kept for API compatibility.
58
+ */
59
+ export declare function inspectBashForEngine(onPermission?: unknown, mode?: string): boolean;
60
+ /** The policy's named-tool, network and path rules plus screening globs (see {@link Policy.engineDenyRules}). */
61
+ export declare function engineDenyRules(policy: RuntimePolicy | Policy | undefined | null, opts?: {
62
+ inspectBash?: boolean;
63
+ }): string[];
64
+ /** "deny" when the policy forbids this request (including screened command text), else null. */
65
+ export declare function policyDecision(policy: RuntimePolicy | Policy | undefined | null, request: PermissionRequest, cwd?: string | null): "deny" | null;
66
+ /**
67
+ * Normalize `session({ permissions })` into [mode, unhandled]. `unhandled: "deny"`: a request the
68
+ * callback does not answer is denied and the agent carries on (no callback denies every request).
69
+ * `"callback"`: every request must go to your callback, so `session()` refuses to start without
70
+ * one; a request it still leaves unanswered (it threw, returned something else, or ran past
71
+ * `decisionTimeoutMs`) is denied and the run stops with `reason: "decision_failed"`.
72
+ */
73
+ export declare function permissionSettings(value: unknown, mode: PermissionMode | undefined, defaultMode: PermissionMode, onPermission: unknown): [PermissionMode, UnhandledPolicy];
74
+ /** Normalize `sandbox` ("required" | "preferred" | "off", or `{ requirement }`). */
75
+ export declare function sandboxRequirement(value: SandboxSetting | undefined | null): SandboxRequirement;
76
+ /** Fail early for "required" when this host plainly has no backend (the runtime decides finally). */
77
+ export declare function sandboxPrecheck(requirement: SandboxRequirement): void;
78
+ /** What one session's runtime is told, and how to confirm it took effect. */
79
+ export declare class SessionPlan {
80
+ readonly env: Record<string, string>;
81
+ readonly requirement: SandboxRequirement;
82
+ readonly policy: Policy | null;
83
+ readonly notes: readonly string[];
84
+ /**
85
+ * The policy asks for a sandboxed shell that could still run (the mode is not plan) and the
86
+ * caller did not accept a weaker fallback: a runtime with no OS sandbox must then refuse the
87
+ * session rather than run the shell unconfined.
88
+ */
89
+ readonly strictShell: boolean;
90
+ constructor(env: Record<string, string>, requirement: SandboxRequirement, policy: Policy | null, notes?: readonly string[], strictShell?: boolean);
91
+ get payload(): string;
92
+ /**
93
+ * Check the ready handshake: the runtime read this policy and has the sandbox asked for.
94
+ * Throws DGCUnsupportedError when the runtime cannot honour it.
95
+ */
96
+ confirm(ready: Record<string, unknown>): SandboxStatus;
97
+ private confirmTools;
98
+ }
99
+ /**
100
+ * Turn a RuntimePolicy and sandbox choice into the runtime's per-session policy. It travels to
101
+ * `dgc serve` in the DGC_SESSION_POLICY environment variable; nothing is written to any config.
102
+ */
103
+ export declare function compileSession(policy: Policy | null, options: {
104
+ cwd: string;
105
+ mode: PermissionMode;
106
+ sandbox: SandboxRequirement;
107
+ tools?: readonly string[];
108
+ /** Whether the workspace may grant this session capabilities (default false). */
109
+ trustWorkspace?: boolean;
110
+ /** False for an inheritUserState session (default true). */
111
+ isolated?: boolean;
112
+ }): SessionPlan;
113
+ /**
114
+ * Answer one permission_request: the policy first, then the callback. A policy deny is final; a
115
+ * request the policy raised only to check it ("once") is answered without the callback; command
116
+ * screening denies unless a reviewing callback is present outside auto mode. A denial the policy
117
+ * made carries a reason, so the runtime tells the model it was the application's policy (not "the
118
+ * user").
119
+ */
120
+ export declare function resolvePermission(policy: Policy | null, request: PermissionRequest, options: {
121
+ cwd: string | null;
122
+ permissionMode: string;
123
+ onPermission: unknown;
124
+ ask: () => Promise<unknown>;
125
+ }): Promise<{
126
+ action: PermissionAction;
127
+ reason: string;
128
+ }>;