@causyne/agent 1.20.60 → 1.20.63
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/agentCatalog.js +1 -1
- package/src/acp/agentCatalog.ts +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/acp/peerProfiles.js +3 -3
- package/src/acp/peerProfiles.ts +3 -3
- package/src/agentLoop.js +239 -33
- package/src/agentLoop.ts +248 -36
- package/src/checkpoints.js +23 -5
- package/src/cliMode.js +13 -2
- package/src/commands.js +534 -78
- package/src/contextManager.d.ts +3 -0
- package/src/contextManager.js +78 -5
- package/src/cortex/autoCondenser.js +105 -145
- package/src/cortex/autoCondenser.ts +185 -0
- package/src/cortex/cortexEngine.js +179 -0
- package/src/cortex/cortexEngine.ts +209 -0
- package/src/cortex/provisioner.js +12 -14
- package/src/cortex/provisioner.ts +29 -0
- package/src/cortex/vectorDb.js +307 -386
- package/src/cortex/vectorDb.ts +473 -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/reporting.js +30 -7
- package/src/sessionJournal.js +13 -0
- package/src/sessionJournal.ts +13 -0
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/tokenTracker.js +22 -0
- package/src/tokenTracker.ts +28 -0
- 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 +62 -9
- 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/completion.js +34 -15
- package/src/tui/composerControls.js +5 -0
- package/src/tui/composerControls.ts +5 -0
- package/src/tui/dialogs.js +5 -2
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/layout.js +1 -1
- package/src/tui/layout.ts +1 -1
- 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 +319 -0
- package/src/tui/observerPicker.ts +382 -0
- package/src/tui/prompt.js +247 -55
- 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 +27 -10
- 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
- package/src/tui/usageCard.js +178 -0
- package/src/tui/usageCard.ts +240 -0
- package/src/utils/paths.js +30 -1
- package/src/utils/paths.ts +32 -1
- package/src/cortex/autoCondenser.d.ts +0 -2
- package/src/cortex/vectorDb.d.ts +0 -1
|
@@ -634,19 +634,62 @@ export function resolveParameterAliases(toolName, args, schema) {
|
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
636
|
else if (canonicalName === 'update_plan') {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
637
|
+
// Peer checklist tools (TodoWrite / todowrite) are aliased to update_plan by
|
|
638
|
+
// name, so their argument shapes must be mapped here as well.
|
|
639
|
+
const planAliases = ['steps', 'items', 'tasks', 'todos', 'entries', 'checklist'];
|
|
640
|
+
if (modified.plan === undefined || modified.plan === null || modified.plan === '') {
|
|
641
|
+
const source = planAliases.find((key) => modified[key] !== undefined && modified[key] !== null);
|
|
642
|
+
if (source) {
|
|
643
|
+
modified.plan = modified[source];
|
|
644
|
+
repairs.push(`Mapped '${source}' to 'plan' parameter for 'update_plan'`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
for (const key of planAliases)
|
|
648
|
+
delete modified[key];
|
|
649
|
+
if (typeof modified.plan === 'string') {
|
|
650
|
+
const text = modified.plan.trim();
|
|
651
|
+
let parsed;
|
|
652
|
+
if (text.startsWith('[') || text.startsWith('{')) {
|
|
653
|
+
try {
|
|
654
|
+
parsed = JSON.parse(text);
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
parsed = undefined;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
661
|
+
const inner = parsed;
|
|
662
|
+
parsed = inner.plan ?? inner.todos ?? inner.steps ?? inner.items ?? parsed;
|
|
663
|
+
}
|
|
664
|
+
if (Array.isArray(parsed)) {
|
|
665
|
+
modified.plan = parsed;
|
|
666
|
+
repairs.push("Parsed JSON-encoded 'plan' for 'update_plan'");
|
|
667
|
+
}
|
|
668
|
+
else if (text) {
|
|
669
|
+
const lines = text.split(/\r?\n/)
|
|
670
|
+
.map((line) => line.replace(/^\s*(?:[-*+]|\d+[.)])?\s*(?:\[[ xX]\])?\s*/, '').trim())
|
|
671
|
+
.filter(Boolean);
|
|
672
|
+
if (lines.length > 0) {
|
|
673
|
+
modified.plan = lines;
|
|
674
|
+
repairs.push("Split plain-text 'plan' into steps for 'update_plan'");
|
|
675
|
+
}
|
|
676
|
+
}
|
|
643
677
|
}
|
|
644
678
|
if (Array.isArray(modified.plan)) {
|
|
645
679
|
let activeCount = 0;
|
|
646
|
-
modified.plan = modified.plan.map((
|
|
647
|
-
|
|
680
|
+
modified.plan = modified.plan.map((entry, idx) => {
|
|
681
|
+
const raw = typeof entry === 'string' && entry.trim()
|
|
682
|
+
? { step: entry.trim(), status: 'pending' }
|
|
683
|
+
: entry;
|
|
684
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
648
685
|
return raw;
|
|
649
686
|
const item = { ...raw };
|
|
687
|
+
if (item.activeForm !== undefined)
|
|
688
|
+
delete item.activeForm;
|
|
689
|
+
if (item.priority !== undefined)
|
|
690
|
+
delete item.priority;
|
|
691
|
+
if (item.id !== undefined && typeof item.id !== 'string')
|
|
692
|
+
item.id = String(item.id);
|
|
650
693
|
if (!item.id)
|
|
651
694
|
item.id = `step-${idx + 1}`;
|
|
652
695
|
if (!item.step && (item.content || item.title || item.name || item.description)) {
|
|
@@ -680,18 +680,51 @@ export function resolveParameterAliases(
|
|
|
680
680
|
});
|
|
681
681
|
}
|
|
682
682
|
} else if (canonicalName === 'update_plan') {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
683
|
+
// Peer checklist tools (TodoWrite / todowrite) are aliased to update_plan by
|
|
684
|
+
// name, so their argument shapes must be mapped here as well.
|
|
685
|
+
const planAliases = ['steps', 'items', 'tasks', 'todos', 'entries', 'checklist'] as const;
|
|
686
|
+
if (modified.plan === undefined || modified.plan === null || modified.plan === '') {
|
|
687
|
+
const source = planAliases.find((key) => modified[key] !== undefined && modified[key] !== null);
|
|
688
|
+
if (source) {
|
|
689
|
+
modified.plan = modified[source];
|
|
690
|
+
repairs.push(`Mapped '${source}' to 'plan' parameter for 'update_plan'`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
for (const key of planAliases) delete modified[key];
|
|
694
|
+
if (typeof modified.plan === 'string') {
|
|
695
|
+
const text = modified.plan.trim();
|
|
696
|
+
let parsed: unknown;
|
|
697
|
+
if (text.startsWith('[') || text.startsWith('{')) {
|
|
698
|
+
try { parsed = JSON.parse(text); } catch { parsed = undefined; }
|
|
699
|
+
}
|
|
700
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
701
|
+
const inner = parsed as Record<string, unknown>;
|
|
702
|
+
parsed = inner.plan ?? inner.todos ?? inner.steps ?? inner.items ?? parsed;
|
|
703
|
+
}
|
|
704
|
+
if (Array.isArray(parsed)) {
|
|
705
|
+
modified.plan = parsed;
|
|
706
|
+
repairs.push("Parsed JSON-encoded 'plan' for 'update_plan'");
|
|
707
|
+
} else if (text) {
|
|
708
|
+
const lines = text.split(/\r?\n/)
|
|
709
|
+
.map((line) => line.replace(/^\s*(?:[-*+]|\d+[.)])?\s*(?:\[[ xX]\])?\s*/, '').trim())
|
|
710
|
+
.filter(Boolean);
|
|
711
|
+
if (lines.length > 0) {
|
|
712
|
+
modified.plan = lines;
|
|
713
|
+
repairs.push("Split plain-text 'plan' into steps for 'update_plan'");
|
|
714
|
+
}
|
|
715
|
+
}
|
|
689
716
|
}
|
|
690
717
|
if (Array.isArray(modified.plan)) {
|
|
691
718
|
let activeCount = 0;
|
|
692
|
-
modified.plan = (modified.plan as
|
|
693
|
-
|
|
694
|
-
|
|
719
|
+
modified.plan = (modified.plan as unknown[]).map((entry, idx) => {
|
|
720
|
+
const raw: unknown = typeof entry === 'string' && entry.trim()
|
|
721
|
+
? { step: entry.trim(), status: 'pending' }
|
|
722
|
+
: entry;
|
|
723
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return raw;
|
|
724
|
+
const item: Record<string, unknown> = { ...(raw as Record<string, unknown>) };
|
|
725
|
+
if (item.activeForm !== undefined) delete item.activeForm;
|
|
726
|
+
if (item.priority !== undefined) delete item.priority;
|
|
727
|
+
if (item.id !== undefined && typeof item.id !== 'string') item.id = String(item.id);
|
|
695
728
|
if (!item.id) item.id = `step-${idx + 1}`;
|
|
696
729
|
if (!item.step && (item.content || item.title || item.name || item.description)) {
|
|
697
730
|
item.step = item.content || item.title || item.name || item.description;
|
|
@@ -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
|
}
|