@causyne/agent 1.20.62 → 1.20.65
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 +2 -2
- package/package.json +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/agentLoop.js +181 -11
- package/src/agentLoop.ts +184 -11
- package/src/approvalPolicy.js +19 -0
- package/src/approvalPolicy.ts +18 -0
- package/src/browser/causyneBrowser.js +34 -4
- package/src/browser/causyneBrowser.ts +32 -4
- package/src/cliMode.js +12 -28
- package/src/commands.js +33 -0
- package/src/decisionPolicy.js +18 -1
- package/src/decisionPolicy.ts +18 -1
- package/src/implementationPlan.js +26 -0
- package/src/implementationPlan.ts +25 -0
- package/src/observer/coldObserver.js +6 -1
- package/src/observer/coldObserver.ts +6 -1
- package/src/observer.js +24 -2
- package/src/observer.ts +24 -2
- package/src/providers/acp.js +2 -8
- package/src/providers/acp.ts +2 -8
- package/src/providers/antigravity.js +7 -10
- package/src/providers/antigravity.ts +7 -10
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/toolPacks.js +1 -1
- package/src/toolPacks.ts +1 -1
- package/src/tools/toolSelfRepair.js +51 -8
- package/src/tools/toolSelfRepair.ts +42 -9
- package/src/tui/CausyneRotor.js +234 -0
- package/src/tui/CausyneRotor.ts +280 -0
- package/src/tui/activityLayout.js +1 -1
- package/src/tui/activityLayout.ts +1 -1
- package/src/tui/chatRenderer.js +56 -7
- package/src/tui/chatboxClipboard.js +96 -10
- package/src/tui/chatboxClipboard.ts +121 -11
- package/src/tui/clipboardImage.js +308 -0
- package/src/tui/clipboardImage.ts +320 -0
- package/src/tui/codeStreamRenderer.js +89 -1
- package/src/tui/codeStreamRenderer.ts +109 -1
- package/src/tui/composerControls.js +2 -0
- package/src/tui/composerControls.ts +2 -0
- package/src/tui/dialogs.js +41 -6
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/lineEditor.js +44 -12
- package/src/tui/messageInteraction.js +16 -5
- package/src/tui/messageInteraction.ts +14 -5
- package/src/tui/observerPicker.js +4 -8
- package/src/tui/observerPicker.ts +4 -8
- package/src/tui/prompt.js +80 -43
- package/src/tui/runningLight.js +213 -0
- package/src/tui/runningLight.ts +271 -0
- package/src/tui/sessionSidebar.js +7 -1
- package/src/tui/sessionSidebar.ts +7 -1
- package/src/tui/stage.js +4 -4
- package/src/tui/stageSurface.js +21 -14
- package/src/tui/statusLine.js +27 -4
- package/src/tui/statusLine.ts +27 -4
- package/src/tui/theme.js +5 -2
- package/src/tui/thinkingBox.js +41 -10
- package/src/tui/thinkingBox.ts +43 -10
- package/src/tui/turnRail.js +155 -24
- package/src/tui/turnRail.ts +170 -22
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CausyneRotor.ts
|
|
3
|
+
* Dependency-free, terminal-native animation for a Causyne CLI/TUI.
|
|
4
|
+
* Uses Unicode Braille pixels (2x4 subpixels per character) and ANSI colors.
|
|
5
|
+
* The logo is drawn geometrically, not played from an image/GIF.
|
|
6
|
+
*
|
|
7
|
+
* If an existing TUI (Ink, Blessed, etc.) owns the terminal screen, call
|
|
8
|
+
* renderCausyneRotor(...) in THAT renderer. Do not also start the standalone
|
|
9
|
+
* interval-based renderer.
|
|
10
|
+
*/
|
|
11
|
+
import { stdout } from 'node:process';
|
|
12
|
+
const BRAILLE_DOTS = [
|
|
13
|
+
[0, 0, 0x01], [0, 1, 0x02], [0, 2, 0x04], [0, 3, 0x40],
|
|
14
|
+
[1, 0, 0x08], [1, 1, 0x10], [1, 2, 0x20], [1, 3, 0x80],
|
|
15
|
+
];
|
|
16
|
+
const TAU = Math.PI * 2;
|
|
17
|
+
const STEP = TAU / 6;
|
|
18
|
+
export const COLORS = {
|
|
19
|
+
charcoal: '\x1b[38;2;115;124;137m',
|
|
20
|
+
lime: '\x1b[38;2;181;214;106m',
|
|
21
|
+
outline: '\x1b[38;2;224;230;229m',
|
|
22
|
+
text: '\x1b[38;2;185;192;196m',
|
|
23
|
+
reset: '\x1b[0m',
|
|
24
|
+
};
|
|
25
|
+
// One triangular blade, defined relative to the hub at (0, 0).
|
|
26
|
+
// The remaining five are exact 60-degree rotations of this triangle.
|
|
27
|
+
// Negative space between blades forms the central hexagonal aperture.
|
|
28
|
+
const BASE_BLADE = [
|
|
29
|
+
{ x: -0.86, y: -0.64 },
|
|
30
|
+
{ x: 0.06, y: -1.06 },
|
|
31
|
+
{ x: -0.42, y: -0.105 },
|
|
32
|
+
];
|
|
33
|
+
function rotate(p, angle) {
|
|
34
|
+
const c = Math.cos(angle);
|
|
35
|
+
const s = Math.sin(angle);
|
|
36
|
+
return { x: p.x * c - p.y * s, y: p.x * s + p.y * c };
|
|
37
|
+
}
|
|
38
|
+
function insideTriangle(p, a, b, c) {
|
|
39
|
+
const cross = (v, w, q) => (w.x - v.x) * (q.y - v.y) - (w.y - v.y) * (q.x - v.x);
|
|
40
|
+
const u = cross(a, b, p);
|
|
41
|
+
const v = cross(b, c, p);
|
|
42
|
+
const w = cross(c, a, p);
|
|
43
|
+
return (u >= 0 && v >= 0 && w >= 0) || (u <= 0 && v <= 0 && w <= 0);
|
|
44
|
+
}
|
|
45
|
+
function distanceToSegment(p, a, b) {
|
|
46
|
+
const dx = b.x - a.x;
|
|
47
|
+
const dy = b.y - a.y;
|
|
48
|
+
const lengthSq = dx * dx + dy * dy;
|
|
49
|
+
const t = lengthSq === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSq));
|
|
50
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
51
|
+
}
|
|
52
|
+
function smoothstep(t) {
|
|
53
|
+
const x = Math.max(0, Math.min(1, t));
|
|
54
|
+
return x * x * (3 - 2 * x);
|
|
55
|
+
}
|
|
56
|
+
export function getAngle(elapsedMs, motion = 'heavy') {
|
|
57
|
+
const t = Math.max(0, elapsedMs);
|
|
58
|
+
if (motion === 'smooth')
|
|
59
|
+
return (t / 4200) * TAU;
|
|
60
|
+
if (motion === 'pulse') {
|
|
61
|
+
const cycle = t / 1000;
|
|
62
|
+
return (Math.floor(cycle) + smoothstep(Math.min(1, (cycle % 1) / 0.75))) * STEP;
|
|
63
|
+
}
|
|
64
|
+
// Heavy engine: deliberate acceleration, high-momentum travel, short settle.
|
|
65
|
+
const cycle = t / 860;
|
|
66
|
+
const index = Math.floor(cycle);
|
|
67
|
+
const progress = (cycle % 1) / 0.88; // final 12% holds precisely on an index
|
|
68
|
+
return (index + smoothstep(progress)) * STEP;
|
|
69
|
+
}
|
|
70
|
+
function sample(p, blades) {
|
|
71
|
+
for (let i = 0; i < 6; i++) {
|
|
72
|
+
const blade = blades[i];
|
|
73
|
+
if (!blade)
|
|
74
|
+
continue;
|
|
75
|
+
const [a, b, c] = blade;
|
|
76
|
+
if (!a || !b || !c || !insideTriangle(p, a, b, c))
|
|
77
|
+
continue;
|
|
78
|
+
// 1.5~2 subpixels: subtle white perimeter like your outlined SVG.
|
|
79
|
+
const edge = Math.min(distanceToSegment(p, a, b), distanceToSegment(p, b, c), distanceToSegment(p, c, a));
|
|
80
|
+
if (edge < 0.018)
|
|
81
|
+
return 3;
|
|
82
|
+
return i === 1 ? 2 : 1;
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
function paint(text, kind, color) {
|
|
87
|
+
if (!color)
|
|
88
|
+
return text;
|
|
89
|
+
const code = kind === 2 ? COLORS.lime : kind === 3 ? COLORS.outline : COLORS.charcoal;
|
|
90
|
+
return code + text + COLORS.reset;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns an ANSI-colored multi-line string. No side effects or timers.
|
|
94
|
+
* Intended for an existing TUI's render() method.
|
|
95
|
+
*/
|
|
96
|
+
export function renderCausyneRotor(elapsedMs, options = {}) {
|
|
97
|
+
const columns = Math.max(12, Math.min(56, Math.floor(options.columns ?? 24)));
|
|
98
|
+
const rows = Math.max(6, Math.min(28, Math.floor(options.rows ?? 12)));
|
|
99
|
+
const color = options.color ?? true;
|
|
100
|
+
const angle = getAngle(elapsedMs, options.motion ?? 'heavy');
|
|
101
|
+
const blades = Array.from({ length: 6 }, (_, i) => {
|
|
102
|
+
const rotAngle = angle + i * STEP;
|
|
103
|
+
return BASE_BLADE.map((p) => rotate(p, rotAngle));
|
|
104
|
+
});
|
|
105
|
+
const widthDots = columns * 2;
|
|
106
|
+
const heightDots = rows * 4;
|
|
107
|
+
const scale = Math.min(widthDots, heightDots) / 2.42;
|
|
108
|
+
const lines = [];
|
|
109
|
+
for (let row = 0; row < rows; row++) {
|
|
110
|
+
let line = '';
|
|
111
|
+
for (let col = 0; col < columns; col++) {
|
|
112
|
+
let mask = 0;
|
|
113
|
+
let dark = 0;
|
|
114
|
+
let lime = 0;
|
|
115
|
+
let outline = 0;
|
|
116
|
+
for (const [dx, dy, bit] of BRAILLE_DOTS) {
|
|
117
|
+
const px = col * 2 + dx + 0.5;
|
|
118
|
+
const py = row * 4 + dy + 0.5;
|
|
119
|
+
const p = {
|
|
120
|
+
x: (px - widthDots / 2) / scale,
|
|
121
|
+
y: (py - heightDots / 2) / scale,
|
|
122
|
+
};
|
|
123
|
+
const hit = sample(p, blades);
|
|
124
|
+
if (!hit)
|
|
125
|
+
continue;
|
|
126
|
+
mask |= bit;
|
|
127
|
+
if (hit === 1)
|
|
128
|
+
dark++;
|
|
129
|
+
else if (hit === 2)
|
|
130
|
+
lime++;
|
|
131
|
+
else
|
|
132
|
+
outline++;
|
|
133
|
+
}
|
|
134
|
+
if (!mask) {
|
|
135
|
+
line += ' ';
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// A Braille cell has a single foreground color. Choose the dominant fill.
|
|
139
|
+
const kind = lime > 0 && lime >= dark ? 2 :
|
|
140
|
+
outline >= 3 && dark === 0 && lime === 0 ? 3 : 1;
|
|
141
|
+
line += paint(String.fromCodePoint(0x2800 + mask), kind, color);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
lines.push(line);
|
|
145
|
+
}
|
|
146
|
+
if (options.label !== '') {
|
|
147
|
+
const label = options.label ?? 'working';
|
|
148
|
+
const status = color
|
|
149
|
+
? `${COLORS.lime}●${COLORS.reset} ${COLORS.text}${label}${COLORS.reset}`
|
|
150
|
+
: `● ${label}`;
|
|
151
|
+
lines.push(status);
|
|
152
|
+
}
|
|
153
|
+
return lines.join('\n');
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Standalone demo/CLI renderer. It owns its multi-line cursor region.
|
|
157
|
+
* If your app uses Ink/Blessed/another renderer, DO NOT call this function;
|
|
158
|
+
* use renderCausyneRotor() inside the existing renderer instead.
|
|
159
|
+
*/
|
|
160
|
+
export function startCausyneRotor(options = {}) {
|
|
161
|
+
const color = options.color ?? (Boolean(stdout.isTTY) && !process.env.NO_COLOR && !process.env.CAUSYNE_NO_COLOR);
|
|
162
|
+
if (!stdout.isTTY) {
|
|
163
|
+
stdout.write((options.label ?? 'working') + '\n');
|
|
164
|
+
return { stop() { } };
|
|
165
|
+
}
|
|
166
|
+
const fps = Math.max(4, Math.min(30, options.fps ?? 16));
|
|
167
|
+
const started = Date.now();
|
|
168
|
+
let stopped = false;
|
|
169
|
+
let lastLines = 0;
|
|
170
|
+
function draw() {
|
|
171
|
+
const frame = renderCausyneRotor(Date.now() - started, { ...options, color });
|
|
172
|
+
const lines = frame.split('\n');
|
|
173
|
+
// Redraw only our reserved lines, never clear the whole terminal.
|
|
174
|
+
if (lastLines > 0)
|
|
175
|
+
stdout.write(`\x1b[${lastLines}A\r`);
|
|
176
|
+
stdout.write(lines.map((line) => `\x1b[2K${line}\n`).join(''));
|
|
177
|
+
lastLines = lines.length;
|
|
178
|
+
}
|
|
179
|
+
stdout.write('\x1b[?25l'); // temporarily hide cursor
|
|
180
|
+
draw();
|
|
181
|
+
const timer = setInterval(draw, Math.round(1000 / fps));
|
|
182
|
+
return {
|
|
183
|
+
stop() {
|
|
184
|
+
if (stopped)
|
|
185
|
+
return;
|
|
186
|
+
stopped = true;
|
|
187
|
+
clearInterval(timer);
|
|
188
|
+
stdout.write('\x1b[?25h'); // restore cursor
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// ---------------------------------------------------------------------------------------------------------
|
|
193
|
+
// Single-Line Status Row / Inline Spinner Integration
|
|
194
|
+
// ---------------------------------------------------------------------------------------------------------
|
|
195
|
+
/**
|
|
196
|
+
* 2-character Braille rotor frames using the CausyneRotor palette (lime + charcoal).
|
|
197
|
+
* 6-phase rotation corresponding directly to the 60-degree indexed rotor blades.
|
|
198
|
+
*/
|
|
199
|
+
export const ROTOR_SPINNER_FRAMES = [
|
|
200
|
+
`${COLORS.charcoal}⠇${COLORS.lime}⠙${COLORS.reset}`,
|
|
201
|
+
`${COLORS.charcoal}⠋${COLORS.lime}⠸${COLORS.reset}`,
|
|
202
|
+
`${COLORS.charcoal}⠙${COLORS.lime}⠴${COLORS.reset}`,
|
|
203
|
+
`${COLORS.lime}⠸${COLORS.charcoal}⠦${COLORS.reset}`,
|
|
204
|
+
`${COLORS.lime}⠴${COLORS.charcoal}⠇${COLORS.reset}`,
|
|
205
|
+
`${COLORS.lime}⠦${COLORS.charcoal}⠋${COLORS.reset}`,
|
|
206
|
+
];
|
|
207
|
+
export const ROTOR_SPINNER_FRAMES_NO_COLOR = [
|
|
208
|
+
'⠇⠙', '⠋⠸', '⠙⠴', '⠸⠦', '⠴⠇', '⠦⠋',
|
|
209
|
+
];
|
|
210
|
+
export const ROTOR_SPINNER_FRAMES_ASCII = [
|
|
211
|
+
'[-]', '[\\]', '[|]', '[/]',
|
|
212
|
+
];
|
|
213
|
+
export function getRotorSpinnerFrames(color = true, unicode = true) {
|
|
214
|
+
if (!unicode)
|
|
215
|
+
return ROTOR_SPINNER_FRAMES_ASCII;
|
|
216
|
+
return color ? ROTOR_SPINNER_FRAMES : ROTOR_SPINNER_FRAMES_NO_COLOR;
|
|
217
|
+
}
|
|
218
|
+
export function getRotorSpinnerFrame(tick, color = true, unicode = true) {
|
|
219
|
+
const frames = getRotorSpinnerFrames(color, unicode);
|
|
220
|
+
const index = Math.abs(Math.floor(tick)) % frames.length;
|
|
221
|
+
return frames[index] ?? frames[0] ?? '⠇⠙';
|
|
222
|
+
}
|
|
223
|
+
const DOT_FRAMES = [' ', '. ', '.. ', '...'];
|
|
224
|
+
export function getAnimatedDots(tick) {
|
|
225
|
+
const stage = Math.floor(Math.abs(Math.floor(tick)) / 2) % DOT_FRAMES.length;
|
|
226
|
+
return DOT_FRAMES[stage] ?? ' ';
|
|
227
|
+
}
|
|
228
|
+
export function formatAnimatedStatus(message, tick) {
|
|
229
|
+
let base = (message || 'working').trimEnd();
|
|
230
|
+
while (base.endsWith('.') || base.endsWith('…')) {
|
|
231
|
+
base = base.slice(0, -1).trimEnd();
|
|
232
|
+
}
|
|
233
|
+
return `${base}${getAnimatedDots(tick)}`;
|
|
234
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CausyneRotor.ts
|
|
3
|
+
* Dependency-free, terminal-native animation for a Causyne CLI/TUI.
|
|
4
|
+
* Uses Unicode Braille pixels (2x4 subpixels per character) and ANSI colors.
|
|
5
|
+
* The logo is drawn geometrically, not played from an image/GIF.
|
|
6
|
+
*
|
|
7
|
+
* If an existing TUI (Ink, Blessed, etc.) owns the terminal screen, call
|
|
8
|
+
* renderCausyneRotor(...) in THAT renderer. Do not also start the standalone
|
|
9
|
+
* interval-based renderer.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { stdout } from 'node:process';
|
|
13
|
+
|
|
14
|
+
export type RotorMotion = 'heavy' | 'smooth' | 'pulse';
|
|
15
|
+
|
|
16
|
+
export interface RotorOptions {
|
|
17
|
+
/** Width of the actual rotor in terminal columns. Default: 24. */
|
|
18
|
+
columns?: number | undefined;
|
|
19
|
+
/** Height of the actual rotor in terminal rows. Default: 12. */
|
|
20
|
+
rows?: number | undefined;
|
|
21
|
+
/** 'heavy' is an eased, weighty 60-degree indexed rotation. */
|
|
22
|
+
motion?: RotorMotion | undefined;
|
|
23
|
+
/** Text shown below the rotor. Set to '' to omit. */
|
|
24
|
+
label?: string | undefined;
|
|
25
|
+
/** Set false for non-color terminals. */
|
|
26
|
+
color?: boolean | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Point = { x: number; y: number };
|
|
30
|
+
type Sample = 0 | 1 | 2 | 3; // empty / charcoal / lime / light outline
|
|
31
|
+
|
|
32
|
+
const BRAILLE_DOTS: ReadonlyArray<readonly [number, number, number]> = [
|
|
33
|
+
[0, 0, 0x01], [0, 1, 0x02], [0, 2, 0x04], [0, 3, 0x40],
|
|
34
|
+
[1, 0, 0x08], [1, 1, 0x10], [1, 2, 0x20], [1, 3, 0x80],
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const TAU = Math.PI * 2;
|
|
38
|
+
const STEP = TAU / 6;
|
|
39
|
+
export const COLORS = {
|
|
40
|
+
charcoal: '\x1b[38;2;115;124;137m',
|
|
41
|
+
lime: '\x1b[38;2;181;214;106m',
|
|
42
|
+
outline: '\x1b[38;2;224;230;229m',
|
|
43
|
+
text: '\x1b[38;2;185;192;196m',
|
|
44
|
+
reset: '\x1b[0m',
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
// One triangular blade, defined relative to the hub at (0, 0).
|
|
48
|
+
// The remaining five are exact 60-degree rotations of this triangle.
|
|
49
|
+
// Negative space between blades forms the central hexagonal aperture.
|
|
50
|
+
const BASE_BLADE: readonly Point[] = [
|
|
51
|
+
{ x: -0.86, y: -0.64 },
|
|
52
|
+
{ x: 0.06, y: -1.06 },
|
|
53
|
+
{ x: -0.42, y: -0.105 },
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function rotate(p: Point, angle: number): Point {
|
|
57
|
+
const c = Math.cos(angle);
|
|
58
|
+
const s = Math.sin(angle);
|
|
59
|
+
return { x: p.x * c - p.y * s, y: p.x * s + p.y * c };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function insideTriangle(p: Point, a: Point, b: Point, c: Point): boolean {
|
|
63
|
+
const cross = (v: Point, w: Point, q: Point): number =>
|
|
64
|
+
(w.x - v.x) * (q.y - v.y) - (w.y - v.y) * (q.x - v.x);
|
|
65
|
+
const u = cross(a, b, p);
|
|
66
|
+
const v = cross(b, c, p);
|
|
67
|
+
const w = cross(c, a, p);
|
|
68
|
+
return (u >= 0 && v >= 0 && w >= 0) || (u <= 0 && v <= 0 && w <= 0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function distanceToSegment(p: Point, a: Point, b: Point): number {
|
|
72
|
+
const dx = b.x - a.x;
|
|
73
|
+
const dy = b.y - a.y;
|
|
74
|
+
const lengthSq = dx * dx + dy * dy;
|
|
75
|
+
const t = lengthSq === 0 ? 0 : Math.max(0, Math.min(1,
|
|
76
|
+
((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSq,
|
|
77
|
+
));
|
|
78
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function smoothstep(t: number): number {
|
|
82
|
+
const x = Math.max(0, Math.min(1, t));
|
|
83
|
+
return x * x * (3 - 2 * x);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getAngle(elapsedMs: number, motion: RotorMotion = 'heavy'): number {
|
|
87
|
+
const t = Math.max(0, elapsedMs);
|
|
88
|
+
if (motion === 'smooth') return (t / 4200) * TAU;
|
|
89
|
+
if (motion === 'pulse') {
|
|
90
|
+
const cycle = t / 1000;
|
|
91
|
+
return (Math.floor(cycle) + smoothstep(Math.min(1, (cycle % 1) / 0.75))) * STEP;
|
|
92
|
+
}
|
|
93
|
+
// Heavy engine: deliberate acceleration, high-momentum travel, short settle.
|
|
94
|
+
const cycle = t / 860;
|
|
95
|
+
const index = Math.floor(cycle);
|
|
96
|
+
const progress = (cycle % 1) / 0.88; // final 12% holds precisely on an index
|
|
97
|
+
return (index + smoothstep(progress)) * STEP;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function sample(p: Point, blades: readonly (readonly Point[])[]): Sample {
|
|
101
|
+
for (let i = 0; i < 6; i++) {
|
|
102
|
+
const blade = blades[i];
|
|
103
|
+
if (!blade) continue;
|
|
104
|
+
const [a, b, c] = blade;
|
|
105
|
+
if (!a || !b || !c || !insideTriangle(p, a, b, c)) continue;
|
|
106
|
+
// 1.5~2 subpixels: subtle white perimeter like your outlined SVG.
|
|
107
|
+
const edge = Math.min(
|
|
108
|
+
distanceToSegment(p, a, b),
|
|
109
|
+
distanceToSegment(p, b, c),
|
|
110
|
+
distanceToSegment(p, c, a),
|
|
111
|
+
);
|
|
112
|
+
if (edge < 0.018) return 3;
|
|
113
|
+
return i === 1 ? 2 : 1;
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function paint(text: string, kind: Sample, color: boolean): string {
|
|
119
|
+
if (!color) return text;
|
|
120
|
+
const code = kind === 2 ? COLORS.lime : kind === 3 ? COLORS.outline : COLORS.charcoal;
|
|
121
|
+
return code + text + COLORS.reset;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns an ANSI-colored multi-line string. No side effects or timers.
|
|
126
|
+
* Intended for an existing TUI's render() method.
|
|
127
|
+
*/
|
|
128
|
+
export function renderCausyneRotor(
|
|
129
|
+
elapsedMs: number,
|
|
130
|
+
options: RotorOptions = {},
|
|
131
|
+
): string {
|
|
132
|
+
const columns = Math.max(12, Math.min(56, Math.floor(options.columns ?? 24)));
|
|
133
|
+
const rows = Math.max(6, Math.min(28, Math.floor(options.rows ?? 12)));
|
|
134
|
+
const color = options.color ?? true;
|
|
135
|
+
const angle = getAngle(elapsedMs, options.motion ?? 'heavy');
|
|
136
|
+
const blades = Array.from({ length: 6 }, (_, i) => {
|
|
137
|
+
const rotAngle = angle + i * STEP;
|
|
138
|
+
return BASE_BLADE.map((p) => rotate(p, rotAngle));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const widthDots = columns * 2;
|
|
142
|
+
const heightDots = rows * 4;
|
|
143
|
+
const scale = Math.min(widthDots, heightDots) / 2.42;
|
|
144
|
+
const lines: string[] = [];
|
|
145
|
+
|
|
146
|
+
for (let row = 0; row < rows; row++) {
|
|
147
|
+
let line = '';
|
|
148
|
+
for (let col = 0; col < columns; col++) {
|
|
149
|
+
let mask = 0;
|
|
150
|
+
let dark = 0;
|
|
151
|
+
let lime = 0;
|
|
152
|
+
let outline = 0;
|
|
153
|
+
for (const [dx, dy, bit] of BRAILLE_DOTS) {
|
|
154
|
+
const px = col * 2 + dx + 0.5;
|
|
155
|
+
const py = row * 4 + dy + 0.5;
|
|
156
|
+
const p = {
|
|
157
|
+
x: (px - widthDots / 2) / scale,
|
|
158
|
+
y: (py - heightDots / 2) / scale,
|
|
159
|
+
};
|
|
160
|
+
const hit = sample(p, blades);
|
|
161
|
+
if (!hit) continue;
|
|
162
|
+
mask |= bit;
|
|
163
|
+
if (hit === 1) dark++;
|
|
164
|
+
else if (hit === 2) lime++;
|
|
165
|
+
else outline++;
|
|
166
|
+
}
|
|
167
|
+
if (!mask) {
|
|
168
|
+
line += ' ';
|
|
169
|
+
} else {
|
|
170
|
+
// A Braille cell has a single foreground color. Choose the dominant fill.
|
|
171
|
+
const kind: Sample = lime > 0 && lime >= dark ? 2 :
|
|
172
|
+
outline >= 3 && dark === 0 && lime === 0 ? 3 : 1;
|
|
173
|
+
line += paint(String.fromCodePoint(0x2800 + mask), kind, color);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
lines.push(line);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (options.label !== '') {
|
|
180
|
+
const label = options.label ?? 'working';
|
|
181
|
+
const status = color
|
|
182
|
+
? `${COLORS.lime}●${COLORS.reset} ${COLORS.text}${label}${COLORS.reset}`
|
|
183
|
+
: `● ${label}`;
|
|
184
|
+
lines.push(status);
|
|
185
|
+
}
|
|
186
|
+
return lines.join('\n');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Standalone demo/CLI renderer. It owns its multi-line cursor region.
|
|
191
|
+
* If your app uses Ink/Blessed/another renderer, DO NOT call this function;
|
|
192
|
+
* use renderCausyneRotor() inside the existing renderer instead.
|
|
193
|
+
*/
|
|
194
|
+
export function startCausyneRotor(options: RotorOptions & { fps?: number | undefined } = {}): {
|
|
195
|
+
stop: () => void;
|
|
196
|
+
} {
|
|
197
|
+
const color = options.color ?? (Boolean(stdout.isTTY) && !process.env.NO_COLOR && !process.env.CAUSYNE_NO_COLOR);
|
|
198
|
+
if (!stdout.isTTY) {
|
|
199
|
+
stdout.write((options.label ?? 'working') + '\n');
|
|
200
|
+
return { stop() {} };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const fps = Math.max(4, Math.min(30, options.fps ?? 16));
|
|
204
|
+
const started = Date.now();
|
|
205
|
+
let stopped = false;
|
|
206
|
+
let lastLines = 0;
|
|
207
|
+
|
|
208
|
+
function draw(): void {
|
|
209
|
+
const frame = renderCausyneRotor(Date.now() - started, { ...options, color });
|
|
210
|
+
const lines = frame.split('\n');
|
|
211
|
+
// Redraw only our reserved lines, never clear the whole terminal.
|
|
212
|
+
if (lastLines > 0) stdout.write(`\x1b[${lastLines}A\r`);
|
|
213
|
+
stdout.write(lines.map((line) => `\x1b[2K${line}\n`).join(''));
|
|
214
|
+
lastLines = lines.length;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
stdout.write('\x1b[?25l'); // temporarily hide cursor
|
|
218
|
+
draw();
|
|
219
|
+
const timer = setInterval(draw, Math.round(1000 / fps));
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
stop(): void {
|
|
223
|
+
if (stopped) return;
|
|
224
|
+
stopped = true;
|
|
225
|
+
clearInterval(timer);
|
|
226
|
+
stdout.write('\x1b[?25h'); // restore cursor
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ---------------------------------------------------------------------------------------------------------
|
|
232
|
+
// Single-Line Status Row / Inline Spinner Integration
|
|
233
|
+
// ---------------------------------------------------------------------------------------------------------
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 2-character Braille rotor frames using the CausyneRotor palette (lime + charcoal).
|
|
237
|
+
* 6-phase rotation corresponding directly to the 60-degree indexed rotor blades.
|
|
238
|
+
*/
|
|
239
|
+
export const ROTOR_SPINNER_FRAMES: readonly string[] = [
|
|
240
|
+
`${COLORS.charcoal}⠇${COLORS.lime}⠙${COLORS.reset}`,
|
|
241
|
+
`${COLORS.charcoal}⠋${COLORS.lime}⠸${COLORS.reset}`,
|
|
242
|
+
`${COLORS.charcoal}⠙${COLORS.lime}⠴${COLORS.reset}`,
|
|
243
|
+
`${COLORS.lime}⠸${COLORS.charcoal}⠦${COLORS.reset}`,
|
|
244
|
+
`${COLORS.lime}⠴${COLORS.charcoal}⠇${COLORS.reset}`,
|
|
245
|
+
`${COLORS.lime}⠦${COLORS.charcoal}⠋${COLORS.reset}`,
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
export const ROTOR_SPINNER_FRAMES_NO_COLOR: readonly string[] = [
|
|
249
|
+
'⠇⠙', '⠋⠸', '⠙⠴', '⠸⠦', '⠴⠇', '⠦⠋',
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
export const ROTOR_SPINNER_FRAMES_ASCII: readonly string[] = [
|
|
253
|
+
'[-]', '[\\]', '[|]', '[/]',
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
export function getRotorSpinnerFrames(color = true, unicode = true): readonly string[] {
|
|
257
|
+
if (!unicode) return ROTOR_SPINNER_FRAMES_ASCII;
|
|
258
|
+
return color ? ROTOR_SPINNER_FRAMES : ROTOR_SPINNER_FRAMES_NO_COLOR;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function getRotorSpinnerFrame(tick: number, color = true, unicode = true): string {
|
|
262
|
+
const frames = getRotorSpinnerFrames(color, unicode);
|
|
263
|
+
const index = Math.abs(Math.floor(tick)) % frames.length;
|
|
264
|
+
return frames[index] ?? frames[0] ?? '⠇⠙';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const DOT_FRAMES = [' ', '. ', '.. ', '...'] as const;
|
|
268
|
+
|
|
269
|
+
export function getAnimatedDots(tick: number): string {
|
|
270
|
+
const stage = Math.floor(Math.abs(Math.floor(tick)) / 2) % DOT_FRAMES.length;
|
|
271
|
+
return DOT_FRAMES[stage] ?? ' ';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function formatAnimatedStatus(message: string, tick: number): string {
|
|
275
|
+
let base = (message || 'working').trimEnd();
|
|
276
|
+
while (base.endsWith('.') || base.endsWith('…')) {
|
|
277
|
+
base = base.slice(0, -1).trimEnd();
|
|
278
|
+
}
|
|
279
|
+
return `${base}${getAnimatedDots(tick)}`;
|
|
280
|
+
}
|
|
@@ -4,6 +4,6 @@ export function activityRows(message, columns, prefix = '▸ ') {
|
|
|
4
4
|
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
5
5
|
const inset = visibleWidth(prefix);
|
|
6
6
|
const bodyWidth = Math.max(1, width - inset - 1);
|
|
7
|
-
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang:
|
|
7
|
+
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 0 });
|
|
8
8
|
return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
|
|
9
9
|
}
|
|
@@ -5,6 +5,6 @@ export function activityRows(message: string, columns: number, prefix = '▸ '):
|
|
|
5
5
|
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
6
6
|
const inset = visibleWidth(prefix);
|
|
7
7
|
const bodyWidth = Math.max(1, width - inset - 1);
|
|
8
|
-
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang:
|
|
8
|
+
const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 0 });
|
|
9
9
|
return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
|
|
10
10
|
}
|
package/src/tui/chatRenderer.js
CHANGED
|
@@ -94,6 +94,11 @@ function renderMarkdown(text, width) {
|
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
98
|
+
lines.push(dim(GLYPHS.hLine.repeat(Math.max(4, Math.min(width, 40)))));
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
97
102
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
98
103
|
if (bullet) {
|
|
99
104
|
const indent = bullet[1] + ' ';
|
|
@@ -104,6 +109,39 @@ function renderMarkdown(text, width) {
|
|
|
104
109
|
continue;
|
|
105
110
|
}
|
|
106
111
|
|
|
112
|
+
const numbered = line.match(/^(\s*)(\d+\.)\s+(.*)$/);
|
|
113
|
+
if (numbered) {
|
|
114
|
+
const prefix = `${numbered[1]}${bold(numbered[2])} `;
|
|
115
|
+
const indent = ' '.repeat(visibleWidth(`${numbered[1]}${numbered[2]} `));
|
|
116
|
+
const wrapped = wrap(inline(numbered[3]), width - indent.length);
|
|
117
|
+
wrapped.forEach((part, index) => {
|
|
118
|
+
lines.push(index === 0 ? `${prefix}${part}` : `${indent}${part}`);
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const quote = line.match(/^(\s*)>\s?(.*)$/);
|
|
124
|
+
if (quote) {
|
|
125
|
+
const indent = quote[1] + paint('muted', '│ ');
|
|
126
|
+
const wrapped = wrap(inline(quote[2]), width - visibleWidth(indent));
|
|
127
|
+
wrapped.forEach((part) => {
|
|
128
|
+
lines.push(`${indent}${part}`);
|
|
129
|
+
});
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (/^\s*\|?(\s*:?-+:?\s*\|)+\s*$/.test(line)) {
|
|
134
|
+
lines.push(dim(' ' + GLYPHS.hLine.repeat(Math.max(4, Math.min(width - 4, 48)))));
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const tableRow = line.match(/^\s*\|(.+)\|\s*$/);
|
|
139
|
+
if (tableRow) {
|
|
140
|
+
const cells = tableRow[1].split('|').map(c => inline(c.trim()));
|
|
141
|
+
lines.push(' ' + cells.join(paint('muted', ' │ ')));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
107
145
|
const trimmed = line.trim();
|
|
108
146
|
if (trimmed === '') { lines.push(''); continue; }
|
|
109
147
|
if (trimmed === '[' || trimmed === ']') continue;
|
|
@@ -206,8 +244,18 @@ function inline(text) {
|
|
|
206
244
|
out = out.replace(/`([^`]+)`/g, (_m, code) => stash(HAS_COLOR ? paint('accent', code) : code));
|
|
207
245
|
out = formatMarkdownMath(out);
|
|
208
246
|
out = HAS_COLOR
|
|
209
|
-
? out.replace(
|
|
247
|
+
? out.replace(/\*\*\*([^*]+)\*\*\*/g, (_m, strong) => bold(paint('accent', strong)))
|
|
248
|
+
: out.replace(/\*\*\*([^*]+)\*\*\*/g, '$1');
|
|
249
|
+
out = HAS_COLOR
|
|
250
|
+
? out.replace(/\*\*([^*]+)\*\*/g, (_m, strong) => bold(strong))
|
|
210
251
|
: out.replace(/\*\*([^*]+)\*\*/g, '$1');
|
|
252
|
+
out = HAS_COLOR
|
|
253
|
+
? out.replace(/(?<=^|[\s(])\*([^*\s](?:[^*]*[^*\s])?)\*(?=[\s).,!?]|$)/g, (_m, italic) => `\x1b[3m${italic}\x1b[23m`)
|
|
254
|
+
: out.replace(/(?<=^|[\s(])\*([^*\s](?:[^*]*[^*\s])?)\*(?=[\s).,!?]|$)/g, '$1');
|
|
255
|
+
out = HAS_COLOR
|
|
256
|
+
? out.replace(/(?<=^|[\s(])_([^\s_](?:[^_]*[^\s_])?)_(?=[\s).,!?]|$)/g, (_m, italic) => `\x1b[3m${italic}\x1b[23m`)
|
|
257
|
+
: out.replace(/(?<=^|[\s(])_([^\s_](?:[^_]*[^\s_])?)_(?=[\s).,!?]|$)/g, '$1');
|
|
258
|
+
out = out.replace(/~~([^~]+)~~/g, HAS_COLOR ? '\x1b[9m$1\x1b[29m' : '$1');
|
|
211
259
|
|
|
212
260
|
if (stashed.length > 0) {
|
|
213
261
|
out = out.replace(/\u0000(\d+)\u0000/g, (m, index) => stashed[Number(index)] || '');
|
|
@@ -472,11 +520,12 @@ export class ChatRenderer {
|
|
|
472
520
|
elapsedMs: Date.now() - since,
|
|
473
521
|
steps: this.stepCount,
|
|
474
522
|
width: this.width() - 1,
|
|
475
|
-
spinnerFrame: frame
|
|
523
|
+
spinnerFrame: frame,
|
|
524
|
+
tick: this.spinnerIndex
|
|
476
525
|
}));
|
|
477
526
|
readline.clearLine(this.out, 1);
|
|
478
527
|
this.spinnerIndex++;
|
|
479
|
-
},
|
|
528
|
+
}, 125);
|
|
480
529
|
}
|
|
481
530
|
|
|
482
531
|
stopSpinner() {
|
|
@@ -952,7 +1001,7 @@ export class ChatRenderer {
|
|
|
952
1001
|
this.frame('approval', () => {
|
|
953
1002
|
this.write();
|
|
954
1003
|
this.write(`${paint('accent', GLYPHS.arrow)} ${bold(safeDisplay(request.header || 'decision required'))}`);
|
|
955
|
-
for (const row of wrapBlock(safeDisplay(request.question || ''), Math.max(20, this.width() - 4))) this.write(` ${row}`);
|
|
1004
|
+
for (const row of wrapBlock(safeDisplay(request.question || ''), Math.max(20, this.width() - 4), { hang: 0 })) this.write(` ${row}`);
|
|
956
1005
|
this.write();
|
|
957
1006
|
}, { kind: request.kind || 'other' });
|
|
958
1007
|
}
|
|
@@ -1174,7 +1223,7 @@ export class ChatRenderer {
|
|
|
1174
1223
|
const head = label ? `${label} ${detail}` : detail;
|
|
1175
1224
|
|
|
1176
1225
|
this.frame('error', () => {
|
|
1177
|
-
const rows = wrapBlock(head, Math.max(20, this.width() - 7));
|
|
1226
|
+
const rows = wrapBlock(head, Math.max(20, this.width() - 7), { hang: 0 });
|
|
1178
1227
|
this.write(` ${paint('danger', GLYPHS.cross)} ${paint('danger', rows[0] || '')}`);
|
|
1179
1228
|
for (const row of rows.slice(1)) this.write(` ${dim(row)}`);
|
|
1180
1229
|
}, { tool: msg.tool });
|
|
@@ -1315,7 +1364,7 @@ export class ChatRenderer {
|
|
|
1315
1364
|
this.write();
|
|
1316
1365
|
this.write(truncate(head, width - 1, GLYPHS.ellipsis));
|
|
1317
1366
|
if (instruction) {
|
|
1318
|
-
for (const line of wrapBlock(safeDisplay(instruction), width - 4)) {
|
|
1367
|
+
for (const line of wrapBlock(safeDisplay(instruction), width - 4, { hang: 0 })) {
|
|
1319
1368
|
this.write(dim(` ${line}`));
|
|
1320
1369
|
}
|
|
1321
1370
|
}
|
|
@@ -1340,7 +1389,7 @@ export class ChatRenderer {
|
|
|
1340
1389
|
this.frame('notice', () => {
|
|
1341
1390
|
const width = this.measure();
|
|
1342
1391
|
const marker = paint(tone === 'muted' ? 'rule' : tone, GLYPHS.vLine);
|
|
1343
|
-
for (const line of wrapBlock(message, width - 2)) {
|
|
1392
|
+
for (const line of wrapBlock(message, width - 2, { hang: 0 })) {
|
|
1344
1393
|
this.write(`${marker} ${dim(line)}`);
|
|
1345
1394
|
}
|
|
1346
1395
|
}, { tone });
|