@vincemakes/kiso-code 0.1.30 → 0.1.32
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/package.json +8 -8
- package/dist/body.d.ts +0 -121
- package/dist/body.js +0 -491
- package/dist/dock.d.ts +0 -75
- package/dist/dock.js +0 -176
- package/dist/editor.d.ts +0 -75
- package/dist/editor.js +0 -444
- package/dist/render.d.ts +0 -135
- package/dist/render.js +0 -325
package/dist/dock.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v2b/v2c — the bottom-anchored UI (TTY + color only). Borrows pi-tui's
|
|
3
|
-
* IDEA — a DECSTBM scroll region with a reserved bottom — without its
|
|
4
|
-
* implementation: zero dependencies, line-level ANSI, no differential
|
|
5
|
-
* renderer.
|
|
6
|
-
*
|
|
7
|
-
* Layout (H = terminal height): rows 1..H-4 = the scroll region (the body
|
|
8
|
-
* streams and scrolls here, never touching the bottom), row H-3 = the
|
|
9
|
-
* upper dim dotted separator (╌), row H-2 = the input line (the blue
|
|
10
|
-
* brick ▌you> + the v2c editor's row — readline is gone from the TTY
|
|
11
|
-
* path), row H-1 = the lower dotted separator, row H = the live status
|
|
12
|
-
* bar (v3 §03: idle "▸ <mode> · /mode to switch · …", running
|
|
13
|
-
* "▖ working Ns · …"; a takeover question replaces it). Bottom redraws
|
|
14
|
-
* are wrapped in CSI 2026 (synchronized output) to avoid flicker — the
|
|
15
|
-
* pi trick. The visual identity is the kiso brick motif — ▌ half-block,
|
|
16
|
-
* dotted separators — deliberately NOT the CC rounded frame nor the pi
|
|
17
|
-
* editor (ADR-0039 Amendment 2).
|
|
18
|
-
*
|
|
19
|
-
* Pipes / NO_COLOR: the dock never activates; the v2a line mode stays
|
|
20
|
-
* byte-for-byte (the existing e2e assertions guard it).
|
|
21
|
-
*/
|
|
22
|
-
export declare class Dock {
|
|
23
|
-
#private;
|
|
24
|
-
/** v2b: docked only on a color TTY — pipes and NO_COLOR stay v2a. */
|
|
25
|
-
get active(): boolean;
|
|
26
|
-
/** Bind the CURRENT input line's state — called when a readline takes
|
|
27
|
-
* over (the chat REPL, the trust question's short-lived rl, resume). */
|
|
28
|
-
bindInput(state: () => {
|
|
29
|
-
line: string;
|
|
30
|
-
cursor: number;
|
|
31
|
-
}, prompt: string): void;
|
|
32
|
-
/** Enter docked mode: draw the chrome. #13 (P1): the DECSTBM scroll
|
|
33
|
-
* region is GONE — v2d-B (ADR-0040): the body uses plain LF scrolling
|
|
34
|
-
* so frozen lines enter the native scrollback deterministically
|
|
35
|
-
* (region-scrolled lines are terminal-dependent — some terminals drop
|
|
36
|
-
* them). The dock rows are redrawn by the body after every scroll. A
|
|
37
|
-
* TTY without a real window size (rows < 4) stays in the v2a line
|
|
38
|
-
* mode — the bottom three rows need room to exist. */
|
|
39
|
-
enter(): void;
|
|
40
|
-
/** Teardown — CSI r resets the scroll region, the cursor lands at the
|
|
41
|
-
* input line, the bottom rows are cleared: no broken terminal. Called
|
|
42
|
-
* from main's finally on EVERY exit path (kill -9 excepted — README:
|
|
43
|
-
* `reset` saves it). */
|
|
44
|
-
exit(): void;
|
|
45
|
-
/** SIGWINCH: recompute the size, redraw the chrome. */
|
|
46
|
-
onResize(): void;
|
|
47
|
-
/** v3 §04: bind the editor's slash-command menu state — the menu rows
|
|
48
|
-
* render ABOVE the chrome (over the body's bottom rows; the menu
|
|
49
|
-
* opens while the buffer is a "/" prefix, when no tail is live). */
|
|
50
|
-
bindMenu(state: () => {
|
|
51
|
-
items: readonly import("./editor.js").MenuItem[];
|
|
52
|
-
selected: number;
|
|
53
|
-
} | null): void;
|
|
54
|
-
/** The input line's edit column — prompt width + cursor + 1. The
|
|
55
|
-
* dock's redraw and the body's cursor return both end here, so the
|
|
56
|
-
* ACTUAL cursor always equals what the editor tracks. The width is
|
|
57
|
-
* DISPLAY width (the editor's cursor column is already width-based —
|
|
58
|
-
* the CJK drift root cause, editor.ts). v2d: public — the Body's
|
|
59
|
-
* render loop ends at this column. */
|
|
60
|
-
editCol(): number;
|
|
61
|
-
/** The status bar's base text (usage, ctx, session, …). */
|
|
62
|
-
setStatus(text: string): void;
|
|
63
|
-
/** The live tail — the spinner glyph or "running <tool> Ns". */
|
|
64
|
-
setTail(tail: string): void;
|
|
65
|
-
/** Show a takeover question at the status position (answered at the
|
|
66
|
-
* input line by the caller's readline); clearQuestion() restores. */
|
|
67
|
-
showQuestion(question: string): void;
|
|
68
|
-
clearQuestion(): void;
|
|
69
|
-
/** The bottom four rows, wrapped in CSI 2026 (synchronized output —
|
|
70
|
-
* the pi trick against flicker). The cursor ends at the input line's
|
|
71
|
-
* edit position. v3 §03: the upper ╌ row, the input row, the lower
|
|
72
|
-
* ╌ row, the status row — the status is dim (blue accents inside
|
|
73
|
-
* come from the CLI's composition). */
|
|
74
|
-
redraw(): void;
|
|
75
|
-
}
|
package/dist/dock.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v2b/v2c — the bottom-anchored UI (TTY + color only). Borrows pi-tui's
|
|
3
|
-
* IDEA — a DECSTBM scroll region with a reserved bottom — without its
|
|
4
|
-
* implementation: zero dependencies, line-level ANSI, no differential
|
|
5
|
-
* renderer.
|
|
6
|
-
*
|
|
7
|
-
* Layout (H = terminal height): rows 1..H-4 = the scroll region (the body
|
|
8
|
-
* streams and scrolls here, never touching the bottom), row H-3 = the
|
|
9
|
-
* upper dim dotted separator (╌), row H-2 = the input line (the blue
|
|
10
|
-
* brick ▌you> + the v2c editor's row — readline is gone from the TTY
|
|
11
|
-
* path), row H-1 = the lower dotted separator, row H = the live status
|
|
12
|
-
* bar (v3 §03: idle "▸ <mode> · /mode to switch · …", running
|
|
13
|
-
* "▖ working Ns · …"; a takeover question replaces it). Bottom redraws
|
|
14
|
-
* are wrapped in CSI 2026 (synchronized output) to avoid flicker — the
|
|
15
|
-
* pi trick. The visual identity is the kiso brick motif — ▌ half-block,
|
|
16
|
-
* dotted separators — deliberately NOT the CC rounded frame nor the pi
|
|
17
|
-
* editor (ADR-0039 Amendment 2).
|
|
18
|
-
*
|
|
19
|
-
* Pipes / NO_COLOR: the dock never activates; the v2a line mode stays
|
|
20
|
-
* byte-for-byte (the existing e2e assertions guard it).
|
|
21
|
-
*/
|
|
22
|
-
import { displayWidth } from "./editor.js";
|
|
23
|
-
import { palette } from "./render.js";
|
|
24
|
-
export class Dock {
|
|
25
|
-
#active = false;
|
|
26
|
-
#height = 0;
|
|
27
|
-
#width = 0;
|
|
28
|
-
#status = "";
|
|
29
|
-
#tail = ""; // the live tail: the spinner glyph or "running <tool> Ns"
|
|
30
|
-
#question = null; // a takeover question shown at H-1
|
|
31
|
-
#inputState = () => ({ line: "", cursor: 0 });
|
|
32
|
-
#inputPrompt = "";
|
|
33
|
-
#bodyRow = 1; // the body's logical row inside the scroll region
|
|
34
|
-
#bodyCol = 1; // …and column (mid-line continuations survive cursor jumps)
|
|
35
|
-
#resizeHandler = null;
|
|
36
|
-
/** v2b: docked only on a color TTY — pipes and NO_COLOR stay v2a. */
|
|
37
|
-
get active() {
|
|
38
|
-
return this.#active;
|
|
39
|
-
}
|
|
40
|
-
/** Bind the CURRENT input line's state — called when a readline takes
|
|
41
|
-
* over (the chat REPL, the trust question's short-lived rl, resume). */
|
|
42
|
-
bindInput(state, prompt) {
|
|
43
|
-
this.#inputState = state;
|
|
44
|
-
this.#inputPrompt = prompt;
|
|
45
|
-
}
|
|
46
|
-
/** Enter docked mode: draw the chrome. #13 (P1): the DECSTBM scroll
|
|
47
|
-
* region is GONE — v2d-B (ADR-0040): the body uses plain LF scrolling
|
|
48
|
-
* so frozen lines enter the native scrollback deterministically
|
|
49
|
-
* (region-scrolled lines are terminal-dependent — some terminals drop
|
|
50
|
-
* them). The dock rows are redrawn by the body after every scroll. A
|
|
51
|
-
* TTY without a real window size (rows < 4) stays in the v2a line
|
|
52
|
-
* mode — the bottom three rows need room to exist. */
|
|
53
|
-
enter() {
|
|
54
|
-
const rows = process.stdout.rows ?? 0;
|
|
55
|
-
if (process.stdout.isTTY !== true || palette().blue === "" || rows < 4)
|
|
56
|
-
return;
|
|
57
|
-
this.#active = true;
|
|
58
|
-
this.#height = rows;
|
|
59
|
-
this.#width = process.stdout.columns ?? 80;
|
|
60
|
-
this.#bodyRow = 1;
|
|
61
|
-
this.#bodyCol = 1;
|
|
62
|
-
this.redraw();
|
|
63
|
-
this.#resizeHandler = () => this.onResize();
|
|
64
|
-
process.stdout.on("resize", this.#resizeHandler);
|
|
65
|
-
}
|
|
66
|
-
/** Teardown — CSI r resets the scroll region, the cursor lands at the
|
|
67
|
-
* input line, the bottom rows are cleared: no broken terminal. Called
|
|
68
|
-
* from main's finally on EVERY exit path (kill -9 excepted — README:
|
|
69
|
-
* `reset` saves it). */
|
|
70
|
-
exit() {
|
|
71
|
-
if (!this.#active)
|
|
72
|
-
return;
|
|
73
|
-
this.#active = false;
|
|
74
|
-
if (this.#resizeHandler !== null) {
|
|
75
|
-
process.stdout.off("resize", this.#resizeHandler);
|
|
76
|
-
this.#resizeHandler = null;
|
|
77
|
-
}
|
|
78
|
-
const H = this.#height;
|
|
79
|
-
process.stdout.write("\x1b[r"); // reset the scroll region
|
|
80
|
-
for (let row = H - 3; row <= H; row += 1) {
|
|
81
|
-
process.stdout.write(`\x1b[${row};1H\x1b[0K`); // clear the four rows
|
|
82
|
-
}
|
|
83
|
-
process.stdout.write(`\x1b[${H};1H`);
|
|
84
|
-
}
|
|
85
|
-
/** SIGWINCH: recompute the size, redraw the chrome. */
|
|
86
|
-
onResize() {
|
|
87
|
-
if (!this.#active)
|
|
88
|
-
return;
|
|
89
|
-
this.#height = process.stdout.rows ?? this.#height;
|
|
90
|
-
this.#width = process.stdout.columns ?? this.#width;
|
|
91
|
-
this.redraw();
|
|
92
|
-
}
|
|
93
|
-
#menuState = null;
|
|
94
|
-
/** v3 §04: bind the editor's slash-command menu state — the menu rows
|
|
95
|
-
* render ABOVE the chrome (over the body's bottom rows; the menu
|
|
96
|
-
* opens while the buffer is a "/" prefix, when no tail is live). */
|
|
97
|
-
bindMenu(state) {
|
|
98
|
-
this.#menuState = state;
|
|
99
|
-
}
|
|
100
|
-
/** The input line's edit column — prompt width + cursor + 1. The
|
|
101
|
-
* dock's redraw and the body's cursor return both end here, so the
|
|
102
|
-
* ACTUAL cursor always equals what the editor tracks. The width is
|
|
103
|
-
* DISPLAY width (the editor's cursor column is already width-based —
|
|
104
|
-
* the CJK drift root cause, editor.ts). v2d: public — the Body's
|
|
105
|
-
* render loop ends at this column. */
|
|
106
|
-
editCol() {
|
|
107
|
-
return this.#inputCol();
|
|
108
|
-
}
|
|
109
|
-
#inputCol() {
|
|
110
|
-
const inp = this.#inputState();
|
|
111
|
-
const promptWidth = displayWidth(this.#inputPrompt.replace(/\x1b\[[0-9;]*m/g, ""));
|
|
112
|
-
return promptWidth + inp.cursor + 1;
|
|
113
|
-
}
|
|
114
|
-
/** The status bar's base text (usage, ctx, session, …). */
|
|
115
|
-
setStatus(text) {
|
|
116
|
-
this.#status = text;
|
|
117
|
-
this.redraw();
|
|
118
|
-
}
|
|
119
|
-
/** The live tail — the spinner glyph or "running <tool> Ns". */
|
|
120
|
-
setTail(tail) {
|
|
121
|
-
this.#tail = tail;
|
|
122
|
-
this.redraw();
|
|
123
|
-
}
|
|
124
|
-
/** Show a takeover question at the status position (answered at the
|
|
125
|
-
* input line by the caller's readline); clearQuestion() restores. */
|
|
126
|
-
showQuestion(question) {
|
|
127
|
-
this.#question = question;
|
|
128
|
-
this.redraw();
|
|
129
|
-
}
|
|
130
|
-
clearQuestion() {
|
|
131
|
-
this.#question = null;
|
|
132
|
-
this.redraw();
|
|
133
|
-
}
|
|
134
|
-
/** The bottom four rows, wrapped in CSI 2026 (synchronized output —
|
|
135
|
-
* the pi trick against flicker). The cursor ends at the input line's
|
|
136
|
-
* edit position. v3 §03: the upper ╌ row, the input row, the lower
|
|
137
|
-
* ╌ row, the status row — the status is dim (blue accents inside
|
|
138
|
-
* come from the CLI's composition). */
|
|
139
|
-
redraw() {
|
|
140
|
-
if (!this.#active)
|
|
141
|
-
return;
|
|
142
|
-
const p = palette();
|
|
143
|
-
const H = this.#height;
|
|
144
|
-
const W = this.#width;
|
|
145
|
-
const sep = `${p.dim}${"╌".repeat(W)}${p.reset}`;
|
|
146
|
-
const status = `${this.#status}${this.#tail === "" ? "" : ` · ${this.#tail}`}`;
|
|
147
|
-
const statusLine = this.#question ?? `${p.dim}${status}${p.reset}`;
|
|
148
|
-
const inp = this.#inputState();
|
|
149
|
-
const out = [];
|
|
150
|
-
// P3 (审查): the DEC private-mode SET/RESET needs the "?" prefix —
|
|
151
|
-
// \x1b[?2026h/l, the pi source's exact form. Without it terminals
|
|
152
|
-
// silently ignore the mode and the anti-flicker never engages.
|
|
153
|
-
out.push("\x1b[?2026h"); // synchronized output ON (DEC 2026)
|
|
154
|
-
// v3 §04: the slash-command menu — above the chrome, one row per
|
|
155
|
-
// filtered command, the selection highlighted. Drawn first so the
|
|
156
|
-
// chrome rows repaint on top of any overlap.
|
|
157
|
-
const menu = this.#menuState?.();
|
|
158
|
-
if (menu !== null && menu !== undefined) {
|
|
159
|
-
for (let i = 0; i < menu.items.length; i += 1) {
|
|
160
|
-
const item = menu.items[i];
|
|
161
|
-
const row = H - 4 - (menu.items.length - 1 - i);
|
|
162
|
-
const text = i === menu.selected
|
|
163
|
-
? `${p.blue}▸ ${item.name}${p.reset} ${item.desc}`
|
|
164
|
-
: `${p.dim} ${item.name} ${item.desc}${p.reset}`;
|
|
165
|
-
out.push(`\x1b[${row};1H\x1b[0K${text}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
out.push(`\x1b[${H - 3};1H\x1b[0K${sep}`);
|
|
169
|
-
out.push(`\x1b[${H - 2};1H\x1b[0K${this.#inputPrompt}${inp.line}`);
|
|
170
|
-
out.push(`\x1b[${H - 1};1H\x1b[0K${sep}`);
|
|
171
|
-
out.push(`\x1b[${H};1H\x1b[0K${statusLine}`);
|
|
172
|
-
out.push(`\x1b[${H - 2};${this.#inputCol()}H`); // back to the edit position
|
|
173
|
-
out.push("\x1b[?2026l"); // synchronized output OFF
|
|
174
|
-
process.stdout.write(out.join(""));
|
|
175
|
-
}
|
|
176
|
-
}
|
package/dist/editor.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v2c — the raw-mode single-line editor that REPLACES readline on the TTY
|
|
3
|
-
* path. Root cause of the v2b drift (plan 2026-08-05-tui-v2b §11): readline
|
|
4
|
-
* re-renders its line by CHARACTER count and assumes it owns the row
|
|
5
|
-
* exclusively — a CJK wide character (2 cells) shifts every following
|
|
6
|
-
* column, and the dock's redraws make the mismatch permanent. Patching
|
|
7
|
-
* readline is a dead end; the TTY path draws its own input row instead.
|
|
8
|
-
* Non-TTY paths keep readline untouched (pipe bytes unchanged).
|
|
9
|
-
*
|
|
10
|
-
* Zero dependencies. The eastAsianWidth table is a ~40-line subset (CJK
|
|
11
|
-
* ideographs/kana/hangul/fullwidth/common wide symbols = 2, everything
|
|
12
|
-
* else = 1). Known limitation, documented in the README: emoji ZWJ
|
|
13
|
-
* clusters (family emoji etc.) are not guaranteed perfect — each code
|
|
14
|
-
* point counts as its width.
|
|
15
|
-
*
|
|
16
|
-
* The editor is a SINGLE line: bracketed paste (?2004h) unwraps and
|
|
17
|
-
* inserts, internal newlines become spaces.
|
|
18
|
-
*/
|
|
19
|
-
/** A code point's display width: 2 for the wide ranges, 1 otherwise. */
|
|
20
|
-
export declare function charWidth(cp: number): number;
|
|
21
|
-
/** Display width of a code-point array (cursor math, scrolling). */
|
|
22
|
-
export declare function widthOf(chars: readonly number[]): number;
|
|
23
|
-
/** Display width of a string. */
|
|
24
|
-
export declare function displayWidth(text: string): number;
|
|
25
|
-
export declare const PROMPT = "\u258Cyou> ";
|
|
26
|
-
export declare const PROMPT_WIDTH: number;
|
|
27
|
-
/** v3 §04 — the slash-command menu's command table (English one-liners). */
|
|
28
|
-
export interface MenuItem {
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly desc: string;
|
|
31
|
-
}
|
|
32
|
-
export declare const MENU_ITEMS: readonly MenuItem[];
|
|
33
|
-
/**
|
|
34
|
-
* The editor. Raw mode + bracketed paste (?2004h) on enter, restored on
|
|
35
|
-
* exit. The input row is rendered by `onRender` (the CLI wires it to the
|
|
36
|
-
* dock's redraw when docked, the editor's own self-render otherwise) —
|
|
37
|
-
* the editor itself never writes while docked. The event handlers are
|
|
38
|
-
* settable — the chat/resume contexts wire them after construction.
|
|
39
|
-
*/
|
|
40
|
-
export declare class Editor {
|
|
41
|
-
#private;
|
|
42
|
-
readonly closed: Promise<void>;
|
|
43
|
-
constructor(onRender: () => void);
|
|
44
|
-
onLine(cb: (line: string) => void): void;
|
|
45
|
-
onSigint(cb: () => void): void;
|
|
46
|
-
onEot(cb: () => void): void;
|
|
47
|
-
onEscape(cb: () => void): void;
|
|
48
|
-
/** The whole buffer as text (the CLI's line()/clearLine()). */
|
|
49
|
-
line(): string;
|
|
50
|
-
clearLine(): void;
|
|
51
|
-
/** The visible slice (dim "…" prefix when scrolled) + the cursor's
|
|
52
|
-
* display column within it — the dock's input-row state. */
|
|
53
|
-
dockState(): {
|
|
54
|
-
line: string;
|
|
55
|
-
cursor: number;
|
|
56
|
-
};
|
|
57
|
-
/** v3 §04: the menu's visible state for the dock — null when closed. */
|
|
58
|
-
menuState(): {
|
|
59
|
-
items: readonly MenuItem[];
|
|
60
|
-
selected: number;
|
|
61
|
-
} | null;
|
|
62
|
-
/** One-shot question mode: the NEXT submit answers, not a turn. */
|
|
63
|
-
question(_query: string, cb: (answer: string) => void): void;
|
|
64
|
-
/** Cancel a pending question — the buffer stays (its text becomes the
|
|
65
|
-
* next turn on Enter, the readline re-emit equivalent). */
|
|
66
|
-
cancelQuestion(): void;
|
|
67
|
-
enter(): void;
|
|
68
|
-
exit(): void;
|
|
69
|
-
/** The row's own render when the dock is inactive (a TTY without a
|
|
70
|
-
* real size): \r + clear + blue brick prompt + visible + cursor
|
|
71
|
-
* column. */
|
|
72
|
-
selfRender(): void;
|
|
73
|
-
/** Feed raw stdin bytes — the parser. Public for unit tests. */
|
|
74
|
-
feed(raw: Uint8Array): void;
|
|
75
|
-
}
|