@itd2902/auggw 1.1.4 → 1.1.5

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.
@@ -1,62 +1,62 @@
1
- const readline = require('readline');
2
- const { apiRequest } = require('../utils/api');
3
- const { saveToken } = require('../utils/token');
4
-
5
- function prompt(question, hidden = false) {
6
- return new Promise((resolve) => {
7
- const rl = readline.createInterface({
8
- input: process.stdin,
9
- output: process.stdout,
10
- });
11
-
12
- if (hidden) {
13
- // Mask password input
14
- const stdin = process.stdin;
15
- const onData = (char) => {
16
- char = char.toString();
17
- if (char === '\n' || char === '\r' || char === '\u0004') return;
18
- process.stdout.clearLine(0);
19
- process.stdout.cursorTo(0);
20
- process.stdout.write(question + '*'.repeat(rl.line.length));
21
- };
22
- stdin.on('data', onData);
23
- rl.question(question, (answer) => {
24
- stdin.removeListener('data', onData);
25
- rl.close();
26
- console.log();
27
- resolve(answer);
28
- });
29
- } else {
30
- rl.question(question, (answer) => {
31
- rl.close();
32
- resolve(answer);
33
- });
34
- }
35
- });
36
- }
37
-
38
- async function loginCommand() {
39
- try {
40
- const username = await prompt('Username: ');
41
- const password = await prompt('Password: ', true);
42
-
43
- if (!username || !password) {
44
- console.error('❌ Username and password are required');
45
- process.exit(1);
46
- }
47
-
48
- const data = await apiRequest('POST', '/api/auth/login', { username, password });
49
- saveToken(data.token);
50
- console.log('✅ Logged in successfully! Token saved.');
51
- } catch (err) {
52
- if (err.status === 401) {
53
- console.error('❌ Login failed: Invalid credentials');
54
- } else {
55
- console.error(`❌ Error: ${err.message}`);
56
- }
57
- process.exit(1);
58
- }
59
- }
60
-
61
- module.exports = loginCommand;
62
-
1
+ const readline = require('readline');
2
+ const { apiRequest } = require('../utils/api');
3
+ const { saveToken } = require('../utils/token');
4
+
5
+ function prompt(question, hidden = false) {
6
+ return new Promise((resolve) => {
7
+ const rl = readline.createInterface({
8
+ input: process.stdin,
9
+ output: process.stdout,
10
+ });
11
+
12
+ if (hidden) {
13
+ // Mask password input
14
+ const stdin = process.stdin;
15
+ const onData = (char) => {
16
+ char = char.toString();
17
+ if (char === '\n' || char === '\r' || char === '\u0004') return;
18
+ process.stdout.clearLine(0);
19
+ process.stdout.cursorTo(0);
20
+ process.stdout.write(question + '*'.repeat(rl.line.length));
21
+ };
22
+ stdin.on('data', onData);
23
+ rl.question(question, (answer) => {
24
+ stdin.removeListener('data', onData);
25
+ rl.close();
26
+ console.log();
27
+ resolve(answer);
28
+ });
29
+ } else {
30
+ rl.question(question, (answer) => {
31
+ rl.close();
32
+ resolve(answer);
33
+ });
34
+ }
35
+ });
36
+ }
37
+
38
+ async function loginCommand() {
39
+ try {
40
+ const username = await prompt('Username: ');
41
+ const password = await prompt('Password: ', true);
42
+
43
+ if (!username || !password) {
44
+ console.error('❌ Username and password are required');
45
+ process.exit(1);
46
+ }
47
+
48
+ const data = await apiRequest('POST', '/api/auth/login', { username, password });
49
+ saveToken(data.token);
50
+ console.log('✅ Logged in successfully! Token saved.');
51
+ } catch (err) {
52
+ if (err.status === 401) {
53
+ console.error('❌ Login failed: Invalid credentials');
54
+ } else {
55
+ console.error(`❌ Error: ${err.message}`);
56
+ }
57
+ process.exit(1);
58
+ }
59
+ }
60
+
61
+ module.exports = loginCommand;
62
+
@@ -1,8 +1,8 @@
1
- const { clearToken } = require("../utils/token");
2
-
3
- function logoutCommand() {
4
- clearToken();
5
- console.log("✅ Logged out. Token removed.");
6
- }
7
-
8
- module.exports = logoutCommand;
1
+ const { clearToken } = require("../utils/token");
2
+
3
+ function logoutCommand() {
4
+ clearToken();
5
+ console.log("✅ Logged out. Token removed.");
6
+ }
7
+
8
+ module.exports = logoutCommand;
@@ -1,58 +1,57 @@
1
- const { apiRequest } = require("../utils/api");
2
- const { requireAuth } = require("../utils/auth");
3
- const { getCliName } = require("../utils/paths");
4
-
5
- async function statusCommand() {
6
- requireAuth();
7
-
8
- try {
9
- const data = await apiRequest("GET", "/api/session/status");
10
-
11
- if (!data.current) {
12
- console.log(`ℹ️ No active session. Run: ${getCliName()} switch`);
13
- console.log();
14
- } else {
15
- console.log("📋 Current Account");
16
- console.log(` Name: ${data.current.name}`);
17
- console.log(` Token: ...${data.current.accessToken}`);
18
- console.log(
19
- ` Status: ${data.current.isLimited ? "🔴 Limited" : "🟢 Active"}`,
20
- );
21
- if (data.current.creditTotal) {
22
- const remaining = data.current.creditRemaining || 0;
23
- const total = data.current.creditTotal;
24
- const used = Math.round(total - remaining);
25
- const pct = Math.round((used / total) * 100);
26
- const barWidth = 30;
27
- const filled = Math.round((pct / 100) * barWidth);
28
- const empty = barWidth - filled;
29
- const color = pct > 90 ? "\x1b[31m" : pct > 70 ? "\x1b[33m" : "\x1b[32m";
30
- const reset = "\x1b[0m";
31
- const bar = `${color}${"█".repeat(filled)}${"\x1b[90m"}${"░".repeat(empty)}${reset}`;
32
- console.log(
33
- ` Credit: ${used.toLocaleString()} / ${total.toLocaleString()} (${pct}%)`,
34
- );
35
- console.log(
36
- ` ${bar} ${color}${pct}% used${reset}`,
37
- );
38
- } else {
39
- console.log(` Credit: \x1b[90mN/A — account chưa login trên admin panel\x1b[0m`);
40
- }
41
- console.log();
42
- }
43
-
44
- console.log("📊 Pool Status");
45
- console.log(` Active: ${data.pool.active} accounts`);
46
- console.log(` Limited: ${data.pool.limited} accounts`);
47
- console.log(` Total: ${data.pool.total} accounts`);
48
- } catch (err) {
49
- if (err.status === 401) {
50
- console.error(`❌ Session expired. Please login again: ${getCliName()} login`);
51
- } else {
52
- console.error(`❌ Error: ${err.message}`);
53
- }
54
- process.exit(1);
55
- }
56
- }
57
-
58
- module.exports = statusCommand;
1
+ const { apiRequest } = require("../utils/api");
2
+ const { requireAuth } = require("../utils/auth");
3
+
4
+ async function statusCommand() {
5
+ requireAuth();
6
+
7
+ try {
8
+ const data = await apiRequest("GET", "/api/session/status");
9
+
10
+ if (!data.current) {
11
+ console.log("ℹ️ No active session. Run: auggw switch");
12
+ console.log();
13
+ } else {
14
+ console.log("📋 Current Account");
15
+ console.log(` Name: ${data.current.name}`);
16
+ console.log(` Token: ...${data.current.accessToken}`);
17
+ console.log(
18
+ ` Status: ${data.current.isLimited ? "🔴 Limited" : "🟢 Active"}`,
19
+ );
20
+ if (data.current.creditTotal) {
21
+ const remaining = data.current.creditRemaining || 0;
22
+ const total = data.current.creditTotal;
23
+ const used = Math.round(total - remaining);
24
+ const pct = Math.round((used / total) * 100);
25
+ const barWidth = 30;
26
+ const filled = Math.round((pct / 100) * barWidth);
27
+ const empty = barWidth - filled;
28
+ const color = pct > 90 ? "\x1b[31m" : pct > 70 ? "\x1b[33m" : "\x1b[32m";
29
+ const reset = "\x1b[0m";
30
+ const bar = `${color}${"█".repeat(filled)}${"\x1b[90m"}${"░".repeat(empty)}${reset}`;
31
+ console.log(
32
+ ` Credit: ${used.toLocaleString()} / ${total.toLocaleString()} (${pct}%)`,
33
+ );
34
+ console.log(
35
+ ` ${bar} ${color}${pct}% used${reset}`,
36
+ );
37
+ } else {
38
+ console.log(` Credit: \x1b[90mN/A account chưa login trên admin panel\x1b[0m`);
39
+ }
40
+ console.log();
41
+ }
42
+
43
+ console.log("📊 Pool Status");
44
+ console.log(` Active: ${data.pool.active} accounts`);
45
+ console.log(` Limited: ${data.pool.limited} accounts`);
46
+ console.log(` Total: ${data.pool.total} accounts`);
47
+ } catch (err) {
48
+ if (err.status === 401) {
49
+ console.error("❌ Session expired. Please login again: auggw login");
50
+ } else {
51
+ console.error(`❌ Error: ${err.message}`);
52
+ }
53
+ process.exit(1);
54
+ }
55
+ }
56
+
57
+ module.exports = statusCommand;
@@ -1,44 +1,44 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { apiRequest } = require("../utils/api");
4
- const { requireAuth } = require("../utils/auth");
5
- const { getSessionPath } = require("../utils/paths");
6
-
7
- async function switchCommand() {
8
- requireAuth();
9
-
10
- try {
11
- const data = await apiRequest("GET", "/api/session/next");
12
-
13
- const sessionPath = getSessionPath();
14
- const sessionDir = path.dirname(sessionPath);
15
-
16
- // Create ~/.augment/ directory if it doesn't exist
17
- if (!fs.existsSync(sessionDir)) {
18
- fs.mkdirSync(sessionDir, { recursive: true });
19
- }
20
-
21
- // Write session file
22
- const session = {
23
- accessToken: data.accessToken,
24
- tenantURL: data.tenantURL,
25
- scopes: data.scopes,
26
- };
27
- fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2), "utf8");
28
-
29
- console.log("✅ Session switched!");
30
- console.log(` Account: ${data.accountName}`);
31
- console.log(` Tenant: ${data.tenantURL}`);
32
- } catch (err) {
33
- if (err.status === 401) {
34
- console.error("❌ Session expired. Please login again: auggw login");
35
- } else if (err.status === 503) {
36
- console.error(`❌ ${err.message}`);
37
- } else {
38
- console.error(`❌ Error: ${err.message}`);
39
- }
40
- process.exit(1);
41
- }
42
- }
43
-
44
- module.exports = switchCommand;
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { apiRequest } = require("../utils/api");
4
+ const { requireAuth } = require("../utils/auth");
5
+ const { getSessionPath } = require("../utils/paths");
6
+
7
+ async function switchCommand() {
8
+ requireAuth();
9
+
10
+ try {
11
+ const data = await apiRequest("GET", "/api/session/next");
12
+
13
+ const sessionPath = getSessionPath();
14
+ const sessionDir = path.dirname(sessionPath);
15
+
16
+ // Create ~/.augment/ directory if it doesn't exist
17
+ if (!fs.existsSync(sessionDir)) {
18
+ fs.mkdirSync(sessionDir, { recursive: true });
19
+ }
20
+
21
+ // Write session file
22
+ const session = {
23
+ accessToken: data.accessToken,
24
+ tenantURL: data.tenantURL,
25
+ scopes: data.scopes,
26
+ };
27
+ fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2), "utf8");
28
+
29
+ console.log("✅ Session switched!");
30
+ console.log(` Account: ${data.accountName}`);
31
+ console.log(` Tenant: ${data.tenantURL}`);
32
+ } catch (err) {
33
+ if (err.status === 401) {
34
+ console.error("❌ Session expired. Please login again: auggw login");
35
+ } else if (err.status === 503) {
36
+ console.error(`❌ ${err.message}`);
37
+ } else {
38
+ console.error(`❌ Error: ${err.message}`);
39
+ }
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ module.exports = switchCommand;
@@ -1,33 +1,33 @@
1
- const { execSync } = require("child_process");
2
- const pkg = require("../../package.json");
3
-
4
- async function updateCommand() {
5
- console.log(`Current version: ${pkg.version}`);
6
- console.log("Checking for updates...\n");
7
-
8
- try {
9
- const resp = await fetch(`https://registry.npmjs.org/${pkg.name}/latest`, {
10
- signal: AbortSignal.timeout(5000),
11
- });
12
- if (!resp.ok) {
13
- console.error("❌ Failed to check for updates.");
14
- process.exit(1);
15
- }
16
- const data = await resp.json();
17
-
18
- if (!data.version || data.version === pkg.version) {
19
- console.log("✅ Already on the latest version.");
20
- return;
21
- }
22
-
23
- console.log(`⬆ Updating: ${pkg.version} → ${data.version}\n`);
24
- const cmd = `npm i -g ${pkg.name}@latest`;
25
- execSync(cmd, { stdio: "inherit" });
26
- console.log(`\n✅ Updated to ${data.version}`);
27
- } catch (err) {
28
- console.error(`❌ Update failed: ${err.message}`);
29
- process.exit(1);
30
- }
31
- }
32
-
33
- module.exports = updateCommand;
1
+ const { execSync } = require("child_process");
2
+ const pkg = require("../../package.json");
3
+
4
+ async function updateCommand() {
5
+ console.log(`Current version: ${pkg.version}`);
6
+ console.log("Checking for updates...\n");
7
+
8
+ try {
9
+ const resp = await fetch(`https://registry.npmjs.org/${pkg.name}/latest`, {
10
+ signal: AbortSignal.timeout(5000),
11
+ });
12
+ if (!resp.ok) {
13
+ console.error("❌ Failed to check for updates.");
14
+ process.exit(1);
15
+ }
16
+ const data = await resp.json();
17
+
18
+ if (!data.version || data.version === pkg.version) {
19
+ console.log("✅ Already on the latest version.");
20
+ return;
21
+ }
22
+
23
+ console.log(`⬆ Updating: ${pkg.version} → ${data.version}\n`);
24
+ const cmd = `npm i -g ${pkg.name}@latest`;
25
+ execSync(cmd, { stdio: "inherit" });
26
+ console.log(`\n✅ Updated to ${data.version}`);
27
+ } catch (err) {
28
+ console.error(`❌ Update failed: ${err.message}`);
29
+ process.exit(1);
30
+ }
31
+ }
32
+
33
+ module.exports = updateCommand;
package/src/index.js CHANGED
@@ -1,51 +1,50 @@
1
- const path = require("path");
2
- require("dotenv").config({ path: path.join(__dirname, "..", ".env"), quiet: true });
3
- const { Command } = require("commander");
4
- const loginCommand = require("./commands/login");
5
- const logoutCommand = require("./commands/logout");
6
- const switchCommand = require("./commands/switch");
7
- const statusCommand = require("./commands/status");
8
- const updateCommand = require("./commands/update");
9
- const fetchCommand = require("./commands/fetch");
10
- const { checkUpdate } = require("./utils/update");
11
- const pkg = require("../package.json");
12
-
13
- const program = new Command();
14
-
15
- program
16
- .name(Object.keys(pkg.bin)[0] || "auggw")
17
- .description("CLI tool for rotating Augment session accounts")
18
- .version(pkg.version);
19
-
20
- program
21
- .command("login")
22
- .description("Authenticate with the session rotator backend")
23
- .action(loginCommand);
24
-
25
- program
26
- .command("logout")
27
- .description("Remove saved token and log out")
28
- .action(logoutCommand);
29
-
30
- program
31
- .command("switch")
32
- .description("Switch to the next available Augment session")
33
- .action(switchCommand);
34
-
35
- program
36
- .command("status")
37
- .description("View current account and pool status")
38
- .action(statusCommand);
39
-
40
- program
41
- .command("update")
42
- .description("Update CLI to the latest version")
43
- .action(updateCommand);
44
-
45
- program
46
- .command("fetch")
47
- .description("Fetch resources from server")
48
- .option("--prompts", "Fetch commands & skills to ~/.augment and/or ~/.claude")
49
- .action(fetchCommand);
50
-
51
- program.parseAsync().then(() => checkUpdate());
1
+ const { Command } = require('commander');
2
+ const loginCommand = require('./commands/login');
3
+ const logoutCommand = require('./commands/logout');
4
+ const switchCommand = require('./commands/switch');
5
+ const statusCommand = require('./commands/status');
6
+ const updateCommand = require('./commands/update');
7
+ const fetchCommand = require('./commands/fetch');
8
+ const { checkUpdate } = require('./utils/update');
9
+ const pkg = require('../package.json');
10
+
11
+ const program = new Command();
12
+
13
+ program
14
+ .name(Object.keys(pkg.bin)[0] || 'auggw')
15
+ .description('CLI tool for rotating Augment session accounts')
16
+ .version(pkg.version);
17
+
18
+ program
19
+ .command('login')
20
+ .description('Authenticate with the session rotator backend')
21
+ .action(loginCommand);
22
+
23
+ program
24
+ .command('logout')
25
+ .description('Remove saved token and log out')
26
+ .action(logoutCommand);
27
+
28
+ program
29
+ .command('switch')
30
+ .description('Switch to the next available Augment session')
31
+ .action(switchCommand);
32
+
33
+ program
34
+ .command('status')
35
+ .description('View current account and pool status')
36
+ .action(statusCommand);
37
+
38
+ program
39
+ .command('update')
40
+ .description('Update CLI to the latest version')
41
+ .action(updateCommand);
42
+
43
+ program
44
+ .command('fetch')
45
+ .description('Fetch resources from server')
46
+ .option('--prompts', 'Fetch commands & skills to ~/.augment and/or ~/.claude')
47
+ .action(fetchCommand);
48
+
49
+ program.parseAsync().then(() => checkUpdate());
50
+