clarity-ai 6.1.1 → 6.2.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 +22 -8
- package/package.json +1 -1
- package/src/app.js +27 -43
- package/src/chat.js +5 -1
- package/src/components/ToolCard.js +16 -11
package/bin/clarity.js
CHANGED
|
@@ -5,15 +5,19 @@ 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
8
|
process.stdout.write('\x1b[2J\x1b[0f');
|
|
12
9
|
|
|
10
|
+
// Force stdin into flowing mode BEFORE any I/O that might pause it.
|
|
11
|
+
// Without this, Ink's useInput never activates, the event loop
|
|
12
|
+
// has no handles, and the process exits immediately.
|
|
13
|
+
process.stdin.resume();
|
|
14
|
+
process.stdin.setEncoding('utf8');
|
|
15
|
+
|
|
13
16
|
async function main() {
|
|
14
17
|
const provider = process.env.CLARITY_PROVIDER || 'groq';
|
|
15
18
|
|
|
16
19
|
if (!hasKey(provider)) {
|
|
20
|
+
// Save raw state before readline hijacks stdin
|
|
17
21
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
18
22
|
const key = await new Promise(resolve => {
|
|
19
23
|
rl.question('\n\x1b[33m No ' + provider + ' API key found.\x1b[0m\n Enter your ' + provider + ' key: ', (answer) => {
|
|
@@ -23,17 +27,28 @@ async function main() {
|
|
|
23
27
|
});
|
|
24
28
|
const { setKey } = await import('../src/config/keys.js');
|
|
25
29
|
setKey(provider, key);
|
|
26
|
-
// Clear the key-prompt residue. Still \x1b[2J, not \x1Bc.
|
|
27
30
|
process.stdout.write('\x1b[2J\x1b[0f');
|
|
31
|
+
// Re-resume stdin — readline.close() can leave it paused
|
|
32
|
+
process.stdin.resume();
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
const config = { provider, model: process.env.CLARITY_MODEL || 'groq/llama-3.3-70b-versatile' };
|
|
31
36
|
|
|
32
|
-
//
|
|
33
|
-
|
|
37
|
+
// Mount Ink. fullscreen:true tells Ink to own stdin/output.
|
|
38
|
+
// Keep the render ref so we can wait for graceful exit.
|
|
39
|
+
const { waitUntilExit, clear } = render(React.createElement(App, { config }), {
|
|
40
|
+
fullscreen: true,
|
|
41
|
+
patchConsole: false,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Keep the event loop alive even if Ink's reconciler settles.
|
|
45
|
+
// On some Termux/Node combos, waitUntilExit can fire early when
|
|
46
|
+
// no async updates are pending — this interval prevents that.
|
|
47
|
+
const keepAlive = setInterval(() => {}, 2 ** 31 - 1);
|
|
34
48
|
|
|
35
|
-
// Cleanup: restore cursor, reset text — no screen clearing, no RIS.
|
|
36
49
|
function cleanup() {
|
|
50
|
+
clearInterval(keepAlive);
|
|
51
|
+
clear();
|
|
37
52
|
process.stdout.write('\x1b[?25h\x1b[0m');
|
|
38
53
|
process.exit(0);
|
|
39
54
|
}
|
|
@@ -46,7 +61,6 @@ async function main() {
|
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
main().catch(err => {
|
|
49
|
-
// Restore terminal state without clearing the screen.
|
|
50
64
|
process.stdout.write('\x1b[?25h\x1b[0m');
|
|
51
65
|
console.error('\n\x1b[31mFatal error:\x1b[0m', err.message);
|
|
52
66
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clarity-ai",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.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,6 +1,5 @@
|
|
|
1
|
-
import React, { useState, useCallback, useRef
|
|
1
|
+
import React, { useState, useCallback, useRef } from 'react';
|
|
2
2
|
import { Box } from 'ink';
|
|
3
|
-
import { Banner } from './components/Banner.js';
|
|
4
3
|
import { MessageList } from './components/MessageList.js';
|
|
5
4
|
import { Composer } from './components/Composer.js';
|
|
6
5
|
import { CommandPicker } from './components/CommandPicker.js';
|
|
@@ -17,9 +16,7 @@ export function App({ config }) {
|
|
|
17
16
|
const [provider, setProvider] = useState(config.provider || 'groq');
|
|
18
17
|
const [showCommands, setShowCommands] = useState(false);
|
|
19
18
|
const [showModels, setShowModels] = useState(false);
|
|
20
|
-
const [showBanner, setShowBanner] = useState(true);
|
|
21
19
|
|
|
22
|
-
// Use refs to avoid stale closures in callbacks
|
|
23
20
|
const stateRef = useRef(state);
|
|
24
21
|
const modelRef = useRef(model);
|
|
25
22
|
const providerRef = useRef(provider);
|
|
@@ -34,9 +31,8 @@ export function App({ config }) {
|
|
|
34
31
|
await handleCommand(input, stateRef.current, setState, setModel, setProvider, modelRef.current, providerRef.current);
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
37
|
-
if (showBanner) setShowBanner(false);
|
|
38
34
|
await handleSend(stateRef.current, setState, input, modelRef.current, providerRef.current, setStreamContent);
|
|
39
|
-
}, [
|
|
35
|
+
}, []);
|
|
40
36
|
|
|
41
37
|
function handleCommandSelect(cmdName) {
|
|
42
38
|
setShowCommands(false);
|
|
@@ -44,8 +40,7 @@ export function App({ config }) {
|
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
function handleModelSelect(modelId) {
|
|
47
|
-
|
|
48
|
-
setProvider(p);
|
|
43
|
+
setProvider(modelId.split('/')[0]);
|
|
49
44
|
setModel(modelId.replace(/^[^/]+\//, ''));
|
|
50
45
|
setShowModels(false);
|
|
51
46
|
setState(s => ({
|
|
@@ -54,42 +49,31 @@ export function App({ config }) {
|
|
|
54
49
|
}));
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
messages: state.messages,
|
|
67
|
-
thinking: state.thinking,
|
|
68
|
-
streamContent,
|
|
69
|
-
agentStatus: state.agentStatus,
|
|
70
|
-
toolExecutions: state.toolExecutions,
|
|
71
|
-
})
|
|
72
|
-
)
|
|
52
|
+
return h(Box, { flexDirection: 'column', backgroundColor: theme.bg, minHeight: '100%' },
|
|
53
|
+
h(Box, { flexGrow: 1, flexDirection: 'column', minHeight: 0 },
|
|
54
|
+
h(MessageList, {
|
|
55
|
+
messages: state.messages,
|
|
56
|
+
thinking: state.thinking,
|
|
57
|
+
streamContent,
|
|
58
|
+
agentStatus: state.agentStatus,
|
|
59
|
+
toolExecutions: state.toolExecutions,
|
|
60
|
+
})
|
|
73
61
|
),
|
|
74
|
-
showCommands
|
|
75
|
-
? h(Box, {
|
|
76
|
-
|
|
77
|
-
h(CommandPicker, {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
onSelect: handleModelSelect,
|
|
90
|
-
onClose: () => setShowModels(false),
|
|
91
|
-
})
|
|
92
|
-
)
|
|
62
|
+
showCommands || showModels
|
|
63
|
+
? h(Box, { flexDirection: 'column', marginBottom: 1, backgroundColor: theme.surfaceAlt, borderStyle: 'round', borderColor: theme.borderLight },
|
|
64
|
+
showCommands
|
|
65
|
+
? h(CommandPicker, {
|
|
66
|
+
query: '',
|
|
67
|
+
onSelect: handleCommandSelect,
|
|
68
|
+
onClose: () => setShowCommands(false),
|
|
69
|
+
})
|
|
70
|
+
: null,
|
|
71
|
+
showModels
|
|
72
|
+
? h(ModelPicker, {
|
|
73
|
+
onSelect: handleModelSelect,
|
|
74
|
+
onClose: () => setShowModels(false),
|
|
75
|
+
})
|
|
76
|
+
: null
|
|
93
77
|
)
|
|
94
78
|
: null,
|
|
95
79
|
h(Composer, {
|
package/src/chat.js
CHANGED
|
@@ -5,7 +5,11 @@ const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
|
5
5
|
|
|
6
6
|
export function createChatState() {
|
|
7
7
|
return {
|
|
8
|
-
messages: [
|
|
8
|
+
messages: [{
|
|
9
|
+
id: 'welcome',
|
|
10
|
+
role: 'system',
|
|
11
|
+
content: 'CLARITY AI ready \u00B7 Ctrl+P commands \u00B7 /help',
|
|
12
|
+
}],
|
|
9
13
|
thinking: false,
|
|
10
14
|
streamContent: '',
|
|
11
15
|
awaitingKey: false,
|
|
@@ -9,22 +9,27 @@ export function ToolCard({ name, args, status, duration, result, error }) {
|
|
|
9
9
|
const icon = status === 'running' ? '\u25CF' :
|
|
10
10
|
status === 'failed' ? '\u2716' : '\u2714';
|
|
11
11
|
const argsStr = args ? JSON.stringify(args).slice(0, 60) : '';
|
|
12
|
-
const timeStr = duration ? ' ' + duration + 'ms' : '';
|
|
12
|
+
const timeStr = duration != null ? ' ' + duration + 'ms' : (status === 'running' ? ' 0ms' : '');
|
|
13
|
+
const w = process.stdout.columns || 80;
|
|
13
14
|
|
|
14
|
-
return h(Box, { flexDirection: 'column', marginY: 1,
|
|
15
|
+
return h(Box, { flexDirection: 'column', marginY: 1, marginLeft: 0,
|
|
16
|
+
borderStyle: 'round', borderColor: col, backgroundColor: theme.surfaceAlt },
|
|
15
17
|
h(Box, { flexDirection: 'row', gap: 1, paddingX: 1 },
|
|
16
|
-
h(Text, { color: col }, icon + ' ' + name),
|
|
17
|
-
argsStr ? h(Text, { color: theme.textMuted }, argsStr) : null,
|
|
18
|
-
timeStr ? h(Text, { color: theme.textMuted }, timeStr) : null,
|
|
18
|
+
h(Text, { color: col, bold: true }, icon + ' ' + name),
|
|
19
|
+
argsStr ? h(Text, { color: theme.textMuted, wrap: 'truncate-end' }, argsStr) : null,
|
|
19
20
|
),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
h(Box, { flexDirection: 'row', paddingX: 1, gap: 2 },
|
|
22
|
+
h(Text, { color: theme.textMuted }, '\u29D6 ' + (status === 'running' ? 'running' : status)),
|
|
23
|
+
timeStr ? h(Text, { color: theme.textMuted }, '\u29D7 ' + timeStr.trim()) : null,
|
|
24
|
+
),
|
|
25
|
+
(status === 'completed' && result)
|
|
26
|
+
? h(Box, { paddingX: 1, paddingTop: 1, borderStyle: 'single', borderColor: theme.border },
|
|
27
|
+
h(Text, { color: theme.textDim, wrap: 'wrap' }, String(result).slice(0, Math.min(w - 8, 300)))
|
|
23
28
|
)
|
|
24
29
|
: null,
|
|
25
|
-
status === 'failed' && error
|
|
26
|
-
? h(Box, { paddingX: 1 },
|
|
27
|
-
h(Text, { color: theme.error, wrap: 'wrap' }, String(error).slice(0,
|
|
30
|
+
(status === 'failed' && error)
|
|
31
|
+
? h(Box, { paddingX: 1, paddingTop: 1 },
|
|
32
|
+
h(Text, { color: theme.error, wrap: 'wrap' }, String(error).slice(0, w - 6))
|
|
28
33
|
)
|
|
29
34
|
: null,
|
|
30
35
|
);
|