clarity-ai 6.0.0 → 6.1.0

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 CHANGED
@@ -5,6 +5,9 @@ import { App } from '../src/app.js';
5
5
  import { hasKey } from '../src/config/keys.js';
6
6
  import { createInterface } from 'readline';
7
7
 
8
+ // Full terminal reset: clear screen, reset cursor, reset scrollback
9
+ process.stdout.write('\x1Bc\x1b[2J\x1b[0f\x1b[?25h');
10
+
8
11
  async function main() {
9
12
  const provider = process.env.CLARITY_PROVIDER || 'groq';
10
13
 
@@ -18,13 +21,32 @@ async function main() {
18
21
  });
19
22
  const { setKey } = await import('../src/config/keys.js');
20
23
  setKey(provider, key);
24
+ // Re-clear after key prompt
25
+ process.stdout.write('\x1Bc\x1b[2J\x1b[0f');
21
26
  }
22
27
 
23
28
  const config = { provider, model: process.env.CLARITY_MODEL || 'groq/llama-3.3-70b-versatile' };
24
- render(React.createElement(App, { config }), { fullscreen: true });
29
+
30
+ const { waitUntilExit } = render(React.createElement(App, { config }), { fullscreen: true });
31
+
32
+ // Cleanup handlers
33
+ function cleanup() {
34
+ process.stdout.write('\x1Bc\x1b[?25h\x1b[0m');
35
+ process.exit(0);
36
+ }
37
+
38
+ process.on('SIGINT', cleanup);
39
+ process.on('SIGTERM', cleanup);
40
+ process.on('exit', () => {
41
+ process.stdout.write('\x1Bc\x1b[?25h\x1b[0m');
42
+ });
43
+
44
+ await waitUntilExit;
45
+ cleanup();
25
46
  }
26
47
 
27
48
  main().catch(err => {
49
+ process.stdout.write('\x1Bc\x1b[?25h\x1b[0m');
28
50
  console.error('\n\x1b[31mFatal error:\x1b[0m', err.message);
29
51
  process.exit(1);
30
52
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-ai",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
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, state, setState, setModel, setProvider, model, provider);
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(state, setState, input, model, provider, setStreamContent);
30
- }, [state, model, provider, showBanner]);
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
- return h(Box, { flexDirection: 'column', height: '100%' },
49
- h(Box, { flexGrow: 1, flexDirection: 'column' },
50
- showBanner ? h(Banner) : null,
51
- h(MessageList, {
52
- messages: state.messages,
53
- thinking: state.thinking,
54
- streamContent,
55
- agentStatus: state.agentStatus,
56
- toolExecutions: state.toolExecutions,
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: '#0A0A0A', borderStyle: 'round', borderColor: '#333', paddingX: 2, paddingY: 1 },
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: '#0A0A0A', borderStyle: 'round', borderColor: '#333', paddingX: 2, paddingY: 1 },
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); setCursorLine(s.col);
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); setCursorLine(s.col); return; }
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); setCursorLine(s.col); return; }
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); setCursorLine(s.col); return; }
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); setCursorLine(s.col); return; }
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); setCursorLine(s.col);
56
+ setLines([...s.lines]); setCursorLine(s.line); setCursorCol(s.col);
58
57
  }
59
58
  });
60
59