@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.
- package/SETUP.md +62 -62
- package/bin/auggw.js +2 -2
- package/bin/augteam.js +3 -3
- package/bin/icbauggw.js +1 -1
- package/package.json +1 -1
- package/publish.js +69 -69
- package/src/commands/fetch.js +145 -145
- package/src/commands/login.js +62 -62
- package/src/commands/logout.js +8 -8
- package/src/commands/status.js +57 -58
- package/src/commands/switch.js +44 -44
- package/src/commands/update.js +33 -33
- package/src/index.js +50 -51
- package/src/utils/api.js +74 -76
- package/src/utils/auth.js +11 -12
- package/src/utils/paths.js +12 -19
- package/src/utils/token.js +30 -30
- package/src/utils/update.js +24 -24
package/src/commands/login.js
CHANGED
|
@@ -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
|
+
|
package/src/commands/logout.js
CHANGED
|
@@ -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;
|
package/src/commands/status.js
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
const { apiRequest } = require("../utils/api");
|
|
2
|
-
const { requireAuth } = require("../utils/auth");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
console.log(
|
|
16
|
-
console.log(`
|
|
17
|
-
console.log(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(
|
|
45
|
-
console.log(`
|
|
46
|
-
console.log(`
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
package/src/commands/switch.js
CHANGED
|
@@ -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;
|
package/src/commands/update.js
CHANGED
|
@@ -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
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
|