flagstaff 1.4.0 → 1.6.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 +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/ora.js +12 -4
- package/dist/progress-bar.d.ts +22 -0
- package/dist/progress-bar.js +25 -0
- package/dist/progress.d.ts +18 -18
- package/dist/progress.js +17 -22
- package/package.json +3 -3
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';
|
package/dist/ora.js
CHANGED
|
@@ -77,6 +77,7 @@ const FALLBACK_INTERVAL = 100;
|
|
|
77
77
|
const DEFAULT_COLUMNS = 80;
|
|
78
78
|
const TRUNCATION_RESERVE = 1;
|
|
79
79
|
const activeHooksPerStream = new Map();
|
|
80
|
+
const writeHooks = new WeakMap();
|
|
80
81
|
const validColors = new Set(['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray']);
|
|
81
82
|
function paint(color, text) {
|
|
82
83
|
if (color === undefined || color === false)
|
|
@@ -428,13 +429,20 @@ export class Ora {
|
|
|
428
429
|
console.warn('[ora] Multiple concurrent spinners detected. This may cause visual corruption. Use one spinner at a time.');
|
|
429
430
|
}
|
|
430
431
|
const originalWrite = stream.write;
|
|
431
|
-
|
|
432
|
+
const record = { wrapped: originalWrite, live: true };
|
|
433
|
+
const hook = (chunk, encoding, callback) => record.live ? this.#hookedWrite(stream, originalWrite, chunk, encoding, callback) : originalWrite.call(stream, chunk, encoding, callback);
|
|
434
|
+
writeHooks.set(hook, record);
|
|
435
|
+
this.#hookedStreams.set(stream, hook);
|
|
432
436
|
activeHooksPerStream.set(stream, this);
|
|
433
|
-
stream.write =
|
|
437
|
+
stream.write = hook;
|
|
434
438
|
}
|
|
435
439
|
#uninstallHook() {
|
|
436
|
-
for (const [stream,
|
|
437
|
-
|
|
440
|
+
for (const [stream, hook] of this.#hookedStreams) {
|
|
441
|
+
const record = writeHooks.get(hook);
|
|
442
|
+
if (record)
|
|
443
|
+
record.live = false;
|
|
444
|
+
for (let top = writeHooks.get(stream.write); top && !top.live; top = writeHooks.get(stream.write))
|
|
445
|
+
stream.write = top.wrapped;
|
|
438
446
|
if (activeHooksPerStream.get(stream) === this)
|
|
439
447
|
activeHooksPerStream.delete(stream);
|
|
440
448
|
}
|
|
@@ -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
|
+
}
|
package/dist/progress.d.ts
CHANGED
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
19
|
-
static: (state) =>
|
|
20
|
-
frame: (
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flagstaff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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",
|
|
@@ -141,9 +141,9 @@
|
|
|
141
141
|
"json"
|
|
142
142
|
],
|
|
143
143
|
"dependencies": {
|
|
144
|
-
"closeout": "^1.1.
|
|
144
|
+
"closeout": "^1.1.3",
|
|
145
145
|
"linegauge": "^1.1.1",
|
|
146
|
-
"paratext": "^1.0.
|
|
146
|
+
"paratext": "^1.0.7",
|
|
147
147
|
"roundel": "^1.1.1"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|