opencode-usage 0.4.8 → 0.5.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/README.md +20 -0
- package/dist/__tests__/commander-app-init.test.d.ts +1 -0
- package/dist/__tests__/commander-command-runner.test.d.ts +1 -0
- package/dist/__tests__/commander-config-service.test.d.ts +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/commander/index.d.ts +1 -0
- package/dist/commander/server.d.ts +7 -0
- package/dist/commander/services/action-service.d.ts +11 -0
- package/dist/commander/services/app-init-service.d.ts +17 -0
- package/dist/commander/services/command-runner.d.ts +12 -0
- package/dist/commander/services/config-service.d.ts +38 -0
- package/dist/commander/services/index.d.ts +2 -0
- package/dist/commander/services/plugin-adapters.d.ts +7 -0
- package/dist/commander/services/quota-service.d.ts +10 -0
- package/dist/commander/services/types.d.ts +33 -0
- package/dist/commander/services/usage-service.d.ts +32 -0
- package/dist/commander/services/usage-worker.d.ts +7 -0
- package/dist/index.js +1395 -3
- package/dist/index.js.map +13 -5
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ CLI tool for tracking [OpenCode](https://github.com/sst/opencode) AI coding assi
|
|
|
11
11
|
- JSON output for scripting and automation
|
|
12
12
|
- Model pricing for accurate cost estimation
|
|
13
13
|
- Terminal table output
|
|
14
|
+
- **Commander web dashboard** with quota status, account management, and ping
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -63,6 +64,25 @@ opencode-usage -w -d 1
|
|
|
63
64
|
opencode-usage --provider anthropic --since 7d --json
|
|
64
65
|
```
|
|
65
66
|
|
|
67
|
+
### Commander Web Dashboard
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Launch the web dashboard
|
|
71
|
+
opencode-usage --commander
|
|
72
|
+
|
|
73
|
+
# Custom port
|
|
74
|
+
opencode-usage --commander --commander-port 5000
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The Commander provides a single-page web UI with:
|
|
78
|
+
|
|
79
|
+
- **Quota Status** - Per-provider account usage with progress bars, thresholds, and stale detection (Anthropic, Codex, Antigravity)
|
|
80
|
+
- **Usage Breakdown** - Daily token usage table with cost estimates and provider drill-down
|
|
81
|
+
- **Account Management** - Add, switch, remove, and re-authenticate accounts
|
|
82
|
+
- **Ping** - Verify account connectivity with live PONG/FAIL indicators
|
|
83
|
+
- **Dark mode** toggle
|
|
84
|
+
- Auto-refresh every 5 minutes
|
|
85
|
+
|
|
66
86
|
## Output
|
|
67
87
|
|
|
68
88
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runCommanderServer } from "./server.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action service — ensures all plugin adapter commands are registered.
|
|
3
|
+
*
|
|
4
|
+
* Call `ensureActionsRegistered()` once at server startup so that
|
|
5
|
+
* account and action commands are available in the command registry.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Import plugin-adapters as a side-effect to register all commands.
|
|
9
|
+
* Safe to call multiple times — registration happens only once.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureActionsRegistered(): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App initializer service — detection + init/repair workflows for gaboe-owned apps.
|
|
3
|
+
*
|
|
4
|
+
* Manages a catalog of 4 apps with detection logic, one-click init,
|
|
5
|
+
* and repair workflows exposed via registered commands.
|
|
6
|
+
*/
|
|
7
|
+
export type AppId = "oc-codex-multi-account" | "oc-anthropic-multi-account" | "opencode-gitbutler" | "opencode-usage";
|
|
8
|
+
export type AppState = "ready" | "partial" | "missing-deps" | "not-installed";
|
|
9
|
+
export type AppStatus = {
|
|
10
|
+
id: AppId;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
state: AppState;
|
|
14
|
+
details: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function getAppCatalog(): Promise<AppStatus[]>;
|
|
17
|
+
export declare function ensureAppCommandsRegistered(): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command registry and background job runner.
|
|
3
|
+
*
|
|
4
|
+
* Commands are registered via `registerCommand`, then executed asynchronously
|
|
5
|
+
* via `runCommand`. Jobs are tracked in-memory with log streaming support.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommandJob, CommandSpec } from "./types.js";
|
|
8
|
+
export declare function registerCommand<I, O>(spec: CommandSpec<I, O>): void;
|
|
9
|
+
export declare function getJob(jobId: string): CommandJob | undefined;
|
|
10
|
+
export declare function listJobs(): CommandJob[];
|
|
11
|
+
export declare function cancelJob(jobId: string): boolean;
|
|
12
|
+
export declare function runCommand(commandId: string, payload: unknown): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config service — read, write, backup and rollback for Commander-managed config files.
|
|
3
|
+
*
|
|
4
|
+
* Supports atomic writes (tmp + rename) and auto-backup before every mutation.
|
|
5
|
+
*/
|
|
6
|
+
export type ConfigSource = "codex-multi-account-accounts" | "anthropic-multi-account-state" | "antigravity-accounts" | "opencode";
|
|
7
|
+
export type ConfigFileMeta = {
|
|
8
|
+
source: ConfigSource;
|
|
9
|
+
path: string;
|
|
10
|
+
exists: boolean;
|
|
11
|
+
parseOk: boolean;
|
|
12
|
+
sizeBytes: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function isValidSource(s: string): s is ConfigSource;
|
|
15
|
+
/**
|
|
16
|
+
* List all known config files with metadata.
|
|
17
|
+
*/
|
|
18
|
+
export declare function listConfigFiles(): Promise<ConfigFileMeta[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Read and parse a config file. Throws if missing or unparseable.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readConfig(source: ConfigSource): unknown;
|
|
23
|
+
/**
|
|
24
|
+
* Write config with atomic tmp+rename and auto-backup.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeConfig(source: ConfigSource, data: unknown): Promise<{
|
|
27
|
+
backupPath: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Rollback config to the latest backup.
|
|
31
|
+
*/
|
|
32
|
+
export declare function rollbackConfig(source: ConfigSource): Promise<{
|
|
33
|
+
restoredFrom: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare class ConfigError extends Error {
|
|
36
|
+
status: number;
|
|
37
|
+
constructor(message: string, status: number);
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quota data service — thin wrapper over quota loaders for the Commander API.
|
|
3
|
+
*/
|
|
4
|
+
import type { QuotaSnapshot } from "../../types.js";
|
|
5
|
+
export type QuotaData = {
|
|
6
|
+
anthropic: QuotaSnapshot[];
|
|
7
|
+
antigravity: QuotaSnapshot[];
|
|
8
|
+
codex: QuotaSnapshot[];
|
|
9
|
+
};
|
|
10
|
+
export declare function getQuotaData(): Promise<QuotaData>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the Commander command system.
|
|
3
|
+
*/
|
|
4
|
+
export type JobStatus = "queued" | "running" | "success" | "failed" | "cancelled";
|
|
5
|
+
export type JobLogEntry = {
|
|
6
|
+
ts: string;
|
|
7
|
+
level: "info" | "warn" | "error";
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
export type CommandJob = {
|
|
11
|
+
id: string;
|
|
12
|
+
commandId: string;
|
|
13
|
+
status: JobStatus;
|
|
14
|
+
startedAt?: string;
|
|
15
|
+
finishedAt?: string;
|
|
16
|
+
logs: JobLogEntry[];
|
|
17
|
+
result?: unknown;
|
|
18
|
+
error?: {
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type CommandContext = {
|
|
24
|
+
log: (level: JobLogEntry["level"], message: string) => void;
|
|
25
|
+
jobId: string;
|
|
26
|
+
};
|
|
27
|
+
export type CommandSpec<Input, Output> = {
|
|
28
|
+
id: string;
|
|
29
|
+
validateInput: (payload: unknown) => Input;
|
|
30
|
+
run: (ctx: CommandContext, input: Input) => Promise<Output>;
|
|
31
|
+
timeoutMs: number;
|
|
32
|
+
allowInUi: boolean;
|
|
33
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage data service — thin wrapper over loader + aggregator for the Commander API.
|
|
3
|
+
*/
|
|
4
|
+
export type UsageQueryOpts = {
|
|
5
|
+
provider?: string;
|
|
6
|
+
days?: number;
|
|
7
|
+
since?: string;
|
|
8
|
+
until?: string;
|
|
9
|
+
monthly?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type SerializedProviderStats = {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cacheWrite: number;
|
|
15
|
+
cacheRead: number;
|
|
16
|
+
reasoning: number;
|
|
17
|
+
cost: number;
|
|
18
|
+
models: string[];
|
|
19
|
+
};
|
|
20
|
+
export type SerializedDailyStats = {
|
|
21
|
+
date: string;
|
|
22
|
+
input: number;
|
|
23
|
+
output: number;
|
|
24
|
+
cacheWrite: number;
|
|
25
|
+
cacheRead: number;
|
|
26
|
+
reasoning: number;
|
|
27
|
+
cost: number;
|
|
28
|
+
models: string[];
|
|
29
|
+
providers: string[];
|
|
30
|
+
providerStats: Record<string, SerializedProviderStats>;
|
|
31
|
+
};
|
|
32
|
+
export declare function getUsageData(opts?: UsageQueryOpts): Promise<SerializedDailyStats[]>;
|