warden-agent 0.4.0 → 0.4.1

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.
@@ -93,16 +93,38 @@ export function toolBody(c, display, { error, denied } = {}) {
93
93
 
94
94
  // ---- spinner -----------------------------------------------------------------
95
95
 
96
+ // One status line, redrawn in place. label may be a function (re-evaluated on every frame); extra() adds text after it
97
+ // (e.g. what you are typing). The line is cut to the terminal width: a wrapped line could not be redrawn in place.
96
98
  export class Spinner {
97
- constructor(out = process.stdout, c = C) { this.out = out; this.c = c; this.timer = null; this.frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; }
99
+ constructor(out = process.stdout, c = C, { hint = "", extra = null } = {}) {
100
+ this.out = out; this.c = c; this.timer = null; this.hint = hint; this.extra = extra; this.i = 0;
101
+ this.frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
102
+ }
103
+ get running() { return !!this.timer; }
104
+ elapsed() { return this.t0 ? Date.now() - this.t0 : 0; }
98
105
  start(label = "Thinking") {
106
+ this.label = label;
99
107
  if (!this.out.isTTY || this.timer) return;
100
- this.t0 = Date.now(); this.label = label; let i = 0;
101
- const draw = () => { const s = Math.floor((Date.now() - this.t0) / 1000); this.out.write(`\r\x1b[2K ${this.c.accent(this.frames[i++ % this.frames.length])} ${this.c.dim(`${this.label}… ${s}s · ctrl+c to interrupt`)}`); };
102
- draw(); this.timer = setInterval(draw, 90);
108
+ this.t0 = Date.now();
109
+ this.draw(); this.timer = setInterval(() => this.draw(), 90);
110
+ }
111
+ draw() {
112
+ const s = Math.floor(this.elapsed() / 1000);
113
+ const label = typeof this.label === "function" ? this.label() : this.label;
114
+ let body = `${label}… ${s}s${this.hint ? " · " + this.hint : ""}${this.extra?.() || ""}`.replace(/[\r\n\t]+/g, " ");
115
+ const room = Math.max(20, (this.out.columns || 80) - 6);
116
+ if (body.length > room) body = body.slice(0, room - 1) + "…";
117
+ this.out.write(`\r\x1b[2K ${this.c.accent(this.frames[this.i++ % this.frames.length])} ${this.c.dim(body)}`);
103
118
  }
104
119
  setLabel(l) { this.label = l; }
120
+ // print a full line above the spinner without breaking it
121
+ print(line) {
122
+ if (!this.timer) { this.out.write(line + "\n"); return; }
123
+ this.out.write("\r\x1b[2K" + line + "\n"); this.draw();
124
+ }
105
125
  stop() { if (!this.timer) return; clearInterval(this.timer); this.timer = null; this.out.write("\r\x1b[2K"); }
106
126
  }
107
127
 
128
+ export const stripAnsi = (s) => String(s).replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
129
+
108
130
  export const fmtTokens = (n) => (n >= 1000 ? (n / 1000).toFixed(1) + "k" : String(n));
package/src/version.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  // Keep in sync with package.json (test/meta.mock.mjs checks this).
2
- export const VERSION = "0.4.0";
2
+ export const VERSION = "0.4.1";
3
3
  export const PACKAGE = "warden-agent";
4
4
  export const REPO = "yashhonap/warden";