@yishiguji/tokenarena 0.22.0 → 0.24.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/index.js +195 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6981,6 +6981,136 @@ var CherryStudioParser = class {
|
|
|
6981
6981
|
};
|
|
6982
6982
|
registerParser(new CherryStudioParser());
|
|
6983
6983
|
|
|
6984
|
+
// src/parsers/muse.ts
|
|
6985
|
+
import { existsSync as existsSync31 } from "fs";
|
|
6986
|
+
import { homedir as homedir31 } from "os";
|
|
6987
|
+
import { dirname as dirname10, join as join32 } from "path";
|
|
6988
|
+
var TOOL_ID22 = "muse";
|
|
6989
|
+
var TOOL_NAME20 = "Muse";
|
|
6990
|
+
var EXPORT_FILE_NAME = "token-usage.jsonl";
|
|
6991
|
+
var DEFAULT_MODEL = "muse-spark";
|
|
6992
|
+
var PROJECT_LABEL = "Muse";
|
|
6993
|
+
var MIN_TS_SECONDS = 1577836800;
|
|
6994
|
+
var MAX_TS_SECONDS = 3471292800;
|
|
6995
|
+
function getMuseExportPath(env = process.env) {
|
|
6996
|
+
const dir = env.MUSE_USAGE_DIR?.trim() || join32(homedir31(), ".local", "share", "muse");
|
|
6997
|
+
return join32(dir, EXPORT_FILE_NAME);
|
|
6998
|
+
}
|
|
6999
|
+
function tokenCount5(value) {
|
|
7000
|
+
if (typeof value !== "number") return null;
|
|
7001
|
+
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
7002
|
+
}
|
|
7003
|
+
function parseMuseRecord(value) {
|
|
7004
|
+
if (typeof value !== "object" || value === null) return null;
|
|
7005
|
+
const raw = value;
|
|
7006
|
+
const ts = raw.ts;
|
|
7007
|
+
if (typeof ts !== "number" || !Number.isFinite(ts) || ts < MIN_TS_SECONDS || ts >= MAX_TS_SECONDS) {
|
|
7008
|
+
return null;
|
|
7009
|
+
}
|
|
7010
|
+
const inputTokens = tokenCount5(raw.inputTokens);
|
|
7011
|
+
const outputTokens = tokenCount5(raw.outputTokens);
|
|
7012
|
+
const messageId = typeof raw.messageId === "string" ? raw.messageId : "";
|
|
7013
|
+
const sessionId = typeof raw.sessionId === "string" ? raw.sessionId : "";
|
|
7014
|
+
const agentId = typeof raw.agentId === "string" ? raw.agentId : "";
|
|
7015
|
+
if (inputTokens === null || outputTokens === null) return null;
|
|
7016
|
+
if (!messageId || !sessionId || !agentId) return null;
|
|
7017
|
+
const model = typeof raw.model === "string" && raw.model.trim() ? raw.model.trim() : void 0;
|
|
7018
|
+
return {
|
|
7019
|
+
ts,
|
|
7020
|
+
messageId,
|
|
7021
|
+
sessionId,
|
|
7022
|
+
agentId,
|
|
7023
|
+
model,
|
|
7024
|
+
inputTokens,
|
|
7025
|
+
outputTokens
|
|
7026
|
+
};
|
|
7027
|
+
}
|
|
7028
|
+
function normalizeModel(model) {
|
|
7029
|
+
if (!model) return DEFAULT_MODEL;
|
|
7030
|
+
if (model.startsWith("ipnext/avocado-")) return DEFAULT_MODEL;
|
|
7031
|
+
return model;
|
|
7032
|
+
}
|
|
7033
|
+
function museRecordsToEntries(records) {
|
|
7034
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7035
|
+
const entries = [];
|
|
7036
|
+
for (const record of records) {
|
|
7037
|
+
const key = JSON.stringify([record.sessionId, record.messageId]);
|
|
7038
|
+
if (seen.has(key)) continue;
|
|
7039
|
+
seen.add(key);
|
|
7040
|
+
entries.push({
|
|
7041
|
+
sessionId: record.sessionId,
|
|
7042
|
+
source: TOOL_ID22,
|
|
7043
|
+
model: normalizeModel(record.model),
|
|
7044
|
+
project: PROJECT_LABEL,
|
|
7045
|
+
timestamp: new Date(record.ts * 1e3),
|
|
7046
|
+
inputTokens: record.inputTokens,
|
|
7047
|
+
outputTokens: record.outputTokens,
|
|
7048
|
+
reasoningTokens: 0,
|
|
7049
|
+
cachedTokens: 0,
|
|
7050
|
+
cacheCreationTokens: 0
|
|
7051
|
+
});
|
|
7052
|
+
}
|
|
7053
|
+
return entries;
|
|
7054
|
+
}
|
|
7055
|
+
var MuseParser = class {
|
|
7056
|
+
tool;
|
|
7057
|
+
filePath;
|
|
7058
|
+
constructor(options = {}) {
|
|
7059
|
+
this.filePath = options.filePath ?? getMuseExportPath();
|
|
7060
|
+
this.tool = {
|
|
7061
|
+
id: TOOL_ID22,
|
|
7062
|
+
name: TOOL_NAME20,
|
|
7063
|
+
dataDir: dirname10(this.filePath)
|
|
7064
|
+
};
|
|
7065
|
+
}
|
|
7066
|
+
isInstalled() {
|
|
7067
|
+
return existsSync31(this.filePath);
|
|
7068
|
+
}
|
|
7069
|
+
listSourceFiles() {
|
|
7070
|
+
return this.isInstalled() ? [this.filePath] : [];
|
|
7071
|
+
}
|
|
7072
|
+
async parse() {
|
|
7073
|
+
const content = readFileSafe(this.filePath);
|
|
7074
|
+
if (content === null) {
|
|
7075
|
+
return this.isInstalled() ? { buckets: [], sessions: [], incomplete: true } : { buckets: [], sessions: [] };
|
|
7076
|
+
}
|
|
7077
|
+
const records = [];
|
|
7078
|
+
let partial = false;
|
|
7079
|
+
for (const line of content.split("\n")) {
|
|
7080
|
+
const trimmed = line.trim();
|
|
7081
|
+
if (!trimmed) continue;
|
|
7082
|
+
let parsed;
|
|
7083
|
+
try {
|
|
7084
|
+
parsed = JSON.parse(trimmed);
|
|
7085
|
+
} catch {
|
|
7086
|
+
partial = true;
|
|
7087
|
+
continue;
|
|
7088
|
+
}
|
|
7089
|
+
const record = parseMuseRecord(parsed);
|
|
7090
|
+
if (record === null) {
|
|
7091
|
+
partial = true;
|
|
7092
|
+
continue;
|
|
7093
|
+
}
|
|
7094
|
+
records.push(record);
|
|
7095
|
+
}
|
|
7096
|
+
const entries = museRecordsToEntries(records);
|
|
7097
|
+
const events = entries.map((entry) => ({
|
|
7098
|
+
sessionId: entry.sessionId ?? "",
|
|
7099
|
+
source: entry.source,
|
|
7100
|
+
project: entry.project,
|
|
7101
|
+
timestamp: entry.timestamp,
|
|
7102
|
+
role: "assistant"
|
|
7103
|
+
}));
|
|
7104
|
+
const result = {
|
|
7105
|
+
buckets: aggregateToBuckets(entries),
|
|
7106
|
+
sessions: extractSessions(events, entries)
|
|
7107
|
+
};
|
|
7108
|
+
if (partial) result.partial = true;
|
|
7109
|
+
return result;
|
|
7110
|
+
}
|
|
7111
|
+
};
|
|
7112
|
+
registerParser(new MuseParser());
|
|
7113
|
+
|
|
6984
7114
|
// src/cli.ts
|
|
6985
7115
|
import { Command, Option } from "commander";
|
|
6986
7116
|
|
|
@@ -7016,8 +7146,8 @@ function getInsecureApiUrlReason(apiUrl) {
|
|
|
7016
7146
|
|
|
7017
7147
|
// src/infrastructure/config/manager.ts
|
|
7018
7148
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
7019
|
-
import { existsSync as
|
|
7020
|
-
import { join as
|
|
7149
|
+
import { existsSync as existsSync32, readFileSync as readFileSync10, unlinkSync } from "fs";
|
|
7150
|
+
import { join as join34 } from "path";
|
|
7021
7151
|
|
|
7022
7152
|
// src/infrastructure/fs/private-files.ts
|
|
7023
7153
|
import { randomUUID } from "crypto";
|
|
@@ -7062,22 +7192,22 @@ function writePrivateFile(path, content) {
|
|
|
7062
7192
|
}
|
|
7063
7193
|
|
|
7064
7194
|
// src/infrastructure/xdg.ts
|
|
7065
|
-
import { homedir as
|
|
7066
|
-
import { join as
|
|
7195
|
+
import { homedir as homedir32 } from "os";
|
|
7196
|
+
import { join as join33 } from "path";
|
|
7067
7197
|
function getConfigHome() {
|
|
7068
|
-
return process.env.XDG_CONFIG_HOME ||
|
|
7198
|
+
return process.env.XDG_CONFIG_HOME || join33(homedir32(), ".config");
|
|
7069
7199
|
}
|
|
7070
7200
|
function getStateHome() {
|
|
7071
|
-
return process.env.XDG_STATE_HOME ||
|
|
7201
|
+
return process.env.XDG_STATE_HOME || join33(homedir32(), ".local", "state");
|
|
7072
7202
|
}
|
|
7073
7203
|
function getRuntimeDir() {
|
|
7074
7204
|
return process.env.XDG_RUNTIME_DIR || getStateHome();
|
|
7075
7205
|
}
|
|
7076
7206
|
|
|
7077
7207
|
// src/infrastructure/config/manager.ts
|
|
7078
|
-
var CONFIG_DIR =
|
|
7208
|
+
var CONFIG_DIR = join34(getConfigHome(), "tokenarena");
|
|
7079
7209
|
var isDev = process.env.TOKEN_ARENA_DEV === "1";
|
|
7080
|
-
var CONFIG_FILE =
|
|
7210
|
+
var CONFIG_FILE = join34(CONFIG_DIR, isDev ? "config.dev.json" : "config.json");
|
|
7081
7211
|
var DEFAULT_API_URL = "https://token.guji.uno";
|
|
7082
7212
|
var VALID_CONFIG_KEYS = [
|
|
7083
7213
|
"apiKey",
|
|
@@ -7093,7 +7223,7 @@ function getConfigDir() {
|
|
|
7093
7223
|
return CONFIG_DIR;
|
|
7094
7224
|
}
|
|
7095
7225
|
function loadConfig() {
|
|
7096
|
-
if (!
|
|
7226
|
+
if (!existsSync32(CONFIG_FILE)) return null;
|
|
7097
7227
|
restrictToOwner(CONFIG_DIR);
|
|
7098
7228
|
restrictToOwner(CONFIG_FILE);
|
|
7099
7229
|
try {
|
|
@@ -7113,7 +7243,7 @@ function saveConfig(config) {
|
|
|
7113
7243
|
`);
|
|
7114
7244
|
}
|
|
7115
7245
|
function deleteConfig() {
|
|
7116
|
-
if (
|
|
7246
|
+
if (existsSync32(CONFIG_FILE)) {
|
|
7117
7247
|
unlinkSync(CONFIG_FILE);
|
|
7118
7248
|
}
|
|
7119
7249
|
}
|
|
@@ -7989,7 +8119,7 @@ var ApiClient = class {
|
|
|
7989
8119
|
// src/infrastructure/runtime/lock.ts
|
|
7990
8120
|
import {
|
|
7991
8121
|
closeSync,
|
|
7992
|
-
existsSync as
|
|
8122
|
+
existsSync as existsSync33,
|
|
7993
8123
|
openSync,
|
|
7994
8124
|
readFileSync as readFileSync11,
|
|
7995
8125
|
rmSync as rmSync4,
|
|
@@ -7997,22 +8127,22 @@ import {
|
|
|
7997
8127
|
} from "fs";
|
|
7998
8128
|
|
|
7999
8129
|
// src/infrastructure/runtime/paths.ts
|
|
8000
|
-
import { join as
|
|
8130
|
+
import { join as join35 } from "path";
|
|
8001
8131
|
var APP_NAME = "tokenarena";
|
|
8002
8132
|
function getRuntimeDirPath() {
|
|
8003
|
-
return
|
|
8133
|
+
return join35(getRuntimeDir(), APP_NAME);
|
|
8004
8134
|
}
|
|
8005
8135
|
function getStateDir() {
|
|
8006
|
-
return
|
|
8136
|
+
return join35(getStateHome(), APP_NAME);
|
|
8007
8137
|
}
|
|
8008
8138
|
function getSyncLockPath() {
|
|
8009
|
-
return
|
|
8139
|
+
return join35(getRuntimeDirPath(), "sync.lock");
|
|
8010
8140
|
}
|
|
8011
8141
|
function getSyncStatePath() {
|
|
8012
|
-
return
|
|
8142
|
+
return join35(getStateDir(), "status.json");
|
|
8013
8143
|
}
|
|
8014
8144
|
function getUploadManifestPath() {
|
|
8015
|
-
return
|
|
8145
|
+
return join35(getStateDir(), "upload-manifest.json");
|
|
8016
8146
|
}
|
|
8017
8147
|
function ensureAppDirs() {
|
|
8018
8148
|
ensurePrivateDir(getRuntimeDirPath());
|
|
@@ -8030,7 +8160,7 @@ function isProcessAlive(pid) {
|
|
|
8030
8160
|
}
|
|
8031
8161
|
}
|
|
8032
8162
|
function readLockMetadata(lockPath) {
|
|
8033
|
-
if (!
|
|
8163
|
+
if (!existsSync33(lockPath)) {
|
|
8034
8164
|
return null;
|
|
8035
8165
|
}
|
|
8036
8166
|
try {
|
|
@@ -8104,13 +8234,13 @@ function describeExistingSyncLock() {
|
|
|
8104
8234
|
}
|
|
8105
8235
|
|
|
8106
8236
|
// src/infrastructure/runtime/state.ts
|
|
8107
|
-
import { existsSync as
|
|
8237
|
+
import { existsSync as existsSync34, readFileSync as readFileSync12 } from "fs";
|
|
8108
8238
|
function getDefaultState() {
|
|
8109
8239
|
return { status: "idle" };
|
|
8110
8240
|
}
|
|
8111
8241
|
function loadSyncState() {
|
|
8112
8242
|
const path = getSyncStatePath();
|
|
8113
|
-
if (!
|
|
8243
|
+
if (!existsSync34(path)) {
|
|
8114
8244
|
return getDefaultState();
|
|
8115
8245
|
}
|
|
8116
8246
|
try {
|
|
@@ -8167,7 +8297,7 @@ function markSyncFailed(source, error, status) {
|
|
|
8167
8297
|
}
|
|
8168
8298
|
|
|
8169
8299
|
// src/infrastructure/runtime/upload-manifest.ts
|
|
8170
|
-
import { existsSync as
|
|
8300
|
+
import { existsSync as existsSync35, readFileSync as readFileSync13 } from "fs";
|
|
8171
8301
|
function isRecordOfStrings(value) {
|
|
8172
8302
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
8173
8303
|
return false;
|
|
@@ -8183,7 +8313,7 @@ function isUploadManifest(value) {
|
|
|
8183
8313
|
}
|
|
8184
8314
|
function loadUploadManifest() {
|
|
8185
8315
|
const path = getUploadManifestPath();
|
|
8186
|
-
if (!
|
|
8316
|
+
if (!existsSync35(path)) {
|
|
8187
8317
|
return null;
|
|
8188
8318
|
}
|
|
8189
8319
|
try {
|
|
@@ -8215,17 +8345,17 @@ function saveUploadManifest(manifest) {
|
|
|
8215
8345
|
import { createHash as createHash7 } from "crypto";
|
|
8216
8346
|
import { readFileSync as readFileSync14, statSync as statSync9 } from "fs";
|
|
8217
8347
|
import { hostname as hostname6 } from "os";
|
|
8218
|
-
import { join as
|
|
8348
|
+
import { join as join37 } from "path";
|
|
8219
8349
|
|
|
8220
8350
|
// src/infrastructure/runtime/cli-version.ts
|
|
8221
|
-
import { dirname as
|
|
8351
|
+
import { dirname as dirname11, join as join36 } from "path";
|
|
8222
8352
|
import { fileURLToPath } from "url";
|
|
8223
8353
|
var FALLBACK_VERSION = "0.0.0";
|
|
8224
8354
|
var versionCache = /* @__PURE__ */ new Map();
|
|
8225
8355
|
function readPackageVersion(startDir) {
|
|
8226
8356
|
let dir = startDir;
|
|
8227
8357
|
while (true) {
|
|
8228
|
-
const contents = readFileSafe(
|
|
8358
|
+
const contents = readFileSafe(join36(dir, "package.json"));
|
|
8229
8359
|
if (contents !== null) {
|
|
8230
8360
|
try {
|
|
8231
8361
|
const { version } = JSON.parse(contents);
|
|
@@ -8234,7 +8364,7 @@ function readPackageVersion(startDir) {
|
|
|
8234
8364
|
return void 0;
|
|
8235
8365
|
}
|
|
8236
8366
|
}
|
|
8237
|
-
const parent =
|
|
8367
|
+
const parent = dirname11(dir);
|
|
8238
8368
|
if (parent === dir) {
|
|
8239
8369
|
return void 0;
|
|
8240
8370
|
}
|
|
@@ -8242,7 +8372,7 @@ function readPackageVersion(startDir) {
|
|
|
8242
8372
|
}
|
|
8243
8373
|
}
|
|
8244
8374
|
function getCliVersion(metaUrl = import.meta.url) {
|
|
8245
|
-
const startDir =
|
|
8375
|
+
const startDir = dirname11(fileURLToPath(metaUrl));
|
|
8246
8376
|
const cached = versionCache.get(startDir);
|
|
8247
8377
|
if (cached !== void 0) {
|
|
8248
8378
|
return cached;
|
|
@@ -8256,10 +8386,10 @@ function getCliVersion(metaUrl = import.meta.url) {
|
|
|
8256
8386
|
var CACHE_FORMAT_VERSION = 1;
|
|
8257
8387
|
var SETTLE_MS = 5e3;
|
|
8258
8388
|
function getParseCacheDir() {
|
|
8259
|
-
return
|
|
8389
|
+
return join37(getStateDir(), "parse-cache");
|
|
8260
8390
|
}
|
|
8261
8391
|
function getParseCachePath(toolId) {
|
|
8262
|
-
return
|
|
8392
|
+
return join37(getParseCacheDir(), `${toolId}.json`);
|
|
8263
8393
|
}
|
|
8264
8394
|
function computeScanFingerprint(files, now = Date.now()) {
|
|
8265
8395
|
const hash = createHash7("sha256");
|
|
@@ -8942,18 +9072,18 @@ View your dashboard at: ${apiUrl}/usage`);
|
|
|
8942
9072
|
|
|
8943
9073
|
// src/commands/init.ts
|
|
8944
9074
|
import { execFileSync as execFileSync8, spawn } from "child_process";
|
|
8945
|
-
import { existsSync as
|
|
9075
|
+
import { existsSync as existsSync38 } from "fs";
|
|
8946
9076
|
import { appendFile, mkdir, readFile } from "fs/promises";
|
|
8947
|
-
import { homedir as
|
|
8948
|
-
import { dirname as
|
|
9077
|
+
import { homedir as homedir35, platform as platform5 } from "os";
|
|
9078
|
+
import { dirname as dirname12, join as join38, posix as posix3, win32 as win322 } from "path";
|
|
8949
9079
|
|
|
8950
9080
|
// src/infrastructure/service/index.ts
|
|
8951
9081
|
import { platform as platform4 } from "os";
|
|
8952
9082
|
|
|
8953
9083
|
// src/infrastructure/service/linux-systemd.ts
|
|
8954
9084
|
import { execFileSync as execFileSync6 } from "child_process";
|
|
8955
|
-
import { existsSync as
|
|
8956
|
-
import { homedir as
|
|
9085
|
+
import { existsSync as existsSync36, mkdirSync as mkdirSync2, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
9086
|
+
import { homedir as homedir33, platform as platform2 } from "os";
|
|
8957
9087
|
import { posix } from "path";
|
|
8958
9088
|
|
|
8959
9089
|
// src/infrastructure/service/utils.ts
|
|
@@ -9015,10 +9145,10 @@ function escapeXml(value) {
|
|
|
9015
9145
|
|
|
9016
9146
|
// src/infrastructure/service/linux-systemd.ts
|
|
9017
9147
|
var SYSTEMD_SERVICE_NAME = "tokenarena";
|
|
9018
|
-
function getLinuxSystemdServiceDir(homePath =
|
|
9148
|
+
function getLinuxSystemdServiceDir(homePath = homedir33()) {
|
|
9019
9149
|
return posix.join(homePath, ".config", "systemd", "user");
|
|
9020
9150
|
}
|
|
9021
|
-
function getLinuxSystemdServiceFile(homePath =
|
|
9151
|
+
function getLinuxSystemdServiceFile(homePath = homedir33()) {
|
|
9022
9152
|
return posix.join(
|
|
9023
9153
|
getLinuxSystemdServiceDir(homePath),
|
|
9024
9154
|
`${SYSTEMD_SERVICE_NAME}.service`
|
|
@@ -9075,7 +9205,7 @@ function ensureSystemdAvailable() {
|
|
|
9075
9205
|
}
|
|
9076
9206
|
function createLinuxSystemdServiceBackend() {
|
|
9077
9207
|
function isInstalled() {
|
|
9078
|
-
return
|
|
9208
|
+
return existsSync36(getLinuxSystemdServiceFile());
|
|
9079
9209
|
}
|
|
9080
9210
|
async function setup(skipPrompt = false) {
|
|
9081
9211
|
if (!ensureSystemdAvailable()) {
|
|
@@ -9200,7 +9330,7 @@ function createLinuxSystemdServiceBackend() {
|
|
|
9200
9330
|
}
|
|
9201
9331
|
async function uninstall(skipPrompt = false) {
|
|
9202
9332
|
const serviceFile = getLinuxSystemdServiceFile();
|
|
9203
|
-
if (!
|
|
9333
|
+
if (!existsSync36(serviceFile)) {
|
|
9204
9334
|
logger.info(formatBullet("\u670D\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728\u3002", "warning"));
|
|
9205
9335
|
return;
|
|
9206
9336
|
}
|
|
@@ -9261,17 +9391,17 @@ function createLinuxSystemdServiceBackend() {
|
|
|
9261
9391
|
|
|
9262
9392
|
// src/infrastructure/service/macos-launchd.ts
|
|
9263
9393
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
9264
|
-
import { existsSync as
|
|
9265
|
-
import { homedir as
|
|
9394
|
+
import { existsSync as existsSync37, mkdirSync as mkdirSync3, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
9395
|
+
import { homedir as homedir34, platform as platform3 } from "os";
|
|
9266
9396
|
import { posix as posix2 } from "path";
|
|
9267
9397
|
var MACOS_LAUNCHD_LABEL = "com.guji.tokenarena";
|
|
9268
9398
|
function getCurrentUid() {
|
|
9269
9399
|
return typeof process.getuid === "function" ? process.getuid() : null;
|
|
9270
9400
|
}
|
|
9271
|
-
function getMacosLaunchAgentDir(homePath =
|
|
9401
|
+
function getMacosLaunchAgentDir(homePath = homedir34()) {
|
|
9272
9402
|
return posix2.join(homePath, "Library", "LaunchAgents");
|
|
9273
9403
|
}
|
|
9274
|
-
function getMacosLaunchAgentFile(homePath =
|
|
9404
|
+
function getMacosLaunchAgentFile(homePath = homedir34()) {
|
|
9275
9405
|
return posix2.join(
|
|
9276
9406
|
getMacosLaunchAgentDir(homePath),
|
|
9277
9407
|
`${MACOS_LAUNCHD_LABEL}.plist`
|
|
@@ -9398,7 +9528,7 @@ function writeLaunchAgentPlist() {
|
|
|
9398
9528
|
label: MACOS_LAUNCHD_LABEL,
|
|
9399
9529
|
programArguments: [command.execPath, ...command.args],
|
|
9400
9530
|
environment: getManagedServiceEnvironment(),
|
|
9401
|
-
workingDirectory:
|
|
9531
|
+
workingDirectory: homedir34(),
|
|
9402
9532
|
standardOutPath: stdoutPath,
|
|
9403
9533
|
standardErrorPath: stderrPath
|
|
9404
9534
|
});
|
|
@@ -9423,7 +9553,7 @@ function bootstrapLaunchAgent() {
|
|
|
9423
9553
|
}
|
|
9424
9554
|
function createMacosLaunchdServiceBackend() {
|
|
9425
9555
|
function isInstalled() {
|
|
9426
|
-
return
|
|
9556
|
+
return existsSync37(getMacosLaunchAgentFile());
|
|
9427
9557
|
}
|
|
9428
9558
|
async function setup(skipPrompt = false) {
|
|
9429
9559
|
if (!ensureLaunchctlAvailable()) {
|
|
@@ -9564,7 +9694,7 @@ function createMacosLaunchdServiceBackend() {
|
|
|
9564
9694
|
}
|
|
9565
9695
|
async function uninstall(skipPrompt = false) {
|
|
9566
9696
|
const plistFile = getMacosLaunchAgentFile();
|
|
9567
|
-
if (!
|
|
9697
|
+
if (!existsSync37(plistFile)) {
|
|
9568
9698
|
logger.info(formatBullet("\u670D\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728\u3002", "warning"));
|
|
9569
9699
|
return;
|
|
9570
9700
|
}
|
|
@@ -9675,7 +9805,7 @@ function resolvePowerShellProfilePath() {
|
|
|
9675
9805
|
const systemRoot = process.env.SYSTEMROOT || "C:\\Windows";
|
|
9676
9806
|
const candidates = [
|
|
9677
9807
|
resolveCommandPath("pwsh.exe"),
|
|
9678
|
-
|
|
9808
|
+
join38(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
|
|
9679
9809
|
].filter((command) => command !== null);
|
|
9680
9810
|
for (const command of candidates) {
|
|
9681
9811
|
try {
|
|
@@ -9704,8 +9834,8 @@ function resolvePowerShellProfilePath() {
|
|
|
9704
9834
|
function resolveShellAliasSetup(options = {}) {
|
|
9705
9835
|
const currentPlatform = options.currentPlatform ?? platform5();
|
|
9706
9836
|
const env = options.env ?? process.env;
|
|
9707
|
-
const homeDir = options.homeDir ??
|
|
9708
|
-
const pathExists = options.exists ??
|
|
9837
|
+
const homeDir = options.homeDir ?? homedir35();
|
|
9838
|
+
const pathExists = options.exists ?? existsSync38;
|
|
9709
9839
|
const shellFromEnv = env.SHELL ? basenameLikeShell(env.SHELL).toLowerCase() : "";
|
|
9710
9840
|
const shellName = shellFromEnv || (currentPlatform === "win32" ? "powershell" : "");
|
|
9711
9841
|
const aliasName = "ta";
|
|
@@ -9905,9 +10035,9 @@ async function setupShellAlias() {
|
|
|
9905
10035
|
return;
|
|
9906
10036
|
}
|
|
9907
10037
|
try {
|
|
9908
|
-
await mkdir(
|
|
10038
|
+
await mkdir(dirname12(setup.configFile), { recursive: true });
|
|
9909
10039
|
let existingContent = "";
|
|
9910
|
-
if (
|
|
10040
|
+
if (existsSync38(setup.configFile)) {
|
|
9911
10041
|
existingContent = await readFile(setup.configFile, "utf-8");
|
|
9912
10042
|
}
|
|
9913
10043
|
const normalizedContent = existingContent.toLowerCase();
|
|
@@ -10568,8 +10698,8 @@ async function runSyncCommand(opts = {}) {
|
|
|
10568
10698
|
}
|
|
10569
10699
|
|
|
10570
10700
|
// src/commands/uninstall.ts
|
|
10571
|
-
import { existsSync as
|
|
10572
|
-
import { homedir as
|
|
10701
|
+
import { existsSync as existsSync39, readFileSync as readFileSync15, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "fs";
|
|
10702
|
+
import { homedir as homedir36, platform as platform6 } from "os";
|
|
10573
10703
|
function removeShellAlias() {
|
|
10574
10704
|
const shell = process.env.SHELL;
|
|
10575
10705
|
if (!shell) return;
|
|
@@ -10578,22 +10708,22 @@ function removeShellAlias() {
|
|
|
10578
10708
|
let configFile;
|
|
10579
10709
|
switch (shellName) {
|
|
10580
10710
|
case "zsh":
|
|
10581
|
-
configFile = `${
|
|
10711
|
+
configFile = `${homedir36()}/.zshrc`;
|
|
10582
10712
|
break;
|
|
10583
10713
|
case "bash":
|
|
10584
|
-
if (platform6() === "darwin" &&
|
|
10585
|
-
configFile = `${
|
|
10714
|
+
if (platform6() === "darwin" && existsSync39(`${homedir36()}/.bash_profile`)) {
|
|
10715
|
+
configFile = `${homedir36()}/.bash_profile`;
|
|
10586
10716
|
} else {
|
|
10587
|
-
configFile = `${
|
|
10717
|
+
configFile = `${homedir36()}/.bashrc`;
|
|
10588
10718
|
}
|
|
10589
10719
|
break;
|
|
10590
10720
|
case "fish":
|
|
10591
|
-
configFile = `${
|
|
10721
|
+
configFile = `${homedir36()}/.config/fish/config.fish`;
|
|
10592
10722
|
break;
|
|
10593
10723
|
default:
|
|
10594
10724
|
return;
|
|
10595
10725
|
}
|
|
10596
|
-
if (!
|
|
10726
|
+
if (!existsSync39(configFile)) return;
|
|
10597
10727
|
try {
|
|
10598
10728
|
let content = readFileSync15(configFile, "utf-8");
|
|
10599
10729
|
const aliasPatterns = [
|
|
@@ -10632,7 +10762,7 @@ async function runUninstall() {
|
|
|
10632
10762
|
const runtimeDir = getRuntimeDirPath();
|
|
10633
10763
|
const serviceBackend = getServiceBackend();
|
|
10634
10764
|
const hasInstalledService = serviceBackend?.isInstalled() ?? false;
|
|
10635
|
-
const hasLocalArtifacts =
|
|
10765
|
+
const hasLocalArtifacts = existsSync39(configPath) || existsSync39(configDir) || existsSync39(stateDir) || existsSync39(runtimeDir) || hasInstalledService;
|
|
10636
10766
|
if (!hasLocalArtifacts) {
|
|
10637
10767
|
logger.info(formatHeader("\u5378\u8F7D TokenArena"));
|
|
10638
10768
|
logger.info(formatBullet("\u672A\u53D1\u73B0\u672C\u5730\u914D\u7F6E\uFF0C\u65E0\u9700\u5378\u8F7D\u3002"));
|
|
@@ -10676,22 +10806,22 @@ async function runUninstall() {
|
|
|
10676
10806
|
}
|
|
10677
10807
|
}
|
|
10678
10808
|
logger.info(formatSection("\u6267\u884C\u7ED3\u679C"));
|
|
10679
|
-
if (
|
|
10809
|
+
if (existsSync39(configPath)) {
|
|
10680
10810
|
deleteConfig();
|
|
10681
10811
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u914D\u7F6E\u6587\u4EF6\u3002", "success"));
|
|
10682
10812
|
}
|
|
10683
|
-
if (
|
|
10813
|
+
if (existsSync39(configDir)) {
|
|
10684
10814
|
try {
|
|
10685
10815
|
rmSync7(configDir, { recursive: false, force: true });
|
|
10686
10816
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u914D\u7F6E\u76EE\u5F55\u3002", "success"));
|
|
10687
10817
|
} catch {
|
|
10688
10818
|
}
|
|
10689
10819
|
}
|
|
10690
|
-
if (
|
|
10820
|
+
if (existsSync39(stateDir)) {
|
|
10691
10821
|
rmSync7(stateDir, { recursive: true, force: true });
|
|
10692
10822
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u72B6\u6001\u6570\u636E\u3002", "success"));
|
|
10693
10823
|
}
|
|
10694
|
-
if (
|
|
10824
|
+
if (existsSync39(runtimeDir)) {
|
|
10695
10825
|
rmSync7(runtimeDir, { recursive: true, force: true });
|
|
10696
10826
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u8FD0\u884C\u65F6\u6570\u636E\u3002", "success"));
|
|
10697
10827
|
}
|
|
@@ -10925,7 +11055,7 @@ function createCli() {
|
|
|
10925
11055
|
}
|
|
10926
11056
|
|
|
10927
11057
|
// src/infrastructure/runtime/main-module.ts
|
|
10928
|
-
import { existsSync as
|
|
11058
|
+
import { existsSync as existsSync40, realpathSync as realpathSync2 } from "fs";
|
|
10929
11059
|
import { resolve as resolve4 } from "path";
|
|
10930
11060
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
10931
11061
|
function isMainModule(metaUrl, argvEntry = process.argv[1]) {
|
|
@@ -10936,7 +11066,7 @@ function isMainModule(metaUrl, argvEntry = process.argv[1]) {
|
|
|
10936
11066
|
try {
|
|
10937
11067
|
return realpathSync2(argvEntry) === realpathSync2(currentModulePath);
|
|
10938
11068
|
} catch {
|
|
10939
|
-
if (!
|
|
11069
|
+
if (!existsSync40(argvEntry)) {
|
|
10940
11070
|
return false;
|
|
10941
11071
|
}
|
|
10942
11072
|
return resolve4(argvEntry) === resolve4(currentModulePath);
|