@openape/apes 0.9.4 → 0.10.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
@@ -249,6 +249,14 @@ interface ApesConfig {
249
249
  * instructions. Default 5. Env var `APES_GRANT_POLL_MAX_MINUTES` wins.
250
250
  */
251
251
  grant_poll_max_minutes?: string;
252
+ /**
253
+ * Exit code emitted by `apes run` / `ape-shell -c` when the async
254
+ * default path creates a pending grant. Default `75` (`EX_TEMPFAIL`
255
+ * from sysexits.h — "temporary failure, retry later"). Set to `0`
256
+ * to restore the pre-0.10.0 exit-0 behaviour. Env var
257
+ * `APES_ASYNC_EXIT_CODE` wins. Valid range 0–255.
258
+ */
259
+ async_exit_code?: string;
252
260
  };
253
261
  agent?: {
254
262
  key?: string;
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  tryLoadAdapter,
35
35
  verifyAndExecute,
36
36
  waitForGrantStatus
37
- } from "./chunk-D3OMN7RV.js";
37
+ } from "./chunk-U4CI2RBO.js";
38
38
  import {
39
39
  clearAuth,
40
40
  getAuthToken,
@@ -44,7 +44,7 @@ import {
44
44
  loadConfig,
45
45
  saveAuth,
46
46
  saveConfig
47
- } from "./chunk-ILKZ5HGV.js";
47
+ } from "./chunk-6JSOSD7R.js";
48
48
  export {
49
49
  ApiError,
50
50
  CliError,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  isApesSelfDispatch,
4
4
  notifyGrantPending
5
- } from "./chunk-ZHTLP2DD.js";
5
+ } from "./chunk-EAXBC4KC.js";
6
6
  import {
7
7
  apiFetch,
8
8
  appendAuditLog,
@@ -15,10 +15,10 @@ import {
15
15
  resolveCommand,
16
16
  verifyAndConsume,
17
17
  waitForGrantStatus
18
- } from "./chunk-D3OMN7RV.js";
18
+ } from "./chunk-U4CI2RBO.js";
19
19
  import {
20
20
  loadAuth
21
- } from "./chunk-ILKZ5HGV.js";
21
+ } from "./chunk-6JSOSD7R.js";
22
22
 
23
23
  // src/shell/orchestrator.ts
24
24
  import { hostname } from "os";
@@ -766,4 +766,4 @@ async function runInteractiveShell() {
766
766
  export {
767
767
  runInteractiveShell
768
768
  };
769
- //# sourceMappingURL=orchestrator-5EZD7ZQE.js.map
769
+ //# sourceMappingURL=orchestrator-QL3AT67U.js.map
@@ -7,12 +7,12 @@ import {
7
7
  loadAdapter,
8
8
  resolveCommand,
9
9
  verifyAndExecute
10
- } from "./chunk-D3OMN7RV.js";
10
+ } from "./chunk-U4CI2RBO.js";
11
11
  import {
12
12
  getAuthToken,
13
13
  getIdpUrl,
14
14
  getRequesterIdentity
15
- } from "./chunk-ILKZ5HGV.js";
15
+ } from "./chunk-6JSOSD7R.js";
16
16
 
17
17
  // src/commands/mcp/server.ts
18
18
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -301,7 +301,7 @@ function registerAdapterTools(server) {
301
301
  async function startMcpServer(transport, port) {
302
302
  const server = new McpServer({
303
303
  name: "apes",
304
- version: true ? "0.9.4" : "0.1.0"
304
+ version: true ? "0.10.1" : "0.1.0"
305
305
  });
306
306
  registerStaticTools(server);
307
307
  registerAdapterTools(server);
@@ -329,4 +329,4 @@ async function startMcpServer(transport, port) {
329
329
  export {
330
330
  startMcpServer
331
331
  };
332
- //# sourceMappingURL=server-ED5MMYT3.js.map
332
+ //# sourceMappingURL=server-GTATJDYX.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/commands/mcp/server.ts","../src/commands/mcp/tools.ts","../src/commands/mcp/adapter-tools.ts"],"sourcesContent":["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'\nimport { createServer } from 'node:http'\nimport consola from 'consola'\nimport { registerAdapterTools, registerStaticTools } from './tools'\n\ndeclare const __VERSION__: string\n\nexport async function startMcpServer(transport: 'stdio' | 'sse', port: number) {\n const server = new McpServer({\n name: 'apes',\n version: typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.1.0',\n })\n\n // Register static tools\n registerStaticTools(server)\n\n // Register adapter-derived tools\n registerAdapterTools(server)\n\n if (transport === 'stdio') {\n const stdioTransport = new StdioServerTransport()\n await server.connect(stdioTransport)\n }\n else if (transport === 'sse') {\n const httpServer = createServer(async (req, res) => {\n if (req.url === '/sse' && req.method === 'GET') {\n const sseTransport = new SSEServerTransport('/messages', res)\n await server.connect(sseTransport)\n }\n else if (req.url === '/messages' && req.method === 'POST') {\n // SSE message handling is done by the transport\n res.writeHead(200)\n res.end()\n }\n else {\n res.writeHead(404)\n res.end('Not found')\n }\n })\n\n httpServer.listen(port, () => {\n consola.info(`MCP SSE server listening on http://localhost:${port}/sse`)\n })\n }\n}\n","import { hostname } from 'node:os'\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport {\n createShapesGrant,\n fetchGrantToken,\n loadAdapter,\n resolveCommand,\n verifyAndExecute,\n} from '../../shapes/index.js'\nimport { z } from 'zod'\nimport { getAuthToken, getIdpUrl, getRequesterIdentity } from '../../config'\nimport { apiFetch, getGrantsEndpoint } from '../../http'\nimport { loadAdapterTools } from './adapter-tools'\n\nexport function registerStaticTools(server: McpServer) {\n server.registerTool('apes.grants.list', {\n description: 'List grants',\n inputSchema: {\n status: z.string().optional().describe('Filter by status: pending, approved, denied, revoked, used'),\n limit: z.string().optional().describe('Max results'),\n },\n }, async ({ status, limit }) => {\n const idp = getIdpUrl()\n if (!idp)\n return { content: [{ type: 'text' as const, text: 'Not configured. Run `apes login` first.' }] }\n\n const grantsUrl = await getGrantsEndpoint(idp)\n const params = new URLSearchParams()\n if (status)\n params.set('status', status)\n if (limit)\n params.set('limit', limit)\n const query = params.toString() ? `?${params.toString()}` : ''\n const response = await apiFetch(`${grantsUrl}${query}`)\n return { content: [{ type: 'text' as const, text: JSON.stringify(response, null, 2) }] }\n })\n\n server.registerTool('apes.grants.request', {\n description: 'Request a grant for a command',\n inputSchema: {\n command: z.string().describe('Command to request permission for'),\n audience: z.string().describe('Service identifier (e.g. escapes, proxy, shapes)'),\n approval: z.string().optional().describe('once, timed, or always'),\n reason: z.string().optional().describe('Reason for the request'),\n },\n }, async ({ command, audience, approval, reason }) => {\n const idp = getIdpUrl()\n const requester = getRequesterIdentity()\n if (!idp || !requester)\n return { content: [{ type: 'text' as const, text: 'Not authenticated. Run `apes login` first.' }] }\n\n const grantsUrl = await getGrantsEndpoint(idp)\n const cmdParts = command.split(' ')\n const grant = await apiFetch<{ id: string, status: string }>(grantsUrl, {\n method: 'POST',\n body: {\n requester,\n target_host: hostname(),\n audience,\n grant_type: approval || 'once',\n command: cmdParts,\n reason: reason || command,\n },\n })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n status: 'pending_approval',\n grant_id: grant.id,\n approve_url: `${idp}/grant-approval?grant_id=${grant.id}`,\n message: 'Grant needs approval. Approve via URL or `apes grants approve <id>`, then retry with grant_id.',\n }, null, 2),\n }],\n }\n })\n\n server.registerTool('apes.config.get', {\n description: 'Get apes configuration value',\n inputSchema: {\n key: z.string().describe('Config key: idp, email'),\n },\n }, ({ key }) => {\n if (key === 'idp') {\n const idp = getIdpUrl()\n return { content: [{ type: 'text' as const, text: idp || 'Not configured' }] }\n }\n if (key === 'email') {\n const email = getRequesterIdentity()\n return { content: [{ type: 'text' as const, text: email || 'Not logged in' }] }\n }\n return { content: [{ type: 'text' as const, text: `Unknown key: ${key}` }] }\n })\n\n server.registerTool('apes.explain', {\n description: 'Show what permissions a command would need',\n inputSchema: {\n command: z.array(z.string()).describe('Command as array of strings (e.g. [\"gh\", \"repo\", \"list\"])'),\n adapter: z.string().optional().describe('Explicit adapter TOML path'),\n },\n }, async ({ command, adapter }) => {\n try {\n const loaded = loadAdapter(command[0]!, adapter)\n const resolved = await resolveCommand(loaded, command)\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n adapter: resolved.adapter.cli.id,\n operation: resolved.detail.operation_id,\n display: resolved.detail.display,\n permission: resolved.permission,\n resource_chain: resolved.detail.resource_chain,\n exact_command: resolved.detail.constraints?.exact_command ?? false,\n adapter_digest: resolved.digest,\n }, null, 2),\n }],\n }\n }\n catch (err) {\n return { content: [{ type: 'text' as const, text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }\n }\n })\n\n server.registerTool('apes.adapter.list', {\n description: 'List installed CLI adapters',\n }, () => {\n const tools = loadAdapterTools()\n const adapters = [...new Set(tools.map(t => t.adapterId))]\n return {\n content: [{\n type: 'text' as const,\n text: adapters.length > 0\n ? `Installed adapters: ${adapters.join(', ')}`\n : 'No adapters installed.',\n }],\n }\n })\n\n server.registerTool('apes.fetch', {\n description: 'Make an authenticated HTTP request',\n inputSchema: {\n method: z.string().describe('HTTP method (GET, POST, PUT, DELETE)'),\n url: z.string().describe('URL to fetch'),\n body: z.string().optional().describe('Request body (JSON string)'),\n },\n }, async ({ method, url, body }) => {\n const token = getAuthToken()\n if (!token)\n return { content: [{ type: 'text' as const, text: 'Not authenticated. Run `apes login` first.' }], isError: true }\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Authorization': `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: body || undefined,\n })\n const text = await response.text()\n try {\n return { content: [{ type: 'text' as const, text: JSON.stringify(JSON.parse(text), null, 2) }] }\n }\n catch {\n return { content: [{ type: 'text' as const, text }] }\n }\n })\n}\n\nexport function registerAdapterTools(server: McpServer) {\n const adapterTools = loadAdapterTools()\n\n for (const tool of adapterTools) {\n // Build Zod schema from adapter operation\n const schemaShape: Record<string, z.ZodType> = {\n grant_id: z.string().optional().describe('Grant ID from a previous pending_approval response'),\n }\n\n if (tool.inputSchema && typeof tool.inputSchema === 'object') {\n const props = (tool.inputSchema as { properties?: Record<string, { description?: string }> }).properties\n if (props) {\n for (const [key, val] of Object.entries(props)) {\n schemaShape[key] = z.string().optional().describe(val.description || key)\n }\n }\n }\n\n server.registerTool(tool.name, {\n description: tool.description,\n inputSchema: schemaShape,\n }, async (args) => {\n const idp = getIdpUrl()\n if (!idp)\n return { content: [{ type: 'text' as const, text: 'Not configured. Run `apes login` first.' }], isError: true }\n\n try {\n const loaded = loadAdapter(tool.adapterId)\n const op = loaded.adapter.operations.find(o => o.id === tool.operationId)\n if (!op)\n return { content: [{ type: 'text' as const, text: `Operation ${tool.operationId} not found` }], isError: true }\n\n const argv = [loaded.adapter.cli.executable, ...op.command]\n if (op.positionals) {\n for (const pos of op.positionals) {\n if (args[pos])\n argv.push(String(args[pos]))\n }\n }\n if (op.required_options) {\n for (const opt of op.required_options) {\n const name = opt.replace(/^--/, '')\n if (args[name])\n argv.push(opt, String(args[name]))\n }\n }\n\n const resolved = await resolveCommand(loaded, argv)\n\n if (args.grant_id) {\n const token = await fetchGrantToken(idp, String(args.grant_id))\n await verifyAndExecute(token, resolved)\n return { content: [{ type: 'text' as const, text: 'Command executed successfully.' }] }\n }\n\n const grant = await createShapesGrant(resolved, { idp, approval: 'once' })\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n status: 'pending_approval',\n grant_id: grant.id,\n approve_url: `${idp}/grant-approval?grant_id=${grant.id}`,\n message: 'Grant needs approval. Approve, then call this tool again with grant_id.',\n }, null, 2),\n }],\n }\n }\n catch (err) {\n return { content: [{ type: 'text' as const, text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }\n }\n })\n }\n}\n","import { readdirSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport { loadAdapter } from '../../shapes/index.js'\nimport type { ShapesOperation } from '../../shapes/index.js'\n\nexport interface AdapterToolDef {\n name: string\n description: string\n inputSchema: Record<string, unknown>\n adapterId: string\n operationId: string\n}\n\nfunction operationToInputSchema(op: ShapesOperation): Record<string, unknown> {\n const properties: Record<string, unknown> = {}\n const required: string[] = []\n\n if (op.positionals) {\n for (const pos of op.positionals) {\n properties[pos] = { type: 'string', description: `Positional argument: ${pos}` }\n required.push(pos)\n }\n }\n\n if (op.required_options) {\n for (const opt of op.required_options) {\n const name = opt.replace(/^--/, '')\n properties[name] = { type: 'string', description: `Required option: ${opt}` }\n required.push(name)\n }\n }\n\n return {\n type: 'object',\n properties,\n required: required.length > 0 ? required : undefined,\n }\n}\n\nfunction scanAdapterDir(dir: string): string[] {\n try {\n return readdirSync(dir)\n .filter(f => f.endsWith('.toml'))\n .map(f => f.replace('.toml', ''))\n }\n catch {\n return []\n }\n}\n\nexport function loadAdapterTools(): AdapterToolDef[] {\n const tools: AdapterToolDef[] = []\n const seen = new Set<string>()\n\n const adapterDirs = [\n join(process.cwd(), '.openape', 'shapes', 'adapters'),\n join(homedir(), '.openape', 'shapes', 'adapters'),\n '/etc/openape/shapes/adapters',\n ]\n\n for (const dir of adapterDirs) {\n for (const id of scanAdapterDir(dir)) {\n if (seen.has(id))\n continue\n seen.add(id)\n\n try {\n const loaded = loadAdapter(id)\n for (const op of loaded.adapter.operations) {\n tools.push({\n name: `apes.run.${id}.${op.id}`,\n description: op.display || `${id}: ${op.id}`,\n inputSchema: operationToInputSchema(op),\n adapterId: id,\n operationId: op.id,\n })\n }\n }\n catch {\n // Skip adapters that fail to load\n }\n }\n }\n\n return tools\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAC7B,OAAO,aAAa;;;ACJpB,SAAS,gBAAgB;AASzB,SAAS,SAAS;;;ACTlB,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,YAAY;AAYrB,SAAS,uBAAuB,IAA8C;AAC5E,QAAM,aAAsC,CAAC;AAC7C,QAAM,WAAqB,CAAC;AAE5B,MAAI,GAAG,aAAa;AAClB,eAAW,OAAO,GAAG,aAAa;AAChC,iBAAW,GAAG,IAAI,EAAE,MAAM,UAAU,aAAa,wBAAwB,GAAG,GAAG;AAC/E,eAAS,KAAK,G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CAAC;AAED,eAAW,OAAO,MAAM,MAAM;AAC5B,cAAQ,KAAK,gDAAgD,IAAI,MAAM;AAAA,IACzE,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/commands/mcp/server.ts","../src/commands/mcp/tools.ts","../src/commands/mcp/adapter-tools.ts"],"sourcesContent":["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'\nimport { createServer } from 'node:http'\nimport consola from 'consola'\nimport { registerAdapterTools, registerStaticTools } from './tools'\n\ndeclare const __VERSION__: string\n\nexport async function startMcpServer(transport: 'stdio' | 'sse', port: number) {\n const server = new McpServer({\n name: 'apes',\n version: typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.1.0',\n })\n\n // Register static tools\n registerStaticTools(server)\n\n // Register adapter-derived tools\n registerAdapterTools(server)\n\n if (transport === 'stdio') {\n const stdioTransport = new StdioServerTransport()\n await server.connect(stdioTransport)\n }\n else if (transport === 'sse') {\n const httpServer = createServer(async (req, res) => {\n if (req.url === '/sse' && req.method === 'GET') {\n const sseTransport = new SSEServerTransport('/messages', res)\n await server.connect(sseTransport)\n }\n else if (req.url === '/messages' && req.method === 'POST') {\n // SSE message handling is done by the transport\n res.writeHead(200)\n res.end()\n }\n else {\n res.writeHead(404)\n res.end('Not found')\n }\n })\n\n httpServer.listen(port, () => {\n consola.info(`MCP SSE server listening on http://localhost:${port}/sse`)\n })\n }\n}\n","import { hostname } from 'node:os'\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport {\n createShapesGrant,\n fetchGrantToken,\n loadAdapter,\n resolveCommand,\n verifyAndExecute,\n} from '../../shapes/index.js'\nimport { z } from 'zod'\nimport { getAuthToken, getIdpUrl, getRequesterIdentity } from '../../config'\nimport { apiFetch, getGrantsEndpoint } from '../../http'\nimport { loadAdapterTools } from './adapter-tools'\n\nexport function registerStaticTools(server: McpServer) {\n server.registerTool('apes.grants.list', {\n description: 'List grants',\n inputSchema: {\n status: z.string().optional().describe('Filter by status: pending, approved, denied, revoked, used'),\n limit: z.string().optional().describe('Max results'),\n },\n }, async ({ status, limit }) => {\n const idp = getIdpUrl()\n if (!idp)\n return { content: [{ type: 'text' as const, text: 'Not configured. Run `apes login` first.' }] }\n\n const grantsUrl = await getGrantsEndpoint(idp)\n const params = new URLSearchParams()\n if (status)\n params.set('status', status)\n if (limit)\n params.set('limit', limit)\n const query = params.toString() ? `?${params.toString()}` : ''\n const response = await apiFetch(`${grantsUrl}${query}`)\n return { content: [{ type: 'text' as const, text: JSON.stringify(response, null, 2) }] }\n })\n\n server.registerTool('apes.grants.request', {\n description: 'Request a grant for a command',\n inputSchema: {\n command: z.string().describe('Command to request permission for'),\n audience: z.string().describe('Service identifier (e.g. escapes, proxy, shapes)'),\n approval: z.string().optional().describe('once, timed, or always'),\n reason: z.string().optional().describe('Reason for the request'),\n },\n }, async ({ command, audience, approval, reason }) => {\n const idp = getIdpUrl()\n const requester = getRequesterIdentity()\n if (!idp || !requester)\n return { content: [{ type: 'text' as const, text: 'Not authenticated. Run `apes login` first.' }] }\n\n const grantsUrl = await getGrantsEndpoint(idp)\n const cmdParts = command.split(' ')\n const grant = await apiFetch<{ id: string, status: string }>(grantsUrl, {\n method: 'POST',\n body: {\n requester,\n target_host: hostname(),\n audience,\n grant_type: approval || 'once',\n command: cmdParts,\n reason: reason || command,\n },\n })\n\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n status: 'pending_approval',\n grant_id: grant.id,\n approve_url: `${idp}/grant-approval?grant_id=${grant.id}`,\n message: 'Grant needs approval. Approve via URL or `apes grants approve <id>`, then retry with grant_id.',\n }, null, 2),\n }],\n }\n })\n\n server.registerTool('apes.config.get', {\n description: 'Get apes configuration value',\n inputSchema: {\n key: z.string().describe('Config key: idp, email'),\n },\n }, ({ key }) => {\n if (key === 'idp') {\n const idp = getIdpUrl()\n return { content: [{ type: 'text' as const, text: idp || 'Not configured' }] }\n }\n if (key === 'email') {\n const email = getRequesterIdentity()\n return { content: [{ type: 'text' as const, text: email || 'Not logged in' }] }\n }\n return { content: [{ type: 'text' as const, text: `Unknown key: ${key}` }] }\n })\n\n server.registerTool('apes.explain', {\n description: 'Show what permissions a command would need',\n inputSchema: {\n command: z.array(z.string()).describe('Command as array of strings (e.g. [\"gh\", \"repo\", \"list\"])'),\n adapter: z.string().optional().describe('Explicit adapter TOML path'),\n },\n }, async ({ command, adapter }) => {\n try {\n const loaded = loadAdapter(command[0]!, adapter)\n const resolved = await resolveCommand(loaded, command)\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n adapter: resolved.adapter.cli.id,\n operation: resolved.detail.operation_id,\n display: resolved.detail.display,\n permission: resolved.permission,\n resource_chain: resolved.detail.resource_chain,\n exact_command: resolved.detail.constraints?.exact_command ?? false,\n adapter_digest: resolved.digest,\n }, null, 2),\n }],\n }\n }\n catch (err) {\n return { content: [{ type: 'text' as const, text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }\n }\n })\n\n server.registerTool('apes.adapter.list', {\n description: 'List installed CLI adapters',\n }, () => {\n const tools = loadAdapterTools()\n const adapters = [...new Set(tools.map(t => t.adapterId))]\n return {\n content: [{\n type: 'text' as const,\n text: adapters.length > 0\n ? `Installed adapters: ${adapters.join(', ')}`\n : 'No adapters installed.',\n }],\n }\n })\n\n server.registerTool('apes.fetch', {\n description: 'Make an authenticated HTTP request',\n inputSchema: {\n method: z.string().describe('HTTP method (GET, POST, PUT, DELETE)'),\n url: z.string().describe('URL to fetch'),\n body: z.string().optional().describe('Request body (JSON string)'),\n },\n }, async ({ method, url, body }) => {\n const token = getAuthToken()\n if (!token)\n return { content: [{ type: 'text' as const, text: 'Not authenticated. Run `apes login` first.' }], isError: true }\n\n const response = await fetch(url, {\n method,\n headers: {\n 'Authorization': `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: body || undefined,\n })\n const text = await response.text()\n try {\n return { content: [{ type: 'text' as const, text: JSON.stringify(JSON.parse(text), null, 2) }] }\n }\n catch {\n return { content: [{ type: 'text' as const, text }] }\n }\n })\n}\n\nexport function registerAdapterTools(server: McpServer) {\n const adapterTools = loadAdapterTools()\n\n for (const tool of adapterTools) {\n // Build Zod schema from adapter operation\n const schemaShape: Record<string, z.ZodType> = {\n grant_id: z.string().optional().describe('Grant ID from a previous pending_approval response'),\n }\n\n if (tool.inputSchema && typeof tool.inputSchema === 'object') {\n const props = (tool.inputSchema as { properties?: Record<string, { description?: string }> }).properties\n if (props) {\n for (const [key, val] of Object.entries(props)) {\n schemaShape[key] = z.string().optional().describe(val.description || key)\n }\n }\n }\n\n server.registerTool(tool.name, {\n description: tool.description,\n inputSchema: schemaShape,\n }, async (args) => {\n const idp = getIdpUrl()\n if (!idp)\n return { content: [{ type: 'text' as const, text: 'Not configured. Run `apes login` first.' }], isError: true }\n\n try {\n const loaded = loadAdapter(tool.adapterId)\n const op = loaded.adapter.operations.find(o => o.id === tool.operationId)\n if (!op)\n return { content: [{ type: 'text' as const, text: `Operation ${tool.operationId} not found` }], isError: true }\n\n const argv = [loaded.adapter.cli.executable, ...op.command]\n if (op.positionals) {\n for (const pos of op.positionals) {\n if (args[pos])\n argv.push(String(args[pos]))\n }\n }\n if (op.required_options) {\n for (const opt of op.required_options) {\n const name = opt.replace(/^--/, '')\n if (args[name])\n argv.push(opt, String(args[name]))\n }\n }\n\n const resolved = await resolveCommand(loaded, argv)\n\n if (args.grant_id) {\n const token = await fetchGrantToken(idp, String(args.grant_id))\n await verifyAndExecute(token, resolved)\n return { content: [{ type: 'text' as const, text: 'Command executed successfully.' }] }\n }\n\n const grant = await createShapesGrant(resolved, { idp, approval: 'once' })\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n status: 'pending_approval',\n grant_id: grant.id,\n approve_url: `${idp}/grant-approval?grant_id=${grant.id}`,\n message: 'Grant needs approval. Approve, then call this tool again with grant_id.',\n }, null, 2),\n }],\n }\n }\n catch (err) {\n return { content: [{ type: 'text' as const, text: `Error: ${err instanceof Error ? err.message : String(err)}` }], isError: true }\n }\n })\n }\n}\n","import { readdirSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport { loadAdapter } from '../../shapes/index.js'\nimport type { ShapesOperation } from '../../shapes/index.js'\n\nexport interface AdapterToolDef {\n name: string\n description: string\n inputSchema: Record<string, unknown>\n adapterId: string\n operationId: string\n}\n\nfunction operationToInputSchema(op: ShapesOperation): Record<string, unknown> {\n const properties: Record<string, unknown> = {}\n const required: string[] = []\n\n if (op.positionals) {\n for (const pos of op.positionals) {\n properties[pos] = { type: 'string', description: `Positional argument: ${pos}` }\n required.push(pos)\n }\n }\n\n if (op.required_options) {\n for (const opt of op.required_options) {\n const name = opt.replace(/^--/, '')\n properties[name] = { type: 'string', description: `Required option: ${opt}` }\n required.push(name)\n }\n }\n\n return {\n type: 'object',\n properties,\n required: required.length > 0 ? required : undefined,\n }\n}\n\nfunction scanAdapterDir(dir: string): string[] {\n try {\n return readdirSync(dir)\n .filter(f => f.endsWith('.toml'))\n .map(f => f.replace('.toml', ''))\n }\n catch {\n return []\n }\n}\n\nexport function loadAdapterTools(): AdapterToolDef[] {\n const tools: AdapterToolDef[] = []\n const seen = new Set<string>()\n\n const adapterDirs = [\n join(process.cwd(), '.openape', 'shapes', 'adapters'),\n join(homedir(), '.openape', 'shapes', 'adapters'),\n '/etc/openape/shapes/adapters',\n ]\n\n for (const dir of adapterDirs) {\n for (const id of scanAdapterDir(dir)) {\n if (seen.has(id))\n continue\n seen.add(id)\n\n try {\n const loaded = loadAdapter(id)\n for (const op of loaded.adapter.operations) {\n tools.push({\n name: `apes.run.${id}.${op.id}`,\n description: op.display || `${id}: ${op.id}`,\n inputSchema: operationToInputSchema(op),\n adapterId: id,\n operationId: op.id,\n })\n }\n }\n catch {\n // Skip adapters that fail to load\n }\n }\n }\n\n return tools\n}\n"],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c,SAAS;AACzB,UAAM,iBAAiB,IAAI,qBAAqB;AAChD,UAAM,OAAO,QAAQ,cAAc;AAAA,EACrC,WACS,cAAc,OAAO;AAC5B,UAAM,aAAa,aAAa,OAAO,KAAK,QAAQ;AAClD,UAAI,IAAI,QAAQ,UAAU,IAAI,WAAW,OAAO;AAC9C,cAAM,eAAe,IAAI,mBAAmB,aAAa,GAAG;AAC5D,cAAM,OAAO,QAAQ,YAAY;AAAA,MACnC,WACS,IAAI,QAAQ,eAAe,IAAI,WAAW,QAAQ;AAEzD,YAAI,UAAU,GAAG;AACjB,YAAI,IAAI;AAAA,MACV,OACK;AACH,YAAI,UAAU,GAAG;AACjB,YAAI,IAAI,WAAW;AAAA,MACrB;AAAA,IACF,CAAC;AAED,eAAW,OAAO,MAAM,MAAM;AAC5B,cAAQ,KAAK,gDAAgD,IAAI,MAAM;AAAA,IACzE,CAAC;AAAA,EACH;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openape/apes",
3
- "version": "0.9.4",
3
+ "version": "0.10.1",
4
4
  "turbo": {
5
5
  "tags": [
6
6
  "publishable"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport interface AuthData {\n idp: string\n access_token: string\n refresh_token?: string\n email: string\n expires_at: number\n}\n\nexport interface ApesConfig {\n defaults?: {\n idp?: string\n approval?: string\n /**\n * Audience for the `apes run` async info block. `agent` (default)\n * emits verbose agent-facing instructions with a polling protocol;\n * `human` emits a short friendly block. Env var `APES_USER` wins.\n */\n user?: 'agent' | 'human'\n /**\n * Poll interval (seconds) embedded in the agent-mode instructions.\n * Default 10. Env var `APES_GRANT_POLL_INTERVAL` wins. Stored as a\n * string in TOML because the hand-rolled parser only handles quoted\n * values — casting to number happens at read time.\n */\n grant_poll_interval_seconds?: string\n /**\n * Maximum poll duration (minutes) embedded in the agent-mode\n * instructions. Default 5. Env var `APES_GRANT_POLL_MAX_MINUTES` wins.\n */\n grant_poll_max_minutes?: string\n }\n agent?: {\n key?: string\n email?: string\n }\n notifications?: {\n pending_command?: string\n }\n}\n\nconst CONFIG_DIR = join(homedir(), '.config', 'apes')\nconst AUTH_FILE = join(CONFIG_DIR, 'auth.json')\nconst CONFIG_FILE = join(CONFIG_DIR, 'config.toml')\n\nfunction ensureDir() {\n if (!existsSync(CONFIG_DIR)) {\n mkdirSync(CONFIG_DIR, { recursive: true })\n }\n}\n\nexport function loadAuth(): AuthData | null {\n if (!existsSync(AUTH_FILE))\n return null\n try {\n return JSON.parse(readFileSync(AUTH_FILE, 'utf-8'))\n }\n catch {\n return null\n }\n}\n\nexport function saveAuth(data: AuthData): void {\n ensureDir()\n writeFileSync(AUTH_FILE, JSON.stringify(data, null, 2), { mode: 0o600 })\n}\n\nexport function clearAuth(): void {\n if (existsSync(AUTH_FILE)) {\n writeFileSync(AUTH_FILE, '', { mode: 0o600 })\n }\n // Also wipe the [agent] section from config.toml so logout disables\n // auto-refresh. Preserves [defaults] so the IdP URL stays configured.\n if (existsSync(CONFIG_FILE)) {\n const existing = loadConfig()\n if (existing.agent) {\n const { agent: _removed, ...rest } = existing\n saveConfig(rest)\n }\n }\n}\n\nexport function loadConfig(): ApesConfig {\n if (!existsSync(CONFIG_FILE))\n return {}\n try {\n return parseTOML(readFileSync(CONFIG_FILE, 'utf-8'))\n }\n catch {\n return {}\n }\n}\n\nfunction parseTOML(content: string): ApesConfig {\n const config: ApesConfig = {}\n let section = ''\n\n for (const line of content.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#'))\n continue\n\n const sectionMatch = trimmed.match(/^\\[(.+)\\]$/)\n if (sectionMatch) {\n section = sectionMatch[1]!\n continue\n }\n\n const kvMatch = trimmed.match(/^(\\w+)\\s*=\\s*\"(.+)\"$/)\n if (kvMatch) {\n const [, key, value] = kvMatch\n if (section === 'defaults') {\n config.defaults = config.defaults || {}\n ;(config.defaults as Record<string, string>)[key!] = value!\n }\n else if (section === 'agent') {\n config.agent = config.agent || {}\n ;(config.agent as Record<string, string>)[key!] = value!\n }\n else if (section === 'notifications') {\n config.notifications = config.notifications || {}\n ;(config.notifications as Record<string, string>)[key!] = value!\n }\n }\n }\n\n return config\n}\n\nexport function saveConfig(config: ApesConfig): void {\n ensureDir()\n const lines: string[] = []\n\n if (config.defaults) {\n lines.push('[defaults]')\n for (const [key, value] of Object.entries(config.defaults)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n if (config.agent) {\n lines.push('[agent]')\n for (const [key, value] of Object.entries(config.agent)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n if (config.notifications) {\n lines.push('[notifications]')\n for (const [key, value] of Object.entries(config.notifications)) {\n if (value)\n lines.push(`${key} = \"${value}\"`)\n }\n lines.push('')\n }\n\n writeFileSync(CONFIG_FILE, lines.join('\\n'), { mode: 0o600 })\n}\n\nexport function getIdpUrl(explicit?: string): string | null {\n if (explicit)\n return explicit\n if (process.env.APES_IDP)\n return process.env.APES_IDP\n\n const auth = loadAuth()\n if (auth?.idp)\n return auth.idp\n\n const config = loadConfig()\n if (config.defaults?.idp)\n return config.defaults.idp\n\n return null\n}\n\nexport function getAuthToken(): string | null {\n const auth = loadAuth()\n if (!auth)\n return null\n\n // Check expiry (with 30s buffer)\n if (auth.expires_at && Date.now() / 1000 > auth.expires_at - 30) {\n return null // expired\n }\n\n return auth.access_token\n}\n\nexport function getRequesterIdentity(): string | null {\n return loadAuth()?.email ?? null\n}\n\nexport { CONFIG_DIR, AUTH_FILE }\n"],"mappings":";;;AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,eAAe;AACxB,SAAS,YAAY;AA0CrB,IAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,MAAM;AACpD,IAAM,YAAY,KAAK,Y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