@first087/agys 0.2.0 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@first087/agys",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Manage multiple antigravity-cli oauth token accounts",
5
5
  "author": "Artit Kiuwilai",
6
6
  "repository": {
@@ -13,15 +13,15 @@
13
13
  "module": "index.ts",
14
14
  "type": "module",
15
15
  "bin": {
16
- "agys": "index.ts"
16
+ "agys": "dist/index.js"
17
17
  },
18
18
  "files": [
19
- "src",
20
- "index.ts"
19
+ "dist"
21
20
  ],
22
21
  "scripts": {
23
22
  "start": "bun run index.ts",
24
- "test": "bun test",
23
+ "test": "bun test src/**/*.test.ts",
24
+ "test:e2e": "bun test src/e2e.spec.ts",
25
25
  "build": "rm -rf dist && bun build index.ts --outdir ./dist --target bun --minify",
26
26
  "lint": "bunx tsc --noEmit",
27
27
  "publish:npm": "bun run build && npm publish --access public"
@@ -35,10 +35,11 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@types/bun": "latest",
38
- "@types/fs-extra": "^11.0.4"
38
+ "@types/fs-extra": "^11.0.4",
39
+ "@types/node": "^25.9.1"
39
40
  },
40
41
  "peerDependencies": {
41
- "typescript": "^5"
42
+ "typescript": "^6"
42
43
  },
43
44
  "dependencies": {
44
45
  "chalk": "^5.6.2",
package/index.ts DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { Command } from "commander";
3
- import packageJson from "./package.json" with { type: "json" };
4
- import { addCommand } from "./src/commands/add";
5
- import { listCommand, lsCommand } from "./src/commands/list";
6
- import { switchCommand, handleSwitch } from "./src/commands/switch";
7
-
8
- const program = new Command();
9
-
10
- program
11
- .name("agys")
12
- .description(`${packageJson.description} (v${packageJson.version})`)
13
- .version(packageJson.version);
14
-
15
- program.addCommand(addCommand);
16
- program.addCommand(listCommand);
17
- program.addCommand(lsCommand);
18
- program.addCommand(switchCommand);
19
-
20
- // Set description for switch command explicitly
21
- switchCommand.description(
22
- "Switch to a different account (run agys without arguments)",
23
- );
24
-
25
- // Set default action if no command is provided
26
- program.action(async () => {
27
- if (program.args.length === 0) {
28
- await handleSwitch();
29
- }
30
- });
31
-
32
- program.addHelpText(
33
- "after",
34
- `
35
- GitHub Repository: https://github.com/first087/agy-switch
36
- `,
37
- );
38
-
39
- program.parse(process.argv);
@@ -1,21 +0,0 @@
1
- import { expect, test, spyOn } from "bun:test";
2
- import * as fileOps from "../utils/fileOperations";
3
-
4
- // Mocking the utility function
5
- spyOn(fileOps, "copyTokenToAccount").mockImplementation(() =>
6
- Promise.resolve("/home/user/.agys/test-account"),
7
- );
8
-
9
- test("add command calls copyTokenToAccount with correct arguments", async () => {
10
- // Logic to test will be added as we implement the command
11
- const accountName = "test-account";
12
- const sourcePath =
13
- "/home/user/.gemini/antigravity-cli/antigravity-oauth-token";
14
-
15
- await fileOps.copyTokenToAccount(accountName, sourcePath);
16
-
17
- expect(fileOps.copyTokenToAccount).toHaveBeenCalledWith(
18
- accountName,
19
- sourcePath,
20
- );
21
- });
@@ -1,27 +0,0 @@
1
- import { Command } from "commander";
2
- import * as fileOps from "../utils/fileOperations";
3
- import chalk from "chalk";
4
- import os from "os";
5
- import path from "path";
6
-
7
- export const addCommand = new Command("add")
8
- .description("Add a new account token")
9
- .argument("[name]", "account name") // Change <name> to [name] to make it optional
10
- .action(async (name) => {
11
- if (!name) {
12
- addCommand.outputHelp();
13
- return;
14
- }
15
- const sourcePath = path.join(
16
- os.homedir(),
17
- ".gemini",
18
- "antigravity-cli",
19
- "antigravity-oauth-token",
20
- );
21
- try {
22
- await fileOps.copyTokenToAccount(name, sourcePath);
23
- console.log(chalk.green(`Account '${name}' added successfully.`));
24
- } catch (error) {
25
- console.error(chalk.red(`Failed to add account '${name}':`), error);
26
- }
27
- });
@@ -1,19 +0,0 @@
1
- import { expect, test, spyOn } from "bun:test";
2
- import * as fileOps from "../utils/fileOperations";
3
-
4
- // Mocking the utility functions
5
- spyOn(fileOps, "getAccounts").mockImplementation(() =>
6
- Promise.resolve(["test", "test2", "test3"]),
7
- );
8
- spyOn(fileOps, "getActiveAccount").mockImplementation(() =>
9
- Promise.resolve("test"),
10
- );
11
-
12
- test("list command returns all accounts with active one marked", async () => {
13
- const accounts = await fileOps.getAccounts();
14
- const active = await fileOps.getActiveAccount();
15
-
16
- expect(accounts).toContain("test");
17
- expect(accounts).toContain("test2");
18
- expect(active).toBe("test");
19
- });
@@ -1,34 +0,0 @@
1
- import { Command } from "commander";
2
- import * as fileOps from "../utils/fileOperations";
3
- import chalk from "chalk";
4
-
5
- async function listAction() {
6
- try {
7
- const accounts = await fileOps.getAccounts();
8
- const active = await fileOps.getActiveAccount();
9
-
10
- if (accounts.length === 0) {
11
- console.log(chalk.yellow("No accounts found. Use 'add' to create one."));
12
- return;
13
- }
14
-
15
- console.log(chalk.blue("Accounts:"));
16
- accounts.forEach((account: string) => {
17
- if (account === active) {
18
- console.log(chalk.green(`* ${account} (active)`));
19
- } else {
20
- console.log(` ${account}`);
21
- }
22
- });
23
- } catch (error) {
24
- console.error(chalk.red("Failed to list accounts:"), error);
25
- }
26
- }
27
-
28
- export const listCommand = new Command("list")
29
- .description("List all accounts")
30
- .action(listAction);
31
-
32
- export const lsCommand = new Command("ls")
33
- .description("Alias for list")
34
- .action(listAction);
@@ -1,26 +0,0 @@
1
- import { expect, test, spyOn } from "bun:test";
2
- import * as fileOps from "../utils/fileOperations";
3
- import inquirer from "inquirer";
4
-
5
- // Mocking the utility functions and inquirer
6
- spyOn(fileOps, "getAccounts").mockImplementation(() =>
7
- Promise.resolve(["test", "test2", "test3"]),
8
- );
9
- // @ts-ignore
10
- spyOn(inquirer, "prompt").mockImplementation(() =>
11
- Promise.resolve({ selectedAccount: "test2" }) as any,
12
- );
13
-
14
- test("switch interactive menu returns selected account", async () => {
15
- const accounts = await fileOps.getAccounts();
16
- const answers = await inquirer.prompt([
17
- {
18
- type: "list",
19
- name: "selectedAccount",
20
- message: "Select account:",
21
- choices: accounts,
22
- },
23
- ]);
24
-
25
- expect(answers.selectedAccount).toBe("test2");
26
- });
@@ -1,77 +0,0 @@
1
- import { Command } from "commander";
2
- import * as fileOps from "../utils/fileOperations";
3
- import inquirer from "inquirer";
4
- import chalk from "chalk";
5
- import path from "path";
6
- import os from "os";
7
- import fs from "fs-extra";
8
- import packageJson from "../../package.json" with { type: "json" };
9
-
10
- export async function handleSwitch() {
11
- console.clear();
12
- try {
13
- const accounts = await fileOps.getAccounts();
14
- const active = await fileOps.getActiveAccount();
15
-
16
- if (accounts.length === 0) {
17
- console.log(
18
- chalk.yellow("No accounts found. Use 'agys add' to create one."),
19
- );
20
- return;
21
- }
22
-
23
- const message = `[agys v${packageJson.version}] Select account (Press Ctrl+C to cancel)`;
24
- const header = `
25
- ${chalk.green("╭" + "─".repeat(message.length + 2) + "╮")}
26
- ${chalk.green("│")} ${chalk.bold(message)} ${chalk.green("│")}
27
- ${chalk.green("╰" + "─".repeat(message.length + 2) + "╯")}`;
28
- console.log(header);
29
-
30
- const { selectedAccount } = await inquirer
31
- .prompt([
32
- {
33
- type: "select",
34
- name: "selectedAccount",
35
- message: "Account:",
36
- choices: accounts.map((account: string) => ({
37
- name: account === active ? `${account} (active)` : account,
38
- value: account,
39
- })),
40
- default: active,
41
- theme: {
42
- icon: { cursor: "👉" },
43
- style: {
44
- highlight: chalk.green,
45
- },
46
- },
47
- },
48
- ])
49
- .catch(() => {
50
- console.log(chalk.yellow("\nSwitching cancelled."));
51
- process.exit(0);
52
- });
53
-
54
- if (selectedAccount !== active) {
55
- const sourcePath = path.join(os.homedir(), ".agys", selectedAccount);
56
- const destPath = path.join(
57
- os.homedir(),
58
- ".gemini",
59
- "antigravity-cli",
60
- "antigravity-oauth-token",
61
- );
62
-
63
- // Use fs.copy to copy from source to dest (token file)
64
- await fs.copy(sourcePath, destPath);
65
- await fileOps.setActiveAccount(selectedAccount);
66
- console.log(chalk.green(`Switched to account '${selectedAccount}'`));
67
- } else {
68
- console.log(chalk.blue(`Already using account '${selectedAccount}'`));
69
- }
70
- } catch (error) {
71
- console.error(chalk.red("Failed to switch account:"), error);
72
- }
73
- }
74
-
75
- export const switchCommand = new Command("switch")
76
- .description("Switch to a different account")
77
- .action(handleSwitch);
@@ -1,41 +0,0 @@
1
- import fs from "fs-extra";
2
- import path from "path";
3
- import os from "os";
4
-
5
- const CONFIG_DIR = path.join(os.homedir(), ".agys");
6
- const ACTIVE_FILE = path.join(CONFIG_DIR, ".active");
7
-
8
- export async function ensureConfigDir() {
9
- await fs.ensureDir(CONFIG_DIR);
10
- }
11
-
12
- export async function copyTokenToAccount(
13
- accountName: string,
14
- sourcePath: string,
15
- ) {
16
- const destPath = path.join(CONFIG_DIR, accountName);
17
- await fs.ensureDir(CONFIG_DIR);
18
- await fs.copy(sourcePath, destPath);
19
- return destPath;
20
- }
21
-
22
- export async function getAccounts() {
23
- await ensureConfigDir();
24
- const files = await fs.readdir(CONFIG_DIR);
25
- return files.filter((file: string) => file !== ".active");
26
- }
27
-
28
- export async function setActiveAccount(accountName: string) {
29
- await ensureConfigDir();
30
- await fs.writeFile(ACTIVE_FILE, accountName, "utf-8");
31
- }
32
-
33
- export async function getActiveAccount() {
34
- await ensureConfigDir();
35
-
36
- if (!fs.existsSync(ACTIVE_FILE)) {
37
- return null;
38
- }
39
-
40
- return await fs.readFile(ACTIVE_FILE, "utf-8");
41
- }