@yishiguji/tokenarena 0.10.0 → 0.11.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 +207 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4713,37 +4713,185 @@ var GrokBuildParser = class {
|
|
|
4713
4713
|
};
|
|
4714
4714
|
registerParser(new GrokBuildParser());
|
|
4715
4715
|
|
|
4716
|
+
// src/parsers/atomcode.ts
|
|
4717
|
+
import { existsSync as existsSync24 } from "fs";
|
|
4718
|
+
import { homedir as homedir25 } from "os";
|
|
4719
|
+
import { basename as basename11, join as join26 } from "path";
|
|
4720
|
+
var TOOL_ID17 = "atomcode";
|
|
4721
|
+
var TOOL_NAME17 = "AtomCode";
|
|
4722
|
+
var DEFAULT_SESSIONS_DIR6 = join26(homedir25(), ".atomcode", "sessions");
|
|
4723
|
+
function getAtomCodeSessionsDirs(env = process.env) {
|
|
4724
|
+
const dirs = [
|
|
4725
|
+
env.TOKEN_ARENA_ATOMCODE_DIR,
|
|
4726
|
+
env.ATOMCODE_HOME ? join26(env.ATOMCODE_HOME, "sessions") : void 0,
|
|
4727
|
+
DEFAULT_SESSIONS_DIR6
|
|
4728
|
+
].filter((value) => Boolean(value));
|
|
4729
|
+
return Array.from(new Set(dirs));
|
|
4730
|
+
}
|
|
4731
|
+
function toNonNegativeNumber3(value) {
|
|
4732
|
+
const numberValue = Number(value);
|
|
4733
|
+
return Number.isFinite(numberValue) && numberValue >= 0 ? numberValue : 0;
|
|
4734
|
+
}
|
|
4735
|
+
function parseTimestamp3(value) {
|
|
4736
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
4737
|
+
const timestamp = new Date(value);
|
|
4738
|
+
return Number.isNaN(timestamp.getTime()) ? null : timestamp;
|
|
4739
|
+
}
|
|
4740
|
+
if (typeof value === "string" && value.trim()) {
|
|
4741
|
+
const asNumber = Number(value);
|
|
4742
|
+
if (Number.isFinite(asNumber)) {
|
|
4743
|
+
const timestamp2 = new Date(asNumber);
|
|
4744
|
+
if (!Number.isNaN(timestamp2.getTime())) {
|
|
4745
|
+
return timestamp2;
|
|
4746
|
+
}
|
|
4747
|
+
}
|
|
4748
|
+
const timestamp = new Date(value);
|
|
4749
|
+
return Number.isNaN(timestamp.getTime()) ? null : timestamp;
|
|
4750
|
+
}
|
|
4751
|
+
return null;
|
|
4752
|
+
}
|
|
4753
|
+
function parseMeta(content) {
|
|
4754
|
+
if (!content) return null;
|
|
4755
|
+
try {
|
|
4756
|
+
const parsed = JSON.parse(content);
|
|
4757
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
4758
|
+
} catch {
|
|
4759
|
+
return null;
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
function getMetaModel(meta) {
|
|
4763
|
+
for (const turn of meta?.turn_stats ?? []) {
|
|
4764
|
+
for (const usage of turn.model_usage ?? []) {
|
|
4765
|
+
if (typeof usage.model_id === "string" && usage.model_id) {
|
|
4766
|
+
return usage.model_id;
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
return "unknown";
|
|
4771
|
+
}
|
|
4772
|
+
function getMetaProject(meta) {
|
|
4773
|
+
if (typeof meta?.working_dir === "string" && meta.working_dir) {
|
|
4774
|
+
return basename11(meta.working_dir) || "unknown";
|
|
4775
|
+
}
|
|
4776
|
+
return "unknown";
|
|
4777
|
+
}
|
|
4778
|
+
var AtomCodeParser = class {
|
|
4779
|
+
tool;
|
|
4780
|
+
sessionsDirs;
|
|
4781
|
+
constructor(sessionsDir) {
|
|
4782
|
+
this.sessionsDirs = sessionsDir ? [sessionsDir] : getAtomCodeSessionsDirs();
|
|
4783
|
+
this.tool = {
|
|
4784
|
+
id: TOOL_ID17,
|
|
4785
|
+
name: TOOL_NAME17,
|
|
4786
|
+
dataDir: this.sessionsDirs[0] ?? DEFAULT_SESSIONS_DIR6
|
|
4787
|
+
};
|
|
4788
|
+
}
|
|
4789
|
+
async parse() {
|
|
4790
|
+
const entries = [];
|
|
4791
|
+
const sessionEvents = [];
|
|
4792
|
+
const seenEntryKeys = /* @__PURE__ */ new Set();
|
|
4793
|
+
for (const sessionsDir of this.sessionsDirs) {
|
|
4794
|
+
for (const filePath of findJsonlFiles(sessionsDir)) {
|
|
4795
|
+
const content = readFileSafe(filePath);
|
|
4796
|
+
if (!content) continue;
|
|
4797
|
+
const rows = parseJsonl(content);
|
|
4798
|
+
if (rows.length === 0) continue;
|
|
4799
|
+
const fallbackSessionId = extractSessionId(filePath);
|
|
4800
|
+
const meta = parseMeta(
|
|
4801
|
+
readFileSafe(filePath.replace(/\.jsonl$/, ".meta"))
|
|
4802
|
+
);
|
|
4803
|
+
const project = getMetaProject(meta);
|
|
4804
|
+
const model = getMetaModel(meta);
|
|
4805
|
+
for (const row of rows) {
|
|
4806
|
+
const sessionId = typeof row.session_id === "string" && row.session_id ? row.session_id : fallbackSessionId;
|
|
4807
|
+
const timestamp = parseTimestamp3(row.ts);
|
|
4808
|
+
if (!timestamp) continue;
|
|
4809
|
+
if (row.user !== void 0 || row.assistant !== void 0) {
|
|
4810
|
+
sessionEvents.push({
|
|
4811
|
+
sessionId,
|
|
4812
|
+
source: TOOL_ID17,
|
|
4813
|
+
project,
|
|
4814
|
+
timestamp,
|
|
4815
|
+
role: row.user !== void 0 ? "user" : "assistant"
|
|
4816
|
+
});
|
|
4817
|
+
}
|
|
4818
|
+
const usage = row.usage;
|
|
4819
|
+
if (!usage) continue;
|
|
4820
|
+
const prompt = toNonNegativeNumber3(usage.prompt);
|
|
4821
|
+
const completion = toNonNegativeNumber3(usage.completion);
|
|
4822
|
+
const cached = toNonNegativeNumber3(usage.cached);
|
|
4823
|
+
const inputTokens = Math.max(0, prompt - cached);
|
|
4824
|
+
if (inputTokens + completion + cached === 0) {
|
|
4825
|
+
continue;
|
|
4826
|
+
}
|
|
4827
|
+
const entryKey = [
|
|
4828
|
+
sessionId,
|
|
4829
|
+
timestamp.toISOString(),
|
|
4830
|
+
model,
|
|
4831
|
+
inputTokens,
|
|
4832
|
+
completion,
|
|
4833
|
+
cached
|
|
4834
|
+
].join("|");
|
|
4835
|
+
if (seenEntryKeys.has(entryKey)) {
|
|
4836
|
+
continue;
|
|
4837
|
+
}
|
|
4838
|
+
seenEntryKeys.add(entryKey);
|
|
4839
|
+
entries.push({
|
|
4840
|
+
sessionId,
|
|
4841
|
+
source: TOOL_ID17,
|
|
4842
|
+
model,
|
|
4843
|
+
project,
|
|
4844
|
+
timestamp,
|
|
4845
|
+
inputTokens,
|
|
4846
|
+
outputTokens: completion,
|
|
4847
|
+
reasoningTokens: 0,
|
|
4848
|
+
cachedTokens: cached
|
|
4849
|
+
});
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
return {
|
|
4854
|
+
buckets: aggregateToBuckets(entries),
|
|
4855
|
+
sessions: extractSessions(sessionEvents, entries)
|
|
4856
|
+
};
|
|
4857
|
+
}
|
|
4858
|
+
isInstalled() {
|
|
4859
|
+
return this.sessionsDirs.some((dir) => existsSync24(dir));
|
|
4860
|
+
}
|
|
4861
|
+
};
|
|
4862
|
+
registerParser(new AtomCodeParser());
|
|
4863
|
+
|
|
4716
4864
|
// src/cli.ts
|
|
4717
4865
|
import { Command, Option } from "commander";
|
|
4718
4866
|
|
|
4719
4867
|
// src/infrastructure/config/manager.ts
|
|
4720
4868
|
import { randomUUID } from "crypto";
|
|
4721
4869
|
import {
|
|
4722
|
-
existsSync as
|
|
4870
|
+
existsSync as existsSync25,
|
|
4723
4871
|
mkdirSync,
|
|
4724
4872
|
readFileSync as readFileSync9,
|
|
4725
4873
|
unlinkSync,
|
|
4726
4874
|
writeFileSync
|
|
4727
4875
|
} from "fs";
|
|
4728
|
-
import { join as
|
|
4876
|
+
import { join as join28 } from "path";
|
|
4729
4877
|
|
|
4730
4878
|
// src/infrastructure/xdg.ts
|
|
4731
|
-
import { homedir as
|
|
4732
|
-
import { join as
|
|
4879
|
+
import { homedir as homedir26 } from "os";
|
|
4880
|
+
import { join as join27 } from "path";
|
|
4733
4881
|
function getConfigHome() {
|
|
4734
|
-
return process.env.XDG_CONFIG_HOME ||
|
|
4882
|
+
return process.env.XDG_CONFIG_HOME || join27(homedir26(), ".config");
|
|
4735
4883
|
}
|
|
4736
4884
|
function getStateHome() {
|
|
4737
|
-
return process.env.XDG_STATE_HOME ||
|
|
4885
|
+
return process.env.XDG_STATE_HOME || join27(homedir26(), ".local", "state");
|
|
4738
4886
|
}
|
|
4739
4887
|
function getRuntimeDir() {
|
|
4740
4888
|
return process.env.XDG_RUNTIME_DIR || getStateHome();
|
|
4741
4889
|
}
|
|
4742
4890
|
|
|
4743
4891
|
// src/infrastructure/config/manager.ts
|
|
4744
|
-
var CONFIG_DIR =
|
|
4892
|
+
var CONFIG_DIR = join28(getConfigHome(), "tokenarena");
|
|
4745
4893
|
var isDev = process.env.TOKEN_ARENA_DEV === "1";
|
|
4746
|
-
var CONFIG_FILE =
|
|
4894
|
+
var CONFIG_FILE = join28(CONFIG_DIR, isDev ? "config.dev.json" : "config.json");
|
|
4747
4895
|
var DEFAULT_API_URL = "https://token.guji.uno";
|
|
4748
4896
|
var VALID_CONFIG_KEYS = [
|
|
4749
4897
|
"apiKey",
|
|
@@ -4759,7 +4907,7 @@ function getConfigDir() {
|
|
|
4759
4907
|
return CONFIG_DIR;
|
|
4760
4908
|
}
|
|
4761
4909
|
function loadConfig() {
|
|
4762
|
-
if (!
|
|
4910
|
+
if (!existsSync25(CONFIG_FILE)) return null;
|
|
4763
4911
|
try {
|
|
4764
4912
|
const raw = readFileSync9(CONFIG_FILE, "utf-8");
|
|
4765
4913
|
const config = JSON.parse(raw);
|
|
@@ -4777,7 +4925,7 @@ function saveConfig(config) {
|
|
|
4777
4925
|
`, "utf-8");
|
|
4778
4926
|
}
|
|
4779
4927
|
function deleteConfig() {
|
|
4780
|
-
if (
|
|
4928
|
+
if (existsSync25(CONFIG_FILE)) {
|
|
4781
4929
|
unlinkSync(CONFIG_FILE);
|
|
4782
4930
|
}
|
|
4783
4931
|
}
|
|
@@ -5639,7 +5787,7 @@ var ApiClient = class {
|
|
|
5639
5787
|
// src/infrastructure/runtime/lock.ts
|
|
5640
5788
|
import {
|
|
5641
5789
|
closeSync,
|
|
5642
|
-
existsSync as
|
|
5790
|
+
existsSync as existsSync26,
|
|
5643
5791
|
openSync,
|
|
5644
5792
|
readFileSync as readFileSync10,
|
|
5645
5793
|
rmSync as rmSync3,
|
|
@@ -5648,22 +5796,22 @@ import {
|
|
|
5648
5796
|
|
|
5649
5797
|
// src/infrastructure/runtime/paths.ts
|
|
5650
5798
|
import { mkdirSync as mkdirSync2 } from "fs";
|
|
5651
|
-
import { join as
|
|
5799
|
+
import { join as join29 } from "path";
|
|
5652
5800
|
var APP_NAME = "tokenarena";
|
|
5653
5801
|
function getRuntimeDirPath() {
|
|
5654
|
-
return
|
|
5802
|
+
return join29(getRuntimeDir(), APP_NAME);
|
|
5655
5803
|
}
|
|
5656
5804
|
function getStateDir() {
|
|
5657
|
-
return
|
|
5805
|
+
return join29(getStateHome(), APP_NAME);
|
|
5658
5806
|
}
|
|
5659
5807
|
function getSyncLockPath() {
|
|
5660
|
-
return
|
|
5808
|
+
return join29(getRuntimeDirPath(), "sync.lock");
|
|
5661
5809
|
}
|
|
5662
5810
|
function getSyncStatePath() {
|
|
5663
|
-
return
|
|
5811
|
+
return join29(getStateDir(), "status.json");
|
|
5664
5812
|
}
|
|
5665
5813
|
function getUploadManifestPath() {
|
|
5666
|
-
return
|
|
5814
|
+
return join29(getStateDir(), "upload-manifest.json");
|
|
5667
5815
|
}
|
|
5668
5816
|
function ensureAppDirs() {
|
|
5669
5817
|
mkdirSync2(getRuntimeDirPath(), { recursive: true });
|
|
@@ -5681,7 +5829,7 @@ function isProcessAlive(pid) {
|
|
|
5681
5829
|
}
|
|
5682
5830
|
}
|
|
5683
5831
|
function readLockMetadata(lockPath) {
|
|
5684
|
-
if (!
|
|
5832
|
+
if (!existsSync26(lockPath)) {
|
|
5685
5833
|
return null;
|
|
5686
5834
|
}
|
|
5687
5835
|
try {
|
|
@@ -5755,13 +5903,13 @@ function describeExistingSyncLock() {
|
|
|
5755
5903
|
}
|
|
5756
5904
|
|
|
5757
5905
|
// src/infrastructure/runtime/state.ts
|
|
5758
|
-
import { existsSync as
|
|
5906
|
+
import { existsSync as existsSync27, readFileSync as readFileSync11, writeFileSync as writeFileSync3 } from "fs";
|
|
5759
5907
|
function getDefaultState() {
|
|
5760
5908
|
return { status: "idle" };
|
|
5761
5909
|
}
|
|
5762
5910
|
function loadSyncState() {
|
|
5763
5911
|
const path = getSyncStatePath();
|
|
5764
|
-
if (!
|
|
5912
|
+
if (!existsSync27(path)) {
|
|
5765
5913
|
return getDefaultState();
|
|
5766
5914
|
}
|
|
5767
5915
|
try {
|
|
@@ -5822,7 +5970,7 @@ function markSyncFailed(source, error, status) {
|
|
|
5822
5970
|
}
|
|
5823
5971
|
|
|
5824
5972
|
// src/infrastructure/runtime/upload-manifest.ts
|
|
5825
|
-
import { existsSync as
|
|
5973
|
+
import { existsSync as existsSync28, readFileSync as readFileSync12, writeFileSync as writeFileSync4 } from "fs";
|
|
5826
5974
|
function isRecordOfStrings(value) {
|
|
5827
5975
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5828
5976
|
return false;
|
|
@@ -5838,7 +5986,7 @@ function isUploadManifest(value) {
|
|
|
5838
5986
|
}
|
|
5839
5987
|
function loadUploadManifest() {
|
|
5840
5988
|
const path = getUploadManifestPath();
|
|
5841
|
-
if (!
|
|
5989
|
+
if (!existsSync28(path)) {
|
|
5842
5990
|
return null;
|
|
5843
5991
|
}
|
|
5844
5992
|
try {
|
|
@@ -6378,18 +6526,18 @@ View your dashboard at: ${apiUrl}/usage`);
|
|
|
6378
6526
|
|
|
6379
6527
|
// src/commands/init.ts
|
|
6380
6528
|
import { execFileSync as execFileSync7, spawn } from "child_process";
|
|
6381
|
-
import { existsSync as
|
|
6529
|
+
import { existsSync as existsSync31 } from "fs";
|
|
6382
6530
|
import { appendFile, mkdir, readFile } from "fs/promises";
|
|
6383
|
-
import { homedir as
|
|
6384
|
-
import { dirname as dirname6, join as
|
|
6531
|
+
import { homedir as homedir29, platform as platform5 } from "os";
|
|
6532
|
+
import { dirname as dirname6, join as join30, posix as posix3, win32 } from "path";
|
|
6385
6533
|
|
|
6386
6534
|
// src/infrastructure/service/index.ts
|
|
6387
6535
|
import { platform as platform4 } from "os";
|
|
6388
6536
|
|
|
6389
6537
|
// src/infrastructure/service/linux-systemd.ts
|
|
6390
6538
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
6391
|
-
import { existsSync as
|
|
6392
|
-
import { homedir as
|
|
6539
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync3, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
6540
|
+
import { homedir as homedir27, platform as platform2 } from "os";
|
|
6393
6541
|
import { posix } from "path";
|
|
6394
6542
|
|
|
6395
6543
|
// src/utils/command.ts
|
|
@@ -6458,10 +6606,10 @@ function escapeXml(value) {
|
|
|
6458
6606
|
|
|
6459
6607
|
// src/infrastructure/service/linux-systemd.ts
|
|
6460
6608
|
var SYSTEMD_SERVICE_NAME = "tokenarena";
|
|
6461
|
-
function getLinuxSystemdServiceDir(homePath =
|
|
6609
|
+
function getLinuxSystemdServiceDir(homePath = homedir27()) {
|
|
6462
6610
|
return posix.join(homePath, ".config", "systemd", "user");
|
|
6463
6611
|
}
|
|
6464
|
-
function getLinuxSystemdServiceFile(homePath =
|
|
6612
|
+
function getLinuxSystemdServiceFile(homePath = homedir27()) {
|
|
6465
6613
|
return posix.join(
|
|
6466
6614
|
getLinuxSystemdServiceDir(homePath),
|
|
6467
6615
|
`${SYSTEMD_SERVICE_NAME}.service`
|
|
@@ -6518,7 +6666,7 @@ function ensureSystemdAvailable() {
|
|
|
6518
6666
|
}
|
|
6519
6667
|
function createLinuxSystemdServiceBackend() {
|
|
6520
6668
|
function isInstalled() {
|
|
6521
|
-
return
|
|
6669
|
+
return existsSync29(getLinuxSystemdServiceFile());
|
|
6522
6670
|
}
|
|
6523
6671
|
async function setup(skipPrompt = false) {
|
|
6524
6672
|
if (!ensureSystemdAvailable()) {
|
|
@@ -6643,7 +6791,7 @@ function createLinuxSystemdServiceBackend() {
|
|
|
6643
6791
|
}
|
|
6644
6792
|
async function uninstall(skipPrompt = false) {
|
|
6645
6793
|
const serviceFile = getLinuxSystemdServiceFile();
|
|
6646
|
-
if (!
|
|
6794
|
+
if (!existsSync29(serviceFile)) {
|
|
6647
6795
|
logger.info(formatBullet("\u670D\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728\u3002", "warning"));
|
|
6648
6796
|
return;
|
|
6649
6797
|
}
|
|
@@ -6704,17 +6852,17 @@ function createLinuxSystemdServiceBackend() {
|
|
|
6704
6852
|
|
|
6705
6853
|
// src/infrastructure/service/macos-launchd.ts
|
|
6706
6854
|
import { execFileSync as execFileSync6 } from "child_process";
|
|
6707
|
-
import { existsSync as
|
|
6708
|
-
import { homedir as
|
|
6855
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync4, rmSync as rmSync5, writeFileSync as writeFileSync6 } from "fs";
|
|
6856
|
+
import { homedir as homedir28, platform as platform3 } from "os";
|
|
6709
6857
|
import { posix as posix2 } from "path";
|
|
6710
6858
|
var MACOS_LAUNCHD_LABEL = "com.guji.tokenarena";
|
|
6711
6859
|
function getCurrentUid() {
|
|
6712
6860
|
return typeof process.getuid === "function" ? process.getuid() : null;
|
|
6713
6861
|
}
|
|
6714
|
-
function getMacosLaunchAgentDir(homePath =
|
|
6862
|
+
function getMacosLaunchAgentDir(homePath = homedir28()) {
|
|
6715
6863
|
return posix2.join(homePath, "Library", "LaunchAgents");
|
|
6716
6864
|
}
|
|
6717
|
-
function getMacosLaunchAgentFile(homePath =
|
|
6865
|
+
function getMacosLaunchAgentFile(homePath = homedir28()) {
|
|
6718
6866
|
return posix2.join(
|
|
6719
6867
|
getMacosLaunchAgentDir(homePath),
|
|
6720
6868
|
`${MACOS_LAUNCHD_LABEL}.plist`
|
|
@@ -6841,7 +6989,7 @@ function writeLaunchAgentPlist() {
|
|
|
6841
6989
|
label: MACOS_LAUNCHD_LABEL,
|
|
6842
6990
|
programArguments: [command.execPath, ...command.args],
|
|
6843
6991
|
environment: getManagedServiceEnvironment(),
|
|
6844
|
-
workingDirectory:
|
|
6992
|
+
workingDirectory: homedir28(),
|
|
6845
6993
|
standardOutPath: stdoutPath,
|
|
6846
6994
|
standardErrorPath: stderrPath
|
|
6847
6995
|
});
|
|
@@ -6866,7 +7014,7 @@ function bootstrapLaunchAgent() {
|
|
|
6866
7014
|
}
|
|
6867
7015
|
function createMacosLaunchdServiceBackend() {
|
|
6868
7016
|
function isInstalled() {
|
|
6869
|
-
return
|
|
7017
|
+
return existsSync30(getMacosLaunchAgentFile());
|
|
6870
7018
|
}
|
|
6871
7019
|
async function setup(skipPrompt = false) {
|
|
6872
7020
|
if (!ensureLaunchctlAvailable()) {
|
|
@@ -7007,7 +7155,7 @@ function createMacosLaunchdServiceBackend() {
|
|
|
7007
7155
|
}
|
|
7008
7156
|
async function uninstall(skipPrompt = false) {
|
|
7009
7157
|
const plistFile = getMacosLaunchAgentFile();
|
|
7010
|
-
if (!
|
|
7158
|
+
if (!existsSync30(plistFile)) {
|
|
7011
7159
|
logger.info(formatBullet("\u670D\u52A1\u6587\u4EF6\u4E0D\u5B58\u5728\u3002", "warning"));
|
|
7012
7160
|
return;
|
|
7013
7161
|
}
|
|
@@ -7118,7 +7266,7 @@ function resolvePowerShellProfilePath() {
|
|
|
7118
7266
|
const systemRoot = process.env.SYSTEMROOT || "C:\\Windows";
|
|
7119
7267
|
const candidates = [
|
|
7120
7268
|
"pwsh.exe",
|
|
7121
|
-
|
|
7269
|
+
join30(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
|
|
7122
7270
|
];
|
|
7123
7271
|
for (const command of candidates) {
|
|
7124
7272
|
try {
|
|
@@ -7147,8 +7295,8 @@ function resolvePowerShellProfilePath() {
|
|
|
7147
7295
|
function resolveShellAliasSetup(options = {}) {
|
|
7148
7296
|
const currentPlatform = options.currentPlatform ?? platform5();
|
|
7149
7297
|
const env = options.env ?? process.env;
|
|
7150
|
-
const homeDir = options.homeDir ??
|
|
7151
|
-
const pathExists = options.exists ??
|
|
7298
|
+
const homeDir = options.homeDir ?? homedir29();
|
|
7299
|
+
const pathExists = options.exists ?? existsSync31;
|
|
7152
7300
|
const shellFromEnv = env.SHELL ? basenameLikeShell(env.SHELL).toLowerCase() : "";
|
|
7153
7301
|
const shellName = shellFromEnv || (currentPlatform === "win32" ? "powershell" : "");
|
|
7154
7302
|
const aliasName = "ta";
|
|
@@ -7345,7 +7493,7 @@ async function setupShellAlias() {
|
|
|
7345
7493
|
try {
|
|
7346
7494
|
await mkdir(dirname6(setup.configFile), { recursive: true });
|
|
7347
7495
|
let existingContent = "";
|
|
7348
|
-
if (
|
|
7496
|
+
if (existsSync31(setup.configFile)) {
|
|
7349
7497
|
existingContent = await readFile(setup.configFile, "utf-8");
|
|
7350
7498
|
}
|
|
7351
7499
|
const normalizedContent = existingContent.toLowerCase();
|
|
@@ -7604,7 +7752,7 @@ function buildLocalUsageDashboardData(input2) {
|
|
|
7604
7752
|
|
|
7605
7753
|
// src/infrastructure/runtime/cli-version.ts
|
|
7606
7754
|
import { readFileSync as readFileSync13 } from "fs";
|
|
7607
|
-
import { dirname as dirname7, join as
|
|
7755
|
+
import { dirname as dirname7, join as join31 } from "path";
|
|
7608
7756
|
import { fileURLToPath } from "url";
|
|
7609
7757
|
var FALLBACK_VERSION = "0.0.0";
|
|
7610
7758
|
var cachedVersion;
|
|
@@ -7612,7 +7760,7 @@ function getCliVersion(metaUrl = import.meta.url) {
|
|
|
7612
7760
|
if (cachedVersion) {
|
|
7613
7761
|
return cachedVersion;
|
|
7614
7762
|
}
|
|
7615
|
-
const packageJsonPath =
|
|
7763
|
+
const packageJsonPath = join31(
|
|
7616
7764
|
dirname7(fileURLToPath(metaUrl)),
|
|
7617
7765
|
"..",
|
|
7618
7766
|
"package.json"
|
|
@@ -8023,8 +8171,8 @@ async function runSyncCommand(opts = {}) {
|
|
|
8023
8171
|
}
|
|
8024
8172
|
|
|
8025
8173
|
// src/commands/uninstall.ts
|
|
8026
|
-
import { existsSync as
|
|
8027
|
-
import { homedir as
|
|
8174
|
+
import { existsSync as existsSync32, readFileSync as readFileSync14, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "fs";
|
|
8175
|
+
import { homedir as homedir30, platform as platform6 } from "os";
|
|
8028
8176
|
function removeShellAlias() {
|
|
8029
8177
|
const shell = process.env.SHELL;
|
|
8030
8178
|
if (!shell) return;
|
|
@@ -8033,22 +8181,22 @@ function removeShellAlias() {
|
|
|
8033
8181
|
let configFile;
|
|
8034
8182
|
switch (shellName) {
|
|
8035
8183
|
case "zsh":
|
|
8036
|
-
configFile = `${
|
|
8184
|
+
configFile = `${homedir30()}/.zshrc`;
|
|
8037
8185
|
break;
|
|
8038
8186
|
case "bash":
|
|
8039
|
-
if (platform6() === "darwin" &&
|
|
8040
|
-
configFile = `${
|
|
8187
|
+
if (platform6() === "darwin" && existsSync32(`${homedir30()}/.bash_profile`)) {
|
|
8188
|
+
configFile = `${homedir30()}/.bash_profile`;
|
|
8041
8189
|
} else {
|
|
8042
|
-
configFile = `${
|
|
8190
|
+
configFile = `${homedir30()}/.bashrc`;
|
|
8043
8191
|
}
|
|
8044
8192
|
break;
|
|
8045
8193
|
case "fish":
|
|
8046
|
-
configFile = `${
|
|
8194
|
+
configFile = `${homedir30()}/.config/fish/config.fish`;
|
|
8047
8195
|
break;
|
|
8048
8196
|
default:
|
|
8049
8197
|
return;
|
|
8050
8198
|
}
|
|
8051
|
-
if (!
|
|
8199
|
+
if (!existsSync32(configFile)) return;
|
|
8052
8200
|
try {
|
|
8053
8201
|
let content = readFileSync14(configFile, "utf-8");
|
|
8054
8202
|
const aliasPatterns = [
|
|
@@ -8087,7 +8235,7 @@ async function runUninstall() {
|
|
|
8087
8235
|
const runtimeDir = getRuntimeDirPath();
|
|
8088
8236
|
const serviceBackend = getServiceBackend();
|
|
8089
8237
|
const hasInstalledService = serviceBackend?.isInstalled() ?? false;
|
|
8090
|
-
const hasLocalArtifacts =
|
|
8238
|
+
const hasLocalArtifacts = existsSync32(configPath) || existsSync32(configDir) || existsSync32(stateDir) || existsSync32(runtimeDir) || hasInstalledService;
|
|
8091
8239
|
if (!hasLocalArtifacts) {
|
|
8092
8240
|
logger.info(formatHeader("\u5378\u8F7D TokenArena"));
|
|
8093
8241
|
logger.info(formatBullet("\u672A\u53D1\u73B0\u672C\u5730\u914D\u7F6E\uFF0C\u65E0\u9700\u5378\u8F7D\u3002"));
|
|
@@ -8131,22 +8279,22 @@ async function runUninstall() {
|
|
|
8131
8279
|
}
|
|
8132
8280
|
}
|
|
8133
8281
|
logger.info(formatSection("\u6267\u884C\u7ED3\u679C"));
|
|
8134
|
-
if (
|
|
8282
|
+
if (existsSync32(configPath)) {
|
|
8135
8283
|
deleteConfig();
|
|
8136
8284
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u914D\u7F6E\u6587\u4EF6\u3002", "success"));
|
|
8137
8285
|
}
|
|
8138
|
-
if (
|
|
8286
|
+
if (existsSync32(configDir)) {
|
|
8139
8287
|
try {
|
|
8140
8288
|
rmSync6(configDir, { recursive: false, force: true });
|
|
8141
8289
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u914D\u7F6E\u76EE\u5F55\u3002", "success"));
|
|
8142
8290
|
} catch {
|
|
8143
8291
|
}
|
|
8144
8292
|
}
|
|
8145
|
-
if (
|
|
8293
|
+
if (existsSync32(stateDir)) {
|
|
8146
8294
|
rmSync6(stateDir, { recursive: true, force: true });
|
|
8147
8295
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u72B6\u6001\u6570\u636E\u3002", "success"));
|
|
8148
8296
|
}
|
|
8149
|
-
if (
|
|
8297
|
+
if (existsSync32(runtimeDir)) {
|
|
8150
8298
|
rmSync6(runtimeDir, { recursive: true, force: true });
|
|
8151
8299
|
logger.info(formatBullet("\u5DF2\u5220\u9664\u8FD0\u884C\u65F6\u6570\u636E\u3002", "success"));
|
|
8152
8300
|
}
|
|
@@ -8377,7 +8525,7 @@ function createCli() {
|
|
|
8377
8525
|
}
|
|
8378
8526
|
|
|
8379
8527
|
// src/infrastructure/runtime/main-module.ts
|
|
8380
|
-
import { existsSync as
|
|
8528
|
+
import { existsSync as existsSync33, realpathSync as realpathSync2 } from "fs";
|
|
8381
8529
|
import { resolve as resolve3 } from "path";
|
|
8382
8530
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8383
8531
|
function isMainModule(argvEntry = process.argv[1], metaUrl = import.meta.url) {
|
|
@@ -8388,7 +8536,7 @@ function isMainModule(argvEntry = process.argv[1], metaUrl = import.meta.url) {
|
|
|
8388
8536
|
try {
|
|
8389
8537
|
return realpathSync2(argvEntry) === realpathSync2(currentModulePath);
|
|
8390
8538
|
} catch {
|
|
8391
|
-
if (!
|
|
8539
|
+
if (!existsSync33(argvEntry)) {
|
|
8392
8540
|
return false;
|
|
8393
8541
|
}
|
|
8394
8542
|
return resolve3(argvEntry) === resolve3(currentModulePath);
|