axusage 3.0.0 → 3.1.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/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { authClearCommand } from "./commands/auth-clear-command.js";
|
|
|
5
5
|
import { authSetupCommand } from "./commands/auth-setup-command.js";
|
|
6
6
|
import { authStatusCommand } from "./commands/auth-status-command.js";
|
|
7
7
|
import { usageCommand } from "./commands/usage-command.js";
|
|
8
|
+
import { getCredentialSourcesPath } from "./config/credential-sources.js";
|
|
8
9
|
import { getBrowserContextsDirectory } from "./services/app-paths.js";
|
|
9
10
|
import { getAvailableServices } from "./services/service-adapter-registry.js";
|
|
10
11
|
import { installAuthManagerCleanup } from "./services/shared-browser-auth-manager.js";
|
|
@@ -30,7 +31,7 @@ const program = new Command()
|
|
|
30
31
|
.option("--auth-status [service]", "check authentication status for services")
|
|
31
32
|
.option("--auth-clear <service>", "clear saved browser authentication for a service (moves files to system Trash)")
|
|
32
33
|
.option("-f, --force", "skip confirmation for destructive actions")
|
|
33
|
-
.addHelpText("after", `\nExamples:\n # Fetch usage for all services\n ${packageJson.name}\n\n # JSON output for a single service\n ${packageJson.name} --service claude --format=json\n\n # TSV output for piping to cut, awk, sort\n ${packageJson.name} --format=tsv | tail -n +2 | awk -F'\\t' '{print $1, $4"%"}'\n\n # Filter Prometheus metrics with standard tools\n ${packageJson.name} --format=prometheus | grep axusage_utilization_percent\n\n # Check authentication status for all services\n ${packageJson.name} --auth-status\n\nStorage: ${getBrowserContextsDirectory()}\n(respects XDG_DATA_HOME and platform defaults)\n\nRequires: claude, codex (ChatGPT), gemini (CLI auth); Playwright Chromium (GitHub Copilot auth)\nOverride CLI paths: AXUSAGE_CLAUDE_PATH, AXUSAGE_CODEX_PATH, AXUSAGE_GEMINI_PATH\nPlaywright: PLAYWRIGHT_BROWSERS_PATH\n`);
|
|
34
|
+
.addHelpText("after", () => `\nExamples:\n # Fetch usage for all services\n ${packageJson.name}\n\n # JSON output for a single service\n ${packageJson.name} --service claude --format=json\n\n # TSV output for piping to cut, awk, sort\n ${packageJson.name} --format=tsv | tail -n +2 | awk -F'\\t' '{print $1, $4"%"}'\n\n # Filter Prometheus metrics with standard tools\n ${packageJson.name} --format=prometheus | grep axusage_utilization_percent\n\n # Check authentication status for all services\n ${packageJson.name} --auth-status\n\nStorage: ${getBrowserContextsDirectory()}\n(respects XDG_DATA_HOME and platform defaults)\nSources config file: ${getCredentialSourcesPath()}\n(or set AXUSAGE_SOURCES to JSON to bypass file)\n\nRequires: claude, codex (ChatGPT), gemini (CLI auth); Playwright Chromium (GitHub Copilot auth)\nOverride CLI paths: AXUSAGE_CLAUDE_PATH, AXUSAGE_CODEX_PATH, AXUSAGE_GEMINI_PATH\nPlaywright: PLAYWRIGHT_BROWSERS_PATH\n`);
|
|
34
35
|
function fail(message) {
|
|
35
36
|
console.error(`Error: ${message}`);
|
|
36
37
|
console.error("Try 'axusage --help' for details.");
|
|
@@ -34,5 +34,13 @@ type ServiceId = VaultSupportedServiceId | "github-copilot";
|
|
|
34
34
|
* @returns Resolved config with source type and optional credential name
|
|
35
35
|
*/
|
|
36
36
|
declare function getServiceSourceConfig(service: ServiceId): ResolvedSourceConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Get the credential sources config file path.
|
|
39
|
+
*
|
|
40
|
+
* This computes the path using env-paths directly instead of instantiating
|
|
41
|
+
* Conf, which avoids all filesystem side effects (Conf creates the config
|
|
42
|
+
* directory during construction).
|
|
43
|
+
*/
|
|
44
|
+
declare function getCredentialSourcesPath(): string;
|
|
37
45
|
export type { ServiceId, VaultSupportedServiceId };
|
|
38
|
-
export { getServiceSourceConfig };
|
|
46
|
+
export { getServiceSourceConfig, getCredentialSourcesPath };
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* - "auto": Try vault first if configured and credential name provided, fallback to local
|
|
8
8
|
*/
|
|
9
9
|
import Conf from "conf";
|
|
10
|
+
import envPaths from "env-paths";
|
|
11
|
+
import path from "node:path";
|
|
10
12
|
import { z } from "zod";
|
|
11
13
|
/** Credential source type */
|
|
12
14
|
const CredentialSourceType = z.enum(["auto", "local", "vault"]);
|
|
@@ -114,4 +116,15 @@ function getServiceSourceConfig(service) {
|
|
|
114
116
|
// Object: source and name
|
|
115
117
|
return { source: serviceConfig.source, name: serviceConfig.name };
|
|
116
118
|
}
|
|
117
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Get the credential sources config file path.
|
|
121
|
+
*
|
|
122
|
+
* This computes the path using env-paths directly instead of instantiating
|
|
123
|
+
* Conf, which avoids all filesystem side effects (Conf creates the config
|
|
124
|
+
* directory during construction).
|
|
125
|
+
*/
|
|
126
|
+
function getCredentialSourcesPath() {
|
|
127
|
+
const configDirectory = envPaths("axusage", { suffix: "" }).config;
|
|
128
|
+
return path.resolve(configDirectory, "config.json");
|
|
129
|
+
}
|
|
130
|
+
export { getServiceSourceConfig, getCredentialSourcesPath };
|
|
@@ -21,8 +21,15 @@ export async function releaseAuthManager() {
|
|
|
21
21
|
}
|
|
22
22
|
references -= 1;
|
|
23
23
|
if (references === 0 && manager) {
|
|
24
|
-
|
|
24
|
+
const closingManager = manager;
|
|
25
25
|
manager = undefined;
|
|
26
|
+
try {
|
|
27
|
+
await closingManager.close();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// Best-effort cleanup: log but don't propagate (prevents masking prior errors in finally blocks)
|
|
31
|
+
console.warn("Failed to close browser auth manager:", error instanceof Error ? error.message : String(error));
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
async function forceClose() {
|
|
@@ -31,14 +38,14 @@ async function forceClose() {
|
|
|
31
38
|
closing = true;
|
|
32
39
|
references = 0;
|
|
33
40
|
if (manager) {
|
|
41
|
+
const closingManager = manager;
|
|
42
|
+
manager = undefined;
|
|
34
43
|
try {
|
|
35
|
-
await
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// ignore
|
|
44
|
+
await closingManager.close();
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
catch (error) {
|
|
47
|
+
// Best-effort cleanup: log but don't propagate during shutdown
|
|
48
|
+
console.warn("Failed to close browser auth manager during shutdown:", error instanceof Error ? error.message : String(error));
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
}
|
|
@@ -17,7 +17,9 @@ export async function verifySessionByFetching(context, url, maxAttempts = DEFAUL
|
|
|
17
17
|
// Wait a bit and try again; tokens/cookies may not be settled yet
|
|
18
18
|
// Skip the delay after the final attempt to avoid unnecessary wait
|
|
19
19
|
if (attempt < maxAttempts - 1) {
|
|
20
|
-
await new Promise((resolve) =>
|
|
20
|
+
await new Promise((resolve) => {
|
|
21
|
+
setTimeout(resolve, delayMs);
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "axusage",
|
|
3
3
|
"author": "Łukasz Jerciński",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.1.0",
|
|
6
6
|
"description": "Monitor API usage across Claude, ChatGPT, GitHub Copilot, and Gemini from a single CLI",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@commander-js/extra-typings": "^14.0.0",
|
|
57
57
|
"@inquirer/prompts": "^8.2.0",
|
|
58
|
-
"axauth": "^1.
|
|
58
|
+
"axauth": "^2.1.0",
|
|
59
59
|
"chalk": "^5.6.2",
|
|
60
60
|
"commander": "^14.0.2",
|
|
61
61
|
"conf": "^15.0.2",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
70
|
-
"@types/node": "^25.0.
|
|
70
|
+
"@types/node": "^25.0.9",
|
|
71
71
|
"@vitest/coverage-v8": "^4.0.17",
|
|
72
72
|
"eslint": "^9.39.2",
|
|
73
|
-
"eslint-config-axkit": "^1.
|
|
73
|
+
"eslint-config-axkit": "^1.1.0",
|
|
74
74
|
"fta-check": "^1.5.1",
|
|
75
75
|
"fta-cli": "^3.0.0",
|
|
76
76
|
"knip": "^5.81.0",
|
|
77
|
-
"prettier": "3.
|
|
77
|
+
"prettier": "3.8.0",
|
|
78
78
|
"semantic-release": "^25.0.2",
|
|
79
79
|
"typescript": "^5.9.3",
|
|
80
80
|
"vitest": "^4.0.17"
|