@use-aistack/cli 0.12.2 → 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 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.2" : "0.0.0-dev";
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, parse) {
979
+ function readParsed(path7, parse2) {
980
980
  const raw = readText(path7);
981
981
  if (raw === null) return null;
982
982
  try {
983
- return parse(raw);
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
- text = readFileSync9(configFile, "utf-8");
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
- const hash = createHash("sha256").update(CODEX_HOOK_COMMAND).digest("hex");
6569
- return text.includes(hash);
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
- trustLine = codexResult.message;
6727
+ if ((deps.codexHookTrustedImpl ?? codexHookTrusted)() !== true) {
6728
+ trustLine = codexResult.message;
6729
+ }
6683
6730
  }
6684
6731
  saveSettings(
6685
6732
  {
@@ -7430,6 +7477,15 @@ 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;
@@ -7539,10 +7595,15 @@ function payloadBlock(payload, width, ownWindow, stats) {
7539
7595
  const label = `${harnessLabel2(payload.harness.name)}${payload.harness.version ? ` ${payload.harness.version}` : ""}`;
7540
7596
  const days = payload.activity.activeDayDates.length;
7541
7597
  const usd = totalUSD(payload);
7598
+ const breakdown = tokenBreakdown(payload);
7542
7599
  const totals = [
7543
7600
  `${payload.activity.sessions} session${payload.activity.sessions === 1 ? "" : "s"}`,
7544
7601
  `${days} active day${days === 1 ? "" : "s"}`,
7545
- `${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
+ ] : []
7546
7607
  ];
7547
7608
  out.push(`${label.toUpperCase()} ${payload.activity.sessions}`);
7548
7609
  if (payload.activity.totalTokens === 0) {