jinzd-ai-cli 0.4.265 → 0.4.267

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.
Files changed (33) hide show
  1. package/dist/{batch-C7SHXRQ2.js → batch-GY5MAN5F.js} +2 -2
  2. package/dist/{chunk-TJBG4F2R.js → chunk-5AEOIETL.js} +4 -4
  3. package/dist/{chunk-NOS3QV7G.js → chunk-5CU72V6P.js} +3 -3
  4. package/dist/{chunk-IFTUBTDA.js → chunk-6C6FLDGH.js} +1 -1
  5. package/dist/{chunk-M2RKBTVZ.js → chunk-7HECI3U5.js} +1 -1
  6. package/dist/{chunk-NJLPA6S4.js → chunk-ARYCWJN6.js} +1 -1
  7. package/dist/{chunk-X6NWK2YK.js → chunk-EWRZMIQE.js} +1 -1
  8. package/dist/{chunk-YXYOLPDB.js → chunk-FI6IWUXW.js} +1 -1
  9. package/dist/{chunk-CVI3LSGR.js → chunk-JH343BDI.js} +105 -2
  10. package/dist/{chunk-E3JRGJCJ.js → chunk-QN7WD2SM.js} +3 -3
  11. package/dist/{chunk-V4D7YD24.js → chunk-R7GERZDA.js} +145 -4
  12. package/dist/{chunk-LZBD2VGJ.js → chunk-RVNL7MQG.js} +1 -1
  13. package/dist/{chunk-Y7KJPNQI.js → chunk-THHPKZJ3.js} +1 -1
  14. package/dist/{chunk-2MR7EP24.js → chunk-WPN7LDLM.js} +1 -1
  15. package/dist/{chunk-YDTYBUAB.js → chunk-XLLUQEGO.js} +1 -1
  16. package/dist/{ci-TDXLI3OM.js → ci-MUEQSNKU.js} +4 -4
  17. package/dist/{ci-format-AFX2LP4Y.js → ci-format-2ZGGSOFK.js} +2 -2
  18. package/dist/{constants-66TQEDGO.js → constants-SZTJESDF.js} +1 -1
  19. package/dist/{doctor-cli-GMCOGCDR.js → doctor-cli-Z272364P.js} +4 -4
  20. package/dist/electron-server.js +781 -420
  21. package/dist/{hub-2YXETHPY.js → hub-MRLGKMRI.js} +1 -1
  22. package/dist/index.js +51 -93
  23. package/dist/{persistent-memory-WTZO5CQ7.js → persistent-memory-3FTOC7QT.js} +2 -2
  24. package/dist/{persistent-memory-2DKCETB7.js → persistent-memory-HZASMDJQ.js} +2 -2
  25. package/dist/{pr-Y2LDG3R7.js → pr-VLLIALRK.js} +4 -4
  26. package/dist/{run-tests-FIUGDIDL.js → run-tests-6MWE6D5S.js} +2 -2
  27. package/dist/{run-tests-PWTNSUVP.js → run-tests-NTDZ6DDU.js} +2 -2
  28. package/dist/{server-OZ4RFDFH.js → server-IALCWKSU.js} +61 -48
  29. package/dist/{server-ZCG5QD6P.js → server-SP3AEHRQ.js} +5 -5
  30. package/dist/{task-orchestrator-Q2L6JEUX.js → task-orchestrator-Q6WFFI4J.js} +5 -5
  31. package/dist/{usage-SDL5Z4CS.js → usage-DJDLHICZ.js} +4 -6
  32. package/package.json +1 -1
  33. package/dist/chunk-YRD6M5XI.js +0 -149
@@ -158,7 +158,7 @@ ${content}`);
158
158
  }
159
159
  }
160
160
  async function runTaskMode(config, providers, configManager, topic) {
161
- const { TaskOrchestrator } = await import("./task-orchestrator-Q2L6JEUX.js");
161
+ const { TaskOrchestrator } = await import("./task-orchestrator-Q6WFFI4J.js");
162
162
  const orchestrator = new TaskOrchestrator(config, providers, configManager);
163
163
  let interrupted = false;
164
164
  const onSigint = () => {
package/dist/index.js CHANGED
@@ -3,9 +3,12 @@ import {
3
3
  McpManager,
4
4
  SNAPSHOT_PROMPT,
5
5
  SkillManager,
6
+ applyThinkCommand,
6
7
  autoTrimSessionIfNeeded,
7
8
  buildInitPrompt,
9
+ buildSessionCostReport,
8
10
  clearDevState,
11
+ costSourceNote,
9
12
  loadDevState,
10
13
  parseSimpleYaml,
11
14
  persistToolRound,
@@ -14,15 +17,13 @@ import {
14
17
  scanProject,
15
18
  sessionHasMeaningfulContent,
16
19
  setupProxy
17
- } from "./chunk-CVI3LSGR.js";
18
- import {
19
- CostTracker
20
- } from "./chunk-V4D7YD24.js";
20
+ } from "./chunk-JH343BDI.js";
21
21
  import {
22
+ CostTracker,
22
23
  computeCost,
23
24
  formatCost,
24
25
  getPricing
25
- } from "./chunk-YRD6M5XI.js";
26
+ } from "./chunk-R7GERZDA.js";
26
27
  import {
27
28
  buildReviewPrompt,
28
29
  buildSecurityReviewPrompt
@@ -54,7 +55,7 @@ import {
54
55
  setMaxOutputCap,
55
56
  spawnAgentContext,
56
57
  undoStack
57
- } from "./chunk-TJBG4F2R.js";
58
+ } from "./chunk-5AEOIETL.js";
58
59
  import {
59
60
  addMemoryEntry,
60
61
  backupMemoryStore,
@@ -80,7 +81,7 @@ import {
80
81
  touchMemoryReferences,
81
82
  updateMemoryApproval,
82
83
  updateMemoryEntry
83
- } from "./chunk-LZBD2VGJ.js";
84
+ } from "./chunk-RVNL7MQG.js";
84
85
  import "./chunk-GLSR2NR3.js";
85
86
  import "./chunk-UUSRWSSX.js";
86
87
  import "./chunk-CKH4KQ4E.js";
@@ -98,14 +99,14 @@ import {
98
99
  formatDoctorReport,
99
100
  loadContextFiles,
100
101
  writeCrashLog
101
- } from "./chunk-E3JRGJCJ.js";
102
+ } from "./chunk-QN7WD2SM.js";
102
103
  import {
103
104
  ProviderRegistry,
104
105
  listBuiltInProviderMetadata
105
106
  } from "./chunk-AUEX6RNY.js";
106
107
  import {
107
108
  ConfigManager
108
- } from "./chunk-X6NWK2YK.js";
109
+ } from "./chunk-EWRZMIQE.js";
109
110
  import {
110
111
  describePlugin,
111
112
  getActivePluginAssets,
@@ -122,7 +123,7 @@ import {
122
123
  trustHook,
123
124
  trustPlugin,
124
125
  untrustHook
125
- } from "./chunk-2MR7EP24.js";
126
+ } from "./chunk-WPN7LDLM.js";
126
127
  import {
127
128
  CONTENT_ONLY_STREAM_REMINDER,
128
129
  TEE_FINAL_USER_NUDGE,
@@ -156,7 +157,7 @@ import {
156
157
  import {
157
158
  fileCheckpoints
158
159
  } from "./chunk-4BKXL7SM.js";
159
- import "./chunk-YDTYBUAB.js";
160
+ import "./chunk-XLLUQEGO.js";
160
161
  import {
161
162
  AGENTIC_BEHAVIOR_GUIDELINE,
162
163
  AUTHOR,
@@ -175,7 +176,7 @@ import {
175
176
  SKILLS_DIR_NAME,
176
177
  VERSION,
177
178
  buildUserIdentityPrompt
178
- } from "./chunk-Y7KJPNQI.js";
179
+ } from "./chunk-THHPKZJ3.js";
179
180
  import {
180
181
  buildChatIndex,
181
182
  clearChatIndex,
@@ -1152,59 +1153,24 @@ function createProviderCommands() {
1152
1153
  description: "Toggle Extended Thinking mode (deep reasoning for supported models)",
1153
1154
  usage: "/think [on|off|low|high|max|status]",
1154
1155
  execute(args, ctx) {
1155
- const sub = args[0]?.toLowerCase() ?? "toggle";
1156
- if (sub === "on") {
1157
- ctx.setThinkingMode(true);
1158
- ctx.renderer.printSuccess("Extended Thinking enabled \u{1F4AD}");
1159
- console.log(theme.dim(" AI will now use deep reasoning before answering."));
1160
- console.log(theme.dim(" Supported: DeepSeek V4, Claude Sonnet/Opus, GLM-5"));
1161
- console.log(theme.dim(" Use /think off to disable."));
1162
- console.log();
1163
- return;
1164
- }
1165
- if (sub === "off") {
1166
- ctx.setThinkingMode(false);
1167
- ctx.renderer.printSuccess("Extended Thinking disabled.");
1168
- console.log();
1169
- return;
1170
- }
1171
- if (sub === "low" || sub === "high" || sub === "max") {
1172
- ctx.setThinkingMode(true);
1173
- ctx.setThinkingEffort(sub);
1174
- ctx.renderer.printSuccess(`Extended Thinking enabled (effort: ${sub}).`);
1175
- console.log();
1176
- return;
1177
- }
1178
- if (sub === "status") {
1179
- const mode = ctx.getThinkingMode();
1180
- const effective = mode ?? ctx.getConfiguredThinking() ?? false;
1181
- const origin = mode !== null ? "runtime override" : ctx.getConfiguredThinking() !== void 0 ? "from config" : "default";
1182
- const label = effective ? theme.accent(`ON (${origin})`) : theme.dim(`OFF (${origin})`);
1183
- console.log(` Extended Thinking: ${label}`);
1184
- if (effective) {
1185
- const supportsEffort = ctx.getProviderSupportsReasoningEffort();
1186
- if (supportsEffort) {
1187
- const effort = ctx.getThinkingEffort() ?? ctx.getConfiguredThinkingEffort();
1188
- console.log(` Reasoning effort: ${effort ?? "high (provider default)"}`);
1189
- } else {
1190
- console.log(theme.dim(` Reasoning effort: n/a for ${ctx.getCurrentProvider()}`));
1191
- }
1192
- } else {
1193
- console.log(theme.dim(" Enable with /think on | low | high | max, or set"));
1194
- console.log(theme.dim(" modelParams.<model>.thinking in ~/.aicli/config.json"));
1195
- }
1196
- console.log();
1197
- return;
1198
- }
1199
- const current = ctx.getThinkingMode();
1200
- if (current === true) {
1201
- ctx.setThinkingMode(false);
1202
- ctx.renderer.printSuccess("Extended Thinking disabled.");
1156
+ const outcome = applyThinkCommand(args[0], {
1157
+ runtimeThinking: ctx.getThinkingMode(),
1158
+ runtimeEffort: ctx.getThinkingEffort(),
1159
+ configuredThinking: ctx.getConfiguredThinking(),
1160
+ configuredEffort: ctx.getConfiguredThinkingEffort(),
1161
+ supportsEffort: ctx.getProviderSupportsReasoningEffort(),
1162
+ provider: ctx.getCurrentProvider()
1163
+ });
1164
+ if (outcome.changed) {
1165
+ ctx.setThinkingMode(outcome.runtimeThinking);
1166
+ ctx.setThinkingEffort(outcome.runtimeEffort);
1167
+ ctx.renderer.printSuccess(outcome.effective ? `${outcome.summary} \u{1F4AD}` : outcome.summary);
1168
+ } else if (outcome.summary.startsWith("Unknown")) {
1169
+ console.log(theme.warning(` ${outcome.summary}`));
1203
1170
  } else {
1204
- ctx.setThinkingMode(true);
1205
- ctx.renderer.printSuccess("Extended Thinking enabled \u{1F4AD}");
1206
- console.log(theme.dim(" Use /think off to disable."));
1171
+ console.log(` ${outcome.effective ? theme.accent(outcome.summary) : theme.dim(outcome.summary)}`);
1207
1172
  }
1173
+ for (const line of outcome.details) console.log(theme.dim(` ${line}`));
1208
1174
  console.log();
1209
1175
  }
1210
1176
  },
@@ -1431,7 +1397,7 @@ No tools match "${filter}".
1431
1397
  const { join: join6 } = await import("path");
1432
1398
  const { existsSync: existsSync6 } = await import("fs");
1433
1399
  const { getGitRoot: getGitRoot2 } = await import("./git-context-EXOEHQSF.js");
1434
- const { MCP_PROJECT_CONFIG_NAME: MCP_PROJECT_CONFIG_NAME2 } = await import("./constants-66TQEDGO.js");
1400
+ const { MCP_PROJECT_CONFIG_NAME: MCP_PROJECT_CONFIG_NAME2 } = await import("./constants-SZTJESDF.js");
1435
1401
  const { approveProject, hashMcpFile } = await import("./project-trust-NKYHL3VZ.js");
1436
1402
  const cwd = process.cwd();
1437
1403
  const projectRoot = getGitRoot2(cwd) ?? cwd;
@@ -2419,7 +2385,7 @@ function createReviewCommands() {
2419
2385
  usage: "/test [command|filter]",
2420
2386
  async execute(args, ctx) {
2421
2387
  try {
2422
- const { executeTests } = await import("./run-tests-PWTNSUVP.js");
2388
+ const { executeTests } = await import("./run-tests-NTDZ6DDU.js");
2423
2389
  const argStr = args.join(" ").trim();
2424
2390
  let testArgs = {};
2425
2391
  if (argStr) {
@@ -3806,21 +3772,16 @@ ${text}
3806
3772
  }
3807
3773
  const provider = ctx.getCurrentProvider();
3808
3774
  const model = ctx.getCurrentModel();
3809
- const pricing = getPricing(provider, model);
3810
3775
  const accrued = ctx.getSessionAccruedCost();
3811
- const usedAccrual = accrued.usd > 0;
3812
- const cost = usedAccrual ? accrued.usd : computeCost(provider, model, usage);
3813
- let savings = null;
3814
- const liveCost = computeCost(provider, model, usage);
3815
- if (liveCost != null && pricing && cacheRead > 0) {
3816
- const costWithoutCache = computeCost(provider, model, {
3817
- inputTokens: usage.inputTokens + cacheRead,
3818
- outputTokens: usage.outputTokens,
3819
- cacheCreationTokens: cacheCreate,
3820
- cacheReadTokens: 0
3821
- });
3822
- if (costWithoutCache != null) savings = costWithoutCache - liveCost;
3823
- }
3776
+ const report = buildSessionCostReport({
3777
+ provider,
3778
+ model,
3779
+ usage: { ...usage, cacheCreationTokens: cacheCreate, cacheReadTokens: cacheRead },
3780
+ accruedUsd: accrued.usd,
3781
+ accrualIncomplete: accrued.incomplete
3782
+ });
3783
+ const cost = report.cost;
3784
+ const savings = report.savings;
3824
3785
  console.log();
3825
3786
  console.log(theme.heading(" \u{1F4B0} Session Cost & Token Usage"));
3826
3787
  console.log(theme.dim(" " + "\u2500".repeat(48)));
@@ -3839,11 +3800,8 @@ ${text}
3839
3800
  console.log(theme.dim(" " + "\u2500".repeat(48)));
3840
3801
  if (cost != null) {
3841
3802
  console.log(theme.dim(" Cost : ") + chalk3.bold.cyan(formatCost(cost).padStart(12)));
3842
- if (usedAccrual && accrued.incomplete) {
3843
- console.log(theme.dim(" (partial \u2014 some turns had unknown pricing)"));
3844
- } else if (!usedAccrual) {
3845
- console.log(theme.dim(" (estimated at current rates)"));
3846
- }
3803
+ const note = costSourceNote(report.costSource);
3804
+ if (note) console.log(theme.dim(` ${note}`));
3847
3805
  if (savings != null && savings > 0) {
3848
3806
  console.log(
3849
3807
  theme.dim(" Cache savings : ") + chalk3.green(`-${formatCost(savings)}`.padStart(12)) + theme.dim(` (vs no cache)`)
@@ -7730,7 +7688,7 @@ program.command("web").description("Start Web UI server with browser-based chat
7730
7688
  console.error("Error: Invalid port number. Must be between 1 and 65535.");
7731
7689
  process.exit(1);
7732
7690
  }
7733
- const { startWebServer } = await import("./server-OZ4RFDFH.js");
7691
+ const { startWebServer } = await import("./server-IALCWKSU.js");
7734
7692
  await startWebServer({ port, host: options.host });
7735
7693
  });
7736
7694
  program.command("user [action] [username]").description("Manage Web UI users (list | create <name> | delete <name> | reset-password <name> | logout-all <name> | migrate <name>)").action(async (action, username) => {
@@ -7897,11 +7855,11 @@ program.command("sessions").description("List recent conversation sessions").opt
7897
7855
  console.log(footer + "\n");
7898
7856
  });
7899
7857
  program.command("usage").description("Show token + cost usage grouped by provider/model (cross-session)").option("--days <n>", "Only the last N days (inclusive of today)").option("--month <ym>", "Only a specific month, format YYYY-MM (e.g. 2026-06)").option("--json", "Output as JSON (for scripting)").action(async (options) => {
7900
- const { runUsageCli } = await import("./usage-SDL5Z4CS.js");
7858
+ const { runUsageCli } = await import("./usage-DJDLHICZ.js");
7901
7859
  await runUsageCli(options);
7902
7860
  });
7903
7861
  program.command("doctor").description("Health check: API keys, config, MCP, recent crashes, tool usage, disk usage").option("--json", "Output as JSON (for scripting)").option("--reset-stats", "Reset accumulated tool usage statistics").action(async (options) => {
7904
- const { runDoctorCli } = await import("./doctor-cli-GMCOGCDR.js");
7862
+ const { runDoctorCli } = await import("./doctor-cli-Z272364P.js");
7905
7863
  const argv = process.argv.slice(2);
7906
7864
  await runDoctorCli({
7907
7865
  json: !!options.json || argv.includes("--json"),
@@ -7910,7 +7868,7 @@ program.command("doctor").description("Health check: API keys, config, MCP, rece
7910
7868
  });
7911
7869
  program.command("batch <action> [arg] [arg2]").description("Anthropic Message Batches: submit | list | status <id> | results <id> [out] | cancel <id>").option("--dry-run", "Parse and validate input without submitting (submit only)").action(async (action, arg, arg2, options) => {
7912
7870
  try {
7913
- const batch = await import("./batch-C7SHXRQ2.js");
7871
+ const batch = await import("./batch-GY5MAN5F.js");
7914
7872
  switch (action) {
7915
7873
  case "submit":
7916
7874
  if (!arg) {
@@ -7953,7 +7911,7 @@ program.command("batch <action> [arg] [arg2]").description("Anthropic Message Ba
7953
7911
  }
7954
7912
  });
7955
7913
  program.command("mcp-serve").description("Start an MCP server over STDIO, exposing aicli's built-in tools to Claude Desktop / Cursor / other MCP clients").option("--allow-destructive", "Allow bash / run_interactive / task_create (always destructive in MCP mode)").option("--allow-outside-cwd", "Allow tool path arguments to escape the sandbox root \u2014 disabled by default").option("--tools <list>", "Comma-separated whitelist of tools to expose (default: all eligible tools)").option("--cwd <path>", "Working directory AND sandbox root (default: current directory)").action(async (options) => {
7956
- const { startMcpServer } = await import("./server-ZCG5QD6P.js");
7914
+ const { startMcpServer } = await import("./server-SP3AEHRQ.js");
7957
7915
  await startMcpServer({
7958
7916
  allowDestructive: !!options.allowDestructive,
7959
7917
  allowOutsideCwd: !!options.allowOutsideCwd,
@@ -7966,7 +7924,7 @@ program.command("pr <action> [target]").description("PR review helpers: review |
7966
7924
  console.error(`Unknown pr action: ${action}. Use review | security-review | summarize.`);
7967
7925
  process.exit(1);
7968
7926
  }
7969
- const { runPrCli } = await import("./pr-Y2LDG3R7.js");
7927
+ const { runPrCli } = await import("./pr-VLLIALRK.js");
7970
7928
  const result = await runPrCli({
7971
7929
  action,
7972
7930
  target,
@@ -7986,8 +7944,8 @@ program.command("pr <action> [target]").description("PR review helpers: review |
7986
7944
  process.exit(result.exitCode);
7987
7945
  });
7988
7946
  program.command("ci").description("Headless PR review (code + security) \u2014 reads git/gh diff, optionally posts to PR. Designed for GitHub Actions.").option("--pr <num>", "PR number or URL; diff fetched via gh pr diff <value>", (v) => /^#?\d+$/.test(v) ? parseInt(v.replace(/^#/, ""), 10) : v).option("--base <ref>", "Base ref for git diff <ref>...HEAD (ignored when --pr set)").option("--post", "Post review as a PR comment (requires gh CLI + GH_TOKEN, needs --pr)").option("--no-update", "Always create a new comment instead of updating the previous aicli review").option("--skip-code", "Skip the code review section").option("--skip-security", "Skip the security review section").option("--detailed", "Use the detailed code-review prompt").option("--max-diff <n>", "Max diff chars sent to the model (default 30000)", (v) => parseInt(v, 10)).option("--provider <id>", "Override provider (default: config.defaultProvider)").option("--model <id>", "Override model").option("--dry-run", "Print result to stdout instead of posting (overrides --post)").option("--json", "Output a structured JSON report").option("--markdown", "Output Markdown report (default)").option("--sarif", "Output SARIF 2.1.0 for code scanning artifacts").option("--fail-on-security-high", "Fail when the security review contains HIGH/CRITICAL findings (default)").option("--no-fail-on-security-high", "Do not fail on security HIGH/CRITICAL findings").option("--fail-on-test-failure", "Fail when the report mentions test failures (default)").option("--no-fail-on-test-failure", "Do not fail on test failure findings").option("--fail-on-lint-failure", "Fail when the report mentions lint/typecheck failures (default)").option("--no-fail-on-lint-failure", "Do not fail on lint/typecheck failure findings").action(async (options) => {
7989
- const { runCi } = await import("./ci-TDXLI3OM.js");
7990
- const { formatCiResult } = await import("./ci-format-AFX2LP4Y.js");
7947
+ const { runCi } = await import("./ci-MUEQSNKU.js");
7948
+ const { formatCiResult } = await import("./ci-format-2ZGGSOFK.js");
7991
7949
  const formats = [options.json, options.markdown, options.sarif].filter(Boolean).length;
7992
7950
  if (formats > 1) {
7993
7951
  console.error("Choose only one output format: --json, --markdown, or --sarif.");
@@ -8145,7 +8103,7 @@ program.command("hub [topic]").description("Start multi-agent hub (discuss / bra
8145
8103
  config.get("customProviders"),
8146
8104
  config.getConfigDir()
8147
8105
  );
8148
- const { startHub } = await import("./hub-2YXETHPY.js");
8106
+ const { startHub } = await import("./hub-MRLGKMRI.js");
8149
8107
  await startHub(
8150
8108
  {
8151
8109
  topic: topic ?? "",
@@ -27,9 +27,9 @@ import {
27
27
  touchMemoryReferences,
28
28
  updateMemoryApproval,
29
29
  updateMemoryEntry
30
- } from "./chunk-YXYOLPDB.js";
30
+ } from "./chunk-FI6IWUXW.js";
31
31
  import "./chunk-YVTASHS5.js";
32
- import "./chunk-M2RKBTVZ.js";
32
+ import "./chunk-7HECI3U5.js";
33
33
  import "./chunk-6BUTA5VW.js";
34
34
  export {
35
35
  addMemoryEntry,
@@ -28,9 +28,9 @@ import {
28
28
  touchMemoryReferences,
29
29
  updateMemoryApproval,
30
30
  updateMemoryEntry
31
- } from "./chunk-LZBD2VGJ.js";
31
+ } from "./chunk-RVNL7MQG.js";
32
32
  import "./chunk-HOSJZMQS.js";
33
- import "./chunk-Y7KJPNQI.js";
33
+ import "./chunk-THHPKZJ3.js";
34
34
  import "./chunk-B5TYJO7V.js";
35
35
  import "./chunk-IW3Q7AE5.js";
36
36
  export {
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  countSeverity,
4
4
  runCi
5
- } from "./chunk-NOS3QV7G.js";
6
- import "./chunk-IFTUBTDA.js";
5
+ } from "./chunk-5CU72V6P.js";
6
+ import "./chunk-6C6FLDGH.js";
7
7
  import {
8
8
  buildReviewPrompt,
9
9
  buildSecurityReviewPrompt,
@@ -17,12 +17,12 @@ import {
17
17
  } from "./chunk-AUEX6RNY.js";
18
18
  import {
19
19
  ConfigManager
20
- } from "./chunk-X6NWK2YK.js";
20
+ } from "./chunk-EWRZMIQE.js";
21
21
  import "./chunk-3OBY7WSS.js";
22
22
  import "./chunk-TU3L3PW7.js";
23
23
  import {
24
24
  VERSION
25
- } from "./chunk-Y7KJPNQI.js";
25
+ } from "./chunk-THHPKZJ3.js";
26
26
  import "./chunk-IW3Q7AE5.js";
27
27
 
28
28
  // src/cli/pr.ts
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  executeTests,
3
3
  runTestsTool
4
- } from "./chunk-NJLPA6S4.js";
5
- import "./chunk-M2RKBTVZ.js";
4
+ } from "./chunk-ARYCWJN6.js";
5
+ import "./chunk-7HECI3U5.js";
6
6
  export {
7
7
  executeTests,
8
8
  runTestsTool
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  executeTests,
4
4
  runTestsTool
5
- } from "./chunk-YDTYBUAB.js";
6
- import "./chunk-Y7KJPNQI.js";
5
+ } from "./chunk-XLLUQEGO.js";
6
+ import "./chunk-THHPKZJ3.js";
7
7
  export {
8
8
  executeTests,
9
9
  runTestsTool
@@ -15,20 +15,24 @@ import {
15
15
  import {
16
16
  McpManager,
17
17
  SkillManager,
18
+ applyThinkCommand,
18
19
  autoTrimSessionIfNeeded,
19
20
  buildInitPrompt,
21
+ buildSessionCostReport,
22
+ costSourceNote,
20
23
  loadDevState,
21
24
  persistToolRound,
22
25
  readGitDiff,
23
26
  scanDirTree,
24
27
  scanProject,
25
28
  setupProxy
26
- } from "./chunk-CVI3LSGR.js";
29
+ } from "./chunk-JH343BDI.js";
27
30
  import {
31
+ CostTracker,
28
32
  computeCost,
29
33
  formatCost,
30
34
  getPricing
31
- } from "./chunk-YRD6M5XI.js";
35
+ } from "./chunk-R7GERZDA.js";
32
36
  import {
33
37
  buildReviewPrompt,
34
38
  buildSecurityReviewPrompt
@@ -67,7 +71,7 @@ import {
67
71
  spawnAgentContext,
68
72
  truncateOutput,
69
73
  undoStack
70
- } from "./chunk-TJBG4F2R.js";
74
+ } from "./chunk-5AEOIETL.js";
71
75
  import {
72
76
  addMemoryEntry,
73
77
  clearMemoryEntries,
@@ -81,7 +85,7 @@ import {
81
85
  parseWritableScope,
82
86
  updateMemoryApproval,
83
87
  updateMemoryEntry
84
- } from "./chunk-LZBD2VGJ.js";
88
+ } from "./chunk-RVNL7MQG.js";
85
89
  import "./chunk-GLSR2NR3.js";
86
90
  import "./chunk-UUSRWSSX.js";
87
91
  import "./chunk-CKH4KQ4E.js";
@@ -95,13 +99,13 @@ import {
95
99
  buildDoctorReport,
96
100
  formatDoctorReport,
97
101
  loadContextFiles
98
- } from "./chunk-E3JRGJCJ.js";
102
+ } from "./chunk-QN7WD2SM.js";
99
103
  import {
100
104
  ProviderRegistry
101
105
  } from "./chunk-AUEX6RNY.js";
102
106
  import {
103
107
  ConfigManager
104
- } from "./chunk-X6NWK2YK.js";
108
+ } from "./chunk-EWRZMIQE.js";
105
109
  import {
106
110
  describePlugin,
107
111
  getActivePluginAssets,
@@ -116,7 +120,7 @@ import {
116
120
  runTool,
117
121
  setPluginEnabled,
118
122
  trustPlugin
119
- } from "./chunk-2MR7EP24.js";
123
+ } from "./chunk-WPN7LDLM.js";
120
124
  import {
121
125
  CONTENT_ONLY_STREAM_REMINDER,
122
126
  TEE_FINAL_USER_NUDGE,
@@ -141,7 +145,7 @@ import {
141
145
  getGitRoot
142
146
  } from "./chunk-HOSJZMQS.js";
143
147
  import "./chunk-4BKXL7SM.js";
144
- import "./chunk-YDTYBUAB.js";
148
+ import "./chunk-XLLUQEGO.js";
145
149
  import {
146
150
  AGENTIC_BEHAVIOR_GUIDELINE,
147
151
  AUTHOR,
@@ -157,7 +161,7 @@ import {
157
161
  SKILLS_DIR_NAME,
158
162
  VERSION,
159
163
  buildUserIdentityPrompt
160
- } from "./chunk-Y7KJPNQI.js";
164
+ } from "./chunk-THHPKZJ3.js";
161
165
  import "./chunk-6RPGQ5CG.js";
162
166
  import "./chunk-KHYD3WXE.js";
163
167
  import "./chunk-NYNSYLFY.js";
@@ -756,30 +760,24 @@ async function handleModel(args, ctx) {
756
760
  ctx.sendStatus();
757
761
  }
758
762
  async function handleThink(args, ctx) {
759
- const sub = args[0]?.toLowerCase() ?? "toggle";
760
- if (sub === "status") {
761
- const configured = ctx.config.get("modelParams")[ctx.currentModel]?.thinking;
762
- const effective = ctx.runtimeThinking ?? configured ?? false;
763
- const origin = ctx.runtimeThinking !== null ? "runtime" : configured !== void 0 ? "config" : "default";
764
- const supportsEffort = ctx.providers.get(ctx.currentProvider)?.supportsReasoningEffort ?? false;
765
- const effortPart = !effective ? "" : supportsEffort ? `; effort: ${ctx.runtimeThinkingEffort ?? ctx.config.get("modelParams")[ctx.currentModel]?.thinkingEffort ?? "high (provider default)"}` : `; effort: n/a for ${ctx.currentProvider}`;
766
- ctx.send({
767
- type: "info",
768
- message: `Thinking mode: ${effective ? "ON" : "OFF"} (${origin})${effortPart}`
769
- });
770
- return;
763
+ const modelParams = ctx.config.get("modelParams")[ctx.currentModel];
764
+ const outcome = applyThinkCommand(args[0], {
765
+ runtimeThinking: ctx.runtimeThinking,
766
+ runtimeEffort: ctx.runtimeThinkingEffort,
767
+ configuredThinking: modelParams?.thinking,
768
+ configuredEffort: modelParams?.thinkingEffort,
769
+ supportsEffort: ctx.providers.get(ctx.currentProvider)?.supportsReasoningEffort ?? false,
770
+ provider: ctx.currentProvider
771
+ });
772
+ if (outcome.changed) {
773
+ ctx.runtimeThinking = outcome.runtimeThinking;
774
+ ctx.runtimeThinkingEffort = outcome.runtimeEffort;
771
775
  }
772
- if (sub === "on") ctx.runtimeThinking = true;
773
- else if (sub === "off") ctx.runtimeThinking = false;
774
- else if (sub === "low" || sub === "high" || sub === "max") {
775
- ctx.runtimeThinking = true;
776
- ctx.runtimeThinkingEffort = sub;
777
- } else ctx.runtimeThinking = ctx.runtimeThinking !== true;
778
776
  ctx.send({
779
777
  type: "info",
780
- message: `Thinking mode: ${ctx.runtimeThinking ? "ON" : "OFF"}${ctx.runtimeThinking ? ` (${ctx.runtimeThinkingEffort ?? "high"})` : ""}`
778
+ message: [outcome.summary, ...outcome.details].join(" \u2014 ")
781
779
  });
782
- ctx.sendStatus();
780
+ if (outcome.changed) ctx.sendStatus();
783
781
  }
784
782
  async function handlePlan(args, ctx) {
785
783
  const sub = args[0];
@@ -837,7 +835,7 @@ Cache: write=${cacheCreate} read=${cacheRead}` : "";
837
835
  Cost: ${formatCost(cost)}` : "";
838
836
  let memoryLine = "";
839
837
  try {
840
- const { countPendingMemories } = await import("./persistent-memory-2DKCETB7.js");
838
+ const { countPendingMemories } = await import("./persistent-memory-HZASMDJQ.js");
841
839
  const pending = countPendingMemories(ctx.config.getConfigDir());
842
840
  if (pending > 0) memoryLine = `
843
841
  Memory: \u26A0 ${pending} pending approval \u2014 see the Memory panel or /memory`;
@@ -1045,18 +1043,16 @@ async function handleExport(args, ctx) {
1045
1043
  }
1046
1044
  async function handleCost(_args, ctx) {
1047
1045
  const u = ctx.sessionTokenUsage;
1048
- const total = u.inputTokens + u.outputTokens + u.cacheCreationTokens + u.cacheReadTokens;
1049
- const cost = computeCost(ctx.currentProvider, ctx.currentModel, u);
1050
- let savings = null;
1051
- if (cost != null && u.cacheReadTokens > 0) {
1052
- const withoutCache = computeCost(ctx.currentProvider, ctx.currentModel, {
1053
- inputTokens: u.inputTokens + u.cacheReadTokens,
1054
- outputTokens: u.outputTokens,
1055
- cacheCreationTokens: u.cacheCreationTokens,
1056
- cacheReadTokens: 0
1057
- });
1058
- if (withoutCache != null) savings = withoutCache - cost;
1059
- }
1046
+ const report = buildSessionCostReport({
1047
+ provider: ctx.currentProvider,
1048
+ model: ctx.currentModel,
1049
+ usage: u,
1050
+ accruedUsd: ctx.sessionAccruedCostUsd,
1051
+ accrualIncomplete: ctx.sessionCostIncomplete
1052
+ });
1053
+ const total = report.totalTokens;
1054
+ const cost = report.cost;
1055
+ const savings = report.savings;
1060
1056
  const lines = [
1061
1057
  "\u{1F4B0} Session Cost & Token Usage",
1062
1058
  ` Provider : ${ctx.currentProvider}`,
@@ -1065,13 +1061,13 @@ async function handleCost(_args, ctx) {
1065
1061
  ` Output : ${u.outputTokens.toLocaleString()}`
1066
1062
  ];
1067
1063
  if (u.cacheCreationTokens > 0) lines.push(` Cache write : ${u.cacheCreationTokens.toLocaleString()}`);
1068
- if (u.cacheReadTokens > 0) {
1069
- const pct = Math.round(u.cacheReadTokens / (u.cacheReadTokens + u.inputTokens) * 100);
1070
- lines.push(` Cache read : ${u.cacheReadTokens.toLocaleString()} (${pct}% hit rate)`);
1064
+ if (report.cacheHitPct != null) {
1065
+ lines.push(` Cache read : ${u.cacheReadTokens.toLocaleString()} (${report.cacheHitPct}% hit rate)`);
1071
1066
  }
1072
1067
  lines.push(` Total tokens : ${total.toLocaleString()}`);
1073
1068
  if (cost != null) {
1074
- lines.push(` Cost : ${formatCost(cost)}`);
1069
+ const note = costSourceNote(report.costSource);
1070
+ lines.push(` Cost : ${formatCost(cost)}${note ? ` ${note}` : ""}`);
1075
1071
  if (savings != null && savings > 0) {
1076
1072
  lines.push(` Cache savings : -${formatCost(savings)} (vs no cache)`);
1077
1073
  }
@@ -1652,7 +1648,7 @@ async function handleTest(args, ctx) {
1652
1648
  const isCommand = argStr.includes(" ") || /^(mvn|gradle|npm|pytest|cargo|go)\b/.test(argStr);
1653
1649
  testArgs = isCommand ? { command: argStr } : { filter: argStr };
1654
1650
  }
1655
- const runTests = ctx.runTests ?? (await import("./run-tests-PWTNSUVP.js")).executeTests;
1651
+ const runTests = ctx.runTests ?? (await import("./run-tests-NTDZ6DDU.js")).executeTests;
1656
1652
  const report = await runTests(testArgs);
1657
1653
  ctx.send({ type: "info", message: report });
1658
1654
  } catch (err) {
@@ -1910,7 +1906,7 @@ async function handleMemory(args, ctx) {
1910
1906
  ctx.handleMemoryManage(sub, args[1], sub === "expire" ? args[2] : void 0);
1911
1907
  } else if (sub === "export") {
1912
1908
  if (args[1] === "md") {
1913
- const { exportMemoryEntries: exportMemoryEntries2 } = await import("./persistent-memory-2DKCETB7.js");
1909
+ const { exportMemoryEntries: exportMemoryEntries2 } = await import("./persistent-memory-HZASMDJQ.js");
1914
1910
  ctx.send({
1915
1911
  type: "export_data",
1916
1912
  format: "md",
@@ -2331,6 +2327,7 @@ var webCommandHandlers = {
2331
2327
  var SessionHandler = class {
2332
2328
  ws;
2333
2329
  config;
2330
+ costTracker;
2334
2331
  providers;
2335
2332
  sessions;
2336
2333
  toolRegistry;
@@ -2344,12 +2341,22 @@ var SessionHandler = class {
2344
2341
  runtimeThinkingEffort = null;
2345
2342
  sessionTokenUsage = { inputTokens: 0, outputTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
2346
2343
  unknownPricingWarnings = /* @__PURE__ */ new Set();
2344
+ /**
2345
+ * 本会话按**调用时刻**费率累计的花费(美元)。
2346
+ * 审计 P2-02 第二批:Web 端此前根本不给 CostTracker 记账,aicli usage 与
2347
+ * monthlyBudget 完全看不到 Web UI 的开销;顺带补上 P3-01 的记账口径。
2348
+ */
2349
+ sessionAccruedCostUsd = 0;
2350
+ sessionCostIncomplete = false;
2347
2351
  /** Accumulate a TokenUsage (with optional cache fields) into sessionTokenUsage. */
2348
2352
  addWebSessionUsage(u) {
2349
2353
  this.sessionTokenUsage.inputTokens += u.inputTokens;
2350
2354
  this.sessionTokenUsage.outputTokens += u.outputTokens;
2351
2355
  this.sessionTokenUsage.cacheCreationTokens += u.cacheCreationTokens ?? 0;
2352
2356
  this.sessionTokenUsage.cacheReadTokens += u.cacheReadTokens ?? 0;
2357
+ const priced = this.costTracker.addCost(this.currentProvider, this.currentModel, u);
2358
+ if (priced === null) this.sessionCostIncomplete = true;
2359
+ else this.sessionAccruedCostUsd += priced;
2353
2360
  const totalTokens = u.inputTokens + u.outputTokens + (u.cacheCreationTokens ?? 0) + (u.cacheReadTokens ?? 0);
2354
2361
  if (totalTokens > 0 && !getPricing(this.currentProvider, this.currentModel)) {
2355
2362
  const key = `${this.currentProvider}/${this.currentModel}`;
@@ -2361,6 +2368,8 @@ var SessionHandler = class {
2361
2368
  }
2362
2369
  resetWebSessionUsage() {
2363
2370
  this.sessionTokenUsage = { inputTokens: 0, outputTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
2371
+ this.sessionAccruedCostUsd = 0;
2372
+ this.sessionCostIncomplete = false;
2364
2373
  }
2365
2374
  abortController = null;
2366
2375
  userInterjection = null;
@@ -2394,6 +2403,7 @@ var SessionHandler = class {
2394
2403
  constructor(ws, shared) {
2395
2404
  this.ws = ws;
2396
2405
  this.config = shared.config;
2406
+ this.costTracker = shared.costTracker;
2397
2407
  this.providers = shared.providers;
2398
2408
  this.sessions = shared.sessions;
2399
2409
  this.toolRegistry = shared.toolRegistry;
@@ -3907,6 +3917,7 @@ async function startWebServer(options = {}) {
3907
3917
  }
3908
3918
  const shared = {
3909
3919
  config,
3920
+ costTracker: new CostTracker(config.getConfigDir()),
3910
3921
  providers,
3911
3922
  sessions,
3912
3923
  toolRegistry,
@@ -4173,6 +4184,8 @@ async function startWebServer(options = {}) {
4173
4184
  const userSessions = new SessionManager(userConfig);
4174
4185
  const userShared = {
4175
4186
  config: userConfig,
4187
+ // 每用户各自的 config 目录 → 各自的 cost-history.json
4188
+ costTracker: new CostTracker(userConfig.getConfigDir()),
4176
4189
  providers,
4177
4190
  // Shared — providers re-read API keys per call
4178
4191
  sessions: userSessions,