@openape/apes 0.6.0 → 0.7.1

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,218 @@
1
- export { AdapterMeta, BuiltGrantRequest, GrantRequestOptions, LoadedAdapter, RegistryEntry, RegistryIndex, ResolvedCapability, ResolvedCommand, ShapesAdapter, ShapesOperation, buildExactCommandGrantRequest, buildStructuredCliGrantRequest, createShapesGrant, extractOption, extractWrappedCommand, fetchGrantToken, fetchRegistry, findAdapter, findConflictingAdapters, findExistingGrant, getInstalledDigest, installAdapter, isInstalled, loadAdapter, removeAdapter, resolveAdapterPath, resolveCapabilityRequest, resolveCommand, searchAdapters, verifyAndExecute, waitForGrantStatus } from '@openape/shapes';
1
+ import { OpenApeGrantRequest, ScopeRiskLevel, OpenApeCliAuthorizationDetail, OpenApeExecutionContext } from '@openape/core';
2
+
3
+ interface ShapesAdapter {
4
+ schema: string;
5
+ cli: {
6
+ id: string;
7
+ executable: string;
8
+ audience?: string;
9
+ version?: string;
10
+ };
11
+ operations: ShapesOperation[];
12
+ }
13
+ interface ShapesOperation {
14
+ id: string;
15
+ command: string[];
16
+ positionals?: string[];
17
+ required_options?: string[];
18
+ display: string;
19
+ action: string;
20
+ risk: ScopeRiskLevel;
21
+ resource_chain: string[];
22
+ exact_command?: boolean;
23
+ }
24
+ interface LoadedAdapter {
25
+ adapter: ShapesAdapter;
26
+ source: string;
27
+ digest: string;
28
+ }
29
+ interface ResolvedCommand {
30
+ adapter: ShapesAdapter;
31
+ source: string;
32
+ digest: string;
33
+ executable: string;
34
+ commandArgv: string[];
35
+ bindings: Record<string, string>;
36
+ detail: OpenApeCliAuthorizationDetail;
37
+ executionContext: OpenApeExecutionContext;
38
+ permission: string;
39
+ }
40
+ interface ResolvedCapability {
41
+ adapter: ShapesAdapter;
42
+ source: string;
43
+ digest: string;
44
+ executable: string;
45
+ details: OpenApeCliAuthorizationDetail[];
46
+ executionContext: OpenApeExecutionContext;
47
+ permissions: string[];
48
+ summary: string;
49
+ }
50
+ interface GrantRequestOptions {
51
+ requester: string;
52
+ target_host: string;
53
+ grant_type: 'once' | 'timed' | 'always';
54
+ reason?: string;
55
+ run_as?: string;
56
+ }
57
+ interface BuiltGrantRequest {
58
+ request: OpenApeGrantRequest;
59
+ }
60
+ interface RegistryEntry {
61
+ id: string;
62
+ name: string;
63
+ description: string;
64
+ category: string;
65
+ tags: string[];
66
+ author: string;
67
+ executable: string;
68
+ min_shapes_version: string;
69
+ digest: string;
70
+ download_url: string;
71
+ }
72
+ interface RegistryIndex {
73
+ version: number;
74
+ generated_at: string;
75
+ adapters: RegistryEntry[];
76
+ }
77
+ interface AdapterMeta {
78
+ id: string;
79
+ name: string;
80
+ description: string;
81
+ author: string;
82
+ category: string;
83
+ tags: string[];
84
+ executable: string;
85
+ risk_summary?: string;
86
+ homepage?: string;
87
+ min_shapes_version: string;
88
+ }
89
+
90
+ declare function resolveAdapterPath(cliId: string, explicitPath?: string): string;
91
+ declare function loadAdapter(cliId: string, explicitPath?: string): LoadedAdapter;
92
+ /** Try to load an adapter locally, return null instead of throwing when not found. */
93
+ declare function tryLoadAdapter(cliId: string, explicitPath?: string): LoadedAdapter | null;
94
+
95
+ /**
96
+ * Append a single entry to the audit log at ~/.config/apes/audit.jsonl.
97
+ * Failures are swallowed — the audit log should never break the actual flow.
98
+ */
99
+ declare function appendAuditLog(entry: {
100
+ action: string;
101
+ timestamp?: number;
102
+ } & Record<string, unknown>): void;
103
+
104
+ /** A parsed shell command string with the executable and its argv extracted. */
105
+ interface ParsedShellCommand {
106
+ /** The program to run (first token, e.g. "rm") */
107
+ executable: string;
108
+ /** Remaining tokens after the executable (e.g. ["-f", "/tmp/foo.txt"]) */
109
+ argv: string[];
110
+ /**
111
+ * true if the command contains compound operators (&&, ||, ;, |),
112
+ * subshells ($(...)), or backticks. These cannot be safely handled
113
+ * by the adapter mode and must fall back to the generic shell grant flow.
114
+ */
115
+ isCompound: boolean;
116
+ /** The original command string for display/logging */
117
+ raw: string;
118
+ }
119
+ /**
120
+ * Parse a shell command string like `rm /tmp/foo.txt` or `git commit -m "hello"` into
121
+ * its executable and argv. Uses `shell-quote` to handle quoting correctly.
122
+ *
123
+ * Returns null for empty/whitespace-only input.
124
+ */
125
+ declare function parseShellCommand(raw: string): ParsedShellCommand | null;
126
+ /**
127
+ * Extract the command string from an `apes run --shell -- bash -c "…"` argv.
128
+ * Returns null if the argv does not follow that shape.
129
+ */
130
+ declare function extractShellCommandString(command: string[]): string | null;
131
+ /**
132
+ * Load an adapter for the given CLI id. If the adapter is not installed locally,
133
+ * try to fetch it from the shapes registry and auto-install it.
134
+ *
135
+ * Returns null when no adapter exists in either location, or when any step fails.
136
+ * Failures are logged but never thrown — callers should fall back to the generic flow.
137
+ */
138
+ declare function loadOrInstallAdapter(cliId: string): Promise<LoadedAdapter | null>;
139
+
140
+ declare function resolveCapabilityRequest(loaded: LoadedAdapter, params: {
141
+ resources: string[];
142
+ selectors?: string[];
143
+ actions: string[];
144
+ }): ResolvedCapability;
145
+
146
+ declare function extractWrappedCommand(args: string[]): string[];
147
+ declare function extractOption(args: string[], name: string): string | undefined;
148
+
149
+ interface SimilarGrantsInfo {
150
+ similar_grants: Array<{
151
+ grant: {
152
+ id: string;
153
+ };
154
+ similar_detail_indices: number[];
155
+ }>;
156
+ widened_details: Array<{
157
+ permission: string;
158
+ }>;
159
+ merged_details: Array<{
160
+ permission: string;
161
+ }>;
162
+ }
163
+ declare function createShapesGrant(resolved: ResolvedCommand, params: {
164
+ idp: string;
165
+ approval: 'once' | 'timed' | 'always';
166
+ reason?: string;
167
+ }): Promise<{
168
+ id: string;
169
+ status: string;
170
+ similar_grants?: SimilarGrantsInfo;
171
+ }>;
172
+ declare function waitForGrantStatus(idp: string, grantId: string): Promise<'approved' | 'denied' | 'revoked'>;
173
+ declare function fetchGrantToken(idp: string, grantId: string): Promise<string>;
174
+ /**
175
+ * One-shot verify + consume + execute. Preserves the legacy behavior of
176
+ * the `apes run --shell` path so existing callers keep working unchanged.
177
+ */
178
+ declare function verifyAndExecute(token: string, resolved: ResolvedCommand): Promise<void>;
179
+ declare function findExistingGrant(resolved: ResolvedCommand, idp: string): Promise<string | null>;
180
+
181
+ declare function resolveCommand(loaded: LoadedAdapter, fullArgv: string[]): Promise<ResolvedCommand>;
182
+
183
+ declare function buildExactCommandGrantRequest(command: string[], options: GrantRequestOptions & {
184
+ audience: string;
185
+ }): Promise<BuiltGrantRequest>;
186
+ declare function buildStructuredCliGrantRequest(resolved: ResolvedCommand | ResolvedCapability, options: GrantRequestOptions): Promise<BuiltGrantRequest>;
187
+
188
+ declare function fetchRegistry(forceRefresh?: boolean): Promise<RegistryIndex>;
189
+ declare function searchAdapters(index: RegistryIndex, query: string): RegistryEntry[];
190
+ /**
191
+ * Look up a registry entry by its id or its executable field. This lets callers
192
+ * pass either the registry id ("o365") or the binary name ("o365-cli"); most
193
+ * adapters have id === executable, but the two can diverge.
194
+ */
195
+ declare function findAdapter(index: RegistryIndex, idOrExecutable: string): RegistryEntry | undefined;
196
+
197
+ interface InstallResult {
198
+ id: string;
199
+ path: string;
200
+ digest: string;
201
+ updated: boolean;
202
+ }
203
+ declare function installAdapter(entry: RegistryEntry, options?: {
204
+ local?: boolean;
205
+ }): Promise<InstallResult>;
206
+ declare function getInstalledDigest(id: string, local: boolean): string | null;
207
+ declare function isInstalled(id: string, local: boolean): boolean;
208
+ declare function removeAdapter(id: string, local: boolean): boolean;
209
+ interface ConflictingAdapter {
210
+ file: string;
211
+ path: string;
212
+ adapterId: string;
213
+ executable: string;
214
+ }
215
+ declare function findConflictingAdapters(executable: string, excludeId: string): ConflictingAdapter[];
2
216
 
3
217
  interface AuthData {
4
218
  idp: string;
@@ -54,4 +268,4 @@ declare class CliExit extends Error {
54
268
  constructor(exitCode?: number);
55
269
  }
56
270
 
57
- export { type ApesConfig, ApiError, type AuthData, CliError, CliExit, apiFetch, clearAuth, discoverEndpoints, getAuthToken, getIdpUrl, getRequesterIdentity, loadAuth, loadConfig, parseDuration, saveAuth, saveConfig };
271
+ export { type AdapterMeta, type ApesConfig, ApiError, type AuthData, type BuiltGrantRequest, CliError, CliExit, type GrantRequestOptions, type LoadedAdapter, type RegistryEntry, type RegistryIndex, type ResolvedCapability, type ResolvedCommand, type ShapesAdapter, type ShapesOperation, apiFetch, appendAuditLog, buildExactCommandGrantRequest, buildStructuredCliGrantRequest, clearAuth, createShapesGrant, discoverEndpoints, extractOption, extractShellCommandString, extractWrappedCommand, fetchGrantToken, fetchRegistry, findAdapter, findConflictingAdapters, findExistingGrant, getAuthToken, getIdpUrl, getInstalledDigest, getRequesterIdentity, installAdapter, isInstalled, loadAdapter, loadAuth, loadConfig, loadOrInstallAdapter, parseDuration, parseShellCommand, removeAdapter, resolveAdapterPath, resolveCapabilityRequest, resolveCommand, saveAuth, saveConfig, searchAdapters, tryLoadAdapter, verifyAndExecute, waitForGrantStatus };
package/dist/index.js CHANGED
@@ -7,52 +7,57 @@ import {
7
7
  import {
8
8
  ApiError,
9
9
  apiFetch,
10
- clearAuth,
11
- discoverEndpoints,
12
- getAuthToken,
13
- getIdpUrl,
14
- getRequesterIdentity,
15
- loadAuth,
16
- loadConfig,
17
- saveAuth,
18
- saveConfig
19
- } from "./chunk-KXESKY4X.js";
20
-
21
- // src/index.ts
22
- import {
23
- loadAdapter,
24
- resolveAdapterPath,
25
- resolveCapabilityRequest,
26
- resolveCommand,
10
+ appendAuditLog,
27
11
  buildExactCommandGrantRequest,
28
12
  buildStructuredCliGrantRequest,
13
+ createShapesGrant,
14
+ discoverEndpoints,
15
+ extractOption,
16
+ extractShellCommandString,
17
+ extractWrappedCommand,
18
+ fetchGrantToken,
29
19
  fetchRegistry,
30
20
  findAdapter,
31
- searchAdapters,
32
21
  findConflictingAdapters,
22
+ findExistingGrant,
33
23
  getInstalledDigest,
34
24
  installAdapter,
35
25
  isInstalled,
26
+ loadAdapter,
27
+ loadOrInstallAdapter,
28
+ parseShellCommand,
36
29
  removeAdapter,
37
- extractWrappedCommand,
38
- extractOption,
39
- createShapesGrant,
40
- fetchGrantToken,
41
- findExistingGrant,
30
+ resolveAdapterPath,
31
+ resolveCapabilityRequest,
32
+ resolveCommand,
33
+ searchAdapters,
34
+ tryLoadAdapter,
42
35
  verifyAndExecute,
43
36
  waitForGrantStatus
44
- } from "@openape/shapes";
37
+ } from "./chunk-B32ZQP5K.js";
38
+ import {
39
+ clearAuth,
40
+ getAuthToken,
41
+ getIdpUrl,
42
+ getRequesterIdentity,
43
+ loadAuth,
44
+ loadConfig,
45
+ saveAuth,
46
+ saveConfig
47
+ } from "./chunk-TBYYREL6.js";
45
48
  export {
46
49
  ApiError,
47
50
  CliError,
48
51
  CliExit,
49
52
  apiFetch,
53
+ appendAuditLog,
50
54
  buildExactCommandGrantRequest,
51
55
  buildStructuredCliGrantRequest,
52
56
  clearAuth,
53
57
  createShapesGrant,
54
58
  discoverEndpoints,
55
59
  extractOption,
60
+ extractShellCommandString,
56
61
  extractWrappedCommand,
57
62
  fetchGrantToken,
58
63
  fetchRegistry,
@@ -68,7 +73,9 @@ export {
68
73
  loadAdapter,
69
74
  loadAuth,
70
75
  loadConfig,
76
+ loadOrInstallAdapter,
71
77
  parseDuration,
78
+ parseShellCommand,
72
79
  removeAdapter,
73
80
  resolveAdapterPath,
74
81
  resolveCapabilityRequest,
@@ -76,6 +83,7 @@ export {
76
83
  saveAuth,
77
84
  saveConfig,
78
85
  searchAdapters,
86
+ tryLoadAdapter,
79
87
  verifyAndExecute,
80
88
  waitForGrantStatus
81
89
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Re-export all shapes library functions\nexport {\n loadAdapter,\n resolveAdapterPath,\n resolveCapabilityRequest,\n resolveCommand,\n buildExactCommandGrantRequest,\n buildStructuredCliGrantRequest,\n fetchRegistry,\n findAdapter,\n searchAdapters,\n findConflictingAdapters,\n getInstalledDigest,\n installAdapter,\n isInstalled,\n removeAdapter,\n extractWrappedCommand,\n extractOption,\n createShapesGrant,\n fetchGrantToken,\n findExistingGrant,\n verifyAndExecute,\n waitForGrantStatus,\n} from '@openape/shapes'\n\nexport type {\n AdapterMeta,\n BuiltGrantRequest,\n GrantRequestOptions,\n LoadedAdapter,\n RegistryEntry,\n RegistryIndex,\n ResolvedCapability,\n ResolvedCommand,\n ShapesAdapter,\n ShapesOperation,\n} from '@openape/shapes'\n\n// Apes-specific exports\nexport { loadAuth, saveAuth, clearAuth, loadConfig, saveConfig, getIdpUrl, getAuthToken, getRequesterIdentity } from './config'\nexport type { AuthData, ApesConfig } from './config'\nexport { apiFetch, discoverEndpoints, ApiError } from './http'\nexport { parseDuration } from './duration'\nexport { CliError, CliExit } from './errors'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}