flagstaff 1.5.0 → 1.7.0

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/README.md CHANGED
@@ -174,6 +174,11 @@ import { table, tableComponent } from 'flagstaff/table';
174
174
  That table is the package's argument in one place. A bar of `█` in a log file tells an agent
175
175
  nothing and tells a screen reader less; the count and the percentage tell both.
176
176
 
177
+ Inside a burgee `--mcp` tool call that asked for progress, `flagstaff/progress` goes one step
178
+ further and draws nothing: it sends its count to the client as `notifications/progress`, with
179
+ the static line as the message. That bridge lives on the subpath only; `progress` from the root
180
+ `flagstaff` entry always draws.
181
+
177
182
  `box` and `table` are also plain string functions, because most callers want the string:
178
183
 
179
184
  ```js
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export * from './loop.js';
12
12
  export * from './box.js';
13
13
  export * from './import.js';
14
14
  export * from './plugin.js';
15
- export * from './progress.js';
15
+ export * from './progress-bar.js';
16
16
  export * from './spinner.js';
17
17
  export * from './table.js';
18
18
  export * from './tasks.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export * from './loop.js';
2
2
  export * from './box.js';
3
3
  export * from './import.js';
4
4
  export * from './plugin.js';
5
- export * from './progress.js';
5
+ export * from './progress-bar.js';
6
6
  export * from './spinner.js';
7
7
  export * from './table.js';
8
8
  export * from './tasks.js';
@@ -0,0 +1,22 @@
1
+ import { type Component } from './plugin.js';
2
+ export interface ProgressState {
3
+ /** Units done so far; clamped into `[0, total]` on the way out. */
4
+ done: number;
5
+ total: number;
6
+ /** What is being counted, e.g. `files`. Read in both projections. */
7
+ label?: string;
8
+ }
9
+ export interface ProgressOptions {
10
+ /** Cells the bar occupies on a terminal. Default 24. */
11
+ width?: number;
12
+ /** The two characters the bar is drawn with. Default `█` and `░`. */
13
+ glyphs?: {
14
+ filled: string;
15
+ empty: string;
16
+ };
17
+ }
18
+ /**
19
+ * A progress bar: `12/30 files · 40%` off a terminal, a drawn bar on one. This is the root entry's,
20
+ * which always draws; `flagstaff/progress` reports to an MCP client instead, inside a call that asked.
21
+ */
22
+ export declare function progress({ width, glyphs }?: ProgressOptions): Component<ProgressState>;
@@ -0,0 +1,25 @@
1
+ import { muted, ok } from 'roundel/tokens';
2
+ const DEFAULT_WIDTH = 24;
3
+ const PERCENT = 100;
4
+ const FILLED = '█';
5
+ const EMPTY = '░';
6
+ function ratio(state) {
7
+ if (state.total <= 0)
8
+ return 1;
9
+ return Math.min(1, Math.max(0, state.done / state.total));
10
+ }
11
+ function suffix(state) {
12
+ const label = state.label === undefined || state.label === '' ? '' : ` ${state.label}`;
13
+ return `${state.done}/${state.total}${label}`;
14
+ }
15
+ const percentage = (state) => `${Math.round(ratio(state) * PERCENT)}%`;
16
+ export function progress({ width = DEFAULT_WIDTH, glyphs = { filled: FILLED, empty: EMPTY } } = {}) {
17
+ return {
18
+ name: 'progress',
19
+ static: (state) => `${suffix(state)} · ${percentage(state)}`,
20
+ frame: (_t, state) => {
21
+ const filled = Math.round(ratio(state) * width);
22
+ return `${ok(glyphs.filled.repeat(filled))}${muted(glyphs.empty.repeat(Math.max(0, width - filled)))} ${suffix(state)}`;
23
+ },
24
+ };
25
+ }
@@ -1,19 +1,19 @@
1
+ /**
2
+ * The progress bar, which reports to an MCP client instead of drawing when it runs inside a
3
+ * burgee `--mcp` tool call that asked for progress (mcp-current R5).
4
+ *
5
+ * A bar drawn into an agent's tool result is noise the agent has to read past; the same count
6
+ * sent as `notifications/progress` is what the client shows its user while the call runs. burgee's
7
+ * server publishes the call it is serving under `Symbol.for('burgee.mcp')`, and its `progress` is
8
+ * the call's `ctx.progress`: it sends with the call's token, and drops a value that does not rise.
9
+ * So the bar reads the symbol on every render, not once, and imports nothing of burgee's.
10
+ * Anywhere else — no server, or a call without a `progressToken` — it draws as it always has.
11
+ *
12
+ * Only this subpath carries the bridge. The root `flagstaff` entry's `progress` always draws:
13
+ * every flagstaff user pays for the root, and only a program served over MCP needs this.
14
+ */
1
15
  import { type Component } from './plugin.js';
2
- export interface ProgressState {
3
- /** Units done so far; clamped into `[0, total]` on the way out. */
4
- done: number;
5
- total: number;
6
- /** What is being counted, e.g. `files`. Read in both projections. */
7
- label?: string;
8
- }
9
- export interface ProgressOptions {
10
- /** Cells the bar occupies on a terminal. Default 24. */
11
- width?: number;
12
- /** The two characters the bar is drawn with. Default `█` and `░`. */
13
- glyphs?: {
14
- filled: string;
15
- empty: string;
16
- };
17
- }
18
- /** A progress bar: `12/30 files · 40%` off a terminal, a drawn bar on one. */
19
- export declare function progress({ width, glyphs }?: ProgressOptions): Component<ProgressState>;
16
+ import { type ProgressOptions, type ProgressState } from './progress-bar.js';
17
+ /** A progress bar: `12/30 files · 40%` off a terminal, a drawn bar on one, and MCP progress inside a call that asked. */
18
+ export declare function progress(options?: ProgressOptions): Component<ProgressState>;
19
+ export type { ProgressOptions, ProgressState } from './progress-bar.js';
package/dist/progress.js CHANGED
@@ -1,25 +1,20 @@
1
- import { muted, ok } from 'roundel/tokens';
2
- const DEFAULT_WIDTH = 24;
3
- const PERCENT = 100;
4
- const FILLED = '█';
5
- const EMPTY = '░';
6
- function ratio(state) {
7
- if (state.total <= 0)
8
- return 1;
9
- return Math.min(1, Math.max(0, state.done / state.total));
10
- }
11
- function suffix(state) {
12
- const label = state.label === undefined || state.label === '' ? '' : ` ${state.label}`;
13
- return `${state.done}/${state.total}${label}`;
14
- }
15
- const percentage = (state) => `${Math.round(ratio(state) * PERCENT)}%`;
16
- export function progress({ width = DEFAULT_WIDTH, glyphs = { filled: FILLED, empty: EMPTY } } = {}) {
1
+ import { progress as bar } from './progress-bar.js';
2
+ const sender = () => Reflect.get(globalThis, Symbol.for('burgee.mcp'))?.()?.progress;
3
+ export function progress(options) {
4
+ const drawn = bar(options);
5
+ const report = (state) => {
6
+ const send = sender();
7
+ if (send === undefined)
8
+ return undefined;
9
+ if (state.total > 0)
10
+ send(Math.min(Math.max(0, state.done), state.total), state.total, drawn.static(state));
11
+ else
12
+ send(state.done, undefined, drawn.static(state));
13
+ return '';
14
+ };
17
15
  return {
18
- name: 'progress',
19
- static: (state) => `${suffix(state)} · ${percentage(state)}`,
20
- frame: (_t, state) => {
21
- const filled = Math.round(ratio(state) * width);
22
- return `${ok(glyphs.filled.repeat(filled))}${muted(glyphs.empty.repeat(Math.max(0, width - filled)))} ${suffix(state)}`;
23
- },
16
+ name: drawn.name,
17
+ static: (state) => report(state) ?? drawn.static(state),
18
+ frame: (t, state) => report(state) ?? drawn.frame(t, state),
24
19
  };
25
20
  }
@@ -8,6 +8,11 @@ export interface Writer {
8
8
  * TTY stream carries it, and a writer without it is taken to be `DEFAULT_COLUMNS` wide.
9
9
  */
10
10
  readonly columns?: number | undefined;
11
+ /**
12
+ * How tall the terminal is, read at every paint like the width (frames-fit-the-screen R1).
13
+ * A writer without it — a pipe — is unbounded, and no frame is clipped.
14
+ */
15
+ readonly rows?: number | undefined;
11
16
  }
12
17
  /** Time as the loop sees it: burgee's `Runtime.clock` satisfies it, so does `manualClock()`. */
13
18
  export interface Clock {
@@ -29,7 +34,9 @@ export declare const DEFAULT_INTERVAL = 80;
29
34
  *
30
35
  * Between paints the cursor rests at the end of the frame's last row, which is where the
31
36
  * hoisted projection has always left it. A frame taller than the terminal cannot be reached
32
- * above its top row; that is the terminal's limit, and a caller lays out within its height.
37
+ * above its top row, so one is clipped (frames-fit-the-screen R2): its tail, the lines that
38
+ * change, under one dim `… N more` line. `release` then writes the whole frame once, because
39
+ * a final write needs no repaint, so nothing the frame held is lost to the clip.
33
40
  */
34
41
  export interface FrameWriter {
35
42
  paint(lines: readonly string[]): void;
@@ -1,6 +1,7 @@
1
1
  import { onExit } from 'closeout';
2
2
  import { HIDE_CURSOR, SHOW_CURSOR } from 'closeout/cursor';
3
3
  import { lineCount } from 'linegauge';
4
+ import { muted } from 'roundel/tokens';
4
5
  export const DEFAULT_INTERVAL = 80;
5
6
  const DEFAULT_COLUMNS = 80;
6
7
  const CSI = '\u001B[';
@@ -40,20 +41,38 @@ function diff(was, now, sameWidth) {
40
41
  }
41
42
  export function frameWriter(out) {
42
43
  let shown;
43
- let width = 0;
44
+ let whole;
45
+ let size = '';
46
+ const write = (bytes) => {
47
+ if (bytes !== '')
48
+ out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
49
+ };
44
50
  return {
45
51
  paint(lines) {
46
- const frame = lines.length === 0 ? [''] : [...lines];
52
+ let frame = lines.length === 0 ? [''] : [...lines];
47
53
  const columns = columnsOf(out);
48
- const now = { lines: frame, rows: frame.map((line) => lineCount(line, columns)) };
49
- const bytes = shown === undefined ? frame.join('\n') : diff(shown, now, columns === width);
54
+ const tall = (out.rows ?? 0) > 0 ? out.rows : Number.POSITIVE_INFINITY;
55
+ const heights = () => frame.map((line) => lineCount(line, columns));
56
+ let rows = heights();
57
+ whole = undefined;
58
+ if (rows.reduce((sum, n) => sum + n, 0) > tall) {
59
+ let cut = frame.length;
60
+ for (let used = 1; cut > 0 && (used += rows[cut - 1]) <= tall;)
61
+ cut -= 1;
62
+ whole = frame;
63
+ frame = [muted(`… ${cut} more`), ...frame.slice(cut)];
64
+ rows = heights();
65
+ }
66
+ const now = { lines: frame, rows };
67
+ const at = `${columns} ${tall}`;
68
+ write(shown === undefined ? frame.join('\n') : diff(shown, now, at === size));
69
+ size = at;
50
70
  shown = now;
51
- width = columns;
52
- if (bytes !== '')
53
- out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
54
71
  },
55
72
  release() {
56
- shown = undefined;
73
+ if (shown !== undefined && whole !== undefined)
74
+ write(diff(shown, { lines: whole, rows: [] }, false));
75
+ shown = whole = undefined;
57
76
  },
58
77
  };
59
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagstaff",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Spinners, progress, boxes and tables on one terminal frame loop, with a static projection for pipes, screen readers and agents, and a plugin host. No dependency outside the burgee family. Drop-in paths for ora, log-update, boxen and cli-table3.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -143,7 +143,7 @@
143
143
  "dependencies": {
144
144
  "closeout": "^1.1.3",
145
145
  "linegauge": "^1.1.1",
146
- "paratext": "^1.0.6",
146
+ "paratext": "^1.0.7",
147
147
  "roundel": "^1.1.1"
148
148
  },
149
149
  "devDependencies": {