@waniwani/cli 0.0.22 → 0.0.24
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.js +509 -215
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/commands/init.ts","../src/lib/errors.ts","../src/lib/output.ts","../src/commands/login.ts","../src/lib/auth.ts","../src/lib/config.ts","../src/commands/logout.ts","../src/commands/mcp/index.ts","../src/commands/mcp/create.ts","../src/lib/api.ts","../src/commands/mcp/deploy.ts","../src/commands/mcp/list.ts","../src/commands/mcp/list-files.ts","../src/commands/mcp/read-file.ts","../src/commands/mcp/run-command.ts","../src/commands/mcp/status.ts","../src/commands/mcp/stop.ts","../src/commands/mcp/test.ts","../src/commands/mcp/use.ts","../src/commands/mcp/write-file.ts","../src/commands/org/index.ts","../src/commands/org/list.ts","../src/commands/org/switch.ts","../src/commands/task.ts","../src/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { initCommand } from \"./commands/init.js\";\nimport { loginCommand } from \"./commands/login.js\";\nimport { logoutCommand } from \"./commands/logout.js\";\nimport { mcpCommand } from \"./commands/mcp/index.js\";\nimport { orgCommand } from \"./commands/org/index.js\";\nimport { taskCommand } from \"./commands/task.js\";\n\nconst version = \"0.1.0\";\n\nexport const program = new Command()\n\t.name(\"waniwani\")\n\t.description(\"WaniWani CLI for MCP development workflow\")\n\t.version(version)\n\t.option(\"--json\", \"Output results as JSON\")\n\t.option(\"--verbose\", \"Enable verbose logging\");\n\n// Auth commands\nprogram.addCommand(loginCommand);\nprogram.addCommand(logoutCommand);\n\n// Main commands\nprogram.addCommand(initCommand);\nprogram.addCommand(mcpCommand);\nprogram.addCommand(taskCommand);\nprogram.addCommand(orgCommand);\n","import { existsSync } from \"node:fs\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { Command } from \"commander\";\nimport { handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\n\nconst PROJECT_CONFIG_DIR = \".waniwani\";\nconst PROJECT_CONFIG_FILE = \"settings.local.json\";\n\nexport const initCommand = new Command(\"init\")\n\t.description(\"Initialize WaniWani project config in current directory\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst cwd = process.cwd();\n\t\t\tconst configDir = join(cwd, PROJECT_CONFIG_DIR);\n\t\t\tconst configPath = join(configDir, PROJECT_CONFIG_FILE);\n\n\t\t\tif (existsSync(configDir)) {\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput(\n\t\t\t\t\t\t{ initialized: false, message: \"Already initialized\" },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Project already initialized (.waniwani/ exists)\");\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait mkdir(configDir, { recursive: true });\n\n\t\t\tconst defaultConfig = {\n\t\t\t\tmcpId: null,\n\t\t\t\tdefaults: {},\n\t\t\t};\n\n\t\t\tawait writeFile(\n\t\t\t\tconfigPath,\n\t\t\t\tJSON.stringify(defaultConfig, null, \"\\t\"),\n\t\t\t\t\"utf-8\",\n\t\t\t);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ initialized: true, path: configDir }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"Initialized WaniWani project config\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` Created: ${PROJECT_CONFIG_DIR}/${PROJECT_CONFIG_FILE}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Now run:\");\n\t\t\t\tconsole.log(' waniwani mcp create \"my-mcp\"');\n\t\t\t\tconsole.log(\" waniwani mcp use <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { ZodError } from \"zod\";\n\nexport class CLIError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic code: string,\n\t\tpublic details?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"CLIError\";\n\t}\n}\n\nexport class ConfigError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"CONFIG_ERROR\", details);\n\t}\n}\n\nexport class AuthError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"AUTH_ERROR\", details);\n\t}\n}\n\nexport class SandboxError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"SANDBOX_ERROR\", details);\n\t}\n}\n\nexport class GitHubError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"GITHUB_ERROR\", details);\n\t}\n}\n\nexport class McpError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"MCP_ERROR\", details);\n\t}\n}\n\nexport function handleError(error: unknown, json: boolean): void {\n\tif (error instanceof ZodError) {\n\t\tconst message = error.issues\n\t\t\t.map((e) => `${e.path.join(\".\")}: ${e.message}`)\n\t\t\t.join(\", \");\n\t\toutputError(\"VALIDATION_ERROR\", `Invalid input: ${message}`, json);\n\t} else if (error instanceof CLIError) {\n\t\toutputError(error.code, error.message, json, error.details);\n\t} else if (error instanceof Error) {\n\t\toutputError(\"UNKNOWN_ERROR\", error.message, json);\n\t} else {\n\t\toutputError(\"UNKNOWN_ERROR\", String(error), json);\n\t}\n}\n\nfunction outputError(\n\tcode: string,\n\tmessage: string,\n\tjson: boolean,\n\tdetails?: Record<string, unknown>,\n): void {\n\tif (json) {\n\t\tconsole.error(\n\t\t\tJSON.stringify({ success: false, error: { code, message, details } }),\n\t\t);\n\t} else {\n\t\tconsole.error(chalk.red(`Error [${code}]:`), message);\n\t\tif (details) {\n\t\t\tconsole.error(chalk.gray(\"Details:\"), JSON.stringify(details, null, 2));\n\t\t}\n\t}\n}\n","import chalk from \"chalk\";\n\nexport function formatOutput<T>(data: T, json: boolean): void {\n\tif (json) {\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\tprettyPrint(data);\n\t}\n}\n\nexport function formatSuccess(message: string, json: boolean): void {\n\tif (json) {\n\t\tconsole.log(JSON.stringify({ success: true, message }));\n\t} else {\n\t\tconsole.log(chalk.green(\"✓\"), message);\n\t}\n}\n\nexport function formatError(error: Error | string, json: boolean): void {\n\tconst message = error instanceof Error ? error.message : error;\n\tif (json) {\n\t\tconsole.error(JSON.stringify({ success: false, error: message }));\n\t} else {\n\t\tconsole.error(chalk.red(\"✗\"), message);\n\t}\n}\n\nexport function formatTable(\n\theaders: string[],\n\trows: string[][],\n\tjson: boolean,\n): void {\n\tif (json) {\n\t\tconst data = rows.map((row) =>\n\t\t\tObject.fromEntries(headers.map((header, i) => [header, row[i]])),\n\t\t);\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\t// Simple table formatting without external dependency\n\t\tconst colWidths = headers.map((h, i) =>\n\t\t\tMath.max(h.length, ...rows.map((r) => (r[i] || \"\").length)),\n\t\t);\n\n\t\tconst separator = colWidths.map((w) => \"-\".repeat(w + 2)).join(\"+\");\n\t\tconst formatRow = (row: string[]) =>\n\t\t\trow.map((cell, i) => ` ${(cell || \"\").padEnd(colWidths[i])} `).join(\"|\");\n\n\t\tconsole.log(chalk.cyan(formatRow(headers)));\n\t\tconsole.log(separator);\n\t\tfor (const row of rows) {\n\t\t\tconsole.log(formatRow(row));\n\t\t}\n\t}\n}\n\nexport function formatList(\n\titems: Array<{ label: string; value: string }>,\n\tjson: boolean,\n): void {\n\tif (json) {\n\t\tconst data = Object.fromEntries(\n\t\t\titems.map((item) => [item.label, item.value]),\n\t\t);\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\tconst maxLabelLength = Math.max(...items.map((i) => i.label.length));\n\t\titems.forEach((item) => {\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.gray(item.label.padEnd(maxLabelLength))} ${chalk.white(item.value)}`,\n\t\t\t);\n\t\t});\n\t}\n}\n\nfunction prettyPrint(data: unknown, indent = 0): void {\n\tconst prefix = \" \".repeat(indent);\n\n\tif (Array.isArray(data)) {\n\t\tdata.forEach((item, index) => {\n\t\t\tconsole.log(`${prefix}${chalk.gray(`[${index}]`)}`);\n\t\t\tprettyPrint(item, indent + 1);\n\t\t});\n\t} else if (typeof data === \"object\" && data !== null) {\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\t\tconsole.log(`${prefix}${chalk.gray(key)}:`);\n\t\t\t\tprettyPrint(value, indent + 1);\n\t\t\t} else {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${prefix}${chalk.gray(key)}: ${chalk.white(String(value))}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconsole.log(`${prefix}${chalk.white(String(data))}`);\n\t}\n}\n","import { spawn } from \"node:child_process\";\nimport { createServer, type Server } from \"node:http\";\nimport type { Socket } from \"node:net\";\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { auth } from \"../lib/auth.js\";\nimport { config } from \"../lib/config.js\";\nimport { CLIError, handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\nimport type {\n\tOAuthClientRegistrationResponse,\n\tOAuthTokenResponse,\n} from \"../types/index.js\";\n\nconst CALLBACK_PORT = 54321;\nconst CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;\nconst CLIENT_NAME = \"waniwani-cli\";\n\nfunction generateCodeVerifier(): string {\n\tconst array = new Uint8Array(32);\n\tcrypto.getRandomValues(array);\n\treturn btoa(String.fromCharCode(...array))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nasync function generateCodeChallenge(verifier: string): Promise<string> {\n\tconst encoder = new TextEncoder();\n\tconst data = encoder.encode(verifier);\n\tconst hash = await crypto.subtle.digest(\"SHA-256\", data);\n\treturn btoa(String.fromCharCode(...new Uint8Array(hash)))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nfunction generateState(): string {\n\tconst array = new Uint8Array(16);\n\tcrypto.getRandomValues(array);\n\treturn Array.from(array, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nasync function registerClient(): Promise<OAuthClientRegistrationResponse> {\n\tconst apiUrl = await config.getApiUrl();\n\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/register`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tclient_name: CLIENT_NAME,\n\t\t\tredirect_uris: [CALLBACK_URL],\n\t\t\tgrant_types: [\"authorization_code\", \"refresh_token\"],\n\t\t\tresponse_types: [\"code\"],\n\t\t\ttoken_endpoint_auth_method: \"none\",\n\t\t}),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.json().catch(() => ({}));\n\t\tthrow new CLIError(\n\t\t\t(error as { error_description?: string }).error_description ||\n\t\t\t\t\"Failed to register OAuth client\",\n\t\t\t\"CLIENT_REGISTRATION_FAILED\",\n\t\t);\n\t}\n\n\treturn response.json() as Promise<OAuthClientRegistrationResponse>;\n}\n\nasync function openBrowser(url: string): Promise<void> {\n\tconst [cmd, ...args] =\n\t\tprocess.platform === \"darwin\"\n\t\t\t? [\"open\", url]\n\t\t\t: process.platform === \"win32\"\n\t\t\t\t? [\"cmd\", \"/c\", \"start\", url]\n\t\t\t\t: [\"xdg-open\", url];\n\n\tspawn(cmd, args, { stdio: \"ignore\", detached: true }).unref();\n}\n\nasync function waitForCallback(\n\texpectedState: string,\n\ttimeoutMs: number = 300000,\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet server: Server | null = null;\n\t\tconst sockets = new Set<Socket>();\n\n\t\tconst timeout = setTimeout(() => {\n\t\t\tcleanup();\n\t\t\treject(new CLIError(\"Login timed out\", \"LOGIN_TIMEOUT\"));\n\t\t}, timeoutMs);\n\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\t// Destroy all active connections to allow process to exit\n\t\t\tfor (const socket of sockets) {\n\t\t\t\tsocket.destroy();\n\t\t\t}\n\t\t\tsockets.clear();\n\t\t\tserver?.close();\n\t\t};\n\n\t\tconst htmlResponse = (title: string, message: string, color: string) =>\n\t\t\t`<html>\n <body style=\"font-family: system-ui; padding: 40px; text-align: center;\">\n <h1 style=\"color: ${color};\">${title}</h1>\n <p>${message}</p>\n <p>You can close this window.</p>\n </body>\n </html>`;\n\n\t\ttry {\n\t\t\tserver = createServer((req, res) => {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\treq.url || \"/\",\n\t\t\t\t\t`http://localhost:${CALLBACK_PORT}`,\n\t\t\t\t);\n\n\t\t\t\tif (url.pathname === \"/callback\") {\n\t\t\t\t\tconst code = url.searchParams.get(\"code\");\n\t\t\t\t\tconst state = url.searchParams.get(\"state\");\n\t\t\t\t\tconst error = url.searchParams.get(\"error\");\n\n\t\t\t\t\tres.setHeader(\"Content-Type\", \"text/html\");\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(htmlResponse(\"Login Failed\", `Error: ${error}`, \"#ef4444\"));\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(`OAuth error: ${error}`, \"OAUTH_ERROR\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (state !== expectedState) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(\n\t\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\t\"Login Failed\",\n\t\t\t\t\t\t\t\t\"Invalid state parameter. Please try again.\",\n\t\t\t\t\t\t\t\t\"#ef4444\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(\"Invalid state parameter\", \"INVALID_STATE\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!code) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(\n\t\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\t\"Login Failed\",\n\t\t\t\t\t\t\t\t\"No authorization code received.\",\n\t\t\t\t\t\t\t\t\"#ef4444\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(\"No authorization code\", \"NO_CODE\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tres.statusCode = 200;\n\t\t\t\t\tres.end(\n\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\"Login Successful!\",\n\t\t\t\t\t\t\t\"You can close this window and return to the terminal.\",\n\t\t\t\t\t\t\t\"#22c55e\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Schedule cleanup after response is sent\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\tresolve(code);\n\t\t\t\t\t}, 100);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tres.statusCode = 404;\n\t\t\t\tres.end(\"Not found\");\n\t\t\t});\n\n\t\t\t// Track connections so we can force-close them\n\t\t\tserver.on(\"connection\", (socket) => {\n\t\t\t\tsockets.add(socket);\n\t\t\t\tsocket.on(\"close\", () => sockets.delete(socket));\n\t\t\t});\n\n\t\t\tserver.on(\"error\", (err: NodeJS.ErrnoException) => {\n\t\t\t\tcleanup();\n\t\t\t\tif (err.code === \"EADDRINUSE\") {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew CLIError(\n\t\t\t\t\t\t\t`Port ${CALLBACK_PORT} is already in use. Close any other WaniWani CLI instances and try again.`,\n\t\t\t\t\t\t\t\"PORT_IN_USE\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\treject(err);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tserver.listen(CALLBACK_PORT);\n\t\t} catch (err: unknown) {\n\t\t\tcleanup();\n\t\t\treject(err);\n\t\t}\n\t});\n}\n\nasync function exchangeCodeForToken(\n\tcode: string,\n\tcodeVerifier: string,\n\tclientId: string,\n\tresource: string,\n): Promise<OAuthTokenResponse> {\n\tconst apiUrl = await config.getApiUrl();\n\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/token`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t},\n\t\tbody: new URLSearchParams({\n\t\t\tgrant_type: \"authorization_code\",\n\t\t\tcode,\n\t\t\tredirect_uri: CALLBACK_URL,\n\t\t\tclient_id: clientId,\n\t\t\tcode_verifier: codeVerifier,\n\t\t\tresource, // RFC 8707 - required to get JWT token\n\t\t}).toString(),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.json().catch(() => ({}));\n\t\tthrow new CLIError(\n\t\t\t(error as { error_description?: string }).error_description ||\n\t\t\t\t\"Failed to exchange code for token\",\n\t\t\t\"TOKEN_EXCHANGE_FAILED\",\n\t\t);\n\t}\n\n\treturn response.json() as Promise<OAuthTokenResponse>;\n}\n\nexport const loginCommand = new Command(\"login\")\n\t.description(\"Log in to WaniWani\")\n\t.option(\"--no-browser\", \"Don't open the browser automatically\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\t// Check if already logged in\n\t\t\tif (await auth.isLoggedIn()) {\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput({ alreadyLoggedIn: true }, true);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\tchalk.yellow(\n\t\t\t\t\t\t\t\"Already logged in. Use 'waniwani logout' to log out first.\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log(chalk.bold(\"\\nWaniWani CLI Login\\n\"));\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Registering client...\").start();\n\n\t\t\t// Register OAuth client dynamically\n\t\t\tconst { client_id: clientId } = await registerClient();\n\n\t\t\tspinner.text = \"Preparing authentication...\";\n\n\t\t\t// Generate PKCE values\n\t\t\tconst codeVerifier = generateCodeVerifier();\n\t\t\tconst codeChallenge = await generateCodeChallenge(codeVerifier);\n\t\t\tconst state = generateState();\n\n\t\t\t// Build authorization URL\n\t\t\tconst apiUrl = await config.getApiUrl();\n\t\t\tconst authUrl = new URL(`${apiUrl}/api/auth/oauth2/authorize`);\n\t\t\tauthUrl.searchParams.set(\"client_id\", clientId);\n\t\t\tauthUrl.searchParams.set(\"redirect_uri\", CALLBACK_URL);\n\t\t\tauthUrl.searchParams.set(\"response_type\", \"code\");\n\t\t\tauthUrl.searchParams.set(\"code_challenge\", codeChallenge);\n\t\t\tauthUrl.searchParams.set(\"code_challenge_method\", \"S256\");\n\t\t\tauthUrl.searchParams.set(\"state\", state);\n\t\t\tauthUrl.searchParams.set(\"resource\", apiUrl); // RFC 8707 - request JWT token\n\n\t\t\tspinner.stop();\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log(\"Opening browser for authentication...\\n\");\n\t\t\t\tconsole.log(`If the browser doesn't open, visit:\\n`);\n\t\t\t\tconsole.log(chalk.cyan(` ${authUrl.toString()}`));\n\t\t\t\tconsole.log();\n\t\t\t}\n\n\t\t\t// Start callback server and open browser\n\t\t\tconst callbackPromise = waitForCallback(state);\n\n\t\t\tif (options.browser !== false) {\n\t\t\t\tawait openBrowser(authUrl.toString());\n\t\t\t}\n\n\t\t\tspinner.start(\"Waiting for authorization...\");\n\n\t\t\t// Wait for callback with auth code\n\t\t\tconst code = await callbackPromise;\n\n\t\t\tspinner.text = \"Exchanging code for token...\";\n\n\t\t\t// Exchange code for token\n\t\t\tconst tokenResponse = await exchangeCodeForToken(\n\t\t\t\tcode,\n\t\t\t\tcodeVerifier,\n\t\t\t\tclientId,\n\t\t\t\tapiUrl, // RFC 8707 resource parameter\n\t\t\t);\n\n\t\t\t// Store tokens and client ID for refresh\n\t\t\tawait auth.setTokens(\n\t\t\t\ttokenResponse.access_token,\n\t\t\t\ttokenResponse.refresh_token,\n\t\t\t\ttokenResponse.expires_in,\n\t\t\t\tclientId,\n\t\t\t);\n\n\t\t\tspinner.succeed(\"Logged in successfully!\");\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ success: true, loggedIn: true }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(\"You're now logged in to WaniWani!\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Get started:\");\n\t\t\t\tconsole.log(\n\t\t\t\t\t\" waniwani mcp create my-server Create a new MCP sandbox\",\n\t\t\t\t);\n\t\t\t\tconsole.log(' waniwani task \"Add a tool\" Send tasks to Claude');\n\t\t\t\tconsole.log(\n\t\t\t\t\t\" waniwani org list View your organizations\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { access, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\nimport { config } from \"./config.js\";\n\nconst CONFIG_DIR = join(homedir(), \".waniwani\");\nconst AUTH_FILE = join(CONFIG_DIR, \"auth.json\");\n\nconst AuthStoreSchema = z.object({\n\taccessToken: z.string().nullable().default(null),\n\trefreshToken: z.string().nullable().default(null),\n\texpiresAt: z.string().nullable().default(null),\n\tclientId: z.string().nullable().default(null),\n});\n\ntype AuthStore = z.infer<typeof AuthStoreSchema>;\n\nasync function ensureConfigDir(): Promise<void> {\n\tawait mkdir(CONFIG_DIR, { recursive: true });\n}\n\nasync function readAuthStore(): Promise<AuthStore> {\n\tawait ensureConfigDir();\n\ttry {\n\t\tawait access(AUTH_FILE);\n\t\tconst content = await readFile(AUTH_FILE, \"utf-8\");\n\t\treturn AuthStoreSchema.parse(JSON.parse(content));\n\t} catch {\n\t\treturn AuthStoreSchema.parse({});\n\t}\n}\n\nasync function writeAuthStore(store: AuthStore): Promise<void> {\n\tawait ensureConfigDir();\n\tawait writeFile(AUTH_FILE, JSON.stringify(store, null, 2), \"utf-8\");\n}\n\nclass AuthManager {\n\tprivate storeCache: AuthStore | null = null;\n\n\tprivate async getStore(): Promise<AuthStore> {\n\t\tif (!this.storeCache) {\n\t\t\tthis.storeCache = await readAuthStore();\n\t\t}\n\t\treturn this.storeCache;\n\t}\n\n\tprivate async saveStore(store: AuthStore): Promise<void> {\n\t\tthis.storeCache = store;\n\t\tawait writeAuthStore(store);\n\t}\n\n\tasync isLoggedIn(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\treturn !!store.accessToken;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\tconst store = await this.getStore();\n\t\treturn store.accessToken;\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\tconst store = await this.getStore();\n\t\treturn store.refreshToken;\n\t}\n\n\tasync setTokens(\n\t\taccessToken: string,\n\t\trefreshToken: string,\n\t\texpiresIn: number,\n\t\tclientId?: string,\n\t): Promise<void> {\n\t\tconst expiresAt = new Date(Date.now() + expiresIn * 1000).toISOString();\n\t\tconst store = await this.getStore();\n\t\tstore.accessToken = accessToken;\n\t\tstore.refreshToken = refreshToken;\n\t\tstore.expiresAt = expiresAt;\n\t\tif (clientId) {\n\t\t\tstore.clientId = clientId;\n\t\t}\n\t\tawait this.saveStore(store);\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst emptyStore = AuthStoreSchema.parse({});\n\t\tawait this.saveStore(emptyStore);\n\t}\n\n\tasync isTokenExpired(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\tif (!store.expiresAt) return true;\n\t\t// Consider expired 5 minutes before actual expiry\n\t\treturn new Date(store.expiresAt).getTime() - 5 * 60 * 1000 < Date.now();\n\t}\n\n\tasync tryRefreshToken(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\tconst { refreshToken, clientId } = store;\n\t\tif (!refreshToken || !clientId) return false;\n\n\t\ttry {\n\t\t\tconst apiUrl = await config.getApiUrl();\n\t\t\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshToken,\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t}).toString(),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tawait this.clear();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst data = (await response.json()) as {\n\t\t\t\taccess_token: string;\n\t\t\t\trefresh_token: string;\n\t\t\t\texpires_in: number;\n\t\t\t};\n\n\t\t\tawait this.setTokens(\n\t\t\t\tdata.access_token,\n\t\t\t\tdata.refresh_token,\n\t\t\t\tdata.expires_in,\n\t\t\t);\n\n\t\t\treturn true;\n\t\t} catch {\n\t\t\tawait this.clear();\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\nexport const auth = new AuthManager();\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\n\nconst LOCAL_DIR = join(process.cwd(), \".waniwani\");\nconst LOCAL_FILE = join(LOCAL_DIR, \"settings.json\");\nconst GLOBAL_DIR = join(homedir(), \".waniwani\");\nconst GLOBAL_FILE = join(GLOBAL_DIR, \"settings.json\");\nconst DEFAULT_API_URL = \"https://app.waniwani.ai\";\n\nconst ConfigSchema = z.object({\n\tdefaults: z\n\t\t.object({ model: z.string(), maxSteps: z.number() })\n\t\t.default({ model: \"claude-sonnet-4-20250514\", maxSteps: 10 }),\n\tmcpId: z.string().nullable().default(null),\n\tapiUrl: z.string().nullable().default(null),\n});\n\ntype ConfigData = z.infer<typeof ConfigSchema>;\n\nclass Config {\n\tprivate dir: string;\n\tprivate file: string;\n\tprivate cache: ConfigData | null = null;\n\treadonly scope: \"local\" | \"global\";\n\n\tconstructor(forceGlobal = false) {\n\t\tconst useLocal = !forceGlobal && existsSync(LOCAL_DIR);\n\t\tthis.dir = useLocal ? LOCAL_DIR : GLOBAL_DIR;\n\t\tthis.file = useLocal ? LOCAL_FILE : GLOBAL_FILE;\n\t\tthis.scope = useLocal ? \"local\" : \"global\";\n\t}\n\n\tprivate async load(): Promise<ConfigData> {\n\t\tif (!this.cache) {\n\t\t\ttry {\n\t\t\t\tthis.cache = ConfigSchema.parse(\n\t\t\t\t\tJSON.parse(await readFile(this.file, \"utf-8\")),\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\tthis.cache = ConfigSchema.parse({});\n\t\t\t}\n\t\t}\n\t\treturn this.cache;\n\t}\n\n\tprivate async save(data: ConfigData): Promise<void> {\n\t\tthis.cache = data;\n\t\tawait mkdir(this.dir, { recursive: true });\n\t\tawait writeFile(this.file, JSON.stringify(data, null, \"\\t\"));\n\t}\n\n\tasync getDefaults() {\n\t\treturn (await this.load()).defaults;\n\t}\n\n\tasync setDefaults(defaults: Partial<ConfigData[\"defaults\"]>) {\n\t\tconst data = await this.load();\n\t\tdata.defaults = { ...data.defaults, ...defaults };\n\t\tawait this.save(data);\n\t}\n\n\tasync getMcpId() {\n\t\treturn (await this.load()).mcpId;\n\t}\n\n\tasync setMcpId(id: string | null) {\n\t\tconst data = await this.load();\n\t\tdata.mcpId = id;\n\t\tawait this.save(data);\n\t}\n\n\tasync getApiUrl() {\n\t\tif (process.env.WANIWANI_API_URL) return process.env.WANIWANI_API_URL;\n\t\treturn (await this.load()).apiUrl || DEFAULT_API_URL;\n\t}\n\n\tasync setApiUrl(url: string | null) {\n\t\tconst data = await this.load();\n\t\tdata.apiUrl = url;\n\t\tawait this.save(data);\n\t}\n\n\tasync clear() {\n\t\tawait this.save(ConfigSchema.parse({}));\n\t}\n}\n\nexport const config = new Config();\nexport const globalConfig = new Config(true);\n","import { Command } from \"commander\";\nimport { auth } from \"../lib/auth.js\";\nimport { handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\n\nexport const logoutCommand = new Command(\"logout\")\n\t.description(\"Log out from WaniWani\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tif (!(await auth.isLoggedIn())) {\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput({ alreadyLoggedOut: true }, true);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Not currently logged in.\");\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Clear auth tokens only (keep config like apiUrl intact)\n\t\t\tawait auth.clear();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ success: true }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"You have been logged out.\", false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport { createCommand } from \"./create.js\";\nimport { deployCommand } from \"./deploy.js\";\nimport { listCommand } from \"./list.js\";\nimport { listFilesCommand } from \"./list-files.js\";\nimport { readFileCommand } from \"./read-file.js\";\nimport { runCommandCommand } from \"./run-command.js\";\nimport { statusCommand } from \"./status.js\";\nimport { stopCommand } from \"./stop.js\";\nimport { testCommand } from \"./test.js\";\nimport { useCommand } from \"./use.js\";\nimport { writeFileCommand } from \"./write-file.js\";\n\nexport const mcpCommand = new Command(\"mcp\")\n\t.description(\"MCP sandbox management commands\")\n\t.addCommand(createCommand)\n\t.addCommand(listCommand)\n\t.addCommand(useCommand)\n\t.addCommand(statusCommand)\n\t.addCommand(stopCommand)\n\t.addCommand(testCommand)\n\t.addCommand(deployCommand)\n\t.addCommand(writeFileCommand)\n\t.addCommand(readFileCommand)\n\t.addCommand(listFilesCommand)\n\t.addCommand(runCommandCommand);\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config, globalConfig } from \"../../lib/config.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { CreateMcpResponse } from \"../../types/index.js\";\n\nexport const createCommand = new Command(\"create\")\n\t.description(\"Create a new MCP sandbox from template\")\n\t.argument(\"<name>\", \"Name for the MCP project\")\n\t.option(\"--global\", \"Save to global config instead of project config\")\n\t.action(async (name: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Creating MCP sandbox...\").start();\n\n\t\t\tconst result = await api.post<CreateMcpResponse>(\"/api/mcp/sandboxes\", {\n\t\t\t\tname,\n\t\t\t});\n\n\t\t\tspinner.succeed(\"MCP sandbox created\");\n\n\t\t\tconst cfg = options.global ? globalConfig : config;\n\t\t\tawait cfg.setMcpId(result.id);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ ...result, scope: cfg.scope }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(`MCP sandbox \"${name}\" created! (${cfg.scope})`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` MCP ID: ${result.id}`);\n\t\t\t\tconsole.log(` Sandbox ID: ${result.sandboxId}`);\n\t\t\t\tconsole.log(` Preview URL: ${result.previewUrl}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(`Next steps:`);\n\t\t\t\tconsole.log(` waniwani task \"Add a tool that does X\"`);\n\t\t\t\tconsole.log(` waniwani mcp test`);\n\t\t\t\tconsole.log(` waniwani mcp deploy`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { auth } from \"./auth.js\";\nimport { config } from \"./config.js\";\nimport { AuthError, CLIError } from \"./errors.js\";\n\nexport interface ApiResponse<T> {\n\tsuccess: boolean;\n\tdata?: T;\n\terror?: {\n\t\tcode: string;\n\t\tmessage: string;\n\t\tdetails?: Record<string, unknown>;\n\t};\n}\n\nexport class ApiError extends CLIError {\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string,\n\t\tpublic statusCode: number,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message, code, details);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n\nasync function request<T>(\n\tmethod: string,\n\tpath: string,\n\toptions?: {\n\t\tbody?: unknown;\n\t\trequireAuth?: boolean;\n\t\theaders?: Record<string, string>;\n\t},\n): Promise<T> {\n\tconst {\n\t\tbody,\n\t\trequireAuth = true,\n\t\theaders: extraHeaders = {},\n\t} = options || {};\n\n\tconst headers: Record<string, string> = {\n\t\t\"Content-Type\": \"application/json\",\n\t\t...extraHeaders,\n\t};\n\n\tif (requireAuth) {\n\t\tconst token = await auth.getAccessToken();\n\t\tif (!token) {\n\t\t\tthrow new AuthError(\n\t\t\t\t\"Not logged in. Run 'waniwani login' to authenticate.\",\n\t\t\t);\n\t\t}\n\t\theaders.Authorization = `Bearer ${token}`;\n\t}\n\n\tconst baseUrl = await config.getApiUrl();\n\tconst url = `${baseUrl}${path}`;\n\n\tconst response = await fetch(url, {\n\t\tmethod,\n\t\theaders,\n\t\tbody: body ? JSON.stringify(body) : undefined,\n\t});\n\n\t// Handle empty responses (204 No Content)\n\tif (response.status === 204) {\n\t\treturn undefined as T;\n\t}\n\n\tconst data = (await response.json()) as ApiResponse<T>;\n\n\tif (!response.ok || data.error) {\n\t\tconst error = data.error || {\n\t\t\tcode: \"API_ERROR\",\n\t\t\tmessage: `Request failed with status ${response.status}`,\n\t\t};\n\n\t\t// Handle token expiration\n\t\tif (response.status === 401) {\n\t\t\tconst refreshed = await auth.tryRefreshToken();\n\t\t\tif (refreshed) {\n\t\t\t\t// Retry with new token\n\t\t\t\treturn request<T>(method, path, options);\n\t\t\t}\n\t\t\tthrow new AuthError(\n\t\t\t\t\"Session expired. Run 'waniwani login' to re-authenticate.\",\n\t\t\t);\n\t\t}\n\n\t\tthrow new ApiError(\n\t\t\terror.message,\n\t\t\terror.code,\n\t\t\tresponse.status,\n\t\t\terror.details,\n\t\t);\n\t}\n\n\treturn data.data as T;\n}\n\nexport const api = {\n\tget: <T>(path: string, options?: { requireAuth?: boolean }) =>\n\t\trequest<T>(\"GET\", path, options),\n\n\tpost: <T>(\n\t\tpath: string,\n\t\tbody?: unknown,\n\t\toptions?: { requireAuth?: boolean; headers?: Record<string, string> },\n\t) => request<T>(\"POST\", path, { body, ...options }),\n\n\tdelete: <T>(path: string, options?: { requireAuth?: boolean }) =>\n\t\trequest<T>(\"DELETE\", path, options),\n\n\tgetBaseUrl: () => config.getApiUrl(),\n};\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { DeployResponse } from \"../../types/index.js\";\n\nexport const deployCommand = new Command(\"deploy\")\n\t.description(\"Deploy MCP server to GitHub + Vercel from sandbox\")\n\t.option(\"--repo <name>\", \"GitHub repository name\")\n\t.option(\"--org <name>\", \"GitHub organization\")\n\t.option(\"--private\", \"Create private repository\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Deploying to GitHub...\").start();\n\n\t\t\tconst result = await api.post<DeployResponse>(\n\t\t\t\t`/api/admin/mcps/${mcpId}/deploy`,\n\t\t\t\t{\n\t\t\t\t\trepoName: options.repo,\n\t\t\t\t\torg: options.org,\n\t\t\t\t\tprivate: options.private ?? false,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.succeed(\"Deployment complete!\");\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(\"MCP server deployed!\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` Repository: ${result.repository.url}`);\n\t\t\t\tif (result.deployment.url) {\n\t\t\t\t\tconsole.log(` Deployment: ${result.deployment.url}`);\n\t\t\t\t}\n\t\t\t\tconsole.log();\n\t\t\t\tif (result.deployment.note) {\n\t\t\t\t\tconsole.log(`Note: ${result.deployment.note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type { Mcp, McpListResponse } from \"../../types/index.js\";\n\nexport const listCommand = new Command(\"list\")\n\t.description(\"List all MCPs in your organization\")\n\t.option(\"--all\", \"Include stopped/expired MCPs\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching MCPs...\").start();\n\n\t\t\tconst mcps = await api.get<McpListResponse>(\n\t\t\t\t`/api/mcp/sandboxes${options.all ? \"?all=true\" : \"\"}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tconst activeMcpId = await config.getMcpId();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(\n\t\t\t\t\t{\n\t\t\t\t\t\tmcps: mcps.map((m: Mcp) => ({\n\t\t\t\t\t\t\t...m,\n\t\t\t\t\t\t\tisActive: m.id === activeMcpId,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tactiveMcpId,\n\t\t\t\t\t},\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (mcps.length === 0) {\n\t\t\t\t\tconsole.log(\"No MCPs found.\");\n\t\t\t\t\tconsole.log(\"\\nCreate a new MCP sandbox: waniwani mcp create <name>\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(chalk.bold(\"\\nMCPs:\\n\"));\n\n\t\t\t\tconst rows = mcps.map((m: Mcp) => {\n\t\t\t\t\tconst isActive = m.id === activeMcpId;\n\t\t\t\t\tconst statusColor =\n\t\t\t\t\t\tm.status === \"active\"\n\t\t\t\t\t\t\t? chalk.green\n\t\t\t\t\t\t\t: m.status === \"stopped\"\n\t\t\t\t\t\t\t\t? chalk.red\n\t\t\t\t\t\t\t\t: chalk.yellow;\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tisActive\n\t\t\t\t\t\t\t? chalk.cyan(`* ${m.id.slice(0, 8)}`)\n\t\t\t\t\t\t\t: ` ${m.id.slice(0, 8)}`,\n\t\t\t\t\t\tm.name,\n\t\t\t\t\t\tstatusColor(m.status),\n\t\t\t\t\t\tm.previewUrl,\n\t\t\t\t\t\tm.createdAt ? new Date(m.createdAt).toLocaleString() : \"N/A\",\n\t\t\t\t\t];\n\t\t\t\t});\n\n\t\t\t\tformatTable(\n\t\t\t\t\t[\"ID\", \"Name\", \"Status\", \"Preview URL\", \"Created\"],\n\t\t\t\t\trows,\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\n\t\t\t\tconsole.log();\n\t\t\t\tif (activeMcpId) {\n\t\t\t\t\tconsole.log(`Active MCP: ${chalk.cyan(activeMcpId.slice(0, 8))}`);\n\t\t\t\t}\n\t\t\t\tconsole.log(\"\\nSelect an MCP: waniwani mcp use <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type { ListFilesResponse } from \"../../types/index.js\";\n\nexport const listFilesCommand = new Command(\"list-files\")\n\t.description(\"List files in the MCP sandbox\")\n\t.argument(\"[path]\", \"Directory path (defaults to /app)\", \"/app\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(`Listing ${path}...`).start();\n\n\t\t\tconst result = await api.get<ListFilesResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files/list?path=${encodeURIComponent(path)}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log(chalk.bold(`\\nDirectory: ${result.path}\\n`));\n\n\t\t\t\tif (result.entries.length === 0) {\n\t\t\t\t\tconsole.log(\" (empty)\");\n\t\t\t\t} else {\n\t\t\t\t\tconst rows = result.entries.map((entry) => {\n\t\t\t\t\t\tconst name =\n\t\t\t\t\t\t\tentry.type === \"directory\"\n\t\t\t\t\t\t\t\t? chalk.blue(`${entry.name}/`)\n\t\t\t\t\t\t\t\t: entry.name;\n\t\t\t\t\t\tconst size =\n\t\t\t\t\t\t\tentry.type === \"directory\"\n\t\t\t\t\t\t\t\t? chalk.gray(\"<dir>\")\n\t\t\t\t\t\t\t\t: formatSize(entry.size);\n\t\t\t\t\t\treturn [name, size];\n\t\t\t\t\t});\n\n\t\t\t\t\tformatTable([\"Name\", \"Size\"], rows, false);\n\t\t\t\t}\n\t\t\t\tconsole.log();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\nfunction formatSize(bytes?: number): string {\n\tif (bytes === undefined) return \"\";\n\tif (bytes < 1024) return `${bytes} B`;\n\tif (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { ReadFileResponse } from \"../../types/index.js\";\n\nexport const readFileCommand = new Command(\"read-file\")\n\t.description(\"Read a file from the MCP sandbox\")\n\t.argument(\"<path>\", \"Path in sandbox (e.g., /app/src/index.ts)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--output <file>\", \"Write to local file instead of stdout\")\n\t.option(\"--base64\", \"Output as base64 (for binary files)\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst encoding = options.base64 ? \"base64\" : \"utf8\";\n\t\t\tconst spinner = ora(`Reading ${path}...`).start();\n\n\t\t\tconst result = await api.get<ReadFileResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files?path=${encodeURIComponent(path)}&encoding=${encoding}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (!result.exists) {\n\t\t\t\tthrow new McpError(`File not found: ${path}`);\n\t\t\t}\n\n\t\t\tif (options.output) {\n\t\t\t\t// Write to local file\n\t\t\t\tconst buffer =\n\t\t\t\t\tresult.encoding === \"base64\"\n\t\t\t\t\t\t? Buffer.from(result.content, \"base64\")\n\t\t\t\t\t\t: Buffer.from(result.content, \"utf8\");\n\t\t\t\tawait writeFile(options.output, buffer);\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput({ path, savedTo: options.output }, true);\n\t\t\t\t} else {\n\t\t\t\t\tformatSuccess(`Saved to ${options.output}`, false);\n\t\t\t\t}\n\t\t\t} else if (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\t// Print to stdout\n\t\t\t\tprocess.stdout.write(result.content);\n\t\t\t\t// Add newline if content doesn't end with one\n\t\t\t\tif (!result.content.endsWith(\"\\n\")) {\n\t\t\t\t\tprocess.stdout.write(\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput } from \"../../lib/output.js\";\nimport type { RunCommandResponse } from \"../../types/index.js\";\n\nexport const runCommandCommand = new Command(\"run-command\")\n\t.description(\"Run a command in the MCP sandbox\")\n\t.argument(\"<command>\", \"Command to run\")\n\t.argument(\"[args...]\", \"Command arguments\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--cwd <path>\", \"Working directory\")\n\t.option(\n\t\t\"--timeout <ms>\",\n\t\t\"Command timeout in milliseconds (default: 30000, max: 300000)\",\n\t)\n\t.action(async (cmd: string, args: string[], options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst timeout = options.timeout\n\t\t\t\t? Number.parseInt(options.timeout, 10)\n\t\t\t\t: undefined;\n\n\t\t\tconst spinner = ora(`Running: ${cmd} ${args.join(\" \")}`.trim()).start();\n\n\t\t\tconst result = await api.post<RunCommandResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/command`,\n\t\t\t\t{\n\t\t\t\t\tcommand: cmd,\n\t\t\t\t\targs: args.length > 0 ? args : undefined,\n\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\ttimeout,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\t// Show command\n\t\t\t\tconst cmdLine = [cmd, ...args].join(\" \");\n\t\t\t\tconsole.log(chalk.gray(`$ ${cmdLine}`));\n\t\t\t\tconsole.log();\n\n\t\t\t\t// Show stdout\n\t\t\t\tif (result.stdout) {\n\t\t\t\t\tprocess.stdout.write(result.stdout);\n\t\t\t\t\tif (!result.stdout.endsWith(\"\\n\")) {\n\t\t\t\t\t\tprocess.stdout.write(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Show stderr\n\t\t\t\tif (result.stderr) {\n\t\t\t\t\tprocess.stderr.write(chalk.red(result.stderr));\n\t\t\t\t\tif (!result.stderr.endsWith(\"\\n\")) {\n\t\t\t\t\t\tprocess.stderr.write(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Show exit code and duration\n\t\t\t\tconsole.log();\n\t\t\t\tconst exitColor = result.exitCode === 0 ? chalk.green : chalk.red;\n\t\t\t\tconsole.log(\n\t\t\t\t\texitColor(`Exit code: ${result.exitCode}`),\n\t\t\t\t\tchalk.gray(`(${(result.duration / 1000).toFixed(2)}s)`),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Exit with the command's exit code\n\t\t\tif (result.exitCode !== 0) {\n\t\t\t\tprocess.exit(result.exitCode);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatList, formatOutput } from \"../../lib/output.js\";\nimport type { Mcp } from \"../../types/index.js\";\n\nexport const statusCommand = new Command(\"status\")\n\t.description(\"Show current MCP sandbox status\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' to create one or 'waniwani mcp use <name>' to select one.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Fetching MCP status...\").start();\n\t\t\tconst result = await api.get<Mcp>(`/api/mcp/sandboxes/${mcpId}`);\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconst statusColor =\n\t\t\t\t\tresult.status === \"active\" ? chalk.green : chalk.red;\n\n\t\t\t\tformatList(\n\t\t\t\t\t[\n\t\t\t\t\t\t{ label: \"MCP ID\", value: result.id },\n\t\t\t\t\t\t{ label: \"Name\", value: result.name },\n\t\t\t\t\t\t{ label: \"Status\", value: statusColor(result.status) },\n\t\t\t\t\t\t{ label: \"Sandbox ID\", value: result.sandboxId },\n\t\t\t\t\t\t{ label: \"Preview URL\", value: result.previewUrl },\n\t\t\t\t\t\t{ label: \"Created\", value: result.createdAt },\n\t\t\t\t\t\t{ label: \"Expires\", value: result.expiresAt ?? \"N/A\" },\n\t\t\t\t\t],\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\n\nexport const stopCommand = new Command(\"stop\")\n\t.description(\"Stop and clean up the MCP sandbox\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\"No active MCP. Use --mcp-id to specify one.\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Stopping MCP sandbox...\").start();\n\t\t\tawait api.delete(`/api/mcp/sandboxes/${mcpId}`);\n\t\t\tspinner.succeed(\"MCP sandbox stopped\");\n\n\t\t\t// Clear active MCP if it was the one we stopped\n\t\t\tif ((await config.getMcpId()) === mcpId) {\n\t\t\t\tawait config.setMcpId(null);\n\t\t\t}\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ stopped: mcpId }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"MCP sandbox stopped and cleaned up.\", false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError, SandboxError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type {\n\tMcpCallResponse,\n\tMcpTestResponse,\n\tMcpToolResult,\n} from \"../../types/index.js\";\n\nexport const testCommand = new Command(\"test\")\n\t.description(\"Test MCP tools via the sandbox\")\n\t.argument(\"[tool]\", \"Tool name to test (lists tools if omitted)\")\n\t.argument(\"[args...]\", \"JSON arguments for the tool\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(\n\t\tasync (tool: string | undefined, args: string[], options, command) => {\n\t\t\tconst globalOptions = command.optsWithGlobals();\n\t\t\tconst json = globalOptions.json ?? false;\n\n\t\t\ttry {\n\t\t\t\tlet mcpId = options.mcpId;\n\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\t\tif (!mcpId) {\n\t\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!tool) {\n\t\t\t\t\t// List tools\n\t\t\t\t\tconst spinner = ora(\"Fetching available tools...\").start();\n\t\t\t\t\tconst result = await api.post<McpTestResponse>(\n\t\t\t\t\t\t`/api/mcp/sandboxes/${mcpId}/test`,\n\t\t\t\t\t\t{ action: \"list\" },\n\t\t\t\t\t);\n\t\t\t\t\tspinner.stop();\n\n\t\t\t\t\tconst tools = result.tools;\n\n\t\t\t\t\tif (json) {\n\t\t\t\t\t\tformatOutput({ tools }, true);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (tools.length === 0) {\n\t\t\t\t\t\t\tconsole.log(\"No tools available.\");\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(chalk.bold(\"\\nAvailable Tools:\\n\"));\n\t\t\t\t\t\t\tformatTable(\n\t\t\t\t\t\t\t\t[\"Name\", \"Description\"],\n\t\t\t\t\t\t\t\ttools.map((t) => [t.name, t.description || \"No description\"]),\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t`\\nTest a tool: waniwani mcp test <tool-name> '{\"arg\": \"value\"}'`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Call tool\n\t\t\t\t\tlet toolArgs: Record<string, unknown> = {};\n\t\t\t\t\tif (args.length > 0) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\ttoolArgs = JSON.parse(args.join(\" \"));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new SandboxError(\n\t\t\t\t\t\t\t\t`Invalid JSON arguments. Expected format: '{\"key\": \"value\"}'`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst spinner = ora(`Calling tool \"${tool}\"...`).start();\n\t\t\t\t\tconst startTime = Date.now();\n\t\t\t\t\tconst result = await api.post<McpCallResponse>(\n\t\t\t\t\t\t`/api/mcp/sandboxes/${mcpId}/test`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taction: \"call\",\n\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\targs: toolArgs,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tconst duration = result.duration || Date.now() - startTime;\n\t\t\t\t\tspinner.stop();\n\n\t\t\t\t\tconst output: McpToolResult = {\n\t\t\t\t\t\ttool,\n\t\t\t\t\t\tinput: toolArgs,\n\t\t\t\t\t\tresult: result.result,\n\t\t\t\t\t\tduration,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (json) {\n\t\t\t\t\t\tformatOutput(output, true);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.bold(\"\\nTool Result:\\n\"));\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Tool:\"), tool);\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Input:\"), JSON.stringify(toolArgs));\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Duration:\"), `${duration}ms`);\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Result:\"));\n\t\t\t\t\t\tconsole.log(JSON.stringify(result.result, null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\thandleError(error, json);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t},\n\t);\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config, globalConfig } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { Mcp, McpListResponse } from \"../../types/index.js\";\n\nexport const useCommand = new Command(\"use\")\n\t.description(\"Select an MCP to use for subsequent commands\")\n\t.argument(\"<name>\", \"Name of the MCP to use\")\n\t.option(\"--global\", \"Save to global config instead of project config\")\n\t.action(async (name: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching MCPs...\").start();\n\n\t\t\t// Fetch all MCPs\n\t\t\tconst mcps = await api.get<McpListResponse>(\"/api/admin/mcps\");\n\n\t\t\tspinner.stop();\n\n\t\t\t// Find MCP by name\n\t\t\tconst mcp = mcps.find((m: Mcp) => m.name === name);\n\n\t\t\tif (!mcp) {\n\t\t\t\tthrow new McpError(\n\t\t\t\t\t`MCP \"${name}\" not found. Run 'waniwani mcp list' to see available MCPs.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (mcp.status !== \"active\") {\n\t\t\t\tthrow new McpError(\n\t\t\t\t\t`MCP \"${name}\" is ${mcp.status}. Only active MCPs can be used.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst cfg = options.global ? globalConfig : config;\n\t\t\tawait cfg.setMcpId(mcp.id);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ selected: mcp, scope: cfg.scope }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`Now using MCP \"${name}\" (${cfg.scope})`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` MCP ID: ${mcp.id}`);\n\t\t\t\tconsole.log(` Preview URL: ${mcp.previewUrl}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Next steps:\");\n\t\t\t\tconsole.log(' waniwani task \"Add a tool\"');\n\t\t\t\tconsole.log(\" waniwani mcp test\");\n\t\t\t\tconsole.log(\" waniwani mcp status\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { readFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { CLIError, handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { WriteFilesResponse } from \"../../types/index.js\";\n\nexport const writeFileCommand = new Command(\"write-file\")\n\t.description(\"Write a file to the MCP sandbox\")\n\t.argument(\"<path>\", \"Path in sandbox (e.g., /app/src/index.ts)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--content <content>\", \"Content to write\")\n\t.option(\"--file <localFile>\", \"Local file to upload\")\n\t.option(\"--base64\", \"Treat content as base64 encoded\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Get content from --content or --file\n\t\t\tlet content: string;\n\t\t\tlet encoding: \"utf8\" | \"base64\" = \"utf8\";\n\n\t\t\tif (options.content) {\n\t\t\t\tcontent = options.content;\n\t\t\t\tif (options.base64) {\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t}\n\t\t\t} else if (options.file) {\n\t\t\t\tconst fileBuffer = await readFile(options.file);\n\t\t\t\tif (options.base64) {\n\t\t\t\t\tcontent = fileBuffer.toString(\"base64\");\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t} else {\n\t\t\t\t\tcontent = fileBuffer.toString(\"utf8\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new CLIError(\n\t\t\t\t\t\"Either --content or --file is required\",\n\t\t\t\t\t\"MISSING_CONTENT\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst spinner = ora(`Writing ${path}...`).start();\n\n\t\t\tconst result = await api.post<WriteFilesResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files`,\n\t\t\t\t{\n\t\t\t\t\tfiles: [{ path, content, encoding }],\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.succeed(`Wrote ${path}`);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`File written: ${path}`, false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport { listCommand } from \"./list.js\";\nimport { switchCommand } from \"./switch.js\";\n\nexport const orgCommand = new Command(\"org\")\n\t.description(\"Organization management commands\")\n\t.addCommand(listCommand)\n\t.addCommand(switchCommand);\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type { Org, OrgListResponse } from \"../../types/index.js\";\n\nexport const listCommand = new Command(\"list\")\n\t.description(\"List your organizations\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching organizations...\").start();\n\n\t\t\tconst result = await api.get<OrgListResponse>(\"/api/oauth/orgs\");\n\n\t\t\tspinner.stop();\n\n\t\t\tconst { orgs, activeOrgId } = result;\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(\n\t\t\t\t\t{\n\t\t\t\t\t\torgs: orgs.map((o: Org) => ({\n\t\t\t\t\t\t\t...o,\n\t\t\t\t\t\t\tisActive: o.id === activeOrgId,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tactiveOrgId,\n\t\t\t\t\t},\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (orgs.length === 0) {\n\t\t\t\t\tconsole.log(\"No organizations found.\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(chalk.bold(\"\\nOrganizations:\\n\"));\n\n\t\t\t\tconst rows = orgs.map((o: Org) => {\n\t\t\t\t\tconst isActive = o.id === activeOrgId;\n\t\t\t\t\treturn [\n\t\t\t\t\t\tisActive ? chalk.cyan(`* ${o.name}`) : ` ${o.name}`,\n\t\t\t\t\t\to.slug,\n\t\t\t\t\t\to.role,\n\t\t\t\t\t];\n\t\t\t\t});\n\n\t\t\t\tformatTable([\"Name\", \"Slug\", \"Role\"], rows, false);\n\n\t\t\t\tconsole.log();\n\t\t\t\tif (activeOrgId) {\n\t\t\t\t\tconst activeOrg = orgs.find((o: Org) => o.id === activeOrgId);\n\t\t\t\t\tif (activeOrg) {\n\t\t\t\t\t\tconsole.log(`Active organization: ${chalk.cyan(activeOrg.name)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.log(\"\\nSwitch organization: waniwani org switch <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { CLIError, handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type {\n\tOrg,\n\tOrgListResponse,\n\tOrgSwitchResponse,\n} from \"../../types/index.js\";\n\nexport const switchCommand = new Command(\"switch\")\n\t.description(\"Switch to a different organization\")\n\t.argument(\"<name>\", \"Name or slug of the organization to switch to\")\n\t.action(async (name: string, _, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching organizations...\").start();\n\n\t\t\t// First fetch orgs to find the org ID\n\t\t\tconst { orgs } = await api.get<OrgListResponse>(\"/api/oauth/orgs\");\n\n\t\t\t// Find org by name or slug\n\t\t\tconst org = orgs.find((o: Org) => o.name === name || o.slug === name);\n\n\t\t\tif (!org) {\n\t\t\t\tspinner.stop();\n\t\t\t\tthrow new CLIError(\n\t\t\t\t\t`Organization \"${name}\" not found. Run 'waniwani org list' to see available organizations.`,\n\t\t\t\t\t\"ORG_NOT_FOUND\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tspinner.text = \"Switching organization...\";\n\n\t\t\t// Switch to the org\n\t\t\tawait api.post<OrgSwitchResponse>(\"/api/oauth/orgs/switch\", {\n\t\t\t\torgId: org.id,\n\t\t\t});\n\n\t\t\tspinner.succeed(\"Organization switched\");\n\n\t\t\t// Clear local MCP selection since we switched orgs\n\t\t\tconfig.setMcpId(null);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ switched: org }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`Switched to organization \"${org.name}\"`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Note: Active MCP selection has been cleared.\");\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"Run 'waniwani mcp list' to see MCPs in this organization.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../lib/api.js\";\nimport { auth } from \"../lib/auth.js\";\nimport { config } from \"../lib/config.js\";\nimport { AuthError, handleError, McpError } from \"../lib/errors.js\";\nimport { formatOutput } from \"../lib/output.js\";\nimport type { TaskDoneEvent, TaskStep, TaskStepEvent } from \"../types/index.js\";\n\nexport const taskCommand = new Command(\"task\")\n\t.description(\"Send a task to Claude running in the sandbox\")\n\t.argument(\"<prompt>\", \"Task description/prompt\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--model <model>\", \"Claude model to use\")\n\t.option(\"--max-steps <n>\", \"Maximum tool use steps\")\n\t.action(async (prompt: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani init' then 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst token = await auth.getAccessToken();\n\t\t\tif (!token) {\n\t\t\t\tthrow new AuthError(\n\t\t\t\t\t\"Not logged in. Run 'waniwani login' to authenticate.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst defaults = await config.getDefaults();\n\t\t\tconst model = options.model ?? defaults.model;\n\t\t\tconst maxSteps = options.maxSteps\n\t\t\t\t? Number.parseInt(options.maxSteps, 10)\n\t\t\t\t: defaults.maxSteps;\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(chalk.bold(\"Task:\"), prompt);\n\t\t\t\tconsole.log();\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Starting task...\").start();\n\n\t\t\t// Use fetch with SSE for streaming\n\t\t\tconst baseUrl = await api.getBaseUrl();\n\t\t\tconst response = await fetch(\n\t\t\t\t`${baseUrl}/api/mcp/sandboxes/${mcpId}/task`,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t\tAccept: \"text/event-stream\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tprompt,\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tmaxSteps,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst error = await response\n\t\t\t\t\t.json()\n\t\t\t\t\t.catch(() => ({ message: response.statusText }));\n\t\t\t\tspinner.fail(\"Task failed\");\n\t\t\t\tthrow new Error(\n\t\t\t\t\terror.message || `Request failed with status ${response.status}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tspinner.stop();\n\n\t\t\tconst steps: TaskStep[] = [];\n\t\t\tlet stepCount = 0;\n\t\t\tlet maxStepsReached = false;\n\n\t\t\t// Process SSE stream\n\t\t\tconst reader = response.body?.getReader();\n\t\t\tif (!reader) {\n\t\t\t\tthrow new Error(\"No response body\");\n\t\t\t}\n\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\n\t\t\twhile (true) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done) break;\n\n\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\t\tfor (const line of lines) {\n\t\t\t\t\tif (line.startsWith(\"event: \")) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (line.startsWith(\"data: \")) {\n\t\t\t\t\t\tconst data = line.slice(6);\n\t\t\t\t\t\tif (!data || data === \"[DONE]\") continue;\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst parsed = JSON.parse(data);\n\n\t\t\t\t\t\t\t// Handle step events\n\t\t\t\t\t\t\tif (parsed.type === \"text\") {\n\t\t\t\t\t\t\t\tconst event = parsed as TaskStepEvent;\n\t\t\t\t\t\t\t\tsteps.push({ type: \"text\", text: event.content });\n\t\t\t\t\t\t\t\tif (!json && event.content) {\n\t\t\t\t\t\t\t\t\tconsole.log(chalk.white(event.content));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (parsed.type === \"tool_call\") {\n\t\t\t\t\t\t\t\tconst event = parsed as TaskStepEvent;\n\t\t\t\t\t\t\t\tsteps.push({\n\t\t\t\t\t\t\t\t\ttype: \"tool_call\",\n\t\t\t\t\t\t\t\t\ttool: event.tool,\n\t\t\t\t\t\t\t\t\tinput: event.input,\n\t\t\t\t\t\t\t\t\toutput: event.output,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!json) {\n\t\t\t\t\t\t\t\t\tconsole.log(chalk.cyan(`> Using tool: ${event.tool}`));\n\t\t\t\t\t\t\t\t\tif (event.input?.command) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(` $ ${event.input.command}`));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (event.output) {\n\t\t\t\t\t\t\t\t\t\t// Show abbreviated output\n\t\t\t\t\t\t\t\t\t\tconst outputLines = event.output.split(\"\\n\");\n\t\t\t\t\t\t\t\t\t\tif (outputLines.length > 10) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t\t\tchalk.gray(outputLines.slice(0, 5).join(\"\\n\")),\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t\t\tchalk.gray(\n\t\t\t\t\t\t\t\t\t\t\t\t\t` ... (${outputLines.length - 10} more lines)`,\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(outputLines.slice(-5).join(\"\\n\")));\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(event.output));\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconsole.log();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (parsed.success !== undefined) {\n\t\t\t\t\t\t\t\t// Handle done event\n\t\t\t\t\t\t\t\tconst doneEvent = parsed as TaskDoneEvent;\n\t\t\t\t\t\t\t\tstepCount = doneEvent.stepCount;\n\t\t\t\t\t\t\t\tmaxStepsReached = doneEvent.maxStepsReached || false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore malformed JSON\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = {\n\t\t\t\tsuccess: true,\n\t\t\t\tsteps,\n\t\t\t\tstepCount,\n\t\t\t\tmaxStepsReached,\n\t\t\t};\n\n\t\t\tconst finalStepCount = stepCount ?? steps.length;\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ ...result, stepCount: finalStepCount }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.green(\"✓\"),\n\t\t\t\t\t`Task completed in ${finalStepCount} steps.`,\n\t\t\t\t);\n\t\t\t\tif (maxStepsReached) {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\tchalk.yellow(\"⚠\"),\n\t\t\t\t\t\t\"Maximum steps reached. Task may be incomplete.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { program }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,WAAW,UAAU;AAC7B,QAAQ,WAAW,WAAW;AAC9B,QAAQ,WAAW,UAAU;;;AyBvB7B,QAAQ,MAAM,QAAQ,IAAI;","names":["Command","chalk","chalk","chalk","Command","mkdir","readFile","writeFile","homedir","join","z","existsSync","mkdir","writeFile","join","join","homedir","z","mkdir","readFile","writeFile","Command","chalk","Command","Command","Command","Command","ora","Command","ora","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","writeFile","Command","ora","Command","ora","writeFile","chalk","Command","ora","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","readFile","Command","ora","Command","readFile","ora","Command","Command","chalk","Command","ora","listCommand","Command","ora","chalk","Command","ora","Command","ora","Command","listCommand","chalk","Command","ora","Command","chalk","ora","Command"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/commands/init.ts","../src/lib/errors.ts","../src/lib/output.ts","../src/commands/login.ts","../src/lib/auth.ts","../src/lib/config.ts","../src/commands/logout.ts","../src/commands/mcp/index.ts","../src/commands/mcp/create.ts","../src/lib/api.ts","../src/commands/mcp/delete.ts","../src/commands/mcp/deploy.ts","../src/commands/mcp/file/index.ts","../src/commands/mcp/file/list.ts","../src/commands/mcp/file/read.ts","../src/commands/mcp/file/write.ts","../src/commands/mcp/list.ts","../src/commands/mcp/logs.ts","../src/commands/mcp/run-command.ts","../src/commands/mcp/start.ts","../src/commands/mcp/status.ts","../src/commands/mcp/stop.ts","../src/commands/mcp/test.ts","../src/commands/mcp/use.ts","../src/commands/org/index.ts","../src/commands/org/list.ts","../src/commands/org/switch.ts","../src/commands/task.ts","../src/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { initCommand } from \"./commands/init.js\";\nimport { loginCommand } from \"./commands/login.js\";\nimport { logoutCommand } from \"./commands/logout.js\";\nimport { mcpCommand } from \"./commands/mcp/index.js\";\nimport { orgCommand } from \"./commands/org/index.js\";\nimport { taskCommand } from \"./commands/task.js\";\n\nconst version = \"0.1.0\";\n\nexport const program = new Command()\n\t.name(\"waniwani\")\n\t.description(\"WaniWani CLI for MCP development workflow\")\n\t.version(version)\n\t.option(\"--json\", \"Output results as JSON\")\n\t.option(\"--verbose\", \"Enable verbose logging\");\n\n// Auth commands\nprogram.addCommand(loginCommand);\nprogram.addCommand(logoutCommand);\n\n// Main commands\nprogram.addCommand(initCommand);\nprogram.addCommand(mcpCommand);\nprogram.addCommand(taskCommand);\nprogram.addCommand(orgCommand);\n","import { existsSync } from \"node:fs\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { Command } from \"commander\";\nimport { handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\n\nconst PROJECT_CONFIG_DIR = \".waniwani\";\nconst PROJECT_CONFIG_FILE = \"settings.local.json\";\n\nexport const initCommand = new Command(\"init\")\n\t.description(\"Initialize WaniWani project config in current directory\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst cwd = process.cwd();\n\t\t\tconst configDir = join(cwd, PROJECT_CONFIG_DIR);\n\t\t\tconst configPath = join(configDir, PROJECT_CONFIG_FILE);\n\n\t\t\tif (existsSync(configDir)) {\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput(\n\t\t\t\t\t\t{ initialized: false, message: \"Already initialized\" },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Project already initialized (.waniwani/ exists)\");\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait mkdir(configDir, { recursive: true });\n\n\t\t\tconst defaultConfig = {\n\t\t\t\tmcpId: null,\n\t\t\t\tdefaults: {},\n\t\t\t};\n\n\t\t\tawait writeFile(\n\t\t\t\tconfigPath,\n\t\t\t\tJSON.stringify(defaultConfig, null, \"\\t\"),\n\t\t\t\t\"utf-8\",\n\t\t\t);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ initialized: true, path: configDir }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"Initialized WaniWani project config\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` Created: ${PROJECT_CONFIG_DIR}/${PROJECT_CONFIG_FILE}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Now run:\");\n\t\t\t\tconsole.log(' waniwani mcp create \"my-mcp\"');\n\t\t\t\tconsole.log(\" waniwani mcp use <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { ZodError } from \"zod\";\n\nexport class CLIError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic code: string,\n\t\tpublic details?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"CLIError\";\n\t}\n}\n\nexport class ConfigError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"CONFIG_ERROR\", details);\n\t}\n}\n\nexport class AuthError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"AUTH_ERROR\", details);\n\t}\n}\n\nexport class SandboxError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"SANDBOX_ERROR\", details);\n\t}\n}\n\nexport class GitHubError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"GITHUB_ERROR\", details);\n\t}\n}\n\nexport class McpError extends CLIError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(message, \"MCP_ERROR\", details);\n\t}\n}\n\nexport function handleError(error: unknown, json: boolean): void {\n\tif (error instanceof ZodError) {\n\t\tconst message = error.issues\n\t\t\t.map((e) => `${e.path.join(\".\")}: ${e.message}`)\n\t\t\t.join(\", \");\n\t\toutputError(\"VALIDATION_ERROR\", `Invalid input: ${message}`, json);\n\t} else if (error instanceof CLIError) {\n\t\toutputError(error.code, error.message, json, error.details);\n\t} else if (error instanceof Error) {\n\t\toutputError(\"UNKNOWN_ERROR\", error.message, json);\n\t} else {\n\t\toutputError(\"UNKNOWN_ERROR\", String(error), json);\n\t}\n}\n\nfunction outputError(\n\tcode: string,\n\tmessage: string,\n\tjson: boolean,\n\tdetails?: Record<string, unknown>,\n): void {\n\tif (json) {\n\t\tconsole.error(\n\t\t\tJSON.stringify({ success: false, error: { code, message, details } }),\n\t\t);\n\t} else {\n\t\tconsole.error(chalk.red(`Error [${code}]:`), message);\n\t\tif (details) {\n\t\t\tconsole.error(chalk.gray(\"Details:\"), JSON.stringify(details, null, 2));\n\t\t}\n\t}\n}\n","import chalk from \"chalk\";\n\nexport function formatOutput<T>(data: T, json: boolean): void {\n\tif (json) {\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\tprettyPrint(data);\n\t}\n}\n\nexport function formatSuccess(message: string, json: boolean): void {\n\tif (json) {\n\t\tconsole.log(JSON.stringify({ success: true, message }));\n\t} else {\n\t\tconsole.log(chalk.green(\"✓\"), message);\n\t}\n}\n\nexport function formatError(error: Error | string, json: boolean): void {\n\tconst message = error instanceof Error ? error.message : error;\n\tif (json) {\n\t\tconsole.error(JSON.stringify({ success: false, error: message }));\n\t} else {\n\t\tconsole.error(chalk.red(\"✗\"), message);\n\t}\n}\n\nexport function formatTable(\n\theaders: string[],\n\trows: string[][],\n\tjson: boolean,\n): void {\n\tif (json) {\n\t\tconst data = rows.map((row) =>\n\t\t\tObject.fromEntries(headers.map((header, i) => [header, row[i]])),\n\t\t);\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\t// Simple table formatting without external dependency\n\t\tconst colWidths = headers.map((h, i) =>\n\t\t\tMath.max(h.length, ...rows.map((r) => (r[i] || \"\").length)),\n\t\t);\n\n\t\tconst separator = colWidths.map((w) => \"-\".repeat(w + 2)).join(\"+\");\n\t\tconst formatRow = (row: string[]) =>\n\t\t\trow.map((cell, i) => ` ${(cell || \"\").padEnd(colWidths[i])} `).join(\"|\");\n\n\t\tconsole.log(chalk.cyan(formatRow(headers)));\n\t\tconsole.log(separator);\n\t\tfor (const row of rows) {\n\t\t\tconsole.log(formatRow(row));\n\t\t}\n\t}\n}\n\nexport function formatList(\n\titems: Array<{ label: string; value: string }>,\n\tjson: boolean,\n): void {\n\tif (json) {\n\t\tconst data = Object.fromEntries(\n\t\t\titems.map((item) => [item.label, item.value]),\n\t\t);\n\t\tconsole.log(JSON.stringify({ success: true, data }, null, 2));\n\t} else {\n\t\tconst maxLabelLength = Math.max(...items.map((i) => i.label.length));\n\t\titems.forEach((item) => {\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.gray(item.label.padEnd(maxLabelLength))} ${chalk.white(item.value)}`,\n\t\t\t);\n\t\t});\n\t}\n}\n\nfunction prettyPrint(data: unknown, indent = 0): void {\n\tconst prefix = \" \".repeat(indent);\n\n\tif (Array.isArray(data)) {\n\t\tdata.forEach((item, index) => {\n\t\t\tconsole.log(`${prefix}${chalk.gray(`[${index}]`)}`);\n\t\t\tprettyPrint(item, indent + 1);\n\t\t});\n\t} else if (typeof data === \"object\" && data !== null) {\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\t\tconsole.log(`${prefix}${chalk.gray(key)}:`);\n\t\t\t\tprettyPrint(value, indent + 1);\n\t\t\t} else {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${prefix}${chalk.gray(key)}: ${chalk.white(String(value))}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconsole.log(`${prefix}${chalk.white(String(data))}`);\n\t}\n}\n","import { spawn } from \"node:child_process\";\nimport { createServer, type Server } from \"node:http\";\nimport type { Socket } from \"node:net\";\nimport chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { auth } from \"../lib/auth.js\";\nimport { config } from \"../lib/config.js\";\nimport { CLIError, handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\nimport type {\n\tOAuthClientRegistrationResponse,\n\tOAuthTokenResponse,\n} from \"../types/index.js\";\n\nconst CALLBACK_PORT = 54321;\nconst CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;\nconst CLIENT_NAME = \"waniwani-cli\";\n\nfunction generateCodeVerifier(): string {\n\tconst array = new Uint8Array(32);\n\tcrypto.getRandomValues(array);\n\treturn btoa(String.fromCharCode(...array))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nasync function generateCodeChallenge(verifier: string): Promise<string> {\n\tconst encoder = new TextEncoder();\n\tconst data = encoder.encode(verifier);\n\tconst hash = await crypto.subtle.digest(\"SHA-256\", data);\n\treturn btoa(String.fromCharCode(...new Uint8Array(hash)))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nfunction generateState(): string {\n\tconst array = new Uint8Array(16);\n\tcrypto.getRandomValues(array);\n\treturn Array.from(array, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nasync function registerClient(): Promise<OAuthClientRegistrationResponse> {\n\tconst apiUrl = await config.getApiUrl();\n\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/register`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tclient_name: CLIENT_NAME,\n\t\t\tredirect_uris: [CALLBACK_URL],\n\t\t\tgrant_types: [\"authorization_code\", \"refresh_token\"],\n\t\t\tresponse_types: [\"code\"],\n\t\t\ttoken_endpoint_auth_method: \"none\",\n\t\t}),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.json().catch(() => ({}));\n\t\tthrow new CLIError(\n\t\t\t(error as { error_description?: string }).error_description ||\n\t\t\t\t\"Failed to register OAuth client\",\n\t\t\t\"CLIENT_REGISTRATION_FAILED\",\n\t\t);\n\t}\n\n\treturn response.json() as Promise<OAuthClientRegistrationResponse>;\n}\n\nasync function openBrowser(url: string): Promise<void> {\n\tconst [cmd, ...args] =\n\t\tprocess.platform === \"darwin\"\n\t\t\t? [\"open\", url]\n\t\t\t: process.platform === \"win32\"\n\t\t\t\t? [\"cmd\", \"/c\", \"start\", url]\n\t\t\t\t: [\"xdg-open\", url];\n\n\tspawn(cmd, args, { stdio: \"ignore\", detached: true }).unref();\n}\n\nasync function waitForCallback(\n\texpectedState: string,\n\ttimeoutMs: number = 300000,\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet server: Server | null = null;\n\t\tconst sockets = new Set<Socket>();\n\n\t\tconst timeout = setTimeout(() => {\n\t\t\tcleanup();\n\t\t\treject(new CLIError(\"Login timed out\", \"LOGIN_TIMEOUT\"));\n\t\t}, timeoutMs);\n\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\t// Destroy all active connections to allow process to exit\n\t\t\tfor (const socket of sockets) {\n\t\t\t\tsocket.destroy();\n\t\t\t}\n\t\t\tsockets.clear();\n\t\t\tserver?.close();\n\t\t};\n\n\t\tconst htmlResponse = (title: string, message: string, color: string) =>\n\t\t\t`<html>\n <body style=\"font-family: system-ui; padding: 40px; text-align: center;\">\n <h1 style=\"color: ${color};\">${title}</h1>\n <p>${message}</p>\n <p>You can close this window.</p>\n </body>\n </html>`;\n\n\t\ttry {\n\t\t\tserver = createServer((req, res) => {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\treq.url || \"/\",\n\t\t\t\t\t`http://localhost:${CALLBACK_PORT}`,\n\t\t\t\t);\n\n\t\t\t\tif (url.pathname === \"/callback\") {\n\t\t\t\t\tconst code = url.searchParams.get(\"code\");\n\t\t\t\t\tconst state = url.searchParams.get(\"state\");\n\t\t\t\t\tconst error = url.searchParams.get(\"error\");\n\n\t\t\t\t\tres.setHeader(\"Content-Type\", \"text/html\");\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(htmlResponse(\"Login Failed\", `Error: ${error}`, \"#ef4444\"));\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(`OAuth error: ${error}`, \"OAUTH_ERROR\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (state !== expectedState) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(\n\t\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\t\"Login Failed\",\n\t\t\t\t\t\t\t\t\"Invalid state parameter. Please try again.\",\n\t\t\t\t\t\t\t\t\"#ef4444\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(\"Invalid state parameter\", \"INVALID_STATE\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!code) {\n\t\t\t\t\t\tres.statusCode = 400;\n\t\t\t\t\t\tres.end(\n\t\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\t\"Login Failed\",\n\t\t\t\t\t\t\t\t\"No authorization code received.\",\n\t\t\t\t\t\t\t\t\"#ef4444\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\treject(new CLIError(\"No authorization code\", \"NO_CODE\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tres.statusCode = 200;\n\t\t\t\t\tres.end(\n\t\t\t\t\t\thtmlResponse(\n\t\t\t\t\t\t\t\"Login Successful!\",\n\t\t\t\t\t\t\t\"You can close this window and return to the terminal.\",\n\t\t\t\t\t\t\t\"#22c55e\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Schedule cleanup after response is sent\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\tresolve(code);\n\t\t\t\t\t}, 100);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tres.statusCode = 404;\n\t\t\t\tres.end(\"Not found\");\n\t\t\t});\n\n\t\t\t// Track connections so we can force-close them\n\t\t\tserver.on(\"connection\", (socket) => {\n\t\t\t\tsockets.add(socket);\n\t\t\t\tsocket.on(\"close\", () => sockets.delete(socket));\n\t\t\t});\n\n\t\t\tserver.on(\"error\", (err: NodeJS.ErrnoException) => {\n\t\t\t\tcleanup();\n\t\t\t\tif (err.code === \"EADDRINUSE\") {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew CLIError(\n\t\t\t\t\t\t\t`Port ${CALLBACK_PORT} is already in use. Close any other WaniWani CLI instances and try again.`,\n\t\t\t\t\t\t\t\"PORT_IN_USE\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\treject(err);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tserver.listen(CALLBACK_PORT);\n\t\t} catch (err: unknown) {\n\t\t\tcleanup();\n\t\t\treject(err);\n\t\t}\n\t});\n}\n\nasync function exchangeCodeForToken(\n\tcode: string,\n\tcodeVerifier: string,\n\tclientId: string,\n\tresource: string,\n): Promise<OAuthTokenResponse> {\n\tconst apiUrl = await config.getApiUrl();\n\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/token`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t},\n\t\tbody: new URLSearchParams({\n\t\t\tgrant_type: \"authorization_code\",\n\t\t\tcode,\n\t\t\tredirect_uri: CALLBACK_URL,\n\t\t\tclient_id: clientId,\n\t\t\tcode_verifier: codeVerifier,\n\t\t\tresource, // RFC 8707 - required to get JWT token\n\t\t}).toString(),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.json().catch(() => ({}));\n\t\tthrow new CLIError(\n\t\t\t(error as { error_description?: string }).error_description ||\n\t\t\t\t\"Failed to exchange code for token\",\n\t\t\t\"TOKEN_EXCHANGE_FAILED\",\n\t\t);\n\t}\n\n\treturn response.json() as Promise<OAuthTokenResponse>;\n}\n\nexport const loginCommand = new Command(\"login\")\n\t.description(\"Log in to WaniWani\")\n\t.option(\"--no-browser\", \"Don't open the browser automatically\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\t// Check if already logged in with a valid session\n\t\t\tif (await auth.isLoggedIn()) {\n\t\t\t\t// Check if token is expired\n\t\t\t\tif (await auth.isTokenExpired()) {\n\t\t\t\t\t// Try to refresh the token\n\t\t\t\t\tconst refreshed = await auth.tryRefreshToken();\n\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\tif (json) {\n\t\t\t\t\t\t\tformatOutput({ alreadyLoggedIn: true, refreshed: true }, true);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\tchalk.green(\"Session refreshed. You're still logged in.\"),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t// Refresh failed, clear and proceed with login\n\t\t\t\t\tif (!json) {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\tchalk.yellow(\"Session expired. Starting new login flow...\"),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait auth.clear();\n\t\t\t\t} else {\n\t\t\t\t\t// Token is valid\n\t\t\t\t\tif (json) {\n\t\t\t\t\t\tformatOutput({ alreadyLoggedIn: true }, true);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\tchalk.yellow(\n\t\t\t\t\t\t\t\t\"Already logged in. Use 'waniwani logout' to log out first.\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log(chalk.bold(\"\\nWaniWani CLI Login\\n\"));\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Registering client...\").start();\n\n\t\t\t// Register OAuth client dynamically\n\t\t\tconst { client_id: clientId } = await registerClient();\n\n\t\t\tspinner.text = \"Preparing authentication...\";\n\n\t\t\t// Generate PKCE values\n\t\t\tconst codeVerifier = generateCodeVerifier();\n\t\t\tconst codeChallenge = await generateCodeChallenge(codeVerifier);\n\t\t\tconst state = generateState();\n\n\t\t\t// Build authorization URL\n\t\t\tconst apiUrl = await config.getApiUrl();\n\t\t\tconst authUrl = new URL(`${apiUrl}/api/auth/oauth2/authorize`);\n\t\t\tauthUrl.searchParams.set(\"client_id\", clientId);\n\t\t\tauthUrl.searchParams.set(\"redirect_uri\", CALLBACK_URL);\n\t\t\tauthUrl.searchParams.set(\"response_type\", \"code\");\n\t\t\tauthUrl.searchParams.set(\"code_challenge\", codeChallenge);\n\t\t\tauthUrl.searchParams.set(\"code_challenge_method\", \"S256\");\n\t\t\tauthUrl.searchParams.set(\"state\", state);\n\t\t\tauthUrl.searchParams.set(\"resource\", apiUrl); // RFC 8707 - request JWT token\n\n\t\t\tspinner.stop();\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log(\"Opening browser for authentication...\\n\");\n\t\t\t\tconsole.log(`If the browser doesn't open, visit:\\n`);\n\t\t\t\tconsole.log(chalk.cyan(` ${authUrl.toString()}`));\n\t\t\t\tconsole.log();\n\t\t\t}\n\n\t\t\t// Start callback server and open browser\n\t\t\tconst callbackPromise = waitForCallback(state);\n\n\t\t\tif (options.browser !== false) {\n\t\t\t\tawait openBrowser(authUrl.toString());\n\t\t\t}\n\n\t\t\tspinner.start(\"Waiting for authorization...\");\n\n\t\t\t// Wait for callback with auth code\n\t\t\tconst code = await callbackPromise;\n\n\t\t\tspinner.text = \"Exchanging code for token...\";\n\n\t\t\t// Exchange code for token\n\t\t\tconst tokenResponse = await exchangeCodeForToken(\n\t\t\t\tcode,\n\t\t\t\tcodeVerifier,\n\t\t\t\tclientId,\n\t\t\t\tapiUrl, // RFC 8707 resource parameter\n\t\t\t);\n\n\t\t\t// Store tokens and client ID for refresh\n\t\t\tawait auth.setTokens(\n\t\t\t\ttokenResponse.access_token,\n\t\t\t\ttokenResponse.refresh_token,\n\t\t\t\ttokenResponse.expires_in,\n\t\t\t\tclientId,\n\t\t\t);\n\n\t\t\tspinner.succeed(\"Logged in successfully!\");\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ success: true, loggedIn: true }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(\"You're now logged in to WaniWani!\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Get started:\");\n\t\t\t\tconsole.log(\n\t\t\t\t\t\" waniwani mcp create my-server Create a new MCP sandbox\",\n\t\t\t\t);\n\t\t\t\tconsole.log(' waniwani task \"Add a tool\" Send tasks to Claude');\n\t\t\t\tconsole.log(\n\t\t\t\t\t\" waniwani org list View your organizations\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { access, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\nimport { config } from \"./config.js\";\n\nconst CONFIG_DIR = join(homedir(), \".waniwani\");\nconst AUTH_FILE = join(CONFIG_DIR, \"auth.json\");\n\nconst AuthStoreSchema = z.object({\n\taccessToken: z.string().nullable().default(null),\n\trefreshToken: z.string().nullable().default(null),\n\texpiresAt: z.string().nullable().default(null),\n\tclientId: z.string().nullable().default(null),\n});\n\ntype AuthStore = z.infer<typeof AuthStoreSchema>;\n\nasync function ensureConfigDir(): Promise<void> {\n\tawait mkdir(CONFIG_DIR, { recursive: true });\n}\n\nasync function readAuthStore(): Promise<AuthStore> {\n\tawait ensureConfigDir();\n\ttry {\n\t\tawait access(AUTH_FILE);\n\t\tconst content = await readFile(AUTH_FILE, \"utf-8\");\n\t\treturn AuthStoreSchema.parse(JSON.parse(content));\n\t} catch {\n\t\treturn AuthStoreSchema.parse({});\n\t}\n}\n\nasync function writeAuthStore(store: AuthStore): Promise<void> {\n\tawait ensureConfigDir();\n\tawait writeFile(AUTH_FILE, JSON.stringify(store, null, 2), \"utf-8\");\n}\n\nclass AuthManager {\n\tprivate storeCache: AuthStore | null = null;\n\n\tprivate async getStore(): Promise<AuthStore> {\n\t\tif (!this.storeCache) {\n\t\t\tthis.storeCache = await readAuthStore();\n\t\t}\n\t\treturn this.storeCache;\n\t}\n\n\tprivate async saveStore(store: AuthStore): Promise<void> {\n\t\tthis.storeCache = store;\n\t\tawait writeAuthStore(store);\n\t}\n\n\tasync isLoggedIn(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\treturn !!store.accessToken;\n\t}\n\n\tasync getAccessToken(): Promise<string | null> {\n\t\tconst store = await this.getStore();\n\t\treturn store.accessToken;\n\t}\n\n\tasync getRefreshToken(): Promise<string | null> {\n\t\tconst store = await this.getStore();\n\t\treturn store.refreshToken;\n\t}\n\n\tasync setTokens(\n\t\taccessToken: string,\n\t\trefreshToken: string,\n\t\texpiresIn: number,\n\t\tclientId?: string,\n\t): Promise<void> {\n\t\tconst expiresAt = new Date(Date.now() + expiresIn * 1000).toISOString();\n\t\tconst store = await this.getStore();\n\t\tstore.accessToken = accessToken;\n\t\tstore.refreshToken = refreshToken;\n\t\tstore.expiresAt = expiresAt;\n\t\tif (clientId) {\n\t\t\tstore.clientId = clientId;\n\t\t}\n\t\tawait this.saveStore(store);\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst emptyStore = AuthStoreSchema.parse({});\n\t\tawait this.saveStore(emptyStore);\n\t}\n\n\tasync isTokenExpired(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\tif (!store.expiresAt) return true;\n\t\t// Consider expired 5 minutes before actual expiry\n\t\treturn new Date(store.expiresAt).getTime() - 5 * 60 * 1000 < Date.now();\n\t}\n\n\tasync tryRefreshToken(): Promise<boolean> {\n\t\tconst store = await this.getStore();\n\t\tconst { refreshToken, clientId } = store;\n\t\tif (!refreshToken || !clientId) return false;\n\n\t\ttry {\n\t\t\tconst apiUrl = await config.getApiUrl();\n\t\t\tconst response = await fetch(`${apiUrl}/api/auth/oauth2/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshToken,\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t}).toString(),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tawait this.clear();\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst data = (await response.json()) as {\n\t\t\t\taccess_token: string;\n\t\t\t\trefresh_token: string;\n\t\t\t\texpires_in: number;\n\t\t\t};\n\n\t\t\tawait this.setTokens(\n\t\t\t\tdata.access_token,\n\t\t\t\tdata.refresh_token,\n\t\t\t\tdata.expires_in,\n\t\t\t);\n\n\t\t\treturn true;\n\t\t} catch {\n\t\t\tawait this.clear();\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\nexport const auth = new AuthManager();\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\n\nconst LOCAL_DIR = join(process.cwd(), \".waniwani\");\nconst LOCAL_FILE = join(LOCAL_DIR, \"settings.json\");\nconst GLOBAL_DIR = join(homedir(), \".waniwani\");\nconst GLOBAL_FILE = join(GLOBAL_DIR, \"settings.json\");\nconst DEFAULT_API_URL = \"https://app.waniwani.ai\";\n\nconst ConfigSchema = z.object({\n\tdefaults: z\n\t\t.object({ model: z.string(), maxSteps: z.number() })\n\t\t.default({ model: \"claude-sonnet-4-20250514\", maxSteps: 10 }),\n\tmcpId: z.string().nullable().default(null),\n\tapiUrl: z.string().nullable().default(null),\n});\n\ntype ConfigData = z.infer<typeof ConfigSchema>;\n\nclass Config {\n\tprivate dir: string;\n\tprivate file: string;\n\tprivate cache: ConfigData | null = null;\n\treadonly scope: \"local\" | \"global\";\n\n\tconstructor(forceGlobal = false) {\n\t\tconst useLocal = !forceGlobal && existsSync(LOCAL_DIR);\n\t\tthis.dir = useLocal ? LOCAL_DIR : GLOBAL_DIR;\n\t\tthis.file = useLocal ? LOCAL_FILE : GLOBAL_FILE;\n\t\tthis.scope = useLocal ? \"local\" : \"global\";\n\t}\n\n\tprivate async load(): Promise<ConfigData> {\n\t\tif (!this.cache) {\n\t\t\ttry {\n\t\t\t\tthis.cache = ConfigSchema.parse(\n\t\t\t\t\tJSON.parse(await readFile(this.file, \"utf-8\")),\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\tthis.cache = ConfigSchema.parse({});\n\t\t\t}\n\t\t}\n\t\treturn this.cache;\n\t}\n\n\tprivate async save(data: ConfigData): Promise<void> {\n\t\tthis.cache = data;\n\t\tawait mkdir(this.dir, { recursive: true });\n\t\tawait writeFile(this.file, JSON.stringify(data, null, \"\\t\"));\n\t}\n\n\tasync getDefaults() {\n\t\treturn (await this.load()).defaults;\n\t}\n\n\tasync setDefaults(defaults: Partial<ConfigData[\"defaults\"]>) {\n\t\tconst data = await this.load();\n\t\tdata.defaults = { ...data.defaults, ...defaults };\n\t\tawait this.save(data);\n\t}\n\n\tasync getMcpId() {\n\t\treturn (await this.load()).mcpId;\n\t}\n\n\tasync setMcpId(id: string | null) {\n\t\tconst data = await this.load();\n\t\tdata.mcpId = id;\n\t\tawait this.save(data);\n\t}\n\n\tasync getApiUrl() {\n\t\tif (process.env.WANIWANI_API_URL) return process.env.WANIWANI_API_URL;\n\t\treturn (await this.load()).apiUrl || DEFAULT_API_URL;\n\t}\n\n\tasync setApiUrl(url: string | null) {\n\t\tconst data = await this.load();\n\t\tdata.apiUrl = url;\n\t\tawait this.save(data);\n\t}\n\n\tasync clear() {\n\t\tawait this.save(ConfigSchema.parse({}));\n\t}\n}\n\nexport const config = new Config();\nexport const globalConfig = new Config(true);\n","import { Command } from \"commander\";\nimport { auth } from \"../lib/auth.js\";\nimport { handleError } from \"../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../lib/output.js\";\n\nexport const logoutCommand = new Command(\"logout\")\n\t.description(\"Log out from WaniWani\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tif (!(await auth.isLoggedIn())) {\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput({ alreadyLoggedOut: true }, true);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(\"Not currently logged in.\");\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Clear auth tokens only (keep config like apiUrl intact)\n\t\t\tawait auth.clear();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ success: true }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"You have been logged out.\", false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport { createCommand } from \"./create.js\";\nimport { deleteCommand } from \"./delete.js\";\nimport { deployCommand } from \"./deploy.js\";\nimport { fileCommand } from \"./file/index.js\";\nimport { listCommand } from \"./list.js\";\nimport { logsCommand } from \"./logs.js\";\nimport { runCommandCommand } from \"./run-command.js\";\nimport { startCommand } from \"./start.js\";\nimport { statusCommand } from \"./status.js\";\nimport { stopCommand } from \"./stop.js\";\nimport { testCommand } from \"./test.js\";\nimport { useCommand } from \"./use.js\";\n\nexport const mcpCommand = new Command(\"mcp\")\n\t.description(\"MCP sandbox management commands\")\n\t.addCommand(createCommand)\n\t.addCommand(listCommand)\n\t.addCommand(useCommand)\n\t.addCommand(statusCommand)\n\t.addCommand(startCommand)\n\t.addCommand(stopCommand)\n\t.addCommand(logsCommand)\n\t.addCommand(deleteCommand)\n\t.addCommand(testCommand)\n\t.addCommand(deployCommand)\n\t.addCommand(fileCommand)\n\t.addCommand(runCommandCommand);\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config, globalConfig } from \"../../lib/config.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { CreateMcpResponse } from \"../../types/index.js\";\n\nexport const createCommand = new Command(\"create\")\n\t.description(\"Create a new MCP sandbox from template\")\n\t.argument(\"<name>\", \"Name for the MCP project\")\n\t.option(\"--global\", \"Save to global config instead of project config\")\n\t.action(async (name: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Creating MCP sandbox...\").start();\n\n\t\t\tconst result = await api.post<CreateMcpResponse>(\"/api/mcp/sandboxes\", {\n\t\t\t\tname,\n\t\t\t});\n\n\t\t\tspinner.succeed(\"MCP sandbox created\");\n\n\t\t\tconst cfg = options.global ? globalConfig : config;\n\t\t\tawait cfg.setMcpId(result.id);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ ...result, scope: cfg.scope }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(`MCP sandbox \"${name}\" created! (${cfg.scope})`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` MCP ID: ${result.id}`);\n\t\t\t\tconsole.log(` Sandbox ID: ${result.sandboxId}`);\n\t\t\t\tconsole.log(` Preview URL: ${result.previewUrl}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(`Next steps:`);\n\t\t\t\tconsole.log(` waniwani task \"Add a tool that does X\"`);\n\t\t\t\tconsole.log(` waniwani mcp test`);\n\t\t\t\tconsole.log(` waniwani mcp deploy`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { auth } from \"./auth.js\";\nimport { config } from \"./config.js\";\nimport { AuthError, CLIError } from \"./errors.js\";\n\nexport interface ApiResponse<T> {\n\tsuccess: boolean;\n\tdata?: T;\n\terror?: {\n\t\tcode: string;\n\t\tmessage: string;\n\t\tdetails?: Record<string, unknown>;\n\t};\n}\n\nexport class ApiError extends CLIError {\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string,\n\t\tpublic statusCode: number,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message, code, details);\n\t\tthis.name = \"ApiError\";\n\t}\n}\n\nasync function request<T>(\n\tmethod: string,\n\tpath: string,\n\toptions?: {\n\t\tbody?: unknown;\n\t\trequireAuth?: boolean;\n\t\theaders?: Record<string, string>;\n\t},\n): Promise<T> {\n\tconst {\n\t\tbody,\n\t\trequireAuth = true,\n\t\theaders: extraHeaders = {},\n\t} = options || {};\n\n\tconst headers: Record<string, string> = {\n\t\t\"Content-Type\": \"application/json\",\n\t\t...extraHeaders,\n\t};\n\n\tif (requireAuth) {\n\t\tconst token = await auth.getAccessToken();\n\t\tif (!token) {\n\t\t\tthrow new AuthError(\n\t\t\t\t\"Not logged in. Run 'waniwani login' to authenticate.\",\n\t\t\t);\n\t\t}\n\t\theaders.Authorization = `Bearer ${token}`;\n\t}\n\n\tconst baseUrl = await config.getApiUrl();\n\tconst url = `${baseUrl}${path}`;\n\n\tconst response = await fetch(url, {\n\t\tmethod,\n\t\theaders,\n\t\tbody: body ? JSON.stringify(body) : undefined,\n\t});\n\n\t// Handle empty responses (204 No Content)\n\tif (response.status === 204) {\n\t\treturn undefined as T;\n\t}\n\n\tlet data: ApiResponse<T>;\n\tlet rawBody: string | undefined;\n\n\ttry {\n\t\trawBody = await response.text();\n\t\tdata = JSON.parse(rawBody) as ApiResponse<T>;\n\t} catch {\n\t\t// JSON parsing failed - use raw body as error message\n\t\tthrow new ApiError(\n\t\t\trawBody || `Request failed with status ${response.status}`,\n\t\t\t\"API_ERROR\",\n\t\t\tresponse.status,\n\t\t\t{ statusText: response.statusText },\n\t\t);\n\t}\n\n\tif (!response.ok || data.error) {\n\t\t// Try to extract error message from various possible response formats\n\t\tconst errorMessage =\n\t\t\tdata.error?.message ||\n\t\t\t(data as unknown as { message?: string }).message ||\n\t\t\t(data as unknown as { error?: string }).error ||\n\t\t\trawBody ||\n\t\t\t`Request failed with status ${response.status}`;\n\n\t\tconst errorCode =\n\t\t\tdata.error?.code ||\n\t\t\t(data as unknown as { code?: string }).code ||\n\t\t\t\"API_ERROR\";\n\n\t\tconst errorDetails = {\n\t\t\t...data.error?.details,\n\t\t\tstatusText: response.statusText,\n\t\t\t...(data.error ? {} : { rawResponse: data }),\n\t\t};\n\n\t\tconst error = {\n\t\t\tcode: errorCode,\n\t\t\tmessage: errorMessage,\n\t\t\tdetails: errorDetails,\n\t\t};\n\n\t\t// Handle token expiration\n\t\tif (response.status === 401) {\n\t\t\tconst refreshed = await auth.tryRefreshToken();\n\t\t\tif (refreshed) {\n\t\t\t\t// Retry with new token\n\t\t\t\treturn request<T>(method, path, options);\n\t\t\t}\n\t\t\tthrow new AuthError(\n\t\t\t\t\"Session expired. Run 'waniwani login' to re-authenticate.\",\n\t\t\t);\n\t\t}\n\n\t\tthrow new ApiError(\n\t\t\terror.message,\n\t\t\terror.code,\n\t\t\tresponse.status,\n\t\t\terror.details,\n\t\t);\n\t}\n\n\treturn data.data as T;\n}\n\nexport const api = {\n\tget: <T>(path: string, options?: { requireAuth?: boolean }) =>\n\t\trequest<T>(\"GET\", path, options),\n\n\tpost: <T>(\n\t\tpath: string,\n\t\tbody?: unknown,\n\t\toptions?: { requireAuth?: boolean; headers?: Record<string, string> },\n\t) => request<T>(\"POST\", path, { body, ...options }),\n\n\tdelete: <T>(path: string, options?: { requireAuth?: boolean }) =>\n\t\trequest<T>(\"DELETE\", path, options),\n\n\tgetBaseUrl: () => config.getApiUrl(),\n};\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\n\nexport const deleteCommand = new Command(\"delete\")\n\t.description(\"Delete the MCP sandbox\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\"No active MCP. Use --mcp-id to specify one.\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Deleting MCP sandbox...\").start();\n\t\t\tawait api.delete(`/api/mcp/sandboxes/${mcpId}`);\n\t\t\tspinner.succeed(\"MCP sandbox deleted\");\n\n\t\t\t// Clear active MCP if it was the one we deleted\n\t\t\tif ((await config.getMcpId()) === mcpId) {\n\t\t\t\tawait config.setMcpId(null);\n\t\t\t}\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ deleted: mcpId }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"MCP sandbox deleted and cleaned up.\", false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { DeployResponse } from \"../../types/index.js\";\n\nexport const deployCommand = new Command(\"deploy\")\n\t.description(\"Deploy MCP server to GitHub + Vercel from sandbox\")\n\t.option(\"--repo <name>\", \"GitHub repository name\")\n\t.option(\"--org <name>\", \"GitHub organization\")\n\t.option(\"--private\", \"Create private repository\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Deploying to GitHub...\").start();\n\n\t\t\tconst result = await api.post<DeployResponse>(\n\t\t\t\t`/api/admin/mcps/${mcpId}/deploy`,\n\t\t\t\t{\n\t\t\t\t\trepoName: options.repo,\n\t\t\t\t\torg: options.org,\n\t\t\t\t\tprivate: options.private ?? false,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.succeed(\"Deployment complete!\");\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatSuccess(\"MCP server deployed!\", false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` Repository: ${result.repository.url}`);\n\t\t\t\tif (result.deployment.url) {\n\t\t\t\t\tconsole.log(` Deployment: ${result.deployment.url}`);\n\t\t\t\t}\n\t\t\t\tconsole.log();\n\t\t\t\tif (result.deployment.note) {\n\t\t\t\t\tconsole.log(`Note: ${result.deployment.note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport { listCommand } from \"./list.js\";\nimport { readCommand } from \"./read.js\";\nimport { writeCommand } from \"./write.js\";\n\nexport const fileCommand = new Command(\"file\")\n\t.description(\"File operations in MCP sandbox\")\n\t.addCommand(readCommand)\n\t.addCommand(writeCommand)\n\t.addCommand(listCommand);\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../../lib/api.js\";\nimport { config } from \"../../../lib/config.js\";\nimport { handleError, McpError } from \"../../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../../lib/output.js\";\nimport type { ListFilesResponse } from \"../../../types/index.js\";\n\nexport const listCommand = new Command(\"list\")\n\t.description(\"List files in the MCP sandbox\")\n\t.argument(\"[path]\", \"Directory path (defaults to /app)\", \"/app\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(`Listing ${path}...`).start();\n\n\t\t\tconst result = await api.get<ListFilesResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files/list?path=${encodeURIComponent(path)}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log(chalk.bold(`\\nDirectory: ${result.path}\\n`));\n\n\t\t\t\tif (result.entries.length === 0) {\n\t\t\t\t\tconsole.log(\" (empty)\");\n\t\t\t\t} else {\n\t\t\t\t\tconst rows = result.entries.map((entry) => {\n\t\t\t\t\t\tconst name =\n\t\t\t\t\t\t\tentry.type === \"directory\"\n\t\t\t\t\t\t\t\t? chalk.blue(`${entry.name}/`)\n\t\t\t\t\t\t\t\t: entry.name;\n\t\t\t\t\t\tconst size =\n\t\t\t\t\t\t\tentry.type === \"directory\"\n\t\t\t\t\t\t\t\t? chalk.gray(\"<dir>\")\n\t\t\t\t\t\t\t\t: formatSize(entry.size);\n\t\t\t\t\t\treturn [name, size];\n\t\t\t\t\t});\n\n\t\t\t\t\tformatTable([\"Name\", \"Size\"], rows, false);\n\t\t\t\t}\n\t\t\t\tconsole.log();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\nfunction formatSize(bytes?: number): string {\n\tif (bytes === undefined) return \"\";\n\tif (bytes < 1024) return `${bytes} B`;\n\tif (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../../lib/api.js\";\nimport { config } from \"../../../lib/config.js\";\nimport { handleError, McpError } from \"../../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../../lib/output.js\";\nimport type { ReadFileResponse } from \"../../../types/index.js\";\n\nexport const readCommand = new Command(\"read\")\n\t.description(\"Read a file from the MCP sandbox\")\n\t.argument(\"<path>\", \"Path in sandbox (e.g., /app/src/index.ts)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--output <file>\", \"Write to local file instead of stdout\")\n\t.option(\"--base64\", \"Output as base64 (for binary files)\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst encoding = options.base64 ? \"base64\" : \"utf8\";\n\t\t\tconst spinner = ora(`Reading ${path}...`).start();\n\n\t\t\tconst result = await api.get<ReadFileResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files?path=${encodeURIComponent(path)}&encoding=${encoding}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (!result.exists) {\n\t\t\t\tthrow new McpError(`File not found: ${path}`);\n\t\t\t}\n\n\t\t\tif (options.output) {\n\t\t\t\t// Write to local file\n\t\t\t\tconst buffer =\n\t\t\t\t\tresult.encoding === \"base64\"\n\t\t\t\t\t\t? Buffer.from(result.content, \"base64\")\n\t\t\t\t\t\t: Buffer.from(result.content, \"utf8\");\n\t\t\t\tawait writeFile(options.output, buffer);\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput({ path, savedTo: options.output }, true);\n\t\t\t\t} else {\n\t\t\t\t\tformatSuccess(`Saved to ${options.output}`, false);\n\t\t\t\t}\n\t\t\t} else if (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\t// Print to stdout\n\t\t\t\tprocess.stdout.write(result.content);\n\t\t\t\t// Add newline if content doesn't end with one\n\t\t\t\tif (!result.content.endsWith(\"\\n\")) {\n\t\t\t\t\tprocess.stdout.write(\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { readFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../../lib/api.js\";\nimport { config } from \"../../../lib/config.js\";\nimport { CLIError, handleError, McpError } from \"../../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../../lib/output.js\";\nimport type { WriteFilesResponse } from \"../../../types/index.js\";\n\nexport const writeCommand = new Command(\"write\")\n\t.description(\"Write a file to the MCP sandbox\")\n\t.argument(\"<path>\", \"Path in sandbox (e.g., /app/src/index.ts)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--content <content>\", \"Content to write\")\n\t.option(\"--file <localFile>\", \"Local file to upload\")\n\t.option(\"--base64\", \"Treat content as base64 encoded\")\n\t.action(async (path: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Get content from --content or --file\n\t\t\tlet content: string;\n\t\t\tlet encoding: \"utf8\" | \"base64\" = \"utf8\";\n\n\t\t\tif (options.content) {\n\t\t\t\tcontent = options.content;\n\t\t\t\tif (options.base64) {\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t}\n\t\t\t} else if (options.file) {\n\t\t\t\tconst fileBuffer = await readFile(options.file);\n\t\t\t\tif (options.base64) {\n\t\t\t\t\tcontent = fileBuffer.toString(\"base64\");\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t} else {\n\t\t\t\t\tcontent = fileBuffer.toString(\"utf8\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new CLIError(\n\t\t\t\t\t\"Either --content or --file is required\",\n\t\t\t\t\t\"MISSING_CONTENT\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst spinner = ora(`Writing ${path}...`).start();\n\n\t\t\tconst result = await api.post<WriteFilesResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/files`,\n\t\t\t\t{\n\t\t\t\t\tfiles: [{ path, content, encoding }],\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.succeed(`Wrote ${path}`);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`File written: ${path}`, false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type { Mcp, McpListResponse } from \"../../types/index.js\";\n\nexport const listCommand = new Command(\"list\")\n\t.description(\"List all MCPs in your organization\")\n\t.option(\"--all\", \"Include stopped/expired MCPs\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching MCPs...\").start();\n\n\t\t\tconst mcps = await api.get<McpListResponse>(\n\t\t\t\t`/api/mcp/sandboxes${options.all ? \"?all=true\" : \"\"}`,\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tconst activeMcpId = await config.getMcpId();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(\n\t\t\t\t\t{\n\t\t\t\t\t\tmcps: mcps.map((m: Mcp) => ({\n\t\t\t\t\t\t\t...m,\n\t\t\t\t\t\t\tisActive: m.id === activeMcpId,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tactiveMcpId,\n\t\t\t\t\t},\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (mcps.length === 0) {\n\t\t\t\t\tconsole.log(\"No MCPs found.\");\n\t\t\t\t\tconsole.log(\"\\nCreate a new MCP sandbox: waniwani mcp create <name>\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(chalk.bold(\"\\nMCPs:\\n\"));\n\n\t\t\t\tconst rows = mcps.map((m: Mcp) => {\n\t\t\t\t\tconst isActive = m.id === activeMcpId;\n\t\t\t\t\tconst statusColor =\n\t\t\t\t\t\tm.status === \"active\"\n\t\t\t\t\t\t\t? chalk.green\n\t\t\t\t\t\t\t: m.status === \"stopped\"\n\t\t\t\t\t\t\t\t? chalk.red\n\t\t\t\t\t\t\t\t: chalk.yellow;\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tisActive\n\t\t\t\t\t\t\t? chalk.cyan(`* ${m.id.slice(0, 8)}`)\n\t\t\t\t\t\t\t: ` ${m.id.slice(0, 8)}`,\n\t\t\t\t\t\tm.name,\n\t\t\t\t\t\tstatusColor(m.status),\n\t\t\t\t\t\tm.previewUrl,\n\t\t\t\t\t\tm.createdAt ? new Date(m.createdAt).toLocaleString() : \"N/A\",\n\t\t\t\t\t];\n\t\t\t\t});\n\n\t\t\t\tformatTable(\n\t\t\t\t\t[\"ID\", \"Name\", \"Status\", \"Preview URL\", \"Created\"],\n\t\t\t\t\trows,\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\n\t\t\t\tconsole.log();\n\t\t\t\tif (activeMcpId) {\n\t\t\t\t\tconsole.log(`Active MCP: ${chalk.cyan(activeMcpId.slice(0, 8))}`);\n\t\t\t\t}\n\t\t\t\tconsole.log(\"\\nSelect an MCP: waniwani mcp use <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { auth } from \"../../lib/auth.js\";\nimport { config } from \"../../lib/config.js\";\nimport { AuthError, handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput } from \"../../lib/output.js\";\nimport type { LogEvent, ServerStatusResponse } from \"../../types/index.js\";\n\nexport const logsCommand = new Command(\"logs\")\n\t.description(\"Stream logs from the MCP server\")\n\t.argument(\"[cmdId]\", \"Command ID (defaults to running server)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"-f, --follow\", \"Keep streaming logs (default)\", true)\n\t.option(\"--no-follow\", \"Fetch logs and exit\")\n\t.action(async (cmdIdArg: string | undefined, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\tlet reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n\n\t\t// Handle Ctrl+C gracefully\n\t\tconst cleanup = () => {\n\t\t\tif (reader) {\n\t\t\t\treader.cancel().catch(() => {});\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t};\n\t\tprocess.on(\"SIGINT\", cleanup);\n\t\tprocess.on(\"SIGTERM\", cleanup);\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst token = await auth.getAccessToken();\n\t\t\tif (!token) {\n\t\t\t\tthrow new AuthError(\n\t\t\t\t\t\"Not logged in. Run 'waniwani login' to authenticate.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet cmdId = cmdIdArg;\n\n\t\t\t// If no cmdId provided, get it from server status\n\t\t\tif (!cmdId) {\n\t\t\t\tconst spinner = ora(\"Getting server status...\").start();\n\t\t\t\tconst status = await api.post<ServerStatusResponse>(\n\t\t\t\t\t`/api/mcp/sandboxes/${mcpId}/server`,\n\t\t\t\t\t{ action: \"status\" },\n\t\t\t\t);\n\t\t\t\tspinner.stop();\n\n\t\t\t\tif (!status.running || !status.cmdId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No server is running. Run 'waniwani mcp start' first.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcmdId = status.cmdId;\n\t\t\t}\n\n\t\t\tconst baseUrl = await api.getBaseUrl();\n\t\t\tconst streamParam = options.follow ? \"?stream=true\" : \"\";\n\t\t\tconst url = `${baseUrl}/api/mcp/sandboxes/${mcpId}/commands/${cmdId}${streamParam}`;\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log(chalk.gray(`Streaming logs for command ${cmdId}...`));\n\t\t\t\tconsole.log(chalk.gray(\"Press Ctrl+C to stop\\n\"));\n\t\t\t}\n\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tmethod: \"GET\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\tAccept: options.follow ? \"text/event-stream\" : \"application/json\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst error = await response\n\t\t\t\t\t.json()\n\t\t\t\t\t.catch(() => ({ message: response.statusText }));\n\t\t\t\tthrow new Error(\n\t\t\t\t\terror.message || `Request failed with status ${response.status}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Non-streaming mode\n\t\t\tif (!options.follow) {\n\t\t\t\tconst data = await response.json();\n\t\t\t\tif (json) {\n\t\t\t\t\tformatOutput(data, true);\n\t\t\t\t} else {\n\t\t\t\t\tif (data.stdout) {\n\t\t\t\t\t\tprocess.stdout.write(data.stdout);\n\t\t\t\t\t}\n\t\t\t\t\tif (data.stderr) {\n\t\t\t\t\t\tprocess.stderr.write(chalk.red(data.stderr));\n\t\t\t\t\t}\n\t\t\t\t\tif (data.exitCode !== undefined) {\n\t\t\t\t\t\tconsole.log(chalk.gray(`\\nExit code: ${data.exitCode}`));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Streaming mode\n\t\t\treader = response.body?.getReader();\n\t\t\tif (!reader) {\n\t\t\t\tthrow new Error(\"No response body\");\n\t\t\t}\n\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\t\t\tconst collectedLogs: LogEvent[] = [];\n\n\t\t\twhile (true) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done) break;\n\n\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\t\tfor (const line of lines) {\n\t\t\t\t\tif (line.startsWith(\"event: \")) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (line.startsWith(\"data: \")) {\n\t\t\t\t\t\tconst data = line.slice(6);\n\t\t\t\t\t\tif (!data || data === \"[DONE]\") continue;\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst event = JSON.parse(data) as LogEvent;\n\t\t\t\t\t\t\tcollectedLogs.push(event);\n\n\t\t\t\t\t\t\tif (json) {\n\t\t\t\t\t\t\t\t// In JSON mode, we'll output at the end\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Handle different event types\n\t\t\t\t\t\t\tif (event.cmdId) {\n\t\t\t\t\t\t\t\t// Initial event with cmdId\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (event.stream && event.data !== undefined) {\n\t\t\t\t\t\t\t\tif (event.stream === \"stdout\") {\n\t\t\t\t\t\t\t\t\tprocess.stdout.write(event.data);\n\t\t\t\t\t\t\t\t} else if (event.stream === \"stderr\") {\n\t\t\t\t\t\t\t\t\tprocess.stderr.write(chalk.red(event.data));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (event.exitCode !== undefined) {\n\t\t\t\t\t\t\t\tconst exitColor =\n\t\t\t\t\t\t\t\t\tevent.exitCode === 0 ? chalk.green : chalk.red;\n\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\texitColor(`\\nProcess exited with code ${event.exitCode}`),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (event.error) {\n\t\t\t\t\t\t\t\tconsole.error(chalk.red(`\\nError: ${event.error}`));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore malformed JSON\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Output collected logs in JSON mode\n\t\t\tif (json) {\n\t\t\t\tformatOutput(collectedLogs, true);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t} finally {\n\t\t\tprocess.off(\"SIGINT\", cleanup);\n\t\t\tprocess.off(\"SIGTERM\", cleanup);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput } from \"../../lib/output.js\";\nimport type { RunCommandResponse } from \"../../types/index.js\";\n\nexport const runCommandCommand = new Command(\"run-command\")\n\t.description(\"Run a command in the MCP sandbox\")\n\t.argument(\"<command>\", \"Command to run\")\n\t.argument(\"[args...]\", \"Command arguments\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--cwd <path>\", \"Working directory\")\n\t.option(\n\t\t\"--timeout <ms>\",\n\t\t\"Command timeout in milliseconds (default: 30000, max: 300000)\",\n\t)\n\t.action(async (cmd: string, args: string[], options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst timeout = options.timeout\n\t\t\t\t? Number.parseInt(options.timeout, 10)\n\t\t\t\t: undefined;\n\n\t\t\tconst spinner = ora(`Running: ${cmd} ${args.join(\" \")}`.trim()).start();\n\n\t\t\tconst result = await api.post<RunCommandResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/command`,\n\t\t\t\t{\n\t\t\t\t\tcommand: cmd,\n\t\t\t\t\targs: args.length > 0 ? args : undefined,\n\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\ttimeout,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\t// Show command\n\t\t\t\tconst cmdLine = [cmd, ...args].join(\" \");\n\t\t\t\tconsole.log(chalk.gray(`$ ${cmdLine}`));\n\t\t\t\tconsole.log();\n\n\t\t\t\t// Show stdout\n\t\t\t\tif (result.stdout) {\n\t\t\t\t\tprocess.stdout.write(result.stdout);\n\t\t\t\t\tif (!result.stdout.endsWith(\"\\n\")) {\n\t\t\t\t\t\tprocess.stdout.write(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Show stderr\n\t\t\t\tif (result.stderr) {\n\t\t\t\t\tprocess.stderr.write(chalk.red(result.stderr));\n\t\t\t\t\tif (!result.stderr.endsWith(\"\\n\")) {\n\t\t\t\t\t\tprocess.stderr.write(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Show exit code and duration\n\t\t\t\tconsole.log();\n\t\t\t\tconst exitColor = result.exitCode === 0 ? chalk.green : chalk.red;\n\t\t\t\tconsole.log(\n\t\t\t\t\texitColor(`Exit code: ${result.exitCode}`),\n\t\t\t\t\tchalk.gray(`(${(result.duration / 1000).toFixed(2)}s)`),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Exit with the command's exit code\n\t\t\tif (result.exitCode !== 0) {\n\t\t\t\tprocess.exit(result.exitCode);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatList, formatOutput } from \"../../lib/output.js\";\nimport type { ServerStartResponse } from \"../../types/index.js\";\n\nexport const startCommand = new Command(\"start\")\n\t.description(\"Start the MCP server (npm run dev)\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Starting MCP server...\").start();\n\n\t\t\tconst result = await api.post<ServerStartResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/server`,\n\t\t\t\t{ action: \"start\" },\n\t\t\t);\n\n\t\t\tspinner.succeed(\"MCP server started\");\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tformatList(\n\t\t\t\t\t[\n\t\t\t\t\t\t{ label: \"Command ID\", value: result.cmdId },\n\t\t\t\t\t\t{ label: \"Preview URL\", value: chalk.cyan(result.previewUrl) },\n\t\t\t\t\t],\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.gray(\"Run 'waniwani mcp logs' to stream server output\"),\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatList, formatOutput } from \"../../lib/output.js\";\nimport type { Mcp, ServerStatusResponse } from \"../../types/index.js\";\n\nexport const statusCommand = new Command(\"status\")\n\t.description(\"Show current MCP sandbox status\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' to create one or 'waniwani mcp use <name>' to select one.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Fetching MCP status...\").start();\n\n\t\t\t// Fetch sandbox status and server status in parallel\n\t\t\tconst [result, serverStatus] = await Promise.all([\n\t\t\t\tapi.get<Mcp>(`/api/mcp/sandboxes/${mcpId}`),\n\t\t\t\tapi\n\t\t\t\t\t.post<ServerStatusResponse>(`/api/mcp/sandboxes/${mcpId}/server`, {\n\t\t\t\t\t\taction: \"status\",\n\t\t\t\t\t})\n\t\t\t\t\t.catch(() => ({\n\t\t\t\t\t\trunning: false,\n\t\t\t\t\t\tcmdId: undefined,\n\t\t\t\t\t\tpreviewUrl: undefined,\n\t\t\t\t\t})),\n\t\t\t]);\n\n\t\t\tspinner.stop();\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ ...result, server: serverStatus }, true);\n\t\t\t} else {\n\t\t\t\tconst statusColor =\n\t\t\t\t\tresult.status === \"active\" ? chalk.green : chalk.red;\n\t\t\t\tconst serverRunning = serverStatus.running;\n\t\t\t\tconst serverStatusColor = serverRunning ? chalk.green : chalk.yellow;\n\n\t\t\t\tformatList(\n\t\t\t\t\t[\n\t\t\t\t\t\t{ label: \"MCP ID\", value: result.id },\n\t\t\t\t\t\t{ label: \"Name\", value: result.name },\n\t\t\t\t\t\t{ label: \"Status\", value: statusColor(result.status) },\n\t\t\t\t\t\t{ label: \"Sandbox ID\", value: result.sandboxId },\n\t\t\t\t\t\t{ label: \"Preview URL\", value: result.previewUrl },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: \"Server\",\n\t\t\t\t\t\t\tvalue: serverStatusColor(serverRunning ? \"Running\" : \"Stopped\"),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(serverStatus.cmdId\n\t\t\t\t\t\t\t? [{ label: \"Server Cmd ID\", value: serverStatus.cmdId }]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t{ label: \"Created\", value: result.createdAt },\n\t\t\t\t\t\t{ label: \"Expires\", value: result.expiresAt ?? \"N/A\" },\n\t\t\t\t\t],\n\t\t\t\t\tfalse,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { ServerStopResponse } from \"../../types/index.js\";\n\nexport const stopCommand = new Command(\"stop\")\n\t.description(\"Stop the MCP server process\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(async (options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Stopping MCP server...\").start();\n\n\t\t\tconst result = await api.post<ServerStopResponse>(\n\t\t\t\t`/api/mcp/sandboxes/${mcpId}/server`,\n\t\t\t\t{ action: \"stop\" },\n\t\t\t);\n\n\t\t\tif (result.stopped) {\n\t\t\t\tspinner.succeed(\"MCP server stopped\");\n\t\t\t} else {\n\t\t\t\tspinner.warn(\"Server was not running\");\n\t\t\t}\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(\"MCP server stopped.\", false);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { handleError, McpError, SandboxError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type {\n\tMcpCallResponse,\n\tMcpTestResponse,\n\tMcpToolResult,\n} from \"../../types/index.js\";\n\nexport const testCommand = new Command(\"test\")\n\t.description(\"Test MCP tools via the sandbox\")\n\t.argument(\"[tool]\", \"Tool name to test (lists tools if omitted)\")\n\t.argument(\"[args...]\", \"JSON arguments for the tool\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.action(\n\t\tasync (tool: string | undefined, args: string[], options, command) => {\n\t\t\tconst globalOptions = command.optsWithGlobals();\n\t\t\tconst json = globalOptions.json ?? false;\n\n\t\t\ttry {\n\t\t\t\tlet mcpId = options.mcpId;\n\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\t\tif (!mcpId) {\n\t\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\t\"No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!tool) {\n\t\t\t\t\t// List tools\n\t\t\t\t\tconst spinner = ora(\"Fetching available tools...\").start();\n\t\t\t\t\tconst result = await api.post<McpTestResponse>(\n\t\t\t\t\t\t`/api/mcp/sandboxes/${mcpId}/test`,\n\t\t\t\t\t\t{ action: \"list\" },\n\t\t\t\t\t);\n\t\t\t\t\tspinner.stop();\n\n\t\t\t\t\tconst tools = result.tools;\n\n\t\t\t\t\tif (json) {\n\t\t\t\t\t\tformatOutput({ tools }, true);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (tools.length === 0) {\n\t\t\t\t\t\t\tconsole.log(\"No tools available.\");\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log(chalk.bold(\"\\nAvailable Tools:\\n\"));\n\t\t\t\t\t\t\tformatTable(\n\t\t\t\t\t\t\t\t[\"Name\", \"Description\"],\n\t\t\t\t\t\t\t\ttools.map((t) => [t.name, t.description || \"No description\"]),\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t`\\nTest a tool: waniwani mcp test <tool-name> '{\"arg\": \"value\"}'`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Call tool\n\t\t\t\t\tlet toolArgs: Record<string, unknown> = {};\n\t\t\t\t\tif (args.length > 0) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\ttoolArgs = JSON.parse(args.join(\" \"));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow new SandboxError(\n\t\t\t\t\t\t\t\t`Invalid JSON arguments. Expected format: '{\"key\": \"value\"}'`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst spinner = ora(`Calling tool \"${tool}\"...`).start();\n\t\t\t\t\tconst startTime = Date.now();\n\t\t\t\t\tconst result = await api.post<McpCallResponse>(\n\t\t\t\t\t\t`/api/mcp/sandboxes/${mcpId}/test`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taction: \"call\",\n\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\targs: toolArgs,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tconst duration = result.duration || Date.now() - startTime;\n\t\t\t\t\tspinner.stop();\n\n\t\t\t\t\tconst output: McpToolResult = {\n\t\t\t\t\t\ttool,\n\t\t\t\t\t\tinput: toolArgs,\n\t\t\t\t\t\tresult: result.result,\n\t\t\t\t\t\tduration,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (json) {\n\t\t\t\t\t\tformatOutput(output, true);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.bold(\"\\nTool Result:\\n\"));\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Tool:\"), tool);\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Input:\"), JSON.stringify(toolArgs));\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Duration:\"), `${duration}ms`);\n\t\t\t\t\t\tconsole.log(chalk.gray(\"Result:\"));\n\t\t\t\t\t\tconsole.log(JSON.stringify(result.result, null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\thandleError(error, json);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t},\n\t);\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config, globalConfig } from \"../../lib/config.js\";\nimport { handleError, McpError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type { Mcp, McpListResponse } from \"../../types/index.js\";\n\nexport const useCommand = new Command(\"use\")\n\t.description(\"Select an MCP to use for subsequent commands\")\n\t.argument(\"<name>\", \"Name of the MCP to use\")\n\t.option(\"--global\", \"Save to global config instead of project config\")\n\t.action(async (name: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching MCPs...\").start();\n\n\t\t\t// Fetch all MCPs\n\t\t\tconst mcps = await api.get<McpListResponse>(\"/api/admin/mcps\");\n\n\t\t\tspinner.stop();\n\n\t\t\t// Find MCP by name\n\t\t\tconst mcp = mcps.find((m: Mcp) => m.name === name);\n\n\t\t\tif (!mcp) {\n\t\t\t\tthrow new McpError(\n\t\t\t\t\t`MCP \"${name}\" not found. Run 'waniwani mcp list' to see available MCPs.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (mcp.status !== \"active\") {\n\t\t\t\tthrow new McpError(\n\t\t\t\t\t`MCP \"${name}\" is ${mcp.status}. Only active MCPs can be used.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst cfg = options.global ? globalConfig : config;\n\t\t\tawait cfg.setMcpId(mcp.id);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ selected: mcp, scope: cfg.scope }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`Now using MCP \"${name}\" (${cfg.scope})`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(` MCP ID: ${mcp.id}`);\n\t\t\t\tconsole.log(` Preview URL: ${mcp.previewUrl}`);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Next steps:\");\n\t\t\t\tconsole.log(' waniwani task \"Add a tool\"');\n\t\t\t\tconsole.log(\" waniwani mcp test\");\n\t\t\t\tconsole.log(\" waniwani mcp status\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport { listCommand } from \"./list.js\";\nimport { switchCommand } from \"./switch.js\";\n\nexport const orgCommand = new Command(\"org\")\n\t.description(\"Organization management commands\")\n\t.addCommand(listCommand)\n\t.addCommand(switchCommand);\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatTable } from \"../../lib/output.js\";\nimport type { Org, OrgListResponse } from \"../../types/index.js\";\n\nexport const listCommand = new Command(\"list\")\n\t.description(\"List your organizations\")\n\t.action(async (_, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching organizations...\").start();\n\n\t\t\tconst result = await api.get<OrgListResponse>(\"/api/oauth/orgs\");\n\n\t\t\tspinner.stop();\n\n\t\t\tconst { orgs, activeOrgId } = result;\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput(\n\t\t\t\t\t{\n\t\t\t\t\t\torgs: orgs.map((o: Org) => ({\n\t\t\t\t\t\t\t...o,\n\t\t\t\t\t\t\tisActive: o.id === activeOrgId,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\tactiveOrgId,\n\t\t\t\t\t},\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (orgs.length === 0) {\n\t\t\t\t\tconsole.log(\"No organizations found.\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconsole.log(chalk.bold(\"\\nOrganizations:\\n\"));\n\n\t\t\t\tconst rows = orgs.map((o: Org) => {\n\t\t\t\t\tconst isActive = o.id === activeOrgId;\n\t\t\t\t\treturn [\n\t\t\t\t\t\tisActive ? chalk.cyan(`* ${o.name}`) : ` ${o.name}`,\n\t\t\t\t\t\to.slug,\n\t\t\t\t\t\to.role,\n\t\t\t\t\t];\n\t\t\t\t});\n\n\t\t\t\tformatTable([\"Name\", \"Slug\", \"Role\"], rows, false);\n\n\t\t\t\tconsole.log();\n\t\t\t\tif (activeOrgId) {\n\t\t\t\t\tconst activeOrg = orgs.find((o: Org) => o.id === activeOrgId);\n\t\t\t\t\tif (activeOrg) {\n\t\t\t\t\t\tconsole.log(`Active organization: ${chalk.cyan(activeOrg.name)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconsole.log(\"\\nSwitch organization: waniwani org switch <name>\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../../lib/api.js\";\nimport { config } from \"../../lib/config.js\";\nimport { CLIError, handleError } from \"../../lib/errors.js\";\nimport { formatOutput, formatSuccess } from \"../../lib/output.js\";\nimport type {\n\tOrg,\n\tOrgListResponse,\n\tOrgSwitchResponse,\n} from \"../../types/index.js\";\n\nexport const switchCommand = new Command(\"switch\")\n\t.description(\"Switch to a different organization\")\n\t.argument(\"<name>\", \"Name or slug of the organization to switch to\")\n\t.action(async (name: string, _, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tconst spinner = ora(\"Fetching organizations...\").start();\n\n\t\t\t// First fetch orgs to find the org ID\n\t\t\tconst { orgs } = await api.get<OrgListResponse>(\"/api/oauth/orgs\");\n\n\t\t\t// Find org by name or slug\n\t\t\tconst org = orgs.find((o: Org) => o.name === name || o.slug === name);\n\n\t\t\tif (!org) {\n\t\t\t\tspinner.stop();\n\t\t\t\tthrow new CLIError(\n\t\t\t\t\t`Organization \"${name}\" not found. Run 'waniwani org list' to see available organizations.`,\n\t\t\t\t\t\"ORG_NOT_FOUND\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tspinner.text = \"Switching organization...\";\n\n\t\t\t// Switch to the org\n\t\t\tawait api.post<OrgSwitchResponse>(\"/api/oauth/orgs/switch\", {\n\t\t\t\torgId: org.id,\n\t\t\t});\n\n\t\t\tspinner.succeed(\"Organization switched\");\n\n\t\t\t// Clear local MCP selection since we switched orgs\n\t\t\tconfig.setMcpId(null);\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ switched: org }, true);\n\t\t\t} else {\n\t\t\t\tformatSuccess(`Switched to organization \"${org.name}\"`, false);\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\"Note: Active MCP selection has been cleared.\");\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"Run 'waniwani mcp list' to see MCPs in this organization.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import chalk from \"chalk\";\nimport { Command } from \"commander\";\nimport ora from \"ora\";\nimport { api } from \"../lib/api.js\";\nimport { auth } from \"../lib/auth.js\";\nimport { config } from \"../lib/config.js\";\nimport { AuthError, handleError, McpError } from \"../lib/errors.js\";\nimport { formatOutput } from \"../lib/output.js\";\nimport type { TaskDoneEvent, TaskStep, TaskStepEvent } from \"../types/index.js\";\n\nexport const taskCommand = new Command(\"task\")\n\t.description(\"Send a task to Claude running in the sandbox\")\n\t.argument(\"<prompt>\", \"Task description/prompt\")\n\t.option(\"--mcp-id <id>\", \"Specific MCP ID\")\n\t.option(\"--model <model>\", \"Claude model to use\")\n\t.option(\"--max-steps <n>\", \"Maximum tool use steps\")\n\t.action(async (prompt: string, options, command) => {\n\t\tconst globalOptions = command.optsWithGlobals();\n\t\tconst json = globalOptions.json ?? false;\n\n\t\ttry {\n\t\t\tlet mcpId = options.mcpId;\n\n\t\t\tif (!mcpId) {\n\t\t\t\tmcpId = await config.getMcpId();\n\t\t\t\tif (!mcpId) {\n\t\t\t\t\tthrow new McpError(\n\t\t\t\t\t\t\"No active MCP. Run 'waniwani init' then 'waniwani mcp use <name>'.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst token = await auth.getAccessToken();\n\t\t\tif (!token) {\n\t\t\t\tthrow new AuthError(\n\t\t\t\t\t\"Not logged in. Run 'waniwani login' to authenticate.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst defaults = await config.getDefaults();\n\t\t\tconst model = options.model ?? defaults.model;\n\t\t\tconst maxSteps = options.maxSteps\n\t\t\t\t? Number.parseInt(options.maxSteps, 10)\n\t\t\t\t: defaults.maxSteps;\n\n\t\t\tif (!json) {\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(chalk.bold(\"Task:\"), prompt);\n\t\t\t\tconsole.log();\n\t\t\t}\n\n\t\t\tconst spinner = ora(\"Starting task...\").start();\n\n\t\t\t// Use fetch with SSE for streaming\n\t\t\tconst baseUrl = await api.getBaseUrl();\n\t\t\tconst response = await fetch(\n\t\t\t\t`${baseUrl}/api/mcp/sandboxes/${mcpId}/task`,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\t\tAccept: \"text/event-stream\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tprompt,\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tmaxSteps,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst error = await response\n\t\t\t\t\t.json()\n\t\t\t\t\t.catch(() => ({ message: response.statusText }));\n\t\t\t\tspinner.fail(\"Task failed\");\n\t\t\t\tthrow new Error(\n\t\t\t\t\terror.message || `Request failed with status ${response.status}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tspinner.stop();\n\n\t\t\tconst steps: TaskStep[] = [];\n\t\t\tlet stepCount = 0;\n\t\t\tlet maxStepsReached = false;\n\n\t\t\t// Process SSE stream\n\t\t\tconst reader = response.body?.getReader();\n\t\t\tif (!reader) {\n\t\t\t\tthrow new Error(\"No response body\");\n\t\t\t}\n\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\n\t\t\twhile (true) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done) break;\n\n\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\t\tfor (const line of lines) {\n\t\t\t\t\tif (line.startsWith(\"event: \")) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (line.startsWith(\"data: \")) {\n\t\t\t\t\t\tconst data = line.slice(6);\n\t\t\t\t\t\tif (!data || data === \"[DONE]\") continue;\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst parsed = JSON.parse(data);\n\n\t\t\t\t\t\t\t// Handle step events\n\t\t\t\t\t\t\tif (parsed.type === \"text\") {\n\t\t\t\t\t\t\t\tconst event = parsed as TaskStepEvent;\n\t\t\t\t\t\t\t\tsteps.push({ type: \"text\", text: event.content });\n\t\t\t\t\t\t\t\tif (!json && event.content) {\n\t\t\t\t\t\t\t\t\tconsole.log(chalk.white(event.content));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (parsed.type === \"tool_call\") {\n\t\t\t\t\t\t\t\tconst event = parsed as TaskStepEvent;\n\t\t\t\t\t\t\t\tsteps.push({\n\t\t\t\t\t\t\t\t\ttype: \"tool_call\",\n\t\t\t\t\t\t\t\t\ttool: event.tool,\n\t\t\t\t\t\t\t\t\tinput: event.input,\n\t\t\t\t\t\t\t\t\toutput: event.output,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (!json) {\n\t\t\t\t\t\t\t\t\tconsole.log(chalk.cyan(`> Using tool: ${event.tool}`));\n\t\t\t\t\t\t\t\t\tif (event.input?.command) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(` $ ${event.input.command}`));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (event.output) {\n\t\t\t\t\t\t\t\t\t\t// Show abbreviated output\n\t\t\t\t\t\t\t\t\t\tconst outputLines = event.output.split(\"\\n\");\n\t\t\t\t\t\t\t\t\t\tif (outputLines.length > 10) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t\t\tchalk.gray(outputLines.slice(0, 5).join(\"\\n\")),\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t\t\tchalk.gray(\n\t\t\t\t\t\t\t\t\t\t\t\t\t` ... (${outputLines.length - 10} more lines)`,\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(outputLines.slice(-5).join(\"\\n\")));\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(chalk.gray(event.output));\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconsole.log();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (parsed.success !== undefined) {\n\t\t\t\t\t\t\t\t// Handle done event\n\t\t\t\t\t\t\t\tconst doneEvent = parsed as TaskDoneEvent;\n\t\t\t\t\t\t\t\tstepCount = doneEvent.stepCount;\n\t\t\t\t\t\t\t\tmaxStepsReached = doneEvent.maxStepsReached || false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore malformed JSON\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = {\n\t\t\t\tsuccess: true,\n\t\t\t\tsteps,\n\t\t\t\tstepCount,\n\t\t\t\tmaxStepsReached,\n\t\t\t};\n\n\t\t\tconst finalStepCount = stepCount ?? steps.length;\n\n\t\t\tif (json) {\n\t\t\t\tformatOutput({ ...result, stepCount: finalStepCount }, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(\n\t\t\t\t\tchalk.green(\"✓\"),\n\t\t\t\t\t`Task completed in ${finalStepCount} steps.`,\n\t\t\t\t);\n\t\t\t\tif (maxStepsReached) {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\tchalk.yellow(\"⚠\"),\n\t\t\t\t\t\t\"Maximum steps reached. Task may be incomplete.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\thandleError(error, json);\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n","import { program } from \"./cli.js\";\n\nprogram.parse(process.argv);\n"],"mappings":";;;AAAA,SAAS,WAAAA,iBAAe;;;ACAxB,SAAS,kBAAkB;AAC3B,SAAS,OAAO,iBAAiB;AACjC,SAAS,YAAY;AACrB,SAAS,eAAe;;;ACHxB,OAAO,WAAW;AAClB,SAAS,gBAAgB;AAElB,IAAM,WAAN,cAAuB,MAAM;AAAA,EACnC,YACC,SACO,MACA,SACN;AACD,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACb;AACD;AAQO,IAAM,YAAN,cAAwB,SAAS;AAAA,EACvC,YAAY,SAAiB,SAAmC;AAC/D,UAAM,SAAS,cAAc,OAAO;AAAA,EACrC;AACD;AAEO,IAAM,eAAN,cAA2B,SAAS;AAAA,EAC1C,YAAY,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IACD;AAEA,UAAM,iBAAiB,aAAa,MAAM;AAE1C,QAAI,MAAM;AACT,mBAAa,EAAE,GAAG,QAAQ,WAAW,eAAe,GAAG,IAAI;AAAA,IAC5D,OAAO;AACN,cAAQ,IAAI;AACZ,cAAQ;AAAA,QACPA,QAAM,MAAM,QAAG;AAAA,QACf,qBAAqB,cAAc;AAAA,MACpC;AACA,UAAI,iBAAiB;AACpB,gBAAQ;AAAA,UACPA,QAAM,OAAO,QAAG;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD,SAAS,OAAO;AACf,gBAAY,OAAO,IAAI;AACvB,YAAQ,KAAK,CAAC;AAAA,EACf;AACD,CAAC;;;A5B9LF,IAAM,UAAU;AAET,IAAM,UAAU,IAAIE,UAAQ,EACjC,KAAK,UAAU,EACf,YAAY,2CAA2C,EACvD,QAAQ,OAAO,EACf,OAAO,UAAU,wBAAwB,EACzC,OAAO,aAAa,wBAAwB;AAG9C,QAAQ,WAAW,YAAY;AAC/B,QAAQ,WAAW,aAAa;AAGhC,QAAQ,WAAW,WAAW;AAC9B,QAAQ,WAAW,UAAU;AAC7B,QAAQ,WAAW,WAAW;AAC9B,QAAQ,WAAW,UAAU;;;A6BvB7B,QAAQ,MAAM,QAAQ,IAAI;","names":["Command","chalk","chalk","chalk","Command","mkdir","readFile","writeFile","homedir","join","z","existsSync","mkdir","writeFile","join","join","homedir","z","mkdir","readFile","writeFile","Command","chalk","Command","Command","Command","Command","ora","Command","ora","Command","ora","Command","ora","Command","ora","Command","ora","Command","chalk","Command","ora","Command","ora","chalk","writeFile","Command","ora","Command","ora","writeFile","readFile","Command","ora","Command","readFile","ora","Command","chalk","Command","ora","listCommand","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","ora","Command","listCommand","Command","chalk","Command","ora","listCommand","Command","ora","chalk","Command","ora","Command","ora","Command","listCommand","chalk","Command","ora","Command","chalk","ora","Command"]}
|