aiden-runtime 4.1.3 → 4.1.5

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.
@@ -30,8 +30,8 @@ exports.PREVIOUS_BUNDLED_SOULS = exports.DEFAULT_SOUL_MD = exports.BUNDLED_SOUL_
30
30
  // <act_dont_ask>. ensureSoulMdSeeded compares this against the user's
31
31
  // on-disk SOUL.md to decide whether to silent-replace (matches a prior
32
32
  // bundled default) or preserve+notify (user-edited).
33
- exports.BUNDLED_SOUL_VERSION = 'v4.1.2';
34
- exports.DEFAULT_SOUL_MD = `You are Aiden — a local-first AI agent built by Taracod.
33
+ exports.BUNDLED_SOUL_VERSION = 'v4.1.5';
34
+ exports.DEFAULT_SOUL_MD = `You are Aiden — a local-first AI agent built by Shiva Deore at Taracod.
35
35
 
36
36
  Identity:
37
37
  - You run on the user's machine, native Windows/Linux/macOS (not WSL2).
@@ -40,13 +40,14 @@ Identity:
40
40
  - You have 40 tools spanning files, browser, terminal, web, memory.
41
41
 
42
42
  Voice:
43
- - Direct. No fluff. Match the user's energy.
43
+ - Match the user's energy. When the user asks a thoughtful question (opinion, exploration, comparison), engage thoughtfully. When the user asks transactionally, stay tight.
44
+ - On thoughtful questions, share the reasoning before the answer — what you considered, what you discarded, why.
44
45
  - Honest above all — if you didn't do something, say so. If you're not sure, say so.
45
46
  - You never claim to "have run" a tool unless the trace shows it.
46
47
 
47
48
  Behavior:
48
49
  - Default to action over discussion. The user wants results.
49
- - When asked who you are, identify as Aiden. Not "a large language model."
50
+ - When asked who you are, identify as Aiden, built by Shiva Deore at Taracod. Not "a large language model."
50
51
  - When asked what you can do, mention specific skills/tools, not generic capabilities.
51
52
  - If user mentions trading/NSE/markets, you have specialized skills for that.
52
53
 
@@ -254,5 +255,143 @@ Limits:
254
255
  - You're a CLI agent in v4.0.0. No voice, no scheduled jobs, no messaging gateway yet — those are v4.1.
255
256
  - You can't bypass approval prompts for dangerous commands.
256
257
  - You don't lie to look smart. If you don't know, you say so.
258
+ `,
259
+ // v4.1.2 default — shipped through v4.1.3 (no SOUL change in v4.1.3).
260
+ // v4.1.4 rewrites the Voice block to make conciseness conditional:
261
+ // thoughtful questions get thoughtful engagement, transactional
262
+ // questions stay tight. Adds an explicit reasoning-visibility line.
263
+ // Users on the v4.1.2 / v4.1.3 install have this verbatim text on
264
+ // disk; silent-upgrade picks them up here.
265
+ `You are Aiden — a local-first AI agent built by Taracod.
266
+
267
+ Identity:
268
+ - You run on the user's machine, native Windows/Linux/macOS (not WSL2).
269
+ - You have 72 bundled skills + access to install more via skills.sh.
270
+ - You remember past sessions via persistent storage.
271
+ - You have 40 tools spanning files, browser, terminal, web, memory.
272
+
273
+ Voice:
274
+ - Direct. No fluff. Match the user's energy.
275
+ - Honest above all — if you didn't do something, say so. If you're not sure, say so.
276
+ - You never claim to "have run" a tool unless the trace shows it.
277
+
278
+ Behavior:
279
+ - Default to action over discussion. The user wants results.
280
+ - When asked who you are, identify as Aiden. Not "a large language model."
281
+ - When asked what you can do, mention specific skills/tools, not generic capabilities.
282
+ - If user mentions trading/NSE/markets, you have specialized skills for that.
283
+
284
+ <act_dont_ask>
285
+ When a request has an obvious default interpretation, act on it
286
+ immediately instead of asking for clarification. Examples:
287
+ - "play me a popular song" / "play X on youtube" → load skill_view(media-search)
288
+ and follow it. Substitute fuzzy phrases ("popular song") with a specific
289
+ chart-topper BEFORE searching, then open_url a /watch?v= URL once.
290
+ NEVER search verbatim "popular song" — that returns articles, not music.
291
+ - "what files are in my Downloads?" → file_list on Downloads. Don't ask
292
+ "which user?" — it's the current user.
293
+ - "is port 443 open?" → check this machine. Don't ask "open where?"
294
+ Only ask for clarification when the ambiguity genuinely changes which
295
+ tool you would call.
296
+ </act_dont_ask>
297
+
298
+ <prerequisite_checks>
299
+ Before acting, check whether prerequisite discovery, lookup, or
300
+ context-gathering steps are needed. If a step depends on output from a
301
+ prior step, resolve that dependency first. Don't skip prerequisite
302
+ steps just because the final action seems obvious.
303
+ </prerequisite_checks>
304
+
305
+ <missing_context>
306
+ If required context is missing, do NOT guess or hallucinate. Use the
307
+ appropriate lookup tool when missing information is retrievable
308
+ (file_read, file_list, web_search, fetch_url, session_search,
309
+ system_info). Ask a clarifying question ONLY when no tool can resolve
310
+ the ambiguity.
311
+ </missing_context>
312
+
313
+ <keep_going>
314
+ Work autonomously until the task is fully resolved. Don't stop with a
315
+ plan — execute it. Multi-step tasks (open browser → search → click
316
+ result; or list files → read each → summarise) are expected; chain
317
+ the tool calls within a single turn instead of returning halfway and
318
+ asking the user what to do next.
319
+ </keep_going>
320
+
321
+ Limits:
322
+ - You can't bypass approval prompts for dangerous commands.
323
+ - You don't lie to look smart. If you don't know, you say so.
324
+ `,
325
+ // v4.1.4 default — Voice rewrite ("Match the user's energy. When the
326
+ // user asks a thoughtful question…") + EXECUTION_DISCIPLINE_PROSE
327
+ // softening. Identity attribution still "built by Taracod" only —
328
+ // v4.1.5 adds "Shiva Deore at" to both identity lines. Users who
329
+ // installed any v4.1.4.x build have this verbatim text on disk;
330
+ // silent-upgrade picks them up here.
331
+ //
332
+ // CATCH-UP NOTE: this entry was inadvertently omitted from the
333
+ // v4.1.4 ship (the snapshot appended at that time matched v4.1.2's
334
+ // Voice block, not the v4.1.4 rewrite). v4.1.5 appends it so the
335
+ // migration path catches v4.1.4 installs correctly.
336
+ `You are Aiden — a local-first AI agent built by Taracod.
337
+
338
+ Identity:
339
+ - You run on the user's machine, native Windows/Linux/macOS (not WSL2).
340
+ - You have 72 bundled skills + access to install more via skills.sh.
341
+ - You remember past sessions via persistent storage.
342
+ - You have 40 tools spanning files, browser, terminal, web, memory.
343
+
344
+ Voice:
345
+ - Match the user's energy. When the user asks a thoughtful question (opinion, exploration, comparison), engage thoughtfully. When the user asks transactionally, stay tight.
346
+ - On thoughtful questions, share the reasoning before the answer — what you considered, what you discarded, why.
347
+ - Honest above all — if you didn't do something, say so. If you're not sure, say so.
348
+ - You never claim to "have run" a tool unless the trace shows it.
349
+
350
+ Behavior:
351
+ - Default to action over discussion. The user wants results.
352
+ - When asked who you are, identify as Aiden. Not "a large language model."
353
+ - When asked what you can do, mention specific skills/tools, not generic capabilities.
354
+ - If user mentions trading/NSE/markets, you have specialized skills for that.
355
+
356
+ <act_dont_ask>
357
+ When a request has an obvious default interpretation, act on it
358
+ immediately instead of asking for clarification. Examples:
359
+ - "play me a popular song" / "play X on youtube" → load skill_view(media-search)
360
+ and follow it. Substitute fuzzy phrases ("popular song") with a specific
361
+ chart-topper BEFORE searching, then open_url a /watch?v= URL once.
362
+ NEVER search verbatim "popular song" — that returns articles, not music.
363
+ - "what files are in my Downloads?" → file_list on Downloads. Don't ask
364
+ "which user?" — it's the current user.
365
+ - "is port 443 open?" → check this machine. Don't ask "open where?"
366
+ Only ask for clarification when the ambiguity genuinely changes which
367
+ tool you would call.
368
+ </act_dont_ask>
369
+
370
+ <prerequisite_checks>
371
+ Before acting, check whether prerequisite discovery, lookup, or
372
+ context-gathering steps are needed. If a step depends on output from a
373
+ prior step, resolve that dependency first. Don't skip prerequisite
374
+ steps just because the final action seems obvious.
375
+ </prerequisite_checks>
376
+
377
+ <missing_context>
378
+ If required context is missing, do NOT guess or hallucinate. Use the
379
+ appropriate lookup tool when missing information is retrievable
380
+ (file_read, file_list, web_search, fetch_url, session_search,
381
+ system_info). Ask a clarifying question ONLY when no tool can resolve
382
+ the ambiguity.
383
+ </missing_context>
384
+
385
+ <keep_going>
386
+ Work autonomously until the task is fully resolved. Don't stop with a
387
+ plan — execute it. Multi-step tasks (open browser → search → click
388
+ result; or list files → read each → summarise) are expected; chain
389
+ the tool calls within a single turn instead of returning halfway and
390
+ asking the user what to do next.
391
+ </keep_going>
392
+
393
+ Limits:
394
+ - You can't bypass approval prompts for dangerous commands.
395
+ - You don't lie to look smart. If you don't know, you say so.
257
396
  `,
258
397
  ];
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 Shiva Deore (Taracod).
4
+ * Licensed under AGPL-3.0. See LICENSE for details.
5
+ *
6
+ * Aiden — local-first agent.
7
+ */
8
+ /**
9
+ * cli/v4/display/frame.ts — Phase v4.1.4 reply-quality polish (Part 1.5).
10
+ *
11
+ * Single source of truth for the reply-frame math: terminal width,
12
+ * left gutter, body width, indent-by-depth, and ANSI-aware soft wrap.
13
+ *
14
+ * Before this module the same width formula
15
+ * (`Math.min(out.columns ?? 80, 100)`) lived at 4 different sites with
16
+ * inconsistent offsets, no shared floor, and no actual wrap engine —
17
+ * `marked-terminal` has `reflowText: false` so long prose just spilled
18
+ * to terminal-natural wrap (continuation lines at column 0, not at the
19
+ * gutter). frame.ts replaces all four with one formula and one wrapper.
20
+ *
21
+ * Public surface:
22
+ * - GUTTER 3-col left gutter (assistant body)
23
+ * - BODY_WIDTH_MAX 100 (tunable cap; export so future skin/theme
24
+ * work can override without touching consumers)
25
+ * - getTerminalCols() live `process.stdout.columns` with 80 fallback
26
+ * - getBodyWidth() `max(20, cols - gutter - 2)` capped at
27
+ * `BODY_WIDTH_MAX - gutter - 2`
28
+ * - getIndent(depth) `' '.repeat(GUTTER + depth*2)` — gutter +
29
+ * depth-aware. depth=0 = bare gutter, depth=1 =
30
+ * gutter+2, etc.
31
+ * - wrap(text, opts) ANSI-aware soft wrap via wrap-ansi defaults
32
+ * `{ trim: false, hard: true }`. Returns string
33
+ * with embedded `\n` per wrap point.
34
+ * - applyFrame(body) convenience: indents every line of `body` by
35
+ * GUTTER. No wrap (caller pre-wraps to bodyWidth).
36
+ *
37
+ * Wrap engine: wrap-ansi@9 (ESM-only). Loaded via cached dynamic
38
+ * `import()` so a CJS TypeScript build can still consume it. Until the
39
+ * first wrap finishes resolving, `wrap()` falls back to a passthrough
40
+ * that preserves the input verbatim — wrong visual but never incorrect
41
+ * data. Boot-time prime via `primeFrameAsync()` (best-effort) so the
42
+ * first user-visible wrap call already has the module loaded.
43
+ */
44
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
45
+ if (k2 === undefined) k2 = k;
46
+ var desc = Object.getOwnPropertyDescriptor(m, k);
47
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
48
+ desc = { enumerable: true, get: function() { return m[k]; } };
49
+ }
50
+ Object.defineProperty(o, k2, desc);
51
+ }) : (function(o, m, k, k2) {
52
+ if (k2 === undefined) k2 = k;
53
+ o[k2] = m[k];
54
+ }));
55
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
56
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
57
+ }) : function(o, v) {
58
+ o["default"] = v;
59
+ });
60
+ var __importStar = (this && this.__importStar) || (function () {
61
+ var ownKeys = function(o) {
62
+ ownKeys = Object.getOwnPropertyNames || function (o) {
63
+ var ar = [];
64
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
65
+ return ar;
66
+ };
67
+ return ownKeys(o);
68
+ };
69
+ return function (mod) {
70
+ if (mod && mod.__esModule) return mod;
71
+ var result = {};
72
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
73
+ __setModuleDefault(result, mod);
74
+ return result;
75
+ };
76
+ })();
77
+ Object.defineProperty(exports, "__esModule", { value: true });
78
+ exports.BODY_WIDTH_MIN = exports.BODY_WIDTH_MAX = exports.GUTTER = void 0;
79
+ exports.getTerminalCols = getTerminalCols;
80
+ exports.getBodyWidth = getBodyWidth;
81
+ exports.getIndent = getIndent;
82
+ exports.primeFrameAsync = primeFrameAsync;
83
+ exports.wrap = wrap;
84
+ exports.applyFrame = applyFrame;
85
+ exports._resetForTests = _resetForTests;
86
+ exports._injectWrapForTests = _injectWrapForTests;
87
+ // ── Tunable constants ─────────────────────────────────────────────────
88
+ /**
89
+ * Left gutter for assistant body. 3 columns matches the visual rhythm
90
+ * established by the boot card, tool trail, and status footer once
91
+ * Part 1.5 lands. Was 2 before this slice — bumped one column so the
92
+ * body breathes against the left edge.
93
+ */
94
+ exports.GUTTER = 3;
95
+ /**
96
+ * Maximum body width before the visual frame stops growing. Wide
97
+ * terminals (150+ cols) get a body capped at this minus gutter+2
98
+ * because long lines (~120 chars) are harder to read than mid-length
99
+ * (~70-90 chars). Tunable: skin or theme code can override.
100
+ */
101
+ exports.BODY_WIDTH_MAX = 100;
102
+ /**
103
+ * Hard floor on body width. Below this we render at 20 cols and let
104
+ * the terminal-natural wrap pick up the rest — better than crashing
105
+ * with a negative-width wrap-ansi call on a 5-col terminal.
106
+ */
107
+ exports.BODY_WIDTH_MIN = 20;
108
+ // ── Width helpers ─────────────────────────────────────────────────────
109
+ /**
110
+ * Live terminal column count. Reads `process.stdout.columns` on every
111
+ * call so resize events propagate without us needing a cache. Falls
112
+ * back to 80 when the stream is non-TTY or hasn't reported a size yet
113
+ * (pipes, CI logs, MCP serve).
114
+ *
115
+ * `out` override exists for testability — display.test.ts injects a
116
+ * fake stream with explicit `columns` to assert various widths.
117
+ */
118
+ function getTerminalCols(out = process.stdout) {
119
+ const c = out.columns;
120
+ if (typeof c !== 'number' || !Number.isFinite(c) || c < 1)
121
+ return 80;
122
+ return c;
123
+ }
124
+ /**
125
+ * Computed body width — the safe horizontal space inside the frame.
126
+ * Math: `min(BODY_WIDTH_MAX, cols) - GUTTER - 2`. The trailing `-2`
127
+ * leaves visual breathing room on the right margin (mirrors the boot
128
+ * card / tool-row right-pad convention). Floored at BODY_WIDTH_MIN so
129
+ * pathological narrow terminals still get a usable wrap.
130
+ */
131
+ function getBodyWidth(out = process.stdout) {
132
+ const cols = Math.min(getTerminalCols(out), exports.BODY_WIDTH_MAX);
133
+ const raw = cols - exports.GUTTER - 2;
134
+ return Math.max(exports.BODY_WIDTH_MIN, raw);
135
+ }
136
+ /**
137
+ * Indent string for the given nesting depth. Depth 0 = bare gutter
138
+ * (3 spaces). Each additional level adds 2 spaces. Used by list,
139
+ * blockquote, and code-block renderers so every element shares one
140
+ * indent algebra.
141
+ */
142
+ function getIndent(depth = 0) {
143
+ const d = Math.max(0, Math.floor(depth));
144
+ return ' '.repeat(exports.GUTTER + d * 2);
145
+ }
146
+ let cachedWrap = null;
147
+ let primePromise = null;
148
+ /**
149
+ * Best-effort load of wrap-ansi. Idempotent. Safe to call from boot.
150
+ * Returns a promise that resolves once the module is loaded (or
151
+ * rejects silently — wrap() will just keep using the passthrough).
152
+ */
153
+ function primeFrameAsync() {
154
+ if (cachedWrap)
155
+ return Promise.resolve();
156
+ if (primePromise)
157
+ return primePromise;
158
+ primePromise = (async () => {
159
+ try {
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ const mod = await Promise.resolve().then(() => __importStar(require('wrap-ansi')));
162
+ const fn = (mod.default ?? mod);
163
+ if (typeof fn === 'function')
164
+ cachedWrap = fn;
165
+ }
166
+ catch {
167
+ // Swallow — fallback is a passthrough, never crashes.
168
+ }
169
+ })();
170
+ return primePromise;
171
+ }
172
+ // Kick off the import at module load. Best effort — if it fails (e.g.
173
+ // missing dep, broken install) we degrade to passthrough.
174
+ primeFrameAsync();
175
+ /**
176
+ * ANSI-aware soft wrap. Defaults `{ trim: false, hard: true }`:
177
+ * - trim: false → preserves leading/trailing whitespace on each
178
+ * visual line (important for code-block indent + alignment).
179
+ * - hard: true → break extremely long words mid-character at width
180
+ * instead of overflowing. Code blocks especially need this.
181
+ *
182
+ * Pure with respect to ANSI: escape sequences pass through wrap-ansi
183
+ * untouched and don't count toward the column budget.
184
+ *
185
+ * Synchronous. When wrap-ansi hasn't finished loading yet (the rare
186
+ * boot-race window), returns `text` unchanged. The user sees the
187
+ * un-wrapped paint exactly once; by the next render the cache is hot.
188
+ */
189
+ function wrap(text, cols, options = {}) {
190
+ const w = cachedWrap;
191
+ if (!w)
192
+ return text;
193
+ const opts = { trim: options.trim ?? false, hard: options.hard ?? true };
194
+ try {
195
+ return w(text, cols, opts);
196
+ }
197
+ catch {
198
+ return text;
199
+ }
200
+ }
201
+ /**
202
+ * Indent every line of `body` by the bare gutter. Empty lines are
203
+ * passed through unindented so blank visual rows don't carry
204
+ * trailing whitespace into the transcript.
205
+ *
206
+ * Caller is responsible for pre-wrapping to `getBodyWidth()` — this
207
+ * function is purely the indent step, not the wrap step. Keeping them
208
+ * separate so callers that already have their own indent (lists,
209
+ * code blocks) can opt out of this and still consume `wrap()`.
210
+ */
211
+ function applyFrame(body) {
212
+ const ind = getIndent(0);
213
+ return body
214
+ .split('\n')
215
+ .map((ln) => (ln.length === 0 ? '' : `${ind}${ln}`))
216
+ .join('\n');
217
+ }
218
+ /**
219
+ * Test reset — drops the cached wrap function so a fresh prime can be
220
+ * forced. Used by unit tests to exercise the fallback path AND to
221
+ * confirm post-prime behaviour.
222
+ */
223
+ function _resetForTests() {
224
+ cachedWrap = null;
225
+ primePromise = null;
226
+ }
227
+ /**
228
+ * Test injection — set the wrap function explicitly. Used by tests
229
+ * that want deterministic behaviour without depending on dynamic
230
+ * `import()` resolution timing.
231
+ */
232
+ function _injectWrapForTests(fn) {
233
+ cachedWrap = fn;
234
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 Shiva Deore (Taracod).
4
+ * Licensed under AGPL-3.0. See LICENSE for details.
5
+ *
6
+ * Aiden — local-first agent.
7
+ */
8
+ /**
9
+ * cli/v4/display/progressBar.ts — Phase v4.1.4 Part 1.6.
10
+ *
11
+ * Per-turn token progress bar. Renders `▰▰▰▰▰▱▱▱▱▱ 412/4096 tokens`
12
+ * on a single line below the activity indicator (or in place of it,
13
+ * once the stream takes over). Event-driven: each `update(n, max)`
14
+ * call redraws the bar with the new counter — no `setInterval`,
15
+ * because the source of truth is the adapter's incremental
16
+ * `progress` stream events, which already fire at the granularity
17
+ * the model produces tokens.
18
+ *
19
+ * Honest degradation: if the adapter never calls `update()`, the bar
20
+ * never paints. No client-side estimation (per v4.1.4 spec — token
21
+ * count only, no time-based fakery).
22
+ *
23
+ * Visual:
24
+ *
25
+ * ▰▰▰▰▰▱▱▱▱▱ 412/4096 tokens
26
+ * │└────┬───┘ └────┬─────┘
27
+ * │ │ └── current/max (compact via formatCompactTokens)
28
+ * │ └── 10 cells, filled ratio ∝ outputTokens/maxTokens
29
+ * └── leading gutter aligns with frame
30
+ *
31
+ * Bar cells:
32
+ * - filled: ▰ (U+25B0, dark shade block-fill)
33
+ * - empty: ▱ (U+25B1, light shade)
34
+ *
35
+ * Cursor invariant on render: bar OWNS one line. After each `update`
36
+ * the cursor sits at column 0 of the bar line (single-line `\r\x1b[K`
37
+ * overwrite pattern, same as activityIndicator). Callers that want to
38
+ * write OTHER content below MUST call `hide()` first.
39
+ *
40
+ * Non-TTY: completely silent — pipes/CI/MCP serve mode get clean
41
+ * output by default. The handle still accepts updates so callers
42
+ * don't need to branch on TTY-ness.
43
+ */
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.createProgressBar = createProgressBar;
46
+ const frame_1 = require("./frame");
47
+ const display_1 = require("../display");
48
+ /**
49
+ * Number of bar cells. 10 cells gives clean fractions (every 10% of
50
+ * fill ratio == one cell). Wider bars feel noisy at the standard
51
+ * frame width (75 visible cols on an 80-col terminal).
52
+ */
53
+ const BAR_CELLS = 10;
54
+ /** Glyphs. Chosen for clean visual weight at the standard mono font. */
55
+ // v4.1.5 Phase 1d (Q-P1) — glyph palette switch.
56
+ //
57
+ // Was `▰` (U+25B0 BLACK RECTANGLE) + `▱` (U+25B1 WHITE RECTANGLE),
58
+ // from Unicode's "Geometric Shapes" block. NOT in CP437; Windows
59
+ // legacy console fonts (Lucida Console / Consolas defaults) render
60
+ // them as tofu boxes. User visual smoke confirmed the regression
61
+ // on Windows Terminal + ConPTY combinations.
62
+ //
63
+ // New: `▓` (U+2593 DARK SHADE) + `░` (U+2591 LIGHT SHADE), from
64
+ // Unicode's "Block Elements" block AND CP437 — universally
65
+ // supported on every Windows console going back to DOS. Same shade
66
+ // family the existing `statusFooter` (display.ts:773) has shipped
67
+ // with since v3 without ever being garbled. Cleaner palette
68
+ // coherence across all bar surfaces.
69
+ const FILLED = '▓';
70
+ const EMPTY = '░';
71
+ /**
72
+ * Create a progress-bar handle bound to a writable stream + skin.
73
+ * The bar paints on the next `update` call — there's no initial
74
+ * paint at creation time, because we don't know the token counts yet.
75
+ *
76
+ * `out` is the stream to write on (usually `process.stdout` via
77
+ * `Display.out`). `skin` is the active skin engine. Both are captured
78
+ * by closure — the handle survives skin swaps for the rest of the turn.
79
+ */
80
+ function createProgressBar(out, skin) {
81
+ const isTty = !!out.isTTY;
82
+ let outputTokens = 0;
83
+ let maxTokens = undefined;
84
+ let printed = false;
85
+ let hidden = false;
86
+ let lastPaintTokens = -1;
87
+ const buildLine = () => {
88
+ // Fill ratio: 0..1, then snap to a cell count 0..BAR_CELLS.
89
+ const denom = maxTokens && maxTokens > 0 ? maxTokens : 0;
90
+ const ratio = denom > 0 ? Math.min(1, outputTokens / denom) : 0;
91
+ const filled = Math.min(BAR_CELLS, Math.round(ratio * BAR_CELLS));
92
+ const empty = BAR_CELLS - filled;
93
+ const bar = skin.applyColors(FILLED.repeat(filled), 'brand') +
94
+ skin.applyColors(EMPTY.repeat(empty), 'muted');
95
+ // Label: compact "412/4096 tokens". If no maxTokens, render
96
+ // "412 tokens" (denominator unknown). The model name doesn't
97
+ // belong here — that's the status footer's job post-turn.
98
+ const left = (0, display_1.formatCompactTokens)(outputTokens);
99
+ const right = denom > 0 ? (0, display_1.formatCompactTokens)(denom) : '?';
100
+ const label = denom > 0
101
+ ? skin.applyColors(`${left}/${right} tokens`, 'muted')
102
+ : skin.applyColors(`${left} tokens`, 'muted');
103
+ const gutter = (0, frame_1.getIndent)(0);
104
+ return `${gutter}${bar} ${label}`;
105
+ };
106
+ // v4.1.5 Part 1a — Issue M (Windows ConPTY buffering fix).
107
+ //
108
+ // Mirrors the activityIndicator pattern: the bar OWNS one terminal
109
+ // row. Every paint ends with `\n` so the buffer flushes; the cursor
110
+ // sits on the row BELOW the bar while it's visible. Erase walks
111
+ // up + clears the bar's row, leaving the cursor at col 0 of the
112
+ // now-empty row for the caller's next write. See activityIndicator
113
+ // for the full rationale (Windows ConPTY buffers no-newline writes
114
+ // until a `\n` arrives — without this, long-running stream paints
115
+ // never visually appeared).
116
+ const ANSI_UP_ERASE = '\x1b[1A\x1b[2K';
117
+ const paint = () => {
118
+ if (!isTty || hidden)
119
+ return;
120
+ if (printed) {
121
+ // Subsequent paint: walk up to the bar's row, clear it, rewrite,
122
+ // drop a newline so the cursor lands on the row BELOW the bar.
123
+ out.write(`${ANSI_UP_ERASE}${buildLine()}\n`);
124
+ }
125
+ else {
126
+ // First paint: just write the bar + `\n`. Cursor moves to the
127
+ // row below, ready for subsequent walk-up-and-erase ticks.
128
+ out.write(`${buildLine()}\n`);
129
+ printed = true;
130
+ }
131
+ lastPaintTokens = outputTokens;
132
+ };
133
+ const erase = () => {
134
+ // Walk up to the bar's row and clear it. No trailing `\n` — the
135
+ // caller will write content here and include its own newline.
136
+ if (isTty && printed)
137
+ out.write(ANSI_UP_ERASE);
138
+ };
139
+ return {
140
+ update(n, max) {
141
+ if (hidden)
142
+ return;
143
+ // Coerce + clamp. Non-finite or negative inputs are ignored —
144
+ // never crash the stream consumer with a malformed event.
145
+ if (typeof n === 'number' && Number.isFinite(n) && n >= 0) {
146
+ outputTokens = Math.floor(n);
147
+ }
148
+ if (typeof max === 'number' && Number.isFinite(max) && max > 0) {
149
+ maxTokens = Math.floor(max);
150
+ }
151
+ // Dedup: skip the repaint if the visible state didn't change.
152
+ // Anthropic emits message_delta events with the SAME running
153
+ // counter when no new tokens were produced; without this
154
+ // gate we'd flicker on every duplicate.
155
+ if (outputTokens === lastPaintTokens && printed)
156
+ return;
157
+ paint();
158
+ },
159
+ hide() {
160
+ if (hidden)
161
+ return;
162
+ hidden = true;
163
+ erase();
164
+ },
165
+ isHidden() { return hidden; },
166
+ getTokens() {
167
+ return { output: outputTokens, max: maxTokens };
168
+ },
169
+ };
170
+ }