@waniwani/cli 0.0.20 → 0.0.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { Command as Command16 } from "commander";
4
+ import { Command as Command20 } from "commander";
5
5
 
6
6
  // src/commands/init.ts
7
7
  import { existsSync } from "fs";
@@ -561,16 +561,36 @@ var loginCommand = new Command2("login").description("Log in to WaniWani").optio
561
561
  const json = globalOptions.json ?? false;
562
562
  try {
563
563
  if (await auth.isLoggedIn()) {
564
- if (json) {
565
- formatOutput({ alreadyLoggedIn: true }, true);
564
+ if (await auth.isTokenExpired()) {
565
+ const refreshed = await auth.tryRefreshToken();
566
+ if (refreshed) {
567
+ if (json) {
568
+ formatOutput({ alreadyLoggedIn: true, refreshed: true }, true);
569
+ } else {
570
+ console.log(
571
+ chalk3.green("Session refreshed. You're still logged in.")
572
+ );
573
+ }
574
+ return;
575
+ }
576
+ if (!json) {
577
+ console.log(
578
+ chalk3.yellow("Session expired. Starting new login flow...")
579
+ );
580
+ }
581
+ await auth.clear();
566
582
  } else {
567
- console.log(
568
- chalk3.yellow(
569
- "Already logged in. Use 'waniwani logout' to log out first."
570
- )
571
- );
583
+ if (json) {
584
+ formatOutput({ alreadyLoggedIn: true }, true);
585
+ } else {
586
+ console.log(
587
+ chalk3.yellow(
588
+ "Already logged in. Use 'waniwani logout' to log out first."
589
+ )
590
+ );
591
+ }
592
+ return;
572
593
  }
573
- return;
574
594
  }
575
595
  if (!json) {
576
596
  console.log(chalk3.bold("\nWaniWani CLI Login\n"));
@@ -667,7 +687,7 @@ var logoutCommand = new Command3("logout").description("Log out from WaniWani").
667
687
  });
668
688
 
669
689
  // src/commands/mcp/index.ts
670
- import { Command as Command11 } from "commander";
690
+ import { Command as Command15 } from "commander";
671
691
 
672
692
  // src/commands/mcp/create.ts
673
693
  import { Command as Command4 } from "commander";
@@ -747,7 +767,7 @@ var createCommand = new Command4("create").description("Create a new MCP sandbox
747
767
  const json = globalOptions.json ?? false;
748
768
  try {
749
769
  const spinner = ora2("Creating MCP sandbox...").start();
750
- const result = await api.post("/api/admin/mcps", {
770
+ const result = await api.post("/api/mcp/sandboxes", {
751
771
  name
752
772
  });
753
773
  spinner.succeed("MCP sandbox created");
@@ -831,7 +851,7 @@ var listCommand = new Command6("list").description("List all MCPs in your organi
831
851
  try {
832
852
  const spinner = ora4("Fetching MCPs...").start();
833
853
  const mcps = await api.get(
834
- `/api/admin/mcps${options.all ? "?all=true" : ""}`
854
+ `/api/mcp/sandboxes${options.all ? "?all=true" : ""}`
835
855
  );
836
856
  spinner.stop();
837
857
  const activeMcpId = await config.getMcpId();
@@ -881,11 +901,177 @@ var listCommand = new Command6("list").description("List all MCPs in your organi
881
901
  }
882
902
  });
883
903
 
884
- // src/commands/mcp/status.ts
904
+ // src/commands/mcp/list-files.ts
885
905
  import chalk5 from "chalk";
886
906
  import { Command as Command7 } from "commander";
887
907
  import ora5 from "ora";
888
- var statusCommand = new Command7("status").description("Show current MCP sandbox status").option("--mcp-id <id>", "Specific MCP ID").action(async (options, command) => {
908
+ var listFilesCommand = new Command7("list-files").description("List files in the MCP sandbox").argument("[path]", "Directory path (defaults to /app)", "/app").option("--mcp-id <id>", "Specific MCP ID").action(async (path, options, command) => {
909
+ const globalOptions = command.optsWithGlobals();
910
+ const json = globalOptions.json ?? false;
911
+ try {
912
+ let mcpId = options.mcpId;
913
+ if (!mcpId) {
914
+ mcpId = await config.getMcpId();
915
+ if (!mcpId) {
916
+ throw new McpError(
917
+ "No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'."
918
+ );
919
+ }
920
+ }
921
+ const spinner = ora5(`Listing ${path}...`).start();
922
+ const result = await api.get(
923
+ `/api/mcp/sandboxes/${mcpId}/files/list?path=${encodeURIComponent(path)}`
924
+ );
925
+ spinner.stop();
926
+ if (json) {
927
+ formatOutput(result, true);
928
+ } else {
929
+ console.log(chalk5.bold(`
930
+ Directory: ${result.path}
931
+ `));
932
+ if (result.entries.length === 0) {
933
+ console.log(" (empty)");
934
+ } else {
935
+ const rows = result.entries.map((entry) => {
936
+ const name = entry.type === "directory" ? chalk5.blue(`${entry.name}/`) : entry.name;
937
+ const size = entry.type === "directory" ? chalk5.gray("<dir>") : formatSize(entry.size);
938
+ return [name, size];
939
+ });
940
+ formatTable(["Name", "Size"], rows, false);
941
+ }
942
+ console.log();
943
+ }
944
+ } catch (error) {
945
+ handleError(error, json);
946
+ process.exit(1);
947
+ }
948
+ });
949
+ function formatSize(bytes) {
950
+ if (bytes === void 0) return "";
951
+ if (bytes < 1024) return `${bytes} B`;
952
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
953
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
954
+ }
955
+
956
+ // src/commands/mcp/read-file.ts
957
+ import { writeFile as writeFile4 } from "fs/promises";
958
+ import { Command as Command8 } from "commander";
959
+ import ora6 from "ora";
960
+ var readFileCommand = new Command8("read-file").description("Read a file from the MCP sandbox").argument("<path>", "Path in sandbox (e.g., /app/src/index.ts)").option("--mcp-id <id>", "Specific MCP ID").option("--output <file>", "Write to local file instead of stdout").option("--base64", "Output as base64 (for binary files)").action(async (path, options, command) => {
961
+ const globalOptions = command.optsWithGlobals();
962
+ const json = globalOptions.json ?? false;
963
+ try {
964
+ let mcpId = options.mcpId;
965
+ if (!mcpId) {
966
+ mcpId = await config.getMcpId();
967
+ if (!mcpId) {
968
+ throw new McpError(
969
+ "No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'."
970
+ );
971
+ }
972
+ }
973
+ const encoding = options.base64 ? "base64" : "utf8";
974
+ const spinner = ora6(`Reading ${path}...`).start();
975
+ const result = await api.get(
976
+ `/api/mcp/sandboxes/${mcpId}/files?path=${encodeURIComponent(path)}&encoding=${encoding}`
977
+ );
978
+ spinner.stop();
979
+ if (!result.exists) {
980
+ throw new McpError(`File not found: ${path}`);
981
+ }
982
+ if (options.output) {
983
+ const buffer = result.encoding === "base64" ? Buffer.from(result.content, "base64") : Buffer.from(result.content, "utf8");
984
+ await writeFile4(options.output, buffer);
985
+ if (json) {
986
+ formatOutput({ path, savedTo: options.output }, true);
987
+ } else {
988
+ formatSuccess(`Saved to ${options.output}`, false);
989
+ }
990
+ } else if (json) {
991
+ formatOutput(result, true);
992
+ } else {
993
+ process.stdout.write(result.content);
994
+ if (!result.content.endsWith("\n")) {
995
+ process.stdout.write("\n");
996
+ }
997
+ }
998
+ } catch (error) {
999
+ handleError(error, json);
1000
+ process.exit(1);
1001
+ }
1002
+ });
1003
+
1004
+ // src/commands/mcp/run-command.ts
1005
+ import chalk6 from "chalk";
1006
+ import { Command as Command9 } from "commander";
1007
+ import ora7 from "ora";
1008
+ var runCommandCommand = new Command9("run-command").description("Run a command in the MCP sandbox").argument("<command>", "Command to run").argument("[args...]", "Command arguments").option("--mcp-id <id>", "Specific MCP ID").option("--cwd <path>", "Working directory").option(
1009
+ "--timeout <ms>",
1010
+ "Command timeout in milliseconds (default: 30000, max: 300000)"
1011
+ ).action(async (cmd, args, options, command) => {
1012
+ const globalOptions = command.optsWithGlobals();
1013
+ const json = globalOptions.json ?? false;
1014
+ try {
1015
+ let mcpId = options.mcpId;
1016
+ if (!mcpId) {
1017
+ mcpId = await config.getMcpId();
1018
+ if (!mcpId) {
1019
+ throw new McpError(
1020
+ "No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'."
1021
+ );
1022
+ }
1023
+ }
1024
+ const timeout = options.timeout ? Number.parseInt(options.timeout, 10) : void 0;
1025
+ const spinner = ora7(`Running: ${cmd} ${args.join(" ")}`.trim()).start();
1026
+ const result = await api.post(
1027
+ `/api/mcp/sandboxes/${mcpId}/command`,
1028
+ {
1029
+ command: cmd,
1030
+ args: args.length > 0 ? args : void 0,
1031
+ cwd: options.cwd,
1032
+ timeout
1033
+ }
1034
+ );
1035
+ spinner.stop();
1036
+ if (json) {
1037
+ formatOutput(result, true);
1038
+ } else {
1039
+ const cmdLine = [cmd, ...args].join(" ");
1040
+ console.log(chalk6.gray(`$ ${cmdLine}`));
1041
+ console.log();
1042
+ if (result.stdout) {
1043
+ process.stdout.write(result.stdout);
1044
+ if (!result.stdout.endsWith("\n")) {
1045
+ process.stdout.write("\n");
1046
+ }
1047
+ }
1048
+ if (result.stderr) {
1049
+ process.stderr.write(chalk6.red(result.stderr));
1050
+ if (!result.stderr.endsWith("\n")) {
1051
+ process.stderr.write("\n");
1052
+ }
1053
+ }
1054
+ console.log();
1055
+ const exitColor = result.exitCode === 0 ? chalk6.green : chalk6.red;
1056
+ console.log(
1057
+ exitColor(`Exit code: ${result.exitCode}`),
1058
+ chalk6.gray(`(${(result.duration / 1e3).toFixed(2)}s)`)
1059
+ );
1060
+ }
1061
+ if (result.exitCode !== 0) {
1062
+ process.exit(result.exitCode);
1063
+ }
1064
+ } catch (error) {
1065
+ handleError(error, json);
1066
+ process.exit(1);
1067
+ }
1068
+ });
1069
+
1070
+ // src/commands/mcp/status.ts
1071
+ import chalk7 from "chalk";
1072
+ import { Command as Command10 } from "commander";
1073
+ import ora8 from "ora";
1074
+ var statusCommand = new Command10("status").description("Show current MCP sandbox status").option("--mcp-id <id>", "Specific MCP ID").action(async (options, command) => {
889
1075
  const globalOptions = command.optsWithGlobals();
890
1076
  const json = globalOptions.json ?? false;
891
1077
  try {
@@ -898,13 +1084,13 @@ var statusCommand = new Command7("status").description("Show current MCP sandbox
898
1084
  );
899
1085
  }
900
1086
  }
901
- const spinner = ora5("Fetching MCP status...").start();
902
- const result = await api.get(`/api/admin/mcps/${mcpId}`);
1087
+ const spinner = ora8("Fetching MCP status...").start();
1088
+ const result = await api.get(`/api/mcp/sandboxes/${mcpId}`);
903
1089
  spinner.stop();
904
1090
  if (json) {
905
1091
  formatOutput(result, true);
906
1092
  } else {
907
- const statusColor = result.status === "active" ? chalk5.green : chalk5.red;
1093
+ const statusColor = result.status === "active" ? chalk7.green : chalk7.red;
908
1094
  formatList(
909
1095
  [
910
1096
  { label: "MCP ID", value: result.id },
@@ -925,9 +1111,9 @@ var statusCommand = new Command7("status").description("Show current MCP sandbox
925
1111
  });
926
1112
 
927
1113
  // src/commands/mcp/stop.ts
928
- import { Command as Command8 } from "commander";
929
- import ora6 from "ora";
930
- var stopCommand = new Command8("stop").description("Stop and clean up the MCP sandbox").option("--mcp-id <id>", "Specific MCP ID").action(async (options, command) => {
1114
+ import { Command as Command11 } from "commander";
1115
+ import ora9 from "ora";
1116
+ var stopCommand = new Command11("stop").description("Stop and clean up the MCP sandbox").option("--mcp-id <id>", "Specific MCP ID").action(async (options, command) => {
931
1117
  const globalOptions = command.optsWithGlobals();
932
1118
  const json = globalOptions.json ?? false;
933
1119
  try {
@@ -938,8 +1124,8 @@ var stopCommand = new Command8("stop").description("Stop and clean up the MCP sa
938
1124
  throw new McpError("No active MCP. Use --mcp-id to specify one.");
939
1125
  }
940
1126
  }
941
- const spinner = ora6("Stopping MCP sandbox...").start();
942
- await api.delete(`/api/admin/mcps/${mcpId}`);
1127
+ const spinner = ora9("Stopping MCP sandbox...").start();
1128
+ await api.delete(`/api/mcp/sandboxes/${mcpId}`);
943
1129
  spinner.succeed("MCP sandbox stopped");
944
1130
  if (await config.getMcpId() === mcpId) {
945
1131
  await config.setMcpId(null);
@@ -956,10 +1142,10 @@ var stopCommand = new Command8("stop").description("Stop and clean up the MCP sa
956
1142
  });
957
1143
 
958
1144
  // src/commands/mcp/test.ts
959
- import chalk6 from "chalk";
960
- import { Command as Command9 } from "commander";
961
- import ora7 from "ora";
962
- var testCommand = new Command9("test").description("Test MCP tools via the sandbox").argument("[tool]", "Tool name to test (lists tools if omitted)").argument("[args...]", "JSON arguments for the tool").option("--mcp-id <id>", "Specific MCP ID").action(
1145
+ import chalk8 from "chalk";
1146
+ import { Command as Command12 } from "commander";
1147
+ import ora10 from "ora";
1148
+ var testCommand = new Command12("test").description("Test MCP tools via the sandbox").argument("[tool]", "Tool name to test (lists tools if omitted)").argument("[args...]", "JSON arguments for the tool").option("--mcp-id <id>", "Specific MCP ID").action(
963
1149
  async (tool, args, options, command) => {
964
1150
  const globalOptions = command.optsWithGlobals();
965
1151
  const json = globalOptions.json ?? false;
@@ -974,9 +1160,9 @@ var testCommand = new Command9("test").description("Test MCP tools via the sandb
974
1160
  }
975
1161
  }
976
1162
  if (!tool) {
977
- const spinner = ora7("Fetching available tools...").start();
1163
+ const spinner = ora10("Fetching available tools...").start();
978
1164
  const result = await api.post(
979
- `/api/admin/mcps/${mcpId}/test`,
1165
+ `/api/mcp/sandboxes/${mcpId}/test`,
980
1166
  { action: "list" }
981
1167
  );
982
1168
  spinner.stop();
@@ -987,7 +1173,7 @@ var testCommand = new Command9("test").description("Test MCP tools via the sandb
987
1173
  if (tools.length === 0) {
988
1174
  console.log("No tools available.");
989
1175
  } else {
990
- console.log(chalk6.bold("\nAvailable Tools:\n"));
1176
+ console.log(chalk8.bold("\nAvailable Tools:\n"));
991
1177
  formatTable(
992
1178
  ["Name", "Description"],
993
1179
  tools.map((t) => [t.name, t.description || "No description"]),
@@ -1010,10 +1196,10 @@ Test a tool: waniwani mcp test <tool-name> '{"arg": "value"}'`
1010
1196
  );
1011
1197
  }
1012
1198
  }
1013
- const spinner = ora7(`Calling tool "${tool}"...`).start();
1199
+ const spinner = ora10(`Calling tool "${tool}"...`).start();
1014
1200
  const startTime = Date.now();
1015
1201
  const result = await api.post(
1016
- `/api/admin/mcps/${mcpId}/test`,
1202
+ `/api/mcp/sandboxes/${mcpId}/test`,
1017
1203
  {
1018
1204
  action: "call",
1019
1205
  tool,
@@ -1031,11 +1217,11 @@ Test a tool: waniwani mcp test <tool-name> '{"arg": "value"}'`
1031
1217
  if (json) {
1032
1218
  formatOutput(output, true);
1033
1219
  } else {
1034
- console.log(chalk6.bold("\nTool Result:\n"));
1035
- console.log(chalk6.gray("Tool:"), tool);
1036
- console.log(chalk6.gray("Input:"), JSON.stringify(toolArgs));
1037
- console.log(chalk6.gray("Duration:"), `${duration}ms`);
1038
- console.log(chalk6.gray("Result:"));
1220
+ console.log(chalk8.bold("\nTool Result:\n"));
1221
+ console.log(chalk8.gray("Tool:"), tool);
1222
+ console.log(chalk8.gray("Input:"), JSON.stringify(toolArgs));
1223
+ console.log(chalk8.gray("Duration:"), `${duration}ms`);
1224
+ console.log(chalk8.gray("Result:"));
1039
1225
  console.log(JSON.stringify(result.result, null, 2));
1040
1226
  }
1041
1227
  }
@@ -1047,13 +1233,13 @@ Test a tool: waniwani mcp test <tool-name> '{"arg": "value"}'`
1047
1233
  );
1048
1234
 
1049
1235
  // src/commands/mcp/use.ts
1050
- import { Command as Command10 } from "commander";
1051
- import ora8 from "ora";
1052
- var useCommand = new Command10("use").description("Select an MCP to use for subsequent commands").argument("<name>", "Name of the MCP to use").option("--global", "Save to global config instead of project config").action(async (name, options, command) => {
1236
+ import { Command as Command13 } from "commander";
1237
+ import ora11 from "ora";
1238
+ var useCommand = new Command13("use").description("Select an MCP to use for subsequent commands").argument("<name>", "Name of the MCP to use").option("--global", "Save to global config instead of project config").action(async (name, options, command) => {
1053
1239
  const globalOptions = command.optsWithGlobals();
1054
1240
  const json = globalOptions.json ?? false;
1055
1241
  try {
1056
- const spinner = ora8("Fetching MCPs...").start();
1242
+ const spinner = ora11("Fetching MCPs...").start();
1057
1243
  const mcps = await api.get("/api/admin/mcps");
1058
1244
  spinner.stop();
1059
1245
  const mcp = mcps.find((m) => m.name === name);
@@ -1088,21 +1274,78 @@ var useCommand = new Command10("use").description("Select an MCP to use for subs
1088
1274
  }
1089
1275
  });
1090
1276
 
1277
+ // src/commands/mcp/write-file.ts
1278
+ import { readFile as readFile3 } from "fs/promises";
1279
+ import { Command as Command14 } from "commander";
1280
+ import ora12 from "ora";
1281
+ var writeFileCommand = new Command14("write-file").description("Write a file to the MCP sandbox").argument("<path>", "Path in sandbox (e.g., /app/src/index.ts)").option("--mcp-id <id>", "Specific MCP ID").option("--content <content>", "Content to write").option("--file <localFile>", "Local file to upload").option("--base64", "Treat content as base64 encoded").action(async (path, options, command) => {
1282
+ const globalOptions = command.optsWithGlobals();
1283
+ const json = globalOptions.json ?? false;
1284
+ try {
1285
+ let mcpId = options.mcpId;
1286
+ if (!mcpId) {
1287
+ mcpId = await config.getMcpId();
1288
+ if (!mcpId) {
1289
+ throw new McpError(
1290
+ "No active MCP. Run 'waniwani mcp create <name>' or 'waniwani mcp use <name>'."
1291
+ );
1292
+ }
1293
+ }
1294
+ let content;
1295
+ let encoding = "utf8";
1296
+ if (options.content) {
1297
+ content = options.content;
1298
+ if (options.base64) {
1299
+ encoding = "base64";
1300
+ }
1301
+ } else if (options.file) {
1302
+ const fileBuffer = await readFile3(options.file);
1303
+ if (options.base64) {
1304
+ content = fileBuffer.toString("base64");
1305
+ encoding = "base64";
1306
+ } else {
1307
+ content = fileBuffer.toString("utf8");
1308
+ }
1309
+ } else {
1310
+ throw new CLIError(
1311
+ "Either --content or --file is required",
1312
+ "MISSING_CONTENT"
1313
+ );
1314
+ }
1315
+ const spinner = ora12(`Writing ${path}...`).start();
1316
+ const result = await api.post(
1317
+ `/api/mcp/sandboxes/${mcpId}/files`,
1318
+ {
1319
+ files: [{ path, content, encoding }]
1320
+ }
1321
+ );
1322
+ spinner.succeed(`Wrote ${path}`);
1323
+ if (json) {
1324
+ formatOutput(result, true);
1325
+ } else {
1326
+ formatSuccess(`File written: ${path}`, false);
1327
+ }
1328
+ } catch (error) {
1329
+ handleError(error, json);
1330
+ process.exit(1);
1331
+ }
1332
+ });
1333
+
1091
1334
  // src/commands/mcp/index.ts
1092
- var mcpCommand = new Command11("mcp").description("MCP sandbox management commands").addCommand(createCommand).addCommand(listCommand).addCommand(useCommand).addCommand(statusCommand).addCommand(stopCommand).addCommand(testCommand).addCommand(deployCommand);
1335
+ var mcpCommand = new Command15("mcp").description("MCP sandbox management commands").addCommand(createCommand).addCommand(listCommand).addCommand(useCommand).addCommand(statusCommand).addCommand(stopCommand).addCommand(testCommand).addCommand(deployCommand).addCommand(writeFileCommand).addCommand(readFileCommand).addCommand(listFilesCommand).addCommand(runCommandCommand);
1093
1336
 
1094
1337
  // src/commands/org/index.ts
1095
- import { Command as Command14 } from "commander";
1338
+ import { Command as Command18 } from "commander";
1096
1339
 
1097
1340
  // src/commands/org/list.ts
1098
- import chalk7 from "chalk";
1099
- import { Command as Command12 } from "commander";
1100
- import ora9 from "ora";
1101
- var listCommand2 = new Command12("list").description("List your organizations").action(async (_, command) => {
1341
+ import chalk9 from "chalk";
1342
+ import { Command as Command16 } from "commander";
1343
+ import ora13 from "ora";
1344
+ var listCommand2 = new Command16("list").description("List your organizations").action(async (_, command) => {
1102
1345
  const globalOptions = command.optsWithGlobals();
1103
1346
  const json = globalOptions.json ?? false;
1104
1347
  try {
1105
- const spinner = ora9("Fetching organizations...").start();
1348
+ const spinner = ora13("Fetching organizations...").start();
1106
1349
  const result = await api.get("/api/oauth/orgs");
1107
1350
  spinner.stop();
1108
1351
  const { orgs, activeOrgId } = result;
@@ -1122,11 +1365,11 @@ var listCommand2 = new Command12("list").description("List your organizations").
1122
1365
  console.log("No organizations found.");
1123
1366
  return;
1124
1367
  }
1125
- console.log(chalk7.bold("\nOrganizations:\n"));
1368
+ console.log(chalk9.bold("\nOrganizations:\n"));
1126
1369
  const rows = orgs.map((o) => {
1127
1370
  const isActive = o.id === activeOrgId;
1128
1371
  return [
1129
- isActive ? chalk7.cyan(`* ${o.name}`) : ` ${o.name}`,
1372
+ isActive ? chalk9.cyan(`* ${o.name}`) : ` ${o.name}`,
1130
1373
  o.slug,
1131
1374
  o.role
1132
1375
  ];
@@ -1136,7 +1379,7 @@ var listCommand2 = new Command12("list").description("List your organizations").
1136
1379
  if (activeOrgId) {
1137
1380
  const activeOrg = orgs.find((o) => o.id === activeOrgId);
1138
1381
  if (activeOrg) {
1139
- console.log(`Active organization: ${chalk7.cyan(activeOrg.name)}`);
1382
+ console.log(`Active organization: ${chalk9.cyan(activeOrg.name)}`);
1140
1383
  }
1141
1384
  }
1142
1385
  console.log("\nSwitch organization: waniwani org switch <name>");
@@ -1148,13 +1391,13 @@ var listCommand2 = new Command12("list").description("List your organizations").
1148
1391
  });
1149
1392
 
1150
1393
  // src/commands/org/switch.ts
1151
- import { Command as Command13 } from "commander";
1152
- import ora10 from "ora";
1153
- var switchCommand = new Command13("switch").description("Switch to a different organization").argument("<name>", "Name or slug of the organization to switch to").action(async (name, _, command) => {
1394
+ import { Command as Command17 } from "commander";
1395
+ import ora14 from "ora";
1396
+ var switchCommand = new Command17("switch").description("Switch to a different organization").argument("<name>", "Name or slug of the organization to switch to").action(async (name, _, command) => {
1154
1397
  const globalOptions = command.optsWithGlobals();
1155
1398
  const json = globalOptions.json ?? false;
1156
1399
  try {
1157
- const spinner = ora10("Fetching organizations...").start();
1400
+ const spinner = ora14("Fetching organizations...").start();
1158
1401
  const { orgs } = await api.get("/api/oauth/orgs");
1159
1402
  const org = orgs.find((o) => o.name === name || o.slug === name);
1160
1403
  if (!org) {
@@ -1187,13 +1430,13 @@ var switchCommand = new Command13("switch").description("Switch to a different o
1187
1430
  });
1188
1431
 
1189
1432
  // src/commands/org/index.ts
1190
- var orgCommand = new Command14("org").description("Organization management commands").addCommand(listCommand2).addCommand(switchCommand);
1433
+ var orgCommand = new Command18("org").description("Organization management commands").addCommand(listCommand2).addCommand(switchCommand);
1191
1434
 
1192
1435
  // src/commands/task.ts
1193
- import chalk8 from "chalk";
1194
- import { Command as Command15 } from "commander";
1195
- import ora11 from "ora";
1196
- var taskCommand = new Command15("task").description("Send a task to Claude running in the sandbox").argument("<prompt>", "Task description/prompt").option("--mcp-id <id>", "Specific MCP ID").option("--model <model>", "Claude model to use").option("--max-steps <n>", "Maximum tool use steps").action(async (prompt, options, command) => {
1436
+ import chalk10 from "chalk";
1437
+ import { Command as Command19 } from "commander";
1438
+ import ora15 from "ora";
1439
+ var taskCommand = new Command19("task").description("Send a task to Claude running in the sandbox").argument("<prompt>", "Task description/prompt").option("--mcp-id <id>", "Specific MCP ID").option("--model <model>", "Claude model to use").option("--max-steps <n>", "Maximum tool use steps").action(async (prompt, options, command) => {
1197
1440
  const globalOptions = command.optsWithGlobals();
1198
1441
  const json = globalOptions.json ?? false;
1199
1442
  try {
@@ -1217,24 +1460,27 @@ var taskCommand = new Command15("task").description("Send a task to Claude runni
1217
1460
  const maxSteps = options.maxSteps ? Number.parseInt(options.maxSteps, 10) : defaults.maxSteps;
1218
1461
  if (!json) {
1219
1462
  console.log();
1220
- console.log(chalk8.bold("Task:"), prompt);
1463
+ console.log(chalk10.bold("Task:"), prompt);
1221
1464
  console.log();
1222
1465
  }
1223
- const spinner = ora11("Starting task...").start();
1466
+ const spinner = ora15("Starting task...").start();
1224
1467
  const baseUrl = await api.getBaseUrl();
1225
- const response = await fetch(`${baseUrl}/api/admin/mcps/${mcpId}/task`, {
1226
- method: "POST",
1227
- headers: {
1228
- "Content-Type": "application/json",
1229
- Authorization: `Bearer ${token}`,
1230
- Accept: "text/event-stream"
1231
- },
1232
- body: JSON.stringify({
1233
- prompt,
1234
- model,
1235
- maxSteps
1236
- })
1237
- });
1468
+ const response = await fetch(
1469
+ `${baseUrl}/api/mcp/sandboxes/${mcpId}/task`,
1470
+ {
1471
+ method: "POST",
1472
+ headers: {
1473
+ "Content-Type": "application/json",
1474
+ Authorization: `Bearer ${token}`,
1475
+ Accept: "text/event-stream"
1476
+ },
1477
+ body: JSON.stringify({
1478
+ prompt,
1479
+ model,
1480
+ maxSteps
1481
+ })
1482
+ }
1483
+ );
1238
1484
  if (!response.ok) {
1239
1485
  const error = await response.json().catch(() => ({ message: response.statusText }));
1240
1486
  spinner.fail("Task failed");
@@ -1271,7 +1517,7 @@ var taskCommand = new Command15("task").description("Send a task to Claude runni
1271
1517
  const event = parsed;
1272
1518
  steps.push({ type: "text", text: event.content });
1273
1519
  if (!json && event.content) {
1274
- console.log(chalk8.white(event.content));
1520
+ console.log(chalk10.white(event.content));
1275
1521
  }
1276
1522
  } else if (parsed.type === "tool_call") {
1277
1523
  const event = parsed;
@@ -1282,24 +1528,24 @@ var taskCommand = new Command15("task").description("Send a task to Claude runni
1282
1528
  output: event.output
1283
1529
  });
1284
1530
  if (!json) {
1285
- console.log(chalk8.cyan(`> Using tool: ${event.tool}`));
1531
+ console.log(chalk10.cyan(`> Using tool: ${event.tool}`));
1286
1532
  if (event.input?.command) {
1287
- console.log(chalk8.gray(` $ ${event.input.command}`));
1533
+ console.log(chalk10.gray(` $ ${event.input.command}`));
1288
1534
  }
1289
1535
  if (event.output) {
1290
1536
  const outputLines = event.output.split("\n");
1291
1537
  if (outputLines.length > 10) {
1292
1538
  console.log(
1293
- chalk8.gray(outputLines.slice(0, 5).join("\n"))
1539
+ chalk10.gray(outputLines.slice(0, 5).join("\n"))
1294
1540
  );
1295
1541
  console.log(
1296
- chalk8.gray(
1542
+ chalk10.gray(
1297
1543
  ` ... (${outputLines.length - 10} more lines)`
1298
1544
  )
1299
1545
  );
1300
- console.log(chalk8.gray(outputLines.slice(-5).join("\n")));
1546
+ console.log(chalk10.gray(outputLines.slice(-5).join("\n")));
1301
1547
  } else {
1302
- console.log(chalk8.gray(event.output));
1548
+ console.log(chalk10.gray(event.output));
1303
1549
  }
1304
1550
  }
1305
1551
  console.log();
@@ -1320,14 +1566,18 @@ var taskCommand = new Command15("task").description("Send a task to Claude runni
1320
1566
  stepCount,
1321
1567
  maxStepsReached
1322
1568
  };
1569
+ const finalStepCount = stepCount ?? steps.length;
1323
1570
  if (json) {
1324
- formatOutput(result, true);
1571
+ formatOutput({ ...result, stepCount: finalStepCount }, true);
1325
1572
  } else {
1326
1573
  console.log();
1327
- console.log(chalk8.green("\u2713"), `Task completed in ${stepCount} steps.`);
1574
+ console.log(
1575
+ chalk10.green("\u2713"),
1576
+ `Task completed in ${finalStepCount} steps.`
1577
+ );
1328
1578
  if (maxStepsReached) {
1329
1579
  console.log(
1330
- chalk8.yellow("\u26A0"),
1580
+ chalk10.yellow("\u26A0"),
1331
1581
  "Maximum steps reached. Task may be incomplete."
1332
1582
  );
1333
1583
  }
@@ -1340,7 +1590,7 @@ var taskCommand = new Command15("task").description("Send a task to Claude runni
1340
1590
 
1341
1591
  // src/cli.ts
1342
1592
  var version = "0.1.0";
1343
- var program = new Command16().name("waniwani").description("WaniWani CLI for MCP development workflow").version(version).option("--json", "Output results as JSON").option("--verbose", "Enable verbose logging");
1593
+ var program = new Command20().name("waniwani").description("WaniWani CLI for MCP development workflow").version(version).option("--json", "Output results as JSON").option("--verbose", "Enable verbose logging");
1344
1594
  program.addCommand(loginCommand);
1345
1595
  program.addCommand(logoutCommand);
1346
1596
  program.addCommand(initCommand);
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/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\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 { 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(stopCommand)\n\t.addCommand(testCommand)\n\t.addCommand(deployCommand);\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/admin/mcps\", {\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/admin/mcps${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 { 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/admin/mcps/${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/admin/mcps/${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/admin/mcps/${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/admin/mcps/${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(`${baseUrl}/api/admin/mcps/${mcpId}/task`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\t\tAccept: \"text/event-stream\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tprompt,\n\t\t\t\t\tmodel,\n\t\t\t\t\tmaxSteps,\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\tif (json) {\n\t\t\t\tformatOutput(result, true);\n\t\t\t} else {\n\t\t\t\tconsole.log();\n\t\t\t\tconsole.log(chalk.green(\"✓\"), `Task completed in ${stepCount} steps.`);\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 \"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AA,YACD,WAAW,OAAO,YAAY,QAAW;AAExC,oBAAM,YAAY;AAClB,0BAAY,UAAU;AACtB,gCAAkB,UAAU,mBAAmB;AAAA,YAChD;AAAA,UACD,QAAQ;AAAA,UAER;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAS;AAAA,MACd,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAEA,QAAI,MAAM;AACT,mBAAa,QAAQ,IAAI;AAAA,IAC1B,OAAO;AACN,cAAQ,IAAI;AACZ,cAAQ,IAAIA,OAAM,MAAM,QAAG,GAAG,qBAAqB,SAAS,SAAS;AACrE,UAAI,iBAAiB;AACpB,gBAAQ;AAAA,UACPA,OAAM,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;;;ApBtLF,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;;;AqBvB7B,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","Command","ora","Command","ora","chalk","Command","ora","Command","ora","chalk","Command","ora","Command","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/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 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 { 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 } 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,SAAiB,SAAmC;AAC/D,UAAM,SAAS,iBAAiB,OAAO;AAAA,EACxC;AACD;AAQO,IAAM,WAAN,cAAuB,SAAS;AAAA,EACtC,YAAY,SAAiB,SAAmC;AAC/D,UAAM,SAAS,aAAa,OAAO;AAAA,EACpC;AACD;AAEO,SAAS,YAAY,OAAgB,MAAqB;AAChE,MAAI,iB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;AAAA,YACD,WAAW,OAAO,YAAY,QAAW;AAExC,oBAAM,YAAY;AAClB,0BAAY,UAAU;AACtB,gCAAkB,UAAU,mBAAmB;AAAA,YAChD;AAAA,UACD,QAAQ;AAAA,UAER;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAS;AAAA,MACd,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,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;;;AxB9LF,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;;;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waniwani/cli",
3
- "version": "0.0.20",
3
+ "version": "0.0.23",
4
4
  "description": "WaniWani CLI for MCP development workflow",
5
5
  "type": "module",
6
6
  "exports": {