agents-deck 1.22.0 → 1.23.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/dist/web/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>agents-deck</title>
|
|
7
7
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext y='84' font-size='84'%3E%E2%97%89%3C/text%3E%3C/svg%3E" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-Pto3y4lD.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-BRoNoC-Z.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agents-deck",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.1",
|
|
4
4
|
"description": "Live deck of Claude Code and Codex agents — watch parallel subagents fork, call tools, and return on one calm canvas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"agents-deck": "bin/agent-dag.js",
|
|
8
|
-
"agent-dag": "bin/agent-dag.js"
|
|
8
|
+
"agent-dag": "bin/agent-dag.js",
|
|
9
|
+
"ccdeck": "bin/agent-dag.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"bin",
|
package/src/server/ccusage.mjs
CHANGED
|
@@ -1,25 +1,149 @@
|
|
|
1
1
|
// Fetches historical usage from the `ccusage` CLI (https://github.com/ccusage/ccusage).
|
|
2
2
|
// ccusage reads the local ~/.claude (and other agent) logs and reports cost +
|
|
3
|
-
// token usage grouped by day.
|
|
4
|
-
// — it is NOT a dependency; npx fetches it on first run (cached afterwards).
|
|
3
|
+
// token usage grouped by day.
|
|
5
4
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
5
|
+
// Performance: we do NOT run `npx -y ccusage@latest` on every call — that hits
|
|
6
|
+
// the npm registry to resolve `@latest` (and re-downloads when the npx cache is
|
|
7
|
+
// cold), so each modal open waited seconds. Instead we keep our OWN managed
|
|
8
|
+
// install under ~/.agents-deck/ccusage and invoke it directly with
|
|
9
|
+
// `node <pkg>/src/cli.js` (no npx, no registry round-trip). A throttled
|
|
10
|
+
// once-per-day background check upgrades it when a newer ccusage ships, while
|
|
11
|
+
// the current call always serves from the already-installed copy. If the
|
|
12
|
+
// managed install is missing/broken we fall back to the old npx path so the
|
|
13
|
+
// feature still works on a fresh machine.
|
|
14
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import os from "node:os";
|
|
10
18
|
|
|
11
|
-
const CACHE_MS = 120_000; // 2 min —
|
|
19
|
+
const CACHE_MS = 120_000; // 2 min — modal is manual-open; cheap to keep warm
|
|
12
20
|
const TIMEOUT_MS = 90_000;
|
|
21
|
+
const INSTALL_TIMEOUT_MS = 120_000; // first-run npm install can be slow
|
|
22
|
+
const UPDATE_CHECK_MS = 24 * 3600_000; // check npm for a newer ccusage once/day
|
|
23
|
+
|
|
24
|
+
const CACHE_DIR = path.join(os.homedir(), ".agents-deck", "ccusage");
|
|
25
|
+
const PKG_DIR = path.join(CACHE_DIR, "node_modules", "ccusage");
|
|
26
|
+
const MARKER = path.join(CACHE_DIR, ".last-update-check");
|
|
13
27
|
|
|
14
28
|
const _cache = new Map(); // key `${since}|${until}` → { result, at }
|
|
15
29
|
|
|
16
|
-
//
|
|
17
|
-
|
|
30
|
+
let _installing = null; // Promise guard so concurrent calls share one install
|
|
31
|
+
let _checkedThisRun = false; // only kick the daily check once per process boot
|
|
32
|
+
|
|
33
|
+
// ── managed install ─────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
// Absolute path to ccusage's CLI entry inside our managed install, or null if
|
|
36
|
+
// not installed. Reads the package's `bin` field (currently "./src/cli.js").
|
|
37
|
+
function resolveEntry() {
|
|
38
|
+
try {
|
|
39
|
+
const pkg = JSON.parse(readFileSync(path.join(PKG_DIR, "package.json"), "utf8"));
|
|
40
|
+
let rel = pkg.bin;
|
|
41
|
+
if (rel && typeof rel === "object") rel = rel.ccusage ?? Object.values(rel)[0];
|
|
42
|
+
if (typeof rel !== "string") return null;
|
|
43
|
+
const entry = path.join(PKG_DIR, rel);
|
|
44
|
+
return existsSync(entry) ? { entry, version: pkg.version } : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Run `npm install ccusage@<spec> --prefix CACHE_DIR`. Synchronous variant for
|
|
51
|
+
// the first-run cold path (we must have a binary before we can answer).
|
|
52
|
+
function installSync(spec = "latest") {
|
|
53
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
54
|
+
const r = spawnSync(
|
|
55
|
+
"npm",
|
|
56
|
+
["install", `ccusage@${spec}`, "--prefix", CACHE_DIR,
|
|
57
|
+
"--no-save", "--no-audit", "--no-fund", "--loglevel", "error"],
|
|
58
|
+
{ shell: true, windowsHide: true, timeout: INSTALL_TIMEOUT_MS, encoding: "utf8" },
|
|
59
|
+
);
|
|
60
|
+
if (r.status !== 0) {
|
|
61
|
+
throw new Error(`npm install ccusage failed: ${(r.stderr || "").trim() || r.status}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Background, non-blocking install (used by the daily update path).
|
|
66
|
+
function installAsync(spec = "latest") {
|
|
67
|
+
try {
|
|
68
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
69
|
+
const child = spawn(
|
|
70
|
+
"npm",
|
|
71
|
+
["install", `ccusage@${spec}`, "--prefix", CACHE_DIR,
|
|
72
|
+
"--no-save", "--no-audit", "--no-fund", "--loglevel", "error"],
|
|
73
|
+
{ shell: true, windowsHide: true, detached: false, stdio: "ignore" },
|
|
74
|
+
);
|
|
75
|
+
child.on("error", () => {});
|
|
76
|
+
child.unref?.();
|
|
77
|
+
} catch { /* best-effort */ }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// True at most once per UPDATE_CHECK_MS, gated by the marker file's mtime so the
|
|
81
|
+
// throttle survives restarts.
|
|
82
|
+
function updateCheckDue() {
|
|
83
|
+
try {
|
|
84
|
+
return Date.now() - statSync(MARKER).mtimeMs > UPDATE_CHECK_MS;
|
|
85
|
+
} catch {
|
|
86
|
+
return true; // no marker yet → due
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// (Re)write the marker so its mtime marks "now" as the last check time.
|
|
90
|
+
function touchMarker() {
|
|
91
|
+
try {
|
|
92
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
93
|
+
writeFileSync(MARKER, String(Date.now()));
|
|
94
|
+
} catch { /* ignore */ }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Non-blocking: compare installed version to npm `latest`; install if newer.
|
|
98
|
+
function maybeBackgroundUpdate(installedVersion) {
|
|
99
|
+
if (_checkedThisRun || !updateCheckDue()) return;
|
|
100
|
+
_checkedThisRun = true;
|
|
101
|
+
touchMarker();
|
|
102
|
+
try {
|
|
103
|
+
const child = spawn("npm", ["view", "ccusage", "version"],
|
|
104
|
+
{ shell: true, windowsHide: true });
|
|
105
|
+
let out = "";
|
|
106
|
+
child.stdout.on("data", d => { out += d; });
|
|
107
|
+
child.on("error", () => {});
|
|
108
|
+
child.on("close", () => {
|
|
109
|
+
const latest = out.trim();
|
|
110
|
+
if (latest && latest !== installedVersion) installAsync(latest);
|
|
111
|
+
});
|
|
112
|
+
} catch { /* ignore */ }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Ensure a runnable ccusage. Returns { kind:"node", entry } for the managed
|
|
116
|
+
// install, or { kind:"npx" } as the portable fallback.
|
|
117
|
+
async function getRunner() {
|
|
118
|
+
let resolved = resolveEntry();
|
|
119
|
+
if (resolved) {
|
|
120
|
+
maybeBackgroundUpdate(resolved.version);
|
|
121
|
+
return { kind: "node", entry: resolved.entry };
|
|
122
|
+
}
|
|
123
|
+
// Cold: install once (deduped across concurrent callers).
|
|
124
|
+
if (!_installing) {
|
|
125
|
+
_installing = (async () => { installSync("latest"); })()
|
|
126
|
+
.catch(e => { console.error("agents-deck ccusage: install failed:", e?.message ?? e); })
|
|
127
|
+
.finally(() => { _installing = null; });
|
|
128
|
+
}
|
|
129
|
+
await _installing;
|
|
130
|
+
resolved = resolveEntry();
|
|
131
|
+
if (resolved) { touchMarker(); return { kind: "node", entry: resolved.entry }; }
|
|
132
|
+
return { kind: "npx" }; // npm unavailable / offline → fall back to npx
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ── invocation ──────────────────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
// Run ccusage with the given args, resolve raw stdout.
|
|
138
|
+
async function runCcusage(args) {
|
|
139
|
+
const runner = await getRunner();
|
|
140
|
+
const [cmd, full] = runner.kind === "node"
|
|
141
|
+
? [process.execPath, [runner.entry, ...args]]
|
|
142
|
+
: ["npx", ["-y", "ccusage@latest", ...args]];
|
|
18
143
|
return new Promise((resolve, reject) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
shell: true,
|
|
144
|
+
const child = spawn(cmd, full, {
|
|
145
|
+
// node path needs no shell; npx fallback does (Windows .cmd shim).
|
|
146
|
+
shell: runner.kind === "npx",
|
|
23
147
|
windowsHide: true,
|
|
24
148
|
});
|
|
25
149
|
let out = "", err = "";
|