@cspeach/cli 1.1.47 → 1.1.48

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.
@@ -598,17 +598,17 @@ export async function runConfigSet(args) {
598
598
  break;
599
599
  }
600
600
  case 'show_cogs': {
601
- // Operator escape hatch — render OUR Anthropic COGS in USD even on a
602
- // managed, metered account (where the customer-facing unit is credits).
603
- // Off/absent is the product default; see cost/display-mode.ts.
601
+ // Operator view — our cost in USD on a managed account. Works only when
602
+ // the server also grants the account `cost_view` (2026-10-19); on its
603
+ // own this setting changes nothing. See cost/display-mode.ts.
604
604
  const b = coerceBool(value);
605
605
  if (b === null) {
606
606
  err(`${key} must be on/off (also accepts true/false, 1/0).`);
607
607
  }
608
608
  cfg.show_cogs = b;
609
609
  console.log(chalk.dim(b
610
- ? ' → cost figures will show USD (our Anthropic cost), not credits.'
611
- : ' → cost figures will show credits on a managed, metered account.'));
610
+ ? ' → applies only to accounts allowed to see costs; everyone else keeps credits.'
611
+ : ' → cost figures show credits.'));
612
612
  break;
613
613
  }
614
614
  case 'word_copy': {
@@ -141,6 +141,7 @@ export async function runCostCommand(sessionId, credits = globalCredits.snapshot
141
141
  emit('');
142
142
  if (inCredits)
143
143
  emit(formatInfo('This month and your top skills: /usage').trimEnd());
144
- emit(formatInfo(`Detailed JSONL: ~/.cspeach/sessions/${sessionId}-cost.jsonl`).trimEnd());
144
+ if (!inCredits)
145
+ emit(formatInfo(`Detailed JSONL: ~/.cspeach/sessions/${sessionId}-cost.jsonl`).trimEnd());
145
146
  emit('');
146
147
  }
@@ -6,6 +6,8 @@ import { DEFAULT_SESSION_MODEL } from './model-defaults.js';
6
6
  import { sanitiseStandaloneProfile } from '../sap/standalone-profile.js';
7
7
  import { DEFAULT_STYLE, parseStyle } from '../agent/style.js';
8
8
  import { DEFAULT_LEVEL, parseLevel } from '../agent/level.js';
9
+ import { setProvisionalCostDisplayMode } from '../cost/credits.js';
10
+ import { provisionalDisplayMode } from '../cost/display-mode.js';
9
11
  /**
10
12
  * Whitelist guard for WriteMode — rejects typos / stale values from disk so
11
13
  * downstream code that trusts the WriteMode type doesn't see garbage.
@@ -148,7 +150,18 @@ export function resolveSapTls(sys) {
148
150
  }
149
151
  /** Tracks whether the one-time legacy-sslVerify deprecation note has printed. */
150
152
  let legacySslVerifyNoticeShown = false;
153
+ /**
154
+ * Load the config, then set the cost display mode it implies until the server
155
+ * answers (2026-10-19). Every command loads the config first, so no path — one
156
+ * that never reaches initCredits included — can show dollars on a managed
157
+ * account by default.
158
+ */
151
159
  export async function loadConfig() {
160
+ const cfg = await readConfig();
161
+ setProvisionalCostDisplayMode(provisionalDisplayMode(cfg));
162
+ return cfg;
163
+ }
164
+ async function readConfig() {
152
165
  try {
153
166
  const raw = await fs.readFile(configFile(), 'utf-8');
154
167
  // Strip a leading UTF-8 BOM (U+FEFF). Node's 'utf-8' read does NOT remove it,
@@ -15,7 +15,7 @@ import fs from 'node:fs/promises';
15
15
  import path from 'node:path';
16
16
  import { sessionsDir } from '../config/paths.js';
17
17
  import { computeCost } from './pricing.js';
18
- import { tokensOnlyActive } from './credits.js';
18
+ import { activeCostDisplayMode } from './credits.js';
19
19
  /**
20
20
  * Task 7 — summarise `message_start.message.input_transformations` (probe P4
21
21
  * shape: `[{ type: 'thinking_dropped', path, reason }]`). Counts the
@@ -56,8 +56,10 @@ export function buildEntry(opts) {
56
56
  turn: opts.turn,
57
57
  model: opts.model,
58
58
  tokens: opts.tokens,
59
- // Azure: no price for the customer's deployment — never consult one.
60
- cost: tokensOnlyActive() ? 0 : computeCost(opts.model, opts.tokens),
59
+ // Only where dollars are shown (own key, or a permitted operator). Credits:
60
+ // this file sits on the customer's disk, so it never holds our cost
61
+ // (2026-10-19). Azure: no price for the customer's deployment.
62
+ cost: activeCostDisplayMode() === 'usd' ? computeCost(opts.model, opts.tokens) : 0,
61
63
  duration_ms: opts.duration_ms,
62
64
  };
63
65
  if (opts.credits) {
@@ -77,7 +79,8 @@ export function buildEntry(opts) {
77
79
  if (opts.input_transformations !== undefined)
78
80
  entry.input_transformations = opts.input_transformations;
79
81
  if (opts.reader && opts.reader.calls > 0) {
80
- entry.reader_cost_usd = Math.round(opts.reader.cost * 10000) / 10000;
82
+ if (activeCostDisplayMode() === 'usd')
83
+ entry.reader_cost_usd = Math.round(opts.reader.cost * 10000) / 10000;
81
84
  entry.reader_calls = opts.reader.calls;
82
85
  }
83
86
  return entry;
@@ -22,7 +22,7 @@
22
22
  * a one-liner and no module has to re-derive the display mode for itself.
23
23
  */
24
24
  import { fetchBalance, globalCredits, setCostDisplayMode, creditsActive, } from './credits.js';
25
- import { costDisplayMode } from './display-mode.js';
25
+ import { costDisplayMode, provisionalDisplayMode } from './display-mode.js';
26
26
  import { globalStore } from '../ui/sap-state-store.js';
27
27
  let wiredCfg = null;
28
28
  let wiredBearer = null;
@@ -39,14 +39,14 @@ function publish() {
39
39
  }
40
40
  /**
41
41
  * Startup: resolve the display mode and seed the opening balance.
42
- * Never throws; on any failure the process stays in USD mode, which is the
43
- * pre-credits behaviour.
42
+ * Never throws. On any failure a managed account stays in credits (2026-10-19:
43
+ * this used to fall back to dollars — our cost on the customer's screen).
44
44
  */
45
45
  export async function initCredits(cfg, getBearer) {
46
46
  try {
47
47
  // Non-managed modes can't be metered by us — skip the round-trip entirely.
48
48
  if (cfg.llm?.mode !== 'managed') {
49
- setCostDisplayMode(cfg.llm?.mode === 'azure' ? 'tokens' : 'usd');
49
+ setCostDisplayMode(provisionalDisplayMode(cfg));
50
50
  return;
51
51
  }
52
52
  const info = await fetchBalance(cfg, getBearer);
@@ -60,8 +60,13 @@ export async function initCredits(cfg, getBearer) {
60
60
  publish();
61
61
  }
62
62
  catch {
63
- // Startup must never be blocked by the meter.
64
- setCostDisplayMode('usd');
63
+ // Startup must never be blocked by the meter — and never shows our cost.
64
+ setCostDisplayMode(provisionalDisplayMode(cfg));
65
+ // The footer reads the store's flag, so publish the mode here too.
66
+ if (creditsActive()) {
67
+ globalCredits.start(null);
68
+ publish();
69
+ }
65
70
  }
66
71
  }
67
72
  /**
@@ -61,6 +61,8 @@ export async function fetchBalance(cfg, getBearer) {
61
61
  };
62
62
  if (b.unprovisioned === true)
63
63
  info.unprovisioned = true;
64
+ if (b.cost_view === true)
65
+ info.cost_view = true;
64
66
  return info;
65
67
  }
66
68
  catch {
@@ -198,9 +200,21 @@ export function formatCreditsLine(s) {
198
200
  */
199
201
  export const globalCredits = new CreditsTracker();
200
202
  let activeMode = 'usd';
203
+ /** True once startup (initCredits) has resolved the mode with the server's answer. */
204
+ let resolved = false;
201
205
  /** Publish the resolved display mode for the whole process. */
202
206
  export function setCostDisplayMode(mode) {
203
207
  activeMode = mode;
208
+ resolved = true;
209
+ }
210
+ /**
211
+ * The mode implied by the config alone, set when the config loads. Applies
212
+ * only until startup resolves the real mode, so a later config reload never
213
+ * overrides the server's answer (2026-10-19).
214
+ */
215
+ export function setProvisionalCostDisplayMode(mode) {
216
+ if (!resolved)
217
+ activeMode = mode;
204
218
  }
205
219
  /** The resolved display mode. Defaults to 'usd' until startup resolves it —
206
220
  * fail-safe for BYOK/local/one-shot paths that never call the setter. */
@@ -218,4 +232,5 @@ export function tokensOnlyActive() {
218
232
  /** Test seam — reset the process-wide mode between cases. */
219
233
  export function resetCostDisplayMode() {
220
234
  activeMode = 'usd';
235
+ resolved = false;
221
236
  }
@@ -15,8 +15,10 @@
15
15
  * - managed but unmetered (or the balance fetch failed): we have no
16
16
  * credit truth to show. Fall back to the existing dollar rendering so
17
17
  * the meter is never blank.
18
- * - `show_cogs = on`: our own operator escape hatch for reading real COGS
19
- * on a managed account (margin analysis, pricing work). Never a default.
18
+ * - `show_cogs = on` AND the server's `cost_view` for this account: our own
19
+ * operator view of real COGS on a managed account (margin analysis,
20
+ * pricing work). The laptop setting alone does nothing (owner 2026-10-19:
21
+ * any customer could type it); the server must say yes as well.
20
22
  *
21
23
  * Callers must treat this as the single source of truth — no site may
22
24
  * re-derive the mode from `cfg.llm.mode` alone.
@@ -28,13 +30,23 @@ export function costDisplayMode(cfg, balanceInfo) {
28
30
  return 'tokens';
29
31
  if (cfg.llm?.mode !== 'managed')
30
32
  return 'usd';
31
- if (cfg.show_cogs === true)
33
+ if (cfg.show_cogs === true && balanceInfo?.cost_view === true)
32
34
  return 'usd';
33
35
  // 2026-09-17 — a managed account NEVER falls back to dollars. Before, a
34
36
  // balance lookup that failed or took over 2.5s at start (slow network on a
35
37
  // customer laptop) dropped the display to USD — our cost on their screen,
36
38
  // exactly what credits mode exists to prevent. Unknown or unmetered
37
39
  // balances render "credits: updating…" until the next good sample.
38
- void balanceInfo;
39
40
  return 'credits';
40
41
  }
42
+ /**
43
+ * The mode before the server has answered — set the moment the config loads,
44
+ * so nothing printed early can show dollars on a managed account.
45
+ */
46
+ export function provisionalDisplayMode(cfg) {
47
+ if (cfg.llm?.mode === 'azure')
48
+ return 'tokens';
49
+ if (cfg.llm?.mode === 'managed')
50
+ return 'credits';
51
+ return 'usd';
52
+ }
@@ -47,7 +47,8 @@ export function largeSessionNotice(sessionInputTokens) {
47
47
  return '';
48
48
  return formatAttention({
49
49
  text: 'session getting large',
50
- fact: `${sessionInputTokens.toLocaleString('en-US')} input tokens`,
50
+ // Credits: no token count beside the credits receipt (owner 2026-10-02).
51
+ fact: creditsActive() ? 'long conversation' : `${sessionInputTokens.toLocaleString('en-US')} input tokens`,
51
52
  next: 'type /compact to summarise older turns, or /exit and start fresh for a new topic',
52
53
  });
53
54
  }
@@ -515,7 +515,10 @@ export function buildAuditReport(input) {
515
515
  else {
516
516
  L(`- **Total:** $${cost.totalCost.toFixed(4)} over ${cost.turns} turn${cost.turns === 1 ? '' : 's'}`);
517
517
  }
518
- L(`- **Tokens:** ${cost.totalTokens.input.toLocaleString('en-US')} in · ${cost.totalTokens.output.toLocaleString('en-US')} out · ${cost.totalTokens.cacheRead.toLocaleString('en-US')} cache-read · ${cost.totalTokens.cacheCreate.toLocaleString('en-US')} cache-write`);
518
+ // Credits: no token counts beside credits (owner 2026-10-02, same as /cost).
519
+ if (!inCredits) {
520
+ L(`- **Tokens:** ${cost.totalTokens.input.toLocaleString('en-US')} in · ${cost.totalTokens.output.toLocaleString('en-US')} out · ${cost.totalTokens.cacheRead.toLocaleString('en-US')} cache-read · ${cost.totalTokens.cacheCreate.toLocaleString('en-US')} cache-write`);
521
+ }
519
522
  if (inCredits && credits?.balance != null) {
520
523
  L(`- **Remaining:** balance ${Math.round(credits.balance).toLocaleString('en-US')}`);
521
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cspeach/cli",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
4
4
  "description": "CSPeach — AI-assisted ABAP development CLI. Direct SAP access, signed skills, safety gates.",
5
5
  "keywords": [
6
6
  "abap",