@kjanat/dreamcli 2.4.0 → 2.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.4.1] - 2026-06-27
11
+
12
+ ### Fixed
13
+
14
+ - **Destructuring `out` and activity handles** — `Out` methods and the spinner/progress activity
15
+ handle methods are now bound to their instance, so pulling them off via destructuring (e.g.
16
+ `const { done } = handle`) no longer breaks `this`-dependent behaviour and cleanup
17
+ (https://github.com/kjanat/dreamcli/pull/40).
18
+
10
19
  ## [2.4.0] - 2026-06-23
11
20
 
12
21
  ### Added
@@ -829,7 +838,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
829
838
  - MIT License.
830
839
  - Markdownlint configuration.
831
840
 
832
- [Unreleased]: https://github.com/kjanat/dreamcli/compare/v2.4.0...HEAD
841
+ [Unreleased]: https://github.com/kjanat/dreamcli/compare/v2.4.1...HEAD
842
+ [2.4.1]: https://github.com/kjanat/dreamcli/compare/v2.4.0...v2.4.1
833
843
  [2.4.0]: https://github.com/kjanat/dreamcli/compare/v2.3.0...v2.4.0
834
844
  [2.3.0]: https://github.com/kjanat/dreamcli/compare/v2.2.1...v2.3.0
835
845
  [2.2.1]: https://github.com/kjanat/dreamcli/compare/v2.2.0...v2.2.1
@@ -1 +1 @@
1
- import{writeLine as e}from"./writer.mjs";const t={update(){},succeed(){},fail(){},stop(){},wrap(e){return e}},n={increment(){},update(){},done(){},fail(){}};var r=class{write;stopped=!1;constructor(t,n){this.write=n,e(n,t)}update(e){}succeed(t){this.stopped||(this.stopped=!0,t!==void 0&&e(this.write,t))}fail(t){this.stopped||(this.stopped=!0,t!==void 0&&e(this.write,t))}stop(){this.stopped||=!0}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},i=class{write;stopped=!1;constructor(t,n){this.write=n,t!==void 0&&e(n,t)}increment(e){}update(e){}done(t){this.stopped||(this.stopped=!0,t!==void 0&&e(this.write,t))}fail(t){this.stopped||(this.stopped=!0,t!==void 0&&e(this.write,t))}};const a=`\x1B[?25l`,o=`\x1B[?25h`,s=`\x1B[2K`,c=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];var l=class{write;stopped=!1;timer;frameIndex=0;text;constructor(e,t){this.write=t,this.text=e,t(a),this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%c.length,this.render()},80)}render(){let e=c[this.frameIndex]??c[0];this.write(`\r${s}${e} ${this.text}`)}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${s}${o}`)}update(e){this.stopped||(this.text=e,this.render())}succeed(t){this.stopped||(this.stopped=!0,this.cleanup(),t!==void 0&&e(this.write,`✓ ${t}`))}fail(t){this.stopped||(this.stopped=!0,this.cleanup(),t!==void 0&&e(this.write,`✗ ${t}`))}stop(){this.stopped||(this.stopped=!0,this.cleanup())}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},u=class{write;stopped=!1;timer;current=0;total;label;pulsePos=0;pulseDir=1;constructor(e,t){this.write=t,this.total=e.total,this.label=e.label??``,t(a),this.render(),this.total===void 0&&(this.timer=setInterval(()=>{this.advancePulse(),this.render()},80))}advancePulse(){this.pulsePos+=this.pulseDir,this.pulsePos+3>20?(this.pulseDir=-1,this.pulsePos=17):this.pulsePos<0&&(this.pulseDir=1,this.pulsePos=0)}render(){let e=this.total===void 0?this.renderIndeterminate():this.renderDeterminate(this.total),t=this.label.length>0?` ${this.label}`:``;this.write(`\r${s}${e}${t}`)}renderDeterminate(e){let t=e>0?Math.max(0,Math.min(this.current/e,1)):0,n=Math.round(t*20),r=20-n,i=Math.round(t*100);return`[${`█`.repeat(n)}${`░`.repeat(r)}] ${String(i)}%`}renderIndeterminate(){let e=``;for(let t=0;t<20;t++)e+=t>=this.pulsePos&&t<this.pulsePos+3?`█`:`░`;return`[${e}]`}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${s}${o}`)}increment(e){this.stopped||(this.current+=e??1,this.render())}update(e){this.stopped||(this.current=e,this.render())}done(t){this.stopped||(this.stopped=!0,this.cleanup(),t!==void 0&&e(this.write,`✓ ${t}`))}fail(t){this.stopped||(this.stopped=!0,this.cleanup(),t!==void 0&&e(this.write,`✗ ${t}`))}},d=class{events;stopped=!1;constructor(e,t){this.events=t,t.push({type:`spinner:start`,text:e})}update(e){this.stopped||this.events.push({type:`spinner:update`,text:e})}succeed(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:succeed`,text:e??``}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:fail`,text:e??``}))}stop(){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:stop`}))}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},f=class{events;stopped=!1;constructor(e,t){this.events=t,t.push({type:`progress:start`,label:e.label??``,total:e.total})}increment(e){this.stopped||this.events.push({type:`progress:increment`,delta:e??1})}update(e){this.stopped||this.events.push({type:`progress:update`,value:e})}done(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:done`,text:e}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:fail`,text:e}))}};export{f as CaptureProgressHandle,d as CaptureSpinnerHandle,i as StaticProgressHandle,r as StaticSpinnerHandle,u as TTYProgressHandle,l as TTYSpinnerHandle,n as noopProgressHandle,t as noopSpinnerHandle};
1
+ import{bindMethods as e}from"./bind.mjs";import{writeLine as t}from"./writer.mjs";const n={update(){},succeed(){},fail(){},stop(){},wrap(e){return e}},r={increment(){},update(){},done(){},fail(){}};var i=class{write;stopped=!1;constructor(n,r){this.write=r,t(r,n),e(this)}update(e){}succeed(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}stop(){this.stopped||=!0}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},a=class{write;stopped=!1;constructor(n,r){this.write=r,n!==void 0&&t(r,n),e(this)}increment(e){}update(e){}done(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}fail(e){this.stopped||(this.stopped=!0,e!==void 0&&t(this.write,e))}};const o=`\x1B[?25l`,s=`\x1B[?25h`,c=`\x1B[2K`,l=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];var u=class{write;stopped=!1;timer;frameIndex=0;text;constructor(t,n){this.write=n,this.text=t,n(o),this.render(),this.timer=setInterval(()=>{this.frameIndex=(this.frameIndex+1)%l.length,this.render()},80),e(this)}render(){let e=l[this.frameIndex]??l[0];this.write(`\r${c}${e} ${this.text}`)}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${c}${s}`)}update(e){this.stopped||(this.text=e,this.render())}succeed(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✗ ${e}`))}stop(){this.stopped||(this.stopped=!0,this.cleanup())}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},d=class{write;stopped=!1;timer;current=0;total;label;pulsePos=0;pulseDir=1;constructor(t,n){this.write=n,this.total=t.total,this.label=t.label??``,n(o),this.render(),this.total===void 0&&(this.timer=setInterval(()=>{this.advancePulse(),this.render()},80)),e(this)}advancePulse(){this.pulsePos+=this.pulseDir,this.pulsePos+3>20?(this.pulseDir=-1,this.pulsePos=17):this.pulsePos<0&&(this.pulseDir=1,this.pulsePos=0)}render(){let e=this.total===void 0?this.renderIndeterminate():this.renderDeterminate(this.total),t=this.label.length>0?` ${this.label}`:``;this.write(`\r${c}${e}${t}`)}renderDeterminate(e){let t=e>0?Math.max(0,Math.min(this.current/e,1)):0,n=Math.round(t*20),r=20-n,i=Math.round(t*100);return`[${`█`.repeat(n)}${`░`.repeat(r)}] ${String(i)}%`}renderIndeterminate(){let e=``;for(let t=0;t<20;t++)e+=t>=this.pulsePos&&t<this.pulsePos+3?`█`:`░`;return`[${e}]`}cleanup(){this.timer!==void 0&&(clearInterval(this.timer),this.timer=void 0),this.write(`\r${c}${s}`)}increment(e){this.stopped||(this.current+=e??1,this.render())}update(e){this.stopped||(this.current=e,this.render())}done(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✓ ${e}`))}fail(e){this.stopped||(this.stopped=!0,this.cleanup(),e!==void 0&&t(this.write,`✗ ${e}`))}},f=class{events;stopped=!1;constructor(t,n){this.events=n,n.push({type:`spinner:start`,text:t}),e(this)}update(e){this.stopped||this.events.push({type:`spinner:update`,text:e})}succeed(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:succeed`,text:e??``}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:fail`,text:e??``}))}stop(){this.stopped||(this.stopped=!0,this.events.push({type:`spinner:stop`}))}async wrap(e,t){try{let n=await e;return this.succeed(t?.succeed),n}catch(e){throw this.fail(t?.fail),e}}},p=class{events;stopped=!1;constructor(t,n){this.events=n,n.push({type:`progress:start`,label:t.label??``,total:t.total}),e(this)}increment(e){this.stopped||this.events.push({type:`progress:increment`,delta:e??1})}update(e){this.stopped||this.events.push({type:`progress:update`,value:e})}done(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:done`,text:e}))}fail(e){this.stopped||(this.stopped=!0,this.events.push({type:`progress:fail`,text:e}))}};export{p as CaptureProgressHandle,f as CaptureSpinnerHandle,a as StaticProgressHandle,i as StaticSpinnerHandle,d as TTYProgressHandle,u as TTYSpinnerHandle,r as noopProgressHandle,n as noopSpinnerHandle};
@@ -0,0 +1,37 @@
1
+ //#region src/core/output/bind.d.ts
2
+ /**
3
+ * Method-binding helper for value objects handed to consumers.
4
+ *
5
+ * Output value objects — the `Out` channel and the spinner/progress handles
6
+ * — expose methods that read instance state via `this`. Consumers naturally
7
+ * detach those methods, either by destructuring
8
+ * (`const { log } = out` / `const { succeed, fail } = spinner`) or by passing
9
+ * them as callbacks (`promise.finally(spinner.stop)`). Detached, an unbound
10
+ * prototype method loses its `this` and crashes on the first field access.
11
+ *
12
+ * {@linkcode bindMethods} eliminates that footgun by installing instance-bound
13
+ * copies of every method, so the ergonomic usage is also the correct one.
14
+ *
15
+ * @module dreamcli/core/output/bind
16
+ * @internal
17
+ */
18
+ /**
19
+ * Bind every method on an instance's prototype chain to the instance.
20
+ *
21
+ * Walks the prototype chain up to (but excluding) `Object.prototype`, binding
22
+ * each method name exactly once — the most-derived definition wins, so subclass
23
+ * overrides (e.g. `CaptureOutputChannel.spinner`) are preserved rather than
24
+ * clobbered by a base-class version. Bound methods are installed as
25
+ * non-enumerable own properties, mirroring the enumerability of the prototype
26
+ * methods they shadow. Getters and non-function members are left untouched.
27
+ *
28
+ * Call this once, last, in a class constructor. Because it reads the live
29
+ * prototype rather than a hand-maintained name list, methods added later are
30
+ * bound automatically — the binding can't silently fall out of date.
31
+ *
32
+ * @param instance - The object whose methods should be bound to it.
33
+ * @internal
34
+ */
35
+ declare function bindMethods(instance: object): void;
36
+ //#endregion
37
+ export { bindMethods };
@@ -0,0 +1 @@
1
+ function e(e){let t=e,n=new Set,r=Object.getPrototypeOf(e);for(;r!==null&&r!==Object.prototype;){for(let i of Object.getOwnPropertyNames(r)){if(i===`constructor`||n.has(i))continue;n.add(i);let a=Object.getOwnPropertyDescriptor(r,i);a===void 0||typeof a.value!=`function`||Object.defineProperty(t,i,{value:a.value.bind(e),writable:!0,enumerable:!1,configurable:!0})}r=Object.getPrototypeOf(r)}}export{e as bindMethods};
@@ -1,2 +1,2 @@
1
- import{formatDisplayValue as e}from"./display-value.mjs";import{writeLine as t}from"./writer.mjs";import{CaptureProgressHandle as n,CaptureSpinnerHandle as r}from"./activity.mjs";import{resolveOutputPolicy as i,resolveProgressPolicy as a,resolveSpinnerPolicy as o,resolveTableFormat as s,resolveTableTextStream as c,resolveTextStream as l,shouldEmitInfo as u}from"./contracts.mjs";import{createProgressHandleFromPolicy as d,createSpinnerHandleFromPolicy as f,resolveWriterForStream as p}from"./renderers.mjs";const m=()=>{},h=new WeakMap;function g(e){if(!Number.isInteger(e)||e<0||e>255)throw RangeError(`Exit code must be an integer from 0 to 255`);return e}function _(e,t){h.set(e,g(t))}function v(e){return h.get(e)}function y(e){h.delete(e)}function b(e){return{stdout:e?.stdout??m,stderr:e?.stderr??m,isTTY:e?.isTTY??!1,verbosity:e?.verbosity??`normal`,jsonMode:e?.jsonMode??!1}}var x=class{options;policy;jsonMode;isTTY;constructor(e){this.options=e,this.policy=i(e),this.jsonMode=e.jsonMode,this.isTTY=e.isTTY}log(e){t(p(this.options,l(this.policy)),e)}info(e){u(this.policy)&&t(p(this.options,l(this.policy)),e)}warn(e){t(this.options.stderr,e)}error(e){t(this.options.stderr,e)}setExitCode(e){_(this,e)}json(e){t(this.options.stdout,JSON.stringify(e))}table(e,n,r){let{columns:i,options:a}=T(n,r),o=s(this.policy,a),c=i??C(e);if(o===`json`){this.json(E(e,c));return}let l=k(e,c);l.length!==0&&t(D(this.options,this.policy,o,a),l)}activeCleanup;stopActive(){this.activeCleanup!==void 0&&(this.activeCleanup(),this.activeCleanup=void 0)}spinner(e,t){let n=f(o(this.policy,t?.fallback??`silent`),e,this.options.stderr);return n.cleanup===void 0?n.handle:(this.stopActive(),this.activeCleanup=n.cleanup,n.handle)}progress(e){let t=d(a(this.policy,e.fallback??`silent`),e,this.options.stderr);return t.cleanup===void 0?t.handle:(this.stopActive(),this.activeCleanup=t.cleanup,t.handle)}},S=class extends x{activity;constructor(e,t){super(e),this.activity=t}spinner(e,t){return new r(e,this.activity)}progress(e){return new n(e,this.activity)}};function C(e){let t=e[0];return t===void 0?[]:Object.keys(t).map(e=>({key:e}))}function w(e){return Array.isArray(e)}function T(e,t){return t===void 0?w(e)?{columns:e,options:t}:{columns:void 0,options:e}:{columns:w(e)?e:void 0,options:t}}function E(e,t){return e.map(e=>Object.fromEntries(t.map(t=>[t.key,e[t.key]])))}function D(e,t,n,r){return n===`json`?e.stdout:p(e,c(t,r))}function O(t){return e(t)}function k(e,t){if(e.length===0||t.length===0)return``;let n=t.map(e=>e.header??e.key),r=e.map(e=>t.map(t=>O(e[t.key]))),i=n.map((e,t)=>{let n=e.length;for(let e of r){let r=e[t];r!==void 0&&r.length>n&&(n=r.length)}return n});return[n.map((e,t)=>e.padEnd(i[t]??0)).join(` `),i.map(e=>`-`.repeat(e)).join(` `),...r.map(e=>e.map((e,t)=>e.padEnd(i[t]??0)).join(` `))].join(`
2
- `)}function A(e){return new x(b(e))}function j(e){let t={stdout:[],stderr:[],activity:[]};return[new S(b({...e,stdout:e=>t.stdout.push(e),stderr:e=>t.stderr.push(e)}),t.activity),t]}export{y as clearRequestedExitCode,j as createCaptureOutput,A as createOutput,v as getRequestedExitCode};
1
+ import{formatDisplayValue as e}from"./display-value.mjs";import{bindMethods as t}from"./bind.mjs";import{writeLine as n}from"./writer.mjs";import{CaptureProgressHandle as r,CaptureSpinnerHandle as i}from"./activity.mjs";import{resolveOutputPolicy as a,resolveProgressPolicy as o,resolveSpinnerPolicy as s,resolveTableFormat as c,resolveTableTextStream as l,resolveTextStream as u,shouldEmitInfo as d}from"./contracts.mjs";import{createProgressHandleFromPolicy as f,createSpinnerHandleFromPolicy as p,resolveWriterForStream as m}from"./renderers.mjs";const h=()=>{},g=new WeakMap;function _(e){if(!Number.isInteger(e)||e<0||e>255)throw RangeError(`Exit code must be an integer from 0 to 255`);return e}function v(e,t){g.set(e,_(t))}function y(e){return g.get(e)}function b(e){g.delete(e)}function x(e){return{stdout:e?.stdout??h,stderr:e?.stderr??h,isTTY:e?.isTTY??!1,verbosity:e?.verbosity??`normal`,jsonMode:e?.jsonMode??!1}}var S=class{options;policy;jsonMode;isTTY;constructor(e){this.options=e,this.policy=a(e),this.jsonMode=e.jsonMode,this.isTTY=e.isTTY,t(this)}log(e){n(m(this.options,u(this.policy)),e)}info(e){d(this.policy)&&n(m(this.options,u(this.policy)),e)}warn(e){n(this.options.stderr,e)}error(e){n(this.options.stderr,e)}setExitCode(e){v(this,e)}json(e){n(this.options.stdout,JSON.stringify(e))}table(e,t,r){let{columns:i,options:a}=E(t,r),o=c(this.policy,a),s=i??w(e);if(o===`json`){this.json(D(e,s));return}let l=A(e,s);l.length!==0&&n(O(this.options,this.policy,o,a),l)}activeCleanup;stopActive(){this.activeCleanup!==void 0&&(this.activeCleanup(),this.activeCleanup=void 0)}spinner(e,t){let n=p(s(this.policy,t?.fallback??`silent`),e,this.options.stderr);return n.cleanup===void 0?n.handle:(this.stopActive(),this.activeCleanup=n.cleanup,n.handle)}progress(e){let t=f(o(this.policy,e.fallback??`silent`),e,this.options.stderr);return t.cleanup===void 0?t.handle:(this.stopActive(),this.activeCleanup=t.cleanup,t.handle)}},C=class extends S{activity;constructor(e,t){super(e),this.activity=t}spinner(e,t){return new i(e,this.activity)}progress(e){return new r(e,this.activity)}};function w(e){let t=e[0];return t===void 0?[]:Object.keys(t).map(e=>({key:e}))}function T(e){return Array.isArray(e)}function E(e,t){return t===void 0?T(e)?{columns:e,options:t}:{columns:void 0,options:e}:{columns:T(e)?e:void 0,options:t}}function D(e,t){return e.map(e=>Object.fromEntries(t.map(t=>[t.key,e[t.key]])))}function O(e,t,n,r){return n===`json`?e.stdout:m(e,l(t,r))}function k(t){return e(t)}function A(e,t){if(e.length===0||t.length===0)return``;let n=t.map(e=>e.header??e.key),r=e.map(e=>t.map(t=>k(e[t.key]))),i=n.map((e,t)=>{let n=e.length;for(let e of r){let r=e[t];r!==void 0&&r.length>n&&(n=r.length)}return n});return[n.map((e,t)=>e.padEnd(i[t]??0)).join(` `),i.map(e=>`-`.repeat(e)).join(` `),...r.map(e=>e.map((e,t)=>e.padEnd(i[t]??0)).join(` `))].join(`
2
+ `)}function j(e){return new S(x(e))}function M(e){let t={stdout:[],stderr:[],activity:[]};return[new C(x({...e,stdout:e=>t.stdout.push(e),stderr:e=>t.stderr.push(e)}),t.activity),t]}export{b as clearRequestedExitCode,M as createCaptureOutput,j as createOutput,y as getRequestedExitCode};
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- const e=`2.4.0`,t=`9e1ac50`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
1
+ const e=`2.4.1`,t=`a683cd2`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kjanat/dreamcli",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Schema-first, fully typed TypeScript CLI framework",
5
5
  "keywords": [
6
6
  "dreamcli",
@@ -10,7 +10,7 @@
10
10
  "schema-first",
11
11
  "command-line"
12
12
  ],
13
- "homepage": "https://dreamcli.kjanat.com",
13
+ "homepage": "https://dreamcli.kjanat.dev",
14
14
  "bugs": {
15
15
  "url": "https://github.com/kjanat/dreamcli/issues"
16
16
  },
@@ -73,15 +73,17 @@
73
73
  "./examples/*"
74
74
  ],
75
75
  "scripts": {
76
- "bd": "bunx --bun tsdown",
77
- "build": "bunx --bun tsdown",
78
- "build:watch": "bunx --bun tsdown --watch",
76
+ "bd": "run build",
77
+ "build": "bun --bun tsdown",
78
+ "build:watch": "run build --watch",
79
79
  "ci": "run -pk typecheck lint format:check meta-descriptions:check test docs:build bd",
80
80
  "coverage": "vitest run --coverage",
81
- "dev": "bunx --bun tsdown --logLevel silent --watch & bunx --bun vitepress@next dev docs --host --port ${PORT:-5173} & wait",
82
- "docs:build": "bunx --bun vitepress@next build docs",
83
- "docs:dev": "bunx --bun vitepress@next dev docs",
84
- "docs:preview": "bunx --bun vitepress@next preview docs",
81
+ "dev": "run -p build:watch docs:dev",
82
+ "docs:build": "bun --bun vitepress build docs",
83
+ "docs:deploy": "wrangler deploy",
84
+ "docs:dev": "bun --bun vitepress dev docs --host --port ${PORT:-5173}",
85
+ "docs:preview": "bun --bun vitepress preview docs",
86
+ "docs:upload": "wrangler versions upload",
85
87
  "fmt": "dprint fmt",
86
88
  "fmt:autofix": "dprint fmt --allow-no-files --excludes .github",
87
89
  "fmt:update": "dprint config update --yes --recursive",
@@ -99,11 +101,11 @@
99
101
  "lint:fix": "biome lint --fix",
100
102
  "meta-descriptions": "bun --bun scripts/build-meta-descriptions.ts",
101
103
  "meta-descriptions:check": "bun --bun scripts/build-meta-descriptions.ts --check",
102
- "prepack": "bunx --bun tsdown --logLevel silent",
104
+ "prepack": "bun --bun tsdown --logLevel silent",
103
105
  "publish:preview": "bunx pkg-pr-new publish --bun --comment=update --packageManager=bun,npm",
104
106
  "schema:emit": "bun scripts/emit-definition-schema.ts",
105
107
  "test": "vitest run",
106
- "test:bun": "bunx --bun vitest run",
108
+ "test:bun": "bun --bun vitest run",
107
109
  "test:gh": "run --dir examples/gh test",
108
110
  "test:node": "npx -y vitest run",
109
111
  "test:watch": "vitest",
@@ -159,8 +161,8 @@
159
161
  }
160
162
  },
161
163
  "volta": {
162
- "node": "25.9.0",
163
- "npm": "11.12.1"
164
+ "node": "26.3.1",
165
+ "npm": "11.17.0"
164
166
  },
165
167
  "publishConfig": {
166
168
  "access": "public",
@@ -21,6 +21,7 @@ import type {
21
21
  ProgressOptions,
22
22
  SpinnerHandle,
23
23
  } from '#internals/core/schema/activity.ts';
24
+ import { bindMethods } from './bind.ts';
24
25
  import type { WriteFn } from './writer.ts';
25
26
  import { writeLine } from './writer.ts';
26
27
 
@@ -90,6 +91,7 @@ class StaticSpinnerHandle implements SpinnerHandle {
90
91
  private readonly write: WriteFn,
91
92
  ) {
92
93
  writeLine(write, text);
94
+ bindMethods(this);
93
95
  }
94
96
 
95
97
  update(_text: string): void {
@@ -153,6 +155,7 @@ class StaticProgressHandle implements ProgressHandle {
153
155
  if (label !== undefined) {
154
156
  writeLine(write, label);
155
157
  }
158
+ bindMethods(this);
156
159
  }
157
160
 
158
161
  increment(_n?: number): void {
@@ -263,6 +266,7 @@ class TTYSpinnerHandle implements SpinnerHandle {
263
266
  this.frameIndex = (this.frameIndex + 1) % SPINNER_FRAMES.length;
264
267
  this.render();
265
268
  }, SPINNER_INTERVAL_MS);
269
+ bindMethods(this);
266
270
  }
267
271
 
268
272
  /** Render the current frame + text, overwriting the current line. */
@@ -372,6 +376,7 @@ class TTYProgressHandle implements ProgressHandle {
372
376
  this.render();
373
377
  }, PULSE_INTERVAL_MS);
374
378
  }
379
+ bindMethods(this);
375
380
  }
376
381
 
377
382
  /** Advance the indeterminate pulse position with bounce logic. */
@@ -472,6 +477,7 @@ class CaptureSpinnerHandle implements SpinnerHandle {
472
477
  private readonly events: ActivityEvent[],
473
478
  ) {
474
479
  events.push({ type: 'spinner:start', text });
480
+ bindMethods(this);
475
481
  }
476
482
 
477
483
  update(text: string): void {
@@ -529,6 +535,7 @@ class CaptureProgressHandle implements ProgressHandle {
529
535
  private readonly events: ActivityEvent[],
530
536
  ) {
531
537
  events.push({ type: 'progress:start', label: opts.label ?? '', total: opts.total });
538
+ bindMethods(this);
532
539
  }
533
540
 
534
541
  increment(n?: number): void {
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Method-binding helper for value objects handed to consumers.
3
+ *
4
+ * Output value objects — the `Out` channel and the spinner/progress handles
5
+ * — expose methods that read instance state via `this`. Consumers naturally
6
+ * detach those methods, either by destructuring
7
+ * (`const { log } = out` / `const { succeed, fail } = spinner`) or by passing
8
+ * them as callbacks (`promise.finally(spinner.stop)`). Detached, an unbound
9
+ * prototype method loses its `this` and crashes on the first field access.
10
+ *
11
+ * {@linkcode bindMethods} eliminates that footgun by installing instance-bound
12
+ * copies of every method, so the ergonomic usage is also the correct one.
13
+ *
14
+ * @module dreamcli/core/output/bind
15
+ * @internal
16
+ */
17
+
18
+ /**
19
+ * Bind every method on an instance's prototype chain to the instance.
20
+ *
21
+ * Walks the prototype chain up to (but excluding) `Object.prototype`, binding
22
+ * each method name exactly once — the most-derived definition wins, so subclass
23
+ * overrides (e.g. `CaptureOutputChannel.spinner`) are preserved rather than
24
+ * clobbered by a base-class version. Bound methods are installed as
25
+ * non-enumerable own properties, mirroring the enumerability of the prototype
26
+ * methods they shadow. Getters and non-function members are left untouched.
27
+ *
28
+ * Call this once, last, in a class constructor. Because it reads the live
29
+ * prototype rather than a hand-maintained name list, methods added later are
30
+ * bound automatically — the binding can't silently fall out of date.
31
+ *
32
+ * @param instance - The object whose methods should be bound to it.
33
+ * @internal
34
+ */
35
+ function bindMethods(instance: object): void {
36
+ const bound = instance as Record<PropertyKey, unknown>;
37
+ const seen = new Set<string>();
38
+ let proto: object | null = Object.getPrototypeOf(instance);
39
+
40
+ while (proto !== null && proto !== Object.prototype) {
41
+ for (const name of Object.getOwnPropertyNames(proto)) {
42
+ if (name === 'constructor' || seen.has(name)) continue;
43
+ seen.add(name);
44
+
45
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
46
+ if (descriptor === undefined || typeof descriptor.value !== 'function') continue;
47
+
48
+ Object.defineProperty(bound, name, {
49
+ value: descriptor.value.bind(instance),
50
+ writable: true,
51
+ enumerable: false,
52
+ configurable: true,
53
+ });
54
+ }
55
+ proto = Object.getPrototypeOf(proto);
56
+ }
57
+ }
58
+
59
+ export { bindMethods };
@@ -31,6 +31,7 @@ import {
31
31
  TTYProgressHandle,
32
32
  TTYSpinnerHandle,
33
33
  } from './activity.ts';
34
+ import { bindMethods } from './bind.ts';
34
35
  import type { OutputPolicy, Verbosity } from './contracts.ts';
35
36
  import {
36
37
  resolveOutputPolicy,
@@ -185,6 +186,11 @@ class OutputChannel implements Out {
185
186
  this.policy = resolveOutputPolicy(options);
186
187
  this.jsonMode = options.jsonMode;
187
188
  this.isTTY = options.isTTY;
189
+
190
+ // Bind methods to the instance so they keep working when destructured
191
+ // off `out` (e.g. `const { log } = out`). Resolves subclass overrides
192
+ // (spinner/progress in CaptureOutputChannel) automatically.
193
+ bindMethods(this);
188
194
  }
189
195
 
190
196
  /**