clarity-ai 6.0.0 → 6.1.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/bin/clarity.js +24 -1
- package/package.json +1 -1
- package/src/app.js +33 -18
- package/src/components/Composer.js +10 -11
package/bin/clarity.js
CHANGED
|
@@ -5,6 +5,11 @@ import { App } from '../src/app.js';
|
|
|
5
5
|
import { hasKey } from '../src/config/keys.js';
|
|
6
6
|
import { createInterface } from 'readline';
|
|
7
7
|
|
|
8
|
+
// EXACTLY ONE screen clear — before any async, before Ink mount.
|
|
9
|
+
// Use safe clear (2J = clear visible screen, 0f = home cursor).
|
|
10
|
+
// Do NOT use \x1Bc (RIS) — it resets the entire terminal aggressively.
|
|
11
|
+
process.stdout.write('\x1b[2J\x1b[0f');
|
|
12
|
+
|
|
8
13
|
async function main() {
|
|
9
14
|
const provider = process.env.CLARITY_PROVIDER || 'groq';
|
|
10
15
|
|
|
@@ -18,13 +23,31 @@ async function main() {
|
|
|
18
23
|
});
|
|
19
24
|
const { setKey } = await import('../src/config/keys.js');
|
|
20
25
|
setKey(provider, key);
|
|
26
|
+
// Clear the key-prompt residue. Still \x1b[2J, not \x1Bc.
|
|
27
|
+
process.stdout.write('\x1b[2J\x1b[0f');
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
const config = { provider, model: process.env.CLARITY_MODEL || 'groq/llama-3.3-70b-versatile' };
|
|
24
|
-
|
|
31
|
+
|
|
32
|
+
// Let Ink manage all rendering from here.
|
|
33
|
+
const { waitUntilExit } = render(React.createElement(App, { config }), { fullscreen: true });
|
|
34
|
+
|
|
35
|
+
// Cleanup: restore cursor, reset text — no screen clearing, no RIS.
|
|
36
|
+
function cleanup() {
|
|
37
|
+
process.stdout.write('\x1b[?25h\x1b[0m');
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
process.on('SIGINT', cleanup);
|
|
42
|
+
process.on('SIGTERM', cleanup);
|
|
43
|
+
|
|
44
|
+
await waitUntilExit;
|
|
45
|
+
cleanup();
|
|
25
46
|
}
|
|
26
47
|
|
|
27
48
|
main().catch(err => {
|
|
49
|
+
// Restore terminal state without clearing the screen.
|
|
50
|
+
process.stdout.write('\x1b[?25h\x1b[0m');
|
|
28
51
|
console.error('\n\x1b[31mFatal error:\x1b[0m', err.message);
|
|
29
52
|
process.exit(1);
|
|
30
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clarity-ai",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Premium OpenCode-style terminal AI agent — 24-bit TrueColor theme, 8s timeout recovery, virtual scroll, inline tool trees, collapsible thought cards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useCallback } from 'react';
|
|
1
|
+
import React, { useState, useCallback, useRef, useEffect } from 'react';
|
|
2
2
|
import { Box } from 'ink';
|
|
3
3
|
import { Banner } from './components/Banner.js';
|
|
4
4
|
import { MessageList } from './components/MessageList.js';
|
|
@@ -6,6 +6,7 @@ import { Composer } from './components/Composer.js';
|
|
|
6
6
|
import { CommandPicker } from './components/CommandPicker.js';
|
|
7
7
|
import { ModelPicker } from './components/ModelPicker.js';
|
|
8
8
|
import { createChatState, handleSend, handleCommand } from './chat.js';
|
|
9
|
+
import { theme } from './config/theme.js';
|
|
9
10
|
const { createElement: h } = React;
|
|
10
11
|
|
|
11
12
|
export function App({ config }) {
|
|
@@ -18,16 +19,24 @@ export function App({ config }) {
|
|
|
18
19
|
const [showModels, setShowModels] = useState(false);
|
|
19
20
|
const [showBanner, setShowBanner] = useState(true);
|
|
20
21
|
|
|
22
|
+
// Use refs to avoid stale closures in callbacks
|
|
23
|
+
const stateRef = useRef(state);
|
|
24
|
+
const modelRef = useRef(model);
|
|
25
|
+
const providerRef = useRef(provider);
|
|
26
|
+
stateRef.current = state;
|
|
27
|
+
modelRef.current = model;
|
|
28
|
+
providerRef.current = provider;
|
|
29
|
+
|
|
21
30
|
const onSubmit = useCallback(async (input) => {
|
|
22
31
|
if (input.startsWith('/')) {
|
|
23
32
|
if (input === '/model' || input === '/models') { setShowModels(true); return; }
|
|
24
33
|
if (input === '/help') { setShowCommands(true); return; }
|
|
25
|
-
await handleCommand(input,
|
|
34
|
+
await handleCommand(input, stateRef.current, setState, setModel, setProvider, modelRef.current, providerRef.current);
|
|
26
35
|
return;
|
|
27
36
|
}
|
|
28
37
|
if (showBanner) setShowBanner(false);
|
|
29
|
-
await handleSend(
|
|
30
|
-
}, [
|
|
38
|
+
await handleSend(stateRef.current, setState, input, modelRef.current, providerRef.current, setStreamContent);
|
|
39
|
+
}, [showBanner]);
|
|
31
40
|
|
|
32
41
|
function handleCommandSelect(cmdName) {
|
|
33
42
|
setShowCommands(false);
|
|
@@ -45,20 +54,26 @@ export function App({ config }) {
|
|
|
45
54
|
}));
|
|
46
55
|
}
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const termHeight = process.stdout.rows || 30;
|
|
58
|
+
|
|
59
|
+
return h(Box, { flexDirection: 'column', backgroundColor: theme.bg },
|
|
60
|
+
h(Box, { flexGrow: 1, flexShrink: 1, flexDirection: 'column', minHeight: 0 },
|
|
61
|
+
showBanner
|
|
62
|
+
? h(Banner)
|
|
63
|
+
: null,
|
|
64
|
+
h(Box, { flexGrow: 1, flexShrink: 1, minHeight: 0 },
|
|
65
|
+
h(MessageList, {
|
|
66
|
+
messages: state.messages,
|
|
67
|
+
thinking: state.thinking,
|
|
68
|
+
streamContent,
|
|
69
|
+
agentStatus: state.agentStatus,
|
|
70
|
+
toolExecutions: state.toolExecutions,
|
|
71
|
+
})
|
|
72
|
+
)
|
|
58
73
|
),
|
|
59
74
|
showCommands
|
|
60
|
-
? h(Box, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center' },
|
|
61
|
-
h(Box, { backgroundColor:
|
|
75
|
+
? h(Box, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center' },
|
|
76
|
+
h(Box, { backgroundColor: theme.bg, borderStyle: 'round', borderColor: theme.borderLight, paddingX: 2, paddingY: 1 },
|
|
62
77
|
h(CommandPicker, {
|
|
63
78
|
query: '',
|
|
64
79
|
onSelect: handleCommandSelect,
|
|
@@ -68,8 +83,8 @@ export function App({ config }) {
|
|
|
68
83
|
)
|
|
69
84
|
: null,
|
|
70
85
|
showModels
|
|
71
|
-
? h(Box, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center' },
|
|
72
|
-
h(Box, { backgroundColor:
|
|
86
|
+
? h(Box, { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center' },
|
|
87
|
+
h(Box, { backgroundColor: theme.bg, borderStyle: 'round', borderColor: theme.borderLight, paddingX: 2, paddingY: 1 },
|
|
73
88
|
h(ModelPicker, {
|
|
74
89
|
onSelect: handleModelSelect,
|
|
75
90
|
onClose: () => setShowModels(false),
|
|
@@ -2,22 +2,21 @@ import React, { useState, useRef } from 'react';
|
|
|
2
2
|
import { Box, Text, useInput } from 'ink';
|
|
3
3
|
import { theme } from '../config/theme.js';
|
|
4
4
|
const { createElement: h } = React;
|
|
5
|
-
const w = () => process.stdout.columns || 80;
|
|
6
5
|
|
|
7
6
|
export function Composer({ provider, model, agentMode, thinking, onSlash, onSubmit }) {
|
|
8
7
|
const [lines, setLines] = useState(['']);
|
|
9
8
|
const [cursorLine, setCursorLine] = useState(0);
|
|
9
|
+
const [cursorCol, setCursorCol] = useState(0);
|
|
10
10
|
const buf = useRef({ lines: [''], line: 0, col: 0 });
|
|
11
11
|
const displayName = provider + '/' + model;
|
|
12
12
|
|
|
13
13
|
useInput((input, key) => {
|
|
14
|
-
if (thinking) return;
|
|
15
14
|
const s = buf.current;
|
|
16
15
|
|
|
17
|
-
if (key.return && !key.shift) {
|
|
16
|
+
if (key.return && !key.shift && !thinking) {
|
|
18
17
|
const text = s.lines.join('\n');
|
|
19
18
|
s.lines = ['']; s.line = 0; s.col = 0;
|
|
20
|
-
setLines(['']); setCursorLine(0);
|
|
19
|
+
setLines(['']); setCursorLine(0); setCursorCol(0);
|
|
21
20
|
if (text.trim()) onSubmit(text);
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
@@ -27,7 +26,7 @@ export function Composer({ provider, model, agentMode, thinking, onSlash, onSubm
|
|
|
27
26
|
s.lines[s.line] = s.lines[s.line].slice(0, s.col);
|
|
28
27
|
s.lines.splice(s.line + 1, 0, rest);
|
|
29
28
|
s.line++; s.col = 0;
|
|
30
|
-
setLines([...s.lines]); setCursorLine(s.line);
|
|
29
|
+
setLines([...s.lines]); setCursorLine(s.line); setCursorCol(0);
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -41,20 +40,20 @@ export function Composer({ provider, model, agentMode, thinking, onSlash, onSubm
|
|
|
41
40
|
s.lines.splice(s.line, 1);
|
|
42
41
|
s.line--;
|
|
43
42
|
}
|
|
44
|
-
setLines([...s.lines]); setCursorLine(s.line);
|
|
43
|
+
setLines([...s.lines]); setCursorLine(s.line); setCursorCol(s.col);
|
|
45
44
|
return;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
if (key.upArrow && s.line > 0) { s.line--; s.col = Math.min(s.col, s.lines[s.line].length); setCursorLine(s.line);
|
|
49
|
-
if (key.downArrow && s.line < s.lines.length - 1) { s.line++; s.col = Math.min(s.col, s.lines[s.line].length); setCursorLine(s.line);
|
|
50
|
-
if (key.leftArrow) { if (s.col > 0) s.col--; else if (s.line > 0) { s.line--; s.col = s.lines[s.line].length; } setCursorLine(s.line);
|
|
51
|
-
if (key.rightArrow) { if (s.col < s.lines[s.line].length) s.col++; else if (s.line < s.lines.length - 1) { s.line++; s.col = 0; } setCursorLine(s.line);
|
|
47
|
+
if (key.upArrow && s.line > 0) { s.line--; s.col = Math.min(s.col, s.lines[s.line].length); setCursorLine(s.line); setCursorCol(s.col); return; }
|
|
48
|
+
if (key.downArrow && s.line < s.lines.length - 1) { s.line++; s.col = Math.min(s.col, s.lines[s.line].length); setCursorLine(s.line); setCursorCol(s.col); return; }
|
|
49
|
+
if (key.leftArrow) { if (s.col > 0) s.col--; else if (s.line > 0) { s.line--; s.col = s.lines[s.line].length; } setCursorLine(s.line); setCursorCol(s.col); return; }
|
|
50
|
+
if (key.rightArrow) { if (s.col < s.lines[s.line].length) s.col++; else if (s.line < s.lines.length - 1) { s.line++; s.col = 0; } setCursorLine(s.line); setCursorCol(s.col); return; }
|
|
52
51
|
|
|
53
52
|
if (input && input.length === 1 && !key.ctrl && !key.meta) {
|
|
54
53
|
if (input === '/' && s.lines.length === 1 && s.lines[0] === '') { onSlash?.(); return; }
|
|
55
54
|
s.lines[s.line] = s.lines[s.line].slice(0, s.col) + input + s.lines[s.line].slice(s.col);
|
|
56
55
|
s.col++;
|
|
57
|
-
setLines([...s.lines]); setCursorLine(s.line);
|
|
56
|
+
setLines([...s.lines]); setCursorLine(s.line); setCursorCol(s.col);
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
|