@use-aistack/cli 0.12.1 → 0.12.4
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 +79 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -348,7 +348,7 @@ function apiEquivalentCost(modelKey, t, atMs) {
|
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
// src/version.ts
|
|
351
|
-
var CLI_VERSION = true ? "0.12.
|
|
351
|
+
var CLI_VERSION = true ? "0.12.4" : "0.0.0-dev";
|
|
352
352
|
|
|
353
353
|
// src/api.ts
|
|
354
354
|
var BASE_URL = process.env.AISTACK_URL || "https://aistack.to";
|
|
@@ -976,11 +976,11 @@ function readText(path7) {
|
|
|
976
976
|
return null;
|
|
977
977
|
}
|
|
978
978
|
}
|
|
979
|
-
function readParsed(path7,
|
|
979
|
+
function readParsed(path7, parse2) {
|
|
980
980
|
const raw = readText(path7);
|
|
981
981
|
if (raw === null) return null;
|
|
982
982
|
try {
|
|
983
|
-
return
|
|
983
|
+
return parse2(raw);
|
|
984
984
|
} catch {
|
|
985
985
|
return null;
|
|
986
986
|
}
|
|
@@ -6476,6 +6476,7 @@ import { createHash } from "node:crypto";
|
|
|
6476
6476
|
import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6477
6477
|
import { homedir as homedir11 } from "node:os";
|
|
6478
6478
|
import { dirname as dirname5, join as join8 } from "node:path";
|
|
6479
|
+
import { parse } from "smol-toml";
|
|
6479
6480
|
function codexHome2() {
|
|
6480
6481
|
return process.env.CODEX_HOME || join8(homedir11(), ".codex");
|
|
6481
6482
|
}
|
|
@@ -6558,15 +6559,59 @@ function codexAutoSyncHookInstalled(file = codexHooksFile()) {
|
|
|
6558
6559
|
if (!Array.isArray(sessionStart)) return false;
|
|
6559
6560
|
return sessionStart.some((m) => (m.hooks ?? []).some((h) => isOurs(h)));
|
|
6560
6561
|
}
|
|
6561
|
-
function codexHookTrusted(configFile = codexConfigFile()) {
|
|
6562
|
-
let text;
|
|
6562
|
+
function codexHookTrusted(configFile = codexConfigFile(), hooksFile = codexHooksFile()) {
|
|
6563
6563
|
try {
|
|
6564
|
-
|
|
6564
|
+
const config = parse(readFileSync9(configFile, "utf-8"));
|
|
6565
|
+
const read = readHooksJson(hooksFile);
|
|
6566
|
+
if ("error" in read) return null;
|
|
6567
|
+
const sessionStart = read.settings.hooks?.SessionStart;
|
|
6568
|
+
if (!Array.isArray(sessionStart)) return false;
|
|
6569
|
+
const matches = [];
|
|
6570
|
+
for (const [groupIndex, group] of sessionStart.entries()) {
|
|
6571
|
+
for (const [handlerIndex, handler] of (group.hooks ?? []).entries()) {
|
|
6572
|
+
if (!isOurs(handler) || typeof handler.command !== "string") continue;
|
|
6573
|
+
const normalizedHandler = {
|
|
6574
|
+
type: "command",
|
|
6575
|
+
command: handler.command,
|
|
6576
|
+
timeout: typeof handler.timeout === "number" ? Math.max(1, handler.timeout) : 600,
|
|
6577
|
+
async: handler.async === true
|
|
6578
|
+
};
|
|
6579
|
+
if (typeof handler.statusMessage === "string") {
|
|
6580
|
+
normalizedHandler.statusMessage = handler.statusMessage;
|
|
6581
|
+
}
|
|
6582
|
+
if (typeof handler.additionalContextLimit === "number" && handler.additionalContextLimit !== 2500) {
|
|
6583
|
+
normalizedHandler.additionalContextLimit = handler.additionalContextLimit;
|
|
6584
|
+
}
|
|
6585
|
+
const identity = {
|
|
6586
|
+
event_name: "session_start",
|
|
6587
|
+
hooks: [normalizedHandler]
|
|
6588
|
+
};
|
|
6589
|
+
if (typeof group.matcher === "string") identity.matcher = group.matcher;
|
|
6590
|
+
const currentHash = `sha256:${createHash("sha256").update(JSON.stringify(canonicalJson2(identity))).digest("hex")}`;
|
|
6591
|
+
const key2 = `${hooksFile}:session_start:${groupIndex}:${handlerIndex}`;
|
|
6592
|
+
matches.push(config.hooks?.state?.[key2]?.trusted_hash === currentHash);
|
|
6593
|
+
}
|
|
6594
|
+
}
|
|
6595
|
+
return matches.length > 0 && matches.every(Boolean);
|
|
6565
6596
|
} catch {
|
|
6566
6597
|
return null;
|
|
6567
6598
|
}
|
|
6568
|
-
|
|
6569
|
-
|
|
6599
|
+
}
|
|
6600
|
+
function canonicalJson2(value) {
|
|
6601
|
+
if (Array.isArray(value)) return value.map(canonicalJson2);
|
|
6602
|
+
if (value && typeof value === "object") {
|
|
6603
|
+
const sorted = {};
|
|
6604
|
+
for (const [key2, child] of Object.entries(value).sort(
|
|
6605
|
+
([a], [b]) => a.localeCompare(b)
|
|
6606
|
+
)) {
|
|
6607
|
+
sorted[key2] = canonicalJson2(child);
|
|
6608
|
+
}
|
|
6609
|
+
return sorted;
|
|
6610
|
+
}
|
|
6611
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
6612
|
+
return value;
|
|
6613
|
+
}
|
|
6614
|
+
throw new TypeError("hook identity is not JSON-serializable");
|
|
6570
6615
|
}
|
|
6571
6616
|
|
|
6572
6617
|
// src/autosync/optin.ts
|
|
@@ -6679,7 +6724,9 @@ async function enableAutoSync(frequencyHours = DEFAULT_FREQUENCY_HOURS, deps = {
|
|
|
6679
6724
|
if (names.has(CODEX_HARNESS_NAME)) {
|
|
6680
6725
|
const codexResult = (deps.installCodexHook ?? installCodexAutoSyncHook)();
|
|
6681
6726
|
if (!codexResult.ok) return codexResult;
|
|
6682
|
-
|
|
6727
|
+
if ((deps.codexHookTrustedImpl ?? codexHookTrusted)() !== true) {
|
|
6728
|
+
trustLine = codexResult.message;
|
|
6729
|
+
}
|
|
6683
6730
|
}
|
|
6684
6731
|
saveSettings(
|
|
6685
6732
|
{
|
|
@@ -7430,24 +7477,23 @@ function totalUSD(payload) {
|
|
|
7430
7477
|
}
|
|
7431
7478
|
return any ? sum : null;
|
|
7432
7479
|
}
|
|
7480
|
+
function tokenBreakdown(payload) {
|
|
7481
|
+
let fresh = 0;
|
|
7482
|
+
let cached = 0;
|
|
7483
|
+
for (const model of payload.models) {
|
|
7484
|
+
fresh += model.tokens.input + model.tokens.output + model.tokens.cacheWrite;
|
|
7485
|
+
cached += model.tokens.cacheRead;
|
|
7486
|
+
}
|
|
7487
|
+
return fresh + cached === payload.activity.totalTokens ? { fresh, cached } : null;
|
|
7488
|
+
}
|
|
7433
7489
|
function withheldCount(payload) {
|
|
7434
7490
|
const w = payload.inventory.withheld;
|
|
7435
7491
|
return w.builtinTools + w.mcpServers + w.skills + w.subagents + w.slashCommands;
|
|
7436
7492
|
}
|
|
7437
7493
|
function buildGateDialog(ctx) {
|
|
7438
7494
|
const { payloads, keptPrivate } = ctx.body;
|
|
7439
|
-
const tokens = payloads.reduce((a, p8) => a + p8.activity.totalTokens, 0);
|
|
7440
|
-
const usds = payloads.map((p8) => totalUSD(p8)).filter((u) => u !== null);
|
|
7441
|
-
const usd = usds.length > 0 ? usds.reduce((a, b) => a + b, 0) : null;
|
|
7442
|
-
const days = payloads[0]?.window.days ?? 0;
|
|
7443
|
-
const facts = [
|
|
7444
|
-
`${fmtTokens(tokens)} tokens`,
|
|
7445
|
-
`${days}-day profile`,
|
|
7446
|
-
...ctx.body.measuredDays && ctx.body.measuredDays.days.length !== days ? [`${ctx.body.measuredDays.days.length} historical days`] : [],
|
|
7447
|
-
...usd === null ? [] : [fmtUSD(usd)]
|
|
7448
|
-
].join(" \xB7 ");
|
|
7449
7495
|
const n = payloads.reduce((a, p8) => a + withheldCount(p8), 0);
|
|
7450
|
-
const lines2 = [
|
|
7496
|
+
const lines2 = ["Publish to aistack?"];
|
|
7451
7497
|
if (n > 0) {
|
|
7452
7498
|
lines2.push(
|
|
7453
7499
|
keptPrivate === void 0 ? `${n} name${n === 1 ? "" : "s"} stay${n === 1 ? "s" : ""} on this machine` : `${n} private review name${n === 1 ? "" : "s"} will be stored`
|
|
@@ -7549,10 +7595,15 @@ function payloadBlock(payload, width, ownWindow, stats) {
|
|
|
7549
7595
|
const label = `${harnessLabel2(payload.harness.name)}${payload.harness.version ? ` ${payload.harness.version}` : ""}`;
|
|
7550
7596
|
const days = payload.activity.activeDayDates.length;
|
|
7551
7597
|
const usd = totalUSD(payload);
|
|
7598
|
+
const breakdown = tokenBreakdown(payload);
|
|
7552
7599
|
const totals = [
|
|
7553
7600
|
`${payload.activity.sessions} session${payload.activity.sessions === 1 ? "" : "s"}`,
|
|
7554
7601
|
`${days} active day${days === 1 ? "" : "s"}`,
|
|
7555
|
-
`${fmtTokens(payload.activity.totalTokens)} tokens
|
|
7602
|
+
`${fmtTokens(payload.activity.totalTokens)} tokens processed`,
|
|
7603
|
+
...breakdown ? [
|
|
7604
|
+
`${fmtTokens(breakdown.fresh)} fresh`,
|
|
7605
|
+
`${fmtTokens(breakdown.cached)} cached`
|
|
7606
|
+
] : []
|
|
7556
7607
|
];
|
|
7557
7608
|
out.push(`${label.toUpperCase()} ${payload.activity.sessions}`);
|
|
7558
7609
|
if (payload.activity.totalTokens === 0) {
|
|
@@ -8217,10 +8268,14 @@ async function syncCommand(options = {}) {
|
|
|
8217
8268
|
const decision = await p7.select({
|
|
8218
8269
|
message: staged.dialog.split("\n").join(dim(" \xB7 ")),
|
|
8219
8270
|
options: [
|
|
8220
|
-
{
|
|
8221
|
-
|
|
8271
|
+
{
|
|
8272
|
+
value: "publish",
|
|
8273
|
+
label: "Publish",
|
|
8274
|
+
hint: "no sensitive data is shared"
|
|
8275
|
+
},
|
|
8276
|
+
{ value: "cancel", label: "Cancel", hint: "nothing leaves this machine" }
|
|
8222
8277
|
],
|
|
8223
|
-
initialValue: "
|
|
8278
|
+
initialValue: "publish"
|
|
8224
8279
|
});
|
|
8225
8280
|
if (p7.isCancel(decision) || decision !== "publish") {
|
|
8226
8281
|
outroCancel("nothing was sent");
|