@itd2902/auggw 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SETUP.md ADDED
@@ -0,0 +1,46 @@
1
+ # Hướng dẫn cài đặt CLI - Augment Session Rotator
2
+
3
+ ## Yêu cầu
4
+
5
+ - Node.js >= 18
6
+
7
+ ## Cài đặt
8
+
9
+ ```bash
10
+ npm install -g auggw
11
+ ```
12
+
13
+ ## Đăng nhập
14
+
15
+ ```bash
16
+ auggw login
17
+ ```
18
+
19
+ Nhập username và password được cấp. Token sẽ lưu tại `~/gg/token`.
20
+
21
+ ## Sử dụng
22
+
23
+ ### Chuyển session
24
+
25
+ ```bash
26
+ auggw switch
27
+ ```
28
+
29
+ Lệnh này lấy account tiếp theo từ pool và ghi vào `~/.augment/session.json`. Chạy lại mỗi khi cần đổi account.
30
+
31
+ ### Xem trạng thái
32
+
33
+ ```bash
34
+ auggw status
35
+ ```
36
+
37
+ Hiển thị account đang dùng, credit usage và số lượng account trong pool.
38
+
39
+ ## Lưu ý
40
+
41
+ - Sau khi `switch`, restart lại Augment extension để nó đọc session mới.
42
+ - Nếu gặp lỗi `Session expired`, chạy lại `auggw login`.
43
+ - Nếu cần trỏ sang server khác (dev/test), set env:
44
+ ```bash
45
+ auggw_API_URL=http://localhost:3000 auggw login
46
+ ```
package/bin/auggw.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../src/index");
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@itd2902/auggw",
3
+ "version": "1.0.1",
4
+ "description": "CLI tool for rotating Augment session accounts",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "auggw": "./bin/auggw.js"
8
+ },
9
+ "scripts": {},
10
+ "keywords": [
11
+ "augment",
12
+ "session",
13
+ "rotate",
14
+ "cli"
15
+ ],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "engines": {
19
+ "node": ">=18.0.0"
20
+ },
21
+ "dependencies": {
22
+ "commander": "^13.1.0"
23
+ }
24
+ }
@@ -0,0 +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
+
@@ -0,0 +1,46 @@
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(` Tenant: ${data.current.tenantURL}`);
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 used = data.current.creditRemaining || 0;
23
+ const total = data.current.creditTotal;
24
+ const pct = Math.round((used / total) * 100);
25
+ console.log(
26
+ ` Credit: ${used.toLocaleString()} / ${total.toLocaleString()} (${pct}%)`,
27
+ );
28
+ }
29
+ console.log();
30
+ }
31
+
32
+ console.log("📊 Pool Status");
33
+ console.log(` Active: ${data.pool.active} accounts`);
34
+ console.log(` Limited: ${data.pool.limited} accounts`);
35
+ console.log(` Total: ${data.pool.total} accounts`);
36
+ } catch (err) {
37
+ if (err.status === 401) {
38
+ console.error("❌ Session expired. Please login again: auggw login");
39
+ } else {
40
+ console.error(`❌ Error: ${err.message}`);
41
+ }
42
+ process.exit(1);
43
+ }
44
+ }
45
+
46
+ module.exports = statusCommand;
@@ -0,0 +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;
package/src/index.js ADDED
@@ -0,0 +1,29 @@
1
+ const { Command } = require('commander');
2
+ const loginCommand = require('./commands/login');
3
+ const switchCommand = require('./commands/switch');
4
+ const statusCommand = require('./commands/status');
5
+
6
+ const program = new Command();
7
+
8
+ program
9
+ .name('auggw')
10
+ .description('CLI tool for rotating Augment session accounts')
11
+ .version('1.0.0');
12
+
13
+ program
14
+ .command('login')
15
+ .description('Authenticate with the session rotator backend')
16
+ .action(loginCommand);
17
+
18
+ program
19
+ .command('switch')
20
+ .description('Switch to the next available Augment session')
21
+ .action(switchCommand);
22
+
23
+ program
24
+ .command('status')
25
+ .description('View current account and pool status')
26
+ .action(statusCommand);
27
+
28
+ program.parse();
29
+
@@ -0,0 +1,74 @@
1
+ const os = require("os");
2
+ const { loadToken } = require("./token");
3
+
4
+ const DEFAULT_API_URL = "https://auggw.quangit.site";
5
+ // const DEFAULT_API_URL = "http://localhost:3000";
6
+
7
+ function getBaseURL() {
8
+ return process.env.auggw_API_URL || DEFAULT_API_URL;
9
+ }
10
+
11
+ function getLocalIP() {
12
+ const interfaces = os.networkInterfaces();
13
+ // Skip virtual/VPN adapters — prefer real Ethernet/Wi-Fi
14
+ const skipPatterns =
15
+ /tailscale|vpn|virtual|vethernet|bluetooth|loopback|docker|vbox|vmware|wsl/i;
16
+
17
+ // First pass: find IP from real adapters (Ethernet, Wi-Fi)
18
+ for (const [name, addrs] of Object.entries(interfaces)) {
19
+ if (skipPatterns.test(name)) continue;
20
+ for (const iface of addrs) {
21
+ if (iface.family === "IPv4" && !iface.internal) {
22
+ return iface.address;
23
+ }
24
+ }
25
+ }
26
+ // Fallback: any non-internal IPv4
27
+ for (const addrs of Object.values(interfaces)) {
28
+ for (const iface of addrs) {
29
+ if (iface.family === "IPv4" && !iface.internal) {
30
+ return iface.address;
31
+ }
32
+ }
33
+ }
34
+ return "127.0.0.1";
35
+ }
36
+
37
+ async function apiRequest(method, path, body = null) {
38
+ const url = `${getBaseURL()}${path}`;
39
+ const token = loadToken();
40
+
41
+ const headers = {
42
+ "Content-Type": "application/json",
43
+ "X-Client-IP": getLocalIP(),
44
+ "X-Client-Hostname": os.hostname(),
45
+ };
46
+ if (token) {
47
+ headers["Authorization"] = `Bearer ${token}`;
48
+ }
49
+
50
+ const options = { method, headers };
51
+ if (body) {
52
+ options.body = JSON.stringify(body);
53
+ }
54
+
55
+ try {
56
+ const res = await fetch(url, options);
57
+ const data = await res.json();
58
+
59
+ if (!res.ok) {
60
+ const err = new Error(data.error || `HTTP ${res.status}`);
61
+ err.status = res.status;
62
+ throw err;
63
+ }
64
+
65
+ return data;
66
+ } catch (err) {
67
+ if (err.cause && err.cause.code === "ECONNREFUSED") {
68
+ throw new Error(`Could not connect to server at ${getBaseURL()}`);
69
+ }
70
+ throw err;
71
+ }
72
+ }
73
+
74
+ module.exports = { apiRequest, getBaseURL };
@@ -0,0 +1,11 @@
1
+ const { loadToken } = require("./token");
2
+
3
+ function requireAuth() {
4
+ const token = loadToken();
5
+ if (!token) {
6
+ console.error("❌ Please login first: auggw login");
7
+ process.exit(1);
8
+ }
9
+ }
10
+
11
+ module.exports = { requireAuth };
@@ -0,0 +1,12 @@
1
+ const os = require("os");
2
+ const path = require("path");
3
+
4
+ function getTokenPath() {
5
+ return path.join(os.homedir(), ".auggw", "token");
6
+ }
7
+
8
+ function getSessionPath() {
9
+ return path.join(os.homedir(), ".augment", "session.json");
10
+ }
11
+
12
+ module.exports = { getTokenPath, getSessionPath };
@@ -0,0 +1,30 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { getTokenPath } = require('./paths');
4
+
5
+ function saveToken(token) {
6
+ const tokenPath = getTokenPath();
7
+ const dir = path.dirname(tokenPath);
8
+ if (!fs.existsSync(dir)) {
9
+ fs.mkdirSync(dir, { recursive: true });
10
+ }
11
+ fs.writeFileSync(tokenPath, token, 'utf8');
12
+ }
13
+
14
+ function loadToken() {
15
+ const tokenPath = getTokenPath();
16
+ if (!fs.existsSync(tokenPath)) {
17
+ return null;
18
+ }
19
+ return fs.readFileSync(tokenPath, 'utf8').trim();
20
+ }
21
+
22
+ function clearToken() {
23
+ const tokenPath = getTokenPath();
24
+ if (fs.existsSync(tokenPath)) {
25
+ fs.unlinkSync(tokenPath);
26
+ }
27
+ }
28
+
29
+ module.exports = { saveToken, loadToken, clearToken };
30
+