@juejin-opensource/jusage 0.1.6-beta.0 → 0.1.7
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/args.d.ts +20 -0
- package/dist/args.js +121 -0
- package/dist/daemon.d.ts +2 -2
- package/dist/daemon.js +8 -7
- package/dist/dashboard/assets/Check-C6Vp6SAU.js +1 -0
- package/dist/dashboard/assets/click-idle-CXAVCmiH.png +0 -0
- package/dist/dashboard/assets/dashboard-CW-mCwMR.js +55 -0
- package/dist/dashboard/assets/download-_xhCt7jY.js +1 -0
- package/dist/dashboard/assets/downloads-63AG5C_E.js +1 -0
- package/dist/dashboard/assets/hawking-idle-QoXt5bST.png +0 -0
- package/dist/dashboard/assets/index-3miiAdwH.js +143 -0
- package/dist/dashboard/assets/{index-I_ub2jqy.css → index-C1vokUY2.css} +1 -1
- package/dist/dashboard/assets/{index-C28OANM4.js → index-DikHz9Xg.js} +1 -1
- package/dist/dashboard/assets/{pricing-C1AgdgdM.js → pricing-Btfm94JM.js} +1 -1
- package/dist/dashboard/assets/rank-LoqZH6uK.js +16 -0
- package/dist/dashboard/assets/{settings-BA_UlPf3.js → settings-BzyD7YMM.js} +1 -1
- package/dist/dashboard/assets/useLocalStorage-C_Z-N_8Q.js +1 -0
- package/dist/dashboard/assets/yoyo-idle-DDvV3ieO.png +0 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/index.d.ts +1 -10
- package/dist/index.js +21 -93
- package/dist/service-linux.js +6 -1
- package/dist/service.d.ts +4 -1
- package/dist/service.js +19 -8
- package/package.json +13 -13
- package/dist/dashboard/assets/ChevronDown-raqOGGZY.js +0 -1
- package/dist/dashboard/assets/click-idle-6pQvdt8N.png +0 -0
- package/dist/dashboard/assets/dashboard-2aS4UXAq.js +0 -55
- package/dist/dashboard/assets/download-w1_SlsVA.js +0 -1
- package/dist/dashboard/assets/downloads-DRt36RTZ.js +0 -1
- package/dist/dashboard/assets/env-Bahc-RuR.js +0 -1
- package/dist/dashboard/assets/hawking-idle-C6M3ZvDm.png +0 -0
- package/dist/dashboard/assets/index-DpG68XJd.js +0 -143
- package/dist/dashboard/assets/rank-DNpmekT1.js +0 -16
- package/dist/dashboard/assets/yoyo-idle-DmXh5tLT.png +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 juejin-cn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ jusage start # 或直接 jusage
|
|
|
55
55
|
```bash
|
|
56
56
|
jusage service start
|
|
57
57
|
jusage start --port 8452
|
|
58
|
+
jusage start --host 0.0.0.0 # 局域网可访问;默认 127.0.0.1
|
|
58
59
|
jusage sync --source=claude # claude | codex | cursor | all
|
|
59
60
|
jusage upload --force # 忽略云端同步开关,强制上报
|
|
60
61
|
jusage upload --reconcile # 全量对账后上报
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const DEFAULT_HOST = "127.0.0.1";
|
|
2
|
+
export declare function isWildcardListenHost(host: string): boolean;
|
|
3
|
+
export declare function formatListenUrl(host: string, port: number): string;
|
|
4
|
+
export interface ParsedArgs {
|
|
5
|
+
command: string;
|
|
6
|
+
serviceAction?: string;
|
|
7
|
+
/** Set only when --port is passed. */
|
|
8
|
+
port?: number;
|
|
9
|
+
/** Set only when --host is passed. */
|
|
10
|
+
host?: string;
|
|
11
|
+
source?: string;
|
|
12
|
+
force?: boolean;
|
|
13
|
+
reconcile?: boolean;
|
|
14
|
+
/** Hidden debug: seed statsSince to N days ago when missing. Not shown in --help. */
|
|
15
|
+
days?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function normalizeListenHost(raw: string): string;
|
|
18
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
19
|
+
export declare function resolveDaysAgo(days: number | undefined): number | undefined;
|
|
20
|
+
export declare function printHelp(): void;
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { DEFAULT_PORT } from '@juejin-opensource/jusage-core';
|
|
2
|
+
export const DEFAULT_HOST = '127.0.0.1';
|
|
3
|
+
export function isWildcardListenHost(host) {
|
|
4
|
+
return host === '0.0.0.0' || host === '::';
|
|
5
|
+
}
|
|
6
|
+
export function formatListenUrl(host, port) {
|
|
7
|
+
const display = isWildcardListenHost(host) ? DEFAULT_HOST : host;
|
|
8
|
+
const formatted = display.includes(':') && !display.startsWith('[') ? `[${display}]` : display;
|
|
9
|
+
return `http://${formatted}:${port}`;
|
|
10
|
+
}
|
|
11
|
+
export function normalizeListenHost(raw) {
|
|
12
|
+
const host = raw.trim();
|
|
13
|
+
if (!host) {
|
|
14
|
+
throw new Error('--host 不能为空,例如 0.0.0.0 或 127.0.0.1');
|
|
15
|
+
}
|
|
16
|
+
if (/[\s/?#]/.test(host)) {
|
|
17
|
+
throw new Error(`无效的 --host: ${raw}`);
|
|
18
|
+
}
|
|
19
|
+
return host;
|
|
20
|
+
}
|
|
21
|
+
function isFlagToken(value) {
|
|
22
|
+
return value != null && value.startsWith('-') && value !== '-';
|
|
23
|
+
}
|
|
24
|
+
export function parseArgs(argv) {
|
|
25
|
+
const args = argv.slice(2);
|
|
26
|
+
let command = args[0] ?? 'start';
|
|
27
|
+
let serviceAction;
|
|
28
|
+
let port;
|
|
29
|
+
let host;
|
|
30
|
+
let source;
|
|
31
|
+
let force = false;
|
|
32
|
+
let reconcile = false;
|
|
33
|
+
let days;
|
|
34
|
+
if (command === 'help' ||
|
|
35
|
+
command === '--help' ||
|
|
36
|
+
command === '-h' ||
|
|
37
|
+
args.includes('--help') ||
|
|
38
|
+
args.includes('-h')) {
|
|
39
|
+
return { command: 'help', port, host, source, force, reconcile };
|
|
40
|
+
}
|
|
41
|
+
if (command === 'service') {
|
|
42
|
+
serviceAction = args[1];
|
|
43
|
+
}
|
|
44
|
+
for (let i = 0; i < args.length; i++) {
|
|
45
|
+
if (args[i] === '--port' && args[i + 1]) {
|
|
46
|
+
port = Number(args[i + 1]) || DEFAULT_PORT;
|
|
47
|
+
i += 1;
|
|
48
|
+
}
|
|
49
|
+
else if (args[i] === '--host') {
|
|
50
|
+
if (isFlagToken(args[i + 1]) || args[i + 1] == null) {
|
|
51
|
+
throw new Error('--host 需要地址,例如 0.0.0.0 或 127.0.0.1');
|
|
52
|
+
}
|
|
53
|
+
host = normalizeListenHost(args[i + 1]);
|
|
54
|
+
i += 1;
|
|
55
|
+
}
|
|
56
|
+
else if (args[i]?.startsWith('--host=')) {
|
|
57
|
+
host = normalizeListenHost(args[i].slice('--host='.length));
|
|
58
|
+
}
|
|
59
|
+
else if (args[i] === '--source' && args[i + 1]) {
|
|
60
|
+
source = args[i + 1];
|
|
61
|
+
i += 1;
|
|
62
|
+
}
|
|
63
|
+
else if (args[i]?.startsWith('--source=')) {
|
|
64
|
+
source = args[i].slice('--source='.length);
|
|
65
|
+
}
|
|
66
|
+
else if (args[i] === '--force') {
|
|
67
|
+
force = true;
|
|
68
|
+
}
|
|
69
|
+
else if (args[i] === '--reconcile') {
|
|
70
|
+
reconcile = true;
|
|
71
|
+
}
|
|
72
|
+
else if (args[i] === '--days' && args[i + 1]) {
|
|
73
|
+
days = Number(args[i + 1]);
|
|
74
|
+
i += 1;
|
|
75
|
+
}
|
|
76
|
+
else if (args[i]?.startsWith('--days=')) {
|
|
77
|
+
days = Number(args[i].slice('--days='.length));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (command.startsWith('-'))
|
|
81
|
+
command = 'start';
|
|
82
|
+
return { command, serviceAction, port, host, source, force, reconcile, days };
|
|
83
|
+
}
|
|
84
|
+
export function resolveDaysAgo(days) {
|
|
85
|
+
if (days === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
if (!Number.isInteger(days) || days <= 0) {
|
|
88
|
+
throw new Error(`--days 须为正整数,收到: ${days}`);
|
|
89
|
+
}
|
|
90
|
+
return days;
|
|
91
|
+
}
|
|
92
|
+
export function printHelp() {
|
|
93
|
+
console.log(`Usage: jusage <command> [options]
|
|
94
|
+
|
|
95
|
+
Commands:
|
|
96
|
+
start 前台启动本地面板与同步(默认;桌面已运行时为观察模式)
|
|
97
|
+
stop 停止当前进程内的服务
|
|
98
|
+
status 查看 CLI / 面板当前启动状态
|
|
99
|
+
sync 手动同步本地用量数据
|
|
100
|
+
upload 上报数据到云端
|
|
101
|
+
service <action> 后台服务与开机自启(macOS / Windows / Linux)
|
|
102
|
+
action: start | stop | status
|
|
103
|
+
help 显示帮助
|
|
104
|
+
|
|
105
|
+
Options:
|
|
106
|
+
--port <number> 面板端口(默认 ${DEFAULT_PORT})
|
|
107
|
+
--host <address> 面板监听地址(默认 ${DEFAULT_HOST};局域网访问用 0.0.0.0)
|
|
108
|
+
--source <name> sync 数据源:claude | codex | cursor | qoder | trae | gemini | opencode | copilot | antigravity | openclaw | hermes | zcode | pi | kimi | roocode | droid | kiro | cline | amp | qwen | codebuddy | workbuddy | grok | mimo | every-code | omp | kilo-cli | kilocode | goose | zed | warp | all
|
|
109
|
+
--force upload 时忽略云端同步开关,强制上报
|
|
110
|
+
--reconcile upload 时做全量对账
|
|
111
|
+
-h, --help 显示帮助
|
|
112
|
+
|
|
113
|
+
Examples:
|
|
114
|
+
jusage
|
|
115
|
+
jusage start --port 8452
|
|
116
|
+
jusage start --host 0.0.0.0
|
|
117
|
+
jusage status
|
|
118
|
+
jusage sync --source=claude
|
|
119
|
+
jusage upload --force
|
|
120
|
+
jusage service start`);
|
|
121
|
+
}
|
package/dist/daemon.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ export { clearPid, getRunningOwner, getRunningPid, isPidAlive, pidFilePath, read
|
|
|
3
3
|
export declare function daemonLogPath(dataDir?: string): string;
|
|
4
4
|
export declare function ensureDaemonLogDir(dataDir?: string): Promise<string>;
|
|
5
5
|
/** True when local-api `/health` returns `{ ok: true }`. */
|
|
6
|
-
export declare function probeLocalHealth(port: number): Promise<boolean>;
|
|
6
|
+
export declare function probeLocalHealth(port: number, host?: string): Promise<boolean>;
|
|
7
7
|
export declare function waitForPid(dataDir?: string, timeoutMs?: number): Promise<number | null>;
|
|
8
8
|
export interface ServiceReady {
|
|
9
9
|
pid: number | null;
|
|
10
10
|
health: boolean;
|
|
11
11
|
}
|
|
12
12
|
/** Wait until the pid file is live, or `/health` is up as a fallback. */
|
|
13
|
-
export declare function waitForServiceReady(dataDir: string, port: number, timeoutMs?: number): Promise<ServiceReady>;
|
|
13
|
+
export declare function waitForServiceReady(dataDir: string, port: number, host?: string, timeoutMs?: number): Promise<ServiceReady>;
|
|
14
14
|
export declare function readDaemonLogTail(dataDir?: string, maxChars?: number): Promise<string>;
|
|
15
15
|
export declare function resolveServiceCommand(cliBinPath: string): {
|
|
16
16
|
nodePath: string;
|
package/dist/daemon.js
CHANGED
|
@@ -3,6 +3,7 @@ import { realpathSync } from 'node:fs';
|
|
|
3
3
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { DEFAULT_DATA_DIR, argsMatchRuntimeKind, logsDir, clearPid, getRunningOwner, getRunningPid, isPidAlive, pidFilePath, readPid, readProcessArgs, readRuntimeOwner, stopPid, writePid, writeRuntimeOwner, } from '@juejin-opensource/jusage-core';
|
|
6
|
+
import { DEFAULT_HOST, formatListenUrl } from './args.js';
|
|
6
7
|
export { clearPid, getRunningOwner, getRunningPid, isPidAlive, pidFilePath, readPid, readRuntimeOwner, stopPid, writePid, writeRuntimeOwner, };
|
|
7
8
|
export function daemonLogPath(dataDir = DEFAULT_DATA_DIR) {
|
|
8
9
|
return join(logsDir(dataDir), 'daemon.log');
|
|
@@ -21,9 +22,9 @@ async function readLivePid(dataDir) {
|
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
23
24
|
/** True when local-api `/health` returns `{ ok: true }`. */
|
|
24
|
-
export async function probeLocalHealth(port) {
|
|
25
|
+
export async function probeLocalHealth(port, host = DEFAULT_HOST) {
|
|
25
26
|
try {
|
|
26
|
-
const res = await fetch(
|
|
27
|
+
const res = await fetch(`${formatListenUrl(host, port)}/health`, {
|
|
27
28
|
signal: AbortSignal.timeout(400),
|
|
28
29
|
});
|
|
29
30
|
if (!res.ok)
|
|
@@ -83,21 +84,21 @@ export async function waitForPid(dataDir = DEFAULT_DATA_DIR, timeoutMs = 15_000)
|
|
|
83
84
|
return getRunningPid(dataDir);
|
|
84
85
|
}
|
|
85
86
|
/** Wait until the pid file is live, or `/health` is up as a fallback. */
|
|
86
|
-
export async function waitForServiceReady(dataDir, port, timeoutMs = 15_000) {
|
|
87
|
+
export async function waitForServiceReady(dataDir, port, host = DEFAULT_HOST, timeoutMs = 15_000) {
|
|
87
88
|
const deadline = Date.now() + timeoutMs;
|
|
88
89
|
while (Date.now() < deadline) {
|
|
89
90
|
const pid = await readLivePid(dataDir);
|
|
90
91
|
if (pid != null)
|
|
91
|
-
return { pid, health: await probeLocalHealth(port) };
|
|
92
|
-
if (await probeLocalHealth(port)) {
|
|
92
|
+
return { pid, health: await probeLocalHealth(port, host) };
|
|
93
|
+
if (await probeLocalHealth(port, host)) {
|
|
93
94
|
return { pid: await recoverPidFromHealth(dataDir, port), health: true };
|
|
94
95
|
}
|
|
95
96
|
await new Promise((r) => setTimeout(r, 200));
|
|
96
97
|
}
|
|
97
98
|
const pid = (await readLivePid(dataDir)) ?? (await getRunningPid(dataDir));
|
|
98
99
|
if (pid != null)
|
|
99
|
-
return { pid, health: await probeLocalHealth(port) };
|
|
100
|
-
if (await probeLocalHealth(port)) {
|
|
100
|
+
return { pid, health: await probeLocalHealth(port, host) };
|
|
101
|
+
if (await probeLocalHealth(port, host)) {
|
|
101
102
|
return { pid: await recoverPidFromHealth(dataDir, port), health: true };
|
|
102
103
|
}
|
|
103
104
|
return { pid: null, health: false };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as p,R as l,j as r,cf as g,r as s,cg as v,a9 as c,bg as f,cb as x,a7 as h,bT as u,ch as w,ci as b,b4 as m}from"./index-3miiAdwH.js";const $=p({slots:{base:"popover",dialog:"popover__dialog",heading:"popover__heading",trigger:"popover__trigger"}}),n=s.createContext({}),d=({children:o,...t})=>{const a=l.useMemo(()=>$(),[]);return r.jsx(n,{value:{slots:a},children:r.jsx(g,{"data-slot":"popover-root",...t,children:o})})},j=({children:o,className:t,...a})=>{const{slots:e}=s.use(n);return r.jsx(n,{value:{slots:e},children:r.jsx(f,{value:{variant:"default"},children:r.jsx(x,{...a,className:h(t,e==null?void 0:e.base()),children:o})})})},C=({children:o,className:t,...a})=>{const e=r.jsx("svg",{"data-slot":"popover-overlay-arrow",fill:"none",height:"12",viewBox:"0 0 12 12",width:"12",xmlns:"http://www.w3.org/2000/svg",children:r.jsx("path",{d:"M0 0C5.48483 8 6.5 8 12 0Z"})}),i=l.isValidElement(o)?l.cloneElement(o,{"data-slot":"popover-overlay-arrow"}):e;return r.jsx(u,{"data-slot":"popover-overlay-arrow-group",...a,className:t,children:i})},P=({children:o,className:t,...a})=>{const{slots:e}=s.use(n);return r.jsx(w,{"data-slot":"popover-dialog",...a,className:c(e==null?void 0:e.dialog,t),children:o})},R=({children:o,className:t,...a})=>{const{slots:e}=s.use(n);return r.jsx(b,{children:r.jsx(m.div,{className:c(e==null?void 0:e.trigger,t),"data-slot":"popover-trigger",role:"button",...a,children:o})})},E=({children:o,className:t,...a})=>{const{slots:e}=s.use(n);return r.jsx(v,{slot:"title",...a,className:c(e==null?void 0:e.heading,t),children:o})},_=Object.assign(d,{Root:d,Trigger:R,Dialog:P,Arrow:C,Content:j,Heading:E}),A=o=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",width:16,height:16,fill:"none",viewBox:"0 0 16 16"},o),s.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M13.488 3.43a.75.75 0 0 1 .081 1.058l-6 7a.75.75 0 0 1-1.1.042l-3.5-3.5A.75.75 0 0 1 4.03 6.97l2.928 2.927 5.473-6.385a.75.75 0 0 1 1.057-.081",clipRule:"evenodd"}));export{A as C,_ as P};
|
|
Binary file
|